menuDevice.icl 25.7 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
implementation module menuDevice;


import misc,xtypes,deltaIOSystem,ioState,commonDef,xkernel,xmenu;
import StdEnv;


    

MenuFunctions ::    DeviceFunctions s;
MenuFunctions = (ShowMenu,OpenMenu,MenuIO,CloseMenu,HideMenu);

CloseMenu :: !(IOState state) -> IOState state;
CloseMenu io_state
   =  UEvaluate_2 (IOStateRemoveDevice io_state` MenuDevice)
                  (DisposeMenuSystemState menu);
      where {
      (menu, io_state`)=: IOStateGetDevice io_state MenuDevice;
      };

HideMenu :: !(IOState s) -> IOState s;
HideMenu io_state
   =  IOStateSetDevice io_state` menu`;
      where {
      menu`            =: ClearMenuSystem menu;
      (menu, io_state`)=: IOStateGetDevice io_state MenuDevice;
      };

ShowMenu :: !(IOState s) -> IOState s;
ShowMenu io_state
   =  IOStateSetDevice io_state` menu`;
      where {
      menu`            =: DrawMenuSystem menu;
      (menu, io_state`)=: IOStateGetDevice io_state MenuDevice;
      };


/* Opening a menu
*/
OpenMenu :: !(DeviceSystem s (IOState s)) !(IOState s) -> IOState s;
OpenMenu (MenuSystem menus) io_state
   #!
43
      menu_bar   = add_menu_bar 0;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
      handles    = CreateXHandles [] menus menu_bar;
   #!
      menu_system= MenuSystemState menu_bar handles; 
   #!
      strict1=(DrawMenuSystem menu_system);
		=
		IOStateSetDevice io_state strict1;

/* For every kind of 'root` menu (moveable/popup/menubar) a structure is build,
   that contains handles to the subparts (menus/items) of this structure.
*/
CreateXHandles :: ![KeyShortcut] ![MenuDef s (IOState s)] Widget 
   -> MenuHandles s (IOState s);
CreateXHandles keys [PullDownMenu id s able items : menus] bar 
   #!   strict1=AddXMenu bar s able;
   #  (new_menu, bar`)     = strict1;
   #!	strict2=CreateXMenuItemHandles keys new_menu items;
		strict3=CreateXHandles keys menus bar`;
   #   (keys`, item_handles)= strict2;
   #!  pulldown_handle      = PullDownHandle able (id,new_menu) item_handles;
   #  (keys``, menus`, b)  = strict3;
		=
		(keys``, [pulldown_handle : menus`], True);
CreateXHandles keys menus bar =  (keys, [], True);

/* Creating all the menu items and putting them in a list that is returned.
   According to the OPEN LOOK guidelines grouping in menus is done by an
   empty menu item.
*/
CreateXMenuItemHandles :: [KeyShortcut] Widget [MenuElement s (IOState s)] 
   -> (![KeyShortcut], ![MenuItemHandle s (IOState s)]);
CreateXMenuItemHandles keys menu [MenuItem id s cut able f : items]
   #!
      cut`              = CorrectKeyShortcut cut keys;
      strict1=AddXMenuItem menu s cut` able;
    # (new_item`, menu`)= strict1;
    #! new_item          = ItemHandle (id, new_item`) f;
    # (keys`, items`)   = CreateXMenuItemHandles (AddKey cut` keys) menu` items;
		=
		(keys`, [new_item : items`]);
CreateXMenuItemHandles keys menu [CheckMenuItem id s cut able mark f : items]
   #!
      cut`              = CorrectKeyShortcut cut keys;
      strict1=AddXCheckMenuItem menu s cut` mark able;
      # (new_item`, menu`)= strict1;
      #! new_item          = ItemHandle (id, new_item`) f;
      # (keys`, items`)   = CreateXMenuItemHandles (AddKey cut` keys) menu` items;
		=
		(keys`, [new_item : items`]);
