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