1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 0.4
5  * revision to 0.5.0
6  * October,November 1998
7  * ===========================
8  *
9  * Copyright (C) 1998, Mario Motta
10  * Developed by Mario Motta <mmotta@guest.net>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Library General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  * 02111-1307, USA.
26  *
27  */
28 
29 #include "vdk/toolbar.h"
30 #include "vdk/forms.h"
31 #include "vdk/vdkobj.h"
32 #include "vdk/colors.h"
33 #define DEFAULT_SPACE_SIZE  5
34 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_EMPTY
35 /*
36  */
37 static GtkWidget* new_pixmap_data (char **pixdata, GdkWindow *window, GdkColor  *background);
38 static GtkWidget* new_pixmap_file (char *pixfile, GdkWindow *window, GdkColor  *background);
39 
40 /*
41  */
~VDKToolbar()42 VDKToolbar::~VDKToolbar()
43 {
44 }
45 /*
46 */
47 void
Add(VDKObject * obj,int,int,int,int)48 VDKToolbar::Add(VDKObject* obj, int , int , int , int)
49 {
50 	AddWidget(obj);
51 }
52 /*
53 */
54 void
AddSpace()55 VDKToolbar::AddSpace()
56 {
57 	gtk_toolbar_append_space(GTK_TOOLBAR(widget));
58 }
59 /*
60 */
61 void
SetOrientation(GtkOrientation orientation)62 VDKToolbar::SetOrientation(GtkOrientation orientation)
63 {
64 	gtk_toolbar_set_orientation(GTK_TOOLBAR(widget),orientation);
65 }
66 /*
67 */
68 void
SetStyle(GtkToolbarStyle style)69 VDKToolbar::SetStyle(GtkToolbarStyle style)
70 {
71 	gtk_toolbar_set_style(GTK_TOOLBAR(widget),style);
72 }
73 /*
74 */
75 void
SetBorderless(bool flag)76 VDKToolbar::SetBorderless(bool flag)
77 {
78 	if (!flag) {
79 		//gtk_toolbar_set_button_relief (GTK_TOOLBAR (widget), GTK_RELIEF_NORMAL);
80 		SetRelief(GTK_RELIEF_NORMAL);
81 	}
82 	else {
83 		//gtk_toolbar_set_button_relief (GTK_TOOLBAR (widget), GTK_RELIEF_NONE);
84 		SetRelief(GTK_RELIEF_NONE);
85 	}
86 }
87 /*
88 */
89 void
SetSpacing(int s)90 VDKToolbar::SetSpacing(int s)
91 {
92 	//gtk_toolbar_set_space_size(GTK_TOOLBAR(widget),s);
93 	// gtk_object_set(GTK_OBJECT(widget), "space_size", s, NULL);
94 }
95 /*
96 */
97 void
SetSpaceStyle(GtkToolbarSpaceStyle style)98 VDKToolbar::SetSpaceStyle(GtkToolbarSpaceStyle style)
99 {
100 	//gtk_toolbar_set_space_style (GTK_TOOLBAR (widget), style);
101 	//gtk_object_set(GTK_OBJECT(widget), "space_style", style, NULL);
102 }
103 /*
104 */
105 GtkToolbarSpaceStyle
GetSpaceStyle()106 VDKToolbar::GetSpaceStyle()
107 {
108 	return (GtkToolbarSpaceStyle) 0; // return GTK_TOOLBAR(widget)->space_style;
109 }
110 /*
111 */
112 VDKObject*
operator [](int ndx)113 VDKToolbar::operator[](int ndx)
114 {
115 	if ((ndx >= 0) && (ndx < tool_buttons.size())) return tool_buttons[ndx];
116 	else return NULL;
117 }
118 /*
119  */
ButtonSignal(GtkWidget * wid,gpointer gp)120 void VDKToolbar::ButtonSignal(GtkWidget *wid, gpointer gp) {
121     int t = 0;
122     g_return_if_fail(wid != NULL);
123     g_return_if_fail(gp != NULL);
124     VDKToolbar* toolbar = reinterpret_cast<VDKToolbar*> (gp);
125     GtkWidgetListIterator li(toolbar->widgets);
126     for(;li;li++,t++)
127         if(wid == li.current())
128             break;
129     if(t < toolbar->widgets.size()) {
130         toolbar->ButtonPressed(t);
131         toolbar->SignalEmit(clicked_signal);
132     }
133 
134 }
135 /*
136  */
VDKToolbar(VDKForm * owner,GtkOrientation orientation)137 VDKToolbar::VDKToolbar(VDKForm* owner, GtkOrientation orientation):
138   VDKObjectContainer(owner),
139   WidgetList("WidgetList",this,NULL),
140   ButtonList("ButtonList",this,NULL),
141   ButtonPressed("ButtonPressed",this,-1),
142   Orientation("Orientation", this, GTK_ORIENTATION_HORIZONTAL,
143 	      &VDKToolbar::SetOrientation),
144   Style("Style",this,GTK_TOOLBAR_ICONS,&VDKToolbar::SetStyle),
145   SpaceStyle("SpaceStyle", this, DEFAULT_SPACE_STYLE,
146 	     &VDKToolbar::SetSpaceStyle, &VDKToolbar::GetSpaceStyle),
147   Borderless("Borderless",this,true,&VDKToolbar::SetBorderless),
148   Relief ("Relief", this, GTK_RELIEF_NONE, &VDKToolbar::SetRelief),
149   Spacing("Spacing",this,DEFAULT_SPACE_SIZE,&VDKToolbar::SetSpacing)
150 {
151   widget = gtk_toolbar_new(/*orientation,GTK_TOOLBAR_ICONS*/);
152   WidgetList(&toolWidgets);
153   ButtonList(&widgets);
154 }
155 
AddWidget(VDKObject * obj,char * tip)156 void VDKToolbar::AddWidget(VDKObject* obj,char* tip)
157 {
158   gtk_toolbar_append_widget(GTK_TOOLBAR(widget),
159 			    obj->Widget(),
160 			    tip,NULL);
161   //gtk_widget_show(obj->Widget());
162   // items.add(obj);
163   toolWidgets.add(obj);
164   //obj->Parent(this);
165   // obj->Setup();
166   VDKObjectContainer::Add(obj,l_justify,0,0,0);
167 }
168 
169 /*
170 */
AddButton(char ** pixdata,char * tip,char * text)171 void VDKToolbar::AddButton(char** pixdata,
172 			   char* tip,
173                            char* text) {
174     GtkWidget *button;
175     GtkWidget *pixmap = pixdata ?
176         new_pixmap_data (pixdata, Owner()->Window()->window, &widget->style->bg[GTK_STATE_NORMAL]) :
177         NULL ;
178 
179     button = gtk_toolbar_append_item (GTK_TOOLBAR (widget), text, NULL,
180                                       NULL, pixmap, GTK_SIGNAL_FUNC(VDKToolbar::ButtonSignal),
181                                       (gpointer) this);
182     VDKObject* tbutton = new VDKObject(Owner(),button);
183     Owner()->Items().add(tbutton);
184     tool_buttons.add(tbutton);
185     if(tip)
186         tbutton->SetTip(tip);
187     widgets.add(button);
188     return ;
189 }
190 
AddButton(char * pixfile,char * tip,char * text)191 void VDKToolbar::AddButton(char* pixfile,
192 			   char* tip,
193                            char* text) {
194     GtkWidget *button;
195     GtkWidget *pixmap = pixfile ?
196         new_pixmap_file (pixfile, Owner()->Window()->window, &widget->style->bg[GTK_STATE_NORMAL]) :
197         NULL ;
198 
199     button = gtk_toolbar_append_item (GTK_TOOLBAR (widget), text, NULL,
200                                       NULL, pixmap, GTK_SIGNAL_FUNC(VDKToolbar::ButtonSignal),
201                                       (gpointer) this);
202     VDKObject* tbutton = new VDKObject(Owner(),button);
203     Owner()->Items().add(tbutton);
204 
205     tool_buttons.add(tbutton);
206     if(tip)
207         tbutton->SetTip(tip);
208     widgets.add(button);
209     return ;
210 }
211 
212 void
SetRelief(GtkReliefStyle style)213 VDKToolbar::SetRelief(GtkReliefStyle style)
214 {
215 
216   GList *children;
217   GtkToolbarChild *child;
218   GtkToolbar* tbar = GTK_TOOLBAR(WrappedWidget());
219   for (children = tbar->children; children; children = children->next)
220     {
221       child = (GtkToolbarChild *) children->data;
222       if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
223 	  child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
224 	  child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
225 	gtk_button_set_relief (GTK_BUTTON (child->widget), GTK_RELIEF_NONE);
226     }
227   gtk_widget_queue_resize (GTK_WIDGET (tbar));
228 
229 }
230 
new_pixmap_data(char ** pixdata,GdkWindow * window,GdkColor * background)231 GtkWidget* new_pixmap_data (char **pixdata, GdkWindow *window, GdkColor  *background) {
232 
233     GtkWidget *wpixmap;
234     GdkPixmap *pixmap;
235     GdkBitmap *mask;
236 
237     pixmap = gdk_pixmap_create_from_xpm_d (window, &mask, background, pixdata);
238     wpixmap = gtk_pixmap_new (pixmap, mask);
239     return wpixmap;
240 }
241 
new_pixmap_file(char * pixfile,GdkWindow * window,GdkColor * background)242 GtkWidget* new_pixmap_file (char *pixfile, GdkWindow *window, GdkColor  *background) {
243 
244     GtkWidget *wpixmap;
245     GdkPixmap *pixmap;
246     GdkBitmap *mask;
247 
248     pixmap = gdk_pixmap_create_from_xpm (window, &mask, background, pixfile);
249     wpixmap = gtk_pixmap_new (pixmap, mask);
250     return wpixmap;
251 }
252 
253 
254 
255