add binfolder path relative filters, fix gbrp color model, vwdw timebar tweaks, title...
[goodguy/history.git] / cinelerra-5.1 / guicast / bcmenuitem.C
index 66f869532b4ba1f8a7673659e2f698f2a278d49c..2c4469e4cf6a9e0a90c6fb7c5ef54b0abd390453 100644 (file)
@@ -28,7 +28,7 @@
 #include "bcresources.h"
 #include "bcsignals.h"
 #include "bcwindowbase.h"
-#include "colors.h"
+#include "bccolors.h"
 
 #include <string.h>
 
@@ -68,8 +68,8 @@ BC_MenuItem::~BC_MenuItem()
        hotkey_text = 0;
        if(submenu) delete submenu;
        submenu = 0;
-// deletes this
-       if(menu_popup) menu_popup->remove_item(this, 1);
+       if(menu_popup)
+               menu_popup->remove_item(this);
 }
 
 void BC_MenuItem::reset()
@@ -130,6 +130,7 @@ int BC_MenuItem::deactivate_submenus(BC_MenuPopup *exclude)
        {
                submenu->deactivate_submenus(exclude);
                submenu->deactivate_menu();
+               submenu->popup_menu = 0;
                highlighted = 0;
        }
        return 0;
@@ -149,6 +150,7 @@ int BC_MenuItem::activate_submenu()
                        &new_x,
                        &new_y,
                        &tempwin);
+               submenu->popup_menu = menu_popup->popup_menu;
                submenu->activate_menu(new_x + 5, new_y, menu_popup->w - 10, h, 0, 0);
                highlighted = 1;
        }
@@ -165,7 +167,7 @@ int BC_MenuItem::dispatch_button_press()
                result = submenu->dispatch_button_press();
        }
 
-       if(!result && top_level->event_win == menu_popup->get_popup()->win)
+       if(!result && menu_popup->get_popup()->is_event_win())
        {
                if(top_level->cursor_x >= 0 && top_level->cursor_x < menu_popup->get_w() &&
                        top_level->cursor_y >= y && top_level->cursor_y < y + h)
@@ -190,8 +192,6 @@ int BC_MenuItem::dispatch_button_press()
 int BC_MenuItem::dispatch_button_release(int &redraw)
 {
        int result = 0;
-       int cursor_x, cursor_y;
-       Window tempwin;
 
        if(!strcmp(text, "-")) return 0;
 
@@ -200,20 +200,11 @@ int BC_MenuItem::dispatch_button_release(int &redraw)
                result = submenu->dispatch_button_release();
        }
 
-       if(!result)
-       {
-               XTranslateCoordinates(top_level->display,
-                       top_level->event_win,
-                       menu_popup->get_popup()->win,
-                       top_level->cursor_x,
-                       top_level->cursor_y,
-                       &cursor_x,
-                       &cursor_y,
-                       &tempwin);
-
-               if(cursor_x >= 0 && cursor_x < menu_popup->get_w() &&
-                       cursor_y >= y && cursor_y < y + h)
-               {
+       if( !result && menu_popup->cursor_inside() ) {
+               int cursor_x, cursor_y;
+               menu_popup->get_popup()->get_relative_cursor(cursor_x, cursor_y);
+               if( cursor_x >= 0 && cursor_x < menu_popup->get_w() &&
+                       cursor_y >= y && cursor_y < y + h ) {
                        if(menu_bar)
                                menu_bar->deactivate();
                        else
@@ -233,40 +224,35 @@ int BC_MenuItem::dispatch_button_release(int &redraw)
 int BC_MenuItem::dispatch_motion_event(int &redraw)
 {
        int result = 0;
-       int cursor_x, cursor_y;
 
        if(submenu)
        {
                result = submenu->dispatch_motion_event();
        }
 
-       top_level->translate_coordinates(top_level->event_win,
-               menu_popup->get_popup()->win,
-               top_level->cursor_x,
-               top_level->cursor_y,
-               &cursor_x,
-               &cursor_y);
-
-       if(cursor_x >= 0 && cursor_x < menu_popup->get_w() &&
-               cursor_y >= y && cursor_y < y + h)
-       {
+       if( !result && menu_popup->cursor_inside() ) {
+               int cursor_x, cursor_y;
+               menu_popup->get_popup()->get_relative_cursor(cursor_x, cursor_y);
+               if( cursor_x >= 0 && cursor_x < menu_popup->get_w() &&
+                       cursor_y >= y && cursor_y < y + h) {
 // Highlight the item
-               if(!highlighted)
-               {
+                       if(!highlighted)
+                       {
 // Deactivate submenus in the parent menu excluding this one.
-                       menu_popup->deactivate_submenus(submenu);
-                       highlighted = 1;
-                       if(submenu) activate_submenu();
+                               menu_popup->deactivate_submenus(submenu);
+                               highlighted = 1;
+                               if(submenu) activate_submenu();
+                               redraw = 1;
+                       }
+                       result = 1;
+               }
+               else
+               if(highlighted)
+               {
+                       highlighted = 0;
+                       result = 1;
                        redraw = 1;
                }
-               result = 1;
-       }
-       else
-       if(highlighted)
-       {
-               highlighted = 0;
-               result = 1;
-               redraw = 1;
        }
        return result;
 }
@@ -286,7 +272,7 @@ int BC_MenuItem::dispatch_cursor_leave()
                result = submenu->dispatch_cursor_leave();
        }
 
-       if(!result && highlighted && top_level->event_win == menu_popup->get_popup()->win)
+       if(!result && highlighted && menu_popup->get_popup()->is_event_win())
        {
                highlighted = 0;
                return 1;
@@ -402,14 +388,14 @@ int BC_MenuItem::draw()
                {
 //                     menu_popup->get_popup()->draw_check(10 + offset, y + 2 + offset);
                        menu_popup->get_popup()->draw_pixmap(menu_popup->check,
-                               offset, 
+                               offset,
                                y + (this->h - menu_popup->check->get_h()) / 2 + offset);
                        menu_popup->get_popup()->set_font(MEDIUMFONT);
-                       menu_popup->get_popup()->draw_text(menu_popup->check->get_w() + offset, 
-                               y + h - text_line - 2 + offset, 
+                       menu_popup->get_popup()->draw_text(menu_popup->check->get_w() + offset,
+                               y + h - text_line - 2 + offset,
                                text);
-                       menu_popup->get_popup()->draw_text(menu_popup->get_key_x() + offset, 
-                               y + h - text_line - 2 + offset, 
+                       menu_popup->get_popup()->draw_text(menu_popup->get_key_x() + offset,
+                               y + h - text_line - 2 + offset,
                                hotkey_text);
                }
                else
@@ -430,6 +416,11 @@ int BC_MenuItem::add_submenu(BC_SubMenu *submenu)
        return 0;
 }
 
+BC_SubMenu* BC_MenuItem::get_submenu()
+{
+       return submenu;
+}
+
 char* BC_MenuItem::get_text()
 {
        return text;