File: vdkb_rbgroup.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 (491 lines) | stat: -rw-r--r-- 13,321 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/*
 * ===========================
 * VDK Builder
 * Version 0.1.1
 * Revision 0.0
 * March 1999
 * ===========================
 *
 * Copyright (C) 1998,1999 Mario Motta
 * Developed by Mario Motta <mmotta@guest.net>
 *
 * Based on VDK Library
 * Copyright (C) 1998, Mario Motta
 *
 * 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-1307, USA.
 *
 */
#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_evcontain.h>
//#include <vdkb2/vdkb_labelbutton.h>
#include <vdkb2/vdkb_form.h>
#include <vdk/vdk.h>
#include <vdkb2/vdkb_utils.h>
#include <vdkb2/vdkb_parser.h>
#include <vdkb2/vdkb_prjman.h>
#include <vdkb2/vdkb_objinspect.h>
#include <vdkb2/vdkb_paned.h>
#include <vdkb2/vdkb_notebook.h>
#include <vdkb2/vdkb_table.h>
#include <vdkb2/vdkb_frame.h>
#include <vdkb2/vdkb_rbgroup.h>
#include <vdkb2/vdkb_radiobutton.h>
#include <vdkb2/vdkb_object.h>
#include <vdkb2/vdkb_fixed.h>
#include <stdlib.h>
static char buff[128];
char* vdkrbuttongroup_signals[] =
{
"toggled_signal",0
};
char* vdkrbuttongroup_nicknames[] =
{
"Toggled",0
};
///////////////////////////////////////////////////////////////////////
/*
Makes a box thats is owned by a form
 */
VDKBRadioButtonGroup::VDKBRadioButtonGroup(char* name,
			   VDKForm* owner, int mode, int w, int h):
  VDKBEventBox(name,owner,mode)
{
Init();
}
/*
makes a box owned by another box
 */
VDKBRadioButtonGroup::VDKBRadioButtonGroup(char* name,
			   VDKBEventContainer* outer, int mode, int w, int h):
    VDKBEventBox(name,outer,mode)
{
Init();
}
/*
 */
void
VDKBRadioButtonGroup::Init()
{
  int t;
  if(delBox)
    delBox->Caption = _("Remove Radio button group");
  for(t=0; vdkrbuttongroup_signals[t]; t++)
    siglist.add(VDKBSignal(vdkrbuttongroup_signals[t],
			   this,
			   vdkrbuttongroup_nicknames[t]));
}
////////////////////////////////////////
/*
 */
void
VDKBRadioButtonGroup::Add(VDKObject* obj, int justify,
		 int expand, int fill , int padding)
{
  AddWidget(obj,justify, expand, fill, padding,true);
 }
/*
 */
void
VDKBRadioButtonGroup::AddWidget(VDKObject* wid, int justify,
			int expand, int fill , int padding,
			bool forceArgs)
{
  VDKBRadioButton* button = NULL;
  VDKBObject* vdkbobj = dynamic_cast<VDKBObject*>(wid);
  if(vdkbobj)
    button = dynamic_cast<VDKBRadioButton*>(vdkbobj);
  if(button)
    VDKBEventBox::AddWidget(wid,justify, expand, fill, padding, forceArgs);
  else
    {
      sprintf(buff,"RadioButton Groups can accomodate only RadioButtons");
      ObjectFromVDK()->Owner()->Application()->VDKMessageBox(APPNAME,buff,
					VDK_OK| VDK_ICONINFORMATION);
    }
}
/*
 */
void
VDKBRadioButtonGroup::WriteOnFrm(FILE* fp, VDKBObject* parentobj)
{
  VDKBEventBox::WriteOnFrm(fp,parentobj);
}

