Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

htmenu.cc

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      htmenu.cc
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "htapp.h"              // for queuemsg
00022 #include "htctrl.h"
00023 #include "htkeyb.h"
00024 #include "htmenu.h"
00025 #include "htpal.h"
00026 #include "htreg.h"
00027 #include "htstring.h"
00028 #include "stream.h"
00029 #include "tools.h"
00030 
00031 #include <string.h>
00032 
00033 #define button_left             100
00034 #define button_right    101
00035 
00036 char *shortcut_str(char *str)
00037 {
00038         while (*str) {
00039                 if (*str=='~') {
00040                         memmove(str, str+1, strlen(str));
00041                         return str;
00042                 }
00043                 str++;
00044         }
00045         return NULL;
00046 }
00047 
00048 bool execute_submenu(int x, int y, ht_context_menu *m)
00049 {
00050         int curentry=0;
00051         bool term=false;
00052         bounds scr;
00053         app->getbounds(&scr);
00054         do {
00055                 bounds b;
00056                 b.x=x+m->xpos-1;
00057                 b.y=y;
00058                 b.w=m->width+4;
00059                 b.h=m->count()+2;
00060                 if (b.y+b.h > scr.h) {
00061                         if (scr.h > b.h) {
00062                                 b.y = scr.h - b.h;
00063                                 if (b.y >= 2) b.y -= 2;
00064                         } else {
00065                                 b.y = 0;
00066                         }
00067                 }
00068                 ht_menu_window *d = new ht_menu_window();
00069                 d->init(&b, m);
00070                 ht_menu_window_data a;
00071                 a.selected = curentry;
00072                 d->databuf_set(&a, sizeof a);
00073                 b.x = 0;
00074                 b.y = 0;
00075                 ht_frame *frame = new ht_menu_frame();
00076                 frame->init(&b, 0, FS_MOVE/*just for fun*/);
00077                 d->setframe(frame);
00078                 d->setpalette(palkey_generic_menu_default);
00079                 int r=d->run(false);
00080                 d->done();
00081                 delete d;
00082                 switch (r) {
00083                         case button_ok: {
00084                                 return true;
00085                         }
00086                         default:
00087                                 term=true;
00088                 }
00089         } while (!term);
00090         return false;
00091 }
00092 
00093 /*
00094  *      CLASS ht_context_menu
00095  */
00096 
00097 void ht_context_menu::init(char *Name)
00098 {
00099         Object::init();
00100         name = ht_strdup(Name);
00101         shortcut = shortcut_str(name);
00102         width = 0;
00103 }
00104 
00105 void ht_context_menu::done()
00106 {
00107         free(name);
00108         Object::done();
00109 }
00110 
00111 int ht_context_menu::count()
00112 {
00113         return 0;
00114 }
00115 
00116 ht_context_menu_entry *ht_context_menu::enum_entry_first()
00117 {
00118         return NULL;
00119 }
00120 
00121 ht_context_menu_entry *ht_context_menu::enum_entry_next()
00122 {
00123         return NULL;
00124 }
00125 
00126 ht_context_menu_entry *ht_context_menu::get_entry(int n)
00127 {
00128         ht_context_menu_entry *e=enum_entry_first();
00129         while (n--) {
00130                 if (!e) break;
00131                 e=enum_entry_next();
00132         }
00133         return e;
00134 }
00135 
00136 char *ht_context_menu::get_name()
00137 {
00138         return name;
00139 }
00140 
00141 char *ht_context_menu::get_shortcut()
00142 {
00143         return shortcut;
00144 }
00145 
00146 /*
00147  *      CLASS ht_static_context_menu
00148  */
00149 
00150 void ht_static_context_menu::init(char *name)
00151 {
00152         ht_context_menu::init(name);
00153         context_menu_entry=new ht_clist();
00154         ((ht_clist*)context_menu_entry)->init();
00155 }
00156 
00157 void ht_static_context_menu::done()
00158 {
00159         context_menu_entry->destroy();
00160         delete context_menu_entry;
00161         ht_context_menu::done();
00162 }
00163 
00164 int ht_static_context_menu::count()
00165 {
00166         return context_menu_entry->count();
00167 }
00168 
00169 ht_context_menu_entry *ht_static_context_menu::enum_entry_first()
00170 {
00171         enum_idx=0;
00172         ht_context_menu_entry *e=(ht_context_menu_entry*)context_menu_entry->get(enum_idx);
00173         return e;
00174 }
00175 
00176 ht_context_menu_entry *ht_static_context_menu::enum_entry_next()
00177 {
00178         enum_idx++;
00179         ht_context_menu_entry *e=(ht_context_menu_entry*)context_menu_entry->get(enum_idx);
00180         return e;
00181 }
00182 
00183 void ht_static_context_menu::insert_entry(char *Name, char *Comment, int cmd, int k, bool a)
00184 {
00185         char *name=ht_strdup(Name), *comment, *shortcut=NULL;
00186         if (Comment) comment = ht_strdup(Comment); else comment = NULL;
00187         shortcut = shortcut_str(name);
00188         int l=strlen(name), cl=comment ? strlen(comment)+2 : 0;
00189         width=MAX(width, l+cl);
00190         ht_context_menu_entry *e = new ht_context_menu_entry();
00191         e->type = CME_ENTRY;
00192         e->entry.name = name;
00193         e->entry.shortcut = shortcut;
00194         e->entry.comment = comment;
00195         e->entry.command = cmd;
00196         e->entry.key = k;
00197         e->entry.active = a;
00198         context_menu_entry->insert(e);
00199 }
00200 
00201 void ht_static_context_menu::insert_separator()
00202 {
00203         ht_context_menu_entry *entry=new ht_context_menu_entry();
00204         entry->type = CME_SEPARATOR;
00205         context_menu_entry->insert(entry);
00206 }
00207 
00208 void ht_static_context_menu::insert_submenu(ht_context_menu *submenu)
00209 {
00210         ht_context_menu_entry *entry=new ht_context_menu_entry();
00211         entry->type = CME_SUBMENU;
00212         entry->submenu = submenu;
00213         submenu->xpos = 0;
00214         context_menu_entry->insert(entry);
00215 }
00216 
00217 /*
00218  *      CLASS ht_context_menu_entry
00219  */
00220 
00221 ht_context_menu_entry::~ht_context_menu_entry()
00222 {
00223         switch (type) {
00224                 case CME_ENTRY:
00225                         if (entry.name) free(entry.name);
00226                         if (entry.comment) free(entry.comment);
00227                         break;
00228                 case CME_SUBMENU:
00229                         submenu->done();
00230                         delete submenu;
00231                         break;
00232         }
00233 }
00234 
00235 /*
00236  *      CLASS ht_menu
00237  */
00238 
00239 void ht_menu::init(bounds *b)
00240 {
00241         ht_view::init(b, VO_OWNBUFFER | VO_POSTPROCESS, "menu");
00242         VIEW_DEBUG_NAME("ht_menu");
00243 
00244         menu=new ht_clist();
00245         ((ht_clist*)menu)->init();
00246         lastmenux = 1;
00247         curmenu = -1;
00248         localmenu = -1;
00249         context_menu_hack = NULL;
00250         last_context_menu_hack = NULL;
00251         context_menu_hack2 = false;
00252 }
00253 
00254 void ht_menu::done()
00255 {
00256         menu->destroy();
00257         delete menu;
00258         ht_view::done();
00259 }
00260 
00261 char *ht_menu::defaultpalette()
00262 {
00263         return palkey_generic_menu_default;
00264 }
00265 
00266 char *ht_menu::defaultpaletteclass()
00267 {
00268         return palclasskey_generic;
00269 }
00270 
00271 ht_context_menu *ht_menu::get_context_menu(int i)
00272 {
00273         ht_context_menu *q = (ht_context_menu*)menu->get(i);
00274         if (context_menu_hack && (i == localmenu) && !q) return context_menu_hack;
00275         return q;
00276 }
00277 
00278 void ht_menu::draw()
00279 {
00280         clear(getcolor(palidx_generic_body));
00281         int c = count();
00282         for (int i=0; i<c; i++) {
00283                 ht_context_menu *c = get_context_menu(i);
00284                 char *n = c->get_name();
00285                 char *s = c->get_shortcut();
00286                 if (i==curmenu) {
00287                         buf_printchar(c->xpos-1, 0, getcolor(palidx_generic_text_selected), ' ');
00288                         buf_print(c->xpos, 0, getcolor(palidx_generic_text_selected), n);
00289                         buf_printchar(c->xpos+strlen(n), 0, getcolor(palidx_generic_text_selected), ' ');
00290                         if (s) buf_printchar(c->xpos+(s - n), 0, getcolor(palidx_generic_text_shortcut_selected), *s);
00291                 } else {
00292                         buf_print(c->xpos, 0, getcolor(palidx_generic_text_focused), n);
00293                         if (s) buf_printchar(c->xpos+(s - n), 0, getcolor(palidx_generic_text_shortcut), *s);
00294                 }
00295         }
00296 }
00297 
00298 void ht_menu::execute_menu(int i)
00299 {
00300         curmenu=i;
00301         int curentry=0;
00302         bool term=false;
00303         dirtyview();
00304         do {
00305                 ht_context_menu *m = get_context_menu(curmenu);
00306                 bounds b;
00307                 b.x=m->xpos-1;
00308                 b.y=1;
00309                 b.w=m->width+4;
00310                 b.h=m->count()+2;
00311                 ht_menu_window *d=new ht_menu_window();
00312                 d->init(&b, m);
00313                 ht_menu_window_data a;
00314                 a.selected = curentry;
00315                 d->databuf_set(&a, sizeof a);
00316                 b.x=0;
00317                 b.y=0;
00318                 ht_frame *frame=new ht_menu_frame();
00319                 frame->init(&b, 0, FS_MOVE);    // just for fun
00320                 d->setframe(frame);
00321                 d->setpalette(palkey_generic_menu_default);
00322                 int r=d->run(false);
00323                 switch (r) {
00324                         case button_left:
00325                                 curmenu--;
00326                                 if (curmenu<0) curmenu = count()-1;
00327                                 curentry=0;
00328                                 dirtyview();
00329                                 break;
00330                         case button_right:
00331                                 curmenu++;
00332                                 if (curmenu>(int)count()-1) curmenu=0;
00333                                 curentry=0;
00334                                 dirtyview();
00335                                 break;
00336                         case button_ok: {
00337 //                      return true;
00338                         }
00339                         default:
00340                                 term=true;
00341                 }
00342                 d->done();
00343                 delete d;
00344         } while (!term);
00345         curmenu=-1;
00346         dirtyview();
00347 }
00348 
00349 void ht_menu::handlemsg(htmsg *msg)
00350 {
00351         if (msg->type==mt_postprocess) {
00352                 if (msg->msg==msg_keypressed) {
00353 /* shortcuts */
00354                         ht_key k=ht_unmetakey((ht_key)msg->data1.integer);
00355                         if (k!=K_INVALID) {
00356                                 int c=count();
00357                                 for (int i=0; i<c; i++) {
00358                                         ht_context_menu *m = get_context_menu(i);
00359                                         int s = *m->get_shortcut();
00360                                         if ((s>='A') && (s<='Z')) s+='a'-'A';
00361                                         if (s==k) {
00362                                                 if (last_context_menu_hack) {
00363                                                         last_context_menu_hack->done();
00364                                                         delete last_context_menu_hack;
00365                                                         last_context_menu_hack = NULL;
00366                                                 }
00367                                                 if (localmenu != -1) {
00368                                                         context_menu_hack = (ht_context_menu*)menu->get(localmenu);
00369                                                         last_context_menu_hack = NULL;
00370                                                         if (context_menu_hack) {
00371                                                                 menu->remove(localmenu);
00372                                                         }
00373                                                 }
00374                                                 context_menu_hack2 = true;
00375                                                 execute_menu(i);
00376                                                 context_menu_hack2 = false;
00377                                                 if (context_menu_hack) {
00378                                                         context_menu_hack->done();
00379                                                         delete context_menu_hack;
00380                                                         context_menu_hack = NULL;
00381                                                 }
00382                                                 if (last_context_menu_hack) {
00383                                                         set_local_menu(last_context_menu_hack);
00384                                                         last_context_menu_hack = NULL;
00385                                                 } else {
00386                                                         delete_local_menu();
00387                                                 }
00388                                                 clearmsg(msg);
00389                                                 return;
00390                                         }
00391                                 }
00392                         }
00393 /* keys associated with menu entries */
00394                         int c = count();
00395                         for (int i=0; i<c; i++) {
00396                                 ht_context_menu *a = get_context_menu(i);
00397                                 if (handle_key_context_menu(a, msg->data1.integer)) {
00398                                         clearmsg(msg);
00399                                         return;
00400                                 }
00401                         }
00402                 }
00403         }
00404         ht_view::handlemsg(msg);
00405 }
00406 
00407 bool ht_menu::handle_key_context_menu(ht_context_menu *a, int k)
00408 {
00409         int t=a->count();
00410         ht_context_menu_entry *e=a->enum_entry_first();
00411         for (int j=0; j<t; j++) {
00412                 if ((e->type == CME_ENTRY) && (e->entry.name)
00413                 && (e->entry.key) && (k == e->entry.key)) {
00414                         htmsg m;
00415                         m.msg = e->entry.command;
00416                         m.type = mt_empty;
00417                         ((ht_app*)app)->queuemsg(app, &m);
00418                         return true;
00419                 } else if (e->type == CME_SUBMENU) {
00420                         if (handle_key_context_menu(e->submenu, k)) return true;
00421                 }
00422                 e=a->enum_entry_next();
00423         }
00424         return false;
00425 }
00426 
00427 int ht_menu::count()
00428 {
00429         ht_context_menu *q = (ht_context_menu*)menu->get(localmenu);
00430         if (context_menu_hack) return menu->count() + (((localmenu != -1) && !q) 
00431                 ? 1 : 0);
00432         return menu->count();
00433 }
00434 
00435 void ht_menu::delete_local_menu()
00436 {
00437         if (localmenu != -1) {
00438 /*              if (last_context_menu_hack) {
00439                         last_context_menu_hack = false;
00440                         if (last_context_menu) {
00441                                 last_context_menu->done();
00442                                 delete last_context_menu;
00443                                 last_context_menu = NULL;
00444                         }
00445                         return;*/
00446 /*                      ht_context_menu *q = (ht_context_menu*)menu->get(localmenu);
00447                         if (q && (q == last_context_menu)) menu->remove(localmenu);
00448                         return;*/
00449 //              }
00450                 if (context_menu_hack2 && last_context_menu_hack) {
00451                         last_context_menu_hack->done();
00452                         delete last_context_menu_hack;
00453                         last_context_menu_hack = NULL;
00454                 }
00455                 menu->del(localmenu);
00456         }               
00457 }
00458 
00459 void ht_menu::insert_local_menu()
00460 {
00461         localmenu = menu->count();
00462 }
00463 
00464 void ht_menu::insert_menu(ht_context_menu *m)
00465 {
00466         int namelen = strlen(m->get_name());
00467 
00468         m->xpos = lastmenux;
00469         menu->insert(m);
00470 
00471         lastmenux += namelen+1;
00472 }
00473 
00474 bool ht_menu::set_local_menu(ht_context_menu *m)
00475 {
00476         if (localmenu == -1) return false;
00477         if (context_menu_hack2) {
00478                 if (last_context_menu_hack) {
00479                         last_context_menu_hack->done();
00480                         delete last_context_menu_hack;
00481                         last_context_menu_hack = NULL;
00482                 }
00483                 last_context_menu_hack = m;
00484         } else {
00485                 int namelen = strlen(m->get_name());
00486 
00487                 ht_context_menu *p = (ht_context_menu*)menu->get(localmenu-1);
00488                 if (p) lastmenux = p->xpos + strlen(p->get_name())+1; else
00489                         lastmenux = 1;
00490 
00491                 m->xpos = lastmenux;
00492 
00493                 menu->set(localmenu, m);
00494 
00495                 lastmenux += namelen+1;
00496         }
00497         return true;
00498 }
00499 
00500 /*
00501  *      CLASS ht_menu_frame
00502  */
00503 
00504 void ht_menu_frame::init(bounds *b, char *desc, UINT style, UINT number)
00505 {
00506         ht_frame::init(b, desc, style, number);
00507         VIEW_DEBUG_NAME("ht_menu_frame");
00508 }
00509 
00510 void ht_menu_frame::done()
00511 {
00512         ht_frame::done();
00513 }
00514 
00515 char *ht_menu_frame::defaultpalette()
00516 {
00517         return palkey_generic_menu_default;
00518 }
00519 
00520 char *ht_menu_frame::defaultpaletteclass()
00521 {
00522         return palclasskey_generic;
00523 }
00524 
00525 int ht_menu_frame::getcurcol_normal()
00526 {
00527         return ht_frame::getcurcol_normal();
00528 }
00529 
00530 int ht_menu_frame::getcurcol_killer()
00531 {
00532         return 0;
00533 }
00534 
00535 /*
00536  *      CLASS ht_context_menu_window_body
00537  */
00538 
00539 void ht_context_menu_window_body::init(bounds *b, ht_context_menu *Menu)
00540 {
00541         ht_view::init(b, VO_OWNBUFFER | VO_SELECTABLE, 0);
00542         VIEW_DEBUG_NAME("ht_context_menu_window_body");
00543         context_menu = Menu;
00544         selected = next_selectable(-1);
00545 }
00546 
00547 void ht_context_menu_window_body::done()
00548 {
00549         ht_view::done();
00550 }
00551 
00552 char *ht_context_menu_window_body::defaultpalette()
00553 {
00554         return palkey_generic_menu_default;
00555 }
00556 
00557 char *ht_context_menu_window_body::defaultpaletteclass()
00558 {
00559         return palclasskey_generic;
00560 }
00561 
00562 void ht_context_menu_window_body::draw()
00563 {
00564         clear(getcolor(palidx_generic_body));
00565         int c=context_menu->count();
00566         if (c>size.h) c=size.h;
00567         ht_context_menu_entry *e=context_menu->enum_entry_first();
00568         for (int i=0; i<c; i++) {
00569                 switch (e->type) {
00570                         case CME_ENTRY: if (i==selected) {
00571                                 if (e->entry.active) {
00572                                         vcp c = getcolor(palidx_generic_text_selected);
00573                                         fill(0, i, size.w, 1, c, ' ');
00574                                         buf_lprint(1, i, c, size.w, e->entry.name);
00575                                         if (e->entry.comment) buf_lprint(size.w-1-strlen(e->entry.comment), i, c, size.w, e->entry.comment);
00576                                         if (e->entry.shortcut) buf_printchar(e->entry.shortcut-e->entry.name+1, i, getcolor(palidx_generic_text_shortcut_selected), *e->entry.shortcut);
00577                                 } else {
00578                                         vcp c = getcolor(palidx_generic_text_disabled);
00579                                         fill(0, i, size.w, 1, c, ' ');
00580                                         buf_lprint(1, i, c, size.w, e->entry.name);
00581                                         if (e->entry.comment) buf_lprint(size.w-1-strlen(e->entry.comment), i, c, size.w, e->entry.comment);
00582                                 }
00583                         } else {
00584                                 if (e->entry.active) {
00585                                         vcp c = getcolor(palidx_generic_text_focused);
00586                                         buf_lprint(1, i, c, size.w, e->entry.name);
00587                                         if (e->entry.comment) buf_lprint(size.w-1-strlen(e->entry.comment), i, c, size.w, e->entry.comment);
00588                                         if (e->entry.shortcut) buf_printchar(e->entry.shortcut-e->entry.name+1, i, getcolor(palidx_generic_text_shortcut), *e->entry.shortcut);
00589                                 } else {
00590                                         vcp c = getcolor(palidx_generic_text_disabled);
00591                                         buf_lprint(1, i, c, size.w, e->entry.name);
00592                                         if (e->entry.comment) buf_lprint(size.w-1-strlen(e->entry.comment), i, c, size.w, e->entry.comment);
00593                                 }
00594                         }
00595                         break;
00596                         case CME_SEPARATOR:
00597                                 fill(0, i, size.w, 1, getcolor(palidx_generic_text_focused), CHAR_LINEH);
00598                                 break;
00599                         case CME_SUBMENU: {
00600                                 char *n = e->submenu->get_name();
00601                                 char *s = e->submenu->get_shortcut();
00602                                 vcp c;
00603                                 if (i == selected) {
00604                                         c = getcolor(palidx_generic_text_selected);
00605                                 } else {
00606                                         c = getcolor(palidx_generic_text_focused);
00607                                 }
00608                                 fill(0, i, size.w, 1, c, ' ');
00609                                 buf_lprint(1, i, c, size.w, n);
00610                                 if (s) buf_printchar(n-s+1, i, getcolor(palidx_generic_text_shortcut), *s);
00611                                 buf_printchar(size.w-2, i, c, CHAR_ARROWBIG_RIGHT);
00612                                 break;
00613                         }
00614                 }
00615                 e=context_menu->enum_entry_next();
00616         }
00617 }
00618 
00619 void ht_context_menu_window_body::handlemsg(htmsg *msg)
00620 {
00621         if (msg->msg==msg_keypressed) {
00622                 switch (msg->data1.integer) {
00623                         case K_Up:
00624                                 selected=prev_selectable(selected);
00625                                 dirtyview();
00626                                 clearmsg(msg);
00627                                 return;
00628                         case K_Down:
00629                                 selected=next_selectable(selected);
00630                                 dirtyview();
00631                                 clearmsg(msg);
00632                                 return;
00633                         case K_Control_PageUp:
00634                         case K_PageUp:
00635                         case K_Home:
00636                                 selected=next_selectable(-1);
00637                                 dirtyview();
00638                                 clearmsg(msg);
00639                                 return;
00640                         case K_Control_PageDown:
00641                         case K_PageDown:
00642                         case K_End:
00643                                 selected=prev_selectable(0);
00644                                 dirtyview();
00645                                 clearmsg(msg);
00646                                 return;
00647                 }
00648 /* shortcuts */
00649                 int k=msg->data1.integer;
00650 //              int k=htalt2key(msg->data_int);
00651 //              if (k!=-1) {
00652                         int c=context_menu->count();
00653                         ht_context_menu_entry *e=context_menu->enum_entry_first();
00654                         for (int i=0; i<c; i++) {
00655                                 char *shortcut = NULL;
00656                                 if ((e->type == CME_ENTRY) && (e->entry.shortcut)) {
00657                                         shortcut = e->entry.shortcut;
00658                                 } else if ((e->type == CME_SUBMENU) && (e->submenu->get_shortcut())) {
00659                                         shortcut = e->submenu->get_shortcut();
00660                                 }
00661                                 if (shortcut) {
00662                                         int s = *shortcut;
00663                                         if ((s>='A') && (s<='Z')) s+='a'-'A';
00664                                         if (s==k) {
00665                                                 selected=i;
00666                                                 ((ht_dialog*)group->group)->sendmsg(msg_button_pressed, button_ok);
00667                                                 dirtyview();
00668                                                 clearmsg(msg);
00669                                                 return;
00670                                         }
00671                                 }                                       
00672                                 e = context_menu->enum_entry_next();
00673                         }
00674 //              }
00675         }
00676         ht_view::handlemsg(msg);
00677 }
00678 
00679 int ht_context_menu_window_body::next_selectable(int to)
00680 {
00681         int s=to+1;
00682         int c=context_menu->count();
00683         if (s>c-1) s=0;
00684         while (s!=to) {
00685                 ht_context_menu_entry *e=context_menu->get_entry(s);
00686                 if ((e->type == CME_ENTRY) || (e->type == CME_SUBMENU)) return s;
00687                 s++;
00688                 if (s>c-1) s=0;
00689         }
00690         return to;
00691 }
00692 
00693 int ht_context_menu_window_body::prev_selectable(int to)
00694 {
00695         int s=to-1;
00696         int c=context_menu->count();
00697         if (s<0) s=c-1;
00698         while (s!=to) {
00699                 ht_context_menu_entry *e=context_menu->get_entry(s);
00700                 if ((e->type == CME_ENTRY) || (e->type == CME_SUBMENU)) return s;
00701                 s--;
00702                 if (s<0) s=c-1;
00703         }
00704         return to;
00705 }
00706 
00707 void ht_context_menu_window_body::getdata(ht_object_stream *s)
00708 {
00709         s->putIntDec(selected, 4, NULL);
00710 }
00711 
00712 void ht_context_menu_window_body::setdata(ht_object_stream *s)
00713 {
00714         selected=s->getIntDec(4, NULL);
00715 }
00716 
00717 /*
00718  *      CLASS ht_menu_window
00719  */
00720 
00721 void ht_menu_window::init(bounds *b, ht_context_menu *m)
00722 {
00723         ht_dialog::init(b, 0, 0);
00724         VIEW_DEBUG_NAME("ht_menu_window");
00725 
00726         bounds c=*b;
00727         c.x=0;
00728         c.y=0;
00729         c.w-=2;
00730         c.h-=2;
00731         menu = m;
00732         body=new ht_menu_window_body();
00733         body->init(&c, menu);
00734         insert(body);
00735 }
00736 
00737 void ht_menu_window::done()
00738 {
00739         ht_dialog::done();
00740 }
00741 
00742 void ht_menu_window::getdata(ht_object_stream *s)
00743 {
00744         body->getdata(s);
00745 }
00746 
00747 void ht_menu_window::handlemsg(htmsg *msg)
00748 {
00749         if (msg->msg==msg_button_pressed) {
00750                 switch (msg->data1.integer) {
00751                         case button_ok: {
00752                                 ht_menu_window_data a;
00753                                 databuf_get(&a, sizeof a);
00754                                 int curentry = a.selected;
00755                                 ht_context_menu_entry *e = menu->get_entry(a.selected);
00756                                 if ((e->type == CME_ENTRY) && (e->entry.active)) {
00757                                         dirtyview();
00758                                         htmsg m;
00759                                         m.msg = e->entry.command;
00760                                         m.type = mt_empty;
00761                                         ((ht_app*)app)->queuemsg(app, &m);
00762 //                                      app->sendmsg(e->entry.command);
00763                                 } else if (e->type == CME_SUBMENU) {
00764                                         if (execute_submenu(menu->xpos+2, 3+curentry, e->submenu)) {
00765                                                 sendmsg(msg_button_pressed, button_cancel);
00766                                         }
00767                                         clearmsg(msg);
00768                                 }
00769                                 break;
00770                         }
00771                 }
00772         }
00773         ht_dialog::handlemsg(msg);
00774 }
00775 
00776 void ht_menu_window::setdata(ht_object_stream *s)
00777 {
00778         body->setdata(s);
00779 }
00780 
00781 /*
00782  *      CLASS ht_menu_window_body
00783  */
00784 
00785 void ht_menu_window_body::init(bounds *b, ht_context_menu *menu)
00786 {
00787         ht_context_menu_window_body::init(b, menu);
00788         VIEW_DEBUG_NAME("ht_menu_window_body");
00789 }
00790 
00791 void ht_menu_window_body::done()
00792 {
00793         ht_context_menu_window_body::done();
00794 }
00795 
00796 void ht_menu_window_body::handlemsg(htmsg *msg)
00797 {
00798         if (msg->msg==msg_keypressed) {
00799                 switch (msg->data1.integer) {
00800                         case K_Left:
00801                                 ((ht_dialog*)baseview)->setstate(ds_term_ok, button_left);
00802                                 dirtyview();
00803                                 clearmsg(msg);
00804                                 return;
00805                         case K_Right:
00806                                 ((ht_dialog*)baseview)->setstate(ds_term_ok, button_right);
00807                                 dirtyview();
00808                                 clearmsg(msg);
00809                                 return;
00810                 }
00811         }
00812         ht_context_menu_window_body::handlemsg(msg);
00813 }
00814 
00815 /*
00816  *      INIT
00817  */
00818 
00819 bool init_menu()
00820 {
00821         return true;
00822 }
00823 
00824 /*
00825  *      DONE
00826  */
00827 
00828 void done_menu()
00829 {
00830 }

Generated on Fri May 7 21:15:35 2004 by doxygen 1.3.5