srchctlg.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/srchctlg.h
  3. // Purpose: generic wxSearchCtrl class
  4. // Author: Vince Harron
  5. // Created: 2006-02-19
  6. // Copyright: Vince Harron
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GENERIC_SEARCHCTRL_H_
  10. #define _WX_GENERIC_SEARCHCTRL_H_
  11. #if wxUSE_SEARCHCTRL
  12. #include "wx/bitmap.h"
  13. class WXDLLIMPEXP_FWD_CORE wxSearchButton;
  14. class WXDLLIMPEXP_FWD_CORE wxSearchTextCtrl;
  15. // ----------------------------------------------------------------------------
  16. // wxSearchCtrl is a combination of wxTextCtrl and wxSearchButton
  17. // ----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_CORE wxSearchCtrl : public wxSearchCtrlBase
  19. {
  20. public:
  21. // creation
  22. // --------
  23. wxSearchCtrl();
  24. wxSearchCtrl(wxWindow *parent, wxWindowID id,
  25. const wxString& value = wxEmptyString,
  26. const wxPoint& pos = wxDefaultPosition,
  27. const wxSize& size = wxDefaultSize,
  28. long style = 0,
  29. const wxValidator& validator = wxDefaultValidator,
  30. const wxString& name = wxSearchCtrlNameStr);
  31. virtual ~wxSearchCtrl();
  32. bool Create(wxWindow *parent, wxWindowID id,
  33. const wxString& value = wxEmptyString,
  34. const wxPoint& pos = wxDefaultPosition,
  35. const wxSize& size = wxDefaultSize,
  36. long style = 0,
  37. const wxValidator& validator = wxDefaultValidator,
  38. const wxString& name = wxSearchCtrlNameStr);
  39. #if wxUSE_MENUS
  40. // get/set search button menu
  41. // --------------------------
  42. virtual void SetMenu( wxMenu* menu );
  43. virtual wxMenu* GetMenu();
  44. #endif // wxUSE_MENUS
  45. // get/set search options
  46. // ----------------------
  47. virtual void ShowSearchButton( bool show );
  48. virtual bool IsSearchButtonVisible() const;
  49. virtual void ShowCancelButton( bool show );
  50. virtual bool IsCancelButtonVisible() const;
  51. // TODO: In 2.9 these should probably be virtual, and declared in the base class...
  52. void SetDescriptiveText(const wxString& text);
  53. wxString GetDescriptiveText() const;
  54. // accessors
  55. // ---------
  56. virtual wxString GetRange(long from, long to) const;
  57. virtual int GetLineLength(long lineNo) const;
  58. virtual wxString GetLineText(long lineNo) const;
  59. virtual int GetNumberOfLines() const;
  60. virtual bool IsModified() const;
  61. virtual bool IsEditable() const;
  62. // more readable flag testing methods
  63. virtual bool IsSingleLine() const;
  64. virtual bool IsMultiLine() const;
  65. // If the return values from and to are the same, there is no selection.
  66. virtual void GetSelection(long* from, long* to) const;
  67. virtual wxString GetStringSelection() const;
  68. // operations
  69. // ----------
  70. // editing
  71. virtual void Clear();
  72. virtual void Replace(long from, long to, const wxString& value);
  73. virtual void Remove(long from, long to);
  74. // load/save the controls contents from/to the file
  75. virtual bool LoadFile(const wxString& file);
  76. virtual bool SaveFile(const wxString& file = wxEmptyString);
  77. // sets/clears the dirty flag
  78. virtual void MarkDirty();
  79. virtual void DiscardEdits();
  80. // set the max number of characters which may be entered in a single line
  81. // text control
  82. virtual void SetMaxLength(unsigned long WXUNUSED(len));
  83. // writing text inserts it at the current position, appending always
  84. // inserts it at the end
  85. virtual void WriteText(const wxString& text);
  86. virtual void AppendText(const wxString& text);
  87. // insert the character which would have resulted from this key event,
  88. // return true if anything has been inserted
  89. virtual bool EmulateKeyPress(const wxKeyEvent& event);
  90. // text control under some platforms supports the text styles: these
  91. // methods allow to apply the given text style to the given selection or to
  92. // set/get the style which will be used for all appended text
  93. virtual bool SetStyle(long start, long end, const wxTextAttr& style);
  94. virtual bool GetStyle(long position, wxTextAttr& style);
  95. virtual bool SetDefaultStyle(const wxTextAttr& style);
  96. virtual const wxTextAttr& GetDefaultStyle() const;
  97. // translate between the position (which is just an index in the text ctrl
  98. // considering all its contents as a single strings) and (x, y) coordinates
  99. // which represent column and line.
  100. virtual long XYToPosition(long x, long y) const;
  101. virtual bool PositionToXY(long pos, long *x, long *y) const;
  102. virtual void ShowPosition(long pos);
  103. // find the character at position given in pixels
  104. //
  105. // NB: pt is in device coords (not adjusted for the client area origin nor
  106. // scrolling)
  107. virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
  108. virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
  109. wxTextCoord *col,
  110. wxTextCoord *row) const;
  111. // Clipboard operations
  112. virtual void Copy();
  113. virtual void Cut();
  114. virtual void Paste();
  115. virtual bool CanCopy() const;
  116. virtual bool CanCut() const;
  117. virtual bool CanPaste() const;
  118. // Undo/redo
  119. virtual void Undo();
  120. virtual void Redo();
  121. virtual bool CanUndo() const;
  122. virtual bool CanRedo() const;
  123. // Insertion point
  124. virtual void SetInsertionPoint(long pos);
  125. virtual void SetInsertionPointEnd();
  126. virtual long GetInsertionPoint() const;
  127. virtual wxTextPos GetLastPosition() const;
  128. virtual void SetSelection(long from, long to);
  129. virtual void SelectAll();
  130. virtual void SetEditable(bool editable);
  131. #if 0
  132. // override streambuf method
  133. #if wxHAS_TEXT_WINDOW_STREAM
  134. int overflow(int i);
  135. #endif // wxHAS_TEXT_WINDOW_STREAM
  136. // stream-like insertion operators: these are always available, whether we
  137. // were, or not, compiled with streambuf support
  138. wxTextCtrl& operator<<(const wxString& s);
  139. wxTextCtrl& operator<<(int i);
  140. wxTextCtrl& operator<<(long i);
  141. wxTextCtrl& operator<<(float f);
  142. wxTextCtrl& operator<<(double d);
  143. wxTextCtrl& operator<<(const wxChar c);
  144. #endif
  145. // do the window-specific processing after processing the update event
  146. virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
  147. virtual bool ShouldInheritColours() const;
  148. // wxWindow overrides
  149. virtual bool SetFont(const wxFont& font);
  150. virtual bool SetBackgroundColour(const wxColour& colour);
  151. // search control generic only
  152. void SetSearchBitmap( const wxBitmap& bitmap );
  153. void SetCancelBitmap( const wxBitmap& bitmap );
  154. #if wxUSE_MENUS
  155. void SetSearchMenuBitmap( const wxBitmap& bitmap );
  156. #endif // wxUSE_MENUS
  157. protected:
  158. virtual void DoSetValue(const wxString& value, int flags);
  159. virtual wxString DoGetValue() const;
  160. virtual bool DoLoadFile(const wxString& file, int fileType);
  161. virtual bool DoSaveFile(const wxString& file, int fileType);
  162. // override the base class virtuals involved into geometry calculations
  163. virtual wxSize DoGetBestSize() const;
  164. virtual void DoMoveWindow(int x, int y, int width, int height);
  165. virtual void LayoutControls(int x, int y, int width, int height);
  166. virtual void RecalcBitmaps();
  167. void Init();
  168. virtual wxBitmap RenderSearchBitmap( int x, int y, bool renderDrop );
  169. virtual wxBitmap RenderCancelBitmap( int x, int y );
  170. void OnCancelButton( wxCommandEvent& event );
  171. void OnSetFocus( wxFocusEvent& event );
  172. void OnSize( wxSizeEvent& event );
  173. bool HasMenu() const
  174. {
  175. #if wxUSE_MENUS
  176. return m_menu != NULL;
  177. #else // !wxUSE_MENUS
  178. return false;
  179. #endif // wxUSE_MENUS/!wxUSE_MENUS
  180. }
  181. private:
  182. friend class wxSearchButton;
  183. // Implement pure virtual function inherited from wxCompositeWindow.
  184. virtual wxWindowList GetCompositeWindowParts() const;
  185. // Position the child controls using the current window size.
  186. void DoLayoutControls();
  187. #if wxUSE_MENUS
  188. void PopupSearchMenu();
  189. #endif // wxUSE_MENUS
  190. // the subcontrols
  191. wxSearchTextCtrl *m_text;
  192. wxSearchButton *m_searchButton;
  193. wxSearchButton *m_cancelButton;
  194. #if wxUSE_MENUS
  195. wxMenu *m_menu;
  196. #endif // wxUSE_MENUS
  197. bool m_searchButtonVisible;
  198. bool m_cancelButtonVisible;
  199. bool m_searchBitmapUser;
  200. bool m_cancelBitmapUser;
  201. #if wxUSE_MENUS
  202. bool m_searchMenuBitmapUser;
  203. #endif // wxUSE_MENUS
  204. wxBitmap m_searchBitmap;
  205. wxBitmap m_cancelBitmap;
  206. #if wxUSE_MENUS
  207. wxBitmap m_searchMenuBitmap;
  208. #endif // wxUSE_MENUS
  209. private:
  210. DECLARE_DYNAMIC_CLASS(wxSearchCtrl)
  211. DECLARE_EVENT_TABLE()
  212. };
  213. #endif // wxUSE_SEARCHCTRL
  214. #endif // _WX_GENERIC_SEARCHCTRL_H_