source: golgotha/src/i4/window/wmanager.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 8.5 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "window/wmanager.hh"
10#include "error/error.hh"
11#include "window/style.hh"
12#include "error/error.hh"
13#include "window/win_evt.hh"
14
15
16
17i4_color i4_window_manager_class::i4_read_color_from_resource(char *resource)
18{
19  i4_const_str::iterator i=i4gets(resource).begin();
20  i4_color red=i.read_number();
21  i4_color grn=i.read_number();
22  i4_color blue=i.read_number();
23
24
25  return i4_pal_man.convert_32_to( (red<<16)|(grn<<8)|(blue),
26                                   &local_image->get_pal()->source);
27
28}
29
30void i4_window_manager_class::set_background_color(w32 color)
31{
32  background_color=color;
33}
34
35void i4_window_manager_class::parent_draw(i4_draw_context_class &context)
36{     
37  i4_rect_list_class child_clip(&context.clip,0,0);
38  child_clip.intersect_list(&undrawn_area);   // intersect clipped area with area that needs to be drawn
39
40  child_clip.swap(&context.clip);                 // make this the display's new clip list
41
42  local_image->clear(background_color,context);          // clear out this area
43
44  child_clip.swap(&context.clip);                 // restore the display's clip list
45}
46
47void i4_window_manager_class::root_draw()  // called by application
48{
49//   i4_draw_context_class c(0,0,639,439);
50//   display->get_screen()->clear(0, c);
51
52  i4_parent_window_class::draw(*display->get_context());
53
54  display->flush();                                   // tell the display to page-flip or copy-dirty rects
55}
56 
57  // a window manager does not actually get associated with anything until prepare_for_mode
58i4_window_manager_class::i4_window_manager_class() : i4_parent_window_class(0,0)
59{
60  drag_drop.active=i4_F;
61  display=0;
62  devices_present=0;
63  style=0;
64  default_cursor=0;
65  background_color=0;
66  no_cursor_installed=i4_T;
67  key_modifiers_pressed=0;
68}
69
70i4_window_manager_class::~i4_window_manager_class()
71{
72  cleanup_old_mode();
73}
74
75void i4_window_manager_class::receive_event(i4_event *ev)
76{
77  if (ev->type()==i4_event::WINDOW_MESSAGE)
78  {
79    CAST_PTR(cc,i4_window_change_cursor_class,ev);
80    if (cc->sub_type==i4_window_message_class::CHANGE_CURSOR)
81    {
82      if (cc->cursor)
83      {
84        display->set_mouse_shape(cc->cursor);
85        no_cursor_installed=i4_F;
86      }
87      else if (default_cursor)  // make sure we have default cursor first
88        display->set_mouse_shape(default_cursor);
89    }
90    else if (cc->sub_type==i4_window_message_class::REQUEST_DRAG_DROP_START)
91    {
92      CAST_PTR(drag, i4_window_request_drag_drop_start_class, ev);
93      drag_drop.active=i4_T;
94      drag_drop.reference_id=drag->reference_id;
95      drag_drop.further_info=drag->further_info;
96      drag_drop.originator=drag->from();
97      if (drag->drag_cursor)
98        display->set_mouse_shape(drag->drag_cursor);
99    }
100    else if (cc->sub_type==i4_window_message_class::REQUEST_DRAG_DROP_END)
101    {
102      i4_error("fixme");
103//       drag_drop.active=i4_F;
104//       if (default_cursor)
105//         display->set_mouse_shape(default_cursor);
106
107//       i4_window_class *prev_from=drag_frop
108
109//       i4_window_got_drop_class drop(drag_drop.originator,
110//                                     drag_drop.reference_id,
111//                                     drag_drop.further_info);
112
113//       i4_parent_window_class::receive_event(&drop);
114    }
115 
116    else if (cc->sub_type==i4_window_message_class::REQUEST_MOUSE_GRAB)
117    {
118      CAST_PTR(grab,i4_window_request_mouse_grab_class,ev);
119     
120      i4_parent_window_class::receive_event(ev);
121    }
122    else if (cc->sub_type==i4_window_message_class::REQUEST_MOUSE_UNGRAB)
123    {
124      CAST_PTR(ungrab,i4_window_request_mouse_ungrab_class,ev);
125     
126      i4_parent_window_class::receive_event(ev);
127      ungrab->return_result=i4_T;
128    } 
129    else i4_parent_window_class::receive_event(ev);
130
131  } else if (ev->type()==i4_event::DISPLAY_CHANGE)
132  {
133
134    i4_image_class *im=display->get_screen();
135    private_resize(im->width(),im->height());         // in case the resolution changed
136    reparent(im,0);                           // grab the new image
137
138  }
139  else
140  {
141    switch (ev->type())
142    {
143      case i4_event::KEY_PRESS :
144        key_modifiers_pressed=((i4_key_press_event_class *)ev)->modifiers;
145        break;
146
147      case i4_event::KEY_RELEASE :
148        key_modifiers_pressed=((i4_key_release_event_class *)ev)->modifiers;
149        break;
150
151      case i4_event::MOUSE_BUTTON_DOWN :
152      case i4_event::MOUSE_BUTTON_UP :
153      {
154        CAST_PTR(bev, i4_mouse_button_event_class,ev);
155        if (bev->time.milli_diff(bev->last_time)<style->time_hint->double_click)
156          bev->double_click=i4_T;
157
158      } break;
159    }
160
161    i4_parent_window_class::receive_event(ev);
162  }
163
164
165  if (drag_drop.active && ev->type()==i4_event::MOUSE_MOVE)
166  {
167    CAST_PTR(mouse_move, i4_mouse_move_event_class, ev);
168    i4_window_drag_drop_move_class move(drag_drop.originator,
169                                        mouse_move->x,
170                                        mouse_move->y,
171                                        drag_drop.reference_id,
172                                        drag_drop.further_info);
173    i4_parent_window_class::receive_event(&move);
174                                       
175  }
176}
177
178void i4_window_manager_class::set_default_cursor(i4_cursor_class *cursor)
179{
180  if (default_cursor)
181    delete default_cursor;
182
183  default_cursor=cursor->copy();
184
185  if (no_cursor_installed)
186    display->set_mouse_shape(cursor);
187}
188
189
190i4_graphical_style_class *i4_window_manager_class::get_style()
191{
192  return style;
193}
194
195void i4_window_manager_class::prepare_for_mode(i4_display_class *display,
196                                               i4_display_class::mode *mode)
197{
198  cleanup_old_mode();
199
200  i4_window_manager_class::display=display;
201
202  const i4_const_str s=i4gets("window_manager",i4_F);
203 
204  if (!s.null())
205  {
206    char buf[100];
207    i4_const_str::iterator i=s.begin();
208    i.read_ascii(buf,100);
209
210    style=i4_style_man.find_style(buf);
211  }
212  else style=0;
213
214  if (!style)
215    style=i4_style_man.first_style();
216
217
218  if (!style)
219     i4_error("No window styles installed");
220
221
222
223
224  i4_image_class *im=display->get_screen();
225  resize(im->width(),im->height());
226  reparent(im,0);
227
228
229  style->prepare_for_mode(local_image->get_pal(), mode);
230
231  i4_kernel.request_events(this,
232                           i4_device_class::FLAG_MOUSE_BUTTON_UP|
233                           i4_device_class::FLAG_MOUSE_BUTTON_DOWN|
234                           i4_device_class::FLAG_MOUSE_MOVE|
235                           i4_device_class::FLAG_KEY_PRESS|
236                           i4_device_class::FLAG_KEY_RELEASE|
237                           i4_device_class::FLAG_DISPLAY_CHANGE|
238                           i4_device_class::FLAG_DRAG_DROP_EVENTS|
239                           i4_device_class::FLAG_IDLE);
240
241  default_cursor=style->cursor_hint->normal_cursor()->copy();
242  display->set_mouse_shape(default_cursor);
243
244
245  i4_const_str::iterator col=i4gets("root_background_color").begin();
246  w32 r=col.read_number();
247  w32 g=col.read_number();
248  w32 b=col.read_number();
249
250
251  background_color=i4_pal_man.convert_32_to( (r<<16)|(g<<8)|(b), 
252                                            &local_image->get_pal()->source);
253}
254
255void i4_window_manager_class::cleanup_old_mode()
256{
257  if (style)  // has a previous mode been used?
258  {   
259    i4_kernel.unrequest_events(this,
260                               i4_device_class::FLAG_MOUSE_BUTTON_UP|
261                               i4_device_class::FLAG_MOUSE_BUTTON_DOWN|
262                               i4_device_class::FLAG_MOUSE_MOVE|
263                               i4_device_class::FLAG_KEY_PRESS|
264                               i4_device_class::FLAG_KEY_RELEASE|
265                               i4_device_class::FLAG_DISPLAY_CHANGE |
266                               i4_device_class::FLAG_DRAG_DROP_EVENTS|
267                               i4_device_class::FLAG_IDLE
268                               );
269    if (default_cursor)
270    {
271      delete default_cursor;
272      default_cursor=0;
273      no_cursor_installed=i4_T;     
274    }
275  }
276}
277
278
Note: See TracBrowser for help on using the repository browser.