diff options
Diffstat (limited to 'app/wlib/mswlib/mswmisc.c')
-rw-r--r-- | app/wlib/mswlib/mswmisc.c | 676 |
1 files changed, 359 insertions, 317 deletions
diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c index 6b5f1c9..5b45e2b 100644 --- a/app/wlib/mswlib/mswmisc.c +++ b/app/wlib/mswlib/mswmisc.c @@ -31,7 +31,6 @@ #include <stdio.h> #include <assert.h> #include <htmlhelp.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" #include "FreeImage.h" @@ -45,6 +44,7 @@ #define OFN_LONGFILENAMES 0x00200000L char * mswStrdup(const char *); +const char * GetCurCommandName(void); #define PAUSE_TIMER (901) #define ALARM_TIMER (902) @@ -69,7 +69,6 @@ char * mswStrdup(const char *); * EXPORTED VARIABLES */ -long debugWindow = 0; HINSTANCE mswHInst; HWND mswHWnd = (HWND)0; @@ -77,18 +76,26 @@ const char *mswDrawWindowClassName = "DRAWWINDOW"; char mswTmpBuff[1024]; int mswEditHeight; int mswAllowBalloonHelp = TRUE; -int mswGroupStyle; HFONT mswOldTextFont; HFONT mswLabelFont; +/** @prefs [msw tweak] ThickFont=1 */ long mswThickFont = 1; double mswScale = 1.0; -double scaleIcon = 1.0; /**< Scaling factor for toolbar icons */ +/** @prefs [Preference] LargeIcons=1.5 Set toolbar icon scaling. Limited 1.0 to 2.0 */ +double scaleIcon = 1.0; /** Scaling factor for toolbar icons */ callBacks_t *mswCallBacks[CALLBACK_CNT]; -void closeBalloonHelp(void); +void closeBalloonHelp(int inx); static wControl_p getControlFromCursor(HWND, wWin_p *); + +#ifdef BALLOON_TRACE +// To use: +// change logFile defn in lprintf.c from static to EXPORT +// Run with some debug flag set to ensure logFile is set +extern FILE * logFile; +#endif /* * LOCAL VARIABLES */ @@ -100,14 +107,14 @@ struct wWin_t { int max_width; int min_height; int max_height; - wPos_t lastX, lastY; - wPos_t padX, padY; + wWinPix_t lastX, lastY; + wWinPix_t padX, padY; wControl_p first, last; wWinCallBack_p winProc; BOOL_T busy; #ifdef OWNERICON HBITMAP wicon_bm; - wPos_t wicon_w, wicon_h; + wWinPix_t wicon_w, wicon_h; #endif DWORD baseStyle; wControl_p focusChainFirst; @@ -131,15 +138,15 @@ static int mResizeBorderH; static int mMenuH; static int screenWidth = 0, screenHeight = 0; -wWin_p mswWin = NULL; -wWin_p winFirst, winLast; +static wWin_p mswWin = NULL; +static wWin_p winFirst, winLast; static long count51 = 0; -static UINT alarmTimer; -static UINT pauseTimer; -static UINT balloonHelpTimer = (UINT)0; -static UINT triggerTimer; +static UINT_PTR alarmTimer; +static UINT_PTR pauseTimer; +static UINT_PTR balloonHelpTimer = (UINT_PTR)0; +static UINT_PTR triggerTimer; static UINT balloonHelpTimeOut = 500; static wControl_p balloonHelpButton = NULL; @@ -160,7 +167,7 @@ static DWORD dwCookie; typedef struct { wControl_p b; } controlMap_t; -dynArr_t controlMap_da; +static dynArr_t controlMap_da; #define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N) @@ -177,8 +184,6 @@ static FILE * helpStrF; #endif static int inMainWndProc = FALSE; -int newHelp = 1; - static wBool_t mswWinBlockEnabled = TRUE; static FILE * dumpControlsF; @@ -187,7 +192,7 @@ static int dumpControls; extern char *userLocale; // list of supported fileformats for image files -char * filterImageFiles[] = { N_("All image files"), +static char * filterImageFiles[] = { N_("All image files"), "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff", N_("GIF files (*.gif)"), "*.gif", @@ -251,8 +256,8 @@ static void doDumpControls(void) b = controlMap(inx).b; if (b) { - fprintf(dumpControlsF, "[%0.3d] [%x] %s %s %s\n", inx, - (unsigned int)b->hWnd, + fprintf(dumpControlsF, "[%0.3d] [%p] %s %s %s\n", inx, + b->hWnd, (b->type>=0&&b->type<=B_BOX?controlNames[b->type]:"NOTYPE"), (b->labelStr?b->labelStr:"<NULL>"), (b->helpStr?b->helpStr:"<NULL>")); @@ -303,7 +308,7 @@ void mswRepaintLabel(HWND hWnd, wControl_p b) LABELFONTSELECT newBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); oldBrush = SelectObject(hDc, newBrush); - dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, strlen(b->labelStr)); + dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (int)(strlen(b->labelStr))); rect.left = b->labelX; rect.top = b->labelY; rect.right = b->labelX + LOWORD(dw); @@ -313,7 +318,7 @@ void mswRepaintLabel(HWND hWnd, wControl_p b) /*SetBkMode( hDc, OPAQUE );*/ SetBkColor(hDc, GetSysColor(COLOR_BTNFACE)); - if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, strlen(b->labelStr))) { + if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, (int)(strlen(b->labelStr)))) { mswFail("Repainting text label"); } @@ -376,14 +381,16 @@ void * mswAlloc( w->data = data; w->focusChainNext = NULL; w->shown = TRUE; + w->hilite = FALSE; + w->errStr = NULL; return w; } void mswComputePos( wControl_p b, - wPos_t origX, - wPos_t origY) + wWinPix_t origX, + wWinPix_t origY) { wWin_p w = b->parent; @@ -403,14 +410,14 @@ void mswComputePos( b->labelY = b->y+2; if (b->labelStr) { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(w->hWnd); LABELFONTSELECT lab_l = strlen(b->labelStr); - dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (UINT)lab_l); b->labelX -= LOWORD(dw) + 5; LABELFONTRESET ReleaseDC(w->hWnd, hDc); @@ -557,7 +564,7 @@ void mswSetFocus( b->parent->focusChainNext = b; } } - + /* ****************************************************************************** * @@ -569,10 +576,10 @@ void mswSetFocus( static void getSavedSizeAndPos( long option, const char * nameStr, - wPos_t *rw, - wPos_t *rh, - wPos_t *rx, - wPos_t *ry, + wWinPix_t *rw, + wWinPix_t *rh, + wWinPix_t *rx, + wWinPix_t *ry, int *showCmd) { char *cq; @@ -580,14 +587,31 @@ static void getSavedSizeAndPos( if ((option&F_RECALLPOS) && nameStr) { int x, y, w, h; + int xadj, yadj; const char *cp; int state; + w = h = 0; + xadj = 1; + yadj = mTitleH + 1; + if (option & F_RESIZE) { + xadj += mResizeBorderW * 2; + yadj += mResizeBorderH * 2; + } + else + { + xadj += mFixBorderW * 2; + yadj += mFixBorderH * 2; + } + //if (option & F_MENUBAR) { + // yadj += mMenuH; + //} + if ((option & F_RESIZE) && (cp = wPrefGetStringBasic("msw window size", nameStr)) && (state = (int)strtol(cp, &cq, 10), cp != cq) && // state is not used - (cp = cq, w = (wPos_t)strtod(cp, &cq), cp != cq) && - (cp = cq, h = (int)strtod(cp, &cq), cp != cq) + (cp = cq, w = (wWinPix_t)(strtod(cp, &cq)), cp != cq) && + (cp = cq, h = (wWinPix_t)(strtod(cp, &cq)), cp != cq) ) { if (w < 10) { w = 10; @@ -597,12 +621,12 @@ static void getSavedSizeAndPos( h = 10; } - if (w > screenWidth) { - w = screenWidth; + if (w > screenWidth - xadj) { + w = screenWidth - xadj; } - if (h > screenHeight) { - h = screenHeight; + if (h > screenHeight - yadj) { + h = screenHeight - yadj; } *rw = w; @@ -610,8 +634,8 @@ static void getSavedSizeAndPos( } if ((cp = wPrefGetStringBasic("msw window pos", nameStr)) && - (x = (wPos_t)strtod(cp, &cq), cp != cq) && - (cp = cq, y = (wPos_t)strtod(cp, &cq), cp != cq) + (x = (wWinPix_t)(strtod(cp, &cq)), cp != cq) && + (cp = cq, y = (wWinPix_t)(strtod(cp, &cq)), cp != cq) ) { if (y < 0) { y = 0; @@ -621,12 +645,12 @@ static void getSavedSizeAndPos( x = 0; } - if (y > screenHeight-40) { - y = screenHeight-40; + if (y + h > screenHeight - yadj) { + y = screenHeight - yadj - h; } - if (x > screenWidth-40) { - x = screenWidth-40; + if (x + w > screenWidth - xadj) { + x = screenWidth - xadj - w; } *rx = x; @@ -647,12 +671,12 @@ static void getSavedSizeAndPos( * \param aspect_ration IN unused on Windows */ void wSetGeometry(wWin_p win, - int min_width, - int max_width, - int min_height, - int max_height, - int base_width, - int base_height, + wWinPix_t min_width, + wWinPix_t max_width, + wWinPix_t min_height, + wWinPix_t max_height, + wWinPix_t base_width, + wWinPix_t base_height, double aspect_ratio) { win->validGeometry = TRUE; //remember that geometry was set @@ -690,15 +714,15 @@ static wWin_p winCommonCreate( long style, const char * labelStr, wWinCallBack_p winProc, - wPos_t w, - wPos_t h, + wWinPix_t w, + wWinPix_t h, void * data, const char * nameStr, int * pShowCmd) { wWin_p win; int index; - wPos_t ww, hh, xx, yy; + wWinPix_t ww, hh, xx, yy; RECT rect; win = (wWin_p)mswAlloc(NULL, typ, mswStrdup(labelStr), sizeof *win, data, &index); @@ -715,6 +739,8 @@ static wWin_p winCommonCreate( if (typ == W_MAIN) { *pShowCmd = ((option & F_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL); + } else { + *pShowCmd = SW_HIDE; //Make sure to hide first } if (xx != CW_USEDEFAULT) { @@ -806,8 +832,8 @@ void wInitAppName(char *_appName) wWin_p wWinMainCreate( const char * name, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, const char * nameStr, @@ -816,7 +842,6 @@ wWin_p wWinMainCreate( void * data) { wWin_p w; - RECT rect; const char * appDir; const char * libDir; int showCmd; @@ -877,26 +902,29 @@ wWin_p wWinMainCreate( nameStr, &showCmd); mswHWnd = w->hWnd; + //HICON hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(0), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE); + //HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(0)); + //SendMessage(mswHWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); + //SendMessage(mswHWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); + if (!mswThickFont) { - SendMessage(w->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L); - hDc = GetDC(w->hWnd); + SendMessage(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); + hDc = GetDC(mswHWnd); GetTextMetrics(hDc, &tm); mswEditHeight = tm.tmHeight+2; - ReleaseDC(w->hWnd, hDc); + ReleaseDC(mswHWnd, hDc); } - ShowWindow(w->hWnd, showCmd); - UpdateWindow(w->hWnd); - GetWindowRect(w->hWnd, &rect); - GetClientRect(w->hWnd, &rect); + ShowWindow(mswHWnd, showCmd); + UpdateWindow(mswHWnd); w->busy = FALSE; return w; } wWin_p wWinPopupCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, const char * nameStr, @@ -1077,7 +1105,7 @@ static wAccelKey_e translateExtKey(UINT wParam) } -long notModKey; +static long notModKey; int mswTranslateAccelerator( HWND hWnd, LPMSG pMsg) @@ -1091,7 +1119,7 @@ int mswTranslateAccelerator( return FALSE; } - acclKey = pMsg->wParam; + acclKey = (long)pMsg->wParam; b = getControlFromCursor(pMsg->hwnd, &win); if (win == NULL) { @@ -1112,7 +1140,7 @@ int mswTranslateAccelerator( } if (acclKey == (long)VK_F1) { - closeBalloonHelp(); + closeBalloonHelp(1); if (!b && win) { wHelp(win->helpStr); @@ -1162,14 +1190,14 @@ int mswTranslateAccelerator( -void wGetDisplaySize(POS_T * width, POS_T * height) +void wGetDisplaySize(wWinPix_t * width, wWinPix_t * height) { *width = screenWidth; *height = screenHeight; } -void wWinGetSize(wWin_p w, POS_T * width, POS_T * height) +void wWinGetSize(wWin_p w, wWinPix_t * width, wWinPix_t * height) { RECT rect; GetWindowRect(w->hWnd, &rect); @@ -1181,7 +1209,7 @@ void wWinGetSize(wWin_p w, POS_T * width, POS_T * height) } -void wWinSetSize(wWin_p w, POS_T width, POS_T height) +void wWinSetSize(wWin_p w, wWinPix_t width, wWinPix_t height) { RECT rect; w->w = width; @@ -1224,33 +1252,24 @@ static void blockingLoop(void) static void savePos(wWin_p win) { - WINDOWPLACEMENT windowPlace; - wPos_t w, h; + wWinPix_t w, h; RECT rect; if (win->nameStr && IsWindowVisible(win->hWnd) /*&& !IsIconic( win->hWnd )*/) { - windowPlace.length = sizeof windowPlace; - GetWindowPlacement(win->hWnd, &windowPlace); + GetWindowRect(win->hWnd, &rect); - if (win->option&F_RECALLPOS) { + if (win->option&F_RECALLPOS) { char posStr[20]; - wsprintf(posStr, "%d %d", - windowPlace.rcNormalPosition.left, - windowPlace.rcNormalPosition.top); - wPrefSetString("msw window pos", win->nameStr, posStr); + wsprintf(posStr, "%d %d", + rect.left, + rect.top); + wPrefSetString("msw window pos", win->nameStr, posStr); if (win->option&F_RESIZE) { - GetClientRect(win->hWnd, &rect); - w = windowPlace.rcNormalPosition.right - windowPlace.rcNormalPosition.left; - h = windowPlace.rcNormalPosition.bottom - windowPlace.rcNormalPosition.top; - w -= mResizeBorderW*2; - h -= mResizeBorderH*2 + mTitleH; - - if (win->option&F_MENUBAR) { - h -= mMenuH; - } - + GetClientRect(win->hWnd, &rect); + w = rect.right - rect.left; + h = rect.bottom - rect.top; wsprintf(posStr, "%d %d %d", 0, // unused w, h); @@ -1265,7 +1284,7 @@ void wWinShow( wWin_p win, BOOL_T show) { - wPos_t x, y; + wWinPix_t x, y; wWin_p win1; win->busy = TRUE; @@ -1292,6 +1311,10 @@ void wWinShow( win->centerWin = FALSE; win->shown = TRUE; + // Clear hilites + for (wControl_p controlP = win->first; controlP; controlP = controlP->next) + controlP->hilite = FALSE; + if (mswHWnd == (HWND)0 || !IsIconic(mswHWnd)) { ShowWindow(win->hWnd, SW_SHOW); @@ -1429,13 +1452,15 @@ const char * wWinGetTitle( void wWinClear( wWin_p win, - wPos_t x, - wPos_t y, - wPos_t width, - wPos_t height) + wWinPix_t x, + wWinPix_t y, + wWinPix_t width, + wWinPix_t height) { } +extern long dontHideCursor; + void wSetCursor(wDraw_p win, wCursor_t cursor) { @@ -1492,6 +1517,11 @@ void wSetCursor(wDraw_p win, case wCursorAppStart: SetCursor(LoadCursor(NULL, IDC_APPSTARTING)); break; + + case wCursorNone: + if (!dontHideCursor) + SetCursor(NULL); + break; } curCursor = cursor; @@ -1667,44 +1697,44 @@ const char * wControlGetHelp(wControl_p b) } -wPos_t wLabelWidth(const char * labelStr) +wWinPix_t wLabelWidth(const char * labelStr) { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(mswHWnd); lab_l = strlen(labelStr); LABELFONTSELECT - dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, (UINT)lab_l); LABELFONTRESET ReleaseDC(mswHWnd, hDc); return LOWORD(dw) + 5; } -wPos_t wControlGetWidth( +wWinPix_t wControlGetWidth( wControl_p b) /* Control */ { return b->w; } -wPos_t wControlGetHeight( +wWinPix_t wControlGetHeight( wControl_p b) /* Control */ { return b->h; } -wPos_t wControlGetPosX( +wWinPix_t wControlGetPosX( wControl_p b) /* Control */ { return b->x; } -wPos_t wControlGetPosY( +wWinPix_t wControlGetPosY( wControl_p b) /* Control */ { return b->y; @@ -1713,21 +1743,21 @@ wPos_t wControlGetPosY( void wControlSetPos( wControl_p b, - wPos_t x, - wPos_t y) + wWinPix_t x, + wWinPix_t y) { b->labelX = x; b->labelY = y+2; if (b->labelStr) { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(b->parent->hWnd); LABELFONTSELECT lab_l = strlen(b->labelStr); - dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (UINT)lab_l); b->labelX -= LOWORD(dw) + 5; LABELFONTRESET ReleaseDC(b->parent->hWnd, hDc); @@ -1757,14 +1787,14 @@ void wControlSetLabel( if (b->type == B_RADIO ) { ; } else { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(b->parent->hWnd); lab_l = strlen(labelStr); LABELFONTSELECT - dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, (UINT)lab_l); LABELFONTRESET b->labelX = b->x - LOWORD(dw) - 5; ReleaseDC(b->parent->hWnd, hDc); @@ -1797,13 +1827,14 @@ void wControlHilite( return; } - if (!IsWindowVisible(b->parent->hWnd)) { + if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd)) || (!IsWindowVisible(b->hWnd))) { + b->hilite = FALSE; return; } - if (!IsWindowVisible(b->hWnd)) { - return; - } + if (b->hilite == hilite) + return; + b->hilite = hilite; hDc = GetDC(b->parent->hWnd); newPen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND | PS_JOIN_BEVEL, @@ -1840,7 +1871,7 @@ void wMessage( { HDC hDc; int oldRop; - POS_T h; + wWinPix_t h; RECT rect; LABELFONTDECL @@ -1855,7 +1886,7 @@ void wMessage( Rectangle(hDc, 0, h, w->w, h); SetROP2(hDc, oldRop); LABELFONTSELECT - TextOut(hDc, 0, h, msg, strlen(msg)); + TextOut(hDc, 0, h, msg, (int)(strlen(msg))); LABELFONTRESET ReleaseDC(w->hWnd, hDc); } @@ -1873,7 +1904,7 @@ unsigned wOpenFileExternal(char *file) res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW); - if ((int)res <= 32) { + if ((UINT_PTR)res <= 32) { wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL); return(FALSE); } @@ -1886,7 +1917,6 @@ void wExit(int rc) INDEX_T inx; wControl_p b; mswPutCustomColors(); - wPrefFlush(); for (inx=controlMap_da.cnt-1; inx>=0; inx--) { b = controlMap(inx).b; @@ -1903,7 +1933,9 @@ void wExit(int rc) } } - for (inx=controlMap_da.cnt-1; inx>=0; inx--) { + wPrefFlush(""); + + for (inx=controlMap_da.cnt-1; inx>=0; inx--) { b = controlMap(inx).b; if (b != NULL) { @@ -1916,14 +1948,14 @@ void wExit(int rc) controlMap(inx).b = NULL; } - deleteBitmaps(); + deleteBitmaps(); if (mswOldTextFont != (HFONT)0) { DeleteObject(mswOldTextFont); } if (helpInitted) { - WinHelp(mswHWnd, helpFile, HELP_QUIT, 0L); + WinHelp(mswHWnd, helpFile, HELP_QUIT, (DWORD)0); helpInitted = FALSE; } @@ -2165,14 +2197,14 @@ void wHelp( { char *pszHelpTopic; HWND hwndHelp; - char *theTopic = "index"; + const char *theTopic = "index"; if (topic) { theTopic = topic; } if (!helpInitted) { - HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ; + HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ; helpInitted = TRUE; } @@ -2199,11 +2231,12 @@ void doHelpMenu(void * context) HH_FTS_QUERY ftsQuery; if (!helpInitted) { - HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ; + HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ; helpInitted = TRUE; } - switch ((int)(long)context) { + const char * topic; + switch ((int)(INT_PTR)context) { case 1: /* Contents */ HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL); break; @@ -2215,12 +2248,11 @@ void doHelpMenu(void * context) ftsQuery.fTitleOnly = FALSE; ftsQuery.pszSearchQuery = NULL; ftsQuery.pszWindow = NULL; - HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD)&ftsQuery); + HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD_PTR)&ftsQuery); break; case 3: /*Context*/ - const char * topic; topic = GetCurCommandName(); wHelp(topic); break; @@ -2267,149 +2299,132 @@ void wControlSetBalloonText(wControl_p b, const char * text) b->tipStr = mswStrdup(text); } - -void startBalloonHelp(void) +void openBalloonHelp(wControl_p b, int dx, int dy) { - HDC hDc; - DWORD extent; - RECT rect; - POINT pt; - wBalloonHelp_t * bh; - const char * hs; - HFONT hFont; - - if (!balloonHelpStrings) { - return; - } - - if (!balloonHelpEnable) { - return; - } - - if (balloonHelpHWnd) { - if (balloonHelpButton->tipStr) { - hs = balloonHelpButton->tipStr; - } else { - hs = balloonHelpButton->helpStr; - - if (!hs) { - return; - } - - for (bh = balloonHelpStrings; bh->name && strcmp(bh->name,hs) != 0; bh++); - - if (!bh->name || !bh->value) { - return; - } + HDC hDc; + DWORD extent; + RECT rect; + POINT pt; + HFONT hFont; + const char * msg; + if (b->errStr) { + msg = b->errStr; + } + else { + msg = b->tipStr; + if (!balloonHelpEnable) { +#ifdef BALLOON_TRACE + fprintf(logFile, "openBalloon !Enable state %d\n", balloonHelpState); fflush(logFile); +#endif + return; + } + } +#ifdef BALLOON_TRACE + fprintf(logFile, "openBalloon %s state %d\n", msg, balloonHelpState); fflush(logFile); +#endif + if (!balloonHelpHWnd) + return; + int w, h; + hDc = GetDC(balloonHelpHWnd); + hFont = SelectObject(hDc, mswLabelFont); + extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, (int)(strlen(msg))); + w = LOWORD(extent); + h = HIWORD(extent); + + if (b->type == B_RADIO || + b->type == B_TOGGLE) { + pt.y = b->h; + } + else { + GetClientRect(b->hWnd, &rect); + pt.y = rect.bottom; + } - balloonHelpButton->tipStr = hs = bh->value; - } + pt.x = dx; + pt.y -= dy; + ClientToScreen(b->hWnd, &pt); - if (newHelp) { - wControlSetBalloon(balloonHelpButton, 0, 0, hs); - } else { - int w, h; - hDc = GetDC(balloonHelpHWnd); - hFont = SelectObject(hDc, mswLabelFont); - extent = GetTextExtent(hDc, CAST_AWAY_CONST hs, strlen(hs)); - w = LOWORD(extent); - h = HIWORD(extent); - pt.x = 0; - - if (balloonHelpButton->type == B_RADIO || - balloonHelpButton->type == B_TOGGLE) { - pt.y = balloonHelpButton->h; - } else { - GetClientRect(balloonHelpButton->hWnd, &rect); - pt.y = rect.bottom; - } + if (pt.x + w + 2 > screenWidth) { + pt.x = screenWidth - (w + 2); + } - ClientToScreen(balloonHelpButton->hWnd, &pt); + if (pt.x < 0) { + pt.x = 0; + } - if (pt.x + w+2 > screenWidth) { - pt.x = screenWidth-(w+2); - } + SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w + 6, h + 4, + SWP_SHOWWINDOW | SWP_NOACTIVATE); + if (!b->errStr) { + SetBkColor(hDc, GetSysColor(COLOR_INFOBK)); + SetTextColor(hDc, GetSysColor(COLOR_INFOTEXT)); + } else { + SetBkColor(hDc, GetSysColor(COLOR_HIGHLIGHT)); + SetTextColor(hDc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + } + TextOut(hDc, 2, 1, msg, (int)(strlen(msg))); + SelectObject(hDc, hFont); + ReleaseDC(balloonHelpHWnd, hDc); + balloonHelpState = balloonHelpShow; + balloonControlButton = b; +} - if (pt.x < 0) { - pt.x = 0; - } - SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w+6, h+4, - SWP_SHOWWINDOW|SWP_NOACTIVATE); - SetBkColor(hDc, GetSysColor(COLOR_INFOBK)); - TextOut(hDc, 2, 1, hs, strlen(hs)); - SelectObject(hDc, hFont); - ReleaseDC(balloonHelpHWnd, hDc); - } - } -} -void closeBalloonHelp(void) +void startBalloonHelp(void) { - if (balloonHelpTimer) { - KillTimer(mswHWnd, balloonHelpTimer); - balloonHelpTimer = 0; - } - - if (balloonHelpState == balloonHelpShow) - if (balloonHelpHWnd) { - ShowWindow(balloonHelpHWnd, SW_HIDE); - } + wBalloonHelp_t * bh; + + if (!balloonHelpButton->tipStr) { + if (!balloonHelpStrings) + return; + for (bh = balloonHelpStrings; bh->name && strcmp(bh->name, balloonHelpButton->helpStr) != 0; bh++); + if (!bh->name || !bh->value) + balloonHelpButton->tipStr = _(balloonHelpButton->helpStr); + else + balloonHelpButton->tipStr = _(bh->value); + } - balloonHelpState = balloonHelpIdle; + openBalloonHelp(balloonHelpButton, 0, 0); } -void wControlSetBalloon(wControl_p b, wPos_t dx, wPos_t dy, const char * msg) +void closeBalloonHelp(int inx) { - HDC hDc; - DWORD extent; - RECT rect; - POINT pt; - HFONT hFont; - - if (msg) { - int w, h; - hDc = GetDC(balloonHelpHWnd); - hFont = SelectObject(hDc, mswLabelFont); - extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, strlen(msg)); - w = LOWORD(extent); - h = HIWORD(extent); - - if (b->type == B_RADIO || - b->type == B_TOGGLE) { - pt.y = b->h; - } else { - GetClientRect(b->hWnd, &rect); - pt.y = rect.bottom; - } +#ifdef BALLOON_TRACE + fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState); fflush(logFile); +#endif + if (balloonHelpTimer) { + KillTimer(mswHWnd, balloonHelpTimer); + balloonHelpTimer = (UINT_PTR)0; + } - pt.x = dx; - pt.y -= dy; - ClientToScreen(b->hWnd, &pt); + if (balloonHelpState == balloonHelpShow) + if (balloonHelpHWnd) { + ShowWindow(balloonHelpHWnd, SW_HIDE); + } - if (pt.x + w+2 > screenWidth) { - pt.x = screenWidth-(w+2); - } + balloonHelpState = balloonHelpIdle; +} - if (pt.x < 0) { - pt.x = 0; - } - SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w+6, h+4, - SWP_SHOWWINDOW|SWP_NOACTIVATE); - SetBkColor(hDc, GetSysColor(COLOR_INFOBK)); - TextOut(hDc, 2, 1, msg, strlen(msg)); - SelectObject(hDc, hFont); - ReleaseDC(balloonHelpHWnd, hDc); - balloonHelpState = balloonHelpShow; - balloonControlButton = b; - } else { - closeBalloonHelp(); - } +void wControlSetBalloon(wControl_p b, wWinPix_t dx, wWinPix_t dy, const char * msg) +{ + if (msg) { + if (b->errStr) + free(b->errStr); + b->errStr = mswStrdup(msg); + openBalloonHelp(b, dx, dy); + } + else { + if (b->errStr) + free(b->errStr); + b->errStr = NULL; + closeBalloonHelp(2); + } } + int wGetKeyState(void) { int rc, keyState; @@ -2613,7 +2628,7 @@ struct wFilSel_t * wFilSelCreate( { char * cp; struct wFilSel_t * ret; - int len; + size_t len; ret = (struct wFilSel_t*)malloc(sizeof *ret); ret->parent = parent; ret->mode = mode; @@ -2671,7 +2686,7 @@ const char * wMemStats(void) ", Unknown Heap Status"); return msg; } - + /* ***************************************************************************** * @@ -2750,8 +2765,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) int inx; wWin_p w; wControl_p b, oldW; - int child = ((GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) != 0); - POS_T newW, newH; + wWinPix_t newW, newH; RECT rect; PAINTSTRUCT ps; HWND hWnd2; @@ -2759,9 +2773,10 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) HDC hDc; wAccelKey_e extChar; + LPMINMAXINFO pMMI; switch (message) { case WM_GETMINMAXINFO: - LPMINMAXINFO pMMI = (LPMINMAXINFO)lParam; + pMMI = (LPMINMAXINFO)lParam; inx = GetWindowWord(hWnd, 0); if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) { @@ -2775,7 +2790,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } } - return(0); + return (LRESULT)0; case WM_MOUSEWHEEL: inx = GetWindowWord(hWnd, 0); @@ -2787,12 +2802,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return mswCallBacks[b->type]->messageProc((wControl_p)b, hWnd, message, wParam, lParam); - return (0); + return (LRESULT)0; - case WM_DRAWITEM: - case WM_COMMAND: + case WM_COMMAND: + closeBalloonHelp(3); + case WM_DRAWITEM: case WM_MEASUREITEM: - closeBalloonHelp(); if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) { break; @@ -2808,10 +2823,10 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) // draw the bitmap mswDrawIcon(((LPDRAWITEMSTRUCT)lParam)->hDC, 0, 0, (wIcon_p)(b->data), FALSE, (COLORREF)0, (COLORREF)0); - return (TRUE); + return (LRESULT)TRUE; } else { mswSetFocus(b); - ret = 0L; + ret = 0; if (!inMainWndProc) { inMainWndProc = TRUE; @@ -2824,7 +2839,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) inMainWndProc = FALSE; } - return ret; + return (LRESULT)ret; } case WM_PAINT: @@ -2846,7 +2861,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } EndPaint(hWnd, &ps); - return 1L; + return (LRESULT)1; } break; @@ -2942,9 +2957,19 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } b = getControlFromCursor(hWnd, NULL); - closeBalloonHelp(); + closeBalloonHelp(4); if (b && b->type == B_DRAW) { + // Change Num keypad to a special code to emulate cursor keys + if (wParam == VK_UP || + wParam == VK_DOWN || + wParam == VK_RIGHT || + wParam == VK_LEFT || + wParam == VK_INSERT || + wParam == VK_DELETE) + { + if ((lParam & 0x1000000) == 0) lParam |= 0x1000000; + } return SendMessage(b->hWnd, WM_CHAR, wParam, lParam); } @@ -2967,7 +2992,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - return 0L; + return (LRESULT)0; case 0x1B: @@ -2988,7 +3013,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } mswSetTrigger((wControl_p)TRIGGER_TIMER, NULL); - return 0L; + return (LRESULT)0; case 0x20: @@ -3010,7 +3035,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - return 0L; + return (LRESULT)0; case 0x09: @@ -3041,16 +3066,16 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - return 0L; + return (LRESULT)0; } /* Not a Draw control */ MessageBeep(MB_ICONHAND); - return 0L; + return (LRESULT)0; break; case WM_ENABLE: - if (wParam == 1) { /* WIN32??? */ + if (wParam == (WPARAM)1) { hWnd2 = SetFocus(hWnd); } @@ -3068,53 +3093,70 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } - closeBalloonHelp(); + closeBalloonHelp(5); wHelp(b->helpStr); - return 0L; + return (LRESULT)0; case WM_SETCURSOR: - /*if (any buttons down) - break;*/ - wSetCursor(NULL, curCursor); + if (hWnd == mswHWnd) + wSetCursor(NULL, curCursor); - if (!mswAllowBalloonHelp) { - return TRUE; - } - - if (IsIconic(mswHWnd)) { - return TRUE; - } + if (!mswAllowBalloonHelp) { + break; + } - b = getControlFromCursor(hWnd, NULL); + if (IsIconic(mswHWnd)) { + break; + } - if (b == balloonControlButton) { - return TRUE; - } + b = getControlFromCursor(hWnd, NULL); + +#ifdef BALLOON_TRACE + fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL"); fflush(logFile); +#endif + if (b == balloonControlButton) { + //closeBalloonHelp(61); + break; + } - if (/*(!IsWindowEnabled(hWnd))*/ GetActiveWindow() != hWnd || - (!b) || b->type == B_DRAW || b->helpStr == NULL) { - closeBalloonHelp(); - return TRUE; - } + if (GetActiveWindow() != hWnd) { + closeBalloonHelp(62); + break; + } + if (!b) { + closeBalloonHelp(63); + break; + } + if (b->type == B_DRAW) { + closeBalloonHelp(64); + break; + } + if (b->helpStr == NULL) { + closeBalloonHelp(65); + break; + } - if (b != balloonHelpButton) { - closeBalloonHelp(); - } + if (b != balloonHelpButton) { + closeBalloonHelp(7); + } +#ifdef BALLOON_TRACE + fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState); fflush(logFile); +#endif + if (balloonHelpState != balloonHelpIdle) { + break; + } - if (balloonHelpState != balloonHelpIdle) { - return TRUE; - } + balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, + balloonHelpTimeOut, NULL); - balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, - balloonHelpTimeOut, NULL); + if (balloonHelpTimer == (UINT_PTR)0) { + break; + } - if (balloonHelpTimer == (UINT)0) { - return TRUE; - } + balloonHelpState = balloonHelpWait; + balloonHelpButton = b; + break; - balloonHelpState = balloonHelpWait; - balloonHelpButton = b; - return TRUE; case WM_SYSCOMMAND: inx = GetWindowWord(hWnd, 0); @@ -3146,7 +3188,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } wWinShow(w, FALSE); - return 0L; + return (LRESULT)0; case WM_CLOSE: inx = GetWindowWord(hWnd, 0); @@ -3168,13 +3210,13 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) (w->winProc(w, wClose_e, NULL, NULL)); } - return 0L; + return (LRESULT)0; } case WM_DESTROY: if (hWnd == mswHWnd) { PostQuitMessage(0L); - return 0L; + return (LRESULT)0; } break; @@ -3192,15 +3234,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } else if (wParam == BALLOONHELP_TIMER) { KillTimer(hWnd, balloonHelpTimer); - balloonHelpTimer = (UINT)0; + balloonHelpTimer = (UINT_PTR)0; startBalloonHelp(); } - return 0L; + return (LRESULT)0; case WM_MENUSELECT: mswAllowBalloonHelp = TRUE; - closeBalloonHelp(); + closeBalloonHelp(8); break; case WM_WINDOWPOSCHANGED: @@ -3226,7 +3268,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_PALETTECHANGED: if (wParam == (WPARAM)hWnd) { - return 0L; + return (LRESULT)0; } case WM_QUERYNEWPALETTE: @@ -3240,12 +3282,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) InvalidateRect(hWnd, NULL, TRUE); } - return inx; + return (LRESULT)inx; } case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) { - closeBalloonHelp(); + closeBalloonHelp(9); } break; @@ -3272,7 +3314,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) inMainWndProc = FALSE; } - return ret; + return (LRESULT)ret; case WM_LBUTTONDOWN: case WM_MOUSEMOVE: @@ -3297,7 +3339,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) inMainWndProc = FALSE; } - return ret; + return (LRESULT)ret; default: ; @@ -3414,9 +3456,9 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, mResizeBorderW = GetSystemMetrics(SM_CXFRAME); mResizeBorderH = GetSystemMetrics(SM_CYFRAME); mMenuH = GetSystemMetrics(SM_CYMENU) + 1; - screenWidth = GetSystemMetrics(SM_CXSCREEN); - screenHeight = GetSystemMetrics(SM_CYSCREEN); - mswLabelFont = GetStockObject(DEFAULT_GUI_FONT); + screenWidth = GetSystemMetrics(SM_CXFULLSCREEN); + screenHeight = GetSystemMetrics(SM_CYFULLSCREEN); + mswLabelFont = GetStockObject(DEFAULT_GUI_FONT); hDc = GetDC(0); mswScale = GetDeviceCaps(hDc, LOGPIXELSX) / 96.0; @@ -3467,5 +3509,5 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, HtmlHelp(NULL, NULL, HH_UNINITIALIZE, (DWORD)dwCookie); } - return msg.wParam; + return (int)msg.wParam; } |