tweak zoom/fullscr to remember cwdw scale after fullscr
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcmenuitem.C
index 2c4469e4cf6a9e0a90c6fb7c5ef54b0abd390453..6653b14f6c9265a6aa67922d255f738141a6f458 100644 (file)
@@ -29,6 +29,7 @@
 #include "bcsignals.h"
 #include "bcwindowbase.h"
 #include "bccolors.h"
+#include "cstrdup.h"
 
 #include <string.h>
 
@@ -44,6 +45,8 @@
 
 BC_MenuItem::BC_MenuItem(const char *text, const char *hotkey_text, int hotkey)
 {
+       this->text = 0;
+       this->hotkey_text = 0;
        reset();
 
        if(text) set_text(text);
@@ -74,10 +77,8 @@ BC_MenuItem::~BC_MenuItem()
 
 void BC_MenuItem::reset()
 {
-       text = new char[1];
-       hotkey_text = new char[1];
-       text[0] = 0;
-       hotkey_text[0] = 0;
+       set_text("");
+       set_hotkey_text("");
        icon = 0;
 }
 
@@ -112,16 +113,14 @@ BC_Pixmap* BC_MenuItem::get_icon()
 
 void BC_MenuItem::set_text(const char *text)
 {
-       if(this->text) delete [] this->text;
-       this->text = new char[strlen(text) + 1];
-       strcpy(this->text, text);
+       delete [] this->text;
+       this->text = cstrdup(text);
 }
 
 void BC_MenuItem::set_hotkey_text(const char *text)
 {
-       if(this->hotkey_text) delete [] this->hotkey_text;
-       this->hotkey_text = new char[strlen(text) + 1];
-       strcpy(this->hotkey_text, text);
+       delete [] this->hotkey_text;
+       this->hotkey_text = cstrdup(text);
 }
 
 int BC_MenuItem::deactivate_submenus(BC_MenuPopup *exclude)
@@ -151,7 +150,7 @@ int BC_MenuItem::activate_submenu()
                        &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);
+               submenu->activate_menu(new_x + xS(5), new_y, menu_popup->w - xS(10), h, 0, 0);
                highlighted = 1;
        }
        return 0;
@@ -312,13 +311,13 @@ int BC_MenuItem::draw()
        if(!strcmp(text, "-"))
        {
                menu_popup->get_popup()->set_color(DKGREY);
-               menu_popup->get_popup()->draw_line(5, y + h / 2, menu_popup->get_w() - 5, y + h / 2);
+               menu_popup->get_popup()->draw_line(xS(5), y + h / 2, menu_popup->get_w() - xS(5), y + h / 2);
                menu_popup->get_popup()->set_color(LTGREY);
-               menu_popup->get_popup()->draw_line(5, y + h / 2 + 1, menu_popup->get_w() - 5, y + h / 2 + 1);
+               menu_popup->get_popup()->draw_line(xS(5), y + h / 2 + 1, menu_popup->get_w() - xS(5), y + h / 2 + 1);
        }
        else
        {
-               int offset = 0;
+               int xoffset = 0, yoffset = 0;
                if(highlighted)
                {
                        int y = this->y;
@@ -352,7 +351,7 @@ int BC_MenuItem::draw()
                                                resources->menu_down,
                                                resources->menu_light);
                                }
-                               offset = 1;
+                               xoffset = xS(1);  yoffset = yS(1);
                        }
                        else
 // Highlighted
@@ -386,23 +385,23 @@ int BC_MenuItem::draw()
                  }
                if(checked)
                {
-//                     menu_popup->get_popup()->draw_check(10 + offset, y + 2 + offset);
+//                     menu_popup->get_popup()->draw_check(xS(10) + xoffset, y + 2 + yoffset);
                        menu_popup->get_popup()->draw_pixmap(menu_popup->check,
-                               offset,
-                               y + (this->h - menu_popup->check->get_h()) / 2 + offset);
+                               xoffset,
+                               y + (this->h - menu_popup->check->get_h()) / 2 + yoffset);
                        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() + xoffset,
+                               y + h - text_line - 2 + yoffset,
                                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() + xoffset,
+                               y + h - text_line - 2 + yoffset,
                                hotkey_text);
                }
                else
                {
                        menu_popup->get_popup()->set_font(MEDIUMFONT);
-                       menu_popup->get_popup()->draw_text(10 + 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, hotkey_text);
+                       menu_popup->get_popup()->draw_text(xS(10) + xoffset, y + h - text_line - 2 + yoffset, text);
+                       menu_popup->get_popup()->draw_text(menu_popup->get_key_x() + xoffset, y + h - text_line - 2 + yoffset, hotkey_text);
                }
        }
        return 0;