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