]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/fl/newbmpbtn.h
Source cleaning: whitespaces, tabs, TRUE/true, FALSE/false, -1/wxID_ANY/wxDefaultCoor...
[wxWidgets.git] / contrib / include / wx / fl / newbmpbtn.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: newbmpbtn.h
3 // Purpose: wxNewBitmapButton header.
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: ??/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __NEWBMPBTN_G__
13 #define __NEWBMPBTN_G__
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "newbmpbtn.h"
17 #endif
18
19 #include "wx/button.h"
20 #include "wx/string.h"
21 #include "wx/fl/fldefs.h"
22
23 // defaults
24 #define NB_DEFAULT_MARGIN 2
25
26 // button label-text alignment types
27
28 #define NB_ALIGN_TEXT_RIGHT 0
29 #define NB_ALIGN_TEXT_BOTTOM 1
30 #define NB_NO_TEXT 2
31 #define NB_NO_IMAGE 3
32
33 // classes declared in this header file
34
35 class WXDLLIMPEXP_FL wxNewBitmapButton;
36 class WXDLLIMPEXP_FL wxBorderLessBitmapButton;
37
38 /*
39 This is an alternative class to wxBitmapButton. It is used
40 in the implementation of dynamic toolbars.
41 */
42
43 class wxNewBitmapButton: public wxPanel
44 {
45 DECLARE_DYNAMIC_CLASS(wxNewBitmapButton)
46
47 protected:
48
49 friend class wxNewBitmapButtonSerializer;
50
51 int mTextToLabelGap;
52 int mMarginX;
53 int mMarginY;
54 int mTextAlignment;
55 bool mIsSticky;
56 bool mIsFlat;
57
58 wxString mLabelText;
59 wxString mImageFileName;
60 wxBitmapType mImageFileType;
61
62 wxBitmap mDepressedBmp; // source image for rendering
63 // labels for particular state
64
65 wxBitmap mFocusedBmp; // may not be always present -
66 // only if mHasFocusedBmp is true
67
68 wxBitmap* mpDepressedImg;
69 wxBitmap* mpPressedImg;
70 wxBitmap* mpDisabledImg;
71 wxBitmap* mpFocusedImg;
72
73 // button state variables;
74 bool mDragStarted;
75 bool mIsPressed;
76 bool mIsInFocus;
77 bool mIsToggled;
78
79 bool mHasFocusedBmp;
80
81 // type of event which is fired upon depression of this button
82 int mFiredEventType;
83
84 // pens for drawing decorations (borders)
85 wxPen mBlackPen;
86 wxPen mDarkPen;
87 wxPen mGrayPen;
88 wxPen mLightPen;
89
90 bool mIsCreated;
91 int mSizeIsSet;
92
93 protected:
94
95 // Internal function for destroying labels.
96 void DestroyLabels();
97
98 // Returns the label that matches the current button state.
99 virtual wxBitmap* GetStateLabel();
100
101 // Draws shading on the button.
102 virtual void DrawShade( int outerLevel,
103 wxDC& dc,
104 wxPen& upperLeftSidePen,
105 wxPen& lowerRightSidePen );
106
107 // Returns true if the given point is in the window.
108 bool IsInWindow( int x, int y );
109
110 virtual void OnIdle(wxIdleEvent& event);
111 // (EVT_UPDATE_UI handler)
112 virtual void DoButtonUpdate();
113
114 public:
115
116 // Constructor.
117 wxNewBitmapButton( const wxBitmap& labelBitmap = wxNullBitmap,
118 const wxString& labelText = wxT(""),
119 int alignText = NB_ALIGN_TEXT_BOTTOM,
120 bool isFlat = true,
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
127 );
128
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,
134 bool isFlat = true,
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
141 );
142
143 // Destructor.
144 ~wxNewBitmapButton();
145
146 // This function should be called after Create. It renders the labels, having
147 // reloaded the button image if necessary.
148 virtual void Reshape();
149
150 // Sets the label and optionally label text.
151 virtual void SetLabel(const wxBitmap& labelBitmap, const wxString& labelText = wxT("") );
152
153 // Unhide method from parents.
154
155 virtual void SetLabel(const wxString& label)
156 { wxPanel::SetLabel(label); };
157
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);
163
164 // Draws the decorations.
165 virtual void DrawDecorations( wxDC& dc );
166
167 // Draws the label.
168 virtual void DrawLabel( wxDC& dc );
169
170 // Renders the label image.
171 virtual void RenderLabelImage( wxBitmap*& destBmp, wxBitmap* srcBmp,
172 bool isEnabled = true,
173 bool isPressed = false);
174
175 // Renders label images.
176 virtual void RenderLabelImages();
177
178 // Renders label images.
179 virtual void RenderAllLabelImages();
180
181 // Enables/disables button
182 virtual bool Enable(bool enable);
183
184 // Depress button
185 virtual bool Toggle(bool enable);
186
187 // Responds to a left mouse button down event.
188 void OnLButtonDown( wxMouseEvent& event );
189
190 // Responds to a left mouse button up event.
191 void OnLButtonUp( wxMouseEvent& event );
192
193 // Responds to mouse enter to window.
194 void OnMouseEnter( wxMouseEvent& event );
195
196 // Responds to mouse leave from window.
197 void OnMouseLeave( wxMouseEvent& event );
198
199 // Responds to a size event.
200 void OnSize( wxSizeEvent& event );
201
202 // Responds to a paint event.
203 void OnPaint( wxPaintEvent& event );
204
205 // Responds to an erase background event.
206 void OnEraseBackground( wxEraseEvent& event );
207
208 // Responds to a kill focus event.
209 void OnKillFocus( wxFocusEvent& event );
210
211 DECLARE_EVENT_TABLE()
212 };
213
214 #endif /* __NEWBMPBTN_G__ */
215