1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/srchctlg.h
3 // Purpose: generic wxSearchCtrl class
4 // Author: Vince Harron
7 // Copyright: Vince Harron
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERIC_SEARCHCTRL_H_
12 #define _WX_GENERIC_SEARCHCTRL_H_
16 #include "wx/bitmap.h"
18 class WXDLLIMPEXP_FWD_CORE wxSearchButton
;
19 class WXDLLIMPEXP_FWD_CORE wxSearchTextCtrl
;
21 // ----------------------------------------------------------------------------
22 // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_CORE wxSearchCtrl
: public wxSearchCtrlBase
32 wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
33 const wxString
& value
= wxEmptyString
,
34 const wxPoint
& pos
= wxDefaultPosition
,
35 const wxSize
& size
= wxDefaultSize
,
37 const wxValidator
& validator
= wxDefaultValidator
,
38 const wxString
& name
= wxSearchCtrlNameStr
);
40 virtual ~wxSearchCtrl();
42 bool Create(wxWindow
*parent
, wxWindowID id
,
43 const wxString
& value
= wxEmptyString
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
47 const wxValidator
& validator
= wxDefaultValidator
,
48 const wxString
& name
= wxSearchCtrlNameStr
);
51 // get/set search button menu
52 // --------------------------
53 virtual void SetMenu( wxMenu
* menu
);
54 virtual wxMenu
* GetMenu();
57 // get/set search options
58 // ----------------------
59 virtual void ShowSearchButton( bool show
);
60 virtual bool IsSearchButtonVisible() const;
62 virtual void ShowCancelButton( bool show
);
63 virtual bool IsCancelButtonVisible() const;
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;
72 virtual wxString
GetRange(long from
, long to
) const;
74 virtual int GetLineLength(long lineNo
) const;
75 virtual wxString
GetLineText(long lineNo
) const;
76 virtual int GetNumberOfLines() const;
78 virtual bool IsModified() const;
79 virtual bool IsEditable() const;
81 // more readable flag testing methods
82 virtual bool IsSingleLine() const;
83 virtual bool IsMultiLine() const;
85 // If the return values from and to are the same, there is no selection.
86 virtual void GetSelection(long* from
, long* to
) const;
88 virtual wxString
GetStringSelection() const;
95 virtual void Replace(long from
, long to
, const wxString
& value
);
96 virtual void Remove(long from
, long to
);
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
);
102 // sets/clears the dirty flag
103 virtual void MarkDirty();
104 virtual void DiscardEdits();
106 // set the max number of characters which may be entered in a single line
108 virtual void SetMaxLength(unsigned long WXUNUSED(len
));
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
);
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
);
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;
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;
133 virtual void ShowPosition(long pos
);
135 // find the character at position given in pixels
137 // NB: pt is in device coords (not adjusted for the client area origin nor
139 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
140 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
142 wxTextCoord
*row
) const;
144 // Clipboard operations
147 virtual void Paste();
149 virtual bool CanCopy() const;
150 virtual bool CanCut() const;
151 virtual bool CanPaste() const;
157 virtual bool CanUndo() const;
158 virtual bool CanRedo() const;
161 virtual void SetInsertionPoint(long pos
);
162 virtual void SetInsertionPointEnd();
163 virtual long GetInsertionPoint() const;
164 virtual wxTextPos
GetLastPosition() const;
166 virtual void SetSelection(long from
, long to
);
167 virtual void SelectAll();
168 virtual void SetEditable(bool editable
);
172 // override streambuf method
173 #if wxHAS_TEXT_WINDOW_STREAM
175 #endif // wxHAS_TEXT_WINDOW_STREAM
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
);
187 // do the window-specific processing after processing the update event
188 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
190 virtual bool ShouldInheritColours() const;
192 // wxWindow overrides
193 virtual bool SetFont(const wxFont
& font
);
195 // search control generic only
196 void SetSearchBitmap( const wxBitmap
& bitmap
);
197 void SetCancelBitmap( const wxBitmap
& bitmap
);
199 void SetSearchMenuBitmap( const wxBitmap
& bitmap
);
200 #endif // wxUSE_MENUS
203 virtual void DoSetValue(const wxString
& value
, int flags
);
204 virtual wxString
DoGetValue() const;
206 virtual bool DoLoadFile(const wxString
& file
, int fileType
);
207 virtual bool DoSaveFile(const wxString
& file
, int fileType
);
209 // override the base class virtuals involved into geometry calculations
210 virtual wxSize
DoGetBestSize() const;
211 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
212 virtual void LayoutControls(int x
, int y
, int width
, int height
);
214 virtual void RecalcBitmaps();
218 virtual wxBitmap
RenderSearchBitmap( int x
, int y
, bool renderDrop
);
219 virtual wxBitmap
RenderCancelBitmap( int x
, int y
);
221 virtual void OnSearchButton( wxCommandEvent
& event
);
223 void OnSetFocus( wxFocusEvent
& event
);
224 void OnSize( wxSizeEvent
& event
);
229 return m_menu
!= NULL
;
230 #else // !wxUSE_MENUS
232 #endif // wxUSE_MENUS/!wxUSE_MENUS
236 friend class wxSearchButton
;
239 void PopupSearchMenu();
240 #endif // wxUSE_MENUS
243 wxSearchTextCtrl
*m_text
;
244 wxSearchButton
*m_searchButton
;
245 wxSearchButton
*m_cancelButton
;
248 #endif // wxUSE_MENUS
250 bool m_searchButtonVisible
;
251 bool m_cancelButtonVisible
;
253 bool m_searchBitmapUser
;
254 bool m_cancelBitmapUser
;
256 bool m_searchMenuBitmapUser
;
257 #endif // wxUSE_MENUS
259 wxBitmap m_searchBitmap
;
260 wxBitmap m_cancelBitmap
;
262 wxBitmap m_searchMenuBitmap
;
263 #endif // wxUSE_MENUS
266 DECLARE_DYNAMIC_CLASS(wxSearchCtrl
)
268 DECLARE_EVENT_TABLE()
271 #endif // wxUSE_SEARCHCTRL
273 #endif // _WX_GENERIC_SEARCHCTRL_H_