Mercurial > dwindows
comparison win/dw.c @ 185:f55677513954
Updated the menu code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 19 Dec 2002 04:16:32 +0000 |
parents | b8caec82a4d2 |
children | 634625c3239d |
comparison
equal
deleted
inserted
replaced
184:4ec906d40ce2 | 185:f55677513954 |
---|---|
3569 * id: An ID to be used for getting the resource from the | 3569 * id: An ID to be used for getting the resource from the |
3570 * resource file. | 3570 * resource file. |
3571 */ | 3571 */ |
3572 HMENUI API dw_menu_new(ULONG id) | 3572 HMENUI API dw_menu_new(ULONG id) |
3573 { | 3573 { |
3574 HMENUI tmp = malloc(sizeof(struct _hmenui)); | 3574 HMENUI tmp; |
3575 | 3575 |
3576 if(!tmp) | 3576 tmp.menu = CreatePopupMenu(); |
3577 return NULL; | 3577 tmp.hwnd = NULL; |
3578 | |
3579 tmp->menu = CreatePopupMenu(); | |
3580 tmp->hwnd = NULL; | |
3581 return tmp; | 3578 return tmp; |
3582 } | 3579 } |
3583 | 3580 |
3584 /* | 3581 /* |
3585 * Create a menubar on a window. | 3582 * Create a menubar on a window. |
3586 * Parameters: | 3583 * Parameters: |
3587 * location: Handle of a window frame to be attached to. | 3584 * location: Handle of a window frame to be attached to. |
3588 */ | 3585 */ |
3589 HMENUI API dw_menubar_new(HWND location) | 3586 HMENUI API dw_menubar_new(HWND location) |
3590 { | 3587 { |
3591 HMENUI tmp = malloc(sizeof(struct _hmenui)); | 3588 HMENUI tmp; |
3592 | 3589 |
3593 if(!tmp) | 3590 tmp.menu = CreateMenu(); |
3594 return NULL; | 3591 tmp.hwnd = location; |
3595 | 3592 |
3596 tmp->menu = CreateMenu(); | 3593 SetMenu(location, tmp.menu); |
3597 tmp->hwnd = location; | |
3598 | |
3599 SetMenu(location, tmp->menu); | |
3600 return tmp; | 3594 return tmp; |
3601 } | 3595 } |
3602 | 3596 |
3603 /* | 3597 /* |
3604 * Destroys a menu created with dw_menubar_new or dw_menu_new. | 3598 * Destroys a menu created with dw_menubar_new or dw_menu_new. |
3605 * Parameters: | 3599 * Parameters: |
3606 * menu: Handle of a menu. | 3600 * menu: Handle of a menu. |
3607 */ | 3601 */ |
3608 void API dw_menu_destroy(HMENUI *menu) | 3602 void API dw_menu_destroy(HMENUI *menu) |
3609 { | 3603 { |
3610 if(menu && *menu) | 3604 if(menu) |
3611 { | 3605 DestroyMenu(menu->menu); |
3612 DestroyMenu((*menu)->menu); | |
3613 free(*menu); | |
3614 *menu = NULL; | |
3615 } | |
3616 } | 3606 } |
3617 | 3607 |
3618 /* | 3608 /* |
3619 * Adds a menuitem or submenu to an existing menu. | 3609 * Adds a menuitem or submenu to an existing menu. |
3620 * Parameters: | 3610 * Parameters: |
3627 * submenu: Handle to an existing menu to be a submenu or NULL. | 3617 * submenu: Handle to an existing menu to be a submenu or NULL. |
3628 */ | 3618 */ |
3629 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) | 3619 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) |
3630 { | 3620 { |
3631 MENUITEMINFO mii; | 3621 MENUITEMINFO mii; |
3632 HMENU menu; | |
3633 | |
3634 if(!menux) | |
3635 return NULL; | |
3636 | |
3637 menu = menux->menu; | |
3638 | 3622 |
3639 mii.cbSize = sizeof(MENUITEMINFO); | 3623 mii.cbSize = sizeof(MENUITEMINFO); |
3640 mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_TYPE; | 3624 mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_TYPE; |
3641 | 3625 |
3642 /* Convert from OS/2 style accellerators to Win32 style */ | 3626 /* Convert from OS/2 style accellerators to Win32 style */ |
3656 mii.fType = MFT_STRING; | 3640 mii.fType = MFT_STRING; |
3657 else | 3641 else |
3658 mii.fType = MFT_SEPARATOR; | 3642 mii.fType = MFT_SEPARATOR; |
3659 | 3643 |
3660 mii.wID = id; | 3644 mii.wID = id; |
3661 mii.hSubMenu = submenu ? submenu->menu : 0; | 3645 mii.hSubMenu = submenu.menu; |
3662 mii.dwTypeData = title; | 3646 mii.dwTypeData = title; |
3663 mii.cch = strlen(title); | 3647 mii.cch = strlen(title); |
3664 | 3648 |
3665 InsertMenuItem(menu, 65535, TRUE, &mii); | 3649 InsertMenuItem(menux.menu, 65535, TRUE, &mii); |
3666 if(menux->hwnd) | 3650 if(menux.hwnd) |
3667 DrawMenuBar(menux->hwnd); | 3651 DrawMenuBar(menux.hwnd); |
3668 if(submenu) | |
3669 free(submenu); | |
3670 return (HWND)id; | 3652 return (HWND)id; |
3671 } | 3653 } |
3672 | 3654 |
3673 /* | 3655 /* |
3674 * Sets the state of a menu item check. | 3656 * Sets the state of a menu item check. |
3678 * check: TRUE for checked FALSE for not checked. | 3660 * check: TRUE for checked FALSE for not checked. |
3679 */ | 3661 */ |
3680 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) | 3662 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) |
3681 { | 3663 { |
3682 MENUITEMINFO mii; | 3664 MENUITEMINFO mii; |
3683 HMENU menu; | |
3684 | |
3685 if(!menux) | |
3686 return; | |
3687 | |
3688 menu = menux->menu; | |
3689 | 3665 |
3690 mii.cbSize = sizeof(MENUITEMINFO); | 3666 mii.cbSize = sizeof(MENUITEMINFO); |
3691 mii.fMask = MIIM_STATE; | 3667 mii.fMask = MIIM_STATE; |
3692 if(check) | 3668 if(check) |
3693 mii.fState = MFS_CHECKED; | 3669 mii.fState = MFS_CHECKED; |
3694 else | 3670 else |
3695 mii.fState = MFS_UNCHECKED; | 3671 mii.fState = MFS_UNCHECKED; |
3696 SetMenuItemInfo(menu, id, FALSE, &mii); | 3672 SetMenuItemInfo(menux.menu, id, FALSE, &mii); |
3697 } | 3673 } |
3698 | 3674 |
3699 /* | 3675 /* |
3700 * Pops up a context menu at given x and y coordinates. | 3676 * Pops up a context menu at given x and y coordinates. |
3701 * Parameters: | 3677 * Parameters: |
3704 * x: X coordinate. | 3680 * x: X coordinate. |
3705 * y: Y coordinate. | 3681 * y: Y coordinate. |
3706 */ | 3682 */ |
3707 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) | 3683 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) |
3708 { | 3684 { |
3709 if(menu && *menu) | 3685 if(menu) |
3710 { | 3686 { |
3711 popup = parent; | 3687 popup = parent; |
3712 TrackPopupMenu((*menu)->menu, 0, x, y, 0, parent, NULL); | 3688 TrackPopupMenu(menu->menu, 0, x, y, 0, parent, NULL); |
3713 DestroyMenu((*menu)->menu); | 3689 DestroyMenu(menu->menu); |
3714 free(*menu); | |
3715 *menu = NULL; | |
3716 } | 3690 } |
3717 } | 3691 } |
3718 | 3692 |
3719 | 3693 |
3720 /* | 3694 /* |