Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / gui.src / obsolete / group.cc
1 /*
2  * Simulator of microcontrollers (group.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM 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
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "groupcl.h"
29 #include "appcl.h"
30
31
32 cl_group::cl_group(class cl_box *ipos, char *iname, class cl_app *iapp):
33   cl_view(ipos, iname, iapp)
34 {
35   current= 0;
36 }
37
38 cl_group::cl_group(char *iname, class cl_app *iapp):
39   cl_view(iname, iapp)
40 {
41   current= 0;
42 }
43
44 cl_group::~cl_group(void)
45 {}
46
47 int
48 cl_group::init(void)
49 {
50   cl_view::init();
51   mk_views(this);
52   return(0);
53 }
54
55 int
56 cl_group::mk_views(class cl_group *ins_to)
57 {
58   return(0);
59 }
60
61
62 /*
63  * Make output by drawing all subviews
64  */
65
66 static void do_draw_view(class cl_view *view)
67 {
68   view->draw();
69 }
70
71 int
72 cl_group::draw(void)
73 {
74   /*int i;
75
76   for (i= 0; i < views->count; i++)
77     {
78       class cl_view *v= (class cl_view *)(views->at(i));
79       v->draw();
80       app->drawn++;
81       }*/
82   for_each(do_draw_view);
83   return(0);
84 }
85
86 /*int
87 cl_group::update(void)
88 {
89   draw();
90   update_panels();
91   doupdate();
92 }*/
93
94
95 int
96 cl_group::handle_event(struct t_event *event)
97 {
98   int handled= 0;
99
100   if (event->what & (EV_KEY|EV_COMMAND))
101     {
102       if (current)
103         handled= current->handle_event(event);
104     }
105   else if (event->what & EV_MESSAGE)
106     {
107       class cl_view *v= last;
108       do 
109         {
110           handled= v->handle_event(event);
111           v= v->next;
112         }
113       while (! handled &&
114              v != last);
115     }
116   return(handled);
117 }
118
119
120 /*
121  * Managing views
122  */
123
124 //class cl_view *
125 void
126 cl_group::insert(class cl_view *view)
127 {
128   /*if (view &&
129       view->ok())
130     {
131       views->add_at(0, view);
132       view->parent= this;
133       view->select();
134       //view->draw();
135       return(view);
136       }
137       return(0);*/
138   insert_before(view, first());
139   if (view->options & OF_SELECTABLE)
140     view->select();
141   draw();
142 }
143
144 void
145 cl_group::insert_before(class cl_view *view, class cl_view *target)
146 {
147   unsigned int ss;
148
149   if (view &&
150       !(view->parent) &&
151       (!target ||
152        target->parent == this))
153     {
154       ss= view->state;
155       //view->hide();
156       insert_view(view, target);
157       /*if (ss & SF_VISIBLE)
158         view->show();*/
159       if (state & SF_ACTIVE)
160         view->change_state(SF_ACTIVE, 1);
161     }
162 }
163
164 void
165 cl_group::insert_view(class cl_view *view, class cl_view *target)
166 {
167   view->parent= this;
168   if (target)
169     {
170       target= target->prev();
171       view->next= target->next;
172       target->next= view;
173     }
174   else
175     {
176       if (!last)
177         view->next= view;
178       else
179         {
180           view->next= last->next;
181           last->next= view;
182         }
183       last= view;
184     }
185 }
186
187 class cl_view *
188 cl_group::first(void)
189 {
190   if (!last)
191     return(0);
192   return(last->next);
193 }
194
195
196 /*class cl_view *
197 cl_group::get_by_state(unsigned int what, int enabled)
198 {
199   int i;
200
201   for (i= 0; i < views->count; i++)
202     {
203       class cl_view *v= (class cl_view *)(views->at(i));
204       if ((enabled &&
205            (state&what))
206           ||
207           (!enabled &&
208            ((~state)&what))
209           )
210         return(v);
211     }
212   return(0);
213 }*/
214
215 /*int
216 cl_group::select(void)
217 {
218 }*/
219
220 /*int
221 cl_group::unselect(void)
222 {
223 }*/
224
225 int
226 cl_group::select_next()
227 {
228   /*  int start, i;
229   class cl_view *v;
230
231   if (views->count <= 1)
232     return(1);
233   if (current)
234     start= views->index_of(current);
235   else
236     if ((v= get_by_state(SF_SELECTED, 1)))
237       start= views->index_of(v);
238     else
239       if ((v= get_by_state(SF_FOCUSED, 1)))
240         start= views->index_of(v);
241       else
242         start= 0;
243   i= (start+1)%(views->count);
244   while (i != start)
245     {
246       v= (class cl_view *)(views->at(i));
247       if ((v->options & OF_SELECTABLE) &&
248           v->select())
249         {
250           //update();
251           return(1);
252         }
253       i= (i+1)%(views->count);
254       }*/
255   return(0);
256 }
257
258 int
259 cl_group::select_prev()
260 {
261   /*  int start, i;
262   class cl_view *v;
263
264   if (views->count <= 1)
265     return(1);
266   if (current)
267     start= views->index_of(current);
268   else
269     if ((v= get_by_state(SF_SELECTED, 1)))
270       start= views->index_of(v);
271     else
272       if ((v= get_by_state(SF_FOCUSED, 1)))
273         start= views->index_of(v);
274       else
275         start= 0;
276   i= start-1; if (i < 0) i= views->count-1;
277   while (i != start)
278     {
279       v= (class cl_view *)(views->at(i));
280       if ((v->options & OF_SELECTABLE) &&
281           v->select())
282         {
283           //update();
284           return(1);
285         }
286       i= start-1; if (i < 0) i= views->count-1;
287       }*/
288   return(0);
289 }
290
291 class cl_view *
292 cl_group::current_sub_view(void)
293 {
294   return(current);
295 }
296
297 void
298 cl_group::for_each(void (*func)(class cl_view *view))
299 {
300   class cl_view *v;
301
302   if (!last)
303     return;
304   v= last->next;
305   do
306     {
307       func(v);
308       v= v->next;
309     }
310   while (v != last);
311 }
312
313 void
314 cl_group::set_current(class cl_view *view)
315 {
316   //current= view;
317   if (current == view)
318     return;
319   //lock();
320   /*focus_view(view, 0);*/
321   if ((state & SF_FOCUSED) &&
322       (current != 0))
323     current->change_state(SF_FOCUSED, 0);
324   //if (mode!=ENTER_SELECT) select_view(current, 0);
325   if (current)
326     current->change_state(SF_SELECTED, 0);
327   //if (mode!=LEAVE_SELECT) select_view(view, 1);
328   if (view)
329     view->change_state(SF_SELECTED, 1);
330   //focuse_view(view, 1);
331   if ((state & SF_FOCUSED) &&
332       (view != 0))
333     view->change_state(SF_SELECTED, 1);
334   current= view;
335   //unlock();
336 }
337
338 /*int
339 cl_group::terminal_view(void)
340 {
341   return(views->count == 0);
342 }*/
343
344 static unsigned int grp_what, grp_en;
345
346 static void
347 do_set_state(class cl_view *v)
348 {
349   v->change_state(grp_what, grp_en);
350 }
351
352 void
353 cl_group::change_state(unsigned int what, int enable)
354 {
355   cl_view::change_state(what, enable);
356   /*if (enable &&
357       (what & SF_SELECTED))
358     {
359       class cl_view *v= get_by_state(SF_SELECTED, 1);
360       if (v)
361         {
362           current= v;
363           current->change_state(SF_FOCUSED, 1);
364           current->change_state(SF_SELECTED, 1);
365         }
366       else
367         {
368           if ((v= get_by_state(SF_FOCUSED, 1)))
369             {
370               current= v;
371               current->change_state(SF_SELECTED, 1);
372             }
373         }
374         }*/
375   switch (what)
376     {
377       case SF_ACTIVE:
378         //lock();
379         grp_what= what;
380         grp_en= enable;
381         for_each(do_set_state);
382         //unlock();
383         break;
384     case SF_FOCUSED:
385       if (current)
386         current->change_state(SF_FOCUSED, enable);
387       break;
388     }
389   draw();
390 }
391
392
393 /* End of gui.src/group.cc */