NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
fndrpldialog.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "fndrpldialog.hpp"
20#include "../globals.hpp"
21#include "../../kernel/core/ui/language.hpp"
22extern Language _guilang;
23
24
26
27BEGIN_EVENT_TABLE(FindReplaceDialog, wxDialog)
28 EVT_BUTTON(wxID_FIND, FindReplaceDialog::OnFind)
29 EVT_BUTTON(wxID_REPLACE, FindReplaceDialog::OnReplace)
30 EVT_BUTTON(wxID_REPLACE_ALL, FindReplaceDialog::OnReplaceAll)
31 EVT_BUTTON(wxID_CANCEL, FindReplaceDialog::OnCancel)
32
33 EVT_UPDATE_UI(wxID_FIND, FindReplaceDialog::OnUpdateFindUI)
34 EVT_UPDATE_UI(wxID_REPLACE, FindReplaceDialog::OnUpdateFindUI)
35 EVT_UPDATE_UI(wxID_REPLACE_ALL, FindReplaceDialog::OnUpdateFindUI)
36
37// EVT_ENTER_WINDOW(FindReplaceDialog::OnEnter)
39 //EVT_KILL_FOCUS(FindReplaceDialog::OnLoseFocus)
40
42
43 EVT_NOTEBOOK_PAGE_CHANGED(-1, FindReplaceDialog::OnPageChange)
45
46// ----------------------------------------------------------------------------
47// wxGenericFindReplaceDialog
48// ----------------------------------------------------------------------------
49
51{
52 m_FindReplaceData = nullptr;
53
54 m_chkWord =
55 m_chkCase =
56 m_chkWrapAround =
57 m_chkWordRepl =
58 m_chkWrapAroundRepl =
59 m_chkCaseRepl = nullptr;
60
61 m_radioDir =
62 m_radioDirRepl = nullptr;
63
64 m_textFind =
65 m_textFindRepl =
66 m_textRepl = nullptr;
67
68 m_tabs = nullptr;
69
70 m_skipFocusing = false;
71}
72
73bool FindReplaceDialog::Create(wxWindow *parent,
74 wxFindReplaceData *data,
75 const wxString& title,
76 int style)
77{
78 parent = GetParentForModalDialog(parent, style);
79
80 if ( !wxDialog::Create(parent, wxID_ANY, title,
81 wxDefaultPosition, wxSize(470*g_pixelScale,230*g_pixelScale),
82 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
83 | style) )
84 {
85 return false;
86 }
87
88 SetData(data);
89
90 wxCHECK_MSG( m_FindReplaceData, false,
91 wxT("can't create dialog without data") );
92
93 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
94
95 m_tabs = new ViewerBook(this, wxID_ANY, wxDefaultPosition , wxSize(470*g_pixelScale,230*g_pixelScale));
96 ViewerPanel* findpage = new ViewerPanel(m_tabs, wxID_ANY);
97 ViewerPanel* replacepage = new ViewerPanel(m_tabs, wxID_ANY);
98
99 wxBoxSizer *leftsizer_find = new wxBoxSizer( wxVERTICAL );
100 wxBoxSizer *leftsizer_replace = new wxBoxSizer( wxVERTICAL );
101
102 // 3 columns because there is a spacer in the middle
103 wxFlexGridSizer *sizer2Col_find = new wxFlexGridSizer(3);
104 wxFlexGridSizer *sizer2Col_replace = new wxFlexGridSizer(3);
105 sizer2Col_find->AddGrowableCol(2);
106 sizer2Col_replace->AddGrowableCol(2);
107
108 sizer2Col_find->Add(new wxStaticText(findpage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_SEARCHFOR"),
109 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
110 0,
111 wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT);
112
113 sizer2Col_replace->Add(new wxStaticText(replacepage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_SEARCHFOR"),
114 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
115 0,
116 wxALIGN_CENTRE_VERTICAL | wxALIGN_RIGHT);
117
118 sizer2Col_find->Add(10, 0);
119 sizer2Col_replace->Add(10, 0);
120
121 m_textFind = new wxTextCtrl(findpage, wxID_ANY, m_FindReplaceData->GetFindString());
122 sizer2Col_find->Add(m_textFind, 1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
123 m_textFindRepl = new wxTextCtrl(replacepage, wxID_ANY, m_FindReplaceData->GetFindString());
124 sizer2Col_replace->Add(m_textFindRepl, 1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
125
126 //if ( style & wxFR_REPLACEDIALOG )
127 {
128 sizer2Col_replace->Add(new wxStaticText(replacepage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_REPLACEWITH"),
129 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
130 0,
131 wxALIGN_CENTRE_VERTICAL |
132 wxALIGN_RIGHT | wxTOP, 5);
133
134 sizer2Col_replace->Add(isPda ? 2 : 10, 0);
135
136 m_textRepl = new wxTextCtrl(replacepage, wxID_ANY,
137 m_FindReplaceData->GetReplaceString());
138 sizer2Col_replace->Add(m_textRepl, 1,
139 wxALIGN_CENTRE_VERTICAL | wxEXPAND | wxTOP, 5);
140 }
141
142 leftsizer_find->Add(sizer2Col_find, 0, wxEXPAND | wxALL, 5);
143 leftsizer_replace->Add(sizer2Col_replace, 0, wxEXPAND | wxALL, 5);
144
145 wxBoxSizer *optsizer_find = new wxBoxSizer( isPda ? wxVERTICAL : wxHORIZONTAL );
146 wxBoxSizer *optsizer_replace = new wxBoxSizer( isPda ? wxVERTICAL : wxHORIZONTAL );
147
148 wxBoxSizer *chksizer_find = new wxBoxSizer( wxVERTICAL);
149 wxBoxSizer *chksizer_replace = new wxBoxSizer( wxVERTICAL);
150
151 m_chkWord = new wxCheckBox(findpage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_WHOLEWORD"));
152 chksizer_find->Add(m_chkWord, 0, wxALL, 3);
153
154 m_chkCase = new wxCheckBox(findpage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_MATCHCASE"));
155 chksizer_find->Add(m_chkCase, 0, wxALL, 3);
156
157 m_chkWrapAround = new wxCheckBox(findpage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_WRAPAROUND"));
158 chksizer_find->Add(m_chkWrapAround, 0, wxALL, 3);
159
160 m_chkWordRepl = new wxCheckBox(replacepage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_WHOLEWORD"));
161 chksizer_replace->Add(m_chkWordRepl, 0, wxALL, 3);
162
163 m_chkCaseRepl = new wxCheckBox(replacepage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_MATCHCASE"));
164 chksizer_replace->Add(m_chkCaseRepl, 0, wxALL, 3);
165
166 m_chkWrapAroundRepl = new wxCheckBox(replacepage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_WRAPAROUND"));
167 chksizer_replace->Add(m_chkWrapAroundRepl, 0, wxALL, 3);
168
169 optsizer_find->Add(chksizer_find, 0, wxALL, 10);
170 optsizer_replace->Add(chksizer_replace, 0, wxALL, 10);
171
172 static const wxString searchDirections[] = {_guilang.get("GUI_DLG_FNDRPLC_DIR_UP"),_guilang.get("GUI_DLG_FNDRPLC_DIR_DOWN")};
173 int majorDimension = 0;
174 int rbStyle ;
175 if (isPda)
176 rbStyle = wxRA_SPECIFY_ROWS;
177 else
178 rbStyle = wxRA_SPECIFY_COLS;
179
180 m_radioDir = new wxRadioBox(findpage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_DIRECTION"),
181 wxDefaultPosition, wxDefaultSize,
182 WXSIZEOF(searchDirections), searchDirections,
183 majorDimension, rbStyle);
184
185 optsizer_find->Add(m_radioDir, 0, wxALL, isPda ? 5 : 10);
186
187 m_radioDirRepl = new wxRadioBox(replacepage, wxID_ANY, _guilang.get("GUI_DLG_FNDRPLC_DIRECTION"),
188 wxDefaultPosition, wxDefaultSize,
189 WXSIZEOF(searchDirections), searchDirections,
190 majorDimension, rbStyle);
191
192 optsizer_replace->Add(m_radioDirRepl, 0, wxALL, isPda ? 5 : 10);
193
194 leftsizer_find->Add(optsizer_find);
195 leftsizer_replace->Add(optsizer_replace);
196
197 wxBoxSizer *bttnsizer_find = new wxBoxSizer(wxVERTICAL);
198 wxBoxSizer *bttnsizer_replace = new wxBoxSizer(wxVERTICAL);
199
200 wxButton* btn_find = new wxButton(findpage, wxID_FIND, _guilang.get("GUI_DLG_FNDRPLC_BTN_FIND"));
201 wxButton* btn_replace = new wxButton(replacepage, wxID_FIND, _guilang.get("GUI_DLG_FNDRPLC_BTN_FIND"));
202 btn_find->SetDefault();
203
204 bttnsizer_find->Add(btn_find, 0, wxALL, 3);
205 bttnsizer_replace->Add(btn_replace, 0, wxALL, 3);
206
207 bttnsizer_find->Add(new wxButton(findpage, wxID_CANCEL, _guilang.get("GUI_DLG_FNDRPLC_BTN_CANCEL")), 0, wxALL, 3);
208 bttnsizer_replace->Add(new wxButton(replacepage, wxID_CANCEL, _guilang.get("GUI_DLG_FNDRPLC_BTN_CANCEL")), 0, wxALL, 3);
209
210 //if ( style & wxFR_REPLACEDIALOG )
211 {
212 bttnsizer_replace->Add(new wxButton(replacepage, wxID_REPLACE, _guilang.get("GUI_DLG_FNDRPLC_BTN_REPLACE")),
213 0, wxALL, 3);
214
215 bttnsizer_replace->Add(new wxButton(replacepage, wxID_REPLACE_ALL, _guilang.get("GUI_DLG_FNDRPLC_BTN_REPLACEALL")),
216 0, wxALL, 3);
217 }
218
219 wxBoxSizer *topsizer_find = new wxBoxSizer( wxHORIZONTAL );
220 wxBoxSizer *topsizer_replace = new wxBoxSizer( wxHORIZONTAL );
221
222 topsizer_find->Add(leftsizer_find, 1, wxALL, isPda ? 0 : 5);
223 topsizer_find->Add(bttnsizer_find, 0, wxALL, isPda ? 0 : 5);
224 topsizer_replace->Add(leftsizer_replace, 1, wxALL, isPda ? 0 : 5);
225 topsizer_replace->Add(bttnsizer_replace, 0, wxALL, isPda ? 0 : 5);
226
227 InitPage();
228
229 //SetAutoLayout( true );
230
231 findpage->SetSizer(topsizer_find);
232 replacepage->SetSizer(topsizer_replace);
233 topsizer_find->SetSizeHints( findpage );
234 topsizer_find->Fit( findpage );
235 topsizer_replace->SetSizeHints( replacepage );
236 topsizer_replace->Fit( replacepage );
237
238 m_tabs->AddPage(findpage, _guilang.get("GUI_DLG_FIND"), (style & wxFR_REPLACEDIALOG) ? false : true);
239 m_tabs->AddPage(replacepage, _guilang.get("GUI_DLG_REPLACE"), (style & wxFR_REPLACEDIALOG) ? true : false);
240 //SetSizer( topsizer_find );
241
242
243 Centre( wxBOTH );
244
245 //m_textFind->SetFocus();
246
247 return true;
248}
249
251{
252 m_textFind->SetValue(m_FindReplaceData->GetFindString());
253 m_textFindRepl->SetValue(m_FindReplaceData->GetFindString());
254 m_textRepl->SetValue(m_FindReplaceData->GetReplaceString());
255
256 int flags = m_FindReplaceData->GetFlags();
257
258 if ( flags & wxFR_MATCHCASE )
259 {
260 m_chkCase->SetValue(true);
261 m_chkCaseRepl->SetValue(true);
262 }
263 if ( flags & wxFR_WHOLEWORD )
264 {
265 m_chkWord->SetValue(true);
266 m_chkWordRepl->SetValue(true);
267 }
268 if ( flags & wxFR_WRAPAROUND )
269 {
270 m_chkWrapAround->SetValue(true);
271 m_chkWrapAroundRepl->SetValue(true);
272 }
273 m_radioDir->SetSelection( flags & wxFR_DOWN );
274 m_radioDirRepl->SetSelection( flags & wxFR_DOWN );
275
276 /*if ( style & wxFR_NOMATCHCASE )
277 m_chkCase->Enable(false);
278
279 if ( style & wxFR_NOWHOLEWORD )
280 m_chkWord->Enable(false);
281
282 if ( style & wxFR_NOUPDOWN)
283 m_radioDir->Enable(false);*/
284}
285
286
287void FindReplaceDialog::OnPageChange(wxNotebookEvent& event)
288{
289 InitPage();
290 wxDialog::SetTitle("NumeRe: " + m_tabs->GetPageText(event.GetSelection()));
291}
292
293// ----------------------------------------------------------------------------
294// send the notification event
295// ----------------------------------------------------------------------------
296
297void FindReplaceDialog::SendEvent(const wxEventType& evtType)
298{
299 wxFindDialogEvent event(evtType, GetId());
300 event.SetEventObject(this);
301 int flags = 0;
302 if (m_tabs->GetSelection()) //replace
303 {
304 event.SetFindString(m_textFindRepl->GetValue());
305 event.SetReplaceString(m_textRepl->GetValue());
306 if ( m_chkCaseRepl->GetValue() )
307 flags |= wxFR_MATCHCASE;
308 if ( m_chkWordRepl->GetValue() )
309 flags |= wxFR_WHOLEWORD;
310 if ( m_chkWrapAroundRepl->GetValue() )
311 flags |= wxFR_WRAPAROUND;
312 if ( !m_radioDirRepl || m_radioDirRepl->GetSelection() == 1 )
313 {
314 flags |= wxFR_DOWN;
315 }
316 }
317 else // find
318 {
319 event.SetFindString(m_textFind->GetValue());
320 if ( m_chkCase->GetValue() )
321 flags |= wxFR_MATCHCASE;
322 if ( m_chkWord->GetValue() )
323 flags |= wxFR_WHOLEWORD;
324 if ( m_chkWrapAround->GetValue() )
325 flags |= wxFR_WRAPAROUND;
326 if ( !m_radioDir || m_radioDir->GetSelection() == 1 )
327 {
328 flags |= wxFR_DOWN;
329 }
330 }
331
332 event.SetFlags(flags);
333
334 wxFindReplaceDialogBase::Send(event);
335}
336
337// ----------------------------------------------------------------------------
338// event handlers
339// ----------------------------------------------------------------------------
340
341void FindReplaceDialog::OnFind(wxCommandEvent& WXUNUSED(event))
342{
343 SendEvent(wxEVT_FIND_NEXT);
344}
345
346void FindReplaceDialog::OnReplace(wxCommandEvent& WXUNUSED(event))
347{
348 SendEvent(wxEVT_FIND_REPLACE);
349}
350
351void FindReplaceDialog::OnReplaceAll(wxCommandEvent& WXUNUSED(event))
352{
353 SendEvent(wxEVT_FIND_REPLACE_ALL);
354}
355
356void FindReplaceDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
357{
358 SendEvent(wxEVT_FIND_CLOSE);
359
360 Show(false);
361}
362
363void FindReplaceDialog::OnEnter(wxMouseEvent& event)
364{
365 if (!m_skipFocusing)
366 this->SetFocus();
367 event.Skip();
368}
369
370void FindReplaceDialog::OnGainFocus(wxFocusEvent& event)
371{
372 m_tabs->GetCurrentPage()->SetFocus();
373 if (m_tabs->GetSelection()) // findreplace
374 {
375 m_textFindRepl->SetFocus();
376 }
377 else // find
378 {
379 m_textFind->SetFocus();
380 }
381 event.Skip();
382}
383
384void FindReplaceDialog::OnLoseFocus(wxFocusEvent& event)
385{
386 this->SetTransparent(100);
387 event.Skip();
388}
389
390void FindReplaceDialog::OnUpdateFindUI(wxUpdateUIEvent &event)
391{
392 // we can't search for empty strings
393 event.Enable( !m_textFind->GetValue().empty() || !m_textFindRepl->GetValue().empty() );
394}
395
397{
398 SendEvent(wxEVT_FIND_CLOSE);
399}
400
402{
403 m_tabs->GetCurrentPage()->SetFocus();
404 if (m_tabs->GetSelection()) // findreplace
405 {
406 m_textFindRepl->SetFocus();
407 }
408 else // find
409 {
410 m_textFind->SetFocus();
411 }
412}
double g_pixelScale
void OnReplaceAll(wxCommandEvent &event)
wxCheckBox * m_chkWrapAround
void OnCancel(wxCommandEvent &event)
void OnLoseFocus(wxFocusEvent &event)
wxCheckBox * m_chkCase
void OnCloseWindow(wxCloseEvent &event)
wxTextCtrl * m_textFind
void OnEnter(wxMouseEvent &event)
ViewerBook * m_tabs
void OnUpdateFindUI(wxUpdateUIEvent &event)
wxTextCtrl * m_textRepl
wxRadioBox * m_radioDir
void OnFind(wxCommandEvent &event)
bool Create(wxWindow *parent, wxFindReplaceData *data, const wxString &title, int style=0)
wxRadioBox * m_radioDirRepl
void OnPageChange(wxNotebookEvent &event)
wxCheckBox * m_chkWrapAroundRepl
wxCheckBox * m_chkCaseRepl
wxCheckBox * m_chkWordRepl
wxCheckBox * m_chkWord
wxTextCtrl * m_textFindRepl
void OnReplace(wxCommandEvent &event)
void OnGainFocus(wxFocusEvent &event)
void SendEvent(const wxEventType &evtType)
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
Language _guilang
#define wxFR_WRAPAROUND
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow, wxWindow)