Fixed a problem with popup-menus.

This commit is contained in:
David Capello 2008-01-06 19:30:17 +00:00
parent cbcc6953b4
commit 6fcea92d7b
7 changed files with 119 additions and 75 deletions

View File

@ -1,3 +1,8 @@
2008-01-06 David A. Capello <dacap@users.sourceforge.net>
* src/modules/rootmenu.c (load_menu_by_id): Added to fix a problem
with popup-menus of the new jmenu.c implementation.
2008-01-05 David A. Capello <dacap@users.sourceforge.net>
* src/commands/cmd_play_animation.c: Added.

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001-2005, 2007, 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -427,11 +427,10 @@ static bool layer_box_msg_proc(JWidget widget, JMessage msg)
if (state == STATE_MOVING) {
/* layer popup menu */
if (msg->mouse.right) {
JWidget popup_menuitem = get_layer_popup_menuitem();
JWidget popup_menu = get_layer_popup_menu();
if (popup_menuitem && jmenuitem_get_submenu(popup_menuitem)) {
jmenu_popup(jmenuitem_get_submenu (popup_menuitem),
msg->mouse.x, msg->mouse.y);
if (popup_menu) {
jmenu_popup(popup_menu, msg->mouse.x, msg->mouse.y);
jview_update(jwidget_get_view(layer_box->widget));
jview_update(jwidget_get_view(layer_box->cel_box->widget));
@ -704,12 +703,11 @@ static bool cel_box_msg_proc(JWidget widget, JMessage msg)
/* show the dialog to change the frlen (frame duration time)? */
else if (msg->mouse.right) {
jwidget_release_mouse(widget);
JWidget popup_menuitem = get_frame_popup_menuitem();
JWidget popup_menu = get_frame_popup_menu();
if (popup_menuitem && jmenuitem_get_submenu(popup_menuitem)) {
if (popup_menu) {
/* show the frame pop-up menu */
jmenu_popup(jmenuitem_get_submenu(popup_menuitem),
msg->mouse.x, msg->mouse.y);
jmenu_popup(popup_menu, msg->mouse.x, msg->mouse.y);
jview_update(jwidget_get_view(cel_box->widget));
jview_update(jwidget_get_view(cel_box->layer_box->widget));
@ -776,12 +774,11 @@ static bool cel_box_msg_proc(JWidget widget, JMessage msg)
set_cel_to_handle(cel_box->layer, cel_box->cel);
if (msg->mouse.right) {
JWidget popup_menuitem = get_cel_popup_menuitem();
JWidget popup_menu = get_cel_popup_menu();
if (popup_menuitem && jmenuitem_get_submenu(popup_menuitem)) {
if (popup_menu) {
/* show the cel pop-up menu */
jmenu_popup(jmenuitem_get_submenu(popup_menuitem),
msg->mouse.x, msg->mouse.y);
jmenu_popup(popup_menu, msg->mouse.x, msg->mouse.y);
destroy_thumbnails();

View File

@ -42,6 +42,7 @@
JM_MESSAGE(open_menuitem);
JM_MESSAGE(close_menuitem);
JM_MESSAGE(close_popup);
JM_MESSAGE(exe_menuitem);
/**
@ -54,6 +55,8 @@ JM_MESSAGE(exe_menuitem);
*/
#define JM_CLOSE_MENUITEM jm_close_menuitem()
#define JM_CLOSE_POPUP jm_close_popup()
#define JM_EXE_MENUITEM jm_exe_menuitem()
/**********************************************************************/
@ -136,6 +139,7 @@ static void unhighlight(JWidget menu);
static void open_menuitem(JWidget menuitem, bool select_first);
static void close_menuitem(JWidget menuitem, bool final_close);
static void close_popup(JWidget menubox);
static void close_all(JWidget menu);
static void exe_menuitem(JWidget menuitem);
@ -308,7 +312,7 @@ int jmenuitem_is_highlight(JWidget widget)
/* TODO complete this routine */
void jmenu_popup(JWidget menu, int x, int y)
{
JWidget window, menubox/* , selected */;
JWidget window, menubox;
Base *base;
do {
@ -320,7 +324,11 @@ void jmenu_popup(JWidget menu, int x, int y)
menubox = jmenubox_new();
base = create_base(menubox);
base->was_clicked = TRUE;
base->is_filtering = TRUE;
jmanager_add_msg_filter(JM_BUTTONPRESSED, menubox);
jwindow_moveable(window, FALSE); /* can't move the window */
@ -342,9 +350,6 @@ void jmenu_popup(JWidget menu, int x, int y)
/* open the window */
jwindow_open_fg(window);
/* selected menu item */
/* selected = base->selected_menuitem; */
/* free focus */
jmanager_free_focus();
@ -353,10 +358,6 @@ void jmenu_popup(JWidget menu, int x, int y)
/* destroy the window */
jwidget_free(window);
/* emit signal */
/* if (selected) */
/* exe_menuitem(selected); */
}
static bool menu_msg_proc(JWidget widget, JMessage msg)
@ -385,6 +386,7 @@ static bool menu_msg_proc(JWidget widget, JMessage msg)
case JM_SETPOS:
menu_set_position(widget, &msg->setpos.rect);
return TRUE;
}
return FALSE;
@ -751,6 +753,12 @@ static bool menubox_msg_proc(JWidget widget, JMessage msg)
}
break;
default:
if (msg->type == JM_CLOSE_POPUP) {
jwindow_close(jwidget_get_window(widget), NULL);
}
break;
}
return FALSE;
@ -1050,6 +1058,7 @@ static Base *create_base(JWidget widget)
base->was_clicked = FALSE;
base->is_filtering = FALSE;
base->is_processing = FALSE;
base->close_all = FALSE;
MBOX(widget)->base = base;
@ -1226,8 +1235,16 @@ static void close_menuitem(JWidget menuitem, bool final_close)
base->is_processing = TRUE;
}
static void close_popup(JWidget menubox)
{
JMessage msg = jmessage_new(JM_CLOSE_POPUP);
jmessage_add_dest(msg, menubox);
jmanager_enqueue_message(msg);
}
static void close_all(JWidget menu)
{
JWidget base_menubox = NULL;
JWidget menuitem = NULL;
JLink link;
Base *base;
@ -1238,14 +1255,14 @@ static void close_all(JWidget menu)
menuitem = MENU(menu)->menuitem;
menu = menuitem->parent;
}
base = get_base(menu->parent);
base_menubox = get_base_menubox(menu->parent);
base = MBOX(base_menubox)->base;
base->close_all = TRUE;
base->was_clicked = FALSE;
if (base->is_filtering) {
base->is_filtering = FALSE;
jmanager_remove_msg_filter(JM_BUTTONPRESSED,
get_base_menubox(menu->parent));
jmanager_remove_msg_filter(JM_BUTTONPRESSED, base_menubox);
}
unhighlight(menu);
@ -1265,6 +1282,11 @@ static void close_all(JWidget menu)
close_menuitem(menuitem, TRUE);
}
}
/* for popuped menus */
if (base_menubox->type == JI_MENUBOX) {
close_popup(base_menubox);
}
}
static void exe_menuitem(JWidget menuitem)

View File

@ -328,7 +328,7 @@ void update_screen_for_sprite(Sprite *sprite)
}
}
status_bar_set_text(app_get_status_bar(), 0, "");
status_bar_set_text(app_get_status_bar(), -1, "");
}
void gui_run(void)

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,11 +41,12 @@
static JWidget root_menu;
static JWidget recent_list_menuitem;
static JWidget layer_popup_menuitem;
static JWidget frame_popup_menuitem;
static JWidget cel_popup_menuitem;
static JWidget filters_popup_menuitem;
static JWidget layer_popup_menu;
static JWidget frame_popup_menu;
static JWidget cel_popup_menu;
static JWidget filters_popup_menu;
static JWidget load_menu_by_id(JXml xml, const char *id, const char *filename);
static JWidget convert_xmlelem_to_menu(JXmlElem elem);
static JWidget convert_xmlelem_to_menuitem(JXmlElem elem);
static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command *command);
@ -59,20 +61,24 @@ int init_module_rootmenu(void)
void exit_module_rootmenu(void)
{
recent_list_menuitem = NULL;
layer_popup_menuitem = NULL;
frame_popup_menuitem = NULL;
cel_popup_menuitem = NULL;
filters_popup_menuitem = NULL;
layer_popup_menu = NULL;
frame_popup_menu = NULL;
cel_popup_menu = NULL;
filters_popup_menu = NULL;
command_reset_keys();
jwidget_free(root_menu);
if (layer_popup_menu) jwidget_free(layer_popup_menu);
if (frame_popup_menu) jwidget_free(frame_popup_menu);
if (cel_popup_menu) jwidget_free(cel_popup_menu);
if (filters_popup_menu) jwidget_free(filters_popup_menu);
}
int load_root_menu(void)
{
JLink link, link2;
DIRS *dirs, *dir;
JXmlElem elem;
JXml xml;
if (app_get_menu_bar())
@ -87,10 +93,10 @@ int load_root_menu(void)
/* create a new empty-menu */
root_menu = NULL;
recent_list_menuitem = NULL;
layer_popup_menuitem = NULL;
frame_popup_menuitem = NULL;
cel_popup_menuitem = NULL;
filters_popup_menuitem = NULL;
layer_popup_menu = NULL;
frame_popup_menu = NULL;
cel_popup_menu = NULL;
filters_popup_menu = NULL;
dirs = filename_in_datadir("usergui.xml");
{
@ -110,27 +116,17 @@ int load_root_menu(void)
/* load menus */
PRINTF("Trying to menus from \"%s\"...\n", dir->path);
/* get the <menu> element with id="main_menu" */
elem = jxml_get_elem_by_id(xml, "main_menu");
if (elem) {
/* is it a <menu> element? */
if (strcmp(jxmlelem_get_name(elem), "menu") == 0) {
/* ok, convert it to a menu JWidget */
root_menu = convert_xmlelem_to_menu(elem);
if (!root_menu) {
PRINTF("Error loading main menu from \"%s\" file.\n", dir->path);
return -1;
}
}
else {
PRINTF("Invalid element with id=\"main_menu\" in \"%s\"\n", dir->path);
return -1;
}
}
else {
PRINTF("main_menu element couldn't be found...\n");
root_menu = load_menu_by_id(xml, "main_menu", dir->path);
if (!root_menu) {
PRINTF("Error loading \"main_menu\" from \"%s\" file.\n", dir->path);
return -1;
}
layer_popup_menu = load_menu_by_id(xml, "layer_popup", dir->path);
frame_popup_menu = load_menu_by_id(xml, "frame_popup", dir->path);
cel_popup_menu = load_menu_by_id(xml, "cel_popup", dir->path);
filters_popup_menu = load_menu_by_id(xml, "filters_popup", dir->path);
/**************************************************/
/* load keyboard shortcuts */
PRINTF("Trying to load keyboard shortcuts from \"%s\"...\n", dir->path);
@ -206,18 +202,40 @@ int load_root_menu(void)
JWidget get_root_menu(void) { return root_menu; }
JWidget get_recent_list_menuitem(void) { return recent_list_menuitem; }
JWidget get_layer_popup_menuitem(void) { return layer_popup_menuitem; }
JWidget get_frame_popup_menuitem(void) { return frame_popup_menuitem; }
JWidget get_cel_popup_menuitem(void) { return cel_popup_menuitem; }
JWidget get_layer_popup_menu(void) { return layer_popup_menu; }
JWidget get_frame_popup_menu(void) { return frame_popup_menu; }
JWidget get_cel_popup_menu(void) { return cel_popup_menu; }
void show_fx_popup_menu(void)
/* void show_fx_popup_menu(void) */
/* { */
/* if (is_interactive() && */
/* filters_popup_menuitem && */
/* jmenuitem_get_submenu(filters_popup_menuitem)) { */
/* jmenu_popup(jmenuitem_get_submenu(filters_popup_menuitem), */
/* jmouse_x(0), jmouse_y(0)); */
/* } */
/* } */
static JWidget load_menu_by_id(JXml xml, const char *id, const char *filename)
{
if (is_interactive() &&
filters_popup_menuitem &&
jmenuitem_get_submenu(filters_popup_menuitem)) {
jmenu_popup(jmenuitem_get_submenu(filters_popup_menuitem),
jmouse_x(0), jmouse_y(0));
JWidget menu = NULL;
JXmlElem elem;
/* get the <menu> element with the specified id */
elem = jxml_get_elem_by_id(xml, id);
if (elem) {
/* is it a <menu> element? */
if (strcmp(jxmlelem_get_name(elem), "menu") == 0) {
/* ok, convert it to a menu JWidget */
menu = convert_xmlelem_to_menu(elem);
}
else
PRINTF("Invalid element with id=\"main_menu\" in \"%s\"\n", filename);
}
else
PRINTF("\"main_menu\" element couldn't be found...\n");
return menu;
}
static JWidget convert_xmlelem_to_menu(JXmlElem elem)
@ -271,6 +289,7 @@ static JWidget convert_xmlelem_to_menuitem(JXmlElem elem)
if (strcmp(id, "recent_list") == 0) {
recent_list_menuitem = menuitem;
}
#if 0
/* layer popup menu */
else if (strcmp(id, "layer_popup") == 0) {
layer_popup_menuitem = menuitem;
@ -287,6 +306,7 @@ static JWidget convert_xmlelem_to_menuitem(JXmlElem elem)
else if (strcmp(id, "fx_popup") == 0) {
filters_popup_menuitem = menuitem;
}
#endif
}
/* has it a sub-menu? */

View File

@ -1,5 +1,6 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007 David A. Capello
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,11 +38,10 @@ int load_root_menu(void);
JWidget get_root_menu(void);
JWidget get_recent_list_menuitem(void);
JWidget get_layer_popup_menuitem(void);
JWidget get_frame_popup_menuitem(void);
JWidget get_cel_popup_menuitem(void);
JWidget get_layer_popup_menu(void);
JWidget get_frame_popup_menu(void);
JWidget get_cel_popup_menu(void);
/* int check_for_accel(int accel_type, JMessage msg); */
void show_fx_popup_menu(void);
/* void show_fx_popup_menu(void); */
#endif /* MODULES_ROOTMENU_H */

View File

@ -852,7 +852,7 @@ void editor_update_status_bar_for_standby(JWidget widget)
editor->sprite->h),
_("Frame"), editor->sprite->frame+1);
status_bar_update(app_get_status_bar());
/* status_bar_update(app_get_status_bar()); */
}
void editor_refresh_region(JWidget widget)