1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/srchctlg.h
3 // Purpose: generic wxSearchCtrl class
4 // Author: Vince Harron
8 // Copyright: Vince Harron
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_SEARCHCTRL_H_
13 #define _WX_GENERIC_SEARCHCTRL_H_
17 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma interface "srchctlg.h"
21 #include "wx/bitmap.h"
23 // ----------------------------------------------------------------------------
25 class WXDLLEXPORT wxSearchButton
;
26 class WXDLLEXPORT wxSearchTextCtrl
;
28 class WXDLLEXPORT wxSearchCtrlBase
: public wxTextCtrlBase
32 virtual ~wxSearchCtrlBase() {}
35 virtual void SetMenu( wxMenu
* menu
) = 0;
36 virtual wxMenu
* GetMenu() = 0;
40 virtual void SetSearchButtonVisible( bool show
) = 0;
41 virtual bool GetSearchButtonVisible() const = 0;
43 virtual void SetCancelButtonVisible( bool show
) = 0;
44 virtual bool GetCancelButtonVisible() const = 0;
48 // ----------------------------------------------------------------------------
49 // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton
50 // ----------------------------------------------------------------------------
52 class WXDLLEXPORT wxSearchCtrl
: public wxSearchCtrlBase
59 wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
60 const wxString
& value
= wxEmptyString
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 const wxSize
& size
= wxDefaultSize
,
64 const wxValidator
& validator
= wxDefaultValidator
,
65 const wxString
& name
= wxSearchCtrlNameStr
);
69 bool Create(wxWindow
*parent
, wxWindowID id
,
70 const wxString
& value
= wxEmptyString
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxValidator
& validator
= wxDefaultValidator
,
75 const wxString
& name
= wxSearchCtrlNameStr
);
77 // get/set search button menu
78 // --------------------------
79 virtual void SetMenu( wxMenu
* menu
);
80 virtual wxMenu
* GetMenu();
82 // get/set search options
83 // ----------------------
84 virtual void SetSearchButtonVisible( bool show
);
85 virtual bool GetSearchButtonVisible() const;
87 virtual void SetCancelButtonVisible( bool show
);
88 virtual bool GetCancelButtonVisible() const;
93 virtual wxString
GetValue() const;
94 virtual void SetValue(const wxString
& value
);
96 virtual wxString
GetRange(long from
, long to
) const;
98 virtual int GetLineLength(long lineNo
) const;
99 virtual wxString
GetLineText(long lineNo
) const;
100 virtual int GetNumberOfLines() const;
102 virtual bool IsModified() const;
103 virtual bool IsEditable() const;
105 // more readable flag testing methods
106 virtual bool IsSingleLine() const;
107 virtual bool IsMultiLine() const;
109 // If the return values from and to are the same, there is no selection.
110 virtual void GetSelection(long* from
, long* to
) const;
112 virtual wxString
GetStringSelection() const;
118 virtual void Clear();
119 virtual void Replace(long from
, long to
, const wxString
& value
);
120 virtual void Remove(long from
, long to
);
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
);
126 // sets/clears the dirty flag
127 virtual void MarkDirty();
128 virtual void DiscardEdits();
130 // set the max number of characters which may be entered in a single line
132 virtual void SetMaxLength(unsigned long WXUNUSED(len
));
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
);
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
);
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;
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;
157 virtual void ShowPosition(long pos
);
159 // find the character at position given in pixels
161 // NB: pt is in device coords (not adjusted for the client area origin nor
163 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
164 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
166 wxTextCoord
*row
) const;
168 // Clipboard operations
171 virtual void Paste();
173 virtual bool CanCopy() const;
174 virtual bool CanCut() const;
175 virtual bool CanPaste() const;
181 virtual bool CanUndo() const;
182 virtual bool CanRedo() const;
185 virtual void SetInsertionPoint(long pos
);
186 virtual void SetInsertionPointEnd();
187 virtual long GetInsertionPoint() const;
188 virtual wxTextPos
GetLastPosition() const;
190 virtual void SetSelection(long from
, long to
);
191 virtual void SelectAll();
192 virtual void SetEditable(bool editable
);
196 // override streambuf method
197 #if wxHAS_TEXT_WINDOW_STREAM
199 #endif // wxHAS_TEXT_WINDOW_STREAM
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
);
211 // do the window-specific processing after processing the update event
212 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
214 virtual bool ShouldInheritColours() const;
216 // wxWindow overrides
217 virtual bool SetFont(const wxFont
& font
);
219 // search control generic only
220 void SetSearchBitmap( const wxBitmap
& bitmap
);
221 void SetSearchMenuBitmap( const wxBitmap
& bitmap
);
222 void SetCancelBitmap( const wxBitmap
& bitmap
);
225 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
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
);
232 virtual void RecalcBitmaps();
236 virtual wxBitmap
RenderSearchBitmap( int x
, int y
, bool renderDrop
);
237 virtual wxBitmap
RenderCancelBitmap( int x
, int y
);
239 virtual void OnSearchButton( wxCommandEvent
& event
);
241 void OnSetFocus( wxFocusEvent
& event
);
244 friend class wxSearchButton
;
246 void PopupSearchMenu();
249 wxSearchTextCtrl
*m_text
;
250 wxSearchButton
*m_searchButton
;
251 wxSearchButton
*m_cancelButton
;
254 bool m_searchButtonVisible
;
255 bool m_cancelButtonVisible
;
257 bool m_searchBitmapUser
;
258 bool m_searchMenuBitmapUser
;
259 bool m_cancelBitmapUser
;
260 wxBitmap m_searchBitmap
;
261 wxBitmap m_searchMenuBitmap
;
262 wxBitmap m_cancelBitmap
;
264 DECLARE_DYNAMIC_CLASS(wxSearchCtrl
)
266 DECLARE_EVENT_TABLE()
269 #endif // wxUSE_SEARCHCTRL
271 #endif // _WX_GENERIC_SEARCHCTRL_H_