]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtextsymboldlg.cpp
Corrected bug in in revision 47973
[wxWidgets.git] / src / richtext / richtextsymboldlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextsymboldlg.cpp
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 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_RICHTEXT
20
21 #include "wx/richtext/richtextsymboldlg.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/sizer.h"
25 #include "wx/stattext.h"
26 #include "wx/combobox.h"
27 #include "wx/button.h"
28 #include "wx/settings.h"
29 #include "wx/icon.h"
30 #include "wx/listbox.h"
31 #endif
32
33 #include "wx/dcbuffer.h"
34
35 // Only for cached font name
36 #include "wx/richtext/richtextctrl.h"
37
38 /* Microsoft Unicode subset numbering
39 */
40
41 typedef enum
42 {
43 U_BASIC_LATIN = 0,
44 U_LATIN_1_SUPPLEMENT = 1,
45 U_LATIN_EXTENDED_A = 2,
46 U_LATIN_EXTENDED_B = 3,
47 U_IPA_EXTENSIONS = 4,
48 U_SPACING_MODIFIER_LETTERS = 5,
49 U_COMBINING_DIACRITICAL_MARKS = 6,
50 U_BASIC_GREEK = 7,
51 U_GREEK_SYMBOLS_AND_COPTIC = 8,
52 U_CYRILLIC = 9,
53 U_ARMENIAN = 10,
54 U_HEBREW_EXTENDED = 12,
55 U_BASIC_HEBREW = 11,
56 U_BASIC_ARABIC = 13,
57 U_ARABIC_EXTENDED = 14,
58 U_DEVANAGARI = 15,
59 U_BENGALI = 16,
60 U_GURMUKHI = 17,
61 U_GUJARATI = 18,
62 U_ORIYA = 19,
63 U_TAMIL = 20,
64 U_TELUGU = 21,
65 U_KANNADA = 22,
66 U_MALAYALAM = 23,
67 U_THAI = 24,
68 U_LAO = 25,
69 U_GEORGIAN_EXTENDED = 27,
70 U_BASIC_GEORGIAN = 26,
71 U_HANGUL_JAMO = 28,
72 U_LATIN_EXTENDED_ADDITIONAL = 29,
73 U_GREEK_EXTENDED = 30,
74 U_GENERAL_PUNCTUATION = 31,
75 U_SUPERSCRIPTS_AND_SUBSCRIPTS = 32,
76 U_CURRENCY_SYMBOLS = 33,
77 U_COMBINING_DIACRITICAL_MARKS_FOR_SYMBOLS = 34,
78 U_LETTERLIKE_SYMBOLS = 35,
79 U_NUMBER_FORMS = 36,
80 U_ARROWS = 37,
81 U_MATHEMATICAL_OPERATORS = 38,
82 U_MISCELLANEOUS_TECHNICAL = 39,
83 U_CONTROL_PICTURES = 40,
84 U_OPTICAL_CHARACTER_RECOGNITION = 41,
85 U_ENCLOSED_ALPHANUMERICS = 42,
86 U_BOX_DRAWING = 43,
87 U_BLOCK_ELEMENTS = 44,
88 U_GEOMETRIC_SHAPES = 45,
89 U_MISCELLANEOUS_SYMBOLS = 46,
90 U_DINGBATS = 47,
91 U_CJK_SYMBOLS_AND_PUNCTUATION = 48,
92 U_HIRAGANA = 49,
93 U_KATAKANA = 50,
94 U_BOPOMOFO = 51,
95 U_HANGUL_COMPATIBILITY_JAMO = 52,
96 U_CJK_MISCELLANEOUS = 53,
97 U_ENCLOSED_CJK = 54,
98 U_CJK_COMPATIBILITY = 55,
99 U_HANGUL = 56,
100 U_HANGUL_SUPPLEMENTARY_A = 57,
101 U_HANGUL_SUPPLEMENTARY_B = 58,
102 U_CJK_UNIFIED_IDEOGRAPHS = 59,
103 U_PRIVATE_USE_AREA = 60,
104 U_CJK_COMPATIBILITY_IDEOGRAPHS = 61,
105 U_ALPHABETIC_PRESENTATION_FORMS = 62,
106 U_ARABIC_PRESENTATION_FORMS_A = 63,
107 U_COMBINING_HALF_MARKS = 64,
108 U_CJK_COMPATIBILITY_FORMS = 65,
109 U_SMALL_FORM_VARIANTS = 66,
110 U_ARABIC_PRESENTATION_FORMS_B = 67,
111 U_SPECIALS = 69,
112 U_HALFWIDTH_AND_FULLWIDTH_FORMS = 68,
113 U_LAST_PLUS_ONE
114 } wxUnicodeSubsetCodes;
115
116 /* Unicode subsets */
117 #ifdef __UNICODE__
118
119 static struct
120 {
121 int m_low, m_high;
122 wxUnicodeSubsetCodes m_subset;
123 const wxChar* m_name;
124 } g_UnicodeSubsetTable[] =
125 {
126 { 0x0000, 0x007E,
127 U_BASIC_LATIN, wxT("Basic Latin") },
128 { 0x00A0, 0x00FF,
129 U_LATIN_1_SUPPLEMENT, wxT("Latin-1 Supplement") },
130 { 0x0100, 0x017F,
131 U_LATIN_EXTENDED_A, wxT("Latin Extended-A") },
132 { 0x0180, 0x024F,
133 U_LATIN_EXTENDED_B, wxT("Latin Extended-B") },
134 { 0x0250, 0x02AF,
135 U_IPA_EXTENSIONS, wxT("IPA Extensions") },
136 { 0x02B0, 0x02FF,
137 U_SPACING_MODIFIER_LETTERS, wxT("Spacing Modifier Letters") },
138 { 0x0300, 0x036F,
139 U_COMBINING_DIACRITICAL_MARKS, wxT("Combining Diacritical Marks") },
140 { 0x0370, 0x03CF,
141 U_BASIC_GREEK, wxT("Basic Greek") },
142 { 0x03D0, 0x03FF,
143 U_GREEK_SYMBOLS_AND_COPTIC, wxT("Greek Symbols and Coptic") },
144 { 0x0400, 0x04FF,
145 U_CYRILLIC, wxT("Cyrillic") },
146 { 0x0530, 0x058F,
147 U_ARMENIAN, wxT("Armenian") },
148 { 0x0590, 0x05CF,
149 U_HEBREW_EXTENDED, wxT("Hebrew Extended") },
150 { 0x05D0, 0x05FF,
151 U_BASIC_HEBREW, wxT("Basic Hebrew") },
152 { 0x0600, 0x0652,
153 U_BASIC_ARABIC, wxT("Basic Arabic") },
154 { 0x0653, 0x06FF,
155 U_ARABIC_EXTENDED, wxT("Arabic Extended") },
156 { 0x0900, 0x097F,
157 U_DEVANAGARI, wxT("Devanagari") },
158 { 0x0980, 0x09FF,
159 U_BENGALI, wxT("Bengali") },
160 { 0x0A00, 0x0A7F,
161 U_GURMUKHI, wxT("Gurmukhi") },
162 { 0x0A80, 0x0AFF,
163 U_GUJARATI, wxT("Gujarati") },
164 { 0x0B00, 0x0B7F,
165 U_ORIYA, wxT("Oriya") },
166 { 0x0B80, 0x0BFF,
167 U_TAMIL, wxT("Tamil") },
168 { 0x0C00, 0x0C7F,
169 U_TELUGU, wxT("Telugu") },
170 { 0x0C80, 0x0CFF,
171 U_KANNADA, wxT("Kannada") },
172 { 0x0D00, 0x0D7F,
173 U_MALAYALAM, wxT("Malayalam") },
174 { 0x0E00, 0x0E7F,
175 U_THAI, wxT("Thai") },
176 { 0x0E80, 0x0EFF,
177 U_LAO, wxT("Lao") },
178 { 0x10A0, 0x10CF,
179 U_GEORGIAN_EXTENDED, wxT("Georgian Extended") },
180 { 0x10D0, 0x10FF,
181 U_BASIC_GEORGIAN, wxT("Basic Georgian") },
182 { 0x1100, 0x11FF,
183 U_HANGUL_JAMO, wxT("Hangul Jamo") },
184 { 0x1E00, 0x1EFF,
185 U_LATIN_EXTENDED_ADDITIONAL, wxT("Latin Extended Additional") },
186 { 0x1F00, 0x1FFF,
187 U_GREEK_EXTENDED, wxT("Greek Extended") },
188 { 0x2000, 0x206F,
189 U_GENERAL_PUNCTUATION, wxT("General Punctuation") },
190 { 0x2070, 0x209F,
191 U_SUPERSCRIPTS_AND_SUBSCRIPTS, wxT("Superscripts and Subscripts") },
192 { 0x20A0, 0x20CF,
193 U_CURRENCY_SYMBOLS, wxT("Currency Symbols") },
194 { 0x20D0, 0x20FF,
195 U_COMBINING_DIACRITICAL_MARKS_FOR_SYMBOLS, wxT("Combining Diacritical Marks for Symbols") },
196 { 0x2100, 0x214F,
197 U_LETTERLIKE_SYMBOLS, wxT("Letterlike Symbols") },
198 { 0x2150, 0x218F,
199 U_NUMBER_FORMS, wxT("Number Forms") },
200 { 0x2190, 0x21FF,
201 U_ARROWS, wxT("Arrows") },
202 { 0x2200, 0x22FF,
203 U_MATHEMATICAL_OPERATORS, wxT("Mathematical Operators") },
204 { 0x2300, 0x23FF,
205 U_MISCELLANEOUS_TECHNICAL, wxT("Miscellaneous Technical") },
206 { 0x2400, 0x243F,
207 U_CONTROL_PICTURES, wxT("Control Pictures") },
208 { 0x2440, 0x245F,
209 U_OPTICAL_CHARACTER_RECOGNITION, wxT("Optical Character Recognition") },
210 { 0x2460, 0x24FF,
211 U_ENCLOSED_ALPHANUMERICS, wxT("Enclosed Alphanumerics") },
212 { 0x2500, 0x257F,
213 U_BOX_DRAWING, wxT("Box Drawing") },
214 { 0x2580, 0x259F,
215 U_BLOCK_ELEMENTS, wxT("Block Elements") },
216 { 0x25A0, 0x25FF,
217 U_GEOMETRIC_SHAPES, wxT("Geometric Shapes") },
218 { 0x2600, 0x26FF,
219 U_MISCELLANEOUS_SYMBOLS, wxT("Miscellaneous Symbols") },
220 { 0x2700, 0x27BF,
221 U_DINGBATS, wxT("Dingbats") },
222 { 0x3000, 0x303F,
223 U_CJK_SYMBOLS_AND_PUNCTUATION, wxT("CJK Symbols and Punctuation") },
224 { 0x3040, 0x309F,
225 U_HIRAGANA, wxT("Hiragana") },
226 { 0x30A0, 0x30FF,
227 U_KATAKANA, wxT("Katakana") },
228 { 0x3100, 0x312F,
229 U_BOPOMOFO, wxT("Bopomofo") },
230 { 0x3130, 0x318F,
231 U_HANGUL_COMPATIBILITY_JAMO, wxT("Hangul Compatibility Jamo") },
232 { 0x3190, 0x319F,
233 U_CJK_MISCELLANEOUS, wxT("CJK Miscellaneous") },
234 { 0x3200, 0x32FF,
235 U_ENCLOSED_CJK, wxT("Enclosed CJK") },
236 { 0x3300, 0x33FF,
237 U_CJK_COMPATIBILITY, wxT("CJK Compatibility") },
238 { 0x3400, 0x4DB5,
239 U_CJK_UNIFIED_IDEOGRAPHS, wxT("CJK Unified Ideographs Extension A") },
240 { 0x4E00, 0x9FFF,
241 U_CJK_UNIFIED_IDEOGRAPHS, wxT("CJK Unified Ideographs") },
242 { 0xAC00, 0xD7A3,
243 U_HANGUL, wxT("Hangul Syllables") },
244 { 0xE000, 0xF8FF,
245 U_PRIVATE_USE_AREA, wxT("Private Use Area") },
246 { 0xF900, 0xFAFF,
247 U_CJK_COMPATIBILITY_IDEOGRAPHS, wxT("CJK Compatibility Ideographs") },
248 { 0xFB00, 0xFB4F,
249 U_ALPHABETIC_PRESENTATION_FORMS, wxT("Alphabetic Presentation Forms") },
250 { 0xFB50, 0xFDFF,
251 U_ARABIC_PRESENTATION_FORMS_A, wxT("Arabic Presentation Forms-A") },
252 { 0xFE20, 0xFE2F,
253 U_COMBINING_HALF_MARKS, wxT("Combining Half Marks") },
254 { 0xFE30, 0xFE4F,
255 U_CJK_COMPATIBILITY_FORMS, wxT("CJK Compatibility Forms") },
256 { 0xFE50, 0xFE6F,
257 U_SMALL_FORM_VARIANTS, wxT("Small Form Variants") },
258 { 0xFE70, 0xFEFE,
259 U_ARABIC_PRESENTATION_FORMS_B, wxT("Arabic Presentation Forms-B") },
260 { 0xFEFF, 0xFEFF,
261 U_SPECIALS, wxT("Specials") },
262 { 0xFF00, 0xFFEF,
263 U_HALFWIDTH_AND_FULLWIDTH_FORMS, wxT("Halfwidth and Fullwidth Forms") },
264 { 0xFFF0, 0xFFFD,
265 U_SPECIALS, wxT("Specials") }
266 };
267
268 #endif // __UNICODE__
269
270 #if 0
271 // Not yet used, but could be used to test under Win32 whether this subset is available
272 // for the given font. The Win32 function is allegedly not accurate, however.
273 bool wxSubsetValidForFont(int subsetIndex, FONTSIGNATURE *fontSig)
274 {
275 return (fontSig->fsUsb[g_UnicodeSubsetTable[subsetIndex].m_subset/32] & (1 << (g_UnicodeSubsetTable[subsetIndex].m_subset % 32)));
276 }
277 #endif
278
279 bool wxSymbolPickerDialog::sm_showToolTips = false;
280
281 /*!
282 * wxSymbolPickerDialog type definition
283 */
284
285 IMPLEMENT_DYNAMIC_CLASS( wxSymbolPickerDialog, wxDialog )
286
287 /*!
288 * wxSymbolPickerDialog event table definition
289 */
290
291 BEGIN_EVENT_TABLE( wxSymbolPickerDialog, wxDialog )
292 EVT_LISTBOX(ID_SYMBOLPICKERDIALOG_LISTCTRL, wxSymbolPickerDialog::OnSymbolSelected)
293
294 ////@begin wxSymbolPickerDialog event table entries
295 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FONT, wxSymbolPickerDialog::OnFontCtrlSelected )
296
297 #if defined(__UNICODE__)
298 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_SUBSET, wxSymbolPickerDialog::OnSubsetSelected )
299 #endif
300
301 #if defined(__UNICODE__)
302 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FROM, wxSymbolPickerDialog::OnFromUnicodeSelected )
303 #endif
304
305 EVT_UPDATE_UI( wxID_OK, wxSymbolPickerDialog::OnOkUpdate )
306
307 ////@end wxSymbolPickerDialog event table entries
308
309 END_EVENT_TABLE()
310
311 /*!
312 * wxSymbolPickerDialog constructors
313 */
314
315 wxSymbolPickerDialog::wxSymbolPickerDialog( )
316 {
317 Init();
318 }
319
320 wxSymbolPickerDialog::wxSymbolPickerDialog( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
321 {
322 Init();
323 Create(symbol, fontName, normalTextFont, parent, id, caption, pos, size, style);
324 }
325
326 /*!
327 * wxSymbolPickerDialog creator
328 */
329
330 bool wxSymbolPickerDialog::Create( const wxString& symbol, const wxString& fontName, const wxString& normalTextFont, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
331 {
332 m_fontName = fontName;
333 m_normalTextFontName = normalTextFont;
334 m_symbol = symbol;
335
336 ////@begin wxSymbolPickerDialog creation
337 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP);
338 wxDialog::Create( parent, id, caption, pos, size, style );
339
340 CreateControls();
341 if (GetSizer())
342 {
343 GetSizer()->SetSizeHints(this);
344 }
345 Centre();
346 ////@end wxSymbolPickerDialog creation
347 return true;
348 }
349
350 /*!
351 * Member initialisation for wxSymbolPickerDialog
352 */
353
354 void wxSymbolPickerDialog::Init()
355 {
356 ////@begin wxSymbolPickerDialog member initialisation
357 m_fromUnicode = true;
358 m_fontCtrl = NULL;
359 #if defined(__UNICODE__)
360 m_subsetCtrl = NULL;
361 #endif
362 m_symbolsCtrl = NULL;
363 m_symbolStaticCtrl = NULL;
364 m_characterCodeCtrl = NULL;
365 #if defined(__UNICODE__)
366 m_fromUnicodeCtrl = NULL;
367 #endif
368 ////@end wxSymbolPickerDialog member initialisation
369 m_dontUpdate = false;
370 }
371
372 /*!
373 * Control creation for wxSymbolPickerDialog
374 */
375
376 void wxSymbolPickerDialog::CreateControls()
377 {
378 ////@begin wxSymbolPickerDialog content construction
379 wxSymbolPickerDialog* itemDialog1 = this;
380
381 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
382 itemDialog1->SetSizer(itemBoxSizer2);
383
384 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
385 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
386
387 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
388 itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5);
389
390 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
391 itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5);
392
393 wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 );
394 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
395
396 wxString* m_fontCtrlStrings = NULL;
397 m_fontCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_FONT, wxEmptyString, wxDefaultPosition, wxSize(240, -1), 0, m_fontCtrlStrings, wxCB_READONLY );
398 m_fontCtrl->SetHelpText(_("The font from which to take the symbol."));
399 if (ShowToolTips())
400 m_fontCtrl->SetToolTip(_("The font from which to take the symbol."));
401 itemBoxSizer5->Add(m_fontCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
402
403 itemBoxSizer5->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
404
405 #if defined(__UNICODE__)
406 wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Subset:"), wxDefaultPosition, wxDefaultSize, 0 );
407 itemBoxSizer5->Add(itemStaticText9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
408
409 #endif
410
411 #if defined(__UNICODE__)
412 wxString* m_subsetCtrlStrings = NULL;
413 m_subsetCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_SUBSET, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, m_subsetCtrlStrings, wxCB_READONLY );
414 m_subsetCtrl->SetHelpText(_("Shows a Unicode subset."));
415 if (ShowToolTips())
416 m_subsetCtrl->SetToolTip(_("Shows a Unicode subset."));
417 itemBoxSizer5->Add(m_subsetCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
418
419 #endif
420
421 m_symbolsCtrl = new wxSymbolListCtrl( itemDialog1, ID_SYMBOLPICKERDIALOG_LISTCTRL, wxDefaultPosition, wxSize(500, 240), wxSIMPLE_BORDER );
422 itemBoxSizer3->Add(m_symbolsCtrl, 1, wxGROW|wxALL, 5);
423
424 wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
425 itemBoxSizer3->Add(itemBoxSizer12, 0, wxGROW, 5);
426
427 m_symbolStaticCtrl = new wxStaticText( itemDialog1, wxID_STATIC, _("xxxx"), wxDefaultPosition, wxSize(40, -1), wxALIGN_CENTRE );
428 itemBoxSizer12->Add(m_symbolStaticCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
429
430 itemBoxSizer12->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
431
432 wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Character code:"), wxDefaultPosition, wxDefaultSize, 0 );
433 itemBoxSizer12->Add(itemStaticText15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
434
435 m_characterCodeCtrl = new wxTextCtrl( itemDialog1, ID_SYMBOLPICKERDIALOG_CHARACTERCODE, wxEmptyString, wxDefaultPosition, wxSize(140, -1), wxTE_READONLY|wxTE_CENTRE );
436 m_characterCodeCtrl->SetHelpText(_("The character code."));
437 if (ShowToolTips())
438 m_characterCodeCtrl->SetToolTip(_("The character code."));
439 itemBoxSizer12->Add(m_characterCodeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
440
441 itemBoxSizer12->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
442
443 #if defined(__UNICODE__)
444 wxStaticText* itemStaticText18 = new wxStaticText( itemDialog1, wxID_STATIC, _("&From:"), wxDefaultPosition, wxDefaultSize, 0 );
445 itemBoxSizer12->Add(itemStaticText18, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
446
447 #endif
448
449 #if defined(__UNICODE__)
450 wxString m_fromUnicodeCtrlStrings[] = {
451 _("ASCII"),
452 _("Unicode")
453 };
454 m_fromUnicodeCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_FROM, _("ASCII"), wxDefaultPosition, wxDefaultSize, 2, m_fromUnicodeCtrlStrings, wxCB_READONLY );
455 m_fromUnicodeCtrl->SetStringSelection(_("ASCII"));
456 m_fromUnicodeCtrl->SetHelpText(_("The range to show."));
457 if (ShowToolTips())
458 m_fromUnicodeCtrl->SetToolTip(_("The range to show."));
459 itemBoxSizer12->Add(m_fromUnicodeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
460
461 #endif
462
463 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
464 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxHORIZONTAL);
465 itemBoxSizer3->Add(itemBoxSizer20, 0, wxGROW, 5);
466
467 itemBoxSizer20->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
468
469 wxButton* itemButton22 = new wxButton( itemDialog1, wxID_OK, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 );
470 itemButton22->SetDefault();
471 itemButton22->SetHelpText(_("Inserts the chosen symbol."));
472 if (ShowToolTips())
473 itemButton22->SetToolTip(_("Inserts the chosen symbol."));
474 itemBoxSizer20->Add(itemButton22, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
475
476 wxButton* itemButton23 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
477 itemButton23->SetHelpText(_("Closes the dialog without inserting a symbol."));
478 if (ShowToolTips())
479 itemButton23->SetToolTip(_("Closes the dialog without inserting a symbol."));
480 itemBoxSizer20->Add(itemButton23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
481
482 #endif
483
484 #if defined(__WXMAC__)
485 wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxHORIZONTAL);
486 itemBoxSizer3->Add(itemBoxSizer24, 0, wxGROW, 5);
487
488 itemBoxSizer24->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
489
490 wxButton* itemButton26 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
491 itemButton26->SetHelpText(_("Closes the dialog without inserting a symbol."));
492 if (ShowToolTips())
493 itemButton26->SetToolTip(_("Closes the dialog without inserting a symbol."));
494 itemBoxSizer24->Add(itemButton26, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
495
496 wxButton* itemButton27 = new wxButton( itemDialog1, wxID_OK, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 );
497 itemButton27->SetDefault();
498 itemButton27->SetHelpText(_("Inserts the chosen symbol."));
499 if (ShowToolTips())
500 itemButton27->SetToolTip(_("Inserts the chosen symbol."));
501 itemBoxSizer24->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
502
503 #endif
504
505 ////@end wxSymbolPickerDialog content construction
506
507 }
508
509 /// Data transfer
510 bool wxSymbolPickerDialog::TransferDataToWindow()
511 {
512 m_dontUpdate = true;
513
514 if (m_fontCtrl->GetCount() == 0)
515 {
516 wxArrayString faceNames = wxRichTextCtrl::GetAvailableFontNames();
517 faceNames.Sort();
518
519 faceNames.Insert(_("(Normal text)"), 0);
520 m_fontCtrl->Append(faceNames);
521 }
522
523 if (m_fontName.empty())
524 m_fontCtrl->SetSelection(0);
525 else
526 {
527 if (m_fontCtrl->FindString(m_fontName) != wxNOT_FOUND)
528 m_fontCtrl->SetStringSelection(m_fontName);
529 else
530 m_fontCtrl->SetSelection(0);
531 }
532
533 if (!m_symbol.empty())
534 {
535 int sel = (int) m_symbol[0];
536 m_symbolsCtrl->SetSelection(sel);
537 }
538
539 #if defined(__UNICODE__)
540 if (m_subsetCtrl->GetCount() == 0)
541 {
542 // Insert items into subset combo
543 int i;
544 for (i = 0; i < (int) (sizeof(g_UnicodeSubsetTable)/sizeof(g_UnicodeSubsetTable[0])); i++)
545 {
546 m_subsetCtrl->Append(g_UnicodeSubsetTable[i].m_name);
547 }
548 m_subsetCtrl->SetSelection(0);
549 }
550 #endif
551
552 UpdateSymbolDisplay();
553
554 m_dontUpdate = false;
555
556 return true;
557 }
558
559 void wxSymbolPickerDialog::UpdateSymbolDisplay(bool updateSymbolList, bool showAtSubset)
560 {
561 wxFont font;
562 wxString fontNameToUse;
563 if (m_fontName.empty())
564 fontNameToUse = m_normalTextFontName;
565 else
566 fontNameToUse = m_fontName;
567
568 if (!fontNameToUse.empty())
569 {
570 font = wxFont(14, wxDEFAULT, wxNORMAL, wxNORMAL, false, fontNameToUse);
571 }
572 else
573 font = *wxNORMAL_FONT;
574
575 if (updateSymbolList)
576 {
577 m_symbolsCtrl->SetFont(font);
578 }
579
580 if (!m_symbol.empty())
581 {
582 m_symbolStaticCtrl->SetFont(font);
583 m_symbolStaticCtrl->SetLabel(m_symbol);
584
585 int symbol = (int) m_symbol[0];
586 m_characterCodeCtrl->SetValue(wxString::Format(wxT("%X hex (%d dec)"), symbol, symbol));
587 }
588 else
589 {
590 m_symbolStaticCtrl->SetLabel(wxEmptyString);
591 m_characterCodeCtrl->SetValue(wxEmptyString);
592 }
593
594 #if defined(__UNICODE__)
595 if (showAtSubset)
596 ShowAtSubset();
597 #else
598 wxUnusedVar(showAtSubset);
599 #endif
600 }
601
602 /// Show at the current subset selection
603 void wxSymbolPickerDialog::ShowAtSubset()
604 {
605 #if defined(__UNICODE__)
606 if (m_fromUnicode)
607 {
608 int sel = m_subsetCtrl->GetSelection();
609 int low = g_UnicodeSubsetTable[sel].m_low;
610 m_symbolsCtrl->EnsureVisible(low);
611 }
612 #endif
613 }
614
615 // Handle font selection
616 void wxSymbolPickerDialog::OnFontCtrlSelected( wxCommandEvent& WXUNUSED(event) )
617 {
618 if (m_fontCtrl->GetSelection() == 0)
619 m_fontName = wxEmptyString;
620 else
621 m_fontName = m_fontCtrl->GetStringSelection();
622
623 UpdateSymbolDisplay();
624 }
625
626 /// Respond to symbol selection
627 void wxSymbolPickerDialog::OnSymbolSelected( wxCommandEvent& event )
628 {
629 if (m_dontUpdate)
630 return;
631
632 int sel = event.GetSelection();
633 if (sel == wxNOT_FOUND)
634 m_symbol = wxEmptyString;
635 else
636 {
637 m_symbol = wxEmptyString;
638 m_symbol << (wxChar) sel;
639 }
640
641 #if defined(__UNICODE__)
642 if (sel != -1 && m_fromUnicode)
643 {
644 // Need to make the subset selection reflect the current symbol
645 int i;
646 for (i = 0; i < (int) (sizeof(g_UnicodeSubsetTable)/sizeof(g_UnicodeSubsetTable[0])); i++)
647 {
648 if (sel >= g_UnicodeSubsetTable[i].m_low && sel <= g_UnicodeSubsetTable[i].m_high)
649 {
650 m_dontUpdate = true;
651 m_subsetCtrl->SetSelection(i);
652 m_dontUpdate = false;
653 break;
654 }
655 }
656 }
657 #endif
658
659 UpdateSymbolDisplay(false, false);
660 }
661
662 #if defined(__UNICODE__)
663 // Handle Unicode/ASCII selection
664 void wxSymbolPickerDialog::OnFromUnicodeSelected( wxCommandEvent& WXUNUSED(event) )
665 {
666 if (m_dontUpdate)
667 return;
668
669 m_fromUnicode = (m_fromUnicodeCtrl->GetSelection() == 1);
670 m_symbolsCtrl->SetUnicodeMode(m_fromUnicode);
671 UpdateSymbolDisplay(false);
672 }
673
674 // Handle subset selection
675 void wxSymbolPickerDialog::OnSubsetSelected( wxCommandEvent& WXUNUSED(event) )
676 {
677 if (m_dontUpdate)
678 return;
679
680 ShowAtSubset();
681 }
682 #endif
683
684 /*!
685 * wxEVT_UPDATE_UI event handler for wxID_OK
686 */
687
688 void wxSymbolPickerDialog::OnOkUpdate( wxUpdateUIEvent& event )
689 {
690 event.Enable(HasSelection());
691 }
692
693 /// Set Unicode mode
694 void wxSymbolPickerDialog::SetUnicodeMode(bool unicodeMode)
695 {
696 #if defined(__UNICODE__)
697 m_dontUpdate = true;
698 m_fromUnicode = unicodeMode;
699 if (m_fromUnicodeCtrl)
700 m_fromUnicodeCtrl->SetSelection(m_fromUnicode ? 1 : 0);
701 UpdateSymbolDisplay();
702 m_dontUpdate = false;
703 #else
704 wxUnusedVar(unicodeMode);
705 #endif
706 }
707
708 /// Get the selected symbol character
709 int wxSymbolPickerDialog::GetSymbolChar() const
710 {
711 if (m_symbol.empty())
712 return -1;
713 else
714 return (int) m_symbol[0];
715 }
716
717
718 /*!
719 * Get bitmap resources
720 */
721
722 wxBitmap wxSymbolPickerDialog::GetBitmapResource( const wxString& name )
723 {
724 // Bitmap retrieval
725 ////@begin wxSymbolPickerDialog bitmap retrieval
726 wxUnusedVar(name);
727 return wxNullBitmap;
728 ////@end wxSymbolPickerDialog bitmap retrieval
729 }
730
731 /*!
732 * Get icon resources
733 */
734
735 wxIcon wxSymbolPickerDialog::GetIconResource( const wxString& name )
736 {
737 // Icon retrieval
738 ////@begin wxSymbolPickerDialog icon retrieval
739 wxUnusedVar(name);
740 return wxNullIcon;
741 ////@end wxSymbolPickerDialog icon retrieval
742 }
743
744 /*!
745 * The scrolling symbol list.
746 */
747
748 // ----------------------------------------------------------------------------
749 // event tables
750 // ----------------------------------------------------------------------------
751
752 BEGIN_EVENT_TABLE(wxSymbolListCtrl, wxVScrolledWindow)
753 EVT_PAINT(wxSymbolListCtrl::OnPaint)
754 EVT_SIZE(wxSymbolListCtrl::OnSize)
755
756 EVT_KEY_DOWN(wxSymbolListCtrl::OnKeyDown)
757 EVT_LEFT_DOWN(wxSymbolListCtrl::OnLeftDown)
758 EVT_LEFT_DCLICK(wxSymbolListCtrl::OnLeftDClick)
759 END_EVENT_TABLE()
760
761 // ============================================================================
762 // implementation
763 // ============================================================================
764
765 IMPLEMENT_ABSTRACT_CLASS(wxSymbolListCtrl, wxVScrolledWindow)
766
767 // ----------------------------------------------------------------------------
768 // wxSymbolListCtrl creation
769 // ----------------------------------------------------------------------------
770
771 void wxSymbolListCtrl::Init()
772 {
773 m_current = wxNOT_FOUND;
774 m_doubleBuffer = NULL;
775 m_cellSize = wxSize(40, 40);
776 m_minSymbolValue = 0;
777 m_maxSymbolValue = 255;
778 m_symbolsPerLine = 0;
779 m_unicodeMode = false;
780 }
781
782 bool wxSymbolListCtrl::Create(wxWindow *parent,
783 wxWindowID id,
784 const wxPoint& pos,
785 const wxSize& size,
786 long style,
787 const wxString& name)
788 {
789 style |= wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE;
790 if ( !wxVScrolledWindow::Create(parent, id, pos, size, style, name) )
791 return false;
792
793 // make sure the native widget has the right colour since we do
794 // transparent drawing by default
795 SetBackgroundColour(GetBackgroundColour());
796 m_colBgSel = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
797
798 // flicker-free drawing requires this
799 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
800
801 SetFont(*wxNORMAL_FONT);
802
803 SetupCtrl();
804
805 return true;
806 }
807
808 wxSymbolListCtrl::~wxSymbolListCtrl()
809 {
810 delete m_doubleBuffer;
811 }
812
813 // ----------------------------------------------------------------------------
814 // selection handling
815 // ----------------------------------------------------------------------------
816
817 bool wxSymbolListCtrl::IsSelected(int item) const
818 {
819 return item == m_current;
820 }
821
822 bool wxSymbolListCtrl::DoSetCurrent(int current)
823 {
824 wxASSERT_MSG( current == wxNOT_FOUND ||
825 (current >= m_minSymbolValue && current <= m_maxSymbolValue),
826 _T("wxSymbolListCtrl::DoSetCurrent(): invalid symbol value") );
827
828 if ( current == m_current )
829 {
830 // nothing to do
831 return false;
832 }
833
834 if ( m_current != wxNOT_FOUND )
835 RefreshRow(SymbolValueToLineNumber(m_current));
836
837 m_current = current;
838
839 if ( m_current != wxNOT_FOUND )
840 {
841 int lineNo = SymbolValueToLineNumber(m_current);
842
843 // if the line is not visible at all, we scroll it into view but we
844 // don't need to refresh it -- it will be redrawn anyhow
845 if ( !IsVisible(lineNo) )
846 {
847 ScrollToRow(lineNo);
848 }
849 else // line is at least partly visible
850 {
851 // it is, indeed, only partly visible, so scroll it into view to
852 // make it entirely visible
853 while ( (unsigned)lineNo + 1 == GetVisibleEnd() &&
854 ScrollToRow(GetVisibleBegin() + 1) )
855 ;
856
857 // but in any case refresh it as even if it was only partly visible
858 // before we need to redraw it entirely as its background changed
859 RefreshRow(lineNo);
860 }
861 }
862
863 return true;
864 }
865
866 void wxSymbolListCtrl::SendSelectedEvent()
867 {
868 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, GetId());
869 event.SetEventObject(this);
870 event.SetInt(m_current);
871
872 (void)GetEventHandler()->ProcessEvent(event);
873 }
874
875 void wxSymbolListCtrl::SetSelection(int selection)
876 {
877 wxCHECK_RET( selection == wxNOT_FOUND ||
878 (selection >= m_minSymbolValue && selection < m_maxSymbolValue),
879 _T("wxSymbolListCtrl::SetSelection(): invalid symbol value") );
880
881 DoSetCurrent(selection);
882 }
883
884 // ----------------------------------------------------------------------------
885 // wxSymbolListCtrl appearance parameters
886 // ----------------------------------------------------------------------------
887
888 void wxSymbolListCtrl::SetMargins(const wxPoint& pt)
889 {
890 if ( pt != m_ptMargins )
891 {
892 m_ptMargins = pt;
893
894 Refresh();
895 }
896 }
897
898 void wxSymbolListCtrl::SetSelectionBackground(const wxColour& col)
899 {
900 m_colBgSel = col;
901 }
902
903 // ----------------------------------------------------------------------------
904 // wxSymbolListCtrl painting
905 // ----------------------------------------------------------------------------
906
907 wxCoord wxSymbolListCtrl::OnGetRowHeight(size_t WXUNUSED(line)) const
908 {
909 return m_cellSize.y + 2*m_ptMargins.y + 1 /* for divider */ ;
910 }
911
912 // draws a line of symbols
913 void wxSymbolListCtrl::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
914 {
915 wxColour oldTextColour = dc.GetTextForeground();
916 int startSymbol = n*m_symbolsPerLine;
917
918 int i;
919 for (i = 0; i < m_symbolsPerLine; i++)
920 {
921 bool resetColour = false;
922 int symbol = startSymbol+i;
923 if (symbol == m_current)
924 {
925 dc.SetBrush(wxBrush(m_colBgSel));
926
927 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
928 resetColour = true;
929
930 wxPen oldPen = dc.GetPen();
931 dc.SetPen(*wxTRANSPARENT_PEN);
932
933 dc.DrawRectangle(rect.x + i*m_cellSize.x, rect.y, m_cellSize.x, rect.y+rect.height);
934 dc.SetPen(oldPen);
935 }
936
937 // Don't draw first line
938 if (i != 0)
939 dc.DrawLine(rect.x + i*m_cellSize.x, rect.y, i*m_cellSize.x, rect.y+rect.height);
940
941 if (symbol >= m_minSymbolValue && symbol <= m_maxSymbolValue)
942 {
943 wxString text;
944 text << (wxChar) symbol;
945
946 wxCoord w, h;
947 dc.GetTextExtent(text, & w, & h);
948
949 int x = rect.x + i*m_cellSize.x + (m_cellSize.x - w)/2;
950 int y = rect.y + (m_cellSize.y - h)/2;
951 dc.DrawText(text, x, y);
952 }
953
954 if (resetColour)
955 dc.SetTextForeground(oldTextColour);
956 }
957
958 // Draw horizontal separator line
959 dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1);
960 }
961
962 void wxSymbolListCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
963 {
964 // If size is larger, recalculate double buffer bitmap
965 wxSize clientSize = GetClientSize();
966
967 if ( !m_doubleBuffer ||
968 clientSize.x > m_doubleBuffer->GetWidth() ||
969 clientSize.y > m_doubleBuffer->GetHeight() )
970 {
971 delete m_doubleBuffer;
972 m_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
973 }
974
975 wxBufferedPaintDC dc(this,*m_doubleBuffer);
976
977 // the update rectangle
978 wxRect rectUpdate = GetUpdateClientRect();
979
980 // fill it with background colour
981 dc.SetBackground(GetBackgroundColour());
982 dc.Clear();
983
984 // set the font to be displayed
985 dc.SetFont(GetFont());
986
987 // the bounding rectangle of the current line
988 wxRect rectRow;
989 rectRow.width = clientSize.x;
990
991 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
992 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
993 dc.SetBackgroundMode(wxTRANSPARENT);
994
995 // iterate over all visible lines
996 const size_t lineMax = GetVisibleEnd();
997 for ( size_t line = GetVisibleBegin(); line < lineMax; line++ )
998 {
999 const wxCoord hRow = OnGetRowHeight(line);
1000
1001 rectRow.height = hRow;
1002
1003 // and draw the ones which intersect the update rect
1004 if ( rectRow.Intersects(rectUpdate) )
1005 {
1006 // don't allow drawing outside of the lines rectangle
1007 wxDCClipper clip(dc, rectRow);
1008
1009 wxRect rect = rectRow;
1010 rect.Deflate(m_ptMargins.x, m_ptMargins.y);
1011 OnDrawItem(dc, rect, line);
1012 }
1013 else // no intersection
1014 {
1015 if ( rectRow.GetTop() > rectUpdate.GetBottom() )
1016 {
1017 // we are already below the update rect, no need to continue
1018 // further
1019 break;
1020 }
1021 //else: the next line may intersect the update rect
1022 }
1023
1024 rectRow.y += hRow;
1025 }
1026 }
1027
1028 // ============================================================================
1029 // wxSymbolListCtrl keyboard/mouse handling
1030 // ============================================================================
1031
1032 void wxSymbolListCtrl::DoHandleItemClick(int item, int WXUNUSED(flags))
1033 {
1034 if (m_current != item)
1035 {
1036 m_current = item;
1037 Refresh();
1038 SendSelectedEvent();
1039 }
1040 }
1041
1042 // ----------------------------------------------------------------------------
1043 // keyboard handling
1044 // ----------------------------------------------------------------------------
1045
1046 void wxSymbolListCtrl::OnKeyDown(wxKeyEvent& event)
1047 {
1048 // No keyboard interface for now
1049 event.Skip();
1050 #if 0
1051 // flags for DoHandleItemClick()
1052 int flags = ItemClick_Kbd;
1053
1054 int currentLineNow = SymbolValueToLineNumber(m_current);
1055
1056 int currentLine;
1057 switch ( event.GetKeyCode() )
1058 {
1059 case WXK_HOME:
1060 currentLine = 0;
1061 break;
1062
1063 case WXK_END:
1064 currentLine = GetLineCount() - 1;
1065 break;
1066
1067 case WXK_DOWN:
1068 if ( currentLineNow == (int)GetLineCount() - 1 )
1069 return;
1070
1071 currentLine = currentLineNow + 1;
1072 break;
1073
1074 case WXK_UP:
1075 if ( m_current == wxNOT_FOUND )
1076 currentLine = GetLineCount() - 1;
1077 else if ( currentLineNow != 0 )
1078 currentLine = currentLineNow - 1;
1079 else // currentLineNow == 0
1080 return;
1081 break;
1082
1083 case WXK_PAGEDOWN:
1084 PageDown();
1085 currentLine = GetFirstVisibleLine();
1086 break;
1087
1088 case WXK_PAGEUP:
1089 if ( currentLineNow == (int)GetFirstVisibleLine() )
1090 {
1091 PageUp();
1092 }
1093
1094 currentLine = GetFirstVisibleLine();
1095 break;
1096
1097 case WXK_SPACE:
1098 // hack: pressing space should work like a mouse click rather than
1099 // like a keyboard arrow press, so trick DoHandleItemClick() in
1100 // thinking we were clicked
1101 flags &= ~ItemClick_Kbd;
1102 currentLine = currentLineNow;
1103 break;
1104
1105 #ifdef __WXMSW__
1106 case WXK_TAB:
1107 // Since we are using wxWANTS_CHARS we need to send navigation
1108 // events for the tabs on MSW
1109 {
1110 wxNavigationKeyEvent ne;
1111 ne.SetDirection(!event.ShiftDown());
1112 ne.SetCurrentFocus(this);
1113 ne.SetEventObject(this);
1114 GetParent()->GetEventHandler()->ProcessEvent(ne);
1115 }
1116 // fall through to default
1117 #endif
1118 default:
1119 event.Skip();
1120 currentLine = 0; // just to silent the stupid compiler warnings
1121 wxUnusedVar(currentNow);
1122 return;
1123 }
1124
1125 #if 0
1126 if ( event.ShiftDown() )
1127 flags |= ItemClick_Shift;
1128 if ( event.ControlDown() )
1129 flags |= ItemClick_Ctrl;
1130
1131 DoHandleItemClick(current, flags);
1132 #endif
1133 #endif
1134 }
1135
1136 // ----------------------------------------------------------------------------
1137 // wxSymbolListCtrl mouse handling
1138 // ----------------------------------------------------------------------------
1139
1140 void wxSymbolListCtrl::OnLeftDown(wxMouseEvent& event)
1141 {
1142 SetFocus();
1143
1144 int item = HitTest(event.GetPosition());
1145
1146 if ( item != wxNOT_FOUND )
1147 {
1148 int flags = 0;
1149 if ( event.ShiftDown() )
1150 flags |= ItemClick_Shift;
1151
1152 // under Mac Apple-click is used in the same way as Ctrl-click
1153 // elsewhere
1154 #ifdef __WXMAC__
1155 if ( event.MetaDown() )
1156 #else
1157 if ( event.ControlDown() )
1158 #endif
1159 flags |= ItemClick_Ctrl;
1160
1161 DoHandleItemClick(item, flags);
1162 }
1163 }
1164
1165 void wxSymbolListCtrl::OnLeftDClick(wxMouseEvent& eventMouse)
1166 {
1167 int item = HitTest(eventMouse.GetPosition());
1168 if ( item != wxNOT_FOUND )
1169 {
1170
1171 // if item double-clicked was not yet selected, then treat
1172 // this event as a left-click instead
1173 if ( item == m_current )
1174 {
1175 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, GetId());
1176 event.SetEventObject(this);
1177 event.SetInt(item);
1178
1179 (void)GetEventHandler()->ProcessEvent(event);
1180 }
1181 else
1182 {
1183 OnLeftDown(eventMouse);
1184 }
1185
1186 }
1187 }
1188
1189 // calculate line number from symbol value
1190 int wxSymbolListCtrl::SymbolValueToLineNumber(int item)
1191 {
1192 return (int) (item/m_symbolsPerLine);
1193 }
1194
1195 // initialise control from current min/max values
1196 void wxSymbolListCtrl::SetupCtrl(bool scrollToSelection)
1197 {
1198 wxSize sz = GetClientSize();
1199
1200 m_symbolsPerLine = sz.x/(m_cellSize.x+m_ptMargins.x);
1201 int noLines = (1 + SymbolValueToLineNumber(m_maxSymbolValue));
1202
1203 SetRowCount(noLines);
1204 Refresh();
1205
1206 if (scrollToSelection && m_current != wxNOT_FOUND && m_current >= m_minSymbolValue && m_current <= m_maxSymbolValue)
1207 {
1208 ScrollToRow(SymbolValueToLineNumber(m_current));
1209 }
1210 }
1211
1212 // make this item visible
1213 void wxSymbolListCtrl::EnsureVisible(int item)
1214 {
1215 if (item != wxNOT_FOUND && item >= m_minSymbolValue && item <= m_maxSymbolValue)
1216 {
1217 ScrollToRow(SymbolValueToLineNumber(item));
1218 }
1219 }
1220
1221
1222 // hit testing
1223 int wxSymbolListCtrl::HitTest(const wxPoint& pt)
1224 {
1225 wxCoord lineHeight = OnGetRowHeight(0);
1226
1227 int atLine = GetVisibleBegin() + (pt.y/lineHeight);
1228 int symbol = (atLine*m_symbolsPerLine) + (pt.x/(m_cellSize.x+1));
1229
1230 if (symbol >= m_minSymbolValue && symbol <= m_maxSymbolValue)
1231 return symbol;
1232
1233 return -1;
1234 }
1235
1236 // Respond to size change
1237 void wxSymbolListCtrl::OnSize(wxSizeEvent& event)
1238 {
1239 SetupCtrl();
1240 event.Skip();
1241 }
1242
1243 // set the current font
1244 bool wxSymbolListCtrl::SetFont(const wxFont& font)
1245 {
1246 wxVScrolledWindow::SetFont(font);
1247
1248 SetupCtrl();
1249
1250 return true;
1251 }
1252
1253 // set Unicode/ASCII mode
1254 void wxSymbolListCtrl::SetUnicodeMode(bool unicodeMode)
1255 {
1256 bool changed = false;
1257 if (unicodeMode && !m_unicodeMode)
1258 {
1259 changed = true;
1260
1261 m_minSymbolValue = 0;
1262 m_maxSymbolValue = 65535;
1263 }
1264 else if (!unicodeMode && m_unicodeMode)
1265 {
1266 changed = true;
1267 m_minSymbolValue = 0;
1268 m_maxSymbolValue = 255;
1269 }
1270 m_unicodeMode = unicodeMode;
1271
1272 if (changed)
1273 SetupCtrl();
1274 }
1275
1276 // ----------------------------------------------------------------------------
1277 // use the same default attributes as wxListBox
1278 // ----------------------------------------------------------------------------
1279
1280 //static
1281 wxVisualAttributes
1282 wxSymbolListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
1283 {
1284 return wxListBox::GetClassDefaultAttributes(variant);
1285 }
1286
1287 #endif // wxUSE_RICHTEXT