This commit was manufactured by cvs2svn to create tag 'lyx-1_1_2'.
[lyx.git] / src / lyxfr0.C
blob27e85b893b4af5973a6a58b77782b78efbad533b
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  * ======================================================*/
11 #include <config.h>
13 #include <cctype>
14 #include <cstring>
15 #include <cstdlib>
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
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
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;
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;
43 //---------------------------------------------------------------
46 // callbacks for form form_search
47 void SearchCancelCB(FL_OBJECT *, long)
49         _FR.SearchCancelCB();
53 void SearchForwardCB(FL_OBJECT *, long)
55         _FR.SearchCB(true);
59 void SearchBackwardCB(FL_OBJECT *, long)
61         _FR.SearchCB(false);
65 void SearchReplaceAllCB(FL_OBJECT *, long)
67         _FR.SearchReplaceAllCB();
71 void SearchReplaceCB(FL_OBJECT *, long)
73         _FR.SearchReplaceCB();
77 //--------------------- LyXFindReplace0's implementation ------------
79 LyXFindReplace0::LyXFindReplace0()
81         fCaseSensitive = false;
82         fMatchWord = false;
86 void LyXFindReplace0::StartSearch()
88         static int ow = -1, oh;
90         FD_form_search *fd_fs = fd_form_search;
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();
108 void LyXFindReplace0::ReInitFromForm()
110         FD_form_search *fd_fs = fd_form_search;
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);
118 // Returns the value of the replace string in the form
119 string const LyXFindReplace0::ReplaceString()
121         return string(fl_get_input(fd_form_search->input_replace));
125 void LyXFindReplace0::SearchCancelCB()
127         fl_hide_form(fd_form_search->form_search);
131 void LyXFindReplace0::SetReplaceEnabled(bool fEnable)
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         }
153 void LyXFindReplace0::SetSearchString(string const &ls)
155         lsSearch = ls;
156         fl_set_input(fd_form_search->input_search, ls.c_str()); 
160 //---------------------------------------------------------------
161 //HB??: Maybe _FR.StartSearch should be called in lyxfunc.C instead of MenuSearch() ?
163 void MenuSearch()
165         _FR.StartSearch();