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