Aggiunto il megawonderful supporto menu a TWindow e conseguentemente a
TApplication git-svn-id: svn://10.65.10.50/trunk@1227 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
71f8628412
commit
7179711a44
@ -243,6 +243,19 @@ void TApplication::stop_run()
|
||||
}
|
||||
|
||||
|
||||
bool TApplication::add_menu(TString_array& menu, MENU_TAG id)
|
||||
{
|
||||
TTemp_window tw(TASK_WIN);
|
||||
return tw.add_menu(menu,id,TRUE);
|
||||
}
|
||||
|
||||
bool TApplication::remove_menu(MENU_TAG id)
|
||||
{
|
||||
TTemp_window tw(TASK_WIN);
|
||||
return tw.remove_menu(id);
|
||||
}
|
||||
|
||||
|
||||
TApplication::TApplication() : _printer(NULL), _savefirm(0), _create_ok(FALSE)
|
||||
, _bar(TASK_MENUBAR)
|
||||
{}
|
||||
|
@ -104,6 +104,10 @@ public:
|
||||
void begin_wait() { set_cursor(TRUE); } // Set CURSOR_WAIT
|
||||
void end_wait() { set_cursor(FALSE); } // Set CURSOR_ARROW
|
||||
|
||||
// Main window menu runtime interface
|
||||
bool add_menu(TString_array& menu, MENU_TAG id = 0);
|
||||
bool remove_menu(MENU_TAG id);
|
||||
|
||||
TApplication();
|
||||
virtual ~TApplication();
|
||||
};
|
||||
|
@ -10,6 +10,62 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
HIDDEN MENU_ITEM* find_menu_item(MENU_ITEM* menu, MENU_TAG id, bool ismbar)
|
||||
{
|
||||
MENU_ITEM* fnd = NULL;
|
||||
MENU_ITEM* mn = ismbar ? &menu[0] : &menu->child[0];
|
||||
|
||||
for (int m = 0; mn != NULL && mn->tag != 0; m++, mn=ismbar?&menu[m]:&menu->child[m])
|
||||
{
|
||||
fnd = mn->tag == id ? mn : find_menu_item(mn, id, FALSE);
|
||||
if (fnd != NULL) break;
|
||||
}
|
||||
|
||||
return fnd;
|
||||
}
|
||||
|
||||
HIDDEN bool remove_menu_item(MENU_ITEM* menu, MENU_TAG id, bool ismbar)
|
||||
{
|
||||
MENU_ITEM* mn = ismbar ? &menu[0] : &menu->child[0];
|
||||
|
||||
for (int m = 0; mn != NULL && mn->tag != 0; m++, mn=ismbar?&menu[m]:&menu->child[m])
|
||||
{
|
||||
if (mn->tag == id)
|
||||
{
|
||||
do {
|
||||
xvt_mem_rep((DATA_PTR)mn, (DATA_PTR)(mn+1), sizeof(MENU_ITEM), 1);
|
||||
mn++;
|
||||
}
|
||||
while (mn->tag != 0);
|
||||
return TRUE;
|
||||
}
|
||||
else if (remove_menu_item(mn, id, FALSE))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
HIDDEN void set_menu_item(MENU_ITEM& m, TToken_string& tt)
|
||||
{
|
||||
MENU_TAG tag = tt.get_int(0);
|
||||
TString flag = tt.items() <= 2 ? "": tt.get(2);
|
||||
char* text = NULL;
|
||||
if (strlen(tt.get(1)) > 0)
|
||||
{
|
||||
text = (char*)xvt_mem_alloc(strlen(tt.get(1)) + 1);
|
||||
strcpy(text, tt.get(1));
|
||||
}
|
||||
|
||||
m.tag = tag;
|
||||
m.text = text;
|
||||
m.enabled = !(flag.find('D') != -1);
|
||||
m.checkable = flag.find('C') != -1 || flag.find('c') != -1;
|
||||
m.checked = flag.find('c') != -1;
|
||||
m.separator = text == NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TWindow_manager
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -772,6 +828,62 @@ void TWindow::clear(COLOR color)
|
||||
void TWindow::set_mode(DRAW_MODE mode)
|
||||
{ xvt_dwin_set_draw_mode(win(), mode); }
|
||||
|
||||
|
||||
bool TWindow::add_menu(TString_array& menu, MENU_TAG id, bool force)
|
||||
{
|
||||
CHECK(menu.items() > 0, "TWindow::add_menu: no menus to add");
|
||||
|
||||
// get menu tree
|
||||
MENU_ITEM* menubar = xvt_menu_get_tree(win());
|
||||
|
||||
if (id == 0) // add to menubar
|
||||
{
|
||||
// count menus
|
||||
for (int nmen = 0; menubar[nmen].tag != 0; nmen++);
|
||||
menubar = (MENU_ITEM*)xvt_mem_realloc((DATA_PTR)menubar,
|
||||
sizeof(MENU_ITEM)*(nmen+menu.items()+1));
|
||||
// zero new
|
||||
xvt_mem_rep((DATA_PTR)&menubar[nmen], "\0", 1, sizeof(MENU_ITEM)*(menu.items()+1));
|
||||
|
||||
// add new menus
|
||||
for (int i = 0; i < menu.items(); i++)
|
||||
set_menu_item(menubar[nmen+i], menu.row(i));
|
||||
}
|
||||
else // add to menu
|
||||
{
|
||||
MENU_ITEM* father = find_menu_item(menubar, id, TRUE);
|
||||
CHECK(father != NULL, "TWindow::add_menu: you're adding to a NULL menu item");
|
||||
|
||||
// count children
|
||||
for (int nmen = 0; father->child != NULL && father->child[nmen].tag != 0; nmen++);
|
||||
father->child = (MENU_ITEM*)xvt_mem_realloc((DATA_PTR)father->child,
|
||||
sizeof(MENU_ITEM)*(nmen+menu.items()+1));
|
||||
// zero new
|
||||
xvt_mem_rep((DATA_PTR)&(father->child[nmen]), "\0", 1, sizeof(MENU_ITEM)*(menu.items()+1));
|
||||
|
||||
// add new menus
|
||||
for (int i = 0; i < menu.items(); i++)
|
||||
set_menu_item(father->child[nmen+i], menu.row(i));
|
||||
}
|
||||
|
||||
xvt_menu_set_tree(win(), menubar);
|
||||
xvt_res_free_menu_tree(menubar);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TWindow::remove_menu(MENU_TAG id)
|
||||
{
|
||||
MENU_ITEM* menubar = xvt_menu_get_tree(win());
|
||||
if (remove_menu_item(menubar, id, TRUE))
|
||||
{
|
||||
xvt_menu_set_tree(win(),menubar);
|
||||
xvt_res_free_menu_tree(menubar);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TTemp_window
|
||||
///////////////////////////////////////////////////////////
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <xvtility.h>
|
||||
#endif
|
||||
|
||||
class TString_array;
|
||||
|
||||
void close_all_dialogs();
|
||||
bool can_close();
|
||||
WINDOW cur_win();
|
||||
@ -195,6 +197,10 @@ public:
|
||||
|
||||
void line(short x0, short y0, short x1, short y1); // Disegna una linea nella finestra
|
||||
void icon(short x0, short y0, int iconid = -1);
|
||||
|
||||
// menu runtime interface
|
||||
bool add_menu(TString_array& menu, MENU_TAG id = 0, bool force = TRUE);
|
||||
bool remove_menu(MENU_TAG id);
|
||||
};
|
||||
|
||||
class TTemp_window : public TWindow
|
||||
|
Loading…
x
Reference in New Issue
Block a user