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