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