]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/lseditor/finddlg.cpp
Fix from Mumit Khan to allow mingw DLL compilation, v.2 :-)
[wxWidgets.git] / utils / wxPython / modules / lseditor / finddlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 08/05/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandars Gluchovas
9 // Licence: GNU General Public License
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "finddlg.h"
24
25 /***** Implementation for class wxFindTextDialog *****/
26
27 //#define wxID_OK 3453453
28
29 BEGIN_EVENT_TABLE( wxFindTextDialog, wxDialog )
30
31 // FIXME:: why OnOk() is not called??
32 //EVT_BUTTON( wxID_OK, wxFindTextDialog::OnOK )
33
34 EVT_CHAR_HOOK(wxFindTextDialog::OnKeyHook)
35
36 END_EVENT_TABLE()
37
38 wxString wxFindTextDialog::mLastExpr;
39 bool wxFindTextDialog::mMatchCase = TRUE;
40 bool wxFindTextDialog::mMatchWord = FALSE;
41 StrListT wxFindTextDialog::mExprList;
42
43 // FIXME:: workaround for mystic. crashes wiht MSDev4.0
44
45 static wxComboBox* __gpCombo = NULL;
46
47 wxFindTextDialog::wxFindTextDialog( wxWindow* parent, const string& expr )
48
49 : wxDialog( parent, -1, "Find",
50 wxDefaultPosition, wxSize( 335, 130 ),
51 wxDIALOG_MODAL | wxCAPTION | wxTAB_TRAVERSAL |
52 wxDEFAULT_DIALOG_STYLE
53 )
54 {
55 mLastExpr = expr;
56
57 int leftMargin = 20;
58 int inputY = 20;
59 int inputWidth = 200;
60
61 wxStaticText* pStatic =
62 new wxStaticText( this, -1, "Fi&nd what:",
63 wxPoint( leftMargin, inputY ) );
64
65 int checkY = inputY + 25;
66
67 mpWordCheck = new wxCheckBox( this, -1, "Match &whole word only",
68 wxPoint( leftMargin, checkY ) );
69
70 mpCaseCheck = new wxCheckBox( this, -1, "Match &case",
71 wxPoint( leftMargin, checkY + 20 ) );
72
73 mpCaseCheck->SetValue( mMatchCase );
74 mpWordCheck->SetValue( mMatchWord );
75
76 int btnX = inputWidth + leftMargin + 23;
77 int btnY = inputY - 4;
78
79 wxSize btnSize( 70, 25 );
80
81 wxButton* pOkBtn = new wxButton( this, wxID_OK, "&Find",
82 wxPoint( btnX, btnY ), btnSize );
83
84 wxButton* pCancelBtn = new wxButton( this, wxID_CANCEL, "&Cancel",
85 wxPoint( btnX, btnY + 10 + btnSize.y ), btnSize );
86
87 __gpCombo = new wxComboBox( this, -1, mLastExpr,
88 wxPoint( leftMargin + 60, inputY - 2 ),
89 wxSize( inputWidth - 50, 20 ) );
90
91 for( size_t i = 0; i != mExprList.size(); ++i )
92
93 __gpCombo->Append( mExprList[i] );
94
95 pOkBtn->SetDefault();
96 __gpCombo->SetFocus();
97
98 Center( wxBOTH );
99 }
100
101 void wxFindTextDialog::SetExpr( const wxString& expr )
102 {
103 mLastExpr = expr;
104 __gpCombo->SetValue( mLastExpr );
105
106 }
107
108 wxComboBox* wxFindTextDialog::GetCombo()
109 {
110 return __gpCombo;
111 }
112
113 bool wxFindTextDialog::TransferDataFromWindow()
114 {
115 mLastExpr = GetCombo()->GetValue();
116 mMatchCase = mpCaseCheck->GetValue();
117 mMatchWord = mpWordCheck->GetValue();
118
119 if ( mLastExpr != "" )
120 {
121 for( size_t i = 0; i != mExprList.size(); ++i )
122
123 if ( mExprList[i] == mLastExpr )
124
125 return TRUE;
126 }
127
128 if ( mExprList.size() > 20 )
129
130 mExprList.pop_back();
131
132 mExprList.push_back( mLastExpr );
133
134 return TRUE;
135 }
136
137 void wxFindTextDialog::OnKeyHook( wxKeyEvent& event )
138 {
139 if ( event.m_keyCode == WXK_RETURN )
140 {
141 TransferDataFromWindow();
142 EndModal( wxID_OK );
143 }
144 else
145 event.Skip();
146 }