button.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/private/button.h
  3. // Purpose: helper functions used with native BUTTON control
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-06-07
  6. // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_MSW_PRIVATE_BUTTON_H_
  10. #define _WX_MSW_PRIVATE_BUTTON_H_
  11. // define some standard button constants which may be missing in the headers
  12. #ifndef BS_PUSHLIKE
  13. #define BS_PUSHLIKE 0x00001000L
  14. #endif
  15. #ifndef BST_UNCHECKED
  16. #define BST_UNCHECKED 0x0000
  17. #endif
  18. #ifndef BST_CHECKED
  19. #define BST_CHECKED 0x0001
  20. #endif
  21. #ifndef BST_INDETERMINATE
  22. #define BST_INDETERMINATE 0x0002
  23. #endif
  24. namespace wxMSWButton
  25. {
  26. // returns BS_MULTILINE if the label contains new lines or 0 otherwise
  27. inline int GetMultilineStyle(const wxString& label)
  28. {
  29. return label.find(wxT('\n')) == wxString::npos ? 0 : BS_MULTILINE;
  30. }
  31. // update the style of the specified HWND to include or exclude BS_MULTILINE
  32. // depending on whether the label contains the new lines
  33. void UpdateMultilineStyle(HWND hwnd, const wxString& label);
  34. // flags for ComputeBestSize() and GetFittingSize()
  35. enum
  36. {
  37. Size_AuthNeeded = 1,
  38. Size_ExactFit = 2
  39. };
  40. // NB: All the functions below are implemented in src/msw/button.cpp
  41. // Compute the button size (as if wxBU_EXACTFIT were specified, i.e. without
  42. // adjusting it to be of default size if it's smaller) for the given label size
  43. WXDLLIMPEXP_CORE wxSize
  44. GetFittingSize(wxWindow *win, const wxSize& sizeLabel, int flags = 0);
  45. // Compute the button size (as if wxBU_EXACTFIT were specified) by computing
  46. // its label size and then calling GetFittingSize().
  47. wxSize ComputeBestFittingSize(wxControl *btn, int flags = 0);
  48. // Increase the size passed as parameter to be at least the standard button
  49. // size if the control doesn't have wxBU_EXACTFIT style and also cache it as
  50. // the best size and return its value -- this is used in DoGetBestSize()
  51. // implementation.
  52. wxSize IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size);
  53. // helper of wxToggleButton::DoGetBestSize()
  54. inline wxSize ComputeBestSize(wxControl *btn, int flags = 0)
  55. {
  56. return IncreaseToStdSizeAndCache(btn, ComputeBestFittingSize(btn, flags));
  57. }
  58. } // namespace wxMSWButton
  59. #endif // _WX_MSW_PRIVATE_BUTTON_H_