char*
VDKBRadioButtonGroup::CreateSource(char* buffer,VDKBParser& parser)
{
  char* source;
  char obj_name[128];
  char obj_mode[16];
  char obj_parent[128];
  char temp[256];
  char bw[16];
  char arg[16];
  // get name, mode and parent
  if ( !parser.GetParam(obj_name,buffer,"this:") ||
       !parser.GetParam(obj_mode,buffer,"mode:") ||
       !parser.GetParam(obj_parent,buffer,"parent:")
       )
    return NULL;
  else
    source = new char[1024];

  sprintf(temp,"\n%s = new VDKRadioButtonGroup(this,%s);",obj_name,obj_mode);
  strcpy(source,temp);
  // get size
  VDKPoint size = parser.Size(buffer);
  if(size.X() > 0 || size.Y() > 0)
    {
      sprintf(temp,"\n%s->SetSize(%d,%d);",obj_name,size.X(),size.Y());
      strcat(source,temp);
    }
  bool adjArg = true;
  // has parent
  if(strcmp(obj_parent,NIHIL_PROP))
    {
      // bad OOP design here :-(
      // but in seek of semplicity..
      // boxes embedded into notebooks act differently
      char* object = parser.GetWidget(obj_parent);
      char obj_class[32];
      if(object)
	{
	  // parent is a notebook
	  if(parser.GetParam(obj_class,object,PARSER_CLASS)
	     && !strcmp(obj_class,"VDKNotebook"))
	    {
	      char label[128];
	      if(!parser.GetParam(label,buffer, PROP_LABEL))
		 *label = '\0';
	      sprintf(temp,"\n%s->AddPage(%s,\"%s\");",
		      obj_parent,
		      obj_name,
		      *label ? label : obj_name);
	      adjArg = false;
	    }
	  // other
	  else if(parser.GetParam(obj_class,object,PARSER_CLASS) &&
	      !strcmp(obj_class,"VDKTable"))
	    {
	      int row,col;
	      if(parser.GetParam(arg,buffer,PROP_TABLEROW) &&
		 strcmp(arg,NIHIL_PROP))
		row = atoi(arg);
	      else
		row = 0;
	      if(parser.GetParam(arg,buffer,PROP_TABLECOL) &&
		 strcmp(arg,NIHIL_PROP))
		col = atoi(arg);
	      else
		col = 0;
	      sprintf(temp,"\n%s->AddToCell(%s,%d,%d);",
		      obj_parent,obj_name,row,col);
	      adjArg = false;
	    }
	  else
	    sprintf(temp,"\n%s->Add(%s",obj_parent,obj_name);
	  delete[] object;
	}
      // other parents
      else
	sprintf(temp,"\n%s->Add(%s",obj_parent,obj_name);
    }
  else
    sprintf(temp,"\nAdd(%s",obj_name);

  strcat(source,temp);

  if(adjArg)
    {
      // prepares arguments for add widget to container
      char justify[16],expand[16],fill[16],padding[16];
      if(parser.GetParam(justify,buffer,PROP_JUSTIFY_INTERNAL) &&
	 parser.GetParam(expand,buffer,PROP_EXPAND_INTERNAL) &&
	 parser.GetParam(fill,buffer,PROP_FILL_INTERNAL) &&
	 parser.GetParam(padding,buffer,PROP_PADDING_INTERNAL))
	{
	  sprintf(temp,",%s,%s,%s,%s);",
		  justify,expand,fill,padding);
	  strcat(source,temp);
	}
      else
	{
	  sprintf(temp,");");
	  strcat(source,temp);
	}
    }

  if(parser.GetParam(bw,buffer,PROP_BORDERWIDTH) &&
     strcmp(bw,NIHIL_PROP))
    {
      sprintf(temp,"\n%s->BorderWidth(%s);",obj_name,bw);
      strcat(source,temp);
    }
  return source;
}
/*
 */
