1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/srchctlg.h
3 // Purpose: generic wxSearchCtrl class
4 // Author: Vince Harron
6 // Copyright: Vince Harron
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GENERIC_SEARCHCTRL_H_
11 #define _WX_GENERIC_SEARCHCTRL_H_
15 #include "wx/bitmap.h"
17 class WXDLLIMPEXP_FWD_CORE wxSearchButton
;
18 class WXDLLIMPEXP_FWD_CORE wxSearchTextCtrl
;
20 // ----------------------------------------------------------------------------
21 // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton
22 // ----------------------------------------------------------------------------
24 class WXDLLIMPEXP_CORE wxSearchCtrl
: public wxSearchCtrlBase
31 wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
32 const wxString
& value
= wxEmptyString
,
33 const wxPoint
& pos
= wxDefaultPosition
,
34 const wxSize
& size
= wxDefaultSize
,
36 const wxValidator
& validator
= wxDefaultValidator
,
37 const wxString
& name
= wxSearchCtrlNameStr
);
39 virtual ~wxSearchCtrl();
41 bool Create(wxWindow
*parent
, wxWindowID id
,
42 const wxString
& value
= wxEmptyString
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
46 const wxValidator
& validator
= wxDefaultValidator
,
47 const wxString
& name
= wxSearchCtrlNameStr
);
50 // get/set search button menu
51 // --------------------------
52 virtual void SetMenu( wxMenu
* menu
);
53 virtual wxMenu
* GetMenu();
56 // get/set search options
57 // ----------------------
58 virtual void ShowSearchButton( bool show
);
59 virtual bool IsSearchButtonVisible() const;
61 virtual void ShowCancelButton( bool show
);
62 virtual bool IsCancelButtonVisible() const;
64 // TODO: In 2.9 these should probably be virtual, and declared in the base class...
65 void SetDescriptiveText(const wxString
& text
);
66 wxString
GetDescriptiveText() const;
71 virtual wxString
GetRange(long from
, long to
) const;
73 virtual int GetLineLength(long lineNo
) const;
74 virtual wxString
GetLineText(long lineNo
) const;
75 virtual int GetNumberOfLines() const;
77 virtual bool IsModified() const;
78 virtual bool IsEditable() const;
80 // more readable flag testing methods
81 virtual bool IsSingleLine() const;
82 virtual bool IsMultiLine() const;
84 // If the return values from and to are the same, there is no selection.
85 virtual void GetSelection(long* from
, long* to
) const;
87 virtual wxString
GetStringSelection() const;
94 virtual void Replace(long from
, long to
, const wxString
& value
);
95 virtual void Remove(long from
, long to
);
97 // load/save the controls contents from/to the file
98 virtual bool LoadFile(const wxString
& file
);
99 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
101 // sets/clears the dirty flag
102 virtual void MarkDirty();
103 virtual void DiscardEdits();
105 // set the max number of characters which may be entered in a single line
107 virtual void SetMaxLength(unsigned long WXUNUSED(len
));
109 // writing text inserts it at the current position, appending always
110 // inserts it at the end
111 virtual void WriteText(const wxString
& text
);
112 virtual void AppendText(const wxString
& text
);
114 // insert the character which would have resulted from this key event,
115 // return true if anything has been inserted
116 virtual bool EmulateKeyPress(const wxKeyEvent
& event
);
118 // text control under some platforms supports the text styles: these
119 // methods allow to apply the given text style to the given selection or to
120 // set/get the style which will be used for all appended text
121 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
122 virtual bool GetStyle(long position
, wxTextAttr
& style
);
123 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
124 virtual const wxTextAttr
& GetDefaultStyle() const;
126 // translate between the position (which is just an index in the text ctrl
127 // considering all its contents as a single strings) and (x, y) coordinates
128 // which represent column and line.
129 virtual long XYToPosition(long x
, long y
) const;
130 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
132 virtual void ShowPosition(long pos
);
134 // find the character at position given in pixels
136 // NB: pt is in device coords (not adjusted for the client area origin nor
138 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
139 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
141 wxTextCoord
*row
) const;
143 // Clipboard operations
146 virtual void Paste();
148 virtual bool CanCopy() const;
149 virtual bool CanCut() const;
150 virtual bool CanPaste() const;
156 virtual bool CanUndo() const;
157 virtual bool CanRedo() const;
160 virtual void SetInsertionPoint(long pos
);
161 virtual void SetInsertionPointEnd();
162 virtual long GetInsertionPoint() const;
163 virtual wxTextPos
GetLastPosition() const;
165 virtual void SetSelection(long from
, long to
);
166 virtual void SelectAll();
167 virtual void SetEditable(bool editable
);
171 // override streambuf method
172 #if wxHAS_TEXT_WINDOW_STREAM
174 #endif // wxHAS_TEXT_WINDOW_STREAM
176 // stream-like insertion operators: these are always available, whether we
177 // were, or not, compiled with streambuf support
178 wxTextCtrl
& operator<<(const wxString
& s
);
179 wxTextCtrl
& operator<<(int i
);
180 wxTextCtrl
& operator<<(long i
);
181 wxTextCtrl
& operator<<(float f
);
182 wxTextCtrl
& operator<<(double d
);
183 wxTextCtrl
& operator<<(const wxChar c
);
186 // do the window-specific processing after processing the update event
187 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
189 virtual bool ShouldInheritColours() const;
191 // wxWindow overrides
192 virtual bool SetFont(const wxFont
& font
);
193 virtual bool SetBackgroundColour(const wxColour
& colour
);
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 void OnCancelButton( 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
;
238 // Implement pure virtual function inherited from wxCompositeWindow.
239 virtual wxWindowList
GetCompositeWindowParts() const;
242 void PopupSearchMenu();
243 #endif // wxUSE_MENUS
246 wxSearchTextCtrl
*m_text
;
247 wxSearchButton
*m_searchButton
;
248 wxSearchButton
*m_cancelButton
;
251 #endif // wxUSE_MENUS
253 bool m_searchButtonVisible
;
254 bool m_cancelButtonVisible
;
256 bool m_searchBitmapUser
;
257 bool m_cancelBitmapUser
;
259 bool m_searchMenuBitmapUser
;
260 #endif // wxUSE_MENUS
262 wxBitmap m_searchBitmap
;
263 wxBitmap m_cancelBitmap
;
265 wxBitmap m_searchMenuBitmap
;
266 #endif // wxUSE_MENUS
269 DECLARE_DYNAMIC_CLASS(wxSearchCtrl
)
271 DECLARE_EVENT_TABLE()
274 #endif // wxUSE_SEARCHCTRL
276 #endif // _WX_GENERIC_SEARCHCTRL_H_