File: vdkb_radiobutton.cc

package info (click to toggle)
vdkbuilder2 2.4.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,680 kB
  • ctags: 4,989
  • sloc: cpp: 40,647; sh: 10,346; ansic: 2,718; makefile: 710; sed: 93
file content (295 lines) | stat: -rw-r--r-- 8,574 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 * ===========================
 * VDK Builder
 * Version 0.1.1
 * Revision 0.0
 * March 1999
 * ===========================
 *
 * Copyright (C) 1998, Mario Motta
 * Developed by Mario Motta <mmotta@guest.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-130
 */
#if HAVE_CONFIG_H
#include <config.h>
#endif

#if !HAVE_GNOME
  #if ENABLE_NLS
    #include <libintl.h>
//#define _(str) gettext(str)
#define _(str) \
    ( g_utf8_validate(gettext(str),-1,NULL) ? \
    gettext(str) : \
    g_locale_to_utf8(gettext(str),-1,NULL,NULL,NULL) )
#define N_(str) str
  #else
    #define _(str) str
    #define N_(str) str 
  #endif
#else
 #include <gnome.h>
#endif

#include <vdkb2/vdkb_radiobutton.h>
#include <vdkb2/vdkb_evbox.h>
#include <vdkb2/vdkb_utils.h>
#include <vdkb2/vdkb_form.h>
#include <vdkb2/vdkb_parser.h>
#include <vdkb2/vdkb_objinspect.h>
#include <vdkb2/vdkb_prjman.h>
#include <stdlib.h>
#include <vdkb2/vdkb_fixed.h>
/*
================================
symbolic constants to templatize
a bit
================================
*/
// for methods and other stuff
#define CLASS VDKBRadioButton
// put here vdk class name string
#define VDK_CLASS "VDKRadioButton"
// put here vdk class name
#define VDK_ANCESTOR  VDKRadioButton
// put here here the widget will be named
// (name+counter)
#define VDK_WIDGET "radiobutton"
extern char* wi_widget_prompts[];
static char buff[128];
extern bool onDraggingAnObjectIntoAFixed;
extern GtkWidget *grabbed_widget;
int
CLASS::OnButtonEvent(GtkWidget *w, GdkEvent* event, void* o)
{
  g_return_val_if_fail(o != NULL, FALSE);
  g_return_val_if_fail(w != NULL, FALSE);
  CLASS* obj = reinterpret_cast<CLASS*>(o);
  VDKBEventContainer* container;
  gtk_signal_emit_stop_by_name(GTK_OBJECT(w),
			       "button_press_event");
  container = dynamic_cast<VDKBEventContainer*>(obj->ObjectFromVDK()->Parent());
  if(container)
    container->OnButtonPressed(obj,event);
  return TRUE;
}

int
CLASS::OnEnterEvent(GtkWidget *w,
				  GdkEvent* event,
				  void* o)
{
  g_return_val_if_fail(o != NULL, FALSE);
  g_return_val_if_fail(w != NULL, FALSE);
  gtk_signal_emit_stop_by_name(GTK_OBJECT(w),"enter_notify_event");
  return true;
}

int
CLASS::OnLeaveEvent(GtkWidget *w,
				  GdkEvent* event,
				  void* o)
{
  g_return_val_if_fail(o != NULL, FALSE);
  g_return_val_if_fail(w != NULL, FALSE);
  gtk_signal_emit_stop_by_name(GTK_OBJECT(w),"leave_notify_event");
  return true;
}
//////////////////////////////////////////////////////////////
/*
  - constructor
 */
CLASS::CLASS(char* name, VDKForm* owner,
				 char* label, char* tip):
  VDKBCheckButton(name,owner,label,tip)
{
  gtk_widget_destroy(widget);
  widget = gtk_radio_button_new_with_label(NULL,label);
  // newly constructed widget counter is incremented
  // each time
  Counter++;
  // assign this to VDKBObject <object> member.
  object = this;
  gtk_signal_connect(GTK_OBJECT(widget),"button_press_event",
		   GTK_SIGNAL_FUNC(CLASS::OnButtonEvent),
			       reinterpret_cast<gpointer>(this));
  gtk_signal_connect(GTK_OBJECT(widget),"enter_notify_event",
		   GTK_SIGNAL_FUNC(CLASS::OnEnterEvent),
			       reinterpret_cast<gpointer>(this));
  gtk_signal_connect(GTK_OBJECT(widget),"leave_notify_event",
		   GTK_SIGNAL_FUNC(CLASS::OnLeaveEvent),
			       reinterpret_cast<gpointer>(this));

}
////////////////////////////////////////////////////////////////
//
//               WRITER TO .FRM FILE
//
///////////////////////////////////////////////////////////////
/*
Writes a .frm format representation of label button widget
This virtual function is called by VDKBForm::WriteBoxesOnFrm()
a recursive algorithm that scans VDKBForm widget tree.
*/
void
CLASS::WriteOnFrm(FILE* fp, VDKBObject* parentobj)
{
  // first of all call ancestor to write common properties
  VDKBObject::WriteOnFrm(fp,parentobj);
  fprintf(fp,"\n\t%s\"%s\";",
	  PROP_CAPTION,(char*) GetProp(CAPTION));
  fprintf(fp,"\n\t%s%s;",
	  PROP_CAPTIONWRAP,(char*) GetProp(CAPTIONWRAP));
}
//////////////////////////////////////////////////////////////////
//
//               PREPARE GUI WIDGETS
//
//////////////////////////////////////////////////////////////////
/*
This method is called by global MakeWidget() in vdkb_design.cc
MakeWidget() scans a table that maps class id's with each
static MakeWidget() for each class. Class id's are generated
during clicks on widget palette.
On return:
0 - successfull
1 - unsupported widget
2 - target is not a container
 */
