1 /*
2  * ===========================
3  * VDK Visual Develeopment Kit
4  * Version 0.4
5  * Revision 0.4.1
6  * October 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 //#include <vdk/widcontain.h>
29 #include <vdk/vdkdockable.h>
30 #include <config.h>
31 /*!
32     Add an object.
33   */
34 void
Add(VDKObject * obj,int justify,int fill,int expand,int padding)35 VDKObjectContainer::Add(VDKObject* obj, int justify,
36 		   int fill, int expand, int padding)
37     {
38       // agreed isn't a good OOP practice, but it's too late to
39       // redesign the whole
40       VDKDockerBox* dbox = dynamic_cast<VDKDockerBox*>(obj);
41       if(dbox)
42 	{
43 	  dbox->justify = justify;
44 	  dbox->fill = fill;
45 	  dbox->expand = expand;
46 	  dbox->padding = padding;
47 	}
48       items.add(obj);
49       obj->Parent(this);
50       obj->Setup();
51       gtk_widget_show(obj->Widget());
52     }
53 /*
54  */
VDKObjectContainer(VDKForm * owner)55 VDKObjectContainer::VDKObjectContainer(VDKForm* owner):
56     VDKObject(owner)
57 {
58 }
59 
60 /*
61 This function will remove an object from a container
62 without destroying it.
63 Note:
64 Should be used to reparent an widget, or it will leak.
65 Use this:
66 // remove from source container
67 // referencing it otherwise will be destroyed by gtk+
68 source->RemoveObjectFromContainer(widget);
69 // add to target container (referencing it again)
70 target->Add(widget);
71 // set target as parent
72 widget->Parent(target);
73 // unref widget again (or it will leak)
74 gtk_widget_unref(widget->Widget());
75  */
76 void
RemoveObjectFromContainer(VDKObject * obj)77 VDKObjectContainer::RemoveObjectFromContainer(VDKObject* obj)
78 {
79 if(obj->Widget() &&
80    GTK_IS_WIDGET(obj->Widget()) &&
81    GTK_IS_CONTAINER(obj->Widget()->parent))
82   {
83     int result = 0;
84     // remove from source container
85     // referencing it otherwise will be destroyed by gtk+
86     gtk_widget_ref(obj->Widget());
87     gtk_container_remove(GTK_CONTAINER (obj->Widget()->parent),
88 			 obj->Widget());
89     result = items.remove(obj);
90 #ifdef VDKDEBUG
91     printf("\nremoved from gtk+ container:%p - result:%d",widget,result);
92     fflush(stdout);
93 #endif
94   }
95 
96 }
97 
98 
99 /*
100  */
RemoveObjects()101 void VDKObjectContainer::RemoveObjects()
102 {
103   ItemListIterator li(items);
104   VDKItem<VDKObject> *p = li.Head();
105   VDKItem<VDKObject> *p1;
106   while(p)
107     {
108       p1 = li.Next(p);
109       li.Now(p)->Destroy();
110       p = p1;
111     }
112 }
113 /*
114  */
FindTag(int tag)115 VDKObject* VDKObjectContainer::FindTag(int tag)
116 {
117 ItemListIterator li(items);
118 for(;li;li++)
119   if(li.current()->Tag == tag)
120     return li.current();
121 return static_cast<VDKObject*>(NULL);
122 }
123 /*
ForEachDo(void (* action)(VDKObject *))124  */void VDKObjectContainer::ForEachDo(void (*action)(VDKObject*))
125 {
126 ItemListIterator li(items);
127 for(;li;li++)
128   action(li.current());
129 }
130 /*
131  */
Select(ItemList * list,bool (* condition)(VDKObject *))132 void VDKObjectContainer::Select(ItemList* list, bool (*condition)(VDKObject*))
133 {
134 ItemListIterator li(items);
135 for(;li;li++)
136   if(condition(li.current()))
137     list->add(li.current());
138 return ;
139 }
140 
141 
142