1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 0.4
5  * October 1998
6  * Revision on vdk 0.5.3
7  * Feb 1999 by mm
8  * ===========================
9  *
10  * Copyright (C) 1998, Mario Motta
11  * Developed by Mario Motta <mmotta@guest.net>
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Library General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Library General Public License for more details.
22  *
23  * You should have received a copy of the GNU Library General Public
24  * License along with this library; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  * 02111-1307, USA.
27  *
28  */
29 #include "vdk/vdkobj.h"
30 #include "vdk/forms.h"
31 #include "vdk/evhandle.h"
32 #include "vdk/evobjhandle.h"
33 #include "vdk/colors.h"
34 #include "vdk/tooltips.h"
35 #include "vdk/vdkfont.h"
36 #include <config.h>
37 #include <vdk/widcontain.h>
38 #include <vdk/vdkcustom.h>
39 #ifdef VDKDEBUG
40 int objectC = 0;
41 int objectD = 0;
42 extern int objRemoved;
43 #endif
44 
45 #define color_nihil VDKRgb(-1,-1,-1)
46 
47 // VDKObjectSignalUnit class
VDKObjectSignalUnit(void * owner,void * obj,char * signal)48 VDKObjectSignalUnit::VDKObjectSignalUnit(void* owner,void *obj, char* signal) :
49         owner(owner),obj(obj),signal(signal)
50 {
51 }
~VDKObjectSignalUnit()52 VDKObjectSignalUnit::~VDKObjectSignalUnit()
53 {
54 }
55 
56 // VDKObjectEventUnit class
VDKObjectEventUnit(void * owner,void * obj,char * signal)57 VDKObjectEventUnit::VDKObjectEventUnit(void* owner,void *obj, char* signal) :
58         owner(owner),obj(obj),signal(signal)
59 {
60 }
61 
~VDKObjectEventUnit()62 VDKObjectEventUnit::~VDKObjectEventUnit()
63 {
64 }
65 
66 // SizeObjectProp class
SizeObjectProp()67 SizeObjectProp::SizeObjectProp()
68 {
69 }
70 
SizeObjectProp(char * name,VDKObject * object,void (VDKObject::* write)(VDKPoint),VDKPoint (VDKObject::* read)(void))71 SizeObjectProp::SizeObjectProp(char* name, VDKObject* object,
72                    void (VDKObject::*write)(VDKPoint),
73                    VDKPoint (VDKObject::*read)(void)) :
74 		SizeOProp(name,object,VDKPoint(0,0),write,read)
75 {
76 }
77 
~SizeObjectProp()78 SizeObjectProp::~SizeObjectProp()
79 {
80 }
81 
82 // VDKObject class
83 void
SetNormalBackground(VDKRgb c)84 VDKObject::SetNormalBackground(VDKRgb c)
85 {
86 	SetBackground(c,GTK_STATE_NORMAL);
87 }
88 void
SetPrelightBackground(VDKRgb c)89 VDKObject::SetPrelightBackground(VDKRgb c)
90 {
91 	SetBackground(c,GTK_STATE_PRELIGHT);
92 }
93 void
SetInsensitiveBackground(VDKRgb c)94 VDKObject::SetInsensitiveBackground(VDKRgb c)
95 {
96 	SetBackground(c,GTK_STATE_INSENSITIVE);
97 }
98 void
SetActiveBackground(VDKRgb c)99 VDKObject::SetActiveBackground(VDKRgb c)
100 {
101 	SetBackground(c,GTK_STATE_ACTIVE);
102 }
103 void
SetSelectedBackground(VDKRgb c)104 VDKObject::SetSelectedBackground(VDKRgb c)
105 {
106 	SetBackground(c,GTK_STATE_SELECTED);
107 }
108 
109 int
isA()110 VDKObject::isA()
111 {
112 	return object_class;
113 }
114 
115 VDKForm*
Owner()116 VDKObject::Owner()
117 {
118 	return owner;
119 }
120 
121 VDKCursorType
GetCursor()122 VDKObject::GetCursor()
123 {
124 	return Cursor;
125 }
126 
127 void
SetNormalForeground(VDKRgb color)128 VDKObject::SetNormalForeground(VDKRgb color)
129 {
130 	SetForeground(color);
131 }
132 
133 void
SetSize(int w,int h)134 VDKObject::SetSize(int w, int h)
135 {
136 	if(GTK_IS_WIDGET(widget))
137 	gtk_widget_set_usize(GTK_WIDGET(widget),w,h);
138 }
139 
140 void
SetUsize(VDKPoint s)141 VDKObject::SetUsize(VDKPoint s)
142 {
143 	SetSize(s.X(),s.Y());
144 }
145 
146 bool
GetEnabled()147 VDKObject::GetEnabled()
148 {
149 	return Enabled;
150 }
151 
152 bool
GetVisible()153 VDKObject::GetVisible()
154 {
155 	return GTK_WIDGET_VISIBLE(widget);
156 }
157 
158 VDKFont*
GetFont()159 VDKObject::GetFont()
160 {
161 	return Font;
162 }
163 
164 ItemList&
Items()165 VDKObject::Items()
166 {
167 	return items;
168 }
169 
170 ItemList&
Garbages()171 VDKObject::Garbages()
172 {
173 	return garbages;
174 }
175 
176 RawList&
Raws()177 VDKObject::Raws()
178 {
179 	return raws;
180 }
181 
182 void
SignalEmitParent(int signal)183 VDKObject::SignalEmitParent(int signal)
184 {
185 	SignalEmit(signal,Parent_level);
186 }
187 
188 GtkWidget*
Widget()189 VDKObject::Widget()
190 {
191   return widget ? GTK_WIDGET(widget): (GtkWidget*) NULL;
192 }
193 /*
194  */
195 GtkWidget*
ConnectingWidget()196 VDKObject::ConnectingWidget()
197 {
198   return sigwid ? GTK_WIDGET(sigwid) : widget ? GTK_WIDGET(widget): (GtkWidget*) NULL;
199 }
200 
201 GtkWidget*
WrappedWidget()202 VDKObject::WrappedWidget()
203 {
204   return ConnectingWidget();
205 }
206 
207 /*
208  */
VDKObject(VDKForm * owner)209 VDKObject::VDKObject(VDKForm* owner):
210   // sets properties
211     NormalBackground("NormalBackGround",this,
212 		     color_nihil,
213 		     &VDKObject::SetNormalBackground),
214     PrelightBackground("PrelightBackGround",this,
215 		       color_nihil,
216 		       &VDKObject::SetPrelightBackground),
217     InsensitiveBackground("InsensitiveBackGround",
218 			  this,
219 			  color_nihil,
220 			  &VDKObject::SetInsensitiveBackground),
221 
222     ActiveBackground("ActiveBackGround",
223 		     this,
224 		     color_nihil,
225 		     &VDKObject::SetActiveBackground),
226 
227     SelectedBackground("SelectedBackGround",
228 		       this,
229 		     color_nihil,
230 		     &VDKObject::SetSelectedBackground),
231     Foreground("Foreground",this,
232 	       color_nihil,
233 	       &VDKObject::SetNormalForeground),
234 
235     Font("Font",this,NULL,&VDKObject::SetFont),
236     Usize("Usize",this),
237     Enabled("Enabled",this,true,&VDKObject::Enable),
238     Cursor("Cursor",this,curDefault,&VDKObject::SetCursor),
239     Visible("Visible",this,true,&VDKObject::SetVisible,&VDKObject::GetVisible),
240     HasFocus("HasFocus",this,false,&VDKObject::isFocused),
241     Tag(0),
242     //
243     tip(NULL),
244     owner(owner),
245     widget(NULL),
246     sigwid(NULL),
247     parent(NULL)
248 #ifdef USE_SIGCPLUSPLUS
249      , OnRawEvent(this)
250      , OnButtonEvent(this)
251      , OnKeyEvent(this)
252      , OnKeyFocusEvent(this)
253      , OnPointerFocusEvent(this)
254      , OnPointerEvent(this)
255      , OnMapEvent(this)
256      , OnGeometryEvent(this)
257      , OnPaintEvent(this)
258 #endif
259     {
260 #ifdef VDKDEBUG
261 	objectC++;
262 #endif /* USE_SIGCPLUSPLUS */
263     }
264 
265 /*
266  */
VDKObject(VDKForm * owner,GtkWidget * widget)267 VDKObject::VDKObject(VDKForm* owner,GtkWidget* widget):
268   // sets properties
269     NormalBackground("NormalBackGround",this,
270 		     color_nihil,
271 		     &VDKObject::SetNormalBackground),
272     PrelightBackground("PrelightBackGround",this,
273 		       color_nihil,
274 		       &VDKObject::SetPrelightBackground),
275     InsensitiveBackground("InsensitiveBackGround",
276 			  this,
277 			  color_nihil,
278 			  &VDKObject::SetInsensitiveBackground),
279     ActiveBackground("ActiveBackGround",
280 		     this,
281 		     color_nihil,
282 		     &VDKObject::SetActiveBackground),
283     SelectedBackground("SelectedBackGround",
284 		       this,
285 		       color_nihil,
286 		       &VDKObject::SetSelectedBackground),
287     Foreground("Foreground",this,
288 	       color_nihil,
289 	       &VDKObject::SetNormalForeground),
290     Font("Font",this,NULL,&VDKObject::SetFont),
291     Usize("Usize",this),
292     Enabled("Enabled",this,true,&VDKObject::Enable),
293     Cursor("Cursor",this,curDefault,&VDKObject::SetCursor),
294     Visible("Visible",this,true,&VDKObject::SetVisible,&VDKObject::GetVisible),
295     HasFocus("HasFocus",this,false,&VDKObject::isFocused),
296     Tag(0),
297     //
298     tip(NULL),
299     owner(owner),
300     widget(widget),
301     sigwid(NULL),
302     parent(NULL)
303 #ifdef USE_SIGCPLUSPLUS
304      , OnRawEvent(this)
305      , OnButtonEvent(this)
306      , OnKeyEvent(this)
307      , OnKeyFocusEvent(this)
308      , OnPointerFocusEvent(this)
309      , OnPointerEvent(this)
310      , OnMapEvent(this)
311      , OnGeometryEvent(this)
312      , OnPaintEvent(this)
313 #endif /* USE_SIGCPLUSPLUS */
314 {
315 #ifdef VDKDEBUG
316     objectC++;
317 #endif
318 }
319 
320 /*
321  */
SetCursor(VDKCursorType curType)322 void VDKObject::SetCursor(VDKCursorType curType)
323 {
324   GdkCursor *cursor = NULL;
325   if((! widget) || (! widget->window)) return;
326   // restore default cursor
327   if(curType == curDefault) gdk_window_set_cursor(widget->window, NULL);
328   else {
329       cursor = gdk_cursor_new((GdkCursorType)curType);
330       gdk_window_set_cursor (widget->window, cursor);
331       // plm - 07/11/2005
332       //gdk_cursor_destroy (cursor);
333       gdk_cursor_unref(cursor);
334   }
335   /* X operations are not synchronous.
336      Request is queued by the client
337      but not delivered to the server.
338      So with this call the change occurs
339      immediately
340   */
341   gdk_flush();
342 }
343 /*
344   Overridden in some subclasses
345  */
ConnectDefaultEvents()346 void VDKObject::ConnectDefaultEvents()
347 {
348 
349 }
350 /*
351 
352  */
ConnectDefaultSignals()353 void VDKObject::ConnectDefaultSignals()
354 {
355   if(! widget )
356     return;
357   else if(!(dynamic_cast<VDKObjectContainer*>(this)))
358      {
359        s_realize.obj = this;
360        s_realize.signal = realize_signal;
361        GtkWidget* gtkwidget = ConnectingWidget();
362        gtk_signal_connect(GTK_OBJECT(gtkwidget),"realize",
363 			  GTK_SIGNAL_FUNC(VDKObject::VDKSignalPipe),
364 			  (gpointer) &s_realize);
365      }
366   /*
367   gtk_widget_set_events(widget,GDK_ALL_EVENTS_MASK);
368   gtk_widget_set_events(WrappedWidget(),GDK_ALL_EVENTS_MASK);
369   */
370   //  printf("\nvoid VDKObject::ConnectDefaultSignals()");
371   // fflush(stdout);
372 
373 }
374 /*
375  */
~VDKObject()376 VDKObject::~VDKObject()
377 {
378   /*
379     delete items, garbage and raws
380   */
381   ItemListIterator li(items);
382   for(;li;li++)
383     delete li.current();
384 
385   ItemListIterator lg(garbages);
386   for(;lg;lg++)
387     delete lg.current();
388 
389   RawListIterator lr(raws);
390   for(;lr;lr++)
391     delete lr.current();
392 
393   // deletes signal unit list
394   SignalUnitListIterator lu(suList);
395   for(;lu;lu++)
396     delete lu.current();
397 
398   // deletes event unit list
399   EventUnitListIterator le(euList);
400   for(;le;le++)
401     delete le.current();
402 #ifdef VDKDEBUG
403     objectD++;
404 #endif
405 
406 }
407 
408 /*
409  */
410 void
SetVisible(bool visible)411 VDKObject::SetVisible(bool visible)
412 {
413   /*
414      could be wrong iterate on subwidget tree
415      since gtk+ makes the job already
416      (who knows ?)
417      mm. 5.51999
418      ItemListIterator li(items);
419      for(;li;li++)
420      li.current()->SetVisible(visible);
421   */
422   ShowWidget(visible);
423 }
424 
425 VDKObject*
Parent(VDKObject * p)426 VDKObject::Parent(VDKObject* p)
427 {
428 	if (p) parent = p;
429 	return parent;
430 }
431 /*
432   ==================================
433   SIGNAL HANDLING FOR STATIC TABLES
434   AND DYNAMIC SIGNAL LISTS
435   ==================================
436   "the signal is considered treated if and only if a user response
437   returned true".
438   Signal flow:
439   1. to object level and up to his hierarchy if not treated.
440   2. to parent level and up to parent hierarchy if not treated.
441   if parent has a parent step 2 will be repeated until found
442   a parent without parent.
443   3. if yet not treated signal is lost.
444 */
445 /*
446 =======================
447 handles signal calling
448 static tables routines
449 =======================
450 */
451 void
VDKSignalPipe(GtkWidget * w,void * s)452 VDKObject::VDKSignalPipe(GtkWidget* w, void* s)
453 {
454   g_return_if_fail(s != NULL);
455   VDKObjectSignal* signal =
456     reinterpret_cast<VDKObjectSignal*>(s);
457   VDKObject* obj = reinterpret_cast<VDKObject*>(signal->obj);
458   // visits class level
459   if(obj->VDKObjectSignalResponse(w,signal->signal,obj,false))
460     return;
461   // visit parent level
462   VDKObject* parent;
463   for(parent = obj->Parent(); parent; parent = parent->Parent())
464     if(parent->VDKSignalResponse(w,signal->signal,obj,obj,false))
465       break;
466 }
467 
468 int
VDKObjectSignalResponse(GtkWidget *,int,void *,bool)469 VDKObject::VDKObjectSignalResponse(GtkWidget* , int , void*, bool)
470 {
471 	return FALSE;
472 }
473 
474 int
VDKObjectEventResponse(GtkWidget *,GdkEvent *,void *,bool)475 VDKObject::VDKObjectEventResponse(GtkWidget* , GdkEvent*, void*, bool)
476 {
477 	return FALSE;
478 }
479 
480 int
ObjectSignalDetach(int,int)481 VDKObject::ObjectSignalDetach(int , int )
482 {
483 	return -1;
484 }
485 
486 bool
ObjectSignalAttach(int)487 VDKObject::ObjectSignalAttach(int )
488 {
489 	return false;
490 }
491 
492 int
ObjectEventDetach(VDKEvent)493 VDKObject::ObjectEventDetach(VDKEvent )
494 {
495 	return -1;
496 }
497 
498 bool
ObjectEventAttach(int)499 VDKObject::ObjectEventAttach(int )
500 {
501 	return false;
502 }
503 
504 int
VDKObjectSignalResponseTableSize()505 VDKObject::VDKObjectSignalResponseTableSize()
506 {
507 	return 0;
508 }
509 
510 int
VDKObjectEventResponseTableSize()511 VDKObject::VDKObjectEventResponseTableSize()
512 {
513 	return 0;
514 }
515 
516 int
VDKSignalResponse(GtkWidget *,int,void *,void *,bool)517 VDKObject::VDKSignalResponse(GtkWidget* , int , void*, void *, bool)
518 {
519 	return 0;
520 }
521 
522 int
VDKEventResponse(GtkWidget *,GdkEvent *,void *,void *,bool)523 VDKObject::VDKEventResponse(GtkWidget* , GdkEvent* , void*, void*, bool )
524 {
525 	return 0;
526 }
527 
528 int
SignalDetach(VDKObject *,int)529 VDKObject::SignalDetach(VDKObject* , int )
530 {
531 	return -1;
532 }
533 
534 bool
SignalAttach(int)535 VDKObject::SignalAttach(int )
536 {
537 	return false;
538 }
539 
540 int
EventDetach(VDKObject *,VDKEvent)541 VDKObject::EventDetach(VDKObject* ,VDKEvent )
542 {
543 	return -1;
544 }
545 
546 bool
EventAttach(int)547 VDKObject::EventAttach(int )
548 {
549 	return false;
550 }
551 
552 int
VDKSignalResponseTableSize()553 VDKObject::VDKSignalResponseTableSize()
554 {
555 	return 0;
556 }
557 
558 int
VDKEventResponseTableSize()559 VDKObject::VDKEventResponseTableSize()
560 {
561 	return 0;
562 }
563 
564 /*
565 =======================
566 handles signal calling
567 dynamic list  routines
568 =======================
569 */
570 void
VDKSignalUnitPipe(GtkWidget * w,void * s)571 VDKObject::VDKSignalUnitPipe(GtkWidget* w, void* s)
572 {
573   g_return_if_fail(s != NULL);
574   VDKObjectSignalUnit* signal =
575     reinterpret_cast<VDKObjectSignalUnit*>(s);
576   VDKObject* obj = reinterpret_cast<VDKObject*>(signal->obj);
577   // visits class level if signal->owner == signal->obj
578   // it depends if user call SignalEmit(obj,signal,func)
579   // or SignalEmitParent(obj,signal,func)
580   if(signal->owner == signal->obj) //SignalEmit()
581     {
582       if(obj->VDKSignalUnitResponse(w,(char*) signal->signal,obj))
583 	return;
584       VDKForm* f;
585       /* if obj is a form, see if has an owner,
586 	 in this case is a child form so try to disseminate
587 	 also to his parent form
588       */
589       if((f = dynamic_cast<VDKForm*>(obj)) )
590 	{
591 	  // main application does not have an owner
592 	  VDKForm* owner = f->Owner();
593 	  if(owner)
594 	    {
595 	      bool result =
596 		owner->VDKSignalUnitResponse(w,(char*) signal->signal,obj);
597 	      if(result)
598 		return;
599 	    }
600 	}
601     }
602     // else visit parent level  user called SignalEmitParent()
603   VDKObject* parent;
604   for(parent = obj->Parent(); parent; parent = parent->Parent())
605     {
606       if(parent->VDKSignalUnitResponse(w,(char*) signal->signal,obj))
607 	break;
608       VDKForm* f;
609       /* if parent is a form, see if has an owner,
610 	 in this case is a child form so try to disseminate
611 	 also to his parent form
612       */
613       if((f = dynamic_cast<VDKForm*>(parent)) )
614 	{
615 	  // main application does not have an owner
616 	  VDKForm* owner = f->Owner();
617 	  if(owner)
618 	    {
619 	      bool result =
620 		owner->VDKSignalUnitResponse(w,(char*) signal->signal,obj);
621 	      if(result)
622 		return;
623 	    }
624 	}
625     }
626 }
627 /*
628 =======================
629 handles events calling
630 static tables routines
631 =======================
632  */
633 int
VDKEventPipe(GtkWidget * w,GdkEvent * event,void * o)634 VDKObject::VDKEventPipe(GtkWidget* w, GdkEvent* event, void* o)
635 {
636   g_return_val_if_fail(o!= NULL, FALSE);
637   VDKObject* obj = reinterpret_cast<VDKObject*>(o);
638   if(obj->VDKObjectEventResponse(w,event,o,false))
639     return TRUE;
640   VDKObject* parent;
641   for(parent = obj->Parent(); parent; parent = parent->Parent())
642     if(parent->VDKEventResponse(w,event,o,o, false))
643       return TRUE;
644   return FALSE; //TRUE;
645 }
646 /*
647 =======================
648 handles events calling
649 dynamic list  routines
650 =======================
651 */
652 int
VDKEventUnitPipe(GtkWidget * w,GdkEvent * ev,void * s)653 VDKObject::VDKEventUnitPipe(GtkWidget* w, GdkEvent* ev, void* s)
654 {
655   g_return_val_if_fail(s != NULL, TRUE);
656   VDKObjectEventUnit* event =
657     reinterpret_cast<VDKObjectEventUnit*>(s);
658   VDKObject* obj = reinterpret_cast<VDKObject*>(event->obj);
659   // visits class level if event->owner == event->obj
660   if(event->owner == event->obj)
661     {
662       if(obj->VDKEventUnitResponse(w,(char*) event->signal, ev, obj))
663 	return TRUE;
664       VDKForm* f;
665       /* if obj is a form, see if has an owner,
666 	 in this case is a child form so try to disseminate
667 	 also to his parent form
668       */
669       if((f = dynamic_cast<VDKForm*>(obj)) )
670 	{
671 	  // main application form does not have an owner
672 	  VDKForm* owner = f->Owner();
673 	  if(owner)
674 	    {
675 	      bool result =
676 		owner->VDKEventUnitResponse(w,(char*) event->signal,ev,obj);
677 	      if(result)
678 		return TRUE;
679 	    }
680 	}
681     }
682     // visit parent level
683   VDKObject* parent;
684   for(parent = obj->Parent(); parent; parent = parent->Parent())
685     {
686       if(parent->VDKEventUnitResponse(w,(char*) event->signal,ev, obj))
687 	return TRUE;
688       VDKForm* f;
689       /* if parent is a form, see if has an owner,
690 	 in this case is a child form so try to disseminate
691 	 also to his parent form
692       */
693       if((f = dynamic_cast<VDKForm*>(parent)) )
694 	{
695 	  // main application form does not have an owner
696 	  VDKForm* owner = f->Owner();
697 	  if(owner)
698 	    {
699 	      bool result = owner->VDKEventUnitResponse(w,(char*) event->signal,ev,obj);
700 	      if(result)
701 		return TRUE;
702 	    }
703 	}
704     }
705   return FALSE;
706 }
707 
708 int
SignalConnect(VDKObject * obj,char * signal,bool (VDKObject::* method)(VDKObject *),bool gtk,bool after)709 VDKObject::SignalConnect(VDKObject* obj,
710       char* signal,
711       bool (VDKObject::*method)(VDKObject*),
712       bool gtk,
713       bool after)
714 {
715 	return -1;
716 }
717 
718 int
SignalConnect(char * signal,bool (VDKObject::* method)(VDKObject *),bool gtk,bool after)719 VDKObject::SignalConnect(char* signal ,
720       bool (VDKObject::*method)(VDKObject*),
721       bool gtk,
722       bool after)
723 {
724 	return -1;
725 }
726 
727 int
VDKSignalUnitResponse(GtkWidget *,char *,void *)728 VDKObject::VDKSignalUnitResponse(GtkWidget* , char* , void*)
729 {
730 	return 0;
731 }
732 
733 bool
SignalDisconnect(int connection)734 VDKObject::SignalDisconnect(int connection)
735 {
736 	return false;
737 }
738 
739 bool
FindSignalAtClassLevel(VDKObject *,char *)740 VDKObject::FindSignalAtClassLevel(VDKObject* , char* )
741 {
742 	return false;
743 }
744 
745 bool
FindSignalAtParentLevel(VDKObject *,char *)746 VDKObject::FindSignalAtParentLevel(VDKObject* , char* )
747 {
748 	return false;
749 }
750 
751 bool
FindEventAtClassLevel(VDKObject *,char *)752 VDKObject::FindEventAtClassLevel(VDKObject* , char* )
753 {
754 	return false;
755 }
756 
757 bool
FindEventAtParentLevel(VDKObject *,char *)758 VDKObject::FindEventAtParentLevel(VDKObject* , char* )
759 {
760 	return false;
761 }
762 
763 int
VDKEventUnitResponse(GtkWidget *,char *,GdkEvent *,void *)764 VDKObject::VDKEventUnitResponse(GtkWidget* , char* , GdkEvent* , void*)
765 {
766 	return 0;
767 }
768 
769 int
EventConnect(VDKObject * obj,char * event,bool (VDKObject::* method)(VDKObject *,GdkEvent *),bool after)770 VDKObject::EventConnect(VDKObject* obj,
771        char* event,
772        bool (VDKObject::*method) (VDKObject* , GdkEvent*),
773        bool after)
774 {
775 	return -1;
776 }
777 
778 int
EventConnect(char *,bool (VDKObject::*)(VDKObject *,GdkEvent *),bool after)779 VDKObject::EventConnect(char* , bool (VDKObject::*) (VDKObject* , GdkEvent*),
780        bool after)
781 {
782 	return -1;
783 }
784 
785 bool
EventDisconnect(int connection)786 VDKObject::EventDisconnect(int connection)
787 {
788 	return false;
789 }
790 int
VDKSignalResponseListSize()791 VDKObject::VDKSignalResponseListSize()
792 {
793 	return 0;
794 }
795 
796 /*
797 ==================
798 signal emitting
799 (static tables)
800 =================
801 */
SignalEmit(int sig)802 void VDKObject::SignalEmit(int sig)
803 {
804   VDKObjectSignal signal;
805   signal.obj = this;
806   signal.signal = sig;
807   VDKSignalPipe(widget,&signal);
808 }
809 /*
810 ==================
811 signal emitting
812 (dyna tables)
813 =================
814  */
SignalEmit(char * sig)815 void VDKObject::SignalEmit(char* sig)
816 {
817   VDKObjectSignalUnit* signal = new VDKObjectSignalUnit(this,this,sig);
818   suList.add(signal);
819   VDKSignalUnitPipe(widget,signal);
820 }
821 /*
822 ==================
823 signal emitting
824 to parent level
825 (dyna lists)
826 =================
827  */
SignalEmitParent(char * sig)828 void VDKObject::SignalEmitParent(char* sig)
829 {
830   VDKObjectSignalUnit* signal = new VDKObjectSignalUnit(Parent(),this,sig);
831   suList.add(signal);
832   VDKSignalUnitPipe(widget,signal);
833 }
834 /*
835 ==================
836 signal emitting
837 to class or
838 parent level
839 (static tables)
840 =================
841 private
842  */
SignalEmit(int signal,int level)843 void VDKObject::SignalEmit(int signal, int level)
844 {
845   VDKObject* obj_parent;
846   switch (level)
847     {
848       // visit class level
849     case Class_level:
850       if(VDKObjectSignalResponse(widget, signal, this,false))
851 	return;
852       // visit level passing himself as sender
853     case Parent_level:
854       for(obj_parent = Parent(); obj_parent; obj_parent = obj_parent->Parent())
855 	if(obj_parent->VDKSignalResponse(widget, signal,
856 					 this, this, false))
857 	  break;
858     }
859 }
860 
861 /*
862 ======================================================================
863 */
864 /*
865  */
866 void
SetFont(VDKFont * font)867 VDKObject::SetFont(VDKFont* font)
868 {
869   if(!widget) return;
870   _setFont_(widget,font);
871   ItemListIterator li(items);
872   for(;li;li++)
873 	li.current()->SetFont(font);
874 
875 }
876 /*
877  */
878 void
_setFont_(GtkWidget * wid,VDKFont * font)879 VDKObject::_setFont_(GtkWidget* wid, VDKFont* font)
880 {
881   if(GTK_IS_WIDGET(wid) && font)
882     {
883 
884       //      if(!GTK_WIDGET_REALIZED(wid))
885       //	{
886       	  PangoFontDescription* font_desc = font->AsPangoFontDescription();
887       	  g_return_if_fail (font_desc != NULL);
888       	  gtk_widget_modify_font (wid,font_desc);
889 
890 	  // 	}
891       /*
892       else
893 	{
894 	  GtkRcStyle *rc_style;
895 	  rc_style = gtk_rc_style_new ();
896 	  rc_style->font_desc =
897 	    pango_font_description_copy (font->AsPangoFontDescription());
898 	  gtk_widget_modify_style (WrappedWidget(), rc_style);
899 	  gtk_rc_style_unref (rc_style);
900 	  gtk_widget_size_request (wid, NULL);
901 	}
902 	  */
903     }
904 }
905 
906 /*
907  */
908 void
SetForeground(VDKRgb color,GtkStateType state)909 VDKObject::SetForeground(VDKRgb color, GtkStateType state)
910 {
911   if(!widget) return;
912   _setForeground_(widget,color.red,color.green,color.blue, state);
913 }
914 
915 /*
916  */
917 void
SetBackground(VDKRgb color,GtkStateType state)918 VDKObject::SetBackground(VDKRgb color, GtkStateType state)
919 {
920   if(!widget) return;
921   _setBackground_(widget,color.red,color.green,color.blue, state);
922 }
923 
924 /*
925 read background color property
926  */
927 VDKRgb
GetBackground(GtkStateType state)928 VDKObject::GetBackground(GtkStateType state)
929 {
930 VDKRgb rgb;
931 switch(state)
932   {
933   case GTK_STATE_ACTIVE:
934     rgb = ActiveBackground;
935     break;
936   case GTK_STATE_PRELIGHT:
937     rgb = PrelightBackground;
938     break;
939   case GTK_STATE_SELECTED:
940     rgb = SelectedBackground;
941     break;
942   case GTK_STATE_INSENSITIVE:
943     rgb = InsensitiveBackground;
944     break;
945   default:
946     rgb = NormalBackground;
947   }
948 return rgb;
949 }
950 /*
951 read foreground color property
952  */
953 VDKRgb
GetForeground(GtkStateType state)954 VDKObject::GetForeground(GtkStateType state)
955 {
956   VDKRgb rgb = Foreground;
957   return rgb;
958 }
959 
960 
961 void
_setBackground_(GtkWidget * wid,int red,int green,int blue,GtkStateType state)962 VDKObject::_setBackground_(GtkWidget* wid,
963 			   int red,int green, int blue,
964 			   GtkStateType state)
965 {
966   VDKColor *color = NULL;
967 
968   if(!GTK_IS_WIDGET(wid))
969     return;
970   else
971     color = new VDKColor(Owner() ? Owner() : this ,red,green,blue);
972   gtk_widget_modify_bg (wid,state,color->Color());
973 }
974 /*
975  */
976 void
_setForeground_(GtkWidget * wid,int red,int green,int blue,GtkStateType state)977 VDKObject::_setForeground_(GtkWidget* wid,
978 			   int red,int green, int blue,
979 			   GtkStateType state)
980 {
981   VDKColor *color = NULL;
982   if(!GTK_IS_WIDGET(wid))
983     return;
984   else
985     color = new VDKColor(Owner() ? Owner() : this ,red,green,blue);
986   gtk_widget_modify_fg (wid,state,color->Color());
987 
988 }
989 /*
990  */
991 void
Enable(bool flag)992 VDKObject::Enable(bool flag)
993 {
994   if(GTK_IS_WIDGET(widget))
995      {
996        gtk_widget_set_sensitive (widget, flag);
997        Enabled(flag);
998      }
999 }
1000 /*
1001  */
1002 void
SetTip(const char * t)1003 VDKObject::SetTip(const char* t)
1004 {
1005   if(tip)
1006     tip->SetTip(t);
1007   else
1008     tip = new VDKTooltip(Owner(), this, t);
1009 }
1010 
1011 /*
1012  */
1013 void
GrabFocus()1014 VDKObject::GrabFocus()
1015 {
1016 	if (widget) {
1017 		VDKCustom* custom = dynamic_cast<VDKCustom*>(this);
1018 		if (custom) gtk_widget_grab_focus(custom->CustomWidget());
1019 		else gtk_widget_grab_focus(WrappedWidget());
1020 	}
1021 }
1022 /*
1023  */
1024 bool
isFocused()1025 VDKObject::isFocused()
1026 {
1027 	if (widget) return gtk_widget_has_focus(widget);
1028 	return false;
1029 }
1030 /*
1031  */
ShowWidget(bool visible)1032 void VDKObject::ShowWidget(bool visible)
1033 {
1034 if(widget && GTK_IS_WIDGET(widget))
1035   {
1036     if(visible)
1037       gtk_widget_show(widget);
1038     else
1039       gtk_widget_hide(widget);
1040   }
1041 }
1042 /*
1043  */
1044 void
Add(VDKObject *,int,int,int,int)1045 VDKObject::Add(VDKObject*, int, int ,
1046 	       int , int  )
1047 {
1048 	g_warning("VDKObject::Add() unuseful call");
1049 }
1050 /*
1051  */
AddItem(VDKObject * item)1052 void VDKObject::AddItem(VDKObject* item)
1053 {
1054 	items.add(item);
1055 }
1056 /*
1057  */
RemoveItem(VDKObject * item)1058 void VDKObject::RemoveItem(VDKObject* item)
1059 {
1060   if(items.remove(item))
1061     {
1062       if(Owner())
1063 	Owner()->Garbages().add(item);
1064       else
1065 	Garbages().add(item);
1066     }
1067 }
1068 /*
1069 recursively removes items
1070  */
RemoveItems()1071 void VDKObject::RemoveItems()
1072 {
1073   if(items.size() > 0)
1074     {
1075       ItemListIterator li(items);
1076       for(;li;li++)
1077 	{
1078 	  li.current()->RemoveItems();
1079 	  if(Owner())
1080 	    Owner()->Garbages().add(li.current());
1081 	  else
1082 	    Garbages().add(li.current());
1083 	}
1084 #ifdef VDKDEBUG
1085       objRemoved += items.size();
1086 #endif
1087       items.flush();
1088     }
1089 if(Owner())
1090   Owner()->Garbages().add(this);
1091 else
1092   Garbages().add(this);
1093 #ifdef VDKDEBUG
1094   objRemoved ++;
1095 #endif
1096 }
1097 
1098 /*
1099 explicitely destroy this
1100 */
1101 
Destroy()1102 bool VDKObject::Destroy()
1103 {
1104   VDKObject* parent = NULL;
1105 
1106   for(parent = Parent() ; parent; parent = parent->Parent())
1107     if( Parent()->Items().remove(this) || Parent()->Garbages().remove(this) )
1108       break;
1109 
1110   if(parent && widget != NULL && GTK_IS_WIDGET(widget))
1111     {
1112 #ifdef VDKDEBUG
1113       printf("\ndestroying widget:%p",Widget());
1114       fflush(stdout);
1115 #endif
1116       gtk_widget_destroy(Widget());
1117       delete this;
1118       return true;
1119     }
1120   else
1121     return false;
1122 }
1123 
1124 /*
1125  */
Draw(GdkRectangle * area)1126 void VDKObject::Draw(GdkRectangle* area)
1127 {
1128   if(widget)
1129     gtk_widget_draw(widget,area);
1130 }
1131 
1132 /*
1133  */
operator =(VDKPoint p)1134 void SizeObjectProp::operator = (VDKPoint p)
1135 {
1136   value = p;
1137   GtkWidget* wid = object->Widget();
1138   if(wid)
1139     gtk_widget_set_size_request(wid,p.X(), p.Y());
1140 }
1141 
1142 /*
1143  */
operator VDKPoint()1144 SizeObjectProp::operator VDKPoint()
1145 {
1146   GtkWidget* wid = object->Widget();
1147   return wid ? VDKPoint (wid->allocation.width,
1148 			 wid->allocation.height) : VDKPoint(0,0);
1149 }
1150 
1151 #ifdef USE_SIGCPLUSPLUS
1152 // Compiled from here in order to avoid complicated conditionals
1153 // in makefile, will change in near future
1154 #include "sigc_events.cc"
1155 #include "sigc_eventsignals.cc"
1156 #endif /* USE_SIGCPLUSPLUS */
1157 
1158 
1159 
1160 
1161 
1162 
1163 
1164 
1165 
1166