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