00001 #include "bcmenu.h"
00002 #include "bcmenubar.h"
00003 #include "bcmenuitem.h"
00004 #include "bcmenupopup.h"
00005 #include "bcpixmap.h"
00006 #include "bcresources.h"
00007 #include "bcsignals.h"
00008 #include <string.h>
00009
00010
00011
00012
00013
00014 BC_Menu::BC_Menu(char *text)
00015 {
00016 strcpy(this->text, text);
00017 menu_bar = 0;
00018 active = 0;
00019 highlighted = 0;
00020 }
00021
00022 BC_Menu::~BC_Menu()
00023 {
00024 delete menu_popup;
00025 }
00026
00027 int BC_Menu::initialize(BC_WindowBase *top_level,
00028 BC_MenuBar *menu_bar,
00029 int x,
00030 int y,
00031 int w,
00032 int h)
00033 {
00034 this->x = x;
00035 this->y = y;
00036 this->w = w;
00037 this->h = h;
00038 this->menu_bar = menu_bar;
00039 this->top_level = top_level;
00040 menu_popup = new BC_MenuPopup;
00041 menu_popup->initialize(top_level, menu_bar, this, 0, 0);
00042 draw_title();
00043 return 0;
00044 }
00045
00046 int BC_Menu::add_item(BC_MenuItem* menuitem)
00047 {
00048 menu_popup->add_item(menuitem);
00049 return 0;
00050 }
00051
00052 int BC_Menu::remove_item(BC_MenuItem *item)
00053 {
00054 menu_popup->remove_item(item);
00055 return 0;
00056 }
00057
00058 int BC_Menu::total_menuitems()
00059 {
00060 return menu_popup->total_menuitems();
00061 }
00062
00063 int BC_Menu::dispatch_button_press()
00064 {
00065 int result = 0;
00066
00067
00068 if(active)
00069 {
00070 result = menu_popup->dispatch_button_press();
00071 }
00072
00073
00074 if(!result)
00075 {
00076 if(top_level->event_win == menu_bar->win &&
00077 top_level->cursor_x >= x && top_level->cursor_x < x + w &&
00078 top_level->cursor_y >= y && top_level->cursor_y < y + h)
00079 {
00080 if(!active)
00081 {
00082 menu_bar->deactivate();
00083 menu_bar->unhighlight();
00084 menu_bar->button_releases = 0;
00085 menu_bar->activate();
00086 activate_menu();
00087 }
00088 result = 1;
00089 }
00090 }
00091 return result;
00092 }
00093
00094 int BC_Menu::dispatch_button_release()
00095 {
00096
00097 int result = 0;
00098 if(top_level->event_win == menu_bar->win &&
00099 top_level->cursor_x >= x && top_level->cursor_y < x + w &&
00100 top_level->cursor_y >= y && top_level->cursor_y < y + h)
00101 {
00102 if(menu_bar->button_releases >= 2)
00103 {
00104 highlighted = 1;
00105 menu_bar->deactivate();
00106 }
00107 result = 1;
00108 }
00109 else
00110
00111 result = menu_popup->dispatch_button_release();
00112 return result;
00113 }
00114
00115 int BC_Menu::dispatch_keypress()
00116 {
00117 return menu_popup->dispatch_key_press();
00118 }
00119
00120 int BC_Menu::dispatch_motion_event()
00121 {
00122 int result = 0;
00123 int cursor_x, cursor_y;
00124 Window tempwin;
00125
00126
00127 if(active)
00128 {
00129 result = menu_popup->dispatch_motion_event();
00130 }
00131
00132 if(!result)
00133 {
00134 top_level->translate_coordinates(top_level->event_win,
00135 menu_bar->win,
00136 top_level->cursor_x,
00137 top_level->cursor_y,
00138 &cursor_x,
00139 &cursor_y);
00140
00141
00142 if(menu_bar->active && !active &&
00143 cursor_x >= x && cursor_x < x + w &&
00144 cursor_y >= y && cursor_y < y + h)
00145 {
00146 menu_bar->activate();
00147 activate_menu();
00148 result = 1;
00149 }
00150 else
00151
00152 if(highlighted)
00153 {
00154 if(cursor_x < x || cursor_x >= x + w ||
00155 cursor_y < y || cursor_y >= y + h)
00156 {
00157 highlighted = 0;
00158 draw_title();
00159 }
00160 }
00161 else
00162 {
00163 if(cursor_x >= x && cursor_x < x + w &&
00164 cursor_y >= y && cursor_y < y + h)
00165 {
00166 menu_bar->unhighlight();
00167 highlighted = 1;
00168 draw_title();
00169 result = 1;
00170 }
00171 }
00172 }
00173 return result;
00174 }
00175
00176 int BC_Menu::dispatch_cursor_leave()
00177 {
00178 if(active)
00179 {
00180 menu_popup->dispatch_cursor_leave();
00181 }
00182 unhighlight();
00183 return 0;
00184 }
00185
00186 int BC_Menu::dispatch_translation_event()
00187 {
00188 if(active)
00189 {
00190 menu_popup->dispatch_translation_event();
00191 }
00192 return 0;
00193 }
00194
00195 int BC_Menu::activate_menu()
00196 {
00197 Window tempwin;
00198 int new_x, new_y, top_w, top_h;
00199 if(menu_bar)
00200 {
00201 XTranslateCoordinates(top_level->display,
00202 menu_bar->win,
00203 top_level->rootwin,
00204 x,
00205 y,
00206 &new_x,
00207 &new_y,
00208 &tempwin);
00209 menu_popup->activate_menu(new_x, new_y, w, h, 0, 1);
00210 }
00211 else
00212 menu_popup->activate_menu(x, y, w, h, 1, 1);
00213
00214 active = 1;
00215 draw_title();
00216 return 0;
00217 }
00218
00219 void BC_Menu::draw_items()
00220 {
00221 if(active) menu_popup->draw_items();
00222 }
00223
00224 int BC_Menu::set_text(char *text)
00225 {
00226 strcpy(this->text, text);
00227 draw_title();
00228 return 0;
00229 }
00230
00231 int BC_Menu::draw_title()
00232 {
00233 BC_Resources *resources = top_level->get_resources();
00234 int text_offset = 0;
00235 SET_TRACE
00236 if(active && menu_popup)
00237 {
00238
00239 SET_TRACE
00240 if(menu_bar->menu_title_bg[0])
00241 {
00242 SET_TRACE
00243 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[2]);
00244 }
00245 else
00246 {
00247 menu_bar->draw_3d_box(x, y, w, h,
00248 resources->menu_shadow,
00249 BLACK,
00250 resources->menu_down,
00251 resources->menu_down,
00252 resources->menu_light);
00253 }
00254 text_offset = 1;
00255 }
00256 else
00257
00258 {
00259 if(highlighted)
00260 {
00261 SET_TRACE
00262 if(menu_bar->menu_title_bg[0])
00263 {
00264 SET_TRACE
00265 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[1]);
00266 }
00267 else
00268 {
00269 menu_bar->set_color(resources->menu_highlighted);
00270 menu_bar->draw_box(x, y, w, h);
00271 }
00272 }
00273 else
00274 {
00275 SET_TRACE
00276 if(menu_bar->menu_title_bg[0])
00277 {
00278 SET_TRACE
00279 menu_bar->draw_9segment(x, 0, w, menu_bar->get_h(), menu_bar->menu_title_bg[0]);
00280 }
00281 else
00282 {
00283 menu_bar->draw_background(x, y, w, h);
00284 }
00285 }
00286 }
00287
00288 menu_bar->set_color(resources->menu_title_text);
00289 menu_bar->set_font(MEDIUMFONT);
00290 menu_bar->draw_text(x + 10 + text_offset,
00291 h - menu_bar->get_text_descent(MEDIUMFONT) + text_offset,
00292 text);
00293 menu_bar->flash();
00294 SET_TRACE
00295 return 0;
00296 }
00297
00298 int BC_Menu::deactivate_menu()
00299 {
00300 if(active)
00301 {
00302 menu_popup->deactivate_menu();
00303 active = 0;
00304 draw_title();
00305 }
00306 return 0;
00307 }
00308
00309 int BC_Menu::unhighlight()
00310 {
00311 if(highlighted)
00312 {
00313 highlighted = 0;
00314 draw_title();
00315 }
00316 return 0;
00317 }