commandlinkbutton.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/commandlinkbutton.h
  3. // Purpose: wxCommandLinkButtonBase and wxGenericCommandLinkButton classes
  4. // Author: Rickard Westerlund
  5. // Created: 2010-06-11
  6. // Copyright: (c) 2010 wxWidgets team
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_COMMANDLINKBUTTON_H_
  10. #define _WX_COMMANDLINKBUTTON_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_COMMANDLINKBUTTON
  13. #include "wx/button.h"
  14. // ----------------------------------------------------------------------------
  15. // Command link button common base class
  16. // ----------------------------------------------------------------------------
  17. // This class has separate "main label" (title-like string) and (possibly
  18. // multiline) "note" which can be set and queried separately but can also be
  19. // set both at once by joining them with a new line and setting them as a
  20. // label and queried by breaking the label into the parts before the first new
  21. // line and after it.
  22. class WXDLLIMPEXP_ADV wxCommandLinkButtonBase : public wxButton
  23. {
  24. public:
  25. wxCommandLinkButtonBase() : wxButton() { }
  26. wxCommandLinkButtonBase(wxWindow *parent,
  27. wxWindowID id,
  28. const wxString& mainLabel = wxEmptyString,
  29. const wxString& note = wxEmptyString,
  30. const wxPoint& pos = wxDefaultPosition,
  31. const wxSize& size = wxDefaultSize,
  32. long style = 0,
  33. const wxValidator& validator =
  34. wxDefaultValidator,
  35. const wxString& name = wxButtonNameStr)
  36. : wxButton(parent,
  37. id,
  38. mainLabel + '\n' + note,
  39. pos,
  40. size,
  41. style,
  42. validator,
  43. name)
  44. { }
  45. virtual void SetMainLabelAndNote(const wxString& mainLabel,
  46. const wxString& note) = 0;
  47. virtual void SetMainLabel(const wxString& mainLabel)
  48. {
  49. SetMainLabelAndNote(mainLabel, GetNote());
  50. }
  51. virtual void SetNote(const wxString& note)
  52. {
  53. SetMainLabelAndNote(GetMainLabel(), note);
  54. }
  55. virtual wxString GetMainLabel() const
  56. {
  57. return GetLabel().BeforeFirst('\n');
  58. }
  59. virtual wxString GetNote() const
  60. {
  61. return GetLabel().AfterFirst('\n');
  62. }
  63. protected:
  64. virtual bool HasNativeBitmap() const { return false; }
  65. private:
  66. wxDECLARE_NO_COPY_CLASS(wxCommandLinkButtonBase);
  67. };
  68. // ----------------------------------------------------------------------------
  69. // Generic command link button
  70. // ----------------------------------------------------------------------------
  71. // Trivial generic implementation simply using a multiline label to show both
  72. // the main label and the note.
  73. class WXDLLIMPEXP_ADV wxGenericCommandLinkButton
  74. : public wxCommandLinkButtonBase
  75. {
  76. public:
  77. wxGenericCommandLinkButton() : wxCommandLinkButtonBase() { }
  78. wxGenericCommandLinkButton(wxWindow *parent,
  79. wxWindowID id,
  80. const wxString& mainLabel = wxEmptyString,
  81. const wxString& note = wxEmptyString,
  82. const wxPoint& pos = wxDefaultPosition,
  83. const wxSize& size = wxDefaultSize,
  84. long style = 0,
  85. const wxValidator& validator = wxDefaultValidator,
  86. const wxString& name = wxButtonNameStr)
  87. : wxCommandLinkButtonBase()
  88. {
  89. Create(parent, id, mainLabel, note, pos, size, style, validator, name);
  90. }
  91. bool Create(wxWindow *parent,
  92. wxWindowID id,
  93. const wxString& mainLabel = wxEmptyString,
  94. const wxString& note = wxEmptyString,
  95. const wxPoint& pos = wxDefaultPosition,
  96. const wxSize& size = wxDefaultSize,
  97. long style = 0,
  98. const wxValidator& validator = wxDefaultValidator,
  99. const wxString& name = wxButtonNameStr);
  100. virtual void SetMainLabelAndNote(const wxString& mainLabel,
  101. const wxString& note)
  102. {
  103. wxButton::SetLabel(mainLabel + '\n' + note);
  104. }
  105. private:
  106. void SetDefaultBitmap();
  107. wxDECLARE_NO_COPY_CLASS(wxGenericCommandLinkButton);
  108. };
  109. #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
  110. #include "wx/msw/commandlinkbutton.h"
  111. #else
  112. class WXDLLIMPEXP_ADV wxCommandLinkButton : public wxGenericCommandLinkButton
  113. {
  114. public:
  115. wxCommandLinkButton() : wxGenericCommandLinkButton() { }
  116. wxCommandLinkButton(wxWindow *parent,
  117. wxWindowID id,
  118. const wxString& mainLabel = wxEmptyString,
  119. const wxString& note = wxEmptyString,
  120. const wxPoint& pos = wxDefaultPosition,
  121. const wxSize& size = wxDefaultSize,
  122. long style = 0,
  123. const wxValidator& validator = wxDefaultValidator,
  124. const wxString& name = wxButtonNameStr)
  125. : wxGenericCommandLinkButton(parent,
  126. id,
  127. mainLabel,
  128. note,
  129. pos,
  130. size,
  131. style,
  132. validator,
  133. name)
  134. { }
  135. private:
  136. wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxCommandLinkButton);
  137. };
  138. #endif // __WXMSW__/!__WXMSW__
  139. #endif // wxUSE_COMMANDLINKBUTTON
  140. #endif // _WX_COMMANDLINKBUTTON_H_