fontpicker.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: fontpicker.h
  3. // Purpose: interface of wxFontPickerCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxFNTP_FONTDESC_AS_LABEL 0x0008
  8. #define wxFNTP_USEFONT_FOR_LABEL 0x0010
  9. #define wxFONTBTN_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL)
  10. #define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
  11. #define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
  12. wxEventType wxEVT_FONTPICKER_CHANGED;
  13. /**
  14. @class wxFontPickerCtrl
  15. This control allows the user to select a font. The generic implementation is
  16. a button which brings up a wxFontDialog when clicked. Native implementation
  17. may differ but this is usually a (small) widget which give access to the
  18. font-chooser dialog.
  19. It is only available if @c wxUSE_FONTPICKERCTRL is set to 1 (the default).
  20. @beginStyleTable
  21. @style{wxFNTP_DEFAULT_STYLE}
  22. The default style: wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL.
  23. @style{wxFNTP_USE_TEXTCTRL}
  24. Creates a text control to the left of the picker button which is
  25. completely managed by the wxFontPickerCtrl and which can be used by
  26. the user to specify a font (see SetSelectedFont). The text control
  27. is automatically synchronized with button's value. Use functions
  28. defined in wxPickerBase to modify the text control.
  29. @style{wxFNTP_FONTDESC_AS_LABEL}
  30. Keeps the label of the button updated with the fontface name and
  31. the font size. E.g. choosing "Times New Roman bold, italic with
  32. size 10" from the fontdialog, will update the label (overwriting
  33. any previous label) with the "Times New Roman, 10" text.
  34. @style{wxFNTP_USEFONT_FOR_LABEL}
  35. Uses the currently selected font to draw the label of the button.
  36. @endStyleTable
  37. @beginEventEmissionTable{wxFontPickerEvent}
  38. @event{EVT_FONTPICKER_CHANGED(id, func)}
  39. The user changed the font selected in the control either using the button
  40. or using text control (see wxFNTP_USE_TEXTCTRL; note that in this case the
  41. event is fired only if the user's input is valid, i.e. recognizable).
  42. @endEventTable
  43. @library{wxcore}
  44. @category{pickers}
  45. @appearance{fontpickerctrl}
  46. @see wxFontDialog, wxFontPickerEvent
  47. */
  48. class wxFontPickerCtrl : public wxPickerBase
  49. {
  50. public:
  51. wxFontPickerCtrl();
  52. /**
  53. Initializes the object and calls Create() with
  54. all the parameters.
  55. */
  56. wxFontPickerCtrl(wxWindow* parent, wxWindowID id,
  57. const wxFont& font = wxNullFont,
  58. const wxPoint& pos = wxDefaultPosition,
  59. const wxSize& size = wxDefaultSize,
  60. long style = wxFNTP_DEFAULT_STYLE,
  61. const wxValidator& validator = wxDefaultValidator,
  62. const wxString& name = wxFontPickerCtrlNameStr);
  63. /**
  64. Creates this widget with given parameters.
  65. @param parent
  66. Parent window, must not be non-@NULL.
  67. @param id
  68. The identifier for the control.
  69. @param font
  70. The initial font shown in the control.
  71. If ::wxNullFont is given, the default font is used.
  72. @param pos
  73. Initial position.
  74. @param size
  75. Initial size.
  76. @param style
  77. The window style, see wxFNTP_* flags.
  78. @param validator
  79. Validator which can be used for additional date checks.
  80. @param name
  81. Control name.
  82. @return @true if the control was successfully created or @false if
  83. creation failed.
  84. */
  85. bool Create(wxWindow* parent, wxWindowID id,
  86. const wxFont& font = wxNullFont,
  87. const wxPoint& pos = wxDefaultPosition,
  88. const wxSize& size = wxDefaultSize,
  89. long style = wxFNTP_DEFAULT_STYLE,
  90. const wxValidator& validator = wxDefaultValidator,
  91. const wxString& name = wxFontPickerCtrlNameStr);
  92. /**
  93. Returns the maximum point size value allowed for the user-chosen font.
  94. */
  95. unsigned int GetMaxPointSize() const;
  96. /**
  97. Returns the currently selected font.
  98. Note that this function is completely different from wxWindow::GetFont.
  99. */
  100. wxFont GetSelectedFont() const;
  101. /**
  102. Sets the maximum point size value allowed for the user-chosen font.
  103. The default value is 100. Note that big fonts can require a lot of memory and
  104. CPU time both for creation and for rendering; thus, specially because the user
  105. has the option to specify the fontsize through a text control
  106. (see wxFNTP_USE_TEXTCTRL), it's a good idea to put a limit to the maximum
  107. font size when huge fonts do not make much sense.
  108. */
  109. void SetMaxPointSize(unsigned int max);
  110. /**
  111. Sets the currently selected font.
  112. Note that this function is completely different from wxWindow::SetFont.
  113. */
  114. void SetSelectedFont(const wxFont& font);
  115. };
  116. /**
  117. @class wxFontPickerEvent
  118. This event class is used for the events generated by
  119. wxFontPickerCtrl.
  120. @beginEventTable{wxFontPickerEvent}
  121. @event{EVT_FONTPICKER_CHANGED(id, func)}
  122. Generated whenever the selected font changes.
  123. @endEventTable
  124. @library{wxcore}
  125. @category{events}
  126. @see wxFontPickerCtrl
  127. */
  128. class wxFontPickerEvent : public wxCommandEvent
  129. {
  130. public:
  131. /**
  132. The constructor is not normally used by the user code.
  133. */
  134. wxFontPickerEvent(wxObject* generator, int id,
  135. const wxFont& font);
  136. /**
  137. Retrieve the font the user has just selected.
  138. */
  139. wxFont GetFont() const;
  140. /**
  141. Set the font associated with the event.
  142. */
  143. void SetFont(const wxFont& f);
  144. };