File: vdkb_comboentry.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 (563 lines) | stat: -rw-r--r-- 16,000 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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
/*  
 * ===========================
 * VDK Builder
 * Version 0.1
 * Revision 0.7
 * September 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
 */

/*
--------
OVERVIEW
--------
- This file should be considered as a template for constructing vdkbuilder
plugin components. Users should copy/paste and easily adapt this file
to their own components.
- See also plugins.txt into /plugins directory for further informations.
*/


// write here your component include file
#define COMPO_INCLUDE <vdkb2/vdkb_comboentry.h>
// leave it as is
#define INTERFACE_INCLUDE <vdkb2/vdkb_interface.h>
// write how vdkbuilder will name components pointers,
// pointer names  will be suffixed with a number
// i.e: databox0
#define VDK_WIDGET "combo_entry"
// write here your interface name
// normally: CLASSComponentInterface
#define INTERFACE  VDKComboEntryComponentInterface
// tip displayed into builder tool palette
// change with your own
#define COMPO_TIP "VDKComboEntry"


//////////////////////
#include COMPO_INCLUDE
#include INTERFACE_INCLUDE
#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>
////////////////////////
/*
icon to be displayed on toolbar palette
*/
/*
 change to your own icon, do not change COMPO_XPM,
 change string constants instead.
*/
static const char * COMPO_XPM[] =
{
/* width height num_colors chars_per_pixel */
"    22    20        5            1",
/* colors */
". c #000000",
"# c #000080",
"a c #000000",
"b c #none",
"c c #none",
/* pixels */
"bbbbbbbbbbbbbbbbbbbbbb",
"baaaaaaaaaaaaaa......b",
"baccccccccccccc.cccb.b",
"bac###########c.c..b.b",
"baccccccccccccc.caab.b",
"baccccccccccccc.bbbb.b",
"ba...................b",
"bbb.cccccccccccccccc.b",
"bbb.cc############cc.b",
"bbb.cccccccccccccccc.b",
"bbb.cc###########ccc.b",
"bbb.################.b",
"bbb.##cccccccccccc##.b",
"bbb.################.b",
"bbb.cc###########ccc.b",
"bbb.cccccccccccccccc.b",
"bbb.cc############cc.b",
"bbb.cccccccccccccccc.b",
"bbb..................b",
"bbbbbbbbbbbbbbbbbbbbbb"
};
////////////////////////
/*
Interface class for builder widget
leave it as is
 */
class INTERFACE : public VDKBAbstractComponentInterface
   {
public:
     INTERFACE() {}
     virtual ~INTERFACE()
    {
    }
     // write vdk code to create component
     char* CreateSource(char* buffer,VDKBParser& parser)
    {
      return CLASS::CreateSource(buffer,parser);
    }
     // parse .frm file to make the component
     bool CreateWidget(VDKBGuiForm* owner,
		       char* buffer,VDKBParser& parser)
    {
      return CLASS::CreateWidget(owner,buffer,parser);
    }
     // make and add a new component to edit form
     int MakeWidget(VDKBGuiForm* owner, GdkEvent* ev = NULL)
   {
     return CLASS::MakeWidget(owner,ev);
   }
     // return component icon to be inserted
     // into vdkbuilder tool palette
     const char** Icon() { return COMPO_XPM; }
     // icon tip
     const char* Tip() { return COMPO_TIP; }
     // return component vdk class name
     const char* VDKName()
    {
      return (const char*) VDK_CLASS;
    }
};
// get a new interface object
// this is called by plugin object from builder
extern "C"
VDKBAbstractComponentInterface* GetExportClass()
{
  return new INTERFACE;
}

/*
 component properties, change here with your own or leave array empty
 like this:
 static char* vdk_props[] = { 0 };
 if your component does not have any property to be set with the WI
*/
#define PROPERTY1     "Editable"
#define PROPERTY2     "Sorted"
  /*
  #define PROPERTY3     "Scrollbars"
*/

