home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-04-23 | 7.4 KB | 197 lines | [TEXT/3PRM] |
- implementation module menuInternal;
-
- import StdClass, StdMisc, StdChar, StdInt, StdString, StdBool,StdArray;
- import menus;
- import ioState;
-
- AppleMenuId :== 128;
-
- SystemAble :== True;
- SystemUnable :== False;
-
- MenuInternalError :: String String -> * x;
- MenuInternalError rule error = Error rule "menuInternal" error;
-
- // Initialization and Allocation:
-
- AppleMenu :: !Toolbox -> (!MenuHandle s, !Toolbox);
- AppleMenu tb
- = InsertAppleMenu menuH tb1;
- where {
- (menuH, tb1) = NewMenuHandle (PullDownMenu AppleMenuId AppleString Able []) AppleMenuId tb;
- };
-
- InsertAppleMenu :: !(MenuHandle s) !Toolbox -> (!MenuHandle s, !Toolbox);
- InsertAppleMenu menuH=:(PullDownHandle menu id macId able items) tb
- = (menuH, tb4);
- where {
- tb1 = AppendMenu menu "About..." tb;
- tb2 = AppendMenu menu "-(" tb1;
- tb3 = AddResMenu menu DriverType tb2;
- tb4 = InsertMenu menu InsertPullDownPosition tb3;
- };
-
- DriverType :: Int;
- DriverType = s4;
- where {
- s3 = toInt 'V' + s2 << 8;
- s2 = toInt 'R' + s1 << 8;
- s1 = toInt 'D';
- s4 = toInt 'R' + s3 << 8;
- };
-
- AppleString :: String;
- AppleString = toString (toChar 20);
-
- EmptyMenuHandle :: !MenuId !Toolbox -> (!MenuHandle s, !Toolbox);
- EmptyMenuHandle macId tb
- = (PullDownHandle menu macId macId Unable [], tb1);
- where {
- (menu, tb1) = NewMenu macId "" tb;
- };
-
- NewMenuHandle :: !(MenuDef s (IOState s)) !MenuId !Toolbox -> (!MenuHandle s, !Toolbox);
- NewMenuHandle (PullDownMenu menuId title select items) macId tb
- | Enabled select = (menuH, EnableItem menu 0 tb1);
- = (menuH, DisableItem menu 0 tb1);
- where {
- menuH = PullDownHandle menu menuId macId select [];
- (menu, tb1) = NewMenu macId title tb;
- };
-
- NewMenuElementHandle :: !(MenuElement s (IOState s)) !MenuId !Toolbox -> (!MenuHandle s, !Toolbox);
- NewMenuElementHandle (SubMenuItem menuId title select items) mId tb
- | Enabled select = (SubMenuItemHandle menu menuId mId [], EnableItem menu 0 tb1);
- = (SubMenuItemHandle menu menuId mId [], DisableItem menu 0 tb1);
- where {
- (menu,tb1) = NewMenu mId title tb;
- };
- NewMenuElementHandle (MenuItem id _ c _ f) _ tb = (MenuItemHandle id (KeyCHAR c) f, tb);
- NewMenuElementHandle (CheckMenuItem id _ c _ _ f) _ tb = (CheckMenuItemHandle id (KeyCHAR c) f, tb);
- NewMenuElementHandle (MenuItemGroup id _) _ tb = (MenuItemGroupHandle id [], tb);
- NewMenuElementHandle (MenuRadioItems _ _) _ tb = (MenuRadioItemsHandle [], tb);
- NewMenuElementHandle MenuSeparator _ tb = (MenuSeparatorHandle, tb);
-
- KeyCHAR :: !KeyShortcut -> Char;
- KeyCHAR (Key c) = c;
- KeyCHAR key = '0';
-
- DisposeMenuHandles :: ![MenuHandle s] !Toolbox -> Toolbox;
- DisposeMenuHandles [PullDownHandle menu menuId macId able items : m_and_hs] tb
- = DisposeMenuHandles m_and_hs (DisposeMenu menu tb);
- DisposeMenuHandles m_and_hs tb = tb;
-
- DisposeMenuSystemState :: !(DeviceSystemState s) !Toolbox -> Toolbox;
- DisposeMenuSystemState (MenuSystemState (menus, cuts, handle, systemAble)) tb
- = DrawMenuBar (ClearMenuBar (DisposeMenuHandles menus tb));
- DisposeMenuSystemState _ _
- = MenuInternalError "DisposeMenuSystemState" "argument is no MenuSystemState";
-
-
- // Forming the MenuBar:
-
- InsertPullDownPosition :== 0;
- InsertSubPosition :== -1;
-
- Insert_menu :: !(MenuHandle s) !Toolbox -> Toolbox;
- Insert_menu (PullDownHandle menu id macId able items) tb
- = InsertMenu menu InsertPullDownPosition tb;
- Insert_menu (SubMenuItemHandle menu id macId items) tb
- = InsertMenu menu InsertSubPosition tb;
-
- GetMenuSystem :: !(DeviceSystemState s) !Toolbox -> (!DeviceSystemState s, !Toolbox);
- GetMenuSystem (MenuSystemState (menus, cuts, menuBar`, systemAble)) tb
- = (MenuSystemState (menus, cuts, menuBar, systemAble), tb1);
- where {
- (menuBar, tb1) = GetMenuBar tb;
- };
-
- SetMenuSystem :: !(DeviceSystemState s) !Toolbox -> Toolbox;
- SetMenuSystem (MenuSystemState (_,_,menuBar,_)) tb = SetMenuBar menuBar tb;
-
-
- // Access-rules on MenuSystemStates:
-
- MenuSystemState_MenuFunction :: !MenuId !Int !(DeviceSystemState s)
- -> (!Bool, !MenuFunction s (IOState s));
- MenuSystemState_MenuFunction menu_id item_nr (MenuSystemState (menus, cuts, handle, system_able))
- = MenuHandles_MenuFunction menu_id item_nr menus;
-
- MenuHandles_MenuFunction :: !MenuId !Int ![MenuHandle s] -> (!Bool, !MenuFunction s (IOState s));
- MenuHandles_MenuFunction menu_id item_nr [PullDownHandle handle id mac_id able items : handles]
- | menu_id == mac_id = MenuElements_MenuFunction item_nr items;
- | not in_here = MenuHandles_MenuFunction menu_id item_nr handles;
- = in_here_f;
- where {
- (in_here, f)= in_here_f;
- in_here_f = SubMenuHandles_MenuFunction menu_id item_nr items;
- };
- MenuHandles_MenuFunction menu_id _ _
- = MenuInternalError "MenuHandles_MenuFunction" ("unknown MenuId: " +++ toString menu_id);
-
- SubMenuHandles_MenuFunction :: !MenuId !Int ![MenuHandle s] -> (!Bool, !MenuFunction s (IOState s));
- SubMenuHandles_MenuFunction menu_id item_nr [SubMenuItemHandle handle id mac_id items : handles]
- | menu_id == mac_id = MenuElements_MenuFunction item_nr items;
- | not in_here = SubMenuHandles_MenuFunction menu_id item_nr handles;
- = in_here_f;
- where {
- (in_here, f)= in_here_f;
- in_here_f = SubMenuHandles_MenuFunction menu_id item_nr items;
- };
- SubMenuHandles_MenuFunction menu_id item_nr [MenuItemGroupHandle id items : handles]
- = SubMenuHandles_MenuFunction menu_id item_nr (Concat items handles);
- SubMenuHandles_MenuFunction menu_id item_nr [MenuRadioItemsHandle items : handles]
- = SubMenuHandles_MenuFunction menu_id item_nr (Concat items handles);
- SubMenuHandles_MenuFunction menu_id item_nr [item_handle : handles]
- = SubMenuHandles_MenuFunction menu_id item_nr handles;
- SubMenuHandles_MenuFunction menu_id item_nr handles = (False, LazyMenuFunction);
-
- MenuElements_MenuFunction :: !Int ![MenuHandle s] -> (!Bool, !MenuFunction s (IOState s));
- MenuElements_MenuFunction 1 [MenuItemHandle _ _ f : _] = (True, f);
- MenuElements_MenuFunction 1 [CheckMenuItemHandle _ _ f : _] = (True, f);
- MenuElements_MenuFunction 1 [MenuSeparatorHandle : _] = (False,LazyMenuFunction);
- MenuElements_MenuFunction v [MenuItemGroupHandle _ items : handles]
- = MenuElements_MenuFunction v (Concat items handles);
- MenuElements_MenuFunction v [MenuRadioItemsHandle items : handles]
- = MenuElements_MenuFunction v (Concat items handles);
- MenuElements_MenuFunction v [_ : handles]
- = MenuElements_MenuFunction (dec v) handles;
- MenuElements_MenuFunction v _
- = MenuInternalError "MenuElements_MenuFunction" ("illegal index value v: " +++ toString v);
-
- LazyMenuFunction :: *s (IOState *s) -> (*s, IOState *s);
- LazyMenuFunction s ioState = (s, ioState);
-
- SplitMenuHandle :: !(MenuHandle s) !Int -> (![MenuHandle s], !MenuHandle s);
- SplitMenuHandle (PullDownHandle handle id mac_id able items) number
- = (back_items, PullDownHandle handle id mac_id able front_items);
- where {
- (front_items, back_items) = SplitMenuElements items number;
- };
- SplitMenuHandle (SubMenuItemHandle handle id mac_id items) number
- = (back_items, SubMenuItemHandle handle id mac_id front_items);
- where {
- (front_items, back_items) = SplitMenuElements items number;
- };
- SplitMenuHandle handle _ = ([], handle);
-
- SplitMenuElements :: ![MenuHandle s] !Int -> (![MenuHandle s], ![MenuHandle s]);
- SplitMenuElements items=:[h : hs] n
- | n < 1 = ([], items);
- = ([h : front_hs], back_hs);
- where {
- (front_hs, back_hs) = SplitMenuElements hs (dec n);
- };
- SplitMenuElements _ _ = ([], []);
-
-
- /* CheckItemTitle transforms the item-title when it's empty or when it begins
- with a hyphen. */
-
- CheckItemTitle :: !String -> String;
- CheckItemTitle "" = " ";
- CheckItemTitle str
- | str.[0] <> '-'
- = str;
- = str := (0,'\320');
-