Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bcmenubar.C

Go to the documentation of this file.
00001 #include "bcmenu.h"
00002 #include "bcmenubar.h"
00003 #include "bcmenupopup.h"
00004 #include "bcpixmap.h"
00005 #include "bcpopup.h"
00006 #include "bcpopupmenu.h"
00007 #include "bcresources.h"
00008 #include "bcsignals.h"
00009 #include "colors.h"
00010 #include "fonts.h"
00011 #include <string.h>
00012 #include "vframe.h"
00013 
00014 
00015 // ================================== Menu bar ==================================
00016 
00017 BC_MenuBar::BC_MenuBar(int x, int y, int w)
00018  : BC_SubWindow(x, y, w, 0, -1)
00019 {
00020 // Height is really determined by the font in create_tool_objects.
00021         button_releases = 0;
00022         active = 0;
00023         menu_bar_bg = 0;
00024         for(int i = 0; i < 3; i++)
00025                 menu_title_bg[i] = 0;
00026 }
00027 
00028 
00029 BC_MenuBar::~BC_MenuBar()
00030 {
00031 // Delete all titles.
00032         for(int i = 0; i < menu_titles.total; i++) delete menu_titles.values[i];
00033         menu_titles.remove_all();
00034         delete menu_bar_bg;
00035         for(int i = 0; i < 3; i++)
00036                 delete menu_title_bg[i];
00037 }
00038 
00039 int BC_MenuBar::initialize()
00040 {
00041 SET_TRACE
00042         BC_Resources *resources = get_resources();
00043 // Initialize dimensions
00044         h = calculate_height(this);
00045         bg_color = resources->menu_up;
00046 
00047         if(resources->menu_bar_bg) menu_bar_bg = new BC_Pixmap(this,
00048                 resources->menu_bar_bg);
00049 
00050         if(resources->menu_title_bg)
00051         {
00052                 for(int i = 0; i < 3; i++)
00053                         menu_title_bg[i] = new BC_Pixmap(this,
00054                                 resources->menu_title_bg[i]);
00055         }
00056 
00057 // Create the subwindow
00058         BC_SubWindow::initialize();
00059 
00060         if(resources->menu_bg) 
00061                 set_background(resources->menu_bg);
00062         draw_face();
00063 SET_TRACE
00064         return 0;
00065 }
00066 
00067 int BC_MenuBar::calculate_height(BC_WindowBase *window)
00068 {
00069         if(get_resources()->menu_bar_bg)
00070                 return get_resources()->menu_bar_bg->get_h();
00071         else
00072                 return window->get_text_height(MEDIUMFONT) + 8;
00073 }
00074 
00075 void BC_MenuBar::draw_items()
00076 {
00077         for(int i = 0; i < menu_titles.total; i++)
00078                 menu_titles.values[i]->draw_items();
00079         flush();
00080 }
00081 
00082 int BC_MenuBar::add_menu(BC_Menu* menu)
00083 {
00084         int x, w;
00085 
00086 // Get dimensions
00087         if(menu_titles.total == 0)
00088                 x = 2;
00089         else
00090                 x = menu_titles.values[menu_titles.total - 1]->x + 
00091                         menu_titles.values[menu_titles.total - 1]->w;
00092 
00093         w = get_text_width(MEDIUMFONT, menu->text) + 20;
00094 // get pointer
00095         menu_titles.append(menu);
00096 // initialize and draw
00097         menu->initialize(top_level, this, x, 2, w, get_h() - 4); 
00098         return 0;
00099 }
00100 
00101 int BC_MenuBar::focus_out_event()
00102 {
00103         deactivate();
00104         return 0;
00105 }
00106 
00107 int BC_MenuBar::button_press_event()
00108 {
00109         int result = 0;
00110 
00111         for(int i = 0; i < menu_titles.total && !result; i++)
00112         {
00113                 result = menu_titles.values[i]->dispatch_button_press();
00114         }
00115 
00116         return result;
00117 }
00118 
00119 int BC_MenuBar::button_release_event()
00120 {
00121         int result = 0;
00122 
00123         button_down = 0;
00124         button_releases++;
00125         for(int i = 0; i < menu_titles.total; i++)
00126         {
00127                 result += menu_titles.values[i]->dispatch_button_release();
00128         }
00129 
00130 // Button was released outside any menu.
00131         if(!result)
00132         {
00133                 deactivate();
00134         }
00135 //printf("BC_MenuBar::button_release_event %d\n", result);
00136 
00137         return result;
00138 }
00139 
00140 int BC_MenuBar::resize_event(int w, int h)
00141 {
00142         resize_window(w, get_h());
00143         draw_face();
00144         for(int i = 0; i < menu_titles.total; i++)
00145         {
00146                 menu_titles.values[i]->draw_title();
00147         }
00148         return 0;
00149 }
00150 
00151 int BC_MenuBar::keypress_event()
00152 {
00153         int result = 0;
00154         if(!top_level->active_subwindow || !top_level->active_subwindow->uses_text())
00155         {
00156                 for(int i = 0; i < menu_titles.total && !result; i++)
00157                 {
00158                         result = menu_titles.values[i]->dispatch_keypress();
00159                 }
00160         }
00161         return result;
00162 }
00163 
00164 int BC_MenuBar::cursor_motion_event()
00165 {
00166         int result = 0;
00167         for(int i = 0; i < menu_titles.total && !result; i++)
00168         {
00169                 result = menu_titles.values[i]->dispatch_motion_event();
00170         }
00171         return result;
00172 }
00173 
00174 int BC_MenuBar::cursor_leave_event()
00175 {
00176         for(int i = 0; i < menu_titles.total; i++)
00177         {
00178                 menu_titles.values[i]->dispatch_cursor_leave();
00179         }
00180         return 0;
00181 }
00182 
00183 int BC_MenuBar::cursor_enter_event()
00184 {
00185         if(active) return 1;
00186         return 0;
00187 }
00188 
00189 int BC_MenuBar::translation_event()
00190 {
00191         if(active)
00192         {
00193                 for(int i = 0; i < menu_titles.total; i++)
00194                 {
00195                         menu_titles.values[i]->dispatch_translation_event();
00196                 }
00197         }
00198         return 0;
00199 }
00200 
00201 int BC_MenuBar::activate()
00202 {
00203         top_level->deactivate();
00204         top_level->active_menubar = this;
00205         active = 1;
00206         return 0;
00207 }
00208 
00209 int BC_MenuBar::deactivate()
00210 {
00211         for(int i = 0; i < menu_titles.total; i++)
00212         {
00213                 menu_titles.values[i]->deactivate_menu();
00214         }
00215         top_level->active_menubar = 0;
00216         active = 0;
00217         return 0;
00218 }
00219 
00220 int BC_MenuBar::unhighlight()
00221 {
00222         for(int i = 0; i < menu_titles.total; i++)
00223         {
00224                 menu_titles.values[i]->unhighlight();
00225         }
00226         return 0;
00227 }
00228 
00229 int BC_MenuBar::draw_face()
00230 {
00231         if(menu_bar_bg)
00232         {
00233                 draw_9segment(0, 0, get_w(), get_h(), menu_bar_bg);
00234         }
00235         else
00236         {
00237                 int lx,ly,ux,uy;
00238                 int h, w;
00239                 h = get_h();
00240                 w = get_w();
00241                 h--; 
00242                 w--;
00243 
00244                 lx = 1;  ly = 1;
00245                 ux = w - 1;  uy = h - 1;
00246 
00247                 set_color(top_level->get_resources()->menu_light);
00248                 draw_line(0, 0, 0, uy);
00249                 draw_line(0, 0, ux, 0);
00250 
00251                 set_color(top_level->get_resources()->menu_shadow);
00252                 draw_line(ux, ly, ux, uy);
00253                 draw_line(lx, uy, ux, uy);
00254                 set_color(BLACK);
00255                 draw_line(w, 0, w, h);
00256                 draw_line(0, h, w, h);
00257         }
00258 
00259         flash();
00260         flush();
00261         return 0;
00262 }
00263 
00264 
00265 
00266 
00267 

Generated on Sun Jan 8 13:26:32 2006 for Guicast-svn by  doxygen 1.4.4