static char* vdk_props[] =
{
  PROPERTY1,
  PROPERTY2,
  /*
    PROPERTY3,
  */
  0
};

/*
 component provided signals, change here signal provided for your component
 or  leave array empty like this:
 static char* vdk_signals[] = { 0 };
 if your component does not have any signal provided
*/
#define SIGNAL1   "activate_signal"
#define SIGNAL2   "changed_signal"
#define SIGNAL3   "focus_in_signal"
#define SIGNAL4   "focus_out_signal"
  /*
  #define SIGNAL5   "databox_selection_stopped_signal"
  #define SIGNAL6   "databox_selection_canceled_signal"
*/


static char* vdk_signals[] =
{
  SIGNAL1,
  SIGNAL2,
  SIGNAL3,
  SIGNAL4,
  /*
    SIGNAL5,
    SIGNAL6,
  */
  0
};

/*
 component signal nicknames, they will be used to make signal response
 signatures like this:
 bool On<componentname><signal nickname>(VdkObject* sender);
 e.g.
 Ondatabox1Zoomed(VDKObject* sender);
 Change here nicknames for your component or leave array empty like this:
 static char* vdk_nicknames[] = { 0 };
 if your component does not have any signal provided
*/
#define NICK1  "Activated"
#define NICK2  "Changed"
#define NICK3  "FocusIn"
#define NICK4  "FocusOut"
/*
  #define NICK5  "SelectionStopped"
  #define NICK6  "SelectionCanceled"
*/

static char* vdk_nicknames[] =
{
  NICK1,
  NICK2,
  NICK3,
  NICK4,
  /*
    NICK5,
    NICK6,
  */
  0
};

/*
local buffer
*/
static char buff[256];
/*
  used to autogenerate default
  component names
*/
int CLASS::Counter = 0;


// dynamic tables
// leave it as is
DEFINE_SIGNAL_LIST(CLASS,VDK_ANCESTOR);
DEFINE_EVENT_LIST(CLASS,VDK_ANCESTOR);
///////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
/*
  - constructor
 */
CLASS::CLASS(char* name, VDKForm* owner):
  VDK_ANCESTOR(owner),VDKBObject(name)
{
  int t = 0;
  // newly constructed component counter is incremented
  // each time
  Counter++;
  // assign this to VDKBObject <object> member.
  object = this;
  // add component specific properties to VDKBObject properties list
  for(t = 0; vdk_props[t]; t++)
    proplist.add(VDKBProperty(vdk_props[t]));
  // add component specifi signal to VDKBObject signal list
  for(t = 0; vdk_signals[t]; t++)
    siglist.add(VDKBSignal(vdk_signals[t], this, vdk_nicknames[t]));
  /*
    here you may want set some default value for some property:
    SetPropValue(<"property name">,<"property value">);
    e.g:
    //set a reasonable size fro the widget in the case
    // it will be dropped into a fixed container
    sprintf(buff,"%d,%d",150,110);
    SetPropValue("Usize",buff);
  */
  //sprintf(buff,"%d",GTK_CALENDAR_SHOW_HEADING);
  SetPropValue("Editable","true");
  //set a reasonable size fro the widget in the case
  // it will be dropped into a fixed container
  sprintf(buff,"%d,%d",150,20);
  SetPropValue("Usize",buff);
  // connects component common events.
  CONNECT_COMMON_EVENTS;
  // makes a pop menu common to all widgets (in vdkb_widpopmenu.cc/h)
  // this pop menu will be popped at righ button press event.
  popmenu = new VDKBWidgetPopMenu(this);
  // a reasonable initial size (mainly for adding the component
  // to a fixed container)
  // change to your own size
  SetSize(150,20);
}
/*
overridden ButtonPressed
used in substitution of
VDKBObject::ButtonPress
*/
bool
VDKBComboEntry::OverriddenButtonPressed(VDKObject* sender, GdkEvent* ev)
{
  VDKBEventContainer* container;
  gtk_signal_emit_stop_by_name(GTK_OBJECT(sender->WrappedWidget()),
  		       "button_press_event");
  container = dynamic_cast<VDKBEventContainer*>(sender->Parent());
  if(container)
    // we pass <this> instead <sender>
    // otherwise entry widget selection
    // is lost (don'y ask me why !)
    container->OnButtonPressed(this,ev);
  return true;
}
///////////////////////////////////////////////
//
//    WRITE WIDGET DESCRIPTION TO .FRM FILE
//
///////////////////////////////////////////////
/*
  Writes a .frm format representation of the component
  This virtual function is called by VDKBForm::WriteBoxesOnFrm()
  a recursive algorithm that scans VDKBForm widget tree.
*/
void
CLASS::WriteOnFrm(FILE* fp, VDKBObject* parentobj)
{
  int t;
  // first call ancestor to write common properties values
  VDKBObject::WriteOnFrm(fp,parentobj);
  // now we write component specific properties values.
  for( t = 0; vdk_props[t]; t++)
      fprintf(fp,"\n\t%s:%s;", vdk_props[t],(char*) GetProp(vdk_props[t]));
}
////////////////////////////////////////
//
//               PREPARE GUI WIDGETS
//
////////////////////////////////////////
/*
  This method is called by global MakeWidget() in vdkb_design.cc
  triggered when user wants drop a widget into a form.
 */
