once again removed #ifdefs that conditionally included the exact same code on Mac...
[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 #include "wx/textctrl.h"
24
25 /*!
26 * Forward declarations
27 */
28
29 ////@begin forward declarations
30 class wxSymbolListCtrl;
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 = 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 );
64
65 /// Creation
66 bool Create( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont,
67 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 );
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 /// Should we show tooltips?
97 static bool ShowToolTips() { return sm_showToolTips; }
98
99 /// Determines whether tooltips will be shown
100 static void SetShowToolTips(bool show) { sm_showToolTips = show; }
101
102 /// Data transfer
103 virtual bool TransferDataToWindow();
104
105 ////@begin wxSymbolPickerDialog event handler declarations
106
107 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FONT
108 void OnFontCtrlSelected( wxCommandEvent& event );
109
110 #if defined(__UNICODE__)
111 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_SUBSET
112 void OnSubsetSelected( wxCommandEvent& event );
113
114 #endif
115 #if defined(__UNICODE__)
116 /// wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SYMBOLPICKERDIALOG_FROM
117 void OnFromUnicodeSelected( wxCommandEvent& event );
118
119 #endif
120
121 /// wxEVT_UPDATE_UI event handler for wxID_OK
122 void OnOkUpdate( wxUpdateUIEvent& event );
123
124 ////@end wxSymbolPickerDialog event handler declarations
125
126 ////@begin wxSymbolPickerDialog member function declarations
127
128 wxString GetFontName() const { return m_fontName ; }
129 void SetFontName(wxString value) { m_fontName = value ; }
130
131 wxString GetSymbol() const { return m_symbol ; }
132 void SetSymbol(wxString value) { m_symbol = value ; }
133
134 bool GetFromUnicode() const { return m_fromUnicode ; }
135 void SetFromUnicode(bool value) { m_fromUnicode = value ; }
136
137 wxString GetNormalTextFontName() const { return m_normalTextFontName ; }
138 void SetNormalTextFontName(wxString value) { m_normalTextFontName = value ; }
139
140 /// Retrieves bitmap resources
141 wxBitmap GetBitmapResource( const wxString& name );
142
143 /// Retrieves icon resources
144 wxIcon GetIconResource( const wxString& name );
145 ////@end wxSymbolPickerDialog member function declarations
146
147 ////@begin wxSymbolPickerDialog member variables
148 wxComboBox* m_fontCtrl;
149 #if defined(__UNICODE__)
150 wxComboBox* m_subsetCtrl;
151 #endif
152 wxSymbolListCtrl* m_symbolsCtrl;
153 wxStaticText* m_symbolStaticCtrl;
154 wxTextCtrl* m_characterCodeCtrl;
155 #if defined(__UNICODE__)
156 wxComboBox* m_fromUnicodeCtrl;
157 #endif
158 wxString m_fontName;
159 wxString m_symbol;
160 bool m_fromUnicode;
161 wxString m_normalTextFontName;
162 /// Control identifiers
163 enum {
164 ID_SYMBOLPICKERDIALOG = 10600,
165 ID_SYMBOLPICKERDIALOG_FONT = 10602,
166 ID_SYMBOLPICKERDIALOG_SUBSET = 10605,
167 ID_SYMBOLPICKERDIALOG_LISTCTRL = 10608,
168 ID_SYMBOLPICKERDIALOG_CHARACTERCODE = 10601,
169 ID_SYMBOLPICKERDIALOG_FROM = 10603
170 };
171 ////@end wxSymbolPickerDialog member variables
172
173 bool m_dontUpdate;
174 static bool sm_showToolTips;
175 };
176
177 /*!
178 * The scrolling symbol list.
179 */
180
181 class WXDLLIMPEXP_RICHTEXT wxSymbolListCtrl : public wxVScrolledWindow
182 {
183 public:
184 // constructors and such
185 // ---------------------
186
187 // default constructor, you must call Create() later
188 wxSymbolListCtrl() { Init(); }
189
190 // normal constructor which calls Create() internally
191 wxSymbolListCtrl(wxWindow *parent,
192 wxWindowID id = wxID_ANY,
193 const wxPoint& pos = wxDefaultPosition,
194 const wxSize& size = wxDefaultSize,
195 long style = 0,
196 const wxString& name = wxPanelNameStr)
197 {
198 Init();
199
200 (void)Create(parent, id, pos, size, style, name);
201 }
202
203 // really creates the control and sets the initial number of items in it
204 // (which may be changed later with SetItemCount())
205 //
206 // returns true on success or false if the control couldn't be created
207 bool Create(wxWindow *parent,
208 wxWindowID id = wxID_ANY,
209 const wxPoint& pos = wxDefaultPosition,
210 const wxSize& size = wxDefaultSize,
211 long style = 0,
212 const wxString& name = wxPanelNameStr);
213
214 // dtor does some internal cleanup
215 virtual ~wxSymbolListCtrl();
216
217
218 // accessors
219 // ---------
220
221 // set the current font
222 virtual bool SetFont(const wxFont& font);
223
224 // set Unicode/ASCII mode
225 void SetUnicodeMode(bool unicodeMode);
226
227 // get the index of the currently selected item or wxNOT_FOUND if there is no selection
228 int GetSelection() const;
229
230 // is this item selected?
231 bool IsSelected(int item) const;
232
233 // is this item the current one?
234 bool IsCurrentItem(int item) const { return item == m_current; }
235
236 // get the margins around each cell
237 wxPoint GetMargins() const { return m_ptMargins; }
238
239 // get the background colour of selected cells
240 const wxColour& GetSelectionBackground() const { return m_colBgSel; }
241
242 // operations
243 // ----------
244
245 // set the selection to the specified item, if it is wxNOT_FOUND the
246 // selection is unset
247 void SetSelection(int selection);
248
249 // make this item visible
250 void EnsureVisible(int item);
251
252 // set the margins: horizontal margin is the distance between the window
253 // border and the item contents while vertical margin is half of the
254 // distance between items
255 //
256 // by default both margins are 0
257 void SetMargins(const wxPoint& pt);
258 void SetMargins(wxCoord x, wxCoord y) { SetMargins(wxPoint(x, y)); }
259
260 // set the cell size
261 void SetCellSize(const wxSize& sz) { m_cellSize = sz; }
262 const wxSize& GetCellSize() const { return m_cellSize; }
263
264 // change the background colour of the selected cells
265 void SetSelectionBackground(const wxColour& col);
266
267 virtual wxVisualAttributes GetDefaultAttributes() const
268 {
269 return GetClassDefaultAttributes(GetWindowVariant());
270 }
271
272 static wxVisualAttributes
273 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
274
275 // Get min/max symbol values
276 int GetMinSymbolValue() const { return m_minSymbolValue; }
277 int GetMaxSymbolValue() const { return m_maxSymbolValue; }
278
279 // Respond to size change
280 void OnSize(wxSizeEvent& event);
281
282 protected:
283
284 // draws a line of symbols
285 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
286
287 // gets the line height
288 virtual wxCoord OnGetRowHeight(size_t line) const;
289
290 // event handlers
291 void OnPaint(wxPaintEvent& event);
292 void OnKeyDown(wxKeyEvent& event);
293 void OnLeftDown(wxMouseEvent& event);
294 void OnLeftDClick(wxMouseEvent& event);
295
296 // common part of all ctors
297 void Init();
298
299 // send the wxEVT_COMMAND_LISTBOX_SELECTED event
300 void SendSelectedEvent();
301
302 // change the current item (in single selection listbox it also implicitly
303 // changes the selection); current may be wxNOT_FOUND in which case there
304 // will be no current item any more
305 //
306 // return true if the current item changed, false otherwise
307 bool DoSetCurrent(int current);
308
309 // flags for DoHandleItemClick
310 enum
311 {
312 ItemClick_Shift = 1, // item shift-clicked
313 ItemClick_Ctrl = 2, // ctrl
314 ItemClick_Kbd = 4 // item selected from keyboard
315 };
316
317 // common part of keyboard and mouse handling processing code
318 void DoHandleItemClick(int item, int flags);
319
320 // calculate line number from symbol value
321 int SymbolValueToLineNumber(int item);
322
323 // initialise control from current min/max values
324 void SetupCtrl(bool scrollToSelection = true);
325
326 // hit testing
327 int HitTest(const wxPoint& pt);
328
329 private:
330 // the current item or wxNOT_FOUND
331 int m_current;
332
333 // margins
334 wxPoint m_ptMargins;
335
336 // the selection bg colour
337 wxColour m_colBgSel;
338
339 // double buffer
340 wxBitmap* m_doubleBuffer;
341
342 // cell size
343 wxSize m_cellSize;
344
345 // minimum and maximum symbol value
346 int m_minSymbolValue;
347
348 // minimum and maximum symbol value
349 int m_maxSymbolValue;
350
351 // number of items per line
352 int m_symbolsPerLine;
353
354 // Unicode/ASCII mode
355 bool m_unicodeMode;
356
357 DECLARE_EVENT_TABLE()
358 DECLARE_NO_COPY_CLASS(wxSymbolListCtrl)
359 DECLARE_ABSTRACT_CLASS(wxSymbolListCtrl)
360 };
361
362 #endif
363 // _RICHTEXTSYMBOLDLG_H_