vdk 2.4.0
vdkcustombutton.h
1 /*
2  * ===========================
3  * VDK Visual Develeopment Kit
4  * Version 0.6.2
5  * May 1999
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26 
27 #ifndef _vdkcustombutton_h
28 #define _vdkcustombutton_h
29 #include <vdk/vdkobj.h>
30 #include <vdk/boxes.h>
31 #include <vdk/label.h>
32 #include <vdk/image.h>
33 #include <vdk/menu.h>
34 // #include <vdk/gtkcombobutton.h>
48 {
49  protected:
50  void ConnectButtonSignals();
51  static void ToggleEvent(GtkWidget *wid, gpointer gp);
52  public:
53 // properties
59  VDKReadOnlyValueProp<VDKCustomButton, VDKBox*> ButtonBox;
72  VDKReadOnlyValueProp<VDKCustomButton, VDKLabel*> Label;
77  VDKReadOnlyValueProp<VDKCustomButton, VDKImage*> Pixmap;
81  VDKReadWriteValueProp<VDKCustomButton, const char*> Caption;
85  VDKReadWriteValueProp<VDKCustomButton, bool> CaptionWrap;
86  /*
87  !
88  Permits to set/get checked state (meaningless if isn't
89  a toggle button
90  */
91  VDKReadWriteValueProp<VDKCustomButton, bool> Checked;
92  /*
93  !
94  Permits to set/get button relief (meaningless if is
95  a toggle button
96  */
97  VDKReadWriteValueProp<VDKCustomButton, GtkReliefStyle> Relief;
121  VDKCustomButton(VDKForm* owner,
122  const char* label,
123  unsigned int type =
124  VDK_CBUTTON_UNTOGGLED | VDK_CBUTTON_NORMAL);
132  VDKCustomButton(VDKForm* owner,
133  const char* pixfile,
134  const char* label,
135  unsigned int type =
136  VDK_CBUTTON_UNTOGGLED | VDK_CBUTTON_NORMAL,
137  GtkPositionType position = GTK_POS_RIGHT);
141  VDKCustomButton(VDKForm* owner,
142  const char** pixdata,
143  const char* label,
144  unsigned int type =
145  VDK_CBUTTON_UNTOGGLED | VDK_CBUTTON_NORMAL,
146  GtkPositionType position = GTK_POS_RIGHT);
147 
148  ~VDKCustomButton();
154  void SetComboMenu(VDKMenu* menu);
155 
156  /*
157  */
158  virtual void SetForeground(VDKRgb color,
159  GtkStateType state = GTK_STATE_NORMAL)
160  {
161  VDKLabel *label = Label;
162  if( label)
163  _setForeground_(label->Widget(),
164  color.red,
165  color.green,
166  color.blue,
167  state);
168  }
169  /*
170  */
171  virtual void SetFont(VDKFont* font)
172  {
173  VDKLabel *label = Label;
174  if( label)
175  _setFont_(label->Widget(),font);
176  }
177  /*
178  */
179  void SetCaption(const char* str)
180  {
181  VDKLabel *label = Label;
182  if( label)
183  label->Caption = str;
184  }
185  /*
186  */
187  const char* GetCaption ()
188  {
189  VDKLabel *label = Label;
190  if( label)
191  return label->Caption;
192  else
193  return (const char*) NULL;
194  }
195  /*
196  */
197  void SetCaptionWrap (bool flag)
198  {
199  VDKLabel *label = Label;
200  if( label)
201  gtk_label_set_line_wrap (GTK_LABEL (label->Widget()), flag);
202  }
203  /*
204  */
205  bool GetCaptionWrap ()
206  {
207  VDKLabel *label = Label;
208  if( label)
209  return GTK_LABEL (label->Widget())->wrap;
210  else
211  return false;
212  }
213  /*
214  */
215  void SetRelief(GtkReliefStyle style)
216  {
217  if(GTK_IS_BUTTON(widget))
218  gtk_button_set_relief(GTK_BUTTON(widget), style);
219  }
220  /*
221  */
222  GtkReliefStyle GetRelief()
223  {
224  if(GTK_IS_BUTTON(widget))
225  return gtk_button_get_relief(GTK_BUTTON(widget));
226  else
227  return GTK_RELIEF_NORMAL;
228  }
229  /*
230  */
231  void Toggle() {
232  if(GTK_IS_TOGGLE_BUTTON(widget))
233  Checked = Checked ? false : true;
234  }
235  /*
236  */
237  void SetChecked(bool flag)
238  {
239  if(GTK_IS_TOGGLE_BUTTON(widget))
240  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(widget),flag);
241  }
242  /*
243  */
244  bool GetChecked()
245  {
246  if(GTK_IS_TOGGLE_BUTTON(widget))
247  return GTK_TOGGLE_BUTTON(widget)->active ? true : false;
248  else
249  return false;
250  }
251  /*
252  */
253  virtual void Enable(bool flag = true);
254 #ifdef USE_SIGCPLUSPLUS
255  public:
261  VDKSignal1<void, bool> OnButtonToggled;
266  VDKSignal0<void> OnButtonClicked;
271  VDKSignal0<void> OnButtonPressed;
276  VDKSignal0<void> OnButtonLeave;
277  private:
278  static void _handle_clicked(GtkWidget*, gpointer);
279  static void _handle_pressed(GtkWidget*, gpointer);
280  static void _handle_leave(GtkWidget*, gpointer);
281 #endif /* USE_SIGCPLUSPLUS */
282 };
283 
284 #endif
Definition: vdkobj.h:137
This class provides an unified wrapper for almost all kind of GtkButton.
Definition: vdkcustombutton.h:47
VDKReadOnlyValueProp< VDKCustomButton, VDKImage * > Pixmap
Definition: vdkcustombutton.h:77
VDKForm widgets, generally the outermost widget container.
Definition: forms.h:68
VDKReadWriteValueProp< VDKLabel, const char * > Caption
Definition: label.h:51
Provides a simple RGB color structure.
Definition: vdkutils.h:37
VDKCustomButton(VDKForm *owner, const char *label, unsigned int type=VDK_CBUTTON_UNTOGGLED|VDK_CBUTTON_NORMAL)
Definition: vdkcustombutton.cc:81
void SetComboMenu(VDKMenu *menu)
Definition: vdkcustombutton.cc:440
virtual void SetFont(VDKFont *font)
Definition: vdkcustombutton.h:171
GtkWidget * widget
Definition: vdkobj.h:241
virtual GtkWidget * Widget()
Definition: vdkobj.cc:49
virtual void SetForeground(VDKRgb color, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkcustombutton.h:158
VDKReadOnlyValueProp< VDKCustomButton, VDKLabel * > Label
Definition: vdkcustombutton.h:72
Provides a gtklabel wrapper.
Definition: label.h:40
VDKReadWriteValueProp< VDKCustomButton, const char * > Caption
Definition: vdkcustombutton.h:81
Provides a raw font.
Definition: vdkfont.h:37
VDKReadOnlyValueProp< VDKCustomButton, VDKBox * > ButtonBox
Definition: vdkcustombutton.h:59
VDKReadWriteValueProp< VDKCustomButton, bool > CaptionWrap
Definition: vdkcustombutton.h:85
Provides a menu items container.
Definition: menu.h:67