]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/private/button.h
97b6de86c0e3ed345cc6e685d62e742de407f38d
[wxWidgets.git] / include / wx / msw / private / button.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/private/button.h
3 // Purpose: helper functions used with native BUTTON control
4 // Author: Vadim Zeitlin
5 // Created: 2008-06-07
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MSW_PRIVATE_BUTTON_H_
12 #define _WX_MSW_PRIVATE_BUTTON_H_
13
14 // define some standard button constants which may be missing in the headers
15 #ifndef BS_PUSHLIKE
16 #define BS_PUSHLIKE 0x00001000L
17 #endif
18
19 #ifndef BST_UNCHECKED
20 #define BST_UNCHECKED 0x0000
21 #endif
22
23 #ifndef BST_CHECKED
24 #define BST_CHECKED 0x0001
25 #endif
26
27 #ifndef BST_INDETERMINATE
28 #define BST_INDETERMINATE 0x0002
29 #endif
30
31 #ifndef DT_HIDEPREFIX
32 #define DT_HIDEPREFIX 0x00100000
33 #endif
34
35 namespace wxMSWButton
36 {
37
38 // returns BS_MULTILINE if the label contains new lines or 0 otherwise
39 inline int GetMultilineStyle(const wxString& label)
40 {
41 return label.find(_T('\n')) == wxString::npos ? 0 : BS_MULTILINE;
42 }
43
44 // update the style of the specified HWND to include or exclude BS_MULTILINE
45 // depending on whether the label contains the new lines
46 inline void UpdateMultilineStyle(HWND hwnd, const wxString& label)
47 {
48 // update BS_MULTILINE style depending on the new label (resetting it
49 // doesn't seem to do anything very useful but it shouldn't hurt and we do
50 // have to set it whenever the label becomes multi line as otherwise it
51 // wouldn't be shown correctly as we don't use BS_MULTILINE when creating
52 // the control unless it already has new lines in its label)
53 long styleOld = ::GetWindowLong(hwnd, GWL_STYLE),
54 styleNew;
55 if ( label.find(_T('\n')) != wxString::npos )
56 styleNew = styleOld | BS_MULTILINE;
57 else
58 styleNew = styleOld & ~BS_MULTILINE;
59
60 if ( styleNew != styleOld )
61 ::SetWindowLong(hwnd, GWL_STYLE, styleNew);
62 }
63
64 // common implementation of wxButton and wxToggleButton::DoGetBestSize()
65 inline wxSize ComputeBestSize(wxControl *btn)
66 {
67 wxClientDC dc(btn);
68
69 wxCoord wBtn,
70 hBtn;
71 dc.GetMultiLineTextExtent(btn->GetLabelText(), &wBtn, &hBtn);
72
73 // FIXME: this is pure guesswork, need to retrieve the real button margins
74 wBtn += 3*btn->GetCharWidth();
75 hBtn = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(hBtn)/10;
76
77 // all buttons have at least the standard size unless the user explicitly
78 // wants them to be of smaller size and used wxBU_EXACTFIT style when
79 // creating the button
80 if ( !btn->HasFlag(wxBU_EXACTFIT) )
81 {
82 wxSize sz = wxButton::GetDefaultSize();
83 if ( wBtn < sz.x )
84 wBtn = sz.x;
85 if ( hBtn < sz.y )
86 hBtn = sz.y;
87 }
88
89 wxSize best(wBtn, hBtn);
90 btn->CacheBestSize(best);
91 return best;
92 }
93
94 } // namespace wxMSWButton
95
96 #endif // _WX_MSW_PRIVATE_BUTTON_H_
97