MENUBAR.C 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/ui/rcs/menubar.c $
  15. * $Revision: 1.10 $
  16. * $Author: matt $
  17. * $Date: 1994/11/27 14:53:11 $
  18. *
  19. * .
  20. *
  21. * $Log: menubar.c $
  22. * Revision 1.10 1994/11/27 14:53:11 matt
  23. * Took out include of medlisp.h
  24. *
  25. * Revision 1.9 1994/11/18 23:07:28 john
  26. * Changed a bunch of shorts to ints.
  27. *
  28. * Revision 1.8 1994/05/31 18:18:41 john
  29. * Fixed bug with F pulling up file menu,
  30. *
  31. * Revision 1.7 1994/05/30 12:03:37 john
  32. * Fixed bug with Alt+F not getting accepted in state 0.
  33. *
  34. * Revision 1.6 1994/05/25 10:05:54 yuan
  35. * Tracking down strange bug with do-wall-dialog.
  36. *
  37. * Revision 1.5 1994/05/24 17:52:22 yuan
  38. * Testing.
  39. *
  40. * Revision 1.4 1994/02/01 13:29:53 john
  41. * *** empty log message ***
  42. *
  43. * Revision 1.3 1993/12/22 17:26:49 john
  44. * made it so that you can hold down Alt key and
  45. * type menu letters to select an item.
  46. *
  47. * Revision 1.2 1993/12/15 11:18:15 yuan
  48. * Changed width of menubar to 700 so that we could squeeze
  49. * in the clock
  50. *
  51. * Revision 1.1 1993/12/07 12:31:09 john
  52. * Initial revision
  53. *
  54. *
  55. */
  56. #pragma off (unreferenced)
  57. static char rcsid[] = "$Id: menubar.c 1.10 1994/11/27 14:53:11 matt Exp $";
  58. #pragma on (unreferenced)
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include <ctype.h>
  63. #include "mem.h"
  64. #include "fix.h"
  65. #include "types.h"
  66. #include "gr.h"
  67. #include "ui.h"
  68. #include "key.h"
  69. #include "mono.h"
  70. #include "func.h"
  71. #include "error.h"
  72. #define MAXMENUS 30
  73. #define MAXITEMS 30
  74. typedef struct {
  75. short x, y, w, h;
  76. char *Text;
  77. char *InactiveText;
  78. short Hotkey;
  79. int (*user_function)(void);
  80. } ITEM;
  81. typedef struct {
  82. short x, y, w, h;
  83. short ShowBar;
  84. short CurrentItem;
  85. short NumItems;
  86. short Displayed;
  87. short Active;
  88. grs_bitmap * Background;
  89. ITEM Item[MAXITEMS];
  90. } MENU;
  91. MENU Menu[MAXMENUS];
  92. static int num_menus = 0;
  93. static int state;
  94. static int menubar_hid;
  95. #define CMENU (Menu[0].CurrentItem+1)
  96. //------------------------- Show a menu item -------------------
  97. void item_show( MENU * menu, int n )
  98. {
  99. ITEM * item = &menu->Item[n];
  100. gr_set_current_canvas(NULL);
  101. // If this is a seperator, then draw it.
  102. if ( item->Text[0] == '-' )
  103. {
  104. gr_setcolor( CBLACK );
  105. gr_urect( item->x, item->y+item->h/2, item->x+item->w-1, item->y+item->h/2 );
  106. return;
  107. }
  108. if ( menu->CurrentItem==n && menu->ShowBar )
  109. {
  110. if ( menu != &Menu[0] )
  111. {
  112. gr_setcolor( CBLACK );
  113. gr_urect( item->x+1, item->y+1, item->x+menu->w-2, item->y+item->h-2 );
  114. }
  115. gr_set_fontcolor( CWHITE, CBLACK );
  116. }else {
  117. if ( menu != &Menu[0] )
  118. {
  119. gr_setcolor( CGREY );
  120. gr_urect( item->x+1, item->y+1, item->x+menu->w-2, item->y+item->h-2 );
  121. }
  122. gr_set_fontcolor( CBLACK, CGREY );
  123. }
  124. if ( menu != &Menu[0] )
  125. {
  126. if ( menu->Active)
  127. gr_ustring( item->x+1, item->y+1, item->Text );
  128. else
  129. gr_ustring( item->x+1, item->y+1, item->InactiveText );
  130. } else {
  131. if ( menu->Active)
  132. gr_ustring( item->x, item->y, item->Text );
  133. else
  134. gr_ustring( item->x, item->y, item->InactiveText );
  135. }
  136. }
  137. //---------------------------- Show a menu ---------------------
  138. void menu_show( MENU * menu )
  139. {
  140. int i;
  141. ui_mouse_hide();
  142. gr_set_current_canvas(NULL);
  143. // Don't save background it if it's already drawn
  144. if (!menu->Displayed)
  145. {
  146. // Save the background
  147. gr_bm_ubitblt(menu->w, menu->h, 0, 0, menu->x, menu->y, &(grd_curscreen->sc_canvas.cv_bitmap), menu->Background);
  148. // Draw the menu background
  149. gr_setcolor( CGREY );
  150. gr_urect( menu->x, menu->y, menu->x + menu->w - 1, menu->y + menu->h - 1 );
  151. if ( menu != &Menu[0] )
  152. {
  153. gr_setcolor( CBLACK );
  154. gr_ubox( menu->x, menu->y, menu->x + menu->w - 1, menu->y + menu->h - 1 );
  155. }
  156. }
  157. // Draw the items
  158. for (i=0; i< menu->NumItems; i++ )
  159. item_show( menu, i );
  160. ui_mouse_show();
  161. // Mark as displayed.
  162. menu->Displayed = 1;
  163. }
  164. //-------------------------- Hide a menu -----------------------
  165. void menu_hide( MENU * menu )
  166. {
  167. // Can't hide if it's not already drawn
  168. if (!menu->Displayed) return;
  169. menu->Active = 0;
  170. // Restore the background
  171. ui_mouse_hide();
  172. gr_bm_ubitblt(menu->w, menu->h, menu->x, menu->y, 0, 0, menu->Background, &(grd_curscreen->sc_canvas.cv_bitmap));
  173. ui_mouse_show();
  174. // Mark as hidden.
  175. menu->Displayed = 0;
  176. }
  177. //------------------------- Move the menu bar ------------------
  178. void menu_move_bar_to( MENU * menu, int number )
  179. {
  180. int old_item;
  181. old_item = menu->CurrentItem;
  182. menu->CurrentItem = number;
  183. if (menu->Displayed && (number != old_item))
  184. {
  185. ui_mouse_hide();
  186. item_show( menu, old_item );
  187. item_show( menu, number );
  188. ui_mouse_show();
  189. }
  190. }
  191. //------------------------ Match keypress to item ------------------
  192. int menu_match_keypress( MENU * menu, int keypress )
  193. {
  194. int i;
  195. char c;
  196. char *letter;
  197. if ((keypress & KEY_CTRLED) || (keypress & KEY_SHIFTED))
  198. return -1;
  199. keypress &= 0xFF;
  200. c = key_to_ascii(keypress);
  201. for (i=0; i< menu->NumItems; i++ )
  202. {
  203. letter = strrchr( menu->Item[i].Text, '&' );
  204. if (letter)
  205. {
  206. letter++;
  207. if (c==tolower(*letter))
  208. return i;
  209. }
  210. }
  211. return -1;
  212. }
  213. int menu_is_mouse_on( ITEM * item )
  214. {
  215. if ((Mouse.x >= item->x) &&
  216. (Mouse.x < item->x + item->w ) &&
  217. (Mouse.y >= item->y) &&
  218. (Mouse.y <= item->y + item->h ) )
  219. return 1;
  220. else
  221. return 0;
  222. }
  223. int menu_check_mouse_item( MENU * menu )
  224. {
  225. int i;
  226. for (i=0; i<menu->NumItems; i++ )
  227. {
  228. if (menu_is_mouse_on( &menu->Item[i] ))
  229. {
  230. if (menu->Item[i].Text[0] == '-')
  231. return -1;
  232. else
  233. return i;
  234. }
  235. }
  236. return -1;
  237. }
  238. void menu_hide_all()
  239. {
  240. int i;
  241. for (i=1; i<num_menus; i++)
  242. menu_hide( &Menu[i] );
  243. Menu[0].ShowBar = 0;
  244. Menu[0].Active = 0;
  245. menu_show( &Menu[0] );
  246. }
  247. static state2_alt_down;
  248. void do_state_0( int keypress )
  249. {
  250. int i, j;
  251. Menu[0].Active = 0;
  252. Menu[0].ShowBar = 0;
  253. if (Menu[0].Displayed==0)
  254. menu_show( &Menu[0] );
  255. if ( keypress & KEY_ALTED ) {
  256. i = menu_match_keypress( &Menu[0], keypress );
  257. if (i > -1 )
  258. {
  259. Menu[0].CurrentItem = i;
  260. Menu[0].Active = 0;
  261. state = 3;
  262. Menu[ CMENU ].ShowBar = 1;
  263. Menu[ CMENU ].Active = 1;
  264. Menu[0].ShowBar = 1;
  265. menu_show( &Menu[ CMENU ] );
  266. menu_show( &Menu[0] );
  267. }
  268. }
  269. for (i=0; i<num_menus; i++ )
  270. for (j=0; j< Menu[i].NumItems; j++ )
  271. {
  272. if ( Menu[i].Item[j].Hotkey == keypress )
  273. {
  274. if (Menu[i].Item[j].user_function)
  275. Menu[i].Item[j].user_function();
  276. last_keypress = 0;
  277. return;
  278. }
  279. }
  280. if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] || ((keypress & 0xFF) == KEY_LALT) )
  281. //if ( (keypress & 0xFF) == KEY_LALT )
  282. {
  283. state = 1;
  284. Menu[0].Active = 1;
  285. menu_show( &Menu[0] );
  286. return;
  287. }
  288. i = menu_check_mouse_item( &Menu[0] );
  289. if ( B1_PRESSED && (i > -1))
  290. {
  291. Menu[0].CurrentItem = i;
  292. state = 3;
  293. Menu[ CMENU ].ShowBar = 1;
  294. Menu[0].ShowBar = 1;
  295. Menu[ CMENU ].Active = 1;
  296. Menu[0].Active = 0;
  297. menu_show( &Menu[ CMENU ] );
  298. menu_show( &Menu[0] );
  299. return;
  300. }
  301. }
  302. void do_state_1( int keypress )
  303. {
  304. int i;
  305. if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] )
  306. {
  307. //state = 2;
  308. //state2_alt_down = 0;
  309. //Menu[0].ShowBar = 1;
  310. //Menu[0].Active = 1;
  311. //menu_show( &Menu[0] );
  312. state = 0;
  313. menu_hide_all();
  314. }
  315. i = menu_match_keypress( &Menu[0], keypress );
  316. if (i > -1 )
  317. {
  318. Menu[0].CurrentItem = i;
  319. Menu[0].Active = 0;
  320. state = 3;
  321. Menu[ CMENU ].ShowBar = 1;
  322. Menu[ CMENU ].Active = 1;
  323. Menu[0].ShowBar = 1;
  324. menu_show( &Menu[ CMENU ] );
  325. menu_show( &Menu[0] );
  326. }
  327. i = menu_check_mouse_item( &Menu[0] );
  328. if ( (i == -1) && B1_JUST_RELEASED )
  329. {
  330. state = 0;
  331. menu_hide_all();
  332. }
  333. if ( B1_PRESSED && (i > -1))
  334. {
  335. Menu[0].CurrentItem = i;
  336. state = 3;
  337. Menu[ CMENU ].ShowBar = 1;
  338. Menu[ CMENU ].Active = 1;
  339. Menu[0].ShowBar = 1;
  340. Menu[0].Active = 0;
  341. menu_show( &Menu[ CMENU ] );
  342. menu_show( &Menu[0] );
  343. }
  344. }
  345. void do_state_2(int keypress)
  346. {
  347. int i;
  348. if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
  349. state2_alt_down = 1;
  350. if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] && state2_alt_down )
  351. {
  352. state = 0;
  353. menu_hide_all();
  354. }
  355. switch( keypress )
  356. {
  357. case KEY_ESC:
  358. state = 0;
  359. menu_hide_all();
  360. break;
  361. case KEY_LEFT:
  362. case KEY_PAD4:
  363. i = Menu[0].CurrentItem-1;
  364. if (i < 0 ) i = Menu[0].NumItems-1;
  365. menu_move_bar_to( &Menu[0], i );
  366. break;
  367. case KEY_RIGHT:
  368. case KEY_PAD6:
  369. i = Menu[0].CurrentItem+1;
  370. if (i >= Menu[0].NumItems ) i = 0;
  371. menu_move_bar_to( &Menu[0], i );
  372. break;
  373. case KEY_ENTER:
  374. case KEY_PADENTER:
  375. case KEY_DOWN:
  376. case KEY_PAD2:
  377. state = 3;
  378. Menu[ CMENU ].ShowBar = 1;
  379. Menu[ CMENU ].Active = 1;
  380. Menu[0].Active = 0;
  381. menu_show( &Menu[ 0 ] );
  382. menu_show( &Menu[ CMENU ] );
  383. break;
  384. default:
  385. i = menu_match_keypress( &Menu[0], keypress );
  386. if (i > -1 )
  387. {
  388. Menu[0].CurrentItem = i;
  389. Menu[0].Active = 0;
  390. state = 3;
  391. Menu[ CMENU ].ShowBar = 1;
  392. Menu[ CMENU ].Active = 1;
  393. Menu[0].ShowBar = 1;
  394. menu_show( &Menu[ CMENU ] );
  395. menu_show( &Menu[0] );
  396. break;
  397. }
  398. i = menu_check_mouse_item( &Menu[0] );
  399. if ( (i == -1) && B1_JUST_RELEASED )
  400. {
  401. state = 0;
  402. menu_hide_all();
  403. break;
  404. }
  405. if ( B1_PRESSED && (i > -1))
  406. {
  407. Menu[0].CurrentItem = i;
  408. Menu[0].Active = 0;
  409. state = 3;
  410. Menu[ CMENU ].ShowBar = 1;
  411. Menu[ CMENU ].Active = 1;
  412. Menu[0].ShowBar = 1;
  413. menu_show( &Menu[ CMENU ] );
  414. menu_show( &Menu[0] );
  415. break;
  416. }
  417. }
  418. }
  419. void do_state_3( int keypress )
  420. {
  421. int i;
  422. switch( keypress )
  423. {
  424. case KEY_ESC:
  425. state = 0;
  426. menu_hide_all();
  427. break;
  428. case KEY_DOWN:
  429. case KEY_PAD2:
  430. i = Menu[ CMENU ].CurrentItem;
  431. do {
  432. i++;
  433. if ( i >= Menu[ CMENU ].NumItems )
  434. i = 0;
  435. } while( Menu[CMENU].Item[i].Text[0] == '-');
  436. menu_move_bar_to( &Menu[ CMENU ], i );
  437. break;
  438. case KEY_UP:
  439. case KEY_PAD8:
  440. i = Menu[ CMENU ].CurrentItem;
  441. do
  442. {
  443. i--;
  444. if ( i < 0 )
  445. i = Menu[ CMENU ].NumItems-1;
  446. } while( Menu[CMENU].Item[i].Text[0] == '-');
  447. menu_move_bar_to( &Menu[ CMENU ], i );
  448. break;
  449. case KEY_RIGHT:
  450. case KEY_PAD6:
  451. menu_hide( &Menu[ CMENU ] );
  452. i = Menu[0].CurrentItem+1;
  453. if (i >= Menu[0].NumItems ) i = 0;
  454. menu_move_bar_to( &Menu[0], i );
  455. Menu[CMENU].ShowBar = 1;
  456. Menu[CMENU].Active = 1;
  457. menu_show( &Menu[CMENU] );
  458. break;
  459. case KEY_LEFT:
  460. case KEY_PAD4:
  461. menu_hide( &Menu[ CMENU ] );
  462. i = Menu[0].CurrentItem-1;
  463. if (i < 0 ) i = Menu[0].NumItems-1;
  464. menu_move_bar_to( &Menu[0], i );
  465. Menu[ CMENU ].ShowBar = 1;
  466. Menu[CMENU].Active = 1;
  467. menu_show( &Menu[ CMENU ] );
  468. break;
  469. case KEY_ENTER:
  470. case KEY_PADENTER:
  471. state = 0;
  472. menu_hide_all();
  473. if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
  474. Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
  475. break;
  476. default:
  477. i = menu_match_keypress( &Menu[ CMENU ], keypress );
  478. if (i > -1 )
  479. {
  480. menu_move_bar_to( &Menu[ CMENU ], i );
  481. state = 0;
  482. menu_hide_all();
  483. if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
  484. Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
  485. break;
  486. }
  487. i = menu_check_mouse_item( &Menu[CMENU] );
  488. if (i > -1 )
  489. {
  490. if ( B1_PRESSED )
  491. menu_move_bar_to( &Menu[ CMENU ], i );
  492. else if ( B1_JUST_RELEASED )
  493. {
  494. menu_move_bar_to( &Menu[ CMENU ], i );
  495. state = 0;
  496. menu_hide_all();
  497. if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
  498. Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
  499. break;
  500. }
  501. } else {
  502. i = menu_check_mouse_item( &Menu[0] );
  503. if ( B1_PRESSED && (i > -1))
  504. {
  505. if ( Menu[0].CurrentItem != i) {
  506. menu_hide( &Menu[ CMENU ] );
  507. menu_move_bar_to( &Menu[0], i );
  508. Menu[ CMENU ].ShowBar = 1;
  509. Menu[CMENU].Active = 1;
  510. menu_show( &Menu[ CMENU ] );
  511. break;
  512. }
  513. }
  514. if ( B1_JUST_RELEASED )
  515. {
  516. state = 0;
  517. menu_hide_all();
  518. break;
  519. }
  520. }
  521. }
  522. }
  523. void menubar_do( int keypress )
  524. {
  525. if (menubar_hid) return;
  526. keypress = keypress;
  527. do_state_0(last_keypress);
  528. while (state > 0 )
  529. {
  530. ui_mega_process();
  531. switch(state)
  532. {
  533. case 1:
  534. do_state_1(last_keypress);
  535. break;
  536. case 2:
  537. do_state_2(last_keypress);
  538. break;
  539. case 3:
  540. do_state_3(last_keypress);
  541. break;
  542. default:
  543. state = 0;
  544. }
  545. last_keypress = 0;
  546. }
  547. }
  548. void CommaParse( int n, char * dest, char * source )
  549. {
  550. int i = 0, j=0, cn = 0;
  551. // Go to the n'th comma
  552. while (cn < n )
  553. if (source[i++] == ',' )
  554. cn++;
  555. // Read all the whitespace
  556. while ( source[i]==' ' || source[i]=='\t' || source[i]==13 || source[i]==10 )
  557. i++;
  558. // Read up until the next comma
  559. while ( source[i] != ',' )
  560. {
  561. dest[j] = source[i++];
  562. j++;
  563. }
  564. // Null-terminate
  565. dest[j++] = 0;
  566. }
  567. void menubar_init( char * file )
  568. {
  569. int i,j, np;
  570. int aw, w, h;
  571. FILE * infile;
  572. char buffer[200];
  573. char buf1[200];
  574. char buf2[200];
  575. int menu, item;
  576. num_menus = state = 0;
  577. for (i=0; i < MAXMENUS; i++ )
  578. {
  579. Menu[i].x = Menu[i].y = Menu[i].w = Menu[i].h = 0;
  580. Menu[i].ShowBar = 0;
  581. Menu[i].CurrentItem = 0;
  582. Menu[i].NumItems = 0;
  583. Menu[i].Displayed = 0;
  584. Menu[i].Background = 0;
  585. for (j=0; j< MAXITEMS; j++ )
  586. {
  587. Menu[i].Item[j].x = Menu[i].Item[j].y = Menu[i].Item[j].w = Menu[i].Item[j].h = 0;
  588. Menu[i].Item[j].Text = NULL;
  589. Menu[i].Item[j].Hotkey = 0;
  590. Menu[i].Item[j].user_function = NULL;
  591. }
  592. }
  593. infile = fopen( file, "rt" );
  594. if (!infile) return;
  595. while ( fgets( buffer, 200, infile) != NULL )
  596. {
  597. if ( buffer[0] == ';' ) continue;
  598. //mprintf( 0, "%s\n", buffer );
  599. CommaParse( 0, buf1, buffer );
  600. menu = atoi( buf1 );
  601. CommaParse( 1, buf1, buffer );
  602. item = atoi(buf1 );
  603. CommaParse( 2, buf1, buffer );
  604. if (buf1[0] != '-' )
  605. {
  606. sprintf( buf2, " %s ", buf1 );
  607. Menu[menu].Item[item].Text = strdup(buf2);
  608. } else
  609. Menu[menu].Item[item].Text = strdup(buf1);
  610. Menu[menu].Item[item].InactiveText = strdup(Menu[menu].Item[item].Text);
  611. j= 0;
  612. for (i=0; i<=strlen(Menu[menu].Item[item].Text); i++ )
  613. {
  614. np = Menu[menu].Item[item].Text[i];
  615. if (np != '&')
  616. Menu[menu].Item[item].InactiveText[j++] = np;
  617. }
  618. CommaParse( 3, buf1, buffer );
  619. if (buf1[0]=='{' && buf1[1] =='}')
  620. Menu[menu].Item[item].Hotkey = -1;
  621. else {
  622. i = DecodeKeyText(buf1);
  623. if (i<1) {
  624. Error("Unknown key, %s, in %s\n", buf1, file );
  625. } else {
  626. Menu[menu].Item[item].Hotkey = i;
  627. }
  628. }
  629. CommaParse( 4, buf1, buffer );
  630. if (strlen(buf1))
  631. {
  632. Menu[menu].Item[item].user_function = func_get(buf1, &np);
  633. // if (!strcmp(buf1,"do-wall-dialog")) {
  634. // mprintf( 0, "Found function %s\n", buf1);
  635. // mprintf( 0, "User function %s\n", Menu[menu].Item[item].user_function);
  636. // }
  637. if (Menu[menu].Item[item].user_function==NULL)
  638. {
  639. Error( "Unknown function, %s, in %s\n", buf1, file );
  640. //MessageBox( -2, -2, 1, buffer, "Ok" );
  641. }
  642. }
  643. Menu[menu].Item[item].x = Menu[menu].x;
  644. Menu[menu].Item[item].y = Menu[menu].y;
  645. if ( Menu[menu].Item[item].Text[0] == '-' )
  646. {
  647. w = 1; h = 3;
  648. } else {
  649. gr_get_string_size( Menu[menu].Item[item].Text, &w, &h, &aw );
  650. w += 2;
  651. h += 2;
  652. }
  653. if (menu==0) {
  654. Menu[0].h = h;
  655. Menu[0].Item[item].x = Menu[0].x + Menu[0].w;
  656. Menu[0].Item[item].y = Menu[0].y;
  657. Menu[item+1].x = Menu[0].x + Menu[0].w;
  658. Menu[item+1].y = Menu[0].h - 2;
  659. Menu[0].Item[item].w = w;
  660. Menu[0].Item[item].h = h;
  661. Menu[0].w += w;
  662. }else {
  663. if ( w > Menu[menu].w )
  664. {
  665. Menu[menu].w = w;
  666. for (i=0; i< Menu[menu].NumItems; i++ )
  667. Menu[menu].Item[i].w = Menu[menu].w;
  668. }
  669. Menu[menu].Item[item].w = Menu[menu].w;
  670. Menu[menu].Item[item].x = Menu[menu].x;
  671. Menu[menu].Item[item].y = Menu[menu].y+Menu[menu].h;
  672. Menu[menu].Item[item].h = h;
  673. Menu[menu].h += h;
  674. }
  675. if ( item >= Menu[menu].NumItems )
  676. {
  677. Menu[menu].NumItems = item+1;
  678. }
  679. if ( menu >= num_menus )
  680. num_menus = menu+1;
  681. }
  682. Menu[0].w = 700;
  683. fclose( infile );
  684. for (i=0; i<num_menus; i++ )
  685. Menu[i].Background = gr_create_bitmap(Menu[i].w, Menu[i].h );
  686. menubar_hid = 1;
  687. }
  688. void menubar_hide()
  689. {
  690. menubar_hid = 1;
  691. state = 0;
  692. menu_hide_all();
  693. menu_hide( &Menu[0] );
  694. }
  695. void menubar_show()
  696. {
  697. menubar_hid = 0;
  698. menu_show( &Menu[0] );
  699. }
  700. void menubar_close()
  701. {
  702. int i;
  703. //menu_hide_all();
  704. //menu_hide( &Menu[0] );
  705. for (i=0; i<num_menus; i++ )
  706. gr_free_bitmap( Menu[i].Background );
  707. }