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 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "newbmpbtn.h"
19 #include "wx/button.h"
20 #include "wx/string.h"
21 #include "wx/fl/fldefs.h"
24 #define NB_DEFAULT_MARGIN 2
26 // button label-text alignment types
28 #define NB_ALIGN_TEXT_RIGHT 0
29 #define NB_ALIGN_TEXT_BOTTOM 1
33 // classes declared in this header file
35 class WXDLLIMPEXP_FL wxNewBitmapButton
;
36 class WXDLLIMPEXP_FL wxBorderLessBitmapButton
;
39 This is an alternative class to wxBitmapButton. It is used
40 in the implementation of dynamic toolbars.
43 class wxNewBitmapButton
: public wxPanel
45 DECLARE_DYNAMIC_CLASS(wxNewBitmapButton
)
49 friend class wxNewBitmapButtonSerializer
;
59 wxString mImageFileName
;
60 wxBitmapType mImageFileType
;
62 wxBitmap mDepressedBmp
; // source image for rendering
63 // labels for particular state
65 wxBitmap mFocusedBmp
; // may not be always present -
66 // only if mHasFocusedBmp is TRUE
68 wxBitmap
* mpDepressedImg
;
69 wxBitmap
* mpPressedImg
;
70 wxBitmap
* mpDisabledImg
;
71 wxBitmap
* mpFocusedImg
;
73 // button state variables;
81 // type of event which is fired upon depression of this button
84 // pens for drawing decorations (borders)
95 // Internal function for destroying labels.
98 // Returns the label that matches the current button state.
99 virtual wxBitmap
* GetStateLabel();
101 // Draws shading on the button.
102 virtual void DrawShade( int outerLevel
,
104 wxPen
& upperLeftSidePen
,
105 wxPen
& lowerRightSidePen
);
107 // Returns TRUE if the given point is in the window.
108 bool IsInWindow( int x
, int y
);
110 virtual void OnIdle(wxIdleEvent
& event
);
111 // (EVT_UPDATE_UI handler)
112 virtual void DoButtonUpdate();
117 wxNewBitmapButton( const wxBitmap
& labelBitmap
= wxNullBitmap
,
118 const wxString
& labelText
= wxT(""),
119 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
121 // this is the default type of fired events
122 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
123 int marginX
= NB_DEFAULT_MARGIN
,
124 int marginY
= NB_DEFAULT_MARGIN
,
125 int textToLabelGap
= 2,
126 bool isSticky
= FALSE
129 // Use this constructor if buttons have to be persistant
130 wxNewBitmapButton( const wxString
& bitmapFileName
,
131 const wxBitmapType bitmapFileType
= wxBITMAP_TYPE_BMP
,
132 const wxString
& labelText
= wxT(""),
133 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
135 // this is the default type of fired events
136 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
137 int marginX
= NB_DEFAULT_MARGIN
,
138 int marginY
= NB_DEFAULT_MARGIN
,
139 int textToLabelGap
= 2,
140 bool isSticky
= FALSE
144 ~wxNewBitmapButton();
146 // This function should be called after Create. It renders the labels, having
147 // reloaded the button image if necessary.
148 virtual void Reshape();
150 // Sets the label and optionally label text.
151 virtual void SetLabel(const wxBitmap
& labelBitmap
, const wxString
& labelText
= wxT("") );
153 // Unhide method from parents.
155 virtual void SetLabel(const wxString
& label
)
156 { wxPanel::SetLabel(label
); };
158 // Sets the text alignment and margins.
159 virtual void SetAlignments( int alignText
= NB_ALIGN_TEXT_BOTTOM
,
160 int marginX
= NB_DEFAULT_MARGIN
,
161 int marginY
= NB_DEFAULT_MARGIN
,
162 int textToLabelGap
= 2);
164 // Draws the decorations.
165 virtual void DrawDecorations( wxDC
& dc
);
168 virtual void DrawLabel( wxDC
& dc
);
170 // Renders the label image.
171 virtual void RenderLabelImage( wxBitmap
*& destBmp
, wxBitmap
* srcBmp
,
172 bool isEnabled
= TRUE
,
173 bool isPressed
= FALSE
);
175 // Renders label images.
176 virtual void RenderLabelImages();
178 // Renders label images.
179 virtual void RenderAllLabelImages();
181 // Enables/disables button
182 virtual bool Enable(bool enable
);
185 virtual bool Toggle(bool enable
);
187 // Responds to a left mouse button down event.
188 void OnLButtonDown( wxMouseEvent
& event
);
190 // Responds to a left mouse button up event.
191 void OnLButtonUp( wxMouseEvent
& event
);
193 // Responds to mouse enter to window.
194 void OnMouseEnter( wxMouseEvent
& event
);
196 // Responds to mouse leave from window.
197 void OnMouseLeave( wxMouseEvent
& event
);
199 // Responds to a size event.
200 void OnSize( wxSizeEvent
& event
);
202 // Responds to a paint event.
203 void OnPaint( wxPaintEvent
& event
);
205 // Responds to an erase background event.
206 void OnEraseBackground( wxEraseEvent
& event
);
208 // Responds to a kill focus event.
209 void OnKillFocus( wxFocusEvent
& event
);
211 DECLARE_EVENT_TABLE()
214 #endif /* __NEWBMPBTN_G__ */