warning fixes/minor cleanup
[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 #if wxUSE_RICHTEXT
20
21 #include "wx/richtext/richtextsymboldlg.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 ////@begin includes
28 ////@end includes
29
30 #include "wx/fontenum.h"
31 #include "wx/dcbuffer.h"
32 #include "wx/settings.h"
33
34 ////@begin XPM images
35 ////@end XPM images
36
37 /* Microsoft Unicode subset numbering
38 */
39
40 typedef enum
41 {
42 U_BASIC_LATIN = 0,
43 U_LATIN_1_SUPPLEMENT = 1,
44 U_LATIN_EXTENDED_A = 2,
45 U_LATIN_EXTENDED_B = 3,
46 U_IPA_EXTENSIONS = 4,
47 U_SPACING_MODIFIER_LETTERS = 5,
48 U_COMBINING_DIACRITICAL_MARKS = 6,
49 U_BASIC_GREEK = 7,
50 U_GREEK_SYMBOLS_AND_COPTIC = 8,
51 U_CYRILLIC = 9,
52 U_ARMENIAN = 10,
53 U_HEBREW_EXTENDED = 12,
54 U_BASIC_HEBREW = 11,
55 U_BASIC_ARABIC = 13,
56 U_ARABIC_EXTENDED = 14,
57 U_DEVANAGARI = 15,
58 U_BENGALI = 16,
59 U_GURMUKHI = 17,
60 U_GUJARATI = 18,
61 U_ORIYA = 19,
62 U_TAMIL = 20,
63 U_TELUGU = 21,
64 U_KANNADA = 22,
65 U_MALAYALAM = 23,
66 U_THAI = 24,
67 U_LAO = 25,
68 U_GEORGIAN_EXTENDED = 27,
69 U_BASIC_GEORGIAN = 26,
70 U_HANGUL_JAMO = 28,
71 U_LATIN_EXTENDED_ADDITIONAL = 29,
72 U_GREEK_EXTENDED = 30,
73 U_GENERAL_PUNCTUATION = 31,
74 U_SUPERSCRIPTS_AND_SUBSCRIPTS = 32,
75 U_CURRENCY_SYMBOLS = 33,
76 U_COMBINING_DIACRITICAL_MARKS_FOR_SYMBOLS = 34,
77 U_LETTERLIKE_SYMBOLS = 35,
78 U_NUMBER_FORMS = 36,
79 U_ARROWS = 37,
80 U_MATHEMATICAL_OPERATORS = 38,
81 U_MISCELLANEOUS_TECHNICAL = 39,
82 U_CONTROL_PICTURES = 40,
83 U_OPTICAL_CHARACTER_RECOGNITION = 41,
84 U_ENCLOSED_ALPHANUMERICS = 42,
85 U_BOX_DRAWING = 43,
86 U_BLOCK_ELEMENTS = 44,
87 U_GEOMETRIC_SHAPES = 45,
88 U_MISCELLANEOUS_SYMBOLS = 46,
89 U_DINGBATS = 47,
90 U_CJK_SYMBOLS_AND_PUNCTUATION = 48,
91 U_HIRAGANA = 49,
92 U_KATAKANA = 50,
93 U_BOPOMOFO = 51,
94 U_HANGUL_COMPATIBILITY_JAMO = 52,
95 U_CJK_MISCELLANEOUS = 53,
96 U_ENCLOSED_CJK = 54,
97 U_CJK_COMPATIBILITY = 55,
98 U_HANGUL = 56,
99 U_HANGUL_SUPPLEMENTARY_A = 57,
100 U_HANGUL_SUPPLEMENTARY_B = 58,
101 U_CJK_UNIFIED_IDEOGRAPHS = 59,
102 U_PRIVATE_USE_AREA = 60,
103 U_CJK_COMPATIBILITY_IDEOGRAPHS = 61,
104 U_ALPHABETIC_PRESENTATION_FORMS = 62,
105 U_ARABIC_PRESENTATION_FORMS_A = 63,
106 U_COMBINING_HALF_MARKS = 64,
107 U_CJK_COMPATIBILITY_FORMS = 65,
108 U_SMALL_FORM_VARIANTS = 66,
109 U_ARABIC_PRESENTATION_FORMS_B = 67,
110 U_SPECIALS = 69,
111 U_HALFWIDTH_AND_FULLWIDTH_FORMS = 68,
112 U_LAST_PLUS_ONE
113 } wxUnicodeSubsetCodes;
114
115 /* Unicode subsets */
116 #ifdef __UNICODE__
117
118 static struct
119 {
120 int m_low, m_high;
121 wxUnicodeSubsetCodes m_subset;
122 wxChar* m_name;
123 } g_UnicodeSubsetTable[] =
124 {
125 { 0x0000, 0x007E,
126 U_BASIC_LATIN, wxT("Basic Latin") },
127 { 0x00A0, 0x00FF,
128 U_LATIN_1_SUPPLEMENT, wxT("Latin-1 Supplement") },
129 { 0x0100, 0x017F,
130 U_LATIN_EXTENDED_A, wxT("Latin Extended-A") },
131 { 0x0180, 0x024F,
132 U_LATIN_EXTENDED_B, wxT("Latin Extended-B") },
133 { 0x0250, 0x02AF,
134 U_IPA_EXTENSIONS, wxT("IPA Extensions") },
135 { 0x02B0, 0x02FF,
136 U_SPACING_MODIFIER_LETTERS, wxT("Spacing Modifier Letters") },
137 { 0x0300, 0x036F,
138 U_COMBINING_DIACRITICAL_MARKS, wxT("Combining Diacritical Marks") },
139 { 0x0370, 0x03CF,
140 U_BASIC_GREEK, wxT("Basic Greek") },
141 { 0x03D0, 0x03FF,
142 U_GREEK_SYMBOLS_AND_COPTIC, wxT("Greek Symbols and Coptic") },
143 { 0x0400, 0x04FF,
144 U_CYRILLIC, wxT("Cyrillic") },
145 { 0x0530, 0x058F,
146 U_ARMENIAN, wxT("Armenian") },
147 { 0x0590, 0x05CF,
148 U_HEBREW_EXTENDED, wxT("Hebrew Extended") },
149 { 0x05D0, 0x05FF,
150 U_BASIC_HEBREW, wxT("Basic Hebrew") },
151 { 0x0600, 0x0652,
152 U_BASIC_ARABIC, wxT("Basic Arabic") },
153 { 0x0653, 0x06FF,
154 U_ARABIC_EXTENDED, wxT("Arabic Extended") },
155 { 0x0900, 0x097F,
156 U_DEVANAGARI, wxT("Devanagari") },
157 { 0x0980, 0x09FF,
158 U_BENGALI, wxT("Bengali") },
159 { 0x0A00, 0x0A7F,
160 U_GURMUKHI, wxT("Gurmukhi") },
161 { 0x0A80, 0x0AFF,
162 U_GUJARATI, wxT("Gujarati") },
163 { 0x0B00, 0x0B7F,
164 U_ORIYA, wxT("Oriya") },
165 { 0x0B80, 0x0BFF,
166 U_TAMIL, wxT("Tamil") },
167 { 0x0C00, 0x0C7F,
168 U_TELUGU, wxT("Telugu") },
169 { 0x0C80, 0x0CFF,
170 U_KANNADA, wxT("Kannada") },
171 { 0x0D00, 0x0D7F,
172 U_MALAYALAM, wxT("Malayalam") },
173 { 0x0E00, 0x0E7F,
174 U_THAI, wxT("Thai") },
175 { 0x0E80, 0x0EFF,
176 U_LAO, wxT("Lao") },
177 { 0x10A0, 0x10CF,
178 U_GEORGIAN_EXTENDED, wxT("Georgian Extended") },
179 { 0x10D0, 0x10FF,
180 U_BASIC_GEORGIAN, wxT("Basic Georgian") },
181 { 0x1100, 0x11FF,
182 U_HANGUL_JAMO, wxT("Hangul Jamo") },
183 { 0x1E00, 0x1EFF,
184 U_LATIN_EXTENDED_ADDITIONAL, wxT("Latin Extended Additional") },
185 { 0x1F00, 0x1FFF,
186 U_GREEK_EXTENDED, wxT("Greek Extended") },
187 { 0x2000, 0x206F,
188 U_GENERAL_PUNCTUATION, wxT("General Punctuation") },
189 { 0x2070, 0x209F,
190 U_SUPERSCRIPTS_AND_SUBSCRIPTS, wxT("Superscripts and Subscripts") },
191 { 0x20A0, 0x20CF,
192 U_CURRENCY_SYMBOLS, wxT("Currency Symbols") },
193 { 0x20D0, 0x20FF,
194 U_COMBINING_DIACRITICAL_MARKS_FOR_SYMBOLS, wxT("Combining Diacritical Marks for Symbols") },
195 { 0x2100, 0x214F,
196 U_LETTERLIKE_SYMBOLS, wxT("Letterlike Symbols") },
197 { 0x2150, 0x218F,
198 U_NUMBER_FORMS, wxT("Number Forms") },
199 { 0x2190, 0x21FF,
200 U_ARROWS, wxT("Arrows") },
201 { 0x2200, 0x22FF,
202 U_MATHEMATICAL_OPERATORS, wxT("Mathematical Operators") },
203 { 0x2300, 0x23FF,
204 U_MISCELLANEOUS_TECHNICAL, wxT("Miscellaneous Technical") },
205 { 0x2400, 0x243F,
206 U_CONTROL_PICTURES, wxT("Control Pictures") },
207 { 0x2440, 0x245F,
208 U_OPTICAL_CHARACTER_RECOGNITION, wxT("Optical Character Recognition") },
209 { 0x2460, 0x24FF,
210 U_ENCLOSED_ALPHANUMERICS, wxT("Enclosed Alphanumerics") },
211 { 0x2500, 0x257F,
212 U_BOX_DRAWING, wxT("Box Drawing") },
213 { 0x2580, 0x259F,
214 U_BLOCK_ELEMENTS, wxT("Block Elements") },
215 { 0x25A0, 0x25FF,
216 U_GEOMETRIC_SHAPES, wxT("Geometric Shapes") },
217 { 0x2600, 0x26FF,
218 U_MISCELLANEOUS_SYMBOLS, wxT("Miscellaneous Symbols") },
219 { 0x2700, 0x27BF,
220 U_DINGBATS, wxT("Dingbats") },
221 { 0x3000, 0x303F,
222 U_CJK_SYMBOLS_AND_PUNCTUATION, wxT("CJK Symbols and Punctuation") },
223 { 0x3040, 0x309F,
224 U_HIRAGANA, wxT("Hiragana") },
225 { 0x30A0, 0x30FF,
226 U_KATAKANA, wxT("Katakana") },
227 { 0x3100, 0x312F,
228 U_BOPOMOFO, wxT("Bopomofo") },
229 { 0x3130, 0x318F,
230 U_HANGUL_COMPATIBILITY_JAMO, wxT("Hangul Compatibility Jamo") },
231 { 0x3190, 0x319F,
232 U_CJK_MISCELLANEOUS, wxT("CJK Miscellaneous") },
233 { 0x3200, 0x32FF,
234 U_ENCLOSED_CJK, wxT("Enclosed CJK") },
235 { 0x3300, 0x33FF,
236 U_CJK_COMPATIBILITY, wxT("CJK Compatibility") },
237 { 0x3400, 0x4DB5,
238 U_CJK_UNIFIED_IDEOGRAPHS, wxT("CJK Unified Ideographs Extension A") },
239 { 0x4E00, 0x9FFF,
240 U_CJK_UNIFIED_IDEOGRAPHS, wxT("CJK Unified Ideographs") },
241 { 0xAC00, 0xD7A3,
242 U_HANGUL, wxT("Hangul Syllables") },
243 { 0xE000, 0xF8FF,
244 U_PRIVATE_USE_AREA, wxT("Private Use Area") },
245 { 0xF900, 0xFAFF,
246 U_CJK_COMPATIBILITY_IDEOGRAPHS, wxT("CJK Compatibility Ideographs") },
247 { 0xFB00, 0xFB4F,
248 U_ALPHABETIC_PRESENTATION_FORMS, wxT("Alphabetic Presentation Forms") },
249 { 0xFB50, 0xFDFF,
250 U_ARABIC_PRESENTATION_FORMS_A, wxT("Arabic Presentation Forms-A") },
251 { 0xFE20, 0xFE2F,
252 U_COMBINING_HALF_MARKS, wxT("Combining Half Marks") },
253 { 0xFE30, 0xFE4F,
254 U_CJK_COMPATIBILITY_FORMS, wxT("CJK Compatibility Forms") },
255 { 0xFE50, 0xFE6F,
256 U_SMALL_FORM_VARIANTS, wxT("Small Form Variants") },
257 { 0xFE70, 0xFEFE,
258 U_ARABIC_PRESENTATION_FORMS_B, wxT("Arabic Presentation Forms-B") },
259 { 0xFEFF, 0xFEFF,
260 U_SPECIALS, wxT("Specials") },
261 { 0xFF00, 0xFFEF,
262 U_HALFWIDTH_AND_FULLWIDTH_FORMS, wxT("Halfwidth and Fullwidth Forms") },
263 { 0xFFF0, 0xFFFD,
264 U_SPECIALS, wxT("Specials") }
265 };
266
267 #endif // __UNICODE__
268
269 #if 0
270 // Not yet used, but could be used to test under Win32 whether this subset is available
271 // for the given font. The Win32 function is allegedly not accurate, however.
272 bool wxSubsetValidForFont(int subsetIndex, FONTSIGNATURE *fontSig)
273 {
274 return (fontSig->fsUsb[g_UnicodeSubsetTable[subsetIndex].m_subset/32] & (1 << (g_UnicodeSubsetTable[subsetIndex].m_subset % 32)));
275 }
276 #endif
277
278 /*!
279 * wxSymbolPickerDialog type definition
280 */
281
282 IMPLEMENT_DYNAMIC_CLASS( wxSymbolPickerDialog, wxDialog )
283
284 /*!
285 * wxSymbolPickerDialog event table definition
286 */
287
288 BEGIN_EVENT_TABLE( wxSymbolPickerDialog, wxDialog )
289 EVT_LISTBOX(ID_SYMBOLPICKERDIALOG_LISTCTRL, wxSymbolPickerDialog::OnSymbolSelected)
290
291 ////@begin wxSymbolPickerDialog event table entries
292 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FONT, wxSymbolPickerDialog::OnFontCtrlSelected )
293
294 #if defined(__UNICODE__)
295 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_SUBSET, wxSymbolPickerDialog::OnSubsetSelected )
296 #endif
297
298 #if defined(__UNICODE__)
299 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FROM, wxSymbolPickerDialog::OnFromUnicodeSelected )
300 #endif
301
302 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXOS2__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
303 EVT_UPDATE_UI( wxID_OK, wxSymbolPickerDialog::OnOkUpdate )
304 #endif
305
306 #if defined(__WXMAC__)
307 EVT_UPDATE_UI( wxID_OK, wxSymbolPickerDialog::OnOkUpdate )
308 #endif
309
310 ////@end wxSymbolPickerDialog event table entries
311
312 END_EVENT_TABLE()
313
314 /*!
315 * wxSymbolPickerDialog constructors
316 */
317
318 wxSymbolPickerDialog::wxSymbolPickerDialog( )
319 {
320 Init();
321 }
322
323 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 )
324 {
325 Init();
326 Create(symbol, fontName, normalTextFont, parent, id, caption, pos, size, style);
327 }
328
329 /*!
330 * wxSymbolPickerDialog creator
331 */
332
333 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 )
334 {
335 m_fontName = fontName;
336 m_normalTextFontName = normalTextFont;
337 m_symbol = symbol;
338
339 ////@begin wxSymbolPickerDialog creation
340 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP);
341 wxDialog::Create( parent, id, caption, pos, size, style );
342
343 CreateControls();
344 if (GetSizer())
345 {
346 GetSizer()->SetSizeHints(this);
347 }
348 Centre();
349 ////@end wxSymbolPickerDialog creation
350 return true;
351 }
352
353 /*!
354 * Member initialisation for wxSymbolPickerDialog
355 */
356
357 void wxSymbolPickerDialog::Init()
358 {
359 ////@begin wxSymbolPickerDialog member initialisation
360 m_fromUnicode = true;
361 m_fontCtrl = NULL;
362 #if defined(__UNICODE__)
363 m_subsetCtrl = NULL;
364 #endif
365 m_symbolsCtrl = NULL;
366 m_symbolStaticCtrl = NULL;
367 m_characterCodeCtrl = NULL;
368 #if defined(__UNICODE__)
369 m_fromUnicodeCtrl = NULL;
370 #endif
371 ////@end wxSymbolPickerDialog member initialisation
372 m_dontUpdate = false;
373 }
374
375 /*!
376 * Control creation for wxSymbolPickerDialog
377 */
378
379 void wxSymbolPickerDialog::CreateControls()
380 {
381 ////@begin wxSymbolPickerDialog content construction
382 wxSymbolPickerDialog* itemDialog1 = this;
383
384 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
385 itemDialog1->SetSizer(itemBoxSizer2);
386
387 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
388 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
389
390 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
391 itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5);
392
393 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
394 itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5);
395
396 wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 );
397 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
398
399 wxString* m_fontCtrlStrings = NULL;
400 m_fontCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_FONT, _T(""), wxDefaultPosition, wxSize(240, -1), 0, m_fontCtrlStrings, wxCB_READONLY );
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|wxADJUST_MINSIZE, 5);
408
409 #endif
410
411 #if defined(__UNICODE__)
412 wxString* m_subsetCtrlStrings = NULL;
413 m_subsetCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_SUBSET, _T(""), 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|wxADJUST_MINSIZE, 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|wxADJUST_MINSIZE, 5);
434
435 m_characterCodeCtrl = new wxTextCtrl( itemDialog1, ID_SYMBOLPICKERDIALOG_CHARACTERCODE, _T(""), wxDefaultPosition, wxSize(140, -1), wxTE_READONLY|wxTE_CENTRE );
436 itemBoxSizer12->Add(m_characterCodeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
437
438 itemBoxSizer12->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
439
440 #if defined(__UNICODE__)
441 wxStaticText* itemStaticText18 = new wxStaticText( itemDialog1, wxID_STATIC, _("&From:"), wxDefaultPosition, wxDefaultSize, 0 );
442 itemBoxSizer12->Add(itemStaticText18, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
443
444 #endif
445
446 #if defined(__UNICODE__)
447 wxString m_fromUnicodeCtrlStrings[] = {
448 _("ASCII"),
449 _("Unicode")
450 };
451 m_fromUnicodeCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_FROM, _("ASCII"), wxDefaultPosition, wxDefaultSize, 2, m_fromUnicodeCtrlStrings, wxCB_READONLY );
452 m_fromUnicodeCtrl->SetStringSelection(_("ASCII"));
453 itemBoxSizer12->Add(m_fromUnicodeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
454
455 #endif
456
457 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXOS2__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
458 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxHORIZONTAL);
459 itemBoxSizer3->Add(itemBoxSizer20, 0, wxGROW, 5);
460
461 itemBoxSizer20->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
462
463 wxButton* itemButton22 = new wxButton( itemDialog1, wxID_OK, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 );
464 itemButton22->SetDefault();
465 itemButton22->SetHelpText(_("Inserts the chosen symbol."));
466 if (ShowToolTips())
467 itemButton22->SetToolTip(_("Inserts the chosen symbol."));
468 itemBoxSizer20->Add(itemButton22, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
469
470 wxButton* itemButton23 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
471 itemButton23->SetHelpText(_("Closes the dialog without inserting a symbol."));
472 if (ShowToolTips())
473 itemButton23->SetToolTip(_("Closes the dialog without inserting a symbol."));
474 itemBoxSizer20->Add(itemButton23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
475
476 #endif
477
478 #if defined(__WXMAC__)
479 wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxHORIZONTAL);
480 itemBoxSizer3->Add(itemBoxSizer24, 0, wxGROW, 5);
481
482 itemBoxSizer24->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
483
484 wxButton* itemButton26 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
485 itemButton26->SetHelpText(_("Closes the dialog without inserting a symbol."));
486 if (ShowToolTips())
487 itemButton26->SetToolTip(_("Closes the dialog without inserting a symbol."));
488 itemBoxSizer24->Add(itemButton26, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
489
490 wxButton* itemButton27 = new wxButton( itemDialog1, wxID_OK, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 );
491 itemButton27->SetDefault();
492 itemButton27->SetHelpText(_("Inserts the chosen symbol."));
493 if (ShowToolTips())
494 itemButton27->SetToolTip(_("Inserts the chosen symbol."));
495 itemBoxSizer24->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
496
497 #endif
498
499 ////@end wxSymbolPickerDialog content construction
500
501 }
502
503 /// Data transfer
504 bool wxSymbolPickerDialog::TransferDataToWindow()
505 {
506 m_dontUpdate = true;
507
508 if (m_fontCtrl->GetCount() == 0)
509 {
510 wxArrayString faceNames = wxFontEnumerator::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 ( unsigned(lineNo) == GetLastVisibleLine() &&
857 ScrollToLine(GetVisibleBegin()+1) )
858 ;
859
860 // but in any case refresh it as even if it was only partly visible
861 // before we need to redraw it entirely as its background changed
862 RefreshLine(lineNo);
863 }
864 }
865
866 return true;
867 }
868
869 void wxSymbolListCtrl::SendSelectedEvent()
870 {
871 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, GetId());
872 event.SetEventObject(this);
873 event.SetInt(m_current);
874
875 (void)GetEventHandler()->ProcessEvent(event);
876 }
877
878 void wxSymbolListCtrl::SetSelection(int selection)
879 {
880 wxCHECK_RET( selection == wxNOT_FOUND ||
881 (selection >= m_minSymbolValue && selection < m_maxSymbolValue),
882 _T("wxSymbolListCtrl::SetSelection(): invalid symbol value") );
883
884 DoSetCurrent(selection);
885 }
886
887 // ----------------------------------------------------------------------------
888 // wxSymbolListCtrl appearance parameters
889 // ----------------------------------------------------------------------------
890
891 void wxSymbolListCtrl::SetMargins(const wxPoint& pt)
892 {
893 if ( pt != m_ptMargins )
894 {
895 m_ptMargins = pt;
896
897 Refresh();
898 }
899 }
900
901 void wxSymbolListCtrl::SetSelectionBackground(const wxColour& col)
902 {
903 m_colBgSel = col;
904 }
905
906 // ----------------------------------------------------------------------------
907 // wxSymbolListCtrl painting
908 // ----------------------------------------------------------------------------
909
910 wxCoord wxSymbolListCtrl::OnGetLineHeight(size_t WXUNUSED(line)) const
911 {
912 return m_cellSize.y + 2*m_ptMargins.y + 1 /* for divider */ ;
913 }
914
915 // draws a line of symbols
916 void wxSymbolListCtrl::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
917 {
918 wxColour oldTextColour = dc.GetTextForeground();
919 int startSymbol = n*m_symbolsPerLine;
920
921 int i;
922 for (i = 0; i < m_symbolsPerLine; i++)
923 {
924 bool resetColour = false;
925 int symbol = startSymbol+i;
926 if (symbol == m_current)
927 {
928 dc.SetBrush(wxBrush(m_colBgSel));
929
930 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
931 resetColour = true;
932
933 wxPen oldPen = dc.GetPen();
934 dc.SetPen(*wxTRANSPARENT_PEN);
935
936 dc.DrawRectangle(rect.x + i*m_cellSize.x, rect.y, m_cellSize.x, rect.y+rect.height);
937 dc.SetPen(oldPen);
938 }
939
940 // Don't draw first line
941 if (i != 0)
942 dc.DrawLine(rect.x + i*m_cellSize.x, rect.y, i*m_cellSize.x, rect.y+rect.height);
943
944 if (symbol >= m_minSymbolValue && symbol <= m_maxSymbolValue)
945 {
946 wxString text;
947 text << (wxChar) symbol;
948
949 wxCoord w, h;
950 dc.GetTextExtent(text, & w, & h);
951
952 int x = rect.x + i*m_cellSize.x + (m_cellSize.x - w)/2;
953 int y = rect.y + (m_cellSize.y - h)/2;
954 dc.DrawText(text, x, y);
955 }
956
957 if (resetColour)
958 dc.SetTextForeground(oldTextColour);
959 }
960
961 // Draw horizontal separator line
962 dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1);
963 }
964
965 void wxSymbolListCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
966 {
967 // If size is larger, recalculate double buffer bitmap
968 wxSize clientSize = GetClientSize();
969
970 if ( !m_doubleBuffer ||
971 clientSize.x > m_doubleBuffer->GetWidth() ||
972 clientSize.y > m_doubleBuffer->GetHeight() )
973 {
974 delete m_doubleBuffer;
975 m_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
976 }
977
978 wxBufferedPaintDC dc(this,*m_doubleBuffer);
979
980 // the update rectangle
981 wxRect rectUpdate = GetUpdateClientRect();
982
983 // fill it with background colour
984 dc.SetBackground(GetBackgroundColour());
985 dc.Clear();
986
987 // set the font to be displayed
988 dc.SetFont(GetFont());
989
990 // the bounding rectangle of the current line
991 wxRect rectLine;
992 rectLine.width = clientSize.x;
993
994 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
995 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
996 dc.SetBackgroundMode(wxTRANSPARENT);
997
998 // iterate over all visible lines
999 const size_t lineMax = GetVisibleEnd();
1000 for ( size_t line = GetFirstVisibleLine(); line < lineMax; line++ )
1001 {
1002 const wxCoord hLine = OnGetLineHeight(line);
1003
1004 rectLine.height = hLine;
1005
1006 // and draw the ones which intersect the update rect
1007 if ( rectLine.Intersects(rectUpdate) )
1008 {
1009 // don't allow drawing outside of the lines rectangle
1010 wxDCClipper clip(dc, rectLine);
1011
1012 wxRect rect = rectLine;
1013 rect.Deflate(m_ptMargins.x, m_ptMargins.y);
1014 OnDrawItem(dc, rect, line);
1015 }
1016 else // no intersection
1017 {
1018 if ( rectLine.GetTop() > rectUpdate.GetBottom() )
1019 {
1020 // we are already below the update rect, no need to continue
1021 // further
1022 break;
1023 }
1024 //else: the next line may intersect the update rect
1025 }
1026
1027 rectLine.y += hLine;
1028 }
1029 }
1030
1031 // ============================================================================
1032 // wxSymbolListCtrl keyboard/mouse handling
1033 // ============================================================================
1034
1035 void wxSymbolListCtrl::DoHandleItemClick(int item, int WXUNUSED(flags))
1036 {
1037 if (m_current != item)
1038 {
1039 m_current = item;
1040 Refresh();
1041 SendSelectedEvent();
1042 }
1043 }
1044
1045 // ----------------------------------------------------------------------------
1046 // keyboard handling
1047 // ----------------------------------------------------------------------------
1048
1049 void wxSymbolListCtrl::OnKeyDown(wxKeyEvent& event)
1050 {
1051 // No keyboard interface for now
1052 event.Skip();
1053 #if 0
1054 // flags for DoHandleItemClick()
1055 int flags = ItemClick_Kbd;
1056
1057 int currentLineNow = SymbolValueToLineNumber(m_current);
1058
1059 int currentLine;
1060 switch ( event.GetKeyCode() )
1061 {
1062 case WXK_HOME:
1063 currentLine = 0;
1064 break;
1065
1066 case WXK_END:
1067 currentLine = GetLineCount() - 1;
1068 break;
1069
1070 case WXK_DOWN:
1071 if ( currentLineNow == (int)GetLineCount() - 1 )
1072 return;
1073
1074 currentLine = currentLineNow + 1;
1075 break;
1076
1077 case WXK_UP:
1078 if ( m_current == wxNOT_FOUND )
1079 currentLine = GetLineCount() - 1;
1080 else if ( currentLineNow != 0 )
1081 currentLine = currentLineNow - 1;
1082 else // currentLineNow == 0
1083 return;
1084 break;
1085
1086 case WXK_PAGEDOWN:
1087 PageDown();
1088 currentLine = GetFirstVisibleLine();
1089 break;
1090
1091 case WXK_PAGEUP:
1092 if ( currentLineNow == (int)GetFirstVisibleLine() )
1093 {
1094 PageUp();
1095 }
1096
1097 currentLine = GetFirstVisibleLine();
1098 break;
1099
1100 case WXK_SPACE:
1101 // hack: pressing space should work like a mouse click rather than
1102 // like a keyboard arrow press, so trick DoHandleItemClick() in
1103 // thinking we were clicked
1104 flags &= ~ItemClick_Kbd;
1105 currentLine = currentLineNow;
1106 break;
1107
1108 #ifdef __WXMSW__
1109 case WXK_TAB:
1110 // Since we are using wxWANTS_CHARS we need to send navigation
1111 // events for the tabs on MSW
1112 {
1113 wxNavigationKeyEvent ne;
1114 ne.SetDirection(!event.ShiftDown());
1115 ne.SetCurrentFocus(this);
1116 ne.SetEventObject(this);
1117 GetParent()->GetEventHandler()->ProcessEvent(ne);
1118 }
1119 // fall through to default
1120 #endif
1121 default:
1122 event.Skip();
1123 currentLine = 0; // just to silent the stupid compiler warnings
1124 wxUnusedVar(currentNow);
1125 return;
1126 }
1127
1128 #if 0
1129 if ( event.ShiftDown() )
1130 flags |= ItemClick_Shift;
1131 if ( event.ControlDown() )
1132 flags |= ItemClick_Ctrl;
1133
1134 DoHandleItemClick(current, flags);
1135 #endif
1136 #endif
1137 }
1138
1139 // ----------------------------------------------------------------------------
1140 // wxSymbolListCtrl mouse handling
1141 // ----------------------------------------------------------------------------
1142
1143 void wxSymbolListCtrl::OnLeftDown(wxMouseEvent& event)
1144 {
1145 SetFocus();
1146
1147 int item = HitTest(event.GetPosition());
1148
1149 if ( item != wxNOT_FOUND )
1150 {
1151 int flags = 0;
1152 if ( event.ShiftDown() )
1153 flags |= ItemClick_Shift;
1154
1155 // under Mac Apple-click is used in the same way as Ctrl-click
1156 // elsewhere
1157 #ifdef __WXMAC__
1158 if ( event.MetaDown() )
1159 #else
1160 if ( event.ControlDown() )
1161 #endif
1162 flags |= ItemClick_Ctrl;
1163
1164 DoHandleItemClick(item, flags);
1165 }
1166 }
1167
1168 void wxSymbolListCtrl::OnLeftDClick(wxMouseEvent& eventMouse)
1169 {
1170 int item = HitTest(eventMouse.GetPosition());
1171 if ( item != wxNOT_FOUND )
1172 {
1173
1174 // if item double-clicked was not yet selected, then treat
1175 // this event as a left-click instead
1176 if ( item == m_current )
1177 {
1178 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, GetId());
1179 event.SetEventObject(this);
1180 event.SetInt(item);
1181
1182 (void)GetEventHandler()->ProcessEvent(event);
1183 }
1184 else
1185 {
1186 OnLeftDown(eventMouse);
1187 }
1188
1189 }
1190 }
1191
1192 // calculate line number from symbol value
1193 int wxSymbolListCtrl::SymbolValueToLineNumber(int item)
1194 {
1195 return (int) (item/m_symbolsPerLine);
1196 }
1197
1198 // initialise control from current min/max values
1199 void wxSymbolListCtrl::SetupCtrl(bool scrollToSelection)
1200 {
1201 wxSize sz = GetClientSize();
1202
1203 m_symbolsPerLine = sz.x/(m_cellSize.x+m_ptMargins.x);
1204 int noLines = (1 + SymbolValueToLineNumber(m_maxSymbolValue));
1205
1206 SetLineCount(noLines);
1207 Refresh();
1208
1209 if (scrollToSelection && m_current != wxNOT_FOUND && m_current >= m_minSymbolValue && m_current <= m_maxSymbolValue)
1210 {
1211 ScrollToLine(SymbolValueToLineNumber(m_current));
1212 }
1213 }
1214
1215 // make this item visible
1216 void wxSymbolListCtrl::EnsureVisible(int item)
1217 {
1218 if (item != wxNOT_FOUND && item >= m_minSymbolValue && item <= m_maxSymbolValue)
1219 {
1220 ScrollToLine(SymbolValueToLineNumber(item));
1221 }
1222 }
1223
1224
1225 // hit testing
1226 int wxSymbolListCtrl::HitTest(const wxPoint& pt)
1227 {
1228 wxCoord lineHeight = OnGetLineHeight(0);
1229
1230 int atLine = GetVisibleBegin() + (pt.y/lineHeight);
1231 int symbol = (atLine*m_symbolsPerLine) + (pt.x/(m_cellSize.x+1));
1232
1233 if (symbol >= m_minSymbolValue && symbol <= m_maxSymbolValue)
1234 return symbol;
1235
1236 return -1;
1237 }
1238
1239 // Respond to size change
1240 void wxSymbolListCtrl::OnSize(wxSizeEvent& event)
1241 {
1242 SetupCtrl();
1243 event.Skip();
1244 }
1245
1246 // set the current font
1247 bool wxSymbolListCtrl::SetFont(const wxFont& font)
1248 {
1249 wxVScrolledWindow::SetFont(font);
1250
1251 SetupCtrl();
1252
1253 return true;
1254 }
1255
1256 // set Unicode/ASCII mode
1257 void wxSymbolListCtrl::SetUnicodeMode(bool unicodeMode)
1258 {
1259 bool changed = false;
1260 if (unicodeMode && !m_unicodeMode)
1261 {
1262 changed = true;
1263
1264 m_minSymbolValue = 0;
1265 m_maxSymbolValue = 65535;
1266 }
1267 else if (!unicodeMode && m_unicodeMode)
1268 {
1269 changed = true;
1270 m_minSymbolValue = 0;
1271 m_maxSymbolValue = 255;
1272 }
1273 m_unicodeMode = unicodeMode;
1274
1275 if (changed)
1276 SetupCtrl();
1277 }
1278
1279 // ----------------------------------------------------------------------------
1280 // use the same default attributes as wxListBox
1281 // ----------------------------------------------------------------------------
1282
1283 //static
1284 wxVisualAttributes
1285 wxSymbolListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
1286 {
1287 return wxListBox::GetClassDefaultAttributes(variant);
1288 }
1289
1290 #endif // wxUSE_RICHTEXT