]> git.saurik.com Git - wxWidgets.git/blob - src/common/bmpbtncmn.cpp
Fix wxHtmlHelpData::SetTempDir() to behave correctly without trailing slash.
[wxWidgets.git] / src / common / bmpbtncmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/bmpbtncmn.cpp
3 // Purpose: wxBitmapButton common code
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_BMPBUTTON
19
20 #include "wx/bmpbuttn.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/log.h"
24 #include "wx/dcmemory.h"
25 #include "wx/image.h"
26 #endif
27
28 #include "wx/artprov.h"
29 #include "wx/renderer.h"
30
31 // ----------------------------------------------------------------------------
32 // XTI
33 // ----------------------------------------------------------------------------
34
35 wxDEFINE_FLAGS( wxBitmapButtonStyle )
36 wxBEGIN_FLAGS( wxBitmapButtonStyle )
37 // new style border flags, we put them first to
38 // use them for streaming out
39 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
40 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
41 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
42 wxFLAGS_MEMBER(wxBORDER_RAISED)
43 wxFLAGS_MEMBER(wxBORDER_STATIC)
44 wxFLAGS_MEMBER(wxBORDER_NONE)
45
46 // old style border flags
47 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
48 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
49 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
50 wxFLAGS_MEMBER(wxRAISED_BORDER)
51 wxFLAGS_MEMBER(wxSTATIC_BORDER)
52 wxFLAGS_MEMBER(wxBORDER)
53
54 // standard window styles
55 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
56 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
57 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
58 wxFLAGS_MEMBER(wxWANTS_CHARS)
59 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
60 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
61 wxFLAGS_MEMBER(wxVSCROLL)
62 wxFLAGS_MEMBER(wxHSCROLL)
63
64 wxFLAGS_MEMBER(wxBU_AUTODRAW)
65 wxFLAGS_MEMBER(wxBU_LEFT)
66 wxFLAGS_MEMBER(wxBU_RIGHT)
67 wxFLAGS_MEMBER(wxBU_TOP)
68 wxFLAGS_MEMBER(wxBU_BOTTOM)
69 wxEND_FLAGS( wxBitmapButtonStyle )
70
71 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxBitmapButton, wxButton, "wx/bmpbuttn.h")
72
73 wxBEGIN_PROPERTIES_TABLE(wxBitmapButton)
74 wxPROPERTY_FLAGS( WindowStyle, wxBitmapButtonStyle, long, \
75 SetWindowStyleFlag, GetWindowStyleFlag, \
76 wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), \
77 wxT("group")) // style
78 wxEND_PROPERTIES_TABLE()
79
80 wxEMPTY_HANDLERS_TABLE(wxBitmapButton)
81
82 wxCONSTRUCTOR_5( wxBitmapButton, wxWindow*, Parent, wxWindowID, Id, \
83 wxBitmap, Bitmap, wxPoint, Position, wxSize, Size )
84
85 /*
86 TODO PROPERTIES :
87
88 long "style" , wxBU_AUTODRAW
89 bool "default" , 0
90 bitmap "selected" ,
91 bitmap "focus" ,
92 bitmap "disabled" ,
93 */
94
95 namespace
96 {
97
98 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
99
100 wxBitmap
101 GetCloseButtonBitmap(wxWindow *win,
102 const wxSize& size,
103 const wxColour& colBg,
104 int flags = 0)
105 {
106 wxBitmap bmp(size);
107 wxMemoryDC dc(bmp);
108 dc.SetBackground(colBg);
109 dc.Clear();
110 wxRendererNative::Get().
111 DrawTitleBarBitmap(win, dc, size, wxTITLEBAR_BUTTON_CLOSE, flags);
112 return bmp;
113 }
114
115 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
116
117 } // anonymous namespace
118
119 /* static */
120 wxBitmapButton*
121 wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid)
122 {
123 wxCHECK_MSG( parent, NULL, wxS("Must have a valid parent") );
124
125 const wxColour colBg = parent->GetBackgroundColour();
126
127 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
128 const wxSize sizeBmp = wxArtProvider::GetSizeHint(wxART_BUTTON);
129 wxBitmap bmp = GetCloseButtonBitmap(parent, sizeBmp, colBg);
130 #else // !wxHAS_DRAW_TITLE_BAR_BITMAP
131 wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
132 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
133
134 wxBitmapButton* const button = new wxBitmapButton
135 (
136 parent,
137 winid,
138 bmp,
139 wxDefaultPosition,
140 wxDefaultSize,
141 wxBORDER_NONE
142 );
143
144 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
145 button->SetBitmapPressed(
146 GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_PRESSED));
147
148 button->SetBitmapCurrent(
149 GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_CURRENT));
150 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
151
152 // The button should blend with its parent background.
153 button->SetBackgroundColour(colBg);
154
155 return button;
156 }
157
158 #endif // wxUSE_BMPBUTTON