diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-07-03 10:19:36 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-07-03 10:19:36 +0200 |
commit | b6bd52cd7330a90fc0e44dbe6022551a8dd768a1 (patch) | |
tree | 9804282102f8c40d27407b9c94119b35eeb5013c /app/wlib/mswlib | |
parent | c9d0740841fbe0539e42e66d3865672bfcd3ac02 (diff) | |
parent | a14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 (diff) |
Update upstream source from tag 'upstream/5.3.0GA'
Update to upstream version '5.3.0GA'
with Debian dir dfd14d63b0238e276ade6f54dd9100325df5b2f9
Diffstat (limited to 'app/wlib/mswlib')
31 files changed, 4768 insertions, 4194 deletions
diff --git a/app/wlib/mswlib/CMakeLists.txt b/app/wlib/mswlib/CMakeLists.txt index 99ac1d4..1d8464a 100644 --- a/app/wlib/mswlib/CMakeLists.txt +++ b/app/wlib/mswlib/CMakeLists.txt @@ -1,51 +1,57 @@ -find_package(FreeImage REQUIRED) - -FILE(GLOB HEADERS *.h) - -SET(SOURCES - backgnd.c - getopt.c - mswbox.c - mswbutt.c - mswbitmap.c - mswchoic.c - mswcolor.c - mswdraw.c - mswedit.c - mswlines.c - mswlist.c - mswmenu.c - mswmisc.c - mswmsg.c - mswpref.c - mswprint.c - mswsplash.c - mswstatus.c - mswtext.c - gwin32.c - simple-gettext.c - utf8conv.c +# +# build the Win32 variant of the wlib +# + + + +if(XTRKCAD_USE_GETTEXT) + if(WIN32) + add_definitions(-DUSE_SIMPLE_GETTEXT ) + endif(WIN32) +endif(XTRKCAD_USE_GETTEXT) + +target_sources(xtrkcad-wlib + PRIVATE + backgnd.c + getopt.c + mswbox.c + mswbutt.c + mswbitmap.c + mswchoic.c + mswcolor.c + mswdraw.c + mswedit.c + mswlines.c + mswlist.c + mswmenu.c + mswmisc.c + mswmsg.c + mswpref.c + mswprint.c + mswsplash.c + mswstatus.c + mswtext.c + gwin32.c + simple-gettext.c + sysinfo.c + utf8conv.c + mswint.h + dynarr.h + getline/getline.c ) -include_directories(${FREEIMAGE_INCLUDE_PATH}) -INCLUDE_DIRECTORIES(${XTrkCAD_BINARY_DIR}) -# INCLUDE_DIRECTORIES(${help_BINARY_DIR}) - -IF(XTRKCAD_USE_GETTEXT) - IF(WIN32) - ADD_DEFINITIONS(-DUSE_SIMPLE_GETTEXT ) - ENDIF(WIN32) -ENDIF(XTRKCAD_USE_GETTEXT) - -ADD_LIBRARY(xtrkcad-wlib ${HEADERS} ${SOURCES}) - -TARGET_LINK_LIBRARIES(xtrkcad-wlib Htmlhelp msimg32 shlwapi) -target_link_libraries(xtrkcad-wlib ${FREEIMAGE_LIBRARY}) +target_link_libraries(xtrkcad-wlib + PRIVATE + Htmlhelp + msimg32 + shlwapi + FreeImage::FreeImage +) install(FILES ${FREEIMAGE_SHAREDLIB} DESTINATION ${XTRKCAD_BIN_INSTALL_DIR} - ) +) if(XTRKCAD_TESTING AND CMOCKA_FOUND) add_subdirectory( unittest ) diff --git a/app/wlib/mswlib/backgnd.c b/app/wlib/mswlib/backgnd.c index 9599beb..f10e0f0 100644 --- a/app/wlib/mswlib/backgnd.c +++ b/app/wlib/mswlib/backgnd.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <windows.h> diff --git a/app/wlib/mswlib/checksum.c b/app/wlib/mswlib/checksum.c index f19d15b..52d8453 100644 --- a/app/wlib/mswlib/checksum.c +++ b/app/wlib/mswlib/checksum.c @@ -20,15 +20,19 @@ int main( int argc, char *argv[] ) set = 0; fp = openfile( argv[1], "rb", &FileSize ); } - if (fp == NULL) + if (fp == NULL) { exit(1); - + } + fprintf( stderr, "File Size = %ld (%lx)\n", FileSize, FileSize ); sum16computed = mswCheck16( fp, FileSize, &sum16stored ); - if (!mswCheck32( fp, FileSize, &sum32off, &sum32computed, &sum32stored )) + if (!mswCheck32( fp, FileSize, &sum32off, &sum32computed, &sum32stored )) { fprintf( stderr, "mswCheck32 error\n" ); - fprintf( stderr, "sum16: stored = %x, computed = %x, sum = %x, expected FFFF\n", sum16stored, sum16computed, sum16stored+sum16computed ); - fprintf( stderr, "sum32: stored = %lx, computed = %lx, expected %lx\n", sum32stored, sum32computed, sum32stored ); + } + fprintf( stderr, "sum16: stored = %x, computed = %x, sum = %x, expected FFFF\n", + sum16stored, sum16computed, sum16stored+sum16computed ); + fprintf( stderr, "sum32: stored = %lx, computed = %lx, expected %lx\n", + sum32stored, sum32computed, sum32stored ); if (set) { fseek( fp, 0x12, SEEK_SET ); sum16computed = 0xFFFF - sum16computed; diff --git a/app/wlib/mswlib/dynarr.h b/app/wlib/mswlib/dynarr.h index e8a178e..8c79933 100644 --- a/app/wlib/mswlib/dynarr.h +++ b/app/wlib/mswlib/dynarr.h @@ -1,8 +1,8 @@ typedef struct { - int cnt; - int max; - void * ptr; - } dynArr_t; + int cnt; + int max; + void * ptr; +} dynArr_t; #define DYNARR_APPEND(T,DA,INCR) \ { if ((DA).cnt >= (DA).max) { \ diff --git a/app/wlib/mswlib/getline/LICENSE b/app/wlib/mswlib/getline/LICENSE new file mode 100644 index 0000000..22df455 --- /dev/null +++ b/app/wlib/mswlib/getline/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2022, Costantino Grana +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/app/wlib/mswlib/getline/README.md b/app/wlib/mswlib/getline/README.md new file mode 100644 index 0000000..60f0dae --- /dev/null +++ b/app/wlib/mswlib/getline/README.md @@ -0,0 +1,5 @@ +A POSIX getdelim() and getline() implementation for MSVC + +Tired of always having problems in reading arbitrary length lines from file under Windows, I tried to write a POSIX getdelim() and getline() implementation for MSVC. Let me know if you have any suggestion for improving this. + +This probably needs a test suite. diff --git a/app/wlib/mswlib/getline/getline.c b/app/wlib/mswlib/getline/getline.c new file mode 100644 index 0000000..202c7e2 --- /dev/null +++ b/app/wlib/mswlib/getline/getline.c @@ -0,0 +1,73 @@ +#include "getline.h" + +#include <stdlib.h> +#include <errno.h> + +// MSVC specific implementation +static void fseterr(FILE *fp) +{ + struct file { // Undocumented implementation detail + unsigned char *_ptr; + unsigned char *_base; + int _cnt; + int _flag; + int _file; + int _charbuf; + int _bufsiz; + }; + #define _IOERR 0x10 + + ((struct file *)fp)->_flag |= _IOERR; +} + +ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim, FILE *restrict stream) +{ + if (lineptr == NULL || n == NULL || stream == NULL || (*lineptr == NULL && *n != 0)) { + errno = EINVAL; + return -1; + } + if (feof(stream) || ferror(stream)) { + return -1; + } + + if (*lineptr == NULL) { + *n = 256; + *lineptr = malloc(*n); + if (*lineptr == NULL) { + fseterr(stream); + errno = ENOMEM; + return -1; + } + } + ssize_t nread = 0; + int c = EOF; + while (c != delim) { + c = fgetc(stream); + if (c == EOF) { + break; + } + if (nread >= (ssize_t)(*n - 1)) { + size_t newn = *n * 2; + char *newptr = realloc(*lineptr, newn); + if (newptr == NULL) { + fseterr(stream); + errno = ENOMEM; + return -1; + } + *lineptr = newptr; + *n = newn; + } + (*lineptr)[nread++] = c; + } + if (c == EOF && nread == 0) { + return -1; + } + (*lineptr)[nread] = 0; + return nread; +} + +ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict stream) +{ + return getdelim(lineptr, n, '\n', stream); +} + diff --git a/app/wlib/mswlib/getopt.c b/app/wlib/mswlib/getopt.c index 888f5f8..48ffca9 100644 --- a/app/wlib/mswlib/getopt.c +++ b/app/wlib/mswlib/getopt.c @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License along with ASPEX; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ----------------------------------------------------------------------*/ @@ -39,49 +39,50 @@ int optind = 1, opterr, optopt; int getopt(int argc, char *argv[], const char *optstring) { - static int pos = 0; - char *str; - - if (pos == 0) { - if ((optind >= argc) || (*argv[optind] != OPTCHAR)) - return EOF; - pos = 1; - if (argv[optind][pos] == '\0') - return EOF; - } - - str = strchr(optstring, argv[optind][pos]); - if (str == NULL) { - optopt = argv[optind][pos]; - if (opterr) - fprintf(stderr, "%s: illegal option -- %c\n", argv[0], - optopt); - return '?'; - } - - if (str[1] == ':') { - if (argv[optind][pos+1] != '\0') { - optarg = &argv[optind][pos+1]; - return *str; + static int pos = 0; + char *str; + + if (pos == 0) { + if ((optind >= argc) || (*argv[optind] != OPTCHAR)) { + return EOF; + } + pos = 1; + if (argv[optind][pos] == '\0') { + return EOF; + } } - optind++; - if (optind >= argc) { - optopt = *str; - if (opterr) - fprintf(stderr, "%s: option requires an argument -- %c\n", - argv[0], optopt); - return '?'; + + str = strchr(optstring, argv[optind][pos]); + if (str == NULL) { + optopt = argv[optind][pos]; + if (opterr) + fprintf(stderr, "%s: illegal option -- %c\n", argv[0], + optopt); + return '?'; } - optarg = argv[optind]; - optind++; pos = 0; - return *str; - } - else { - pos++; - if (argv[optind][pos] == '\0') { - optind++; - pos = 0; + + if (str[1] == ':') { + if (argv[optind][pos+1] != '\0') { + optarg = &argv[optind][pos+1]; + return *str; + } + optind++; + if (optind >= argc) { + optopt = *str; + if (opterr) + fprintf(stderr, "%s: option requires an argument -- %c\n", + argv[0], optopt); + return '?'; + } + optarg = argv[optind]; + optind++; pos = 0; + return *str; + } else { + pos++; + if (argv[optind][pos] == '\0') { + optind++; + pos = 0; + } + return *str; } - return *str; - } } diff --git a/app/wlib/mswlib/gwin32.c b/app/wlib/mswlib/gwin32.c index 877c329..c537439 100644 --- a/app/wlib/mswlib/gwin32.c +++ b/app/wlib/mswlib/gwin32.c @@ -13,16 +13,15 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* * Modified by the GLib Team and others 1997-2000. See the AUTHORS * file for a list of people on the GLib Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GLib at ftp://ftp.gtk.org/pub/gtk/. + * GLib at ftp://ftp.gtk.org/pub/gtk/. * * Ported to standard C by Martin Fischer 2009 * @@ -48,17 +47,17 @@ #endif #if _MSC_VER > 1300 - #define stricmp _stricmp - #define strnicmp _strnicmp - #define strdup _strdup +#define stricmp _stricmp +#define strnicmp _strnicmp +#define strdup _strdup #endif /** - * This function gets the current thread locale from Windows - without any + * This function gets the current thread locale from Windows - without any * encoding info - and returns it as a string of the above form for use in forming * file names etc. The setlocale() function in the Microsoft C library uses locale * names of the form "English_United States.1252" etc. We want the - * UNIXish standard form "en_US", "zh_TW" etc. The returned string should be + * UNIXish standard form "en_US", "zh_TW" etc. The returned string should be * deallocated with free(). * * \return newly-allocated locale name. @@ -67,80 +66,80 @@ char * g_win32_getlocale (void) { - LCID lcid; - LANGID langid; - char *ev; - char *loc; - int primary, sub; - char iso639[10]; - char iso3166[10]; - const char *script = NULL; + LCID lcid; + LANGID langid; + char *ev; + char *loc; + int primary, sub; + char iso639[10]; + char iso3166[10]; + const char *script = NULL; - /* Let the user override the system settings through environment - * variables, as on POSIX systems. Note that in GTK+ applications - * since GTK+ 2.10.7 setting either LC_ALL or LANG also sets the - * Win32 locale and C library locale through code in gtkmain.c. - */ - if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0') - || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0') - || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0')) - return strdup (ev); + /* Let the user override the system settings through environment + * variables, as on POSIX systems. Note that in GTK+ applications + * since GTK+ 2.10.7 setting either LC_ALL or LANG also sets the + * Win32 locale and C library locale through code in gtkmain.c. + */ + if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0') + || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0') + || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0')) { + return strdup (ev); + } - lcid = GetThreadLocale (); + lcid = GetThreadLocale (); - if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) || - !GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166))) - return strdup ("C"); - - /* Strip off the sorting rules, keep only the language part. */ - langid = LANGIDFROMLCID (lcid); + if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) || + !GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166))) { + return strdup ("C"); + } - /* Split into language and territory part. */ - primary = PRIMARYLANGID (langid); - sub = SUBLANGID (langid); + /* Strip off the sorting rules, keep only the language part. */ + langid = LANGIDFROMLCID (lcid); - /* Handle special cases */ - switch (primary) - { - case LANG_AZERI: - switch (sub) - { - case SUBLANG_AZERI_LATIN: - script = "@Latn"; - break; - case SUBLANG_AZERI_CYRILLIC: - script = "@Cyrl"; - break; - } - break; - case LANG_SERBIAN: /* LANG_CROATIAN == LANG_SERBIAN */ - switch (sub) - { - case SUBLANG_SERBIAN_LATIN: - case 0x06: /* Serbian (Latin) - Bosnia and Herzegovina */ - script = "@Latn"; - break; + /* Split into language and territory part. */ + primary = PRIMARYLANGID (langid); + sub = SUBLANGID (langid); + + /* Handle special cases */ + switch (primary) { + case LANG_AZERI: + switch (sub) { + case SUBLANG_AZERI_LATIN: + script = "@Latn"; + break; + case SUBLANG_AZERI_CYRILLIC: + script = "@Cyrl"; + break; + } + break; + case LANG_SERBIAN: /* LANG_CROATIAN == LANG_SERBIAN */ + switch (sub) { + case SUBLANG_SERBIAN_LATIN: + case 0x06: /* Serbian (Latin) - Bosnia and Herzegovina */ + script = "@Latn"; + break; + } + break; + case LANG_UZBEK: + switch (sub) { + case SUBLANG_UZBEK_LATIN: + script = "@Latn"; + break; + case SUBLANG_UZBEK_CYRILLIC: + script = "@Cyrl"; + break; + } + break; } - break; - case LANG_UZBEK: - switch (sub) - { - case SUBLANG_UZBEK_LATIN: - script = "@Latn"; - break; - case SUBLANG_UZBEK_CYRILLIC: - script = "@Cyrl"; - break; + + loc = malloc( strlen( iso639 ) + strlen( iso3166 ) + (script ? strlen( + script ) : 0) + 2 ); + strcpy( loc, iso639 ); + strcat( loc, "_" ); + strcat( loc, iso3166 ); + if( script ) { + strcat( loc, script ); } - break; - } - - loc = malloc( strlen( iso639 ) + strlen( iso3166 ) + (script ? strlen( script ) : 0) + 2 ); - strcpy( loc, iso639 ); - strcat( loc, "_" ); - strcat( loc, iso3166 ); - if( script ) - strcat( loc, script ); - return loc; + return loc; } diff --git a/app/wlib/mswlib/mswbitmap.c b/app/wlib/mswlib/mswbitmap.c index d4ee83c..9069c35 100644 --- a/app/wlib/mswlib/mswbitmap.c +++ b/app/wlib/mswlib/mswbitmap.c @@ -18,12 +18,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <windows.h> #include <string.h> -#include <malloc.h> #include <math.h> #include <stdlib.h> #include <commdlg.h> @@ -33,24 +32,24 @@ #include "i18n.h" #if _MSC_VER > 1300 - #define stricmp _stricmp - #define strnicmp _strnicmp - #define strdup _strdup +#define stricmp _stricmp +#define strnicmp _strnicmp +#define strdup _strdup #endif struct wBitmap_t { - WOBJ_COMMON - }; + WOBJ_COMMON +}; HPALETTE hOldPal; HBITMAP mswCreateBitMap( - COLORREF fgCol1, - COLORREF fgCol2, - COLORREF bgCol, - int w, - int h, - const char * bits ) + COLORREF fgCol1, + COLORREF fgCol2, + COLORREF bgCol, + int w, + int h, + const char * bits ) { HDC hDc; HDC hButtDc; @@ -69,7 +68,7 @@ HBITMAP mswCreateBitMap( if (mswPalette) { hOldPal = SelectPalette( hButtDc, mswPalette, 0 ); } - + /*PatBlt( hButtDc, 0, 0, w, h, WHITENESS );*/ newBrush = CreateSolidBrush( bgCol ); oldBrush = SelectObject( hButtDc, newBrush ); @@ -84,8 +83,9 @@ HBITMAP mswCreateBitMap( for ( j = 0; j < h; j++ ) { byt = (0xFF & *byts_p++) | 0x100; for ( i = 0; i < w; i++ ) { - if (byt == 1) + if (byt == 1) { byt = (0xFF & *byts_p++) | 0x100; + } if ( byt & 0x1 ) { SetPixel( hButtDc, i, j, fgCol1 ); SetPixel( hButtDc, i+1, j+1, fgCol2 ); @@ -104,7 +104,7 @@ static dynArr_t bitmap_da; #define bitmap(N) DYNARR_N(HBITMAP,bitmap_da,N) void mswRegisterBitMap( - HBITMAP hBm ) + HBITMAP hBm ) { DYNARR_APPEND( HBITMAP, bitmap_da, 10 ); bitmap(bitmap_da.cnt-1) = hBm; @@ -113,14 +113,15 @@ void mswRegisterBitMap( void deleteBitmaps( void ) { int inx; - for ( inx=0; inx<bitmap_da.cnt; inx++ ) + for ( inx=0; inx<bitmap_da.cnt; inx++ ) { DeleteObject( bitmap(inx) ); + } } /** * Draw a bitmap to the screen. * - * \param hDc IN device context + * \param hDc IN device context * \param offw IN horizontal offset * \param offh IN vertical offset * \param bm IN icon to draw @@ -131,46 +132,48 @@ void deleteBitmaps( void ) */ void mswDrawIcon( - HDC hDc, - int offw, - int offh, - wIcon_p bm, - int disabled, - COLORREF color1, - COLORREF color2 ) + HDC hDc, + int offw, + int offh, + wIcon_p bm, + int disabled, + COLORREF color1, + COLORREF color2 ) { int i; int byt; BITMAPINFO *bmiInfo; COLORREF col; - /* draw the bitmap by dynamically creating a Windows DIB in memory */ + /* draw the bitmap by dynamically creating a Windows DIB in memory */ /* BITMAPINFO already has one RGBQUAD color struct, so only allocate the rest */ - bmiInfo = malloc( sizeof( BITMAPINFO ) + (bm->colorcnt - 1) * sizeof( RGBQUAD )); - if( !bmiInfo ) { - fprintf( stderr, "could not allocate memory for bmiInfo\n" ); - abort(); - } - - /* initialize bitmap header from XPM information */ - bmiInfo->bmiHeader.biSize = sizeof( bmiInfo->bmiHeader ); - bmiInfo->bmiHeader.biWidth = bm->w; - bmiInfo->bmiHeader.biHeight = bm->h; - bmiInfo->bmiHeader.biPlanes = 1; - if( bm->type == mswIcon_bitmap ) - bmiInfo->bmiHeader.biBitCount = 1; - else - bmiInfo->bmiHeader.biBitCount = 8; /* up to 256 colors */ - bmiInfo->bmiHeader.biCompression = BI_RGB; /* no compression */ - bmiInfo->bmiHeader.biSizeImage = 0; - bmiInfo->bmiHeader.biXPelsPerMeter = 0; - bmiInfo->bmiHeader.biYPelsPerMeter = 0; - bmiInfo->bmiHeader.biClrUsed = bm->colorcnt; /* number of colors used */ - bmiInfo->bmiHeader.biClrImportant = bm->colorcnt; + bmiInfo = malloc( sizeof( BITMAPINFO ) + (bm->colorcnt - 1) * sizeof( + RGBQUAD )); + if( !bmiInfo ) { + fprintf( stderr, "could not allocate memory for bmiInfo\n" ); + abort(); + } + + /* initialize bitmap header from XPM information */ + bmiInfo->bmiHeader.biSize = sizeof( bmiInfo->bmiHeader ); + bmiInfo->bmiHeader.biWidth = bm->w; + bmiInfo->bmiHeader.biHeight = bm->h; + bmiInfo->bmiHeader.biPlanes = 1; + if( bm->type == mswIcon_bitmap ) { + bmiInfo->bmiHeader.biBitCount = 1; + } else { + bmiInfo->bmiHeader.biBitCount = 8; /* up to 256 colors */ + } + bmiInfo->bmiHeader.biCompression = BI_RGB; /* no compression */ + bmiInfo->bmiHeader.biSizeImage = 0; + bmiInfo->bmiHeader.biXPelsPerMeter = 0; + bmiInfo->bmiHeader.biYPelsPerMeter = 0; + bmiInfo->bmiHeader.biClrUsed = bm->colorcnt; /* number of colors used */ + bmiInfo->bmiHeader.biClrImportant = bm->colorcnt; /* * create a transparency mask and paint to screen - */ + */ if( bm->type == mswIcon_bitmap ) { memset( &bmiInfo->bmiColors[ 0 ], 0xFF, sizeof( RGBQUAD )); memset( &bmiInfo->bmiColors[ 1 ], 0, sizeof( RGBQUAD )); @@ -180,69 +183,71 @@ void mswDrawIcon( } StretchDIBits(hDc, offw, offh, - (int)ceil(bmiInfo->bmiHeader.biWidth*scaleIcon), - (int)ceil(bmiInfo->bmiHeader.biHeight*scaleIcon), + bmiInfo->bmiHeader.biWidth, + bmiInfo->bmiHeader.biHeight, 0, 0, bmiInfo->bmiHeader.biWidth, bmiInfo->bmiHeader.biHeight, bm->pixels, bmiInfo, DIB_RGB_COLORS, SRCAND); - + /* now paint the bitmap with transparent set to black */ if( bm->type == mswIcon_bitmap ) { - if( disabled ) { + if( disabled ) { col = color2; } else { col = color1; } memset( &bmiInfo->bmiColors[ 0 ], 0, sizeof( RGBQUAD )); - bmiInfo->bmiColors[ 1 ].rgbRed = GetRValue( col ); - bmiInfo->bmiColors[ 1 ].rgbGreen = GetGValue( col ); - bmiInfo->bmiColors[ 1 ].rgbBlue = GetBValue( col ); - } else { + bmiInfo->bmiColors[ 1 ].rgbRed = GetRValue( col ); + bmiInfo->bmiColors[ 1 ].rgbGreen = GetGValue( col ); + bmiInfo->bmiColors[ 1 ].rgbBlue = GetBValue( col ); + } else { if( disabled ) { /* create a gray scale palette */ for( i = 0; i < bm->colorcnt; i ++ ) { if (i != bm->transparent) { byt = (30 * bm->colormap[i].rgbRed + - 59 * bm->colormap[i].rgbGreen + - 11 * bm->colormap[i].rgbBlue) / 100; + 59 * bm->colormap[i].rgbGreen + + 11 * bm->colormap[i].rgbBlue) / 100; /* if totally black, use a dark gray */ - if (byt == 0) + if (byt == 0) { byt = 0x66; + } bmiInfo->bmiColors[i].rgbRed = byt; bmiInfo->bmiColors[i].rgbGreen = byt; bmiInfo->bmiColors[i].rgbBlue = byt; } } - } else { - /* copy the palette */ - memcpy( (void *)bmiInfo->bmiColors, (void *)bm->colormap, bm->colorcnt * sizeof( RGBQUAD )); - } + } else { + /* copy the palette */ + memcpy( (void *)bmiInfo->bmiColors, (void *)bm->colormap, + bm->colorcnt * sizeof( RGBQUAD )); + } memset( &bmiInfo->bmiColors[ bm->transparent ], 0, sizeof( RGBQUAD )); - } - - /* show the bitmap */ - StretchDIBits(hDc, offw, offh, - (int)ceil(bmiInfo->bmiHeader.biWidth*scaleIcon), - (int)ceil(bmiInfo->bmiHeader.biHeight*scaleIcon), - 0, 0, - bmiInfo->bmiHeader.biWidth, - bmiInfo->bmiHeader.biHeight, - bm->pixels, bmiInfo, - DIB_RGB_COLORS, SRCPAINT); - - /* forget the data */ - free( bmiInfo ); + } + + /* show the bitmap */ + StretchDIBits(hDc, offw, offh, + bmiInfo->bmiHeader.biWidth, + bmiInfo->bmiHeader.biHeight, + 0, 0, + bmiInfo->bmiHeader.biWidth, + bmiInfo->bmiHeader.biHeight, + bm->pixels, bmiInfo, + DIB_RGB_COLORS, SRCPAINT); + + /* forget the data */ + free( bmiInfo ); } /** - * Create a two color bitmap. This creates a two color icon. Pixels set to 1 are painted + * Create a two color bitmap. This creates a two color icon. Pixels set to 1 are painted * in the specified color, pixels set to 0 are transparent - * in order to convert the format, a lot of bit fiddling is necessary. The order of - * scanlines needs to be reversed and the bit order (high order - low order) is reversed + * in order to convert the format, a lot of bit fiddling is necessary. The order of + * scanlines needs to be reversed and the bit order (high order - low order) is reversed * as well. * \param w IN width in pixels * \param h IN height in pixels @@ -251,12 +256,13 @@ void mswDrawIcon( * \return pointer to icon */ -wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_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; unsigned char *dest; - static unsigned char revbits[] = { 0, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F }; + static unsigned char revbits[] = { 0, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F }; unsigned long col = wDrawGetRGB( color ); wIcon_p ip; @@ -278,13 +284,13 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol ip->colormap[ 1 ].rgbBlue = col & 0xFF; ip->colormap[ 1 ].rgbRed = (col>>16) & 0xFF; ip->colormap[ 1 ].rgbGreen = (col>>8) & 0xFF; - ip->colormap[ 1 ].rgbReserved = 0; + ip->colormap[ 1 ].rgbReserved = 0; color = GetSysColor( COLOR_BTNFACE ); ip->colormap[ 0 ].rgbBlue = GetBValue( color ); ip->colormap[ 0 ].rgbRed = GetRValue( color ); ip->colormap[ 0 ].rgbGreen = GetGValue( color ); - ip->colormap[ 0 ].rgbReserved = 0; + ip->colormap[ 0 ].rgbReserved = 0; lineLength = (((( ip->w + 7 ) / 8 ) + 3 ) >> 2 ) << 2; ip->pixels = malloc( lineLength * ip->h ); @@ -293,19 +299,19 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol abort(); } - /* + /* * copy the bits from source to the buffer, at this time the order of * scanlines is reversed by starting with the last source line. */ for( i = 0; i < ip->h; i++ ) { dest = ip->pixels + i * lineLength; - memcpy( dest, bits + ( ip->h - i - 1 ) * (( ip->w + 7) / 8), ( ip->w + 7 ) / 8 ); + memcpy( dest, bits + ( ip->h - i - 1 ) * (( ip->w + 7) / 8), + ( ip->w + 7 ) / 8 ); /* * and now, the bit order is changed, this is done via a lookup table */ - for( j = 0; j < lineLength; j++ ) - { + for( j = 0; j < lineLength; j++ ) { unsigned byte = dest[ j ]; unsigned low = byte & 0x0F; unsigned high = (byte & 0xF0) >> 4; @@ -323,7 +329,7 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol * transparency, other symbolic names are not supported. * * \param pm IN XPM variable - * \return pointer to icon, call free() if not needed anymore. + * \return pointer to icon, call free() if not needed anymore. */ wIcon_p wIconCreatePixMap( char *pm[]) @@ -355,9 +361,9 @@ wIcon_p wIconCreatePixMap( char *pm[]) height = (int)strtol(cq, &cq, 10 ); /* height of image */ col = (int)strtol(cq, &cq, 10 ); /* number of colors used */ numchars = (int)strtol(cq, &cq, 10 ); /* get number of chars per pixel */ - + ip->colormap = malloc( col * sizeof( RGBQUAD )); - ip->w = width; + ip->w = width; ip->h = height; ip->colorcnt = col; /* number of colors used */ @@ -368,19 +374,19 @@ wIcon_p wIconCreatePixMap( char *pm[]) if( numchars == 1 ) { keys[ col ] = (unsigned)ptr[0]; + } else if( numchars == 2 ) { + keys[ col ] = (unsigned) ( ptr[ 0 ] + ptr[ 1 ] * 256 ); } - else if( numchars == 2 ) { - keys[ col ] = (unsigned) ( ptr[ 0 ] + ptr[ 1 ] * 256 ); - } - + cp = strtok( ptr + numchars, "\t " ); /* cp points to color type */ assert( *cp == 'c' ); /* should always be color */ - - cp = strtok( NULL, "\t " ); /* go to next token, the color definition itself */ + + cp = strtok( NULL, + "\t " ); /* go to next token, the color definition itself */ if( *cp == '#' ) { /* is this a hex RGB specification? */ len = strlen( cp+1 ) / 3; - assert( len == 4 || len == 2 ); /* expecting three 2 char or 4 char values */ + assert( len == 4 || len == 2 ); /* expecting three 2 char or 4 char values */ buff[2] = 0; /* if yes, extract the values */ memcpy( buff, cp + 1, 2 ); r = (int)strtol(buff, &cq, 16); @@ -397,9 +403,9 @@ wIcon_p wIconCreatePixMap( char *pm[]) } else { if( !stricmp( cp, "none" )) { /* special case transparency*/ ip->transparent = col; + } else { + assert( *cp == '#' ); /* if no, abort for the moment */ } - else - assert( *cp == '#' ); /* if no, abort for the moment */ } free( ptr ); } @@ -413,32 +419,34 @@ wIcon_p wIconCreatePixMap( char *pm[]) abort(); } - /* + /* convert the XPM pixel data to indexes into color table - at the same time the order of rows is reversed + at the same time the order of rows is reversed Win32 should be able to do that but I couldn't find out - how, so this is coded by hand. + how, so this is coded by hand. */ /* for all rows */ for( i = 0; i < ip->h; i++ ) { - + cq = ip->pixels + lineLength * i; /* get the next row */ cp = pm[ ip->h - i + ip->colorcnt ]; /* for all pixels in row */ for( j = 0; j < ip->w; j++ ) { /* get the pixel info */ - if( numchars == 1 ) + if( numchars == 1 ) { pixel = ( unsigned )*cp; - else + } else { pixel = (unsigned) (*cp + *(cp+1)*256); + } cp += numchars; /* look up pixel info in color table */ k = 0; - while(k < col && pixel != keys[ k ] ) + while(k < col && pixel != keys[ k ] ) { k++; + } if (pixel == keys[k]) { /* save the index into color table */ *(cq + j) = k; @@ -446,9 +454,9 @@ wIcon_p wIconCreatePixMap( char *pm[]) *(cq + j) = 0; } } - } + } free( keys ); - + return ip; } @@ -468,7 +476,7 @@ void wIconSetColor( wIcon_p ip, wDrawColor color ) * * \param d IN drawing area * \param bm IN bitmap to draw - * \param x IN x position + * \param x IN x position * \param y IN y position */ @@ -489,20 +497,22 @@ wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y ) */ wControl_p -wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option, const struct wIcon_t * iconP ) +wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option, + const struct wIcon_t * iconP ) { wBitmap_p control; int index; DWORD style = SS_OWNERDRAW | WS_VISIBLE | WS_CHILD; - control = mswAlloc( parent, B_BITMAP, NULL, sizeof( struct wBitmap_t ), NULL, &index ); + control = mswAlloc( parent, B_BITMAP, NULL, sizeof( struct wBitmap_t ), NULL, + &index ); mswComputePos( (wControl_p)control, x, y ); control->option = option; control->hWnd = CreateWindow( "STATIC", NULL, - style, control->x, control->y, - iconP->w, iconP->h, - ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); + style, control->x, control->y, + iconP->w, iconP->h, + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (control->hWnd == NULL) { mswFail("CreateWindow(BITMAP)"); diff --git a/app/wlib/mswlib/mswbox.c b/app/wlib/mswlib/mswbox.c index 4f90cf4..5698ae4 100644 --- a/app/wlib/mswlib/mswbox.c +++ b/app/wlib/mswlib/mswbox.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -15,9 +14,9 @@ */ struct wBox_t { - WOBJ_COMMON - wBoxType_e boxTyp; - }; + WOBJ_COMMON + wBoxType_e boxTyp; +}; #define B (1) #define W (2) @@ -29,9 +28,9 @@ struct wBox_t { void wBoxSetSize( - wBox_p bb, - wWinPix_t w, - wWinPix_t h ) + wBox_p bb, + wWinPix_t w, + wWinPix_t h ) { bb->w = w; bb->h = h; @@ -39,7 +38,7 @@ void wBoxSetSize( static void repaintBox( HWND hWnd, wControl_p b ) -{ +{ HDC hDc; wBox_p bb = (wBox_p)(b); wWinPix_t x0, y0, x1, y1; @@ -53,7 +52,8 @@ static void repaintBox( HWND hWnd, wControl_p b ) { /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} }, { /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} }, { /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} }, - { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} } }; + { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} } + }; x0 = bb->x; x1 = bb->x+bb->w; @@ -89,18 +89,19 @@ static void repaintBox( HWND hWnd, wControl_p b ) static callBacks_t boxCallBacks = { - repaintBox, - NULL, - NULL }; + repaintBox, + NULL, + NULL +}; wBox_p wBoxCreate( - wWin_p parent, - wWinPix_t origX, - wWinPix_t origY, - const char * labelStr, - wBoxType_e typ, - wWinPix_t width, - wWinPix_t height ) + wWin_p parent, + wWinPix_t origX, + wWinPix_t origY, + const char * labelStr, + wBoxType_e typ, + wWinPix_t width, + wWinPix_t height ) { wBox_p b; int index; @@ -113,7 +114,7 @@ wBox_p wBoxCreate( b->w = width; b->h = height; mswAddButton( (wControl_p)b, FALSE, NULL ); - mswCallBacks[B_BOX] = &boxCallBacks; + mswCallBacks[B_BOX] = &boxCallBacks; repaintBox( ((wControl_p)parent)->hWnd, (wControl_p)b ); return b; -} +} diff --git a/app/wlib/mswlib/mswbutt.c b/app/wlib/mswlib/mswbutt.c index ac5bc87..be72257 100644 --- a/app/wlib/mswlib/mswbutt.c +++ b/app/wlib/mswlib/mswbutt.c @@ -17,12 +17,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -48,28 +47,29 @@ static XWNDPROC oldButtProc = NULL; struct wButton_t { - WOBJ_COMMON - wButtonCallBack_p action; - wBool_t busy; - wBool_t selected; - wIcon_p icon; - UINT_PTR timer_id; - int timer_count; - int timer_state; - }; + WOBJ_COMMON + wButtonCallBack_p action; + wBool_t busy; + wBool_t selected; + wIcon_p icon; + UINT_PTR timer_id; + int timer_count; + int timer_state; +}; void mswButtPush( - wControl_p b ) + wControl_p b ) { - if ( ((wButton_p)b)->action ) + if ( ((wButton_p)b)->action ) { ((wButton_p)b)->action( ((wButton_p)b)->data ); + } } /** * Paint function for toolbar buttons - * + * * \param hButtDc IN valid device context * \param bm IN bitmap to add to button * \param selected IN selected state of button @@ -77,27 +77,25 @@ void mswButtPush( */ static void drawButton( - HDC hButtDc, - wIcon_p bm, - BOOL_T selected, - BOOL_T disabled ) + HDC hButtDc, + wIcon_p bm, + BOOL_T selected, + BOOL_T disabled ) { HGDIOBJ oldBrush, newBrush; HPEN oldPen, newPen; RECT rect; COLORREF color1, color2; wWinPix_t offw=5, offh=5; - TRIVERTEX vert[2] ; - GRADIENT_RECT gRect; COLORREF colL; COLORREF colD; COLORREF colF; #define LEFT (0) -#define RIGHT (LONG)ceil(bm->w*scaleIcon+10) +#define RIGHT (bm->w+9) #define TOP (0) -#define BOTTOM (LONG)ceil(bm->h*scaleIcon+10) +#define BOTTOM (bm->h+9) /* get the lightest and the darkest color to use */ colL = GetSysColor( COLOR_BTNHIGHLIGHT ); @@ -117,8 +115,7 @@ static void drawButton( DeleteObject( SelectObject( hButtDc, oldBrush ) ); /* disabled button remain flat */ - if( !disabled ) - { + if( !disabled ) { /* select colors for the gradient */ if( selected ) { color1 = colD; @@ -128,67 +125,27 @@ static void drawButton( color2 = colD; } -#define GRADIENT_WIDTH 6 - - /* - first draw the top gradient - this always ends in the button face color - starting color depends on button state (selected or not) - */ - vert [0] .x = LEFT; - vert [0] .y = TOP; - vert [0] .Red = GetRValue( color1 )* 256; - vert [0] .Green = GetGValue( color1 )* 256; - vert [0] .Blue = GetBValue( color1 )* 256; - vert [0] .Alpha = 0x0000; - vert [1] .x = RIGHT; - vert [1] .y = TOP + GRADIENT_WIDTH; - vert [1] .Red = GetRValue( colF )* 256; - vert [1] .Green = GetGValue( colF )* 256; - vert [1] .Blue = GetBValue( colF )* 256; - vert [1] .Alpha = 0x0000; - - gRect.UpperLeft = 0; - gRect.LowerRight = 1; - - GradientFill(hButtDc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V); - - /* - now draw the bottom gradient - this always starts with the button face color - ending color depends on button state (selected or not) - */ - vert [0] .x = LEFT; - vert [0] .y = BOTTOM - GRADIENT_WIDTH; - vert [0] .Red = GetRValue( colF )* 256; - vert [0] .Green = GetGValue( colF )* 256; - vert [0] .Blue = GetBValue( colF )* 256; - vert [0] .Alpha = 0x0000; - vert [1] .x = RIGHT; - vert [1] .y = BOTTOM; - vert [1] .Red = GetRValue( color2 )* 256; - vert [1] .Green = GetGValue( color2 )* 256; - vert [1] .Blue = GetBValue( color2 )* 256; - vert [1] .Alpha = 0x0000; - gRect.UpperLeft = 0; - gRect.LowerRight = 1; - GradientFill(hButtDc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V); + /* draw delimiting lines in shadow color */ + newPen = CreatePen( PS_SOLID, 0, color1 ); + oldPen = SelectObject( hButtDc, newPen ); + + MoveTo( hButtDc, RIGHT-1, TOP ); + LineTo( hButtDc, LEFT, TOP ); + LineTo( hButtDc, LEFT, BOTTOM ); + DeleteObject( SelectObject( hButtDc, oldPen ) ); + + newPen = CreatePen( PS_SOLID, 0, color2 ); + oldPen = SelectObject( hButtDc, newPen ); + MoveTo( hButtDc, RIGHT, TOP+1 ); + LineTo( hButtDc, RIGHT, BOTTOM ); + LineTo( hButtDc, LEFT, BOTTOM ); + DeleteObject( SelectObject( hButtDc, oldPen ) ); } - /* draw delimiting lines in shadow color */ - newPen = CreatePen( PS_SOLID, 0, colD ); - oldPen = SelectObject( hButtDc, newPen ); - - MoveTo( hButtDc, LEFT, TOP ); - LineTo( hButtDc, LEFT, BOTTOM ); - MoveTo( hButtDc, RIGHT, TOP ); - LineTo( hButtDc, RIGHT, BOTTOM ); - - DeleteObject( SelectObject( hButtDc, oldPen ) ); - color2 = GetSysColor( COLOR_BTNSHADOW ); - color1 = RGB( bm->colormap[ 1 ].rgbRed, bm->colormap[ 1 ].rgbGreen, bm->colormap[ 1 ].rgbBlue ); + color1 = RGB( bm->colormap[ 1 ].rgbRed, bm->colormap[ 1 ].rgbGreen, + bm->colormap[ 1 ].rgbBlue ); if (selected) { offw++; offh++; @@ -198,45 +155,46 @@ static void drawButton( static void buttDrawIcon( - wButton_p b, - HDC butt_hDc ) + wButton_p b, + HDC butt_hDc ) { - wIcon_p bm = b->icon; - wWinPix_t offw=5, offh=5; + wIcon_p bm = b->icon; + wWinPix_t offw=5, offh=5; - if (b->selected || b->busy) { - offw++; offh++; - } else if ( (b->option & BO_DISABLED) != 0 ) { - ; - } else { - ; - } - drawButton( butt_hDc, bm, b->selected || b->busy, (b->option & BO_DISABLED) != 0 ); + if (b->selected || b->busy) { + offw++; offh++; + } else if ( (b->option & BO_DISABLED) != 0 ) { + ; + } else { + ; + } + drawButton( butt_hDc, bm, b->selected + || b->busy, (b->option & BO_DISABLED) != 0 ); } void wButtonSetBusy( - wButton_p b, - int value) + wButton_p b, + int value) { - 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); + 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); } void wButtonSetLabel( - wButton_p b, - const char * label ) + wButton_p b, + const char * label ) { if ((b->option&BO_ICON) == 0) { /*b->labelStr = label;*/ @@ -248,11 +206,11 @@ void wButtonSetLabel( } /** - * Button timer: handle timer events for buttons. These are used for + * 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 + * - initial delay before repetitions begin + * - slow repeats for a few cycles + * - fast repeats therafter * - stop timer * * \param hWnd Handle of the window, unused @@ -264,45 +222,46 @@ void wButtonSetLabel( 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; + 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 ) + +static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, + LPARAM lParam ) { wButton_p bb = (wButton_p)b; DRAWITEMSTRUCT * di = (DRAWITEMSTRUCT *)lParam; @@ -319,13 +278,14 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L case WM_MEASUREITEM: { MEASUREITEMSTRUCT * mi = (MEASUREITEMSTRUCT *)lParam; - if (bb->type != B_BUTTON || (bb->option & BO_ICON) == 0) + if (bb->type != B_BUTTON || (bb->option & BO_ICON) == 0) { break; + } mi->CtlType = ODT_BUTTON; mi->CtlID = (UINT)wParam; - mi->itemWidth = (UINT)ceil(bb->w*scaleIcon); - mi->itemHeight = (UINT)ceil(bb->h*scaleIcon); - } return (LRESULT)0; + mi->itemWidth = (UINT)bb->w; + mi->itemHeight = (UINT)bb->h; + } return (LRESULT)0; case WM_DRAWITEM: if (bb->type == B_BUTTON && (bb->option & BO_ICON) != 0) { @@ -343,16 +303,16 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L static void buttDone( - wControl_p b ) + wControl_p b ) { free(b); } LRESULT CALLBACK pushButt( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ @@ -377,7 +337,7 @@ LRESULT CALLBACK pushButt( case 0x09: /*SetFocus( ((wControl_p)(b->parent))->hWnd );*/ SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR, - wParam, lParam ); + wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ return (LONG_PTR)0; @@ -385,8 +345,9 @@ LRESULT CALLBACK pushButt( } break; case WM_KILLFOCUS: - if ( b ) + if ( b ) { InvalidateRect( b->hWnd, NULL, TRUE ); + } return (LRESULT)0; break; case WM_LBUTTONDOWN: @@ -396,11 +357,12 @@ LRESULT CALLBACK pushButt( b->timer_id = (UINT_PTR)b; } break; - case WM_LBUTTONUP: - /* don't know why but this solves a problem with color selection */ - Sleep( 0 ); - if (b->timer_id) + 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; @@ -409,20 +371,21 @@ LRESULT CALLBACK pushButt( } static callBacks_t buttonCallBacks = { - mswRepaintLabel, - buttDone, - buttPush }; + mswRepaintLabel, + buttDone, + buttPush +}; wButton_p wButtonCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - wButtonCallBack_p action, - void * data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + wButtonCallBack_p action, + void * data ) { wButton_p b; RECT rect; @@ -432,8 +395,9 @@ wButton_p wButtonCreate( HDC hDc; wIcon_p bm; - if (width <= 0) + if (width <= 0) { width = 80; + } if ((option&BO_ICON) == 0) { labelStr = mswStrdup( labelStr ); } else { @@ -446,20 +410,21 @@ wButton_p wButtonCreate( b->selected = 0; mswComputePos( (wControl_p)b, x, y ); if (b->option&BO_ICON) { - width = (wWinPix_t)ceil(bm->w*scaleIcon)+10; - h = (int)ceil(bm->h*scaleIcon)+10; + width = (wWinPix_t)(bm->w+10); + h = bm->h+10; b->icon = bm; } else { width = (wWinPix_t)(width*mswScale); } style = ((b->option&BO_ICON)? BS_OWNERDRAW : BS_PUSHBUTTON) | - WS_CHILD | WS_VISIBLE | - mswGetBaseStyle(parent); - if ((b->option&BB_DEFAULT) != 0) + WS_CHILD | WS_VISIBLE | + mswGetBaseStyle(parent); + if ((b->option&BB_DEFAULT) != 0) { style |= BS_DEFPUSHBUTTON; + } b->hWnd = CreateWindow( "BUTTON", labelStr, style, b->x, b->y, - /*CW_USEDEFAULT, CW_USEDEFAULT,*/ width, h, - ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); + /*CW_USEDEFAULT, CW_USEDEFAULT,*/ width, h, + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(BUTTON)"); return b; @@ -473,19 +438,16 @@ wButton_p wButtonCreate( mswCallBacks[B_BUTTON] = &buttonCallBacks; mswChainFocus( (wControl_p)b ); - oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)&pushButt); -#ifdef _OLDCODE - oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt); -#endif + oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, + (LONG_PTR)&pushButt); if (mswPalette) { hDc = GetDC( b->hWnd ); SelectPalette( hDc, mswPalette, 0 ); RealizePalette( hDc ); ReleaseDC( b->hWnd, hDc ); } - if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); + 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 55ed177..ac58023 100644 --- a/app/wlib/mswlib/mswchoic.c +++ b/app/wlib/mswlib/mswchoic.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -22,25 +21,25 @@ static XWNDPROC oldChoiceItemProc = NULL; static XWNDPROC newChoiceItemProc; typedef struct { - WOBJ_COMMON - wChoice_p owner; - } wChoiceItem_t, * wChoiceItem_p; + WOBJ_COMMON + wChoice_p owner; +} wChoiceItem_t, * wChoiceItem_p; struct wChoice_t { - WOBJ_COMMON - const char * const * labels; - wChoiceItem_p *buttList; - long *valueP; - long oldVal; - wChoiceCallBack_p action; - HWND hBorder; - }; + WOBJ_COMMON + const char * const * labels; + wChoiceItem_p *buttList; + long *valueP; + long oldVal; + wChoiceCallBack_p action; + HWND hBorder; +}; static FARPROC oldChoiceProc; void wRadioSetValue( - wChoice_p bc, - long val ) + wChoice_p bc, + long val ) { const char * const * labels; long cnt; @@ -49,14 +48,15 @@ void wRadioSetValue( butts = (wChoiceItem_p*)bc->buttList; for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ ) SendMessage( (*butts)->hWnd, BM_SETCHECK, - (WPARAM)((val==cnt)?1:0), (LPARAM)0 ); + (WPARAM)((val==cnt)?1:0), (LPARAM)0 ); bc->oldVal = val; - if (bc->valueP) + if (bc->valueP) { *bc->valueP = val; + } } long wRadioGetValue( - wChoice_p bc ) + wChoice_p bc ) { return bc->oldVal; } @@ -64,8 +64,8 @@ long wRadioGetValue( void wToggleSetValue( - wChoice_p bc, - long val ) + wChoice_p bc, + long val ) { const char * const * labels; long cnt; @@ -74,49 +74,53 @@ void wToggleSetValue( butts = (wChoiceItem_p*)bc->buttList; for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ ) SendMessage( (*butts)->hWnd, BM_SETCHECK, - (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 ); + (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 ); bc->oldVal = val; - if (bc->valueP) + if (bc->valueP) { *bc->valueP = val; + } } long wToggleGetValue( - wChoice_p bc ) + wChoice_p bc ) { return bc->oldVal; } static void choiceSetBusy( - wControl_p b, - BOOL_T busy) + wControl_p b, + BOOL_T busy) { wChoiceItem_p * butts; wChoice_p bc = (wChoice_p)b; - for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) + for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) { EnableWindow( (*butts)->hWnd, !(BOOL)busy ); + } } static void choiceShow( - wControl_p b, - BOOL_T show) + wControl_p b, + BOOL_T show) { wChoice_p bc = (wChoice_p)b; wChoiceItem_p * butts; - if ((bc->option & BC_NOBORDER)==0) + if ((bc->option & BC_NOBORDER)==0) { ShowWindow( bc->hBorder, show?SW_SHOW:SW_HIDE ); + } - for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) + for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) { ShowWindow( (*butts)->hWnd, show?SW_SHOW:SW_HIDE ); + } } static void choiceSetPos( - wControl_p b, - wWinPix_t x, - wWinPix_t y ) + wControl_p b, + wWinPix_t x, + wWinPix_t y ) { wChoice_p bc = (wChoice_p)b; wChoiceItem_p * butts; @@ -126,25 +130,25 @@ static void choiceSetPos( dy = y - bc->y; if ((bc->option & BC_NOBORDER)==0) SetWindowPos( bc->hBorder, HWND_TOP, x, y, CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOSIZE|SWP_NOZORDER ); + 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, (*butts)->y, - CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOSIZE|SWP_NOZORDER ); + (*butts)->x, (*butts)->y, + CW_USEDEFAULT, CW_USEDEFAULT, + SWP_NOSIZE|SWP_NOZORDER ); } bc->x = x; bc->y = y; } LRESULT FAR PASCAL _export pushChoiceItem( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); @@ -157,9 +161,9 @@ LRESULT FAR PASCAL _export pushChoiceItem( case 0x0D: case 0x1B: case 0x09: - SetFocus( ((wControl_p)(b->parent))->hWnd ); + SetFocus( ((wControl_p)(b->parent))->hWnd ); SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR, - wParam, lParam ); + wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ return (LRESULT)0; @@ -171,18 +175,18 @@ LRESULT FAR PASCAL _export pushChoiceItem( } LRESULT choiceItemProc( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) -{ + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) +{ wChoiceItem_p me = (wChoiceItem_p)b, *rest; wChoice_p bc; int num; switch( message ) { - + case WM_COMMAND: switch (WCMD_PARAM_NOTF) { case BN_CLICKED: @@ -196,9 +200,9 @@ LRESULT choiceItemProc( bc->oldVal ^= (1L<<num); } SendMessage( (*rest)->hWnd, BM_SETCHECK, - (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 ); + (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 ); break; - + case B_RADIO: if (*rest != me) { SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)0, (LPARAM)0 ); @@ -209,35 +213,39 @@ LRESULT choiceItemProc( break; } } - if (bc->valueP) + if (bc->valueP) { *bc->valueP = bc->oldVal; - if (bc->action) + } + if (bc->action) { bc->action( bc->oldVal, bc->data ); + } break; } break; - } - + } + return DefWindowProc( hWnd, message, wParam, lParam ); -} +} static callBacks_t choiceCallBacks = { - mswRepaintLabel, - NULL, - NULL, - choiceSetBusy, - choiceShow, - choiceSetPos }; + mswRepaintLabel, + NULL, + NULL, + choiceSetBusy, + choiceShow, + choiceSetPos +}; static callBacks_t choiceItemCallBacks = { - NULL, - NULL, - choiceItemProc }; + NULL, + NULL, + choiceItemProc +}; /** - * Creates choice buttons. This function is used to create a group of + * Creates choice buttons. This function is used to create a group of * radio buttons and checkboxes. * * \param type IN type of button @@ -254,17 +262,17 @@ static callBacks_t choiceItemCallBacks = { */ static wChoice_p choiceCreate( - wType_e type, - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - const char * const * labels, - long *valueP, - wChoiceCallBack_p action, - void *data ) + wType_e type, + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + const char * const * labels, + long *valueP, + wChoiceCallBack_p action, + void *data ) { wChoice_p b; const char * const * lp; @@ -289,17 +297,17 @@ static wChoice_p choiceCreate( b->action = action; b->labels = labels; b->labelY += 6; - + ppx = b->x; ppy = b->y; switch (b->type) { case B_TOGGLE: - bs = BS_CHECKBOX; - break; + bs = BS_CHECKBOX; + break; case B_RADIO: - bs = BS_RADIOBUTTON; - break; + bs = BS_RADIOBUTTON; + break; } for (lp = b->labels,cnt=0; *lp; lp++,cnt++ ); butts = (wChoiceItem_p*)malloc( (cnt+1) * sizeof *butts ); @@ -307,58 +315,60 @@ static wChoice_p choiceCreate( b->oldVal = (b->valueP?*b->valueP:0); ph = pw = 2; maxW = 0; - if (helpStr) + if (helpStr) { helpStrCopy = mswStrdup( helpStr ); - for (lp = b->labels, cnt=0; *lp; lp++, cnt++, butts++ ) { - *butts = (wChoiceItem_p)mswAlloc( parent, B_CHOICEITEM, - mswStrdup(_((char *)*lp)), sizeof( wChoiceItem_t ), data, &index ); - (*butts)->owner = b; - (*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)(UINT_PTR)index, mswHInst, NULL ); - if ( hButt == (HWND)0 ) { - mswFail( "choiceCreate button" ); - return b; - } - (*butts)->x = b->x+pw; - (*butts)->y = b->y+ph; - if (b->hWnd == 0) - b->hWnd = (*butts)->hWnd; - (*butts)->helpStr = helpStrCopy; - - hDc = GetDC( hButt ); - lab_l = strlen((*butts)->labelStr); - - if (!mswThickFont) {hFont = SelectObject( hDc, mswLabelFont );} - dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), (UINT)lab_l ); - if (!mswThickFont) {SelectObject( hDc, hFont );} - - w = LOWORD(dw) + CHOICE_MIN_WIDTH; - - if (w > maxW) - maxW = w; - SetBkMode( hDc, TRANSPARENT ); - ReleaseDC( hButt, hDc ); - if (b->option & BC_HORZ) { - pw += w; - } else { - ph += CHOICE_HEIGHT; - } - if (!SetWindowPos( hButt, HWND_TOP, 0, 0, - w, CHOICE_HEIGHT, SWP_NOMOVE|SWP_NOZORDER)) { - mswFail("Create CHOICE: SetWindowPos"); - } - mswChainFocus( (wControl_p)*butts ); - newChoiceItemProc = MakeProcInstance( (XWNDPROC)pushChoiceItem, mswHInst ); - oldChoiceItemProc = (XWNDPROC)GetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC); - SetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC, (LPARAM)newChoiceItemProc); + } + for (lp = b->labels, cnt=0; *lp; lp++, cnt++, butts++ ) { + *butts = (wChoiceItem_p)mswAlloc( parent, B_CHOICEITEM, + mswStrdup(_((char *)*lp)), sizeof( wChoiceItem_t ), data, &index ); + (*butts)->owner = b; + (*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)(UINT_PTR)index, mswHInst, NULL ); + if ( hButt == (HWND)0 ) { + mswFail( "choiceCreate button" ); + return b; + } + (*butts)->x = b->x+pw; + (*butts)->y = b->y+ph; + if (b->hWnd == 0) { + b->hWnd = (*butts)->hWnd; + } + (*butts)->helpStr = helpStrCopy; + + hDc = GetDC( hButt ); + lab_l = strlen((*butts)->labelStr); + + hFont = SelectObject( hDc, mswLabelFont ); + dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), (UINT)lab_l ); + SelectObject( hDc, hFont ); + + w = LOWORD(dw) + CHOICE_MIN_WIDTH; + + if (w > maxW) { + maxW = w; + } + SetBkMode( hDc, TRANSPARENT ); + ReleaseDC( hButt, hDc ); + if (b->option & BC_HORZ) { + pw += w; + } else { + ph += CHOICE_HEIGHT; + } + if (!SetWindowPos( hButt, HWND_TOP, 0, 0, + w, CHOICE_HEIGHT, SWP_NOMOVE|SWP_NOZORDER)) { + mswFail("Create CHOICE: SetWindowPos"); + } + mswChainFocus( (wControl_p)*butts ); + newChoiceItemProc = MakeProcInstance( (XWNDPROC)pushChoiceItem, mswHInst ); + 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); + oldChoiceItemProc = (XWNDPROC)GetWindowLong((*butts)->hWnd, GWL_WNDPROC); + SetWindowLong((*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc); #endif - if ( !mswThickFont ) - SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); + SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); } *butts = NULL; switch (b->type) { @@ -376,13 +386,13 @@ static wChoice_p choiceCreate( } pw += 4; ph += 4; b->w = pw; - b->h = ph; + b->h = ph; #define FRAME_STYLE SS_ETCHEDFRAME if ((b->option & BC_NOBORDER)==0) { b->hBorder = CreateWindow( "STATIC", NULL, WS_CHILD | WS_VISIBLE | FRAME_STYLE, - b->x, b->y, pw, ph, ((wControl_p)parent)->hWnd, 0, mswHInst, NULL ); + b->x, b->y, pw, ph, ((wControl_p)parent)->hWnd, 0, mswHInst, NULL ); } mswAddButton( (wControl_p)b, TRUE, helpStr ); mswCallBacks[ B_CHOICEITEM ] = &choiceItemCallBacks; @@ -392,33 +402,33 @@ static wChoice_p choiceCreate( wChoice_p wRadioCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - const char * const *labels, - long *valueP, - wChoiceCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + const char * const *labels, + long *valueP, + wChoiceCallBack_p action, + void *data ) { return choiceCreate( B_RADIO, parent, x, y, helpStr, labelStr, - option, labels, valueP, action, data ); + option, labels, valueP, action, data ); } wChoice_p wToggleCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - const char * const *labels, - long *valueP, - wChoiceCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + const char * const *labels, + long *valueP, + wChoiceCallBack_p action, + void *data ) { return choiceCreate( B_TOGGLE, parent, x, y, helpStr, labelStr, - option, labels, valueP, action, data ); + option, labels, valueP, action, data ); } diff --git a/app/wlib/mswlib/mswcolor.c b/app/wlib/mswlib/mswcolor.c index fb9b0ba..f28e298 100644 --- a/app/wlib/mswlib/mswcolor.c +++ b/app/wlib/mswlib/mswcolor.c @@ -4,7 +4,6 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -34,16 +33,17 @@ static void mswGetCustomColors( void ); static struct { - WORD palVersion; - WORD palNumEntries; - PALETTEENTRY palPalEntry[NUM_COLORS]; - } colorPalette = { - 0x300, - 2, - { + WORD palVersion; + WORD palNumEntries; + PALETTEENTRY palPalEntry[NUM_COLORS]; +} colorPalette = { + 0x300, + 2, + { { 255, 255, 255 }, /* White */ { 0, 0, 0 } /* Black */ - } }; + } +}; static long flipRGB( long rgb ) @@ -68,8 +68,10 @@ static void getpalette( void ) cnt = GetDeviceCaps(hdc, SIZEPALETTE); GetSystemPaletteEntries( hdc, 0, cnt, pe ); f = fopen( "palette.txt", "w" ); - for (inx=0;inx<cnt;inx++) - fprintf(f, "%d [ %d %d %d %d ]\n", inx, pe[inx].peRed, pe[inx].peGreen, pe[inx].peBlue, pe[inx].peFlags ); + for (inx=0; inx<cnt; inx++) { + fprintf(f, "%d [ %d %d %d %d ]\n", inx, pe[inx].peRed, pe[inx].peGreen, + pe[inx].peBlue, pe[inx].peFlags ); + } fclose(f); ReleaseDC( mswHWnd, hdc ); } @@ -91,8 +93,9 @@ static int findColor( int r0, int g0, int b0 ) b1 = pal[c].peBlue; g1 = pal[c].peGreen; d1 = abs(r0-r1) + abs(g0-g1) + abs(b0-b1); - if (d1 == 0) + if (d1 == 0) { return c; + } if (d1 < d0) { d0 = d1; cc = c; @@ -104,7 +107,8 @@ static int findColor( int r0, int g0, int b0 ) pal[colorPalette.palNumEntries].peBlue = b0; if ( mswPalette ) { ResizePalette( mswPalette, colorPalette.palNumEntries+1 ); - SetPaletteEntries( mswPalette, colorPalette.palNumEntries, 1, &pal[colorPalette.palNumEntries] ); + SetPaletteEntries( mswPalette, colorPalette.palNumEntries, 1, + &pal[colorPalette.palNumEntries] ); } return colorPalette.palNumEntries++; } @@ -130,8 +134,9 @@ void mswInitColorPalette( void ) PALETTEENTRY palPalEntry[256]; } pe; - if (initted) + if (initted) { return; + } initted = TRUE; mswGetCustomColors(); @@ -158,7 +163,7 @@ HPALETTE mswCreatePalette( void ) int mswGetColorList( RGBQUAD * colors ) { int i; - for (i=0;i<(int)colorPalette.palNumEntries;i++) { + for (i=0; i<(int)colorPalette.palNumEntries; i++) { colors[i].rgbBlue = colorPalette.palPalEntry[i].peBlue; colors[i].rgbGreen = colorPalette.palPalEntry[i].peGreen; colors[i].rgbRed = colorPalette.palPalEntry[i].peRed; @@ -170,37 +175,41 @@ int mswGetColorList( RGBQUAD * colors ) COLORREF mswGetColor( wBool_t hasPalette, wDrawColor color ) { - if ( hasPalette ) + if ( hasPalette ) { return PALETTEINDEX(color); - else - return RGB( colorPalette.palPalEntry[color].peRed, colorPalette.palPalEntry[color].peGreen, colorPalette.palPalEntry[color].peBlue ); + } else { + return RGB( colorPalette.palPalEntry[color].peRed, + colorPalette.palPalEntry[color].peGreen, + colorPalette.palPalEntry[color].peBlue ); + } } wDrawColor wDrawColorGray( - int percent ) + int percent ) { int n; n = (percent * NUM_GRAYS) / 100; - if ( n <= 0 ) + if ( n <= 0 ) { return wDrawColorBlack; - else if ( n > NUM_GRAYS ) + } else if ( n > NUM_GRAYS ) { return wDrawColorWhite; - else { + } else { n = (n*256)/NUM_GRAYS; return wDrawFindColor( wRGB(n,n,n) ); } } wDrawColor wDrawFindColor( - long rgb0 ) + long rgb0 ) { static long saved_rgb = wRGB(255,255,255); static wDrawColor saved_color = 0; int r0, g0, b0; - if (rgb0 == saved_rgb) + if (rgb0 == saved_rgb) { return saved_color; + } r0 = (int)(rgb0>>16)&0xFF; g0 = (int)(rgb0>>8)&0xFF; b0 = (int)(rgb0)&0xFF; @@ -210,7 +219,7 @@ wDrawColor wDrawFindColor( long wDrawGetRGB( - wDrawColor color ) + wDrawColor color ) { long rgb; int r, g, b; @@ -259,8 +268,8 @@ void mswPutCustomColors( void ) wBool_t wColorSelect( - const char * title, - wDrawColor * color ) + const char * title, + wDrawColor * color ) { long rgb; @@ -285,18 +294,18 @@ wBool_t wColorSelect( typedef struct { - wDrawColor * valueP; - wColorSelectButtonCallBack_p action; - const char * labelStr; - void * data; - wDrawColor color; - wButton_p button; - wIcon_p bm; - } colorData_t; + wDrawColor * valueP; + wColorSelectButtonCallBack_p action; + const char * labelStr; + void * data; + wDrawColor color; + wButton_p button; + wIcon_p bm; +} colorData_t; static void doColorButton( - void * data ) + void * data ) { colorData_t * cd = (colorData_t*)data; wDrawColor newColor; @@ -305,30 +314,33 @@ static void doColorButton( if (wColorSelect( cd->labelStr, &newColor )) { cd->color = newColor; wColorSelectButtonSetColor( cd->button, newColor ); - if (cd->valueP) + if (cd->valueP) { *cd->valueP = newColor; - if (cd->action) + } + if (cd->action) { cd->action( cd->data, newColor ); + } } } wButton_p wColorSelectButtonCreate( - wWin_p win, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - wDrawColor * color, - wColorSelectButtonCallBack_p action, - void * data ) + wWin_p win, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + wDrawColor * color, + wColorSelectButtonCallBack_p action, + void * data ) { wButton_p bb; wIcon_p bm; colorData_t * cd; - bm = wIconCreateBitMap( square10_width, square10_height, square10_bits, (color?*color:0) ); + bm = wIconCreateBitMap( square10_width, square10_height, square10_bits, + (color?*color:0) ); cd = malloc( sizeof *cd ); cd->valueP = color; cd->action = action; @@ -336,17 +348,19 @@ wButton_p wColorSelectButtonCreate( cd->labelStr = labelStr; cd->color = (color?*color:0); cd->bm = bm; - bb = wButtonCreate( win, x, y, helpStr, (char*)bm, option|BO_ICON, width, doColorButton, cd ); + bb = wButtonCreate( win, x, y, helpStr, (char*)bm, option|BO_ICON, width, + doColorButton, cd ); cd->button = bb; - if ( labelStr ) - wControlSetLabel( (wControl_p)bb, labelStr ); + if ( labelStr ) { + wControlSetLabel( (wControl_p)bb, labelStr ); + } return bb; } void wColorSelectButtonSetColor( - wButton_p bb, - wDrawColor color ) + wButton_p bb, + wDrawColor color ) { ((colorData_t*)((wControl_p)bb)->data)->color = color; wIconSetColor( ((colorData_t*)((wControl_p)bb)->data)->bm, color ); @@ -355,7 +369,7 @@ void wColorSelectButtonSetColor( wDrawColor wColorSelectButtonGetColor( - wButton_p bb ) + wButton_p bb ) { return ((colorData_t*)((wControl_p)bb)->data)->color; } diff --git a/app/wlib/mswlib/mswdraw.c b/app/wlib/mswlib/mswdraw.c index be5bcd6..7ab38ac 100644 --- a/app/wlib/mswlib/mswdraw.c +++ b/app/wlib/mswlib/mswdraw.c @@ -17,13 +17,12 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #define _WIN32_WINNT 0x0600 /* for wheel mouse supposrt */ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -113,20 +112,15 @@ static wWinPix_t YDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t y ) -/** @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( - wDraw_p d, - wBool_t delay ) + wDraw_p d, + wBool_t delay ) { } wBool_t wDrawSetTempMode( - wDraw_p bd, - wBool_t bTemp ) + wDraw_p bd, + wBool_t bTemp ) { wBool_t rc = bd->bTempMode; bd->bTempMode = bTemp; @@ -134,14 +128,14 @@ wBool_t wDrawSetTempMode( // Main to Temp drawing // Copy mainBM to tempBM wDrawClearTemp( bd ); - if (bDrawMainBM) return rc; + if (bDrawMainBM) { return rc; } HDC hDcOld = CreateCompatibleDC(bd->hDc); HBITMAP hBmOld = SelectObject(hDcOld, bd->hBmMain); SelectObject(bd->hDc, bd->hBmTemp); BitBlt(bd->hDc, 0, 0, - bd->w, bd->h, - hDcOld, 0, 0, - SRCCOPY); + bd->w, bd->h, + hDcOld, 0, 0, + SRCCOPY); SelectObject(hDcOld, hBmOld); DeleteDC(hDcOld); bd->bCopiedMain = TRUE; @@ -151,21 +145,20 @@ wBool_t wDrawSetTempMode( /** * Sets the proper pen and composition for the next drawing operation - * * - * \param hDc IN device context - * \param d IN ??? + * + * \param d IN drawing context * \param dw IN line width * \param lt IN line type (dashed, solid, ...) * \param dc IN color - * \param dopt IN ???? + * \param dopt IN drawing options */ static void setDrawMode( - wDraw_p d, - wDrawWidth dw, - wDrawLineType_e lt, - wDrawColor dc, - wDrawOpts dopt ) + wDraw_p d, + wDrawWidth dw, + wDrawLineType_e lt, + wDrawColor dc, + wDrawOpts dopt ) { long centerPen[] = {40,10,20,10}; long phantomPen[] = {40,10,20,10,20,10}; @@ -178,10 +171,11 @@ static void setDrawMode( static LOGBRUSH logBrush = { 0, 0, 0 }; DWORD penStyle; - if ( wDrawDoTempDraw && (dopt & wDrawOptTemp) ) + if ( wDrawDoTempDraw && (dopt & wDrawOptTemp) ) { SelectObject(d->hDc, d->hBmTemp); - else + } else { SelectObject(d->hDc, d->hBmMain); + } if ( d->hasPalette ) { int winPaletteClock = mswGetPaletteClock(); @@ -192,12 +186,14 @@ static void setDrawMode( } SetROP2( d->hDc, R2_COPYPEN ); - if ( d == d0 && dw0 == dw && lt == lt0 && dc == dc0 ) + if ( d == d0 && dw0 == dw && lt == lt0 && dc == dc0 ) { return; + } // make sure that the line width is at least 1! - if( !dw ) + if( !dw ) { dw++; + } d0 = d; dw0 = dw; lt0 = lt; dc0 = dc; @@ -206,16 +202,14 @@ static void setDrawMode( logBrush.lbColor = mswGetColor(d->hasPalette,dc); if ( lt==wDrawLineSolid ) { - penStyle = PS_GEOMETRIC | PS_SOLID; - if ( noFlatEndCaps == FALSE ) - penStyle |= PS_ENDCAP_FLAT; + penStyle = PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT; } else if (lt == wDrawLineDot) { penStyle = PS_GEOMETRIC | PS_DOT; } else if (lt == wDrawLineDash) { penStyle = PS_GEOMETRIC | PS_DASH; } else if (lt == wDrawLineDashDot) { penStyle = PS_GEOMETRIC | PS_DASHDOT; - } else if ( lt == wDrawLineDashDotDot){ + } else if ( lt == wDrawLineDashDotDot) { penStyle = PS_GEOMETRIC | PS_DASHDOTDOT; } else if ( lt == wDrawLineCenter) { penStyle = PS_GEOMETRIC | PS_USERSTYLE; @@ -225,47 +219,49 @@ static void setDrawMode( penStyle = PS_GEOMETRIC | PS_USERSTYLE; penarray = &phantomPen; penarray_size = sizeof(phantomPen) / sizeof(long); - } else + } else { penStyle = PS_GEOMETRIC | PS_SOLID; + } d->hPen = ExtCreatePen( penStyle, - dw, - &logBrush, - penarray_size, - penarray ); + dw, + &logBrush, + penarray_size, + penarray ); hOldPen = SelectObject( d->hDc, d->hPen ); DeleteObject( hOldPen ); } static void setDrawBrush( - wDraw_p d, - wDrawColor dc, - wDrawOpts dopt ) + wDraw_p d, + wDrawColor dc, + wDrawOpts dopt ) { HBRUSH hOldBrush; static wDraw_p d0; static wDrawColor dc0 = -1; setDrawMode( d, 0, wDrawLineSolid, dc, dopt ); - if ( d == d0 && dc == dc0 ) + if ( d == d0 && dc == dc0 ) { return; + } d0 = d; dc0 = dc; - d->hBrush = CreateSolidBrush( - mswGetColor(d->hasPalette,dc) ); + d->hBrush = CreateSolidBrush( + mswGetColor(d->hasPalette,dc) ); hOldBrush = SelectObject( d->hDc, d->hBrush ); DeleteObject( hOldBrush ); } static void myInvalidateRect( - wDraw_p d, - RECT * prect ) + wDraw_p d, + RECT * prect ) { - if ( prect->top < 0 ) prect->top = 0; - if ( prect->left < 0 ) prect->left = 0; - if ( prect->bottom > d->h ) prect->bottom = d->h; - if ( prect->right > d->w ) prect->right = d->w; + if ( prect->top < 0 ) { prect->top = 0; } + if ( prect->left < 0 ) { prect->left = 0; } + if ( prect->bottom > d->h ) { prect->bottom = d->h; } + if ( prect->right > d->w ) { prect->right = d->w; } InvalidateRect( d->hWnd, prect, FALSE ); } @@ -274,8 +270,8 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d ) { long int x0=p0->x, y0=p0->y, x1=p1->x, y1=p1->y; long int dx, dy; - if ( x0<0 && x1<0 ) return 0; - if ( y0<0 && y1<0 ) return 0; + if ( x0<0 && x1<0 ) { return 0; } + if ( y0<0 && y1<0 ) { return 0; } dx=x1-x0; dy=y1-y0; if ( x0 < 0 ) { @@ -283,7 +279,7 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d ) x0 = 0; } if ( y0 < 0 ) { - if ( (x0 -= y0*dx/dy) < 0 ) return 0; + if ( (x0 -= y0*dx/dy) < 0 ) { return 0; } y0 = 0; } if ( x1 < 0 ) { @@ -291,7 +287,7 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d ) x1 = 0; } if ( y1 < 0 ) { - if ( (x1 -= y1*dx/dy) < 0 ) return 0; + if ( (x1 -= y1*dx/dy) < 0 ) { return 0; } y1 = 0; } p0->x = (int)x0; @@ -303,15 +299,15 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d ) void wDrawLine( - wDraw_p d, - wDrawPix_t p0x, - wDrawPix_t p0y, - wDrawPix_t p1x, - wDrawPix_t p1y, - wDrawWidth dw, - wDrawLineType_e lt, - wDrawColor dc, - wDrawOpts dopt ) + wDraw_p d, + wDrawPix_t p0x, + wDrawPix_t p0y, + wDrawPix_t p1x, + wDrawPix_t p1y, + wDrawWidth dw, + wDrawLineType_e lt, + wDrawColor dc, + wDrawOpts dopt ) { POINT p0, p1; RECT rect; @@ -320,29 +316,29 @@ void wDrawLine( 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 ); LineTo( d->hDc, p1.x, p1.y ); if (d->hWnd) { - if (dw==0) + if (dw==0) { dw = 1; + } dw++; - if (p0.y<p1.y) { - rect.top = p0.y-dw; - rect.bottom = p1.y+dw; - } else { - rect.top = p1.y-dw; - rect.bottom = p0.y+dw; - } - if (p0.x<p1.x) { - rect.left = p0.x-dw; - rect.right = p1.x+dw; - } else { - rect.left = p1.x-dw; - rect.right = p0.x+dw; - } - myInvalidateRect( d, &rect ); + if (p0.y<p1.y) { + rect.top = p0.y-dw; + rect.bottom = p1.y+dw; + } else { + rect.top = p1.y-dw; + rect.bottom = p0.y+dw; + } + if (p0.x<p1.x) { + rect.left = p0.x-dw; + rect.right = p1.x+dw; + } else { + rect.left = p1.x-dw; + rect.right = p0.x+dw; + } + myInvalidateRect( d, &rect ); } } @@ -354,16 +350,16 @@ static double d2r(double angle) static double mswsin( double angle ) { - while (angle < 0.0) angle += 360.0; - while (angle >= 360.0) angle -= 360.0; + while (angle < 0.0) { angle += 360.0; } + while (angle >= 360.0) { angle -= 360.0; } angle *= (M_PI*2.0)/360.0; return sin( angle ); } static double mswcos( double angle ) { - while (angle < 0.0) angle += 360.0; - while (angle >= 360.0) angle -= 360.0; + while (angle < 0.0) { angle += 360.0; } + while (angle >= 360.0) { angle -= 360.0; } angle *= (M_PI*2.0)/360.0; return cos( angle ); } @@ -376,6 +372,13 @@ static double mswasin( double x, double h ) return angle; } +static double mswNormalizeAngle( double a ) +{ + while (a<0.0) { a += 360.0; } + while (a>=360.0) { a -= 360.0; } + return a; +} + /** * Draw an arc around a specified center * @@ -392,26 +395,30 @@ static double mswasin( double x, double h ) void wDrawArc( - wDraw_p d, - wDrawPix_t px, - wDrawPix_t py, - wDrawPix_t r, - double a0, - double a1, - int sizeCenter, - wDrawWidth dw, - wDrawLineType_e lt, - wDrawColor dc, - wDrawOpts dopt ) + wDraw_p d, + wDrawPix_t px, + wDrawPix_t py, + wDrawPix_t r, + double a0, + double a1, + int sizeCenter, + wDrawWidth dw, + wDrawLineType_e lt, + wDrawColor dc, + wDrawOpts dopt ) { int i, cnt; POINT p0, p1, ps, pe, pp0, pp1, pp2, pc; wDrawPix_t psx, psy, pex, pey; - double len, aa, ai; + double aa, ai; RECT rect; int needMoveTo; wBool_t fakeArc = FALSE; + // calculate the center coordinates + pc.x = XDRAWPIX2WINPIX( d, px ); + pc.y = YDRAWPIX2WINPIX( d, py ); + p0.x = XDRAWPIX2WINPIX(d,px-r); p0.y = YDRAWPIX2WINPIX(d,py+r); p1.x = XDRAWPIX2WINPIX(d,px+r); @@ -431,30 +438,30 @@ void wDrawArc( setDrawMode( d, dw, lt, dc, dopt ); - if (dw == 0) + if (dw == 0) { dw = 1; + } - /* Windows drawing will overshoot the end of the arc for large radius */ - if (r > 500) { + if ( r > 30000 || a1 < 1.0 ) { /* The book says 32K but experience says otherwise */ fakeArc = TRUE; } - if ( noNegDrawArgs > 0 ) { - if ( p0.x < 0 || p0.y < 0 || p1.x < 0 || p1.y < 0 ) - fakeArc = TRUE; - } + + // Starting point + psx = px + r * mswsin(a0); + psy = py + r * mswcos(a0); + pp0.x = XDRAWPIX2WINPIX( d, psx ); + pp0.y = YDRAWPIX2WINPIX( d, psy ); + if ( fakeArc ) { cnt = (int)(a1 / 2); - if ( cnt <= 0 ) cnt = 1; - if ( cnt > 180 ) cnt = 180; - // Convert a0 and a1 to radians here + if ( cnt <= 0 ) { cnt = 1; } + if ( cnt > 180 ) { cnt = 180; } + 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++ ) { aa += ai; psx = px + r * sin(aa); @@ -473,53 +480,68 @@ void wDrawArc( pp0.x = pp2.x; pp0.y = pp2.y; } } else { - if ( a0 == 0.0 && a1 == 360.0 ) { - 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 ); + DWORD rr = XDRAWPIX2WINPIX( d, r ); + SetArcDirection( d->hDc,AD_CLOCKWISE ); + + // Draw two arcs from the center to eliminate the odd pie-shaped end artifact + if ( dw > 2.0 ) { + double a2 = a1 / 2.0; + pp2.x = XDRAWPIX2WINPIX( d, px + r * mswsin(a0+a2) ); + pp2.y = YDRAWPIX2WINPIX( d, py + r * mswcos(a0+a2) ); + + MoveTo( d->hDc, pp2.x, pp2.y ); + AngleArc( d->hDc, pc.x, pc.y, rr, (float)mswNormalizeAngle(90 - (a0+a2)), + (float)(-a2) ); + MoveTo( d->hDc, pp2.x, pp2.y ); + AngleArc( d->hDc, pc.x, pc.y, rr, (float)mswNormalizeAngle(90 - (a0+a2)), + (float)(a2) ); } else { - Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, ps.y, pe.x, pe.y ); + MoveTo( d->hDc, pp0.x, pp0.y ); + AngleArc( d->hDc, pc.x, pc.y, rr, (float)mswNormalizeAngle(90 - a0), + (float)(-a1) ); } } // should the center of the arc be drawn? if( sizeCenter ) { - - // calculate the center coordinates - pc.x = XDRAWPIX2WINPIX( d, px ); - pc.y = YDRAWPIX2WINPIX( d, py ); - // now draw the crosshair - 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*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 ); + + // now draw the crosshair + 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*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 ); } if (d->hWnd) { dw++; a1 += a0; - if (a1>360.0) + if (a1>360.0) { rect.top = p0.y; - else + } else { rect.top = min(pe.y,ps.y); - if (a1>(a0>180?360.0:0.0)+180) + } + if (a1>(a0>180?360.0:0.0)+180) { rect.bottom = p1.y; - else + } else { rect.bottom = max(pe.y,ps.y); - if (a1>(a0>270?360.0:0.0)+270) + } + if (a1>(a0>270?360.0:0.0)+270) { rect.left = p0.x; - else + } else { rect.left = min(pe.x,ps.x); - if (a1>(a0>90?360.0:0.0)+90) + } + if (a1>(a0>90?360.0:0.0)+90) { rect.right = p1.x; - else + } else { rect.right = max(pe.x,ps.x); + } rect.top -= dw; rect.bottom += dw; rect.left -= dw; @@ -530,11 +552,11 @@ void wDrawArc( } void wDrawPoint( - wDraw_p d, - wDrawPix_t px, - wDrawPix_t py, - wDrawColor dc, - wDrawOpts dopt ) + wDraw_p d, + wDrawPix_t px, + wDrawPix_t py, + wDrawColor dc, + wDrawOpts dopt ) { POINT p0; RECT rect; @@ -542,13 +564,16 @@ void wDrawPoint( p0.x = XDRAWPIX2WINPIX(d,px); p0.y = YDRAWPIX2WINPIX(d,py); - if ( p0.x < 0 || p0.y < 0 ) + if ( p0.x < 0 || p0.y < 0 ) { return; - if ( p0.x >= d->w || p0.y >= d->h ) + } + if ( p0.x >= d->w || p0.y >= d->h ) { return; + } setDrawMode( d, 0, wDrawLineSolid, dc, dopt ); - SetPixel( d->hDc, p0.x, p0.y, mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/ ); + SetPixel( d->hDc, p0.x, p0.y, mswGetColor(d->hasPalette, + dc) /*colorPalette.palPalEntry[dc]*/ ); if (d->hWnd) { rect.top = p0.y-1; rect.bottom = p0.y+1; @@ -568,126 +593,141 @@ void wDrawPoint( static LOGFONT logFont = { - /* Initial default values */ - -24, 0, /* H, W */ - 0, /* A */ - 0, - FW_REGULAR, - 0, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Arial" }; + /* Initial default values */ + -24, 0, /* H, W */ + 0, /* A */ + 0, + FW_REGULAR, + 0, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Arial" + }; static LOGFONT timesFont[2][2] = { - { { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_REGULAR, - 0, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Times" }, + { { + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_REGULAR, + 0, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Times" + }, { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_REGULAR, - 1, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Times" } }, - { { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_BOLD, - 0, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Times" }, + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_REGULAR, + 1, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Times" + } + }, + { { + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_BOLD, + 0, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Times" + }, { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_BOLD, - 1, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Times" } } }; + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_BOLD, + 1, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Times" + } + } +}; static LOGFONT helvFont[2][2] = { - { { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_REGULAR, - 0, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Arial" }, + { { + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_REGULAR, + 0, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Arial" + }, { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_REGULAR, - 1, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Arial" } }, - { { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_BOLD, - 0, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Arial" }, + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_REGULAR, + 1, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Arial" + } + }, + { { + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_BOLD, + 0, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Arial" + }, { - /* Initial default values */ - 0, 0, /* H, W */ - 0, /* A */ - 0, - FW_BOLD, - 1, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - 0, /* P&F */ - "Hevletica" } } }; + /* Initial default values */ + 0, 0, /* H, W */ + 0, /* A */ + 0, + FW_BOLD, + 1, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + 0, /* P&F */ + "Hevletica" + } + } +}; void mswFontInit( void ) @@ -721,8 +761,9 @@ static void doChooseFont( void ) rc = ChooseFont( &chooseFont ); if (rc) { fontSize = (wFontSize_t)(-logFont.lfHeight * 72) / 96.0 / fontFactor; - if (fontSize < 1) + if (fontSize < 1) { fontSize = 1; + } wPrefSetString( "msw window font", "face", logFont.lfFaceName ); wPrefSetInteger( "msw window font", "size", logFont.lfHeight ); } @@ -733,20 +774,21 @@ static int computeFontSize( wDraw_p d, double siz ) int ret; siz = (siz * d->DPI) / 72.0; ret = (int)(siz * fontFactor); - if (ret < 1) + if (ret < 1) { ret = 1; + } return -ret; } void wDrawGetTextSize( - wDrawPix_t *w, - wDrawPix_t *h, - wDrawPix_t *d, - wDrawPix_t *a, - wDraw_p bd, - const char * text, - wFont_p fp, - double siz ) + wDrawPix_t *w, + wDrawPix_t *h, + wDrawPix_t *d, + wDrawPix_t *a, + wDraw_p bd, + const char * text, + wFont_p fp, + double siz ) { wWinPix_t x, y; HFONT newFont, prevFont; @@ -754,8 +796,9 @@ void wDrawGetTextSize( int oldLfHeight; TEXTMETRIC textMetric; - if (fp == NULL) + if (fp == NULL) { fp = &logFont; + } fp->lfEscapement = 0; oldLfHeight = fp->lfHeight; fp->lfHeight = computeFontSize( bd, siz ); @@ -779,7 +822,7 @@ void wDrawGetTextSize( } /** * Draw text - * + * * \param d device context * \param px position x * \param py position y @@ -791,80 +834,74 @@ void wDrawGetTextSize( * \param dopts drawing options */ void wDrawString( - wDraw_p d, - wDrawPix_t px, - wDrawPix_t py, - double angle, - const char * text, - wFont_p fp, - double siz, - wDrawColor dc, - wDrawOpts dopts) + wDraw_p d, + wDrawPix_t px, + wDrawPix_t py, + double angle, + const char * text, + wFont_p fp, + double siz, + wDrawColor dc, + wDrawOpts dopts) { - int x, y; - HFONT newFont, prevFont; - DWORD extent; - int w, h; - RECT rect; - int oldLfHeight; - - if (fp == NULL) { - fp = &logFont; - } - - oldLfHeight = fp->lfHeight; - fp->lfEscapement = (int)(angle*10.0); - fp->lfHeight = computeFontSize(d, siz); - fp->lfWidth = 0; - newFont = CreateFontIndirect(fp); - 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); - return; - } - - setDrawMode( d, 0, wDrawLineSolid, dc, dopts ); - prevFont = SelectObject(d->hDc, newFont); - SetBkMode(d->hDc, TRANSPARENT); - - if (dopts & wDrawOutlineFont) { - HPEN oldPen; - BeginPath(d->hDc); - TextOut(d->hDc, x, y, text, (int)strlen(text)); - EndPath(d->hDc); - - // Now draw outline text - oldPen = SelectObject(d->hDc, - CreatePen(PS_SOLID, 1, - mswGetColor(d->hasPalette, dc))); - StrokePath(d->hDc); - SelectObject(d->hDc, oldPen); - } else { - COLORREF old; - - old = SetTextColor(d->hDc, mswGetColor(d->hasPalette, - dc)); - TextOut(d->hDc, x, y, text, (int)(strlen(text))); - SetTextColor(d->hDc, old); - } - - extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text))); - SelectObject(d->hDc, prevFont); - w = LOWORD(extent); - h = HIWORD(extent); - - if (d->hWnd) { - rect.top = y - (w + h + 1); - rect.bottom = y + (w + h + 1); - rect.left = x - (w + h + 1); - rect.right = x + (w + h + 1); - myInvalidateRect(d, &rect); - } - - DeleteObject(newFont); - fp->lfHeight = oldLfHeight; + int x, y; + HFONT newFont, prevFont; + DWORD extent; + int w, h; + RECT rect; + int oldLfHeight; + + if (fp == NULL) { + fp = &logFont; + } + + oldLfHeight = fp->lfHeight; + fp->lfEscapement = (int)(angle*10.0); + fp->lfHeight = computeFontSize(d, siz); + fp->lfWidth = 0; + newFont = CreateFontIndirect(fp); + x = XDRAWPIX2WINPIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5); + y = YDRAWPIX2WINPIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5); + + setDrawMode( d, 0, wDrawLineSolid, dc, dopts ); + prevFont = SelectObject(d->hDc, newFont); + SetBkMode(d->hDc, TRANSPARENT); + + if (dopts & wDrawOutlineFont) { + HPEN oldPen; + BeginPath(d->hDc); + TextOut(d->hDc, x, y, text, (int)strlen(text)); + EndPath(d->hDc); + + // Now draw outline text + oldPen = SelectObject(d->hDc, + CreatePen(PS_SOLID, 1, + mswGetColor(d->hasPalette, dc))); + StrokePath(d->hDc); + SelectObject(d->hDc, oldPen); + } else { + COLORREF old; + + old = SetTextColor(d->hDc, mswGetColor(d->hasPalette, dc)); + TextOut(d->hDc, x, y, text, (int)(strlen(text))); + SetTextColor(d->hDc, old); + } + + extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text))); + SelectObject(d->hDc, prevFont); + w = LOWORD(extent); + h = HIWORD(extent); + + if (d->hWnd) { + rect.top = y - (w + h + 1); + rect.bottom = y + (w + h + 1); + rect.left = x - (w + h + 1); + rect.right = x + (w + h + 1); + myInvalidateRect(d, &rect); + } + + DeleteObject(newFont); + fp->lfHeight = oldLfHeight; } static const char * wCurFont( void ) @@ -878,12 +915,13 @@ void wInitializeFonts() wFont_p wStandardFont( int family, wBool_t bold, wBool_t italic ) { - if (family == F_TIMES) + if (family == F_TIMES) { return ×Font[bold][italic]; - else if (family == F_HELV) + } else if (family == F_HELV) { return &helvFont[bold][italic]; - else + } else { return NULL; + } } void wSelectFont( const char * title ) @@ -913,23 +951,23 @@ void wSetSelectedFontSize(wFontSize_t size) void wDrawFilledRectangle( - wDraw_p d, - wDrawPix_t px, - wDrawPix_t py, - wDrawPix_t sx, - wDrawPix_t sy, - wDrawColor color, - wDrawOpts opts ) + wDraw_p d, + wDrawPix_t px, + wDrawPix_t py, + wDrawPix_t sx, + wDrawPix_t sy, + wDrawColor color, + wDrawOpts opts ) { int mode; RECT rect; - if (d == NULL) + if (d == NULL) { return; + } setDrawBrush( d, color, opts ); if (opts & wDrawOptTransparent) { mode = R2_NOTXORPEN; - } - else { + } else { mode = R2_COPYPEN; } SetROP2(d->hDc, mode); @@ -938,19 +976,25 @@ void wDrawFilledRectangle( rect.top = YDRAWPIX2WINPIX(d,py+sy); rect.bottom = YDRAWPIX2WINPIX(d,py); if ( rect.right < 0 || - rect.bottom < 0 ) + rect.bottom < 0 ) { return; - if ( rect.left < 0 ) + } + if ( rect.left < 0 ) { rect.left = 0; - if ( rect.top < 0 ) + } + if ( rect.top < 0 ) { rect.top = 0; + } if ( rect.left > d->w || - rect.top > d->h ) + rect.top > d->h ) { return; - if ( rect.right > d->w ) + } + if ( rect.right > d->w ) { rect.right = d->w; - if ( rect.bottom > d->h ) + } + if ( rect.bottom > d->h ) { rect.bottom = d->h; + } Rectangle( d->hDc, rect.left, rect.top, rect.right, rect.bottom ); if (d->hWnd) { rect.top--; @@ -962,7 +1006,7 @@ void wDrawFilledRectangle( } #ifdef DRAWFILLPOLYLOG - static FILE * logF; +static FILE * logF; #endif static dynArr_t wFillPoints_da; @@ -983,34 +1027,34 @@ static dynArr_t wFillType_da; */ static void addPoint( - wDraw_p d, - int pk, - coOrd * pp, - BYTE type, RECT * pr) + wDraw_p d, + int pk, + coOrd * pp, + BYTE type, RECT * pr) { - POINT p; - p.x = XDRAWPIX2WINPIX(d, pp->x); - p.y = YDRAWPIX2WINPIX(d, pp->y); + POINT p; + 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); + fprintf(logF, " q[%d] = {%d,%d}\n", pk, p.x, p.y); #endif - DYNARR_N(POINT, wFillPoints_da, pk) = p; - DYNARR_N(BYTE, wFillType_da, pk) = type; - - if (p.x < pr->left) { - pr->left = p.x; - } - if (p.x > pr->right) { - pr->right = p.x; - } - if (p.y < pr->top) { - pr->top = p.y; - } - if (p.y > pr->bottom) { - pr->bottom = p.y; - } + DYNARR_N(POINT, wFillPoints_da, pk) = p; + DYNARR_N(BYTE, wFillType_da, pk) = type; + + if (p.x < pr->left) { + pr->left = p.x; + } + if (p.x > pr->right) { + pr->right = p.x; + } + if (p.y < pr->top) { + pr->top = p.y; + } + if (p.y > pr->bottom) { + pr->bottom = p.y; + } } /** @@ -1030,208 +1074,190 @@ static void addPoint( */ void wDrawPolygon( - wDraw_p d, - wDrawPix_t node[][2], - wPolyLine_e type[], - wIndex_t cnt, - wDrawColor color, - wDrawWidth dw, - wDrawLineType_e lt, - wDrawOpts opts, - int fill, - int open) + wDraw_p d, + wDrawPix_t node[][2], + wPolyLine_e type[], + wIndex_t cnt, + wDrawColor color, + wDrawWidth dw, + wDrawLineType_e lt, + wDrawOpts opts, + int fill, + int open) { - RECT rect; - int i, prevNode, nextNode; - int pointCount = 0; - coOrd endPoint0, endPoint1, controlPoint0, controlPoint1; - coOrd point, startingPoint; - BOOL rc; - int closed = 0; - - if (d == NULL) { - return; - } - - // make sure the array for the points is large enough - // worst case are rounded corners that require 4 points - DYNARR_RESET(POINT,wFillPoints_da); - DYNARR_SET(POINT,wFillPoints_da,(cnt + 1) * 4); - DYNARR_RESET(BYTE,wFillType_da); - DYNARR_SET(POINT,wFillType_da, (cnt + 1) * 4); - - BeginPath(d->hDc); - - if (fill) { + RECT rect; + int i, prevNode, nextNode; + int pointCount = 0; + coOrd endPoint0, endPoint1, controlPoint0, controlPoint1; + coOrd point, startingPoint; + BOOL rc; + int closed = 0; + + if (d == NULL) { + return; + } + + // make sure the array for the points is large enough + // worst case are rounded corners that require 4 points + DYNARR_RESET(POINT,wFillPoints_da); + DYNARR_SET(POINT,wFillPoints_da,(cnt + 1) * 4); + DYNARR_RESET(BYTE,wFillType_da); + DYNARR_SET(POINT,wFillType_da, (cnt + 1) * 4); + + BeginPath(d->hDc); + + if (fill) { int mode; - setDrawBrush(d, color, opts); + setDrawBrush(d, color, opts); if (opts & wDrawOptTransparent) { mode = R2_NOTXORPEN; - } - else { + } else { mode = R2_COPYPEN; } SetROP2(d->hDc, mode); - } else { - setDrawMode(d, dw, lt, color, opts); - } + } else { + setDrawMode(d, dw, lt, color, opts); + } - rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1); - rect.top = rect.bottom = YDRAWPIX2WINPIX(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"); - fprintf(logF, "\np[%d] = {%d,%d}\n", cnt-1, node[0][0], node[0][1]); + logF = fopen("log.txt", "a"); + fprintf(logF, "\np[%d] = {%d,%d}\n", cnt-1, node[0][0], node[0][1]); #endif - for (i=0; i<cnt; i++) { - wPolyLine_e type1; - point.x = node[i][0]; - point.y = node[i][1]; - if (type != NULL) + for (i=0; i<cnt; i++) { + wPolyLine_e type1; + point.x = node[i][0]; + point.y = node[i][1]; + if (type != NULL) { type1 = type[i]; - else + } else { type1 = wPolyLineStraight; + } - if (type1 == wPolyLineRound || type1 == wPolyLineSmooth) { - prevNode = (i == 0) ? cnt - 1 : i - 1; - nextNode = (i == cnt - 1) ? 0 : i + 1; - - // calculate distance to neighboring nodes - 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]; - endPoint0.y = (prevYDistance/2)+node[prevNode][1]; - endPoint1.x = (nextXDistance/2)+node[i][0]; - endPoint1.y = (nextYDistance/2)+node[i][1]; - - if (type1 == wPolyLineRound) { - double distNext = (nextXDistance*nextXDistance + nextYDistance * nextYDistance); - double distPrev = (prevXDistance*prevXDistance + prevYDistance * prevYDistance); - // but should be half of the shortest line length (equidistant from node) for round - if ((distPrev > 0) && (distNext > 0)) { - double ratio = sqrt(distPrev / distNext); - if (distPrev < distNext) { - endPoint1.x = ((nextXDistance*ratio) / 2) + node[i][0]; - endPoint1.y = ((nextYDistance*ratio) / 2) + node[i][1]; - } else { - endPoint0.x = node[i][0] - (prevXDistance / (2 * ratio)); - endPoint0.y = node[i][1] - (prevYDistance / (2 * ratio)); - } - } - // experience says that the best look is achieved if the - // control points are in the middle between end point and node - controlPoint0.x = (node[i][0] - endPoint0.x) / 2 + endPoint0.x; - controlPoint0.y = (node[i][1] - endPoint0.y) / 2 + endPoint0.y; - - controlPoint1.x = (endPoint1.x - node[i][0]) / 2 + node[i][0]; - controlPoint1.y = (endPoint1.y - node[i][1]) / 2 + node[i][1]; - } else { - controlPoint0 = point; - controlPoint1 = point; - } - } - - if (i==0) { - if (type1 == wPolyLineStraight || open) { - // for straight lines or open shapes use the starting point as passed - addPoint(d, pointCount++, &point, PT_MOVETO, &rect); - startingPoint = point; - } else { - // for Bezier begin with the calculated starting point - addPoint(d, pointCount++, &endPoint0, PT_MOVETO, &rect); - addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect); - addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect); - addPoint(d, pointCount++, &endPoint1, PT_BEZIERTO, &rect); - startingPoint = endPoint0; - } - } else { - if (type1 == wPolyLineStraight || (open && (i==cnt-1))) { - addPoint(d, pointCount++, &point, PT_LINETO, &rect); - } else { - if (i==cnt-1 && !open) { - closed = TRUE; - } - addPoint(d, pointCount++, &endPoint0, PT_LINETO, &rect); - addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect); - addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect); - addPoint(d, pointCount++, &endPoint1, - PT_BEZIERTO | (closed ? PT_CLOSEFIGURE : 0), &rect); - } - } - } - - if (!open && !closed) { - addPoint(d, pointCount++, &startingPoint, PT_LINETO, &rect); - } - rc = PolyDraw(d->hDc, wFillPoints_da.ptr, wFillType_da.ptr, pointCount); - - EndPath(d->hDc); - - if (fill && !open) { - FillPath(d->hDc); - } else { - StrokePath(d->hDc); - } - - if (d->hWnd) { - rect.top--; - rect.left--; - rect.bottom++; - rect.right++; - myInvalidateRect(d, &rect); - } + if (type1 == wPolyLineRound || type1 == wPolyLineSmooth) { + prevNode = (i == 0) ? cnt - 1 : i - 1; + nextNode = (i == cnt - 1) ? 0 : i + 1; + + // calculate distance to neighboring nodes + 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]; + endPoint0.y = (prevYDistance/2)+node[prevNode][1]; + endPoint1.x = (nextXDistance/2)+node[i][0]; + endPoint1.y = (nextYDistance/2)+node[i][1]; + + if (type1 == wPolyLineRound) { + double distNext = (nextXDistance*nextXDistance + nextYDistance * nextYDistance); + double distPrev = (prevXDistance*prevXDistance + prevYDistance * prevYDistance); + // but should be half of the shortest line length (equidistant from node) for round + if ((distPrev > 0) && (distNext > 0)) { + double ratio = sqrt(distPrev / distNext); + if (distPrev < distNext) { + endPoint1.x = ((nextXDistance*ratio) / 2) + node[i][0]; + endPoint1.y = ((nextYDistance*ratio) / 2) + node[i][1]; + } else { + endPoint0.x = node[i][0] - (prevXDistance / (2 * ratio)); + endPoint0.y = node[i][1] - (prevYDistance / (2 * ratio)); + } + } + // experience says that the best look is achieved if the + // control points are in the middle between end point and node + controlPoint0.x = (node[i][0] - endPoint0.x) / 2 + endPoint0.x; + controlPoint0.y = (node[i][1] - endPoint0.y) / 2 + endPoint0.y; + + controlPoint1.x = (endPoint1.x - node[i][0]) / 2 + node[i][0]; + controlPoint1.y = (endPoint1.y - node[i][1]) / 2 + node[i][1]; + } else { + controlPoint0 = point; + controlPoint1 = point; + } + } + + if (i==0) { + if (type1 == wPolyLineStraight || open) { + // for straight lines or open shapes use the starting point as passed + addPoint(d, pointCount++, &point, PT_MOVETO, &rect); + startingPoint = point; + } else { + // for Bezier begin with the calculated starting point + addPoint(d, pointCount++, &endPoint0, PT_MOVETO, &rect); + addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect); + addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect); + addPoint(d, pointCount++, &endPoint1, PT_BEZIERTO, &rect); + startingPoint = endPoint0; + } + } else { + if (type1 == wPolyLineStraight || (open && (i==cnt-1))) { + addPoint(d, pointCount++, &point, PT_LINETO, &rect); + } else { + if (i==cnt-1 && !open) { + closed = TRUE; + } + addPoint(d, pointCount++, &endPoint0, PT_LINETO, &rect); + addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect); + addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect); + addPoint(d, pointCount++, &endPoint1, + PT_BEZIERTO | (closed ? PT_CLOSEFIGURE : 0), &rect); + } + } + } + + if (!open && !closed) { + addPoint(d, pointCount++, &startingPoint, PT_LINETO, &rect); + } + rc = PolyDraw(d->hDc, wFillPoints_da.ptr, wFillType_da.ptr, pointCount); + + EndPath(d->hDc); + + if (fill && !open) { + FillPath(d->hDc); + } else { + StrokePath(d->hDc); + } + + if (d->hWnd) { + rect.top--; + rect.left--; + rect.bottom++; + rect.right++; + myInvalidateRect(d, &rect); + } } #define MAX_FILLCIRCLE_POINTS (30) void wDrawFilledCircle( - wDraw_p d, - wDrawPix_t x, - wDrawPix_t y, - wDrawPix_t r, - wDrawColor color, - wDrawOpts opts ) + wDraw_p d, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t r, + wDrawColor color, + wDrawOpts opts ) { POINT p0, p1; RECT rect; static wDrawPix_t circlePts[MAX_FILLCIRCLE_POINTS][2]; - int inx, cnt; - double dang; 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 = XDRAWPIX2WINPIX(d,r); - else - cnt = 8; - dang = 360.0/cnt; - for ( inx=0; inx<cnt; inx++ ) { - circlePts[inx][0] = x + (int)(r * mswcos( inx*dang ) + 0.5 ); - circlePts[inx][1] = y + (int)(r * mswsin( inx*dang ) + 0.5 ); - } - //wDrawFilledPolygon( d, circlePts, NULL, cnt, color, opts ); - wDrawPolygon(d, circlePts, NULL, cnt, color, 1, wDrawLineSolid,opts, TRUE, FALSE ); - } else { - Ellipse( d->hDc, p0.x, p0.y, p1.x, p1.y ); - if (d->hWnd) { - rect.top = p0.y; - rect.bottom = p1.y; - rect.left = p0.x; - rect.right = p1.x; - myInvalidateRect( d, &rect ); - } + + setDrawBrush( d, color, opts ); + Ellipse( d->hDc, p0.x, p0.y, p1.x, p1.y ); + if (d->hWnd) { + rect.top = p0.y; + rect.bottom = p1.y; + rect.left = p0.x; + rect.right = p1.x; + myInvalidateRect( d, &rect ); } } @@ -1245,22 +1271,23 @@ void wDrawFilledCircle( void wDrawSaveImage( - wDraw_p bd ) + wDraw_p bd ) { - if ( bd->hBmBackup ) { + if ( bd->hBmBackup ) { SelectObject( bd->hDcBackup, bd->hBmBackupOld ); DeleteObject( bd->hBmBackup ); bd->hBmBackup = (HBITMAP)0; } - if ( bd->hDcBackup == (HDC)0 ) - bd->hDcBackup = CreateCompatibleDC( bd->hDc ); + if ( bd->hDcBackup == (HDC)0 ) { + bd->hDcBackup = CreateCompatibleDC( bd->hDc ); + } bd->hBmBackup = CreateCompatibleBitmap( bd->hDc, bd->w, bd->h ); bd->hBmBackupOld = SelectObject( bd->hDcBackup, bd->hBmBackup ); BitBlt( bd->hDcBackup, 0, 0, bd->w, bd->h, bd->hDc, 0, 0, SRCCOPY ); } void wDrawRestoreImage( - wDraw_p bd ) + wDraw_p bd ) { if ( bd->hBmBackup == (HBITMAP)0 ) { mswFail( "wDrawRestoreImage: hBmBackup == 0" ); @@ -1296,14 +1323,14 @@ void wDrawClear( wDraw_p d ) void wDrawSetSize( - wDraw_p d, - wWinPix_t width, - wWinPix_t height, void * redraw) + wDraw_p d, + wWinPix_t width, + wWinPix_t height, void * redraw) { d->w = width; d->h = height; if (!SetWindowPos( d->hWnd, HWND_TOP, 0, 0, - d->w, d->h, SWP_NOMOVE|SWP_NOZORDER)) { + d->w, d->h, SWP_NOMOVE|SWP_NOZORDER)) { mswFail("wDrawSetSize: SetWindowPos"); } /*wRedraw( d );*/ @@ -1311,9 +1338,9 @@ void wDrawSetSize( void wDrawGetSize( - wDraw_p d, - wWinPix_t * width, - wWinPix_t * height ) + wDraw_p d, + wWinPix_t * width, + wWinPix_t * height ) { *width = d->w-2; *height = d->h-2; @@ -1337,11 +1364,11 @@ double wDrawGetMaxRadius( wDraw_p d ) } void wDrawClip( - wDraw_p d, - wDrawPix_t x, - wDrawPix_t y, - wDrawPix_t w, - wDrawPix_t h ) + wDraw_p d, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h ) { wWinPix_t ix0, iy0, ix1, iy1; HRGN hRgnClip; @@ -1359,9 +1386,96 @@ void wDrawClip( void wRedraw( wDraw_p d ) { wDrawClear( d ); - if (d->drawRepaint) + if (d->drawRepaint) { d->drawRepaint( d, d->data, 0, 0 ); + } } + +/* + ***************************************************************************** + * + * Cursor handling + * + ***************************************************************************** + */ + + +extern long dontHideCursor; +static wCursor_t curCursor = wCursorNormal; + +void DoSetCursor() +{ + switch (curCursor) { + case wCursorNormal: + default: + SetCursor(LoadCursor(NULL, IDC_ARROW)); + break; + + case wCursorWait: + SetCursor(LoadCursor(NULL, IDC_WAIT)); + break; + + case wCursorCross: + SetCursor(LoadCursor(NULL, IDC_CROSS)); + break; + + case wCursorIBeam: + SetCursor(LoadCursor(NULL, IDC_IBEAM)); + break; + + case wCursorQuestion: + SetCursor(LoadCursor(NULL, IDC_HELP)); + break; + + case wCursorHand: + SetCursor(LoadCursor(NULL, IDC_HAND)); + break; + + case wCursorNo: + SetCursor(LoadCursor(NULL, IDC_NO)); + break; + + case wCursorSizeAll: + SetCursor(LoadCursor(NULL, IDC_SIZEALL)); + break; + + case wCursorSizeNESW: + SetCursor(LoadCursor(NULL, IDC_SIZENESW)); + break; + + case wCursorSizeNWSE: + SetCursor(LoadCursor(NULL, IDC_SIZENWSE)); + break; + + case wCursorSizeNS: + SetCursor(LoadCursor(NULL, IDC_SIZENS)); + break; + + case wCursorSizeWE: + SetCursor(LoadCursor(NULL, IDC_SIZEWE)); + break; + + case wCursorAppStart: + SetCursor(LoadCursor(NULL, IDC_APPSTARTING)); + break; + + case wCursorNone: + if (!dontHideCursor) { + SetCursor(NULL); + } + break; + } + +} + +void wSetCursor(wDraw_p win, + wCursor_t cursor) +{ + curCursor = cursor; + DoSetCursor(); +} + + /* ***************************************************************************** @@ -1372,27 +1486,27 @@ void wRedraw( wDraw_p d ) */ struct wDrawBitMap_t { - wDrawBitMap_p next; - wDrawPix_t x; - wDrawPix_t y; - wDrawPix_t w; - wDrawPix_t h; - char * bmx; - wDrawColor color; - HBITMAP bm; - }; + wDrawBitMap_p next; + wDrawPix_t x; + wDrawPix_t y; + wDrawPix_t w; + wDrawPix_t h; + char * bmx; + wDrawColor color; + HBITMAP bm; +}; static wDrawBitMap_p bmRoot = NULL; extern wDrawColor drawColorWhite; extern wDrawColor drawColorBlack; void wDrawBitMap( - wDraw_p d, - wDrawBitMap_p bm, - wDrawPix_t px, - wDrawPix_t py, - wDrawColor dc, - wDrawOpts dopt ) + wDraw_p d, + wDrawBitMap_p bm, + wDrawPix_t px, + wDrawPix_t py, + wDrawColor dc, + wDrawOpts dopt ) { HDC bmDc; HBITMAP oldBm; @@ -1403,8 +1517,9 @@ void wDrawBitMap( x0 = XDRAWPIX2WINPIX(d,px-bm->x); y0 = YDRAWPIX2WINPIX(d,py-bm->y+bm->h); #ifdef LATER - if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) ) + if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) ) { return; + } #endif if (dc == drawColorWhite) { mode = clrOp; @@ -1414,10 +1529,12 @@ void wDrawBitMap( } if ( bm->color != dc ) { - if ( bm->bm ) + if ( bm->bm ) { DeleteObject( bm->bm ); - bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ), - RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx ); + } + bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette, + dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ), + RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx ); bm->color = dc; } @@ -1428,22 +1545,22 @@ void wDrawBitMap( SelectObject( bmDc, oldBm ); DeleteDC( bmDc ); if (d->hWnd) { - rect.top = y0-1; - rect.bottom = rect.top+ (wWinPix_t)bm->h+1; - rect.left = x0-1; - rect.right = rect.left+ (wWinPix_t)bm->w+1; - myInvalidateRect( d, &rect ); + rect.top = y0-1; + rect.bottom = rect.top+ (wWinPix_t)bm->h+1; + rect.left = x0-1; + rect.right = rect.left+ (wWinPix_t)bm->w+1; + myInvalidateRect( d, &rect ); } } wDrawBitMap_p wDrawBitMapCreate( - wDraw_p d, - int w, - int h, - int x, - int y, - const unsigned char * bits ) + wDraw_p d, + int w, + int h, + int x, + int y, + const unsigned char * bits ) { wDrawBitMap_p bm; int bmSize = ((w+7)/8) * h; @@ -1478,10 +1595,10 @@ wDrawBitMap_p wDrawBitMapCreate( static int doSetFocus = 1; LRESULT FAR PASCAL XEXPORT mswDrawPush( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wDraw_p b; @@ -1505,7 +1622,7 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush( b->hBmTemp = 0; b->hBmOld = 0; } else { - b->hDc = CreateCompatibleDC( hDc ); + b->hDc = CreateCompatibleDC( hDc ); b->hBmMain = CreateCompatibleBitmap( hDc, b->w, b->h ); b->hBmTemp = CreateCompatibleBitmap( hDc, b->w, b->h ); b->hBmOld = SelectObject( b->hDc, b->hBmMain ); @@ -1538,68 +1655,84 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush( if (b->hWnd) { if ( b->option & BD_DIRECT ) { } else { - hDc = GetDC( b->hWnd ); + hDc = GetDC( b->hWnd ); //- DeleteObject( b->hBmOld ); - DeleteObject( b->hBmMain ); - DeleteObject( b->hBmTemp ); - b->hBmMain = CreateCompatibleBitmap( hDc, b->w, b->h ); - b->hBmTemp = CreateCompatibleBitmap( hDc, b->w, b->h ); + DeleteObject( b->hBmMain ); + DeleteObject( b->hBmTemp ); + b->hBmMain = CreateCompatibleBitmap( hDc, b->w, b->h ); + b->hBmTemp = CreateCompatibleBitmap( hDc, b->w, b->h ); //- b->hBmOld = SelectObject( b->hDc, b->hBmMain ); - ReleaseDC( b->hWnd, hDc ); - SetROP2( b->hDc, R2_WHITE ); - Rectangle( b->hDc, 0, 0, b->w, b->h ); + ReleaseDC( b->hWnd, hDc ); + SetROP2( b->hDc, R2_WHITE ); + Rectangle( b->hDc, 0, 0, b->w, b->h ); } } /*if (b->drawResize) b->drawResize( b, b->size );*/ - if (b->drawRepaint) + if (b->drawRepaint) { b->drawRepaint( b, b->data, 0, 0 ); + } return (LRESULT)0; case WM_MOUSEMOVE: activeWnd = GetActiveWindow(); focusWnd = GetFocus(); if (focusWnd != hWnd) { b = (wDraw_p)mswMapIndex( inx ); - if (!b) + if (!b) { break; - if ( !((wControl_p)b->parent) ) + } + if ( !((wControl_p)b->parent) ) { break; - if ( ((wControl_p)b->parent)->hWnd != activeWnd ) + } + if ( ((wControl_p)b->parent)->hWnd != activeWnd ) { break; + } } case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_LBUTTONDBLCLK: - if (message == WM_LBUTTONDOWN) + case WM_MBUTTONUP: + case WM_MBUTTONDOWN: + if (message == WM_LBUTTONDOWN) { action = wActionLDown; - else if (message == WM_RBUTTONDOWN) + } else if (message == WM_RBUTTONDOWN) { action = wActionRDown; - else if (message == WM_LBUTTONUP) + } else if (message == WM_LBUTTONUP) { action = wActionLUp; - else if (message == WM_RBUTTONUP) + } else if (message == WM_RBUTTONUP) { action = wActionRUp; - else if (message == WM_LBUTTONDBLCLK) + } else if (message == WM_MBUTTONUP) { + action = wActionMUp; + } else if (message == WM_MBUTTONDOWN) { + action = wActionMDown; + } else if (message == WM_LBUTTONDBLCLK) { action = wActionLDownDouble; - else { - if ( (wParam & MK_LBUTTON) != 0) + } else { + if ( (wParam & MK_LBUTTON) != 0) { action = wActionLDrag; - else if ( (wParam & MK_RBUTTON) != 0) + } else if ( (wParam & MK_RBUTTON) != 0) { action = wActionRDrag; - else + } else if ( (wParam & MK_MBUTTON) != 0) { + action = wActionMDrag; + } else { action = wActionMove; + } } b = (wDraw_p)mswMapIndex( inx ); - if (!b) + if (!b) { break; - if (doSetFocus && message != WM_MOUSEMOVE) + } + if (doSetFocus && message != WM_MOUSEMOVE) { SetFocus( ((wControl_p)b->parent)->hWnd ); + } if ( (b->option&BD_NOCAPTURE) == 0 ) { - if (message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN) + if (message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN) { SetCapture( b->hWnd ); - else if (message == WM_LBUTTONUP || message == WM_RBUTTONUP) + } else if (message == WM_LBUTTONUP || message == WM_RBUTTONUP) { ReleaseCapture(); + } } ix = LOWORD( lParam ); iy = HIWORD( lParam ); @@ -1607,45 +1740,50 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush( y = YWINPIX2DRAWPIX( b, iy ); b->lastX = x; b->lastY = y; - if (b->action) + if (b->action) { b->action( b, b->data, action, x, y ); - if (b->hWnd) + } + if (b->hWnd) { UpdateWindow(b->hWnd); + } return (LRESULT)0; case WM_CHAR: b = (wDraw_p)mswMapIndex( inx ); extChar = wAccelKey_None; if (lParam & 0x01000000L) - switch( wParam ) { - case VK_DELETE: extChar = wAccelKey_Del; break; - case VK_INSERT: extChar = wAccelKey_Ins; break; - case VK_HOME: extChar = wAccelKey_Home; break; - case VK_END: extChar = wAccelKey_End; break; - case VK_PRIOR: extChar = wAccelKey_Pgup; break; - case VK_NEXT: extChar = wAccelKey_Pgdn; break; - case VK_UP: extChar = wAccelKey_Up; break; - case VK_DOWN: extChar = wAccelKey_Down; break; - case VK_RIGHT: extChar = wAccelKey_Right; break; - case VK_LEFT: extChar = wAccelKey_Left; break; - case VK_BACK: extChar = wAccelKey_Back; break; - case VK_F1: extChar = wAccelKey_F1; break; - case VK_F2: extChar = wAccelKey_F2; break; - case VK_F3: extChar = wAccelKey_F3; break; - case VK_F4: extChar = wAccelKey_F4; break; - case VK_F5: extChar = wAccelKey_F5; break; - case VK_F6: extChar = wAccelKey_F6; break; - case VK_F7: extChar = wAccelKey_F7; break; - case VK_F8: extChar = wAccelKey_F8; break; - case VK_F9: extChar = wAccelKey_F9; break; - case VK_F10: extChar = wAccelKey_F10; break; - case VK_F11: extChar = wAccelKey_F11; break; - case VK_F12: extChar = wAccelKey_F12; break; - } + switch( wParam ) { + case VK_DELETE: extChar = wAccelKey_Del; break; + case VK_INSERT: extChar = wAccelKey_Ins; break; + case VK_HOME: extChar = wAccelKey_Home; break; + case VK_END: extChar = wAccelKey_End; break; + case VK_PRIOR: extChar = wAccelKey_Pgup; break; + case VK_NEXT: extChar = wAccelKey_Pgdn; break; + case VK_UP: extChar = wAccelKey_Up; break; + case VK_DOWN: extChar = wAccelKey_Down; break; + case VK_RIGHT: extChar = wAccelKey_Right; break; + case VK_LEFT: extChar = wAccelKey_Left; break; + case VK_BACK: extChar = wAccelKey_Back; break; + case VK_F1: extChar = wAccelKey_F1; break; + case VK_F2: extChar = wAccelKey_F2; break; + case VK_F3: extChar = wAccelKey_F3; break; + case VK_F4: extChar = wAccelKey_F4; break; + case VK_F5: extChar = wAccelKey_F5; break; + case VK_F6: extChar = wAccelKey_F6; break; + case VK_F7: extChar = wAccelKey_F7; break; + case VK_F8: extChar = wAccelKey_F8; break; + case VK_F9: extChar = wAccelKey_F9; break; + case VK_F10: extChar = wAccelKey_F10; break; + case VK_F11: extChar = wAccelKey_F11; break; + case VK_F12: extChar = wAccelKey_F12; break; + } if (b && b->action) { - if (extChar != wAccelKey_None) - b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX, b->lastY ); - else - b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX, b->lastY ); + if (extChar != wAccelKey_None) { + b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX, + b->lastY ); + } else { + b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX, + b->lastY ); + } } return (LRESULT)0; @@ -1663,17 +1801,17 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush( } HBITMAP hBmOld = SelectObject( b->hDc, b->hBmMain ); - if (bDrawMainBM) { - BitBlt(hDc, rect.left, rect.top, - rect.right - rect.left, rect.bottom - rect.top, - b->hDc, rect.left, rect.top, - SRCCOPY); - } + if (bDrawMainBM) { + BitBlt(hDc, rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + b->hDc, rect.left, rect.top, + SRCCOPY); + } SelectObject( b->hDc, b->bCopiedMain?b->hBmTemp:b->hBmMain ); BitBlt( hDc, rect.left, rect.top, - rect.right-rect.left, rect.bottom-rect.top, - b->hDc, rect.left, rect.top, - bDrawMainBM?SRCAND:SRCCOPY); + rect.right-rect.left, rect.bottom-rect.top, + b->hDc, rect.left, rect.top, + bDrawMainBM?SRCAND:SRCCOPY); SelectObject( b->hDc, hBmOld ); EndPaint( hWnd, &ps ); b->bCopiedMain = FALSE; @@ -1693,6 +1831,13 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush( } } break; + + case WM_SETCURSOR: + // Set cursor based on wSetCursor + DoSetCursor(); + // return TRUE to suppress my parent from overriding me + return TRUE; + default: break; } @@ -1700,10 +1845,11 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush( } -static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) +static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, + LPARAM lParam ) { wAction_t action; - + switch( message ) { case WM_MOUSEWHEEL: /* handle mouse wheel events */ @@ -1728,8 +1874,9 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L action = wActionWheelDown; } } - if (b->action) + if (b->action) { b->action( b, b->data, action, b->lastX, b->lastY ); + } return (LRESULT)0; case WM_MOUSEHWHEEL: if ( GET_KEYSTATE_WPARAM(wParam) & (MK_SHIFT|MK_MBUTTON)) { @@ -1739,8 +1886,9 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L action = wActionScrollLeft; } } - if (b->action) + if (b->action) { b->action( b, b->data, action, b->lastX, b->lastY ); + } return (LRESULT)0; } @@ -1777,17 +1925,19 @@ static void drawDoneProc( wControl_p b ) d->hDcBackup = (HDC)0; } while (bmRoot) { - if (bmRoot->bm) + if (bmRoot->bm) { DeleteObject( bmRoot->bm ); + } bmRoot = bmRoot->next; } } static callBacks_t drawCallBacks = { - NULL, - drawDoneProc, - (messageCallback_p)drawMsgProc }; + NULL, + drawDoneProc, + (messageCallback_p)drawMsgProc +}; static wDraw_p drawList = NULL; @@ -1796,8 +1946,9 @@ void mswRedrawAll( void ) { wDraw_p p; for ( p=drawList; p; p=p->drawNext ) { - if (p->drawRepaint) + if (p->drawRepaint) { p->drawRepaint( p, p->data, 0, 0 ); + } } } @@ -1814,14 +1965,14 @@ void mswRepaintAll( void ) hDc = BeginPaint( b->hWnd, &ps ); HBITMAP hBmOld = SelectObject( b->hDc, b->hBmMain ); BitBlt( hDc, rect.left, rect.top, - rect.right-rect.left, rect.bottom-rect.top, - b->hDc, rect.left, rect.top, - SRCCOPY ); + rect.right-rect.left, rect.bottom-rect.top, + b->hDc, rect.left, rect.top, + SRCCOPY ); SelectObject( b->hDc, b->hBmTemp ); BitBlt( hDc, rect.left, rect.top, - rect.right-rect.left, rect.bottom-rect.top, - b->hDc, rect.left, rect.top, - SRCAND ); + rect.right-rect.left, rect.bottom-rect.top, + b->hDc, rect.left, rect.top, + SRCAND ); SelectObject( b->hDc, hBmOld ); EndPaint( b->hWnd, &ps ); } @@ -1830,27 +1981,22 @@ void mswRepaintAll( void ) wDraw_p wDrawCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - long option, - wWinPix_t w, - wWinPix_t h, - void * data, - wDrawRedrawCallBack_p redrawProc, - wDrawActionCallBack_p action ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + long option, + wWinPix_t w, + wWinPix_t h, + void * data, + wDrawRedrawCallBack_p redrawProc, + wDrawActionCallBack_p action ) { wDraw_p d; RECT rect; int index; HDC hDc; - if ( noNegDrawArgs < 0 ) { - wPrefGetInteger( "msw tweak", "NoNegDrawArgs", &noNegDrawArgs, 0 ); - wPrefGetInteger( "msw tweak", "NoFlatEndCaps", &noFlatEndCaps, 0 ); - } - d = mswAlloc( parent, B_DRAW, NULL, sizeof *d, data, &index ); mswComputePos( (wControl_p)d, x, y ); d->w = w; @@ -1860,9 +2006,9 @@ wDraw_p wDrawCreate( d->option = option; d->hWnd = CreateWindow( mswDrawWindowClassName, NULL, - WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER, - d->x, d->y, w, h, - ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); + WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER, + d->x, d->y, w, h, + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (d->hWnd == (HWND)0) { mswFail( "CreateWindow(DRAW)" ); @@ -1916,7 +2062,7 @@ wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int planes ) d->option = 0; hDc = GetDC(mswHWnd); - d->hDc = CreateCompatibleDC( hDc ); + d->hDc = CreateCompatibleDC( hDc ); if ( d->hDc == (HDC)0 ) { wNoticeEx( NT_ERROR, "CreateBitMap: CreateDC fails", "Ok", NULL ); return FALSE; @@ -1984,57 +2130,57 @@ wBool_t wBitMapDelete( wDraw_p d ) wBool_t wBitMapWriteFile(wDraw_p d, const char * fileName) { - FIBITMAP *dib = NULL; - FIBITMAP *dib2 = NULL; - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - - if (d->hBmMain) { - - BITMAP bm; - GetObject(d->hBmMain, sizeof(BITMAP), (LPSTR)&bm); - dib = FreeImage_Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); - // The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why) - // So we save these infos below. This is needed for palettized images only. - int nColors = FreeImage_GetColorsUsed(dib); - HDC dc = GetDC(NULL); - GetDIBits(dc, - d->hBmMain, - 0, - FreeImage_GetHeight(dib), - FreeImage_GetBits(dib), - FreeImage_GetInfo(dib), - DIB_RGB_COLORS); - ReleaseDC(NULL, dc); - - // restore BITMAPINFO members - FreeImage_GetInfoHeader(dib)->biClrUsed = nColors; - FreeImage_GetInfoHeader(dib)->biClrImportant = nColors; - // we will get a 32 bit bitmap on Windows systems with invalid alpha - // so it needs to be converted to 24 bits. - // (see: https://sourceforge.net/p/freeimage/discussion/36110/thread/0699ce8e/ ) - dib2 = FreeImage_ConvertTo24Bits(dib); - FreeImage_Unload(dib); - } - - // Try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(fileName); - if (fif != FIF_UNKNOWN) { - // Check that the dib can be saved in this format - BOOL bCanSave; - - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib2); - if (image_type == FIT_BITMAP) { - // standard bitmap type - WORD bpp = FreeImage_GetBPP(dib2); - bCanSave = (FreeImage_FIFSupportsWriting(fif) && - FreeImage_FIFSupportsExportBPP(fif, bpp)); - } else { - // special bitmap type - bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); - } - - if (bCanSave) { + FIBITMAP *dib = NULL; + FIBITMAP *dib2 = NULL; + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + BOOL bSuccess = FALSE; + + if (d->hBmMain) { + + BITMAP bm; + GetObject(d->hBmMain, sizeof(BITMAP), (LPSTR)&bm); + dib = FreeImage_Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); + // The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why) + // So we save these infos below. This is needed for palettized images only. + int nColors = FreeImage_GetColorsUsed(dib); + HDC dc = GetDC(NULL); + GetDIBits(dc, + d->hBmMain, + 0, + FreeImage_GetHeight(dib), + FreeImage_GetBits(dib), + FreeImage_GetInfo(dib), + DIB_RGB_COLORS); + ReleaseDC(NULL, dc); + + // restore BITMAPINFO members + FreeImage_GetInfoHeader(dib)->biClrUsed = nColors; + FreeImage_GetInfoHeader(dib)->biClrImportant = nColors; + // we will get a 32 bit bitmap on Windows systems with invalid alpha + // so it needs to be converted to 24 bits. + // (see: https://sourceforge.net/p/freeimage/discussion/36110/thread/0699ce8e/ ) + dib2 = FreeImage_ConvertTo24Bits(dib); + FreeImage_Unload(dib); + } + + // Try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(fileName); + if (fif != FIF_UNKNOWN) { + // Check that the dib can be saved in this format + BOOL bCanSave; + + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib2); + if (image_type == FIT_BITMAP) { + // standard bitmap type + WORD bpp = FreeImage_GetBPP(dib2); + bCanSave = (FreeImage_FIFSupportsWriting(fif) && + FreeImage_FIFSupportsExportBPP(fif, bpp)); + } else { + // special bitmap type + bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); + } + + if (bCanSave) { int flags; switch (fif) { @@ -2047,11 +2193,11 @@ wBitMapWriteFile(wDraw_p d, const char * fileName) default: flags = 0; // whatver the default is for the file format } - bSuccess = FreeImage_Save(fif, dib2, fileName, flags); - } - } - FreeImage_Unload(dib2); + bSuccess = FreeImage_Save(fif, dib2, fileName, flags); + } + } + FreeImage_Unload(dib2); - return bSuccess; + return bSuccess; } diff --git a/app/wlib/mswlib/mswedit.c b/app/wlib/mswlib/mswedit.c index b6da004..db7409e 100644 --- a/app/wlib/mswlib/mswedit.c +++ b/app/wlib/mswlib/mswedit.c @@ -1,7 +1,7 @@ /** \file mswedit.c * Text entry widgets */ - + /* XTrackCAD - Model Railroad CAD * Copyright (C) 2005 Dave Bullis * @@ -17,12 +17,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - + #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <stdio.h> #include <commdlg.h> @@ -31,29 +30,29 @@ struct wString_t { - WOBJ_COMMON - char * valueP; - wIndex_t valueL; - wStringCallBack_p action; - wBool_t enter_pressed; /**< flag if enter was pressed */ - }; + WOBJ_COMMON + char * valueP; + wIndex_t valueL; + wStringCallBack_p action; + wBool_t enter_pressed; /**< flag if enter was pressed */ +}; #ifdef LATER struct wInteger_t { - WOBJ_COMMON - long low, high; - long * valueP; - long oldValue; - wIntegerCallBack_p action; - }; + WOBJ_COMMON + long low, high; + long * valueP; + long oldValue; + wIntegerCallBack_p action; +}; struct wFloat_t { - WOBJ_COMMON - double low, high; - double * valueP; - double oldValue; - wFloatCallBack_p action; - }; + WOBJ_COMMON + double low, high; + double * valueP; + double oldValue; + wFloatCallBack_p action; +}; #endif // LATER @@ -67,33 +66,32 @@ static void triggerFloat( wControl_p b ); LRESULT FAR PASCAL _export pushEdit( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wString_p b = (wString_p)mswMapIndex(inx); - switch (message) - { + switch (message) { case WM_CHAR: - if (b != NULL) { - switch (wParam) { - case VK_RETURN: - triggerString(b); - 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 (LRESULT)0; - } - } - break; + if (b != NULL) { + switch (wParam) { + case VK_RETURN: + triggerString(b); + 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 (LRESULT)0; + } + } + break; } return CallWindowProc(oldEditProc, hWnd, message, wParam, lParam); @@ -109,8 +107,8 @@ LRESULT FAR PASCAL _export pushEdit( void wStringSetValue( - wString_p b, - const char * arg ) + wString_p b, + const char * arg ) { WORD len = (WORD)strlen( arg ); SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)arg ); @@ -121,18 +119,18 @@ void wStringSetValue( void wStringSetWidth( - wString_p b, - wWinPix_t w ) + wString_p b, + 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 ); } const char * wStringGetValue( - wString_p b ) + wString_p b ) { static char buff[1024]; SendMessage( b->hWnd, WM_GETTEXT, (WPARAM)sizeof buff, (LPARAM)buff ); @@ -141,29 +139,29 @@ const char * wStringGetValue( /** * Get the string from a entry field. The returned pointer has to be free() after processing is complete. - * + * * \param bs IN string entry field - * + * * \return pointer to entered string or NULL if entry field is empty. */ static char *getString(wString_p bs) { - char *tmpBuffer = NULL; - 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, (WPARAM)0, (LPARAM)tmpBuffer); - tmpBuffer[chars] = '\0'; - } else { - tmpBuffer = malloc(2); - tmpBuffer[0] = '\n'; - tmpBuffer[1] = '\0'; - } - - return (tmpBuffer); + char *tmpBuffer = NULL; + 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, (WPARAM)0, (LPARAM)tmpBuffer); + tmpBuffer[chars] = '\0'; + } else { + tmpBuffer = malloc(2); + tmpBuffer[0] = '\n'; + tmpBuffer[1] = '\0'; + } + + return (tmpBuffer); } /** @@ -174,20 +172,19 @@ static char *getString(wString_p bs) */ static void triggerString( - wString_p b) + wString_p b) { const char *output = "\n"; - char *enteredString = getString(b); - if (enteredString) - { - if (b->valueP) { - strcpy(b->valueP, enteredString); - } + char *enteredString = getString(b); + if (enteredString) { + if (b->valueP) { + strcpy(b->valueP, enteredString); + } if (b->action) { b->enter_pressed = TRUE; b->action(output, b->data); - } + } free(enteredString); } @@ -195,84 +192,87 @@ static void triggerString( LRESULT stringProc( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam) + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam) { - wString_p bs = (wString_p)b; - int modified; - - switch (message) { - - case WM_COMMAND: - switch (WCMD_PARAM_NOTF) { - case EN_KILLFOCUS: - modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, (WPARAM)0, (LPARAM)0); - if (!modified) { - break; - } - - char *enteredString = getString(bs); - if (enteredString) { - if (bs->valueP) { - strcpy(bs->valueP, enteredString); - } - if (bs->action) { - bs->action(enteredString, bs->data); - mswSetTrigger(NULL, NULL); - } - free(enteredString); - } - SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0); - } - break; - } - - return DefWindowProc(hWnd, message, wParam, lParam); + wString_p bs = (wString_p)b; + int modified; + + switch (message) { + + case WM_COMMAND: + switch (WCMD_PARAM_NOTF) { + case EN_KILLFOCUS: + modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, (WPARAM)0, (LPARAM)0); + if (!modified) { + break; + } + + char *enteredString = getString(bs); + if (enteredString) { + if (bs->valueP) { + strcpy(bs->valueP, enteredString); + } + if (bs->action) { + bs->action(enteredString, bs->data); + mswSetTrigger(NULL, NULL); + } + free(enteredString); + } + SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0); + } + break; + } + + return DefWindowProc(hWnd, message, wParam, lParam); } static callBacks_t stringCallBacks = { - mswRepaintLabel, - NULL, - stringProc }; + mswRepaintLabel, + NULL, + stringProc +}; wString_p wStringCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - char *valueP, - wIndex_t valueL, - wStringCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + char *valueP, + wIndex_t valueL, + wStringCallBack_p action, + void *data ) { wString_p b; RECT rect; int index; DWORD style = 0; - b = (wString_p)mswAlloc( parent, B_STRING, mswStrdup(labelStr), sizeof *b, data, &index ); + b = (wString_p)mswAlloc( parent, B_STRING, mswStrdup(labelStr), sizeof *b, data, + &index ); mswComputePos( (wControl_p)b, x, y ); b->option = option; b->valueP = valueP; b->valueL = valueL; b->labelY += 2; b->action = action; - if (option & BO_READONLY) + if (option & BO_READONLY) { style |= ES_READONLY; + } 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)(UINT_PTR)index, mswHInst, NULL ); + ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style, + b->x, b->y, + width, mswEditHeight, + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(STRING)"); return b; @@ -290,8 +290,8 @@ wString_p wStringCreate( SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)b->valueP ); } SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 ); - if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); + 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; @@ -317,8 +317,8 @@ wString_p wStringCreate( void wIntegerSetValue( - wInteger_p b, - long arg ) + wInteger_p b, + long arg ) { b->oldValue = arg; wsprintf( mswTmpBuff, "%ld", arg ); @@ -328,14 +328,14 @@ void wIntegerSetValue( long wIntegerGetValue( - wInteger_p b ) + wInteger_p b ) { return b->oldValue; } static void triggerInteger( - wControl_p b ) + wControl_p b ) { wInteger_p bi = (wInteger_p)b; int cnt; @@ -344,17 +344,22 @@ static void triggerInteger( if (bi->action) { *(WPARAM*)&mswTmpBuff[0] = 78; - cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0, (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0, + (DWORD)(LPSTR)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; - if (strcmp( mswTmpBuff, "-" )==0 ) + if (strcmp( mswTmpBuff, "-" )==0 ) { return; + } value = strtol( mswTmpBuff, &cp, 10 ); - if (*cp != '\0' || value < bi->low || value > bi->high ) + if (*cp != '\0' || value < bi->low || value > bi->high ) { return; - if (bi->oldValue == value) + } + if (bi->oldValue == value) { return; - if (bi->valueP) + } + if (bi->valueP) { *bi->valueP = value; + } bi->oldValue = value; bi->action( value, bi->data ); } @@ -362,31 +367,33 @@ static void triggerInteger( LRESULT integerProc( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) -{ + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) +{ wInteger_p bi = (wInteger_p)b; int inx; int cnt; long value; - char * cp; + char * cp; wBool_t ok; int modified; - + switch( message ) { - + case WM_COMMAND: switch (WCMD_PARAM_NOTF) { case EN_KILLFOCUS: ok = TRUE; modified = (int)SendMessage( bi->hWnd, (UINT)EM_GETMODIFY, 0, 0L ); - if (!modified) + if (!modified) { break; + } *(WPARAM*)&mswTmpBuff[0] = 78; - cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0, (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0, + (DWORD)(LPSTR)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if (strcmp( mswTmpBuff, "-" )==0 && 0 >= bi->low && 0 <= bi->high ) { value = 0; @@ -395,23 +402,25 @@ LRESULT integerProc( if (*cp != '\0' || value < bi->low || value > bi->high ) { inx = GetWindowWord( bi->hWnd, GWW_ID ); if (wWinIsVisible(bi->parent)) { - PostMessage( ((wControl_p)(bi->parent))->hWnd, - WM_NOTVALID, inx, 0L ); + PostMessage( ((wControl_p)(bi->parent))->hWnd, + WM_NOTVALID, inx, 0L ); return TRUE; } else { - if (value < bi->low) + if (value < bi->low) { value = bi->low; - else + } else { value = bi->high; + } sprintf( mswTmpBuff, "%ld", value ); SendMessage( bi->hWnd, (UINT)WM_SETTEXT, 0, - (DWORD)(LPSTR)mswTmpBuff ); + (DWORD)(LPSTR)mswTmpBuff ); } } } bi->oldValue = value; - if (bi->valueP) + if (bi->valueP) { *bi->valueP = value; + } if (bi->action) { bi->action( value, bi->data ); mswSetTrigger( NULL, NULL ); @@ -422,21 +431,22 @@ LRESULT integerProc( case WM_NOTVALID: wsprintf( mswTmpBuff, "Please enter a value between %ld and %ld", - bi->low, bi->high ); + bi->low, bi->high ); if (bi->low > MININT && bi->high < MAXINT) sprintf( mswTmpBuff, - "Please enter an integer value between %ld and %ld", - bi->low, bi->high ); + "Please enter an integer value between %ld and %ld", + bi->low, bi->high ); else if (bi->low > MININT) sprintf( mswTmpBuff, - "Please enter an integer value greater or equal to %ld", - bi->low ); + "Please enter an integer value greater or equal to %ld", + bi->low ); else if (bi->high < MAXINT) sprintf( mswTmpBuff, - "Please enter an integer value less or equal to %ld", - bi->high ); - else + "Please enter an integer value less or equal to %ld", + bi->high ); + else { strcpy( mswTmpBuff, "Please enter an integer value" ); + } MessageBox( bi->hWnd, mswTmpBuff, "Invalid entry", MB_OK ); SetFocus( bi->hWnd ); #ifdef WIN32 @@ -447,31 +457,32 @@ LRESULT integerProc( #endif return TRUE; - } - + } + return DefWindowProc( hWnd, message, wParam, lParam ); -} +} static callBacks_t integerCallBacks = { - mswRepaintLabel, - NULL, - integerProc }; + mswRepaintLabel, + NULL, + integerProc +}; wInteger_p wIntegerCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - long low, - long high, - long *valueP, - wIntegerCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + long low, + long high, + long *valueP, + wIntegerCallBack_p action, + void *data ) { wInteger_p b; RECT rect; @@ -486,32 +497,35 @@ wInteger_p wIntegerCreate( b->valueP = valueP; b->labelY += 2; b->action = action; - if (option & BO_READONLY) + if (option & BO_READONLY) { style |= ES_READONLY; + } 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 ); + 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 ); if (b->hWnd == NULL) { mswFail("CreateWindow(INTEGER)"); return b; } - + newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc ); - if ( !mswThickFont ) + if ( !mswThickFont ) { SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + } if (b->valueP) { wsprintf( mswTmpBuff, "%ld", *b->valueP ); SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)(LPSTR)mswTmpBuff ); b->oldValue = *b->valueP; - } else + } else { b->oldValue = 0; + } SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L ); GetWindowRect( b->hWnd, &rect ); @@ -539,8 +553,8 @@ wInteger_p wIntegerCreate( void wFloatSetValue( - wFloat_p b, - double arg ) + wFloat_p b, + double arg ) { b->oldValue = arg; sprintf( mswTmpBuff, "%0.3f", arg ); @@ -550,67 +564,72 @@ void wFloatSetValue( double wFloatGetValue( - wFloat_p b ) + wFloat_p b ) { return b->oldValue; } static void triggerFloat( - wControl_p b ) + wControl_p b ) { wFloat_p bf = (wFloat_p)b; int cnt; double value; - char * cp; + char * cp; if (bf->action) { *(WPARAM*)&mswTmpBuff[0] = 78; cnt = (int)SendMessage( bf->hWnd, (UINT)EM_GETLINE, 0, - (DWORD)(LPSTR)mswTmpBuff ); + (DWORD)(LPSTR)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; - if (strcmp( mswTmpBuff, "-" )==0) + if (strcmp( mswTmpBuff, "-" )==0) { return; + } value = strtod( mswTmpBuff, &cp ); - if (*cp != '\0' || value < bf->low || value > bf->high ) + if (*cp != '\0' || value < bf->low || value > bf->high ) { return; - if (bf->oldValue == value) + } + if (bf->oldValue == value) { return; + } bf->oldValue = value; - if (bf->valueP) - *bf->valueP = value; + if (bf->valueP) { + *bf->valueP = value; + } bf->action( wFloatGetValue(bf), bf->data ); } } LRESULT floatProc( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) -{ + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) +{ wFloat_p bf = (wFloat_p)b; int inx; int cnt; double value; - char * cp; + char * cp; wBool_t ok; int modified; switch( message ) { - + case WM_COMMAND: switch (HIWORD(lParam)) { case EN_KILLFOCUS: ok = TRUE; modified = (int)SendMessage( bf->hWnd, (UINT)EM_GETMODIFY, 0, 0L ); - if (!modified) + if (!modified) { break; + } *(WPARAM*)&mswTmpBuff[0] = 78; cnt = (int)SendMessage( bf->hWnd, (UINT)EM_GETLINE, 0, - (DWORD)(LPSTR)mswTmpBuff ); + (DWORD)(LPSTR)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if (strcmp( mswTmpBuff, "-" )==0 && 0 >= bf->low && 0 <= bf->high ) { value = 0; @@ -619,23 +638,25 @@ LRESULT floatProc( if (*cp != '\0' || value < bf->low || value > bf->high ) { inx = GetWindowWord( bf->hWnd, GWW_ID ); if (wWinIsVisible(bf->parent)) { - PostMessage( ((wControl_p)(bf->parent))->hWnd, - WM_NOTVALID, inx, 0L ); + PostMessage( ((wControl_p)(bf->parent))->hWnd, + WM_NOTVALID, inx, 0L ); return TRUE; } else { - if (value < bf->low) + if (value < bf->low) { value = bf->low; - else + } else { value = bf->high; + } sprintf( mswTmpBuff, "%0.3f", value ); SendMessage( bf->hWnd, (UINT)WM_SETTEXT, 0, - (DWORD)(LPSTR)mswTmpBuff ); + (DWORD)(LPSTR)mswTmpBuff ); } } } bf->oldValue = value; - if (bf->valueP) + if (bf->valueP) { *bf->valueP = value; + } if (bf->action) { bf->action( value, bf->data ); mswSetTrigger( NULL, NULL ); @@ -647,18 +668,19 @@ LRESULT floatProc( case WM_NOTVALID: if (bf->low > MINFLT && bf->high < MAXFLT) sprintf( mswTmpBuff, - "Please enter an float value between %0.3f and %0.3f", - bf->low, bf->high ); + "Please enter an float value between %0.3f and %0.3f", + bf->low, bf->high ); else if (bf->low > MINFLT) sprintf( mswTmpBuff, - "Please enter an float value greater or equal to %0.3f", - bf->low ); + "Please enter an float value greater or equal to %0.3f", + bf->low ); else if (bf->high < MAXFLT) sprintf( mswTmpBuff, - "Please enter an float value less or equal to %0.3f", - bf->high ); - else + "Please enter an float value less or equal to %0.3f", + bf->high ); + else { strcpy( mswTmpBuff, "Please enter an float value" ); + } MessageBox( bf->hWnd, mswTmpBuff, "Invalid entry", MB_OK ); SetFocus( bf->hWnd ); #ifdef WIN32 @@ -669,30 +691,31 @@ LRESULT floatProc( #endif return TRUE; - } + } return DefWindowProc( hWnd, message, wParam, lParam ); -} +} static callBacks_t floatCallBacks = { - mswRepaintLabel, - NULL, - floatProc }; + mswRepaintLabel, + NULL, + floatProc +}; wFloat_p wFloatCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - double low, - double high, - double *valueP, - wFloatCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + double low, + double high, + double *valueP, + wFloatCallBack_p action, + void *data ) { wFloat_p b; RECT rect; @@ -707,34 +730,38 @@ wFloat_p wFloatCreate( b->valueP = valueP; b->labelY += 2; b->action = action; - if (option & BO_READONLY) + if (option & BO_READONLY) { style |= ES_READONLY; + } 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 ); + 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 ); if (b->hWnd == NULL) { mswFail("CreateWindow(FLOAT)"); return b; } - + newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc ); if (b->valueP) { - b->oldValue = *b->valueP; - } else - b->oldValue = 0.0; - if (b->valueP) - sprintf( mswTmpBuff, "%0.3f", *b->valueP ); - else - strcpy( mswTmpBuff, "0.000" ); - if ( !mswThickFont ) + b->oldValue = *b->valueP; + } else { + b->oldValue = 0.0; + } + if (b->valueP) { + sprintf( mswTmpBuff, "%0.3f", *b->valueP ); + } else { + strcpy( mswTmpBuff, "0.000" ); + } + if ( !mswThickFont ) { SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + } SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)(LPSTR)mswTmpBuff ); SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L ); diff --git a/app/wlib/mswlib/mswint.h b/app/wlib/mswlib/mswint.h index 5fd5da9..525a37c 100644 --- a/app/wlib/mswlib/mswint.h +++ b/app/wlib/mswlib/mswint.h @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "wlib.h" @@ -173,9 +173,7 @@ extern HFONT mswOldTextFont; extern HFONT mswLabelFont; extern wDrawColor wDrawColorWhite; extern wDrawColor wDrawColorBlack; -extern long mswThickFont; extern double mswScale; -extern double scaleIcon; DWORD mswGetBaseStyle( wWin_p ); char * mswStrdup( const char * ); diff --git a/app/wlib/mswlib/mswlines.c b/app/wlib/mswlib/mswlines.c index f6bb574..a55618e 100644 --- a/app/wlib/mswlib/mswlines.c +++ b/app/wlib/mswlib/mswlines.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -15,10 +14,10 @@ */ struct wLine_t { - WOBJ_COMMON - int count; - wLines_t * lines; - }; + WOBJ_COMMON + int count; + wLines_t * lines; +}; static void repaintLines( HWND hWnd, wControl_p b ) { @@ -45,24 +44,26 @@ static void repaintLines( HWND hWnd, wControl_p b ) static callBacks_t linesCallBacks = { - repaintLines, - NULL, - NULL }; + repaintLines, + NULL, + NULL +}; wLine_p wLineCreate( - wWin_p parent, - const char * labelStr, - int count, - wLines_t * lines ) + wWin_p parent, + const char * labelStr, + int count, + wLines_t * lines ) { wLine_p b; wLines_p lp; wWinPix_t minX, maxX, minY, maxY; int index; - if (count <= 0) + if (count <= 0) { return NULL; + } b = (wLine_p)mswAlloc( parent, B_LINES, labelStr, sizeof *b, NULL, &index ); b->count = count; b->lines = lines; @@ -71,22 +72,30 @@ wLine_p wLineCreate( minX = maxX = lp->x0; minY = maxY = lp->y0; for (lp=lines; lp<&b->lines[count]; lp++) { - if (minX > lp->x0) + if (minX > lp->x0) { minX = lp->x0; - if (maxX < lp->x0) + } + if (maxX < lp->x0) { maxX = lp->x0; - if (minY > lp->y0) + } + if (minY > lp->y0) { minY = lp->y0; - if (maxY < lp->y0) + } + if (maxY < lp->y0) { maxY = lp->y0; - if (minX > lp->x1) + } + if (minX > lp->x1) { minX = lp->x1; - if (maxX < lp->x1) + } + if (maxX < lp->x1) { maxX = lp->x1; - if (minY > lp->y1) + } + if (minY > lp->y1) { minY = lp->y1; - if (maxY < lp->y1) + } + if (maxY < lp->y1) { maxY = lp->y1; + } } b->x = minX; b->y = minY; diff --git a/app/wlib/mswlib/mswlist.c b/app/wlib/mswlib/mswlist.c index 836f4f0..c955c25 100644 --- a/app/wlib/mswlib/mswlist.c +++ b/app/wlib/mswlib/mswlist.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -20,44 +19,45 @@ static XWNDPROC oldComboProc = NULL; static XWNDPROC newComboProc; struct wList_t { - WOBJ_COMMON - int count; - int last; - long * valueP; - wListCallBack_p action; - wBool_t editable; - int colCnt; - wWinPix_t * colWidths; - wBool_t * colRightJust; - const char * * colTitles; - wWinPix_t maxWidth; - wWinPix_t scrollPos; - HWND hScrollWnd; - wWinPix_t scrollH; - wWinPix_t dragPos; - int dragCol; - wWinPix_t dragColWidth; - }; + WOBJ_COMMON + int count; + int last; + long * valueP; + wListCallBack_p action; + wBool_t editable; + int colCnt; + wWinPix_t * colWidths; + wBool_t * colRightJust; + const char * * colTitles; + wWinPix_t maxWidth; + wWinPix_t scrollPos; + HWND hScrollWnd; + wWinPix_t scrollH; + wWinPix_t dragPos; + int dragCol; + wWinPix_t dragColWidth; +}; typedef struct { - void * itemContext; - wIcon_p bm; - wBool_t selected; - } listData; + void * itemContext; + wIcon_p bm; + wBool_t selected; +} listData; static int LIST_HEIGHT = 19; static int listTitleHeight = 16; void wListClear( - wList_p b ) + wList_p b ) { UINT msg; - if (b->type==B_LIST) + if (b->type==B_LIST) { msg = LB_RESETCONTENT; - else + } else { msg = CB_RESETCONTENT; + } SendMessage( b->hWnd, msg, (WPARAM)0, (LPARAM)0 ); b->last = -1; b->count = 0; @@ -73,20 +73,21 @@ void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h ) bl->w = w; bl->h = h; - y = bl->y; - if ( bl->hScrollWnd && bl->maxWidth > bl->w ) + y = bl->y; + if ( bl->hScrollWnd && bl->maxWidth > bl->w ) { h -= bl->scrollH; + } if ( bl->colTitles ) { h -= listTitleHeight; y += listTitleHeight; } rc = SetWindowPos( bl->hWnd, HWND_TOP, 0, 0, - w, h, SWP_NOMOVE|SWP_NOZORDER); + w, h, SWP_NOMOVE|SWP_NOZORDER); if ( bl->hScrollWnd ) { if ( bl->maxWidth > bl->w ) { GetClientRect( bl->hWnd, &rect ); rc = SetWindowPos( bl->hScrollWnd, HWND_TOP, bl->x, y+rect.bottom+2, - bl->w, bl->scrollH, SWP_NOZORDER); + bl->w, bl->scrollH, SWP_NOZORDER); ShowWindow( bl->hScrollWnd, SW_SHOW ); } else { ShowWindow( bl->hScrollWnd, SW_HIDE ); @@ -97,71 +98,77 @@ void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h ) void wListSetIndex( - wList_p bl, - int index ) + wList_p bl, + int index ) { listData * ldp; wListGetCount(bl); - if ( index >= bl->count ) + if ( index >= bl->count ) { index = bl->count-1; - if ( bl->last == index && index == -1 ) + } + if ( bl->last == index && index == -1 ) { return; + } if ( bl->type==B_LIST && (bl->option&BL_MANY) != 0 ) { - if ( bl->last != -1 ) + if ( bl->last != -1 ) { SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)0, (LPARAM)bl->last ); - if ( index >= 0 ) + } + if ( index >= 0 ) { SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)1, (LPARAM)index ); + } } else { SendMessage( bl->hWnd, - bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)index, (LPARAM)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), - (WPARAM)bl->last, (LPARAM)0 ); - if ( ldp && ldp!=(void*)LB_ERR ) + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (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), - (WPARAM)index, (LPARAM)0 ); - if ( ldp && ldp!=(void*)LB_ERR ) + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (WPARAM)index, (LPARAM)0 ); + if ( ldp && ldp!=(void*)LB_ERR ) { ldp->selected = TRUE; + } } /*if (b->option&BL_ICON)*/ - InvalidateRect( bl->hWnd, NULL, FALSE ); + InvalidateRect( bl->hWnd, NULL, FALSE ); bl->last = index; } wIndex_t wListGetIndex( - wList_p b ) + wList_p b ) { return b->last; } void wListSetActive( - wList_p b, - int inx, - wBool_t active ) + wList_p b, + int inx, + wBool_t active ) { } void wListSetEditable( - wList_p b, - wBool_t editable ) + wList_p b, + wBool_t editable ) { b->editable = editable; } void wListSetValue( - wList_p bl, - const char * val ) + wList_p bl, + const char * val ) { if ( bl->type == B_DROPLIST ) { SendMessage( bl->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)val ); @@ -171,30 +178,31 @@ void wListSetValue( wIndex_t wListFindValue( - wList_p bl, - const char * val ) + wList_p bl, + const char * val ) { wIndex_t inx; WORD cnt; wListGetCount(bl); for ( inx = 0; inx < bl->count ; inx++ ) { cnt = (int)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), (WPARAM)inx, - (LPARAM)mswTmpBuff ); + (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), (WPARAM)inx, + (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; - if ( strcmp( val, mswTmpBuff ) == 0 ) + if ( strcmp( val, mswTmpBuff ) == 0 ) { return inx; + } } return -1; } wIndex_t wListGetValues( - wList_p bl, - char * s, - int siz, - void * * listContextRef, - void * * itemContextRef ) + wList_p bl, + char * s, + int siz, + void * * listContextRef, + void * * itemContextRef ) { WORD cnt; WORD msg; @@ -204,8 +212,9 @@ wIndex_t wListGetValues( msg = WM_GETTEXT; inx = sizeof mswTmpBuff; } else { - if ( bl->last < 0 ) + if ( bl->last < 0 ) { goto EMPTY; + } if ( bl->type==B_LIST ) { msg = LB_GETTEXT; } else { @@ -220,29 +229,32 @@ wIndex_t wListGetValues( } if (bl->last >= 0) { ldp = (listData*)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - (WPARAM)bl->last, (LPARAM)0 ); - if ( ldp==(listData*)LB_ERR ) + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (WPARAM)bl->last, (LPARAM)0 ); + if ( ldp==(listData*)LB_ERR ) { ldp = NULL; + } } else { ldp = NULL; } EMPTY: - if (itemContextRef) + if (itemContextRef) { *itemContextRef = (ldp?ldp->itemContext:NULL); - if (listContextRef) + } + if (listContextRef) { *listContextRef = bl->data; + } return bl->last; } wBool_t wListSetValues( - wList_p b, - wIndex_t inx, - const char * labelStr, - wIcon_p bm, - void * itemData ) + wList_p b, + wIndex_t inx, + const char * labelStr, + wIcon_p bm, + void * itemData ) { - listData * ldp; + listData * ldp; WORD curSel = -1; ldp = (listData*)malloc( sizeof *ldp ); ldp->itemContext = itemData; @@ -250,40 +262,40 @@ wBool_t wListSetValues( ldp->selected = FALSE; if ( (b->option&BL_MANY) == 0 ) curSel = (WORD)SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_GETCURSEL:CB_GETCURSEL, - (WPARAM)0, - (LPARAM)0 ); + (UINT)b->type==B_LIST?LB_GETCURSEL:CB_GETCURSEL, + (WPARAM)0, + (LPARAM)0 ); SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, - (WPARAM)inx, - (LPARAM)0 ); + (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, + (WPARAM)inx, + (LPARAM)0 ); inx = (wIndex_t)SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_INSERTSTRING:CB_INSERTSTRING, - (WPARAM)inx, - (LPARAM)labelStr ); + (UINT)b->type==B_LIST?LB_INSERTSTRING:CB_INSERTSTRING, + (WPARAM)inx, + (LPARAM)labelStr ); SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, - (WPARAM)inx, - (LPARAM)ldp ); + (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, + (WPARAM)inx, + (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, - (LPARAM)0 ); + SendMessage( b->hWnd, + (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, + (WPARAM)inx, + (LPARAM)0 ); /*if (b->option&BL_ICON)*/ - InvalidateRect( b->hWnd, NULL, FALSE ); + InvalidateRect( b->hWnd, NULL, FALSE ); return TRUE; } void wListDelete( - wList_p b, - wIndex_t inx ) + wList_p b, + wIndex_t inx ) { SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, - (WPARAM)inx, - (LPARAM)0 ); + (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, + (WPARAM)inx, + (LPARAM)0 ); } @@ -301,69 +313,71 @@ void wListSelectAll( wList_p bl ) // mark all items selected SendMessage( bl->hWnd, - LB_SETSEL, - (WPARAM)TRUE, - (LPARAM)-1 ); + LB_SETSEL, + (WPARAM)TRUE, + (LPARAM)-1 ); - // and synchronize the internal data structures + // 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), - (WPARAM)inx, (LPARAM)0 ); + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (WPARAM)inx, (LPARAM)0 ); ldp->selected = TRUE; SendMessage( bl->hWnd, - (UINT)bl->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, - (WPARAM)inx, - (LPARAM)ldp ); + (UINT)bl->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, + (WPARAM)inx, + (LPARAM)ldp ); } } wIndex_t wListGetCount( - wList_p bl ) -{ - bl->count = (int)SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, (WPARAM)0, (LPARAM)0 ); + wList_p bl ) +{ + bl->count = (int)SendMessage( bl->hWnd, + (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, (WPARAM)0, (LPARAM)0 ); return bl->count; } void * wListGetItemContext( - wList_p bl, - wIndex_t inx ) + wList_p bl, + wIndex_t inx ) { listData * ldp; wListGetCount(bl); - if ( inx < 0 || inx >= bl->count ) return NULL; + if ( inx < 0 || inx >= bl->count ) { return NULL; } ldp = (listData*)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - (WPARAM)inx, (LPARAM)0 ); + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (WPARAM)inx, (LPARAM)0 ); return ((ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL); } wBool_t wListGetItemSelected( - wList_p bl, - wIndex_t inx ) + wList_p bl, + wIndex_t inx ) { listData * ldp; wListGetCount(bl); - if ( inx < 0 || inx >= bl->count ) return FALSE; + if ( inx < 0 || inx >= bl->count ) { return FALSE; } ldp = (listData*)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - (WPARAM)inx, (LPARAM)0 ); + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (WPARAM)inx, (LPARAM)0 ); return ((ldp&&ldp!=(void*)LB_ERR)?ldp->selected:FALSE); } wIndex_t wListGetSelectedCount( - wList_p bl ) + wList_p bl ) { wIndex_t selcnt, inx; wListGetCount(bl); for ( selcnt=inx=0; inx<bl->count; inx++ ) - if ( wListGetItemSelected( bl, inx ) ) + if ( wListGetItemSelected( bl, inx ) ) { selcnt++; + } return selcnt; } @@ -371,10 +385,10 @@ wIndex_t wListGetSelectedCount( wIndex_t wListAddValue( - wList_p b, - const char * value, - wIcon_p bm, - void * itemContext ) + wList_p b, + const char * value, + wIcon_p bm, + void * itemContext ) { int nindex; listData * ldp; @@ -382,106 +396,116 @@ wIndex_t wListAddValue( ldp->itemContext = itemContext; ldp->bm = bm; ldp->selected = FALSE; - if ( value == NULL ) + if ( value == NULL ) { value = ""; + } b->count++; nindex = (int)SendMessage( - b->hWnd, - (UINT)b->type==B_LIST?LB_ADDSTRING:CB_ADDSTRING, - (WPARAM)0, - (LPARAM)value ); + b->hWnd, + (UINT)b->type==B_LIST?LB_ADDSTRING:CB_ADDSTRING, + (WPARAM)0, + (LPARAM)value ); if (nindex == 0) { SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, - (WPARAM)nindex, - (LPARAM)0 ); + (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, + (WPARAM)nindex, + (LPARAM)0 ); b->last = 0; } SendMessage( b->hWnd, - (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, - (WPARAM)nindex, - (LPARAM)ldp ); + (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, + (WPARAM)nindex, + (LPARAM)ldp ); return nindex; } int wListGetColumnWidths( - wList_p bl, - int colCnt, - wWinPix_t * colWidths ) + wList_p bl, + int colCnt, + wWinPix_t * colWidths ) { wIndex_t inx; - if ( bl->type != B_LIST ) + if ( bl->type != B_LIST ) { return 0; - if ( bl->colWidths == NULL ) + } + if ( bl->colWidths == NULL ) { return 0; + } for ( inx=0; inx<colCnt; inx++ ) { - if ( inx < bl->colCnt ) + if ( inx < bl->colCnt ) { colWidths[inx] = bl->colWidths[inx]; - else + } else { colWidths[inx] = 0; + } } return bl->colCnt; } static void listSetBusy( - wControl_p b, - BOOL_T busy) + wControl_p b, + BOOL_T busy) { wList_p bl = (wList_p)b; EnableWindow( bl->hWnd, !(BOOL)busy ); - if ( bl->hScrollWnd ) + if ( bl->hScrollWnd ) { EnableWindow( bl->hScrollWnd, !(BOOL)busy ); + } } static void listShow( - wControl_p b, - BOOL_T show) + wControl_p b, + BOOL_T show) { wList_p bl = (wList_p)b; ShowWindow( bl->hWnd, show?SW_SHOW:SW_HIDE ); - if ( bl->hScrollWnd && bl->maxWidth > bl->w ) + if ( bl->hScrollWnd && bl->maxWidth > bl->w ) { ShowWindow( bl->hScrollWnd, show?SW_SHOW:SW_HIDE ); + } #ifdef SHOW_DOES_SETFOCUS - if ( show && (bl->option&BO_READONLY)==0 ) + if ( show && (bl->option&BO_READONLY)==0 ) { hWnd = SetFocus( bl->hWnd ); + } #endif } static void listSetPos( - wControl_p b, - wWinPix_t x, - wWinPix_t y ) + wControl_p b, + wWinPix_t x, + wWinPix_t y ) { wList_p bl = (wList_p)b; wWinPix_t x1, y1; RECT rect; - + bl->x = x1 = x; bl->y = y1 = y; - if ( bl->colTitles ) + if ( bl->colTitles ) { y1 += listTitleHeight; + } if (!SetWindowPos( b->hWnd, HWND_TOP, x1, y1, - CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOSIZE|SWP_NOZORDER)) - mswFail("listSetPos"); + CW_USEDEFAULT, CW_USEDEFAULT, + SWP_NOSIZE|SWP_NOZORDER)) { + mswFail("listSetPos"); + } if ( bl->hScrollWnd && bl->maxWidth > bl->w ) { GetClientRect( bl->hWnd, &rect ); if (!SetWindowPos( bl->hScrollWnd, HWND_TOP, x1, y1+rect.bottom+2, - CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOSIZE|SWP_NOZORDER)) - mswFail("listSetPos2"); + CW_USEDEFAULT, CW_USEDEFAULT, + SWP_NOSIZE|SWP_NOZORDER)) { + mswFail("listSetPos2"); + } } } static void listRepaintLabel( - HWND hWnd, - wControl_p b ) + HWND hWnd, + wControl_p b ) { wList_p bl = (wList_p)b; HDC hDc; @@ -495,8 +519,9 @@ static void listRepaintLabel( wWinPix_t colWidth; mswRepaintLabel( hWnd, b ); - if ( bl->colTitles == NULL ) + if ( bl->colTitles == NULL ) { return; + } hDc = GetDC( hWnd ); start = bl->x-bl->scrollPos+2; rc.top = bl->y; @@ -506,7 +531,7 @@ static void listRepaintLabel( hBrush = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) ); FillRect( hDc, &rc, hBrush ); SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) ); - + hFont = SelectObject( hDc, mswLabelFont ); hPen1 = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNTEXT ) ); hPen2 = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNHIGHLIGHT ) ); @@ -527,28 +552,31 @@ static void listRepaintLabel( LineTo( hDc, rc.right-1, rc.top+1 ); rc.top += 2; rc.bottom -= 1; - for ( inx=0,title=bl->colTitles; inx<bl->colCnt&&*title&&start<bl->x+bl->w; inx++ ) { + for ( inx=0,title=bl->colTitles; inx<bl->colCnt&&*title + &&start<bl->x+bl->w; inx++ ) { colWidth = bl->colWidths[inx]; if ( start+colWidth >= 3 ) { rc.left = start; - if ( rc.left < bl->x+2 ) + if ( rc.left < bl->x+2 ) { rc.left = bl->x+2; + } rc.right = start+colWidth; - if ( rc.right > bl->x+bl->w-1 ) + if ( rc.right > bl->x+bl->w-1 ) { rc.right = bl->x+bl->w-1; + } ExtTextOut( hDc, start+1, rc.top+0, - ETO_CLIPPED|ETO_OPAQUE, &rc, - *title, (int)(strlen(*title)), NULL ); + ETO_CLIPPED|ETO_OPAQUE, &rc, + *title, (int)(strlen(*title)), NULL ); if ( start-bl->x >= 3 ) { - SelectObject( hDc, hPen1 ); - MoveTo( hDc, start-1, rc.top-1 ); - LineTo( hDc, start-1, rc.bottom+3 ); - SelectObject( hDc, hPen2 ); - MoveTo( hDc, start, rc.top ); - LineTo( hDc, start, rc.bottom+1 ); - SelectObject( hDc, hPen3 ); - MoveTo( hDc, start-2, rc.top ); - LineTo( hDc, start-2, rc.bottom+1 ); + SelectObject( hDc, hPen1 ); + MoveTo( hDc, start-1, rc.top-1 ); + LineTo( hDc, start-1, rc.bottom+3 ); + SelectObject( hDc, hPen2 ); + MoveTo( hDc, start, rc.top ); + LineTo( hDc, start, rc.bottom+1 ); + SelectObject( hDc, hPen3 ); + MoveTo( hDc, start-2, rc.top ); + LineTo( hDc, start-2, rc.bottom+1 ); } } title++; @@ -581,12 +609,12 @@ static void listHandleFocusState( LPDRAWITEMSTRUCT lpdis, LPRECT rc ) LRESULT listProc( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) -{ + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) +{ wList_p bl = (wList_p)b; int cnt, inx, selected; size_t len; @@ -607,345 +635,380 @@ LRESULT listProc( COLORREF col; if (bl) switch( message ) { - - case WM_COMMAND: - notification = WCMD_PARAM_NOTF; - switch (bl->type) { - case B_LIST: - switch (notification) { - case LBN_SELCHANGE: - case LBN_DBLCLK: - if ( (bl->option&BL_DBLCLICK)!=0 ? - notification!=LBN_DBLCLK : - notification==LBN_DBLCLK ) - break; - if ( (bl->option&BL_MANY) ) { - wListGetCount(bl); - for ( inx=0; inx<bl->count; inx++ ) { - 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, (WPARAM)inx, (LPARAM)0 ) != 0L ); - if ( selected != ldp->selected ) { - ldp->selected = selected; - if ( selected ) { - bl->last = inx; - cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last, (LPARAM)mswTmpBuff ); - mswTmpBuff[cnt] = '\0'; - } else { - mswTmpBuff[0] = '\0'; + + case WM_COMMAND: + notification = WCMD_PARAM_NOTF; + switch (bl->type) { + case B_LIST: + switch (notification) { + case LBN_SELCHANGE: + case LBN_DBLCLK: + if ( (bl->option&BL_DBLCLICK)!=0 ? + notification!=LBN_DBLCLK : + notification==LBN_DBLCLK ) { + break; + } + if ( (bl->option&BL_MANY) ) { + wListGetCount(bl); + for ( inx=0; inx<bl->count; inx++ ) { + 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, (WPARAM)inx, + (LPARAM)0 ) != 0L ); + if ( selected != ldp->selected ) { + ldp->selected = selected; + if ( selected ) { + bl->last = inx; + cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last, + (LPARAM)mswTmpBuff ); + mswTmpBuff[cnt] = '\0'; + } else { + mswTmpBuff[0] = '\0'; + } + if ( bl->action ) { + bl->action( inx, mswTmpBuff, selected?1:2, bl->data, ldp->itemContext ); + } + if ( selected && bl->valueP ) { + *bl->valueP = bl->last; + } + } } - if ( bl->action ) - bl->action( inx, mswTmpBuff, selected?1:2, bl->data, ldp->itemContext ); - if ( selected && bl->valueP ) - *bl->valueP = bl->last; } + } else { + 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, + (WPARAM)bl->last, (LPARAM)0 ); + bl->action( bl->last, mswTmpBuff, 1, bl->data, + ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) ); + } + if (bl->valueP) { + *bl->valueP = bl->last; + } + } + break; + + case LBN_KILLFOCUS: + if ( ( bl->option&BL_MANY ) == 0 && + 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; + + case B_DROPLIST: + case B_COMBOLIST: + switch (notification) { + case CBN_SELCHANGE: + case CBN_DBLCLK: + if ( (bl->type == B_DROPLIST) || + ( (bl->option&BL_DBLCLICK)!=0 ? + notification!=CBN_DBLCLK : + notification==CBN_DBLCLK) ) { + break; } + + case CBN_CLOSEUP: + bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); + if (bl->last < 0) { + break; } - } else { - 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, - (WPARAM)bl->last, (LPARAM)0 ); + cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT, + (WPARAM)bl->last, (LPARAM)mswTmpBuff ); + ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA, + (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) ); + ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) ); } if (bl->valueP) { *bl->valueP = bl->last; } - } - break; - - case LBN_KILLFOCUS: - if ( ( bl->option&BL_MANY ) == 0 && - 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; - - case B_DROPLIST: - case B_COMBOLIST: - switch (notification) { - case CBN_SELCHANGE: - case CBN_DBLCLK: - if ( (bl->type == B_DROPLIST) || - ( (bl->option&BL_DBLCLICK)!=0 ? - notification!=CBN_DBLCLK : - notification==CBN_DBLCLK) ) + mswAllowBalloonHelp = TRUE; + /*SendMessage( bl->bWnd, CB_SETCURSEL, bl->last, 0L );*/ break; - case CBN_CLOSEUP: - bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); - if (bl->last < 0) + case CBN_KILLFOCUS: + inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); + if ( bl->last != inx ) { + (void)SendMessage( bl->hWnd, CB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 ); + } break; - if (bl->action) { - cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT, - (WPARAM)bl->last, (LPARAM)mswTmpBuff ); - ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA, - (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) ); - } - if (bl->valueP) { - *bl->valueP = bl->last; - } - mswAllowBalloonHelp = TRUE; - /*SendMessage( bl->bWnd, CB_SETCURSEL, bl->last, 0L );*/ - break; - case CBN_KILLFOCUS: - inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); - if ( bl->last != inx ) - (void)SendMessage( bl->hWnd, CB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 ); - break; - - case CBN_DROPDOWN: - mswAllowBalloonHelp = FALSE; - break; + case CBN_DROPDOWN: + mswAllowBalloonHelp = FALSE; + break; - case CBN_EDITCHANGE: - bl->last = -1; - if (bl->action) { - cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, (WPARAM)sizeof mswTmpBuff, - (LPARAM)mswTmpBuff ); - mswTmpBuff[cnt] = '\0'; - bl->action( -1, mswTmpBuff, 1, bl->data, NULL ); + case CBN_EDITCHANGE: + bl->last = -1; + if (bl->action) { + cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, (WPARAM)sizeof mswTmpBuff, + (LPARAM)mswTmpBuff ); + mswTmpBuff[cnt] = '\0'; + bl->action( -1, mswTmpBuff, 1, bl->data, NULL ); + } + break; } break; } break; - } - break; - case WM_MEASUREITEM: - lpmis = (LPMEASUREITEMSTRUCT)lParam; - hDc = GetDC( hWnd ); - if ( bl->type == B_LIST ) - hFont = SelectObject( hDc, mswLabelFont ); - GetTextMetrics( hDc, &tm ); - lpmis->itemHeight = tm.tmHeight; - if ( bl->type == B_LIST ) - SelectObject( hDc, hFont ); - ReleaseDC( hWnd, hDc ); - break; + case WM_MEASUREITEM: + lpmis = (LPMEASUREITEMSTRUCT)lParam; + hDc = GetDC( hWnd ); + if ( bl->type == B_LIST ) { + hFont = SelectObject( hDc, mswLabelFont ); + } + GetTextMetrics( hDc, &tm ); + lpmis->itemHeight = tm.tmHeight; + if ( bl->type == B_LIST ) { + SelectObject( hDc, hFont ); + } + ReleaseDC( hWnd, hDc ); + break; - case WM_DRAWITEM: - lpdis = (LPDRAWITEMSTRUCT)lParam; - if (lpdis->itemID == -1) { - listHandleFocusState(lpdis, &lpdis->rcItem); - return TRUE; - } - ldp = (listData*)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - (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), - (WPARAM)lpdis->itemID, (LPARAM)mswTmpBuff ); - mswTmpBuff[cnt] = '\0'; - if ( lpdis->itemState & ODS_SELECTED ) { - SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); - SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) ); - } else { - SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) ); - SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) ); + case WM_DRAWITEM: + lpdis = (LPDRAWITEMSTRUCT)lParam; + if (lpdis->itemID == -1) { + listHandleFocusState(lpdis, &lpdis->rcItem); + return TRUE; } - rc1 = rc; - rc1.left -= bl->scrollPos; - for ( inx=0,cp0=mswTmpBuff; inx<bl->colCnt&&cp0&&rc1.left<rc.right; inx++ ) { - if ( inx>=bl->colCnt-1 || (cp1=strchr(cp0,'\t')) == NULL ) { - len = strlen( cp0 ); - cp1=cp0 + len; // JBB, to avoid an MSC error below where cp1 has not been defined. - } else { - len = cp1-cp0; - cp1 ++; + ldp = (listData*)SendMessage( bl->hWnd, + (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), + (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 ); } - if ( bl->colWidths ) { - colWidth = bl->colWidths[inx]; + cnt = (int)SendMessage( lpdis->hwndItem, + (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), + (WPARAM)lpdis->itemID, (LPARAM)mswTmpBuff ); + mswTmpBuff[cnt] = '\0'; + if ( lpdis->itemState & ODS_SELECTED ) { + SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); + SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) ); } else { - colWidth = rc.right; + SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) ); + SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) ); } - if ( inx == 0 && ldp && ldp!=(void*)LB_ERR && ldp->bm ) { - if (mswPalette) { - SelectPalette( lpdis->hDC, mswPalette, 0 ); - cnt = RealizePalette( lpdis->hDC ); + rc1 = rc; + rc1.left -= bl->scrollPos; + for ( inx=0,cp0=mswTmpBuff; inx<bl->colCnt&&cp0&&rc1.left<rc.right; inx++ ) { + if ( inx>=bl->colCnt-1 || (cp1=strchr(cp0,'\t')) == NULL ) { + len = strlen( cp0 ); + cp1=cp0 + len; // JBB, to avoid an MSC error below where cp1 has not been defined. + } else { + len = cp1-cp0; + cp1 ++; + } + if ( bl->colWidths ) { + colWidth = bl->colWidths[inx]; + } else { + colWidth = rc.right; + } + if ( inx == 0 && ldp && ldp!=(void*)LB_ERR && ldp->bm ) { + if (mswPalette) { + SelectPalette( lpdis->hDC, mswPalette, 0 ); + cnt = RealizePalette( lpdis->hDC ); + } + hPen = SelectObject( lpdis->hDC, CreatePen( PS_SOLID, 0, + GetSysColor( COLOR_WINDOW ) ) ); + hBrush = SelectObject( lpdis->hDC, + CreateSolidBrush( GetSysColor( COLOR_WINDOW ) ) ); + Rectangle( lpdis->hDC, rc1.left, rc1.top, rc1.right, rc1.bottom ); + DeleteObject( SelectObject( lpdis->hDC, hPen ) ); + DeleteObject( SelectObject( lpdis->hDC, hBrush ) ); + + col = RGB( (ldp->bm->colormap[ 1 ]).rgbRed, + (ldp->bm->colormap[ 1 ]).rgbGreen, + (ldp->bm->colormap[ 1 ]).rgbBlue ); + mswDrawIcon( lpdis->hDC, rc1.left+2, rc.top+0, ldp->bm, 0, col, col); + + rc1.left += ldp->bm->w+6; + colWidth -= ldp->bm->w+6; } - hPen = SelectObject( lpdis->hDC, CreatePen( PS_SOLID, 0, GetSysColor( COLOR_WINDOW ) ) ); - hBrush = SelectObject( lpdis->hDC, CreateSolidBrush( GetSysColor( COLOR_WINDOW ) ) ); - Rectangle( lpdis->hDC, rc1.left, rc1.top, rc1.right, rc1.bottom ); - DeleteObject( SelectObject( lpdis->hDC, hPen ) ); - DeleteObject( SelectObject( lpdis->hDC, hBrush ) ); - - col = RGB( (ldp->bm->colormap[ 1 ]).rgbRed, - (ldp->bm->colormap[ 1 ]).rgbGreen, - (ldp->bm->colormap[ 1 ]).rgbBlue ); - mswDrawIcon( lpdis->hDC, rc1.left+2, rc.top+0, ldp->bm, 0, col, col); - - rc1.left += ldp->bm->w+6; - colWidth -= ldp->bm->w+6; + if ( inx>=bl->colCnt-1 || (rc1.right = rc1.left + colWidth) > rc.right ) { + rc1.right = rc.right; + } + if ( rc1.right > 0 && rc1.left+3 < rc.right ) { + ExtTextOut( lpdis->hDC, rc1.left+3, rc1.top+1, + ETO_CLIPPED | ETO_OPAQUE, &rc1, + (LPSTR)cp0, (int)len, NULL ); + } + rc1.left = rc1.right; + cp0 = cp1; } - if ( inx>=bl->colCnt-1 || (rc1.right = rc1.left + colWidth) > rc.right ) - rc1.right = rc.right; - if ( rc1.right > 0 && rc1.left+3 < rc.right ) { - ExtTextOut( lpdis->hDC, rc1.left+3, rc1.top+1, - ETO_CLIPPED | ETO_OPAQUE, &rc1, - (LPSTR)cp0, (int)len, NULL ); + if ( lpdis->itemState & ODS_SELECTED ) { + SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) ); + SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) ); } - rc1.left = rc1.right; - cp0 = cp1; - } - if ( lpdis->itemState & ODS_SELECTED ) { - SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) ); - SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) ); - } - if (lpdis->itemState & ODS_FOCUS) { - DrawFocusRect( lpdis->hDC, &rc ); + if (lpdis->itemState & ODS_FOCUS) { + DrawFocusRect( lpdis->hDC, &rc ); + } + if ( bl->type == B_LIST) { + SelectObject( lpdis->hDC, hFont ); + } + return (LRESULT)TRUE; } - if ( bl->type == B_LIST) - SelectObject( lpdis->hDC, hFont ); - return (LRESULT)TRUE; - } - - break; - case WM_HSCROLL: - len = ((long)bl->maxWidth)-((long)bl->w); - if ( len <= 0 ) - return (LRESULT)0; - switch ( WSCROLL_PARAM_CODE ) { - case SB_LEFT: - if ( bl->scrollPos == 0 ) - return (LRESULT)0; - bl->scrollPos = 0; break; - case SB_LINELEFT: - case SB_PAGELEFT: - if ( bl->scrollPos == 0 ) + + case WM_HSCROLL: + len = ((long)bl->maxWidth)-((long)bl->w); + if ( len <= 0 ) { return (LRESULT)0; - for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { - if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) { - bl->scrollPos = colWidth; - break; - } - colWidth += bl->colWidths[inx]; } - break; - case SB_LINERIGHT: - case SB_PAGERIGHT: - if ( bl->scrollPos >= len ) - return (LRESULT)0; - for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { - if ( colWidth >= bl->scrollPos ) { - bl->scrollPos = colWidth+bl->colWidths[inx]; - break; + switch ( WSCROLL_PARAM_CODE ) { + case SB_LEFT: + if ( bl->scrollPos == 0 ) { + return (LRESULT)0; } - colWidth += bl->colWidths[inx]; - } - break; - case SB_RIGHT: - if ( bl->scrollPos >= len ) + bl->scrollPos = 0; + break; + case SB_LINELEFT: + case SB_PAGELEFT: + if ( bl->scrollPos == 0 ) { + return (LRESULT)0; + } + for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { + if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) { + bl->scrollPos = colWidth; + break; + } + colWidth += bl->colWidths[inx]; + } + break; + case SB_LINERIGHT: + case SB_PAGERIGHT: + if ( bl->scrollPos >= len ) { + return (LRESULT)0; + } + for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { + if ( colWidth >= bl->scrollPos ) { + bl->scrollPos = colWidth+bl->colWidths[inx]; + break; + } + colWidth += bl->colWidths[inx]; + } + break; + case SB_RIGHT: + if ( bl->scrollPos >= len ) { + return (LRESULT)0; + } + bl->scrollPos = (int)len; + break; + case SB_THUMBTRACK: return (LRESULT)0; - bl->scrollPos = (int)len; - break; - case SB_THUMBTRACK: + case SB_THUMBPOSITION: + nPos = (int)WSCROLL_PARAM_NPOS; + bl->scrollPos = (int)(len*nPos/100); + break; + case SB_ENDSCROLL: + return (LRESULT)0; + } + if ( bl->scrollPos > len ) { bl->scrollPos = (int)len; } + if ( bl->scrollPos < 0 ) { bl->scrollPos = 0; } + nPos = (int)(((long)bl->scrollPos)*100L/len+0.5); + SetScrollPos( bl->hScrollWnd, SB_CTL, nPos, TRUE ); + InvalidateRect( bl->hWnd, NULL, FALSE ); + listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); return (LRESULT)0; - case SB_THUMBPOSITION: - nPos = (int)WSCROLL_PARAM_NPOS; - bl->scrollPos = (int)(len*nPos/100); - break; - case SB_ENDSCROLL: + + case WM_LBUTTONDOWN: + if ( bl->type != B_LIST ) { + break; + } + if ( bl->colCnt <= 1 ) { + break; + } + x = bl->dragPos = LOWORD(lParam)+bl->scrollPos-4; + bl->dragCol = -1; + for ( inx=0; inx<bl->colCnt; inx++ ) { + x -= bl->colWidths[inx]; + if ( x < -5 ) { break; } + if ( x <= 0 ) { bl->dragCol = inx; break; } + if ( x > bl->colWidths[inx+1] ) { continue; } + if ( x <= 10 ) { bl->dragCol = inx; break; } + } + if ( bl->dragCol >= 0 ) { + bl->dragColWidth = bl->colWidths[inx]; + } return (LRESULT)0; - } - if ( bl->scrollPos > len ) bl->scrollPos = (int)len; - if ( bl->scrollPos < 0 ) bl->scrollPos = 0; - nPos = (int)(((long)bl->scrollPos)*100L/len+0.5); - SetScrollPos( bl->hScrollWnd, SB_CTL, nPos, TRUE ); - InvalidateRect( bl->hWnd, NULL, FALSE ); - listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); - return (LRESULT)0; - - case WM_LBUTTONDOWN: - if ( bl->type != B_LIST ) - break; - if ( bl->colCnt <= 1 ) - break; - x = bl->dragPos = LOWORD(lParam)+bl->scrollPos-4; - bl->dragCol = -1; - for ( inx=0; inx<bl->colCnt; inx++ ) { - x -= bl->colWidths[inx]; - if ( x < -5 ) break; - if ( x <= 0 ) { bl->dragCol = inx; break; } - if ( x > bl->colWidths[inx+1] ) continue; - if ( x <= 10 ) { bl->dragCol = inx; break; } - } - if ( bl->dragCol >= 0 ) - bl->dragColWidth = bl->colWidths[inx]; - return (LRESULT)0; #ifdef LATER - case WM_MOUSEMOVE: - if ( (wParam&MK_LBUTTON) == 0 ) - break; - if ( bl->type != B_LIST ) - break; - if ( bl->colCnt <= 1 ) - break; - x = LOWORD(lParam)+bl->scrolPos; - for ( inx=0; inx<bl->colCnt; inx++ ) { - x -= bl->colWidths[inx]; - if ( x <= 0 ) + case WM_MOUSEMOVE: + if ( (wParam&MK_LBUTTON) == 0 ) { break; - } - return (LRESULT)0; + } + if ( bl->type != B_LIST ) { + break; + } + if ( bl->colCnt <= 1 ) { + break; + } + x = LOWORD(lParam)+bl->scrolPos; + for ( inx=0; inx<bl->colCnt; inx++ ) { + x -= bl->colWidths[inx]; + if ( x <= 0 ) { + break; + } + } + return (LRESULT)0; #endif - case WM_MOUSEMOVE: - if ( (wParam&MK_LBUTTON) == 0 ) - break; - case WM_LBUTTONUP: - if ( bl->type != B_LIST ) - break; - if ( bl->colCnt <= 1 ) - break; - if ( bl->dragCol < 0 ) - break; - x = LOWORD(lParam)+bl->scrollPos-4-bl->dragPos; /* WIN32??? */ - bl->colWidths[bl->dragCol] = bl->dragColWidth+x; - if ( bl->colWidths[bl->dragCol] < 0 ) - bl->colWidths[bl->dragCol] = 0; - for ( bl->maxWidth=inx=0; inx<bl->colCnt; inx++ ) - bl->maxWidth += bl->colWidths[inx]; - if ( bl->maxWidth <= bl->w ) { - x = bl->w - bl->maxWidth; - bl->colWidths[bl->colCnt-1] += x; - bl->maxWidth = bl->w; - bl->scrollPos = 0; - } else { - if ( bl->scrollPos+bl->w > bl->maxWidth ) { - bl->scrollPos = bl->maxWidth - bl->w; + case WM_MOUSEMOVE: + if ( (wParam&MK_LBUTTON) == 0 ) { + break; + } + case WM_LBUTTONUP: + if ( bl->type != B_LIST ) { + break; + } + if ( bl->colCnt <= 1 ) { + break; } + if ( bl->dragCol < 0 ) { + break; + } + x = LOWORD(lParam)+bl->scrollPos-4-bl->dragPos; /* WIN32??? */ + bl->colWidths[bl->dragCol] = bl->dragColWidth+x; + if ( bl->colWidths[bl->dragCol] < 0 ) { + bl->colWidths[bl->dragCol] = 0; + } + for ( bl->maxWidth=inx=0; inx<bl->colCnt; inx++ ) { + bl->maxWidth += bl->colWidths[inx]; + } + if ( bl->maxWidth <= bl->w ) { + x = bl->w - bl->maxWidth; + bl->colWidths[bl->colCnt-1] += x; + bl->maxWidth = bl->w; + bl->scrollPos = 0; + } else { + if ( bl->scrollPos+bl->w > bl->maxWidth ) { + bl->scrollPos = bl->maxWidth - bl->w; + } + } + InvalidateRect( bl->hWnd, NULL, FALSE ); + listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); + return (LRESULT)0; + } - InvalidateRect( bl->hWnd, NULL, FALSE ); - listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); - return (LRESULT)0; - } - return DefWindowProc( hWnd, message, wParam, lParam ); -} +} LRESULT FAR PASCAL _export pushList( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ wIndex_t inx = (wIndex_t)GetWindowLongPtr(hWnd, GWL_ID); @@ -962,9 +1025,9 @@ LRESULT FAR PASCAL _export pushList( case 0x0D: case 0x1B: case 0x09: - SetFocus( ((wControl_p)(b->parent))->hWnd ); + SetFocus( ((wControl_p)(b->parent))->hWnd ); SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR, - wParam, lParam ); + wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ return (LRESULT)0; @@ -976,10 +1039,10 @@ LRESULT FAR PASCAL _export pushList( } LRESULT FAR PASCAL _export pushCombo( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); @@ -992,9 +1055,9 @@ LRESULT FAR PASCAL _export pushCombo( case 0x0D: case 0x1B: case 0x09: - SetFocus( ((wControl_p)(b->parent))->hWnd ); + SetFocus( ((wControl_p)(b->parent))->hWnd ); SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR, - wParam, lParam ); + wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ return (LRESULT)0; @@ -1006,37 +1069,39 @@ LRESULT FAR PASCAL _export pushCombo( } static callBacks_t listCallBacks = { - listRepaintLabel, - NULL, - listProc, - listSetBusy, - listShow, - listSetPos }; + listRepaintLabel, + NULL, + listProc, + listSetBusy, + listShow, + listSetPos +}; static wList_p listCreate( - int typ, - const char *className, - long style, - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - long number, - wWinPix_t width, - long *valueP, - wListCallBack_p action, - void *data, - wBool_t addFocus, - int *indexR ) -{ + int typ, + const char *className, + long style, + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + long number, + wWinPix_t width, + long *valueP, + wListCallBack_p action, + void *data, + wBool_t addFocus, + int *indexR ) +{ wList_p b; - RECT rect; + RECT rect; int index; - b = (wList_p)mswAlloc( parent, typ, mswStrdup(labelStr), sizeof *b, data, &index ); + b = (wList_p)mswAlloc( parent, typ, mswStrdup(labelStr), sizeof *b, data, + &index ); mswComputePos( (wControl_p)b, x, y ); b->option = option; b->count = 0; @@ -1051,9 +1116,9 @@ static wList_p listCreate( b->dragCol = -1; 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)(UINT_PTR)index, mswHInst, NULL ); + style | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x, b->y, + width, LIST_HEIGHT*(int)number, + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(LIST)"); return b; @@ -1078,8 +1143,7 @@ static wList_p listCreate( oldListProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC); SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newListProc); #endif - } - else { + } else { newComboProc = MakeProcInstance((XWNDPROC)pushCombo, mswHInst); oldComboProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newComboProc); @@ -1089,31 +1153,32 @@ static wList_p listCreate( #endif } } - if ( indexR ) + if ( indexR ) { *indexR = index; - if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); + } + + SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); return b; } wList_p wListCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - long number, - wWinPix_t width, - int colCnt, - wWinPix_t * colWidths, - wBool_t * colRightJust, - const char * * colTitles, - long *valueP, - wListCallBack_p action, - void *data ) -{ + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + long number, + wWinPix_t width, + int colCnt, + wWinPix_t * colWidths, + wBool_t * colRightJust, + const char * * colTitles, + long *valueP, + wListCallBack_p action, + void *data ) +{ long bs; wList_p bl; static int dbu = 0; @@ -1122,22 +1187,25 @@ wList_p wListCreate( int i; bs = LBS_NOTIFY | WS_VSCROLL | WS_BORDER | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS; - if (option & BL_MANY) + if (option & BL_MANY) { bs |= LBS_MULTIPLESEL|LBS_EXTENDEDSEL; - if (option & BL_SORT) + } + if (option & BL_SORT) { bs |= LBS_SORT; - if ( colCnt > 1 ) + } + if ( colCnt > 1 ) { bs |= WS_HSCROLL; + } if ( colTitles ) { y += listTitleHeight; number -= 1; } bl = listCreate( B_LIST, "LISTBOX", bs, parent, x, y, helpStr, - labelStr, option, number, width, valueP, action, data, TRUE, &index ); + labelStr, option, number, width, valueP, action, data, TRUE, &index ); if ( colTitles ) { bl->y -= listTitleHeight; bl->h += listTitleHeight; - } + } if ( colCnt > 1 ) { bl->colCnt = colCnt; bl->colWidths = (wWinPix_t*)malloc( colCnt * sizeof *bl->colWidths ); @@ -1150,11 +1218,13 @@ wList_p wListCreate( bl->maxWidth += bl->colWidths[i]; } 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)(UINT_PTR)index, mswHInst, NULL ); - if (bl->hScrollWnd == NULL) + SBS_HORZ | SBS_BOTTOMALIGN | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), + bl->x, bl->y, + width, CW_USEDEFAULT, + ((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 ); GetWindowRect( bl->hScrollWnd, &rect ); bl->scrollH = rect.bottom - rect.top+2; @@ -1164,49 +1234,52 @@ wList_p wListCreate( wList_p wDropListCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - long number, - wWinPix_t width, - long *valueP, - wListCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + long number, + wWinPix_t width, + long *valueP, + wListCallBack_p action, + void *data ) { long bs; - if ( (option&BL_EDITABLE) != 0 ) + if ( (option&BL_EDITABLE) != 0 ) { bs = CBS_DROPDOWN; - else + } else { bs = CBS_DROPDOWNLIST; + } bs |= WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS; - if (option & BL_SORT) + if (option & BL_SORT) { bs |= CBS_SORT; + } return listCreate( B_DROPLIST, "COMBOBOX", bs, parent, x, y, helpStr, - labelStr, option, number, width, valueP, action, data, TRUE, NULL ); + labelStr, option, number, width, valueP, action, data, TRUE, NULL ); } wList_p wComboListCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - long number, - wWinPix_t width, - long *valueP, - wListCallBack_p action, - void *data ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + long number, + wWinPix_t width, + long *valueP, + wListCallBack_p action, + void *data ) { long bs; bs = CBS_SIMPLE | WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS; - if (option & BL_SORT) + if (option & BL_SORT) { bs |= CBS_SORT; + } return listCreate( B_COMBOLIST, "COMBOBOX", bs, parent, x, y, helpStr, - labelStr, option, number, width, valueP, action, data, FALSE, NULL ); + labelStr, option, number, width, valueP, action, data, FALSE, NULL ); } diff --git a/app/wlib/mswlib/mswmenu.c b/app/wlib/mswlib/mswmenu.c index 9e36c8b..0a2851d 100644 --- a/app/wlib/mswlib/mswmenu.c +++ b/app/wlib/mswlib/mswmenu.c @@ -18,14 +18,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define OEMRESOURCE #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -48,8 +47,8 @@ typedef enum { MM_BUTT, MM_MENU, MM_BAR, MM_POPUP } mmtype_e; typedef struct wMenuItem_t * wMenuItem_p; struct radioButtonGroup { - int firstButton; /* id of first button in group */ - int lastButton; /* id of last button in group */ + int firstButton; /* id of first button in group */ + int lastButton; /* id of last button in group */ }; /* NOTE: first field must be the same as WOBJ_COMMON */ @@ -61,58 +60,58 @@ struct radioButtonGroup { wMenuItem_p mnext; struct wMenuItem_t { - MOBJ_COMMON - }; + MOBJ_COMMON +}; struct wMenu_t { - MOBJ_COMMON - mmtype_e mmtype; - wMenuItem_p first, last; - struct radioButtonGroup *radioGroup; - HMENU menu; - wButton_p button; - wMenuTraceCallBack_p traceFunc; - void * traceData; - }; + MOBJ_COMMON + mmtype_e mmtype; + wMenuItem_p first, last; + struct radioButtonGroup *radioGroup; + HMENU menu; + wButton_p button; + wMenuTraceCallBack_p traceFunc; + void * traceData; +}; struct wMenuPush_t { - MOBJ_COMMON - wMenu_p mparent; - wMenuCallBack_p action; - long acclKey; - wBool_t enabled; - }; + MOBJ_COMMON + wMenu_p mparent; + wMenuCallBack_p action; + long acclKey; + wBool_t enabled; +}; struct wMenuRadio_t { - MOBJ_COMMON - wMenu_p mparent; - wMenuCallBack_p action; - long acclKey; - wBool_t enabled; - }; + MOBJ_COMMON + wMenu_p mparent; + wMenuCallBack_p action; + long acclKey; + wBool_t enabled; +}; struct wMenuToggle_t { - MOBJ_COMMON - wMenu_p mparent; - wMenuCallBack_p action; - long acclKey; - wBool_t enabled; - }; + MOBJ_COMMON + wMenu_p mparent; + wMenuCallBack_p action; + long acclKey; + wBool_t enabled; +}; typedef struct wMenuListItem_t * wMenuListItem_p; struct wMenuList_t { - MOBJ_COMMON - wMenuListItem_p left, right; - wMenu_p mlparent; - int max; - int count; - wMenuListCallBack_p action; - }; + MOBJ_COMMON + wMenuListItem_p left, right; + wMenu_p mlparent; + int max; + int count; + wMenuListCallBack_p action; +}; struct wMenuListItem_t { - MOBJ_COMMON - wMenuListItem_p left, right; - wMenuListCallBack_p action; - }; + MOBJ_COMMON + wMenuListItem_p left, right; + wMenuListCallBack_p action; +}; #define UNCHECK (0) #define CHECK (1) @@ -139,17 +138,18 @@ char * mswStrdup( const char * str ) if (str) { ret = (char*)malloc( strlen(str)+1 ); strcpy( ret, str ); - } else + } else { ret = NULL; + } return ret; } static LRESULT menuPush( - wControl_p b, - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam ) + wControl_p b, + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam ) { wMenuItem_p m = (wMenuItem_p)b; wBool_t set; @@ -165,29 +165,34 @@ static LRESULT menuPush( mswFail( "pushMenu" ); break; case M_PUSH: - if (((wMenuPush_p)m)->action) + if (((wMenuPush_p)m)->action) { ((wMenuPush_p)m)->action(((wMenuPush_p)m)->data); + } break; case M_TOGGLE: set = wMenuToggleGet((wMenuToggle_p)m); set = !set; wMenuToggleSet((wMenuToggle_p)m,set); - if (((wMenuToggle_p)m)->action) + if (((wMenuToggle_p)m)->action) { ((wMenuToggle_p)m)->action(((wMenuPush_p)m)->data); + } break; case M_LISTITEM: - if (((wMenuListItem_p)m)->action) + if (((wMenuListItem_p)m)->action) { ((wMenuListItem_p)m)->action(0, "", ((wMenuListItem_p)m)->data); + } break; case M_RADIO: - if (((wMenuRadio_p)m)->action) + if (((wMenuRadio_p)m)->action) { ((wMenuRadio_p)m)->action(((wMenuRadio_p)m)->data); + } break; } return (LRESULT)0; } if ( (m->parentMenu)->traceFunc ) { - (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, ((wMenu_p)m->parentMenu)->traceData ); + (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, + ((wMenu_p)m->parentMenu)->traceData ); } return DefWindowProc( hWnd, message, wParam, lParam ); } @@ -198,24 +203,26 @@ static void menuDone( wControl_p b ) switch ( m->mtype ) { case M_MENU: if ( ((wMenu_p)m)->mmtype == MM_BUTT || - ((wMenu_p)m)->mmtype == MM_POPUP ) + ((wMenu_p)m)->mmtype == MM_POPUP ) { DestroyMenu( ((wMenu_p)m)->menu ); + } break; } } static callBacks_t menuItemCallBacks = { - NULL, - menuDone, - menuPush }; + NULL, + menuDone, + menuPush +}; static wMenuItem_p createMenuItem( - wMenu_p m, - mtype_e mtype, - const char * helpStr, - const char * labelStr, - int size ) + wMenu_p m, + mtype_e mtype, + const char * helpStr, + const char * labelStr, + int size ) { wMenuItem_p mi; @@ -254,29 +261,31 @@ static wMenuItem_p createMenuItem( typedef struct { - long acclKey; - wMenuPush_p mp; - wAccelKeyCallBack_p action; - wAccelKey_e key; - void * data; - } acclTable_t, *acclTable_p; + long acclKey; + wMenuPush_p mp; + wAccelKeyCallBack_p action; + wAccelKey_e key; + void * data; +} acclTable_t, *acclTable_p; static dynArr_t acclTable_da; #define acclTable(N) DYNARR_N( acclTable_t, acclTable_da, N ) int mswMenuAccelerator( - wWin_p win, - long acclKey ) + wWin_p win, + long acclKey ) { acclTable_p at; if ( ((wControl_p)win)->type != W_MAIN && - ((wControl_p)win)->type != W_POPUP ) + ((wControl_p)win)->type != W_POPUP ) { return 0; + } for ( at = &acclTable(0); at<&acclTable(acclTable_da.cnt); at++ ) { if (at->acclKey == acclKey) { if (at->mp) { - if (at->mp->enabled && at->mp->action) + if (at->mp->enabled && at->mp->action) { at->mp->action(at->mp->data); + } return 1; } else if (at->action) { at->action( at->key, at->data ); @@ -292,40 +301,40 @@ int mswMenuAccelerator( static long acclKeyMap[] = { - 0, /* wAccelKey_None, */ - VK_DELETE, /* wAccelKey_Del, */ - VK_INSERT, /* wAccelKey_Ins, */ - VK_HOME, /* wAccelKey_Home, */ - VK_END, /* wAccelKey_End, */ - VK_PRIOR, /* wAccelKey_Pgup, */ - VK_NEXT, /* wAccelKey_Pgdn, */ - VK_UP, /* wAccelKey_Up, */ - VK_DOWN, /* wAccelKey_Down, */ - VK_RIGHT, /* wAccelKey_Right, */ - VK_LEFT, /* wAccelKey_Left, */ - VK_BACK, /* wAccelKey_Back, */ - VK_F1, /* wAccelKey_F1, */ - VK_F2, /* wAccelKey_F2, */ - VK_F3, /* wAccelKey_F3, */ - VK_F4, /* wAccelKey_F4, */ - VK_F5, /* wAccelKey_F5, */ - VK_F6, /* wAccelKey_F6, */ - VK_F7, /* wAccelKey_F7, */ - VK_F8, /* wAccelKey_F8, */ - VK_F9, /* wAccelKey_F9, */ - VK_F10, /* wAccelKey_F10, */ - VK_F11, /* wAccelKey_F11, */ - VK_F12, /* wAccelKey_F12, */ - VK_ADD, /* wAccelKey_Numpad_Add, */ - VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */ - }; + 0, /* wAccelKey_None, */ + VK_DELETE, /* wAccelKey_Del, */ + VK_INSERT, /* wAccelKey_Ins, */ + VK_HOME, /* wAccelKey_Home, */ + VK_END, /* wAccelKey_End, */ + VK_PRIOR, /* wAccelKey_Pgup, */ + VK_NEXT, /* wAccelKey_Pgdn, */ + VK_UP, /* wAccelKey_Up, */ + VK_DOWN, /* wAccelKey_Down, */ + VK_RIGHT, /* wAccelKey_Right, */ + VK_LEFT, /* wAccelKey_Left, */ + VK_BACK, /* wAccelKey_Back, */ + VK_F1, /* wAccelKey_F1, */ + VK_F2, /* wAccelKey_F2, */ + VK_F3, /* wAccelKey_F3, */ + VK_F4, /* wAccelKey_F4, */ + VK_F5, /* wAccelKey_F5, */ + VK_F6, /* wAccelKey_F6, */ + VK_F7, /* wAccelKey_F7, */ + VK_F8, /* wAccelKey_F8, */ + VK_F9, /* wAccelKey_F9, */ + VK_F10, /* wAccelKey_F10, */ + VK_F11, /* wAccelKey_F11, */ + VK_F12, /* wAccelKey_F12, */ + VK_ADD, /* wAccelKey_Numpad_Add, */ + VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */ +}; void wAttachAccelKey( - wAccelKey_e key, - int modifier, - wAccelKeyCallBack_p action, - void * data ) + wAccelKey_e key, + int modifier, + wAccelKeyCallBack_p action, + void * data ) { acclTable_t * ad; if ( key < 1 || key > wAccelKey_Numpad_Subtract ) { @@ -349,135 +358,133 @@ void wAttachAccelKey( ***************************************************************************** */ -HBITMAP GetMyCheckBitmaps(UINT fuCheck) -{ - COLORREF crBackground; /* background color */ - HBRUSH hbrBackground; /* background brush */ - HBRUSH hbrTargetOld; /* original background brush */ - HDC hdcSource; /* source device context */ - HDC hdcTarget; /* target device context */ - HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */ - BITMAP bmCheckbox; /* structure for bitmap data */ - HBITMAP hbmpSourceOld; /* handle to original source bitmap */ - HBITMAP hbmpTargetOld; /* handle to original target bitmap */ - HBITMAP hbmpCheck; /* handle to check-mark bitmap */ - RECT rc; /* rectangle for check-box bitmap */ - WORD wBitmapX; /* width of check-mark bitmap */ - WORD wBitmapY; /* height of check-mark bitmap */ +HBITMAP GetMyCheckBitmaps(UINT fuCheck) +{ + COLORREF crBackground; /* background color */ + HBRUSH hbrBackground; /* background brush */ + HBRUSH hbrTargetOld; /* original background brush */ + HDC hdcSource; /* source device context */ + HDC hdcTarget; /* target device context */ + HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */ + BITMAP bmCheckbox; /* structure for bitmap data */ + HBITMAP hbmpSourceOld; /* handle to original source bitmap */ + HBITMAP hbmpTargetOld; /* handle to original target bitmap */ + HBITMAP hbmpCheck; /* handle to check-mark bitmap */ + RECT rc; /* rectangle for check-box bitmap */ + WORD wBitmapX; /* width of check-mark bitmap */ + WORD wBitmapY; /* height of check-mark bitmap */ WORD wMenuH; /* height of menu line */ - - /* Get the menu background color and create a solid brush - with that color. */ - - crBackground = GetSysColor(COLOR_MENU); - hbrBackground = CreateSolidBrush(crBackground); - - /* Create memory device contexts for the source and - destination bitmaps. */ - - hdcSource = CreateCompatibleDC((HDC) NULL); - hdcTarget = CreateCompatibleDC(hdcSource); - - /* Get the size of the system default check-mark bitmap and - create a compatible bitmap of the same size. */ - - wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); - wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); + + /* Get the menu background color and create a solid brush + with that color. */ + + crBackground = GetSysColor(COLOR_MENU); + hbrBackground = CreateSolidBrush(crBackground); + + /* Create memory device contexts for the source and + destination bitmaps. */ + + hdcSource = CreateCompatibleDC((HDC) NULL); + hdcTarget = CreateCompatibleDC(hdcSource); + + /* Get the size of the system default check-mark bitmap and + create a compatible bitmap of the same size. */ + + wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); + wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); wMenuH = GetSystemMetrics(SM_CYMENU); - - hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, - wBitmapY); - - /* Select the background brush and bitmap into the target DC. */ - - hbrTargetOld = SelectObject(hdcTarget, hbrBackground); - hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck); - - /* Use the selected brush to initialize the background color - of the bitmap in the target device context. */ - - PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY); - - /* Load the predefined check box bitmaps and select it - into the source DC. */ - - hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL, - (LPTSTR) OBM_CHECKBOXES); - - hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes); - - /* Fill a BITMAP structure with information about the - check box bitmaps, and then find the upper-left corner of - the unchecked check box or the checked check box. */ - - GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox); - + + hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, + wBitmapY); + + /* Select the background brush and bitmap into the target DC. */ + + hbrTargetOld = SelectObject(hdcTarget, hbrBackground); + hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck); + + /* Use the selected brush to initialize the background color + of the bitmap in the target device context. */ + + PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY); + + /* Load the predefined check box bitmaps and select it + into the source DC. */ + + hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL, + (LPTSTR) OBM_CHECKBOXES); + + hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes); + + /* Fill a BITMAP structure with information about the + check box bitmaps, and then find the upper-left corner of + the unchecked check box or the checked check box. */ + + GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox); + switch( fuCheck ) { - + case UNCHECK: - rc.left = 0; - rc.right = (bmCheckbox.bmWidth / 4); - rc.top = 0; - rc.bottom = (bmCheckbox.bmHeight / 3); - break; - case CHECK: - rc.left = (bmCheckbox.bmWidth / 4); - rc.right = (bmCheckbox.bmWidth / 4) * 2; - rc.top = 0; - rc.bottom = (bmCheckbox.bmHeight / 3); + rc.left = 0; + rc.right = (bmCheckbox.bmWidth / 4); + rc.top = 0; + rc.bottom = (bmCheckbox.bmHeight / 3); + break; + case CHECK: + rc.left = (bmCheckbox.bmWidth / 4); + rc.right = (bmCheckbox.bmWidth / 4) * 2; + rc.top = 0; + rc.bottom = (bmCheckbox.bmHeight / 3); break; case RADIOCHECK: - rc.left = (bmCheckbox.bmWidth / 4); - rc.right = (bmCheckbox.bmWidth / 4) * 2; + rc.left = (bmCheckbox.bmWidth / 4); + rc.right = (bmCheckbox.bmWidth / 4) * 2; rc.top = (bmCheckbox.bmHeight / 3); - rc.bottom = (bmCheckbox.bmHeight / 3) * 2; + rc.bottom = (bmCheckbox.bmHeight / 3) * 2; break; case RADIOUNCHECK: rc.top = (bmCheckbox.bmHeight / 3); - rc.bottom = (bmCheckbox.bmHeight / 3) * 2; - rc.left = 0; - rc.right = (bmCheckbox.bmWidth / 4); + rc.bottom = (bmCheckbox.bmHeight / 3) * 2; + rc.left = 0; + rc.right = (bmCheckbox.bmWidth / 4); break; } - - /* Copy the appropriate bitmap into the target DC. If the - check-box bitmap is larger than the default check-mark - bitmap, use StretchBlt to make it fit; otherwise, just - copy it. */ - if (((rc.right - rc.left) > (int) wBitmapX) || - ((rc.bottom - rc.top) > (int) wBitmapY)) - { - StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, - hdcSource, rc.left, rc.top, rc.right - rc.left, - rc.bottom - rc.top, SRCCOPY); - } - - else - { + + /* Copy the appropriate bitmap into the target DC. If the + check-box bitmap is larger than the default check-mark + bitmap, use StretchBlt to make it fit; otherwise, just + copy it. */ + if (((rc.right - rc.left) > (int) wBitmapX) || + ((rc.bottom - rc.top) > (int) wBitmapY)) { + StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, + hdcSource, rc.left, rc.top, rc.right - rc.left, + rc.bottom - rc.top, SRCCOPY); + } + + else { // Center it vertically WORD dy = (wMenuH > wBitmapY) ? (wMenuH - wBitmapY) / 2 : 0; BitBlt(hdcTarget, 0, dy, rc.right - rc.left, - rc.bottom - rc.top, - hdcSource, rc.left, rc.top, SRCCOPY); - } - - /* Select the old source and destination bitmaps into the - source and destination DCs, and then delete the DCs and - the background brush. */ - - SelectObject(hdcSource, hbmpSourceOld); - SelectObject(hdcTarget, hbrTargetOld); - hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld); - - DeleteObject(hbrBackground); - DeleteObject(hdcSource); - DeleteObject(hdcTarget); - - /* Return a handle to the new check-mark bitmap. */ - - return hbmpCheck; -} + rc.bottom - rc.top, + hdcSource, rc.left, rc.top, SRCCOPY); + } + + /* Select the old source and destination bitmaps into the + source and destination DCs, and then delete the DCs and + the background brush. */ + + SelectObject(hdcSource, hbmpSourceOld); + SelectObject(hdcTarget, hbrTargetOld); + hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld); + + DeleteObject(hbrBackground); + DeleteObject(hdcSource); + DeleteObject(hdcTarget); + + /* Return a handle to the new check-mark bitmap. */ + + return hbmpCheck; +} void mswCreateCheckBitmaps() { @@ -489,12 +496,12 @@ void mswCreateCheckBitmaps() } wMenuRadio_p wMenuRadioCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wMenuCallBack_p action, - void *data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wMenuCallBack_p action, + void *data ) { wMenuRadio_p mi; int rc; @@ -538,8 +545,9 @@ wMenuRadio_p wMenuRadioCreate( ac = tolower( ac ); } vk = VkKeyScan( ac ); - if ( vk & 0xFF00 ) + if ( vk & 0xFF00 ) { modifier |= WKEY_SHIFT; + } acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF); acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mi; } @@ -547,7 +555,8 @@ wMenuRadio_p wMenuRadioCreate( /* add the correct bitmaps for radio buttons */ - rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio, checkedRadio ); + rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio, + checkedRadio ); if( m->radioGroup == NULL ) { m->radioGroup = malloc( sizeof( struct radioButtonGroup )); @@ -564,25 +573,26 @@ void wMenuRadioSetActive(wMenuRadio_p mi ) { BOOL rc; - rc = CheckMenuRadioItem( mi->mparent->menu, - mi->mparent->radioGroup->firstButton, - mi->mparent->radioGroup->lastButton, - mi->index, - MF_BYCOMMAND ); -} + rc = CheckMenuRadioItem( mi->mparent->menu, + mi->mparent->radioGroup->firstButton, + mi->mparent->radioGroup->lastButton, + mi->index, + MF_BYCOMMAND ); +} wMenuPush_p wMenuPushCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wMenuCallBack_p action, - void *data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wMenuCallBack_p action, + void *data ) { wMenuPush_p mi; int rc; - char *label = malloc(strlen(labelStr) + 30 ); /**< The label and sufficient space for the keyboard shortcut */ + char *label = malloc(strlen(labelStr) + + 30 ); /**< The label and sufficient space for the keyboard shortcut */ char *cp; char ac; UINT vk; @@ -622,8 +632,9 @@ wMenuPush_p wMenuPushCreate( ac = tolower( ac ); } vk = VkKeyScan( ac ); - if ( vk & 0xFF00 ) + if ( vk & 0xFF00 ) { modifier |= WKEY_SHIFT; + } acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF); acclTable(acclTable_da.cnt-1).mp = mi; } @@ -634,19 +645,19 @@ wMenuPush_p wMenuPushCreate( void wMenuPushEnable( - wMenuPush_p mi, - BOOL_T enable ) + wMenuPush_p mi, + BOOL_T enable ) { EnableMenuItem( mi->mparent->menu, mi->index, - MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); + MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); mi->enabled = enable; } wMenu_p wMenuMenuCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr ) + wMenu_p m, + const char * helpStr, + const char * labelStr ) { wMenu_p mm; int rc; @@ -657,13 +668,14 @@ wMenu_p wMenuMenuCreate( /*mm->parent = (wControl_p)m;*/ mm->first = mm->last = NULL; - rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu), mm->labelStr ); + rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu), + mm->labelStr ); return mm; } void wMenuSeparatorCreate( - wMenu_p m ) + wMenu_p m ) { int rc; createMenuItem( m, M_SEPARATOR, NULL, NULL, sizeof *(wMenuItem_p)NULL ); @@ -680,8 +692,8 @@ void wMenuSeparatorCreate( static void appendItem( - wMenuListItem_p ml, - wMenuListItem_p mi ) + wMenuListItem_p ml, + wMenuListItem_p mi ) { mi->right = ml->right; ml->right->left = mi; @@ -691,7 +703,7 @@ static void appendItem( static void removeItem( - wMenuListItem_p mi ) + wMenuListItem_p mi ) { mi->left->right = mi->right; mi->right->left = mi->left; @@ -700,10 +712,10 @@ static void removeItem( wMenuList_p wMenuListCreate( - wMenu_p m, - const char * helpStr, - int max, - wMenuListCallBack_p action ) + wMenu_p m, + const char * helpStr, + int max, + wMenuListCallBack_p action ) { wMenuList_p mi; mi = (wMenuList_p)createMenuItem( m, M_LIST, helpStr, NULL, sizeof *mi ); @@ -729,8 +741,9 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml ) count++; break; case M_LIST: - if (mi == (wMenuItem_p)ml) + if (mi == (wMenuItem_p)ml) { return count; + } count += ((wMenuList_p)mi)->count; break; default: @@ -742,10 +755,10 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml ) void wMenuListAdd( - wMenuList_p ml, - int index, - const char * labelStr, - void * data ) + wMenuList_p ml, + int index, + const char * labelStr, + void * data ) { int origin; wMenuListItem_p wl_p; @@ -754,7 +767,8 @@ void wMenuListAdd( int rc; origin = getMlistOrigin(ml->mlparent, ml); - for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) { + for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; + count++,wl_p=wl_p->right ) { if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) { /* move item */ if (count != index) { @@ -772,34 +786,37 @@ void wMenuListAdd( removeItem( ml->left ); add: ml->count--; - if (wl_p->labelStr ) + if (wl_p->labelStr ) { free( CAST_AWAY_CONST wl_p->labelStr ); + } wl_p->labelStr = mswStrdup( labelStr ); } else { wl_p = (wMenuListItem_p)createMenuItem( NULL, M_LISTITEM, NULL, - labelStr, sizeof *wl_p ); + labelStr, sizeof *wl_p ); } ((wMenuListItem_p)wl_p)->data = data; ((wMenuListItem_p)wl_p)->action = ml->action; - if (index < 0 || index > ml->count) + if (index < 0 || index > ml->count) { index = ml->count; + } for ( mi=(wMenuListItem_p)ml,count=0; count<index; mi=mi->right,count++); rc = InsertMenu( ml->mlparent->menu, origin+index, - MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr ); + MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr ); appendItem( mi, wl_p ); ml->count++; } void wMenuListDelete( - wMenuList_p ml, - const char * labelStr ) + wMenuList_p ml, + const char * labelStr ) { int origin, count; wMenuListItem_p wl_p; origin = getMlistOrigin(ml->mlparent, ml); - for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) { + for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; + count++,wl_p=wl_p->right ) { if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) { /* delete item */ mswUnregister( wl_p->index ); @@ -814,27 +831,30 @@ void wMenuListDelete( const char * wMenuListGet( - wMenuList_p ml, - int index, - void ** data ) + wMenuList_p ml, + int index, + void ** data ) { int origin, count; wMenuListItem_p wl_p; - if (index >= ml->count) + if (index >= ml->count) { return NULL; + } origin = getMlistOrigin(ml->mlparent, ml); for ( count=0,wl_p=ml->right; wl_p&&count<index; count++,wl_p=wl_p->right ); - if (wl_p==NULL) + if (wl_p==NULL) { return NULL; - if ( data ) + } + if ( data ) { *data = wl_p->data; + } return wl_p->labelStr; } void wMenuListClear( - wMenuList_p ml ) + wMenuList_p ml ) { int origin, count; wMenuListItem_p wl_p, wl_q; @@ -854,13 +874,13 @@ void wMenuListClear( wMenuToggle_p wMenuToggleCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wBool_t set, - wMenuCallBack_p action, - void * data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wBool_t set, + wMenuCallBack_p action, + void * data ) { wMenuToggle_p mt; int rc; @@ -870,7 +890,8 @@ wMenuToggle_p wMenuToggleCreate( UINT vk; long modifier; - mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, sizeof *mt ); + mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, + sizeof *mt ); /*setAcclKey( m->parent, m->menu, mt->menu_item, acclKey );*/ mt->action = action; mt->data = data; @@ -911,8 +932,9 @@ wMenuToggle_p wMenuToggleCreate( ac = tolower( ac ); } vk = VkKeyScan( ac ); - if ( vk & 0xFF00 ) + if ( vk & 0xFF00 ) { modifier |= WKEY_SHIFT; + } acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF); acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mt; } @@ -924,30 +946,33 @@ wMenuToggle_p wMenuToggleCreate( wBool_t wMenuToggleGet( - wMenuToggle_p mt ) + wMenuToggle_p mt ) { - return (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0; + return (GetMenuState( mt->mparent->menu, mt->index, + MF_BYCOMMAND ) & MF_CHECKED) != 0; } wBool_t wMenuToggleSet( - wMenuToggle_p mt, - wBool_t set ) + wMenuToggle_p mt, + wBool_t set ) { wBool_t rc; - CheckMenuItem( mt->mparent->menu, mt->index, MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) ); - rc = (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0; + CheckMenuItem( mt->mparent->menu, mt->index, + MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) ); + rc = (GetMenuState( mt->mparent->menu, mt->index, + MF_BYCOMMAND ) & MF_CHECKED) != 0; return rc; } void wMenuToggleEnable( - wMenuToggle_p mt, - wBool_t enable ) + wMenuToggle_p mt, + wBool_t enable ) { EnableMenuItem( mt->mparent->menu, mt->index, - MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); + MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) ); mt->enabled = enable; -} +} /* ***************************************************************************** @@ -959,39 +984,40 @@ void wMenuToggleEnable( void mswMenuMove( - wMenu_p m, - wWinPix_t x, - wWinPix_t y ) + wMenu_p m, + wWinPix_t x, + wWinPix_t y ) { wControl_p b; b = (wControl_p)m->parent; if (b && b->hWnd) if (!SetWindowPos( b->hWnd, HWND_TOP, x, y, - CW_USEDEFAULT, CW_USEDEFAULT, - SWP_NOSIZE|SWP_NOZORDER)) - mswFail("mswMenuMove"); + CW_USEDEFAULT, CW_USEDEFAULT, + SWP_NOSIZE|SWP_NOZORDER)) { + mswFail("mswMenuMove"); + } } static void pushMenuButt( - void * data ) + void * data ) { wMenu_p m = (wMenu_p)data; RECT rect; mswAllowBalloonHelp = FALSE; GetWindowRect( m->hWnd, &rect ); TrackPopupMenu( m->menu, TPM_LEFTALIGN, rect.left, rect.bottom, - 0, ((wControl_p)(m->parent))->hWnd, NULL ); + 0, ((wControl_p)(m->parent))->hWnd, NULL ); } wMenu_p wMenuCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option ) { wMenu_p m; wControl_p b; @@ -1004,7 +1030,7 @@ wMenu_p wMenuCreate( } m = (wMenu_p)createMenuItem( NULL, M_MENU, helpStr, label, sizeof *m ); m->button = wButtonCreate( parent, x, y, helpStr, labelStr, - buttOption, 0, pushMenuButt, (void*)m ); + buttOption, 0, pushMenuButt, (void*)m ); b = (wControl_p)m->button; m->parent = b->parent; m->x = b->x; @@ -1023,9 +1049,9 @@ wMenu_p wMenuCreate( wMenu_p wMenuBarAdd( - wWin_p w, - const char * helpStr, - const char * labelStr ) + wWin_p w, + const char * helpStr, + const char * labelStr ) { HMENU menu; wMenu_p m; @@ -1043,7 +1069,8 @@ wMenu_p wMenuBarAdd( m->mmtype = MM_BAR; m->first = m->last = NULL; - rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu), labelStr ); + rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu), + labelStr ); DrawMenuBar( ((wControl_p)w)->hWnd ); return m; @@ -1052,8 +1079,8 @@ wMenu_p wMenuBarAdd( wMenu_p wMenuPopupCreate( - wWin_p w, - const char * labelStr ) + wWin_p w, + const char * labelStr ) { wMenu_p m; long buttOption = 0; @@ -1083,21 +1110,21 @@ void wMenuPopupShow( wMenu_p mp ) GetCursorPos( &pt ); TrackPopupMenu( mp->menu, TPM_LEFTALIGN, pt.x, pt.y, 0, mp->hWnd, NULL ); } - + /*-----------------------------------------------------------------*/ void wMenuSetTraceCallBack( - wMenu_p m, - wMenuTraceCallBack_p func, - void * data ) + wMenu_p m, + wMenuTraceCallBack_p func, + void * data ) { m->traceFunc = func; m->traceData = data; } wBool_t wMenuAction( - wMenu_p m, - const char * label ) + wMenu_p m, + const char * label ) { wMenuItem_p mi; wMenuToggle_p mt; @@ -1108,10 +1135,11 @@ wBool_t wMenuAction( case M_SEPARATOR: break; case M_PUSH: - if ( ((wMenuPush_p)mi)->enabled == FALSE ) + if ( ((wMenuPush_p)mi)->enabled == FALSE ) { wBeep(); - else + } else { ((wMenuPush_p)mi)->action( ((wMenuPush_p)mi)->data ); + } break; case M_TOGGLE: mt = (wMenuToggle_p)mi; diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c index 5b45e2b..4bf9481 100644 --- a/app/wlib/mswlib/mswmisc.c +++ b/app/wlib/mswlib/mswmisc.c @@ -17,14 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define _WIN32_WINNT 0x0500 #include <windows.h> #include <shellapi.h> #include <string.h> -#include <malloc.h> +#include <malloc.h> // required for heapinfo in function wMemStats #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -61,8 +61,8 @@ const char * GetCurCommandName(void); #define LABELFONTRESET #else #define LABELFONTDECL HFONT hFont; -#define LABELFONTRESET if (!mswThickFont) {SelectObject( hDc, hFont );} -#define LABELFONTSELECT if (!mswThickFont) {hFont = SelectObject( hDc, mswLabelFont );} +#define LABELFONTRESET SelectObject( hDc, hFont ); +#define LABELFONTSELECT hFont = SelectObject( hDc, mswLabelFont ); #endif /* @@ -78,13 +78,8 @@ int mswEditHeight; int mswAllowBalloonHelp = TRUE; HFONT mswOldTextFont; HFONT mswLabelFont; -/** @prefs [msw tweak] ThickFont=1 */ -long mswThickFont = 1; double mswScale = 1.0; -/** @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(int inx); @@ -101,12 +96,12 @@ extern FILE * logFile; */ struct wWin_t { - WOBJ_COMMON - int validGeometry; - int min_width; - int max_width; - int min_height; - int max_height; + WOBJ_COMMON + int validGeometry; + int min_width; + int max_width; + int min_height; + int max_height; wWinPix_t lastX, lastY; wWinPix_t padX, padY; wControl_p first, last; @@ -177,8 +172,6 @@ char *mswProfileFile; static wBalloonHelp_t * balloonHelpStrings; -static wCursor_t curCursor = wCursorNormal; - #ifdef HELPSTR static FILE * helpStrF; #endif @@ -193,18 +186,20 @@ extern char *userLocale; // list of supported fileformats for image files static char * filterImageFiles[] = { N_("All image files"), - "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff", - N_("GIF files (*.gif)"), - "*.gif", - N_("JPEG files (*.jpeg,*.jpg)"), - "*.jpg;*.jpeg", - N_("PNG files (*.png)"), - "*.png", - N_("TIFF files (*.tiff, *.tif)"), - "*.tif;*.tiff", - N_("All files (*)"), - "*", - }; + "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff", + N_("GIF files (*.gif)"), + "*.gif", + N_("JPEG files (*.jpeg,*.jpg)"), + "*.jpg;*.jpeg", + N_("PNG files (*.png)"), + "*.png", + N_("TIFF files (*.tiff, *.tif)"), + "*.tif;*.tiff", + N_("All files (*)"), + "*", + }; + +static HICON hWindowIcon; /* ***************************************************************************** @@ -308,7 +303,8 @@ 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, (int)(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); @@ -318,7 +314,8 @@ void mswRepaintLabel(HWND hWnd, wControl_p b) /*SetBkMode( hDc, OPAQUE );*/ SetBkColor(hDc, GetSysColor(COLOR_BTNFACE)); - if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, (int)(strlen(b->labelStr)))) { + if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, + (int)(strlen(b->labelStr)))) { mswFail("Repainting text label"); } @@ -381,8 +378,8 @@ void * mswAlloc( w->data = data; w->focusChainNext = NULL; w->shown = TRUE; - w->hilite = FALSE; - w->errStr = NULL; + w->hilite = FALSE; + w->errStr = NULL; return w; } @@ -587,29 +584,27 @@ static void getSavedSizeAndPos( if ((option&F_RECALLPOS) && nameStr) { int x, y, w, h; - int xadj, yadj; + 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; - //} + 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 + (state = (int)strtol(cp, &cq, 10), cp != cq) && // state is not used (cp = cq, w = (wWinPix_t)(strtod(cp, &cq)), cp != cq) && (cp = cq, h = (wWinPix_t)(strtod(cp, &cq)), cp != cq) ) { @@ -645,6 +640,11 @@ static void getSavedSizeAndPos( x = 0; } + // Make sure we can see the dialog + xadj += 100; + yadj += 100; + + if (y + h > screenHeight - yadj) { y = screenHeight - yadj - h; } @@ -660,7 +660,7 @@ static void getSavedSizeAndPos( } /** - * Set min and max dimensions for a window. + * Set min and max dimensions for a window. * * \param min_width IN minimum width of window * \param max_width IN maximum width of window @@ -671,21 +671,21 @@ static void getSavedSizeAndPos( * \param aspect_ration IN unused on Windows */ void wSetGeometry(wWin_p win, - 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) + 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 - win->min_width = min_width; - win->max_width = max_width; - win->min_height = min_height; - win->max_height = max_height; + win->validGeometry = TRUE; //remember that geometry was set + win->min_width = min_width; + win->max_width = max_width; + win->min_height = min_height; + win->max_height = max_height; - return; + return; } /** @@ -695,13 +695,13 @@ void wSetGeometry(wWin_p win, * \param typ IN type of window (W_MAIN or W_POPUP) * \param option IN options for window creation * \param classname IN pre-registered window class - * \param style IN + * \param style IN * \param labelStr IN window title * \param winProc IN callback procedure * \param w IN default window width * \param h IN default window height * \param data IN ?? - * \param nameStr IN name of window + * \param nameStr IN name of window * \param pShowCmd IN/OUT window show option (maximize or show normal) * \return window data structure */ @@ -740,7 +740,7 @@ 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 + *pShowCmd = SW_HIDE; //Make sure to hide first } if (xx != CW_USEDEFAULT) { @@ -800,6 +800,10 @@ static wWin_p winCommonCreate( win->nameStr = mswStrdup(nameStr); + //HICON hIcon1 = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(101), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE); + SendMessage(win->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon); + SendMessage(win->hWnd, WM_SETICON, ICON_BIG, (LPARAM)hWindowIcon); + if (typ == W_MAIN) { mswInitColorPalette(); } @@ -850,7 +854,7 @@ wWin_p wWinMainCreate( TEXTMETRIC tm; char *pos; char * configName; - long maximize; + long maximize; /* check for configuration name */ if (pos = strchr(name, ';')) { @@ -887,14 +891,9 @@ wWin_p wWinMainCreate( /* length of path + \ + length of filename + . + length of extension + \0 */ helpFile = (char*)malloc(strlen(libDir) + 1 + strlen(appName) + 1 + 3 + 1); wsprintf(helpFile, "%s\\%s.chm", libDir, appName); - wPrefGetInteger("msw tweak", "ThickFont", &mswThickFont, 0); - - wPrefGetInteger("draw", "maximized", &maximize, 0L); - option |= (maximize ? F_MAXIMIZE : 0); - wPrefGetFloat(PREFSECTION, LARGEICON, &scaleIcon, 1.0); - if (scaleIcon < 1.0) scaleIcon = 1.0; - if (scaleIcon > 2.0) scaleIcon = 2.0; + wPrefGetInteger("draw", "maximized", &maximize, 0L); + option |= (maximize ? F_MAXIMIZE : 0); showCmd = SW_SHOW; w = winCommonCreate(NULL, W_MAIN, option|F_RESIZE, "MswMainWindow", @@ -902,18 +901,11 @@ 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(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); - hDc = GetDC(mswHWnd); - GetTextMetrics(hDc, &tm); - mswEditHeight = tm.tmHeight+2; - ReleaseDC(mswHWnd, hDc); - } + SendMessage(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); + hDc = GetDC(mswHWnd); + GetTextMetrics(hDc, &tm); + mswEditHeight = tm.tmHeight+2; + ReleaseDC(mswHWnd, hDc); ShowWindow(mswHWnd, showCmd); UpdateWindow(mswHWnd); @@ -1257,19 +1249,19 @@ static void savePos(wWin_p win) if (win->nameStr && IsWindowVisible(win->hWnd) /*&& !IsIconic( win->hWnd )*/) { - GetWindowRect(win->hWnd, &rect); + GetWindowRect(win->hWnd, &rect); - if (win->option&F_RECALLPOS) { + if (win->option&F_RECALLPOS) { char posStr[20]; - wsprintf(posStr, "%d %d", - rect.left, - rect.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 = rect.right - rect.left; - h = rect.bottom - rect.top; + GetClientRect(win->hWnd, &rect); + w = rect.right - rect.left; + h = rect.bottom - rect.top; wsprintf(posStr, "%d %d %d", 0, // unused w, h); @@ -1311,9 +1303,10 @@ void wWinShow( win->centerWin = FALSE; win->shown = TRUE; - // Clear hilites - for (wControl_p controlP = win->first; controlP; controlP = controlP->next) - controlP->hilite = FALSE; + // 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); @@ -1459,73 +1452,6 @@ void wWinClear( { } -extern long dontHideCursor; - -void wSetCursor(wDraw_p win, - wCursor_t cursor) -{ - switch (cursor) { - case wCursorNormal: - default: - SetCursor(LoadCursor(NULL, IDC_ARROW)); - break; - - case wCursorWait: - SetCursor(LoadCursor(NULL, IDC_WAIT)); - break; - - case wCursorCross: - SetCursor(LoadCursor(NULL, IDC_CROSS)); - break; - - case wCursorIBeam: - SetCursor(LoadCursor(NULL, IDC_IBEAM)); - break; - - case wCursorQuestion: - SetCursor(LoadCursor(NULL, IDC_HELP)); - break; - - case wCursorHand: - SetCursor(LoadCursor(NULL, IDC_HAND)); - break; - - case wCursorNo: - SetCursor(LoadCursor(NULL, IDC_NO)); - break; - - case wCursorSizeAll: - SetCursor(LoadCursor(NULL, IDC_SIZEALL)); - break; - - case wCursorSizeNESW: - SetCursor(LoadCursor(NULL, IDC_SIZENESW)); - break; - - case wCursorSizeNWSE: - SetCursor(LoadCursor(NULL, IDC_SIZENWSE)); - break; - - case wCursorSizeNS: - SetCursor(LoadCursor(NULL, IDC_SIZENS)); - break; - - case wCursorSizeWE: - SetCursor(LoadCursor(NULL, IDC_SIZEWE)); - break; - - case wCursorAppStart: - SetCursor(LoadCursor(NULL, IDC_APPSTARTING)); - break; - - case wCursorNone: - if (!dontHideCursor) - SetCursor(NULL); - break; - } - - curCursor = cursor; -} void wWinDoCancel(wWin_p win) { @@ -1821,34 +1747,36 @@ void wControlHilite( HDC hDc; HPEN oldPen, newPen; int oldMode; - LOGBRUSH logBrush = { BS_SOLID, CONTROLHILITECOLOR, (ULONG_PTR)NULL }; + LOGBRUSH logBrush = { BS_SOLID, CONTROLHILITECOLOR, (ULONG_PTR)NULL }; if (b == NULL) { return; } - if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd)) || (!IsWindowVisible(b->hWnd))) { - b->hilite = FALSE; + if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd)) + || (!IsWindowVisible(b->hWnd))) { + b->hilite = FALSE; return; } - if (b->hilite == hilite) - return; - b->hilite = hilite; + 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, - CONTROLHILITEWIDTH, - &logBrush, - 0, - NULL); + newPen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND | PS_JOIN_BEVEL, + CONTROLHILITEWIDTH, + &logBrush, + 0, + NULL); oldPen = SelectObject(hDc, newPen); oldMode = SetROP2(hDc, R2_NOTXORPEN); - Rectangle(hDc, - b->x - CONTROLHILITEWIDTH - 1, - b->y - CONTROLHILITEWIDTH - 1, - b->x + b->w + CONTROLHILITEWIDTH + 1, - b->y + b->h + CONTROLHILITEWIDTH + 1); + Rectangle(hDc, + b->x - CONTROLHILITEWIDTH - 1, + b->y - CONTROLHILITEWIDTH - 1, + b->x + b->w + CONTROLHILITEWIDTH + 1, + b->y + b->h + CONTROLHILITEWIDTH + 1); SetROP2(hDc, oldMode); SelectObject(hDc, oldPen); DeleteObject(newPen); @@ -1893,23 +1821,23 @@ void wMessage( /** * Open a document using an external application - * + * * \param file * \return TRUE on success, FALSE on error - * + * */ unsigned wOpenFileExternal(char *file) { - HINSTANCE res; + HINSTANCE res; - res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW); + res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW); - if ((UINT_PTR)res <= 32) { - wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL); - return(FALSE); - } + if ((UINT_PTR)res <= 32) { + wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL); + return(FALSE); + } - return(TRUE); + return(TRUE); } void wExit(int rc) @@ -1933,9 +1861,9 @@ void wExit(int rc) } } - wPrefFlush(""); + wPrefFlush(""); - for (inx=controlMap_da.cnt-1; inx>=0; inx--) { + for (inx=controlMap_da.cnt-1; inx>=0; inx--) { b = controlMap(inx).b; if (b != NULL) { @@ -1948,7 +1876,7 @@ void wExit(int rc) controlMap(inx).b = NULL; } - deleteBitmaps(); + deleteBitmaps(); if (mswOldTextFont != (HFONT)0) { DeleteObject(mswOldTextFont); @@ -2187,7 +2115,7 @@ int wNotice3( } /** - * Show help text for the given topic. + * Show help text for the given topic. * * \param topic The topic. if NULL the index page is shown. */ @@ -2197,11 +2125,11 @@ void wHelp( { char *pszHelpTopic; HWND hwndHelp; - const char *theTopic = "index"; + const char *theTopic = "index"; - if (topic) { - theTopic = topic; - } + if (topic) { + theTopic = topic; + } if (!helpInitted) { HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ; @@ -2235,7 +2163,7 @@ void doHelpMenu(void * context) helpInitted = TRUE; } - const char * topic; + const char * topic; switch ((int)(INT_PTR)context) { case 1: /* Contents */ HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL); @@ -2253,9 +2181,9 @@ void doHelpMenu(void * context) case 3: /*Context*/ - topic = GetCurCommandName(); - wHelp(topic); - break; + topic = GetCurCommandName(); + wHelp(topic); + break; default: return; @@ -2264,8 +2192,9 @@ void doHelpMenu(void * context) helpInitted = TRUE; } -void wDoAccelHelp(wAccelKey_e key, void * context) { - doHelpMenu(context); +void wDoAccelHelp(wAccelKey_e key, void * context) +{ + doHelpMenu(context); } void wMenuAddHelp( @@ -2301,126 +2230,133 @@ void wControlSetBalloonText(wControl_p b, const char * text) void openBalloonHelp(wControl_p b, int dx, int dy) { - 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) { + 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); + fprintf(logFile, "openBalloon !Enable state %d\n", balloonHelpState); + fflush(logFile); #endif - return; - } - } + return; + } + } #ifdef BALLOON_TRACE - fprintf(logFile, "openBalloon %s state %d\n", msg, balloonHelpState); fflush(logFile); + 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; - } - - pt.x = dx; - pt.y -= dy; - ClientToScreen(b->hWnd, &pt); - - if (pt.x + w + 2 > screenWidth) { - pt.x = screenWidth - (w + 2); - } - - if (pt.x < 0) { - pt.x = 0; - } - - 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 (!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; + } + + pt.x = dx; + pt.y -= dy; + ClientToScreen(b->hWnd, &pt); + + if (pt.x + w + 2 > screenWidth) { + pt.x = screenWidth - (w + 2); + } + + if (pt.x < 0) { + pt.x = 0; + } + + 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; } void startBalloonHelp(void) { - 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); - } + wBalloonHelp_t * bh; - openBalloonHelp(balloonHelpButton, 0, 0); + 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); + } + } + + openBalloonHelp(balloonHelpButton, 0, 0); } void closeBalloonHelp(int inx) { #ifdef BALLOON_TRACE - fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState); fflush(logFile); + fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState); + fflush(logFile); #endif - if (balloonHelpTimer) { - KillTimer(mswHWnd, balloonHelpTimer); - balloonHelpTimer = (UINT_PTR)0; - } + if (balloonHelpTimer) { + KillTimer(mswHWnd, balloonHelpTimer); + balloonHelpTimer = (UINT_PTR)0; + } - if (balloonHelpState == balloonHelpShow) - if (balloonHelpHWnd) { - ShowWindow(balloonHelpHWnd, SW_HIDE); - } + if (balloonHelpState == balloonHelpShow) + if (balloonHelpHWnd) { + ShowWindow(balloonHelpHWnd, SW_HIDE); + } - balloonHelpState = balloonHelpIdle; + balloonHelpState = balloonHelpIdle; } -void wControlSetBalloon(wControl_p b, wWinPix_t dx, wWinPix_t dy, const char * msg) +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); - } + 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); + } } @@ -2482,19 +2418,20 @@ struct wFilSel_t { char * GetImageFileFormats(void) { - char *filter = malloc(2048); - char *current = filter; - char *message; + char *filter = malloc(2048); + char *current = filter; + char *message; - for (int i = 0; i < sizeof(filterImageFiles) / sizeof(filterImageFiles[0]); i += 2) { - message = gettext(filterImageFiles[i]); - strcpy(current, message); - current += strlen(message) + 1; - strcpy(current, filterImageFiles[i + 1]); - current += strlen(current) + 1; - } - *current = '\0'; - return(filter); + for (int i = 0; i < sizeof(filterImageFiles) / sizeof(filterImageFiles[0]); + i += 2) { + message = gettext(filterImageFiles[i]); + strcpy(current, message); + current += strlen(message) + 1; + strcpy(current, filterImageFiles[i + 1]); + current += strlen(current) + 1; + } + *current = '\0'; + return(filter); } /** @@ -2530,12 +2467,11 @@ int wFilSelect( memset(&ofn, 0, sizeof ofn); ofn.lStructSize = sizeof ofn; ofn.hwndOwner = mswHWnd; - if (fs->option == FS_PICTURES) { - ofn.lpstrFilter = GetImageFileFormats(); - } - else { - ofn.lpstrFilter = fs->extList; - } + if (fs->option == FS_PICTURES) { + ofn.lpstrFilter = GetImageFileFormats(); + } else { + ofn.lpstrFilter = fs->extList; + } ofn.nFilterIndex = 0; selFileName = malloc(SELECTEDFILENAME_BUFFERSIZE); @@ -2773,24 +2709,24 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) HDC hDc; wAccelKey_e extChar; - LPMINMAXINFO pMMI; + LPMINMAXINFO pMMI; switch (message) { - case WM_GETMINMAXINFO: - pMMI = (LPMINMAXINFO)lParam; - inx = GetWindowWord(hWnd, 0); - - if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) { - w = (wWin_p)controlMap(inx - CONTROL_BASE).b; - if (w != NULL) { - if (w->validGeometry) { - pMMI->ptMaxTrackSize.x = w->max_width; - pMMI->ptMaxTrackSize.y = w->max_height; - pMMI->ptMinTrackSize.x = w->min_width; - pMMI->ptMinTrackSize.y = w->min_height; - } - } - } - return (LRESULT)0; + case WM_GETMINMAXINFO: + pMMI = (LPMINMAXINFO)lParam; + inx = GetWindowWord(hWnd, 0); + + if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) { + w = (wWin_p)controlMap(inx - CONTROL_BASE).b; + if (w != NULL) { + if (w->validGeometry) { + pMMI->ptMaxTrackSize.x = w->max_width; + pMMI->ptMaxTrackSize.y = w->max_height; + pMMI->ptMinTrackSize.x = w->min_width; + pMMI->ptMinTrackSize.y = w->min_height; + } + } + } + return (LRESULT)0; case WM_MOUSEWHEEL: inx = GetWindowWord(hWnd, 0); @@ -2800,13 +2736,13 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (mswCallBacks[b->type] != NULL && mswCallBacks[b->type]->messageProc) return mswCallBacks[b->type]->messageProc((wControl_p)b, hWnd, - message, wParam, lParam); + message, wParam, lParam); return (LRESULT)0; - case WM_COMMAND: + case WM_COMMAND: closeBalloonHelp(3); - case WM_DRAWITEM: + case WM_DRAWITEM: case WM_MEASUREITEM: if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) { @@ -2891,8 +2827,8 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case SIZE_MAXIMIZED: case SIZE_MINIMIZED: case SIZE_RESTORED: - newW = LOWORD(lParam); - newH = HIWORD(lParam); + newW = LOWORD(lParam); + newH = HIWORD(lParam); if (newW <= 0 || newH <= 0) { break; @@ -2910,8 +2846,8 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (w->winProc) { w->winProc(w, wResize_e, NULL, w->data); - w->winProc(w, wState_e, NULL, w->data); - } + w->winProc(w, wState_e, NULL, w->data); + } break; @@ -2939,7 +2875,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (mswCallBacks[w->type] != NULL && mswCallBacks[w->type]->messageProc) return mswCallBacks[w->type]->messageProc((wControl_p)w, hWnd, - message, wParam, lParam); + message, wParam, lParam); break; } @@ -2961,14 +2897,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 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; + 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); } @@ -2984,7 +2921,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (mswCallBacks[B_BUTTON] != NULL && mswCallBacks[B_BUTTON]->messageProc) { ret = mswCallBacks[B_BUTTON]->messageProc(b, b->hWnd, - WM_COMMAND, wParam, lParam); + WM_COMMAND, wParam, lParam); } inMainWndProc = FALSE; @@ -3004,7 +2941,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (mswCallBacks[B_BUTTON] != NULL && mswCallBacks[B_BUTTON]->messageProc) { ret = mswCallBacks[B_BUTTON]->messageProc(b, b->hWnd, - WM_COMMAND, wParam, lParam); + WM_COMMAND, wParam, lParam); } inMainWndProc = FALSE; @@ -3027,7 +2964,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (mswCallBacks[b->type] != NULL && mswCallBacks[b->type]->messageProc) { ret = mswCallBacks[b->type]->messageProc(b, b->hWnd, - WM_COMMAND, MAKELPARAM(LOWORD(wParam), BN_CLICKED), (LPARAM)(b->hWnd)); + WM_COMMAND, MAKELPARAM(LOWORD(wParam), BN_CLICKED), (LPARAM)(b->hWnd)); } inMainWndProc = FALSE; @@ -3098,64 +3035,66 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return (LRESULT)0; case WM_SETCURSOR: - if (hWnd == mswHWnd) - wSetCursor(NULL, curCursor); + // Set normal Arrow cursor, DefWindowProc can override it + SetCursor(LoadCursor(NULL, IDC_ARROW)); + + if (!mswAllowBalloonHelp) { + break; + } - if (!mswAllowBalloonHelp) { - break; - } + if (IsIconic(mswHWnd)) { + break; + } - if (IsIconic(mswHWnd)) { - break; - } + b = getControlFromCursor(hWnd, NULL); - b = getControlFromCursor(hWnd, NULL); - #ifdef BALLOON_TRACE - fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL"); fflush(logFile); + fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL"); + fflush(logFile); #endif - if (b == balloonControlButton) { - //closeBalloonHelp(61); - break; - } - - 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(7); - } + if (b == balloonControlButton) { + //closeBalloonHelp(61); + break; + } + + 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(7); + } #ifdef BALLOON_TRACE - fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState); fflush(logFile); + fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState); + fflush(logFile); #endif - if (balloonHelpState != balloonHelpIdle) { - break; - } + if (balloonHelpState != balloonHelpIdle) { + break; + } - balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, - balloonHelpTimeOut, NULL); + balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, + balloonHelpTimeOut, NULL); - if (balloonHelpTimer == (UINT_PTR)0) { - break; - } + if (balloonHelpTimer == (UINT_PTR)0) { + break; + } - balloonHelpState = balloonHelpWait; - balloonHelpButton = b; - break; + balloonHelpState = balloonHelpWait; + balloonHelpButton = b; + break; case WM_SYSCOMMAND: @@ -3263,7 +3202,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case 51: count51++; - /*return NULL;*/ + /*return NULL;*/ case WM_PALETTECHANGED: @@ -3421,7 +3360,7 @@ static BOOL InitApplication(HINSTANCE hinstCurrent) wc.cbWndExtra = 4; if (!RegisterClass(&wc)) { - mswFail("RegisterClass(drawClass)"); + mswFail("RegisterClass(drawClass)"); return FALSE; } @@ -3443,11 +3382,11 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, char **argv; int argc; - if (!hinstPrevious) { - if (!InitApplication(hinstCurrent)) { - return FALSE; - } - } + if (!hinstPrevious) { + if (!InitApplication(hinstCurrent)) { + return FALSE; + } + } mswHInst = hinstCurrent; mTitleH = GetSystemMetrics(SM_CYCAPTION) - 1; @@ -3456,11 +3395,12 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, mResizeBorderW = GetSystemMetrics(SM_CXFRAME); mResizeBorderH = GetSystemMetrics(SM_CYFRAME); mMenuH = GetSystemMetrics(SM_CYMENU) + 1; - screenWidth = GetSystemMetrics(SM_CXFULLSCREEN); - screenHeight = GetSystemMetrics(SM_CYFULLSCREEN); - mswLabelFont = GetStockObject(DEFAULT_GUI_FONT); + screenWidth = GetSystemMetrics(SM_CXSCREEN); + screenHeight = GetSystemMetrics(SM_CYSCREEN); + mswLabelFont = GetStockObject(DEFAULT_GUI_FONT); hDc = GetDC(0); mswScale = GetDeviceCaps(hDc, LOGPIXELSX) / 96.0; + hWindowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(101)); if (mswScale < 1.0) { mswScale = 1.0; diff --git a/app/wlib/mswlib/mswmsg.c b/app/wlib/mswlib/mswmsg.c index 8487e31..154d89d 100644 --- a/app/wlib/mswlib/mswmsg.c +++ b/app/wlib/mswlib/mswmsg.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -22,14 +21,14 @@ #define SCALE_SMALL 0.8 struct wMessage_t { - WOBJ_COMMON - long flags; - const char * message; - }; + WOBJ_COMMON + long flags; + const char * message; +}; static void repaintMessage( - HWND hWnd, - wControl_p b ) + HWND hWnd, + wControl_p b ) { wMessage_p bm = (wMessage_p)b; HDC hDc; @@ -41,33 +40,29 @@ static void repaintMessage( hDc = GetDC( hWnd ); - if ( !mswThickFont ) - hFont = SelectObject( hDc, mswLabelFont ); + hFont = SelectObject( hDc, mswLabelFont ); - switch( wMessageSetFont( ((wMessage_p)b)->flags )) - { - case BM_LARGE: - scale = SCALE_LARGE; - break; - case BM_SMALL: - scale = SCALE_SMALL; - break; + switch( wMessageSetFont( ((wMessage_p)b)->flags )) { + case BM_LARGE: + scale = SCALE_LARGE; + break; + case BM_SMALL: + scale = SCALE_SMALL; + break; } - /* is a non-standard text height required? */ - if( scale != 1.0 ) - { + /* is a non-standard text height required? */ + if( scale != 1.0 ) { /* if yes, get information about the standard font used */ GetObject( GetStockObject( DEFAULT_GUI_FONT ), sizeof( LOGFONT ), &msgFont ); /* change the height */ - msgFont.lfHeight = (long)((double)msgFont.lfHeight * scale); + msgFont.lfHeight = (long)((double)msgFont.lfHeight * scale); /* create and activate the new font */ hFont = SelectObject( hDc, CreateFontIndirect( &msgFont ) ); } else { - if ( !mswThickFont ) - hFont = SelectObject( hDc, mswLabelFont ); + hFont = SelectObject( hDc, mswLabelFont ); } GetTextMetrics(hDc, &textMetrics); @@ -78,36 +73,41 @@ 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, (int)(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 */ + { DeleteObject( SelectObject( hDc, GetStockObject( DEFAULT_GUI_FONT ))); - else - if ( !mswThickFont ) - SelectObject( hDc, hFont ); + } else { + SelectObject( hDc, hFont ); + } ReleaseDC( hWnd, hDc ); } void wMessageSetValue( - wMessage_p b, - const char * arg ) + wMessage_p b, + const char * arg ) { - if (b->message) + if (b->message) { free( CAST_AWAY_CONST b->message ); - if (arg) + } + if (arg) { b->message = mswStrdup( arg ); - else + } else { b->message = NULL; + } repaintMessage( ((wControl_p)(b->parent))->hWnd, (wControl_p)b ); } void wMessageSetWidth( - wMessage_p b, - wWinPix_t width ) + wMessage_p b, + wWinPix_t width ) { b->w = width; @@ -122,41 +122,44 @@ wWinPix_t wMessageGetHeight( long flags ) { double scale = 1.0; - if( flags & BM_LARGE ) + if( flags & BM_LARGE ) { scale = SCALE_LARGE; - if( flags & BM_SMALL ) + } + if( flags & BM_SMALL ) { scale = SCALE_SMALL; + } return((wWinPix_t)((mswEditHeight) * scale )); } static void mswMessageSetBusy( - wControl_p b, - BOOL_T busy ) + wControl_p b, + BOOL_T busy ) { } static callBacks_t messageCallBacks = { - repaintMessage, - NULL, - NULL, - mswMessageSetBusy }; + repaintMessage, + NULL, + NULL, + mswMessageSetBusy +}; wMessage_p wMessageCreateEx( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - wWinPix_t width, - const char *message, - long flags ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + wWinPix_t width, + const char *message, + long flags ) { wMessage_p b; int index; - + b = (wMessage_p)mswAlloc( parent, B_MESSAGE, NULL, sizeof *b, NULL, &index ); mswComputePos( (wControl_p)b, x, y ); diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c index 55fedb4..e65b0dd 100644 --- a/app/wlib/mswlib/mswpref.c +++ b/app/wlib/mswlib/mswpref.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -10,7 +9,7 @@ #include <Shlwapi.h> #if _MSC_VER >=1400 - #define stricmp _stricmp +#define stricmp _stricmp #endif char * mswStrdup( const char * ); @@ -26,40 +25,41 @@ static char appWorkDirName[MAX_PATH]; const char * wGetAppLibDir( void ) { - char *cp; - char module_name[MAX_PATH]; + char *cp; + char module_name[MAX_PATH]; - if (appLibDirName[0] != '\0') { - return appLibDirName; - } + if (appLibDirName[0] != '\0') { + return appLibDirName; + } - GetModuleFileName( mswHInst, module_name, sizeof module_name ); - cp = strrchr( module_name, '\\' ); - if (cp) - *cp = '\0'; + GetModuleFileName( mswHInst, module_name, sizeof module_name ); + cp = strrchr( module_name, '\\' ); + if (cp) { + *cp = '\0'; + } #ifdef XTRKCAD_CMAKE_BUILD - 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 - - strncpy(appLibDirName, module_name, sizeof(appLibDirName)); - appLibDirName[sizeof(appLibDirName)-1] = '\0'; - return appLibDirName; + 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 + + strncpy(appLibDirName, module_name, sizeof(appLibDirName)); + appLibDirName[sizeof(appLibDirName)-1] = '\0'; + return appLibDirName; } /** - * Gets the working directory for the application. At least the INI file is stored here. + * Gets the working directory for the application. At least the INI file is stored here. * The working directory can be specified manually by creating a file called xtrkcad0.ini - * in the application lib dir (the directory where the .EXE is located). + * in the application lib dir (the directory where the .EXE is located). * * [workdir] * path=somepath - * + * * when somepath is set to the keyword "installdir", the install directory for the EXE is * used. * @@ -68,229 +68,302 @@ const char * wGetAppLibDir( void ) */ const char * wGetAppWorkDir( void ) { - char *cp; - int rc; - if ( appWorkDirName[0] != 0 ) { - return appWorkDirName; - } - wGetAppLibDir(); - snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName ); - rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, sizeof appWorkDirName, mswTmpBuff ); - if ( rc!=0 ) { - if ( stricmp( appWorkDirName, "installdir" ) == 0 ) { - strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) ); - appWorkDirName[sizeof(appWorkDirName)-1] = '\0'; - } else { - cp = &appWorkDirName[strlen(appWorkDirName)-1]; - while (cp>appWorkDirName && *cp == '\\') *cp-- = 0; - } - return appWorkDirName; - } - - if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_APPDATA, 0 ) == 0 ) { - wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL ); - wExit(0); - } else { - 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 ); - wExit(0); - } - } - } - - return appWorkDirName; + char *cp; + int rc; + if ( appWorkDirName[0] != 0 ) { + return appWorkDirName; + } + wGetAppLibDir(); + snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName ); + rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, + sizeof appWorkDirName, mswTmpBuff ); + if ( rc!=0 ) { + if ( stricmp( appWorkDirName, "installdir" ) == 0 ) { + strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) ); + appWorkDirName[sizeof(appWorkDirName)-1] = '\0'; + } else { + cp = &appWorkDirName[strlen(appWorkDirName)-1]; + while (cp>appWorkDirName && *cp == '\\') { + *cp-- = 0; + } + } + return appWorkDirName; + } + + if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_APPDATA, 0 ) == 0 ) { + wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL ); + wExit(0); + } else { + 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 ); + wExit(0); + } + } + } + + return appWorkDirName; } -/** Get the user's home directory. The environment variable HOME is - * assumed to contain the proper directory. +/** Get the user's Documents directory. * - * \return pointer to the user's home directory + * \return pointer to the user's Documents directory */ const char *wGetUserHomeDir( void ) { - if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_PERSONAL, 0 ) == 0 ) { - wNoticeEx( NT_ERROR, "Cannot get user's home directory", "Exit", NULL ); - wExit(0); - return( NULL ); - } else { - return( mswTmpBuff ); - } + if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_PERSONAL, 0 ) == 0 ) { + wNoticeEx( NT_ERROR, "Cannot get user's documents directory", "Exit", NULL ); + wExit(0); + return( NULL ); + } else { + return( mswTmpBuff ); + } } typedef struct { - char * section; - char * name; - BOOL_T present; - BOOL_T dirty; - char * val; - } prefs_t; + char * section; + char * name; + BOOL_T present; + BOOL_T dirty; + char * val; +} prefs_t; 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 ) +void wPrefSetString( const char * section, const char * name, + const char * sval ) { - prefs_t * p; - - for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { - if (p->val) - free(p->val); - p->dirty = TRUE; - p->val = mswStrdup( sval ); - return; - } - } - DYNARR_APPEND( prefs_t, prefs_da, 10 ); - p = &prefs(prefs_da.cnt-1); - p->name = mswStrdup(name); - p->section = mswStrdup(section); - p->dirty = TRUE; - p->val = mswStrdup(sval); + prefs_t * p; + + for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { + if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { + if (p->val) { + free(p->val); + } + p->dirty = TRUE; + p->val = mswStrdup( sval ); + return; + } + } + DYNARR_APPEND( prefs_t, prefs_da, 10 ); + p = &prefs(prefs_da.cnt-1); + p->name = mswStrdup(name); + p->section = mswStrdup(section); + p->dirty = TRUE; + 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); - } +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 ) { - prefs_t * p; - int rc; - - for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { - return p->val; - } - } - - rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff, mswProfileFile ); - if (rc==0) - return NULL; - DYNARR_APPEND( prefs_t, prefs_da, 10 ); - p = &prefs(prefs_da.cnt-1); - p->name = mswStrdup(name); - p->section = mswStrdup(section); - p->dirty = FALSE; - p->val = mswStrdup(mswTmpBuff); - return p->val; + prefs_t * p; + int rc; + + for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { + if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { + return p->val; + } + } + + rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff, + mswProfileFile ); + if (rc==0) { + return NULL; + } + DYNARR_APPEND( prefs_t, prefs_da, 10 ); + p = &prefs(prefs_da.cnt-1); + p->name = mswStrdup(name); + p->section = mswStrdup(section); + p->dirty = FALSE; + p->val = mswStrdup(mswTmpBuff); + return p->val; } void wPrefSetInteger( const char * section, const char * name, long lval ) { - char tmp[20]; - - snprintf( tmp, sizeof(tmp), "%ld", lval ); - wPrefSetString( section, name, tmp ); + char tmp[20]; + + snprintf( tmp, sizeof(tmp), "%ld", lval ); + wPrefSetString( section, name, tmp ); } wBool_t wPrefGetIntegerBasic( - const char * section, - const char * name, - long *res, - long def ) + const char * section, + const char * name, + long *res, + long def ) { - const char * cp; - char * cp1; - - cp = wPrefGetStringBasic( section, name ); - if (cp == NULL) { - *res = def; - return FALSE; - } - *res = strtol(cp,&cp1,0); - if (cp==cp1) { - *res = def; - return FALSE; - } - return TRUE; + const char * cp; + char * cp1; + + cp = wPrefGetStringBasic( section, name ); + if (cp == NULL) { + *res = def; + return FALSE; + } + *res = strtol(cp,&cp1,0); + if (cp==cp1) { + *res = def; + return FALSE; + } + return TRUE; } void wPrefSetFloat( - const char * section, /* Section */ - const char * name, /* Name */ - double lval ) /* Value */ + const char * section, /* Section */ + const char * name, /* Name */ + double lval ) /* Value */ /* */ { - char tmp[20]; + char tmp[20]; - snprintf(tmp, sizeof(tmp), "%0.6f", lval ); - wPrefSetString( section, name, tmp ); + snprintf(tmp, sizeof(tmp), "%0.6f", lval ); + wPrefSetString( section, name, tmp ); } wBool_t wPrefGetFloatBasic( - const char * section, /* Section */ - const char * name, /* Name */ - double * res, /* Address of result */ - double def ) /* Default value */ + const char * section, /* Section */ + const char * name, /* Name */ + double * res, /* Address of result */ + double def ) /* Default value */ /* */ { - const char * cp; - char * cp1; - - cp = wPrefGetStringBasic( section, name ); - if (cp == NULL) { - *res = def; - return FALSE; - } - *res = strtod(cp, &cp1); - if (cp == cp1) { - *res = def; - return FALSE; - } - return TRUE; + const char * cp; + char * cp1; + + cp = wPrefGetStringBasic( section, name ); + if (cp == NULL) { + *res = def; + return FALSE; + } + *res = strtod(cp, &cp1); + if (cp == cp1) { + *res = def; + return FALSE; + } + return TRUE; } void wPrefFlush( char * name ) { - prefs_t * p; - - for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if (name && name[0]) - WritePrivateProfileString( p->section, p->name, p->val, name ); - else if (p->dirty) - WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile ); - } - if (name && name[0]) - WritePrivateProfileString( NULL, NULL, NULL, name ); - else - WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); + prefs_t * p; + + for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { + if (name && name[0]) { + WritePrivateProfileString( p->section, p->name, p->val, name ); + } else if (p->dirty) { + WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile ); + } + } + if (name && name[0]) { + WritePrivateProfileString( NULL, NULL, NULL, name ); + } else { + WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); + } } void wPrefReset( - void ) + void ) /* */ { - prefs_t * p; - - for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if (p->section) - free( p->section ); - if (p->name) - free( p->name ); - if (p->val) - free( p->val ); - } - prefs_da.cnt = 0; + prefs_t * p; + + for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { + if (p->section) { + free( p->section ); + } + if (p->name) { + free( p->name ); + } + if (p->val) { + free( p->val ); + } + } + prefs_da.cnt = 0; +} + +/** + * Split a line from the config file ie. an ini-file into separate tokens. The + * line is split into sections, name of value and value following. Pointers + * to the respective token are returned. These are zero-terminated. + * If a token is not present, NULL is returned instead. + * The input line is modified. + * + * \param line input line, modified during excution of function + * \param section section if present + * \param name name of config value if present + * \param value name of value if present + */ + +void +wPrefTokenize(char* line, char** section, char** name, char** value) +{ + *section = NULL; + *name = NULL; + *value = NULL; + + if (*line == '[') { + *section = strtok(line, "[]"); + } else { + *name = strtok(line, "="); + *value = strtok(NULL, "\n"); + } +} + +/** + * A valid line for a config file is created from the individual elements. + * Values not need for specific statement are ignored. Eg. when section is + * present, name and value are not used. + * The caller has to make sure, that the return buffer is large enough. + * + * \param section section, returned inside squared brackets + * \param name name, left side of '=' + * \param value value, right side of '=' + * \param result pointer to buffer for formated line. + */ + +void +wPrefFormatLine(const char* section, const char* name, + const char* value, char* result) +{ + if (!value || *value == '\0') { + value = ""; + } + + if (section) { + sprintf(result, "[%s]", section); + } + else { + sprintf(result, "%s=%s", name, value); + } } diff --git a/app/wlib/mswlib/mswprint.c b/app/wlib/mswlib/mswprint.c index e38ca05..9a7f65b 100644 --- a/app/wlib/mswlib/mswprint.c +++ b/app/wlib/mswlib/mswprint.c @@ -1,6 +1,5 @@ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -42,11 +41,11 @@ void getPageDim( HDC hDc ) int res_w, res_h, size_w, size_h; rc = Escape( hDc, GETPHYSPAGESIZE, 0, NULL, (LPPOINT)&dims ); if (rc <0) { - mswFail( "GETPHYPAGESIZE" ); + mswFail( "GETPHYPAGESIZE" ); } rc = Escape( hDc, GETPRINTINGOFFSET, 0, NULL, (LPPOINT)&offs ); if (rc <0) { - mswFail( "GETPRINTINGOFFSET" ); + mswFail( "GETPRINTINGOFFSET" ); } print_d.wFactor = (double)GetDeviceCaps( hDc, LOGPIXELSX ); print_d.hFactor = (double)GetDeviceCaps( hDc, LOGPIXELSY ); @@ -115,17 +114,18 @@ static wBool_t printInit( void ) while (*temp) { if (*temp == ',') { *temp++ = 0; - while( *temp == ' ' ) + while( *temp == ' ' ) { temp++; - if (!ptrDrvr) + } + if (!ptrDrvr) { ptrDrvr = temp; - else { + } else { ptrPort = temp; break; } - } - else + } else { temp = AnsiNext(temp); + } } strcpy( ptrDrvrDvr, ptrDrvr ); strcat( ptrDrvrDvr, ".drv" ); @@ -134,9 +134,11 @@ static wBool_t printInit( void ) return FALSE; } if (( extDeviceMode = GetProcAddress( hDriver, "ExtDeviceMode" )) != NULL) { - size = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)NULL, (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, 0 ); + size = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)NULL, + (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, 0 ); printMode = (DEVMODE*)malloc( size ); - rc = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)printMode, (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, DM_OUT_BUFFER ); + rc = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)printMode, + (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, DM_OUT_BUFFER ); #ifdef LATER if (rc != IDOK && rc != IDCANCEL) { mswFail( "printInit: extDeviceMode" ); @@ -160,7 +162,7 @@ static wBool_t printInit( void ) } getPageDim( hDc ); DeleteDC( hDc ); - + FreeLibrary( hDriver ); #endif printerOk = TRUE; @@ -201,9 +203,9 @@ const char* wPrintGetName() DEVNAMES* pDevNames = GlobalLock(hDevNames); if (pDevNames == NULL) { strcpy(sPrinterName, "Printer"); - } - else { - strncpy(sPrinterName, (char*)pDevNames + pDevNames->wDeviceOffset, sizeof sPrinterName - 1); + } else { + strncpy(sPrinterName, (char*)pDevNames + pDevNames->wDeviceOffset, + sizeof sPrinterName - 1); sPrinterName[sizeof sPrinterName - 1] = '\0'; } GlobalUnlock( hDevNames ); @@ -211,15 +213,15 @@ const char* wPrintGetName() } void wPrintGetMargins( - double * tMargin, - double * rMargin, - double * bMargin, - double * lMargin ) + double * tMargin, + double * rMargin, + double * bMargin, + double * lMargin ) { - if ( tMargin ) *tMargin = tBorder; - if ( rMargin ) *rMargin = rBorder; - if ( bMargin ) *bMargin = bBorder; - if ( lMargin ) *lMargin = lBorder; + if ( tMargin ) { *tMargin = tBorder; } + if ( rMargin ) { *rMargin = rBorder; } + if ( bMargin ) { *bMargin = bBorder; } + if ( lMargin ) { *lMargin = lBorder; } } @@ -240,10 +242,11 @@ HDC mswGetPrinterDC( void ) printDlg.lStructSize = sizeof printDlg; printDlg.hwndOwner = NULL; printDlg.Flags = PD_RETURNDC|PD_NOPAGENUMS|PD_NOSELECTION; - if (PrintDlg(&printDlg) != 0) + if (PrintDlg(&printDlg) != 0) { return printDlg.hDC; - else + } else { return (HDC)0; + } } @@ -290,51 +293,55 @@ wBool_t wPrintDocStart( const char * title, int fpageCount, int * copiesP ) if (print_d.hDc == (HDC)0) { return FALSE; } - printStatus = TRUE; - docInfo.cbSize = sizeof docInfo; - docInfo.lpszDocName = title; - docInfo.lpszOutput = NULL; - lpAbortDlg = MakeProcInstance( (FARPROC)mswAbortDlg, mswHInst ); - lpAbortProc = MakeProcInstance( (FARPROC)mswAbortProc, mswHInst ); - SetAbortProc( print_d.hDc, (ABORTPROC)lpAbortProc ); - if (StartDoc( print_d.hDc, &docInfo ) < 0) { - MessageBox( mswHWnd, "Unable to start print job", - NULL, MB_OK|MB_ICONHAND ); - FreeProcInstance( lpAbortDlg ); - FreeProcInstance( lpAbortProc ); - DeleteDC( print_d.hDc ); - return FALSE; - } - printAbort = FALSE; - hAbortDlgWnd = CreateDialog( mswHInst, "MswAbortDlg", mswHWnd, - (DLGPROC)lpAbortDlg ); - /*SetDlgItemText( hAbortDlgWnd, IDM_PRINTAPP, title );*/ - SetWindowText( hAbortDlgWnd, title ); - ShowWindow( hAbortDlgWnd, SW_NORMAL ); - UpdateWindow( hAbortDlgWnd ); - EnableWindow( mswHWnd, FALSE ); - if (copiesP) - *copiesP = printDlg.nCopies; - if (printDlg.nCopies>1) - pageCount *= printDlg.nCopies; - if ( (GetDeviceCaps( printDlg.hDC, RASTERCAPS ) & RC_PALETTE) ) { - newPrintPalette = mswCreatePalette(); - oldPrintPalette = SelectPalette( printDlg.hDC, newPrintPalette, 0 ); - RealizePalette( printDlg.hDC ); - } - return TRUE; + printStatus = TRUE; + docInfo.cbSize = sizeof docInfo; + docInfo.lpszDocName = title; + docInfo.lpszOutput = NULL; + lpAbortDlg = MakeProcInstance( (FARPROC)mswAbortDlg, mswHInst ); + lpAbortProc = MakeProcInstance( (FARPROC)mswAbortProc, mswHInst ); + SetAbortProc( print_d.hDc, (ABORTPROC)lpAbortProc ); + if (StartDoc( print_d.hDc, &docInfo ) < 0) { + MessageBox( mswHWnd, "Unable to start print job", + NULL, MB_OK|MB_ICONHAND ); + FreeProcInstance( lpAbortDlg ); + FreeProcInstance( lpAbortProc ); + DeleteDC( print_d.hDc ); + return FALSE; + } + printAbort = FALSE; + hAbortDlgWnd = CreateDialog( mswHInst, "MswAbortDlg", mswHWnd, + (DLGPROC)lpAbortDlg ); + /*SetDlgItemText( hAbortDlgWnd, IDM_PRINTAPP, title );*/ + SetWindowText( hAbortDlgWnd, title ); + ShowWindow( hAbortDlgWnd, SW_NORMAL ); + UpdateWindow( hAbortDlgWnd ); + EnableWindow( mswHWnd, FALSE ); + if (copiesP) { + *copiesP = printDlg.nCopies; + } + if (printDlg.nCopies>1) { + pageCount *= printDlg.nCopies; + } + if ( (GetDeviceCaps( printDlg.hDC, RASTERCAPS ) & RC_PALETTE) ) { + newPrintPalette = mswCreatePalette(); + oldPrintPalette = SelectPalette( printDlg.hDC, newPrintPalette, 0 ); + RealizePalette( printDlg.hDC ); + } + return TRUE; } wDraw_p wPrintPageStart( void ) { char pageL[80]; - if (!printStatus) + if (!printStatus) { return NULL; + } pageNumber++; - if (pageCount > 0) + if (pageCount > 0) { wsprintf( pageL, "Page %d of %d", pageNumber, pageCount ); - else + } else { wsprintf( pageL, "Page %d", pageNumber ); + } SetDlgItemText( hAbortDlgWnd, IDM_PRINTPAGE, pageL ); StartPage( printDlg.hDC ); #ifdef LATER @@ -367,15 +374,16 @@ wBool_t wPrintQuit( void ) void wPrintDocEnd( void ) { - if (!printStatus) + if (!printStatus) { return; + } EndDoc( printDlg.hDC ); if ( newPrintPalette ) { SelectPalette( printDlg.hDC, oldPrintPalette, 0 ); DeleteObject( newPrintPalette ); newPrintPalette = (HPALETTE)0; } - + EnableWindow( mswHWnd, TRUE ); DestroyWindow( hAbortDlgWnd ); FreeProcInstance( lpAbortDlg ); @@ -394,7 +402,8 @@ wBool_t wPrintNewPrinter( const char * printer ) return TRUE; } -wBool_t wPrintNewMargin( const char * name, double t, double b, double l, double r ) +wBool_t wPrintNewMargin( const char * name, double t, double b, double l, + double r ) { return TRUE; } diff --git a/app/wlib/mswlib/mswsplash.c b/app/wlib/mswlib/mswsplash.c index bd7644f..848bd00 100644 --- a/app/wlib/mswlib/mswsplash.c +++ b/app/wlib/mswlib/mswsplash.c @@ -2,27 +2,26 @@ * Splash window for Windows */ - /* XTrkCad - Model Railroad CAD - * Copyright (C) 2007 Martin Fischer - * - * 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. - */ +/* XTrkCad - Model Railroad CAD +* Copyright (C) 2007 Martin Fischer +* +* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -41,13 +40,13 @@ static HWND hSplash; static LPWORD lpwAlign( LPWORD lpIn ) { - ULONGLONG ul; + ULONGLONG ul; - ul = (ULONGLONG) lpIn; - ul +=3; - ul >>=2; - ul <<=2; - return (LPWORD) ul; + ul = (ULONGLONG) lpIn; + ul +=3; + ul >>=2; + ul <<=2; + return (LPWORD) ul; } /** @@ -57,7 +56,7 @@ static LPWORD lpwAlign( LPWORD lpIn ) BOOL PaintBitmap( HWND hWnd, HBITMAP hBmp ) { - HDC hdc, hdcMem; + HDC hdc, hdcMem; RECT rect; HGDIOBJ oldObject; @@ -66,19 +65,19 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp ) /* get device context for destination window ( the dialog control ) */ hdc = GetDC( hWnd ); GetClientRect( hWnd, &rect ); - + /* create a memory dc holding the bitmap */ hdcMem = CreateCompatibleDC( hdc ); oldObject = SelectObject( hdcMem, hBmp ); - /* - show it in the upper left corner - the window is created with the size of the bitmap, so there is no need - for any special transformation + /* + show it in the upper left corner + the window is created with the size of the bitmap, so there is no need + for any special transformation */ BitBlt( hdc, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, - hdcMem, 0, 0, SRCCOPY ); + hdcMem, 0, 0, SRCCOPY ); /* release the DCs that are not needed any more */ SelectObject(hdcMem, oldObject); @@ -89,31 +88,31 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp ) } /** - * This is the dialog procedure for the splash window. Main activity is to + * This is the dialog procedure for the splash window. Main activity is to * catch the WM_PAINT message and draw the logo bitmap into that area. */ -BOOL CALLBACK +BOOL CALLBACK SplashDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { static HWND hWndBmp; static HBITMAP hBmp; switch( msg ) { - case WM_INITDIALOG: - /* bitmap handle is passed at dialog creation */ - hBmp = (HBITMAP)lParam; - - hWndBmp = GetDlgItem( hDlg, IDBITMAP ); - return TRUE; - case WM_PAINT: - /* paint the logo bitmap */ - PaintBitmap( hWndBmp, hBmp ); - break; - case WM_DESTROY: - /* destroy the bitmap */ - DeleteObject( hBmp ); - break; + case WM_INITDIALOG: + /* bitmap handle is passed at dialog creation */ + hBmp = (HBITMAP)lParam; + + hWndBmp = GetDlgItem( hDlg, IDBITMAP ); + return TRUE; + case WM_PAINT: + /* paint the logo bitmap */ + PaintBitmap( hWndBmp, hBmp ); + break; + case WM_DESTROY: + /* destroy the bitmap */ + DeleteObject( hBmp ); + break; } return FALSE; } @@ -133,7 +132,7 @@ int wCreateSplash( char *appname, char *appver ) { HGLOBAL hgbl; - LPDLGTEMPLATE lpdt; + LPDLGTEMPLATE lpdt; LPWORD lpw; LPDLGITEMTEMPLATE lpdit; int cxDlgUnit, cyDlgUnit; @@ -149,60 +148,65 @@ wCreateSplash( char *appname, char *appver ) /* load the logo bitmap */ snprintf( logoPath, sizeof(logoPath), "%s\\logo.bmp", wGetAppLibDir()); - hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE ); - if( !hBmp ) + hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, + LR_DEFAULTCOLOR | LR_LOADFROMFILE ); + if( !hBmp ) { return( 0 ); + } - /* get info about the loaded logo file */ + /* get info about the loaded logo file */ GetObject( hBmp, sizeof(BITMAP), (LPVOID)&bmp ); /* calculate the size of dialog box */ cx = (bmp.bmWidth * 4) / cxDlgUnit; /* start with the size of the bitmap */ - cy = (bmp.bmHeight * 8) / cyDlgUnit + 20; /* 20 is enough for two lines of text and some room */ + cy = (bmp.bmHeight * 8) / cyDlgUnit + + 20; /* 20 is enough for two lines of text and some room */ /* allocate memory block for dialog template */ hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024); - if (!hgbl) + if (!hgbl) { return -1; - lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl); + } + lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl); - /* Define a dialog box. */ - lpdt->style = WS_POPUP | WS_BORDER | WS_VISIBLE | DS_MODALFRAME | DS_CENTER; - lpdt->cdit = 3; // number of controls - lpdt->x = 0; lpdt->y = 0; - lpdt->cx = cx; lpdt->cy = cy; + /* Define a dialog box. */ + lpdt->style = WS_POPUP | WS_BORDER | WS_VISIBLE | DS_MODALFRAME | DS_CENTER; + lpdt->cdit = 3; // number of controls + lpdt->x = 0; lpdt->y = 0; + lpdt->cx = cx; lpdt->cy = cy; - lpw = (LPWORD) (lpdt + 1); - *lpw++ = 0; /* no menu */ - *lpw++ = 0; /* predefined dialog box class (by default) */ - *lpw++ = 0; + lpw = (LPWORD) (lpdt + 1); + *lpw++ = 0; /* no menu */ + *lpw++ = 0; /* predefined dialog box class (by default) */ + *lpw++ = 0; /* add the static control for the logo bitmap */ lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw); lpdit->x = 0; lpdit->y = 0; - lpdit->cx = (SHORT)((bmp.bmWidth * 4) / cxDlgUnit); + lpdit->cx = (SHORT)((bmp.bmWidth * 4) / cxDlgUnit); lpdit->cy = (SHORT)((bmp.bmHeight * 8) / cyDlgUnit); - lpdit->id = IDBITMAP; - lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; - lpw = (LPWORD) (lpdit + 1); - *lpw++ = 0xFFFF; - *lpw++ = 0x0082; /* static class */ + lpdit->id = IDBITMAP; + lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; + lpw = (LPWORD) (lpdit + 1); + *lpw++ = 0xFFFF; + *lpw++ = 0x0082; /* static class */ - lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Logo should be here...", -1, (LPWSTR)lpw, 50); + lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Logo should be here...", -1, + (LPWSTR)lpw, 50); /* add the static control for the program title */ lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw); lpdit->x = 2; lpdit->y = (short)( 1 + (bmp.bmHeight * 8) / cyDlgUnit ); - lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit; - lpdit->id = IDAPPNAME; - lpdit->style = WS_CHILD | WS_VISIBLE | SS_CENTER; - lpw = (LPWORD) (lpdit + 1); - *lpw++ = 0xFFFF; - *lpw++ = 0x0082; /* static class */ - - /* create the title string */ + lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit; + lpdit->id = IDAPPNAME; + lpdit->style = WS_CHILD | WS_VISIBLE | SS_CENTER; + lpw = (LPWORD) (lpdit + 1); + *lpw++ = 0xFFFF; + *lpw++ = 0x0082; /* static class */ + + /* create the title string */ pszBuf = malloc( strlen( appname ) + strlen( appver ) + 2 ); if (!pszBuf) { GlobalUnlock(hgbl); @@ -216,26 +220,27 @@ wCreateSplash( char *appname, char *appver ) /* add the static control for the loading message */ lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw); lpdit->x = 2; lpdit->y = (short)(bmp.bmHeight * 8) / cyDlgUnit + 10; - lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit; - lpdit->id = IDMESSAGE; - lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; - lpw = (LPWORD) (lpdit + 1); - *lpw++ = 0xFFFF; - *lpw++ = 0x0082; /* static class */ + lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit; + lpdit->id = IDMESSAGE; + lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; + lpw = (LPWORD) (lpdit + 1); + *lpw++ = 0xFFFF; + *lpw++ = 0x0082; /* static class */ - lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Starting Application...", -1, (LPWSTR)lpw, 50); + lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Starting Application...", -1, + (LPWSTR)lpw, 50); /* create the dialog */ - GlobalUnlock(hgbl); - hSplash = CreateDialogIndirectParam( mswHInst, (LPDLGTEMPLATE) hgbl, - mswHWnd, (DLGPROC)SplashDlgProc, (LPARAM)hBmp ); - + GlobalUnlock(hgbl); + hSplash = CreateDialogIndirectParam( mswHInst, (LPDLGTEMPLATE) hgbl, + mswHWnd, (DLGPROC)SplashDlgProc, (LPARAM)hBmp ); + /* free allocated memory */ - GlobalFree(hgbl); + GlobalFree(hgbl); free( pszBuf ); /* that's it */ - return 1; + return 1; } @@ -243,9 +248,9 @@ wCreateSplash( char *appname, char *appver ) * Update the progress message inside the splash window * msg text message to display * return nonzero if ok - */ + */ -int +int wSetSplashInfo( char *msg ) { if( msg ) { diff --git a/app/wlib/mswlib/mswstatus.c b/app/wlib/mswlib/mswstatus.c index 1502a4e..7473ec8 100644 --- a/app/wlib/mswlib/mswstatus.c +++ b/app/wlib/mswlib/mswstatus.c @@ -39,10 +39,10 @@ */ void wStatusSetValue( - wStatus_p b, - const char * arg) + wStatus_p b, + const char * arg) { - wMessageSetValue((wMessage_p)b, arg); + wMessageSetValue((wMessage_p)b, arg); } /** * Create a window for a simple text. @@ -58,14 +58,14 @@ void wStatusSetValue( */ wStatus_p wStatusCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * labelStr, - wWinPix_t width, - const char *message) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * labelStr, + wWinPix_t width, + const char *message) { - return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0); + return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0); } /** @@ -78,7 +78,7 @@ wStatus_p wStatusCreate( wWinPix_t wStatusGetWidth(const char *testString) { - return (wMessageGetWidth(testString)); + return (wMessageGetWidth(testString)); } /** @@ -89,9 +89,9 @@ wStatusGetWidth(const char *testString) */ wWinPix_t wStatusGetHeight( - long flags) + long flags) { - return (wMessageGetHeight(flags)); + return (wMessageGetHeight(flags)); } /** @@ -103,8 +103,8 @@ wWinPix_t wStatusGetHeight( */ void wStatusSetWidth( - wStatus_p b, - wWinPix_t width) + wStatus_p b, + wWinPix_t width) { - wMessageSetWidth((wMessage_p)b, width); + wMessageSetWidth((wMessage_p)b, width); } diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c index b43a5d4..93c97b8 100644 --- a/app/wlib/mswlib/mswtext.c +++ b/app/wlib/mswlib/mswtext.c @@ -17,12 +17,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <windows.h> #include <string.h> -#include <malloc.h> #include <stdlib.h> #include <commdlg.h> #include <math.h> @@ -38,38 +37,38 @@ */ static LOGFONT fixedFont = { - /* Initial default values */ - -18, 0, /* H, W */ - 0, /* A */ - 0, - FW_REGULAR, - 0, 0, 0,/* I, U, SO */ - ANSI_CHARSET, - 0, /* OP */ - 0, /* CP */ - 0, /* Q */ - FIXED_PITCH|FF_MODERN, /* P&F */ - "Courier" -}; + /* Initial default values */ + -18, 0, /* H, W */ + 0, /* A */ + 0, + FW_REGULAR, + 0, 0, 0,/* I, U, SO */ + ANSI_CHARSET, + 0, /* OP */ + 0, /* CP */ + 0, /* Q */ + FIXED_PITCH|FF_MODERN, /* P&F */ + "Courier" + }; static HFONT fixedTextFont, prevTextFont; struct wText_t { - WOBJ_COMMON - HANDLE hText; + WOBJ_COMMON + HANDLE hText; }; void wTextClear( - wText_p b) + wText_p b) { - 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, (WPARAM)1, (LPARAM)0); - } + 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, (WPARAM)1, (LPARAM)0); + } } /** @@ -84,53 +83,53 @@ void wTextClear( */ void wTextAppend( - wText_p b, - const char * text) + wText_p b, + const char * text) { - char *cp; - char *buffer; - char *extText; - int textSize; - size_t len = strlen(text); - - if (!len) { - return; - } - - for (cp = (char *)text; *cp; cp++) { - if (*cp == '\n') { - len++; - } - } - - extText = malloc(len + 1 + 10); - - for (cp=extText; *text; cp++,text++) { - if (*text == '\n') { - *cp++ = '\r'; - *cp = '\n'; - } else { - *cp = *text; - } - } - - *cp = '\0'; - textSize = GetWindowTextLength(b->hWnd); - buffer = malloc((textSize + len + 1) * sizeof(char)); - - if (buffer) { - GetWindowText(b->hWnd, buffer, textSize + 1); - strcat(buffer, extText); - SetWindowText(b->hWnd, buffer); - free(extText); - free(buffer); - } else { - abort(); - } - - if (b->option&BO_READONLY) { - SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0); - } + char *cp; + char *buffer; + char *extText; + int textSize; + size_t len = strlen(text); + + if (!len) { + return; + } + + for (cp = (char *)text; *cp; cp++) { + if (*cp == '\n') { + len++; + } + } + + extText = malloc(len + 1 + 10); + + for (cp=extText; *text; cp++,text++) { + if (*text == '\n') { + *cp++ = '\r'; + *cp = '\n'; + } else { + *cp = *text; + } + } + + *cp = '\0'; + textSize = GetWindowTextLength(b->hWnd); + buffer = malloc((textSize + len + 1) * sizeof(char)); + + if (buffer) { + GetWindowText(b->hWnd, buffer, textSize + 1); + strcat(buffer, extText); + SetWindowText(b->hWnd, buffer); + free(extText); + free(buffer); + } else { + abort(); + } + + if (b->option&BO_READONLY) { + SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0); + } // scroll to bottom of text box SendMessage(b->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)10000); @@ -138,146 +137,146 @@ void wTextAppend( BOOL_T wTextSave( - wText_p b, - const char * fileName) + wText_p b, + const char * fileName) { - FILE * f; - int lc, l, len; - char line[255]; - f = wFileOpen(fileName, "w"); - - if (f == NULL) { - MessageBox(((wControl_p)(b->parent))->hWnd, "TextSave", "", MB_OK|MB_ICONHAND); - return FALSE; - } - - 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, (WPARAM)l, (LPARAM)line); - line[len] = '\0'; - fprintf(f, "%s\n", line); - } - - fclose(f); - return TRUE; + FILE * f; + int lc, l, len; + char line[255]; + f = wFileOpen(fileName, "w"); + + if (f == NULL) { + MessageBox(((wControl_p)(b->parent))->hWnd, "TextSave", "", MB_OK|MB_ICONHAND); + return FALSE; + } + + 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, (WPARAM)l, (LPARAM)line); + line[len] = '\0'; + fprintf(f, "%s\n", line); + } + + fclose(f); + return TRUE; } BOOL_T wTextPrint( - wText_p b) + wText_p b) { - int lc, l, len; - char line[255]; - HDC hDc; - int lineSpace; - int linesPerPage; - int currentLine; - int IOStatus; - TEXTMETRIC textMetric; - DOCINFO docInfo; - hDc = mswGetPrinterDC(); + int lc, l, len; + char line[255]; + HDC hDc; + int lineSpace; + int linesPerPage; + int currentLine; + int IOStatus; + TEXTMETRIC textMetric; + DOCINFO docInfo; + hDc = mswGetPrinterDC(); HFONT hFont, hOldFont; - if (hDc == (HDC)0) { - MessageBox(((wControl_p)(b->parent))->hWnd, "Print", "Cannot print", - MB_OK|MB_ICONHAND); - return FALSE; - } + if (hDc == (HDC)0) { + MessageBox(((wControl_p)(b->parent))->hWnd, "Print", "Cannot print", + MB_OK|MB_ICONHAND); + return FALSE; + } - docInfo.cbSize = sizeof(DOCINFO); - docInfo.lpszDocName = "XTrkcad Log"; - docInfo.lpszOutput = (LPSTR)NULL; + docInfo.cbSize = sizeof(DOCINFO); + docInfo.lpszDocName = "XTrkcad Log"; + docInfo.lpszOutput = (LPSTR)NULL; - // Retrieve a handle to the monospaced stock font. + // Retrieve a handle to the monospaced stock font. hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT); hOldFont = (HFONT)SelectObject(hDc, hFont); - if (StartDoc(hDc, &docInfo) < 0) { - MessageBox(((wControl_p)(b->parent))->hWnd, "Unable to start print job", NULL, - MB_OK|MB_ICONHAND); - DeleteDC(hDc); - return FALSE; - } - - StartPage(hDc); - - GetTextMetrics(hDc, &textMetric); - lineSpace = textMetric.tmHeight + textMetric.tmExternalLeading; - linesPerPage = GetDeviceCaps(hDc, VERTRES) / lineSpace; - currentLine = 1; - 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, (WPARAM)l, (LPARAM)line); - TextOut(hDc, 0, currentLine*lineSpace, line, len); - - if (++currentLine > linesPerPage) { - IOStatus = EndPage(hDc); - if (IOStatus < 0 ) { - break; - } - StartPage(hDc); + if (StartDoc(hDc, &docInfo) < 0) { + MessageBox(((wControl_p)(b->parent))->hWnd, "Unable to start print job", NULL, + MB_OK|MB_ICONHAND); + DeleteDC(hDc); + return FALSE; + } + + StartPage(hDc); + + GetTextMetrics(hDc, &textMetric); + lineSpace = textMetric.tmHeight + textMetric.tmExternalLeading; + linesPerPage = GetDeviceCaps(hDc, VERTRES) / lineSpace; + currentLine = 1; + 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, (WPARAM)l, (LPARAM)line); + TextOut(hDc, 0, currentLine*lineSpace, line, len); + + if (++currentLine > linesPerPage) { + IOStatus = EndPage(hDc); + if (IOStatus < 0 ) { + break; + } + StartPage(hDc); currentLine = 1; } - } + } - if (IOStatus >= 0 ) { - EndPage(hDc); - EndDoc(hDc); - } + if (IOStatus >= 0 ) { + EndPage(hDc); + EndDoc(hDc); + } SelectObject(hDc, hOldFont); - DeleteDC(hDc); - return TRUE; + DeleteDC(hDc); + return TRUE; } wBool_t wTextGetModified( - wText_p b) + wText_p b) { - int rc; - rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, (WPARAM)0, (LPARAM)0); - return (wBool_t)rc; + int rc; + rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, (WPARAM)0, (LPARAM)0); + return (wBool_t)rc; } /** * Get the size of the text in the text control including terminating '\0'. Note that * the text actually might be shorter if the text includes CRs. - * + * * \param b IN text control * \return required buffer size */ int wTextGetSize( - wText_p b) + wText_p b) { int len; len = GetWindowTextLength(b->hWnd); - return len + 1; + return len + 1; } -/** +/** * Get the text from a textentry. The buffer must be large enough for the text and * the terminating \0. * In case the string contains carriage returns these are removed. The returned string - * will be shortened accordingly. + * will be shortened accordingly. * To get the complete contents the buffer size must be equal or greater then the return * value of wTextGetSize() - * + * * \param b IN text entry * \param t IN/OUT buffer for text - * \param s IN size of buffer + * \param s IN size of buffer */ - + void wTextGetText( - wText_p b, - char * t, - int s) + wText_p b, + char * t, + int s) { char *buffer = malloc(s); char *ptr = buffer; @@ -296,153 +295,154 @@ void wTextGetText( void wTextSetReadonly( - wText_p b, - wBool_t ro) + wText_p b, + wBool_t ro) { - if (ro) { - b->option |= BO_READONLY; - } else { - b->option &= ~BO_READONLY; - } + if (ro) { + b->option |= BO_READONLY; + } else { + b->option &= ~BO_READONLY; + } - SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0); + SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0); } void wTextSetSize( - wText_p bt, - wWinPix_t width, - wWinPix_t height) + wText_p bt, + wWinPix_t width, + wWinPix_t height) { - bt->w = width; - bt->h = height; + bt->w = width; + bt->h = height; - if (!SetWindowPos(bt->hWnd, HWND_TOP, 0, 0, - bt->w, bt->h, SWP_NOMOVE|SWP_NOZORDER)) { - mswFail("wTextSetSize: SetWindowPos"); - } + if (!SetWindowPos(bt->hWnd, HWND_TOP, 0, 0, + bt->w, bt->h, SWP_NOMOVE|SWP_NOZORDER)) { + mswFail("wTextSetSize: SetWindowPos"); + } } void wTextComputeSize( - wText_p bt, - wWinPix_t rows, - wWinPix_t lines, - wWinPix_t * w, - wWinPix_t * h) + wText_p bt, + wWinPix_t rows, + wWinPix_t lines, + wWinPix_t * w, + wWinPix_t * h) { - static wWinPix_t scrollV_w = -1; - static wWinPix_t scrollH_h = -1; - HDC hDc; - TEXTMETRIC metrics; - - if (scrollV_w < 0) { - scrollV_w = GetSystemMetrics(SM_CXVSCROLL); - } - - if (scrollH_h < 0) { - scrollH_h = GetSystemMetrics(SM_CYHSCROLL); - } - - hDc = GetDC(bt->hWnd); - GetTextMetrics(hDc, &metrics); - *w = rows * metrics.tmAveCharWidth + scrollV_w; - *h = lines * (metrics.tmHeight + metrics.tmExternalLeading); - ReleaseDC(bt->hWnd, hDc); - - if (bt->option&BT_HSCROLL) { - *h += scrollH_h; - } + static wWinPix_t scrollV_w = -1; + static wWinPix_t scrollH_h = -1; + HDC hDc; + TEXTMETRIC metrics; + + if (scrollV_w < 0) { + scrollV_w = GetSystemMetrics(SM_CXVSCROLL); + } + + if (scrollH_h < 0) { + scrollH_h = GetSystemMetrics(SM_CYHSCROLL); + } + + hDc = GetDC(bt->hWnd); + GetTextMetrics(hDc, &metrics); + *w = rows * metrics.tmAveCharWidth + scrollV_w; + *h = lines * (metrics.tmHeight + metrics.tmExternalLeading); + ReleaseDC(bt->hWnd, hDc); + + if (bt->option&BT_HSCROLL) { + *h += scrollH_h; + } } void wTextSetPosition( - wText_p bt, - int pos) + wText_p bt, + int pos) { - LRESULT rc; - rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535, 0)); + LRESULT rc; + rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535, + 0)); } static void textDoneProc(wControl_p b) { - wText_p t = (wText_p)b; - HDC hDc; - hDc = GetDC(t->hWnd); - SelectObject(hDc, mswOldTextFont); - ReleaseDC(t->hWnd, hDc); + wText_p t = (wText_p)b; + HDC hDc; + hDc = GetDC(t->hWnd); + SelectObject(hDc, mswOldTextFont); + ReleaseDC(t->hWnd, hDc); } static callBacks_t textCallBacks = { - mswRepaintLabel, - textDoneProc, - NULL + mswRepaintLabel, + textDoneProc, + NULL }; wText_p wTextCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - wWinPix_t height) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + wWinPix_t height) { - wText_p b; - DWORD style; - RECT rect; - int index; - b = mswAlloc(parent, B_TEXT, labelStr, sizeof *b, NULL, &index); - mswComputePos((wControl_p)b, x, y); - b->option = option; - style = ES_MULTILINE | ES_LEFT | ES_AUTOVSCROLL | ES_WANTRETURN | - WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL; + wText_p b; + DWORD style; + RECT rect; + int index; + b = mswAlloc(parent, B_TEXT, labelStr, sizeof *b, NULL, &index); + mswComputePos((wControl_p)b, x, y); + b->option = option; + style = ES_MULTILINE | ES_LEFT | ES_AUTOVSCROLL | ES_WANTRETURN | + WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL; #ifdef BT_HSCROLL - if (option & BT_HSCROLL) { - style |= WS_HSCROLL | ES_AUTOHSCROLL; - } + if (option & BT_HSCROLL) { + style |= WS_HSCROLL | ES_AUTOHSCROLL; + } #endif - /* if (option & BO_READONLY) - style |= ES_READONLY;*/ - b->hWnd = CreateWindow("EDIT", NULL, - style, b->x, b->y, - width, height, - ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL); - - if (b->hWnd == NULL) { - mswFail("CreateWindow(TEXT)"); - return b; - } - - if (option & BT_FIXEDFONT) { - if (fixedTextFont == (HFONT)0) { - fixedTextFont = CreateFontIndirect(&fixedFont); - } - - SendMessage(b->hWnd, WM_SETFONT, (WPARAM)fixedTextFont, (LPARAM)MAKELONG(1, 0)); - } else if (!mswThickFont) { - SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); - } - - b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0); - - if (option & BT_CHARUNITS) { - wWinPix_t w, h; - wTextComputeSize(b, width, height, &w, &h); - - if (!SetWindowPos(b->hWnd, HWND_TOP, 0, 0, - w, h, SWP_NOMOVE|SWP_NOZORDER)) { - mswFail("wTextCreate: SetWindowPos"); - } - } - - GetWindowRect(b->hWnd, &rect); - b->w = rect.right - rect.left; - b->h = rect.bottom - rect.top; - mswAddButton((wControl_p)b, FALSE, helpStr); - mswCallBacks[B_TEXT] = &textCallBacks; - return b; + /* if (option & BO_READONLY) + style |= ES_READONLY;*/ + b->hWnd = CreateWindow("EDIT", NULL, + style, b->x, b->y, + width, height, + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL); + + if (b->hWnd == NULL) { + mswFail("CreateWindow(TEXT)"); + return b; + } + + if (option & BT_FIXEDFONT) { + if (fixedTextFont == (HFONT)0) { + fixedTextFont = CreateFontIndirect(&fixedFont); + } + + SendMessage(b->hWnd, WM_SETFONT, (WPARAM)fixedTextFont, (LPARAM)MAKELONG(1, 0)); + } else { + SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); + } + + b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0); + + if (option & BT_CHARUNITS) { + wWinPix_t w, h; + wTextComputeSize(b, width, height, &w, &h); + + if (!SetWindowPos(b->hWnd, HWND_TOP, 0, 0, + w, h, SWP_NOMOVE|SWP_NOZORDER)) { + mswFail("wTextCreate: SetWindowPos"); + } + } + + GetWindowRect(b->hWnd, &rect); + b->w = rect.right - rect.left; + b->h = rect.bottom - rect.top; + mswAddButton((wControl_p)b, FALSE, helpStr); + mswCallBacks[B_TEXT] = &textCallBacks; + return b; } diff --git a/app/wlib/mswlib/simple-gettext.c b/app/wlib/mswlib/simple-gettext.c index 951ce4c..592e3a3 100644 --- a/app/wlib/mswlib/simple-gettext.c +++ b/app/wlib/mswlib/simple-gettext.c @@ -1,4 +1,4 @@ -/* \file simple-gettext.c +/* \file simple-gettext.c * a simplified version of gettext. * Copyright (C) 1995, 1996, 1997, 1999, * 2005 Free Software Foundation, Inc. @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* This is a simplified version of gettext written by Ulrich Drepper. @@ -28,8 +28,8 @@ */ /* - * Based on the simple-gettext from GnuPG a version appropriate for the - * needs of XTrackCAD was derived. This is a workaround for any compiler + * Based on the simple-gettext from GnuPG a version appropriate for the + * needs of XTrackCAD was derived. This is a workaround for any compiler * specifics or runtime library dependencies. mf 26.07.09 */ @@ -50,10 +50,10 @@ #include "mswint.h" #if _MSC_VER > 1300 - #define stricmp _stricmp - #define strnicmp _strnicmp - #define strdup _strdup - #define fileno _fileno +#define stricmp _stricmp +#define strnicmp _strnicmp +#define strdup _strdup +#define fileno _fileno #endif typedef unsigned long u32; @@ -67,60 +67,56 @@ typedef unsigned long u32; /* Header for binary .mo file format. */ -struct mo_file_header -{ - /* The magic number. */ - u32 magic; - /* The revision number of the file format. */ - u32 revision; - /* The number of strings pairs. */ - u32 nstrings; - /* Offset of table with start offsets of original strings. */ - u32 orig_tab_offset; - /* Offset of table with start offsets of translation strings. */ - u32 trans_tab_offset; - /* Size of hashing table. */ - u32 hash_tab_size; - /* Offset of first hashing entry. */ - u32 hash_tab_offset; +struct mo_file_header { + /* The magic number. */ + u32 magic; + /* The revision number of the file format. */ + u32 revision; + /* The number of strings pairs. */ + u32 nstrings; + /* Offset of table with start offsets of original strings. */ + u32 orig_tab_offset; + /* Offset of table with start offsets of translation strings. */ + u32 trans_tab_offset; + /* Size of hashing table. */ + u32 hash_tab_size; + /* Offset of first hashing entry. */ + u32 hash_tab_offset; }; -struct string_desc -{ - /* Length of addressed string. */ - u32 length; - /* Offset of string in file. */ - u32 offset; +struct string_desc { + /* Length of addressed string. */ + u32 length; + /* Offset of string in file. */ + u32 offset; }; -struct overflow_space_s -{ - struct overflow_space_s *next; - u32 idx; - char d[1]; +struct overflow_space_s { + struct overflow_space_s *next; + u32 idx; + char d[1]; }; -struct loaded_domain -{ - char *data; - int must_swap; - u32 nstrings; - char *mapped; /* 0 = not yet mapped, 1 = mapped, +struct loaded_domain { + char *data; + int must_swap; + u32 nstrings; + char *mapped; /* 0 = not yet mapped, 1 = mapped, 2 = mapped to overflow space */ - struct overflow_space_s *overflow_space; - struct string_desc *orig_tab; - struct string_desc *trans_tab; - u32 hash_size; - u32 *hash_tab; + struct overflow_space_s *overflow_space; + struct string_desc *orig_tab; + struct string_desc *trans_tab; + u32 hash_size; + u32 *hash_tab; }; static struct loaded_domain *the_domain; /** * Translate the input string from UTF8 to Windows codepage. - * + * * \param str IN string in UTF-8 format to translate. * \param len IN number of chars to translate * \param dummy IN ? @@ -129,7 +125,7 @@ static struct loaded_domain *the_domain; char * utf8_to_native( char *str, unsigned int len, int dummy ) { - /* maximum output length is size of string * 2 */ + /* maximum output length is size of string * 2 */ int buflen = (len + 1) * 2; char *buf = malloc( buflen ); int wcharLen; @@ -143,22 +139,24 @@ utf8_to_native( char *str, unsigned int len, int dummy ) /* the system codepage, we need to take two steps */ /* 1. convert from UTF-8 to UTF-16 */ - wcharLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, (LPWSTR)buf, buflen / 2 ); - + wcharLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, (LPWSTR)buf, + buflen / 2 ); + /* 2. convert from UTF-8 to system codepage */ - WideCharToMultiByte(CP_ACP, 0, (LPWSTR)buf, wcharLen, resBuffer, len + 1, NULL, NULL ); + WideCharToMultiByte(CP_ACP, 0, (LPWSTR)buf, wcharLen, resBuffer, len + 1, NULL, + NULL ); } free(buf); - return( resBuffer ); + return( resBuffer ); } static u32 do_swap_u32( u32 i ) { - return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); + return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); } #define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data) ) @@ -174,205 +172,203 @@ do_swap_u32( u32 i ) static unsigned long hash_string( const char *str_param ) { - unsigned long int hval, g; - const char *str = str_param; - - hval = 0; - while (*str != '\0') - { - hval <<= 4; - hval += (unsigned long int) *str++; - g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); - if (g != 0) - { - hval ^= g >> (HASHWORDBITS - 8); - hval ^= g; + unsigned long int hval, g; + const char *str = str_param; + + hval = 0; + while (*str != '\0') { + hval <<= 4; + hval += (unsigned long int) *str++; + g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); + if (g != 0) { + hval ^= g >> (HASHWORDBITS - 8); + hval ^= g; + } } - } - return hval; + return hval; } static struct loaded_domain * load_domain( const char *filename ) { - FILE *fp; - size_t size; - struct stat st; - struct mo_file_header *data = NULL; - struct loaded_domain *domain = NULL; - size_t to_read; - char *read_ptr; - - fp = fopen( filename, "rb" ); - if( !fp ) - return NULL; /* can't open the file */ - /* we must know about the size of the file */ - if( fstat( fileno(fp ), &st ) - || (size = (size_t)st.st_size) != st.st_size - || size < sizeof (struct mo_file_header) ) { - fclose( fp ); - return NULL; - } - - data = malloc( size ); - if( !data ) { - fclose( fp ); - return NULL; /* out of memory */ - } - - to_read = size; - read_ptr = (char *) data; - do { - unsigned long int nb = (unsigned int)fread( read_ptr, 1, to_read, fp ); - if( nb < to_read ) { - fclose (fp); - free(data); - return NULL; /* read error */ + FILE *fp; + size_t size; + struct stat st; + struct mo_file_header *data = NULL; + struct loaded_domain *domain = NULL; + size_t to_read; + char *read_ptr; + + fp = fopen( filename, "rb" ); + if( !fp ) { + return NULL; /* can't open the file */ } - read_ptr += nb; - to_read -= nb; - } while( to_read > 0 ); - fclose (fp); - - /* Using the magic number we can test whether it really is a message - * catalog file. */ - if( data->magic != MAGIC && data->magic != MAGIC_SWAPPED ) { - /* The magic number is wrong: not a message catalog file. */ - free( data ); - return NULL; - } - - domain = calloc( 1, sizeof *domain ); - if( !domain ) { - free( data ); - return NULL; - } - domain->data = (char *) data; - domain->must_swap = data->magic != MAGIC; - - /* Fill in the information about the available tables. */ - switch( SWAPIT(domain->must_swap, data->revision) ) { - case 0: - domain->nstrings = SWAPIT(domain->must_swap, data->nstrings); - domain->orig_tab = (struct string_desc *) - ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset)); - domain->trans_tab = (struct string_desc *) - ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset)); - domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size); - domain->hash_tab = (u32 *) - ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset)); - break; - - default: /* This is an invalid revision. */ - free( data ); - free( domain ); - return NULL; - } - - /* Allocate an array to keep track of code page mappings. */ - domain->mapped = calloc( 1, domain->nstrings ); - if( !domain->mapped ) { - free( data ); - free( domain ); - return NULL; - } - - return domain; + /* we must know about the size of the file */ + if( fstat( fileno(fp ), &st ) + || (size = (size_t)st.st_size) != st.st_size + || size < sizeof (struct mo_file_header) ) { + fclose( fp ); + return NULL; + } + + data = malloc( size ); + if( !data ) { + fclose( fp ); + return NULL; /* out of memory */ + } + + to_read = size; + read_ptr = (char *) data; + do { + unsigned long int nb = (unsigned int)fread( read_ptr, 1, to_read, fp ); + if( nb < to_read ) { + fclose (fp); + free(data); + return NULL; /* read error */ + } + read_ptr += nb; + to_read -= nb; + } while( to_read > 0 ); + fclose (fp); + + /* Using the magic number we can test whether it really is a message + * catalog file. */ + if( data->magic != MAGIC && data->magic != MAGIC_SWAPPED ) { + /* The magic number is wrong: not a message catalog file. */ + free( data ); + return NULL; + } + + domain = calloc( 1, sizeof *domain ); + if( !domain ) { + free( data ); + return NULL; + } + domain->data = (char *) data; + domain->must_swap = data->magic != MAGIC; + + /* Fill in the information about the available tables. */ + switch( SWAPIT(domain->must_swap, data->revision) ) { + case 0: + domain->nstrings = SWAPIT(domain->must_swap, data->nstrings); + domain->orig_tab = (struct string_desc *) + ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset)); + domain->trans_tab = (struct string_desc *) + ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset)); + domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size); + domain->hash_tab = (u32 *) + ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset)); + break; + + default: /* This is an invalid revision. */ + free( data ); + free( domain ); + return NULL; + } + + /* Allocate an array to keep track of code page mappings. */ + domain->mapped = calloc( 1, domain->nstrings ); + if( !domain->mapped ) { + free( data ); + free( domain ); + return NULL; + } + + return domain; } /** * Set the file used for translations. Pass a NULL to disable - * translation. A new filename may be set at anytime. WARNING: - * After changing the filename you should not access any data + * translation. A new filename may be set at anytime. WARNING: + * After changing the filename you should not access any data * retrieved by gettext(). */ int set_gettext_file ( const char *filename, const char *regkey ) { - struct loaded_domain *domain = NULL; - - if( filename && *filename ) { - if( filename[0] == '/' - || ( isalpha(filename[0]) - && filename[1] == ':' - && (filename[2] == '/' || filename[2] == '\\') ) - ) { - /* absolute path - use it as is */ - domain = load_domain( filename ); + struct loaded_domain *domain = NULL; + + if( filename && *filename ) { + if( filename[0] == '/' + || ( isalpha(filename[0]) + && filename[1] == ':' + && (filename[2] == '/' || filename[2] == '\\') ) + ) { + /* absolute path - use it as is */ + domain = load_domain( filename ); + } + if (!domain) { + return -1; + } + } + + if( the_domain ) { + struct overflow_space_s *os, *os2; + free( the_domain->data ); + free( the_domain->mapped ); + for (os=the_domain->overflow_space; os; os = os2) { + os2 = os->next; + free (os); + } + free( the_domain ); + the_domain = NULL; } - if (!domain) - return -1; - } - - if( the_domain ) { - struct overflow_space_s *os, *os2; - free( the_domain->data ); - free( the_domain->mapped ); - for (os=the_domain->overflow_space; os; os = os2) { - os2 = os->next; - free (os); - } - free( the_domain ); - the_domain = NULL; - } - the_domain = domain; - return 0; + the_domain = domain; + return 0; } /** - * Return the required string from the message table. Before returning the result, + * Return the required string from the message table. Before returning the result, * codepage translation from UTF8 to current codepage is performed. */ static const char* get_string( struct loaded_domain *domain, u32 idx ) { - struct overflow_space_s *os; - char *p; - - p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset); - if (!domain->mapped[idx]) - { - size_t plen, buflen; - char *buf; - - domain->mapped[idx] = 1; - - plen = strlen (p); - buf = utf8_to_native (p, (unsigned int)plen, -1); - buflen = strlen (buf); - if (buflen <= plen){ - strcpy (p, buf); - free( buf ); - } else { - /* There is not enough space for the translation - store it - in the overflow_space else and mark that in the mapped - array. Because we expect that this won't happen too - often, we use a simple linked list. */ - os = malloc (sizeof *os + buflen); - if (os) - { - os->idx = idx; - strcpy (os->d, buf); - os->next = domain->overflow_space; - domain->overflow_space = os; - p = os->d; - } - else - p = "ERROR in GETTEXT MALLOC"; - free (buf); - } - } - else if (domain->mapped[idx] == 2) - { /* We need to get the string from the overflow_space. */ - for (os=domain->overflow_space; os; os = os->next) - if (os->idx == idx) - return (const char*)os->d; - p = "ERROR in GETTEXT\n"; - } - return (const char*)p; + struct overflow_space_s *os; + char *p; + + p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset); + if (!domain->mapped[idx]) { + size_t plen, buflen; + char *buf; + + domain->mapped[idx] = 1; + + plen = strlen (p); + buf = utf8_to_native (p, (unsigned int)plen, -1); + buflen = strlen (buf); + if (buflen <= plen) { + strcpy (p, buf); + free( buf ); + } else { + /* There is not enough space for the translation - store it + in the overflow_space else and mark that in the mapped + array. Because we expect that this won't happen too + often, we use a simple linked list. */ + os = malloc (sizeof *os + buflen); + if (os) { + os->idx = idx; + strcpy (os->d, buf); + os->next = domain->overflow_space; + domain->overflow_space = os; + p = os->d; + } else { + p = "ERROR in GETTEXT MALLOC"; + } + free (buf); + } + } else if (domain->mapped[idx] == 2) { + /* We need to get the string from the overflow_space. */ + for (os=domain->overflow_space; os; os = os->next) + if (os->idx == idx) { + return (const char*)os->d; + } + p = "ERROR in GETTEXT\n"; + } + return (const char*)p; } /** @@ -382,78 +378,85 @@ get_string( struct loaded_domain *domain, u32 idx ) char * gettext( const char *msgid ) { - struct loaded_domain *domain; - size_t act = 0; - size_t top, bottom; - - if( !(domain = the_domain) ) - goto not_found; - - /* Locate the MSGID and its translation. */ - if( domain->hash_size > 2 && domain->hash_tab ) { - /* Use the hashing table. */ - 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)); - u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]); - - if ( !nstr ) /* Hash table entry is empty. */ - goto not_found; - - if( SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].length) == len - && !strcmp( msgid, - domain->data + SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].offset)) ) - return (char *)get_string( domain, nstr - 1 ); - - for(;;) { - if (idx >= domain->hash_size - incr) - idx -= domain->hash_size - incr; - else - idx += incr; - - nstr = SWAPIT(domain->must_swap, domain->hash_tab[idx]); - if( !nstr ) - goto not_found; /* Hash table entry is empty. */ - - if ( SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].length) == len - && !strcmp (msgid, - domain->data + SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].offset))) - return (char *)get_string( domain, nstr-1 ); + struct loaded_domain *domain; + size_t act = 0; + size_t top, bottom; + + if( !(domain = the_domain) ) { + goto not_found; + } + + /* Locate the MSGID and its translation. */ + if( domain->hash_size > 2 && domain->hash_tab ) { + /* Use the hashing table. */ + 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)); + u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]); + + if ( !nstr ) { /* Hash table entry is empty. */ + goto not_found; + } + + if( SWAPIT(domain->must_swap, + domain->orig_tab[nstr - 1].length) == len + && !strcmp( msgid, + domain->data + SWAPIT(domain->must_swap, + domain->orig_tab[nstr - 1].offset)) ) { + return (char *)get_string( domain, nstr - 1 ); + } + + for(;;) { + if (idx >= domain->hash_size - incr) { + idx -= domain->hash_size - incr; + } else { + idx += incr; + } + + nstr = SWAPIT(domain->must_swap, domain->hash_tab[idx]); + if( !nstr ) { + goto not_found; /* Hash table entry is empty. */ + } + + if ( SWAPIT(domain->must_swap, + domain->orig_tab[nstr - 1].length) == len + && !strcmp (msgid, + domain->data + SWAPIT(domain->must_swap, + domain->orig_tab[nstr - 1].offset))) { + return (char *)get_string( domain, nstr-1 ); + } + } + /* NOTREACHED */ + } + + /* Now we try the default method: binary search in the sorted + array of messages. */ + bottom = 0; + top = domain->nstrings; + while( bottom < top ) { + int cmp_val; + + act = (bottom + top) / 2; + cmp_val = strcmp(msgid, domain->data + + SWAPIT(domain->must_swap, + domain->orig_tab[act].offset)); + if (cmp_val < 0) { + top = act; + } else if (cmp_val > 0) { + bottom = act + 1; + } else { + return (char *)get_string( domain, (int)(act) ); + } } - /* NOTREACHED */ - } - - /* Now we try the default method: binary search in the sorted - array of messages. */ - bottom = 0; - top = domain->nstrings; - while( bottom < top ) { - int cmp_val; - - act = (bottom + top) / 2; - cmp_val = strcmp(msgid, domain->data - + SWAPIT(domain->must_swap, - domain->orig_tab[act].offset)); - if (cmp_val < 0) - top = act; - else if (cmp_val > 0) - bottom = act + 1; - else - return (char *)get_string( domain, (int)(act) ); - } - - not_found: - return (char *)msgid; + +not_found: + return (char *)msgid; } /** - * This is the main initialization function for simple gettext. The message file is - * opened and read into memory. The function must be called once before translating + * This is the main initialization function for simple gettext. The message file is + * opened and read into memory. The function must be called once before translating * a string. * * The message files are expected to be in a directory named in the UNIXish form en_US @@ -474,12 +477,13 @@ bindtextdomain( char *domainname, char *dirname ) loc = g_win32_getlocale(); /* make sure that path does not end with trailing slash */ - if( dirname[ strlen(dirname) ] == '/' ) + if( dirname[ strlen(dirname) ] == '/' ) { dirname[ strlen(dirname) ] = '\0'; + } /* allocate buffer for filename, 20 bytes should be enough for extension etc. */ dir = malloc( strlen( domainname ) + strlen( dirname ) + strlen( loc ) + 20 ); - + if( dir ) { /* create the full filename */ sprintf( dir, "%s/%s/LC_MESSAGES/%s.mo", dirname, loc, domainname ); @@ -487,18 +491,18 @@ bindtextdomain( char *domainname, char *dirname ) set_gettext_file( dir, NULL ); free( dir ); } - + free( loc ); return( NULL ); } /** - * This is a dummy function to maintain source code compatibility + * This is a dummy function to maintain source code compatibility * with other implementations of gettext. * For this implementation, UTF-8 input encoding is assumed * * \param domainname IN domain - * \param codeset In codeset + * \param codeset In codeset * \return always NULL */ @@ -509,7 +513,7 @@ bind_textdomain_codeset(char *domainname, char *codeset ) } /** - * This is a dummy function to maintain source code compatibility + * This is a dummy function to maintain source code compatibility * with other implementations of gettext. * * \param domainname IN domain diff --git a/app/wlib/mswlib/sysinfo.c b/app/wlib/mswlib/sysinfo.c new file mode 100644 index 0000000..b4745f5 --- /dev/null +++ b/app/wlib/mswlib/sysinfo.c @@ -0,0 +1,138 @@ +/** \file sysinfo.c + * Collect info about runtime environment +*/ + +/* XTrkCad - Model Railroad CAD + * Copyright (C) 2024 Martin Fischer + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <process.h> +#include <stdio.h> +#include <stdlib.h> + +#include <Windows.h> +#include <fileapi.h> +#include <shlobj.h> +#include <Shlwapi.h> + +#include <wlib.h> +#include "mswint.h" + +#ifdef WINDOWS +#define itoa(a,b,c) _itoa(a,b,c) +#define getpid() _getpid() +#endif + +static char buffer[MAX_PATH + 1]; + +/** + * Return the path to a temporary directory. The directory is not created. + * The result is put into a buffer and is only valid immediately after the call. + * + * \return pointer to fully qualified directory path + */ + +char * +wGetTempPath() +{ + unsigned retChars; + + retChars = GetTempPath(MAX_PATH + 1, buffer); + + if (retChars <= MAX_PATH + 1) { + char str[20]; + strcat(buffer, "xtc"); + itoa(getpid(), str, 10); + strcat(buffer, str); + } + + return(buffer); +} + +/** + * Get the Windows version. This function uses the Windows ver command to + * retrieve the OS version. The result is put into a buffer and is only + * valid immediately after the call. + * + * \return buffer containing the zero terminated string + * + */ + +char * +wGetOSVersion() +{ + FILE* pPipe; + pPipe = _popen("ver", "r"); + + while (fgets(buffer, sizeof(buffer), pPipe)) + ; + + if (buffer[strlen(buffer) -1] == '\n') + buffer[strlen(buffer) -1 ] = '\0'; + _pclose(pPipe); + + return(buffer); +} + +/** + * Get the name of the configuration file. + * + * \return pointer to the filename. + * + */ + +char * +wGetProfileFilename() +{ + return(mswProfileFile); +} + +/** + * Get the name of the current user. The result is put into a buffer and is only + * valid immediately after the call. + * + * \return buffer containing the zero terminated string + * + */ + +char * +wGetUserID() +{ + DWORD bufferSize = sizeof(buffer); + + GetUserName(buffer, &bufferSize); + + return(buffer); +} + +/** Get the user's profile directory. Other than on UNIX Windows differentiates + * between the home directory and and the profile directory. + * + * \return pointer to the user's profile directory + */ + +const char* wGetUserHomeRootDir(void) +{ + if (SHGetSpecialFolderPath(NULL, mswTmpBuff, CSIDL_PROFILE, 0) == 0) { + wNoticeEx(NT_ERROR, "Cannot get user's profile directory", "Exit", NULL); + wExit(0); + return(NULL); + } + else { + return(mswTmpBuff); + } +} diff --git a/app/wlib/mswlib/unittest/CMakeLists.txt b/app/wlib/mswlib/unittest/CMakeLists.txt index b91c1ff..9bebe2b 100644 --- a/app/wlib/mswlib/unittest/CMakeLists.txt +++ b/app/wlib/mswlib/unittest/CMakeLists.txt @@ -1,11 +1,23 @@ # build unit tests for the xtrkcad Windows library add_executable(utf8test + "") + +target_sources(utf8test + PRIVATE utf8test.c ../utf8conv.c - ) +) target_link_libraries(utf8test - ${LIBS}) + PRIVATE + xtrkcad-wlib + ${CMOCKA_LIBRARIES} +) add_test(UTF8ConversionTest utf8test) + +set_target_properties( + utf8test + PROPERTIES FOLDER UnitTests + ) diff --git a/app/wlib/mswlib/utf8conv.c b/app/wlib/mswlib/utf8conv.c index 5a39b34..2363df9 100644 --- a/app/wlib/mswlib/utf8conv.c +++ b/app/wlib/mswlib/utf8conv.c @@ -19,10 +19,9 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <malloc.h> #include <stdbool.h> #include <string.h> @@ -43,29 +42,29 @@ bool wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength) { - unsigned int cnt = 2 * (unsigned int)(strlen(inString) + 1); - char *tempBuffer = malloc(cnt); - - // convert to wide character (UTF16) - MultiByteToWideChar(CP_ACP, - 0, - inString, - -1, - (LPWSTR)tempBuffer, - cnt); - - // convert from wide char to UTF-8 - WideCharToMultiByte(CP_UTF8, - 0, - (LPCWCH)tempBuffer, - -1, - (LPSTR)outString, - outStringLength, - NULL, - NULL); - - free(tempBuffer); - return true; + unsigned int cnt = 2 * (unsigned int)(strlen(inString) + 1); + char *tempBuffer = malloc(cnt); + + // convert to wide character (UTF16) + MultiByteToWideChar(CP_ACP, + 0, + inString, + -1, + (LPWSTR)tempBuffer, + cnt); + + // convert from wide char to UTF-8 + WideCharToMultiByte(CP_UTF8, + 0, + (LPCWCH)tempBuffer, + -1, + (LPSTR)outString, + outStringLength, + NULL, + NULL); + + free(tempBuffer); + return true; } /** @@ -81,43 +80,43 @@ wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength) bool wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength) { - unsigned int cnt = 2 * (int)(strlen(inString) + 1); - char *tempBuffer = malloc(cnt); - - // convert to wide character (UTF16) - MultiByteToWideChar(CP_UTF8, - 0, - inString, - -1, - (LPWSTR)tempBuffer, - cnt); - - - cnt = WideCharToMultiByte(CP_ACP, - 0, - (LPCWCH)tempBuffer, - -1, - (LPSTR)outString, - 0L, - NULL, - NULL); - - if (outStringLength <= cnt) { - return (false); - } - - // convert from wide char to system codepage - WideCharToMultiByte(CP_ACP, - 0, - (LPCWCH)tempBuffer, - -1, - (LPSTR)outString, - outStringLength, - NULL, - NULL); - - free(tempBuffer); - return true; + unsigned int cnt = 2 * (int)(strlen(inString) + 1); + char *tempBuffer = malloc(cnt); + + // convert to wide character (UTF16) + MultiByteToWideChar(CP_UTF8, + 0, + inString, + -1, + (LPWSTR)tempBuffer, + cnt); + + + cnt = WideCharToMultiByte(CP_ACP, + 0, + (LPCWCH)tempBuffer, + -1, + (LPSTR)outString, + 0L, + NULL, + NULL); + + if (outStringLength <= cnt) { + return (false); + } + + // convert from wide char to system codepage + WideCharToMultiByte(CP_ACP, + 0, + (LPCWCH)tempBuffer, + -1, + (LPSTR)outString, + outStringLength, + NULL, + NULL); + + free(tempBuffer); + return true; } /** @@ -131,80 +130,80 @@ wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength) bool wIsUTF8(const char * string) { - if (!string) { - return 0; - } - - const unsigned char * bytes = (const unsigned char *)string; - while (*bytes) { - if ((// ASCII - // use bytes[0] <= 0x7F to allow ASCII control characters - bytes[0] == 0x09 || - bytes[0] == 0x0A || - bytes[0] == 0x0D || - (0x20 <= bytes[0] && bytes[0] <= 0x7E) - ) - ) { - bytes += 1; - continue; - } - - if ((// non-overlong 2-byte - (0xC2 <= bytes[0] && bytes[0] <= 0xDF) && - (0x80 <= bytes[1] && bytes[1] <= 0xBF) - ) - ) { - bytes += 2; - continue; - } - - if ((// excluding overlongs - bytes[0] == 0xE0 && - (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && - (0x80 <= bytes[2] && bytes[2] <= 0xBF) - ) || - (// straight 3-byte - ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || - bytes[0] == 0xEE || - bytes[0] == 0xEF) && - (0x80 <= bytes[1] && bytes[1] <= 0xBF) && - (0x80 <= bytes[2] && bytes[2] <= 0xBF) - ) || - (// excluding surrogates - bytes[0] == 0xED && - (0x80 <= bytes[1] && bytes[1] <= 0x9F) && - (0x80 <= bytes[2] && bytes[2] <= 0xBF) - ) - ) { - bytes += 3; - continue; - } - - if ((// planes 1-3 - bytes[0] == 0xF0 && - (0x90 <= bytes[1] && bytes[1] <= 0xBF) && - (0x80 <= bytes[2] && bytes[2] <= 0xBF) && - (0x80 <= bytes[3] && bytes[3] <= 0xBF) - ) || - (// planes 4-15 - (0xF1 <= bytes[0] && bytes[0] <= 0xF3) && - (0x80 <= bytes[1] && bytes[1] <= 0xBF) && - (0x80 <= bytes[2] && bytes[2] <= 0xBF) && - (0x80 <= bytes[3] && bytes[3] <= 0xBF) - ) || - (// plane 16 - bytes[0] == 0xF4 && - (0x80 <= bytes[1] && bytes[1] <= 0x8F) && - (0x80 <= bytes[2] && bytes[2] <= 0xBF) && - (0x80 <= bytes[3] && bytes[3] <= 0xBF) - ) - ) { - bytes += 4; - continue; - } - - return false; - } - - return true; -}
\ No newline at end of file + if (!string) { + return 0; + } + + const unsigned char * bytes = (const unsigned char *)string; + while (*bytes) { + if ((// ASCII + // use bytes[0] <= 0x7F to allow ASCII control characters + bytes[0] == 0x09 || + bytes[0] == 0x0A || + bytes[0] == 0x0D || + (0x20 <= bytes[0] && bytes[0] <= 0x7E) + ) + ) { + bytes += 1; + continue; + } + + if ((// non-overlong 2-byte + (0xC2 <= bytes[0] && bytes[0] <= 0xDF) && + (0x80 <= bytes[1] && bytes[1] <= 0xBF) + ) + ) { + bytes += 2; + continue; + } + + if ((// excluding overlongs + bytes[0] == 0xE0 && + (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) + ) || + (// straight 3-byte + ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || + bytes[0] == 0xEE || + bytes[0] == 0xEF) && + (0x80 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) + ) || + (// excluding surrogates + bytes[0] == 0xED && + (0x80 <= bytes[1] && bytes[1] <= 0x9F) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) + ) + ) { + bytes += 3; + continue; + } + + if ((// planes 1-3 + bytes[0] == 0xF0 && + (0x90 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) && + (0x80 <= bytes[3] && bytes[3] <= 0xBF) + ) || + (// planes 4-15 + (0xF1 <= bytes[0] && bytes[0] <= 0xF3) && + (0x80 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) && + (0x80 <= bytes[3] && bytes[3] <= 0xBF) + ) || + (// plane 16 + bytes[0] == 0xF4 && + (0x80 <= bytes[1] && bytes[1] <= 0x8F) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) && + (0x80 <= bytes[3] && bytes[3] <= 0xBF) + ) + ) { + bytes += 4; + continue; + } + + return false; + } + + return true; +} |