CreateXMenuItemHandles keys menu [SubMenuItem id s able sub_items : items]
   #!
		strict2=AddXSubMenuItem menu s able;
   #  (sub_widget, menu`)= strict2;
   #! strict1=CreateXMenuItemHandles keys sub_widget sub_items;
   #  (keys`, sub_items`)= strict1;
      (keys``, items`)   = CreateXMenuItemHandles keys` menu` items;
   #! sub_menu           = SubMenuHandle (id, sub_widget) sub_items`;
		=
		(keys``, [sub_menu : items`]);
CreateXMenuItemHandles keys menu [MenuItemGroup id group_items : items]
   #!
      strict1=AddXGroupItemHandles keys menu group_items;
   #
      (keys` , group_items`)= strict1;
   #!
      group                 = MenuItemGroupHandle (id, menu) group_items`;
	#
      (keys``, items`      )= CreateXMenuItemHandles keys` menu items;
		=
		(keys``, [group : items`]);
CreateXMenuItemHandles keys menu [MenuRadioItems id radios : items] 
   #!
      strict1=CreateXRadioItems keys menu radios id;
   #  (keys` , radios`, menu`)= strict1;
      (keys``, items`)        = CreateXMenuItemHandles keys` menu` items;
		=
		(keys``, [radios` : items`]);
CreateXMenuItemHandles keys menu [MenuSeparator : items]
   #!
      strict1=AddXMenuSeparator menu;
   #  (new_item`, menu`)= strict1;
      (keys`, items`)   = CreateXMenuItemHandles keys menu` items;
      new_item          = MenuSeparatorHandle new_item`;
		=
		(keys`, [new_item : items`]);
CreateXMenuItemHandles keys menu items =  (keys, []);

/* Creation of MenuRadioItems as a "group" of CheckMenuItems.               
*/
CreateXRadioItems :: ![KeyShortcut] !Widget ![RadioElement s (IOState s)]
      !MenuItemId
   -> (![KeyShortcut], !MenuItemHandle s (IOState s), !Widget);
CreateXRadioItems keys menu radios id 
   =  (keys`, RadioHandle id radios`, menu`);
      where {
      (keys`, radios`, menu`)=: CreateXRadioItems` keys menu id radios;
      };

CreateXRadioItems` :: ![KeyShortcut] Widget !MenuItemId
      ![RadioElement s (IOState s)] 
   -> (![KeyShortcut], ![RadioMenuItemHandle s (IOState s)], !Widget);
CreateXRadioItems` keys w defaultId [MenuRadioItem id s sh able f : radios]
   | id == defaultId   #!
		sh`=sh`;
		newkeys=newkeys;
      strict3=AddXCheckMenuItem w s sh` Mark   able;
   #  (radio_item , w` )= strict3;
      radio = RadioItemHandle (id, radio_item ) f;
      (keys` , radios` , menu` )= CreateXRadioItems` newkeys w`  defaultId radios;
   #!	radios`=radios`;
		=
		(keys` , [radio  : radios` ], menu` );
   #!
		sh`=sh`;
		newkeys=newkeys;
		strict4=AddXCheckMenuItem w s sh` NoMark able;
    # (radio_item`, w``)= strict4;
      radio`= RadioItemHandle (id, radio_item`) f;
    # (keys``, radios``, menu``)= CreateXRadioItems` newkeys w`` defaultId radios;

	#!	radios``=radios``;
		=
		(keys``, [radio` : radios``], menu``);
      where {
      sh`               =: CorrectKeyShortcut sh keys;
      newkeys           =: AddKey sh` keys;
		};
CreateXRadioItems` keys w id radios =  (keys, [], w);


/* Doing menu I/O
*/
MenuIO :: !Event !*s !(IOState *s) -> (!Bool, !*s, !IOState *s);
MenuIO (widget, XMenuDevice, e) state io_state 
   =  (True, state`, io_state``);
      where {
      (state`, io_state``)=: MenuIO` widget menus state io_state`;
      (menus,  io_state` )=: IOStateGetDevice io_state MenuDevice;
      };
MenuIO no_menu_device state io_state =  (False, state, io_state);

MenuIO` :: !Widget !(DeviceSystemState *s) !*s !(IOState *s) -> (!*s, !IOState *s);
/* RWS don't do any menu io on disabled menu systems */
MenuIO` _ (MenuSystemState _ (_,_,False)) state io_state
	=	(state, io_state);
MenuIO` widget (MenuSystemState bar h=:(keys,menu_specs,able)) state io_state
   =  menu_f state io_state;
      where {
      menu_f=: GetMenuFunction widget menu_specs;
      };

GetMenuFunction :: !Widget ![MenuHandle s (IOState s)] -> MenuFunction s (IOState s);
/* RWS only consider able menus
	GetMenuFunction widget [PullDownHandle ability xh items : menus] */
GetMenuFunction widget [PullDownHandle Able xh items : menus]
   | found   =  f;
      where {
      (found, f)=: GetMenuFunction` widget items;
      };
GetMenuFunction widget [_ : menus]
   =  GetMenuFunction widget menus;
/* RWS : no function applicable, return noop function */
GetMenuFunction widget []
	=	noop;
	where
	{
		noop state io
			=	(state, io);
	}

GetMenuFunction` :: !Widget ![MenuItemHandle s (IOState s)] 
   -> (!Bool, !MenuFunction s (IOState s));
GetMenuFunction` widget [ItemHandle (id`,w) f : items]
   | widget == w =  (True, f);
   =  GetMenuFunction` widget items;
GetMenuFunction` widget [SubMenuHandle xhandle sub_items : items]
   =  GetMenuFunction` widget (Concat sub_items items);
GetMenuFunction` widget [MenuItemGroupHandle xhandle group_items : items]
   =  GetMenuFunction` widget (Concat group_items items);
GetMenuFunction` widget [RadioHandle id` radio_items : items] 
   | found =  (True, RadioFunction f radio_items widget);
   =  GetMenuFunction` widget items;
      where {
      (found, f)=: GetRadioFunction widget radio_items;
      };
GetMenuFunction` widget [item : items] =  GetMenuFunction` widget items;
GetMenuFunction` widget items =  (False, NoFunc);

GetRadioFunction :: !Widget ![RadioMenuItemHandle s (IOState s)] 
   -> (!Bool, !MenuFunction s (IOState s));
GetRadioFunction widget [RadioItemHandle (id`,w) f : radios] 
   | widget == w =  (True, f);
   =  GetRadioFunction widget radios;
GetRadioFunction widget radios =  (False, NoFunc);

RadioFunction :: !(MenuFunction *s (IOState *s)) ![RadioMenuItemHandle *s io] !Widget 
                 *s !(IOState *s) -> (*s, !IOState *s);
RadioFunction f radios widget s io
	= f s (SetRadios radios widget io);

SetRadios :: ![RadioMenuItemHandle s io] !Widget !(IOState s) -> IOState s;
SetRadios [RadioItemHandle (id,w) f : radios] widget io
   | widget == w =  UEvaluate_2 radios` (CheckXWidget w Mark);
   =  UEvaluate_2 radios` (CheckXWidget w NoMark);
      where {
      radios`=: SetRadios radios widget io;
      };
SetRadios radios widget io =  io;

NoFunc :: *s (IOState *s) -> (*s, IOState *s);
NoFunc s io =  (s,io);


     

  XMark   :== 1;
  XNoMark :== 0;

  Set     :== 1;
  UnSet   :== 0;


    

/* Allocation and creation of menus/items etc.
*/
AddXMenu :: !Widget !String !SelectState -> (!Widget, !Widget);
AddXMenu bar s able 
   | Enabled able #!
		menu=menu;
		=
275
		 (enable_menu_widget  menu, bar);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
276 277 278
   #!
		menu=menu;
		=
279
		(disable_menu_widget menu, bar);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
280
      where {
281
      menu=: add_menu bar s;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
282 283 284
      };

AddXMenuSeparator :: !Widget -> (!Widget, !Widget);
285
AddXMenuSeparator menu =  (add_menu_separator menu, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
286 287 288

AddXMenuItem :: !Widget !String !KeyShortcut !SelectState -> (!Widget, !Widget);
AddXMenuItem menu s ks able 
289
   #!   item = add_menu_item menu s;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
290 291 292
     	item`= InstallKeyShortcut item ks;
   | Enabled able
		=
293
		 (enable_menu_widget  item`, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
294
		=
295
		(disable_menu_widget item`, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
296 297 298 299 300 301

AddXSubMenuItem :: !Widget !String !SelectState -> (!Widget, !Widget);
AddXSubMenuItem menu s able 
   | Enabled able #!
		sub=sub;
		=
302
		 (enable_menu_widget  sub, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
303 304 305
   #!
		sub=sub;
		=
306
		(disable_menu_widget sub, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
307
      where {
308
      sub=: add_sub_menu menu s;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
309 310 311 312 313 314 315 316 317 318
      };

AddXCheckMenuItem :: !Widget !String !KeyShortcut !MarkState !SelectState
   -> (!Widget, !Widget);
AddXCheckMenuItem menu s ks ms able 
   #!
      item = AddXCheckMenuItem` menu s ms;
	  item`= InstallKeyShortcut item ks;
   | Enabled able
   		=
319
		(enable_menu_widget  item`, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
320
		=
321
		(disable_menu_widget item`, menu);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
322 323 324

AddXCheckMenuItem` :: !Widget !String !MarkState -> Widget;
AddXCheckMenuItem` menu s ms
325 326
   | MarkEqual Mark ms =  add_check_item menu s XMark;
   =  add_check_item menu s XNoMark;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370

/* Handling group items
*/
AddXGroupItemHandle :: ![KeyShortcut] !Widget !(MenuElement s (IOState s))
   -> (!KeyShortcut, !MenuItemHandle s (IOState s), !Widget);
AddXGroupItemHandle keys group (MenuItem id s key able f)
   =  (key`, ItemHandle (id, item) f, group`); 
      where {
      key`          =: CorrectKeyShortcut key keys;
      (item, group`)=: AddXMenuItem group s key` able;
      };
AddXGroupItemHandle keys group (CheckMenuItem id s key able mark f)
   =  (key`, ItemHandle (id, item) f, group`);
      where {
      key`          =: CorrectKeyShortcut key keys;
      (item, group`)=: AddXCheckMenuItem group s key` mark able;
      };
AddXGroupItemHandle keys group MenuSeparator
   =  (NoKey, MenuSeparatorHandle item, group`);
      where {
      (item, group`)=: AddXMenuItem group " " NoKey Unable;
      };

AddXGroupItemHandles :: ![KeyShortcut] !Widget ![MenuElement s (IOState s)] 
   -> (![KeyShortcut], ![MenuItemHandle s (IOState s)]);
AddXGroupItemHandles keys group [item : items]
   | IsGroupItem item #!
		item`=item`;
		=
		(keys``, [item` : items`]);
   =  (keys  , items`);
      where {
      (key, item`, group`)=: AddXGroupItemHandle keys group item;
      (keys``, items`)    =: AddXGroupItemHandles (AddKey key keys) group` items;
      };
AddXGroupItemHandles keys group items =  (keys, []);

IsGroupItem :: !(MenuElement s (IOState s)) -> Bool;
IsGroupItem (MenuItem      id s key able      f) =  True;
IsGroupItem (CheckMenuItem id s key able mark f) =  True;
IsGroupItem MenuSeparator                        =  True;
IsGroupItem item =  False;

InsertInGroup :: !MenuItemGroupId !Int ![MenuElement s (IOState s)]
371
                 !(DeviceSystemState s) -> DeviceSystemState s;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
InsertInGroup id index item (MenuSystemState w (keys, menu_specs, able))
   #!
      strict1=InsertInGroup` id index item menu_specs keys;
   #
      (keys`, menu_specs`, b)= strict1;
		=
		MenuSystemState w (keys`, menu_specs`, able);

InsertInGroup` :: !MenuItemGroupId !Int ![MenuElement s (IOState s)]
      ![MenuHandle s (IOState s)] ![KeyShortcut]
   -> MenuHandles s (IOState s);
InsertInGroup` id index item [menu=: (PullDownHandle ability xh items) : menus] keys
   #!
		strict2=InsertInGroup`` id index item items keys;
   #
      (ready, keys`, items`)= strict2;
	| ready =  (keys` , [PullDownHandle ability xh items` : menus], True);
   #!
      strict1=InsertInGroup` id index item menus keys;
   #
      (keys``, menus`, b)   = strict1;
		=
		(keys``, [menu : menus`], True);
InsertInGroup` id index item menus keys =  (keys, [], True);

InsertInGroup`` :: !MenuItemGroupId !Int ![MenuElement s (IOState s)]
      ![MenuItemHandle s (IOState s)] ![KeyShortcut]
   -> (!Bool, ![KeyShortcut], ![MenuItemHandle s (IOState s)]);
InsertInGroup`` id index newitems [item=: (MenuItemGroupHandle (id`, w) els) : items] keys| id == id`
	#!	strict7=ReconstructMenuElements els keys;
	#   (keys1, els``)   = strict7;
	#!	strict6=ReconstructMenuElements items keys1;
	    els``=els``
    #  (keys2, reitems) = strict6;
    #!  strict4=(InsertInThisGroup index newitems els``);
    # (keys3, els`)    = AddXGroupItemHandles keys2 w
                              strict4;
      (keys4, reitems`)= CreateXMenuItemHandles keys3 w reitems;
	#! reitems`=reitems`;
	    els`=els`;

		=
		(True,  keys4, [MenuItemGroupHandle (id`,w) els` : reitems`]);
   #!
		strict8=InsertInGroup`` id index newitems items keys;
      (ready, keys5, result)= strict8;
	#! result=result;
		=
		(ready, keys5, [item : result]);
InsertInGroup`` id index newitems [item : items] keys
   #!
		strict1=strict1;
		=
		(ready, keys`, [item : items`]);
      where {
      (ready, keys`, items`)= strict1;
      strict1=InsertInGroup`` id index newitems items keys;
		};
InsertInGroup`` id index newitems items keys =  (False, keys, items);

InsertInThisGroup :: !Int ![MenuElement s (IOState s)] 
      ![MenuElement s (IOState s)]
   -> [MenuElement s (IOState s)];
InsertInThisGroup index elems [item]
   | index <= 1   =  Append elems item;
   =  [item : elems];
InsertInThisGroup index elems [item1, item2]
   | index <= 1   =  Append (InsertInThisGroup index elems [item1]) item2;
   | index  == 2                          #!
		strict1=strict1;
		=
		[item1 : strict1];
   #!
		strict2=strict2;
		=
		[item1 : strict2];
	where {
	strict2=InsertInThisGroup index elems [item2];
		
	strict1=Append elems item2;
		};
InsertInThisGroup index elems [item : items]
   | index <= 1    =  Concat (InsertInThisGroup index elems [item]) items;
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=InsertInThisGroup (dec index) elems items;
		
	};
InsertInThisGroup index elems items 
   =  elems;

DelFromGroupIndex :: !MenuItemGroupId ![Int] !(DeviceSystemState s)
   -> DeviceSystemState s;
DelFromGroupIndex id indexes (MenuSystemState w (keys, menuhandles, able))
   #!
      strict1=DelFromGroup id indexes menuhandles keys;
   #
      (keys`,menuhandles`,b)= strict1;
		=
		MenuSystemState w (keys`, menuhandles`, able);

DelFromGroup :: !MenuItemGroupId ![Int] ![MenuHandle s (IOState s)]
      ![KeyShortcut]
   -> MenuHandles s (IOState s);
DelFromGroup id indexes [menu=:PullDownHandle ability xh items : menus] keys
   #! strict2=DelFromGroup` id indexes items keys;
   #  (ready, keys`, items`)= strict2;
   | ready
		=
		(keys`,  [PullDownHandle ability xh items` : menus], True);
   #!
      strict1=DelFromGroup  id indexes menus keys;
   #  (keys``, menus`, b)   = strict1;
		=
		(keys``, [menu : menus`], True);
DelFromGroup id indexes menus keys =  (keys, menus, True);

DelFromGroup` :: !MenuItemGroupId ![Int] ![MenuItemHandle s (IOState s)] 
      ![KeyShortcut]
   -> (!Bool, ![KeyShortcut], ![MenuItemHandle s (IOState s)]);
DelFromGroup` id indexes [item=: MenuItemGroupHandle (id`,w) els : items] keys
   | id == id`
	#!	strict6=ReconstructMenuElements els keys;

    #  (keys1, els``)        = strict6;
	#!	els``=els``;
		strict5=ReconstructMenuElements items keys1;
    #  (keys2, reitems)      = strict5;
    #! strict3=(DelFromThisGroup 1 indexes els``);
    #  (keys3, els`)         = AddXGroupItemHandles keys2 w 
                                   strict3;
	#!	els`=els`;
    #  (keys4, reitems`)     = CreateXMenuItemHandles keys3 w reitems;
	#!	reitems`=reitems`;
		=
		(True,  keys4, [MenuItemGroupHandle (id`,w) els` : reitems`]);
   #!
		strict7=DelFromGroup` id indexes items keys;
   #   (ready, keys5, result)= strict7;
		=
		(ready, keys5, [item : result]);
DelFromGroup` id indexes [item : items] keys
   #!
      strict1=DelFromGroup` id indexes items keys;
   #
      (ready, keys`, items`)= strict1;
		=
		(ready, keys`, [item : items`]);
DelFromGroup` id indexes items keys =  (False, keys, items);

DelFromThisGroup :: !Int ![Int] ![MenuElement s (IOState s)]
   -> [MenuElement s (IOState s)];
DelFromThisGroup index indexes [item : items]
   | IdListContainsId indexes index =  DelFromThisGroup index` indexes items;
   #!
		strict1=strict1;
		=
		[item : strict1];
      where {
      index`=: inc index;
      strict1=DelFromThisGroup index` indexes items;
		};
DelFromThisGroup index indexes items =  items;

539
DelFromGroups :: ![MenuItemId] !(DeviceSystemState s) -> DeviceSystemState s;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
DelFromGroups ids (MenuSystemState w (keys, menuhandles, able))
   #!
		strict1=strict1;
		=
		MenuSystemState w strict1;
	where {
	strict1=(DelFromGroups` ids menuhandles keys able);
		
	};

DelFromGroups` :: ![MenuItemId] ![MenuHandle s (IOState s)] ![KeyShortcut] !Bool
   -> MenuHandles s (IOState s);
DelFromGroups` ids [menu=: PullDownHandle ability xh items : menus] keys able
   #!	strict3=DelFromGroups`` ids items keys;
   #   (keys``,items`)   = strict3;
   #!
      strict2=DelFromGroups`  ids menus keys`` able;
   #   (keys`, menus`, b)= strict2;
		items`=items`;
		=
		(keys`, [PullDownHandle ability xh items` : menus`], able);
DelFromGroups` ids menus keys able =  (keys, menus, able);

DelFromGroups`` :: ![MenuItemId] ![MenuItemHandle s (IOState s)] ![KeyShortcut]
   -> (![KeyShortcut], ![MenuItemHandle s (IOState s)]);
DelFromGroups`` ids [MenuItemGroupHandle (id`,w) els : items] keys
   #!
		strict7=ReconstructMenuElements els keys;
   #   (keys1, els``)   = strict7;
	#!	els``=els``;
		strict6=ReconstructMenuElements items keys1;
   #   (keys2, reitems) = strict6;
	#!	strict4=(RemoveFromThisGroup ids els``);
    #  (keys3, els`)    = AddXGroupItemHandles keys2 w 
                             strict4;
	#!	els`=els`;
    #  (keys4, reitems`)= CreateXMenuItemHandles keys3 w reitems;
    #!  strict3=DelFromGroups`` ids reitems` keys4;
    #  (keys5, items`)  = strict3;
	#!	items`=items`;
		=
		(keys5, [MenuItemGroupHandle (id`,w) els` : items`]);
DelFromGroups`` ids [item : items] keys
   #!
      strict1=DelFromGroups`` ids items keys;
   #
      (keys`, items`)= strict1;
		=
		(keys`, [item : items`]);
DelFromGroups`` ids items keys =  (keys, items);

RemoveFromThisGroup :: ![MenuItemId] ![MenuElement s (IOState s)]
   -> [MenuElement s (IOState s)];
RemoveFromThisGroup ids [item=: MenuItem id s k a f : items]
   | IdListContainsId ids id =  RemoveFromThisGroup ids items;
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=RemoveFromThisGroup ids items;
		
	};
RemoveFromThisGroup ids [item=: CheckMenuItem id s k a m f : items]
   | IdListContainsId ids id =  RemoveFromThisGroup ids items;
   #!
		strict1=strict1;
		=
		[item: strict1];
	where {
	strict1=RemoveFromThisGroup ids items;
		
	};
RemoveFromThisGroup ids [item : items]
   #!
		strict1=strict1;
		=
		[item : strict1];
	where {
	strict1=RemoveFromThisGroup ids items;
		
	};
RemoveFromThisGroup ids items =  items;

ReconstructMenuElements :: ![MenuItemHandle s (IOState s)] ![KeyShortcut]
   -> (![KeyShortcut], ![MenuElement s (IOState s)]);
ReconstructMenuElements [ItemHandle (id,w) f : items] keys 
   #
628
      info            = get_item_info w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
      (keys` , item  )= ConvertItemHandle info id f keys;
   #!
		strict2=ReconstructMenuElements items keys`;
   #    (keys``, items`)= strict2;
   #!
      strict1=DestroyOld item w;
		=
		(keys``, [strict1 : items`]);
ReconstructMenuElements [MenuSeparatorHandle w : items] keys
   #!
		strict2=ReconstructMenuElements items keys;
   #   (keys`, items`)= strict2;
   #!   strict1=DestroyOld MenuSeparator w;
		=
		(keys`, [strict1 : items`]);
ReconstructMenuElements [SubMenuHandle (id,w) handles : items] keys
   #!
		strict3=ReconstructMenuElements handles keys;
    #  (keys` , subitems)= strict3;
	#!	strict2=ReconstructMenuElements items keys`;
   #   (keys``, items`  )= strict2;
650
      (title, ability)  = get_submenu_info w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
      ability`          = if (ability == 0) Unable Able;
   #!   strict1=DestroyOld (SubMenuItem id title ability` subitems) w;
		=
		(keys``, [strict1 : items`]);
ReconstructMenuElements [MenuItemGroupHandle (id,w) handles : items] keys
   #!
		strict2=ReconstructMenuElements handles keys;
   #
      (keys` , subitems)= strict2;
   #!
      strict1=ReconstructMenuElements items keys`;
   #
      (keys``, items`  )= strict1;
		=
		(keys``, [MenuItemGroup id subitems : items`]);
ReconstructMenuElements [RadioHandle id radios : items] keys
   #!
		strict2=ReconstructRadioElements 0 radios keys;
   #
      (did, keys`, radios`)= strict2;
   #!
      strict1=ReconstructMenuElements items keys`;
   #
      (keys``, items`)     = strict1;
		=
		(keys``, [MenuRadioItems did radios` : items`]);
ReconstructMenuElements items keys =  (keys, []);

ReconstructRadioElements :: !Int ![RadioMenuItemHandle s (IOState s)]
      ![KeyShortcut]
   -> (!Int, ![KeyShortcut], ![RadioElement s (IOState s)]);
ReconstructRadioElements did [RadioItemHandle (id,w) f : items] keys
   #!
684
      info                  = get_item_info w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
685 686 687 688 689 690 691 692 693 694
		strict3=ConvertRadioItemHandle info id f keys;
    #  (id` , keys` , item  )= strict3;
	#!	strict2=ReconstructRadioElements id` items keys`;
   #   (id``, keys``, items`)= strict2;
    #!  strict1=DestroyOld item w;
		=
		(id``, keys``, [strict1 : items`]);
ReconstructRadioElements did items keys =  (did, keys, []);

DestroyOld :: !x !Widget -> x;
695
DestroyOld x w =  Evaluate_2 x (destroy_item_widget w);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732

ConvertItemHandle :: !(!Int, !Int, !String, !String) !Int
      !(MenuFunction s (IOState s)) ![KeyShortcut]
   -> (![KeyShortcut], MenuElement s (IOState s));
ConvertItemHandle (ability,-1,title,key) id f keys
   =  (keys`, MenuItem id title key` ability` f);
      where {
      keys`   =: RemoveKey key` keys;
      key`    =: if (key == "") NoKey (Key (key.[0]));
      ability`=: if (ability == 0) Unable Able;
      };
ConvertItemHandle (ability,state,title,key) id f keys
   =  (keys`, CheckMenuItem id title key` ability` state` f);
      where {
      keys`   =: RemoveKey key` keys;
      key`    =: if (key == "") NoKey (Key (key.[0]));
      ability`=: if (ability == 0) Unable Able;
      state`  =: if (state == 0) NoMark Mark;
      };

ConvertRadioItemHandle :: !(!Int, !Int, !String, !String) !Int
      !(MenuFunction s (IOState s)) ![KeyShortcut]
   -> (!Int, ![KeyShortcut], RadioElement s (IOState s));
ConvertRadioItemHandle (ability,state,title,key) id f keys
   | state == 1 =  (id, keys`, radio);
   =  (0,  keys`, radio);
      where {
      keys`   =: RemoveKey key` keys;
      key`    =: if (key == "") NoKey (Key (key.[0]));
      ability`=: if (ability == 0) Unable Able;
      radio=:MenuRadioItem id title key` ability` f;
		};


/* Controlling the appearance of menus and items.
*/
CheckXWidget :: !Widget !MarkState -> Widget;
733 734
CheckXWidget w Mark =  check_widget w XMark ;
CheckXWidget w NoMark =  check_widget w XNoMark;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
735 736

SetWidgetAbility :: !Widget !SelectState -> Widget;
737 738
SetWidgetAbility w Able =  enable_menu_widget w ;
SetWidgetAbility w Unable =  disable_menu_widget w;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
739 740 741 742 743 744 745 746 747

SetMenuAbility :: !Widget !SelectState -> Widget;
SetMenuAbility w state =  SetWidgetAbility w state;


/* Disposing a MenuSystem, i.e. destroying the corresponding widgettree!
*/
DisposeMenuSystemState :: !(DeviceSystemState s) -> DeviceSystemState s;
DisposeMenuSystemState (MenuSystemState w handles)
748
   =  Evaluate_2 (MenuSystemState 0 ([],[],True)) (destroy_menu w);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
749 750 751 752

/* (Un)drawing a MenuSystem (menubar),i.e. (un)managing widgets.
*/
ClearMenuSystem :: !(DeviceSystemState s) -> DeviceSystemState s;
753
ClearMenuSystem h=:(MenuSystemState w handles) =  Evaluate_2 h (hide_menu w);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
754

755
DrawMenuSystem :: !(DeviceSystemState s) -> DeviceSystemState s;
756
DrawMenuSystem h=:(MenuSystemState w handles) =  Evaluate_2 h (show_menu w);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
757 758 759 760 761


/* Installing key shortcuts.
*/
InstallKeyShortcut :: !Widget !KeyShortcut -> Widget;
762
InstallKeyShortcut w (Key c) =  install_shortcut w (toString c);
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
763 764
InstallKeyShortcut w key =  w;

765
AddKey :: !KeyShortcut ![KeyShortcut] -> [KeyShortcut];
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
AddKey NoKey keys =  keys;
AddKey key keys =  [key : keys];

CorrectKeyShortcut :: !KeyShortcut ![KeyShortcut] -> KeyShortcut;
CorrectKeyShortcut key=:(Key c) [Key c` : keys]
   | c == c` =  NoKey;
   =  CorrectKeyShortcut key keys;
CorrectKeyShortcut key keys =  key;

RemoveKey :: !KeyShortcut ![KeyShortcut] -> [KeyShortcut];
RemoveKey k=:(Key c) [k`=:Key c` : keys]
   | c == c` =  keys;
   #!
		strict1=strict1;
		=
		[k` : strict1];
	where {
	strict1=RemoveKey k keys;
		
	};
RemoveKey key keys =  keys;

IdListContainsId :: ![Int] !Int -> Bool;
IdListContainsId [id` : ids] id
      | id` == id=  True; 
   =  IdListContainsId ids id;
IdListContainsId ids id =  False;