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 class WXDLLEXPORT wxSearchButton
;
22 class WXDLLEXPORT wxSearchTextCtrl
;
24 class WXDLLEXPORT wxSearchCtrlBase
: public wxTextCtrlBase
28 virtual ~wxSearchCtrlBase() {}
31 virtual void SetMenu( wxMenu
* menu
) = 0;
32 virtual wxMenu
* GetMenu() = 0;
36 virtual void SetSearchButtonVisible( bool show
) = 0;
37 virtual bool GetSearchButtonVisible() const = 0;
39 virtual void SetCancelButtonVisible( bool show
) = 0;
40 virtual bool GetCancelButtonVisible() const = 0;
44 // ----------------------------------------------------------------------------
45 // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton
46 // ----------------------------------------------------------------------------
48 class WXDLLEXPORT wxSearchCtrl
: public wxSearchCtrlBase
55 wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
56 const wxString
& value
= wxEmptyString
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
60 const wxValidator
& validator
= wxDefaultValidator
,
61 const wxString
& name
= wxSearchCtrlNameStr
);
65 bool Create(wxWindow
*parent
, wxWindowID id
,
66 const wxString
& value
= wxEmptyString
,
67 const wxPoint
& pos
= wxDefaultPosition
,
68 const wxSize
& size
= wxDefaultSize
,
70 const wxValidator
& validator
= wxDefaultValidator
,
71 const wxString
& name
= wxSearchCtrlNameStr
);
73 // get/set search button menu
74 // --------------------------
75 virtual void SetMenu( wxMenu
* menu
);
76 virtual wxMenu
* GetMenu();
78 // get/set search options
79 // ----------------------
80 virtual void SetSearchButtonVisible( bool show
);
81 virtual bool GetSearchButtonVisible() const;
83 virtual void SetCancelButtonVisible( bool show
);
84 virtual bool GetCancelButtonVisible() const;
89 virtual wxString
GetValue() const;
90 virtual void SetValue(const wxString
& value
);
92 virtual wxString
GetRange(long from
, long to
) const;
94 virtual int GetLineLength(long lineNo
) const;
95 virtual wxString
GetLineText(long lineNo
) const;
96 virtual int GetNumberOfLines() const;
98 virtual bool IsModified() const;
99 virtual bool IsEditable() const;
101 // more readable flag testing methods
102 virtual bool IsSingleLine() const;
103 virtual bool IsMultiLine() const;
105 // If the return values from and to are the same, there is no selection.
106 virtual void GetSelection(long* from
, long* to
) const;
108 virtual wxString
GetStringSelection() const;
114 virtual void Clear();
115 virtual void Replace(long from
, long to
, const wxString
& value
);
116 virtual void Remove(long from
, long to
);
118 // load/save the controls contents from/to the file
119 virtual bool LoadFile(const wxString
& file
);
120 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
122 // sets/clears the dirty flag
123 virtual void MarkDirty();
124 virtual void DiscardEdits();
126 // set the max number of characters which may be entered in a single line
128 virtual void SetMaxLength(unsigned long WXUNUSED(len
));
130 // writing text inserts it at the current position, appending always
131 // inserts it at the end
132 virtual void WriteText(const wxString
& text
);
133 virtual void AppendText(const wxString
& text
);
135 // insert the character which would have resulted from this key event,
136 // return true if anything has been inserted
137 virtual bool EmulateKeyPress(const wxKeyEvent
& event
);
139 // text control under some platforms supports the text styles: these
140 // methods allow to apply the given text style to the given selection or to
141 // set/get the style which will be used for all appended text
142 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
143 virtual bool GetStyle(long position
, wxTextAttr
& style
);
144 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
145 virtual const wxTextAttr
& GetDefaultStyle() const;
147 // translate between the position (which is just an index in the text ctrl
148 // considering all its contents as a single strings) and (x, y) coordinates
149 // which represent column and line.
150 virtual long XYToPosition(long x
, long y
) const;
151 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
153 virtual void ShowPosition(long pos
);
155 // find the character at position given in pixels
157 // NB: pt is in device coords (not adjusted for the client area origin nor
159 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
160 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
162 wxTextCoord
*row
) const;
164 // Clipboard operations
167 virtual void Paste();
169 virtual bool CanCopy() const;
170 virtual bool CanCut() const;
171 virtual bool CanPaste() const;
177 virtual bool CanUndo() const;
178 virtual bool CanRedo() const;
181 virtual void SetInsertionPoint(long pos
);
182 virtual void SetInsertionPointEnd();
183 virtual long GetInsertionPoint() const;
184 virtual wxTextPos
GetLastPosition() const;
186 virtual void SetSelection(long from
, long to
);
187 virtual void SelectAll();
188 virtual void SetEditable(bool editable
);
192 // override streambuf method
193 #if wxHAS_TEXT_WINDOW_STREAM
195 #endif // wxHAS_TEXT_WINDOW_STREAM
197 // stream-like insertion operators: these are always available, whether we
198 // were, or not, compiled with streambuf support
199 wxTextCtrl
& operator<<(const wxString
& s
);
200 wxTextCtrl
& operator<<(int i
);
201 wxTextCtrl
& operator<<(long i
);
202 wxTextCtrl
& operator<<(float f
);
203 wxTextCtrl
& operator<<(double d
);
204 wxTextCtrl
& operator<<(const wxChar c
);
207 // do the window-specific processing after processing the update event
208 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
210 virtual bool ShouldInheritColours() const;
212 // wxWindow overrides
213 virtual bool SetFont(const wxFont
& font
);
215 // search control generic only
216 void SetSearchBitmap( const wxBitmap
& bitmap
);
217 void SetSearchMenuBitmap( const wxBitmap
& bitmap
);
218 void SetCancelBitmap( const wxBitmap
& bitmap
);
221 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
223 // override the base class virtuals involved into geometry calculations
224 virtual wxSize
DoGetBestSize() const;
225 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
226 virtual void LayoutControls(int x
, int y
, int width
, int height
);
228 virtual void RecalcBitmaps();
232 virtual wxBitmap
RenderSearchBitmap( int x
, int y
, bool renderDrop
);
233 virtual wxBitmap
RenderCancelBitmap( int x
, int y
);
235 virtual void OnSearchButton( wxCommandEvent
& event
);
237 void OnSetFocus( wxFocusEvent
& event
);
240 friend class wxSearchButton
;
242 void PopupSearchMenu();
245 wxSearchTextCtrl
*m_text
;
246 wxSearchButton
*m_searchButton
;
247 wxSearchButton
*m_cancelButton
;
250 bool m_searchButtonVisible
;
251 bool m_cancelButtonVisible
;
253 bool m_searchBitmapUser
;
254 bool m_searchMenuBitmapUser
;
255 bool m_cancelBitmapUser
;
256 wxBitmap m_searchBitmap
;
257 wxBitmap m_searchMenuBitmap
;
258 wxBitmap m_cancelBitmap
;
260 DECLARE_DYNAMIC_CLASS(wxSearchCtrl
)
262 DECLARE_EVENT_TABLE()
265 #endif // wxUSE_SEARCHCTRL
267 #endif // _WX_GENERIC_SEARCHCTRL_H_