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 #include "wx/bitmap.h"
19 class WXDLLEXPORT wxSearchButton
;
20 class WXDLLEXPORT wxSearchTextCtrl
;
22 // ----------------------------------------------------------------------------
23 // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton
24 // ----------------------------------------------------------------------------
26 class WXDLLEXPORT wxSearchCtrl
: public wxSearchCtrlBase
33 wxSearchCtrl(wxWindow
*parent
, wxWindowID id
,
34 const wxString
& value
= wxEmptyString
,
35 const wxPoint
& pos
= wxDefaultPosition
,
36 const wxSize
& size
= wxDefaultSize
,
38 const wxValidator
& validator
= wxDefaultValidator
,
39 const wxString
& name
= wxSearchCtrlNameStr
);
43 bool Create(wxWindow
*parent
, wxWindowID id
,
44 const wxString
& value
= wxEmptyString
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
,
48 const wxValidator
& validator
= wxDefaultValidator
,
49 const wxString
& name
= wxSearchCtrlNameStr
);
51 // get/set search button menu
52 // --------------------------
53 virtual void SetMenu( wxMenu
* menu
);
54 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;
67 virtual wxString
GetValue() const;
68 virtual void SetValue(const wxString
& value
);
70 virtual wxString
GetRange(long from
, long to
) const;
72 virtual int GetLineLength(long lineNo
) const;
73 virtual wxString
GetLineText(long lineNo
) const;
74 virtual int GetNumberOfLines() const;
76 virtual bool IsModified() const;
77 virtual bool IsEditable() const;
79 // more readable flag testing methods
80 virtual bool IsSingleLine() const;
81 virtual bool IsMultiLine() const;
83 // If the return values from and to are the same, there is no selection.
84 virtual void GetSelection(long* from
, long* to
) const;
86 virtual wxString
GetStringSelection() const;
93 virtual void Replace(long from
, long to
, const wxString
& value
);
94 virtual void Remove(long from
, long to
);
96 // load/save the controls contents from/to the file
97 virtual bool LoadFile(const wxString
& file
);
98 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
100 // sets/clears the dirty flag
101 virtual void MarkDirty();
102 virtual void DiscardEdits();
104 // set the max number of characters which may be entered in a single line
106 virtual void SetMaxLength(unsigned long WXUNUSED(len
));
108 // writing text inserts it at the current position, appending always
109 // inserts it at the end
110 virtual void WriteText(const wxString
& text
);
111 virtual void AppendText(const wxString
& text
);
113 // insert the character which would have resulted from this key event,
114 // return true if anything has been inserted
115 virtual bool EmulateKeyPress(const wxKeyEvent
& event
);
117 // text control under some platforms supports the text styles: these
118 // methods allow to apply the given text style to the given selection or to
119 // set/get the style which will be used for all appended text
120 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
121 virtual bool GetStyle(long position
, wxTextAttr
& style
);
122 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
123 virtual const wxTextAttr
& GetDefaultStyle() const;
125 // translate between the position (which is just an index in the text ctrl
126 // considering all its contents as a single strings) and (x, y) coordinates
127 // which represent column and line.
128 virtual long XYToPosition(long x
, long y
) const;
129 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
131 virtual void ShowPosition(long pos
);
133 // find the character at position given in pixels
135 // NB: pt is in device coords (not adjusted for the client area origin nor
137 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
138 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
140 wxTextCoord
*row
) const;
142 // Clipboard operations
145 virtual void Paste();
147 virtual bool CanCopy() const;
148 virtual bool CanCut() const;
149 virtual bool CanPaste() const;
155 virtual bool CanUndo() const;
156 virtual bool CanRedo() const;
159 virtual void SetInsertionPoint(long pos
);
160 virtual void SetInsertionPointEnd();
161 virtual long GetInsertionPoint() const;
162 virtual wxTextPos
GetLastPosition() const;
164 virtual void SetSelection(long from
, long to
);
165 virtual void SelectAll();
166 virtual void SetEditable(bool editable
);
170 // override streambuf method
171 #if wxHAS_TEXT_WINDOW_STREAM
173 #endif // wxHAS_TEXT_WINDOW_STREAM
175 // stream-like insertion operators: these are always available, whether we
176 // were, or not, compiled with streambuf support
177 wxTextCtrl
& operator<<(const wxString
& s
);
178 wxTextCtrl
& operator<<(int i
);
179 wxTextCtrl
& operator<<(long i
);
180 wxTextCtrl
& operator<<(float f
);
181 wxTextCtrl
& operator<<(double d
);
182 wxTextCtrl
& operator<<(const wxChar c
);
185 // do the window-specific processing after processing the update event
186 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
188 virtual bool ShouldInheritColours() const;
190 // wxWindow overrides
191 virtual bool SetFont(const wxFont
& font
);
193 // search control generic only
194 void SetSearchBitmap( const wxBitmap
& bitmap
);
195 void SetSearchMenuBitmap( const wxBitmap
& bitmap
);
196 void SetCancelBitmap( const wxBitmap
& bitmap
);
199 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
201 // override the base class virtuals involved into geometry calculations
202 virtual wxSize
DoGetBestSize() const;
203 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
204 virtual void LayoutControls(int x
, int y
, int width
, int height
);
206 virtual void RecalcBitmaps();
210 virtual wxBitmap
RenderSearchBitmap( int x
, int y
, bool renderDrop
);
211 virtual wxBitmap
RenderCancelBitmap( int x
, int y
);
213 virtual void OnSearchButton( wxCommandEvent
& event
);
215 void OnSetFocus( wxFocusEvent
& event
);
218 friend class wxSearchButton
;
220 void PopupSearchMenu();
223 wxSearchTextCtrl
*m_text
;
224 wxSearchButton
*m_searchButton
;
225 wxSearchButton
*m_cancelButton
;
228 bool m_searchButtonVisible
;
229 bool m_cancelButtonVisible
;
231 bool m_searchBitmapUser
;
232 bool m_searchMenuBitmapUser
;
233 bool m_cancelBitmapUser
;
234 wxBitmap m_searchBitmap
;
235 wxBitmap m_searchMenuBitmap
;
236 wxBitmap m_cancelBitmap
;
238 DECLARE_DYNAMIC_CLASS(wxSearchCtrl
)
240 DECLARE_EVENT_TABLE()
243 #endif // wxUSE_SEARCHCTRL
245 #endif // _WX_GENERIC_SEARCHCTRL_H_