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 EVT_UPDATE_UI( wxID_OK
, wxSymbolPickerDialog::OnOkUpdate
)
307 ////@end wxSymbolPickerDialog event table entries
312 * wxSymbolPickerDialog constructors
315 wxSymbolPickerDialog::wxSymbolPickerDialog( )
320 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
)
323 Create(symbol
, fontName
, normalTextFont
, parent
, id
, caption
, pos
, size
, style
);
327 * wxSymbolPickerDialog creator
330 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
)
332 m_fontName
= fontName
;
333 m_normalTextFontName
= normalTextFont
;
336 ////@begin wxSymbolPickerDialog creation
337 SetExtraStyle(wxWS_EX_BLOCK_EVENTS
|wxDIALOG_EX_CONTEXTHELP
);
338 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
343 GetSizer()->SetSizeHints(this);
346 ////@end wxSymbolPickerDialog creation
351 * Member initialisation for wxSymbolPickerDialog
354 void wxSymbolPickerDialog::Init()
356 ////@begin wxSymbolPickerDialog member initialisation
357 m_fromUnicode
= true;
359 #if defined(__UNICODE__)
362 m_symbolsCtrl
= NULL
;
363 m_symbolStaticCtrl
= NULL
;
364 m_characterCodeCtrl
= NULL
;
365 #if defined(__UNICODE__)
366 m_fromUnicodeCtrl
= NULL
;
368 ////@end wxSymbolPickerDialog member initialisation
369 m_dontUpdate
= false;
373 * Control creation for wxSymbolPickerDialog
376 void wxSymbolPickerDialog::CreateControls()
378 ////@begin wxSymbolPickerDialog content construction
379 wxSymbolPickerDialog
* itemDialog1
= this;
381 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
382 itemDialog1
->SetSizer(itemBoxSizer2
);
384 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
385 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
387 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
388 itemBoxSizer3
->Add(itemBoxSizer4
, 0, wxGROW
, 5);
390 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxHORIZONTAL
);
391 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
393 wxStaticText
* itemStaticText6
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Font:"), wxDefaultPosition
, wxDefaultSize
, 0 );
394 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
396 wxArrayString m_fontCtrlStrings
;
397 m_fontCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_FONT
, _T(""), wxDefaultPosition
, wxSize(240, -1), m_fontCtrlStrings
, wxCB_READONLY
);
398 m_fontCtrl
->SetHelpText(_("The font from which to take the symbol."));
399 if (wxSymbolPickerDialog::ShowToolTips())
400 m_fontCtrl
->SetToolTip(_("The font from which to take the symbol."));
401 itemBoxSizer5
->Add(m_fontCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
403 itemBoxSizer5
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
405 #if defined(__UNICODE__)
406 wxStaticText
* itemStaticText9
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Subset:"), wxDefaultPosition
, wxDefaultSize
, 0 );
407 itemBoxSizer5
->Add(itemStaticText9
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
411 #if defined(__UNICODE__)
412 wxArrayString m_subsetCtrlStrings
;
413 m_subsetCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_SUBSET
, _T(""), wxDefaultPosition
, wxDefaultSize
, m_subsetCtrlStrings
, wxCB_READONLY
);
414 m_subsetCtrl
->SetHelpText(_("Shows a Unicode subset."));
415 if (wxSymbolPickerDialog::ShowToolTips())
416 m_subsetCtrl
->SetToolTip(_("Shows a Unicode subset."));
417 itemBoxSizer5
->Add(m_subsetCtrl
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
421 m_symbolsCtrl
= new wxSymbolListCtrl( itemDialog1
, ID_SYMBOLPICKERDIALOG_LISTCTRL
, wxDefaultPosition
, wxSize(500, 200), 0 );
422 itemBoxSizer3
->Add(m_symbolsCtrl
, 1, wxGROW
|wxALL
, 5);
424 wxBoxSizer
* itemBoxSizer12
= new wxBoxSizer(wxHORIZONTAL
);
425 itemBoxSizer3
->Add(itemBoxSizer12
, 0, wxGROW
, 5);
427 m_symbolStaticCtrl
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("xxxx"), wxDefaultPosition
, wxSize(40, -1), wxALIGN_CENTRE
);
428 itemBoxSizer12
->Add(m_symbolStaticCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
430 itemBoxSizer12
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
432 wxStaticText
* itemStaticText15
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&Character code:"), wxDefaultPosition
, wxDefaultSize
, 0 );
433 itemBoxSizer12
->Add(itemStaticText15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
435 m_characterCodeCtrl
= new wxTextCtrl( itemDialog1
, ID_SYMBOLPICKERDIALOG_CHARACTERCODE
, _T(""), wxDefaultPosition
, wxSize(140, -1), wxTE_READONLY
|wxTE_CENTRE
);
436 m_characterCodeCtrl
->SetHelpText(_("The character code."));
437 if (wxSymbolPickerDialog::ShowToolTips())
438 m_characterCodeCtrl
->SetToolTip(_("The character code."));
439 itemBoxSizer12
->Add(m_characterCodeCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
441 itemBoxSizer12
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
443 #if defined(__UNICODE__)
444 wxStaticText
* itemStaticText18
= new wxStaticText( itemDialog1
, wxID_STATIC
, _("&From:"), wxDefaultPosition
, wxDefaultSize
, 0 );
445 itemBoxSizer12
->Add(itemStaticText18
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
449 #if defined(__UNICODE__)
450 wxArrayString m_fromUnicodeCtrlStrings
;
451 m_fromUnicodeCtrlStrings
.Add(_("ASCII"));
452 m_fromUnicodeCtrlStrings
.Add(_("Unicode"));
453 m_fromUnicodeCtrl
= new wxComboBox( itemDialog1
, ID_SYMBOLPICKERDIALOG_FROM
, _("ASCII"), wxDefaultPosition
, wxDefaultSize
, m_fromUnicodeCtrlStrings
, wxCB_READONLY
);
454 m_fromUnicodeCtrl
->SetStringSelection(_("ASCII"));
455 m_fromUnicodeCtrl
->SetHelpText(_("The range to show."));
456 if (wxSymbolPickerDialog::ShowToolTips())
457 m_fromUnicodeCtrl
->SetToolTip(_("The range to show."));
458 itemBoxSizer12
->Add(m_fromUnicodeCtrl
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
462 wxBoxSizer
* itemBoxSizer20
= new wxBoxSizer(wxHORIZONTAL
);
463 itemBoxSizer3
->Add(itemBoxSizer20
, 0, wxGROW
, 5);
465 itemBoxSizer20
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
467 wxStdDialogButtonSizer
* itemStdDialogButtonSizer22
= new wxStdDialogButtonSizer
;
469 itemBoxSizer20
->Add(itemStdDialogButtonSizer22
, 0, wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
, 5);
470 wxButton
* itemButton23
= new wxButton( itemDialog1
, wxID_OK
, _("Insert"), wxDefaultPosition
, wxDefaultSize
, 0 );
471 itemButton23
->SetDefault();
472 itemStdDialogButtonSizer22
->AddButton(itemButton23
);
474 wxButton
* itemButton24
= new wxButton( itemDialog1
, wxID_CANCEL
, _("Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
475 itemStdDialogButtonSizer22
->AddButton(itemButton24
);
477 itemStdDialogButtonSizer22
->Realize();
479 ////@end wxSymbolPickerDialog content construction
484 bool wxSymbolPickerDialog::TransferDataToWindow()
488 if (m_fontCtrl
->GetCount() == 0)
490 wxArrayString faceNames
= wxRichTextCtrl::GetAvailableFontNames();
493 faceNames
.Insert(_("(Normal text)"), 0);
494 m_fontCtrl
->Append(faceNames
);
497 if (m_fontName
.empty())
498 m_fontCtrl
->SetSelection(0);
501 if (m_fontCtrl
->FindString(m_fontName
) != wxNOT_FOUND
)
502 m_fontCtrl
->SetStringSelection(m_fontName
);
504 m_fontCtrl
->SetSelection(0);
507 if (!m_symbol
.empty())
509 int sel
= (int) m_symbol
[0];
510 m_symbolsCtrl
->SetSelection(sel
);
513 #if defined(__UNICODE__)
514 if (m_subsetCtrl
->GetCount() == 0)
516 // Insert items into subset combo
518 for (i
= 0; i
< (int) (sizeof(g_UnicodeSubsetTable
)/sizeof(g_UnicodeSubsetTable
[0])); i
++)
520 m_subsetCtrl
->Append(g_UnicodeSubsetTable
[i
].m_name
);
522 m_subsetCtrl
->SetSelection(0);
526 UpdateSymbolDisplay();
528 m_dontUpdate
= false;
533 void wxSymbolPickerDialog::UpdateSymbolDisplay(bool updateSymbolList
, bool showAtSubset
)
536 wxString fontNameToUse
;
537 if (m_fontName
.empty())
538 fontNameToUse
= m_normalTextFontName
;
540 fontNameToUse
= m_fontName
;
542 if (!fontNameToUse
.empty())
544 font
= wxFont(14, wxDEFAULT
, wxNORMAL
, wxNORMAL
, false, fontNameToUse
);
547 font
= *wxNORMAL_FONT
;
549 if (updateSymbolList
)
551 m_symbolsCtrl
->SetFont(font
);
554 if (!m_symbol
.empty())
556 m_symbolStaticCtrl
->SetFont(font
);
557 m_symbolStaticCtrl
->SetLabel(m_symbol
);
559 int symbol
= (int) m_symbol
[0];
560 m_characterCodeCtrl
->SetValue(wxString::Format(wxT("%X hex (%d dec)"), symbol
, symbol
));
564 m_symbolStaticCtrl
->SetLabel(wxEmptyString
);
565 m_characterCodeCtrl
->SetValue(wxEmptyString
);
568 #if defined(__UNICODE__)
572 wxUnusedVar(showAtSubset
);
576 /// Show at the current subset selection
577 void wxSymbolPickerDialog::ShowAtSubset()
579 #if defined(__UNICODE__)
582 int sel
= m_subsetCtrl
->GetSelection();
583 int low
= g_UnicodeSubsetTable
[sel
].m_low
;
584 m_symbolsCtrl
->EnsureVisible(low
);
589 // Handle font selection
590 void wxSymbolPickerDialog::OnFontCtrlSelected( wxCommandEvent
& WXUNUSED(event
) )
592 if (m_fontCtrl
->GetSelection() == 0)
593 m_fontName
= wxEmptyString
;
595 m_fontName
= m_fontCtrl
->GetStringSelection();
597 UpdateSymbolDisplay();
600 /// Respond to symbol selection
601 void wxSymbolPickerDialog::OnSymbolSelected( wxCommandEvent
& event
)
606 int sel
= event
.GetSelection();
607 if (sel
== wxNOT_FOUND
)
608 m_symbol
= wxEmptyString
;
611 m_symbol
= wxEmptyString
;
612 m_symbol
<< (wxChar
) sel
;
615 #if defined(__UNICODE__)
616 if (sel
!= -1 && m_fromUnicode
)
618 // Need to make the subset selection reflect the current symbol
620 for (i
= 0; i
< (int) (sizeof(g_UnicodeSubsetTable
)/sizeof(g_UnicodeSubsetTable
[0])); i
++)
622 if (sel
>= g_UnicodeSubsetTable
[i
].m_low
&& sel
<= g_UnicodeSubsetTable
[i
].m_high
)
625 m_subsetCtrl
->SetSelection(i
);
626 m_dontUpdate
= false;
633 UpdateSymbolDisplay(false, false);
636 #if defined(__UNICODE__)
637 // Handle Unicode/ASCII selection
638 void wxSymbolPickerDialog::OnFromUnicodeSelected( wxCommandEvent
& WXUNUSED(event
) )
643 m_fromUnicode
= (m_fromUnicodeCtrl
->GetSelection() == 1);
644 m_symbolsCtrl
->SetUnicodeMode(m_fromUnicode
);
645 UpdateSymbolDisplay(false);
648 // Handle subset selection
649 void wxSymbolPickerDialog::OnSubsetSelected( wxCommandEvent
& WXUNUSED(event
) )
659 * wxEVT_UPDATE_UI event handler for wxID_OK
662 void wxSymbolPickerDialog::OnOkUpdate( wxUpdateUIEvent
& event
)
664 event
.Enable(HasSelection());
668 void wxSymbolPickerDialog::SetUnicodeMode(bool unicodeMode
)
670 #if defined(__UNICODE__)
672 m_fromUnicode
= unicodeMode
;
673 if (m_fromUnicodeCtrl
)
674 m_fromUnicodeCtrl
->SetSelection(m_fromUnicode
? 1 : 0);
675 UpdateSymbolDisplay();
676 m_dontUpdate
= false;
678 wxUnusedVar(unicodeMode
);
682 /// Get the selected symbol character
683 int wxSymbolPickerDialog::GetSymbolChar() const
685 if (m_symbol
.empty())
688 return (int) m_symbol
[0];
693 * Get bitmap resources
696 wxBitmap
wxSymbolPickerDialog::GetBitmapResource( const wxString
& name
)
699 ////@begin wxSymbolPickerDialog bitmap retrieval
702 ////@end wxSymbolPickerDialog bitmap retrieval
709 wxIcon
wxSymbolPickerDialog::GetIconResource( const wxString
& name
)
712 ////@begin wxSymbolPickerDialog icon retrieval
715 ////@end wxSymbolPickerDialog icon retrieval
719 * The scrolling symbol list.
722 // ----------------------------------------------------------------------------
724 // ----------------------------------------------------------------------------
726 BEGIN_EVENT_TABLE(wxSymbolListCtrl
, wxVScrolledWindow
)
727 EVT_PAINT(wxSymbolListCtrl::OnPaint
)
728 EVT_SIZE(wxSymbolListCtrl::OnSize
)
730 EVT_KEY_DOWN(wxSymbolListCtrl::OnKeyDown
)
731 EVT_LEFT_DOWN(wxSymbolListCtrl::OnLeftDown
)
732 EVT_LEFT_DCLICK(wxSymbolListCtrl::OnLeftDClick
)
735 // ============================================================================
737 // ============================================================================
739 IMPLEMENT_ABSTRACT_CLASS(wxSymbolListCtrl
, wxVScrolledWindow
)
741 // ----------------------------------------------------------------------------
742 // wxSymbolListCtrl creation
743 // ----------------------------------------------------------------------------
745 void wxSymbolListCtrl::Init()
747 m_current
= wxNOT_FOUND
;
748 m_doubleBuffer
= NULL
;
749 m_cellSize
= wxSize(40, 40);
750 m_minSymbolValue
= 0;
751 m_maxSymbolValue
= 255;
752 m_symbolsPerLine
= 0;
753 m_unicodeMode
= false;
756 bool wxSymbolListCtrl::Create(wxWindow
*parent
,
761 const wxString
& name
)
763 style
|= wxWANTS_CHARS
| wxFULL_REPAINT_ON_RESIZE
;
765 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
766 style
|= wxBORDER_THEME
;
768 if ( !wxVScrolledWindow::Create(parent
, id
, pos
, size
, style
, name
) )
771 // make sure the native widget has the right colour since we do
772 // transparent drawing by default
773 SetBackgroundColour(GetBackgroundColour());
774 m_colBgSel
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
776 // flicker-free drawing requires this
777 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
779 SetFont(*wxNORMAL_FONT
);
786 wxSymbolListCtrl::~wxSymbolListCtrl()
788 delete m_doubleBuffer
;
791 // ----------------------------------------------------------------------------
792 // selection handling
793 // ----------------------------------------------------------------------------
795 bool wxSymbolListCtrl::IsSelected(int item
) const
797 return item
== m_current
;
800 bool wxSymbolListCtrl::DoSetCurrent(int current
)
802 wxASSERT_MSG( current
== wxNOT_FOUND
||
803 (current
>= m_minSymbolValue
&& current
<= m_maxSymbolValue
),
804 _T("wxSymbolListCtrl::DoSetCurrent(): invalid symbol value") );
806 if ( current
== m_current
)
812 if ( m_current
!= wxNOT_FOUND
)
813 RefreshRow(SymbolValueToLineNumber(m_current
));
817 if ( m_current
!= wxNOT_FOUND
)
819 int lineNo
= SymbolValueToLineNumber(m_current
);
821 // if the line is not visible at all, we scroll it into view but we
822 // don't need to refresh it -- it will be redrawn anyhow
823 if ( !IsVisible(lineNo
) )
827 else // line is at least partly visible
829 // it is, indeed, only partly visible, so scroll it into view to
830 // make it entirely visible
831 while ( (unsigned)lineNo
+ 1 == GetVisibleEnd() &&
832 ScrollToRow(GetVisibleBegin() + 1) )
835 // but in any case refresh it as even if it was only partly visible
836 // before we need to redraw it entirely as its background changed
844 void wxSymbolListCtrl::SendSelectedEvent()
846 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, GetId());
847 event
.SetEventObject(this);
848 event
.SetInt(m_current
);
850 (void)GetEventHandler()->ProcessEvent(event
);
853 void wxSymbolListCtrl::SetSelection(int selection
)
855 wxCHECK_RET( selection
== wxNOT_FOUND
||
856 (selection
>= m_minSymbolValue
&& selection
< m_maxSymbolValue
),
857 _T("wxSymbolListCtrl::SetSelection(): invalid symbol value") );
859 DoSetCurrent(selection
);
862 // ----------------------------------------------------------------------------
863 // wxSymbolListCtrl appearance parameters
864 // ----------------------------------------------------------------------------
866 void wxSymbolListCtrl::SetMargins(const wxPoint
& pt
)
868 if ( pt
!= m_ptMargins
)
876 void wxSymbolListCtrl::SetSelectionBackground(const wxColour
& col
)
881 // ----------------------------------------------------------------------------
882 // wxSymbolListCtrl painting
883 // ----------------------------------------------------------------------------
885 wxCoord
wxSymbolListCtrl::OnGetRowHeight(size_t WXUNUSED(line
)) const
887 return m_cellSize
.y
+ 2*m_ptMargins
.y
+ 1 /* for divider */ ;
890 // draws a line of symbols
891 void wxSymbolListCtrl::OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const
893 wxColour oldTextColour
= dc
.GetTextForeground();
894 int startSymbol
= n
*m_symbolsPerLine
;
897 for (i
= 0; i
< m_symbolsPerLine
; i
++)
899 bool resetColour
= false;
900 int symbol
= startSymbol
+i
;
901 if (symbol
== m_current
)
903 dc
.SetBrush(wxBrush(m_colBgSel
));
905 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
908 wxPen oldPen
= dc
.GetPen();
909 dc
.SetPen(*wxTRANSPARENT_PEN
);
911 dc
.DrawRectangle(rect
.x
+ i
*m_cellSize
.x
, rect
.y
, m_cellSize
.x
, rect
.y
+rect
.height
);
915 // Don't draw first line
917 dc
.DrawLine(rect
.x
+ i
*m_cellSize
.x
, rect
.y
, i
*m_cellSize
.x
, rect
.y
+rect
.height
);
919 if (symbol
>= m_minSymbolValue
&& symbol
<= m_maxSymbolValue
)
922 text
<< (wxChar
) symbol
;
925 dc
.GetTextExtent(text
, & w
, & h
);
927 int x
= rect
.x
+ i
*m_cellSize
.x
+ (m_cellSize
.x
- w
)/2;
928 int y
= rect
.y
+ (m_cellSize
.y
- h
)/2;
929 dc
.DrawText(text
, x
, y
);
933 dc
.SetTextForeground(oldTextColour
);
936 // Draw horizontal separator line
937 dc
.DrawLine(rect
.x
, rect
.y
+rect
.height
-1, rect
.x
+rect
.width
, rect
.y
+rect
.height
-1);
940 void wxSymbolListCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
942 // If size is larger, recalculate double buffer bitmap
943 wxSize clientSize
= GetClientSize();
945 if ( !m_doubleBuffer
||
946 clientSize
.x
> m_doubleBuffer
->GetWidth() ||
947 clientSize
.y
> m_doubleBuffer
->GetHeight() )
949 delete m_doubleBuffer
;
950 m_doubleBuffer
= new wxBitmap(clientSize
.x
+25,clientSize
.y
+25);
953 wxBufferedPaintDC
dc(this,*m_doubleBuffer
);
955 // the update rectangle
956 wxRect rectUpdate
= GetUpdateClientRect();
958 // fill it with background colour
959 dc
.SetBackground(GetBackgroundColour());
962 // set the font to be displayed
963 dc
.SetFont(GetFont());
965 // the bounding rectangle of the current line
967 rectRow
.width
= clientSize
.x
;
969 dc
.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
)));
970 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
971 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
973 // iterate over all visible lines
974 const size_t lineMax
= GetVisibleEnd();
975 for ( size_t line
= GetVisibleBegin(); line
< lineMax
; line
++ )
977 const wxCoord hRow
= OnGetRowHeight(line
);
979 rectRow
.height
= hRow
;
981 // and draw the ones which intersect the update rect
982 if ( rectRow
.Intersects(rectUpdate
) )
984 // don't allow drawing outside of the lines rectangle
985 wxDCClipper
clip(dc
, rectRow
);
987 wxRect rect
= rectRow
;
988 rect
.Deflate(m_ptMargins
.x
, m_ptMargins
.y
);
989 OnDrawItem(dc
, rect
, line
);
991 else // no intersection
993 if ( rectRow
.GetTop() > rectUpdate
.GetBottom() )
995 // we are already below the update rect, no need to continue
999 //else: the next line may intersect the update rect
1006 // ============================================================================
1007 // wxSymbolListCtrl keyboard/mouse handling
1008 // ============================================================================
1010 void wxSymbolListCtrl::DoHandleItemClick(int item
, int WXUNUSED(flags
))
1012 if (m_current
!= item
)
1016 SendSelectedEvent();
1020 // ----------------------------------------------------------------------------
1021 // keyboard handling
1022 // ----------------------------------------------------------------------------
1024 void wxSymbolListCtrl::OnKeyDown(wxKeyEvent
& event
)
1026 // No keyboard interface for now
1029 // flags for DoHandleItemClick()
1030 int flags
= ItemClick_Kbd
;
1032 int currentLineNow
= SymbolValueToLineNumber(m_current
);
1035 switch ( event
.GetKeyCode() )
1042 currentLine
= GetLineCount() - 1;
1046 if ( currentLineNow
== (int)GetLineCount() - 1 )
1049 currentLine
= currentLineNow
+ 1;
1053 if ( m_current
== wxNOT_FOUND
)
1054 currentLine
= GetLineCount() - 1;
1055 else if ( currentLineNow
!= 0 )
1056 currentLine
= currentLineNow
- 1;
1057 else // currentLineNow == 0
1063 currentLine
= GetFirstVisibleLine();
1067 if ( currentLineNow
== (int)GetFirstVisibleLine() )
1072 currentLine
= GetFirstVisibleLine();
1076 // hack: pressing space should work like a mouse click rather than
1077 // like a keyboard arrow press, so trick DoHandleItemClick() in
1078 // thinking we were clicked
1079 flags
&= ~ItemClick_Kbd
;
1080 currentLine
= currentLineNow
;
1085 // Since we are using wxWANTS_CHARS we need to send navigation
1086 // events for the tabs on MSW
1088 wxNavigationKeyEvent ne
;
1089 ne
.SetDirection(!event
.ShiftDown());
1090 ne
.SetCurrentFocus(this);
1091 ne
.SetEventObject(this);
1092 GetParent()->GetEventHandler()->ProcessEvent(ne
);
1094 // fall through to default
1098 currentLine
= 0; // just to silent the stupid compiler warnings
1099 wxUnusedVar(currentNow
);
1104 if ( event
.ShiftDown() )
1105 flags
|= ItemClick_Shift
;
1106 if ( event
.ControlDown() )
1107 flags
|= ItemClick_Ctrl
;
1109 DoHandleItemClick(current
, flags
);
1114 // ----------------------------------------------------------------------------
1115 // wxSymbolListCtrl mouse handling
1116 // ----------------------------------------------------------------------------
1118 void wxSymbolListCtrl::OnLeftDown(wxMouseEvent
& event
)
1122 int item
= HitTest(event
.GetPosition());
1124 if ( item
!= wxNOT_FOUND
)
1127 if ( event
.ShiftDown() )
1128 flags
|= ItemClick_Shift
;
1130 // under Mac Apple-click is used in the same way as Ctrl-click
1133 if ( event
.MetaDown() )
1135 if ( event
.ControlDown() )
1137 flags
|= ItemClick_Ctrl
;
1139 DoHandleItemClick(item
, flags
);
1143 void wxSymbolListCtrl::OnLeftDClick(wxMouseEvent
& eventMouse
)
1145 int item
= HitTest(eventMouse
.GetPosition());
1146 if ( item
!= wxNOT_FOUND
)
1149 // if item double-clicked was not yet selected, then treat
1150 // this event as a left-click instead
1151 if ( item
== m_current
)
1153 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, GetId());
1154 event
.SetEventObject(this);
1157 (void)GetEventHandler()->ProcessEvent(event
);
1161 OnLeftDown(eventMouse
);
1167 // calculate line number from symbol value
1168 int wxSymbolListCtrl::SymbolValueToLineNumber(int item
)
1170 return (int) (item
/m_symbolsPerLine
);
1173 // initialise control from current min/max values
1174 void wxSymbolListCtrl::SetupCtrl(bool scrollToSelection
)
1176 wxSize sz
= GetClientSize();
1178 m_symbolsPerLine
= sz
.x
/(m_cellSize
.x
+m_ptMargins
.x
);
1179 int noLines
= (1 + SymbolValueToLineNumber(m_maxSymbolValue
));
1181 SetRowCount(noLines
);
1184 if (scrollToSelection
&& m_current
!= wxNOT_FOUND
&& m_current
>= m_minSymbolValue
&& m_current
<= m_maxSymbolValue
)
1186 ScrollToRow(SymbolValueToLineNumber(m_current
));
1190 // make this item visible
1191 void wxSymbolListCtrl::EnsureVisible(int item
)
1193 if (item
!= wxNOT_FOUND
&& item
>= m_minSymbolValue
&& item
<= m_maxSymbolValue
)
1195 ScrollToRow(SymbolValueToLineNumber(item
));
1201 int wxSymbolListCtrl::HitTest(const wxPoint
& pt
)
1203 wxCoord lineHeight
= OnGetRowHeight(0);
1205 int atLine
= GetVisibleBegin() + (pt
.y
/lineHeight
);
1206 int symbol
= (atLine
*m_symbolsPerLine
) + (pt
.x
/(m_cellSize
.x
+1));
1208 if (symbol
>= m_minSymbolValue
&& symbol
<= m_maxSymbolValue
)
1214 // Respond to size change
1215 void wxSymbolListCtrl::OnSize(wxSizeEvent
& event
)
1221 // set the current font
1222 bool wxSymbolListCtrl::SetFont(const wxFont
& font
)
1224 wxVScrolledWindow::SetFont(font
);
1231 // set Unicode/ASCII mode
1232 void wxSymbolListCtrl::SetUnicodeMode(bool unicodeMode
)
1234 bool changed
= false;
1235 if (unicodeMode
&& !m_unicodeMode
)
1239 m_minSymbolValue
= 0;
1240 m_maxSymbolValue
= 65535;
1242 else if (!unicodeMode
&& m_unicodeMode
)
1245 m_minSymbolValue
= 0;
1246 m_maxSymbolValue
= 255;
1248 m_unicodeMode
= unicodeMode
;
1254 // ----------------------------------------------------------------------------
1255 // use the same default attributes as wxListBox
1256 // ----------------------------------------------------------------------------
1260 wxSymbolListCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
1262 return wxListBox::GetClassDefaultAttributes(variant
);
1265 #endif // wxUSE_RICHTEXT