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