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