]>
Commit | Line | Data |
---|---|---|
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 | 33 | #include "wx/dcbuffer.h" |
ebf0a029 | 34 | |
dadd4f55 JS |
35 | // Only for cached font name |
36 | #include "wx/richtext/richtextctrl.h" | |
37 | ||
ebf0a029 JS |
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 */ | |
416f4cd9 | 117 | #ifdef __UNICODE__ |
ebf0a029 JS |
118 | |
119 | static struct | |
120 | { | |
121 | int m_low, m_high; | |
122 | wxUnicodeSubsetCodes m_subset; | |
9a9b00b5 | 123 | const wxChar* m_name; |
ebf0a029 JS |
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 | ||
416f4cd9 VZ |
268 | #endif // __UNICODE__ |
269 | ||
ebf0a029 JS |
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 | ||
dadd4f55 JS |
279 | bool wxSymbolPickerDialog::sm_showToolTips = false; |
280 | ||
ebf0a029 JS |
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 ) | |
ebf0a029 JS |
296 | #if defined(__UNICODE__) |
297 | EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_SUBSET, wxSymbolPickerDialog::OnSubsetSelected ) | |
93023965 | 298 | EVT_UPDATE_UI( ID_SYMBOLPICKERDIALOG_SUBSET, wxSymbolPickerDialog::OnSymbolpickerdialogSubsetUpdate ) |
ebf0a029 JS |
299 | #endif |
300 | ||
301 | #if defined(__UNICODE__) | |
302 | EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FROM, wxSymbolPickerDialog::OnFromUnicodeSelected ) | |
303 | #endif | |
304 | ||
ebf0a029 | 305 | EVT_UPDATE_UI( wxID_OK, wxSymbolPickerDialog::OnOkUpdate ) |
3bb084c4 JS |
306 | EVT_BUTTON( wxID_HELP, wxSymbolPickerDialog::OnHelpClick ) |
307 | EVT_UPDATE_UI( wxID_HELP, wxSymbolPickerDialog::OnHelpUpdate ) | |
ebf0a029 JS |
308 | ////@end wxSymbolPickerDialog event table entries |
309 | ||
310 | END_EVENT_TABLE() | |
311 | ||
603f702b JS |
312 | IMPLEMENT_HELP_PROVISION(wxSymbolPickerDialog) |
313 | ||
ebf0a029 JS |
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 | |
2fce6547 | 340 | SetExtraStyle(wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP); |
ebf0a029 JS |
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 | |
603f702b | 371 | m_stdButtonSizer = NULL; |
ebf0a029 JS |
372 | ////@end wxSymbolPickerDialog member initialisation |
373 | m_dontUpdate = false; | |
374 | } | |
375 | ||
376 | /*! | |
377 | * Control creation for wxSymbolPickerDialog | |
378 | */ | |
379 | ||
380 | void wxSymbolPickerDialog::CreateControls() | |
381 | { | |
2fb1532a JS |
382 | #ifdef __WXMAC__ |
383 | SetWindowVariant(wxWINDOW_VARIANT_SMALL); | |
384 | #endif | |
385 | ||
ebf0a029 JS |
386 | ////@begin wxSymbolPickerDialog content construction |
387 | wxSymbolPickerDialog* itemDialog1 = this; | |
388 | ||
389 | wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); | |
390 | itemDialog1->SetSizer(itemBoxSizer2); | |
391 | ||
392 | wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); | |
393 | itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5); | |
394 | ||
395 | wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL); | |
396 | itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5); | |
397 | ||
398 | wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL); | |
399 | itemBoxSizer4->Add(itemBoxSizer5, 1, wxGROW, 5); | |
400 | ||
401 | wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Font:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 402 | itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
ebf0a029 | 403 | |
2fce6547 | 404 | wxArrayString m_fontCtrlStrings; |
93023965 | 405 | m_fontCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_FONT, wxEmptyString, wxDefaultPosition, wxSize(240, -1), m_fontCtrlStrings, wxCB_READONLY ); |
dadd4f55 | 406 | m_fontCtrl->SetHelpText(_("The font from which to take the symbol.")); |
2fce6547 | 407 | if (wxSymbolPickerDialog::ShowToolTips()) |
dadd4f55 | 408 | m_fontCtrl->SetToolTip(_("The font from which to take the symbol.")); |
ebf0a029 JS |
409 | itemBoxSizer5->Add(m_fontCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
410 | ||
411 | itemBoxSizer5->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
412 | ||
413 | #if defined(__UNICODE__) | |
414 | wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Subset:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 415 | itemBoxSizer5->Add(itemStaticText9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
ebf0a029 JS |
416 | |
417 | #endif | |
418 | ||
419 | #if defined(__UNICODE__) | |
2fce6547 | 420 | wxArrayString m_subsetCtrlStrings; |
93023965 | 421 | m_subsetCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_SUBSET, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_subsetCtrlStrings, wxCB_READONLY ); |
ebf0a029 | 422 | m_subsetCtrl->SetHelpText(_("Shows a Unicode subset.")); |
2fce6547 | 423 | if (wxSymbolPickerDialog::ShowToolTips()) |
ebf0a029 JS |
424 | m_subsetCtrl->SetToolTip(_("Shows a Unicode subset.")); |
425 | itemBoxSizer5->Add(m_subsetCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
426 | ||
427 | #endif | |
428 | ||
2fce6547 | 429 | m_symbolsCtrl = new wxSymbolListCtrl( itemDialog1, ID_SYMBOLPICKERDIALOG_LISTCTRL, wxDefaultPosition, wxSize(500, 200), 0 ); |
ebf0a029 JS |
430 | itemBoxSizer3->Add(m_symbolsCtrl, 1, wxGROW|wxALL, 5); |
431 | ||
432 | wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL); | |
433 | itemBoxSizer3->Add(itemBoxSizer12, 0, wxGROW, 5); | |
434 | ||
dadd4f55 | 435 | m_symbolStaticCtrl = new wxStaticText( itemDialog1, wxID_STATIC, _("xxxx"), wxDefaultPosition, wxSize(40, -1), wxALIGN_CENTRE ); |
69ce77e2 | 436 | itemBoxSizer12->Add(m_symbolStaticCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
ebf0a029 JS |
437 | |
438 | itemBoxSizer12->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
439 | ||
440 | wxStaticText* itemStaticText15 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Character code:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 441 | itemBoxSizer12->Add(itemStaticText15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
ebf0a029 | 442 | |
93023965 | 443 | m_characterCodeCtrl = new wxTextCtrl( itemDialog1, ID_SYMBOLPICKERDIALOG_CHARACTERCODE, wxEmptyString, wxDefaultPosition, wxSize(140, -1), wxTE_READONLY|wxTE_CENTRE ); |
dadd4f55 | 444 | m_characterCodeCtrl->SetHelpText(_("The character code.")); |
2fce6547 | 445 | if (wxSymbolPickerDialog::ShowToolTips()) |
dadd4f55 | 446 | m_characterCodeCtrl->SetToolTip(_("The character code.")); |
ebf0a029 JS |
447 | itemBoxSizer12->Add(m_characterCodeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
448 | ||
449 | itemBoxSizer12->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
450 | ||
451 | #if defined(__UNICODE__) | |
452 | wxStaticText* itemStaticText18 = new wxStaticText( itemDialog1, wxID_STATIC, _("&From:"), wxDefaultPosition, wxDefaultSize, 0 ); | |
69ce77e2 | 453 | itemBoxSizer12->Add(itemStaticText18, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
ebf0a029 JS |
454 | |
455 | #endif | |
456 | ||
457 | #if defined(__UNICODE__) | |
2fce6547 JS |
458 | wxArrayString m_fromUnicodeCtrlStrings; |
459 | m_fromUnicodeCtrlStrings.Add(_("ASCII")); | |
460 | m_fromUnicodeCtrlStrings.Add(_("Unicode")); | |
93023965 JS |
461 | m_fromUnicodeCtrl = new wxComboBox( itemDialog1, ID_SYMBOLPICKERDIALOG_FROM, _("Unicode"), wxDefaultPosition, wxDefaultSize, m_fromUnicodeCtrlStrings, wxCB_READONLY ); |
462 | m_fromUnicodeCtrl->SetStringSelection(_("Unicode")); | |
dadd4f55 | 463 | m_fromUnicodeCtrl->SetHelpText(_("The range to show.")); |
2fce6547 | 464 | if (wxSymbolPickerDialog::ShowToolTips()) |
dadd4f55 | 465 | m_fromUnicodeCtrl->SetToolTip(_("The range to show.")); |
ebf0a029 JS |
466 | itemBoxSizer12->Add(m_fromUnicodeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
467 | ||
468 | #endif | |
469 | ||
603f702b | 470 | m_stdButtonSizer = new wxStdDialogButtonSizer; |
ebf0a029 | 471 | |
603f702b JS |
472 | itemBoxSizer3->Add(m_stdButtonSizer, 0, wxGROW|wxTOP|wxBOTTOM, 5); |
473 | wxButton* itemButton21 = new wxButton( itemDialog1, wxID_OK, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 ); | |
474 | itemButton21->SetDefault(); | |
475 | m_stdButtonSizer->AddButton(itemButton21); | |
ebf0a029 | 476 | |
603f702b JS |
477 | wxButton* itemButton22 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 ); |
478 | m_stdButtonSizer->AddButton(itemButton22); | |
ebf0a029 | 479 | |
603f702b JS |
480 | wxButton* itemButton23 = new wxButton( itemDialog1, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, 0 ); |
481 | m_stdButtonSizer->AddButton(itemButton23); | |
ebf0a029 | 482 | |
603f702b | 483 | m_stdButtonSizer->Realize(); |
ebf0a029 JS |
484 | |
485 | ////@end wxSymbolPickerDialog content construction | |
486 | ||
603f702b JS |
487 | if (GetHelpId() == -1) |
488 | { | |
489 | wxWindow* button = FindWindowById(wxID_HELP); | |
490 | if (button) | |
491 | m_stdButtonSizer->Show(button, false); | |
492 | } | |
ebf0a029 JS |
493 | } |
494 | ||
495 | /// Data transfer | |
496 | bool wxSymbolPickerDialog::TransferDataToWindow() | |
497 | { | |
498 | m_dontUpdate = true; | |
499 | ||
500 | if (m_fontCtrl->GetCount() == 0) | |
501 | { | |
dadd4f55 | 502 | wxArrayString faceNames = wxRichTextCtrl::GetAvailableFontNames(); |
ebf0a029 JS |
503 | faceNames.Sort(); |
504 | ||
505 | faceNames.Insert(_("(Normal text)"), 0); | |
506 | m_fontCtrl->Append(faceNames); | |
507 | } | |
508 | ||
b68603d5 | 509 | if (m_fontName.empty()) |
ebf0a029 JS |
510 | m_fontCtrl->SetSelection(0); |
511 | else | |
512 | { | |
513 | if (m_fontCtrl->FindString(m_fontName) != wxNOT_FOUND) | |
514 | m_fontCtrl->SetStringSelection(m_fontName); | |
515 | else | |
516 | m_fontCtrl->SetSelection(0); | |
517 | } | |
518 | ||
ebf0a029 JS |
519 | #if defined(__UNICODE__) |
520 | if (m_subsetCtrl->GetCount() == 0) | |
521 | { | |
522 | // Insert items into subset combo | |
523 | int i; | |
9611b797 | 524 | for (i = 0; i < (int) WXSIZEOF(g_UnicodeSubsetTable); i++) |
ebf0a029 JS |
525 | { |
526 | m_subsetCtrl->Append(g_UnicodeSubsetTable[i].m_name); | |
527 | } | |
528 | m_subsetCtrl->SetSelection(0); | |
529 | } | |
530 | #endif | |
531 | ||
93023965 JS |
532 | #if defined(__UNICODE__) |
533 | m_symbolsCtrl->SetUnicodeMode(m_fromUnicode); | |
534 | #endif | |
535 | ||
09783f72 JS |
536 | if (!m_symbol.empty()) |
537 | { | |
538 | int sel = (int) m_symbol[0]; | |
539 | m_symbolsCtrl->SetSelection(sel); | |
540 | } | |
541 | ||
f18d5c6f | 542 | UpdateSymbolDisplay(true, m_symbol.empty()); |
ebf0a029 JS |
543 | |
544 | m_dontUpdate = false; | |
545 | ||
546 | return true; | |
547 | } | |
548 | ||
549 | void wxSymbolPickerDialog::UpdateSymbolDisplay(bool updateSymbolList, bool showAtSubset) | |
550 | { | |
551 | wxFont font; | |
552 | wxString fontNameToUse; | |
b68603d5 | 553 | if (m_fontName.empty()) |
ebf0a029 JS |
554 | fontNameToUse = m_normalTextFontName; |
555 | else | |
556 | fontNameToUse = m_fontName; | |
557 | ||
b68603d5 | 558 | if (!fontNameToUse.empty()) |
ebf0a029 JS |
559 | { |
560 | font = wxFont(14, wxDEFAULT, wxNORMAL, wxNORMAL, false, fontNameToUse); | |
561 | } | |
562 | else | |
563 | font = *wxNORMAL_FONT; | |
564 | ||
565 | if (updateSymbolList) | |
566 | { | |
567 | m_symbolsCtrl->SetFont(font); | |
568 | } | |
569 | ||
b68603d5 | 570 | if (!m_symbol.empty()) |
ebf0a029 JS |
571 | { |
572 | m_symbolStaticCtrl->SetFont(font); | |
573 | m_symbolStaticCtrl->SetLabel(m_symbol); | |
574 | ||
575 | int symbol = (int) m_symbol[0]; | |
576 | m_characterCodeCtrl->SetValue(wxString::Format(wxT("%X hex (%d dec)"), symbol, symbol)); | |
577 | } | |
578 | else | |
579 | { | |
580 | m_symbolStaticCtrl->SetLabel(wxEmptyString); | |
581 | m_characterCodeCtrl->SetValue(wxEmptyString); | |
582 | } | |
583 | ||
584 | #if defined(__UNICODE__) | |
585 | if (showAtSubset) | |
586 | ShowAtSubset(); | |
587 | #else | |
588 | wxUnusedVar(showAtSubset); | |
589 | #endif | |
590 | } | |
591 | ||
592 | /// Show at the current subset selection | |
593 | void wxSymbolPickerDialog::ShowAtSubset() | |
594 | { | |
595 | #if defined(__UNICODE__) | |
596 | if (m_fromUnicode) | |
597 | { | |
598 | int sel = m_subsetCtrl->GetSelection(); | |
599 | int low = g_UnicodeSubsetTable[sel].m_low; | |
600 | m_symbolsCtrl->EnsureVisible(low); | |
601 | } | |
602 | #endif | |
603 | } | |
604 | ||
605 | // Handle font selection | |
606 | void wxSymbolPickerDialog::OnFontCtrlSelected( wxCommandEvent& WXUNUSED(event) ) | |
607 | { | |
608 | if (m_fontCtrl->GetSelection() == 0) | |
609 | m_fontName = wxEmptyString; | |
610 | else | |
611 | m_fontName = m_fontCtrl->GetStringSelection(); | |
612 | ||
613 | UpdateSymbolDisplay(); | |
614 | } | |
615 | ||
616 | /// Respond to symbol selection | |
617 | void wxSymbolPickerDialog::OnSymbolSelected( wxCommandEvent& event ) | |
618 | { | |
619 | if (m_dontUpdate) | |
620 | return; | |
621 | ||
622 | int sel = event.GetSelection(); | |
b68603d5 | 623 | if (sel == wxNOT_FOUND) |
ebf0a029 JS |
624 | m_symbol = wxEmptyString; |
625 | else | |
626 | { | |
627 | m_symbol = wxEmptyString; | |
628 | m_symbol << (wxChar) sel; | |
629 | } | |
630 | ||
631 | #if defined(__UNICODE__) | |
632 | if (sel != -1 && m_fromUnicode) | |
633 | { | |
634 | // Need to make the subset selection reflect the current symbol | |
635 | int i; | |
9611b797 | 636 | for (i = 0; i < (int) WXSIZEOF(g_UnicodeSubsetTable); i++) |
ebf0a029 JS |
637 | { |
638 | if (sel >= g_UnicodeSubsetTable[i].m_low && sel <= g_UnicodeSubsetTable[i].m_high) | |
639 | { | |
640 | m_dontUpdate = true; | |
641 | m_subsetCtrl->SetSelection(i); | |
642 | m_dontUpdate = false; | |
643 | break; | |
644 | } | |
645 | } | |
646 | } | |
647 | #endif | |
648 | ||
649 | UpdateSymbolDisplay(false, false); | |
650 | } | |
651 | ||
652 | #if defined(__UNICODE__) | |
653 | // Handle Unicode/ASCII selection | |
654 | void wxSymbolPickerDialog::OnFromUnicodeSelected( wxCommandEvent& WXUNUSED(event) ) | |
655 | { | |
656 | if (m_dontUpdate) | |
657 | return; | |
658 | ||
659 | m_fromUnicode = (m_fromUnicodeCtrl->GetSelection() == 1); | |
660 | m_symbolsCtrl->SetUnicodeMode(m_fromUnicode); | |
661 | UpdateSymbolDisplay(false); | |
662 | } | |
663 | ||
664 | // Handle subset selection | |
665 | void wxSymbolPickerDialog::OnSubsetSelected( wxCommandEvent& WXUNUSED(event) ) | |
666 | { | |
667 | if (m_dontUpdate) | |
668 | return; | |
669 | ||
670 | ShowAtSubset(); | |
671 | } | |
672 | #endif | |
673 | ||
93023965 JS |
674 | #if defined(__UNICODE__) |
675 | ||
676 | /*! | |
677 | * wxEVT_UPDATE_UI event handler for ID_SYMBOLPICKERDIALOG_SUBSET | |
678 | */ | |
679 | ||
680 | void wxSymbolPickerDialog::OnSymbolpickerdialogSubsetUpdate( wxUpdateUIEvent& event ) | |
681 | { | |
682 | event.Enable(m_fromUnicode); | |
683 | } | |
684 | #endif | |
685 | ||
ebf0a029 JS |
686 | /*! |
687 | * wxEVT_UPDATE_UI event handler for wxID_OK | |
688 | */ | |
689 | ||
690 | void wxSymbolPickerDialog::OnOkUpdate( wxUpdateUIEvent& event ) | |
691 | { | |
692 | event.Enable(HasSelection()); | |
693 | } | |
694 | ||
695 | /// Set Unicode mode | |
696 | void wxSymbolPickerDialog::SetUnicodeMode(bool unicodeMode) | |
697 | { | |
698 | #if defined(__UNICODE__) | |
699 | m_dontUpdate = true; | |
700 | m_fromUnicode = unicodeMode; | |
701 | if (m_fromUnicodeCtrl) | |
702 | m_fromUnicodeCtrl->SetSelection(m_fromUnicode ? 1 : 0); | |
703 | UpdateSymbolDisplay(); | |
704 | m_dontUpdate = false; | |
705 | #else | |
706 | wxUnusedVar(unicodeMode); | |
707 | #endif | |
708 | } | |
709 | ||
710 | /// Get the selected symbol character | |
711 | int wxSymbolPickerDialog::GetSymbolChar() const | |
712 | { | |
b68603d5 | 713 | if (m_symbol.empty()) |
ebf0a029 JS |
714 | return -1; |
715 | else | |
716 | return (int) m_symbol[0]; | |
717 | } | |
718 | ||
719 | ||
ebf0a029 JS |
720 | /*! |
721 | * Get bitmap resources | |
722 | */ | |
723 | ||
724 | wxBitmap wxSymbolPickerDialog::GetBitmapResource( const wxString& name ) | |
725 | { | |
726 | // Bitmap retrieval | |
727 | ////@begin wxSymbolPickerDialog bitmap retrieval | |
728 | wxUnusedVar(name); | |
729 | return wxNullBitmap; | |
730 | ////@end wxSymbolPickerDialog bitmap retrieval | |
731 | } | |
732 | ||
733 | /*! | |
734 | * Get icon resources | |
735 | */ | |
736 | ||
737 | wxIcon wxSymbolPickerDialog::GetIconResource( const wxString& name ) | |
738 | { | |
739 | // Icon retrieval | |
740 | ////@begin wxSymbolPickerDialog icon retrieval | |
741 | wxUnusedVar(name); | |
742 | return wxNullIcon; | |
743 | ////@end wxSymbolPickerDialog icon retrieval | |
744 | } | |
745 | ||
746 | /*! | |
747 | * The scrolling symbol list. | |
748 | */ | |
749 | ||
750 | // ---------------------------------------------------------------------------- | |
751 | // event tables | |
752 | // ---------------------------------------------------------------------------- | |
753 | ||
754 | BEGIN_EVENT_TABLE(wxSymbolListCtrl, wxVScrolledWindow) | |
755 | EVT_PAINT(wxSymbolListCtrl::OnPaint) | |
756 | EVT_SIZE(wxSymbolListCtrl::OnSize) | |
757 | ||
758 | EVT_KEY_DOWN(wxSymbolListCtrl::OnKeyDown) | |
759 | EVT_LEFT_DOWN(wxSymbolListCtrl::OnLeftDown) | |
760 | EVT_LEFT_DCLICK(wxSymbolListCtrl::OnLeftDClick) | |
761 | END_EVENT_TABLE() | |
762 | ||
763 | // ============================================================================ | |
764 | // implementation | |
765 | // ============================================================================ | |
766 | ||
767 | IMPLEMENT_ABSTRACT_CLASS(wxSymbolListCtrl, wxVScrolledWindow) | |
768 | ||
769 | // ---------------------------------------------------------------------------- | |
770 | // wxSymbolListCtrl creation | |
771 | // ---------------------------------------------------------------------------- | |
772 | ||
773 | void wxSymbolListCtrl::Init() | |
774 | { | |
775 | m_current = wxNOT_FOUND; | |
776 | m_doubleBuffer = NULL; | |
777 | m_cellSize = wxSize(40, 40); | |
778 | m_minSymbolValue = 0; | |
779 | m_maxSymbolValue = 255; | |
780 | m_symbolsPerLine = 0; | |
781 | m_unicodeMode = false; | |
782 | } | |
783 | ||
784 | bool wxSymbolListCtrl::Create(wxWindow *parent, | |
785 | wxWindowID id, | |
786 | const wxPoint& pos, | |
787 | const wxSize& size, | |
788 | long style, | |
789 | const wxString& name) | |
790 | { | |
791 | style |= wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE; | |
2fce6547 JS |
792 | |
793 | if ((style & wxBORDER_MASK) == wxBORDER_DEFAULT) | |
794 | style |= wxBORDER_THEME; | |
795 | ||
ebf0a029 JS |
796 | if ( !wxVScrolledWindow::Create(parent, id, pos, size, style, name) ) |
797 | return false; | |
798 | ||
799 | // make sure the native widget has the right colour since we do | |
800 | // transparent drawing by default | |
801 | SetBackgroundColour(GetBackgroundColour()); | |
802 | m_colBgSel = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); | |
803 | ||
804 | // flicker-free drawing requires this | |
805 | SetBackgroundStyle(wxBG_STYLE_CUSTOM); | |
806 | ||
807 | SetFont(*wxNORMAL_FONT); | |
808 | ||
809 | SetupCtrl(); | |
810 | ||
93023965 JS |
811 | SetInitialSize(size); |
812 | ||
ebf0a029 JS |
813 | return true; |
814 | } | |
815 | ||
816 | wxSymbolListCtrl::~wxSymbolListCtrl() | |
817 | { | |
818 | delete m_doubleBuffer; | |
819 | } | |
820 | ||
821 | // ---------------------------------------------------------------------------- | |
822 | // selection handling | |
823 | // ---------------------------------------------------------------------------- | |
824 | ||
825 | bool wxSymbolListCtrl::IsSelected(int item) const | |
826 | { | |
827 | return item == m_current; | |
828 | } | |
829 | ||
830 | bool wxSymbolListCtrl::DoSetCurrent(int current) | |
831 | { | |
832 | wxASSERT_MSG( current == wxNOT_FOUND || | |
833 | (current >= m_minSymbolValue && current <= m_maxSymbolValue), | |
9a83f860 | 834 | wxT("wxSymbolListCtrl::DoSetCurrent(): invalid symbol value") ); |
ebf0a029 JS |
835 | |
836 | if ( current == m_current ) | |
837 | { | |
838 | // nothing to do | |
839 | return false; | |
840 | } | |
841 | ||
842 | if ( m_current != wxNOT_FOUND ) | |
f18eaf26 | 843 | RefreshRow(SymbolValueToLineNumber(m_current)); |
ebf0a029 JS |
844 | |
845 | m_current = current; | |
846 | ||
847 | if ( m_current != wxNOT_FOUND ) | |
848 | { | |
849 | int lineNo = SymbolValueToLineNumber(m_current); | |
850 | ||
851 | // if the line is not visible at all, we scroll it into view but we | |
852 | // don't need to refresh it -- it will be redrawn anyhow | |
853 | if ( !IsVisible(lineNo) ) | |
854 | { | |
f18eaf26 | 855 | ScrollToRow(lineNo); |
ebf0a029 JS |
856 | } |
857 | else // line is at least partly visible | |
858 | { | |
859 | // it is, indeed, only partly visible, so scroll it into view to | |
860 | // make it entirely visible | |
e02c72fa VZ |
861 | while ( (unsigned)lineNo + 1 == GetVisibleEnd() && |
862 | ScrollToRow(GetVisibleBegin() + 1) ) | |
07854e5e | 863 | ; |
ebf0a029 JS |
864 | |
865 | // but in any case refresh it as even if it was only partly visible | |
866 | // before we need to redraw it entirely as its background changed | |
f18eaf26 | 867 | RefreshRow(lineNo); |
ebf0a029 JS |
868 | } |
869 | } | |
870 | ||
871 | return true; | |
872 | } | |
873 | ||
874 | void wxSymbolListCtrl::SendSelectedEvent() | |
875 | { | |
876 | wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, GetId()); | |
877 | event.SetEventObject(this); | |
878 | event.SetInt(m_current); | |
879 | ||
880 | (void)GetEventHandler()->ProcessEvent(event); | |
881 | } | |
882 | ||
883 | void wxSymbolListCtrl::SetSelection(int selection) | |
884 | { | |
885 | wxCHECK_RET( selection == wxNOT_FOUND || | |
886 | (selection >= m_minSymbolValue && selection < m_maxSymbolValue), | |
9a83f860 | 887 | wxT("wxSymbolListCtrl::SetSelection(): invalid symbol value") ); |
ebf0a029 JS |
888 | |
889 | DoSetCurrent(selection); | |
890 | } | |
891 | ||
892 | // ---------------------------------------------------------------------------- | |
893 | // wxSymbolListCtrl appearance parameters | |
894 | // ---------------------------------------------------------------------------- | |
895 | ||
896 | void wxSymbolListCtrl::SetMargins(const wxPoint& pt) | |
897 | { | |
898 | if ( pt != m_ptMargins ) | |
899 | { | |
900 | m_ptMargins = pt; | |
901 | ||
902 | Refresh(); | |
903 | } | |
904 | } | |
905 | ||
906 | void wxSymbolListCtrl::SetSelectionBackground(const wxColour& col) | |
907 | { | |
908 | m_colBgSel = col; | |
909 | } | |
910 | ||
911 | // ---------------------------------------------------------------------------- | |
912 | // wxSymbolListCtrl painting | |
913 | // ---------------------------------------------------------------------------- | |
914 | ||
e02c72fa | 915 | wxCoord wxSymbolListCtrl::OnGetRowHeight(size_t WXUNUSED(line)) const |
ebf0a029 JS |
916 | { |
917 | return m_cellSize.y + 2*m_ptMargins.y + 1 /* for divider */ ; | |
918 | } | |
919 | ||
920 | // draws a line of symbols | |
921 | void wxSymbolListCtrl::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const | |
922 | { | |
923 | wxColour oldTextColour = dc.GetTextForeground(); | |
924 | int startSymbol = n*m_symbolsPerLine; | |
925 | ||
926 | int i; | |
927 | for (i = 0; i < m_symbolsPerLine; i++) | |
928 | { | |
929 | bool resetColour = false; | |
930 | int symbol = startSymbol+i; | |
931 | if (symbol == m_current) | |
932 | { | |
933 | dc.SetBrush(wxBrush(m_colBgSel)); | |
934 | ||
935 | dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT)); | |
936 | resetColour = true; | |
937 | ||
938 | wxPen oldPen = dc.GetPen(); | |
939 | dc.SetPen(*wxTRANSPARENT_PEN); | |
940 | ||
941 | dc.DrawRectangle(rect.x + i*m_cellSize.x, rect.y, m_cellSize.x, rect.y+rect.height); | |
942 | dc.SetPen(oldPen); | |
943 | } | |
944 | ||
945 | // Don't draw first line | |
946 | if (i != 0) | |
947 | dc.DrawLine(rect.x + i*m_cellSize.x, rect.y, i*m_cellSize.x, rect.y+rect.height); | |
948 | ||
949 | if (symbol >= m_minSymbolValue && symbol <= m_maxSymbolValue) | |
950 | { | |
951 | wxString text; | |
952 | text << (wxChar) symbol; | |
953 | ||
954 | wxCoord w, h; | |
955 | dc.GetTextExtent(text, & w, & h); | |
956 | ||
957 | int x = rect.x + i*m_cellSize.x + (m_cellSize.x - w)/2; | |
958 | int y = rect.y + (m_cellSize.y - h)/2; | |
959 | dc.DrawText(text, x, y); | |
960 | } | |
961 | ||
962 | if (resetColour) | |
963 | dc.SetTextForeground(oldTextColour); | |
964 | } | |
965 | ||
966 | // Draw horizontal separator line | |
967 | dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1); | |
968 | } | |
969 | ||
970 | void wxSymbolListCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
971 | { | |
972 | // If size is larger, recalculate double buffer bitmap | |
973 | wxSize clientSize = GetClientSize(); | |
974 | ||
975 | if ( !m_doubleBuffer || | |
976 | clientSize.x > m_doubleBuffer->GetWidth() || | |
977 | clientSize.y > m_doubleBuffer->GetHeight() ) | |
978 | { | |
979 | delete m_doubleBuffer; | |
980 | m_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25); | |
981 | } | |
982 | ||
983 | wxBufferedPaintDC dc(this,*m_doubleBuffer); | |
984 | ||
985 | // the update rectangle | |
986 | wxRect rectUpdate = GetUpdateClientRect(); | |
987 | ||
988 | // fill it with background colour | |
989 | dc.SetBackground(GetBackgroundColour()); | |
990 | dc.Clear(); | |
991 | ||
992 | // set the font to be displayed | |
993 | dc.SetFont(GetFont()); | |
994 | ||
995 | // the bounding rectangle of the current line | |
e02c72fa VZ |
996 | wxRect rectRow; |
997 | rectRow.width = clientSize.x; | |
ebf0a029 JS |
998 | |
999 | dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT))); | |
1000 | dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); | |
04ee05f9 | 1001 | dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
ebf0a029 JS |
1002 | |
1003 | // iterate over all visible lines | |
1004 | const size_t lineMax = GetVisibleEnd(); | |
e02c72fa | 1005 | for ( size_t line = GetVisibleBegin(); line < lineMax; line++ ) |
ebf0a029 | 1006 | { |
e02c72fa | 1007 | const wxCoord hRow = OnGetRowHeight(line); |
ebf0a029 | 1008 | |
e02c72fa | 1009 | rectRow.height = hRow; |
ebf0a029 JS |
1010 | |
1011 | // and draw the ones which intersect the update rect | |
e02c72fa | 1012 | if ( rectRow.Intersects(rectUpdate) ) |
ebf0a029 JS |
1013 | { |
1014 | // don't allow drawing outside of the lines rectangle | |
e02c72fa | 1015 | wxDCClipper clip(dc, rectRow); |
ebf0a029 | 1016 | |
e02c72fa | 1017 | wxRect rect = rectRow; |
ebf0a029 JS |
1018 | rect.Deflate(m_ptMargins.x, m_ptMargins.y); |
1019 | OnDrawItem(dc, rect, line); | |
1020 | } | |
1021 | else // no intersection | |
1022 | { | |
e02c72fa | 1023 | if ( rectRow.GetTop() > rectUpdate.GetBottom() ) |
ebf0a029 JS |
1024 | { |
1025 | // we are already below the update rect, no need to continue | |
1026 | // further | |
1027 | break; | |
1028 | } | |
1029 | //else: the next line may intersect the update rect | |
1030 | } | |
1031 | ||
e02c72fa | 1032 | rectRow.y += hRow; |
ebf0a029 JS |
1033 | } |
1034 | } | |
1035 | ||
1036 | // ============================================================================ | |
1037 | // wxSymbolListCtrl keyboard/mouse handling | |
1038 | // ============================================================================ | |
1039 | ||
1040 | void wxSymbolListCtrl::DoHandleItemClick(int item, int WXUNUSED(flags)) | |
1041 | { | |
1042 | if (m_current != item) | |
1043 | { | |
1044 | m_current = item; | |
1045 | Refresh(); | |
1046 | SendSelectedEvent(); | |
1047 | } | |
1048 | } | |
1049 | ||
1050 | // ---------------------------------------------------------------------------- | |
1051 | // keyboard handling | |
1052 | // ---------------------------------------------------------------------------- | |
1053 | ||
1054 | void wxSymbolListCtrl::OnKeyDown(wxKeyEvent& event) | |
1055 | { | |
1056 | // No keyboard interface for now | |
1057 | event.Skip(); | |
1058 | #if 0 | |
1059 | // flags for DoHandleItemClick() | |
1060 | int flags = ItemClick_Kbd; | |
1061 | ||
1062 | int currentLineNow = SymbolValueToLineNumber(m_current); | |
1063 | ||
1064 | int currentLine; | |
1065 | switch ( event.GetKeyCode() ) | |
1066 | { | |
1067 | case WXK_HOME: | |
1068 | currentLine = 0; | |
1069 | break; | |
1070 | ||
1071 | case WXK_END: | |
1072 | currentLine = GetLineCount() - 1; | |
1073 | break; | |
1074 | ||
1075 | case WXK_DOWN: | |
1076 | if ( currentLineNow == (int)GetLineCount() - 1 ) | |
1077 | return; | |
1078 | ||
1079 | currentLine = currentLineNow + 1; | |
1080 | break; | |
1081 | ||
1082 | case WXK_UP: | |
1083 | if ( m_current == wxNOT_FOUND ) | |
1084 | currentLine = GetLineCount() - 1; | |
1085 | else if ( currentLineNow != 0 ) | |
1086 | currentLine = currentLineNow - 1; | |
1087 | else // currentLineNow == 0 | |
1088 | return; | |
1089 | break; | |
1090 | ||
1091 | case WXK_PAGEDOWN: | |
1092 | PageDown(); | |
1093 | currentLine = GetFirstVisibleLine(); | |
1094 | break; | |
1095 | ||
1096 | case WXK_PAGEUP: | |
1097 | if ( currentLineNow == (int)GetFirstVisibleLine() ) | |
1098 | { | |
1099 | PageUp(); | |
1100 | } | |
1101 | ||
1102 | currentLine = GetFirstVisibleLine(); | |
1103 | break; | |
1104 | ||
1105 | case WXK_SPACE: | |
1106 | // hack: pressing space should work like a mouse click rather than | |
1107 | // like a keyboard arrow press, so trick DoHandleItemClick() in | |
1108 | // thinking we were clicked | |
1109 | flags &= ~ItemClick_Kbd; | |
1110 | currentLine = currentLineNow; | |
1111 | break; | |
1112 | ||
1113 | #ifdef __WXMSW__ | |
1114 | case WXK_TAB: | |
1115 | // Since we are using wxWANTS_CHARS we need to send navigation | |
1116 | // events for the tabs on MSW | |
1117 | { | |
1118 | wxNavigationKeyEvent ne; | |
1119 | ne.SetDirection(!event.ShiftDown()); | |
1120 | ne.SetCurrentFocus(this); | |
1121 | ne.SetEventObject(this); | |
1122 | GetParent()->GetEventHandler()->ProcessEvent(ne); | |
1123 | } | |
1124 | // fall through to default | |
1125 | #endif | |
1126 | default: | |
1127 | event.Skip(); | |
1128 | currentLine = 0; // just to silent the stupid compiler warnings | |
1129 | wxUnusedVar(currentNow); | |
1130 | return; | |
1131 | } | |
1132 | ||
1133 | #if 0 | |
1134 | if ( event.ShiftDown() ) | |
1135 | flags |= ItemClick_Shift; | |
1136 | if ( event.ControlDown() ) | |
1137 | flags |= ItemClick_Ctrl; | |
1138 | ||
1139 | DoHandleItemClick(current, flags); | |
1140 | #endif | |
1141 | #endif | |
1142 | } | |
1143 | ||
1144 | // ---------------------------------------------------------------------------- | |
1145 | // wxSymbolListCtrl mouse handling | |
1146 | // ---------------------------------------------------------------------------- | |
1147 | ||
1148 | void wxSymbolListCtrl::OnLeftDown(wxMouseEvent& event) | |
1149 | { | |
1150 | SetFocus(); | |
1151 | ||
1152 | int item = HitTest(event.GetPosition()); | |
1153 | ||
1154 | if ( item != wxNOT_FOUND ) | |
1155 | { | |
1156 | int flags = 0; | |
1157 | if ( event.ShiftDown() ) | |
1158 | flags |= ItemClick_Shift; | |
1159 | ||
1160 | // under Mac Apple-click is used in the same way as Ctrl-click | |
1161 | // elsewhere | |
1162 | #ifdef __WXMAC__ | |
1163 | if ( event.MetaDown() ) | |
1164 | #else | |
1165 | if ( event.ControlDown() ) | |
1166 | #endif | |
1167 | flags |= ItemClick_Ctrl; | |
1168 | ||
1169 | DoHandleItemClick(item, flags); | |
1170 | } | |
1171 | } | |
1172 | ||
1173 | void wxSymbolListCtrl::OnLeftDClick(wxMouseEvent& eventMouse) | |
1174 | { | |
1175 | int item = HitTest(eventMouse.GetPosition()); | |
1176 | if ( item != wxNOT_FOUND ) | |
1177 | { | |
1178 | ||
1179 | // if item double-clicked was not yet selected, then treat | |
1180 | // this event as a left-click instead | |
1181 | if ( item == m_current ) | |
1182 | { | |
1183 | wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, GetId()); | |
1184 | event.SetEventObject(this); | |
1185 | event.SetInt(item); | |
1186 | ||
1187 | (void)GetEventHandler()->ProcessEvent(event); | |
1188 | } | |
1189 | else | |
1190 | { | |
1191 | OnLeftDown(eventMouse); | |
1192 | } | |
1193 | ||
1194 | } | |
1195 | } | |
1196 | ||
1197 | // calculate line number from symbol value | |
1198 | int wxSymbolListCtrl::SymbolValueToLineNumber(int item) | |
1199 | { | |
1200 | return (int) (item/m_symbolsPerLine); | |
1201 | } | |
1202 | ||
1203 | // initialise control from current min/max values | |
1204 | void wxSymbolListCtrl::SetupCtrl(bool scrollToSelection) | |
1205 | { | |
1206 | wxSize sz = GetClientSize(); | |
1207 | ||
1208 | m_symbolsPerLine = sz.x/(m_cellSize.x+m_ptMargins.x); | |
1209 | int noLines = (1 + SymbolValueToLineNumber(m_maxSymbolValue)); | |
1210 | ||
f18eaf26 | 1211 | SetRowCount(noLines); |
ebf0a029 JS |
1212 | Refresh(); |
1213 | ||
1214 | if (scrollToSelection && m_current != wxNOT_FOUND && m_current >= m_minSymbolValue && m_current <= m_maxSymbolValue) | |
1215 | { | |
f18eaf26 | 1216 | ScrollToRow(SymbolValueToLineNumber(m_current)); |
ebf0a029 JS |
1217 | } |
1218 | } | |
1219 | ||
1220 | // make this item visible | |
1221 | void wxSymbolListCtrl::EnsureVisible(int item) | |
1222 | { | |
1223 | if (item != wxNOT_FOUND && item >= m_minSymbolValue && item <= m_maxSymbolValue) | |
1224 | { | |
f18eaf26 | 1225 | ScrollToRow(SymbolValueToLineNumber(item)); |
ebf0a029 JS |
1226 | } |
1227 | } | |
1228 | ||
1229 | ||
1230 | // hit testing | |
1231 | int wxSymbolListCtrl::HitTest(const wxPoint& pt) | |
1232 | { | |
e02c72fa | 1233 | wxCoord lineHeight = OnGetRowHeight(0); |
ebf0a029 JS |
1234 | |
1235 | int atLine = GetVisibleBegin() + (pt.y/lineHeight); | |
1236 | int symbol = (atLine*m_symbolsPerLine) + (pt.x/(m_cellSize.x+1)); | |
1237 | ||
1238 | if (symbol >= m_minSymbolValue && symbol <= m_maxSymbolValue) | |
1239 | return symbol; | |
07854e5e | 1240 | |
ebf0a029 JS |
1241 | return -1; |
1242 | } | |
1243 | ||
1244 | // Respond to size change | |
1245 | void wxSymbolListCtrl::OnSize(wxSizeEvent& event) | |
1246 | { | |
1247 | SetupCtrl(); | |
1248 | event.Skip(); | |
1249 | } | |
1250 | ||
1251 | // set the current font | |
1252 | bool wxSymbolListCtrl::SetFont(const wxFont& font) | |
1253 | { | |
1254 | wxVScrolledWindow::SetFont(font); | |
1255 | ||
1256 | SetupCtrl(); | |
1257 | ||
1258 | return true; | |
1259 | } | |
1260 | ||
1261 | // set Unicode/ASCII mode | |
1262 | void wxSymbolListCtrl::SetUnicodeMode(bool unicodeMode) | |
1263 | { | |
1264 | bool changed = false; | |
1265 | if (unicodeMode && !m_unicodeMode) | |
1266 | { | |
1267 | changed = true; | |
1268 | ||
1269 | m_minSymbolValue = 0; | |
1270 | m_maxSymbolValue = 65535; | |
1271 | } | |
1272 | else if (!unicodeMode && m_unicodeMode) | |
1273 | { | |
1274 | changed = true; | |
1275 | m_minSymbolValue = 0; | |
1276 | m_maxSymbolValue = 255; | |
1277 | } | |
1278 | m_unicodeMode = unicodeMode; | |
1279 | ||
1280 | if (changed) | |
1281 | SetupCtrl(); | |
1282 | } | |
1283 | ||
1284 | // ---------------------------------------------------------------------------- | |
1285 | // use the same default attributes as wxListBox | |
1286 | // ---------------------------------------------------------------------------- | |
1287 | ||
1288 | //static | |
1289 | wxVisualAttributes | |
1290 | wxSymbolListCtrl::GetClassDefaultAttributes(wxWindowVariant variant) | |
1291 | { | |
1292 | return wxListBox::GetClassDefaultAttributes(variant); | |
1293 | } | |
1294 | ||
3bb084c4 JS |
1295 | /*! |
1296 | * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_HELP | |
1297 | */ | |
1298 | ||
1299 | void wxSymbolPickerDialog::OnHelpClick( wxCommandEvent& WXUNUSED(event) ) | |
1300 | { | |
1301 | if ((GetHelpInfo().GetHelpId() != -1) && GetHelpInfo().GetUICustomization()) | |
1302 | ShowHelp(this); | |
1303 | } | |
1304 | ||
1305 | /*! | |
1306 | * wxEVT_UPDATE_UI event handler for wxID_HELP | |
1307 | */ | |
1308 | ||
1309 | void wxSymbolPickerDialog::OnHelpUpdate( wxUpdateUIEvent& event ) | |
1310 | { | |
1311 | event.Enable((GetHelpInfo().GetHelpId() != -1) && GetHelpInfo().GetUICustomization()); | |
1312 | } | |
1313 | ||
1314 | #endif | |
1315 | // wxUSE_RICHTEXT |