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