int
CLASS::MakeWidget(VDKBGuiForm* owner, GdkEvent* ev)
{
  CLASS* button = NULL;
 // widget name generation failed
  if(!owner->GenerateWidgetName(buff,VDK_WIDGET,&CLASS::Counter))
    // unauthorized operation
    return 2;
  else
    button = new CLASS(buff,owner,buff);
  return owner->AddToSelf(button,ev);
}
/*
This is called by a global CreateSource() in vdkb_parser.cc.
CreateSource() scans a table that maps class names with
each static CreateSource() in widget class.
 */
char*
CLASS::CreateSource(char* buffer,VDKBParser& parser)
{
  char* source;
  char obj_name[128];
  char obj_parent[128];
  char arg[64];
  char tmp[256];
  char obj_caption[128];
  // gets widget name and parent name
  if(! parser.GetNameAndParent(buffer, obj_name, obj_parent))
     return NULL;
  bool nls_support = parser.CheckNLSSupport();
  source = new char[4096];
  if(!parser.GetParam(obj_caption,buffer,PROP_CAPTION))
    strcpy(obj_caption,"none");
  if(nls_support)
    sprintf(tmp,"\n%s = new %s(this,_(\"%s\"));",
	    obj_name,VDK_CLASS,obj_caption);
  else
    sprintf(tmp,"\n%s = new %s(this,\"%s\");",
	  obj_name,VDK_CLASS,obj_caption);
  strcpy(source,tmp);
  ///////////////////////////////////////
  // call ancestor to set common properties
  char* props = VDKBObject::CreateSource(buffer,parser,obj_name);
  if(props)
    {
      strcat(source,props);
      delete[] props;
    }
  // get label button  props
  if(parser.GetParam(arg,buffer,PROP_CAPTIONWRAP) &&
     strcmp(arg,NIHIL_PROP))
   {
     sprintf(tmp,"\n%s->%s = %s;",obj_name,CAPTIONWRAP,arg);
     strcat(source,tmp);
   }
  // set widget specific properties
  // get label button  props
  if(parser.GetParam(arg,buffer,PROP_CAPTIONWRAP) &&
     strcmp(arg,NIHIL_PROP)
     )
   {
     sprintf(tmp,"\n%s->%s = %s;",obj_name,CAPTIONWRAP,arg);
     strcat(source,tmp);
   }
  // get code that adds widget to container
  parser.WriteCodeToPack(obj_parent,obj_name,source,buffer,tmp);
  /*
    visible property must be wrote after adding it to a parent
    container. That's the reason why is written here and not
    in vdkb_object class as should be. Written only if == false
  */
  parser.WriteVisible( obj_name, arg, source,buffer,  tmp);
  return source;
}
/*
Invoked by VDKBGuiForm::MakeGuiObjects() during gui creation
reading .frm file.
MakeGuiObjects() scans .frm file and call a global CreateWidget()
that scans a table that maps class names with
each static CreateWidget() in widget class.
*/
bool
CLASS::CreateWidget(VDKBGuiForm* owner,
			      char* buffer,VDKBParser& parser)
{
  char obj_name[128];
  char obj_parent[128];
  char obj_caption[256];
  char arg[64];
  CLASS* button;
 // get widget name and parent
  if(! parser.GetNameAndParent(buffer, obj_name, obj_parent))
    return false;
  // get caption
  if(!parser.GetParam(obj_caption,buffer,PROP_CAPTION))
    strcpy(obj_caption,"none");
  VDKObject* p = owner->ChildWithName(obj_parent);
  VDKBEventContainer* container = p ?
    dynamic_cast<VDKBEventContainer*>(p) : (VDKBEventContainer*) NULL;
  if(container)
    {
      button = new CLASS(obj_name,owner,obj_caption);
      if(parser.GetParam(arg,buffer,PROP_CAPTIONWRAP) &&
	 strcmp(arg,NIHIL_PROP))
	{
	button->CaptionWrap = !strcmp(arg,CHECK_TRUE);
	button->SetPropValue(CAPTIONWRAP,arg);
	}
      // pack widget to container
      return owner->PackToSelf(button, container, buffer, parser);
    }
  else
    return false;
}