richtextsymboldlg.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: richtext/richtextsymboldlg.h
  3. // Purpose: interface of wxSymbolPickerDialog
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxSymbolPickerDialog
  9. wxSymbolPickerDialog presents the user with a choice of fonts and a grid
  10. of available characters. This modal dialog provides the application with
  11. a selected symbol and optional font selection.
  12. Although this dialog is contained in the rich text library, the dialog
  13. is generic and can be used in other contexts.
  14. To use the dialog, pass a default symbol specified as a string, an initial font
  15. name, and a current font name. The difference between the initial font and
  16. current font is that the initial font determines what the font control will be
  17. set to when the dialog shows - an empty string will show the selection
  18. @e normal text.
  19. The current font, on the other hand, is used by the dialog to determine what
  20. font to display the characters in, even when no initial font is selected.
  21. This allows the user (and application) to distinguish between inserting a
  22. symbol in the current font, and inserting it with a specified font.
  23. When the dialog is dismissed, the application can get the selected symbol
  24. with wxSymbolPickerDialog::GetSymbol and test whether a font was specified
  25. with wxSymbolPickerDialog::UseNormalFont,fetching the specified font with
  26. wxSymbolPickerDialog::GetFontName.
  27. Here's a realistic example, inserting the supplied symbol into a
  28. rich text control in either the current font or specified font.
  29. @code
  30. wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
  31. wxTextAttr attr;
  32. attr.SetFlags(wxTEXT_ATTR_FONT);
  33. ctrl-GetStyle(ctrl->GetInsertionPoint(), attr);
  34. wxString currentFontName;
  35. if (attr.HasFont() && attr.GetFont().IsOk())
  36. currentFontName = attr.GetFont().GetFaceName();
  37. // Don't set the initial font in the dialog (so the user is choosing
  38. // 'normal text', i.e. the current font) but do tell the dialog
  39. // what 'normal text' is.
  40. wxSymbolPickerDialog dlg("*", wxEmptyString, currentFontName, this);
  41. if (dlg.ShowModal() == wxID_OK)
  42. {
  43. if (dlg.HasSelection())
  44. {
  45. long insertionPoint = ctrl-GetInsertionPoint();
  46. ctrl->WriteText(dlg.GetSymbol());
  47. if (!dlg.UseNormalFont())
  48. {
  49. wxFont font(attr.GetFont());
  50. font.SetFaceName(dlg.GetFontName());
  51. attr.SetFont(font);
  52. ctrl-SetStyle(insertionPoint, insertionPoint+1, attr);
  53. }
  54. }
  55. }
  56. @endcode
  57. @library{wxrichtext}
  58. @category{cmndlg}
  59. */
  60. class wxSymbolPickerDialog : public wxDialog
  61. {
  62. public:
  63. /**
  64. Default ctor.
  65. */
  66. wxSymbolPickerDialog();
  67. /**
  68. Constructor.
  69. @param symbol
  70. The initial symbol to show.
  71. Specify a single character in a string, or an empty string.
  72. @param initialFont
  73. The initial font to be displayed in the font list.
  74. If empty, the item normal text will be selected.
  75. @param normalTextFont
  76. The font the dialog will use to display the symbols if the
  77. initial font is empty.
  78. @param parent
  79. The dialog's parent.
  80. @param id
  81. The dialog's identifier.
  82. @param title
  83. The dialog's caption.
  84. @param pos
  85. The dialog's position.
  86. @param size
  87. The dialog's size.
  88. @param style
  89. The dialog's window style.
  90. */
  91. wxSymbolPickerDialog(const wxString& symbol,
  92. const wxString& initialFont,
  93. const wxString& normalTextFont,
  94. wxWindow* parent,
  95. wxWindowID id = wxID_ANY,
  96. const wxString& title = _("Symbols"),
  97. const wxPoint& pos = wxDefaultPosition,
  98. const wxSize& size = wxDefaultSize,
  99. long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX);
  100. /**
  101. Creation: see @ref wxSymbolPickerDialog() "the constructor" for details about
  102. the parameters.
  103. */
  104. bool Create(const wxString& symbol, const wxString& initialFont,
  105. const wxString& normalTextFont, wxWindow* parent,
  106. wxWindowID id = wxID_ANY,
  107. const wxString& caption = wxGetTranslation("Symbols"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(400, 300), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX);
  108. /**
  109. Returns the font name (the font reflected in the font list).
  110. */
  111. wxString GetFontName() const;
  112. /**
  113. Returns @true if the dialog is showing the full range of Unicode characters.
  114. */
  115. bool GetFromUnicode() const;
  116. /**
  117. Gets the font name used for displaying symbols in the absence of a selected font.
  118. */
  119. wxString GetNormalTextFontName() const;
  120. /**
  121. Gets the current or initial symbol as a string.
  122. */
  123. wxString GetSymbol() const;
  124. /**
  125. Gets the selected symbol character as an integer.
  126. */
  127. int GetSymbolChar() const;
  128. /**
  129. Returns @true if a symbol is selected.
  130. */
  131. bool HasSelection() const;
  132. /**
  133. Sets the initial/selected font name.
  134. */
  135. void SetFontName(wxString value);
  136. /**
  137. Sets the internal flag indicating that the full Unicode range should be
  138. displayed.
  139. */
  140. void SetFromUnicode(bool value);
  141. /**
  142. Sets the name of the font to be used in the absence of a selected font.
  143. */
  144. void SetNormalTextFontName(wxString value);
  145. /**
  146. Sets the symbol as a one or zero character string.
  147. */
  148. void SetSymbol(wxString value);
  149. /**
  150. Sets Unicode display mode.
  151. */
  152. void SetUnicodeMode(bool unicodeMode);
  153. /**
  154. Returns @true if the has specified normal text - that is, there is no selected font.
  155. */
  156. bool UseNormalFont() const;
  157. };