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