Nuovo campo di ricerca semi-intelligente dei menu
git-svn-id: svn://10.65.10.50/trunk@350 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
17b72d9cdb
commit
bb4dd09abb
74
ba/ba0.cpp
74
ba/ba0.cpp
@ -110,15 +110,22 @@ protected:
|
||||
void test_temp() const;
|
||||
void load_menu();
|
||||
int do_level();
|
||||
int find_menu(const char* s) const;
|
||||
virtual bool create();
|
||||
virtual bool menu(MENU_TAG m);
|
||||
|
||||
static bool menu_item_handler(TMask_field&f, KEY k);
|
||||
static bool menu_find_handler(TMask_field&f, KEY k);
|
||||
|
||||
public:
|
||||
TMenu_application(const char* name) : _name(name) {}
|
||||
};
|
||||
|
||||
|
||||
static short last_button = 0;
|
||||
static bool find_button = FALSE;
|
||||
|
||||
inline TMenu_application& app()
|
||||
{ return (TMenu_application&)main_app(); }
|
||||
|
||||
void TMenu_application::load_menu()
|
||||
{
|
||||
@ -150,18 +157,60 @@ void TMenu_application::load_menu()
|
||||
_first[++_max] = _menu.items();
|
||||
}
|
||||
|
||||
int TMenu_application::find_menu(const char* s) const
|
||||
{
|
||||
TString80 str(s); str.upper();
|
||||
int found = -1;
|
||||
|
||||
for (int i = 0; i < _menu.items(); i++)
|
||||
{
|
||||
TToken_string& l = (TToken_string&)_menu[i];
|
||||
const int m = l.get_int(0);
|
||||
if (m != _level)
|
||||
{
|
||||
TString80 v(l.get()); v.upper();
|
||||
if (v.find(str) >= 0)
|
||||
{
|
||||
found = m;
|
||||
if (isalpha(l.get_char())) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
HIDDEN bool menu_item_handler(TMask_field&f, KEY k)
|
||||
bool TMenu_application::menu_item_handler(TMask_field&f, KEY k)
|
||||
{
|
||||
if (k == K_SPACE)
|
||||
{
|
||||
last_button = f.dlg();
|
||||
find_button = FALSE;
|
||||
f.mask().stop_run(K_AUTO_ENTER);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool TMenu_application::menu_find_handler(TMask_field&f, KEY k)
|
||||
{
|
||||
if (k == K_TAB && f.focusdirty())
|
||||
{
|
||||
const TString& v = f.get();
|
||||
if (v.not_empty())
|
||||
{
|
||||
last_button = app().find_menu(v);
|
||||
if (last_button >= 0)
|
||||
{
|
||||
find_button = TRUE;
|
||||
f.mask().stop_run(K_AUTO_ENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int TMenu_application::do_level()
|
||||
{
|
||||
const int first = _first[_level];
|
||||
@ -170,11 +219,11 @@ int TMenu_application::do_level()
|
||||
const TString80 head(row.get(1));
|
||||
|
||||
const int width = 72;
|
||||
const int heigth = 18;
|
||||
const int height = 18;
|
||||
const int bwidth = 20;
|
||||
const int x = width-bwidth-12;
|
||||
const short pic = BA0_PICTURE+(short)row.get_int();
|
||||
TPicture_mask menu(head, width, heigth, pic);
|
||||
TPicture_mask menu(head, width, height, pic);
|
||||
|
||||
int y = 1;
|
||||
|
||||
@ -193,11 +242,13 @@ int TMenu_application::do_level()
|
||||
menu.add_button(100+y, 0, t, x, y, 1, 1);
|
||||
menu.set_handler(100+y, menu_item_handler);
|
||||
}
|
||||
menu.add_string(99, 0, "Cerca ", 1,-3, 32);
|
||||
menu.set_handler(99, menu_find_handler);
|
||||
|
||||
t = first ? "Menu precedente" : "Fine";
|
||||
menu.add_button(first ? DLG_CANCEL : DLG_QUIT, 0, t, -22, -2, bwidth, 2);
|
||||
menu.add_button(first ? DLG_CANCEL : DLG_QUIT, 0, t, -22, -1, bwidth, 2);
|
||||
if (first)
|
||||
menu.add_button(DLG_QUIT, 0, "Fine", -12, -2, bwidth, 2);
|
||||
menu.add_button(DLG_QUIT, 0, "Fine", -12, -1, bwidth, 2);
|
||||
|
||||
const int k = menu.run();
|
||||
int m = 0;
|
||||
@ -209,7 +260,11 @@ int TMenu_application::do_level()
|
||||
menu.reset();
|
||||
m = -2; break;
|
||||
default:
|
||||
m = first+last_button-100; break;
|
||||
if (find_button)
|
||||
m = -1;
|
||||
else
|
||||
m = first+last_button-100;
|
||||
break;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
@ -279,7 +334,10 @@ bool TMenu_application::menu(MENU_TAG)
|
||||
else
|
||||
{
|
||||
if (m < -1) break;
|
||||
_level = (--i >= 0) ? refarray[i] : 0;
|
||||
if (find_button)
|
||||
_level = last_button;
|
||||
else
|
||||
_level = (--i >= 0) ? refarray[i] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user