diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:24 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:24 +0100 |
commit | 5d2c2b27a6323e2666378b986129b2a7c2c39e5c (patch) | |
tree | ce8982b6c0111f79791068de2c2d4c6ce3138a49 /app/wlib/mswlib | |
parent | b623f5953691b2a0614e6f1f4def86bdbb9a4113 (diff) |
New upstream version 5.2.2GAupstream/5.2.2GA
Diffstat (limited to 'app/wlib/mswlib')
-rw-r--r-- | app/wlib/mswlib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | app/wlib/mswlib/backgnd.c | 367 | ||||
-rw-r--r-- | app/wlib/mswlib/dynarr.h | 4 | ||||
-rw-r--r-- | app/wlib/mswlib/gwin32.c | 2 | ||||
-rw-r--r-- | app/wlib/mswlib/mswbitmap.c | 22 | ||||
-rw-r--r-- | app/wlib/mswlib/mswbox.c | 14 | ||||
-rw-r--r-- | app/wlib/mswlib/mswbutt.c | 155 | ||||
-rw-r--r-- | app/wlib/mswlib/mswchoic.c | 87 | ||||
-rw-r--r-- | app/wlib/mswlib/mswcolor.c | 13 | ||||
-rw-r--r-- | app/wlib/mswlib/mswdraw.c | 409 | ||||
-rw-r--r-- | app/wlib/mswlib/mswedit.c | 115 | ||||
-rw-r--r-- | app/wlib/mswlib/mswint.h | 179 | ||||
-rw-r--r-- | app/wlib/mswlib/mswlines.c | 2 | ||||
-rw-r--r-- | app/wlib/mswlib/mswlist.c | 238 | ||||
-rw-r--r-- | app/wlib/mswlib/mswmenu.c | 38 | ||||
-rw-r--r-- | app/wlib/mswlib/mswmisc.c | 676 | ||||
-rw-r--r-- | app/wlib/mswlib/mswmsg.c | 75 | ||||
-rw-r--r-- | app/wlib/mswlib/mswpref.c | 47 | ||||
-rw-r--r-- | app/wlib/mswlib/mswprint.c | 23 | ||||
-rw-r--r-- | app/wlib/mswlib/mswsplash.c | 9 | ||||
-rw-r--r-- | app/wlib/mswlib/mswstatus.c | 14 | ||||
-rw-r--r-- | app/wlib/mswlib/mswtext.c | 78 | ||||
-rw-r--r-- | app/wlib/mswlib/simple-gettext.c | 8 | ||||
-rw-r--r-- | app/wlib/mswlib/utf8conv.c | 4 |
24 files changed, 1350 insertions, 1230 deletions
diff --git a/app/wlib/mswlib/CMakeLists.txt b/app/wlib/mswlib/CMakeLists.txt index 07558f9..99ac1d4 100644 --- a/app/wlib/mswlib/CMakeLists.txt +++ b/app/wlib/mswlib/CMakeLists.txt @@ -29,6 +29,7 @@ SET(SOURCES include_directories(${FREEIMAGE_INCLUDE_PATH}) INCLUDE_DIRECTORIES(${XTrkCAD_BINARY_DIR}) +# INCLUDE_DIRECTORIES(${help_BINARY_DIR}) IF(XTRKCAD_USE_GETTEXT) IF(WIN32) diff --git a/app/wlib/mswlib/backgnd.c b/app/wlib/mswlib/backgnd.c index d35f19a..9599beb 100644 --- a/app/wlib/mswlib/backgnd.c +++ b/app/wlib/mswlib/backgnd.c @@ -29,192 +29,215 @@ static char *lastErrorMessage; /**< store last message from FreeImage */ #define ERRORPUNCTUATION " : " -/**
- * FreeImage error handler
- * \param fif Format / Plugin responsible for the error
- * \param message Error message
+/** + * FreeImage error handler + * \param fif Format / Plugin responsible for the error + * \param message Error message */ -static void
-HandleFreeImageError(FREE_IMAGE_FORMAT fif, const char *message)
-{
- unsigned totalLength = strlen(message) + 1;
-
- if (fif != FIF_UNKNOWN) {
- totalLength += strlen(FreeImage_GetFormatFromFIF(fif)) + strlen(ERRORPUNCTUATION);
- }
-
- lastErrorMessage = malloc(totalLength);
-
- if (fif != FIF_UNKNOWN) {
- sprintf(lastErrorMessage,
- "%s" ERRORPUNCTUATION "%s",
- FreeImage_GetFormatFromFIF(fif),
- message);
- } else {
- strcpy(lastErrorMessage, message);
- }
+static void +HandleFreeImageError( FREE_IMAGE_FORMAT fif, const char *message ) +{ + size_t totalLength = strlen( message ) + 1; + + if( fif != FIF_UNKNOWN ) { + totalLength += strlen( FreeImage_GetFormatFromFIF( fif ) ) + strlen( + ERRORPUNCTUATION ); + } + + lastErrorMessage = malloc( totalLength ); + + if( fif != FIF_UNKNOWN ) { + sprintf( lastErrorMessage, + "%s" ERRORPUNCTUATION "%s", + FreeImage_GetFormatFromFIF( fif ), + message ); + } else { + strcpy( lastErrorMessage, message ); + } } -/**
-* Load the background image
-* \param bd drawing context
-* \param path filename for image file, if NULL the existing background will be removed
-* \param error returned error message
-* \return -1 unsupported or invalid file, 0 success, 1 background removed
+/** +* Load the background image +* \param bd drawing context +* \param path filename for image file, if NULL the existing background will be removed +* \param error returned error message +* \return -1 unsupported or invalid file, 0 success, 1 background removed */ int -wDrawSetBackground(wDraw_p bd, char * path, char ** error) +wDrawSetBackground( wDraw_p bd, char * path, char ** error ) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + FreeImage_SetOutputMessage( HandleFreeImageError ); - FreeImage_SetOutputMessage(HandleFreeImageError); -
- if (lastErrorMessage) {
- free(lastErrorMessage);
- lastErrorMessage = NULL;
+ if( lastErrorMessage ) { + free( lastErrorMessage ); + lastErrorMessage = NULL; } - if (path) { - // check the file signature and deduce its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(path, 0); - - if (fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(path); - } - - // check that the plugin has reading capabilities ... - if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // ok, let's load the file - bd->background = FreeImage_Load(fif, path, 0); - - // unless a bad file format, we are done ! - if (!bd->background) { - *error = lastErrorMessage; - return (-1); - } else { - return (0); - } - } else { - *error = strdup(_("Image file is invalid or cannot be read.")); - return (-1); - } - } else { - if (bd->background) { - FreeImage_Unload(bd->background); - bd->background = 0; - } - - return (1); - } + if( path ) { + // check the file signature and deduce its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType( path, 0 ); + + if( fif == FIF_UNKNOWN ) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename( path ); + } + + // check that the plugin has reading capabilities ... + if( ( fif != FIF_UNKNOWN ) && FreeImage_FIFSupportsReading( fif ) ) { + // ok, let's load the file + bd->background = FreeImage_Load( fif, path, 0 ); + + // unless a bad file format, we are done ! + if( !bd->background ) { + *error = lastErrorMessage; + return ( -1 ); + } else { + return ( 0 ); + } + } else { + *error = _strdup( _( "Image file is invalid or cannot be read." ) ); + return ( -1 ); + } + } else { + if( bd->background ) { + FreeImage_Unload( bd->background ); + bd->background = 0; + } + + return ( 1 ); + } } +/** + * Use a loaded background in another context. + * + * \param from context with background + * \param to context to get a reference to the existing background + */ -/**
-* Draw background to screen. The background will be sized and rotated before being shown. The bitmap
-* is scaled so that the width is equal to size. The height is changed proportionally.
-*
-* \param bd drawing context
-* \param pos_x, pos_y bitmap position
-* \param size desired width after scaling
-* \param angle
-* \param screen visibility of bitmap in percent
+void +wDrawCloneBackground( wDraw_p from, wDraw_p to ) +{ + if( from->background ) { + to->background = from->background; + } else { + to->background = NULL; + } +} + +/** +* Draw background to screen. The background will be sized and rotated before being shown. The bitmap +* is scaled so that the width is equal to size. The height is changed proportionally. +* +* \param bd drawing context +* \param pos_x, pos_y bitmap position +* \param size desired width after scaling +* \param angle +* \param screen visibility of bitmap in percent */ void -wDrawShowBackground(wDraw_p bd, wPos_t pos_x, wPos_t pos_y, wPos_t size, - wAngle_t angle, int screen) +wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, + wWinPix_t size, + wAngle_t angle, int screen ) { - if (bd->background) { - double scale; - FIBITMAP *tmp; - FIBITMAP *rotated; - - if (size == 0) { - scale = 1.0; - } else { - scale = (double)size / FreeImage_GetWidth(bd->background); - } - - tmp = FreeImage_RescaleRect(bd->background, - (int)((double)FreeImage_GetWidth(bd->background) * scale), - (int)((double)FreeImage_GetHeight(bd->background) * scale), - 0, - 0, - FreeImage_GetWidth(bd->background), - FreeImage_GetHeight(bd->background), - FILTER_BILINEAR, - 0); - FreeImage_AdjustColors(tmp, screen, -screen, 1.0, FALSE); - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(tmp); - - switch (image_type) { - case FIT_BITMAP: - switch (FreeImage_GetBPP(tmp)) { - case 8: { - BYTE color = 255; - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case 24: // we could also use 'RGBTRIPLE color' here - case 32: { - RGBQUAD color = { 255, 255, 255, 0 }; - // for 24-bit images, the first 3 bytes will be read - // for 32-bit images, the first 4 bytes will be read - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - } - - break; - - case FIT_UINT16: { - WORD color = 255; - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case FIT_RGB16: // we could also use 'FIRGB16 color' here - case FIT_RGBA16: { - FIRGBA16 color = { 255, 255, 255, 0 }; - // for RGB16 images, the first 3 WORD will be read - // for RGBA16 images, the first 4 WORD will be read - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case FIT_FLOAT: { - float color = 1.0F; - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case FIT_RGBF: // we could also use 'FIRGBF color' here - case FIT_RGBAF: { - FIRGBAF color = { 1, 1, 1, 0 }; - // for RGBF images, the first 3 float will be read - // for RGBAF images, the first 4 float will be read - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - } - - SetDIBitsToDevice(bd->hDc, - pos_x, - bd->h - pos_y - FreeImage_GetHeight(rotated), - FreeImage_GetWidth(rotated), - FreeImage_GetHeight(rotated), - 0, 0, - 0, - FreeImage_GetHeight(rotated), - FreeImage_GetBits(rotated), - FreeImage_GetInfo(rotated), - DIB_RGB_COLORS); - FreeImage_Unload(tmp); - FreeImage_Unload(rotated); - } -}
\ No newline at end of file + if( bd->background ) { + double scale; + FIBITMAP *tmp; + FIBITMAP *rotated; + + if( size == 0 ) { + scale = 1.0; + } else { + scale = ( double )size / FreeImage_GetWidth( bd->background ); + } + + tmp = FreeImage_RescaleRect( bd->background, + ( int )( ( double )FreeImage_GetWidth( bd->background ) * scale ), + ( int )( ( double )FreeImage_GetHeight( bd->background ) * scale ), + 0, + 0, + FreeImage_GetWidth( bd->background ), + FreeImage_GetHeight( bd->background ), + FILTER_BILINEAR, + 0 ); + + if( tmp == NULL ) { + return; + } + + FreeImage_AdjustColors( tmp, screen, -screen, 1.0, FALSE ); + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType( tmp ); + + switch( image_type ) { + case FIT_BITMAP: + switch( FreeImage_GetBPP( tmp ) ) { + case 8: { + BYTE color = 255; + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case 24: // we could also use 'RGBTRIPLE color' here + case 32: { + RGBQUAD color = { 255, 255, 255, 0 }; + // for 24-bit images, the first 3 bytes will be read + // for 32-bit images, the first 4 bytes will be read + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + } + + break; + + case FIT_UINT16: { + WORD color = 255; + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case FIT_RGB16: // we could also use 'FIRGB16 color' here + case FIT_RGBA16: { + FIRGBA16 color = { 255, 255, 255, 0 }; + // for RGB16 images, the first 3 WORD will be read + // for RGBA16 images, the first 4 WORD will be read + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case FIT_FLOAT: { + float color = 1.0F; + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case FIT_RGBF: // we could also use 'FIRGBF color' here + case FIT_RGBAF: { + FIRGBAF color = { 1, 1, 1, 0 }; + // for RGBF images, the first 3 float will be read + // for RGBAF images, the first 4 float will be read + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + } + + SetDIBitsToDevice( bd->hDc, + pos_x, + bd->h - pos_y - FreeImage_GetHeight( rotated ), + FreeImage_GetWidth( rotated ), + FreeImage_GetHeight( rotated ), + 0, 0, + 0, + FreeImage_GetHeight( rotated ), + FreeImage_GetBits( rotated ), + FreeImage_GetInfo( rotated ), + DIB_RGB_COLORS ); + FreeImage_Unload( tmp ); + FreeImage_Unload( rotated ); + } +} diff --git a/app/wlib/mswlib/dynarr.h b/app/wlib/mswlib/dynarr.h index 5bd7a8e..e8a178e 100644 --- a/app/wlib/mswlib/dynarr.h +++ b/app/wlib/mswlib/dynarr.h @@ -31,10 +31,6 @@ typedef struct { #ifdef WINDOWS -#ifndef WIN32 -#define FAR _far -#endif -#define M_PI 3.14159 #define strcasecmp _stricmp #else #endif diff --git a/app/wlib/mswlib/gwin32.c b/app/wlib/mswlib/gwin32.c index 6b0c7f3..877c329 100644 --- a/app/wlib/mswlib/gwin32.c +++ b/app/wlib/mswlib/gwin32.c @@ -40,7 +40,7 @@ #include <errno.h> #include <ctype.h> #if defined(_MSC_VER) || defined(__DMC__) -# include <io.h> +#include <io.h> #endif /* _MSC_VER || __DMC__ */ #ifndef SUBLANG_SERBIAN_LATIN_BA diff --git a/app/wlib/mswlib/mswbitmap.c b/app/wlib/mswlib/mswbitmap.c index 95b8a69..d4ee83c 100644 --- a/app/wlib/mswlib/mswbitmap.c +++ b/app/wlib/mswlib/mswbitmap.c @@ -29,7 +29,6 @@ #include <commdlg.h> #include <stdio.h> #include <assert.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" @@ -49,8 +48,8 @@ HBITMAP mswCreateBitMap( COLORREF fgCol1, COLORREF fgCol2, COLORREF bgCol, - wPos_t w, - wPos_t h, + int w, + int h, const char * bits ) { HDC hDc; @@ -100,7 +99,7 @@ HBITMAP mswCreateBitMap( return hBitMap; } -dynArr_t bitmap_da; +static dynArr_t bitmap_da; #define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N) #define bitmap(N) DYNARR_N(HBITMAP,bitmap_da,N) @@ -252,7 +251,7 @@ void mswDrawIcon( * \return pointer to icon */ -wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor color ) +wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawColor color ) { int lineLength; int i, j; @@ -330,12 +329,13 @@ wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor col wIcon_p wIconCreatePixMap( char *pm[]) { wIcon_p ip; - int col, r, g, b, len; + int col, r, g, b; + size_t len; int width, height; char buff[3]; char * cp, * cq, * ptr; int i, j, k; - int lineLength; + size_t lineLength; unsigned *keys; unsigned numchars; unsigned pixel; @@ -473,7 +473,7 @@ void wIconSetColor( wIcon_p ip, wDrawColor color ) */ void -wIconDraw( wDraw_p d, wIcon_p bm, wPos_t x, wPos_t y ) +wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y ) { mswDrawIcon( d->hDc, (int)x, (int)y, bm, FALSE, 0, 0 ); } @@ -489,7 +489,7 @@ wIconDraw( wDraw_p d, wIcon_p bm, wPos_t x, wPos_t y ) */ wControl_p -wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP ) +wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option, const struct wIcon_t * iconP ) { wBitmap_p control; int index; @@ -502,7 +502,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP ) control->hWnd = CreateWindow( "STATIC", NULL, style, control->x, control->y, iconP->w, iconP->h, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (control->hWnd == NULL) { mswFail("CreateWindow(BITMAP)"); @@ -510,7 +510,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP ) } control->h = iconP->h; control->w = iconP->w; - control->data = iconP; + control->data = (void*)iconP; return (wControl_p)control; } diff --git a/app/wlib/mswlib/mswbox.c b/app/wlib/mswlib/mswbox.c index 04b3656..4f90cf4 100644 --- a/app/wlib/mswlib/mswbox.c +++ b/app/wlib/mswlib/mswbox.c @@ -30,8 +30,8 @@ struct wBox_t { void wBoxSetSize( wBox_p bb, - wPos_t w, - wPos_t h ) + wWinPix_t w, + wWinPix_t h ) { bb->w = w; bb->h = h; @@ -42,7 +42,7 @@ static void repaintBox( HWND hWnd, wControl_p b ) { HDC hDc; wBox_p bb = (wBox_p)(b); - wPos_t x0, y0, x1, y1; + wWinPix_t x0, y0, x1, y1; char lastColor; int lastRop; static char colors[8][4][2] = { @@ -95,12 +95,12 @@ static callBacks_t boxCallBacks = { wBox_p wBoxCreate( wWin_p parent, - wPos_t origX, - wPos_t origY, + wWinPix_t origX, + wWinPix_t origY, const char * labelStr, wBoxType_e typ, - wPos_t width, - wPos_t height ) + wWinPix_t width, + wWinPix_t height ) { wBox_p b; int index; diff --git a/app/wlib/mswlib/mswbutt.c b/app/wlib/mswlib/mswbutt.c index 16f31c1..ac5bc87 100644 --- a/app/wlib/mswlib/mswbutt.c +++ b/app/wlib/mswlib/mswbutt.c @@ -27,7 +27,15 @@ #include <commdlg.h> #include <math.h> #include "mswint.h" -int kludge12 = 0; + +/** Macros for button repeat timers */ +#define REPEAT_STAGE0_DELAY 500 +#define REPEAT_STAGE1_DELAY 150 +#define REPEAT_STAGE2_DELAY 75 +#define STOP_TIMER (-1) +#define INITIAL_WAIT (0) +#define SLOW_REPEATS (1) +#define FAST_REPEATS (2) /* ***************************************************************************** @@ -45,6 +53,9 @@ struct wButton_t { wBool_t busy; wBool_t selected; wIcon_p icon; + UINT_PTR timer_id; + int timer_count; + int timer_state; }; @@ -75,7 +86,7 @@ static void drawButton( HPEN oldPen, newPen; RECT rect; COLORREF color1, color2; - POS_T offw=5, offh=5; + wWinPix_t offw=5, offh=5; TRIVERTEX vert[2] ; GRADIENT_RECT gRect; @@ -191,7 +202,7 @@ static void buttDrawIcon( HDC butt_hDc ) { wIcon_p bm = b->icon; - POS_T offw=5, offh=5; + wWinPix_t offw=5, offh=5; if (b->selected || b->busy) { offw++; offh++; @@ -204,14 +215,22 @@ static void buttDrawIcon( } void wButtonSetBusy( - wButton_p b, - int value ) + wButton_p b, + int value) { - b->busy = value; - if (!value) - b->selected = FALSE; - /*SendMessage( b->hWnd, BM_SETSTATE, (WPARAM)value, 0L );*/ - InvalidateRgn( b->hWnd, NULL, FALSE ); + b->busy = value; + if (!value) { + b->selected = FALSE; + } + + // in case a timer is associated with the button, kill it + if (b->timer_id) { + KillTimer(b->hWnd, b->timer_id); + b->timer_id = 0; + b->timer_state = STOP_TIMER; + } + + InvalidateRgn(b->hWnd, NULL, FALSE); } @@ -227,6 +246,60 @@ void wButtonSetLabel( } InvalidateRgn( b->hWnd, NULL, FALSE ); } + +/** + * Button timer: handle timer events for buttons. These are used for + * auto-repeating presses. Three phases used are + * - initial delay before repetitions begin + * - slow repeats for a few cycles + * - fast repeats therafter + * - stop timer + * + * \param hWnd Handle of the window, unused + * \param message The message, unused + * \param timer The timer id is the wlib widget . + * \param timepast The timepast, unused + */ + +void CALLBACK buttTimer(HWND hWnd, UINT message, UINT_PTR timer, + DWORD timepast) +{ + wButton_p b = (wButton_p)timer; + if (b->timer_id == 0) { + b->timer_state = STOP_TIMER; + return ; + } + + /* Autorepeat state machine */ + switch (b->timer_state) { + case INITIAL_WAIT: + b->timer_state = SLOW_REPEATS; + b->timer_count = 0; + KillTimer(hWnd, (UINT_PTR)b); + SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE1_DELAY, buttTimer); + break; + case SLOW_REPEATS: /* Enable slow auto-repeat */ + if (b->timer_count++ > 10) { + /* Start fast auto-repeat */ + b->timer_state = FAST_REPEATS; + KillTimer(hWnd, (UINT_PTR)b); + SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE2_DELAY, buttTimer); + } + break; + case FAST_REPEATS: + break; + case STOP_TIMER: + default: + KillTimer(hWnd, (UINT_PTR)b); + b->timer_id = 0; + return; + break; + } + if (b->action) { + b->action(b->data); + } + return; +} static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) @@ -240,7 +313,7 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L case WM_COMMAND: if (bb->action /*&& !bb->busy*/) { bb->action( bb->data ); - return 0L; + return (LRESULT)0; } break; @@ -249,10 +322,10 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L if (bb->type != B_BUTTON || (bb->option & BO_ICON) == 0) break; mi->CtlType = ODT_BUTTON; - mi->CtlID = wParam; + mi->CtlID = (UINT)wParam; mi->itemWidth = (UINT)ceil(bb->w*scaleIcon); mi->itemHeight = (UINT)ceil(bb->h*scaleIcon); - } return 0L; + } return (LRESULT)0; case WM_DRAWITEM: if (bb->type == B_BUTTON && (bb->option & BO_ICON) != 0) { @@ -261,10 +334,9 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L bb->selected = selected; InvalidateRgn( bb->hWnd, NULL, FALSE ); } - return TRUE; + return (LRESULT)TRUE; } break; - } return DefWindowProc( hWnd, message, wParam, lParam ); } @@ -279,15 +351,12 @@ static void buttDone( LRESULT CALLBACK pushButt( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif + + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wButton_p b = (wButton_p)mswMapIndex( inx ); PAINTSTRUCT ps; @@ -297,7 +366,7 @@ LRESULT CALLBACK pushButt( BeginPaint( hWnd, &ps ); buttDrawIcon( (wButton_p)b, ps.hdc ); EndPaint( hWnd, &ps ); - return 1L; + return (LRESULT)1; } break; case WM_CHAR: @@ -311,18 +380,29 @@ LRESULT CALLBACK pushButt( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LONG_PTR)0; } } break; case WM_KILLFOCUS: if ( b ) InvalidateRect( b->hWnd, NULL, TRUE ); - return 0L; + return (LRESULT)0; + break; + case WM_LBUTTONDOWN: + if (b->option&BO_REPEAT) { + SetTimer(hWnd, (UINT_PTR)b,REPEAT_STAGE0_DELAY,buttTimer); + b->timer_state = INITIAL_WAIT; + b->timer_id = (UINT_PTR)b; + } break; - case WM_LBUTTONUP: - /* don't know why but this solves a problem with color selection */ - Sleep( 0 ); + case WM_LBUTTONUP: + /* don't know why but this solves a problem with color selection */ + Sleep( 0 ); + if (b->timer_id) + KillTimer(hWnd, (UINT_PTR)b); + b->timer_id = 0; + b->timer_state = STOP_TIMER; break; } return CallWindowProc( oldButtProc, hWnd, message, wParam, lParam ); @@ -335,12 +415,12 @@ static callBacks_t buttonCallBacks = { wButton_p wButtonCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - wPos_t width, + wWinPix_t width, wButtonCallBack_p action, void * data ) { @@ -366,11 +446,11 @@ wButton_p wButtonCreate( b->selected = 0; mswComputePos( (wControl_p)b, x, y ); if (b->option&BO_ICON) { - width = (wPos_t)ceil(bm->w*scaleIcon)+10; + width = (wWinPix_t)ceil(bm->w*scaleIcon)+10; h = (int)ceil(bm->h*scaleIcon)+10; b->icon = bm; } else { - width = (wPos_t)(width*mswScale); + width = (wWinPix_t)(width*mswScale); } style = ((b->option&BO_ICON)? BS_OWNERDRAW : BS_PUSHBUTTON) | WS_CHILD | WS_VISIBLE | @@ -379,7 +459,7 @@ wButton_p wButtonCreate( style |= BS_DEFPUSHBUTTON; b->hWnd = CreateWindow( "BUTTON", labelStr, style, b->x, b->y, /*CW_USEDEFAULT, CW_USEDEFAULT,*/ width, h, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(BUTTON)"); return b; @@ -393,7 +473,10 @@ wButton_p wButtonCreate( mswCallBacks[B_BUTTON] = &buttonCallBacks; mswChainFocus( (wControl_p)b ); - oldButtProc = (WNDPROC) SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt); + oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)&pushButt); +#ifdef _OLDCODE + oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt); +#endif if (mswPalette) { hDc = GetDC( b->hWnd ); SelectPalette( hDc, mswPalette, 0 ); @@ -401,7 +484,7 @@ wButton_p wButtonCreate( ReleaseDC( b->hWnd, hDc ); } if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); InvalidateRect(b->hWnd, &rect, TRUE); diff --git a/app/wlib/mswlib/mswchoic.c b/app/wlib/mswlib/mswchoic.c index 2ac391a..55ed177 100644 --- a/app/wlib/mswlib/mswchoic.c +++ b/app/wlib/mswlib/mswchoic.c @@ -15,8 +15,8 @@ ***************************************************************************** */ -int CHOICE_HEIGHT=(17); -int CHOICE_MIN_WIDTH=25; +#define CHOICE_HEIGHT (17) +#define CHOICE_MIN_WIDTH (25) static XWNDPROC oldChoiceItemProc = NULL; static XWNDPROC newChoiceItemProc; @@ -28,7 +28,7 @@ typedef struct { struct wChoice_t { WOBJ_COMMON - const char * * labels; + const char * const * labels; wChoiceItem_p *buttList; long *valueP; long oldVal; @@ -42,14 +42,14 @@ void wRadioSetValue( wChoice_p bc, long val ) { - const char ** labels; + const char * const * labels; long cnt; wChoiceItem_p * butts; butts = (wChoiceItem_p*)bc->buttList; for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ ) SendMessage( (*butts)->hWnd, BM_SETCHECK, - (val==cnt)?1:0, 0L ); + (WPARAM)((val==cnt)?1:0), (LPARAM)0 ); bc->oldVal = val; if (bc->valueP) *bc->valueP = val; @@ -67,14 +67,14 @@ void wToggleSetValue( wChoice_p bc, long val ) { - const char ** labels; + const char * const * labels; long cnt; wChoiceItem_p * butts; butts = (wChoiceItem_p*)bc->buttList; for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ ) SendMessage( (*butts)->hWnd, BM_SETCHECK, - (val & (1L<<cnt)) != 0, 0L ); + (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 ); bc->oldVal = val; if (bc->valueP) *bc->valueP = val; @@ -115,12 +115,12 @@ static void choiceShow( static void choiceSetPos( wControl_p b, - wPos_t x, - wPos_t y ) + wWinPix_t x, + wWinPix_t y ) { wChoice_p bc = (wChoice_p)b; wChoiceItem_p * butts; - wPos_t dx, dy; + wWinPix_t dx, dy; dx = x - bc->x; dy = y - bc->y; @@ -129,8 +129,10 @@ static void choiceSetPos( SWP_NOSIZE|SWP_NOZORDER ); for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) { + (*butts)->x += dx; + (*butts)->y += dy; SetWindowPos( (*butts)->hWnd, HWND_TOP, - (*butts)->x+=dx, (*butts)->y+=dy, + (*butts)->x, (*butts)->y, CW_USEDEFAULT, CW_USEDEFAULT, SWP_NOSIZE|SWP_NOZORDER ); } @@ -138,19 +140,14 @@ static void choiceSetPos( bc->y = y; } -long FAR PASCAL _export pushChoiceItem( +LRESULT FAR PASCAL _export pushChoiceItem( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif - + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wControl_p b = mswMapIndex( inx ); switch (message) { @@ -165,7 +162,7 @@ long FAR PASCAL _export pushChoiceItem( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LRESULT)0; } } break; @@ -194,20 +191,20 @@ LRESULT choiceItemProc( for (rest = (wChoiceItem_p*)bc->buttList; *rest; rest++ ) { switch (bc->type) { case B_TOGGLE: - num = rest-(wChoiceItem_p*)bc->buttList; + num = (int)(rest-(wChoiceItem_p*)bc->buttList); if (*rest == me) { bc->oldVal ^= (1L<<num); } SendMessage( (*rest)->hWnd, BM_SETCHECK, - (bc->oldVal & (1L<<num)) != 0, 0L ); + (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 ); break; case B_RADIO: if (*rest != me) { - SendMessage( (*rest)->hWnd, BM_SETCHECK, 0, 0L ); + SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)0, (LPARAM)0 ); } else { - bc->oldVal = rest-(wChoiceItem_p*)bc->buttList; - SendMessage( (*rest)->hWnd, BM_SETCHECK, 1, 0L ); + bc->oldVal = (long)(rest-(wChoiceItem_p*)bc->buttList); + SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)1, (LPARAM)0 ); } break; } @@ -259,25 +256,25 @@ static callBacks_t choiceItemCallBacks = { static wChoice_p choiceCreate( wType_e type, wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const * labels, long *valueP, wChoiceCallBack_p action, void *data ) { wChoice_p b; - const char ** lp; + const char * const * lp; int cnt; wChoiceItem_p * butts; - int ppx, ppy; + wWinPix_t ppx, ppy; int bs; HDC hDc; HWND hButt; - int lab_l; + size_t lab_l; DWORD dw; int w, maxW; int pw, ph; @@ -319,7 +316,7 @@ static wChoice_p choiceCreate( (*butts)->hWnd = hButt = CreateWindow( "BUTTON", (*butts)->labelStr, bs | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x+pw, b->y+ph, 80, CHOICE_HEIGHT, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if ( hButt == (HWND)0 ) { mswFail( "choiceCreate button" ); return b; @@ -334,7 +331,7 @@ static wChoice_p choiceCreate( lab_l = strlen((*butts)->labelStr); if (!mswThickFont) {hFont = SelectObject( hDc, mswLabelFont );} - dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), lab_l ); + dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), (UINT)lab_l ); if (!mswThickFont) {SelectObject( hDc, hFont );} w = LOWORD(dw) + CHOICE_MIN_WIDTH; @@ -354,10 +351,14 @@ static wChoice_p choiceCreate( } mswChainFocus( (wControl_p)*butts ); newChoiceItemProc = MakeProcInstance( (XWNDPROC)pushChoiceItem, mswHInst ); - oldChoiceItemProc = (XWNDPROC)GetWindowLong( (*butts)->hWnd, GWL_WNDPROC ); - SetWindowLong( (*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc ); + oldChoiceItemProc = (XWNDPROC)GetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC); + SetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC, (LPARAM)newChoiceItemProc); +#ifdef _OLDCODE + oldChoiceItemProc = (XWNDPROC)GetWindowLong((*butts)->hWnd, GWL_WNDPROC); + SetWindowLong((*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc); +#endif if ( !mswThickFont ) - SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); } *butts = NULL; switch (b->type) { @@ -392,12 +393,12 @@ static wChoice_p choiceCreate( wChoice_p wRadioCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data ) @@ -408,12 +409,12 @@ wChoice_p wRadioCreate( wChoice_p wToggleCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data ) diff --git a/app/wlib/mswlib/mswcolor.c b/app/wlib/mswlib/mswcolor.c index 41bf6a9..fb9b0ba 100644 --- a/app/wlib/mswlib/mswcolor.c +++ b/app/wlib/mswlib/mswcolor.c @@ -25,8 +25,8 @@ #define NUM_GRAYS (16) #define NUM_COLORS (256) -wDrawColor wDrawColorWhite = 0; -wDrawColor wDrawColorBlack = 1; +static wDrawColor wDrawColorWhite = 0; +static wDrawColor wDrawColorBlack = 1; #define MAX_COLOR_DISTANCE (3) @@ -45,8 +45,6 @@ static struct { { 0, 0, 0 } /* Black */ } }; -COLORREF mappedColors[NUM_COLORS]; - static long flipRGB( long rgb ) { @@ -236,6 +234,7 @@ static void mswGetCustomColors( void ) strcpy( colorName, "custom-" ); for ( inx=0; inx<16; inx++ ) { sprintf( colorName+7, "%d", inx ); + /** @prefs [mswcolor] custom-0=<rgb> to custom-15=<rgb> Set custom colors */ wPrefGetInteger( "mswcolor", colorName, &rgb, 0 ); aclrCust[inx] = flipRGB(rgb); } @@ -316,12 +315,12 @@ static void doColorButton( wButton_p wColorSelectButtonCreate( wWin_p win, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - wPos_t width, + wWinPix_t width, wDrawColor * color, wColorSelectButtonCallBack_p action, void * data ) diff --git a/app/wlib/mswlib/mswdraw.c b/app/wlib/mswlib/mswdraw.c index c2739e6..be5bcd6 100644 --- a/app/wlib/mswlib/mswdraw.c +++ b/app/wlib/mswlib/mswdraw.c @@ -29,13 +29,8 @@ #include <math.h> #include <winuser.h> -#ifdef WIN32 #define wFont_t tagLOGFONTA -#else -#define wFont_t tagLOGFONT -#endif -#include "misc.h" #include "mswint.h" #include <FreeImage.h> @@ -48,9 +43,9 @@ wBool_t wDrawDoTempDraw = TRUE; ***************************************************************************** */ -static wBool_t initted = FALSE; +#define M_PI 3.14159265358979323846 -long wDebugFont; +static wBool_t initted = FALSE; static FARPROC oldDrawProc; @@ -59,69 +54,53 @@ static long tmpOp = 0x990066; static long setOp = 0x8800c6; static long clrOp = 0xbb0226; -#define CENTERMARK_LENGTH 6 +#define CENTERMARK_LENGTH 4 -bool bDrawMainBM = 0; +static bool bDrawMainBM = 0; + +typedef struct { + double x, y; +} coOrd; #ifdef SLOW -static wPos_t XPIX2INCH( wDraw_p d, int ix ) +static wDrawPix_t XWINPIX2DRAWPIX( wDraw_p d, wWinPix_t ix ) { - return (wPos_t)ix; + return (wDrawPix_t)ix; } -static wPos_t YPIX2INCH( wDraw_p d, int iy ) +static wDrawPix_t YWINPIX2DRAWPIX( wDraw_p d, wWinPix_t iy ) { - wPos_t y; - y = (wPos_t)(d->h-2-iy); + wWinPix_t y; + y = (wDrawPix_t)(d->h-2-iy); return y; } -static int XINCH2PIX( wDraw_p d, wPos_t xx ) +static wWinPix_t XDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t xx ) { - int ix; - ix = (int)(xx); + wWinPix_t ix; + ix = (wWinPix_t)(xx); return ix; } -static int YINCH2PIX( wDraw_p d, wPos_t y ) +static wWinPix_t YDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t y ) { - int iy; - iy = d->h-2 - (int)(y); + wWinPix_t iy; + iy = (d->h)-2 - (wWinPix_t)(y); return iy; } - -static wPos_t XPIXELSTOINCH( wDraw_p d, int ix ) -{ - return (wPos_t)ix; -} - - -static wPos_t YPIXELSTOINCH( wDraw_p d, int iy ) -{ - return (wPos_t)iy; -} #else -#define XPIX2INCH( d, ix ) \ - ((wPos_t)ix) - -#define YPIX2INCH( d, iy ) \ - ((wPos_t)(d->h-2-iy)) - -#define XINCH2PIX( d, xx ) \ - ((int)(xx)) - -#define YINCH2PIX( d, y ) \ - (d->h-2 - (int)(y)) +#define XWINPIX2DRAWPIX( d, ix ) \ + ((wDrawPix_t)ix) +#define YWINPIX2DRAWPIX( d, iy ) \ + ((wDrawPix_t)(d->h-2-iy)) -#define XPIXELSTOINCH( d, ix ) \ - ((wPos_t)ix) - - -#define YPIXELSTOINCH( d, iy ) \ - ((wPos_t)iy) +#define XDRAWPIX2WINPIX( d, xx ) \ + ((wWinPix_t)(xx)) +#define YDRAWPIX2WINPIX( d, y ) \ + (d->h - 2 - (wWinPix_t)(y)) #endif /* @@ -134,7 +113,9 @@ static wPos_t YPIXELSTOINCH( wDraw_p d, int iy ) +/** @prefs [msw tweak] NoNegDrawArgs=1 Suppress drawing if x < 0 or y < 0 (-1 value causes preference read) */ static long noNegDrawArgs = -1; +/** @prefs [msw tweak] NoFlatEndCaps=1 Suppress EndCap Flat pen style */ static long noFlatEndCaps = 0; void wDrawDelayUpdate( @@ -323,10 +304,10 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d ) void wDrawLine( wDraw_p d, - wPos_t p0x, - wPos_t p0y, - wPos_t p1x, - wPos_t p1y, + wDrawPix_t p0x, + wDrawPix_t p0y, + wDrawPix_t p1x, + wDrawPix_t p1y, wDrawWidth dw, wDrawLineType_e lt, wDrawColor dc, @@ -335,10 +316,10 @@ void wDrawLine( POINT p0, p1; RECT rect; setDrawMode( d, dw, lt, dc, dopt ); - p0.x = XINCH2PIX(d,p0x); - p0.y = YINCH2PIX(d,p0y); - p1.x = XINCH2PIX(d,p1x); - p1.y = YINCH2PIX(d,p1y); + p0.x = XDRAWPIX2WINPIX(d,p0x); + p0.y = YDRAWPIX2WINPIX(d,p0y); + p1.x = XDRAWPIX2WINPIX(d,p1x); + p1.y = YDRAWPIX2WINPIX(d,p1y); if ( noNegDrawArgs>0 && !clip0( &p0, &p1, d ) ) return; MoveTo( d->hDc, p0.x, p0.y ); @@ -365,6 +346,12 @@ void wDrawLine( } } +static double d2r(double angle) +{ + angle *= (M_PI / 180.0); + return angle; +} + static double mswsin( double angle ) { while (angle < 0.0) angle += 360.0; @@ -406,12 +393,12 @@ static double mswasin( double x, double h ) void wDrawArc( wDraw_p d, - wPos_t px, - wPos_t py, - wPos_t r, + wDrawPix_t px, + wDrawPix_t py, + wDrawPix_t r, double a0, double a1, - int drawCenter, + int sizeCenter, wDrawWidth dw, wDrawLineType_e lt, wDrawColor dc, @@ -419,19 +406,16 @@ void wDrawArc( { int i, cnt; POINT p0, p1, ps, pe, pp0, pp1, pp2, pc; - double psx, psy, pex, pey, len, aa; + wDrawPix_t psx, psy, pex, pey; + double len, aa, ai; RECT rect; int needMoveTo; wBool_t fakeArc = FALSE; - len = a1/360.0 * (2 * M_PI) * r; - if (len < 3) - return; - - p0.x = XINCH2PIX(d,px-r); - p0.y = YINCH2PIX(d,py+r)+1; - p1.x = XINCH2PIX(d,px+r); - p1.y = YINCH2PIX(d,py-r)+1; + p0.x = XDRAWPIX2WINPIX(d,px-r); + p0.y = YDRAWPIX2WINPIX(d,py+r); + p1.x = XDRAWPIX2WINPIX(d,px+r); + p1.y = YDRAWPIX2WINPIX(d,py-r); pex = px + r * mswsin(a0); pey = py + r * mswcos(a0); @@ -440,17 +424,18 @@ void wDrawArc( /*pointOnCircle( &pe, p, r, a0 ); pointOnCircle( &ps, p, r, a0+a1 );*/ - ps.x = XINCH2PIX(d,(wPos_t)psx); - ps.y = YINCH2PIX(d,(wPos_t)psy); - pe.x = XINCH2PIX(d,(wPos_t)pex); - pe.y = YINCH2PIX(d,(wPos_t)pey); + ps.x = XDRAWPIX2WINPIX(d,psx); + ps.y = YDRAWPIX2WINPIX(d,psy); + pe.x = XDRAWPIX2WINPIX(d,pex); + pe.y = YDRAWPIX2WINPIX(d,pey); setDrawMode( d, dw, lt, dc, dopt ); if (dw == 0) dw = 1; - if (r>4096) { + /* Windows drawing will overshoot the end of the arc for large radius */ + if (r > 500) { /* The book says 32K but experience says otherwise */ fakeArc = TRUE; } @@ -459,21 +444,23 @@ void wDrawArc( fakeArc = TRUE; } if ( fakeArc ) { - cnt = (int)a1; + cnt = (int)(a1 / 2); if ( cnt <= 0 ) cnt = 1; - if ( cnt > 360 ) cnt = 360; - aa = a1 / cnt; - psx = px + r * mswsin(a0); - psy = py + r * mswcos(a0); - pp0.x = XINCH2PIX( d, (wPos_t)psx ); - pp0.y = YINCH2PIX( d, (wPos_t)psy ); + if ( cnt > 180 ) cnt = 180; + // Convert a0 and a1 to radians here + ai = d2r(a1) / cnt; + aa = d2r(a0); + psx = px + r * sin(aa); + psy = py + r * cos(aa); + pp0.x = XDRAWPIX2WINPIX( d, psx ); + pp0.y = YDRAWPIX2WINPIX( d, psy ); needMoveTo = TRUE; for ( i=0; i<cnt; i++ ) { - a0 += aa; - psx = px + r * mswsin(a0); - psy = py + r * mswcos(a0); - pp2.x = pp1.x = XINCH2PIX( d, (wPos_t)psx ); - pp2.y = pp1.y = YINCH2PIX( d, (wPos_t)psy ); + aa += ai; + psx = px + r * sin(aa); + psy = py + r * cos(aa); + pp2.x = pp1.x = XDRAWPIX2WINPIX( d, psx ); + pp2.y = pp1.y = YDRAWPIX2WINPIX( d, psy ); if ( clip0( &pp0, &pp1, d ) ) { if (needMoveTo) { MoveTo( d->hDc, pp0.x, pp0.y ); @@ -487,30 +474,30 @@ void wDrawArc( } } else { if ( a0 == 0.0 && a1 == 360.0 ) { - Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p0.y-1, pe.x, p1.y-1 ); - Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y-1, pe.x, p0.y-1 ); + Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p0.y, pe.x, p1.y ); + Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y, pe.x, p0.y ); } else { Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, ps.y, pe.x, pe.y ); } } // should the center of the arc be drawn? - if( drawCenter ) { + if( sizeCenter ) { // calculate the center coordinates - pc.x = XINCH2PIX( d, px ); - pc.y = YINCH2PIX( d, py ); + pc.x = XDRAWPIX2WINPIX( d, px ); + pc.y = YDRAWPIX2WINPIX( d, py ); // now draw the crosshair - MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH/2, pc.y ); - LineTo( d->hDc, pc.x + CENTERMARK_LENGTH/2, pc.y ); - MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH/2 ); - LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH/2 ); + MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH*sizeCenter, pc.y ); + LineTo( d->hDc, pc.x + CENTERMARK_LENGTH*sizeCenter, pc.y ); + MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH*sizeCenter ); + LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH*sizeCenter ); // invalidate the area of the crosshair - rect.top = pc.y - CENTERMARK_LENGTH / 2 - 1; - rect.bottom = pc.y + CENTERMARK_LENGTH / 2 + 1; - rect.left = pc.x - CENTERMARK_LENGTH / 2 - 1; - rect.right = pc.x + CENTERMARK_LENGTH / 2 + 1; + rect.top = pc.y - CENTERMARK_LENGTH*sizeCenter - 1; + rect.bottom = pc.y + CENTERMARK_LENGTH*sizeCenter + 1; + rect.left = pc.x - CENTERMARK_LENGTH*sizeCenter - 1; + rect.right = pc.x + CENTERMARK_LENGTH*sizeCenter + 1; myInvalidateRect( d, &rect ); } @@ -544,16 +531,16 @@ void wDrawArc( void wDrawPoint( wDraw_p d, - wPos_t px, - wPos_t py, + wDrawPix_t px, + wDrawPix_t py, wDrawColor dc, wDrawOpts dopt ) { POINT p0; RECT rect; - p0.x = XINCH2PIX(d,px); - p0.y = YINCH2PIX(d,py); + p0.x = XDRAWPIX2WINPIX(d,px); + p0.y = YDRAWPIX2WINPIX(d,py); if ( p0.x < 0 || p0.y < 0 ) return; @@ -707,7 +694,9 @@ void mswFontInit( void ) { const char * face; long size; + /** @prefs [msw window font] face=FontName */ face = wPrefGetString( "msw window font", "face" ); + /** @prefs [msw window font] size=-24 */ wPrefGetInteger( "msw window font", "size", &size, -24 ); if (face) { strncpy( logFont.lfFaceName, face, LF_FACESIZE ); @@ -750,16 +739,16 @@ static int computeFontSize( wDraw_p d, double siz ) } void wDrawGetTextSize( - wPos_t *w, - wPos_t *h, - wPos_t *d, - wPos_t *a, + wDrawPix_t *w, + wDrawPix_t *h, + wDrawPix_t *d, + wDrawPix_t *a, wDraw_p bd, const char * text, wFont_p fp, double siz ) { - int x, y; + wWinPix_t x, y; HFONT newFont, prevFont; DWORD extent; int oldLfHeight; @@ -773,16 +762,16 @@ void wDrawGetTextSize( fp->lfWidth = 0; newFont = CreateFontIndirect( fp ); prevFont = SelectObject( bd->hDc, newFont ); - extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, strlen(text) ); + extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, (int)(strlen(text)) ); GetTextMetrics(bd->hDc, &textMetric); x = LOWORD(extent); y = HIWORD(extent); - *w = XPIXELSTOINCH( bd, x ); - *h = YPIXELSTOINCH( bd, y ); - *d = YPIXELSTOINCH(bd, textMetric.tmDescent ); - *a = YPIXELSTOINCH(bd, textMetric.tmAscent ); + *w = (wDrawPix_t)x; + *h = (wDrawPix_t)y; + *d = (wDrawPix_t)textMetric.tmDescent; + *a = (wDrawPix_t)textMetric.tmAscent; SelectObject( bd->hDc, prevFont ); DeleteObject( newFont ); @@ -803,8 +792,8 @@ void wDrawGetTextSize( */ void wDrawString( wDraw_p d, - wPos_t px, - wPos_t py, + wDrawPix_t px, + wDrawPix_t py, double angle, const char * text, wFont_p fp, @@ -828,8 +817,8 @@ void wDrawString( fp->lfHeight = computeFontSize(d, siz); fp->lfWidth = 0; newFont = CreateFontIndirect(fp); - x = XINCH2PIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5); - y = YINCH2PIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5); + x = XDRAWPIX2WINPIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5); + y = YDRAWPIX2WINPIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5); if (noNegDrawArgs > 0 && (x < 0 || y < 0)) { DeleteObject(newFont); @@ -843,7 +832,7 @@ void wDrawString( if (dopts & wDrawOutlineFont) { HPEN oldPen; BeginPath(d->hDc); - TextOut(d->hDc, x, y, text, strlen(text)); + TextOut(d->hDc, x, y, text, (int)strlen(text)); EndPath(d->hDc); // Now draw outline text @@ -857,11 +846,11 @@ void wDrawString( old = SetTextColor(d->hDc, mswGetColor(d->hasPalette, dc)); - TextOut(d->hDc, x, y, text, strlen(text)); + TextOut(d->hDc, x, y, text, (int)(strlen(text))); SetTextColor(d->hDc, old); } - extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, strlen(text)); + extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text))); SelectObject(d->hDc, prevFont); w = LOWORD(extent); h = HIWORD(extent); @@ -925,10 +914,10 @@ void wSetSelectedFontSize(wFontSize_t size) void wDrawFilledRectangle( wDraw_p d, - wPos_t px, - wPos_t py, - wPos_t sx, - wPos_t sy, + wDrawPix_t px, + wDrawPix_t py, + wDrawPix_t sx, + wDrawPix_t sy, wDrawColor color, wDrawOpts opts ) { @@ -944,10 +933,10 @@ void wDrawFilledRectangle( mode = R2_COPYPEN; } SetROP2(d->hDc, mode); - rect.left = XINCH2PIX(d,px); - rect.right = XINCH2PIX(d,px+sx); - rect.top = YINCH2PIX(d,py+sy); - rect.bottom = YINCH2PIX(d,py); + rect.left = XDRAWPIX2WINPIX(d,px); + rect.right = XDRAWPIX2WINPIX(d,px+sx); + rect.top = YDRAWPIX2WINPIX(d,py+sy); + rect.bottom = YDRAWPIX2WINPIX(d,py); if ( rect.right < 0 || rect.bottom < 0 ) return; @@ -1000,8 +989,8 @@ static void addPoint( BYTE type, RECT * pr) { POINT p; - p.x = XINCH2PIX(d, pp->x); - p.y = YINCH2PIX(d, pp->y); + p.x = XDRAWPIX2WINPIX(d, pp->x); + p.y = YDRAWPIX2WINPIX(d, pp->y); #ifdef DRAWFILLPOLYLOG fprintf(logF, " q[%d] = {%d,%d}\n", pk, p.x, p.y); @@ -1042,7 +1031,7 @@ static void addPoint( void wDrawPolygon( wDraw_p d, - wPos_t node[][2], + wDrawPix_t node[][2], wPolyLine_e type[], wIndex_t cnt, wDrawColor color, @@ -1088,8 +1077,8 @@ void wDrawPolygon( setDrawMode(d, dw, lt, color, opts); } - rect.left = rect.right = XINCH2PIX(d,node[cnt-1][0]-1); - rect.top = rect.bottom = YINCH2PIX(d,node[cnt-1][1]+1); + rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1); + rect.top = rect.bottom = YDRAWPIX2WINPIX(d,node[cnt-1][1]+1); #ifdef DRAWFILLPOLYLOG logF = fopen("log.txt", "a"); @@ -1110,10 +1099,10 @@ void wDrawPolygon( nextNode = (i == cnt - 1) ? 0 : i + 1; // calculate distance to neighboring nodes - int prevXDistance = node[i][0] - node[prevNode][0]; - int prevYDistance = node[i][1] - node[prevNode][1]; - int nextXDistance = node[nextNode][0]-node[i][0]; - int nextYDistance = node[nextNode][1]-node[i][1]; + int prevXDistance = (wWinPix_t)(node[i][0] - node[prevNode][0]); + int prevYDistance = (wWinPix_t)(node[i][1] - node[prevNode][1]); + int nextXDistance = (wWinPix_t)(node[nextNode][0]-node[i][0]); + int nextYDistance = (wWinPix_t)(node[nextNode][1]-node[i][1]); // distance from node to endpoints of curve is half the line length endPoint0.x = (prevXDistance/2)+node[prevNode][0]; @@ -1202,29 +1191,29 @@ void wDrawPolygon( #define MAX_FILLCIRCLE_POINTS (30) void wDrawFilledCircle( wDraw_p d, - wPos_t x, - wPos_t y, - wPos_t r, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t r, wDrawColor color, wDrawOpts opts ) { POINT p0, p1; RECT rect; - static wPos_t circlePts[MAX_FILLCIRCLE_POINTS][2]; + static wDrawPix_t circlePts[MAX_FILLCIRCLE_POINTS][2]; int inx, cnt; double dang; - p0.x = XINCH2PIX(d,x-r); - p0.y = YINCH2PIX(d,y+r)+1; - p1.x = XINCH2PIX(d,x+r); - p1.y = YINCH2PIX(d,y-r)+1; + p0.x = XDRAWPIX2WINPIX(d,x-r); + p0.y = YDRAWPIX2WINPIX(d,y+r); + p1.x = XDRAWPIX2WINPIX(d,x+r); + p1.y = YDRAWPIX2WINPIX(d,y-r); setDrawBrush( d, color, opts ); if ( noNegDrawArgs > 0 && ( p0.x < 0 || p0.y < 0 ) ) { if ( r > MAX_FILLCIRCLE_POINTS ) cnt = MAX_FILLCIRCLE_POINTS; else if ( r > 8 ) - cnt = r; + cnt = XDRAWPIX2WINPIX(d,r); else cnt = 8; dang = 360.0/cnt; @@ -1308,8 +1297,8 @@ void wDrawClear( wDraw_p d ) void wDrawSetSize( wDraw_p d, - wPos_t width, - wPos_t height, void * redraw) + wWinPix_t width, + wWinPix_t height, void * redraw) { d->w = width; d->h = height; @@ -1323,8 +1312,8 @@ void wDrawSetSize( void wDrawGetSize( wDraw_p d, - wPos_t * width, - wPos_t * height ) + wWinPix_t * width, + wWinPix_t * height ) { *width = d->w-2; *height = d->h-2; @@ -1349,17 +1338,17 @@ double wDrawGetMaxRadius( wDraw_p d ) void wDrawClip( wDraw_p d, - wPos_t x, - wPos_t y, - wPos_t w, - wPos_t h ) + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h ) { - int ix0, iy0, ix1, iy1; + wWinPix_t ix0, iy0, ix1, iy1; HRGN hRgnClip; - ix0 = XINCH2PIX(d,x); - iy0 = YINCH2PIX(d,y); - ix1 = XINCH2PIX(d,x+w); - iy1 = YINCH2PIX(d,y+h); + ix0 = XDRAWPIX2WINPIX(d,x); + iy0 = YDRAWPIX2WINPIX(d,y); + ix1 = XDRAWPIX2WINPIX(d,x+w); + iy1 = YDRAWPIX2WINPIX(d,y+h); /* Note: Ydim is upside down so iy1<iy0 */ hRgnClip = CreateRectRgn( ix0, iy1, ix1, iy0 ); SelectClipRgn( d->hDc, hRgnClip ); @@ -1384,22 +1373,24 @@ void wRedraw( wDraw_p d ) struct wDrawBitMap_t { wDrawBitMap_p next; - wPos_t x; - wPos_t y; - wPos_t w; - wPos_t h; + wDrawPix_t x; + wDrawPix_t y; + wDrawPix_t w; + wDrawPix_t h; char * bmx; wDrawColor color; HBITMAP bm; }; -wDrawBitMap_p bmRoot = NULL; +static wDrawBitMap_p bmRoot = NULL; +extern wDrawColor drawColorWhite; +extern wDrawColor drawColorBlack; void wDrawBitMap( wDraw_p d, wDrawBitMap_p bm, - wPos_t px, - wPos_t py, + wDrawPix_t px, + wDrawPix_t py, wDrawColor dc, wDrawOpts dopt ) { @@ -1409,15 +1400,15 @@ void wDrawBitMap( int x0, y0; RECT rect; - x0 = XINCH2PIX(d,px-bm->x); - y0 = YINCH2PIX(d,py-bm->y+bm->h); + x0 = XDRAWPIX2WINPIX(d,px-bm->x); + y0 = YDRAWPIX2WINPIX(d,py-bm->y+bm->h); #ifdef LATER if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) ) return; #endif - if (dc == wDrawColorWhite) { + if (dc == drawColorWhite) { mode = clrOp; - dc = wDrawColorBlack; + dc = drawColorBlack; } else { mode = setOp; } @@ -1426,21 +1417,21 @@ void wDrawBitMap( if ( bm->bm ) DeleteObject( bm->bm ); bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ), - RGB( 255, 255, 255 ), bm->w, bm->h, bm->bmx ); + RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx ); bm->color = dc; } bmDc = CreateCompatibleDC( d->hDc ); setDrawMode( d, 0, wDrawLineSolid, dc, dopt ); oldBm = SelectObject( bmDc, bm->bm ); - BitBlt( d->hDc, x0, y0, bm->w, bm->h, bmDc, 0, 0, mode ); + BitBlt( d->hDc, x0, y0, (wWinPix_t)bm->w, (wWinPix_t)bm->h, bmDc, 0, 0, mode ); SelectObject( bmDc, oldBm ); DeleteDC( bmDc ); if (d->hWnd) { rect.top = y0-1; - rect.bottom = rect.top+bm->h+1; + rect.bottom = rect.top+ (wWinPix_t)bm->h+1; rect.left = x0-1; - rect.right = rect.left+bm->w+1; + rect.right = rect.left+ (wWinPix_t)bm->w+1; myInvalidateRect( d, &rect ); } } @@ -1484,22 +1475,18 @@ wDrawBitMap_p wDrawBitMapCreate( ***************************************************************************** */ -int doSetFocus = 1; +static int doSetFocus = 1; -long FAR PASCAL XEXPORT mswDrawPush( +LRESULT FAR PASCAL XEXPORT mswDrawPush( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wDraw_p b; - short int ix, iy; - wPos_t x, y; + wWinPix_t ix, iy; + wDrawPix_t x, y; HDC hDc; PAINTSTRUCT ps; wAction_t action; @@ -1529,7 +1516,10 @@ long FAR PASCAL XEXPORT mswDrawPush( } b->wFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSX ); b->hFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSY ); - b->DPI = 96.0; /*min( b->wFactor, b->hFactor );*/ + double dpi; + /** @prefs [Preference] ScreenDPI=96.0 Sets DPI of screen */ + wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); + b->DPI = dpi; b->hWnd = hWnd; SetROP2( b->hDc, R2_WHITE ); Rectangle( b->hDc, 0, 0, b->w, b->h ); @@ -1564,7 +1554,7 @@ long FAR PASCAL XEXPORT mswDrawPush( b->drawResize( b, b->size );*/ if (b->drawRepaint) b->drawRepaint( b, b->data, 0, 0 ); - return 0; + return (LRESULT)0; case WM_MOUSEMOVE: activeWnd = GetActiveWindow(); focusWnd = GetFocus(); @@ -1613,15 +1603,15 @@ long FAR PASCAL XEXPORT mswDrawPush( } ix = LOWORD( lParam ); iy = HIWORD( lParam ); - x = XPIX2INCH( b, ix ); - y = YPIX2INCH( b, iy ); + x = XWINPIX2DRAWPIX( b, ix ); + y = YWINPIX2DRAWPIX( b, iy ); b->lastX = x; b->lastY = y; if (b->action) b->action( b, b->data, action, x, y ); if (b->hWnd) UpdateWindow(b->hWnd); - return 0; + return (LRESULT)0; case WM_CHAR: b = (wDraw_p)mswMapIndex( inx ); extChar = wAccelKey_None; @@ -1655,9 +1645,9 @@ long FAR PASCAL XEXPORT mswDrawPush( if (extChar != wAccelKey_None) b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX, b->lastY ); else - b->action( b, b->data, wActionText + ( wParam << 8 ), b->lastX, b->lastY ); + b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX, b->lastY ); } - return 0; + return (LRESULT)0; case WM_PAINT: b = (wDraw_p)mswMapIndex( inx ); @@ -1740,7 +1730,7 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L } if (b->action) b->action( b, b->data, action, b->lastX, b->lastY ); - return 0; + return (LRESULT)0; case WM_MOUSEHWHEEL: if ( GET_KEYSTATE_WPARAM(wParam) & (MK_SHIFT|MK_MBUTTON)) { if ( GET_WHEEL_DELTA_WPARAM(wParam) > 0 ) { @@ -1751,7 +1741,7 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L } if (b->action) b->action( b, b->data, action, b->lastX, b->lastY ); - return 0; + return (LRESULT)0; } return DefWindowProc( hWnd, message, wParam, lParam ); @@ -1799,7 +1789,7 @@ static callBacks_t drawCallBacks = { drawDoneProc, (messageCallback_p)drawMsgProc }; -wDraw_p drawList = NULL; +static wDraw_p drawList = NULL; void mswRedrawAll( void ) @@ -1841,12 +1831,12 @@ void mswRepaintAll( void ) wDraw_p wDrawCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, long option, - wPos_t w, - wPos_t h, + wWinPix_t w, + wWinPix_t h, void * data, wDrawRedrawCallBack_p redrawProc, wDrawActionCallBack_p action ) @@ -1872,7 +1862,7 @@ wDraw_p wDrawCreate( d->hWnd = CreateWindow( mswDrawWindowClassName, NULL, WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER, d->x, d->y, w, h, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (d->hWnd == (HWND)0) { mswFail( "CreateWindow(DRAW)" ); @@ -1909,7 +1899,7 @@ wDraw_p wDrawCreate( ***************************************************************************** */ -wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes ) +wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int planes ) { wDraw_p d; HDC hDc; @@ -1934,11 +1924,13 @@ wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes ) d->hBmMain = CreateCompatibleBitmap( hDc, d->w, d->h ); if ( d->hBmMain == (HBITMAP)0 ) { wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Main fails", "Ok", NULL ); + ReleaseDC(mswHWnd, hDc); return FALSE; } d->hBmTemp = CreateCompatibleBitmap( hDc, d->w, d->h ); if ( d->hBmTemp == (HBITMAP)0 ) { wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Temp fails", "Ok", NULL ); + ReleaseDC(mswHWnd, hDc); return FALSE; } d->hasPalette = (GetDeviceCaps(hDc,RASTERCAPS ) & RC_PALETTE) != 0; @@ -2043,8 +2035,19 @@ wBitMapWriteFile(wDraw_p d, const char * fileName) } if (bCanSave) { - bSuccess = FreeImage_Save(fif, dib2, fileName, PNG_DEFAULT); - return bSuccess; + int flags; + + switch (fif) { + case FIF_JPEG: + flags = JPEG_QUALITYNORMAL; + break; + case FIF_PNG: + flags = PNG_DEFAULT; + break; + default: + flags = 0; // whatver the default is for the file format + } + bSuccess = FreeImage_Save(fif, dib2, fileName, flags); } } FreeImage_Unload(dib2); diff --git a/app/wlib/mswlib/mswedit.c b/app/wlib/mswlib/mswedit.c index dc70ac3..b6da004 100644 --- a/app/wlib/mswlib/mswedit.c +++ b/app/wlib/mswlib/mswedit.c @@ -35,6 +35,7 @@ struct wString_t { char * valueP; wIndex_t valueL; wStringCallBack_p action; + wBool_t enter_pressed; /**< flag if enter was pressed */ }; #ifdef LATER @@ -58,26 +59,22 @@ struct wFloat_t { static XWNDPROC oldEditProc = NULL; static XWNDPROC newEditProc; -static void triggerString( wControl_p b ); +static void triggerString( wString_p b ); #ifdef LATER static void triggerInteger( wControl_p b ); static void triggerFloat( wControl_p b ); #endif -long FAR PASCAL _export pushEdit( +LRESULT FAR PASCAL _export pushEdit( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif - wControl_p b = mswMapIndex(inx); + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); + wString_p b = (wString_p)mswMapIndex(inx); switch (message) { @@ -86,14 +83,14 @@ long FAR PASCAL _export pushEdit( switch (wParam) { case VK_RETURN: triggerString(b); - return (0L); + return (LRESULT)0; break; case 0x1B: case 0x09: SetFocus(((wControl_p)(b->parent))->hWnd); SendMessage(((wControl_p)(b->parent))->hWnd, WM_CHAR, wParam, lParam); - return 0L; + return (LRESULT)0; } } break; @@ -116,25 +113,21 @@ void wStringSetValue( const char * arg ) { WORD len = (WORD)strlen( arg ); - SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)arg ); -#ifdef WIN32 - SendMessage( b->hWnd, EM_SETSEL, 0, -1 ); - SendMessage( b->hWnd, EM_SCROLLCARET, 0, 0L ); -#else - SendMessage( b->hWnd, EM_SETSEL, 0, MAKELPARAM(len,len) ); -#endif - SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L ); + SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)arg ); + SendMessage( b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1 ); + SendMessage( b->hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0 ); + SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 ); } void wStringSetWidth( wString_p b, - wPos_t w ) + wWinPix_t w ) { int rc; b->w = w; rc = SetWindowPos( b->hWnd, HWND_TOP, 0, 0, - b->w, b->h, SWP_NOMOVE|SWP_NOZORDER ); + b->w, b->h, SWP_NOMOVE|SWP_NOZORDER ); } @@ -142,7 +135,7 @@ const char * wStringGetValue( wString_p b ) { static char buff[1024]; - SendMessage( b->hWnd, WM_GETTEXT, sizeof buff, (DWORD)buff ); + SendMessage( b->hWnd, WM_GETTEXT, (WPARAM)sizeof buff, (LPARAM)buff ); return buff; } @@ -157,13 +150,17 @@ const char * wStringGetValue( static char *getString(wString_p bs) { char *tmpBuffer = NULL; - UINT chars = SendMessage(bs->hWnd, EM_LINELENGTH, (WPARAM)0, 0L); + UINT chars = (UINT)SendMessage(bs->hWnd, EM_LINELENGTH, (WPARAM)0, (LPARAM)0); if (chars) { tmpBuffer = malloc(chars > sizeof(WORD)? chars + 1 : sizeof(WORD) + 1); *(WORD *)tmpBuffer = chars; - SendMessage(bs->hWnd, (UINT)EM_GETLINE, 0, (LPARAM)tmpBuffer); + SendMessage(bs->hWnd, (UINT)EM_GETLINE, (WPARAM)0, (LPARAM)tmpBuffer); tmpBuffer[chars] = '\0'; + } else { + tmpBuffer = malloc(2); + tmpBuffer[0] = '\n'; + tmpBuffer[1] = '\0'; } return (tmpBuffer); @@ -177,19 +174,21 @@ static char *getString(wString_p bs) */ static void triggerString( - wControl_p b) + wString_p b) { - wString_p bs = (wString_p)b; + const char *output = "\n"; - char *enteredString = getString(bs); + char *enteredString = getString(b); if (enteredString) { - if (bs->valueP) { - strcpy(bs->valueP, enteredString); + if (b->valueP) { + strcpy(b->valueP, enteredString); } - if (bs->action) { - bs->action(enteredString, bs->data); + if (b->action) { + b->enter_pressed = TRUE; + b->action(output, b->data); } + free(enteredString); } } @@ -210,7 +209,7 @@ LRESULT stringProc( case WM_COMMAND: switch (WCMD_PARAM_NOTF) { case EN_KILLFOCUS: - modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, 0, 0L); + modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, (WPARAM)0, (LPARAM)0); if (!modified) { break; } @@ -226,7 +225,7 @@ LRESULT stringProc( } free(enteredString); } - SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, FALSE, 0L); + SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0); } break; } @@ -243,12 +242,12 @@ static callBacks_t stringCallBacks = { wString_p wStringCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, + wWinPix_t width, char *valueP, wIndex_t valueL, wStringCallBack_p action, @@ -269,34 +268,30 @@ wString_p wStringCreate( if (option & BO_READONLY) style |= ES_READONLY; -#ifdef WIN32 b->hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style, b->x, b->y, width, mswEditHeight, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); -#else - b->hWnd = CreateWindow( "EDIT", NULL, - ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style, - b->x, b->y, - width, mswEditHeight, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); -#endif + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(STRING)"); return b; } newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); - oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); + oldEditProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); + SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newEditProc); +#ifdef _OLDCODE + oldEditProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWL_WNDPROC ); SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc ); +#endif // WIN64 if (b->valueP) { - SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)b->valueP ); + SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)b->valueP ); } - SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L ); + SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 ); if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); GetWindowRect( b->hWnd, &rect ); b->w = rect.right - rect.left; b->h = rect.bottom - rect.top; @@ -466,12 +461,12 @@ static callBacks_t integerCallBacks = { wInteger_p wIntegerCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, + wWinPix_t width, long low, long high, long *valueP, @@ -504,10 +499,7 @@ wInteger_p wIntegerCreate( return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl( b->hWnd); -#endif - + newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc ); @@ -690,12 +682,12 @@ static callBacks_t floatCallBacks = { wFloat_p wFloatCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, + wWinPix_t width, double low, double high, double *valueP, @@ -728,9 +720,6 @@ wFloat_p wFloatCreate( return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl( b->hWnd); -#endif newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); diff --git a/app/wlib/mswlib/mswint.h b/app/wlib/mswlib/mswint.h index e560053..5fd5da9 100644 --- a/app/wlib/mswlib/mswint.h +++ b/app/wlib/mswlib/mswint.h @@ -1,15 +1,31 @@ +/** \file mswint.h + * Windows specific definitions and prototypes for wlib + */ + +/* XTrackCAD - Model Railroad CAD + * Copyright (C) 2005 Dave Bullis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + #include "wlib.h" #include "mswlib.h" -//#include "dynarr.h" -#include "common.h" -#ifndef WIN32 -/*#define CONTROL3D*/ -#endif -#include "stdio.h" +#include "dynarr.h" -#ifdef CONTROL3D -#include "ctl3d.h" -#endif +#include <FreeImage.h> +#include <stdio.h> #ifdef WIN32 #ifdef FAR @@ -40,39 +56,39 @@ #endif #ifndef CAST_AWAY_CONST - #define CAST_AWAY_CONST (char *) +#define CAST_AWAY_CONST (char *) #endif #define BOOL_T wBool_t -#define POS_T wPos_t #define INDEX_T wIndex_t #define INTEGER_T wInteger_t typedef enum { - W_MAIN, W_POPUP, - B_BUTTON, B_STRING, B_INTEGER, B_FLOAT, - B_LIST, B_DROPLIST, B_COMBOLIST, - B_RADIO, B_TOGGLE, - B_DRAW, B_TEXT, B_MESSAGE, B_LINES, - B_MENUITEM, B_CHOICEITEM, B_BOX, - B_BITMAP } wType_e; - -typedef void (*repaintProcCallback_p)( HWND, wControl_p ); -typedef void (*doneProcCallback_p)( wControl_p b ); -typedef LRESULT (*messageCallback_p)( wControl_p, HWND, UINT, WPARAM, LPARAM ); -typedef void (*setTriggerCallback_p)( wControl_p b ); -typedef void (*setBusyCallback_p)( wControl_p, BOOL_T ); -typedef void (*showCallback_p)( wControl_p, BOOL_T ); -typedef void (*setPosCallback_p)( wControl_p, wPos_t, wPos_t ); + W_MAIN, W_POPUP, + B_BUTTON, B_STRING, B_INTEGER, B_FLOAT, + B_LIST, B_DROPLIST, B_COMBOLIST, + B_RADIO, B_TOGGLE, + B_DRAW, B_TEXT, B_MESSAGE, B_LINES, + B_MENUITEM, B_CHOICEITEM, B_BOX, + B_BITMAP +} wType_e; + +typedef void ( *repaintProcCallback_p )( HWND, wControl_p ); +typedef void ( *doneProcCallback_p )( wControl_p b ); +typedef LRESULT( *messageCallback_p )( wControl_p, HWND, UINT, WPARAM, LPARAM ); +typedef void ( *setTriggerCallback_p )( wControl_p b ); +typedef void ( *setBusyCallback_p )( wControl_p, BOOL_T ); +typedef void ( *showCallback_p )( wControl_p, BOOL_T ); +typedef void ( *setPosCallback_p )( wControl_p, wWinPix_t, wWinPix_t ); typedef struct { - repaintProcCallback_p repaintProc; - doneProcCallback_p doneProc; - messageCallback_p messageProc; - setBusyCallback_p setBusyProc; - showCallback_p showProc; - setPosCallback_p setPosProc; - } callBacks_t; + repaintProcCallback_p repaintProc; + doneProcCallback_p doneProc; + messageCallback_p messageProc; + setBusyCallback_p setBusyProc; + showCallback_p showProc; + setPosCallback_p setPosProc; +} callBacks_t; #define CALLBACK_CNT (B_BOX+1) extern callBacks_t *mswCallBacks[CALLBACK_CNT]; @@ -83,67 +99,68 @@ extern callBacks_t *mswCallBacks[CALLBACK_CNT]; wControl_p next; \ wControl_p synonym; \ wWin_p parent; \ - POS_T x, y; \ - POS_T w, h; \ + wWinPix_t x, y; \ + wWinPix_t w, h; \ long option; \ - POS_T labelX, labelY; \ + wWinPix_t labelX, labelY; \ const char * labelStr; \ const char * helpStr; \ const char * tipStr; \ + char * errStr; \ HWND hWnd; \ void * data;\ wControl_p focusChainNext; \ - wBool_t shown; + wBool_t shown; \ + wBool_t hilite; struct wControl_t { - WOBJ_COMMON - }; + WOBJ_COMMON +}; typedef struct { - unsigned key; - wDrawColor color; - } wIconColorMap_t; + unsigned key; + wDrawColor color; +} wIconColorMap_t; #define mswIcon_bitmap (1) #define mswIcon_pixmap (2) struct wIcon_t { - int type; - wPos_t w; /**< width */ - wPos_t h; /**< height */ - wDrawColor color; - int colorcnt; /**< number of colors */ - RGBQUAD *colormap; - char *pixels; /**< pointer to pixel information */ - int transparent; /**< index of transparent color */ - }; + int type; + wWinPix_t w; /**< width */ + wWinPix_t h; /**< height */ + wDrawColor color; + int colorcnt; /**< number of colors */ + RGBQUAD *colormap; + char *pixels; /**< pointer to pixel information */ + int transparent; /**< index of transparent color */ +}; struct wDraw_t { - WOBJ_COMMON - HDC hDc; - double wFactor; - double hFactor; - double DPI; - wDrawRedrawCallBack_p drawRepaint; - wDrawActionCallBack_p action; - HBITMAP hBmMain; - HBITMAP hBmTemp; - HBITMAP hBmOld; - HPEN hPen; - HBRUSH hBrush; - wDraw_p drawNext; - wBool_t hasPalette; - int paletteClock; - HBITMAP hBmBackup; - HDC hDcBackup; - HBITMAP hBmBackupOld; - void *background; - wBool_t bTempMode; - wBool_t bCopiedMain; - - wPos_t lastX; - wPos_t lastY; - - }; + WOBJ_COMMON + HDC hDc; + double wFactor; + double hFactor; + double DPI; + wDrawRedrawCallBack_p drawRepaint; + wDrawActionCallBack_p action; + HBITMAP hBmMain; + HBITMAP hBmTemp; + HBITMAP hBmOld; + HPEN hPen; + HBRUSH hBrush; + wDraw_p drawNext; + wBool_t hasPalette; + int paletteClock; + HBITMAP hBmBackup; + HDC hDcBackup; + HBITMAP hBmBackupOld; + FIBITMAP *background; + wBool_t bTempMode; + wBool_t bCopiedMain; + wDrawPix_t lastX; + wDrawPix_t lastY; + +}; extern HINSTANCE mswHInst; extern char mswTmpBuff[1024]; @@ -168,7 +185,7 @@ void mswResize( wWin_p ); wControl_p mswMapIndex( INDEX_T ); void mswButtPush( wControl_p ); void * mswAlloc( wWin_p, wType_e, const char *, int, void *, int * ); -void mswComputePos( wControl_p, wPos_t, wPos_t ); +void mswComputePos( wControl_p, wWinPix_t, wWinPix_t ); void mswAddButton( wControl_p, BOOL_T, const char * ); void mswRepaintLabel( HWND, wControl_p ); int mswRegister( wControl_p ); @@ -178,7 +195,7 @@ void mswSetFocus( wControl_p ); void mswSetTrigger( wControl_p, setTriggerCallback_p ); void mswMenuPush( wControl_p ); void mswCreateCheckBitmaps( void ); -long FAR PASCAL XEXPORT mswDrawPush( HWND, UINT, UINT, LONG ); +LRESULT FAR PASCAL XEXPORT mswDrawPush( HWND, UINT, WPARAM, LPARAM ); #ifdef WIN32 DWORD GetTextExtent( HDC, CHAR *, UINT ); #endif @@ -186,7 +203,7 @@ void mswRedrawAll( void ); void mswRepaintAll( void ); HDC mswGetPrinterDC( void ); int mswMenuAccelerator( wWin_p, long ); -void mswMenuMove( wMenu_p, wPos_t, wPos_t ); +void mswMenuMove( wMenu_p, wWinPix_t, wWinPix_t ); void mswRegisterBitMap( HBITMAP ); void mswFontInit( void ); void mswInitColorPalette( void ); @@ -202,5 +219,5 @@ void deleteBitmaps( void ); void mswDrawIcon( HDC, int, int, wIcon_p, int, COLORREF, COLORREF ); /* gwin32.c*/ -char *g_win32_getlocale (void); +char *g_win32_getlocale( void ); diff --git a/app/wlib/mswlib/mswlines.c b/app/wlib/mswlib/mswlines.c index be1330d..f6bb574 100644 --- a/app/wlib/mswlib/mswlines.c +++ b/app/wlib/mswlib/mswlines.c @@ -58,7 +58,7 @@ wLine_p wLineCreate( { wLine_p b; wLines_p lp; - POS_T minX, maxX, minY, maxY; + wWinPix_t minX, maxX, minY, maxY; int index; if (count <= 0) diff --git a/app/wlib/mswlib/mswlist.c b/app/wlib/mswlib/mswlist.c index 95ecec3..836f4f0 100644 --- a/app/wlib/mswlib/mswlist.c +++ b/app/wlib/mswlib/mswlist.c @@ -27,16 +27,16 @@ struct wList_t { wListCallBack_p action; wBool_t editable; int colCnt; - wPos_t * colWidths; + wWinPix_t * colWidths; wBool_t * colRightJust; const char * * colTitles; - wPos_t maxWidth; - wPos_t scrollPos; + wWinPix_t maxWidth; + wWinPix_t scrollPos; HWND hScrollWnd; - wPos_t scrollH; - wPos_t dragPos; + wWinPix_t scrollH; + wWinPix_t dragPos; int dragCol; - wPos_t dragColWidth; + wWinPix_t dragColWidth; }; @@ -58,18 +58,18 @@ void wListClear( msg = LB_RESETCONTENT; else msg = CB_RESETCONTENT; - SendMessage( b->hWnd, msg, 0, 0 ); + SendMessage( b->hWnd, msg, (WPARAM)0, (LPARAM)0 ); b->last = -1; b->count = 0; } -void wListSetSize( wList_p bl, wPos_t w, wPos_t h ) +void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h ) { int rc; RECT rect; - wPos_t y; + wWinPix_t y; bl->w = w; bl->h = h; @@ -109,24 +109,24 @@ void wListSetIndex( return; if ( bl->type==B_LIST && (bl->option&BL_MANY) != 0 ) { if ( bl->last != -1 ) - SendMessage( bl->hWnd, LB_SETSEL, 0, MAKELPARAM(bl->last,0) ); + SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)0, (LPARAM)bl->last ); if ( index >= 0 ) - SendMessage( bl->hWnd, LB_SETSEL, 1, MAKELPARAM(index, 0) ); + SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)1, (LPARAM)index ); } else { SendMessage( bl->hWnd, - bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, index, 0 ); + bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)index, (LPARAM)0 ); } if ( bl->last >= 0 ) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); if ( ldp && ldp!=(void*)LB_ERR ) ldp->selected = FALSE; } if ( index >= 0 ) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - index, 0L ); + (WPARAM)index, (LPARAM)0 ); if ( ldp && ldp!=(void*)LB_ERR ) ldp->selected = TRUE; } @@ -164,7 +164,7 @@ void wListSetValue( const char * val ) { if ( bl->type == B_DROPLIST ) { - SendMessage( bl->hWnd, WM_SETTEXT, 0, (DWORD)(LPSTR)val ); + SendMessage( bl->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)val ); bl->last = -1; } } @@ -179,8 +179,8 @@ wIndex_t wListFindValue( wListGetCount(bl); for ( inx = 0; inx < bl->count ; inx++ ) { cnt = (int)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), inx, - (DWORD)(LPSTR)mswTmpBuff ); + (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), (WPARAM)inx, + (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if ( strcmp( val, mswTmpBuff ) == 0 ) return inx; @@ -212,7 +212,7 @@ wIndex_t wListGetValues( msg = CB_GETLBTEXT; } } - cnt = (int)SendMessage( bl->hWnd, msg, inx, (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, msg, (WPARAM)inx, (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if (s) { strncpy(s, mswTmpBuff, siz); @@ -221,7 +221,7 @@ wIndex_t wListGetValues( if (bl->last >= 0) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); if ( ldp==(listData*)LB_ERR ) ldp = NULL; } else { @@ -252,24 +252,24 @@ wBool_t wListSetValues( curSel = (WORD)SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_GETCURSEL:CB_GETCURSEL, (WPARAM)0, - (DWORD)0L ); + (LPARAM)0 ); SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, (WPARAM)inx, - (DWORD)0L ); + (LPARAM)0 ); inx = (wIndex_t)SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_INSERTSTRING:CB_INSERTSTRING, (WPARAM)inx, - (DWORD)(LPSTR)labelStr ); + (LPARAM)labelStr ); SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, (WPARAM)inx, - (DWORD)ldp ); + (LPARAM)ldp ); if ( (b->option&BL_MANY) == 0 && curSel == (WORD)inx) SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)inx, - (DWORD)0L ); + (LPARAM)0 ); /*if (b->option&BL_ICON)*/ InvalidateRect( b->hWnd, NULL, FALSE ); return TRUE; @@ -283,7 +283,7 @@ void wListDelete( SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, (WPARAM)inx, - (DWORD)0L ); + (LPARAM)0 ); } @@ -303,19 +303,19 @@ void wListSelectAll( wList_p bl ) SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)TRUE, - (DWORD)-1L ); + (LPARAM)-1 ); // and synchronize the internal data structures wListGetCount(bl); for ( inx=0; inx<bl->count; inx++ ) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - inx, 0L ); + (WPARAM)inx, (LPARAM)0 ); ldp->selected = TRUE; SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, (WPARAM)inx, - (DWORD)ldp ); + (LPARAM)ldp ); } } @@ -323,7 +323,7 @@ void wListSelectAll( wList_p bl ) wIndex_t wListGetCount( wList_p bl ) { - bl->count = (int)SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, 0, 0L ); + bl->count = (int)SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, (WPARAM)0, (LPARAM)0 ); return bl->count; } @@ -337,7 +337,7 @@ void * wListGetItemContext( if ( inx < 0 || inx >= bl->count ) return NULL; ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - inx, 0L ); + (WPARAM)inx, (LPARAM)0 ); return ((ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL); } @@ -351,7 +351,7 @@ wBool_t wListGetItemSelected( if ( inx < 0 || inx >= bl->count ) return FALSE; ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - inx, 0L ); + (WPARAM)inx, (LPARAM)0 ); return ((ldp&&ldp!=(void*)LB_ERR)?ldp->selected:FALSE); } @@ -389,18 +389,18 @@ wIndex_t wListAddValue( b->hWnd, (UINT)b->type==B_LIST?LB_ADDSTRING:CB_ADDSTRING, (WPARAM)0, - (DWORD)value ); + (LPARAM)value ); if (nindex == 0) { SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)nindex, - (DWORD)0 ); + (LPARAM)0 ); b->last = 0; } SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, (WPARAM)nindex, - (DWORD)ldp ); + (LPARAM)ldp ); return nindex; } @@ -408,7 +408,7 @@ wIndex_t wListAddValue( int wListGetColumnWidths( wList_p bl, int colCnt, - wPos_t * colWidths ) + wWinPix_t * colWidths ) { wIndex_t inx; @@ -454,11 +454,11 @@ static void listShow( static void listSetPos( wControl_p b, - wPos_t x, - wPos_t y ) + wWinPix_t x, + wWinPix_t y ) { wList_p bl = (wList_p)b; - wPos_t x1, y1; + wWinPix_t x1, y1; RECT rect; bl->x = x1 = x; @@ -492,7 +492,7 @@ static void listRepaintLabel( const char * * title; int inx; int start; - wPos_t colWidth; + wWinPix_t colWidth; mswRepaintLabel( hWnd, b ); if ( bl->colTitles == NULL ) @@ -538,7 +538,7 @@ static void listRepaintLabel( rc.right = bl->x+bl->w-1; ExtTextOut( hDc, start+1, rc.top+0, ETO_CLIPPED|ETO_OPAQUE, &rc, - *title, strlen(*title), NULL ); + *title, (int)(strlen(*title)), NULL ); if ( start-bl->x >= 3 ) { SelectObject( hDc, hPen1 ); MoveTo( hDc, start-1, rc.top-1 ); @@ -589,7 +589,7 @@ LRESULT listProc( { wList_p bl = (wList_p)b; int cnt, inx, selected; - long len; + size_t len; listData * ldp; HDC hDc; LPMEASUREITEMSTRUCT lpmis; @@ -597,7 +597,8 @@ LRESULT listProc( LPDRAWITEMSTRUCT lpdis; RECT rc, rc1; char * cp0, * cp1; - wPos_t colWidth, x; + wWinPix_t x; + int colWidth; int nPos; HFONT hFont; HPEN hPen; @@ -621,14 +622,14 @@ LRESULT listProc( if ( (bl->option&BL_MANY) ) { wListGetCount(bl); for ( inx=0; inx<bl->count; inx++ ) { - ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA, inx, 0L ); + ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA, (WPARAM)inx, (LPARAM)0 ); if ( ldp != NULL && ldp != (void*)LB_ERR ) { - selected = ((long)SendMessage( bl->hWnd, LB_GETSEL, inx, 0L ) != 0L ); + selected = ((long)SendMessage( bl->hWnd, LB_GETSEL, (WPARAM)inx, (LPARAM)0 ) != 0L ); if ( selected != ldp->selected ) { ldp->selected = selected; if ( selected ) { bl->last = inx; - cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, bl->last, (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last, (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; } else { mswTmpBuff[0] = '\0'; @@ -641,13 +642,13 @@ LRESULT listProc( } } } else { - bl->last = (int)SendMessage( bl->hWnd, LB_GETCURSEL, 0, 0L ); - cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, bl->last, - (DWORD)(LPSTR)mswTmpBuff ); + bl->last = (int)SendMessage( bl->hWnd, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); + cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last, + (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if (bl->action) { ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA, - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); bl->action( bl->last, mswTmpBuff, 1, bl->data, ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) ); } @@ -659,8 +660,8 @@ LRESULT listProc( case LBN_KILLFOCUS: if ( ( bl->option&BL_MANY ) == 0 && - bl->last != (int)SendMessage( bl->hWnd, LB_GETCURSEL, 0, 0L ) ) - (void)SendMessage( bl->hWnd, LB_SETCURSEL, bl->last, 0L ); + bl->last != (int)SendMessage( bl->hWnd, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 ) ) + (void)SendMessage( bl->hWnd, LB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 ); break; } break; @@ -677,14 +678,14 @@ LRESULT listProc( break; case CBN_CLOSEUP: - bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, 0, 0L ); + bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); if (bl->last < 0) break; if (bl->action) { - cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT, bl->last, - (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT, + (WPARAM)bl->last, (LPARAM)mswTmpBuff ); ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA, - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); mswTmpBuff[cnt] = '\0'; bl->action( bl->last, mswTmpBuff, 1, bl->data, ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) ); @@ -697,9 +698,9 @@ LRESULT listProc( break; case CBN_KILLFOCUS: - inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, 0, 0L ); + inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); if ( bl->last != inx ) - (void)SendMessage( bl->hWnd, CB_SETCURSEL, bl->last, 0L ); + (void)SendMessage( bl->hWnd, CB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 ); break; case CBN_DROPDOWN: @@ -709,8 +710,8 @@ LRESULT listProc( case CBN_EDITCHANGE: bl->last = -1; if (bl->action) { - cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, sizeof mswTmpBuff, - (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, (WPARAM)sizeof mswTmpBuff, + (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; bl->action( -1, mswTmpBuff, 1, bl->data, NULL ); } @@ -740,14 +741,14 @@ LRESULT listProc( } ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - lpdis->itemID, 0L ); + (WPARAM)lpdis->itemID, (LPARAM)0); rc = lpdis->rcItem; if (lpdis->itemAction & (ODA_DRAWENTIRE|ODA_SELECT|ODA_FOCUS)) { if( bl->type == B_LIST ) hFont = SelectObject( lpdis->hDC, mswLabelFont ); cnt = (int)SendMessage( lpdis->hwndItem, (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), - lpdis->itemID, (LONG)(LPSTR)mswTmpBuff ); + (WPARAM)lpdis->itemID, (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if ( lpdis->itemState & ODS_SELECTED ) { SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); @@ -809,7 +810,7 @@ LRESULT listProc( } if ( bl->type == B_LIST) SelectObject( lpdis->hDC, hFont ); - return TRUE; + return (LRESULT)TRUE; } break; @@ -817,17 +818,17 @@ LRESULT listProc( case WM_HSCROLL: len = ((long)bl->maxWidth)-((long)bl->w); if ( len <= 0 ) - return 0; + return (LRESULT)0; switch ( WSCROLL_PARAM_CODE ) { case SB_LEFT: if ( bl->scrollPos == 0 ) - return 0; + return (LRESULT)0; bl->scrollPos = 0; break; case SB_LINELEFT: case SB_PAGELEFT: if ( bl->scrollPos == 0 ) - return 0; + return (LRESULT)0; for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) { bl->scrollPos = colWidth; @@ -839,7 +840,7 @@ LRESULT listProc( case SB_LINERIGHT: case SB_PAGERIGHT: if ( bl->scrollPos >= len ) - return 0; + return (LRESULT)0; for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { if ( colWidth >= bl->scrollPos ) { bl->scrollPos = colWidth+bl->colWidths[inx]; @@ -850,17 +851,17 @@ LRESULT listProc( break; case SB_RIGHT: if ( bl->scrollPos >= len ) - return 0; + return (LRESULT)0; bl->scrollPos = (int)len; break; case SB_THUMBTRACK: - return 0; + return (LRESULT)0; case SB_THUMBPOSITION: nPos = (int)WSCROLL_PARAM_NPOS; bl->scrollPos = (int)(len*nPos/100); break; case SB_ENDSCROLL: - return 0; + return (LRESULT)0; } if ( bl->scrollPos > len ) bl->scrollPos = (int)len; if ( bl->scrollPos < 0 ) bl->scrollPos = 0; @@ -868,7 +869,7 @@ LRESULT listProc( SetScrollPos( bl->hScrollWnd, SB_CTL, nPos, TRUE ); InvalidateRect( bl->hWnd, NULL, FALSE ); listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); - return 0; + return (LRESULT)0; case WM_LBUTTONDOWN: if ( bl->type != B_LIST ) @@ -886,7 +887,7 @@ LRESULT listProc( } if ( bl->dragCol >= 0 ) bl->dragColWidth = bl->colWidths[inx]; - return 0L; + return (LRESULT)0; #ifdef LATER case WM_MOUSEMOVE: @@ -902,7 +903,7 @@ LRESULT listProc( if ( x <= 0 ) break; } - return 0L; + return (LRESULT)0; #endif case WM_MOUSEMOVE: @@ -933,26 +934,26 @@ LRESULT listProc( } InvalidateRect( bl->hWnd, NULL, FALSE ); listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); - return 0L; + return (LRESULT)0; } return DefWindowProc( hWnd, message, wParam, lParam ); } -long FAR PASCAL _export pushList( +LRESULT FAR PASCAL _export pushList( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 + wIndex_t inx = (wIndex_t)GetWindowLongPtr(hWnd, GWL_ID); + wControl_p b = mswMapIndex(inx); +#ifdef OLDCODE long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif wControl_p b = mswMapIndex( inx ); +#endif switch (message) { case WM_CHAR: @@ -966,7 +967,7 @@ long FAR PASCAL _export pushList( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LRESULT)0; } } break; @@ -974,18 +975,14 @@ long FAR PASCAL _export pushList( return CallWindowProc( oldListProc, hWnd, message, wParam, lParam ); } -long FAR PASCAL _export pushCombo( +LRESULT FAR PASCAL _export pushCombo( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wControl_p b = mswMapIndex( inx ); switch (message) { @@ -1000,7 +997,7 @@ long FAR PASCAL _export pushCombo( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LRESULT)0; } } break; @@ -1022,13 +1019,13 @@ static wList_p listCreate( const char *className, long style, wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data, @@ -1056,16 +1053,12 @@ static wList_p listCreate( b->hWnd = CreateWindow( className, NULL, style | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x, b->y, width, LIST_HEIGHT*(int)number, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(LIST)"); return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl( b->hWnd ); -#endif - GetWindowRect( b->hWnd, &rect ); b->w = rect.right - rect.left; b->h = rect.bottom - rect.top; @@ -1078,34 +1071,43 @@ static wList_p listCreate( if (addFocus) { mswChainFocus( (wControl_p)b ); if (b->type == B_LIST) { - newListProc = MakeProcInstance( (XWNDPROC)pushList, mswHInst ); - oldListProc = (XWNDPROC)GetWindowLong( b->hWnd, GWL_WNDPROC ); - SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newListProc ); - } else { - newComboProc = MakeProcInstance( (XWNDPROC)pushCombo, mswHInst ); - oldComboProc = (XWNDPROC)GetWindowLong( b->hWnd, GWL_WNDPROC ); - SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newComboProc ); + newListProc = MakeProcInstance((XWNDPROC)pushList, mswHInst); + oldListProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); + SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newListProc); +#ifdef _OLDCODE + oldListProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC); + SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newListProc); +#endif + } + else { + newComboProc = MakeProcInstance((XWNDPROC)pushCombo, mswHInst); + oldComboProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); + SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newComboProc); +#ifdef _OLDCODE + oldComboProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC); + SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newComboProc); +#endif } } if ( indexR ) *indexR = index; if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); return b; } wList_p wListCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, int colCnt, - wPos_t * colWidths, + wWinPix_t * colWidths, wBool_t * colRightJust, const char * * colTitles, long *valueP, @@ -1138,7 +1140,7 @@ wList_p wListCreate( } if ( colCnt > 1 ) { bl->colCnt = colCnt; - bl->colWidths = (int*)malloc( colCnt * sizeof *bl->colWidths ); + bl->colWidths = (wWinPix_t*)malloc( colCnt * sizeof *bl->colWidths ); bl->colRightJust = (wBool_t*)malloc( colCnt * sizeof *bl->colRightJust ); bl->colTitles = colTitles; bl->maxWidth = 0; @@ -1150,7 +1152,7 @@ wList_p wListCreate( bl->hScrollWnd = CreateWindow( "ScrollBar", NULL, SBS_HORZ | SBS_BOTTOMALIGN | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), bl->x, bl->y, width, CW_USEDEFAULT, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (bl->hScrollWnd == NULL) mswFail("CreateWindow(LISTSCROLL)"); SetScrollRange( bl->hScrollWnd, SB_CTL, 0, 100, TRUE ); @@ -1163,13 +1165,13 @@ wList_p wListCreate( wList_p wDropListCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data ) @@ -1189,13 +1191,13 @@ wList_p wDropListCreate( wList_p wComboListCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data ) diff --git a/app/wlib/mswlib/mswmenu.c b/app/wlib/mswlib/mswmenu.c index d56e24d..9e36c8b 100644 --- a/app/wlib/mswlib/mswmenu.c +++ b/app/wlib/mswlib/mswmenu.c @@ -31,7 +31,6 @@ #include <math.h> #include <ctype.h> #include <assert.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" @@ -94,7 +93,7 @@ struct wMenuRadio_t { struct wMenuToggle_t { MOBJ_COMMON wMenu_p mparent; - wMenuToggleCallBack_p action; + wMenuCallBack_p action; long acclKey; wBool_t enabled; }; @@ -174,7 +173,7 @@ static LRESULT menuPush( set = !set; wMenuToggleSet((wMenuToggle_p)m,set); if (((wMenuToggle_p)m)->action) - ((wMenuToggle_p)m)->action(set, ((wMenuPush_p)m)->data); + ((wMenuToggle_p)m)->action(((wMenuPush_p)m)->data); break; case M_LISTITEM: if (((wMenuListItem_p)m)->action) @@ -185,7 +184,7 @@ static LRESULT menuPush( ((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 ); @@ -261,7 +260,7 @@ typedef struct { wAccelKey_e key; void * data; } acclTable_t, *acclTable_p; -dynArr_t acclTable_da; +static dynArr_t acclTable_da; #define acclTable(N) DYNARR_N( acclTable_t, acclTable_da, N ) @@ -364,7 +363,8 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) 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 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. */ @@ -383,6 +383,7 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); + wMenuH = GetSystemMetrics(SM_CYMENU); hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, wBitmapY); @@ -428,11 +429,11 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) case RADIOCHECK: rc.left = (bmCheckbox.bmWidth / 4); rc.right = (bmCheckbox.bmWidth / 4) * 2; - rc.top = (bmCheckbox.bmHeight / 3) + 1; + rc.top = (bmCheckbox.bmHeight / 3); rc.bottom = (bmCheckbox.bmHeight / 3) * 2; break; case RADIOUNCHECK: - rc.top = (bmCheckbox.bmHeight / 3) + 1; + rc.top = (bmCheckbox.bmHeight / 3); rc.bottom = (bmCheckbox.bmHeight / 3) * 2; rc.left = 0; rc.right = (bmCheckbox.bmWidth / 4); @@ -444,7 +445,6 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) 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)) { @@ -455,7 +455,9 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) else { - BitBlt(hdcTarget, 0, 0, rc.right - rc.left, + // 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); } @@ -655,7 +657,7 @@ 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; } @@ -857,7 +859,7 @@ wMenuToggle_p wMenuToggleCreate( const char * labelStr, long acclKey, wBool_t set, - wMenuToggleCallBack_p action, + wMenuCallBack_p action, void * data ) { wMenuToggle_p mt; @@ -958,8 +960,8 @@ void wMenuToggleEnable( void mswMenuMove( wMenu_p m, - wPos_t x, - wPos_t y ) + wWinPix_t x, + wWinPix_t y ) { wControl_p b; b = (wControl_p)m->parent; @@ -985,8 +987,8 @@ static void pushMenuButt( wMenu_p wMenuCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option ) @@ -1041,7 +1043,7 @@ 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; @@ -1118,7 +1120,7 @@ wBool_t wMenuAction( } else { set = wMenuToggleGet( mt ); wMenuToggleSet( mt, !set ); - mt->action( set, mt->data ); + mt->action( mt->data ); } break; case M_MENU: 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; } diff --git a/app/wlib/mswlib/mswmsg.c b/app/wlib/mswlib/mswmsg.c index 6445299..8487e31 100644 --- a/app/wlib/mswlib/mswmsg.c +++ b/app/wlib/mswlib/mswmsg.c @@ -21,17 +21,12 @@ #define SCALE_LARGE 1.6 #define SCALE_SMALL 0.8 -#ifdef CONTROL3D -static int messageHeight = 18; -#endif - struct wMessage_t { WOBJ_COMMON long flags; const char * message; }; -#ifndef CONTROL3D static void repaintMessage( HWND hWnd, wControl_p b ) @@ -83,7 +78,7 @@ static void repaintMessage( rect.left = bm->x; SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) ); - ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2), ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, strlen( bm->message ), NULL ); + ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2), ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, (int)(strlen( bm->message )), NULL ); if( scale != 1.0 ) /* in case we did create a new font earlier, delete it now */ @@ -94,7 +89,6 @@ static void repaintMessage( ReleaseDC( hWnd, hDc ); } -#endif void wMessageSetValue( wMessage_p b, @@ -106,34 +100,26 @@ void wMessageSetValue( b->message = mswStrdup( arg ); else b->message = NULL; -#ifdef CONTROL3D - SetWindowText( b->hWnd, arg ); -#else + repaintMessage( ((wControl_p)(b->parent))->hWnd, (wControl_p)b ); -#endif + } void wMessageSetWidth( wMessage_p b, - wPos_t width ) + wWinPix_t width ) { b->w = width; -#ifdef CONTROL3D - SetWindowPos( b->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT, - width, messageHeight, SWP_NOMOVE ); -#endif + } -wPos_t wMessageGetWidth(const char *string) +wWinPix_t wMessageGetWidth(const char *string) { return(wLabelWidth(string)); } -wPos_t wMessageGetHeight( long flags ) +wWinPix_t wMessageGetHeight( long flags ) { -#ifdef CONTROL3D - return messageHeight; -#else double scale = 1.0; if( flags & BM_LARGE ) @@ -141,8 +127,8 @@ wPos_t wMessageGetHeight( long flags ) if( flags & BM_SMALL ) scale = SCALE_SMALL; - return((wPos_t)((mswEditHeight) * scale )); -#endif + return((wWinPix_t)((mswEditHeight) * scale )); + } static void mswMessageSetBusy( @@ -152,68 +138,39 @@ static void mswMessageSetBusy( } -#ifndef CONTROL3D + static callBacks_t messageCallBacks = { repaintMessage, NULL, NULL, mswMessageSetBusy }; -#endif - wMessage_p wMessageCreateEx( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, - POS_T width, + wWinPix_t width, const char *message, long flags ) { wMessage_p b; int index; -#ifdef CONTROL3D - RECT rect; -#endif - + b = (wMessage_p)mswAlloc( parent, B_MESSAGE, NULL, sizeof *b, NULL, &index ); mswComputePos( (wControl_p)b, x, y ); b->option |= BO_READONLY; b->message = mswStrdup( message ); b->flags = flags; -#ifdef CONTROL3D - if ( width <= 0 && strlen(b->message) > 0 ) { - width = wLabelWidth( b->message ); - } - - b->hWnd = CreateWindow( "STATIC", NULL, - SS_LEFTNOWORDWRAP | WS_CHILD | WS_VISIBLE, - b->x, b->y, - width, messageHeight, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); - if (b->hWnd == NULL) { - mswFail("CreateWindow(MESSAGE)"); - return b; - } - - if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); - SetWindowText( b->hWnd, message ); - - GetWindowRect( b->hWnd, &rect ); - b->w = rect.right - rect.left; - b->h = rect.bottom - rect.top; -#else b->w = width; b->h = wMessageGetHeight( flags ) + 1; repaintMessage( ((wControl_p)parent)->hWnd, (wControl_p)b ); -#endif + mswAddButton( (wControl_p)b, FALSE, helpStr ); -#ifndef CONTROL3D mswCallBacks[B_MESSAGE] = &messageCallBacks; -#endif + return b; } diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c index 201171a..55fedb4 100644 --- a/app/wlib/mswlib/mswpref.c +++ b/app/wlib/mswlib/mswpref.c @@ -5,7 +5,6 @@ #include <commdlg.h> #include <math.h> #include <stdio.h> -#include "misc.h" #include "mswint.h" #include <shlobj.h> #include <Shlwapi.h> @@ -40,13 +39,15 @@ const char * wGetAppLibDir( void ) *cp = '\0'; #ifdef XTRKCAD_CMAKE_BUILD - strcpy(appLibDirName, module_name); - strcat(appLibDirName, "\\..\\share\\xtrkcad"); + strncpy(appLibDirName, module_name, sizeof(appLibDirName)); + size_t len = sizeof(appLibDirName)-strlen(appLibDirName)-1; + strncat(appLibDirName, "\\..\\share\\xtrkcad", len); _fullpath( appLibDirName, appLibDirName, MAX_PATH ); return appLibDirName; #endif - strcpy(appLibDirName, module_name); + strncpy(appLibDirName, module_name, sizeof(appLibDirName)); + appLibDirName[sizeof(appLibDirName)-1] = '\0'; return appLibDirName; } @@ -73,11 +74,12 @@ const char * wGetAppWorkDir( void ) return appWorkDirName; } wGetAppLibDir(); - sprintf( mswTmpBuff, "%s\\xtrkcad0.ini", appLibDirName ); + snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName ); rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, sizeof appWorkDirName, mswTmpBuff ); if ( rc!=0 ) { if ( stricmp( appWorkDirName, "installdir" ) == 0 ) { - strcpy( appWorkDirName, appLibDirName ); + strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) ); + appWorkDirName[sizeof(appWorkDirName)-1] = '\0'; } else { cp = &appWorkDirName[strlen(appWorkDirName)-1]; while (cp>appWorkDirName && *cp == '\\') *cp-- = 0; @@ -89,7 +91,7 @@ const char * wGetAppWorkDir( void ) wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL ); wExit(0); } else { - sprintf( appWorkDirName, "%s\\%s", mswTmpBuff, "XTrackCad" ); + snprintf( appWorkDirName, sizeof(appWorkDirName), "%s\\%s", mswTmpBuff, "XTrackCad" ); if( !PathIsDirectory( appWorkDirName )) { if( !CreateDirectory( appWorkDirName, NULL )) { wNoticeEx( NT_ERROR, "Cannot create user's profile directory", "Exit", NULL ); @@ -125,7 +127,8 @@ typedef struct { BOOL_T dirty; char * val; } prefs_t; -dynArr_t prefs_da; + +static dynArr_t prefs_da; #define prefs(N) DYNARR_N(prefs_t,prefs_da,N) void wPrefSetString( const char * section, const char * name, const char * sval ) @@ -149,6 +152,17 @@ void wPrefSetString( const char * section, const char * name, const char * sval p->val = mswStrdup(sval); } +void wPrefsLoad(char * name) { + prefs_t *p; + for (int i= 0; i<prefs_da.cnt; i++) { + p = &prefs(i); + if (!name || !name[0]) name = mswProfileFile; + int rc = GetPrivateProfileString( p->section, p->name, "", mswTmpBuff, sizeof mswTmpBuff, name ); + if (rc==0) + continue; + p->val = mswStrdup(mswTmpBuff); + } +} char * wPrefGetStringBasic( const char * section, const char * name ) { @@ -160,6 +174,7 @@ char * wPrefGetStringBasic( const char * section, const char * name ) return p->val; } } + rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff, mswProfileFile ); if (rc==0) return NULL; @@ -177,7 +192,7 @@ void wPrefSetInteger( const char * section, const char * name, long lval ) { char tmp[20]; - sprintf( tmp, "%ld", lval ); + snprintf( tmp, sizeof(tmp), "%ld", lval ); wPrefSetString( section, name, tmp ); } @@ -214,7 +229,7 @@ void wPrefSetFloat( { char tmp[20]; - sprintf(tmp, "%0.6f", lval ); + snprintf(tmp, sizeof(tmp), "%0.6f", lval ); wPrefSetString( section, name, tmp ); } @@ -244,15 +259,20 @@ wBool_t wPrefGetFloatBasic( } -void wPrefFlush( void ) +void wPrefFlush( char * name ) { prefs_t * p; for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if ( p->dirty ) + if (name && name[0]) + WritePrivateProfileString( p->section, p->name, p->val, name ); + else if (p->dirty) WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile ); } - WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); + if (name && name[0]) + WritePrivateProfileString( NULL, NULL, NULL, name ); + else + WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); } @@ -273,3 +293,4 @@ void wPrefReset( } prefs_da.cnt = 0; } + diff --git a/app/wlib/mswlib/mswprint.c b/app/wlib/mswlib/mswprint.c index 13756c7..e38ca05 100644 --- a/app/wlib/mswlib/mswprint.c +++ b/app/wlib/mswlib/mswprint.c @@ -4,9 +4,6 @@ #include <stdlib.h> #include <commdlg.h> #include <math.h> -#ifndef WIN32 -#include <print.h> -#endif #include "mswint.h" /* @@ -18,13 +15,9 @@ */ -struct wDraw_t print_d; +static struct wDraw_t print_d; -#ifdef WIN32 -struct tagPDA printDlg; -#else -struct tagPD printDlg; -#endif +static struct tagPDA printDlg; static int printStatus = FALSE; static DOCINFO docInfo; static double tBorder = 0.0, rBorder = 0.0, bBorder = 0.0, lBorder = 0.0; @@ -35,7 +28,7 @@ static HPALETTE newPrintPalette; static HPALETTE oldPrintPalette; -void wPrintClip( wPos_t x, wPos_t y, wPos_t w, wPos_t h ) +void wPrintClip( wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h ) { wDrawClip( &print_d, x, y, w, h ); } @@ -196,9 +189,9 @@ void wPrintSetup( wPrintSetupCallBack_p callback ) if (PrintDlg(&printDlg) != 0 && printDlg.hDC) { getPageDim( printDlg.hDC ); } - if ( callback ) { - callback( TRUE ); - } + //if ( callback ) { + // callback( TRUE ); + //} } const char* wPrintGetName() @@ -255,8 +248,8 @@ HDC mswGetPrinterDC( void ) static wBool_t printAbort = FALSE; -HWND hAbortDlgWnd; -FARPROC lpAbortDlg, lpAbortProc; +static HWND hAbortDlgWnd; +static FARPROC lpAbortDlg, lpAbortProc; static int pageNumber; int FAR PASCAL mswAbortDlg( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) diff --git a/app/wlib/mswlib/mswsplash.c b/app/wlib/mswlib/mswsplash.c index 172b563..bd7644f 100644 --- a/app/wlib/mswlib/mswsplash.c +++ b/app/wlib/mswlib/mswsplash.c @@ -41,9 +41,9 @@ static HWND hSplash; static LPWORD lpwAlign( LPWORD lpIn ) { - ULONG ul; + ULONGLONG ul; - ul = (ULONG) lpIn; + ul = (ULONGLONG) lpIn; ul +=3; ul >>=2; ul <<=2; @@ -148,7 +148,7 @@ wCreateSplash( char *appname, char *appver ) cyDlgUnit = HIWORD(GetDialogBaseUnits()); /* load the logo bitmap */ - sprintf( logoPath, "%s\\logo.bmp", wGetAppLibDir()); + snprintf( logoPath, sizeof(logoPath), "%s\\logo.bmp", wGetAppLibDir()); hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE ); if( !hBmp ) return( 0 ); @@ -266,4 +266,5 @@ wDestroySplash(void) { DestroyWindow( hSplash ); return; -}
\ No newline at end of file +} + diff --git a/app/wlib/mswlib/mswstatus.c b/app/wlib/mswlib/mswstatus.c index f9d72f4..1502a4e 100644 --- a/app/wlib/mswlib/mswstatus.c +++ b/app/wlib/mswlib/mswstatus.c @@ -59,10 +59,10 @@ void wStatusSetValue( wStatus_p wStatusCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * labelStr, - wPos_t width, + wWinPix_t width, const char *message) { return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0); @@ -75,7 +75,7 @@ wStatus_p wStatusCreate( * \return expected width of message box */ -wPos_t +wWinPix_t wStatusGetWidth(const char *testString) { return (wMessageGetWidth(testString)); @@ -88,7 +88,7 @@ wStatusGetWidth(const char *testString) * \return text height */ -wPos_t wStatusGetHeight( +wWinPix_t wStatusGetHeight( long flags) { return (wMessageGetHeight(flags)); @@ -104,7 +104,7 @@ wPos_t wStatusGetHeight( void wStatusSetWidth( wStatus_p b, - wPos_t width) + wWinPix_t width) { wMessageSetWidth((wMessage_p)b, width); -}
\ No newline at end of file +} diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c index 0a0ce88..b43a5d4 100644 --- a/app/wlib/mswlib/mswtext.c +++ b/app/wlib/mswlib/mswtext.c @@ -58,23 +58,17 @@ struct wText_t { HANDLE hText; }; -BOOL_T textPrintAbort = FALSE; - void wTextClear( wText_p b) { - long rc; - rc = SendMessage(b->hWnd, EM_SETREADONLY, 0, 0L); -#ifdef WIN32 - rc = SendMessage(b->hWnd, EM_SETSEL, 0, -1); -#else - rc = SendMessage(b->hWnd, EM_SETSEL, 1, MAKELONG(0, -1)); -#endif - rc = SendMessage(b->hWnd, WM_CLEAR, 0, 0L); + LRESULT rc; + rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)0, (LPARAM)0); + rc = SendMessage(b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1); + rc = SendMessage(b->hWnd, WM_CLEAR, (WPARAM)0, (LPARAM)0); if (b->option&BO_READONLY) { - rc = SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L); + rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0); } } @@ -97,7 +91,7 @@ void wTextAppend( char *buffer; char *extText; int textSize; - int len = strlen(text); + size_t len = strlen(text); if (!len) { return; @@ -135,11 +129,11 @@ void wTextAppend( } if (b->option&BO_READONLY) { - SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L); + SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0); } // scroll to bottom of text box - SendMessage(b->hWnd, EM_LINESCROLL, 0, 10000L); + SendMessage(b->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)10000); } @@ -157,11 +151,11 @@ BOOL_T wTextSave( return FALSE; } - lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L); + lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0); for (l=0; l<lc; l++) { *(WORD*)line = sizeof(line)-1; - len = (int)SendMessage(b->hWnd, EM_GETLINE, l, (DWORD)(LPSTR)line); + len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line); line[len] = '\0'; fprintf(f, "%s\n", line); } @@ -213,17 +207,17 @@ BOOL_T wTextPrint( lineSpace = textMetric.tmHeight + textMetric.tmExternalLeading; linesPerPage = GetDeviceCaps(hDc, VERTRES) / lineSpace; currentLine = 1; - lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L); + lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0); IOStatus = 0; for (l=0; l<lc; l++) { *(WORD*)line = sizeof(line)-1; - len = (int)SendMessage(b->hWnd, EM_GETLINE, l, (DWORD)(LPSTR)line); + len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line); TextOut(hDc, 0, currentLine*lineSpace, line, len); if (++currentLine > linesPerPage) { IOStatus = EndPage(hDc); - if (IOStatus < 0 || textPrintAbort) { + if (IOStatus < 0 ) { break; } StartPage(hDc); @@ -231,7 +225,7 @@ BOOL_T wTextPrint( } } - if (IOStatus >= 0 && !textPrintAbort) { + if (IOStatus >= 0 ) { EndPage(hDc); EndDoc(hDc); } @@ -246,7 +240,7 @@ wBool_t wTextGetModified( wText_p b) { int rc; - rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, 0, 0L); + rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, (WPARAM)0, (LPARAM)0); return (wBool_t)rc; } @@ -311,14 +305,14 @@ void wTextSetReadonly( b->option &= ~BO_READONLY; } - SendMessage(b->hWnd, EM_SETREADONLY, ro, 0L); + SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0); } void wTextSetSize( wText_p bt, - wPos_t width, - wPos_t height) + wWinPix_t width, + wWinPix_t height) { bt->w = width; bt->h = height; @@ -332,13 +326,13 @@ void wTextSetSize( void wTextComputeSize( wText_p bt, - int rows, - int lines, - wPos_t * w, - wPos_t * h) + wWinPix_t rows, + wWinPix_t lines, + wWinPix_t * w, + wWinPix_t * h) { - static wPos_t scrollV_w = -1; - static wPos_t scrollH_h = -1; + static wWinPix_t scrollV_w = -1; + static wWinPix_t scrollH_h = -1; HDC hDc; TEXTMETRIC metrics; @@ -366,8 +360,8 @@ void wTextSetPosition( wText_p bt, int pos) { - long rc; - rc = SendMessage(bt->hWnd, EM_LINESCROLL, 0, MAKELONG(-65535, 0)); + LRESULT rc; + rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535, 0)); } static void textDoneProc(wControl_p b) @@ -387,13 +381,13 @@ static callBacks_t textCallBacks = { wText_p wTextCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, - POS_T height) + wWinPix_t width, + wWinPix_t height) { wText_p b; DWORD style; @@ -416,17 +410,13 @@ wText_p wTextCreate( b->hWnd = CreateWindow("EDIT", NULL, style, b->x, b->y, width, height, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL); if (b->hWnd == NULL) { mswFail("CreateWindow(TEXT)"); return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl(b->hWnd); -#endif - if (option & BT_FIXEDFONT) { if (fixedTextFont == (HFONT)0) { fixedTextFont = CreateFontIndirect(&fixedFont); @@ -434,13 +424,13 @@ wText_p wTextCreate( SendMessage(b->hWnd, WM_SETFONT, (WPARAM)fixedTextFont, (LPARAM)MAKELONG(1, 0)); } else if (!mswThickFont) { - SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L); + SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); } - b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, 0, 0L); + b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0); if (option & BT_CHARUNITS) { - wPos_t w, h; + wWinPix_t w, h; wTextComputeSize(b, width, height, &w, &h); if (!SetWindowPos(b->hWnd, HWND_TOP, 0, 0, diff --git a/app/wlib/mswlib/simple-gettext.c b/app/wlib/mswlib/simple-gettext.c index 412eece..951ce4c 100644 --- a/app/wlib/mswlib/simple-gettext.c +++ b/app/wlib/mswlib/simple-gettext.c @@ -224,7 +224,7 @@ load_domain( const char *filename ) to_read = size; read_ptr = (char *) data; do { - unsigned long int nb = fread( read_ptr, 1, to_read, fp ); + unsigned long int nb = (unsigned int)fread( read_ptr, 1, to_read, fp ); if( nb < to_read ) { fclose (fp); free(data); @@ -341,7 +341,7 @@ get_string( struct loaded_domain *domain, u32 idx ) domain->mapped[idx] = 1; plen = strlen (p); - buf = utf8_to_native (p, plen, -1); + buf = utf8_to_native (p, (unsigned int)plen, -1); buflen = strlen (buf); if (buflen <= plen){ strcpy (p, buf); @@ -392,7 +392,7 @@ gettext( const char *msgid ) /* Locate the MSGID and its translation. */ if( domain->hash_size > 2 && domain->hash_tab ) { /* Use the hashing table. */ - u32 len = strlen (msgid); + u32 len = (u32)strlen (msgid); u32 hash_val = hash_string (msgid); u32 idx = hash_val % domain->hash_size; u32 incr = 1 + (hash_val % (domain->hash_size - 2)); @@ -444,7 +444,7 @@ gettext( const char *msgid ) else if (cmp_val > 0) bottom = act + 1; else - return (char *)get_string( domain, act ); + return (char *)get_string( domain, (int)(act) ); } not_found: diff --git a/app/wlib/mswlib/utf8conv.c b/app/wlib/mswlib/utf8conv.c index 62ada76..5a39b34 100644 --- a/app/wlib/mswlib/utf8conv.c +++ b/app/wlib/mswlib/utf8conv.c @@ -43,7 +43,7 @@ bool wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength) { - unsigned int cnt = 2 * (strlen(inString) + 1); + unsigned int cnt = 2 * (unsigned int)(strlen(inString) + 1); char *tempBuffer = malloc(cnt); // convert to wide character (UTF16) @@ -81,7 +81,7 @@ wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength) bool wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength) { - unsigned int cnt = 2 * (strlen(inString) + 1); + unsigned int cnt = 2 * (int)(strlen(inString) + 1); char *tempBuffer = malloc(cnt); // convert to wide character (UTF16) |