1 /*
2 * ===========================
3 * VDK Visual Development Kit
4 * Version 0.4
5 * October 1998
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 #include "vdk/checkbutton.h"
28 #include "vdk/forms.h"
29 #include "vdk/tooltips.h"
30 #include "vdk/colors.h"
31 /*
32 should be investigated more since
33 seems to be unuseless, perhaps this
34 compiler is'nt full ANSI compliant
35 */
36 /*
37 template <class T>
38 void vdk_cast(T** obj ,void* gp)
39 {
40 T* addr = reinterpret_cast<T*>(gp);
41 *obj = dynamic_cast<T*>(addr);
42 }
43 */
44
ToggleEvent(GtkWidget * wid,gpointer gp)45 void VDKCheckButton::ToggleEvent(GtkWidget *wid, gpointer gp)
46 {
47 g_return_if_fail(wid != NULL);
48 g_return_if_fail(gp != NULL);
49 VDKCheckButton* obj = reinterpret_cast<VDKCheckButton*>(gp);
50 obj->Checked(GTK_TOGGLE_BUTTON(wid)->active ? true : false);
51 obj->SignalEmit(toggled_signal);
52 #ifdef USE_SIGCPLUSPLUS
53 obj->OnButtonToggled(obj, GTK_TOGGLE_BUTTON(wid)->active ? true : false);
54 #endif /* USE_SIGCPLUSPLUS */
55 }
56
VDKCheckButton(VDKForm * owner,char * label,char * tip)57 VDKCheckButton::VDKCheckButton(VDKForm* owner, char* label, char* tip):
58 VDKAbstractButton(owner),
59 Checked ("Checked", this, false, &VDKCheckButton::SetChecked,
60 &VDKCheckButton::GetChecked),
61 Caption ("Caption", this, label, &VDKCheckButton::SetCaption,
62 &VDKCheckButton::GetCaption),
63 CaptionWrap ("CaptionWrap", this, true, &VDKCheckButton::SetCaptionWrap,
64 &VDKCheckButton::GetCaptionWrap)
65 {
66 if (label) widget = gtk_check_button_new_with_label(label);
67 else widget = gtk_check_button_new ();
68 connectId = gtk_signal_connect(GTK_OBJECT(widget),"toggled",
69 GTK_SIGNAL_FUNC(VDKCheckButton::ToggleEvent),
70 reinterpret_cast<gpointer>(this));
71 #ifdef USE_SIGCPLUSPLUS
72 make_gtksigc_connection(this, widget);
73 #endif /* USE_SIGCPLUSPLUS */
74 if (tip) tooltip = new VDKTooltip(owner, this, tip);
75 else tooltip = 0;
76 ConnectDefaultSignals();
77 }
78
~VDKCheckButton()79 VDKCheckButton::~VDKCheckButton()
80 {
81 }
82
83 void
Toggle()84 VDKCheckButton::Toggle()
85 {
86 Checked = Checked ? false : true;
87 }
88
89 void
SetChecked(bool flag)90 VDKCheckButton::SetChecked(bool flag)
91 {
92 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(widget),flag);
93 }
94
95 bool
GetChecked()96 VDKCheckButton::GetChecked()
97 {
98 return GTK_TOGGLE_BUTTON(widget)->active ? true : false;
99 }
100
SetCaption(char * str)101 void VDKCheckButton::SetCaption(char* str)
102 {
103 gtk_label_set_text (GTK_LABEL(GTK_BIN(widget)->child),str);
104 }
105
GetCaption()106 char* VDKCheckButton::GetCaption () {
107 return GTK_LABEL (GTK_BIN(widget)->child)->label;
108 }
109
SetCaptionWrap(bool flag)110 void VDKCheckButton::SetCaptionWrap (bool flag) {
111 gtk_label_set_line_wrap (GTK_LABEL (GTK_BIN(widget)->child), flag);
112 }
113
GetCaptionWrap()114 bool VDKCheckButton::GetCaptionWrap () {
115 return GTK_LABEL (GTK_BIN(widget)->child)->wrap;
116 }
117
118 void
SetForeground(VDKRgb color,GtkStateType state)119 VDKCheckButton::SetForeground(VDKRgb color, GtkStateType state)
120 {
121 VDKColor *vdkcolor = NULL;
122 if(!GTK_IS_WIDGET(widget))
123 return;
124 else
125 {
126 GtkButton* button = GTK_BUTTON(widget);
127 GtkLabel* label = GTK_LABEL(GTK_BIN (button)->child);
128
129 // vdkcolor = new VDKColor(/*Owner() ? Owner() : */this ,color);
130 vdkcolor = new VDKColor(Owner() ? static_cast<VDKObject*>(Owner())
131 : static_cast<VDKObject*>(this)
132 ,color);
133 gtk_widget_modify_fg (GTK_WIDGET(label),
134 state, vdkcolor->Color());
135 }
136 }
137
138 void
SetFont(VDKFont * font)139 VDKCheckButton::SetFont(VDKFont* font)
140 {
141 if(!GTK_IS_WIDGET(widget))
142 return;
143 else
144 {
145 GtkButton* button = GTK_BUTTON(widget);
146 GtkWidget* label = GTK_WIDGET(GTK_BIN (button)->child);
147 VDKObject::_setFont_(label,font);
148 }
149 }
150