1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxNewBitmapButton header.
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __NEWBMPBTN_G__
13 #define __NEWBMPBTN_G__
15 #include "wx/button.h"
16 #include "wx/string.h"
17 #include "wx/fl/fldefs.h"
20 #define NB_DEFAULT_MARGIN 2
22 // button label-text alignment types
24 #define NB_ALIGN_TEXT_RIGHT 0
25 #define NB_ALIGN_TEXT_BOTTOM 1
29 // classes declared in this header file
31 class WXDLLIMPEXP_FL wxNewBitmapButton
;
32 class WXDLLIMPEXP_FL wxBorderLessBitmapButton
;
35 This is an alternative class to wxBitmapButton. It is used
36 in the implementation of dynamic toolbars.
39 class wxNewBitmapButton
: public wxPanel
41 DECLARE_DYNAMIC_CLASS(wxNewBitmapButton
)
45 friend class wxNewBitmapButtonSerializer
;
55 wxString mImageFileName
;
56 wxBitmapType mImageFileType
;
58 wxBitmap mDepressedBmp
; // source image for rendering
59 // labels for particular state
61 wxBitmap mFocusedBmp
; // may not be always present -
62 // only if mHasFocusedBmp is true
64 wxBitmap
* mpDepressedImg
;
65 wxBitmap
* mpPressedImg
;
66 wxBitmap
* mpDisabledImg
;
67 wxBitmap
* mpFocusedImg
;
69 // button state variables;
77 // type of event which is fired upon depression of this button
80 // pens for drawing decorations (borders)
91 // Internal function for destroying labels.
94 // Returns the label that matches the current button state.
95 virtual wxBitmap
* GetStateLabel();
97 // Draws shading on the button.
98 virtual void DrawShade( int outerLevel
,
100 wxPen
& upperLeftSidePen
,
101 wxPen
& lowerRightSidePen
);
103 // Returns true if the given point is in the window.
104 bool IsInWindow( int x
, int y
);
106 virtual void OnIdle(wxIdleEvent
& event
);
107 // (EVT_UPDATE_UI handler)
108 virtual void DoButtonUpdate();
113 wxNewBitmapButton( const wxBitmap
& labelBitmap
= wxNullBitmap
,
114 const wxString
& labelText
= wxT(""),
115 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
117 // this is the default type of fired events
118 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
119 int marginX
= NB_DEFAULT_MARGIN
,
120 int marginY
= NB_DEFAULT_MARGIN
,
121 int textToLabelGap
= 2,
122 bool isSticky
= false
125 // Use this constructor if buttons have to be persistant
126 wxNewBitmapButton( const wxString
& bitmapFileName
,
127 const wxBitmapType bitmapFileType
= wxBITMAP_TYPE_BMP
,
128 const wxString
& labelText
= wxT(""),
129 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
131 // this is the default type of fired events
132 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
133 int marginX
= NB_DEFAULT_MARGIN
,
134 int marginY
= NB_DEFAULT_MARGIN
,
135 int textToLabelGap
= 2,
136 bool isSticky
= false
140 ~wxNewBitmapButton();
142 // This function should be called after Create. It renders the labels, having
143 // reloaded the button image if necessary.
144 virtual void Reshape();
146 // Sets the label and optionally label text.
147 virtual void SetLabel(const wxBitmap
& labelBitmap
, const wxString
& labelText
= wxT("") );
149 // Unhide method from parents.
151 virtual void SetLabel(const wxString
& label
)
152 { wxPanel::SetLabel(label
); };
154 // Sets the text alignment and margins.
155 virtual void SetAlignments( int alignText
= NB_ALIGN_TEXT_BOTTOM
,
156 int marginX
= NB_DEFAULT_MARGIN
,
157 int marginY
= NB_DEFAULT_MARGIN
,
158 int textToLabelGap
= 2);
160 // Draws the decorations.
161 virtual void DrawDecorations( wxDC
& dc
);
164 virtual void DrawLabel( wxDC
& dc
);
166 // Renders the label image.
167 virtual void RenderLabelImage( wxBitmap
*& destBmp
, wxBitmap
* srcBmp
,
168 bool isEnabled
= true,
169 bool isPressed
= false);
171 // Renders label images.
172 virtual void RenderLabelImages();
174 // Renders label images.
175 virtual void RenderAllLabelImages();
177 // Enables/disables button
178 virtual bool Enable(bool enable
);
181 virtual bool Toggle(bool enable
);
183 // Responds to a left mouse button down event.
184 void OnLButtonDown( wxMouseEvent
& event
);
186 // Responds to a left mouse button up event.
187 void OnLButtonUp( wxMouseEvent
& event
);
189 // Responds to mouse enter to window.
190 void OnMouseEnter( wxMouseEvent
& event
);
192 // Responds to mouse leave from window.
193 void OnMouseLeave( wxMouseEvent
& event
);
195 // Responds to a size event.
196 void OnSize( wxSizeEvent
& event
);
198 // Responds to a paint event.
199 void OnPaint( wxPaintEvent
& event
);
201 // Responds to an erase background event.
202 void OnEraseBackground( wxEraseEvent
& event
);
204 // Responds to a kill focus event.
205 void OnKillFocus( wxFocusEvent
& event
);
207 DECLARE_EVENT_TABLE()
210 #endif /* __NEWBMPBTN_G__ */