richtextsymboldlg.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/richtext/richtextsymboldlg.h
  3. // Purpose:
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 10/5/2006 3:11:58 PM
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _RICHTEXTSYMBOLDLG_H_
  11. #define _RICHTEXTSYMBOLDLG_H_
  12. /*!
  13. * Includes
  14. */
  15. #include "wx/richtext/richtextuicustomization.h"
  16. #include "wx/dialog.h"
  17. #include "wx/vscroll.h"
  18. /*!
  19. * Forward declarations
  20. */
  21. class WXDLLIMPEXP_FWD_CORE wxStaticText;
  22. class WXDLLIMPEXP_FWD_CORE wxComboBox;
  23. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  24. ////@begin forward declarations
  25. class wxSymbolListCtrl;
  26. class wxStdDialogButtonSizer;
  27. ////@end forward declarations
  28. // __UNICODE__ is a symbol used by DialogBlocks-generated code.
  29. #ifndef __UNICODE__
  30. #if wxUSE_UNICODE
  31. #define __UNICODE__
  32. #endif
  33. #endif
  34. /*!
  35. * Symbols
  36. */
  37. #define SYMBOL_WXSYMBOLPICKERDIALOG_STYLE (wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX)
  38. #define SYMBOL_WXSYMBOLPICKERDIALOG_TITLE wxGetTranslation("Symbols")
  39. #define SYMBOL_WXSYMBOLPICKERDIALOG_IDNAME ID_SYMBOLPICKERDIALOG
  40. #define SYMBOL_WXSYMBOLPICKERDIALOG_SIZE wxSize(400, 300)
  41. #define SYMBOL_WXSYMBOLPICKERDIALOG_POSITION wxDefaultPosition
  42. /*!
  43. * wxSymbolPickerDialog class declaration
  44. */
  45. class WXDLLIMPEXP_RICHTEXT wxSymbolPickerDialog: public wxDialog
  46. {
  47. DECLARE_DYNAMIC_CLASS( wxSymbolPickerDialog )
  48. DECLARE_EVENT_TABLE()
  49. DECLARE_HELP_PROVISION()
  50. public:
  51. /// Constructors
  52. wxSymbolPickerDialog( );
  53. wxSymbolPickerDialog( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont,
  54. wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& caption = SYMBOL_WXSYMBOLPICKERDIALOG_TITLE, const wxPoint& pos = SYMBOL_WXSYMBOLPICKERDIALOG_POSITION, const wxSize& size = SYMBOL_WXSYMBOLPICKERDIALOG_SIZE, long style = SYMBOL_WXSYMBOLPICKERDIALOG_STYLE );
  55. /// Creation
  56. bool Create( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont,
  57. wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& caption = SYMBOL_WXSYMBOLPICKERDIALOG_TITLE, const wxPoint& pos = SYMBOL_WXSYMBOLPICKERDIALOG_POSITION, const wxSize& size = SYMBOL_WXSYMBOLPICKERDIALOG_SIZE, long style = SYMBOL_WXSYMBOLPICKERDIALOG_STYLE );
  58. /// Initialises members variables
  59. void Init();
  60. /// Creates the controls and sizers
  61. void CreateControls();
  62. /// Update the display
  63. void UpdateSymbolDisplay(bool updateSymbolList = true, bool showAtSubset = true);
  64. /// Respond to symbol selection
  65. void OnSymbolSelected( wxCommandEvent& event );
  66. /// Set Unicode mode
  67. void SetUnicodeMode(bool unicodeMode);
  68. /// Show at the current subset selection
  69. void ShowAtSubset();
  70. /// Get the selected symbol character
  71. int GetSymbolChar() const;
  72. /// Is there a selection?
  73. bool HasSelection() const { return !m_symbol.IsEmpty(); }
  74. /// Specifying normal text?
  75. bool UseNormalFont() const { return m_fontName.IsEmpty(); }
  76. /// Should we show tooltips?
  77. static bool ShowToolTips() { return sm_showToolTips; }
  78. /// Determines whether tooltips will be shown
  79. static void SetShowToolTips(bool show) { sm_showToolTips = show; }
  80. /// Data transfer
  81. virtual bool TransferDataToWindow();
  82. ////@begin wxSymbolPickerDialog event handler declarations
  83. /// wxEVT_COMBOBOX event handler for ID_SYMBOLPICKERDIALOG_FONT
  84. void OnFontCtrlSelected( wxCommandEvent& event );
  85. #if defined(__UNICODE__)
  86. /// wxEVT_COMBOBOX event handler for ID_SYMBOLPICKERDIALOG_SUBSET
  87. void OnSubsetSelected( wxCommandEvent& event );
  88. /// wxEVT_UPDATE_UI event handler for ID_SYMBOLPICKERDIALOG_SUBSET
  89. void OnSymbolpickerdialogSubsetUpdate( wxUpdateUIEvent& event );
  90. #endif
  91. #if defined(__UNICODE__)
  92. /// wxEVT_COMBOBOX event handler for ID_SYMBOLPICKERDIALOG_FROM
  93. void OnFromUnicodeSelected( wxCommandEvent& event );
  94. #endif
  95. /// wxEVT_UPDATE_UI event handler for wxID_OK
  96. void OnOkUpdate( wxUpdateUIEvent& event );
  97. /// wxEVT_BUTTON event handler for wxID_HELP
  98. void OnHelpClick( wxCommandEvent& event );
  99. /// wxEVT_UPDATE_UI event handler for wxID_HELP
  100. void OnHelpUpdate( wxUpdateUIEvent& event );
  101. ////@end wxSymbolPickerDialog event handler declarations
  102. ////@begin wxSymbolPickerDialog member function declarations
  103. wxString GetFontName() const { return m_fontName ; }
  104. void SetFontName(wxString value) { m_fontName = value ; }
  105. bool GetFromUnicode() const { return m_fromUnicode ; }
  106. void SetFromUnicode(bool value) { m_fromUnicode = value ; }
  107. wxString GetNormalTextFontName() const { return m_normalTextFontName ; }
  108. void SetNormalTextFontName(wxString value) { m_normalTextFontName = value ; }
  109. wxString GetSymbol() const { return m_symbol ; }
  110. void SetSymbol(wxString value) { m_symbol = value ; }
  111. /// Retrieves bitmap resources
  112. wxBitmap GetBitmapResource( const wxString& name );
  113. /// Retrieves icon resources
  114. wxIcon GetIconResource( const wxString& name );
  115. ////@end wxSymbolPickerDialog member function declarations
  116. ////@begin wxSymbolPickerDialog member variables
  117. wxComboBox* m_fontCtrl;
  118. #if defined(__UNICODE__)
  119. wxComboBox* m_subsetCtrl;
  120. #endif
  121. wxSymbolListCtrl* m_symbolsCtrl;
  122. wxStaticText* m_symbolStaticCtrl;
  123. wxTextCtrl* m_characterCodeCtrl;
  124. #if defined(__UNICODE__)
  125. wxComboBox* m_fromUnicodeCtrl;
  126. #endif
  127. wxStdDialogButtonSizer* m_stdButtonSizer;
  128. wxString m_fontName;
  129. bool m_fromUnicode;
  130. wxString m_normalTextFontName;
  131. wxString m_symbol;
  132. /// Control identifiers
  133. enum {
  134. ID_SYMBOLPICKERDIALOG = 10600,
  135. ID_SYMBOLPICKERDIALOG_FONT = 10602,
  136. ID_SYMBOLPICKERDIALOG_SUBSET = 10605,
  137. ID_SYMBOLPICKERDIALOG_LISTCTRL = 10608,
  138. ID_SYMBOLPICKERDIALOG_CHARACTERCODE = 10601,
  139. ID_SYMBOLPICKERDIALOG_FROM = 10603
  140. };
  141. ////@end wxSymbolPickerDialog member variables
  142. bool m_dontUpdate;
  143. static bool sm_showToolTips;
  144. };
  145. /*!
  146. * The scrolling symbol list.
  147. */
  148. class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl : public wxVScrolledWindow
  149. {
  150. public:
  151. // constructors and such
  152. // ---------------------
  153. // default constructor, you must call Create() later
  154. wxSymbolListCtrl() { Init(); }
  155. // normal constructor which calls Create() internally
  156. wxSymbolListCtrl(wxWindow *parent,
  157. wxWindowID id = wxID_ANY,
  158. const wxPoint& pos = wxDefaultPosition,
  159. const wxSize& size = wxDefaultSize,
  160. long style = 0,
  161. const wxString& name = wxPanelNameStr)
  162. {
  163. Init();
  164. (void)Create(parent, id, pos, size, style, name);
  165. }
  166. // really creates the control and sets the initial number of items in it
  167. // (which may be changed later with SetItemCount())
  168. //
  169. // returns true on success or false if the control couldn't be created
  170. bool Create(wxWindow *parent,
  171. wxWindowID id = wxID_ANY,
  172. const wxPoint& pos = wxDefaultPosition,
  173. const wxSize& size = wxDefaultSize,
  174. long style = 0,
  175. const wxString& name = wxPanelNameStr);
  176. // dtor does some internal cleanup
  177. virtual ~wxSymbolListCtrl();
  178. // accessors
  179. // ---------
  180. // set the current font
  181. virtual bool SetFont(const wxFont& font);
  182. // set Unicode/ASCII mode
  183. void SetUnicodeMode(bool unicodeMode);
  184. // get the index of the currently selected item or wxNOT_FOUND if there is no selection
  185. int GetSelection() const;
  186. // is this item selected?
  187. bool IsSelected(int item) const;
  188. // is this item the current one?
  189. bool IsCurrentItem(int item) const { return item == m_current; }
  190. // get the margins around each cell
  191. wxPoint GetMargins() const { return m_ptMargins; }
  192. // get the background colour of selected cells
  193. const wxColour& GetSelectionBackground() const { return m_colBgSel; }
  194. // operations
  195. // ----------
  196. // set the selection to the specified item, if it is wxNOT_FOUND the
  197. // selection is unset
  198. void SetSelection(int selection);
  199. // make this item visible
  200. void EnsureVisible(int item);
  201. // set the margins: horizontal margin is the distance between the window
  202. // border and the item contents while vertical margin is half of the
  203. // distance between items
  204. //
  205. // by default both margins are 0
  206. void SetMargins(const wxPoint& pt);
  207. void SetMargins(wxCoord x, wxCoord y) { SetMargins(wxPoint(x, y)); }
  208. // set the cell size
  209. void SetCellSize(const wxSize& sz) { m_cellSize = sz; }
  210. const wxSize& GetCellSize() const { return m_cellSize; }
  211. // change the background colour of the selected cells
  212. void SetSelectionBackground(const wxColour& col);
  213. virtual wxVisualAttributes GetDefaultAttributes() const
  214. {
  215. return GetClassDefaultAttributes(GetWindowVariant());
  216. }
  217. static wxVisualAttributes
  218. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  219. // Get min/max symbol values
  220. int GetMinSymbolValue() const { return m_minSymbolValue; }
  221. int GetMaxSymbolValue() const { return m_maxSymbolValue; }
  222. // Respond to size change
  223. void OnSize(wxSizeEvent& event);
  224. protected:
  225. // draws a line of symbols
  226. virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
  227. // gets the line height
  228. virtual wxCoord OnGetRowHeight(size_t line) const;
  229. // event handlers
  230. void OnPaint(wxPaintEvent& event);
  231. void OnKeyDown(wxKeyEvent& event);
  232. void OnLeftDown(wxMouseEvent& event);
  233. void OnLeftDClick(wxMouseEvent& event);
  234. // common part of all ctors
  235. void Init();
  236. // send the wxEVT_LISTBOX event
  237. void SendSelectedEvent();
  238. // change the current item (in single selection listbox it also implicitly
  239. // changes the selection); current may be wxNOT_FOUND in which case there
  240. // will be no current item any more
  241. //
  242. // return true if the current item changed, false otherwise
  243. bool DoSetCurrent(int current);
  244. // flags for DoHandleItemClick
  245. enum
  246. {
  247. ItemClick_Shift = 1, // item shift-clicked
  248. ItemClick_Ctrl = 2, // ctrl
  249. ItemClick_Kbd = 4 // item selected from keyboard
  250. };
  251. // common part of keyboard and mouse handling processing code
  252. void DoHandleItemClick(int item, int flags);
  253. // calculate line number from symbol value
  254. int SymbolValueToLineNumber(int item);
  255. // initialise control from current min/max values
  256. void SetupCtrl(bool scrollToSelection = true);
  257. // hit testing
  258. int HitTest(const wxPoint& pt);
  259. private:
  260. // the current item or wxNOT_FOUND
  261. int m_current;
  262. // margins
  263. wxPoint m_ptMargins;
  264. // the selection bg colour
  265. wxColour m_colBgSel;
  266. // double buffer
  267. wxBitmap* m_doubleBuffer;
  268. // cell size
  269. wxSize m_cellSize;
  270. // minimum and maximum symbol value
  271. int m_minSymbolValue;
  272. // minimum and maximum symbol value
  273. int m_maxSymbolValue;
  274. // number of items per line
  275. int m_symbolsPerLine;
  276. // Unicode/ASCII mode
  277. bool m_unicodeMode;
  278. DECLARE_EVENT_TABLE()
  279. wxDECLARE_NO_COPY_CLASS(wxSymbolListCtrl);
  280. DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl)
  281. };
  282. #endif
  283. // _RICHTEXTSYMBOLDLG_H_