bool
VDKBRadioButtonGroup::CreateWidget(VDKBGuiForm* owner, char* buffer,VDKBParser& parser)
{
  char obj_name[128];
  char obj_mode[16];
  char obj_parent[128];
  VDKBRadioButtonGroup* box;
  int mode;
  // get name, mode and parent
  if ( !parser.GetParam(obj_name,buffer,"this:") ||
       !parser.GetParam(obj_mode,buffer,"mode:") ||
       !parser.GetParam(obj_parent,buffer,"parent:")
       )
    return false;
  // get mode and size
  mode = !strcmp(obj_mode,"h_box") ? h_box : v_box;
  VDKPoint size = parser.Size(buffer);
  // get packing args
  int justification = l_justify;
  int expand=0,fill=0,padding=0;
  int bw; // border width
  char arg[32];
  if(parser.GetParam(arg,buffer,PROP_JUSTIFY_INTERNAL))
    justification = atoi(arg);
  if(parser.GetParam(arg,buffer,PROP_EXPAND_INTERNAL))
    expand = atoi(arg);
  if(parser.GetParam(arg,buffer,PROP_FILL_INTERNAL))
    fill= atoi(arg);
  if(parser.GetParam(arg,buffer,PROP_PADDING_INTERNAL))
    padding= atoi(arg);
  if(parser.GetParam(arg,buffer,PROP_BORDERWIDTH) &&
     strcmp(arg,NIHIL_PROP))
      bw = atoi(arg);
  else
    bw = -1;
  // no parent, widget will be added to owner form innerbox
  if(!strcmp(obj_parent,NIHIL_PROP))
    {
      box = new VDKBRadioButtonGroup(obj_name,owner->InnerBox(),mode);
      // call ancestor to set common properties
      VDKBObject::CreateWidget(box,buffer,parser);
      owner->AddWidget(box,justification,expand,fill,padding);
      if(size.X() > 0 || size.Y() > 0)
	box->ObjectFromVDK()->SetSize(size.X(),size.Y());
      if(bw >= 0)
	{
	  box->BorderWidth(bw);
	  box->SetPropValue(BORDERWIDTH,arg);
	}

    }
  else
    // has a parent, will be added to parent.
    // Parent should be a container
    {
      // get parent container address
      VDKObject* p = owner->ChildWithName(obj_parent);
      VDKBEventContainer* container = p ?
	dynamic_cast<VDKBEventContainer*>(p) : (VDKBEventContainer*) NULL;
      if(container)
	{
	  box = new VDKBRadioButtonGroup(obj_name,container,mode);
	  // bad OOP design here :-(
	  // but in seek of semplicity..
	  // we use justification for row
	  // and expand for col to add boxes
	  char* object = parser.GetWidget(obj_parent);
	  char obj_class[32];
	  if(object)
	    {
	      // parent is a table
	      if(parser.GetParam(obj_class,object,PARSER_CLASS)
		 && !strcmp(obj_class,"VDKTable"))
		{
		  if(parser.GetParam(arg,buffer,PROP_TABLEROW) &&
		     strcmp(arg,NIHIL_PROP))
		    justification = atoi(arg);
		  else
		    justification = 0;
		  if(parser.GetParam(arg,buffer,PROP_TABLECOL) &&
		     strcmp(arg,NIHIL_PROP))
		    expand = atoi(arg);
		  else
		    expand = 0;
		}
	    }
	  // call ancestor to set common properties
	  VDKBObject::CreateWidget(box,buffer,parser);
	  container->AddWidget(box,justification,expand,fill,padding,true);
	  if(size.X() > 0 || size.Y() > 0)
	    box->ObjectFromVDK()->SetSize(size.X(),size.Y());
	  box->outerbox = container;

	  if(bw >= 0)
	    {
	      char local[16];
	      box->BorderWidth(bw);
	      sprintf(local,"%d",bw);
	      box->SetPropValue(BORDERWIDTH,local);
	    }
	}
      else
	return false; // FIX ME: user warning
    }
return true;
}
/*
  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
  3 - no active widget
*/
int
VDKBRadioButtonGroup::MakeWidgetV(VDKBGuiForm* owner, GdkEvent* ev)
{
  // autogenerate first suitable box counter
  // to ensure unicity
  int result = 0;
  VDKBRadioButtonGroup* box = NULL;
  if(owner->Active)
    {
      for(sprintf(buff,"VRadioButtonGroup%d",VDKBEventBox::Counter);
	  owner->ChildWithName(buff)!= (VDKObject*) NULL;
	  VDKBEventBox::Counter++)
	sprintf(buff,"VRadioButtonGroup%d",VDKBEventBox::Counter);
      box = new VDKBRadioButtonGroup(buff,owner,v_box);
      VDKBEventContainer* container =
	dynamic_cast<VDKBEventContainer*>(owner->Active);
      if(container)
	{
	   if(ev && dynamic_cast<VDKBFixed*>(container))
	    {
	      GdkEventButton* event = (GdkEventButton*) ev;
	      sprintf(buff,"%d",int(event->x));
	      box->SetPropValue(JUSTIFY_INTERNAL,buff);
	      sprintf(buff,"%d",int(event->y));
	      box->SetPropValue( EXPAND_INTERNAL,buff);
	      // others than justify and flag unuseful
	      container->AddWidget(box,int(event->x),
				   int(event->y),
				   true,true,true);
	    }
	  else
	    container->AddWidget(box);
	  box->outerbox = container;
	}
      // target isn't a container
      else if(! owner->Active->AddToParent(box,ev))
	result =  2;
    }
  else
    // no active widget
    result =  3;
 // 0 on success
  if(result && box)
    box->Destroy();
 return result;
}

/*
  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
  3 - no active widget
*/
int
VDKBRadioButtonGroup::MakeWidgetH(VDKBGuiForm* owner, GdkEvent* ev)
{
  // autogenerate first suitable box counter
  // to ensure unicity
  int result = 0;
  VDKBRadioButtonGroup* box = NULL;
  if(owner->Active)
    {
      for(sprintf(buff,"HRadioButtonGroup%d",VDKBEventBox::Counter);
	  owner->ChildWithName(buff)!= (VDKObject*) NULL;
	  VDKBEventBox::Counter++)
	sprintf(buff,"HRadioButtonGroup%d",VDKBEventBox::Counter);
      box = new VDKBRadioButtonGroup(buff,owner,h_box);
      VDKBEventContainer* container =
	dynamic_cast<VDKBEventContainer*>(owner->Active);
      if(container)
	{
	   if(ev && dynamic_cast<VDKBFixed*>(container))
	    {
	      GdkEventButton* event = (GdkEventButton*) ev;
	      sprintf(buff,"%d",int(event->x));
	      box->SetPropValue(JUSTIFY_INTERNAL,buff);
	      sprintf(buff,"%d",int(event->y));
	      box->SetPropValue( EXPAND_INTERNAL,buff);
	      // others than justify and flag unuseful
	      container->AddWidget(box,int(event->x),
				   int(event->y),
				   true,true,true);
	    }
	  else
	    container->AddWidget(box);
	  box->outerbox = container;
	}
      // target isn't a container
      else if(! owner->Active->AddToParent(box,ev))
	result = 2;
    }
  else
    // no active widget
    result =  3;
 // 0 on success
  if(result && box)
    box->Destroy();
 return result;
}

VDKObjectContainer*
VDKBRadioButtonGroup::ExtraWidget(VDKBObjectInspector* isp)
{
  return VDKBEventContainer::ExtraWidget(isp);
}