#include "bcsignals.h"
#include "bcwindowbase.h"
#include "bccolors.h"
+#include "cstrdup.h"
#include <string.h>
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);
alt_hotkey = 0;
ctrl_hotkey = 0;
menu_popup = 0;
+ enabled = 1;
}
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;
}
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)
return 0;
}
+int BC_MenuItem::get_enabled(int v)
+{
+ return enabled;
+}
+void BC_MenuItem::set_enabled(int v)
+{
+ enabled = v;
+}
+
+
int BC_MenuItem::activate_submenu()
{
int new_x, new_y;
&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;
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;
resources->menu_down,
resources->menu_light);
}
- offset = 1;
+ xoffset = xS(1); yoffset = yS(1);
}
else
// Highlighted
}
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;