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