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
)
299 EVT_UPDATE_UI( ID_SYMBOLPICKERDIALOG_SUBSET
, wxSymbolPickerDialog::OnSymbolpickerdialogSubsetUpdate
)
302 #if defined(__UNICODE__)
303 EVT_COMBOBOX( ID_SYMBOLPICKERDIALOG_FROM
, wxSymbolPickerDialog::OnFromUnicodeSelected
)
306 EVT_UPDATE_UI( wxID_OK
, wxSymbolPickerDialog::OnOkUpdate
)
308 ////@end wxSymbolPickerDialog event table entries
312 IMPLEMENT_HELP_PROVISION(wxSymbolPickerDialog
)
315 * wxSymbolPickerDialog constructors
318 wxSymbolPickerDialog::wxSymbolPickerDialog( )
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
)
326 Create(symbol
, fontName
, normalTextFont
, parent
, id
, caption
, pos
, size
, style
);
330 * wxSymbolPickerDialog creator
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
)
335 m_fontName
= fontName
;
336 m_normalTextFontName
= normalTextFont
;
339 ////@begin wxSymbolPickerDialog creation
340 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
341 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
346 GetSizer()->SetSizeHints(this);
349 ////@end wxSymbolPickerDialog creation
354 * Member initialisation for wxSymbolPickerDialog
357 void wxSymbolPickerDialog::Init()
359 ////@begin wxSymbolPickerDialog member initialisation
360 m_fromUnicode
= true;
362 #if defined(__UNICODE__)
365 m_symbolsCtrl
= NULL
;
366 m_symbolStaticCtrl
= NULL
;
367 m_characterCodeCtrl
= NULL
;
368 #if defined(__UNICODE__)
369 m_fromUnicodeCtrl
= NULL
;
371 m_stdButtonSizer
= NULL
;
372 ////@end wxSymbolPickerDialog member initialisation
373 m_dontUpdate
= false;
377 * Control creation for wxSymbolPickerDialog
380 void wxSymbolPickerDialog::CreateControls()
383 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
386 ////@begin wxSymbolPickerDialog content construction
387 wxSymbolPickerDialog
* itemDialog1
= this;
389 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
390 itemDialog1
->SetSizer(itemBoxSizer2
);
392 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
393 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
395 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
396 itemBoxSizer3
->Add(itemBoxSizer4
, 0, wxGROW
, 5);
398 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxHORIZONTAL
);
399 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
401 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
402 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
404 wxArrayString m_fontCtrlStrings
;
405 m_fontCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_FONT
, wxEmptyString
, wxDefaultPosition
, wxSize(240, -1), m_fontCtrlStrings
, wxCB_READONLY
);
406 m_fontCtrl
->SetHelpText(_("The font from which to take the symbol."));
407 if (wxSymbolPickerDialog::ShowToolTips())
408 m_fontCtrl
->SetToolTip(_("The font from which to take the symbol."));
409 itemBoxSizer5
->Add(m_fontCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
411 itemBoxSizer5
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
413 #if defined(__UNICODE__)
414 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Subset:"), wxDefaultPosition
, wxDefaultSize
, 0 );
415 itemBoxSizer5
->Add(itemStaticText9
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
419 #if defined(__UNICODE__)
420 wxArrayString m_subsetCtrlStrings
;
421 m_subsetCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_SUBSET
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, m_subsetCtrlStrings
, wxCB_READONLY
);
422 m_subsetCtrl
->SetHelpText(_("Shows a Unicode subset."));
423 if (wxSymbolPickerDialog::ShowToolTips())
424 m_subsetCtrl
->SetToolTip(_("Shows a Unicode subset."));
425 itemBoxSizer5
->Add(m_subsetCtrl
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
429 m_symbolsCtrl
= new wxSymbolListCtrl( itemDialog1
, ID_SYMBOLPICKERDIALOG_LISTCTRL
, wxDefaultPosition
, wxSize(500, 200), 0 );
430 itemBoxSizer3
->Add(m_symbolsCtrl
, 1, wxGROW
|wxALL
, 5);
432 wxBoxSizer
* itemBoxSizer12
= new wxBoxSizer(wxHORIZONTAL
);
433 itemBoxSizer3
->Add(itemBoxSizer12
, 0, wxGROW
, 5);
435 m_symbolStaticCtrl
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("xxxx"), wxDefaultPosition
, wxSize(40, -1), wxALIGN_CENTRE
);
436 itemBoxSizer12
->Add(m_symbolStaticCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
438 itemBoxSizer12
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
440 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Character code:"), wxDefaultPosition
, wxDefaultSize
, 0 );
441 itemBoxSizer12
->Add(itemStaticText15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
443 m_characterCodeCtrl
= new wxTextCtrl( itemDialog1
, ID_SYMBOLPICKERDIALOG_CHARACTERCODE
, wxEmptyString
, wxDefaultPosition
, wxSize(140, -1), wxTE_READONLY
|wxTE_CENTRE
);
444 m_characterCodeCtrl
->SetHelpText(_("The character code."));
445 if (wxSymbolPickerDialog::ShowToolTips())
446 m_characterCodeCtrl
->SetToolTip(_("The character code."));
447 itemBoxSizer12
->Add(m_characterCodeCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
449 itemBoxSizer12
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
451 #if defined(__UNICODE__)
452 wxStaticText
* itemStaticText18
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&From:"), wxDefaultPosition
, wxDefaultSize
, 0 );
453 itemBoxSizer12
->Add(itemStaticText18
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
457 #if defined(__UNICODE__)
458 wxArrayString m_fromUnicodeCtrlStrings
;
459 m_fromUnicodeCtrlStrings
.Add(_("ASCII"));
460 m_fromUnicodeCtrlStrings
.Add(_("Unicode"));
461 m_fromUnicodeCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_FROM
, _("Unicode"), wxDefaultPosition
, wxDefaultSize
, m_fromUnicodeCtrlStrings
, wxCB_READONLY
);
462 m_fromUnicodeCtrl
->SetStringSelection(_("Unicode"));
463 m_fromUnicodeCtrl
->SetHelpText(_("The range to show."));
464 if (wxSymbolPickerDialog::ShowToolTips())
465 m_fromUnicodeCtrl
->SetToolTip(_("The range to show."));
466 itemBoxSizer12
->Add(m_fromUnicodeCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
470 m_stdButtonSizer
= new wxStdDialogButtonSizer
;
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
);
477 wxButton
* itemButton22
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
478 m_stdButtonSizer
->AddButton(itemButton22
);
480 wxButton
* itemButton23
= new wxButton( itemDialog1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0 );
481 m_stdButtonSizer
->AddButton(itemButton23
);
483 m_stdButtonSizer
->Realize();
485 ////@end wxSymbolPickerDialog content construction
487 if (GetHelpId() == -1)
489 wxWindow
* button
= FindWindowById(wxID_HELP
);
491 m_stdButtonSizer
->Show(button
, false);
496 bool wxSymbolPickerDialog::TransferDataToWindow()
500 if (m_fontCtrl
->GetCount() == 0)
502 wxArrayString faceNames
= wxRichTextCtrl::GetAvailableFontNames();
505 faceNames
.Insert(_("(Normal text)"), 0);
506 m_fontCtrl
->Append(faceNames
);
509 if (m_fontName
.empty())
510 m_fontCtrl
->SetSelection(0);
513 if (m_fontCtrl
->FindString(m_fontName
) != wxNOT_FOUND
)
514 m_fontCtrl
->SetStringSelection(m_fontName
);
516 m_fontCtrl
->SetSelection(0);
519 #if defined(__UNICODE__)
520 if (m_subsetCtrl
->GetCount() == 0)
522 // Insert items into subset combo
524 for (i
= 0; i
< (int) WXSIZEOF(g_UnicodeSubsetTable
); i
++)
526 m_subsetCtrl
->Append(g_UnicodeSubsetTable
[i
].m_name
);
528 m_subsetCtrl
->SetSelection(0);
532 #if defined(__UNICODE__)
533 m_symbolsCtrl
->SetUnicodeMode(m_fromUnicode
);
536 if (!m_symbol
.empty())
538 int sel
= (int) m_symbol
[0];
539 m_symbolsCtrl
->SetSelection(sel
);
542 UpdateSymbolDisplay(true, m_symbol
.empty());
544 m_dontUpdate
= false;
549 void wxSymbolPickerDialog::UpdateSymbolDisplay(bool updateSymbolList
, bool showAtSubset
)
552 wxString fontNameToUse
;
553 if (m_fontName
.empty())
554 fontNameToUse
= m_normalTextFontName
;
556 fontNameToUse
= m_fontName
;
558 if (!fontNameToUse
.empty())
560 font
= wxFont(14, wxDEFAULT
, wxNORMAL
, wxNORMAL
, false, fontNameToUse
);
563 font
= *wxNORMAL_FONT
;
565 if (updateSymbolList
)
567 m_symbolsCtrl
->SetFont(font
);
570 if (!m_symbol
.empty())
572 m_symbolStaticCtrl
->SetFont(font
);
573 m_symbolStaticCtrl
->SetLabel(m_symbol
);
575 int symbol
= (int) m_symbol
[0];
576 m_characterCodeCtrl
->SetValue(wxString::Format(wxT("%X hex (%d dec)"), symbol
, symbol
));
580 m_symbolStaticCtrl
->SetLabel(wxEmptyString
);
581 m_characterCodeCtrl
->SetValue(wxEmptyString
);
584 #if defined(__UNICODE__)
588 wxUnusedVar(showAtSubset
);
592 /// Show at the current subset selection
593 void wxSymbolPickerDialog::ShowAtSubset()
595 #if defined(__UNICODE__)
598 int sel
= m_subsetCtrl
->GetSelection();
599 int low
= g_UnicodeSubsetTable
[sel
].m_low
;
600 m_symbolsCtrl
->EnsureVisible(low
);
605 // Handle font selection
606 void wxSymbolPickerDialog::OnFontCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
608 if (m_fontCtrl
->GetSelection() == 0)
609 m_fontName
= wxEmptyString
;
611 m_fontName
= m_fontCtrl
->GetStringSelection();
613 UpdateSymbolDisplay();
616 /// Respond to symbol selection
617 void wxSymbolPickerDialog::OnSymbolSelected( wxCommandEvent
& event
)
622 int sel
= event
.GetSelection();
623 if (sel
== wxNOT_FOUND
)
624 m_symbol
= wxEmptyString
;
627 m_symbol
= wxEmptyString
;
628 m_symbol
<< (wxChar
) sel
;
631 #if defined(__UNICODE__)
632 if (sel
!= -1 && m_fromUnicode
)
634 // Need to make the subset selection reflect the current symbol
636 for (i
= 0; i
< (int) WXSIZEOF(g_UnicodeSubsetTable
); i
++)
638 if (sel
>= g_UnicodeSubsetTable
[i
].m_low
&& sel
<= g_UnicodeSubsetTable
[i
].m_high
)
641 m_subsetCtrl
->SetSelection(i
);
642 m_dontUpdate
= false;
649 UpdateSymbolDisplay(false, false);
652 #if defined(__UNICODE__)
653 // Handle Unicode/ASCII selection
654 void wxSymbolPickerDialog::OnFromUnicodeSelected( wxCommandEvent
& WXUNUSED(event
) )
659 m_fromUnicode
= (m_fromUnicodeCtrl
->GetSelection() == 1);
660 m_symbolsCtrl
->SetUnicodeMode(m_fromUnicode
);
661 UpdateSymbolDisplay(false);
664 // Handle subset selection
665 void wxSymbolPickerDialog::OnSubsetSelected( wxCommandEvent
& WXUNUSED(event
) )
674 #if defined(__UNICODE__)
677 * wxEVT_UPDATE_UI event handler for ID_SYMBOLPICKERDIALOG_SUBSET
680 void wxSymbolPickerDialog::OnSymbolpickerdialogSubsetUpdate( wxUpdateUIEvent
& event
)
682 event
.Enable(m_fromUnicode
);
687 * wxEVT_UPDATE_UI event handler for wxID_OK
690 void wxSymbolPickerDialog::OnOkUpdate( wxUpdateUIEvent
& event
)
692 event
.Enable(HasSelection());
696 void wxSymbolPickerDialog::SetUnicodeMode(bool unicodeMode
)
698 #if defined(__UNICODE__)
700 m_fromUnicode
= unicodeMode
;
701 if (m_fromUnicodeCtrl
)
702 m_fromUnicodeCtrl
->SetSelection(m_fromUnicode
? 1 : 0);
703 UpdateSymbolDisplay();
704 m_dontUpdate
= false;
706 wxUnusedVar(unicodeMode
);
710 /// Get the selected symbol character
711 int wxSymbolPickerDialog::GetSymbolChar() const
713 if (m_symbol
.empty())
716 return (int) m_symbol
[0];
721 * Get bitmap resources
724 wxBitmap
wxSymbolPickerDialog::GetBitmapResource( const wxString
& name
)
727 ////@begin wxSymbolPickerDialog bitmap retrieval
730 ////@end wxSymbolPickerDialog bitmap retrieval
737 wxIcon
wxSymbolPickerDialog::GetIconResource( const wxString
& name
)
740 ////@begin wxSymbolPickerDialog icon retrieval
743 ////@end wxSymbolPickerDialog icon retrieval
747 * The scrolling symbol list.
750 // ----------------------------------------------------------------------------
752 // ----------------------------------------------------------------------------
754 BEGIN_EVENT_TABLE(wxSymbolListCtrl
, wxVScrolledWindow
)
755 EVT_PAINT(wxSymbolListCtrl::OnPaint
)
756 EVT_SIZE(wxSymbolListCtrl::OnSize
)
758 EVT_KEY_DOWN(wxSymbolListCtrl::OnKeyDown
)
759 EVT_LEFT_DOWN(wxSymbolListCtrl::OnLeftDown
)
760 EVT_LEFT_DCLICK(wxSymbolListCtrl::OnLeftDClick
)
763 // ============================================================================
765 // ============================================================================
767 IMPLEMENT_ABSTRACT_CLASS(wxSymbolListCtrl
, wxVScrolledWindow
)
769 // ----------------------------------------------------------------------------
770 // wxSymbolListCtrl creation
771 // ----------------------------------------------------------------------------
773 void wxSymbolListCtrl::Init()
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;
784 bool wxSymbolListCtrl::Create(wxWindow
*parent
,
789 const wxString
& name
)
791 style
|= wxWANTS_CHARS
| wxFULL_REPAINT_ON_RESIZE
;
793 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
794 style
|= wxBORDER_THEME
;
796 if ( !wxVScrolledWindow::Create(parent
, id
, pos
, size
, style
, name
) )
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
);
804 // flicker-free drawing requires this
805 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
807 SetFont(*wxNORMAL_FONT
);
811 SetInitialSize(size
);
816 wxSymbolListCtrl::~wxSymbolListCtrl()
818 delete m_doubleBuffer
;
821 // ----------------------------------------------------------------------------
822 // selection handling
823 // ----------------------------------------------------------------------------
825 bool wxSymbolListCtrl::IsSelected(int item
) const
827 return item
== m_current
;
830 bool wxSymbolListCtrl::DoSetCurrent(int current
)
832 wxASSERT_MSG( current
== wxNOT_FOUND
||
833 (current
>= m_minSymbolValue
&& current
<= m_maxSymbolValue
),
834 wxT("wxSymbolListCtrl::DoSetCurrent(): invalid symbol value") );
836 if ( current
== m_current
)
842 if ( m_current
!= wxNOT_FOUND
)
843 RefreshRow(SymbolValueToLineNumber(m_current
));
847 if ( m_current
!= wxNOT_FOUND
)
849 int lineNo
= SymbolValueToLineNumber(m_current
);
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
) )
857 else // line is at least partly visible
859 // it is, indeed, only partly visible, so scroll it into view to
860 // make it entirely visible
861 while ( (unsigned)lineNo
+ 1 == GetVisibleEnd() &&
862 ScrollToRow(GetVisibleBegin() + 1) )
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
874 void wxSymbolListCtrl::SendSelectedEvent()
876 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, GetId());
877 event
.SetEventObject(this);
878 event
.SetInt(m_current
);
880 (void)GetEventHandler()->ProcessEvent(event
);
883 void wxSymbolListCtrl::SetSelection(int selection
)
885 wxCHECK_RET( selection
== wxNOT_FOUND
||
886 (selection
>= m_minSymbolValue
&& selection
< m_maxSymbolValue
),
887 wxT("wxSymbolListCtrl::SetSelection(): invalid symbol value") );
889 DoSetCurrent(selection
);
892 // ----------------------------------------------------------------------------
893 // wxSymbolListCtrl appearance parameters
894 // ----------------------------------------------------------------------------
896 void wxSymbolListCtrl::SetMargins(const wxPoint
& pt
)
898 if ( pt
!= m_ptMargins
)
906 void wxSymbolListCtrl::SetSelectionBackground(const wxColour
& col
)
911 // ----------------------------------------------------------------------------
912 // wxSymbolListCtrl painting
913 // ----------------------------------------------------------------------------
915 wxCoord
wxSymbolListCtrl::OnGetRowHeight(size_t WXUNUSED(line
)) const
917 return m_cellSize
.y
+ 2*m_ptMargins
.y
+ 1 /* for divider */ ;
920 // draws a line of symbols
921 void wxSymbolListCtrl::OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
923 wxColour oldTextColour
= dc
.GetTextForeground();
924 int startSymbol
= n
*m_symbolsPerLine
;
927 for (i
= 0; i
< m_symbolsPerLine
; i
++)
929 bool resetColour
= false;
930 int symbol
= startSymbol
+i
;
931 if (symbol
== m_current
)
933 dc
.SetBrush(wxBrush(m_colBgSel
));
935 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
938 wxPen oldPen
= dc
.GetPen();
939 dc
.SetPen(*wxTRANSPARENT_PEN
);
941 dc
.DrawRectangle(rect
.x
+ i
*m_cellSize
.x
, rect
.y
, m_cellSize
.x
, rect
.y
+rect
.height
);
945 // Don't draw first line
947 dc
.DrawLine(rect
.x
+ i
*m_cellSize
.x
, rect
.y
, i
*m_cellSize
.x
, rect
.y
+rect
.height
);
949 if (symbol
>= m_minSymbolValue
&& symbol
<= m_maxSymbolValue
)
952 text
<< (wxChar
) symbol
;
955 dc
.GetTextExtent(text
, & w
, & h
);
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
);
963 dc
.SetTextForeground(oldTextColour
);
966 // Draw horizontal separator line
967 dc
.DrawLine(rect
.x
, rect
.y
+rect
.height
-1, rect
.x
+rect
.width
, rect
.y
+rect
.height
-1);
970 void wxSymbolListCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
972 // If size is larger, recalculate double buffer bitmap
973 wxSize clientSize
= GetClientSize();
975 if ( !m_doubleBuffer
||
976 clientSize
.x
> m_doubleBuffer
->GetWidth() ||
977 clientSize
.y
> m_doubleBuffer
->GetHeight() )
979 delete m_doubleBuffer
;
980 m_doubleBuffer
= new wxBitmap(clientSize
.x
+25,clientSize
.y
+25);
983 wxBufferedPaintDC
dc(this,*m_doubleBuffer
);
985 // the update rectangle
986 wxRect rectUpdate
= GetUpdateClientRect();
988 // fill it with background colour
989 dc
.SetBackground(GetBackgroundColour());
992 // set the font to be displayed
993 dc
.SetFont(GetFont());
995 // the bounding rectangle of the current line
997 rectRow
.width
= clientSize
.x
;
999 dc
.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
)));
1000 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1001 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1003 // iterate over all visible lines
1004 const size_t lineMax
= GetVisibleEnd();
1005 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
1007 const wxCoord hRow
= OnGetRowHeight(line
);
1009 rectRow
.height
= hRow
;
1011 // and draw the ones which intersect the update rect
1012 if ( rectRow
.Intersects(rectUpdate
) )
1014 // don't allow drawing outside of the lines rectangle
1015 wxDCClipper
clip(dc
, rectRow
);
1017 wxRect rect
= rectRow
;
1018 rect
.Deflate(m_ptMargins
.x
, m_ptMargins
.y
);
1019 OnDrawItem(dc
, rect
, line
);
1021 else // no intersection
1023 if ( rectRow
.GetTop() > rectUpdate
.GetBottom() )
1025 // we are already below the update rect, no need to continue
1029 //else: the next line may intersect the update rect
1036 // ============================================================================
1037 // wxSymbolListCtrl keyboard/mouse handling
1038 // ============================================================================
1040 void wxSymbolListCtrl::DoHandleItemClick(int item
, int WXUNUSED(flags
))
1042 if (m_current
!= item
)
1046 SendSelectedEvent();
1050 // ----------------------------------------------------------------------------
1051 // keyboard handling
1052 // ----------------------------------------------------------------------------
1054 void wxSymbolListCtrl::OnKeyDown(wxKeyEvent
& event
)
1056 // No keyboard interface for now
1059 // flags for DoHandleItemClick()
1060 int flags
= ItemClick_Kbd
;
1062 int currentLineNow
= SymbolValueToLineNumber(m_current
);
1065 switch ( event
.GetKeyCode() )
1072 currentLine
= GetLineCount() - 1;
1076 if ( currentLineNow
== (int)GetLineCount() - 1 )
1079 currentLine
= currentLineNow
+ 1;
1083 if ( m_current
== wxNOT_FOUND
)
1084 currentLine
= GetLineCount() - 1;
1085 else if ( currentLineNow
!= 0 )
1086 currentLine
= currentLineNow
- 1;
1087 else // currentLineNow == 0
1093 currentLine
= GetFirstVisibleLine();
1097 if ( currentLineNow
== (int)GetFirstVisibleLine() )
1102 currentLine
= GetFirstVisibleLine();
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
;
1115 // Since we are using wxWANTS_CHARS we need to send navigation
1116 // events for the tabs on MSW
1118 wxNavigationKeyEvent ne
;
1119 ne
.SetDirection(!event
.ShiftDown());
1120 ne
.SetCurrentFocus(this);
1121 ne
.SetEventObject(this);
1122 GetParent()->GetEventHandler()->ProcessEvent(ne
);
1124 // fall through to default
1128 currentLine
= 0; // just to silent the stupid compiler warnings
1129 wxUnusedVar(currentNow
);
1134 if ( event
.ShiftDown() )
1135 flags
|= ItemClick_Shift
;
1136 if ( event
.ControlDown() )
1137 flags
|= ItemClick_Ctrl
;
1139 DoHandleItemClick(current
, flags
);
1144 // ----------------------------------------------------------------------------
1145 // wxSymbolListCtrl mouse handling
1146 // ----------------------------------------------------------------------------
1148 void wxSymbolListCtrl::OnLeftDown(wxMouseEvent
& event
)
1152 int item
= HitTest(event
.GetPosition());
1154 if ( item
!= wxNOT_FOUND
)
1157 if ( event
.ShiftDown() )
1158 flags
|= ItemClick_Shift
;
1160 // under Mac Apple-click is used in the same way as Ctrl-click
1163 if ( event
.MetaDown() )
1165 if ( event
.ControlDown() )
1167 flags
|= ItemClick_Ctrl
;
1169 DoHandleItemClick(item
, flags
);
1173 void wxSymbolListCtrl::OnLeftDClick(wxMouseEvent
& eventMouse
)
1175 int item
= HitTest(eventMouse
.GetPosition());
1176 if ( item
!= wxNOT_FOUND
)
1179 // if item double-clicked was not yet selected, then treat
1180 // this event as a left-click instead
1181 if ( item
== m_current
)
1183 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, GetId());
1184 event
.SetEventObject(this);
1187 (void)GetEventHandler()->ProcessEvent(event
);
1191 OnLeftDown(eventMouse
);
1197 // calculate line number from symbol value
1198 int wxSymbolListCtrl::SymbolValueToLineNumber(int item
)
1200 return (int) (item
/m_symbolsPerLine
);
1203 // initialise control from current min/max values
1204 void wxSymbolListCtrl::SetupCtrl(bool scrollToSelection
)
1206 wxSize sz
= GetClientSize();
1208 m_symbolsPerLine
= sz
.x
/(m_cellSize
.x
+m_ptMargins
.x
);
1209 int noLines
= (1 + SymbolValueToLineNumber(m_maxSymbolValue
));
1211 SetRowCount(noLines
);
1214 if (scrollToSelection
&& m_current
!= wxNOT_FOUND
&& m_current
>= m_minSymbolValue
&& m_current
<= m_maxSymbolValue
)
1216 ScrollToRow(SymbolValueToLineNumber(m_current
));
1220 // make this item visible
1221 void wxSymbolListCtrl::EnsureVisible(int item
)
1223 if (item
!= wxNOT_FOUND
&& item
>= m_minSymbolValue
&& item
<= m_maxSymbolValue
)
1225 ScrollToRow(SymbolValueToLineNumber(item
));
1231 int wxSymbolListCtrl::HitTest(const wxPoint
& pt
)
1233 wxCoord lineHeight
= OnGetRowHeight(0);
1235 int atLine
= GetVisibleBegin() + (pt
.y
/lineHeight
);
1236 int symbol
= (atLine
*m_symbolsPerLine
) + (pt
.x
/(m_cellSize
.x
+1));
1238 if (symbol
>= m_minSymbolValue
&& symbol
<= m_maxSymbolValue
)
1244 // Respond to size change
1245 void wxSymbolListCtrl::OnSize(wxSizeEvent
& event
)
1251 // set the current font
1252 bool wxSymbolListCtrl::SetFont(const wxFont
& font
)
1254 wxVScrolledWindow::SetFont(font
);
1261 // set Unicode/ASCII mode
1262 void wxSymbolListCtrl::SetUnicodeMode(bool unicodeMode
)
1264 bool changed
= false;
1265 if (unicodeMode
&& !m_unicodeMode
)
1269 m_minSymbolValue
= 0;
1270 m_maxSymbolValue
= 65535;
1272 else if (!unicodeMode
&& m_unicodeMode
)
1275 m_minSymbolValue
= 0;
1276 m_maxSymbolValue
= 255;
1278 m_unicodeMode
= unicodeMode
;
1284 // ----------------------------------------------------------------------------
1285 // use the same default attributes as wxListBox
1286 // ----------------------------------------------------------------------------
1290 wxSymbolListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
1292 return wxListBox::GetClassDefaultAttributes(variant
);
1295 #endif // wxUSE_RICHTEXT