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