bmpbuttn.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/bmpbuttn.h
  3. // Purpose: wxBitmapButton class interface
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 25.08.00
  7. // Copyright: (c) 2000 Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_BMPBUTTON_H_BASE_
  11. #define _WX_BMPBUTTON_H_BASE_
  12. #include "wx/defs.h"
  13. #if wxUSE_BMPBUTTON
  14. #include "wx/button.h"
  15. // FIXME: right now only wxMSW, wxGTK and wxOSX implement bitmap support in wxButton
  16. // itself, this shouldn't be used for the other platforms neither
  17. // when all of them do it
  18. #if (defined(__WXMSW__) || defined(__WXGTK20__) || defined(__WXOSX__)) && !defined(__WXUNIVERSAL__)
  19. #define wxHAS_BUTTON_BITMAP
  20. #endif
  21. class WXDLLIMPEXP_FWD_CORE wxBitmapButton;
  22. // ----------------------------------------------------------------------------
  23. // wxBitmapButton: a button which shows bitmaps instead of the usual string.
  24. // It has different bitmaps for different states (focused/disabled/pressed)
  25. // ----------------------------------------------------------------------------
  26. class WXDLLIMPEXP_CORE wxBitmapButtonBase : public wxButton
  27. {
  28. public:
  29. wxBitmapButtonBase()
  30. {
  31. #ifndef wxHAS_BUTTON_BITMAP
  32. m_marginX =
  33. m_marginY = 0;
  34. #endif // wxHAS_BUTTON_BITMAP
  35. }
  36. bool Create(wxWindow *parent,
  37. wxWindowID winid,
  38. const wxPoint& pos,
  39. const wxSize& size,
  40. long style,
  41. const wxValidator& validator,
  42. const wxString& name)
  43. {
  44. // We use wxBU_NOTEXT to let the base class Create() know that we are
  45. // not going to show the label: this is a hack needed for wxGTK where
  46. // we can show both label and bitmap only with GTK 2.6+ but we always
  47. // can show just one of them and this style allows us to choose which
  48. // one we need.
  49. //
  50. // And we also use wxBU_EXACTFIT to avoid being resized up to the
  51. // standard button size as this doesn't make sense for bitmap buttons
  52. // which are not standard anyhow and should fit their bitmap size.
  53. return wxButton::Create(parent, winid, "",
  54. pos, size,
  55. style | wxBU_NOTEXT | wxBU_EXACTFIT,
  56. validator, name);
  57. }
  58. // Special creation function for a standard "Close" bitmap. It allows to
  59. // simply create a close button with the image appropriate for the common
  60. // platform.
  61. static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid);
  62. // set/get the margins around the button
  63. virtual void SetMargins(int x, int y)
  64. {
  65. DoSetBitmapMargins(x, y);
  66. }
  67. int GetMarginX() const { return DoGetBitmapMargins().x; }
  68. int GetMarginY() const { return DoGetBitmapMargins().y; }
  69. // deprecated synonym for SetBitmapLabel()
  70. #if WXWIN_COMPATIBILITY_2_6
  71. wxDEPRECATED_INLINE( void SetLabel(const wxBitmap& bitmap),
  72. SetBitmapLabel(bitmap); )
  73. // prevent virtual function hiding
  74. virtual void SetLabel(const wxString& label)
  75. { wxWindow::SetLabel(label); }
  76. #endif // WXWIN_COMPATIBILITY_2_6
  77. protected:
  78. #ifndef wxHAS_BUTTON_BITMAP
  79. // function called when any of the bitmaps changes
  80. virtual void OnSetBitmap() { InvalidateBestSize(); Refresh(); }
  81. virtual wxBitmap DoGetBitmap(State which) const { return m_bitmaps[which]; }
  82. virtual void DoSetBitmap(const wxBitmap& bitmap, State which)
  83. { m_bitmaps[which] = bitmap; OnSetBitmap(); }
  84. virtual wxSize DoGetBitmapMargins() const
  85. {
  86. return wxSize(m_marginX, m_marginY);
  87. }
  88. virtual void DoSetBitmapMargins(int x, int y)
  89. {
  90. m_marginX = x;
  91. m_marginY = y;
  92. }
  93. // the bitmaps for various states
  94. wxBitmap m_bitmaps[State_Max];
  95. // the margins around the bitmap
  96. int m_marginX,
  97. m_marginY;
  98. #endif // !wxHAS_BUTTON_BITMAP
  99. wxDECLARE_NO_COPY_CLASS(wxBitmapButtonBase);
  100. };
  101. #if defined(__WXUNIVERSAL__)
  102. #include "wx/univ/bmpbuttn.h"
  103. #elif defined(__WXMSW__)
  104. #include "wx/msw/bmpbuttn.h"
  105. #elif defined(__WXMOTIF__)
  106. #include "wx/motif/bmpbuttn.h"
  107. #elif defined(__WXGTK20__)
  108. #include "wx/gtk/bmpbuttn.h"
  109. #elif defined(__WXGTK__)
  110. #include "wx/gtk1/bmpbuttn.h"
  111. #elif defined(__WXMAC__)
  112. #include "wx/osx/bmpbuttn.h"
  113. #elif defined(__WXCOCOA__)
  114. #include "wx/cocoa/bmpbuttn.h"
  115. #elif defined(__WXPM__)
  116. #include "wx/os2/bmpbuttn.h"
  117. #endif
  118. #endif // wxUSE_BMPBUTTON
  119. #endif // _WX_BMPBUTTON_H_BASE_