1 /*
2 * ===========================
3 * VDK Visual Development Kit
4 * Version 0.5
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
28
29 #include "vdk/vdkcustom.h"
30 #include "vdk/forms.h"
31 #define color_nihil VDKRgb(-1,-1,-1)
32
33 // Tuple class
Tuple(int n,int key)34 Tuple::Tuple(int n, int key) : StringArray(n),KeyIndex(key)
35 {
36 }
37
~Tuple()38 Tuple::~Tuple()
39 {
40 }
41
42 int
operator <(Tuple & t)43 Tuple::operator < (Tuple& t)
44 {
45 return (*this)[KeyIndex] < t[KeyIndex];
46 }
47 int
operator ==(Tuple & t)48 Tuple::operator == (Tuple& t)
49 {
50 return (*this)[KeyIndex] == t[KeyIndex];
51 }
52
53 // VDKCustom class
ColumnClick(GtkWidget *,gint column,gpointer s)54 void VDKCustom::ColumnClick(GtkWidget* ,
55 gint column,
56 gpointer s)
57 {
58 g_return_if_fail(s != NULL);
59 VDKObjectSignal* signal =
60 reinterpret_cast<VDKObjectSignal*>(s);
61 VDKCustom* obj = reinterpret_cast<VDKCustom*>(signal->obj);
62 obj->SelectedTitle(column);
63 obj->SignalEmit(signal->signal);
64 obj->SignalEmit("click_column");
65 }
66 /////////////////////////////////////////////////
67 /*
68 */
VDKCustom(VDKForm * owner,int columns,char ** titles,GtkSelectionMode mode)69 VDKCustom::VDKCustom(VDKForm* owner,
70 int columns,
71 char** titles,
72 GtkSelectionMode mode):
73 VDKObject(owner),
74 VPolicy("VPolicy",this,GTK_POLICY_AUTOMATIC,&VDKCustom::SetVPolicy),
75 HPolicy("HPolicy",this,GTK_POLICY_AUTOMATIC,&VDKCustom::SetHPolicy),
76 BorderShadow("BorderShadow",this,GTK_SHADOW_ETCHED_OUT,
77 &VDKCustom::SetBorderShadow),
78 RowHeight("RowHeight",this,0,&VDKCustom::SetRowHeight),
79 AutoResize("AutoResizeColumn",this,false,
80 &VDKCustom::SetAutoResize),
81 SelectedForeground("SelectedForeground",this,color_nihil,
82 &VDKCustom::SetSelectedForeground),
83 UnselectedBackground("UnselectedBackground",this,color_nihil,
84 &VDKCustom::SetUnselectedBackground),
85 UnselectedForeground("UnselectedForeground",this,color_nihil,
86 &VDKCustom::SetUnselectedForeground),
87 SelectedTitle("SelectedTitle",this,-1),
88 columns(columns),
89 mode(mode)
90 {
91 if(titles)
92 Titles = VDKObjectArray(columns);
93 custom_widget = NULL;
94 widget = gtk_scrolled_window_new (NULL, NULL);
95 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget),
96 GTK_POLICY_AUTOMATIC,
97 GTK_POLICY_AUTOMATIC);
98
99 }
100 /*
101 */
~VDKCustom()102 VDKCustom::~VDKCustom()
103 {
104 }
105
106 int
ColumnClicked()107 VDKCustom::ColumnClicked()
108 {
109 return SelectedTitle;
110 }
111
112 GtkWidget*
CustomWidget()113 VDKCustom::CustomWidget()
114 {
115 return GTK_WIDGET(custom_widget);
116 }
117
118 void
Freeze()119 VDKCustom::Freeze()
120 {
121 gtk_clist_freeze(GTK_CLIST(custom_widget));
122 }
123
124 void
Thaw()125 VDKCustom::Thaw()
126 {
127 gtk_clist_thaw(GTK_CLIST(custom_widget));
128 }
129
130 void
Clear()131 VDKCustom::Clear()
132 {
133 gtk_clist_clear (GTK_CLIST(custom_widget));
134 }
135
136 int
Size()137 VDKCustom::Size()
138 {
139 return GTK_CLIST(custom_widget)->rows;
140 }
141
142 /*
143 */
144 void
ConnectSignals()145 VDKCustom::ConnectSignals()
146 {
147 s_list_click_column.obj = this;
148 s_list_click_column.signal = click_column_signal;
149 gtk_signal_connect(GTK_OBJECT(custom_widget),
150 "click_column",
151 GTK_SIGNAL_FUNC(VDKCustom::ColumnClick),
152 (gpointer) &s_list_click_column);
153 }
154 /*
155 */
156 void
SetBackground(VDKRgb c,GtkStateType state)157 VDKCustom::SetBackground(VDKRgb c, GtkStateType state)
158 {
159 VDKColor *color = NULL;
160 if( !custom_widget)
161 return;
162 else
163 {
164 if(Owner())
165 color = new VDKColor(Owner(),c.red,c.green,c.blue);
166 else
167 color = new VDKColor(this, c.red,c.green,c.blue);
168 }
169 if(state != GTK_STATE_SELECTED)
170 gtk_widget_modify_base (custom_widget, state,color->Color());
171 else
172 gtk_widget_modify_bg (custom_widget, state,color->Color());
173 };
174 /*
175 */
176 void
SetForeground(VDKRgb color,GtkStateType state)177 VDKCustom::SetForeground(VDKRgb color, GtkStateType state)
178 {
179 if(custom_widget)
180 _setForeground_(custom_widget,color.red,color.green,color.blue, state);
181 }
182
183 /*
184 void
185 VDKCustom::SetSelectedBackground(VDKColor* bg)
186 {
187 gtk_widget_modify_bg(custom_widget,GTK_STATE_SELECTED ,bg ? bg->Color() : NULL);
188 }
189 */
190
191 void
SetSelectedForeground(VDKRgb rgb)192 VDKCustom::SetSelectedForeground(VDKRgb rgb)
193 {
194 VDKColor *fg = new VDKColor(Owner(),rgb.red,rgb.green,rgb.blue);
195 gtk_widget_modify_fg(custom_widget,GTK_STATE_SELECTED ,fg ? fg->Color() : NULL);
196 }
197
198 void
199
200 /*
201 deprecated, reverts to normal background
202 */
SetUnselectedBackground(VDKRgb rgb)203 VDKCustom::SetUnselectedBackground(VDKRgb rgb)
204 {
205 VDKColor *bg = new VDKColor(Owner() ,rgb.red,rgb.green,rgb.blue);
206 gtk_widget_modify_base(custom_widget,GTK_STATE_NORMAL ,bg ? bg->Color() : NULL);
207 }
208 /*
209 deprecated, reverts to normal foreground
210 */
211 void
SetUnselectedForeground(VDKRgb rgb)212 VDKCustom::SetUnselectedForeground(VDKRgb rgb)
213 {
214 VDKColor *fg = new VDKColor(Owner() ,rgb.red,rgb.green,rgb.blue);
215 gtk_widget_modify_fg(custom_widget,GTK_STATE_NORMAL ,fg ? fg->Color() : NULL);
216 }
217 /*
218 */
219 void
SetFont(VDKFont * font)220 VDKCustom::SetFont(VDKFont* font)
221 {
222 if(custom_widget)
223 _setFont_(custom_widget,font);
224 }
225
226 /*
227 */
ActiveTitle(int col,bool flag)228 void VDKCustom::ActiveTitle(int col,bool flag)
229 {
230 if(Titles.size() <= 0)
231 return;
232 if(flag)
233 gtk_clist_column_title_active(GTK_CLIST(custom_widget),col);
234 else
235 gtk_clist_column_title_passive(GTK_CLIST(custom_widget),col);
236 }
237 /*
238 */
ActiveTitles(bool flag)239 void VDKCustom::ActiveTitles(bool flag)
240 {
241 for(int t = 0; t < columns; t++)
242 ActiveTitle(t,flag);
243 }
244 /*
245 */
246 void
EnableTitles(bool flag)247 VDKCustom::EnableTitles(bool flag)
248 {
249 for(int t = 0; t < columns; t++)
250 Titles[t]->Enable(flag);
251 }
252 /*
253 */
254 GtkSelectionMode
SelectionMode()255 VDKCustom::SelectionMode() { return mode; }
256
257 /*
258 */
259 void
ColumnSize(int col,int size)260 VDKCustom::ColumnSize(int col, int size)
261 {
262 if(col < 0 || col >= columns)
263 return ;
264 gtk_clist_set_column_width (GTK_CLIST(custom_widget), col, size);
265 return;
266 }
267 /*
268 */
269 void
SetAutoResize(bool flag)270 VDKCustom::SetAutoResize(bool flag)
271 {
272 for(int i = 0; i < columns; i++)
273 gtk_clist_set_column_auto_resize(GTK_CLIST(custom_widget),
274 i, (gboolean) flag);
275
276 }
277 /*
278 */
279 void
AutoResizeColumn(int col,bool flag)280 VDKCustom::AutoResizeColumn(int col,bool flag)
281 {
282 gtk_clist_set_column_resizeable(GTK_CLIST(custom_widget),
283 col, (gboolean) flag);
284 }
285
286
287 #ifdef USE_SIGCPLUSPLUS
288 void
make_gtksigc_connection(VDKCustom * obj)289 VDKCustom::make_gtksigc_connection(VDKCustom* obj)
290 {
291 gtk_signal_connect(GTK_OBJECT(obj->CustomWidget()), "click_column",
292 GTK_SIGNAL_FUNC(VDKCustom::_handle_click_column),
293 (gpointer) obj);
294 }
295
296 void
_handle_click_column(GtkWidget * wid,int col,gpointer gp)297 VDKCustom::_handle_click_column(GtkWidget* wid, int col,
298 gpointer gp)
299 {
300 VDKCustom* obj=reinterpret_cast<VDKCustom*>(gp);
301 obj->OnColumnClick(obj, col);
302 }
303 #endif /* USE_SIGCPLUSPLUS */
304