source: golgotha/src/i4/menu/menuitem.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 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: 4.2 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 "menu/menuitem.hh"
10#include "window/win_evt.hh"
11#include "window/style.hh"
12
13i4_menu_item_class::i4_menu_item_class(const i4_const_str *idle_context_help,
14                                       i4_graphical_style_class *hint,
15                                       w16 w, w16 h,
16                                       i4_event_reaction_class *press,   
17                                       i4_event_reaction_class *depress,
18                                       i4_event_reaction_class *activate,
19                                       i4_event_reaction_class *deactivate
20                                       ) :
21  i4_parent_window_class(w,h),
22  hint(hint)
23{
24  if (idle_context_help)
25    context_help=new i4_str(*idle_context_help);
26  else
27    context_help=0;
28 
29  send.press=press;
30  send.depress=depress;
31  send.activate=activate;
32  send.deactivate=deactivate;
33  menu_parent=0;
34
35  active=i4_F;
36  pressed=i4_F;
37  disabled=i4_F;
38}
39
40void i4_menu_item_class::send_event(i4_event_reaction_class *ev, reaction_type type)
41{
42  if (menu_parent)
43    menu_parent->note_reaction_sent(this, ev, type);
44
45  if (ev && ev->event && ev->handler_reference.get())
46    i4_kernel.send_event(ev->handler_reference.get(), ev->event);
47}
48
49void i4_menu_item_class::receive_event(i4_event *ev)
50{
51  i4_parent_window_class::receive_event(ev);
52
53  if (!disabled)
54  {
55    if (ev->type()==i4_event::MOUSE_BUTTON_UP || ev->type()==i4_event::MOUSE_BUTTON_DOWN)
56      if (context_help_window.get())
57        i4_kernel.delete_handler(context_help_window.get());
58
59
60    if (ev->type()==i4_event::WINDOW_MESSAGE)
61    {
62      CAST_PTR(w,i4_window_message_class,ev);
63      switch (w->sub_type)
64      {
65        case i4_window_message_class::GOT_KEYBOARD_FOCUS :
66        case i4_window_message_class::GOT_MOUSE_FOCUS :
67        {         
68          do_activate();
69          send_event(send.activate, ACTIVATED);
70        } break;
71        case i4_window_message_class::LOST_KEYBOARD_FOCUS :
72        case i4_window_message_class::LOST_MOUSE_FOCUS :
73        {
74          if (context_help_window.get())
75          {
76            i4_window_class *w=context_help_window.get();
77            context_help_window=0;
78            i4_kernel.delete_handler(w);
79          }
80
81          do_deactivate();
82          send_event(send.deactivate, DEACTIVATED);
83        } break;
84
85      }
86    }
87    else if (ev->type()==i4_event::IDLE_MESSAGE)
88      do_idle();
89
90  }
91}
92
93
94void i4_menu_item_class::do_idle()
95{
96  if (!context_help_window.get() && context_help)
97    context_help_window=hint->create_quick_context_help(x(), y()+height()+5, *context_help);
98}
99
100void i4_menu_item_class::do_activate()
101{
102  if (!active)
103  {
104    active=i4_T;
105    request_redraw();
106  }
107}
108
109void i4_menu_item_class::do_deactivate()
110{
111  if (active)
112  {
113    active=i4_F;
114    request_redraw();
115  }
116}
117
118void i4_menu_item_class::do_disable()
119{
120  if (!disabled)
121  {
122    disabled=i4_T;
123    request_redraw();
124  }
125}
126
127void i4_menu_item_class::do_undisable()
128{
129  if (disabled)
130  {
131    disabled=i4_F;
132    request_redraw();
133  }
134}
135
136void i4_menu_item_class::do_press()
137{
138  if (!pressed)
139  {
140    pressed=i4_T;
141    request_redraw();
142  }
143}
144
145void i4_menu_item_class::do_depress()
146{
147  if (pressed)
148  {
149    pressed=i4_F;
150    request_redraw();
151  }
152}
153
154
155i4_menu_item_class::~i4_menu_item_class()
156{
157  if (context_help_window.get())
158    i4_kernel.delete_handler(context_help_window.get());
159
160  if (context_help)
161    delete context_help;
162
163  if (send.press)
164    delete send.press;   
165
166  if (send.depress)
167    delete send.depress;
168
169  if (send.activate)
170    delete send.activate;
171
172  if (send.deactivate)
173    delete send.deactivate;
174}
175
176
Note: See TracBrowser for help on using the repository browser.