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