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