diff options
Diffstat (limited to 'app/wlib/mswlib/mswmisc.c')
-rw-r--r-- | app/wlib/mswlib/mswmisc.c | 266 |
1 files changed, 211 insertions, 55 deletions
diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c index e045cc8..6b5f1c9 100644 --- a/app/wlib/mswlib/mswmisc.c +++ b/app/wlib/mswlib/mswmisc.c @@ -22,6 +22,7 @@ #define _WIN32_WINNT 0x0500 #include <windows.h> +#include <shellapi.h> #include <string.h> #include <malloc.h> #include <stdlib.h> @@ -30,8 +31,10 @@ #include <stdio.h> #include <assert.h> #include <htmlhelp.h> +#include "misc.h" #include "mswint.h" #include "i18n.h" +#include "FreeImage.h" #if _MSC_VER > 1300 #define stricmp _stricmp @@ -47,6 +50,8 @@ char * mswStrdup(const char *); #define ALARM_TIMER (902) #define BALLOONHELP_TIMER (903) #define TRIGGER_TIMER (904) +#define CONTROLHILITEWIDTH (2) +#define CONTROLHILITECOLOR (RGB(0x3a,0x5f,0xcd)) #define WANT_LITTLE_LABEL_FONT @@ -78,6 +83,8 @@ HFONT mswLabelFont; long mswThickFont = 1; double mswScale = 1.0; +double scaleIcon = 1.0; /**< Scaling factor for toolbar icons */ + callBacks_t *mswCallBacks[CALLBACK_CNT]; void closeBalloonHelp(void); @@ -87,7 +94,12 @@ static wControl_p getControlFromCursor(HWND, wWin_p *); */ struct wWin_t { - WOBJ_COMMON + WOBJ_COMMON + int validGeometry; + int min_width; + int max_width; + int min_height; + int max_height; wPos_t lastX, lastY; wPos_t padX, padY; wControl_p first, last; @@ -174,7 +186,21 @@ static int dumpControls; extern char *userLocale; - +// list of supported fileformats for image files +char * filterImageFiles[] = { N_("All image files"), + "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff", + N_("GIF files (*.gif)"), + "*.gif", + N_("JPEG files (*.jpeg,*.jpg)"), + "*.jpg;*.jpeg", + N_("PNG files (*.png)"), + "*.png", + N_("TIFF files (*.tiff, *.tif)"), + "*.tif;*.tiff", + N_("All files (*)"), + "*", + }; + /* ***************************************************************************** * @@ -610,6 +636,35 @@ static void getSavedSizeAndPos( } /** + * Set min and max dimensions for a window. + * + * \param min_width IN minimum width of window + * \param max_width IN maximum width of window + * \param min_height IN minimum height of window + * \param max_height IN maximum height of window + * \param base_width IN unused on Windows + * \param base_height IN unused on Windows + * \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, + double aspect_ratio) +{ + win->validGeometry = TRUE; //remember that geometry was set + win->min_width = min_width; + win->max_width = max_width; + win->min_height = min_height; + win->max_height = max_height; + + return; +} + +/** * Create a window. Retrieves the saved size and position and restores the created window accordingly. * * \param hWnd IN parent window @@ -812,6 +867,10 @@ wWin_p wWinMainCreate( wPrefGetInteger("draw", "maximized", &maximize, 0L); option |= (maximize ? F_MAXIMIZE : 0); + wPrefGetFloat(PREFSECTION, LARGEICON, &scaleIcon, 1.0); + if (scaleIcon < 1.0) scaleIcon = 1.0; + if (scaleIcon > 2.0) scaleIcon = 2.0; + showCmd = SW_SHOW; w = winCommonCreate(NULL, W_MAIN, option|F_RESIZE, "MswMainWindow", WS_OVERLAPPEDWINDOW, labelStr, winProc, x, y, data, @@ -819,13 +878,10 @@ wWin_p wWinMainCreate( mswHWnd = w->hWnd; if (!mswThickFont) { - DWORD dw; SendMessage(w->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L); hDc = GetDC(w->hWnd); GetTextMetrics(hDc, &tm); mswEditHeight = tm.tmHeight+2; - dw = GetTextExtent(hDc, "AXqypj", 6); - mswEditHeight = HIWORD(dw)+2; ReleaseDC(w->hWnd, hDc); } @@ -1380,12 +1436,11 @@ void wWinClear( { } -void wSetCursor( +void wSetCursor(wDraw_p win, wCursor_t cursor) { switch (cursor) { case wCursorNormal: - case wCursorQuestion: default: SetCursor(LoadCursor(NULL, IDC_ARROW)); break; @@ -1401,6 +1456,42 @@ void wSetCursor( case wCursorIBeam: SetCursor(LoadCursor(NULL, IDC_IBEAM)); break; + + case wCursorQuestion: + SetCursor(LoadCursor(NULL, IDC_HELP)); + break; + + case wCursorHand: + SetCursor(LoadCursor(NULL, IDC_HAND)); + break; + + case wCursorNo: + SetCursor(LoadCursor(NULL, IDC_NO)); + break; + + case wCursorSizeAll: + SetCursor(LoadCursor(NULL, IDC_SIZEALL)); + break; + + case wCursorSizeNESW: + SetCursor(LoadCursor(NULL, IDC_SIZENESW)); + break; + + case wCursorSizeNWSE: + SetCursor(LoadCursor(NULL, IDC_SIZENWSE)); + break; + + case wCursorSizeNS: + SetCursor(LoadCursor(NULL, IDC_SIZENS)); + break; + + case wCursorSizeWE: + SetCursor(LoadCursor(NULL, IDC_SIZEWE)); + break; + + case wCursorAppStart: + SetCursor(LoadCursor(NULL, IDC_APPSTARTING)); + break; } curCursor = cursor; @@ -1663,7 +1754,7 @@ void wControlSetLabel( wControl_p b, const char * labelStr) { - if (b->type == B_RADIO || b->type == B_TOGGLE) { + if (b->type == B_RADIO ) { ; } else { int lab_l; @@ -1693,8 +1784,6 @@ void wControlSetContext( b->data = context; } -static int controlHiliteWidth = 5; -static int controlHiliteWidth2 = 3; void wControlHilite( wControl_p b, wBool_t hilite) @@ -1702,12 +1791,13 @@ void wControlHilite( HDC hDc; HPEN oldPen, newPen; int oldMode; + LOGBRUSH logBrush = { BS_SOLID, CONTROLHILITECOLOR, (ULONG_PTR)NULL }; if (b == NULL) { return; } - if (!IsWindowVisible(b->parent->hWnd)) { + if (!IsWindowVisible(b->parent->hWnd)) { return; } @@ -1716,14 +1806,18 @@ void wControlHilite( } hDc = GetDC(b->parent->hWnd); - newPen = CreatePen(PS_SOLID, controlHiliteWidth, RGB(0,0,0)); + newPen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND | PS_JOIN_BEVEL, + CONTROLHILITEWIDTH, + &logBrush, + 0, + NULL); oldPen = SelectObject(hDc, newPen); oldMode = SetROP2(hDc, R2_NOTXORPEN); - MoveTo(hDc, b->x-controlHiliteWidth2, b->y-controlHiliteWidth2); - LineTo(hDc, b->x+b->w+controlHiliteWidth2, b->y-controlHiliteWidth2); - LineTo(hDc, b->x+b->w+controlHiliteWidth2, b->y+b->h+controlHiliteWidth2); - LineTo(hDc, b->x-controlHiliteWidth2, b->y+b->h+controlHiliteWidth2); - LineTo(hDc, b->x-controlHiliteWidth2, b->y-controlHiliteWidth2); + Rectangle(hDc, + b->x - CONTROLHILITEWIDTH - 1, + b->y - CONTROLHILITEWIDTH - 1, + b->x + b->w + CONTROLHILITEWIDTH + 1, + b->y + b->h + CONTROLHILITEWIDTH + 1); SetROP2(hDc, oldMode); SelectObject(hDc, oldPen); DeleteObject(newPen); @@ -1766,6 +1860,26 @@ void wMessage( ReleaseDC(w->hWnd, hDc); } +/** + * Open a document using an external application + * + * \param file + * \return TRUE on success, FALSE on error + * + */ +unsigned wOpenFileExternal(char *file) +{ + HINSTANCE res; + + res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW); + + if ((int)res <= 32) { + wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL); + return(FALSE); + } + + return(TRUE); +} void wExit(int rc) { @@ -2040,12 +2154,22 @@ int wNotice3( } } +/** + * Show help text for the given topic. + * + * \param topic The topic. if NULL the index page is shown. + */ void wHelp( const char * topic) { char *pszHelpTopic; HWND hwndHelp; + char *theTopic = "index"; + + if (topic) { + theTopic = topic; + } if (!helpInitted) { HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ; @@ -2054,9 +2178,9 @@ void wHelp( /* "c:\\help.chm::/intro.htm>mainwin", */ /* attention: always adapt constant value (10) to needed number of formatting characters */ - pszHelpTopic = malloc(strlen(helpFile) + strlen(topic) + 10); + pszHelpTopic = malloc(strlen(helpFile) + strlen(theTopic) + 10); assert(pszHelpTopic != NULL); - sprintf(pszHelpTopic, "/%s.html", topic); + sprintf(pszHelpTopic, "/%s.html", theTopic); hwndHelp = HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOPIC, (DWORD_PTR)pszHelpTopic); @@ -2068,6 +2192,8 @@ void wHelp( } + + void doHelpMenu(void * context) { HH_FTS_QUERY ftsQuery; @@ -2092,6 +2218,13 @@ void doHelpMenu(void * context) HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD)&ftsQuery); break; + + case 3: /*Context*/ + const char * topic; + topic = GetCurCommandName(); + wHelp(topic); + break; + default: return; } @@ -2099,11 +2232,16 @@ void doHelpMenu(void * context) helpInitted = TRUE; } +void wDoAccelHelp(wAccelKey_e key, void * context) { + doHelpMenu(context); +} + void wMenuAddHelp( wMenu_p m) { - wMenuPushCreate(m, NULL, "&Contents", 0, doHelpMenu, (void*)1); - wMenuPushCreate(m, NULL, "&Search for Help on...", 0, doHelpMenu, (void*)2); + wMenuPushCreate(m, NULL, _("&Contents"), 0, doHelpMenu, (void*)1); + wMenuPushCreate(m, NULL, _("&Search for Help on..."), 0, doHelpMenu, (void*)2); + wMenuPushCreate(m, NULL, _("Co&mmand Context Help"), 0, doHelpMenu, (void*)3); } @@ -2326,6 +2464,24 @@ struct wFilSel_t { #define SELECTEDFILENAME_BUFFERSIZE (8*1024) /**<estimated size in case all param files are selected */ +char * +GetImageFileFormats(void) +{ + char *filter = malloc(2048); + char *current = filter; + char *message; + + for (int i = 0; i < sizeof(filterImageFiles) / sizeof(filterImageFiles[0]); i += 2) { + message = gettext(filterImageFiles[i]); + strcpy(current, message); + current += strlen(message) + 1; + strcpy(current, filterImageFiles[i + 1]); + current += strlen(current) + 1; + } + *current = '\0'; + return(filter); +} + /** * Run the file selector. After the selector is finished an array of filenames is * created. Each filename will be fully qualified. The array and the number of @@ -2356,11 +2512,16 @@ int wFilSelect( strcmp(dirName, ".") == 0) { dirName = wGetUserHomeDir(); } - memset(&ofn, 0, sizeof ofn); ofn.lStructSize = sizeof ofn; ofn.hwndOwner = mswHWnd; - ofn.lpstrFilter = fs->extList; + if (fs->option == FS_PICTURES) { + ofn.lpstrFilter = GetImageFileFormats(); + } + else { + ofn.lpstrFilter = fs->extList; + } + ofn.nFilterIndex = 0; selFileName = malloc(SELECTEDFILENAME_BUFFERSIZE); memset(selFileName, '\0', SELECTEDFILENAME_BUFFERSIZE); @@ -2599,6 +2760,23 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) wAccelKey_e extChar; switch (message) { + case WM_GETMINMAXINFO: + LPMINMAXINFO pMMI = (LPMINMAXINFO)lParam; + inx = GetWindowWord(hWnd, 0); + + if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) { + w = (wWin_p)controlMap(inx - CONTROL_BASE).b; + if (w != NULL) { + if (w->validGeometry) { + pMMI->ptMaxTrackSize.x = w->max_width; + pMMI->ptMaxTrackSize.y = w->max_height; + pMMI->ptMinTrackSize.x = w->min_width; + pMMI->ptMinTrackSize.y = w->min_height; + } + } + } + return(0); + case WM_MOUSEWHEEL: inx = GetWindowWord(hWnd, 0); b = getControlFromCursor(hWnd, NULL); @@ -2614,22 +2792,6 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_DRAWITEM: case WM_COMMAND: case WM_MEASUREITEM: - case WM_NOTVALID: - if (WCMD_PARAM_ID == IDM_DOHELP) { - b = getControlFromCursor(hWnd, NULL); - closeBalloonHelp(); - - if (!b) { - return 0L; - } - - if (b->helpStr) { - wHelp(b->helpStr); - } - - return 0L; - } - closeBalloonHelp(); if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) { @@ -2913,26 +3075,26 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_SETCURSOR: /*if (any buttons down) break;*/ - wSetCursor(curCursor); + wSetCursor(NULL, curCursor); if (!mswAllowBalloonHelp) { - break; + return TRUE; } if (IsIconic(mswHWnd)) { - break; + return TRUE; } b = getControlFromCursor(hWnd, NULL); if (b == balloonControlButton) { - break; + return TRUE; } if (/*(!IsWindowEnabled(hWnd))*/ GetActiveWindow() != hWnd || (!b) || b->type == B_DRAW || b->helpStr == NULL) { closeBalloonHelp(); - break; + return TRUE; } if (b != balloonHelpButton) { @@ -2940,19 +3102,19 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } if (balloonHelpState != balloonHelpIdle) { - break; + return TRUE; } balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, balloonHelpTimeOut, NULL); if (balloonHelpTimer == (UINT)0) { - break; + return TRUE; } balloonHelpState = balloonHelpWait; balloonHelpButton = b; - break; + return TRUE; case WM_SYSCOMMAND: inx = GetWindowWord(hWnd, 0); @@ -3211,13 +3373,13 @@ static BOOL InitApplication(HINSTANCE hinstCurrent) return FALSE; } - wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC; + wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC | CS_DBLCLKS; wc.lpfnWndProc = mswDrawPush; wc.lpszClassName = mswDrawWindowClassName; wc.cbWndExtra = 4; if (!RegisterClass(&wc)) { - mswFail("RegisterClass(drawClass)"); + mswFail("RegisterClass(drawClass)"); return FALSE; } @@ -3238,8 +3400,6 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, HDC hDc; char **argv; int argc; - TEXTMETRIC tm; - DWORD dw; if (!hinstPrevious) { if (!InitApplication(hinstCurrent)) { @@ -3264,10 +3424,6 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, mswScale = 1.0; } - GetTextMetrics(hDc, &tm); - mswEditHeight = tm.tmHeight + 8; - dw = GetTextExtent(hDc, "AXqypj", 6); - mswEditHeight = HIWORD(dw)+2; ReleaseDC(0, hDc); mswCreateCheckBitmaps(); /* |