diff options
Diffstat (limited to 'app/wlib/mswlib/mswmenu.c')
-rw-r--r-- | app/wlib/mswlib/mswmenu.c | 694 |
1 files changed, 362 insertions, 332 deletions
diff --git a/app/wlib/mswlib/mswmenu.c b/app/wlib/mswlib/mswmenu.c index d56e24d..0a2851d 100644 --- a/app/wlib/mswlib/mswmenu.c +++ b/app/wlib/mswlib/mswmenu.c @@ -18,20 +18,18 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define OEMRESOURCE #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> #include <ctype.h> #include <assert.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" @@ -49,8 +47,8 @@ typedef enum { MM_BUTT, MM_MENU, MM_BAR, MM_POPUP } mmtype_e; typedef struct wMenuItem_t * wMenuItem_p; struct radioButtonGroup { - int firstButton; /* id of first button in group */ - int lastButton; /* id of last button in group */ + int firstButton; /* id of first button in group */ + int lastButton; /* id of last button in group */ }; /* NOTE: first field must be the same as WOBJ_COMMON */ @@ -62,58 +60,58 @@ struct radioButtonGroup { wMenuItem_p mnext; struct wMenuItem_t { - MOBJ_COMMON - }; + MOBJ_COMMON +}; struct wMenu_t { - MOBJ_COMMON - mmtype_e mmtype; - wMenuItem_p first, last; - struct radioButtonGroup *radioGroup; - HMENU menu; - wButton_p button; - wMenuTraceCallBack_p traceFunc; - void * traceData; - }; + MOBJ_COMMON + mmtype_e mmtype; + wMenuItem_p first, last; + struct radioButtonGroup *radioGroup; + HMENU menu; + wButton_p button; + wMenuTraceCallBack_p traceFunc; + void * traceData; +}; struct wMenuPush_t { - MOBJ_COMMON - wMenu_p mparent; - wMenuCallBack_p action; - long acclKey; - wBool_t enabled; - }; + MOBJ_COMMON + wMenu_p mparent; + wMenuCallBack_p action; + long acclKey; + wBool_t enabled; +}; struct wMenuRadio_t { - MOBJ_COMMON - wMenu_p mparent; - wMenuCallBack_p action; - long acclKey; - wBool_t enabled; - }; + MOBJ_COMMON + wMenu_p mparent; + wMenuCallBack_p action; + long acclKey; + wBool_t enabled; +}; struct wMenuToggle_t { - MOBJ_COMMON - wMenu_p mparent; - wMenuToggleCallBack_p action; - long acclKey; - wBool_t enabled; - }; + MOBJ_COMMON + wMenu_p mparent; + wMenuCallBack_p action; + long acclKey; + wBool_t enabled; +}; typedef struct wMenuListItem_t * wMenuListItem_p; struct wMenuList_t { - MOBJ_COMMON - wMenuListItem_p left, right; - wMenu_p mlparent; - int max; - int count; - wMenuListCallBack_p action; - }; + MOBJ_COMMON + wMenuListItem_p left, right; + wMenu_p mlparent; + int max; + int count; + wMenuListCallBack_p action; +}; struct wMenuListItem_t { - MOBJ_COMMON - wMenuListItem_p left, right; - wMenuListCallBack_p action; - }; + MOBJ_COMMON + wMenuListItem_p left, right; + wMenuListCallBack_p action; +}; #define UNCHECK (0) #define CHECK (1) @@ -140,17 +138,18 @@ char * mswStrdup( const char * str ) if (str) { ret = (char*)malloc( strlen(str)+1 ); strcpy( ret, str ); - } else + } else { ret = NULL; + } return ret; } static LRESULT menuPush( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { wMenuItem_p m = (wMenuItem_p)b; wBool_t set; @@ -166,29 +165,34 @@ static LRESULT menuPush( mswFail( "pushMenu" ); break; case M_PUSH: - if (((wMenuPush_p)m)->action) + if (((wMenuPush_p)m)->action) { ((wMenuPush_p)m)->action(((wMenuPush_p)m)->data); + } break; case M_TOGGLE: set = wMenuToggleGet((wMenuToggle_p)m); set = !set; wMenuToggleSet((wMenuToggle_p)m,set); - if (((wMenuToggle_p)m)->action) - ((wMenuToggle_p)m)->action(set, ((wMenuPush_p)m)->data); + if (((wMenuToggle_p)m)->action) { + ((wMenuToggle_p)m)->action(((wMenuPush_p)m)->data); + } break; case M_LISTITEM: - if (((wMenuListItem_p)m)->action) + if (((wMenuListItem_p)m)->action) { ((wMenuListItem_p)m)->action(0, "", ((wMenuListItem_p)m)->data); + } break; case M_RADIO: - if (((wMenuRadio_p)m)->action) + if (((wMenuRadio_p)m)->action) { ((wMenuRadio_p)m)->action(((wMenuRadio_p)m)->data); + } break; } - return 0L; + return (LRESULT)0; } if ( (m->parentMenu)->traceFunc ) { - (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, ((wMenu_p)m->parentMenu)->traceData ); + (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, + ((wMenu_p)m->parentMenu)->traceData ); } return DefWindowProc( hWnd, message, wParam, lParam ); } @@ -199,24 +203,26 @@ static void menuDone( wControl_p b ) switch ( m->mtype ) { case M_MENU: if ( ((wMenu_p)m)->mmtype == MM_BUTT || - ((wMenu_p)m)->mmtype == MM_POPUP ) + ((wMenu_p)m)->mmtype == MM_POPUP ) { DestroyMenu( ((wMenu_p)m)->menu ); + } break; } } static callBacks_t menuItemCallBacks = { - NULL, - menuDone, - menuPush }; + NULL, + menuDone, + menuPush +}; static wMenuItem_p createMenuItem( - wMenu_p m, - mtype_e mtype, - const char * helpStr, - const char * labelStr, - int size ) + wMenu_p m, + mtype_e mtype, + const char * helpStr, + const char * labelStr, + int size ) { wMenuItem_p mi; @@ -255,29 +261,31 @@ static wMenuItem_p createMenuItem( typedef struct { - long acclKey; - wMenuPush_p mp; - wAccelKeyCallBack_p action; - wAccelKey_e key; - void * data; - } acclTable_t, *acclTable_p; -dynArr_t acclTable_da; + long acclKey; + wMenuPush_p mp; + wAccelKeyCallBack_p action; + wAccelKey_e key; + void * data; +} acclTable_t, *acclTable_p; +static dynArr_t acclTable_da; #define acclTable(N) DYNARR_N( acclTable_t, acclTable_da, N ) int mswMenuAccelerator( - wWin_p win, - long acclKey ) + wWin_p win, + long acclKey ) { acclTable_p at; if ( ((wControl_p)win)->type != W_MAIN && - ((wControl_p)win)->type != W_POPUP ) + ((wControl_p)win)->type != W_POPUP ) { return 0; + } for ( at = &acclTable(0); at<&acclTable(acclTable_da.cnt); at++ ) { if (at->acclKey == acclKey) { if (at->mp) { - if (at->mp->enabled && at->mp->action) + if (at->mp->enabled && at->mp->action) { at->mp->action(at->mp->data); + } return 1; } else if (at->action) { at->action( at->key, at->data ); @@ -293,40 +301,40 @@ int mswMenuAccelerator( static long acclKeyMap[] = { - 0, /* wAccelKey_None, */ - VK_DELETE, /* wAccelKey_Del, */ - VK_INSERT, /* wAccelKey_Ins, */ - VK_HOME, /* wAccelKey_Home, */ - VK_END, /* wAccelKey_End, */ - VK_PRIOR, /* wAccelKey_Pgup, */ - VK_NEXT, /* wAccelKey_Pgdn, */ - VK_UP, /* wAccelKey_Up, */ - VK_DOWN, /* wAccelKey_Down, */ - VK_RIGHT, /* wAccelKey_Right, */ - VK_LEFT, /* wAccelKey_Left, */ - VK_BACK, /* wAccelKey_Back, */ - VK_F1, /* wAccelKey_F1, */ - VK_F2, /* wAccelKey_F2, */ - VK_F3, /* wAccelKey_F3, */ - VK_F4, /* wAccelKey_F4, */ - VK_F5, /* wAccelKey_F5, */ - VK_F6, /* wAccelKey_F6, */ - VK_F7, /* wAccelKey_F7, */ - VK_F8, /* wAccelKey_F8, */ - VK_F9, /* wAccelKey_F9, */ - VK_F10, /* wAccelKey_F10, */ - VK_F11, /* wAccelKey_F11, */ - VK_F12, /* wAccelKey_F12, */ - VK_ADD, /* wAccelKey_Numpad_Add, */ - VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */ - }; + 0, /* wAccelKey_None, */ + VK_DELETE, /* wAccelKey_Del, */ + VK_INSERT, /* wAccelKey_Ins, */ + VK_HOME, /* wAccelKey_Home, */ + VK_END, /* wAccelKey_End, */ + VK_PRIOR, /* wAccelKey_Pgup, */ + VK_NEXT, /* wAccelKey_Pgdn, */ + VK_UP, /* wAccelKey_Up, */ + VK_DOWN, /* wAccelKey_Down, */ + VK_RIGHT, /* wAccelKey_Right, */ + VK_LEFT, /* wAccelKey_Left, */ + VK_BACK, /* wAccelKey_Back, */ + VK_F1, /* wAccelKey_F1, */ + VK_F2, /* wAccelKey_F2, */ + VK_F3, /* wAccelKey_F3, */ + VK_F4, /* wAccelKey_F4, */ + VK_F5, /* wAccelKey_F5, */ + VK_F6, /* wAccelKey_F6, */ + VK_F7, /* wAccelKey_F7, */ + VK_F8, /* wAccelKey_F8, */ + VK_F9, /* wAccelKey_F9, */ + VK_F10, /* wAccelKey_F10, */ + VK_F11, /* wAccelKey_F11, */ + VK_F12, /* wAccelKey_F12, */ + VK_ADD, /* wAccelKey_Numpad_Add, */ + VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */ +}; void wAttachAccelKey( - wAccelKey_e key, - int modifier, - wAccelKeyCallBack_p action, - void * data ) + wAccelKey_e key, + int modifier, + wAccelKeyCallBack_p action, + void * data ) { acclTable_t * ad; if ( key < 1 || key > wAccelKey_Numpad_Subtract ) { @@ -350,132 +358,133 @@ void wAttachAccelKey( ***************************************************************************** */ -HBITMAP GetMyCheckBitmaps(UINT fuCheck) -{ - COLORREF crBackground; /* background color */ - HBRUSH hbrBackground; /* background brush */ - HBRUSH hbrTargetOld; /* original background brush */ - HDC hdcSource; /* source device context */ - HDC hdcTarget; /* target device context */ - HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */ - BITMAP bmCheckbox; /* structure for bitmap data */ - HBITMAP hbmpSourceOld; /* handle to original source bitmap */ - HBITMAP hbmpTargetOld; /* handle to original target bitmap */ - HBITMAP hbmpCheck; /* handle to check-mark bitmap */ - RECT rc; /* rectangle for check-box bitmap */ - WORD wBitmapX; /* width of check-mark bitmap */ - WORD wBitmapY; /* height of check-mark bitmap */ - - /* Get the menu background color and create a solid brush - with that color. */ - - crBackground = GetSysColor(COLOR_MENU); - hbrBackground = CreateSolidBrush(crBackground); - - /* Create memory device contexts for the source and - destination bitmaps. */ - - hdcSource = CreateCompatibleDC((HDC) NULL); - hdcTarget = CreateCompatibleDC(hdcSource); - - /* Get the size of the system default check-mark bitmap and - create a compatible bitmap of the same size. */ - - wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); - wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); - - hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, - wBitmapY); - - /* Select the background brush and bitmap into the target DC. */ - - hbrTargetOld = SelectObject(hdcTarget, hbrBackground); - hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck); - - /* Use the selected brush to initialize the background color - of the bitmap in the target device context. */ - - PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY); - - /* Load the predefined check box bitmaps and select it - into the source DC. */ - - hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL, - (LPTSTR) OBM_CHECKBOXES); - - hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes); - - /* Fill a BITMAP structure with information about the - check box bitmaps, and then find the upper-left corner of - the unchecked check box or the checked check box. */ - - GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox); - +HBITMAP GetMyCheckBitmaps(UINT fuCheck) +{ + COLORREF crBackground; /* background color */ + HBRUSH hbrBackground; /* background brush */ + HBRUSH hbrTargetOld; /* original background brush */ + HDC hdcSource; /* source device context */ + HDC hdcTarget; /* target device context */ + HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */ + BITMAP bmCheckbox; /* structure for bitmap data */ + HBITMAP hbmpSourceOld; /* handle to original source bitmap */ + HBITMAP hbmpTargetOld; /* handle to original target bitmap */ + HBITMAP hbmpCheck; /* handle to check-mark bitmap */ + RECT rc; /* rectangle for check-box bitmap */ + WORD wBitmapX; /* width of check-mark bitmap */ + WORD wBitmapY; /* height of check-mark bitmap */ + WORD wMenuH; /* height of menu line */ + + /* Get the menu background color and create a solid brush + with that color. */ + + crBackground = GetSysColor(COLOR_MENU); + hbrBackground = CreateSolidBrush(crBackground); + + /* Create memory device contexts for the source and + destination bitmaps. */ + + hdcSource = CreateCompatibleDC((HDC) NULL); + hdcTarget = CreateCompatibleDC(hdcSource); + + /* Get the size of the system default check-mark bitmap and + create a compatible bitmap of the same size. */ + + wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); + wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); + wMenuH = GetSystemMetrics(SM_CYMENU); + + hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, + wBitmapY); + + /* Select the background brush and bitmap into the target DC. */ + + hbrTargetOld = SelectObject(hdcTarget, hbrBackground); + hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck); + + /* Use the selected brush to initialize the background color + of the bitmap in the target device context. */ + + PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY); + + /* Load the predefined check box bitmaps and select it + into the source DC. */ + + hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL, + (LPTSTR) OBM_CHECKBOXES); + + hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes); + + /* Fill a BITMAP structure with information about the + check box bitmaps, and then find the upper-left corner of + the unchecked check box or the checked check box. */ + + GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox); + switch( fuCheck ) { - + case UNCHECK: - rc.left = 0; - rc.right = (bmCheckbox.bmWidth / 4); - rc.top = 0; - rc.bottom = (bmCheckbox.bmHeight / 3); - break; - case CHECK: - rc.left = (bmCheckbox.bmWidth / 4); - rc.right = (bmCheckbox.bmWidth / 4) * 2; - rc.top = 0; - rc.bottom = (bmCheckbox.bmHeight / 3); + rc.left = 0; + rc.right = (bmCheckbox.bmWidth / 4); + rc.top = 0; + rc.bottom = (bmCheckbox.bmHeight / 3); + break; + case CHECK: + rc.left = (bmCheckbox.bmWidth / 4); + rc.right = (bmCheckbox.bmWidth / 4) * 2; + rc.top = 0; + rc.bottom = (bmCheckbox.bmHeight / 3); break; case RADIOCHECK: - rc.left = (bmCheckbox.bmWidth / 4); - rc.right = (bmCheckbox.bmWidth / 4) * 2; - rc.top = (bmCheckbox.bmHeight / 3) + 1; - rc.bottom = (bmCheckbox.bmHeight / 3) * 2; + rc.left = (bmCheckbox.bmWidth / 4); + rc.right = (bmCheckbox.bmWidth / 4) * 2; + rc.top = (bmCheckbox.bmHeight / 3); + rc.bottom = (bmCheckbox.bmHeight / 3) * 2; break; case RADIOUNCHECK: - rc.top = (bmCheckbox.bmHeight / 3) + 1; - rc.bottom = (bmCheckbox.bmHeight / 3) * 2; - rc.left = 0; - rc.right = (bmCheckbox.bmWidth / 4); + rc.top = (bmCheckbox.bmHeight / 3); + rc.bottom = (bmCheckbox.bmHeight / 3) * 2; + rc.left = 0; + rc.right = (bmCheckbox.bmWidth / 4); break; } - - /* Copy the appropriate bitmap into the target DC. If the - check-box bitmap is larger than the default check-mark - bitmap, use StretchBlt to make it fit; otherwise, just - copy it. */ - - if (((rc.right - rc.left) > (int) wBitmapX) || - ((rc.bottom - rc.top) > (int) wBitmapY)) - { - StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, - hdcSource, rc.left, rc.top, rc.right - rc.left, - rc.bottom - rc.top, SRCCOPY); - } - - else - { - BitBlt(hdcTarget, 0, 0, rc.right - rc.left, - rc.bottom - rc.top, - hdcSource, rc.left, rc.top, SRCCOPY); - } - - /* Select the old source and destination bitmaps into the - source and destination DCs, and then delete the DCs and - the background brush. */ - - SelectObject(hdcSource, hbmpSourceOld); - SelectObject(hdcTarget, hbrTargetOld); - hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld); - - DeleteObject(hbrBackground); - DeleteObject(hdcSource); - DeleteObject(hdcTarget); - - /* Return a handle to the new check-mark bitmap. */ - - return hbmpCheck; -} + + /* Copy the appropriate bitmap into the target DC. If the + check-box bitmap is larger than the default check-mark + bitmap, use StretchBlt to make it fit; otherwise, just + copy it. */ + if (((rc.right - rc.left) > (int) wBitmapX) || + ((rc.bottom - rc.top) > (int) wBitmapY)) { + StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, + hdcSource, rc.left, rc.top, rc.right - rc.left, + rc.bottom - rc.top, SRCCOPY); + } + + else { + // Center it vertically + WORD dy = (wMenuH > wBitmapY) ? (wMenuH - wBitmapY) / 2 : 0; + BitBlt(hdcTarget, 0, dy, rc.right - rc.left, + rc.bottom - rc.top, + hdcSource, rc.left, rc.top, SRCCOPY); + } + + /* Select the old source and destination bitmaps into the + source and destination DCs, and then delete the DCs and + the background brush. */ + + SelectObject(hdcSource, hbmpSourceOld); + SelectObject(hdcTarget, hbrTargetOld); + hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld); + + DeleteObject(hbrBackground); + DeleteObject(hdcSource); + DeleteObject(hdcTarget); + + /* Return a handle to the new check-mark bitmap. */ + + return hbmpCheck; +} void mswCreateCheckBitmaps() { @@ -487,12 +496,12 @@ void mswCreateCheckBitmaps() } wMenuRadio_p wMenuRadioCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wMenuCallBack_p action, - void *data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wMenuCallBack_p action, + void *data ) { wMenuRadio_p mi; int rc; @@ -536,8 +545,9 @@ wMenuRadio_p wMenuRadioCreate( ac = tolower( ac ); } vk = VkKeyScan( ac ); - if ( vk & 0xFF00 ) + if ( vk & 0xFF00 ) { modifier |= WKEY_SHIFT; + } acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF); acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mi; } @@ -545,7 +555,8 @@ wMenuRadio_p wMenuRadioCreate( /* add the correct bitmaps for radio buttons */ - rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio, checkedRadio ); + rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio, + checkedRadio ); if( m->radioGroup == NULL ) { m->radioGroup = malloc( sizeof( struct radioButtonGroup )); @@ -562,25 +573,26 @@ void wMenuRadioSetActive(wMenuRadio_p mi ) { BOOL rc; - rc = CheckMenuRadioItem( mi->mparent->menu, - mi->mparent->radioGroup->firstButton, - mi->mparent->radioGroup->lastButton, - mi->index, - MF_BYCOMMAND ); -} + rc = CheckMenuRadioItem( mi->mparent->menu, + mi->mparent->radioGroup->firstButton, + mi->mparent->radioGroup->lastButton, + mi->index, + MF_BYCOMMAND ); +} wMenuPush_p wMenuPushCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wMenuCallBack_p action, - void *data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wMenuCallBack_p action, + void *data ) { wMenuPush_p mi; int rc; - char *label = malloc(strlen(labelStr) + 30 ); /**< The label and sufficient space for the keyboard shortcut */ + char *label = malloc(strlen(labelStr) + + 30 ); /**< The label and sufficient space for the keyboard shortcut */ char *cp; char ac; UINT vk; @@ -620,8 +632,9 @@ wMenuPush_p wMenuPushCreate( ac = tolower( ac ); } vk = VkKeyScan( ac ); - if ( vk & 0xFF00 ) + if ( vk & 0xFF00 ) { modifier |= WKEY_SHIFT; + } acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF); acclTable(acclTable_da.cnt-1).mp = mi; } @@ -632,19 +645,19 @@ wMenuPush_p wMenuPushCreate( void wMenuPushEnable( - wMenuPush_p mi, - BOOL_T enable ) + wMenuPush_p mi, + BOOL_T enable ) { EnableMenuItem( mi->mparent->menu, mi->index, - MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); + MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); mi->enabled = enable; } wMenu_p wMenuMenuCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr ) + wMenu_p m, + const char * helpStr, + const char * labelStr ) { wMenu_p mm; int rc; @@ -655,13 +668,14 @@ wMenu_p wMenuMenuCreate( /*mm->parent = (wControl_p)m;*/ mm->first = mm->last = NULL; - rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT)mm->menu, mm->labelStr ); + rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu), + mm->labelStr ); return mm; } void wMenuSeparatorCreate( - wMenu_p m ) + wMenu_p m ) { int rc; createMenuItem( m, M_SEPARATOR, NULL, NULL, sizeof *(wMenuItem_p)NULL ); @@ -678,8 +692,8 @@ void wMenuSeparatorCreate( static void appendItem( - wMenuListItem_p ml, - wMenuListItem_p mi ) + wMenuListItem_p ml, + wMenuListItem_p mi ) { mi->right = ml->right; ml->right->left = mi; @@ -689,7 +703,7 @@ static void appendItem( static void removeItem( - wMenuListItem_p mi ) + wMenuListItem_p mi ) { mi->left->right = mi->right; mi->right->left = mi->left; @@ -698,10 +712,10 @@ static void removeItem( wMenuList_p wMenuListCreate( - wMenu_p m, - const char * helpStr, - int max, - wMenuListCallBack_p action ) + wMenu_p m, + const char * helpStr, + int max, + wMenuListCallBack_p action ) { wMenuList_p mi; mi = (wMenuList_p)createMenuItem( m, M_LIST, helpStr, NULL, sizeof *mi ); @@ -727,8 +741,9 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml ) count++; break; case M_LIST: - if (mi == (wMenuItem_p)ml) + if (mi == (wMenuItem_p)ml) { return count; + } count += ((wMenuList_p)mi)->count; break; default: @@ -740,10 +755,10 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml ) void wMenuListAdd( - wMenuList_p ml, - int index, - const char * labelStr, - void * data ) + wMenuList_p ml, + int index, + const char * labelStr, + void * data ) { int origin; wMenuListItem_p wl_p; @@ -752,7 +767,8 @@ void wMenuListAdd( int rc; origin = getMlistOrigin(ml->mlparent, ml); - for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) { + for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; + count++,wl_p=wl_p->right ) { if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) { /* move item */ if (count != index) { @@ -770,34 +786,37 @@ void wMenuListAdd( removeItem( ml->left ); add: ml->count--; - if (wl_p->labelStr ) + if (wl_p->labelStr ) { free( CAST_AWAY_CONST wl_p->labelStr ); + } wl_p->labelStr = mswStrdup( labelStr ); } else { wl_p = (wMenuListItem_p)createMenuItem( NULL, M_LISTITEM, NULL, - labelStr, sizeof *wl_p ); + labelStr, sizeof *wl_p ); } ((wMenuListItem_p)wl_p)->data = data; ((wMenuListItem_p)wl_p)->action = ml->action; - if (index < 0 || index > ml->count) + if (index < 0 || index > ml->count) { index = ml->count; + } for ( mi=(wMenuListItem_p)ml,count=0; count<index; mi=mi->right,count++); rc = InsertMenu( ml->mlparent->menu, origin+index, - MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr ); + MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr ); appendItem( mi, wl_p ); ml->count++; } void wMenuListDelete( - wMenuList_p ml, - const char * labelStr ) + wMenuList_p ml, + const char * labelStr ) { int origin, count; wMenuListItem_p wl_p; origin = getMlistOrigin(ml->mlparent, ml); - for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) { + for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; + count++,wl_p=wl_p->right ) { if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) { /* delete item */ mswUnregister( wl_p->index ); @@ -812,27 +831,30 @@ void wMenuListDelete( const char * wMenuListGet( - wMenuList_p ml, - int index, - void ** data ) + wMenuList_p ml, + int index, + void ** data ) { int origin, count; wMenuListItem_p wl_p; - if (index >= ml->count) + if (index >= ml->count) { return NULL; + } origin = getMlistOrigin(ml->mlparent, ml); for ( count=0,wl_p=ml->right; wl_p&&count<index; count++,wl_p=wl_p->right ); - if (wl_p==NULL) + if (wl_p==NULL) { return NULL; - if ( data ) + } + if ( data ) { *data = wl_p->data; + } return wl_p->labelStr; } void wMenuListClear( - wMenuList_p ml ) + wMenuList_p ml ) { int origin, count; wMenuListItem_p wl_p, wl_q; @@ -852,13 +874,13 @@ void wMenuListClear( wMenuToggle_p wMenuToggleCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wBool_t set, - wMenuToggleCallBack_p action, - void * data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wBool_t set, + wMenuCallBack_p action, + void * data ) { wMenuToggle_p mt; int rc; @@ -868,7 +890,8 @@ wMenuToggle_p wMenuToggleCreate( UINT vk; long modifier; - mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, sizeof *mt ); + mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, + sizeof *mt ); /*setAcclKey( m->parent, m->menu, mt->menu_item, acclKey );*/ mt->action = action; mt->data = data; @@ -909,8 +932,9 @@ wMenuToggle_p wMenuToggleCreate( ac = tolower( ac ); } vk = VkKeyScan( ac ); - if ( vk & 0xFF00 ) + if ( vk & 0xFF00 ) { modifier |= WKEY_SHIFT; + } acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF); acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mt; } @@ -922,30 +946,33 @@ wMenuToggle_p wMenuToggleCreate( wBool_t wMenuToggleGet( - wMenuToggle_p mt ) + wMenuToggle_p mt ) { - return (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0; + return (GetMenuState( mt->mparent->menu, mt->index, + MF_BYCOMMAND ) & MF_CHECKED) != 0; } wBool_t wMenuToggleSet( - wMenuToggle_p mt, - wBool_t set ) + wMenuToggle_p mt, + wBool_t set ) { wBool_t rc; - CheckMenuItem( mt->mparent->menu, mt->index, MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) ); - rc = (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0; + CheckMenuItem( mt->mparent->menu, mt->index, + MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) ); + rc = (GetMenuState( mt->mparent->menu, mt->index, + MF_BYCOMMAND ) & MF_CHECKED) != 0; return rc; } void wMenuToggleEnable( - wMenuToggle_p mt, - wBool_t enable ) + wMenuToggle_p mt, + wBool_t enable ) { EnableMenuItem( mt->mparent->menu, mt->index, - MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); + MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); mt->enabled = enable; -} +} /* ***************************************************************************** @@ -957,39 +984,40 @@ void wMenuToggleEnable( void mswMenuMove( - wMenu_p m, - wPos_t x, - wPos_t y ) + wMenu_p m, + wWinPix_t x, + wWinPix_t y ) { wControl_p b; b = (wControl_p)m->parent; if (b && b->hWnd) if (!SetWindowPos( b->hWnd, HWND_TOP, x, y, - CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOSIZE|SWP_NOZORDER)) - mswFail("mswMenuMove"); + CW_USEDEFAULT, CW_USEDEFAULT, + SWP_NOSIZE|SWP_NOZORDER)) { + mswFail("mswMenuMove"); + } } static void pushMenuButt( - void * data ) + void * data ) { wMenu_p m = (wMenu_p)data; RECT rect; mswAllowBalloonHelp = FALSE; GetWindowRect( m->hWnd, &rect ); TrackPopupMenu( m->menu, TPM_LEFTALIGN, rect.left, rect.bottom, - 0, ((wControl_p)(m->parent))->hWnd, NULL ); + 0, ((wControl_p)(m->parent))->hWnd, NULL ); } wMenu_p wMenuCreate( - wWin_p parent, - POS_T x, - POS_T y, - const char * helpStr, - const char * labelStr, - long option ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option ) { wMenu_p m; wControl_p b; @@ -1002,7 +1030,7 @@ wMenu_p wMenuCreate( } m = (wMenu_p)createMenuItem( NULL, M_MENU, helpStr, label, sizeof *m ); m->button = wButtonCreate( parent, x, y, helpStr, labelStr, - buttOption, 0, pushMenuButt, (void*)m ); + buttOption, 0, pushMenuButt, (void*)m ); b = (wControl_p)m->button; m->parent = b->parent; m->x = b->x; @@ -1021,9 +1049,9 @@ wMenu_p wMenuCreate( wMenu_p wMenuBarAdd( - wWin_p w, - const char * helpStr, - const char * labelStr ) + wWin_p w, + const char * helpStr, + const char * labelStr ) { HMENU menu; wMenu_p m; @@ -1041,7 +1069,8 @@ wMenu_p wMenuBarAdd( m->mmtype = MM_BAR; m->first = m->last = NULL; - rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT)m->menu, labelStr ); + rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu), + labelStr ); DrawMenuBar( ((wControl_p)w)->hWnd ); return m; @@ -1050,8 +1079,8 @@ wMenu_p wMenuBarAdd( wMenu_p wMenuPopupCreate( - wWin_p w, - const char * labelStr ) + wWin_p w, + const char * labelStr ) { wMenu_p m; long buttOption = 0; @@ -1081,21 +1110,21 @@ void wMenuPopupShow( wMenu_p mp ) GetCursorPos( &pt ); TrackPopupMenu( mp->menu, TPM_LEFTALIGN, pt.x, pt.y, 0, mp->hWnd, NULL ); } - + /*-----------------------------------------------------------------*/ void wMenuSetTraceCallBack( - wMenu_p m, - wMenuTraceCallBack_p func, - void * data ) + wMenu_p m, + wMenuTraceCallBack_p func, + void * data ) { m->traceFunc = func; m->traceData = data; } wBool_t wMenuAction( - wMenu_p m, - const char * label ) + wMenu_p m, + const char * label ) { wMenuItem_p mi; wMenuToggle_p mt; @@ -1106,10 +1135,11 @@ wBool_t wMenuAction( case M_SEPARATOR: break; case M_PUSH: - if ( ((wMenuPush_p)mi)->enabled == FALSE ) + if ( ((wMenuPush_p)mi)->enabled == FALSE ) { wBeep(); - else + } else { ((wMenuPush_p)mi)->action( ((wMenuPush_p)mi)->data ); + } break; case M_TOGGLE: mt = (wMenuToggle_p)mi; @@ -1118,7 +1148,7 @@ wBool_t wMenuAction( } else { set = wMenuToggleGet( mt ); wMenuToggleSet( mt, !set ); - mt->action( set, mt->data ); + mt->action( mt->data ); } break; case M_MENU: |