int
CLASS::MakeWidget(VDKBGuiForm* owner, GdkEvent* ev)
{
  // autogenerate first suitable counter
  // to ensure unicity
  CLASS* component;
  // component name generation failed
  if(!owner->GenerateWidgetName(buff,VDK_WIDGET,&CLASS::Counter))
    // unauthorized operation
    return 2;
  else
    {
      // actually makes component
      // <buff> contains component pointer name (autogenerated)
      // may be your constructor is different
      // patch if necessary
      ////////////////////////////////////////
      component = new CLASS(buff,owner);
      ////////////////////////////////////////
    }
  /*
    in this part we write some widget specific initailization code,
    patch or comment out if not applicable to your widget
  */
  
  ////////////////////////////////////////////
  // add component to form
  return owner->AddToSelf(component,ev);
}
/*
  This is called by a global CreateSource() in vdkb_parser.cc.
*/
char*
CLASS::CreateSource(char* buffer,VDKBParser& parser)
{
  char* source;
  char obj_name[128];
  char obj_parent[128];
  char arg[64];
  char tmp[256];
  // gets component name and parent name
  if(! parser.GetNameAndParent(buffer, obj_name, obj_parent))
     return NULL;
  source = new char[4096];
  // writes code to make the component
  // may be your constructor is different
  // patch if necessary
  ///////////////////////////////////////////////////////
  sprintf(tmp,"\n%s = new %s(this);",obj_name,VDK_CLASS);
  ///////////////////////////////////////////////////////
  strcpy(source,tmp);
  // call ancestor to set common properties
  char* props = VDKBObject::CreateSource(buffer,parser,obj_name);
  if(props)
    {
      strcat(source,props);
      delete[] props;
    }
  /*
    in this part we write some component specific initialization code,
    reading properties values from .frm file and setting them
    to into widget.
  */
  ///////////////////////////////////////////////////////////////
  char local[64];
  int t = 0;
  for( t = 0; vdk_props[t]; t++)
    {
      /*
	since in .frm file property is suffixed with colon
	we have to precisely write it in order to be correctly
	parsed by parser.GetParam()
      */
      sprintf(local,"%s:",vdk_props[t]);
      if(parser.GetParam(arg,buffer,local) && strcmp(arg,NIHIL_PROP) )
	{
	  sprintf(tmp,"\n%s->%s = %s;", obj_name,  vdk_props[t], arg);
	  strcat(source,tmp);
	}
    }
  //////////////////////////////////////////////////////////////
  // get code that adds component 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()
*/
bool
CLASS::CreateWidget(VDKBGuiForm* owner,
			      char* buffer,VDKBParser& parser)
{
  char obj_name[128];
  char obj_parent[128];
  char arg[64],local[64];
  CLASS* component;
  // get component name and parent
  if(! parser.GetNameAndParent(buffer, obj_name, obj_parent))
    return false;

  VDKObject* p = owner->ChildWithName(obj_parent);
  VDKBEventContainer* container = p ?
    dynamic_cast<VDKBEventContainer*>(p) : (VDKBEventContainer*) NULL;
  if(container)
    {
      // actually makes component
      // <obj_name> contains component pointer name (autogenerated)
      // may be your constructor is different
      // patch if necessary
      ///////////////////////////////////////////
      component = new CLASS(obj_name,owner);
      ///////////////////////////////////////////
      /*
	in this part we write some component specific initialization code,
	and we can't use vdk_props[] loop.
	Patch or comment out if not applicable to your widget
      */
      sprintf(local,"%s:",PROPERTY1);
      if(parser.GetParam(arg,buffer,local) && strcmp(arg,NIHIL_PROP))
	component->SetPropValue(PROPERTY1,arg);
      sprintf(local,"%s:",PROPERTY2);
      if(parser.GetParam(arg,buffer,local) && strcmp(arg,NIHIL_PROP))
	component->SetPropValue(PROPERTY2,arg);
      ////////////////////////////////////////////
      // pack widget to container
      return owner->PackToSelf(component, container, buffer, parser);
    }
  else
    return false;
}
////////////////////////////
//   WIDGET INSPECTOR STUFF
////////////////////////////
/*
  This part of code is dedicated to widget inspector
  management. All widget described here have the
  purpose to let the end-user set component properties
  that will be showed at the bottom of the WI when end-user
  selects your component.
  So this part of code is only a footstep, you have to
  write your own, anyway i hope will be useful.
  I suggest to initially write components without this part
  and add it after you have checked component works
  properly withou properties setting.
*/

static char *cbCaptions[CHECK_BUTTONS_NUMBER] = { "Editable","Sorted" };
/*
  This is called by Widget Inspector when end-user selects
  your component on edit form.
*/
VDKObjectContainer*
CLASS::ExtraWidget(VDKBObjectInspector* isp)
{
  // assign inspector for later use
  inspector = isp;
  /*
    generally we make a frame and fill it with widgets.
    Frame will be returned to widget inspector and
    showed at his bottom
  */
  VDKFrame* bframe = new VDKFrame(inspector,NULL,v_box,shadow_etched_in);
  /*
    now we make a table that will accomodate all widgets
    since we have 2 check buttons and a set button
  */
  VDKTable* table = new VDKTable(inspector,2,1,true);
  table->SetSize(219,-1);  
  setButton = new VDKCustomButton(inspector,"Set");
  table->AddToCell(setButton,2,0);
  // set component as parent
  setButton->Parent(this);
  // now we connect "clicked" signal with signal response
  SignalConnect(setButton,"clicked",&CLASS::OnSetProperties);
  // makes all check buttons
  VDKString True = CHECK_TRUE;
  int t = 0;
  for(;t < CHECK_BUTTONS_NUMBER; t++)
    {
      checkButtons[t] = new VDKCheckButton( inspector, cbCaptions[t]);
      checkButtons[t]->Checked = GetProp(vdk_props[t]) == True;
    }
  // add cb to table
  table->AddToCell(checkButtons[0],0,0);
  table->AddToCell(checkButtons[1],0,1);
  /*
    we have finished, now add table to frame and return it
  */
  bframe->Add(table,l_justify,false,false,false);
  return bframe;
}
/*
signal response to clicked signal on setButton
*/
bool
CLASS::OnSetProperties(VDKObject* sender)
{
  int t = 0;
  for(; t < CHECK_BUTTONS_NUMBER; t++)
    {
      bool state = checkButtons[t]->Checked;
      SetPropValue(vdk_props[t],state ? CHECK_TRUE : CHECK_FALSE);
    }
  inspector->FormNeedToBeChanged();
  return true;
}