1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextsymboldlg.cpp
4 // Author: Julian Smart
6 // Created: 10/5/2006 3:11:58 PM
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/richtext/richtextsymboldlg.h"
25 #include "wx/stattext.h"
26 #include "wx/combobox.h"
27 #include "wx/button.h"
28 #include "wx/settings.h"
30 #include "wx/listbox.h"
33 #include "wx/dcbuffer.h"
35 // Only for cached font name
36 #include "wx/richtext/richtextctrl.h"
38 /* Microsoft Unicode subset numbering
44 U_LATIN_1_SUPPLEMENT
= 1,
45 U_LATIN_EXTENDED_A
= 2,
46 U_LATIN_EXTENDED_B
= 3,
48 U_SPACING_MODIFIER_LETTERS
= 5,
49 U_COMBINING_DIACRITICAL_MARKS
= 6,
51 U_GREEK_SYMBOLS_AND_COPTIC
= 8,
54 U_HEBREW_EXTENDED
= 12,
57 U_ARABIC_EXTENDED
= 14,
69 U_GEORGIAN_EXTENDED
= 27,
70 U_BASIC_GEORGIAN
= 26,
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,
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,
87 U_BLOCK_ELEMENTS
= 44,
88 U_GEOMETRIC_SHAPES
= 45,
89 U_MISCELLANEOUS_SYMBOLS
= 46,
91 U_CJK_SYMBOLS_AND_PUNCTUATION
= 48,
95 U_HANGUL_COMPATIBILITY_JAMO
= 52,
96 U_CJK_MISCELLANEOUS
= 53,
98 U_CJK_COMPATIBILITY
= 55,
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,
112 U_HALFWIDTH_AND_FULLWIDTH_FORMS
= 68,
114 } wxUnicodeSubsetCodes
;
116 /* Unicode subsets */
122 wxUnicodeSubsetCodes m_subset
;
123 const wxChar
* m_name
;
124 } g_UnicodeSubsetTable
[] =
127 U_BASIC_LATIN
, wxT("Basic Latin") },
129 U_LATIN_1_SUPPLEMENT
, wxT("Latin-1 Supplement") },
131 U_LATIN_EXTENDED_A
, wxT("Latin Extended-A") },
133 U_LATIN_EXTENDED_B
, wxT("Latin Extended-B") },
135 U_IPA_EXTENSIONS
, wxT("IPA Extensions") },
137 U_SPACING_MODIFIER_LETTERS
, wxT("Spacing Modifier Letters") },
139 U_COMBINING_DIACRITICAL_MARKS
, wxT("Combining Diacritical Marks") },
141 U_BASIC_GREEK
, wxT("Basic Greek") },
143 U_GREEK_SYMBOLS_AND_COPTIC
, wxT("Greek Symbols and Coptic") },
145 U_CYRILLIC
, wxT("Cyrillic") },
147 U_ARMENIAN
, wxT("Armenian") },
149 U_HEBREW_EXTENDED
, wxT("Hebrew Extended") },
151 U_BASIC_HEBREW
, wxT("Basic Hebrew") },
153 U_BASIC_ARABIC
, wxT("Basic Arabic") },
155 U_ARABIC_EXTENDED
, wxT("Arabic Extended") },
157 U_DEVANAGARI
, wxT("Devanagari") },
159 U_BENGALI
, wxT("Bengali") },
161 U_GURMUKHI
, wxT("Gurmukhi") },
163 U_GUJARATI
, wxT("Gujarati") },
165 U_ORIYA
, wxT("Oriya") },
167 U_TAMIL
, wxT("Tamil") },
169 U_TELUGU
, wxT("Telugu") },
171 U_KANNADA
, wxT("Kannada") },
173 U_MALAYALAM
, wxT("Malayalam") },
175 U_THAI
, wxT("Thai") },
179 U_GEORGIAN_EXTENDED
, wxT("Georgian Extended") },
181 U_BASIC_GEORGIAN
, wxT("Basic Georgian") },
183 U_HANGUL_JAMO
, wxT("Hangul Jamo") },
185 U_LATIN_EXTENDED_ADDITIONAL
, wxT("Latin Extended Additional") },
187 U_GREEK_EXTENDED
, wxT("Greek Extended") },
189 U_GENERAL_PUNCTUATION
, wxT("General Punctuation") },
191 U_SUPERSCRIPTS_AND_SUBSCRIPTS
, wxT("Superscripts and Subscripts") },
193 U_CURRENCY_SYMBOLS
, wxT("Currency Symbols") },
195 U_COMBINING_DIACRITICAL_MARKS_FOR_SYMBOLS
, wxT("Combining Diacritical Marks for Symbols") },
197 U_LETTERLIKE_SYMBOLS
, wxT("Letterlike Symbols") },
199 U_NUMBER_FORMS
, wxT("Number Forms") },
201 U_ARROWS
, wxT("Arrows") },
203 U_MATHEMATICAL_OPERATORS
, wxT("Mathematical Operators") },
205 U_MISCELLANEOUS_TECHNICAL
, wxT("Miscellaneous Technical") },
207 U_CONTROL_PICTURES
, wxT("Control Pictures") },
209 U_OPTICAL_CHARACTER_RECOGNITION
, wxT("Optical Character Recognition") },
211 U_ENCLOSED_ALPHANUMERICS
, wxT("Enclosed Alphanumerics") },
213 U_BOX_DRAWING
, wxT("Box Drawing") },
215 U_BLOCK_ELEMENTS
, wxT("Block Elements") },
217 U_GEOMETRIC_SHAPES
, wxT("Geometric Shapes") },
219 U_MISCELLANEOUS_SYMBOLS
, wxT("Miscellaneous Symbols") },
221 U_DINGBATS
, wxT("Dingbats") },
223 U_CJK_SYMBOLS_AND_PUNCTUATION
, wxT("CJK Symbols and Punctuation") },
225 U_HIRAGANA
, wxT("Hiragana") },
227 U_KATAKANA
, wxT("Katakana") },
229 U_BOPOMOFO
, wxT("Bopomofo") },
231 U_HANGUL_COMPATIBILITY_JAMO
, wxT("Hangul Compatibility Jamo") },
233 U_CJK_MISCELLANEOUS
, wxT("CJK Miscellaneous") },
235 U_ENCLOSED_CJK
, wxT("Enclosed CJK") },
237 U_CJK_COMPATIBILITY
, wxT("CJK Compatibility") },
239 U_CJK_UNIFIED_IDEOGRAPHS
, wxT("CJK Unified Ideographs Extension A") },
241 U_CJK_UNIFIED_IDEOGRAPHS
, wxT("CJK Unified Ideographs") },
243 U_HANGUL
, wxT("Hangul Syllables") },
245 U_PRIVATE_USE_AREA
, wxT("Private Use Area") },
247 U_CJK_COMPATIBILITY_IDEOGRAPHS
, wxT("CJK Compatibility Ideographs") },
249 U_ALPHABETIC_PRESENTATION_FORMS
, wxT("Alphabetic Presentation Forms") },
251 U_ARABIC_PRESENTATION_FORMS_A
, wxT("Arabic Presentation Forms-A") },
253 U_COMBINING_HALF_MARKS
, wxT("Combining Half Marks") },
255 U_CJK_COMPATIBILITY_FORMS
, wxT("CJK Compatibility Forms") },
257 U_SMALL_FORM_VARIANTS
, wxT("Small Form Variants") },
259 U_ARABIC_PRESENTATION_FORMS_B
, wxT("Arabic Presentation Forms-B") },
261 U_SPECIALS
, wxT("Specials") },
263 U_HALFWIDTH_AND_FULLWIDTH_FORMS
, wxT("Halfwidth and Fullwidth Forms") },
265 U_SPECIALS
, wxT("Specials") }
268 #endif // __UNICODE__
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
)
275 return (fontSig
->fsUsb
[g_UnicodeSubsetTable
[subsetIndex
].m_subset
/32] & (1 << (g_UnicodeSubsetTable
[subsetIndex
].m_subset
% 32)));
279 bool wxSymbolPickerDialog::sm_showToolTips
= false;
282 * wxSymbolPickerDialog type definition
285 IMPLEMENT_DYNAMIC_CLASS( wxSymbolPickerDialog
, wxDialog
)
288 * wxSymbolPickerDialog event table definition
291 BEGIN_EVENT_TABLE( wxSymbolPickerDialog
, wxDialog
)
292 EVT_LISTBOX(ID_SYMBOLPICKERDIALOG_LISTCTRL
, wxSymbolPickerDialog::OnSymbolSelected
)
294 ////@begin wxSymbolPickerDialog event table entries
295 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FONT
, wxSymbolPickerDialog::OnFontCtrlSelected
)
297 #if defined(__UNICODE__)
298 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_SUBSET
, wxSymbolPickerDialog::OnSubsetSelected
)
301 #if defined(__UNICODE__)
302 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FROM
, wxSymbolPickerDialog::OnFromUnicodeSelected
)
305 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
306 EVT_UPDATE_UI( wxID_OK
, wxSymbolPickerDialog::OnOkUpdate
)
309 #if defined(__WXMAC__)
310 EVT_UPDATE_UI( wxID_OK
, wxSymbolPickerDialog::OnOkUpdate
)
313 ////@end wxSymbolPickerDialog event table entries
318 * wxSymbolPickerDialog constructors
321 wxSymbolPickerDialog::wxSymbolPickerDialog( )
326 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
)
329 Create(symbol
, fontName
, normalTextFont
, parent
, id
, caption
, pos
, size
, style
);
333 * wxSymbolPickerDialog creator
336 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
)
338 m_fontName
= fontName
;
339 m_normalTextFontName
= normalTextFont
;
342 ////@begin wxSymbolPickerDialog creation
343 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
344 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
349 GetSizer()->SetSizeHints(this);
352 ////@end wxSymbolPickerDialog creation
357 * Member initialisation for wxSymbolPickerDialog
360 void wxSymbolPickerDialog::Init()
362 ////@begin wxSymbolPickerDialog member initialisation
363 m_fromUnicode
= true;
365 #if defined(__UNICODE__)
368 m_symbolsCtrl
= NULL
;
369 m_symbolStaticCtrl
= NULL
;
370 m_characterCodeCtrl
= NULL
;
371 #if defined(__UNICODE__)
372 m_fromUnicodeCtrl
= NULL
;
374 ////@end wxSymbolPickerDialog member initialisation
375 m_dontUpdate
= false;
379 * Control creation for wxSymbolPickerDialog
382 void wxSymbolPickerDialog::CreateControls()
384 ////@begin wxSymbolPickerDialog content construction
385 wxSymbolPickerDialog
* itemDialog1
= this;
387 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
388 itemDialog1
->SetSizer(itemBoxSizer2
);
390 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
391 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
393 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
394 itemBoxSizer3
->Add(itemBoxSizer4
, 0, wxGROW
, 5);
396 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxHORIZONTAL
);
397 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
399 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
400 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
402 wxArrayString m_fontCtrlStrings
;
403 m_fontCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_FONT
, _T(""), wxDefaultPosition
, wxSize(240, -1), m_fontCtrlStrings
, wxCB_READONLY
);
404 m_fontCtrl
->SetHelpText(_("The font from which to take the symbol."));
405 if (wxSymbolPickerDialog::ShowToolTips())
406 m_fontCtrl
->SetToolTip(_("The font from which to take the symbol."));
407 itemBoxSizer5
->Add(m_fontCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
409 itemBoxSizer5
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
411 #if defined(__UNICODE__)
412 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Subset:"), wxDefaultPosition
, wxDefaultSize
, 0 );
413 itemBoxSizer5
->Add(itemStaticText9
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
417 #if defined(__UNICODE__)
418 wxArrayString m_subsetCtrlStrings
;
419 m_subsetCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_SUBSET
, _T(""), wxDefaultPosition
, wxDefaultSize
, m_subsetCtrlStrings
, wxCB_READONLY
);
420 m_subsetCtrl
->SetHelpText(_("Shows a Unicode subset."));
421 if (wxSymbolPickerDialog::ShowToolTips())
422 m_subsetCtrl
->SetToolTip(_("Shows a Unicode subset."));
423 itemBoxSizer5
->Add(m_subsetCtrl
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
427 m_symbolsCtrl
= new wxSymbolListCtrl( itemDialog1
, ID_SYMBOLPICKERDIALOG_LISTCTRL
, wxDefaultPosition
, wxSize(500, 200), 0 );
428 itemBoxSizer3
->Add(m_symbolsCtrl
, 1, wxGROW
|wxALL
, 5);
430 wxBoxSizer
* itemBoxSizer12
= new wxBoxSizer(wxHORIZONTAL
);
431 itemBoxSizer3
->Add(itemBoxSizer12
, 0, wxGROW
, 5);
433 m_symbolStaticCtrl
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("xxxx"), wxDefaultPosition
, wxSize(40, -1), wxALIGN_CENTRE
);
434 itemBoxSizer12
->Add(m_symbolStaticCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
436 itemBoxSizer12
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
438 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Character code:"), wxDefaultPosition
, wxDefaultSize
, 0 );
439 itemBoxSizer12
->Add(itemStaticText15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
441 m_characterCodeCtrl
= new wxTextCtrl( itemDialog1
, ID_SYMBOLPICKERDIALOG_CHARACTERCODE
, _T(""), wxDefaultPosition
, wxSize(140, -1), wxTE_READONLY
|wxTE_CENTRE
);
442 m_characterCodeCtrl
->SetHelpText(_("The character code."));
443 if (wxSymbolPickerDialog::ShowToolTips())
444 m_characterCodeCtrl
->SetToolTip(_("The character code."));
445 itemBoxSizer12
->Add(m_characterCodeCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
447 itemBoxSizer12
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
449 #if defined(__UNICODE__)
450 wxStaticText
* itemStaticText18
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&From:"), wxDefaultPosition
, wxDefaultSize
, 0 );
451 itemBoxSizer12
->Add(itemStaticText18
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
455 #if defined(__UNICODE__)
456 wxArrayString m_fromUnicodeCtrlStrings
;
457 m_fromUnicodeCtrlStrings
.Add(_("ASCII"));
458 m_fromUnicodeCtrlStrings
.Add(_("Unicode"));
459 m_fromUnicodeCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_FROM
, _("ASCII"), wxDefaultPosition
, wxDefaultSize
, m_fromUnicodeCtrlStrings
, wxCB_READONLY
);
460 m_fromUnicodeCtrl
->SetStringSelection(_("ASCII"));
461 m_fromUnicodeCtrl
->SetHelpText(_("The range to show."));
462 if (wxSymbolPickerDialog::ShowToolTips())
463 m_fromUnicodeCtrl
->SetToolTip(_("The range to show."));
464 itemBoxSizer12
->Add(m_fromUnicodeCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
468 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMGL__) || defined(__WXMOTIF__) || defined(__WXCOCOA__) || defined(__WXX11__) || defined(__WXPALMOS__)
469 wxBoxSizer
* itemBoxSizer20
= new wxBoxSizer(wxHORIZONTAL
);
470 itemBoxSizer3
->Add(itemBoxSizer20
, 0, wxGROW
, 5);
472 itemBoxSizer20
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
474 wxButton
* itemButton22
= new wxButton( itemDialog1
, wxID_OK
, _("Insert"), wxDefaultPosition
, wxDefaultSize
, 0 );
475 itemButton22
->SetDefault();
476 itemButton22
->SetHelpText(_("Inserts the chosen symbol."));
477 if (wxSymbolPickerDialog::ShowToolTips())
478 itemButton22
->SetToolTip(_("Inserts the chosen symbol."));
479 itemBoxSizer20
->Add(itemButton22
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
481 wxButton
* itemButton23
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
482 itemButton23
->SetHelpText(_("Closes the dialog without inserting a symbol."));
483 if (wxSymbolPickerDialog::ShowToolTips())
484 itemButton23
->SetToolTip(_("Closes the dialog without inserting a symbol."));
485 itemBoxSizer20
->Add(itemButton23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
489 #if defined(__WXMAC__)
490 wxBoxSizer
* itemBoxSizer24
= new wxBoxSizer(wxHORIZONTAL
);
491 itemBoxSizer3
->Add(itemBoxSizer24
, 0, wxGROW
, 5);
493 itemBoxSizer24
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
495 wxButton
* itemButton26
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
496 itemButton26
->SetHelpText(_("Closes the dialog without inserting a symbol."));
497 if (wxSymbolPickerDialog::ShowToolTips())
498 itemButton26
->SetToolTip(_("Closes the dialog without inserting a symbol."));
499 itemBoxSizer24
->Add(itemButton26
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
501 wxButton
* itemButton27
= new wxButton( itemDialog1
, wxID_OK
, _("Insert"), wxDefaultPosition
, wxDefaultSize
, 0 );
502 itemButton27
->SetDefault();
503 itemButton27
->SetHelpText(_("Inserts the chosen symbol."));
504 if (wxSymbolPickerDialog::ShowToolTips())
505 itemButton27
->SetToolTip(_("Inserts the chosen symbol."));
506 itemBoxSizer24
->Add(itemButton27
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
510 ////@end wxSymbolPickerDialog content construction
515 bool wxSymbolPickerDialog::TransferDataToWindow()
519 if (m_fontCtrl
->GetCount() == 0)
521 wxArrayString faceNames
= wxRichTextCtrl::GetAvailableFontNames();
524 faceNames
.Insert(_("(Normal text)"), 0);
525 m_fontCtrl
->Append(faceNames
);
528 if (m_fontName
.empty())
529 m_fontCtrl
->SetSelection(0);
532 if (m_fontCtrl
->FindString(m_fontName
) != wxNOT_FOUND
)
533 m_fontCtrl
->SetStringSelection(m_fontName
);
535 m_fontCtrl
->SetSelection(0);
538 if (!m_symbol
.empty())
540 int sel
= (int) m_symbol
[0];
541 m_symbolsCtrl
->SetSelection(sel
);
544 #if defined(__UNICODE__)
545 if (m_subsetCtrl
->GetCount() == 0)
547 // Insert items into subset combo
549 for (i
= 0; i
< (int) (sizeof(g_UnicodeSubsetTable
)/sizeof(g_UnicodeSubsetTable
[0])); i
++)
551 m_subsetCtrl
->Append(g_UnicodeSubsetTable
[i
].m_name
);
553 m_subsetCtrl
->SetSelection(0);
557 UpdateSymbolDisplay();
559 m_dontUpdate
= false;
564 void wxSymbolPickerDialog::UpdateSymbolDisplay(bool updateSymbolList
, bool showAtSubset
)
567 wxString fontNameToUse
;
568 if (m_fontName
.empty())
569 fontNameToUse
= m_normalTextFontName
;
571 fontNameToUse
= m_fontName
;
573 if (!fontNameToUse
.empty())
575 font
= wxFont(14, wxDEFAULT
, wxNORMAL
, wxNORMAL
, false, fontNameToUse
);
578 font
= *wxNORMAL_FONT
;
580 if (updateSymbolList
)
582 m_symbolsCtrl
->SetFont(font
);
585 if (!m_symbol
.empty())
587 m_symbolStaticCtrl
->SetFont(font
);
588 m_symbolStaticCtrl
->SetLabel(m_symbol
);
590 int symbol
= (int) m_symbol
[0];
591 m_characterCodeCtrl
->SetValue(wxString::Format(wxT("%X hex (%d dec)"), symbol
, symbol
));
595 m_symbolStaticCtrl
->SetLabel(wxEmptyString
);
596 m_characterCodeCtrl
->SetValue(wxEmptyString
);
599 #if defined(__UNICODE__)
603 wxUnusedVar(showAtSubset
);
607 /// Show at the current subset selection
608 void wxSymbolPickerDialog::ShowAtSubset()
610 #if defined(__UNICODE__)
613 int sel
= m_subsetCtrl
->GetSelection();
614 int low
= g_UnicodeSubsetTable
[sel
].m_low
;
615 m_symbolsCtrl
->EnsureVisible(low
);
620 // Handle font selection
621 void wxSymbolPickerDialog::OnFontCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
623 if (m_fontCtrl
->GetSelection() == 0)
624 m_fontName
= wxEmptyString
;
626 m_fontName
= m_fontCtrl
->GetStringSelection();
628 UpdateSymbolDisplay();
631 /// Respond to symbol selection
632 void wxSymbolPickerDialog::OnSymbolSelected( wxCommandEvent
& event
)
637 int sel
= event
.GetSelection();
638 if (sel
== wxNOT_FOUND
)
639 m_symbol
= wxEmptyString
;
642 m_symbol
= wxEmptyString
;
643 m_symbol
<< (wxChar
) sel
;
646 #if defined(__UNICODE__)
647 if (sel
!= -1 && m_fromUnicode
)
649 // Need to make the subset selection reflect the current symbol
651 for (i
= 0; i
< (int) (sizeof(g_UnicodeSubsetTable
)/sizeof(g_UnicodeSubsetTable
[0])); i
++)
653 if (sel
>= g_UnicodeSubsetTable
[i
].m_low
&& sel
<= g_UnicodeSubsetTable
[i
].m_high
)
656 m_subsetCtrl
->SetSelection(i
);
657 m_dontUpdate
= false;
664 UpdateSymbolDisplay(false, false);
667 #if defined(__UNICODE__)
668 // Handle Unicode/ASCII selection
669 void wxSymbolPickerDialog::OnFromUnicodeSelected( wxCommandEvent
& WXUNUSED(event
) )
674 m_fromUnicode
= (m_fromUnicodeCtrl
->GetSelection() == 1);
675 m_symbolsCtrl
->SetUnicodeMode(m_fromUnicode
);
676 UpdateSymbolDisplay(false);
679 // Handle subset selection
680 void wxSymbolPickerDialog::OnSubsetSelected( wxCommandEvent
& WXUNUSED(event
) )
690 * wxEVT_UPDATE_UI event handler for wxID_OK
693 void wxSymbolPickerDialog::OnOkUpdate( wxUpdateUIEvent
& event
)
695 event
.Enable(HasSelection());
699 void wxSymbolPickerDialog::SetUnicodeMode(bool unicodeMode
)
701 #if defined(__UNICODE__)
703 m_fromUnicode
= unicodeMode
;
704 if (m_fromUnicodeCtrl
)
705 m_fromUnicodeCtrl
->SetSelection(m_fromUnicode
? 1 : 0);
706 UpdateSymbolDisplay();
707 m_dontUpdate
= false;
709 wxUnusedVar(unicodeMode
);
713 /// Get the selected symbol character
714 int wxSymbolPickerDialog::GetSymbolChar() const
716 if (m_symbol
.empty())
719 return (int) m_symbol
[0];
724 * Get bitmap resources
727 wxBitmap
wxSymbolPickerDialog::GetBitmapResource( const wxString
& name
)
730 ////@begin wxSymbolPickerDialog bitmap retrieval
733 ////@end wxSymbolPickerDialog bitmap retrieval
740 wxIcon
wxSymbolPickerDialog::GetIconResource( const wxString
& name
)
743 ////@begin wxSymbolPickerDialog icon retrieval
746 ////@end wxSymbolPickerDialog icon retrieval
750 * The scrolling symbol list.
753 // ----------------------------------------------------------------------------
755 // ----------------------------------------------------------------------------
757 BEGIN_EVENT_TABLE(wxSymbolListCtrl
, wxVScrolledWindow
)
758 EVT_PAINT(wxSymbolListCtrl::OnPaint
)
759 EVT_SIZE(wxSymbolListCtrl::OnSize
)
761 EVT_KEY_DOWN(wxSymbolListCtrl::OnKeyDown
)
762 EVT_LEFT_DOWN(wxSymbolListCtrl::OnLeftDown
)
763 EVT_LEFT_DCLICK(wxSymbolListCtrl::OnLeftDClick
)
766 // ============================================================================
768 // ============================================================================
770 IMPLEMENT_ABSTRACT_CLASS(wxSymbolListCtrl
, wxVScrolledWindow
)
772 // ----------------------------------------------------------------------------
773 // wxSymbolListCtrl creation
774 // ----------------------------------------------------------------------------
776 void wxSymbolListCtrl::Init()
778 m_current
= wxNOT_FOUND
;
779 m_doubleBuffer
= NULL
;
780 m_cellSize
= wxSize(40, 40);
781 m_minSymbolValue
= 0;
782 m_maxSymbolValue
= 255;
783 m_symbolsPerLine
= 0;
784 m_unicodeMode
= false;
787 bool wxSymbolListCtrl::Create(wxWindow
*parent
,
792 const wxString
& name
)
794 style
|= wxWANTS_CHARS
| wxFULL_REPAINT_ON_RESIZE
;
796 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
797 style
|= wxBORDER_THEME
;
799 if ( !wxVScrolledWindow::Create(parent
, id
, pos
, size
, style
, name
) )
802 // make sure the native widget has the right colour since we do
803 // transparent drawing by default
804 SetBackgroundColour(GetBackgroundColour());
805 m_colBgSel
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
807 // flicker-free drawing requires this
808 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
810 SetFont(*wxNORMAL_FONT
);
817 wxSymbolListCtrl::~wxSymbolListCtrl()
819 delete m_doubleBuffer
;
822 // ----------------------------------------------------------------------------
823 // selection handling
824 // ----------------------------------------------------------------------------
826 bool wxSymbolListCtrl::IsSelected(int item
) const
828 return item
== m_current
;
831 bool wxSymbolListCtrl::DoSetCurrent(int current
)
833 wxASSERT_MSG( current
== wxNOT_FOUND
||
834 (current
>= m_minSymbolValue
&& current
<= m_maxSymbolValue
),
835 _T("wxSymbolListCtrl::DoSetCurrent(): invalid symbol value") );
837 if ( current
== m_current
)
843 if ( m_current
!= wxNOT_FOUND
)
844 RefreshRow(SymbolValueToLineNumber(m_current
));
848 if ( m_current
!= wxNOT_FOUND
)
850 int lineNo
= SymbolValueToLineNumber(m_current
);
852 // if the line is not visible at all, we scroll it into view but we
853 // don't need to refresh it -- it will be redrawn anyhow
854 if ( !IsVisible(lineNo
) )
858 else // line is at least partly visible
860 // it is, indeed, only partly visible, so scroll it into view to
861 // make it entirely visible
862 while ( (unsigned)lineNo
+ 1 == GetVisibleEnd() &&
863 ScrollToRow(GetVisibleBegin() + 1) )
866 // but in any case refresh it as even if it was only partly visible
867 // before we need to redraw it entirely as its background changed
875 void wxSymbolListCtrl::SendSelectedEvent()
877 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, GetId());
878 event
.SetEventObject(this);
879 event
.SetInt(m_current
);
881 (void)GetEventHandler()->ProcessEvent(event
);
884 void wxSymbolListCtrl::SetSelection(int selection
)
886 wxCHECK_RET( selection
== wxNOT_FOUND
||
887 (selection
>= m_minSymbolValue
&& selection
< m_maxSymbolValue
),
888 _T("wxSymbolListCtrl::SetSelection(): invalid symbol value") );
890 DoSetCurrent(selection
);
893 // ----------------------------------------------------------------------------
894 // wxSymbolListCtrl appearance parameters
895 // ----------------------------------------------------------------------------
897 void wxSymbolListCtrl::SetMargins(const wxPoint
& pt
)
899 if ( pt
!= m_ptMargins
)
907 void wxSymbolListCtrl::SetSelectionBackground(const wxColour
& col
)
912 // ----------------------------------------------------------------------------
913 // wxSymbolListCtrl painting
914 // ----------------------------------------------------------------------------
916 wxCoord
wxSymbolListCtrl::OnGetRowHeight(size_t WXUNUSED(line
)) const
918 return m_cellSize
.y
+ 2*m_ptMargins
.y
+ 1 /* for divider */ ;
921 // draws a line of symbols
922 void wxSymbolListCtrl::OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
924 wxColour oldTextColour
= dc
.GetTextForeground();
925 int startSymbol
= n
*m_symbolsPerLine
;
928 for (i
= 0; i
< m_symbolsPerLine
; i
++)
930 bool resetColour
= false;
931 int symbol
= startSymbol
+i
;
932 if (symbol
== m_current
)
934 dc
.SetBrush(wxBrush(m_colBgSel
));
936 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
939 wxPen oldPen
= dc
.GetPen();
940 dc
.SetPen(*wxTRANSPARENT_PEN
);
942 dc
.DrawRectangle(rect
.x
+ i
*m_cellSize
.x
, rect
.y
, m_cellSize
.x
, rect
.y
+rect
.height
);
946 // Don't draw first line
948 dc
.DrawLine(rect
.x
+ i
*m_cellSize
.x
, rect
.y
, i
*m_cellSize
.x
, rect
.y
+rect
.height
);
950 if (symbol
>= m_minSymbolValue
&& symbol
<= m_maxSymbolValue
)
953 text
<< (wxChar
) symbol
;
956 dc
.GetTextExtent(text
, & w
, & h
);
958 int x
= rect
.x
+ i
*m_cellSize
.x
+ (m_cellSize
.x
- w
)/2;
959 int y
= rect
.y
+ (m_cellSize
.y
- h
)/2;
960 dc
.DrawText(text
, x
, y
);
964 dc
.SetTextForeground(oldTextColour
);
967 // Draw horizontal separator line
968 dc
.DrawLine(rect
.x
, rect
.y
+rect
.height
-1, rect
.x
+rect
.width
, rect
.y
+rect
.height
-1);
971 void wxSymbolListCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
973 // If size is larger, recalculate double buffer bitmap
974 wxSize clientSize
= GetClientSize();
976 if ( !m_doubleBuffer
||
977 clientSize
.x
> m_doubleBuffer
->GetWidth() ||
978 clientSize
.y
> m_doubleBuffer
->GetHeight() )
980 delete m_doubleBuffer
;
981 m_doubleBuffer
= new wxBitmap(clientSize
.x
+25,clientSize
.y
+25);
984 wxBufferedPaintDC
dc(this,*m_doubleBuffer
);
986 // the update rectangle
987 wxRect rectUpdate
= GetUpdateClientRect();
989 // fill it with background colour
990 dc
.SetBackground(GetBackgroundColour());
993 // set the font to be displayed
994 dc
.SetFont(GetFont());
996 // the bounding rectangle of the current line
998 rectRow
.width
= clientSize
.x
;
1000 dc
.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
)));
1001 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1002 dc
.SetBackgroundMode(wxTRANSPARENT
);
1004 // iterate over all visible lines
1005 const size_t lineMax
= GetVisibleEnd();
1006 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
1008 const wxCoord hRow
= OnGetRowHeight(line
);
1010 rectRow
.height
= hRow
;
1012 // and draw the ones which intersect the update rect
1013 if ( rectRow
.Intersects(rectUpdate
) )
1015 // don't allow drawing outside of the lines rectangle
1016 wxDCClipper
clip(dc
, rectRow
);
1018 wxRect rect
= rectRow
;
1019 rect
.Deflate(m_ptMargins
.x
, m_ptMargins
.y
);
1020 OnDrawItem(dc
, rect
, line
);
1022 else // no intersection
1024 if ( rectRow
.GetTop() > rectUpdate
.GetBottom() )
1026 // we are already below the update rect, no need to continue
1030 //else: the next line may intersect the update rect
1037 // ============================================================================
1038 // wxSymbolListCtrl keyboard/mouse handling
1039 // ============================================================================
1041 void wxSymbolListCtrl::DoHandleItemClick(int item
, int WXUNUSED(flags
))
1043 if (m_current
!= item
)
1047 SendSelectedEvent();
1051 // ----------------------------------------------------------------------------
1052 // keyboard handling
1053 // ----------------------------------------------------------------------------
1055 void wxSymbolListCtrl::OnKeyDown(wxKeyEvent
& event
)
1057 // No keyboard interface for now
1060 // flags for DoHandleItemClick()
1061 int flags
= ItemClick_Kbd
;
1063 int currentLineNow
= SymbolValueToLineNumber(m_current
);
1066 switch ( event
.GetKeyCode() )
1073 currentLine
= GetLineCount() - 1;
1077 if ( currentLineNow
== (int)GetLineCount() - 1 )
1080 currentLine
= currentLineNow
+ 1;
1084 if ( m_current
== wxNOT_FOUND
)
1085 currentLine
= GetLineCount() - 1;
1086 else if ( currentLineNow
!= 0 )
1087 currentLine
= currentLineNow
- 1;
1088 else // currentLineNow == 0
1094 currentLine
= GetFirstVisibleLine();
1098 if ( currentLineNow
== (int)GetFirstVisibleLine() )
1103 currentLine
= GetFirstVisibleLine();
1107 // hack: pressing space should work like a mouse click rather than
1108 // like a keyboard arrow press, so trick DoHandleItemClick() in
1109 // thinking we were clicked
1110 flags
&= ~ItemClick_Kbd
;
1111 currentLine
= currentLineNow
;
1116 // Since we are using wxWANTS_CHARS we need to send navigation
1117 // events for the tabs on MSW
1119 wxNavigationKeyEvent ne
;
1120 ne
.SetDirection(!event
.ShiftDown());
1121 ne
.SetCurrentFocus(this);
1122 ne
.SetEventObject(this);
1123 GetParent()->GetEventHandler()->ProcessEvent(ne
);
1125 // fall through to default
1129 currentLine
= 0; // just to silent the stupid compiler warnings
1130 wxUnusedVar(currentNow
);
1135 if ( event
.ShiftDown() )
1136 flags
|= ItemClick_Shift
;
1137 if ( event
.ControlDown() )
1138 flags
|= ItemClick_Ctrl
;
1140 DoHandleItemClick(current
, flags
);
1145 // ----------------------------------------------------------------------------
1146 // wxSymbolListCtrl mouse handling
1147 // ----------------------------------------------------------------------------
1149 void wxSymbolListCtrl::OnLeftDown(wxMouseEvent
& event
)
1153 int item
= HitTest(event
.GetPosition());
1155 if ( item
!= wxNOT_FOUND
)
1158 if ( event
.ShiftDown() )
1159 flags
|= ItemClick_Shift
;
1161 // under Mac Apple-click is used in the same way as Ctrl-click
1164 if ( event
.MetaDown() )
1166 if ( event
.ControlDown() )
1168 flags
|= ItemClick_Ctrl
;
1170 DoHandleItemClick(item
, flags
);
1174 void wxSymbolListCtrl::OnLeftDClick(wxMouseEvent
& eventMouse
)
1176 int item
= HitTest(eventMouse
.GetPosition());
1177 if ( item
!= wxNOT_FOUND
)
1180 // if item double-clicked was not yet selected, then treat
1181 // this event as a left-click instead
1182 if ( item
== m_current
)
1184 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, GetId());
1185 event
.SetEventObject(this);
1188 (void)GetEventHandler()->ProcessEvent(event
);
1192 OnLeftDown(eventMouse
);
1198 // calculate line number from symbol value
1199 int wxSymbolListCtrl::SymbolValueToLineNumber(int item
)
1201 return (int) (item
/m_symbolsPerLine
);
1204 // initialise control from current min/max values
1205 void wxSymbolListCtrl::SetupCtrl(bool scrollToSelection
)
1207 wxSize sz
= GetClientSize();
1209 m_symbolsPerLine
= sz
.x
/(m_cellSize
.x
+m_ptMargins
.x
);
1210 int noLines
= (1 + SymbolValueToLineNumber(m_maxSymbolValue
));
1212 SetRowCount(noLines
);
1215 if (scrollToSelection
&& m_current
!= wxNOT_FOUND
&& m_current
>= m_minSymbolValue
&& m_current
<= m_maxSymbolValue
)
1217 ScrollToRow(SymbolValueToLineNumber(m_current
));
1221 // make this item visible
1222 void wxSymbolListCtrl::EnsureVisible(int item
)
1224 if (item
!= wxNOT_FOUND
&& item
>= m_minSymbolValue
&& item
<= m_maxSymbolValue
)
1226 ScrollToRow(SymbolValueToLineNumber(item
));
1232 int wxSymbolListCtrl::HitTest(const wxPoint
& pt
)
1234 wxCoord lineHeight
= OnGetRowHeight(0);
1236 int atLine
= GetVisibleBegin() + (pt
.y
/lineHeight
);
1237 int symbol
= (atLine
*m_symbolsPerLine
) + (pt
.x
/(m_cellSize
.x
+1));
1239 if (symbol
>= m_minSymbolValue
&& symbol
<= m_maxSymbolValue
)
1245 // Respond to size change
1246 void wxSymbolListCtrl::OnSize(wxSizeEvent
& event
)
1252 // set the current font
1253 bool wxSymbolListCtrl::SetFont(const wxFont
& font
)
1255 wxVScrolledWindow::SetFont(font
);
1262 // set Unicode/ASCII mode
1263 void wxSymbolListCtrl::SetUnicodeMode(bool unicodeMode
)
1265 bool changed
= false;
1266 if (unicodeMode
&& !m_unicodeMode
)
1270 m_minSymbolValue
= 0;
1271 m_maxSymbolValue
= 65535;
1273 else if (!unicodeMode
&& m_unicodeMode
)
1276 m_minSymbolValue
= 0;
1277 m_maxSymbolValue
= 255;
1279 m_unicodeMode
= unicodeMode
;
1285 // ----------------------------------------------------------------------------
1286 // use the same default attributes as wxListBox
1287 // ----------------------------------------------------------------------------
1291 wxSymbolListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
1293 return wxListBox::GetClassDefaultAttributes(variant
);
1296 #endif // wxUSE_RICHTEXT