]>
Commit | Line | Data |
---|---|---|
3f7f284d RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/generic/srchctlg.h | |
3 | // Purpose: generic wxSearchCtrl class | |
4 | // Author: Vince Harron | |
3f7f284d | 5 | // Created: 2006-02-19 |
8bc333d7 | 6 | // RCS-ID: $Id$ |
3f7f284d RD |
7 | // Copyright: Vince Harron |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_GENERIC_SEARCHCTRL_H_ | |
12 | #define _WX_GENERIC_SEARCHCTRL_H_ | |
13 | ||
14 | #if wxUSE_SEARCHCTRL | |
15 | ||
2efce8f1 RD |
16 | #include "wx/bitmap.h" |
17 | ||
b5dbe15d VS |
18 | class WXDLLIMPEXP_FWD_CORE wxSearchButton; |
19 | class WXDLLIMPEXP_FWD_CORE wxSearchTextCtrl; | |
3f7f284d | 20 | |
3f7f284d RD |
21 | // ---------------------------------------------------------------------------- |
22 | // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
53a2db12 | 25 | class WXDLLIMPEXP_CORE wxSearchCtrl : public wxSearchCtrlBase |
3f7f284d RD |
26 | { |
27 | public: | |
28 | // creation | |
29 | // -------- | |
30 | ||
31 | wxSearchCtrl(); | |
32 | wxSearchCtrl(wxWindow *parent, wxWindowID id, | |
33 | const wxString& value = wxEmptyString, | |
34 | const wxPoint& pos = wxDefaultPosition, | |
35 | const wxSize& size = wxDefaultSize, | |
36 | long style = 0, | |
37 | const wxValidator& validator = wxDefaultValidator, | |
38 | const wxString& name = wxSearchCtrlNameStr); | |
39 | ||
8bc333d7 | 40 | virtual ~wxSearchCtrl(); |
3f7f284d RD |
41 | |
42 | bool Create(wxWindow *parent, wxWindowID id, | |
43 | const wxString& value = wxEmptyString, | |
44 | const wxPoint& pos = wxDefaultPosition, | |
45 | const wxSize& size = wxDefaultSize, | |
46 | long style = 0, | |
47 | const wxValidator& validator = wxDefaultValidator, | |
48 | const wxString& name = wxSearchCtrlNameStr); | |
49 | ||
cfddeb10 | 50 | #if wxUSE_MENUS |
3f7f284d RD |
51 | // get/set search button menu |
52 | // -------------------------- | |
53 | virtual void SetMenu( wxMenu* menu ); | |
54 | virtual wxMenu* GetMenu(); | |
cfddeb10 | 55 | #endif // wxUSE_MENUS |
8bc333d7 | 56 | |
3f7f284d RD |
57 | // get/set search options |
58 | // ---------------------- | |
ec184e32 VZ |
59 | virtual void ShowSearchButton( bool show ); |
60 | virtual bool IsSearchButtonVisible() const; | |
3f7f284d | 61 | |
ec184e32 VZ |
62 | virtual void ShowCancelButton( bool show ); |
63 | virtual bool IsCancelButtonVisible() const; | |
3f7f284d | 64 | |
6646ca90 RD |
65 | // TODO: In 2.9 these should probably be virtual, and declared in the base class... |
66 | void SetDescriptiveText(const wxString& text); | |
67 | wxString GetDescriptiveText() const; | |
6646ca90 | 68 | |
3f7f284d RD |
69 | // accessors |
70 | // --------- | |
71 | ||
3f7f284d RD |
72 | virtual wxString GetRange(long from, long to) const; |
73 | ||
74 | virtual int GetLineLength(long lineNo) const; | |
75 | virtual wxString GetLineText(long lineNo) const; | |
76 | virtual int GetNumberOfLines() const; | |
77 | ||
78 | virtual bool IsModified() const; | |
79 | virtual bool IsEditable() const; | |
80 | ||
81 | // more readable flag testing methods | |
82 | virtual bool IsSingleLine() const; | |
83 | virtual bool IsMultiLine() const; | |
84 | ||
85 | // If the return values from and to are the same, there is no selection. | |
86 | virtual void GetSelection(long* from, long* to) const; | |
87 | ||
88 | virtual wxString GetStringSelection() const; | |
89 | ||
90 | // operations | |
91 | // ---------- | |
92 | ||
93 | // editing | |
94 | virtual void Clear(); | |
95 | virtual void Replace(long from, long to, const wxString& value); | |
96 | virtual void Remove(long from, long to); | |
97 | ||
98 | // load/save the controls contents from/to the file | |
99 | virtual bool LoadFile(const wxString& file); | |
100 | virtual bool SaveFile(const wxString& file = wxEmptyString); | |
101 | ||
102 | // sets/clears the dirty flag | |
103 | virtual void MarkDirty(); | |
104 | virtual void DiscardEdits(); | |
105 | ||
106 | // set the max number of characters which may be entered in a single line | |
107 | // text control | |
108 | virtual void SetMaxLength(unsigned long WXUNUSED(len)); | |
109 | ||
110 | // writing text inserts it at the current position, appending always | |
111 | // inserts it at the end | |
112 | virtual void WriteText(const wxString& text); | |
113 | virtual void AppendText(const wxString& text); | |
114 | ||
115 | // insert the character which would have resulted from this key event, | |
116 | // return true if anything has been inserted | |
117 | virtual bool EmulateKeyPress(const wxKeyEvent& event); | |
118 | ||
119 | // text control under some platforms supports the text styles: these | |
120 | // methods allow to apply the given text style to the given selection or to | |
121 | // set/get the style which will be used for all appended text | |
122 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); | |
123 | virtual bool GetStyle(long position, wxTextAttr& style); | |
124 | virtual bool SetDefaultStyle(const wxTextAttr& style); | |
125 | virtual const wxTextAttr& GetDefaultStyle() const; | |
126 | ||
127 | // translate between the position (which is just an index in the text ctrl | |
128 | // considering all its contents as a single strings) and (x, y) coordinates | |
129 | // which represent column and line. | |
130 | virtual long XYToPosition(long x, long y) const; | |
131 | virtual bool PositionToXY(long pos, long *x, long *y) const; | |
132 | ||
133 | virtual void ShowPosition(long pos); | |
134 | ||
135 | // find the character at position given in pixels | |
136 | // | |
137 | // NB: pt is in device coords (not adjusted for the client area origin nor | |
138 | // scrolling) | |
139 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; | |
140 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, | |
141 | wxTextCoord *col, | |
142 | wxTextCoord *row) const; | |
143 | ||
144 | // Clipboard operations | |
145 | virtual void Copy(); | |
146 | virtual void Cut(); | |
147 | virtual void Paste(); | |
148 | ||
149 | virtual bool CanCopy() const; | |
150 | virtual bool CanCut() const; | |
151 | virtual bool CanPaste() const; | |
152 | ||
153 | // Undo/redo | |
154 | virtual void Undo(); | |
155 | virtual void Redo(); | |
156 | ||
157 | virtual bool CanUndo() const; | |
158 | virtual bool CanRedo() const; | |
159 | ||
160 | // Insertion point | |
161 | virtual void SetInsertionPoint(long pos); | |
162 | virtual void SetInsertionPointEnd(); | |
163 | virtual long GetInsertionPoint() const; | |
164 | virtual wxTextPos GetLastPosition() const; | |
165 | ||
166 | virtual void SetSelection(long from, long to); | |
167 | virtual void SelectAll(); | |
168 | virtual void SetEditable(bool editable); | |
169 | ||
170 | #if 0 | |
171 | ||
172 | // override streambuf method | |
173 | #if wxHAS_TEXT_WINDOW_STREAM | |
174 | int overflow(int i); | |
175 | #endif // wxHAS_TEXT_WINDOW_STREAM | |
176 | ||
177 | // stream-like insertion operators: these are always available, whether we | |
178 | // were, or not, compiled with streambuf support | |
179 | wxTextCtrl& operator<<(const wxString& s); | |
180 | wxTextCtrl& operator<<(int i); | |
181 | wxTextCtrl& operator<<(long i); | |
182 | wxTextCtrl& operator<<(float f); | |
183 | wxTextCtrl& operator<<(double d); | |
184 | wxTextCtrl& operator<<(const wxChar c); | |
185 | #endif | |
186 | ||
187 | // do the window-specific processing after processing the update event | |
188 | virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); | |
189 | ||
190 | virtual bool ShouldInheritColours() const; | |
191 | ||
192 | // wxWindow overrides | |
193 | virtual bool SetFont(const wxFont& font); | |
35368572 | 194 | virtual bool SetBackgroundColour(const wxColour& colour); |
3f7f284d RD |
195 | |
196 | // search control generic only | |
197 | void SetSearchBitmap( const wxBitmap& bitmap ); | |
3f7f284d | 198 | void SetCancelBitmap( const wxBitmap& bitmap ); |
cfddeb10 VZ |
199 | #if wxUSE_MENUS |
200 | void SetSearchMenuBitmap( const wxBitmap& bitmap ); | |
201 | #endif // wxUSE_MENUS | |
3f7f284d RD |
202 | |
203 | protected: | |
0ec1179b | 204 | virtual void DoSetValue(const wxString& value, int flags); |
135b23b2 | 205 | virtual wxString DoGetValue() const; |
135b23b2 | 206 | |
0ec1179b VZ |
207 | virtual bool DoLoadFile(const wxString& file, int fileType); |
208 | virtual bool DoSaveFile(const wxString& file, int fileType); | |
3f7f284d RD |
209 | |
210 | // override the base class virtuals involved into geometry calculations | |
211 | virtual wxSize DoGetBestSize() const; | |
212 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
213 | virtual void LayoutControls(int x, int y, int width, int height); | |
214 | ||
215 | virtual void RecalcBitmaps(); | |
216 | ||
217 | void Init(); | |
218 | ||
219 | virtual wxBitmap RenderSearchBitmap( int x, int y, bool renderDrop ); | |
220 | virtual wxBitmap RenderCancelBitmap( int x, int y ); | |
221 | ||
222 | virtual void OnSearchButton( wxCommandEvent& event ); | |
223 | ||
224 | void OnSetFocus( wxFocusEvent& event ); | |
af1f44f1 | 225 | void OnSize( wxSizeEvent& event ); |
cfddeb10 VZ |
226 | |
227 | bool HasMenu() const | |
228 | { | |
229 | #if wxUSE_MENUS | |
230 | return m_menu != NULL; | |
231 | #else // !wxUSE_MENUS | |
232 | return false; | |
233 | #endif // wxUSE_MENUS/!wxUSE_MENUS | |
234 | } | |
235 | ||
3f7f284d RD |
236 | private: |
237 | friend class wxSearchButton; | |
238 | ||
35368572 VZ |
239 | // Implement pure virtual function inherited from wxCompositeWindow. |
240 | virtual wxWindowList GetCompositeWindowParts() const; | |
241 | ||
cfddeb10 | 242 | #if wxUSE_MENUS |
3f7f284d | 243 | void PopupSearchMenu(); |
cfddeb10 | 244 | #endif // wxUSE_MENUS |
3f7f284d RD |
245 | |
246 | // the subcontrols | |
247 | wxSearchTextCtrl *m_text; | |
248 | wxSearchButton *m_searchButton; | |
249 | wxSearchButton *m_cancelButton; | |
cfddeb10 | 250 | #if wxUSE_MENUS |
3f7f284d | 251 | wxMenu *m_menu; |
cfddeb10 | 252 | #endif // wxUSE_MENUS |
3f7f284d RD |
253 | |
254 | bool m_searchButtonVisible; | |
255 | bool m_cancelButtonVisible; | |
256 | ||
257 | bool m_searchBitmapUser; | |
3f7f284d | 258 | bool m_cancelBitmapUser; |
cfddeb10 VZ |
259 | #if wxUSE_MENUS |
260 | bool m_searchMenuBitmapUser; | |
261 | #endif // wxUSE_MENUS | |
262 | ||
3f7f284d | 263 | wxBitmap m_searchBitmap; |
3f7f284d | 264 | wxBitmap m_cancelBitmap; |
cfddeb10 VZ |
265 | #if wxUSE_MENUS |
266 | wxBitmap m_searchMenuBitmap; | |
267 | #endif // wxUSE_MENUS | |
268 | ||
3f7f284d RD |
269 | private: |
270 | DECLARE_DYNAMIC_CLASS(wxSearchCtrl) | |
271 | ||
272 | DECLARE_EVENT_TABLE() | |
273 | }; | |
274 | ||
275 | #endif // wxUSE_SEARCHCTRL | |
276 | ||
277 | #endif // _WX_GENERIC_SEARCHCTRL_H_ | |
278 |