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__
16 #pragma interface "newbmpbtn.h"
19 #include "wx/button.h"
20 #include "wx/string.h"
23 #define NB_DEFAULT_MARGIN 2
25 // button label-text alignment types
27 #define NB_ALIGN_TEXT_RIGHT 0
28 #define NB_ALIGN_TEXT_BOTTOM 1
32 // classes declared in this header file
34 class wxNewBitmapButton
;
35 class wxBorderLessBitmapButton
;
38 This is an alternative class to wxBitmapButton. It is used
39 in the implementation of dynamic toolbars.
42 class wxNewBitmapButton
: public wxPanel
44 DECLARE_DYNAMIC_CLASS(wxNewBitmapButton
)
48 friend class wxNewBitmapButtonSerializer
;
58 wxString mImageFileName
;
59 wxBitmapType mImageFileType
;
61 wxBitmap mDepressedBmp
; // source image for rendering
62 // labels for particular state
64 wxBitmap mFocusedBmp
; // may not be always present -
65 // only if mHasFocusedBmp is TRUE
67 wxBitmap
* mpDepressedImg
;
68 wxBitmap
* mpPressedImg
;
69 wxBitmap
* mpDisabledImg
;
70 wxBitmap
* mpFocusedImg
;
72 // button state variables;
79 // type of event which is fired upon depression of this button
82 // pens for drawing decorations (borders)
93 // Internal function for destroying labels.
96 // Returns the label that matches the current button state.
97 virtual wxBitmap
* GetStateLabel();
99 // Draws shading on the button.
100 virtual void DrawShade( int outerLevel
,
102 wxPen
& upperLeftSidePen
,
103 wxPen
& lowerRightSidePen
);
105 // Returns TRUE if the given point is in the window.
106 bool IsInWindow( int x
, int y
);
111 wxNewBitmapButton( const wxBitmap
& labelBitmap
= wxNullBitmap
,
112 const wxString
& labelText
= "",
113 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
115 // this is the default type of fired events
116 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
117 int marginX
= NB_DEFAULT_MARGIN
,
118 int marginY
= NB_DEFAULT_MARGIN
,
119 int textToLabelGap
= 2,
120 bool isSticky
= FALSE
123 // Use this constructor if buttons have to be persistant
124 wxNewBitmapButton( const wxString
& bitmapFileName
,
125 const wxBitmapType bitmapFileType
= wxBITMAP_TYPE_BMP
,
126 const wxString
& labelText
= "",
127 int alignText
= NB_ALIGN_TEXT_BOTTOM
,
129 // this is the default type of fired events
130 int firedEventType
= wxEVT_COMMAND_MENU_SELECTED
,
131 int marginX
= NB_DEFAULT_MARGIN
,
132 int marginY
= NB_DEFAULT_MARGIN
,
133 int textToLabelGap
= 2,
134 bool isSticky
= FALSE
138 ~wxNewBitmapButton();
140 // This function should be called after Create. It renders the labels, having
141 // reloaded the button image if necessary.
142 virtual void Reshape();
144 // Sets the label and optionally label text.
145 virtual void SetLabel(const wxBitmap
& labelBitmap
, const wxString
& labelText
= "" );
147 // Sets the text alignment and margins.
148 virtual void SetAlignments( int alignText
= NB_ALIGN_TEXT_BOTTOM
,
149 int marginX
= NB_DEFAULT_MARGIN
,
150 int marginY
= NB_DEFAULT_MARGIN
,
151 int textToLabelGap
= 2);
153 // Draws the decorations.
154 virtual void DrawDecorations( wxDC
& dc
);
157 virtual void DrawLabel( wxDC
& dc
);
159 // Renders the label image.
160 virtual void RenderLabelImage( wxBitmap
*& destBmp
, wxBitmap
* srcBmp
,
161 bool isEnabled
= TRUE
,
162 bool isPressed
= FALSE
);
164 // Renders label images.
165 virtual void RenderLabelImages();
167 // Renders label images.
168 virtual void RenderAllLabelImages();
170 // Enables/disables button
171 virtual bool Enable(bool enable
);
173 // Responds to a left mouse button down event.
174 void OnLButtonDown( wxMouseEvent
& event
);
176 // Responds to a left mouse button up event.
177 void OnLButtonUp( wxMouseEvent
& event
);
179 // Responds to a left mouse button double click.
180 void OnLButtonDClick( wxMouseEvent
& event
);
182 // Responds to mouse enter to window.
183 void OnMouseEnter( wxMouseEvent
& event
);
185 // Responds to mouse leave from window.
186 void OnMouseLeave( wxMouseEvent
& event
);
188 // Responds to a size event.
189 void OnSize( wxSizeEvent
& event
);
191 // Responds to a paint event.
192 void OnPaint( wxPaintEvent
& event
);
194 // Responds to an erase background event.
195 void OnEraseBackground( wxEraseEvent
& event
);
197 // Responds to a kill focus event.
198 void OnKillFocus( wxFocusEvent
& event
);
200 // Maps bitmap to current system colours on Windows
202 WXHBITMAP
MapBitmap(WXHBITMAP bitmap
, int width
, int height
);
205 DECLARE_EVENT_TABLE()
208 #endif /* __NEWBMPBTN_G__ */