]> git.lyx.org Git - lyx.git/blob - src/lyxfr0.C
white-space changes, removed definitions.h several enum changes because of this,...
[lyx.git] / src / lyxfr0.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich,
7  *          Copyright 1995-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #include <cctype>
14 #include <cstring>
15 #include <cstdlib>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "LString.h"
22 #include "lyx_main.h"
23 #include FORMS_H_LOCATION
24 #include "form1.h"
25 #include "lyxfr0.h"
26 #include "lyxfr1.h"
27 #include "lyxfunc.h"
28 #include "lyxscreen.h"
29 #include "debug.h"
30 #include "lyxtext.h"
31 #include "gettext.h"
32 #include "LyXView.h" // only because of form_main
33
34 //---------------------------------------------------------------
35 // I hate global variables, but the same search object must be used everywhere,
36 // and the form is also global, so... 
37 LyXFindReplace1 _FR;
38
39 // This one should be a protected member of LyXFindReplace1
40 // Form creation/destruction must also be done in LyXFindReplace1
41 extern FD_form_search *fd_form_search;
42
43 //---------------------------------------------------------------
44
45
46 // callbacks for form form_search
47 void SearchCancelCB(FL_OBJECT *, long)
48 {
49         _FR.SearchCancelCB();
50 }
51
52
53 void SearchForwardCB(FL_OBJECT *, long)
54 {
55         _FR.SearchCB(true);
56 }
57
58
59 void SearchBackwardCB(FL_OBJECT *, long)
60 {
61         _FR.SearchCB(false);
62 }
63
64
65 void SearchReplaceAllCB(FL_OBJECT *, long)
66 {
67         _FR.SearchReplaceAllCB();
68 }
69
70
71 void SearchReplaceCB(FL_OBJECT *, long)
72 {
73         _FR.SearchReplaceCB();
74 }
75
76
77 //--------------------- LyXFindReplace0's implementation ------------
78
79 LyXFindReplace0::LyXFindReplace0()
80 {
81         fCaseSensitive = false;
82         fMatchWord = false;
83 }
84
85
86 void LyXFindReplace0::StartSearch()
87 {
88         static int ow = -1, oh;
89
90         FD_form_search *fd_fs = fd_form_search;
91
92         if (fd_fs->form_search->visible) {
93                 fl_raise_form(fd_fs->form_search);
94         } else {
95                 fl_show_form(fd_fs->form_search,
96                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
97                              _("Find & Replace"));      // RVDK_PATCH_5
98                 if (ow < 0) {
99                         ow = fd_form_search->form_search->w;
100                         oh = fd_form_search->form_search->h;
101                 }
102                 fl_set_form_minsize(fd_form_search->form_search, ow, oh);
103         }
104         ReInitFromForm();
105 }
106
107
108 void LyXFindReplace0::ReInitFromForm()
109 {
110         FD_form_search *fd_fs = fd_form_search;
111
112         lsSearch = fl_get_input(fd_fs->input_search);
113         fCaseSensitive = fl_get_button(fd_fs->btnCaseSensitive);
114         fMatchWord = fl_get_button(fd_fs->btnMatchWord);
115 }
116
117
118 // Returns the value of the replace string in the form
119 string const LyXFindReplace0::ReplaceString()
120 {
121         return string(fl_get_input(fd_form_search->input_replace));
122 }
123
124
125 void LyXFindReplace0::SearchCancelCB()
126 {
127         fl_hide_form(fd_form_search->form_search);
128 }
129
130
131 void LyXFindReplace0::SetReplaceEnabled(bool fEnable)
132 {
133         FD_form_search *fd_fs = fd_form_search;
134         fReplaceEnabled = fEnable;
135         if (fEnable) {
136         fl_activate_object(fd_fs->replace_button);
137         fl_activate_object(fd_fs->replaceall_button);
138         fl_activate_object(fd_fs->input_replace);
139                 fl_set_object_lcol(fd_fs->replace_button, FL_BLACK);
140                 fl_set_object_lcol(fd_fs->replaceall_button, FL_BLACK);
141                 fl_set_object_lcol(fd_fs->input_replace, FL_BLACK);
142         } else {
143         fl_deactivate_object(fd_fs->replace_button);
144         fl_deactivate_object(fd_fs->replaceall_button);
145         fl_deactivate_object(fd_fs->input_replace);
146                 fl_set_object_lcol(fd_fs->replace_button, FL_INACTIVE);
147                 fl_set_object_lcol(fd_fs->replaceall_button, FL_INACTIVE);
148                 fl_set_object_lcol(fd_fs->input_replace, FL_INACTIVE);
149         }
150 }
151
152
153 void LyXFindReplace0::SetSearchString(string const &ls)
154 {
155         lsSearch = ls;
156         fl_set_input(fd_form_search->input_search, ls.c_str()); 
157 }
158
159
160 //---------------------------------------------------------------
161 //HB??: Maybe _FR.StartSearch should be called in lyxfunc.C instead of MenuSearch() ?
162
163 void MenuSearch()
164 {
165         _FR.StartSearch();   
166 }