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;
80 // type of event which is fired upon depression of this button
83 // pens for drawing decorations (borders)
94 // Internal function for destroying labels.
97 // Returns the label that matches the current button state.
98 virtual wxBitmap
* GetStateLabel();
100 // Draws shading on the button.
101 virtual void DrawShade( int outerLevel
,
103 wxPen
& upperLeftSidePen
,
104 wxPen
& lowerRightSidePen
);
106 // Returns TRUE if the given point is in the window.
107 bool IsInWindow( int x
, int y
);
112 wxNewBitmapButton( const wxBitmap
& labelBitmap
= wxNullBitmap
,
113 const wxString
& labelText
= wxT(""),
114 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
116 // this is the default type of fired events
117 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
118 int marginX
= NB_DEFAULT_MARGIN
,
119 int marginY
= NB_DEFAULT_MARGIN
,
120 int textToLabelGap
= 2,
121 bool isSticky
= FALSE
124 // Use this constructor if buttons have to be persistant
125 wxNewBitmapButton( const wxString
& bitmapFileName
,
126 const wxBitmapType bitmapFileType
= wxBITMAP_TYPE_BMP
,
127 const wxString
& labelText
= wxT(""),
128 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
130 // this is the default type of fired events
131 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
132 int marginX
= NB_DEFAULT_MARGIN
,
133 int marginY
= NB_DEFAULT_MARGIN
,
134 int textToLabelGap
= 2,
135 bool isSticky
= FALSE
139 ~wxNewBitmapButton();
141 // This function should be called after Create. It renders the labels, having
142 // reloaded the button image if necessary.
143 virtual void Reshape();
145 // Sets the label and optionally label text.
146 virtual void SetLabel(const wxBitmap
& labelBitmap
, const wxString
& labelText
= wxT("") );
148 // Unhide method from parents.
150 virtual void SetLabel(const wxString
& label
)
151 { wxPanel::SetLabel(label
); };
153 // Sets the text alignment and margins.
154 virtual void SetAlignments( int alignText
= NB_ALIGN_TEXT_BOTTOM
,
155 int marginX
= NB_DEFAULT_MARGIN
,
156 int marginY
= NB_DEFAULT_MARGIN
,
157 int textToLabelGap
= 2);
159 // Draws the decorations.
160 virtual void DrawDecorations( wxDC
& dc
);
163 virtual void DrawLabel( wxDC
& dc
);
165 // Renders the label image.
166 virtual void RenderLabelImage( wxBitmap
*& destBmp
, wxBitmap
* srcBmp
,
167 bool isEnabled
= TRUE
,
168 bool isPressed
= FALSE
);
170 // Renders label images.
171 virtual void RenderLabelImages();
173 // Renders label images.
174 virtual void RenderAllLabelImages();
176 // Enables/disables button
177 virtual bool Enable(bool enable
);
179 // Responds to a left mouse button down event.
180 void OnLButtonDown( wxMouseEvent
& event
);
182 // Responds to a left mouse button up event.
183 void OnLButtonUp( wxMouseEvent
& event
);
185 // Responds to mouse enter to window.
186 void OnMouseEnter( wxMouseEvent
& event
);
188 // Responds to mouse leave from window.
189 void OnMouseLeave( wxMouseEvent
& event
);
191 // Responds to a size event.
192 void OnSize( wxSizeEvent
& event
);
194 // Responds to a paint event.
195 void OnPaint( wxPaintEvent
& event
);
197 // Responds to an erase background event.
198 void OnEraseBackground( wxEraseEvent
& event
);
200 // Responds to a kill focus event.
201 void OnKillFocus( wxFocusEvent
& event
);
203 DECLARE_EVENT_TABLE()
206 #endif /* __NEWBMPBTN_G__ */