Mercurial > dwindows
comparison os2/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 | b5a92b04b298 |
children | f4c9fa77136a |
comparison
equal
deleted
inserted
replaced
184:4ec906d40ce2 | 185:f55677513954 |
---|---|
3680 * id: An ID to be used for getting the resource from the | 3680 * id: An ID to be used for getting the resource from the |
3681 * resource file. | 3681 * resource file. |
3682 */ | 3682 */ |
3683 HMENUI API dw_menu_new(ULONG id) | 3683 HMENUI API dw_menu_new(ULONG id) |
3684 { | 3684 { |
3685 HMENUI tmp = malloc(sizeof(struct _hmenui)); | 3685 HMENUI tmp = WinCreateWindow(HWND_OBJECT, |
3686 | 3686 WC_MENU, |
3687 if(!tmp) | 3687 NULL, |
3688 return NULL; | 3688 WS_VISIBLE, |
3689 | 3689 0,0,2000,1000, |
3690 tmp->menu = WinCreateWindow(HWND_OBJECT, | 3690 NULLHANDLE, |
3691 WC_MENU, | 3691 HWND_TOP, |
3692 NULL, | 3692 id, |
3693 WS_VISIBLE, | 3693 NULL, |
3694 0,0,2000,1000, | 3694 NULL); |
3695 NULLHANDLE, | |
3696 HWND_TOP, | |
3697 id, | |
3698 NULL, | |
3699 NULL); | |
3700 return tmp; | 3695 return tmp; |
3701 } | 3696 } |
3702 | 3697 |
3703 /* | 3698 /* |
3704 * Create a menubar on a window. | 3699 * Create a menubar on a window. |
3705 * Parameters: | 3700 * Parameters: |
3706 * location: Handle of a window frame to be attached to. | 3701 * location: Handle of a window frame to be attached to. |
3707 */ | 3702 */ |
3708 HMENUI API dw_menubar_new(HWND location) | 3703 HMENUI API dw_menubar_new(HWND location) |
3709 { | 3704 { |
3710 HMENUI tmp = malloc(sizeof(struct _hmenui)); | 3705 HMENUI tmp = WinCreateWindow(location, |
3711 | 3706 WC_MENU, |
3712 if(!tmp) | 3707 NULL, |
3713 return NULL; | 3708 WS_VISIBLE | MS_ACTIONBAR, |
3714 | 3709 0,0,2000,1000, |
3715 tmp->menu = WinCreateWindow(location, | 3710 location, |
3716 WC_MENU, | 3711 HWND_TOP, |
3717 NULL, | 3712 FID_MENU, |
3718 WS_VISIBLE | MS_ACTIONBAR, | 3713 NULL, |
3719 0,0,2000,1000, | 3714 NULL); |
3720 location, | |
3721 HWND_TOP, | |
3722 FID_MENU, | |
3723 NULL, | |
3724 NULL); | |
3725 return tmp; | 3715 return tmp; |
3726 } | 3716 } |
3727 | 3717 |
3728 /* | 3718 /* |
3729 * Destroys a menu created with dw_menubar_new or dw_menu_new. | 3719 * Destroys a menu created with dw_menubar_new or dw_menu_new. |
3730 * Parameters: | 3720 * Parameters: |
3731 * menu: Handle of a menu. | 3721 * menu: Handle of a menu. |
3732 */ | 3722 */ |
3733 void API dw_menu_destroy(HMENUI *menu) | 3723 void API dw_menu_destroy(HMENUI *menu) |
3734 { | 3724 { |
3735 if(menu && *menu) | 3725 if(menu) |
3736 { | 3726 WinDestroyWindow(*menu); |
3737 WinDestroyWindow((*menu)->menu); | |
3738 free(*menu); | |
3739 *menu = NULL; | |
3740 } | |
3741 } | 3727 } |
3742 | 3728 |
3743 /* | 3729 /* |
3744 * Adds a menuitem or submenu to an existing menu. | 3730 * Adds a menuitem or submenu to an existing menu. |
3745 * Parameters: | 3731 * Parameters: |
3752 * submenu: Handle to an existing menu to be a submenu or NULL. | 3738 * submenu: Handle to an existing menu to be a submenu or NULL. |
3753 */ | 3739 */ |
3754 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) | 3740 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) |
3755 { | 3741 { |
3756 MENUITEM miSubMenu; | 3742 MENUITEM miSubMenu; |
3757 HWND menu; | |
3758 | 3743 |
3759 if(!menux) | 3744 if(!menux) |
3760 return NULLHANDLE; | 3745 return NULLHANDLE; |
3761 | |
3762 menu = menux->menu; | |
3763 | 3746 |
3764 if(end) | 3747 if(end) |
3765 miSubMenu.iPosition=MIT_END; | 3748 miSubMenu.iPosition=MIT_END; |
3766 else | 3749 else |
3767 miSubMenu.iPosition=0; | 3750 miSubMenu.iPosition=0; |
3770 miSubMenu.afStyle=MIS_SEPARATOR | flags; | 3753 miSubMenu.afStyle=MIS_SEPARATOR | flags; |
3771 else | 3754 else |
3772 miSubMenu.afStyle=MIS_TEXT | flags; | 3755 miSubMenu.afStyle=MIS_TEXT | flags; |
3773 miSubMenu.afAttribute=0; | 3756 miSubMenu.afAttribute=0; |
3774 miSubMenu.id=id; | 3757 miSubMenu.id=id; |
3775 miSubMenu.hwndSubMenu = submenu ? submenu->menu : 0; | 3758 miSubMenu.hwndSubMenu = submenu; |
3776 miSubMenu.hItem=NULLHANDLE; | 3759 miSubMenu.hItem=NULLHANDLE; |
3777 | 3760 |
3778 WinSendMsg(menu, | 3761 WinSendMsg(menux, |
3779 MM_INSERTITEM, | 3762 MM_INSERTITEM, |
3780 MPFROMP(&miSubMenu), | 3763 MPFROMP(&miSubMenu), |
3781 MPFROMP(title)); | 3764 MPFROMP(title)); |
3782 if(submenu) | |
3783 free(submenu); | |
3784 return (HWND)id; | 3765 return (HWND)id; |
3785 } | 3766 } |
3786 | 3767 |
3787 /* | 3768 /* |
3788 * Sets the state of a menu item check. | 3769 * Sets the state of a menu item check. |
3791 * id: Menuitem id. | 3772 * id: Menuitem id. |
3792 * check: TRUE for checked FALSE for not checked. | 3773 * check: TRUE for checked FALSE for not checked. |
3793 */ | 3774 */ |
3794 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) | 3775 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) |
3795 { | 3776 { |
3796 HWND menu; | |
3797 | |
3798 if(!menux) | |
3799 return; | |
3800 | |
3801 menu = menux->menu; | |
3802 | |
3803 if(check) | 3777 if(check) |
3804 WinSendMsg(menu, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), | 3778 WinSendMsg(menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), |
3805 MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)); | 3779 MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)); |
3806 else | 3780 else |
3807 WinSendMsg(menu, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), | 3781 WinSendMsg(menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), |
3808 MPFROM2SHORT(MIA_CHECKED, 0)); | 3782 MPFROM2SHORT(MIA_CHECKED, 0)); |
3809 } | 3783 } |
3810 | 3784 |
3811 /* | 3785 /* |
3812 * Pops up a context menu at given x and y coordinates. | 3786 * Pops up a context menu at given x and y coordinates. |
3816 * x: X coordinate. | 3790 * x: X coordinate. |
3817 * y: Y coordinate. | 3791 * y: Y coordinate. |
3818 */ | 3792 */ |
3819 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) | 3793 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) |
3820 { | 3794 { |
3821 if(menu && *menu) | 3795 if(menu) |
3822 { | 3796 { |
3823 popup = parent; | 3797 popup = parent; |
3824 WinPopupMenu(HWND_DESKTOP, parent, (*menu)->menu, x, dw_screen_height() - y, 0, PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_VCONSTRAIN | PU_HCONSTRAIN); | 3798 WinPopupMenu(HWND_DESKTOP, parent, *menu, x, dw_screen_height() - y, 0, PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_VCONSTRAIN | PU_HCONSTRAIN); |
3825 free(*menu); | |
3826 *menu = NULL; | |
3827 } | 3799 } |
3828 } | 3800 } |
3829 | 3801 |
3830 /* | 3802 /* |
3831 * Returns the current X and Y coordinates of the mouse pointer. | 3803 * Returns the current X and Y coordinates of the mouse pointer. |