summaryrefslogtreecommitdiff
path: root/app/wlib/mswlib
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/mswlib')
-rw-r--r--app/wlib/mswlib/CMakeLists.txt89
-rw-r--r--app/wlib/mswlib/backgnd.c369
-rw-r--r--app/wlib/mswlib/checksum.c14
-rw-r--r--app/wlib/mswlib/dynarr.h12
-rw-r--r--app/wlib/mswlib/getline/LICENSE25
-rw-r--r--app/wlib/mswlib/getline/README.md5
-rw-r--r--app/wlib/mswlib/getline/getline.c73
-rw-r--r--app/wlib/mswlib/getopt.c87
-rw-r--r--app/wlib/mswlib/gwin32.c155
-rw-r--r--app/wlib/mswlib/mswbitmap.c252
-rw-r--r--app/wlib/mswlib/mswbox.c45
-rw-r--r--app/wlib/mswlib/mswbutt.c341
-rw-r--r--app/wlib/mswlib/mswchoic.c357
-rw-r--r--app/wlib/mswlib/mswcolor.c131
-rw-r--r--app/wlib/mswlib/mswdraw.c1921
-rw-r--r--app/wlib/mswlib/mswedit.c592
-rw-r--r--app/wlib/mswlib/mswint.h181
-rw-r--r--app/wlib/mswlib/mswlines.c53
-rw-r--r--app/wlib/mswlib/mswlist.c1285
-rw-r--r--app/wlib/mswlib/mswmenu.c694
-rw-r--r--app/wlib/mswlib/mswmisc.c882
-rw-r--r--app/wlib/mswlib/mswmsg.c168
-rw-r--r--app/wlib/mswlib/mswpref.c442
-rw-r--r--app/wlib/mswlib/mswprint.c158
-rw-r--r--app/wlib/mswlib/mswsplash.c196
-rw-r--r--app/wlib/mswlib/mswstatus.c38
-rw-r--r--app/wlib/mswlib/mswtext.c568
-rw-r--r--app/wlib/mswlib/simple-gettext.c600
-rw-r--r--app/wlib/mswlib/sysinfo.c138
-rw-r--r--app/wlib/mswlib/unittest/CMakeLists.txt16
-rw-r--r--app/wlib/mswlib/utf8conv.c277
31 files changed, 5429 insertions, 4735 deletions
diff --git a/app/wlib/mswlib/CMakeLists.txt b/app/wlib/mswlib/CMakeLists.txt
index 07558f9..1d8464a 100644
--- a/app/wlib/mswlib/CMakeLists.txt
+++ b/app/wlib/mswlib/CMakeLists.txt
@@ -1,50 +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})
-
-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 d35f19a..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>
@@ -29,192 +29,215 @@
static char *lastErrorMessage; /**< store last message from FreeImage */
#define ERRORPUNCTUATION " : "
-/**
- * FreeImage error handler
- * \param fif Format / Plugin responsible for the error
- * \param message Error message
+/**
+ * FreeImage error handler
+ * \param fif Format / Plugin responsible for the error
+ * \param message Error message
*/
-static void
-HandleFreeImageError(FREE_IMAGE_FORMAT fif, const char *message)
-{
- unsigned totalLength = strlen(message) + 1;
-
- if (fif != FIF_UNKNOWN) {
- totalLength += strlen(FreeImage_GetFormatFromFIF(fif)) + strlen(ERRORPUNCTUATION);
- }
-
- lastErrorMessage = malloc(totalLength);
-
- if (fif != FIF_UNKNOWN) {
- sprintf(lastErrorMessage,
- "%s" ERRORPUNCTUATION "%s",
- FreeImage_GetFormatFromFIF(fif),
- message);
- } else {
- strcpy(lastErrorMessage, message);
- }
+static void
+HandleFreeImageError( FREE_IMAGE_FORMAT fif, const char *message )
+{
+ size_t totalLength = strlen( message ) + 1;
+
+ if( fif != FIF_UNKNOWN ) {
+ totalLength += strlen( FreeImage_GetFormatFromFIF( fif ) ) + strlen(
+ ERRORPUNCTUATION );
+ }
+
+ lastErrorMessage = malloc( totalLength );
+
+ if( fif != FIF_UNKNOWN ) {
+ sprintf( lastErrorMessage,
+ "%s" ERRORPUNCTUATION "%s",
+ FreeImage_GetFormatFromFIF( fif ),
+ message );
+ } else {
+ strcpy( lastErrorMessage, message );
+ }
}
-/**
-* Load the background image
-* \param bd drawing context
-* \param path filename for image file, if NULL the existing background will be removed
-* \param error returned error message
-* \return -1 unsupported or invalid file, 0 success, 1 background removed
+/**
+* Load the background image
+* \param bd drawing context
+* \param path filename for image file, if NULL the existing background will be removed
+* \param error returned error message
+* \return -1 unsupported or invalid file, 0 success, 1 background removed
*/
int
-wDrawSetBackground(wDraw_p bd, char * path, char ** error)
+wDrawSetBackground( wDraw_p bd, char * path, char ** error )
{
- FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
+ FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
+
+ FreeImage_SetOutputMessage( HandleFreeImageError );
- FreeImage_SetOutputMessage(HandleFreeImageError);
-
- if (lastErrorMessage) {
- free(lastErrorMessage);
- lastErrorMessage = NULL;
+ if( lastErrorMessage ) {
+ free( lastErrorMessage );
+ lastErrorMessage = NULL;
}
- if (path) {
- // check the file signature and deduce its format
- // (the second argument is currently not used by FreeImage)
- fif = FreeImage_GetFileType(path, 0);
-
- if (fif == FIF_UNKNOWN) {
- // no signature ?
- // try to guess the file format from the file extension
- fif = FreeImage_GetFIFFromFilename(path);
- }
-
- // check that the plugin has reading capabilities ...
- if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
- // ok, let's load the file
- bd->background = FreeImage_Load(fif, path, 0);
-
- // unless a bad file format, we are done !
- if (!bd->background) {
- *error = lastErrorMessage;
- return (-1);
- } else {
- return (0);
- }
- } else {
- *error = strdup(_("Image file is invalid or cannot be read."));
- return (-1);
- }
- } else {
- if (bd->background) {
- FreeImage_Unload(bd->background);
- bd->background = 0;
- }
-
- return (1);
- }
+ if( path ) {
+ // check the file signature and deduce its format
+ // (the second argument is currently not used by FreeImage)
+ fif = FreeImage_GetFileType( path, 0 );
+
+ if( fif == FIF_UNKNOWN ) {
+ // no signature ?
+ // try to guess the file format from the file extension
+ fif = FreeImage_GetFIFFromFilename( path );
+ }
+
+ // check that the plugin has reading capabilities ...
+ if( ( fif != FIF_UNKNOWN ) && FreeImage_FIFSupportsReading( fif ) ) {
+ // ok, let's load the file
+ bd->background = FreeImage_Load( fif, path, 0 );
+
+ // unless a bad file format, we are done !
+ if( !bd->background ) {
+ *error = lastErrorMessage;
+ return ( -1 );
+ } else {
+ return ( 0 );
+ }
+ } else {
+ *error = _strdup( _( "Image file is invalid or cannot be read." ) );
+ return ( -1 );
+ }
+ } else {
+ if( bd->background ) {
+ FreeImage_Unload( bd->background );
+ bd->background = 0;
+ }
+
+ return ( 1 );
+ }
}
+/**
+ * Use a loaded background in another context.
+ *
+ * \param from context with background
+ * \param to context to get a reference to the existing background
+ */
-/**
-* Draw background to screen. The background will be sized and rotated before being shown. The bitmap
-* is scaled so that the width is equal to size. The height is changed proportionally.
-*
-* \param bd drawing context
-* \param pos_x, pos_y bitmap position
-* \param size desired width after scaling
-* \param angle
-* \param screen visibility of bitmap in percent
+void
+wDrawCloneBackground( wDraw_p from, wDraw_p to )
+{
+ if( from->background ) {
+ to->background = from->background;
+ } else {
+ to->background = NULL;
+ }
+}
+
+/**
+* Draw background to screen. The background will be sized and rotated before being shown. The bitmap
+* is scaled so that the width is equal to size. The height is changed proportionally.
+*
+* \param bd drawing context
+* \param pos_x, pos_y bitmap position
+* \param size desired width after scaling
+* \param angle
+* \param screen visibility of bitmap in percent
*/
void
-wDrawShowBackground(wDraw_p bd, wPos_t pos_x, wPos_t pos_y, wPos_t size,
- wAngle_t angle, int screen)
+wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y,
+ wWinPix_t size,
+ wAngle_t angle, int screen )
{
- if (bd->background) {
- double scale;
- FIBITMAP *tmp;
- FIBITMAP *rotated;
-
- if (size == 0) {
- scale = 1.0;
- } else {
- scale = (double)size / FreeImage_GetWidth(bd->background);
- }
-
- tmp = FreeImage_RescaleRect(bd->background,
- (int)((double)FreeImage_GetWidth(bd->background) * scale),
- (int)((double)FreeImage_GetHeight(bd->background) * scale),
- 0,
- 0,
- FreeImage_GetWidth(bd->background),
- FreeImage_GetHeight(bd->background),
- FILTER_BILINEAR,
- 0);
- FreeImage_AdjustColors(tmp, screen, -screen, 1.0, FALSE);
- FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(tmp);
-
- switch (image_type) {
- case FIT_BITMAP:
- switch (FreeImage_GetBPP(tmp)) {
- case 8: {
- BYTE color = 255;
- rotated = FreeImage_Rotate(tmp, angle, &color);
- }
- break;
-
- case 24: // we could also use 'RGBTRIPLE color' here
- case 32: {
- RGBQUAD color = { 255, 255, 255, 0 };
- // for 24-bit images, the first 3 bytes will be read
- // for 32-bit images, the first 4 bytes will be read
- rotated = FreeImage_Rotate(tmp, angle, &color);
- }
- break;
- }
-
- break;
-
- case FIT_UINT16: {
- WORD color = 255;
- rotated = FreeImage_Rotate(tmp, angle, &color);
- }
- break;
-
- case FIT_RGB16: // we could also use 'FIRGB16 color' here
- case FIT_RGBA16: {
- FIRGBA16 color = { 255, 255, 255, 0 };
- // for RGB16 images, the first 3 WORD will be read
- // for RGBA16 images, the first 4 WORD will be read
- rotated = FreeImage_Rotate(tmp, angle, &color);
- }
- break;
-
- case FIT_FLOAT: {
- float color = 1.0F;
- rotated = FreeImage_Rotate(tmp, angle, &color);
- }
- break;
-
- case FIT_RGBF: // we could also use 'FIRGBF color' here
- case FIT_RGBAF: {
- FIRGBAF color = { 1, 1, 1, 0 };
- // for RGBF images, the first 3 float will be read
- // for RGBAF images, the first 4 float will be read
- rotated = FreeImage_Rotate(tmp, angle, &color);
- }
- break;
- }
-
- SetDIBitsToDevice(bd->hDc,
- pos_x,
- bd->h - pos_y - FreeImage_GetHeight(rotated),
- FreeImage_GetWidth(rotated),
- FreeImage_GetHeight(rotated),
- 0, 0,
- 0,
- FreeImage_GetHeight(rotated),
- FreeImage_GetBits(rotated),
- FreeImage_GetInfo(rotated),
- DIB_RGB_COLORS);
- FreeImage_Unload(tmp);
- FreeImage_Unload(rotated);
- }
-} \ No newline at end of file
+ if( bd->background ) {
+ double scale;
+ FIBITMAP *tmp;
+ FIBITMAP *rotated;
+
+ if( size == 0 ) {
+ scale = 1.0;
+ } else {
+ scale = ( double )size / FreeImage_GetWidth( bd->background );
+ }
+
+ tmp = FreeImage_RescaleRect( bd->background,
+ ( int )( ( double )FreeImage_GetWidth( bd->background ) * scale ),
+ ( int )( ( double )FreeImage_GetHeight( bd->background ) * scale ),
+ 0,
+ 0,
+ FreeImage_GetWidth( bd->background ),
+ FreeImage_GetHeight( bd->background ),
+ FILTER_BILINEAR,
+ 0 );
+
+ if( tmp == NULL ) {
+ return;
+ }
+
+ FreeImage_AdjustColors( tmp, screen, -screen, 1.0, FALSE );
+ FREE_IMAGE_TYPE image_type = FreeImage_GetImageType( tmp );
+
+ switch( image_type ) {
+ case FIT_BITMAP:
+ switch( FreeImage_GetBPP( tmp ) ) {
+ case 8: {
+ BYTE color = 255;
+ rotated = FreeImage_Rotate( tmp, angle, &color );
+ }
+ break;
+
+ case 24: // we could also use 'RGBTRIPLE color' here
+ case 32: {
+ RGBQUAD color = { 255, 255, 255, 0 };
+ // for 24-bit images, the first 3 bytes will be read
+ // for 32-bit images, the first 4 bytes will be read
+ rotated = FreeImage_Rotate( tmp, angle, &color );
+ }
+ break;
+ }
+
+ break;
+
+ case FIT_UINT16: {
+ WORD color = 255;
+ rotated = FreeImage_Rotate( tmp, angle, &color );
+ }
+ break;
+
+ case FIT_RGB16: // we could also use 'FIRGB16 color' here
+ case FIT_RGBA16: {
+ FIRGBA16 color = { 255, 255, 255, 0 };
+ // for RGB16 images, the first 3 WORD will be read
+ // for RGBA16 images, the first 4 WORD will be read
+ rotated = FreeImage_Rotate( tmp, angle, &color );
+ }
+ break;
+
+ case FIT_FLOAT: {
+ float color = 1.0F;
+ rotated = FreeImage_Rotate( tmp, angle, &color );
+ }
+ break;
+
+ case FIT_RGBF: // we could also use 'FIRGBF color' here
+ case FIT_RGBAF: {
+ FIRGBAF color = { 1, 1, 1, 0 };
+ // for RGBF images, the first 3 float will be read
+ // for RGBAF images, the first 4 float will be read
+ rotated = FreeImage_Rotate( tmp, angle, &color );
+ }
+ break;
+ }
+
+ SetDIBitsToDevice( bd->hDc,
+ pos_x,
+ bd->h - pos_y - FreeImage_GetHeight( rotated ),
+ FreeImage_GetWidth( rotated ),
+ FreeImage_GetHeight( rotated ),
+ 0, 0,
+ 0,
+ FreeImage_GetHeight( rotated ),
+ FreeImage_GetBits( rotated ),
+ FreeImage_GetInfo( rotated ),
+ DIB_RGB_COLORS );
+ FreeImage_Unload( tmp );
+ FreeImage_Unload( rotated );
+ }
+}
diff --git a/app/wlib/mswlib/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 5bd7a8e..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) { \
@@ -31,10 +31,6 @@ typedef struct {
#ifdef WINDOWS
-#ifndef WIN32
-#define FAR _far
-#endif
-#define M_PI 3.14159
#define strcasecmp _stricmp
#else
#endif
diff --git a/app/wlib/mswlib/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 6b0c7f3..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
*
@@ -40,7 +39,7 @@
#include <errno.h>
#include <ctype.h>
#if defined(_MSC_VER) || defined(__DMC__)
-# include <io.h>
+#include <io.h>
#endif /* _MSC_VER || __DMC__ */
#ifndef SUBLANG_SERBIAN_LATIN_BA
@@ -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 95b8a69..9069c35 100644
--- a/app/wlib/mswlib/mswbitmap.c
+++ b/app/wlib/mswlib/mswbitmap.c
@@ -18,40 +18,38 @@
*
* 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>
#include <stdio.h>
#include <assert.h>
-#include "misc.h"
#include "mswint.h"
#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,
- wPos_t w,
- wPos_t h,
- const char * bits )
+ COLORREF fgCol1,
+ COLORREF fgCol2,
+ COLORREF bgCol,
+ int w,
+ int h,
+ const char * bits )
{
HDC hDc;
HDC hButtDc;
@@ -70,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 );
@@ -85,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 );
@@ -100,12 +99,12 @@ HBITMAP mswCreateBitMap(
return hBitMap;
}
-dynArr_t bitmap_da;
+static dynArr_t bitmap_da;
#define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N)
#define bitmap(N) DYNARR_N(HBITMAP,bitmap_da,N)
void mswRegisterBitMap(
- HBITMAP hBm )
+ HBITMAP hBm )
{
DYNARR_APPEND( HBITMAP, bitmap_da, 10 );
bitmap(bitmap_da.cnt-1) = hBm;
@@ -114,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
@@ -132,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 ));
@@ -181,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
@@ -252,12 +256,13 @@ void mswDrawIcon(
* \return pointer to icon
*/
-wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor color )
+wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits,
+ wDrawColor color )
{
int lineLength;
int i, j;
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;
@@ -279,13 +284,13 @@ wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor col
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 );
@@ -294,19 +299,19 @@ wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor col
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;
@@ -324,18 +329,19 @@ wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor col
* 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[])
{
wIcon_p ip;
- int col, r, g, b, len;
+ int col, r, g, b;
+ size_t len;
int width, height;
char buff[3];
char * cp, * cq, * ptr;
int i, j, k;
- int lineLength;
+ size_t lineLength;
unsigned *keys;
unsigned numchars;
unsigned pixel;
@@ -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,12 +476,12 @@ 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
*/
void
-wIconDraw( wDraw_p d, wIcon_p bm, wPos_t x, wPos_t y )
+wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y )
{
mswDrawIcon( d->hDc, (int)x, (int)y, bm, FALSE, 0, 0 );
}
@@ -489,20 +497,22 @@ wIconDraw( wDraw_p d, wIcon_p bm, wPos_t x, wPos_t y )
*/
wControl_p
-wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP )
+wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option,
+ const struct wIcon_t * iconP )
{
wBitmap_p control;
int index;
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)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)");
@@ -510,7 +520,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP )
}
control->h = iconP->h;
control->w = iconP->w;
- control->data = iconP;
+ control->data = (void*)iconP;
return (wControl_p)control;
}
diff --git a/app/wlib/mswlib/mswbox.c b/app/wlib/mswlib/mswbox.c
index 04b3656..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,
- wPos_t w,
- wPos_t h )
+ wBox_p bb,
+ wWinPix_t w,
+ wWinPix_t h )
{
bb->w = w;
bb->h = h;
@@ -39,10 +38,10 @@ void wBoxSetSize(
static void repaintBox( HWND hWnd, wControl_p b )
-{
+{
HDC hDc;
wBox_p bb = (wBox_p)(b);
- wPos_t x0, y0, x1, y1;
+ wWinPix_t x0, y0, x1, y1;
char lastColor;
int lastRop;
static char colors[8][4][2] = {
@@ -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,
- wPos_t origX,
- wPos_t origY,
- const char * labelStr,
- wBoxType_e typ,
- wPos_t width,
- wPos_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 16f31c1..be72257 100644
--- a/app/wlib/mswlib/mswbutt.c
+++ b/app/wlib/mswlib/mswbutt.c
@@ -17,17 +17,24 @@
*
* 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>
#include "mswint.h"
-int kludge12 = 0;
+
+/** Macros for button repeat timers */
+#define REPEAT_STAGE0_DELAY 500
+#define REPEAT_STAGE1_DELAY 150
+#define REPEAT_STAGE2_DELAY 75
+#define STOP_TIMER (-1)
+#define INITIAL_WAIT (0)
+#define SLOW_REPEATS (1)
+#define FAST_REPEATS (2)
/*
*****************************************************************************
@@ -40,25 +47,29 @@ int kludge12 = 0;
static XWNDPROC oldButtProc = NULL;
struct wButton_t {
- WOBJ_COMMON
- wButtonCallBack_p action;
- wBool_t busy;
- wBool_t selected;
- wIcon_p icon;
- };
+ 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
@@ -66,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;
- POS_T offw=5, offh=5;
- TRIVERTEX vert[2] ;
- GRADIENT_RECT gRect;
+ wWinPix_t offw=5, offh=5;
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 );
@@ -106,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;
@@ -117,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++;
@@ -187,37 +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;
- POS_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)
+ if (!value) {
b->selected = FALSE;
- /*SendMessage( b->hWnd, BM_SETSTATE, (WPARAM)value, 0L );*/
- InvalidateRgn( b->hWnd, NULL, 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;*/
@@ -227,9 +204,64 @@ void wButtonSetLabel(
}
InvalidateRgn( b->hWnd, NULL, FALSE );
}
-
-static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+/**
+ * Button timer: handle timer events for buttons. These are used for
+ * auto-repeating presses. Three phases used are
+ * - initial delay before repetitions begin
+ * - slow repeats for a few cycles
+ * - fast repeats therafter
+ * - stop timer
+ *
+ * \param hWnd Handle of the window, unused
+ * \param message The message, unused
+ * \param timer The timer id is the wlib widget .
+ * \param timepast The timepast, unused
+ */
+
+void CALLBACK buttTimer(HWND hWnd, UINT message, UINT_PTR timer,
+ DWORD timepast)
+{
+ wButton_p b = (wButton_p)timer;
+ if (b->timer_id == 0) {
+ b->timer_state = STOP_TIMER;
+ return ;
+ }
+
+ /* Autorepeat state machine */
+ switch (b->timer_state) {
+ case INITIAL_WAIT:
+ b->timer_state = SLOW_REPEATS;
+ b->timer_count = 0;
+ KillTimer(hWnd, (UINT_PTR)b);
+ SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE1_DELAY, buttTimer);
+ break;
+ case SLOW_REPEATS: /* Enable slow auto-repeat */
+ if (b->timer_count++ > 10) {
+ /* Start fast auto-repeat */
+ b->timer_state = FAST_REPEATS;
+ KillTimer(hWnd, (UINT_PTR)b);
+ SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE2_DELAY, buttTimer);
+ }
+ break;
+ case FAST_REPEATS:
+ break;
+ case STOP_TIMER:
+ default:
+ KillTimer(hWnd, (UINT_PTR)b);
+ b->timer_id = 0;
+ return;
+ break;
+ }
+ if (b->action) {
+ b->action(b->data);
+ }
+ return;
+}
+
+
+static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam,
+ LPARAM lParam )
{
wButton_p bb = (wButton_p)b;
DRAWITEMSTRUCT * di = (DRAWITEMSTRUCT *)lParam;
@@ -240,19 +272,20 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L
case WM_COMMAND:
if (bb->action /*&& !bb->busy*/) {
bb->action( bb->data );
- return 0L;
+ return (LRESULT)0;
}
break;
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 = wParam;
- mi->itemWidth = (UINT)ceil(bb->w*scaleIcon);
- mi->itemHeight = (UINT)ceil(bb->h*scaleIcon);
- } return 0L;
+ mi->CtlID = (UINT)wParam;
+ 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) {
@@ -261,33 +294,29 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L
bb->selected = selected;
InvalidateRgn( bb->hWnd, NULL, FALSE );
}
- return TRUE;
+ return (LRESULT)TRUE;
}
break;
-
}
return DefWindowProc( hWnd, message, wParam, lParam );
}
static void buttDone(
- wControl_p b )
+ wControl_p b )
{
free(b);
}
LRESULT CALLBACK pushButt(
- HWND hWnd,
- UINT message,
- UINT wParam,
- LONG lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
-#ifdef WIN32
- long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
+
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wButton_p b = (wButton_p)mswMapIndex( inx );
PAINTSTRUCT ps;
@@ -297,7 +326,7 @@ LRESULT CALLBACK pushButt(
BeginPaint( hWnd, &ps );
buttDrawIcon( (wButton_p)b, ps.hdc );
EndPaint( hWnd, &ps );
- return 1L;
+ return (LRESULT)1;
}
break;
case WM_CHAR:
@@ -308,41 +337,55 @@ 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 0L;
+ return (LONG_PTR)0;
}
}
break;
case WM_KILLFOCUS:
- if ( b )
+ if ( b ) {
InvalidateRect( b->hWnd, NULL, TRUE );
- return 0L;
+ }
+ return (LRESULT)0;
+ break;
+ case WM_LBUTTONDOWN:
+ if (b->option&BO_REPEAT) {
+ SetTimer(hWnd, (UINT_PTR)b,REPEAT_STAGE0_DELAY,buttTimer);
+ b->timer_state = INITIAL_WAIT;
+ b->timer_id = (UINT_PTR)b;
+ }
break;
case WM_LBUTTONUP:
/* don't know why but this solves a problem with color selection */
Sleep( 0 );
+ if (b->timer_id) {
+ KillTimer(hWnd, (UINT_PTR)b);
+ }
+ b->timer_id = 0;
+ b->timer_state = STOP_TIMER;
break;
}
return CallWindowProc( oldButtProc, hWnd, message, wParam, lParam );
}
static callBacks_t buttonCallBacks = {
- mswRepaintLabel,
- buttDone,
- buttPush };
+ mswRepaintLabel,
+ buttDone,
+ buttPush
+};
wButton_p wButtonCreate(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wPos_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;
@@ -352,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 {
@@ -366,20 +410,21 @@ wButton_p wButtonCreate(
b->selected = 0;
mswComputePos( (wControl_p)b, x, y );
if (b->option&BO_ICON) {
- width = (wPos_t)ceil(bm->w*scaleIcon)+10;
- h = (int)ceil(bm->h*scaleIcon)+10;
+ width = (wWinPix_t)(bm->w+10);
+ h = bm->h+10;
b->icon = bm;
} else {
- width = (wPos_t)(width*mswScale);
+ width = (wWinPix_t)(width*mswScale);
}
style = ((b->option&BO_ICON)? BS_OWNERDRAW : BS_PUSHBUTTON) |
- WS_CHILD | WS_VISIBLE |
- 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)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;
@@ -393,16 +438,16 @@ wButton_p wButtonCreate(
mswCallBacks[B_BUTTON] = &buttonCallBacks;
mswChainFocus( (wControl_p)b );
- oldButtProc = (WNDPROC) SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt);
+ oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC,
+ (LONG_PTR)&pushButt);
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, 0L );
+ SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
InvalidateRect(b->hWnd, &rect, TRUE);
diff --git a/app/wlib/mswlib/mswchoic.c b/app/wlib/mswlib/mswchoic.c
index 2ac391a..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>
@@ -15,48 +14,49 @@
*****************************************************************************
*/
-int CHOICE_HEIGHT=(17);
-int CHOICE_MIN_WIDTH=25;
+#define CHOICE_HEIGHT (17)
+#define CHOICE_MIN_WIDTH (25)
static XWNDPROC oldChoiceItemProc = NULL;
static XWNDPROC newChoiceItemProc;
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 * * 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 ** labels;
+ const char * const * labels;
long cnt;
wChoiceItem_p * butts;
butts = (wChoiceItem_p*)bc->buttList;
for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ )
SendMessage( (*butts)->hWnd, BM_SETCHECK,
- (val==cnt)?1:0, 0L );
+ (WPARAM)((val==cnt)?1:0), (LPARAM)0 );
bc->oldVal = val;
- if (bc->valueP)
+ if (bc->valueP) {
*bc->valueP = val;
+ }
}
long wRadioGetValue(
- wChoice_p bc )
+ wChoice_p bc )
{
return bc->oldVal;
}
@@ -64,93 +64,94 @@ long wRadioGetValue(
void wToggleSetValue(
- wChoice_p bc,
- long val )
+ wChoice_p bc,
+ long val )
{
- const char ** labels;
+ const char * const * labels;
long cnt;
wChoiceItem_p * butts;
butts = (wChoiceItem_p*)bc->buttList;
for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ )
SendMessage( (*butts)->hWnd, BM_SETCHECK,
- (val & (1L<<cnt)) != 0, 0L );
+ (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 );
bc->oldVal = val;
- if (bc->valueP)
+ 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,
- wPos_t x,
- wPos_t y )
+ wControl_p b,
+ wWinPix_t x,
+ wWinPix_t y )
{
wChoice_p bc = (wChoice_p)b;
wChoiceItem_p * butts;
- wPos_t dx, dy;
+ wWinPix_t dx, dy;
dx = x - bc->x;
dy = y - bc->y;
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+=dx, (*butts)->y+=dy,
- 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;
}
-long FAR PASCAL _export pushChoiceItem(
- HWND hWnd,
- UINT message,
- UINT wParam,
- LONG lParam )
+LRESULT FAR PASCAL _export pushChoiceItem(
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
-#ifdef WIN32
- long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
-
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wControl_p b = mswMapIndex( inx );
switch (message) {
@@ -160,12 +161,12 @@ long 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 0L;
+ return (LRESULT)0;
}
}
break;
@@ -174,18 +175,18 @@ long 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:
@@ -194,53 +195,57 @@ LRESULT choiceItemProc(
for (rest = (wChoiceItem_p*)bc->buttList; *rest; rest++ ) {
switch (bc->type) {
case B_TOGGLE:
- num = rest-(wChoiceItem_p*)bc->buttList;
+ num = (int)(rest-(wChoiceItem_p*)bc->buttList);
if (*rest == me) {
bc->oldVal ^= (1L<<num);
}
SendMessage( (*rest)->hWnd, BM_SETCHECK,
- (bc->oldVal & (1L<<num)) != 0, 0L );
+ (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 );
break;
-
+
case B_RADIO:
if (*rest != me) {
- SendMessage( (*rest)->hWnd, BM_SETCHECK, 0, 0L );
+ SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)0, (LPARAM)0 );
} else {
- bc->oldVal = rest-(wChoiceItem_p*)bc->buttList;
- SendMessage( (*rest)->hWnd, BM_SETCHECK, 1, 0L );
+ bc->oldVal = (long)(rest-(wChoiceItem_p*)bc->buttList);
+ SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)1, (LPARAM)0 );
}
break;
}
}
- 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
@@ -257,27 +262,27 @@ static callBacks_t choiceItemCallBacks = {
*/
static wChoice_p choiceCreate(
- wType_e type,
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char **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 ** lp;
+ const char * const * lp;
int cnt;
wChoiceItem_p * butts;
- int ppx, ppy;
+ wWinPix_t ppx, ppy;
int bs;
HDC hDc;
HWND hButt;
- int lab_l;
+ size_t lab_l;
DWORD dw;
int w, maxW;
int pw, ph;
@@ -292,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 );
@@ -310,54 +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)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), 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)GetWindowLong( (*butts)->hWnd, GWL_WNDPROC );
- SetWindowLong( (*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc );
- if ( !mswThickFont )
- SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
+ }
+ 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);
+#endif
+ SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
}
*butts = NULL;
switch (b->type) {
@@ -375,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;
@@ -391,33 +402,33 @@ static wChoice_p choiceCreate(
wChoice_p wRadioCreate(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char **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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char **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 41bf6a9..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>
@@ -25,8 +24,8 @@
#define NUM_GRAYS (16)
#define NUM_COLORS (256)
-wDrawColor wDrawColorWhite = 0;
-wDrawColor wDrawColorBlack = 1;
+static wDrawColor wDrawColorWhite = 0;
+static wDrawColor wDrawColorBlack = 1;
#define MAX_COLOR_DISTANCE (3)
@@ -34,18 +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 */
- } };
-
-COLORREF mappedColors[NUM_COLORS];
+ }
+};
static long flipRGB( long rgb )
@@ -70,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 );
}
@@ -93,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;
@@ -106,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++;
}
@@ -132,8 +134,9 @@ void mswInitColorPalette( void )
PALETTEENTRY palPalEntry[256];
} pe;
- if (initted)
+ if (initted) {
return;
+ }
initted = TRUE;
mswGetCustomColors();
@@ -160,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;
@@ -172,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;
@@ -212,7 +219,7 @@ wDrawColor wDrawFindColor(
long wDrawGetRGB(
- wDrawColor color )
+ wDrawColor color )
{
long rgb;
int r, g, b;
@@ -236,6 +243,7 @@ static void mswGetCustomColors( void )
strcpy( colorName, "custom-" );
for ( inx=0; inx<16; inx++ ) {
sprintf( colorName+7, "%d", inx );
+ /** @prefs [mswcolor] custom-0=<rgb> to custom-15=<rgb> Set custom colors */
wPrefGetInteger( "mswcolor", colorName, &rgb, 0 );
aclrCust[inx] = flipRGB(rgb);
}
@@ -260,8 +268,8 @@ void mswPutCustomColors( void )
wBool_t wColorSelect(
- const char * title,
- wDrawColor * color )
+ const char * title,
+ wDrawColor * color )
{
long rgb;
@@ -286,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;
@@ -306,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,
- wPos_t x,
- wPos_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wPos_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;
@@ -337,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 );
@@ -356,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 c2739e6..7ab38ac 100644
--- a/app/wlib/mswlib/mswdraw.c
+++ b/app/wlib/mswlib/mswdraw.c
@@ -17,25 +17,19 @@
*
* 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>
#include <winuser.h>
-#ifdef WIN32
#define wFont_t tagLOGFONTA
-#else
-#define wFont_t tagLOGFONT
-#endif
-#include "misc.h"
#include "mswint.h"
#include <FreeImage.h>
@@ -48,9 +42,9 @@ wBool_t wDrawDoTempDraw = TRUE;
*****************************************************************************
*/
-static wBool_t initted = FALSE;
+#define M_PI 3.14159265358979323846
-long wDebugFont;
+static wBool_t initted = FALSE;
static FARPROC oldDrawProc;
@@ -59,69 +53,53 @@ static long tmpOp = 0x990066;
static long setOp = 0x8800c6;
static long clrOp = 0xbb0226;
-#define CENTERMARK_LENGTH 6
+#define CENTERMARK_LENGTH 4
-bool bDrawMainBM = 0;
+static bool bDrawMainBM = 0;
+
+typedef struct {
+ double x, y;
+} coOrd;
#ifdef SLOW
-static wPos_t XPIX2INCH( wDraw_p d, int ix )
+static wDrawPix_t XWINPIX2DRAWPIX( wDraw_p d, wWinPix_t ix )
{
- return (wPos_t)ix;
+ return (wDrawPix_t)ix;
}
-static wPos_t YPIX2INCH( wDraw_p d, int iy )
+static wDrawPix_t YWINPIX2DRAWPIX( wDraw_p d, wWinPix_t iy )
{
- wPos_t y;
- y = (wPos_t)(d->h-2-iy);
+ wWinPix_t y;
+ y = (wDrawPix_t)(d->h-2-iy);
return y;
}
-static int XINCH2PIX( wDraw_p d, wPos_t xx )
+static wWinPix_t XDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t xx )
{
- int ix;
- ix = (int)(xx);
+ wWinPix_t ix;
+ ix = (wWinPix_t)(xx);
return ix;
}
-static int YINCH2PIX( wDraw_p d, wPos_t y )
+static wWinPix_t YDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t y )
{
- int iy;
- iy = d->h-2 - (int)(y);
+ wWinPix_t iy;
+ iy = (d->h)-2 - (wWinPix_t)(y);
return iy;
}
-
-static wPos_t XPIXELSTOINCH( wDraw_p d, int ix )
-{
- return (wPos_t)ix;
-}
-
-
-static wPos_t YPIXELSTOINCH( wDraw_p d, int iy )
-{
- return (wPos_t)iy;
-}
#else
-#define XPIX2INCH( d, ix ) \
- ((wPos_t)ix)
-
-#define YPIX2INCH( d, iy ) \
- ((wPos_t)(d->h-2-iy))
-
-#define XINCH2PIX( d, xx ) \
- ((int)(xx))
-
-#define YINCH2PIX( d, y ) \
- (d->h-2 - (int)(y))
-
+#define XWINPIX2DRAWPIX( d, ix ) \
+ ((wDrawPix_t)ix)
-#define XPIXELSTOINCH( d, ix ) \
- ((wPos_t)ix)
+#define YWINPIX2DRAWPIX( d, iy ) \
+ ((wDrawPix_t)(d->h-2-iy))
+#define XDRAWPIX2WINPIX( d, xx ) \
+ ((wWinPix_t)(xx))
-#define YPIXELSTOINCH( d, iy ) \
- ((wPos_t)iy)
-
+#define YDRAWPIX2WINPIX( d, y ) \
+ (d->h - 2 - (wWinPix_t)(y))
#endif
/*
@@ -134,18 +112,15 @@ static wPos_t YPIXELSTOINCH( wDraw_p d, int iy )
-static long noNegDrawArgs = -1;
-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;
@@ -153,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;
@@ -170,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};
@@ -197,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();
@@ -211,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;
@@ -225,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;
@@ -244,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 );
}
@@ -293,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 ) {
@@ -302,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 ) {
@@ -310,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;
@@ -322,61 +299,67 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d )
void wDrawLine(
- wDraw_p d,
- wPos_t p0x,
- wPos_t p0y,
- wPos_t p1x,
- wPos_t p1y,
- 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;
setDrawMode( d, dw, lt, dc, dopt );
- p0.x = XINCH2PIX(d,p0x);
- p0.y = YINCH2PIX(d,p0y);
- p1.x = XINCH2PIX(d,p1x);
- p1.y = YINCH2PIX(d,p1y);
- if ( noNegDrawArgs>0 && !clip0( &p0, &p1, d ) )
- return;
+ p0.x = XDRAWPIX2WINPIX(d,p0x);
+ p0.y = YDRAWPIX2WINPIX(d,p0y);
+ p1.x = XDRAWPIX2WINPIX(d,p1x);
+ p1.y = YDRAWPIX2WINPIX(d,p1y);
+
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 );
}
}
+static double d2r(double angle)
+{
+ angle *= (M_PI / 180.0);
+ return 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 );
}
@@ -389,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
*
@@ -405,33 +395,34 @@ static double mswasin( double x, double h )
void wDrawArc(
- wDraw_p d,
- wPos_t px,
- wPos_t py,
- wPos_t r,
- double a0,
- double a1,
- int drawCenter,
- 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;
- double psx, psy, pex, pey, len, aa;
+ wDrawPix_t psx, psy, pex, pey;
+ double aa, ai;
RECT rect;
int needMoveTo;
wBool_t fakeArc = FALSE;
- len = a1/360.0 * (2 * M_PI) * r;
- if (len < 3)
- return;
+ // calculate the center coordinates
+ pc.x = XDRAWPIX2WINPIX( d, px );
+ pc.y = YDRAWPIX2WINPIX( d, py );
- p0.x = XINCH2PIX(d,px-r);
- p0.y = YINCH2PIX(d,py+r)+1;
- p1.x = XINCH2PIX(d,px+r);
- p1.y = YINCH2PIX(d,py-r)+1;
+ p0.x = XDRAWPIX2WINPIX(d,px-r);
+ p0.y = YDRAWPIX2WINPIX(d,py+r);
+ p1.x = XDRAWPIX2WINPIX(d,px+r);
+ p1.y = YDRAWPIX2WINPIX(d,py-r);
pex = px + r * mswsin(a0);
pey = py + r * mswcos(a0);
@@ -440,40 +431,43 @@ void wDrawArc(
/*pointOnCircle( &pe, p, r, a0 );
pointOnCircle( &ps, p, r, a0+a1 );*/
- ps.x = XINCH2PIX(d,(wPos_t)psx);
- ps.y = YINCH2PIX(d,(wPos_t)psy);
- pe.x = XINCH2PIX(d,(wPos_t)pex);
- pe.y = YINCH2PIX(d,(wPos_t)pey);
+ ps.x = XDRAWPIX2WINPIX(d,psx);
+ ps.y = YDRAWPIX2WINPIX(d,psy);
+ pe.x = XDRAWPIX2WINPIX(d,pex);
+ pe.y = YDRAWPIX2WINPIX(d,pey);
setDrawMode( d, dw, lt, dc, dopt );
- if (dw == 0)
+ if (dw == 0) {
dw = 1;
+ }
- if (r>4096) {
+ 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;
- if ( cnt <= 0 ) cnt = 1;
- if ( cnt > 360 ) cnt = 360;
- aa = a1 / cnt;
- psx = px + r * mswsin(a0);
- psy = py + r * mswcos(a0);
- pp0.x = XINCH2PIX( d, (wPos_t)psx );
- pp0.y = YINCH2PIX( d, (wPos_t)psy );
+ cnt = (int)(a1 / 2);
+ if ( cnt <= 0 ) { cnt = 1; }
+ if ( cnt > 180 ) { cnt = 180; }
+
+ ai = d2r(a1) / cnt;
+ aa = d2r(a0);
needMoveTo = TRUE;
+
for ( i=0; i<cnt; i++ ) {
- a0 += aa;
- psx = px + r * mswsin(a0);
- psy = py + r * mswcos(a0);
- pp2.x = pp1.x = XINCH2PIX( d, (wPos_t)psx );
- pp2.y = pp1.y = YINCH2PIX( d, (wPos_t)psy );
+ aa += ai;
+ psx = px + r * sin(aa);
+ psy = py + r * cos(aa);
+ pp2.x = pp1.x = XDRAWPIX2WINPIX( d, psx );
+ pp2.y = pp1.y = YDRAWPIX2WINPIX( d, psy );
if ( clip0( &pp0, &pp1, d ) ) {
if (needMoveTo) {
MoveTo( d->hDc, pp0.x, pp0.y );
@@ -486,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-1, pe.x, p1.y-1 );
- Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y-1, pe.x, p0.y-1 );
+ 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( drawCenter ) {
-
- // calculate the center coordinates
- pc.x = XINCH2PIX( d, px );
- pc.y = YINCH2PIX( d, py );
- // now draw the crosshair
- MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH/2, pc.y );
- LineTo( d->hDc, pc.x + CENTERMARK_LENGTH/2, pc.y );
- MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH/2 );
- LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH/2 );
-
- // invalidate the area of the crosshair
- rect.top = pc.y - CENTERMARK_LENGTH / 2 - 1;
- rect.bottom = pc.y + CENTERMARK_LENGTH / 2 + 1;
- rect.left = pc.x - CENTERMARK_LENGTH / 2 - 1;
- rect.right = pc.x + CENTERMARK_LENGTH / 2 + 1;
- myInvalidateRect( d, &rect );
+ if( sizeCenter ) {
+
+ // 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;
@@ -543,25 +552,28 @@ void wDrawArc(
}
void wDrawPoint(
- wDraw_p d,
- wPos_t px,
- wPos_t py,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
POINT p0;
RECT rect;
- p0.x = XINCH2PIX(d,px);
- p0.y = YINCH2PIX(d,py);
+ p0.x = XDRAWPIX2WINPIX(d,px);
+ p0.y = YDRAWPIX2WINPIX(d,py);
- if ( p0.x < 0 || p0.y < 0 )
+ 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;
@@ -581,133 +593,150 @@ 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 )
{
const char * face;
long size;
+ /** @prefs [msw window font] face=FontName */
face = wPrefGetString( "msw window font", "face" );
+ /** @prefs [msw window font] size=-24 */
wPrefGetInteger( "msw window font", "size", &size, -24 );
if (face) {
strncpy( logFont.lfFaceName, face, LF_FACESIZE );
@@ -732,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 );
}
@@ -744,45 +774,47 @@ 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(
- wPos_t *w,
- wPos_t *h,
- wPos_t *d,
- wPos_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 )
{
- int x, y;
+ wWinPix_t x, y;
HFONT newFont, prevFont;
DWORD extent;
int oldLfHeight;
TEXTMETRIC textMetric;
- if (fp == NULL)
+ if (fp == NULL) {
fp = &logFont;
+ }
fp->lfEscapement = 0;
oldLfHeight = fp->lfHeight;
fp->lfHeight = computeFontSize( bd, siz );
fp->lfWidth = 0;
newFont = CreateFontIndirect( fp );
prevFont = SelectObject( bd->hDc, newFont );
- extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, strlen(text) );
+ extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, (int)(strlen(text)) );
GetTextMetrics(bd->hDc, &textMetric);
x = LOWORD(extent);
y = HIWORD(extent);
- *w = XPIXELSTOINCH( bd, x );
- *h = YPIXELSTOINCH( bd, y );
- *d = YPIXELSTOINCH(bd, textMetric.tmDescent );
- *a = YPIXELSTOINCH(bd, textMetric.tmAscent );
+ *w = (wDrawPix_t)x;
+ *h = (wDrawPix_t)y;
+ *d = (wDrawPix_t)textMetric.tmDescent;
+ *a = (wDrawPix_t)textMetric.tmAscent;
SelectObject( bd->hDc, prevFont );
DeleteObject( newFont );
@@ -790,7 +822,7 @@ void wDrawGetTextSize(
}
/**
* Draw text
- *
+ *
* \param d device context
* \param px position x
* \param py position y
@@ -802,80 +834,74 @@ void wDrawGetTextSize(
* \param dopts drawing options
*/
void wDrawString(
- wDraw_p d,
- wPos_t px,
- wPos_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 = XINCH2PIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5);
- y = YINCH2PIX(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, 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, strlen(text));
- SetTextColor(d->hDc, old);
- }
-
- extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, 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 )
@@ -889,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 &timesFont[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 )
@@ -924,44 +951,50 @@ void wSetSelectedFontSize(wFontSize_t size)
void wDrawFilledRectangle(
- wDraw_p d,
- wPos_t px,
- wPos_t py,
- wPos_t sx,
- wPos_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);
- rect.left = XINCH2PIX(d,px);
- rect.right = XINCH2PIX(d,px+sx);
- rect.top = YINCH2PIX(d,py+sy);
- rect.bottom = YINCH2PIX(d,py);
+ rect.left = XDRAWPIX2WINPIX(d,px);
+ rect.right = XDRAWPIX2WINPIX(d,px+sx);
+ rect.top = YDRAWPIX2WINPIX(d,py+sy);
+ rect.bottom = YDRAWPIX2WINPIX(d,py);
if ( rect.right < 0 ||
- rect.bottom < 0 )
+ 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--;
@@ -973,7 +1006,7 @@ void wDrawFilledRectangle(
}
#ifdef DRAWFILLPOLYLOG
- static FILE * logF;
+static FILE * logF;
#endif
static dynArr_t wFillPoints_da;
@@ -994,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 = XINCH2PIX(d, pp->x);
- p.y = YINCH2PIX(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;
+ }
}
/**
@@ -1041,208 +1074,190 @@ static void addPoint(
*/
void wDrawPolygon(
- wDraw_p d,
- wPos_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 = XINCH2PIX(d,node[cnt-1][0]-1);
- rect.top = rect.bottom = YINCH2PIX(d,node[cnt-1][1]+1);
+ rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1);
+ rect.top = rect.bottom = YDRAWPIX2WINPIX(d,node[cnt-1][1]+1);
#ifdef DRAWFILLPOLYLOG
- logF = fopen("log.txt", "a");
- 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 (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 = node[i][0] - node[prevNode][0];
- int prevYDistance = node[i][1] - node[prevNode][1];
- int nextXDistance = node[nextNode][0]-node[i][0];
- int nextYDistance = node[nextNode][1]-node[i][1];
-
- // 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 (!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,
- wPos_t x,
- wPos_t y,
- wPos_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 wPos_t circlePts[MAX_FILLCIRCLE_POINTS][2];
- int inx, cnt;
- double dang;
-
- p0.x = XINCH2PIX(d,x-r);
- p0.y = YINCH2PIX(d,y+r)+1;
- p1.x = XINCH2PIX(d,x+r);
- p1.y = YINCH2PIX(d,y-r)+1;
-
- setDrawBrush( d, color, opts );
- if ( noNegDrawArgs > 0 && ( p0.x < 0 || p0.y < 0 ) ) {
- if ( r > MAX_FILLCIRCLE_POINTS )
- cnt = MAX_FILLCIRCLE_POINTS;
- else if ( r > 8 )
- cnt = r;
- 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 );
- }
+ static wDrawPix_t circlePts[MAX_FILLCIRCLE_POINTS][2];
+
+ 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 );
+ 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 );
}
}
@@ -1256,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" );
@@ -1307,14 +1323,14 @@ void wDrawClear( wDraw_p d )
void wDrawSetSize(
- wDraw_p d,
- wPos_t width,
- wPos_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 );*/
@@ -1322,9 +1338,9 @@ void wDrawSetSize(
void wDrawGetSize(
- wDraw_p d,
- wPos_t * width,
- wPos_t * height )
+ wDraw_p d,
+ wWinPix_t * width,
+ wWinPix_t * height )
{
*width = d->w-2;
*height = d->h-2;
@@ -1348,18 +1364,18 @@ double wDrawGetMaxRadius( wDraw_p d )
}
void wDrawClip(
- wDraw_p d,
- wPos_t x,
- wPos_t y,
- wPos_t w,
- wPos_t h )
+ wDraw_p d,
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t w,
+ wDrawPix_t h )
{
- int ix0, iy0, ix1, iy1;
+ wWinPix_t ix0, iy0, ix1, iy1;
HRGN hRgnClip;
- ix0 = XINCH2PIX(d,x);
- iy0 = YINCH2PIX(d,y);
- ix1 = XINCH2PIX(d,x+w);
- iy1 = YINCH2PIX(d,y+h);
+ ix0 = XDRAWPIX2WINPIX(d,x);
+ iy0 = YDRAWPIX2WINPIX(d,y);
+ ix1 = XDRAWPIX2WINPIX(d,x+w);
+ iy1 = YDRAWPIX2WINPIX(d,y+h);
/* Note: Ydim is upside down so iy1<iy0 */
hRgnClip = CreateRectRgn( ix0, iy1, ix1, iy0 );
SelectClipRgn( d->hDc, hRgnClip );
@@ -1370,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();
+}
+
+
/*
*****************************************************************************
@@ -1383,25 +1486,27 @@ void wRedraw( wDraw_p d )
*/
struct wDrawBitMap_t {
- wDrawBitMap_p next;
- wPos_t x;
- wPos_t y;
- wPos_t w;
- wPos_t h;
- char * bmx;
- wDrawColor color;
- HBITMAP bm;
- };
-wDrawBitMap_p bmRoot = NULL;
-
+ 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,
- wPos_t px,
- wPos_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;
@@ -1409,50 +1514,53 @@ void wDrawBitMap(
int x0, y0;
RECT rect;
- x0 = XINCH2PIX(d,px-bm->x);
- y0 = YINCH2PIX(d,py-bm->y+bm->h);
+ x0 = XDRAWPIX2WINPIX(d,px-bm->x);
+ y0 = YDRAWPIX2WINPIX(d,py-bm->y+bm->h);
#ifdef LATER
- if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) )
+ if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) ) {
return;
+ }
#endif
- if (dc == wDrawColorWhite) {
+ if (dc == drawColorWhite) {
mode = clrOp;
- dc = wDrawColorBlack;
+ dc = drawColorBlack;
} else {
mode = setOp;
}
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 ), bm->w, 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;
}
bmDc = CreateCompatibleDC( d->hDc );
setDrawMode( d, 0, wDrawLineSolid, dc, dopt );
oldBm = SelectObject( bmDc, bm->bm );
- BitBlt( d->hDc, x0, y0, bm->w, bm->h, bmDc, 0, 0, mode );
+ BitBlt( d->hDc, x0, y0, (wWinPix_t)bm->w, (wWinPix_t)bm->h, bmDc, 0, 0, mode );
SelectObject( bmDc, oldBm );
DeleteDC( bmDc );
if (d->hWnd) {
- rect.top = y0-1;
- rect.bottom = rect.top+bm->h+1;
- rect.left = x0-1;
- rect.right = rect.left+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;
@@ -1484,22 +1592,18 @@ wDrawBitMap_p wDrawBitMapCreate(
*****************************************************************************
*/
-int doSetFocus = 1;
+static int doSetFocus = 1;
-long FAR PASCAL XEXPORT mswDrawPush(
- HWND hWnd,
- UINT message,
- UINT wParam,
- LONG lParam )
+LRESULT FAR PASCAL XEXPORT mswDrawPush(
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
-#ifdef WIN32
- long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wDraw_p b;
- short int ix, iy;
- wPos_t x, y;
+ wWinPix_t ix, iy;
+ wDrawPix_t x, y;
HDC hDc;
PAINTSTRUCT ps;
wAction_t action;
@@ -1518,7 +1622,7 @@ long 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 );
@@ -1529,7 +1633,10 @@ long FAR PASCAL XEXPORT mswDrawPush(
}
b->wFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSX );
b->hFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSY );
- b->DPI = 96.0; /*min( b->wFactor, b->hFactor );*/
+ double dpi;
+ /** @prefs [Preference] ScreenDPI=96.0 Sets DPI of screen */
+ wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0);
+ b->DPI = dpi;
b->hWnd = hWnd;
SetROP2( b->hDc, R2_WHITE );
Rectangle( b->hDc, 0, 0, b->w, b->h );
@@ -1548,116 +1655,137 @@ long 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 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 );
- x = XPIX2INCH( b, ix );
- y = YPIX2INCH( b, iy );
+ x = XWINPIX2DRAWPIX( b, ix );
+ y = YWINPIX2DRAWPIX( b, iy );
b->lastX = x;
b->lastY = y;
- if (b->action)
+ if (b->action) {
b->action( b, b->data, action, x, y );
- if (b->hWnd)
+ }
+ if (b->hWnd) {
UpdateWindow(b->hWnd);
- return 0;
+ }
+ 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 + ( 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 0;
+ return (LRESULT)0;
case WM_PAINT:
b = (wDraw_p)mswMapIndex( inx );
@@ -1673,17 +1801,17 @@ long 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;
@@ -1703,6 +1831,13 @@ long 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;
}
@@ -1710,10 +1845,11 @@ long 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 */
@@ -1738,9 +1874,10 @@ 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 0;
+ }
+ return (LRESULT)0;
case WM_MOUSEHWHEEL:
if ( GET_KEYSTATE_WPARAM(wParam) & (MK_SHIFT|MK_MBUTTON)) {
if ( GET_WHEEL_DELTA_WPARAM(wParam) > 0 ) {
@@ -1749,9 +1886,10 @@ 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 0;
+ }
+ return (LRESULT)0;
}
return DefWindowProc( hWnd, message, wParam, lParam );
@@ -1787,27 +1925,30 @@ 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
+};
-wDraw_p drawList = NULL;
+static wDraw_p drawList = NULL;
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 );
+ }
}
}
@@ -1824,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 );
}
@@ -1840,27 +1981,22 @@ void mswRepaintAll( void )
wDraw_p wDrawCreate(
- wWin_p parent,
- wPos_t x,
- wPos_t y,
- const char * helpStr,
- long option,
- wPos_t w,
- wPos_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;
@@ -1870,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)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)" );
@@ -1909,7 +2045,7 @@ wDraw_p wDrawCreate(
*****************************************************************************
*/
-wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes )
+wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int planes )
{
wDraw_p d;
HDC hDc;
@@ -1926,7 +2062,7 @@ wDraw_p wBitMapCreate( wPos_t w, wPos_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;
@@ -1934,11 +2070,13 @@ wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes )
d->hBmMain = CreateCompatibleBitmap( hDc, d->w, d->h );
if ( d->hBmMain == (HBITMAP)0 ) {
wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Main fails", "Ok", NULL );
+ ReleaseDC(mswHWnd, hDc);
return FALSE;
}
d->hBmTemp = CreateCompatibleBitmap( hDc, d->w, d->h );
if ( d->hBmTemp == (HBITMAP)0 ) {
wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Temp fails", "Ok", NULL );
+ ReleaseDC(mswHWnd, hDc);
return FALSE;
}
d->hasPalette = (GetDeviceCaps(hDc,RASTERCAPS ) & RC_PALETTE) != 0;
@@ -1992,63 +2130,74 @@ 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) {
- bSuccess = FreeImage_Save(fif, dib2, fileName, PNG_DEFAULT);
- return bSuccess;
- }
- }
- FreeImage_Unload(dib2);
-
- return bSuccess;
+ 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) {
+ case FIF_JPEG:
+ flags = JPEG_QUALITYNORMAL;
+ break;
+ case FIF_PNG:
+ flags = PNG_DEFAULT;
+ break;
+ default:
+ flags = 0; // whatver the default is for the file format
+ }
+ bSuccess = FreeImage_Save(fif, dib2, fileName, flags);
+ }
+ }
+ FreeImage_Unload(dib2);
+
+ return bSuccess;
}
diff --git a/app/wlib/mswlib/mswedit.c b/app/wlib/mswlib/mswedit.c
index dc70ac3..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,72 +30,68 @@
struct wString_t {
- WOBJ_COMMON
- char * valueP;
- wIndex_t valueL;
- wStringCallBack_p action;
- };
+ 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
static XWNDPROC oldEditProc = NULL;
static XWNDPROC newEditProc;
-static void triggerString( wControl_p b );
+static void triggerString( wString_p b );
#ifdef LATER
static void triggerInteger( wControl_p b );
static void triggerFloat( wControl_p b );
#endif
-long FAR PASCAL _export pushEdit(
- HWND hWnd,
- UINT message,
- UINT wParam,
- LONG lParam )
+LRESULT FAR PASCAL _export pushEdit(
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
-#ifdef WIN32
- long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
- wControl_p b = mswMapIndex(inx);
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
+ wString_p b = (wString_p)mswMapIndex(inx);
- switch (message)
- {
+ switch (message) {
case WM_CHAR:
- if (b != NULL) {
- switch (wParam) {
- case VK_RETURN:
- triggerString(b);
- return (0L);
- break;
- case 0x1B:
- case 0x09:
- SetFocus(((wControl_p)(b->parent))->hWnd);
- SendMessage(((wControl_p)(b->parent))->hWnd, WM_CHAR,
- wParam, lParam);
- return 0L;
- }
- }
- 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);
@@ -112,61 +107,61 @@ long 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, 0, (DWORD)arg );
-#ifdef WIN32
- SendMessage( b->hWnd, EM_SETSEL, 0, -1 );
- SendMessage( b->hWnd, EM_SCROLLCARET, 0, 0L );
-#else
- SendMessage( b->hWnd, EM_SETSEL, 0, MAKELPARAM(len,len) );
-#endif
- SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L );
+ SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)arg );
+ SendMessage( b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1 );
+ SendMessage( b->hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0 );
+ SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 );
}
void wStringSetWidth(
- wString_p b,
- wPos_t w )
+ 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, sizeof buff, (DWORD)buff );
+ SendMessage( b->hWnd, WM_GETTEXT, (WPARAM)sizeof buff, (LPARAM)buff );
return buff;
}
/**
* 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 = SendMessage(bs->hWnd, EM_LINELENGTH, (WPARAM)0, 0L);
-
- if (chars) {
- tmpBuffer = malloc(chars > sizeof(WORD)? chars + 1 : sizeof(WORD) + 1);
- *(WORD *)tmpBuffer = chars;
- SendMessage(bs->hWnd, (UINT)EM_GETLINE, 0, (LPARAM)tmpBuffer);
- tmpBuffer[chars] = '\0';
- }
+ 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);
+ return (tmpBuffer);
}
/**
@@ -177,126 +172,126 @@ static char *getString(wString_p bs)
*/
static void triggerString(
- wControl_p b)
+ wString_p b)
{
- wString_p bs = (wString_p)b;
-
- char *enteredString = getString(bs);
- if (enteredString)
- {
- if (bs->valueP) {
- strcpy(bs->valueP, enteredString);
- }
- if (bs->action) {
- bs->action(enteredString, bs->data);
- }
+ const char *output = "\n";
+
+ 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);
}
}
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, 0, 0L);
- 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, FALSE, 0L);
- }
- 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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- POS_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;
+ }
-#ifdef WIN32
b->hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL,
- ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
- b->x, b->y,
- width, mswEditHeight,
- ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
-#else
- b->hWnd = CreateWindow( "EDIT", NULL,
- ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
- b->x, b->y,
- width, mswEditHeight,
- ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
-#endif
+ 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;
}
newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst );
- oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC );
+ oldEditProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC);
+ SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newEditProc);
+#ifdef _OLDCODE
+ oldEditProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWL_WNDPROC );
SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc );
+#endif // WIN64
if (b->valueP) {
- SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)b->valueP );
+ SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)b->valueP );
}
- SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L );
- if ( !mswThickFont )
- SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
+ SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (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;
@@ -322,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 );
@@ -333,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;
@@ -349,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 );
}
@@ -367,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;
@@ -400,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 );
@@ -427,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
@@ -452,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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- POS_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;
@@ -491,35 +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;
}
-#ifdef CONTROL3D
- Ctl3dSubclassCtl( b->hWnd);
-#endif
-
+
newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst );
oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC );
SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc );
- 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 );
@@ -547,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 );
@@ -558,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;
@@ -627,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 );
@@ -655,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
@@ -677,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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- POS_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;
@@ -715,37 +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;
}
-#ifdef CONTROL3D
- Ctl3dSubclassCtl( b->hWnd);
-#endif
-
+
newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst );
oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC );
SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc );
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 e560053..525a37c 100644
--- a/app/wlib/mswlib/mswint.h
+++ b/app/wlib/mswlib/mswint.h
@@ -1,15 +1,31 @@
+/** \file mswint.h
+ * Windows specific definitions and prototypes for wlib
+ */
+
+/* XTrackCAD - Model Railroad CAD
+ * Copyright (C) 2005 Dave Bullis
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include "wlib.h"
#include "mswlib.h"
-//#include "dynarr.h"
-#include "common.h"
-#ifndef WIN32
-/*#define CONTROL3D*/
-#endif
-#include "stdio.h"
+#include "dynarr.h"
-#ifdef CONTROL3D
-#include "ctl3d.h"
-#endif
+#include <FreeImage.h>
+#include <stdio.h>
#ifdef WIN32
#ifdef FAR
@@ -40,39 +56,39 @@
#endif
#ifndef CAST_AWAY_CONST
- #define CAST_AWAY_CONST (char *)
+#define CAST_AWAY_CONST (char *)
#endif
#define BOOL_T wBool_t
-#define POS_T wPos_t
#define INDEX_T wIndex_t
#define INTEGER_T wInteger_t
typedef enum {
- W_MAIN, W_POPUP,
- B_BUTTON, B_STRING, B_INTEGER, B_FLOAT,
- B_LIST, B_DROPLIST, B_COMBOLIST,
- B_RADIO, B_TOGGLE,
- B_DRAW, B_TEXT, B_MESSAGE, B_LINES,
- B_MENUITEM, B_CHOICEITEM, B_BOX,
- B_BITMAP } wType_e;
-
-typedef void (*repaintProcCallback_p)( HWND, wControl_p );
-typedef void (*doneProcCallback_p)( wControl_p b );
-typedef LRESULT (*messageCallback_p)( wControl_p, HWND, UINT, WPARAM, LPARAM );
-typedef void (*setTriggerCallback_p)( wControl_p b );
-typedef void (*setBusyCallback_p)( wControl_p, BOOL_T );
-typedef void (*showCallback_p)( wControl_p, BOOL_T );
-typedef void (*setPosCallback_p)( wControl_p, wPos_t, wPos_t );
+ W_MAIN, W_POPUP,
+ B_BUTTON, B_STRING, B_INTEGER, B_FLOAT,
+ B_LIST, B_DROPLIST, B_COMBOLIST,
+ B_RADIO, B_TOGGLE,
+ B_DRAW, B_TEXT, B_MESSAGE, B_LINES,
+ B_MENUITEM, B_CHOICEITEM, B_BOX,
+ B_BITMAP
+} wType_e;
+
+typedef void ( *repaintProcCallback_p )( HWND, wControl_p );
+typedef void ( *doneProcCallback_p )( wControl_p b );
+typedef LRESULT( *messageCallback_p )( wControl_p, HWND, UINT, WPARAM, LPARAM );
+typedef void ( *setTriggerCallback_p )( wControl_p b );
+typedef void ( *setBusyCallback_p )( wControl_p, BOOL_T );
+typedef void ( *showCallback_p )( wControl_p, BOOL_T );
+typedef void ( *setPosCallback_p )( wControl_p, wWinPix_t, wWinPix_t );
typedef struct {
- repaintProcCallback_p repaintProc;
- doneProcCallback_p doneProc;
- messageCallback_p messageProc;
- setBusyCallback_p setBusyProc;
- showCallback_p showProc;
- setPosCallback_p setPosProc;
- } callBacks_t;
+ repaintProcCallback_p repaintProc;
+ doneProcCallback_p doneProc;
+ messageCallback_p messageProc;
+ setBusyCallback_p setBusyProc;
+ showCallback_p showProc;
+ setPosCallback_p setPosProc;
+} callBacks_t;
#define CALLBACK_CNT (B_BOX+1)
extern callBacks_t *mswCallBacks[CALLBACK_CNT];
@@ -83,67 +99,68 @@ extern callBacks_t *mswCallBacks[CALLBACK_CNT];
wControl_p next; \
wControl_p synonym; \
wWin_p parent; \
- POS_T x, y; \
- POS_T w, h; \
+ wWinPix_t x, y; \
+ wWinPix_t w, h; \
long option; \
- POS_T labelX, labelY; \
+ wWinPix_t labelX, labelY; \
const char * labelStr; \
const char * helpStr; \
const char * tipStr; \
+ char * errStr; \
HWND hWnd; \
void * data;\
wControl_p focusChainNext; \
- wBool_t shown;
+ wBool_t shown; \
+ wBool_t hilite;
struct wControl_t {
- WOBJ_COMMON
- };
+ WOBJ_COMMON
+};
typedef struct {
- unsigned key;
- wDrawColor color;
- } wIconColorMap_t;
+ unsigned key;
+ wDrawColor color;
+} wIconColorMap_t;
#define mswIcon_bitmap (1)
#define mswIcon_pixmap (2)
struct wIcon_t {
- int type;
- wPos_t w; /**< width */
- wPos_t h; /**< height */
- wDrawColor color;
- int colorcnt; /**< number of colors */
- RGBQUAD *colormap;
- char *pixels; /**< pointer to pixel information */
- int transparent; /**< index of transparent color */
- };
+ int type;
+ wWinPix_t w; /**< width */
+ wWinPix_t h; /**< height */
+ wDrawColor color;
+ int colorcnt; /**< number of colors */
+ RGBQUAD *colormap;
+ char *pixels; /**< pointer to pixel information */
+ int transparent; /**< index of transparent color */
+};
struct wDraw_t {
- WOBJ_COMMON
- HDC hDc;
- double wFactor;
- double hFactor;
- double DPI;
- wDrawRedrawCallBack_p drawRepaint;
- wDrawActionCallBack_p action;
- HBITMAP hBmMain;
- HBITMAP hBmTemp;
- HBITMAP hBmOld;
- HPEN hPen;
- HBRUSH hBrush;
- wDraw_p drawNext;
- wBool_t hasPalette;
- int paletteClock;
- HBITMAP hBmBackup;
- HDC hDcBackup;
- HBITMAP hBmBackupOld;
- void *background;
- wBool_t bTempMode;
- wBool_t bCopiedMain;
-
- wPos_t lastX;
- wPos_t lastY;
-
- };
+ WOBJ_COMMON
+ HDC hDc;
+ double wFactor;
+ double hFactor;
+ double DPI;
+ wDrawRedrawCallBack_p drawRepaint;
+ wDrawActionCallBack_p action;
+ HBITMAP hBmMain;
+ HBITMAP hBmTemp;
+ HBITMAP hBmOld;
+ HPEN hPen;
+ HBRUSH hBrush;
+ wDraw_p drawNext;
+ wBool_t hasPalette;
+ int paletteClock;
+ HBITMAP hBmBackup;
+ HDC hDcBackup;
+ HBITMAP hBmBackupOld;
+ FIBITMAP *background;
+ wBool_t bTempMode;
+ wBool_t bCopiedMain;
+ wDrawPix_t lastX;
+ wDrawPix_t lastY;
+
+};
extern HINSTANCE mswHInst;
extern char mswTmpBuff[1024];
@@ -156,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 * );
@@ -168,7 +183,7 @@ void mswResize( wWin_p );
wControl_p mswMapIndex( INDEX_T );
void mswButtPush( wControl_p );
void * mswAlloc( wWin_p, wType_e, const char *, int, void *, int * );
-void mswComputePos( wControl_p, wPos_t, wPos_t );
+void mswComputePos( wControl_p, wWinPix_t, wWinPix_t );
void mswAddButton( wControl_p, BOOL_T, const char * );
void mswRepaintLabel( HWND, wControl_p );
int mswRegister( wControl_p );
@@ -178,7 +193,7 @@ void mswSetFocus( wControl_p );
void mswSetTrigger( wControl_p, setTriggerCallback_p );
void mswMenuPush( wControl_p );
void mswCreateCheckBitmaps( void );
-long FAR PASCAL XEXPORT mswDrawPush( HWND, UINT, UINT, LONG );
+LRESULT FAR PASCAL XEXPORT mswDrawPush( HWND, UINT, WPARAM, LPARAM );
#ifdef WIN32
DWORD GetTextExtent( HDC, CHAR *, UINT );
#endif
@@ -186,7 +201,7 @@ void mswRedrawAll( void );
void mswRepaintAll( void );
HDC mswGetPrinterDC( void );
int mswMenuAccelerator( wWin_p, long );
-void mswMenuMove( wMenu_p, wPos_t, wPos_t );
+void mswMenuMove( wMenu_p, wWinPix_t, wWinPix_t );
void mswRegisterBitMap( HBITMAP );
void mswFontInit( void );
void mswInitColorPalette( void );
@@ -202,5 +217,5 @@ void deleteBitmaps( void );
void mswDrawIcon( HDC, int, int, wIcon_p, int, COLORREF, COLORREF );
/* gwin32.c*/
-char *g_win32_getlocale (void);
+char *g_win32_getlocale( void );
diff --git a/app/wlib/mswlib/mswlines.c b/app/wlib/mswlib/mswlines.c
index be1330d..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;
- POS_T minX, maxX, minY, maxY;
+ 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 95ecec3..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,73 +19,75 @@ 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;
- wPos_t * colWidths;
- wBool_t * colRightJust;
- const char * * colTitles;
- wPos_t maxWidth;
- wPos_t scrollPos;
- HWND hScrollWnd;
- wPos_t scrollH;
- wPos_t dragPos;
- int dragCol;
- wPos_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, 0, 0 );
+ }
+ SendMessage( b->hWnd, msg, (WPARAM)0, (LPARAM)0 );
b->last = -1;
b->count = 0;
}
-void wListSetSize( wList_p bl, wPos_t w, wPos_t h )
+void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h )
{
int rc;
RECT rect;
- wPos_t y;
+ wWinPix_t y;
bl->w = w;
bl->h = h;
- 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,104 +98,111 @@ void wListSetSize( wList_p bl, wPos_t w, wPos_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 )
- SendMessage( bl->hWnd, LB_SETSEL, 0, MAKELPARAM(bl->last,0) );
- if ( index >= 0 )
- SendMessage( bl->hWnd, LB_SETSEL, 1, MAKELPARAM(index, 0) );
+ if ( bl->last != -1 ) {
+ SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)0, (LPARAM)bl->last );
+ }
+ if ( index >= 0 ) {
+ SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)1, (LPARAM)index );
+ }
} else {
SendMessage( bl->hWnd,
- bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, index, 0 );
+ bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)index, (LPARAM)0 );
}
if ( bl->last >= 0 ) {
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- bl->last, 0L );
- 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),
- index, 0L );
- 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, 0, (DWORD)(LPSTR)val );
+ SendMessage( bl->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)val );
bl->last = -1;
}
}
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), inx,
- (DWORD)(LPSTR)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,15 +212,16 @@ 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 {
msg = CB_GETLBTEXT;
}
}
- cnt = (int)SendMessage( bl->hWnd, msg, inx, (DWORD)(LPSTR)mswTmpBuff );
+ cnt = (int)SendMessage( bl->hWnd, msg, (WPARAM)inx, (LPARAM)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
if (s) {
strncpy(s, mswTmpBuff, siz);
@@ -220,29 +229,32 @@ wIndex_t wListGetValues(
}
if (bl->last >= 0) {
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- bl->last, 0L );
- 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,
- (DWORD)0L );
+ (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,
- (DWORD)0L );
+ (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,
- (DWORD)(LPSTR)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,
- (DWORD)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,
- (DWORD)0L );
+ 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,
- (DWORD)0L );
+ (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,
- (DWORD)-1L );
+ 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),
- inx, 0L );
+ (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,
- (DWORD)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, 0, 0L );
+ 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),
- inx, 0L );
+ (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),
- inx, 0L );
+ (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,
- (DWORD)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,
- (DWORD)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,
- (DWORD)ldp );
+ (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
+ (WPARAM)nindex,
+ (LPARAM)ldp );
return nindex;
}
int wListGetColumnWidths(
- wList_p bl,
- int colCnt,
- wPos_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,
- wPos_t x,
- wPos_t y )
+ wControl_p b,
+ wWinPix_t x,
+ wWinPix_t y )
{
wList_p bl = (wList_p)b;
- wPos_t x1, y1;
+ wWinPix_t x1, y1;
RECT rect;
-
+
bl->x = x1 = x;
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;
@@ -492,11 +516,12 @@ static void listRepaintLabel(
const char * * title;
int inx;
int start;
- wPos_t colWidth;
+ 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, 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,15 +609,15 @@ 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;
- long len;
+ size_t len;
listData * ldp;
HDC hDc;
LPMEASUREITEMSTRUCT lpmis;
@@ -597,7 +625,8 @@ LRESULT listProc(
LPDRAWITEMSTRUCT lpdis;
RECT rc, rc1;
char * cp0, * cp1;
- wPos_t colWidth, x;
+ wWinPix_t x;
+ int colWidth;
int nPos;
HFONT hFont;
HPEN hPen;
@@ -606,353 +635,388 @@ 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, inx, 0L );
- if ( ldp != NULL && ldp != (void*)LB_ERR ) {
- selected = ((long)SendMessage( bl->hWnd, LB_GETSEL, inx, 0L ) != 0L );
- if ( selected != ldp->selected ) {
- ldp->selected = selected;
- if ( selected ) {
- bl->last = inx;
- cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, bl->last, (DWORD)(LPSTR)mswTmpBuff );
- 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, 0, 0L );
- cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, bl->last,
- (DWORD)(LPSTR)mswTmpBuff );
- mswTmpBuff[cnt] = '\0';
if (bl->action) {
- ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA,
- bl->last, 0L );
+ 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, 0, 0L ) )
- (void)SendMessage( bl->hWnd, LB_SETCURSEL, bl->last, 0L );
- 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, 0, 0L );
- 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, bl->last,
- (DWORD)(LPSTR)mswTmpBuff );
- ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA,
- bl->last, 0L );
- 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, 0, 0L );
- if ( bl->last != inx )
- (void)SendMessage( bl->hWnd, CB_SETCURSEL, bl->last, 0L );
- 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, sizeof mswTmpBuff,
- (DWORD)(LPSTR)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),
- lpdis->itemID, 0L );
- rc = lpdis->rcItem;
- if (lpdis->itemAction & (ODA_DRAWENTIRE|ODA_SELECT|ODA_FOCUS)) {
- if( bl->type == B_LIST )
- hFont = SelectObject( lpdis->hDC, mswLabelFont );
- cnt = (int)SendMessage( lpdis->hwndItem,
- (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT),
- lpdis->itemID, (LONG)(LPSTR)mswTmpBuff );
- 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 TRUE;
- }
-
- break;
- case WM_HSCROLL:
- len = ((long)bl->maxWidth)-((long)bl->w);
- if ( len <= 0 )
- return 0;
- switch ( WSCROLL_PARAM_CODE ) {
- case SB_LEFT:
- if ( bl->scrollPos == 0 )
- return 0;
- bl->scrollPos = 0;
break;
- case SB_LINELEFT:
- case SB_PAGELEFT:
- if ( bl->scrollPos == 0 )
- return 0;
- for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) {
- if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) {
- bl->scrollPos = colWidth;
- break;
- }
- colWidth += bl->colWidths[inx];
+
+ case WM_HSCROLL:
+ len = ((long)bl->maxWidth)-((long)bl->w);
+ if ( len <= 0 ) {
+ return (LRESULT)0;
}
- break;
- case SB_LINERIGHT:
- case SB_PAGERIGHT:
- if ( bl->scrollPos >= len )
- return 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;
+ }
+ 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];
}
- 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;
+ case SB_THUMBPOSITION:
+ nPos = (int)WSCROLL_PARAM_NPOS;
+ bl->scrollPos = (int)(len*nPos/100);
+ break;
+ case SB_ENDSCROLL:
+ return (LRESULT)0;
}
- break;
- case SB_RIGHT:
- if ( bl->scrollPos >= len )
- return 0;
- bl->scrollPos = (int)len;
- break;
- case SB_THUMBTRACK:
- return 0;
- case SB_THUMBPOSITION:
- nPos = (int)WSCROLL_PARAM_NPOS;
- bl->scrollPos = (int)(len*nPos/100);
- break;
- case SB_ENDSCROLL:
- return 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 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 0L;
+ 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 0L;
+ }
+ 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 0L;
- }
-
return DefWindowProc( hWnd, message, wParam, lParam );
-}
+}
-long FAR PASCAL _export pushList(
- HWND hWnd,
- UINT message,
- UINT wParam,
- LONG lParam )
+LRESULT FAR PASCAL _export pushList(
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
-#ifdef WIN32
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr(hWnd, GWL_ID);
+ wControl_p b = mswMapIndex(inx);
+#ifdef OLDCODE
long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
wControl_p b = mswMapIndex( inx );
+#endif
switch (message) {
case WM_CHAR:
@@ -961,12 +1025,12 @@ long 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 0L;
+ return (LRESULT)0;
}
}
break;
@@ -974,18 +1038,14 @@ long FAR PASCAL _export pushList(
return CallWindowProc( oldListProc, hWnd, message, wParam, lParam );
}
-long FAR PASCAL _export pushCombo(
- HWND hWnd,
- UINT message,
- UINT wParam,
- LONG lParam )
+LRESULT FAR PASCAL _export pushCombo(
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
-#ifdef WIN32
- long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wControl_p b = mswMapIndex( inx );
switch (message) {
@@ -995,12 +1055,12 @@ long 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 0L;
+ return (LRESULT)0;
}
}
break;
@@ -1009,37 +1069,39 @@ long 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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- POS_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;
@@ -1054,18 +1116,14 @@ 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)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;
}
-#ifdef CONTROL3D
- Ctl3dSubclassCtl( b->hWnd );
-#endif
-
GetWindowRect( b->hWnd, &rect );
b->w = rect.right - rect.left;
b->h = rect.bottom - rect.top;
@@ -1078,40 +1136,49 @@ static wList_p listCreate(
if (addFocus) {
mswChainFocus( (wControl_p)b );
if (b->type == B_LIST) {
- newListProc = MakeProcInstance( (XWNDPROC)pushList, mswHInst );
- oldListProc = (XWNDPROC)GetWindowLong( b->hWnd, GWL_WNDPROC );
- SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newListProc );
+ newListProc = MakeProcInstance((XWNDPROC)pushList, mswHInst);
+ oldListProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC);
+ SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newListProc);
+#ifdef _OLDCODE
+ oldListProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC);
+ SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newListProc);
+#endif
} else {
- newComboProc = MakeProcInstance( (XWNDPROC)pushCombo, mswHInst );
- oldComboProc = (XWNDPROC)GetWindowLong( b->hWnd, GWL_WNDPROC );
- SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newComboProc );
+ newComboProc = MakeProcInstance((XWNDPROC)pushCombo, mswHInst);
+ oldComboProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC);
+ SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newComboProc);
+#ifdef _OLDCODE
+ oldComboProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC);
+ SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newComboProc);
+#endif
}
}
- if ( indexR )
+ if ( indexR ) {
*indexR = index;
- if ( !mswThickFont )
- SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
+ }
+
+ SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
return b;
}
wList_p wListCreate(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- POS_T width,
- int colCnt,
- wPos_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;
@@ -1120,25 +1187,28 @@ 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 = (int*)malloc( colCnt * sizeof *bl->colWidths );
+ bl->colWidths = (wWinPix_t*)malloc( colCnt * sizeof *bl->colWidths );
bl->colRightJust = (wBool_t*)malloc( colCnt * sizeof *bl->colRightJust );
bl->colTitles = colTitles;
bl->maxWidth = 0;
@@ -1148,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)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;
@@ -1162,49 +1234,52 @@ wList_p wListCreate(
wList_p wDropListCreate(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- POS_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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- POS_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 d56e24d..0a2851d 100644
--- a/app/wlib/mswlib/mswmenu.c
+++ b/app/wlib/mswlib/mswmenu.c
@@ -18,20 +18,18 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define OEMRESOURCE
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
#include <ctype.h>
#include <assert.h>
-#include "misc.h"
#include "mswint.h"
#include "i18n.h"
@@ -49,8 +47,8 @@ typedef enum { MM_BUTT, MM_MENU, MM_BAR, MM_POPUP } mmtype_e;
typedef struct wMenuItem_t * wMenuItem_p;
struct radioButtonGroup {
- int firstButton; /* id of first button in group */
- int lastButton; /* id of last button in group */
+ int firstButton; /* id of first button in group */
+ int lastButton; /* id of last button in group */
};
/* NOTE: first field must be the same as WOBJ_COMMON */
@@ -62,58 +60,58 @@ struct radioButtonGroup {
wMenuItem_p mnext;
struct wMenuItem_t {
- MOBJ_COMMON
- };
+ MOBJ_COMMON
+};
struct wMenu_t {
- MOBJ_COMMON
- mmtype_e mmtype;
- wMenuItem_p first, last;
- struct radioButtonGroup *radioGroup;
- HMENU menu;
- wButton_p button;
- wMenuTraceCallBack_p traceFunc;
- void * traceData;
- };
+ MOBJ_COMMON
+ mmtype_e mmtype;
+ wMenuItem_p first, last;
+ struct radioButtonGroup *radioGroup;
+ HMENU menu;
+ wButton_p button;
+ wMenuTraceCallBack_p traceFunc;
+ void * traceData;
+};
struct wMenuPush_t {
- MOBJ_COMMON
- wMenu_p mparent;
- wMenuCallBack_p action;
- long acclKey;
- wBool_t enabled;
- };
+ MOBJ_COMMON
+ wMenu_p mparent;
+ wMenuCallBack_p action;
+ long acclKey;
+ wBool_t enabled;
+};
struct wMenuRadio_t {
- MOBJ_COMMON
- wMenu_p mparent;
- wMenuCallBack_p action;
- long acclKey;
- wBool_t enabled;
- };
+ MOBJ_COMMON
+ wMenu_p mparent;
+ wMenuCallBack_p action;
+ long acclKey;
+ wBool_t enabled;
+};
struct wMenuToggle_t {
- MOBJ_COMMON
- wMenu_p mparent;
- wMenuToggleCallBack_p action;
- long acclKey;
- wBool_t enabled;
- };
+ MOBJ_COMMON
+ wMenu_p mparent;
+ wMenuCallBack_p action;
+ long acclKey;
+ wBool_t enabled;
+};
typedef struct wMenuListItem_t * wMenuListItem_p;
struct wMenuList_t {
- MOBJ_COMMON
- wMenuListItem_p left, right;
- wMenu_p mlparent;
- int max;
- int count;
- wMenuListCallBack_p action;
- };
+ MOBJ_COMMON
+ wMenuListItem_p left, right;
+ wMenu_p mlparent;
+ int max;
+ int count;
+ wMenuListCallBack_p action;
+};
struct wMenuListItem_t {
- MOBJ_COMMON
- wMenuListItem_p left, right;
- wMenuListCallBack_p action;
- };
+ MOBJ_COMMON
+ wMenuListItem_p left, right;
+ wMenuListCallBack_p action;
+};
#define UNCHECK (0)
#define CHECK (1)
@@ -140,17 +138,18 @@ char * mswStrdup( const char * str )
if (str) {
ret = (char*)malloc( strlen(str)+1 );
strcpy( ret, str );
- } else
+ } else {
ret = NULL;
+ }
return ret;
}
static LRESULT menuPush(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
wMenuItem_p m = (wMenuItem_p)b;
wBool_t set;
@@ -166,29 +165,34 @@ static LRESULT menuPush(
mswFail( "pushMenu" );
break;
case M_PUSH:
- if (((wMenuPush_p)m)->action)
+ if (((wMenuPush_p)m)->action) {
((wMenuPush_p)m)->action(((wMenuPush_p)m)->data);
+ }
break;
case M_TOGGLE:
set = wMenuToggleGet((wMenuToggle_p)m);
set = !set;
wMenuToggleSet((wMenuToggle_p)m,set);
- if (((wMenuToggle_p)m)->action)
- ((wMenuToggle_p)m)->action(set, ((wMenuPush_p)m)->data);
+ if (((wMenuToggle_p)m)->action) {
+ ((wMenuToggle_p)m)->action(((wMenuPush_p)m)->data);
+ }
break;
case M_LISTITEM:
- if (((wMenuListItem_p)m)->action)
+ if (((wMenuListItem_p)m)->action) {
((wMenuListItem_p)m)->action(0, "", ((wMenuListItem_p)m)->data);
+ }
break;
case M_RADIO:
- if (((wMenuRadio_p)m)->action)
+ if (((wMenuRadio_p)m)->action) {
((wMenuRadio_p)m)->action(((wMenuRadio_p)m)->data);
+ }
break;
}
- return 0L;
+ return (LRESULT)0;
}
if ( (m->parentMenu)->traceFunc ) {
- (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, ((wMenu_p)m->parentMenu)->traceData );
+ (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr,
+ ((wMenu_p)m->parentMenu)->traceData );
}
return DefWindowProc( hWnd, message, wParam, lParam );
}
@@ -199,24 +203,26 @@ static void menuDone( wControl_p b )
switch ( m->mtype ) {
case M_MENU:
if ( ((wMenu_p)m)->mmtype == MM_BUTT ||
- ((wMenu_p)m)->mmtype == MM_POPUP )
+ ((wMenu_p)m)->mmtype == MM_POPUP ) {
DestroyMenu( ((wMenu_p)m)->menu );
+ }
break;
}
}
static callBacks_t menuItemCallBacks = {
- NULL,
- menuDone,
- menuPush };
+ NULL,
+ menuDone,
+ menuPush
+};
static wMenuItem_p createMenuItem(
- wMenu_p m,
- mtype_e mtype,
- const char * helpStr,
- const char * labelStr,
- int size )
+ wMenu_p m,
+ mtype_e mtype,
+ const char * helpStr,
+ const char * labelStr,
+ int size )
{
wMenuItem_p mi;
@@ -255,29 +261,31 @@ static wMenuItem_p createMenuItem(
typedef struct {
- long acclKey;
- wMenuPush_p mp;
- wAccelKeyCallBack_p action;
- wAccelKey_e key;
- void * data;
- } acclTable_t, *acclTable_p;
-dynArr_t acclTable_da;
+ long acclKey;
+ wMenuPush_p mp;
+ wAccelKeyCallBack_p action;
+ wAccelKey_e key;
+ void * data;
+} acclTable_t, *acclTable_p;
+static dynArr_t acclTable_da;
#define acclTable(N) DYNARR_N( acclTable_t, acclTable_da, N )
int mswMenuAccelerator(
- wWin_p win,
- long acclKey )
+ wWin_p win,
+ long acclKey )
{
acclTable_p at;
if ( ((wControl_p)win)->type != W_MAIN &&
- ((wControl_p)win)->type != W_POPUP )
+ ((wControl_p)win)->type != W_POPUP ) {
return 0;
+ }
for ( at = &acclTable(0); at<&acclTable(acclTable_da.cnt); at++ ) {
if (at->acclKey == acclKey) {
if (at->mp) {
- if (at->mp->enabled && at->mp->action)
+ if (at->mp->enabled && at->mp->action) {
at->mp->action(at->mp->data);
+ }
return 1;
} else if (at->action) {
at->action( at->key, at->data );
@@ -293,40 +301,40 @@ int mswMenuAccelerator(
static long acclKeyMap[] = {
- 0, /* wAccelKey_None, */
- VK_DELETE, /* wAccelKey_Del, */
- VK_INSERT, /* wAccelKey_Ins, */
- VK_HOME, /* wAccelKey_Home, */
- VK_END, /* wAccelKey_End, */
- VK_PRIOR, /* wAccelKey_Pgup, */
- VK_NEXT, /* wAccelKey_Pgdn, */
- VK_UP, /* wAccelKey_Up, */
- VK_DOWN, /* wAccelKey_Down, */
- VK_RIGHT, /* wAccelKey_Right, */
- VK_LEFT, /* wAccelKey_Left, */
- VK_BACK, /* wAccelKey_Back, */
- VK_F1, /* wAccelKey_F1, */
- VK_F2, /* wAccelKey_F2, */
- VK_F3, /* wAccelKey_F3, */
- VK_F4, /* wAccelKey_F4, */
- VK_F5, /* wAccelKey_F5, */
- VK_F6, /* wAccelKey_F6, */
- VK_F7, /* wAccelKey_F7, */
- VK_F8, /* wAccelKey_F8, */
- VK_F9, /* wAccelKey_F9, */
- VK_F10, /* wAccelKey_F10, */
- VK_F11, /* wAccelKey_F11, */
- VK_F12, /* wAccelKey_F12, */
- VK_ADD, /* wAccelKey_Numpad_Add, */
- VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */
- };
+ 0, /* wAccelKey_None, */
+ VK_DELETE, /* wAccelKey_Del, */
+ VK_INSERT, /* wAccelKey_Ins, */
+ VK_HOME, /* wAccelKey_Home, */
+ VK_END, /* wAccelKey_End, */
+ VK_PRIOR, /* wAccelKey_Pgup, */
+ VK_NEXT, /* wAccelKey_Pgdn, */
+ VK_UP, /* wAccelKey_Up, */
+ VK_DOWN, /* wAccelKey_Down, */
+ VK_RIGHT, /* wAccelKey_Right, */
+ VK_LEFT, /* wAccelKey_Left, */
+ VK_BACK, /* wAccelKey_Back, */
+ VK_F1, /* wAccelKey_F1, */
+ VK_F2, /* wAccelKey_F2, */
+ VK_F3, /* wAccelKey_F3, */
+ VK_F4, /* wAccelKey_F4, */
+ VK_F5, /* wAccelKey_F5, */
+ VK_F6, /* wAccelKey_F6, */
+ VK_F7, /* wAccelKey_F7, */
+ VK_F8, /* wAccelKey_F8, */
+ VK_F9, /* wAccelKey_F9, */
+ VK_F10, /* wAccelKey_F10, */
+ VK_F11, /* wAccelKey_F11, */
+ VK_F12, /* wAccelKey_F12, */
+ VK_ADD, /* wAccelKey_Numpad_Add, */
+ VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */
+};
void wAttachAccelKey(
- wAccelKey_e key,
- int modifier,
- wAccelKeyCallBack_p action,
- void * data )
+ wAccelKey_e key,
+ int modifier,
+ wAccelKeyCallBack_p action,
+ void * data )
{
acclTable_t * ad;
if ( key < 1 || key > wAccelKey_Numpad_Subtract ) {
@@ -350,132 +358,133 @@ void wAttachAccelKey(
*****************************************************************************
*/
-HBITMAP GetMyCheckBitmaps(UINT fuCheck)
-{
- COLORREF crBackground; /* background color */
- HBRUSH hbrBackground; /* background brush */
- HBRUSH hbrTargetOld; /* original background brush */
- HDC hdcSource; /* source device context */
- HDC hdcTarget; /* target device context */
- HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */
- BITMAP bmCheckbox; /* structure for bitmap data */
- HBITMAP hbmpSourceOld; /* handle to original source bitmap */
- HBITMAP hbmpTargetOld; /* handle to original target bitmap */
- HBITMAP hbmpCheck; /* handle to check-mark bitmap */
- RECT rc; /* rectangle for check-box bitmap */
- WORD wBitmapX; /* width of check-mark bitmap */
- WORD wBitmapY; /* height of check-mark bitmap */
-
- /* Get the menu background color and create a solid brush
- with that color. */
-
- crBackground = GetSysColor(COLOR_MENU);
- hbrBackground = CreateSolidBrush(crBackground);
-
- /* Create memory device contexts for the source and
- destination bitmaps. */
-
- hdcSource = CreateCompatibleDC((HDC) NULL);
- hdcTarget = CreateCompatibleDC(hdcSource);
-
- /* Get the size of the system default check-mark bitmap and
- create a compatible bitmap of the same size. */
-
- wBitmapX = GetSystemMetrics(SM_CXMENUCHECK);
- wBitmapY = GetSystemMetrics(SM_CYMENUCHECK);
-
- hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX,
- wBitmapY);
-
- /* Select the background brush and bitmap into the target DC. */
-
- hbrTargetOld = SelectObject(hdcTarget, hbrBackground);
- hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck);
-
- /* Use the selected brush to initialize the background color
- of the bitmap in the target device context. */
-
- PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY);
-
- /* Load the predefined check box bitmaps and select it
- into the source DC. */
-
- hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL,
- (LPTSTR) OBM_CHECKBOXES);
-
- hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes);
-
- /* Fill a BITMAP structure with information about the
- check box bitmaps, and then find the upper-left corner of
- the unchecked check box or the checked check box. */
-
- GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox);
-
+HBITMAP GetMyCheckBitmaps(UINT fuCheck)
+{
+ COLORREF crBackground; /* background color */
+ HBRUSH hbrBackground; /* background brush */
+ HBRUSH hbrTargetOld; /* original background brush */
+ HDC hdcSource; /* source device context */
+ HDC hdcTarget; /* target device context */
+ HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */
+ BITMAP bmCheckbox; /* structure for bitmap data */
+ HBITMAP hbmpSourceOld; /* handle to original source bitmap */
+ HBITMAP hbmpTargetOld; /* handle to original target bitmap */
+ HBITMAP hbmpCheck; /* handle to check-mark bitmap */
+ RECT rc; /* rectangle for check-box bitmap */
+ WORD wBitmapX; /* width of check-mark bitmap */
+ WORD wBitmapY; /* height of check-mark bitmap */
+ WORD wMenuH; /* height of menu line */
+
+ /* Get the menu background color and create a solid brush
+ with that color. */
+
+ crBackground = GetSysColor(COLOR_MENU);
+ hbrBackground = CreateSolidBrush(crBackground);
+
+ /* Create memory device contexts for the source and
+ destination bitmaps. */
+
+ hdcSource = CreateCompatibleDC((HDC) NULL);
+ hdcTarget = CreateCompatibleDC(hdcSource);
+
+ /* Get the size of the system default check-mark bitmap and
+ create a compatible bitmap of the same size. */
+
+ wBitmapX = GetSystemMetrics(SM_CXMENUCHECK);
+ wBitmapY = GetSystemMetrics(SM_CYMENUCHECK);
+ wMenuH = GetSystemMetrics(SM_CYMENU);
+
+ hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX,
+ wBitmapY);
+
+ /* Select the background brush and bitmap into the target DC. */
+
+ hbrTargetOld = SelectObject(hdcTarget, hbrBackground);
+ hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck);
+
+ /* Use the selected brush to initialize the background color
+ of the bitmap in the target device context. */
+
+ PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY);
+
+ /* Load the predefined check box bitmaps and select it
+ into the source DC. */
+
+ hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL,
+ (LPTSTR) OBM_CHECKBOXES);
+
+ hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes);
+
+ /* Fill a BITMAP structure with information about the
+ check box bitmaps, and then find the upper-left corner of
+ the unchecked check box or the checked check box. */
+
+ GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox);
+
switch( fuCheck ) {
-
+
case UNCHECK:
- rc.left = 0;
- rc.right = (bmCheckbox.bmWidth / 4);
- rc.top = 0;
- rc.bottom = (bmCheckbox.bmHeight / 3);
- break;
- case CHECK:
- rc.left = (bmCheckbox.bmWidth / 4);
- rc.right = (bmCheckbox.bmWidth / 4) * 2;
- rc.top = 0;
- rc.bottom = (bmCheckbox.bmHeight / 3);
+ rc.left = 0;
+ rc.right = (bmCheckbox.bmWidth / 4);
+ rc.top = 0;
+ rc.bottom = (bmCheckbox.bmHeight / 3);
+ break;
+ case CHECK:
+ rc.left = (bmCheckbox.bmWidth / 4);
+ rc.right = (bmCheckbox.bmWidth / 4) * 2;
+ rc.top = 0;
+ rc.bottom = (bmCheckbox.bmHeight / 3);
break;
case RADIOCHECK:
- rc.left = (bmCheckbox.bmWidth / 4);
- rc.right = (bmCheckbox.bmWidth / 4) * 2;
- rc.top = (bmCheckbox.bmHeight / 3) + 1;
- rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
+ rc.left = (bmCheckbox.bmWidth / 4);
+ rc.right = (bmCheckbox.bmWidth / 4) * 2;
+ rc.top = (bmCheckbox.bmHeight / 3);
+ rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
break;
case RADIOUNCHECK:
- rc.top = (bmCheckbox.bmHeight / 3) + 1;
- rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
- rc.left = 0;
- rc.right = (bmCheckbox.bmWidth / 4);
+ rc.top = (bmCheckbox.bmHeight / 3);
+ rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
+ rc.left = 0;
+ rc.right = (bmCheckbox.bmWidth / 4);
break;
}
-
- /* Copy the appropriate bitmap into the target DC. If the
- check-box bitmap is larger than the default check-mark
- bitmap, use StretchBlt to make it fit; otherwise, just
- copy it. */
-
- if (((rc.right - rc.left) > (int) wBitmapX) ||
- ((rc.bottom - rc.top) > (int) wBitmapY))
- {
- StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY,
- hdcSource, rc.left, rc.top, rc.right - rc.left,
- rc.bottom - rc.top, SRCCOPY);
- }
-
- else
- {
- BitBlt(hdcTarget, 0, 0, rc.right - rc.left,
- rc.bottom - rc.top,
- hdcSource, rc.left, rc.top, SRCCOPY);
- }
-
- /* Select the old source and destination bitmaps into the
- source and destination DCs, and then delete the DCs and
- the background brush. */
-
- SelectObject(hdcSource, hbmpSourceOld);
- SelectObject(hdcTarget, hbrTargetOld);
- hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld);
-
- DeleteObject(hbrBackground);
- DeleteObject(hdcSource);
- DeleteObject(hdcTarget);
-
- /* Return a handle to the new check-mark bitmap. */
-
- return hbmpCheck;
-}
+
+ /* Copy the appropriate bitmap into the target DC. If the
+ check-box bitmap is larger than the default check-mark
+ bitmap, use StretchBlt to make it fit; otherwise, just
+ copy it. */
+ if (((rc.right - rc.left) > (int) wBitmapX) ||
+ ((rc.bottom - rc.top) > (int) wBitmapY)) {
+ StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY,
+ hdcSource, rc.left, rc.top, rc.right - rc.left,
+ rc.bottom - rc.top, SRCCOPY);
+ }
+
+ else {
+ // Center it vertically
+ WORD dy = (wMenuH > wBitmapY) ? (wMenuH - wBitmapY) / 2 : 0;
+ BitBlt(hdcTarget, 0, dy, rc.right - rc.left,
+ rc.bottom - rc.top,
+ hdcSource, rc.left, rc.top, SRCCOPY);
+ }
+
+ /* Select the old source and destination bitmaps into the
+ source and destination DCs, and then delete the DCs and
+ the background brush. */
+
+ SelectObject(hdcSource, hbmpSourceOld);
+ SelectObject(hdcTarget, hbrTargetOld);
+ hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld);
+
+ DeleteObject(hbrBackground);
+ DeleteObject(hdcSource);
+ DeleteObject(hdcTarget);
+
+ /* Return a handle to the new check-mark bitmap. */
+
+ return hbmpCheck;
+}
void mswCreateCheckBitmaps()
{
@@ -487,12 +496,12 @@ void mswCreateCheckBitmaps()
}
wMenuRadio_p wMenuRadioCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wMenuCallBack_p action,
- void *data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wMenuCallBack_p action,
+ void *data )
{
wMenuRadio_p mi;
int rc;
@@ -536,8 +545,9 @@ wMenuRadio_p wMenuRadioCreate(
ac = tolower( ac );
}
vk = VkKeyScan( ac );
- if ( vk & 0xFF00 )
+ if ( vk & 0xFF00 ) {
modifier |= WKEY_SHIFT;
+ }
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mi;
}
@@ -545,7 +555,8 @@ wMenuRadio_p wMenuRadioCreate(
/* add the correct bitmaps for radio buttons */
- rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio, checkedRadio );
+ rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio,
+ checkedRadio );
if( m->radioGroup == NULL ) {
m->radioGroup = malloc( sizeof( struct radioButtonGroup ));
@@ -562,25 +573,26 @@ void wMenuRadioSetActive(wMenuRadio_p mi )
{
BOOL rc;
- rc = CheckMenuRadioItem( mi->mparent->menu,
- mi->mparent->radioGroup->firstButton,
- mi->mparent->radioGroup->lastButton,
- mi->index,
- MF_BYCOMMAND );
-}
+ rc = CheckMenuRadioItem( mi->mparent->menu,
+ mi->mparent->radioGroup->firstButton,
+ mi->mparent->radioGroup->lastButton,
+ mi->index,
+ MF_BYCOMMAND );
+}
wMenuPush_p wMenuPushCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wMenuCallBack_p action,
- void *data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wMenuCallBack_p action,
+ void *data )
{
wMenuPush_p mi;
int rc;
- char *label = malloc(strlen(labelStr) + 30 ); /**< The label and sufficient space for the keyboard shortcut */
+ char *label = malloc(strlen(labelStr) +
+ 30 ); /**< The label and sufficient space for the keyboard shortcut */
char *cp;
char ac;
UINT vk;
@@ -620,8 +632,9 @@ wMenuPush_p wMenuPushCreate(
ac = tolower( ac );
}
vk = VkKeyScan( ac );
- if ( vk & 0xFF00 )
+ if ( vk & 0xFF00 ) {
modifier |= WKEY_SHIFT;
+ }
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
acclTable(acclTable_da.cnt-1).mp = mi;
}
@@ -632,19 +645,19 @@ wMenuPush_p wMenuPushCreate(
void wMenuPushEnable(
- wMenuPush_p mi,
- BOOL_T enable )
+ wMenuPush_p mi,
+ BOOL_T enable )
{
EnableMenuItem( mi->mparent->menu, mi->index,
- MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
+ MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
mi->enabled = enable;
}
wMenu_p wMenuMenuCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr )
{
wMenu_p mm;
int rc;
@@ -655,13 +668,14 @@ wMenu_p wMenuMenuCreate(
/*mm->parent = (wControl_p)m;*/
mm->first = mm->last = NULL;
- rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT)mm->menu, mm->labelStr );
+ rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu),
+ mm->labelStr );
return mm;
}
void wMenuSeparatorCreate(
- wMenu_p m )
+ wMenu_p m )
{
int rc;
createMenuItem( m, M_SEPARATOR, NULL, NULL, sizeof *(wMenuItem_p)NULL );
@@ -678,8 +692,8 @@ void wMenuSeparatorCreate(
static void appendItem(
- wMenuListItem_p ml,
- wMenuListItem_p mi )
+ wMenuListItem_p ml,
+ wMenuListItem_p mi )
{
mi->right = ml->right;
ml->right->left = mi;
@@ -689,7 +703,7 @@ static void appendItem(
static void removeItem(
- wMenuListItem_p mi )
+ wMenuListItem_p mi )
{
mi->left->right = mi->right;
mi->right->left = mi->left;
@@ -698,10 +712,10 @@ static void removeItem(
wMenuList_p wMenuListCreate(
- wMenu_p m,
- const char * helpStr,
- int max,
- wMenuListCallBack_p action )
+ wMenu_p m,
+ const char * helpStr,
+ int max,
+ wMenuListCallBack_p action )
{
wMenuList_p mi;
mi = (wMenuList_p)createMenuItem( m, M_LIST, helpStr, NULL, sizeof *mi );
@@ -727,8 +741,9 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml )
count++;
break;
case M_LIST:
- if (mi == (wMenuItem_p)ml)
+ if (mi == (wMenuItem_p)ml) {
return count;
+ }
count += ((wMenuList_p)mi)->count;
break;
default:
@@ -740,10 +755,10 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml )
void wMenuListAdd(
- wMenuList_p ml,
- int index,
- const char * labelStr,
- void * data )
+ wMenuList_p ml,
+ int index,
+ const char * labelStr,
+ void * data )
{
int origin;
wMenuListItem_p wl_p;
@@ -752,7 +767,8 @@ void wMenuListAdd(
int rc;
origin = getMlistOrigin(ml->mlparent, ml);
- for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) {
+ for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml;
+ count++,wl_p=wl_p->right ) {
if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) {
/* move item */
if (count != index) {
@@ -770,34 +786,37 @@ void wMenuListAdd(
removeItem( ml->left );
add:
ml->count--;
- if (wl_p->labelStr )
+ if (wl_p->labelStr ) {
free( CAST_AWAY_CONST wl_p->labelStr );
+ }
wl_p->labelStr = mswStrdup( labelStr );
} else {
wl_p = (wMenuListItem_p)createMenuItem( NULL, M_LISTITEM, NULL,
- labelStr, sizeof *wl_p );
+ labelStr, sizeof *wl_p );
}
((wMenuListItem_p)wl_p)->data = data;
((wMenuListItem_p)wl_p)->action = ml->action;
- if (index < 0 || index > ml->count)
+ if (index < 0 || index > ml->count) {
index = ml->count;
+ }
for ( mi=(wMenuListItem_p)ml,count=0; count<index; mi=mi->right,count++);
rc = InsertMenu( ml->mlparent->menu, origin+index,
- MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr );
+ MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr );
appendItem( mi, wl_p );
ml->count++;
}
void wMenuListDelete(
- wMenuList_p ml,
- const char * labelStr )
+ wMenuList_p ml,
+ const char * labelStr )
{
int origin, count;
wMenuListItem_p wl_p;
origin = getMlistOrigin(ml->mlparent, ml);
- for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) {
+ for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml;
+ count++,wl_p=wl_p->right ) {
if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) {
/* delete item */
mswUnregister( wl_p->index );
@@ -812,27 +831,30 @@ void wMenuListDelete(
const char * wMenuListGet(
- wMenuList_p ml,
- int index,
- void ** data )
+ wMenuList_p ml,
+ int index,
+ void ** data )
{
int origin, count;
wMenuListItem_p wl_p;
- if (index >= ml->count)
+ if (index >= ml->count) {
return NULL;
+ }
origin = getMlistOrigin(ml->mlparent, ml);
for ( count=0,wl_p=ml->right; wl_p&&count<index; count++,wl_p=wl_p->right );
- if (wl_p==NULL)
+ if (wl_p==NULL) {
return NULL;
- if ( data )
+ }
+ if ( data ) {
*data = wl_p->data;
+ }
return wl_p->labelStr;
}
void wMenuListClear(
- wMenuList_p ml )
+ wMenuList_p ml )
{
int origin, count;
wMenuListItem_p wl_p, wl_q;
@@ -852,13 +874,13 @@ void wMenuListClear(
wMenuToggle_p wMenuToggleCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wBool_t set,
- wMenuToggleCallBack_p action,
- void * data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wBool_t set,
+ wMenuCallBack_p action,
+ void * data )
{
wMenuToggle_p mt;
int rc;
@@ -868,7 +890,8 @@ wMenuToggle_p wMenuToggleCreate(
UINT vk;
long modifier;
- mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, sizeof *mt );
+ mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr,
+ sizeof *mt );
/*setAcclKey( m->parent, m->menu, mt->menu_item, acclKey );*/
mt->action = action;
mt->data = data;
@@ -909,8 +932,9 @@ wMenuToggle_p wMenuToggleCreate(
ac = tolower( ac );
}
vk = VkKeyScan( ac );
- if ( vk & 0xFF00 )
+ if ( vk & 0xFF00 ) {
modifier |= WKEY_SHIFT;
+ }
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mt;
}
@@ -922,30 +946,33 @@ wMenuToggle_p wMenuToggleCreate(
wBool_t wMenuToggleGet(
- wMenuToggle_p mt )
+ wMenuToggle_p mt )
{
- return (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0;
+ return (GetMenuState( mt->mparent->menu, mt->index,
+ MF_BYCOMMAND ) & MF_CHECKED) != 0;
}
wBool_t wMenuToggleSet(
- wMenuToggle_p mt,
- wBool_t set )
+ wMenuToggle_p mt,
+ wBool_t set )
{
wBool_t rc;
- CheckMenuItem( mt->mparent->menu, mt->index, MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) );
- rc = (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0;
+ CheckMenuItem( mt->mparent->menu, mt->index,
+ MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) );
+ rc = (GetMenuState( mt->mparent->menu, mt->index,
+ MF_BYCOMMAND ) & MF_CHECKED) != 0;
return rc;
}
void wMenuToggleEnable(
- wMenuToggle_p mt,
- wBool_t enable )
+ wMenuToggle_p mt,
+ wBool_t enable )
{
EnableMenuItem( mt->mparent->menu, mt->index,
- MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
+ MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
mt->enabled = enable;
-}
+}
/*
*****************************************************************************
@@ -957,39 +984,40 @@ void wMenuToggleEnable(
void mswMenuMove(
- wMenu_p m,
- wPos_t x,
- wPos_t y )
+ wMenu_p m,
+ wWinPix_t x,
+ wWinPix_t y )
{
wControl_p b;
b = (wControl_p)m->parent;
if (b && b->hWnd)
if (!SetWindowPos( b->hWnd, HWND_TOP, x, y,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER))
- mswFail("mswMenuMove");
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER)) {
+ mswFail("mswMenuMove");
+ }
}
static void pushMenuButt(
- void * data )
+ void * data )
{
wMenu_p m = (wMenu_p)data;
RECT rect;
mswAllowBalloonHelp = FALSE;
GetWindowRect( m->hWnd, &rect );
TrackPopupMenu( m->menu, TPM_LEFTALIGN, rect.left, rect.bottom,
- 0, ((wControl_p)(m->parent))->hWnd, NULL );
+ 0, ((wControl_p)(m->parent))->hWnd, NULL );
}
wMenu_p wMenuCreate(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option )
{
wMenu_p m;
wControl_p b;
@@ -1002,7 +1030,7 @@ wMenu_p wMenuCreate(
}
m = (wMenu_p)createMenuItem( NULL, M_MENU, helpStr, label, sizeof *m );
m->button = wButtonCreate( parent, x, y, helpStr, labelStr,
- buttOption, 0, pushMenuButt, (void*)m );
+ buttOption, 0, pushMenuButt, (void*)m );
b = (wControl_p)m->button;
m->parent = b->parent;
m->x = b->x;
@@ -1021,9 +1049,9 @@ wMenu_p wMenuCreate(
wMenu_p wMenuBarAdd(
- wWin_p w,
- const char * helpStr,
- const char * labelStr )
+ wWin_p w,
+ const char * helpStr,
+ const char * labelStr )
{
HMENU menu;
wMenu_p m;
@@ -1041,7 +1069,8 @@ wMenu_p wMenuBarAdd(
m->mmtype = MM_BAR;
m->first = m->last = NULL;
- rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT)m->menu, labelStr );
+ rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu),
+ labelStr );
DrawMenuBar( ((wControl_p)w)->hWnd );
return m;
@@ -1050,8 +1079,8 @@ wMenu_p wMenuBarAdd(
wMenu_p wMenuPopupCreate(
- wWin_p w,
- const char * labelStr )
+ wWin_p w,
+ const char * labelStr )
{
wMenu_p m;
long buttOption = 0;
@@ -1081,21 +1110,21 @@ void wMenuPopupShow( wMenu_p mp )
GetCursorPos( &pt );
TrackPopupMenu( mp->menu, TPM_LEFTALIGN, pt.x, pt.y, 0, mp->hWnd, NULL );
}
-
+
/*-----------------------------------------------------------------*/
void wMenuSetTraceCallBack(
- wMenu_p m,
- wMenuTraceCallBack_p func,
- void * data )
+ wMenu_p m,
+ wMenuTraceCallBack_p func,
+ void * data )
{
m->traceFunc = func;
m->traceData = data;
}
wBool_t wMenuAction(
- wMenu_p m,
- const char * label )
+ wMenu_p m,
+ const char * label )
{
wMenuItem_p mi;
wMenuToggle_p mt;
@@ -1106,10 +1135,11 @@ wBool_t wMenuAction(
case M_SEPARATOR:
break;
case M_PUSH:
- if ( ((wMenuPush_p)mi)->enabled == FALSE )
+ if ( ((wMenuPush_p)mi)->enabled == FALSE ) {
wBeep();
- else
+ } else {
((wMenuPush_p)mi)->action( ((wMenuPush_p)mi)->data );
+ }
break;
case M_TOGGLE:
mt = (wMenuToggle_p)mi;
@@ -1118,7 +1148,7 @@ wBool_t wMenuAction(
} else {
set = wMenuToggleGet( mt );
wMenuToggleSet( mt, !set );
- mt->action( set, mt->data );
+ mt->action( mt->data );
}
break;
case M_MENU:
diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c
index 6b5f1c9..4bf9481 100644
--- a/app/wlib/mswlib/mswmisc.c
+++ b/app/wlib/mswlib/mswmisc.c
@@ -17,21 +17,20 @@
*
* 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>
#include <stdio.h>
#include <assert.h>
#include <htmlhelp.h>
-#include "misc.h"
#include "mswint.h"
#include "i18n.h"
#include "FreeImage.h"
@@ -45,6 +44,7 @@
#define OFN_LONGFILENAMES 0x00200000L
char * mswStrdup(const char *);
+const char * GetCurCommandName(void);
#define PAUSE_TIMER (901)
#define ALARM_TIMER (902)
@@ -61,15 +61,14 @@ char * mswStrdup(const char *);
#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
/*
* EXPORTED VARIABLES
*/
-long debugWindow = 0;
HINSTANCE mswHInst;
HWND mswHWnd = (HWND)0;
@@ -77,37 +76,40 @@ const char *mswDrawWindowClassName = "DRAWWINDOW";
char mswTmpBuff[1024];
int mswEditHeight;
int mswAllowBalloonHelp = TRUE;
-int mswGroupStyle;
HFONT mswOldTextFont;
HFONT mswLabelFont;
-long mswThickFont = 1;
double mswScale = 1.0;
-double scaleIcon = 1.0; /**< Scaling factor for toolbar icons */
-
callBacks_t *mswCallBacks[CALLBACK_CNT];
-void closeBalloonHelp(void);
+void closeBalloonHelp(int inx);
static wControl_p getControlFromCursor(HWND, wWin_p *);
+
+#ifdef BALLOON_TRACE
+// To use:
+// change logFile defn in lprintf.c from static to EXPORT
+// Run with some debug flag set to ensure logFile is set
+extern FILE * logFile;
+#endif
/*
* LOCAL VARIABLES
*/
struct wWin_t {
- WOBJ_COMMON
- int validGeometry;
- int min_width;
- int max_width;
- int min_height;
- int max_height;
- wPos_t lastX, lastY;
- wPos_t padX, padY;
+ 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;
wWinCallBack_p winProc;
BOOL_T busy;
#ifdef OWNERICON
HBITMAP wicon_bm;
- wPos_t wicon_w, wicon_h;
+ wWinPix_t wicon_w, wicon_h;
#endif
DWORD baseStyle;
wControl_p focusChainFirst;
@@ -131,15 +133,15 @@ static int mResizeBorderH;
static int mMenuH;
static int screenWidth = 0, screenHeight = 0;
-wWin_p mswWin = NULL;
-wWin_p winFirst, winLast;
+static wWin_p mswWin = NULL;
+static wWin_p winFirst, winLast;
static long count51 = 0;
-static UINT alarmTimer;
-static UINT pauseTimer;
-static UINT balloonHelpTimer = (UINT)0;
-static UINT triggerTimer;
+static UINT_PTR alarmTimer;
+static UINT_PTR pauseTimer;
+static UINT_PTR balloonHelpTimer = (UINT_PTR)0;
+static UINT_PTR triggerTimer;
static UINT balloonHelpTimeOut = 500;
static wControl_p balloonHelpButton = NULL;
@@ -160,7 +162,7 @@ static DWORD dwCookie;
typedef struct {
wControl_p b;
} controlMap_t;
-dynArr_t controlMap_da;
+static dynArr_t controlMap_da;
#define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N)
@@ -170,15 +172,11 @@ char *mswProfileFile;
static wBalloonHelp_t * balloonHelpStrings;
-static wCursor_t curCursor = wCursorNormal;
-
#ifdef HELPSTR
static FILE * helpStrF;
#endif
static int inMainWndProc = FALSE;
-int newHelp = 1;
-
static wBool_t mswWinBlockEnabled = TRUE;
static FILE * dumpControlsF;
@@ -187,19 +185,21 @@ static int dumpControls;
extern char *userLocale;
// list of supported fileformats for image files
-char * filterImageFiles[] = { N_("All image files"),
- "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff",
- N_("GIF files (*.gif)"),
- "*.gif",
- N_("JPEG files (*.jpeg,*.jpg)"),
- "*.jpg;*.jpeg",
- N_("PNG files (*.png)"),
- "*.png",
- N_("TIFF files (*.tiff, *.tif)"),
- "*.tif;*.tiff",
- N_("All files (*)"),
- "*",
- };
+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 (*)"),
+ "*",
+ };
+
+static HICON hWindowIcon;
/*
*****************************************************************************
@@ -251,8 +251,8 @@ static void doDumpControls(void)
b = controlMap(inx).b;
if (b) {
- fprintf(dumpControlsF, "[%0.3d] [%x] %s %s %s\n", inx,
- (unsigned int)b->hWnd,
+ fprintf(dumpControlsF, "[%0.3d] [%p] %s %s %s\n", inx,
+ b->hWnd,
(b->type>=0&&b->type<=B_BOX?controlNames[b->type]:"NOTYPE"),
(b->labelStr?b->labelStr:"<NULL>"),
(b->helpStr?b->helpStr:"<NULL>"));
@@ -303,7 +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, strlen(b->labelStr));
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr,
+ (int)(strlen(b->labelStr)));
rect.left = b->labelX;
rect.top = b->labelY;
rect.right = b->labelX + LOWORD(dw);
@@ -313,7 +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, strlen(b->labelStr))) {
+ if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr,
+ (int)(strlen(b->labelStr)))) {
mswFail("Repainting text label");
}
@@ -376,14 +378,16 @@ void * mswAlloc(
w->data = data;
w->focusChainNext = NULL;
w->shown = TRUE;
+ w->hilite = FALSE;
+ w->errStr = NULL;
return w;
}
void mswComputePos(
wControl_p b,
- wPos_t origX,
- wPos_t origY)
+ wWinPix_t origX,
+ wWinPix_t origY)
{
wWin_p w = b->parent;
@@ -403,14 +407,14 @@ void mswComputePos(
b->labelY = b->y+2;
if (b->labelStr) {
- int lab_l;
+ size_t lab_l;
HDC hDc;
DWORD dw;
LABELFONTDECL
hDc = GetDC(w->hWnd);
LABELFONTSELECT
lab_l = strlen(b->labelStr);
- dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, lab_l);
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (UINT)lab_l);
b->labelX -= LOWORD(dw) + 5;
LABELFONTRESET
ReleaseDC(w->hWnd, hDc);
@@ -557,7 +561,7 @@ void mswSetFocus(
b->parent->focusChainNext = b;
}
}
-
+
/*
******************************************************************************
*
@@ -569,10 +573,10 @@ void mswSetFocus(
static void getSavedSizeAndPos(
long option,
const char * nameStr,
- wPos_t *rw,
- wPos_t *rh,
- wPos_t *rx,
- wPos_t *ry,
+ wWinPix_t *rw,
+ wWinPix_t *rh,
+ wWinPix_t *rx,
+ wWinPix_t *ry,
int *showCmd)
{
char *cq;
@@ -580,14 +584,29 @@ static void getSavedSizeAndPos(
if ((option&F_RECALLPOS) && nameStr) {
int x, y, w, h;
+ int xadj, yadj;
const char *cp;
int state;
+ w = h = 0;
+ xadj = 1;
+ yadj = mTitleH + 1;
+ if (option & F_RESIZE) {
+ xadj += mResizeBorderW * 2;
+ yadj += mResizeBorderH * 2;
+ } else {
+ xadj += mFixBorderW * 2;
+ yadj += mFixBorderH * 2;
+ }
+ //if (option & F_MENUBAR) {
+ // yadj += mMenuH;
+ //}
+
if ((option & F_RESIZE) &&
(cp = wPrefGetStringBasic("msw window size", nameStr)) &&
- (state = (int)strtol(cp, &cq, 10), cp != cq) && // state is not used
- (cp = cq, w = (wPos_t)strtod(cp, &cq), cp != cq) &&
- (cp = cq, h = (int)strtod(cp, &cq), cp != cq)
+ (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)
) {
if (w < 10) {
w = 10;
@@ -597,12 +616,12 @@ static void getSavedSizeAndPos(
h = 10;
}
- if (w > screenWidth) {
- w = screenWidth;
+ if (w > screenWidth - xadj) {
+ w = screenWidth - xadj;
}
- if (h > screenHeight) {
- h = screenHeight;
+ if (h > screenHeight - yadj) {
+ h = screenHeight - yadj;
}
*rw = w;
@@ -610,8 +629,8 @@ static void getSavedSizeAndPos(
}
if ((cp = wPrefGetStringBasic("msw window pos", nameStr)) &&
- (x = (wPos_t)strtod(cp, &cq), cp != cq) &&
- (cp = cq, y = (wPos_t)strtod(cp, &cq), cp != cq)
+ (x = (wWinPix_t)(strtod(cp, &cq)), cp != cq) &&
+ (cp = cq, y = (wWinPix_t)(strtod(cp, &cq)), cp != cq)
) {
if (y < 0) {
y = 0;
@@ -621,12 +640,17 @@ static void getSavedSizeAndPos(
x = 0;
}
- if (y > screenHeight-40) {
- y = screenHeight-40;
+ // Make sure we can see the dialog
+ xadj += 100;
+ yadj += 100;
+
+
+ if (y + h > screenHeight - yadj) {
+ y = screenHeight - yadj - h;
}
- if (x > screenWidth-40) {
- x = screenWidth-40;
+ if (x + w > screenWidth - xadj) {
+ x = screenWidth - xadj - w;
}
*rx = x;
@@ -636,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
@@ -647,21 +671,21 @@ static void getSavedSizeAndPos(
* \param aspect_ration IN unused on Windows
*/
void wSetGeometry(wWin_p win,
- int min_width,
- int max_width,
- int min_height,
- int max_height,
- int base_width,
- int base_height,
- 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;
}
/**
@@ -671,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
*/
@@ -690,15 +714,15 @@ static wWin_p winCommonCreate(
long style,
const char * labelStr,
wWinCallBack_p winProc,
- wPos_t w,
- wPos_t h,
+ wWinPix_t w,
+ wWinPix_t h,
void * data,
const char * nameStr,
int * pShowCmd)
{
wWin_p win;
int index;
- wPos_t ww, hh, xx, yy;
+ wWinPix_t ww, hh, xx, yy;
RECT rect;
win = (wWin_p)mswAlloc(NULL, typ, mswStrdup(labelStr), sizeof *win, data,
&index);
@@ -715,6 +739,8 @@ static wWin_p winCommonCreate(
if (typ == W_MAIN) {
*pShowCmd = ((option & F_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
+ } else {
+ *pShowCmd = SW_HIDE; //Make sure to hide first
}
if (xx != CW_USEDEFAULT) {
@@ -774,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();
}
@@ -806,8 +836,8 @@ void wInitAppName(char *_appName)
wWin_p wWinMainCreate(
const char * name,
- POS_T x,
- POS_T y,
+ wWinPix_t x,
+ wWinPix_t y,
const char * helpStr,
const char * labelStr,
const char * nameStr,
@@ -816,7 +846,6 @@ wWin_p wWinMainCreate(
void * data)
{
wWin_p w;
- RECT rect;
const char * appDir;
const char * libDir;
int showCmd;
@@ -825,7 +854,7 @@ wWin_p wWinMainCreate(
TEXTMETRIC tm;
char *pos;
char * configName;
- long maximize;
+ long maximize;
/* check for configuration name */
if (pos = strchr(name, ';')) {
@@ -862,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",
@@ -877,26 +901,22 @@ wWin_p wWinMainCreate(
nameStr, &showCmd);
mswHWnd = w->hWnd;
- if (!mswThickFont) {
- SendMessage(w->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L);
- hDc = GetDC(w->hWnd);
- GetTextMetrics(hDc, &tm);
- mswEditHeight = tm.tmHeight+2;
- ReleaseDC(w->hWnd, hDc);
- }
+ SendMessage(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0);
+ hDc = GetDC(mswHWnd);
+ GetTextMetrics(hDc, &tm);
+ mswEditHeight = tm.tmHeight+2;
+ ReleaseDC(mswHWnd, hDc);
- ShowWindow(w->hWnd, showCmd);
- UpdateWindow(w->hWnd);
- GetWindowRect(w->hWnd, &rect);
- GetClientRect(w->hWnd, &rect);
+ ShowWindow(mswHWnd, showCmd);
+ UpdateWindow(mswHWnd);
w->busy = FALSE;
return w;
}
wWin_p wWinPopupCreate(
wWin_p parent,
- POS_T x,
- POS_T y,
+ wWinPix_t x,
+ wWinPix_t y,
const char * helpStr,
const char * labelStr,
const char * nameStr,
@@ -1077,7 +1097,7 @@ static wAccelKey_e translateExtKey(UINT wParam)
}
-long notModKey;
+static long notModKey;
int mswTranslateAccelerator(
HWND hWnd,
LPMSG pMsg)
@@ -1091,7 +1111,7 @@ int mswTranslateAccelerator(
return FALSE;
}
- acclKey = pMsg->wParam;
+ acclKey = (long)pMsg->wParam;
b = getControlFromCursor(pMsg->hwnd, &win);
if (win == NULL) {
@@ -1112,7 +1132,7 @@ int mswTranslateAccelerator(
}
if (acclKey == (long)VK_F1) {
- closeBalloonHelp();
+ closeBalloonHelp(1);
if (!b && win) {
wHelp(win->helpStr);
@@ -1162,14 +1182,14 @@ int mswTranslateAccelerator(
-void wGetDisplaySize(POS_T * width, POS_T * height)
+void wGetDisplaySize(wWinPix_t * width, wWinPix_t * height)
{
*width = screenWidth;
*height = screenHeight;
}
-void wWinGetSize(wWin_p w, POS_T * width, POS_T * height)
+void wWinGetSize(wWin_p w, wWinPix_t * width, wWinPix_t * height)
{
RECT rect;
GetWindowRect(w->hWnd, &rect);
@@ -1181,7 +1201,7 @@ void wWinGetSize(wWin_p w, POS_T * width, POS_T * height)
}
-void wWinSetSize(wWin_p w, POS_T width, POS_T height)
+void wWinSetSize(wWin_p w, wWinPix_t width, wWinPix_t height)
{
RECT rect;
w->w = width;
@@ -1224,33 +1244,24 @@ static void blockingLoop(void)
static void savePos(wWin_p win)
{
- WINDOWPLACEMENT windowPlace;
- wPos_t w, h;
+ wWinPix_t w, h;
RECT rect;
if (win->nameStr &&
IsWindowVisible(win->hWnd) /*&& !IsIconic( win->hWnd )*/) {
- windowPlace.length = sizeof windowPlace;
- GetWindowPlacement(win->hWnd, &windowPlace);
+ GetWindowRect(win->hWnd, &rect);
if (win->option&F_RECALLPOS) {
char posStr[20];
wsprintf(posStr, "%d %d",
- windowPlace.rcNormalPosition.left,
- windowPlace.rcNormalPosition.top);
+ rect.left,
+ rect.top);
wPrefSetString("msw window pos", win->nameStr, posStr);
if (win->option&F_RESIZE) {
GetClientRect(win->hWnd, &rect);
- w = windowPlace.rcNormalPosition.right - windowPlace.rcNormalPosition.left;
- h = windowPlace.rcNormalPosition.bottom - windowPlace.rcNormalPosition.top;
- w -= mResizeBorderW*2;
- h -= mResizeBorderH*2 + mTitleH;
-
- if (win->option&F_MENUBAR) {
- h -= mMenuH;
- }
-
+ w = rect.right - rect.left;
+ h = rect.bottom - rect.top;
wsprintf(posStr, "%d %d %d",
0, // unused
w, h);
@@ -1265,7 +1276,7 @@ void wWinShow(
wWin_p win,
BOOL_T show)
{
- wPos_t x, y;
+ wWinPix_t x, y;
wWin_p win1;
win->busy = TRUE;
@@ -1292,6 +1303,11 @@ void wWinShow(
win->centerWin = FALSE;
win->shown = TRUE;
+ // Clear hilites
+ for (wControl_p controlP = win->first; controlP; controlP = controlP->next) {
+ controlP->hilite = FALSE;
+ }
+
if (mswHWnd == (HWND)0 || !IsIconic(mswHWnd)) {
ShowWindow(win->hWnd, SW_SHOW);
@@ -1429,73 +1445,13 @@ const char * wWinGetTitle(
void wWinClear(
wWin_p win,
- wPos_t x,
- wPos_t y,
- wPos_t width,
- wPos_t height)
+ wWinPix_t x,
+ wWinPix_t y,
+ wWinPix_t width,
+ wWinPix_t height)
{
}
-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;
- }
-
- curCursor = cursor;
-}
void wWinDoCancel(wWin_p win)
{
@@ -1667,44 +1623,44 @@ const char * wControlGetHelp(wControl_p b)
}
-wPos_t wLabelWidth(const char * labelStr)
+wWinPix_t wLabelWidth(const char * labelStr)
{
- int lab_l;
+ size_t lab_l;
HDC hDc;
DWORD dw;
LABELFONTDECL
hDc = GetDC(mswHWnd);
lab_l = strlen(labelStr);
LABELFONTSELECT
- dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l);
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, (UINT)lab_l);
LABELFONTRESET
ReleaseDC(mswHWnd, hDc);
return LOWORD(dw) + 5;
}
-wPos_t wControlGetWidth(
+wWinPix_t wControlGetWidth(
wControl_p b) /* Control */
{
return b->w;
}
-wPos_t wControlGetHeight(
+wWinPix_t wControlGetHeight(
wControl_p b) /* Control */
{
return b->h;
}
-wPos_t wControlGetPosX(
+wWinPix_t wControlGetPosX(
wControl_p b) /* Control */
{
return b->x;
}
-wPos_t wControlGetPosY(
+wWinPix_t wControlGetPosY(
wControl_p b) /* Control */
{
return b->y;
@@ -1713,21 +1669,21 @@ wPos_t wControlGetPosY(
void wControlSetPos(
wControl_p b,
- wPos_t x,
- wPos_t y)
+ wWinPix_t x,
+ wWinPix_t y)
{
b->labelX = x;
b->labelY = y+2;
if (b->labelStr) {
- int lab_l;
+ size_t lab_l;
HDC hDc;
DWORD dw;
LABELFONTDECL
hDc = GetDC(b->parent->hWnd);
LABELFONTSELECT
lab_l = strlen(b->labelStr);
- dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, lab_l);
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (UINT)lab_l);
b->labelX -= LOWORD(dw) + 5;
LABELFONTRESET
ReleaseDC(b->parent->hWnd, hDc);
@@ -1757,14 +1713,14 @@ void wControlSetLabel(
if (b->type == B_RADIO ) {
;
} else {
- int lab_l;
+ size_t lab_l;
HDC hDc;
DWORD dw;
LABELFONTDECL
hDc = GetDC(b->parent->hWnd);
lab_l = strlen(labelStr);
LABELFONTSELECT
- dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l);
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, (UINT)lab_l);
LABELFONTRESET
b->labelX = b->x - LOWORD(dw) - 5;
ReleaseDC(b->parent->hWnd, hDc);
@@ -1791,33 +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 (!IsWindowVisible(b->parent->hWnd)) {
+ if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd))
+ || (!IsWindowVisible(b->hWnd))) {
+ b->hilite = FALSE;
return;
}
- if (!IsWindowVisible(b->hWnd)) {
+ 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);
@@ -1840,7 +1799,7 @@ void wMessage(
{
HDC hDc;
int oldRop;
- POS_T h;
+ wWinPix_t h;
RECT rect;
LABELFONTDECL
@@ -1855,30 +1814,30 @@ void wMessage(
Rectangle(hDc, 0, h, w->w, h);
SetROP2(hDc, oldRop);
LABELFONTSELECT
- TextOut(hDc, 0, h, msg, strlen(msg));
+ TextOut(hDc, 0, h, msg, (int)(strlen(msg)));
LABELFONTRESET
ReleaseDC(w->hWnd, hDc);
}
/**
* 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 ((int)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)
@@ -1886,7 +1845,6 @@ void wExit(int rc)
INDEX_T inx;
wControl_p b;
mswPutCustomColors();
- wPrefFlush();
for (inx=controlMap_da.cnt-1; inx>=0; inx--) {
b = controlMap(inx).b;
@@ -1903,6 +1861,8 @@ void wExit(int rc)
}
}
+ wPrefFlush("");
+
for (inx=controlMap_da.cnt-1; inx>=0; inx--) {
b = controlMap(inx).b;
@@ -1923,7 +1883,7 @@ void wExit(int rc)
}
if (helpInitted) {
- WinHelp(mswHWnd, helpFile, HELP_QUIT, 0L);
+ WinHelp(mswHWnd, helpFile, HELP_QUIT, (DWORD)0);
helpInitted = FALSE;
}
@@ -2155,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.
*/
@@ -2165,14 +2125,14 @@ void wHelp(
{
char *pszHelpTopic;
HWND hwndHelp;
- char *theTopic = "index";
+ const char *theTopic = "index";
- if (topic) {
- theTopic = topic;
- }
+ if (topic) {
+ theTopic = topic;
+ }
if (!helpInitted) {
- HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ;
+ HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ;
helpInitted = TRUE;
}
@@ -2199,11 +2159,12 @@ void doHelpMenu(void * context)
HH_FTS_QUERY ftsQuery;
if (!helpInitted) {
- HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ;
+ HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ;
helpInitted = TRUE;
}
- switch ((int)(long)context) {
+ const char * topic;
+ switch ((int)(INT_PTR)context) {
case 1: /* Contents */
HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL);
break;
@@ -2215,15 +2176,14 @@ void doHelpMenu(void * context)
ftsQuery.fTitleOnly = FALSE;
ftsQuery.pszSearchQuery = NULL;
ftsQuery.pszWindow = NULL;
- HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD)&ftsQuery);
+ HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD_PTR)&ftsQuery);
break;
case 3: /*Context*/
- const char * topic;
- topic = GetCurCommandName();
- wHelp(topic);
- break;
+ topic = GetCurCommandName();
+ wHelp(topic);
+ break;
default:
return;
@@ -2232,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(
@@ -2267,88 +2228,108 @@ void wControlSetBalloonText(wControl_p b, const char * text)
b->tipStr = mswStrdup(text);
}
-
-void startBalloonHelp(void)
+void openBalloonHelp(wControl_p b, int dx, int dy)
{
HDC hDc;
DWORD extent;
RECT rect;
POINT pt;
- wBalloonHelp_t * bh;
- const char * hs;
HFONT hFont;
-
- if (!balloonHelpStrings) {
- return;
+ const char * msg;
+ if (b->errStr) {
+ msg = b->errStr;
+ } else {
+ msg = b->tipStr;
+ if (!balloonHelpEnable) {
+#ifdef BALLOON_TRACE
+ fprintf(logFile, "openBalloon !Enable state %d\n", balloonHelpState);
+ fflush(logFile);
+#endif
+ return;
+ }
}
-
- if (!balloonHelpEnable) {
+#ifdef BALLOON_TRACE
+ fprintf(logFile, "openBalloon %s state %d\n", msg, balloonHelpState);
+ fflush(logFile);
+#endif
+ if (!balloonHelpHWnd) {
return;
}
+ int w, h;
+ hDc = GetDC(balloonHelpHWnd);
+ hFont = SelectObject(hDc, mswLabelFont);
+ extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, (int)(strlen(msg)));
+ w = LOWORD(extent);
+ h = HIWORD(extent);
- if (balloonHelpHWnd) {
- if (balloonHelpButton->tipStr) {
- hs = balloonHelpButton->tipStr;
- } else {
- hs = balloonHelpButton->helpStr;
-
- if (!hs) {
- return;
- }
+ if (b->type == B_RADIO ||
+ b->type == B_TOGGLE) {
+ pt.y = b->h;
+ } else {
+ GetClientRect(b->hWnd, &rect);
+ pt.y = rect.bottom;
+ }
- for (bh = balloonHelpStrings; bh->name && strcmp(bh->name,hs) != 0; bh++);
+ pt.x = dx;
+ pt.y -= dy;
+ ClientToScreen(b->hWnd, &pt);
- if (!bh->name || !bh->value) {
- return;
- }
+ if (pt.x + w + 2 > screenWidth) {
+ pt.x = screenWidth - (w + 2);
+ }
- balloonHelpButton->tipStr = hs = bh->value;
- }
+ if (pt.x < 0) {
+ pt.x = 0;
+ }
- if (newHelp) {
- wControlSetBalloon(balloonHelpButton, 0, 0, hs);
- } else {
- int w, h;
- hDc = GetDC(balloonHelpHWnd);
- hFont = SelectObject(hDc, mswLabelFont);
- extent = GetTextExtent(hDc, CAST_AWAY_CONST hs, strlen(hs));
- w = LOWORD(extent);
- h = HIWORD(extent);
- pt.x = 0;
-
- if (balloonHelpButton->type == B_RADIO ||
- balloonHelpButton->type == B_TOGGLE) {
- pt.y = balloonHelpButton->h;
- } else {
- GetClientRect(balloonHelpButton->hWnd, &rect);
- pt.y = rect.bottom;
- }
+ 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;
+}
- ClientToScreen(balloonHelpButton->hWnd, &pt);
- if (pt.x + w+2 > screenWidth) {
- pt.x = screenWidth-(w+2);
- }
- if (pt.x < 0) {
- pt.x = 0;
- }
+void startBalloonHelp(void)
+{
+ wBalloonHelp_t * bh;
- SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w+6, h+4,
- SWP_SHOWWINDOW|SWP_NOACTIVATE);
- SetBkColor(hDc, GetSysColor(COLOR_INFOBK));
- TextOut(hDc, 2, 1, hs, strlen(hs));
- SelectObject(hDc, hFont);
- ReleaseDC(balloonHelpHWnd, hDc);
+ 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(void)
+
+void closeBalloonHelp(int inx)
{
+#ifdef BALLOON_TRACE
+ fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState);
+ fflush(logFile);
+#endif
if (balloonHelpTimer) {
KillTimer(mswHWnd, balloonHelpTimer);
- balloonHelpTimer = 0;
+ balloonHelpTimer = (UINT_PTR)0;
}
if (balloonHelpState == balloonHelpShow)
@@ -2360,56 +2341,26 @@ void closeBalloonHelp(void)
}
-void wControlSetBalloon(wControl_p b, wPos_t dx, wPos_t dy, const char * msg)
+void wControlSetBalloon(wControl_p b, wWinPix_t dx, wWinPix_t dy,
+ const char * msg)
{
- HDC hDc;
- DWORD extent;
- RECT rect;
- POINT pt;
- HFONT hFont;
-
if (msg) {
- int w, h;
- hDc = GetDC(balloonHelpHWnd);
- hFont = SelectObject(hDc, mswLabelFont);
- extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, strlen(msg));
- w = LOWORD(extent);
- h = HIWORD(extent);
-
- if (b->type == B_RADIO ||
- b->type == B_TOGGLE) {
- pt.y = b->h;
- } else {
- GetClientRect(b->hWnd, &rect);
- pt.y = rect.bottom;
+ if (b->errStr) {
+ free(b->errStr);
}
-
- 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);
- SetBkColor(hDc, GetSysColor(COLOR_INFOBK));
- TextOut(hDc, 2, 1, msg, strlen(msg));
- SelectObject(hDc, hFont);
- ReleaseDC(balloonHelpHWnd, hDc);
- balloonHelpState = balloonHelpShow;
- balloonControlButton = b;
+ b->errStr = mswStrdup(msg);
+ openBalloonHelp(b, dx, dy);
} else {
- closeBalloonHelp();
+ if (b->errStr) {
+ free(b->errStr);
+ }
+ b->errStr = NULL;
+ closeBalloonHelp(2);
}
}
+
int wGetKeyState(void)
{
int rc, keyState;
@@ -2467,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);
}
/**
@@ -2515,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);
@@ -2613,7 +2564,7 @@ struct wFilSel_t * wFilSelCreate(
{
char * cp;
struct wFilSel_t * ret;
- int len;
+ size_t len;
ret = (struct wFilSel_t*)malloc(sizeof *ret);
ret->parent = parent;
ret->mode = mode;
@@ -2671,7 +2622,7 @@ const char * wMemStats(void)
", Unknown Heap Status");
return msg;
}
-
+
/*
*****************************************************************************
*
@@ -2750,8 +2701,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int inx;
wWin_p w;
wControl_p b, oldW;
- int child = ((GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) != 0);
- POS_T newW, newH;
+ wWinPix_t newW, newH;
RECT rect;
PAINTSTRUCT ps;
HWND hWnd2;
@@ -2759,23 +2709,24 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HDC hDc;
wAccelKey_e extChar;
+ LPMINMAXINFO pMMI;
switch (message) {
- case WM_GETMINMAXINFO:
- LPMINMAXINFO pMMI = (LPMINMAXINFO)lParam;
- inx = GetWindowWord(hWnd, 0);
-
- if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) {
- w = (wWin_p)controlMap(inx - CONTROL_BASE).b;
- if (w != NULL) {
- if (w->validGeometry) {
- pMMI->ptMaxTrackSize.x = w->max_width;
- pMMI->ptMaxTrackSize.y = w->max_height;
- pMMI->ptMinTrackSize.x = w->min_width;
- pMMI->ptMinTrackSize.y = w->min_height;
- }
- }
- }
- return(0);
+ case WM_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);
@@ -2785,14 +2736,14 @@ 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 (0);
+ return (LRESULT)0;
- case WM_DRAWITEM:
case WM_COMMAND:
+ closeBalloonHelp(3);
+ case WM_DRAWITEM:
case WM_MEASUREITEM:
- closeBalloonHelp();
if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) {
break;
@@ -2808,10 +2759,10 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// draw the bitmap
mswDrawIcon(((LPDRAWITEMSTRUCT)lParam)->hDC, 0, 0, (wIcon_p)(b->data), FALSE,
(COLORREF)0, (COLORREF)0);
- return (TRUE);
+ return (LRESULT)TRUE;
} else {
mswSetFocus(b);
- ret = 0L;
+ ret = 0;
if (!inMainWndProc) {
inMainWndProc = TRUE;
@@ -2824,7 +2775,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
inMainWndProc = FALSE;
}
- return ret;
+ return (LRESULT)ret;
}
case WM_PAINT:
@@ -2846,7 +2797,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
EndPaint(hWnd, &ps);
- return 1L;
+ return (LRESULT)1;
}
break;
@@ -2876,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;
@@ -2895,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;
@@ -2924,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;
}
@@ -2942,9 +2893,20 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
b = getControlFromCursor(hWnd, NULL);
- closeBalloonHelp();
+ closeBalloonHelp(4);
if (b && b->type == B_DRAW) {
+ // Change Num keypad to a special code to emulate cursor keys
+ if (wParam == VK_UP ||
+ wParam == VK_DOWN ||
+ wParam == VK_RIGHT ||
+ wParam == VK_LEFT ||
+ wParam == VK_INSERT ||
+ wParam == VK_DELETE) {
+ if ((lParam & 0x1000000) == 0) {
+ lParam |= 0x1000000;
+ }
+ }
return SendMessage(b->hWnd, WM_CHAR, wParam, lParam);
}
@@ -2959,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;
@@ -2967,7 +2929,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
}
- return 0L;
+ return (LRESULT)0;
case 0x1B:
@@ -2979,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;
@@ -2988,7 +2950,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
mswSetTrigger((wControl_p)TRIGGER_TIMER, NULL);
- return 0L;
+ return (LRESULT)0;
case 0x20:
@@ -3002,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;
@@ -3010,7 +2972,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
}
- return 0L;
+ return (LRESULT)0;
case 0x09:
@@ -3041,16 +3003,16 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
}
- return 0L;
+ return (LRESULT)0;
}
/* Not a Draw control */
MessageBeep(MB_ICONHAND);
- return 0L;
+ return (LRESULT)0;
break;
case WM_ENABLE:
- if (wParam == 1) { /* WIN32??? */
+ if (wParam == (WPARAM)1) {
hWnd2 = SetFocus(hWnd);
}
@@ -3068,53 +3030,72 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
- closeBalloonHelp();
+ closeBalloonHelp(5);
wHelp(b->helpStr);
- return 0L;
+ return (LRESULT)0;
case WM_SETCURSOR:
- /*if (any buttons down)
- break;*/
- wSetCursor(NULL, curCursor);
+ // Set normal Arrow cursor, DefWindowProc can override it
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
if (!mswAllowBalloonHelp) {
- return TRUE;
+ break;
}
if (IsIconic(mswHWnd)) {
- return TRUE;
+ break;
}
b = getControlFromCursor(hWnd, NULL);
+#ifdef BALLOON_TRACE
+ fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL");
+ fflush(logFile);
+#endif
if (b == balloonControlButton) {
- return TRUE;
+ //closeBalloonHelp(61);
+ break;
}
- if (/*(!IsWindowEnabled(hWnd))*/ GetActiveWindow() != hWnd ||
- (!b) || b->type == B_DRAW || b->helpStr == NULL) {
- closeBalloonHelp();
- return TRUE;
+ if (GetActiveWindow() != hWnd) {
+ closeBalloonHelp(62);
+ break;
+ }
+ if (!b) {
+ closeBalloonHelp(63);
+ break;
+ }
+ if (b->type == B_DRAW) {
+ closeBalloonHelp(64);
+ break;
+ }
+ if (b->helpStr == NULL) {
+ closeBalloonHelp(65);
+ break;
}
if (b != balloonHelpButton) {
- closeBalloonHelp();
+ closeBalloonHelp(7);
}
-
+#ifdef BALLOON_TRACE
+ fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState);
+ fflush(logFile);
+#endif
if (balloonHelpState != balloonHelpIdle) {
- return TRUE;
+ break;
}
balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER,
balloonHelpTimeOut, NULL);
- if (balloonHelpTimer == (UINT)0) {
- return TRUE;
+ if (balloonHelpTimer == (UINT_PTR)0) {
+ break;
}
balloonHelpState = balloonHelpWait;
balloonHelpButton = b;
- return TRUE;
+ break;
+
case WM_SYSCOMMAND:
inx = GetWindowWord(hWnd, 0);
@@ -3146,7 +3127,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
wWinShow(w, FALSE);
- return 0L;
+ return (LRESULT)0;
case WM_CLOSE:
inx = GetWindowWord(hWnd, 0);
@@ -3168,13 +3149,13 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
(w->winProc(w, wClose_e, NULL, NULL));
}
- return 0L;
+ return (LRESULT)0;
}
case WM_DESTROY:
if (hWnd == mswHWnd) {
PostQuitMessage(0L);
- return 0L;
+ return (LRESULT)0;
}
break;
@@ -3192,15 +3173,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
} else if (wParam == BALLOONHELP_TIMER) {
KillTimer(hWnd, balloonHelpTimer);
- balloonHelpTimer = (UINT)0;
+ balloonHelpTimer = (UINT_PTR)0;
startBalloonHelp();
}
- return 0L;
+ return (LRESULT)0;
case WM_MENUSELECT:
mswAllowBalloonHelp = TRUE;
- closeBalloonHelp();
+ closeBalloonHelp(8);
break;
case WM_WINDOWPOSCHANGED:
@@ -3221,12 +3202,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case 51:
count51++;
- /*return NULL;*/
+ /*return NULL;*/
case WM_PALETTECHANGED:
if (wParam == (WPARAM)hWnd) {
- return 0L;
+ return (LRESULT)0;
}
case WM_QUERYNEWPALETTE:
@@ -3240,12 +3221,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
InvalidateRect(hWnd, NULL, TRUE);
}
- return inx;
+ return (LRESULT)inx;
}
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE) {
- closeBalloonHelp();
+ closeBalloonHelp(9);
}
break;
@@ -3272,7 +3253,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
inMainWndProc = FALSE;
}
- return ret;
+ return (LRESULT)ret;
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
@@ -3297,7 +3278,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
inMainWndProc = FALSE;
}
- return ret;
+ return (LRESULT)ret;
default:
;
@@ -3379,7 +3360,7 @@ static BOOL InitApplication(HINSTANCE hinstCurrent)
wc.cbWndExtra = 4;
if (!RegisterClass(&wc)) {
- mswFail("RegisterClass(drawClass)");
+ mswFail("RegisterClass(drawClass)");
return FALSE;
}
@@ -3401,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;
@@ -3419,6 +3400,7 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
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;
@@ -3467,5 +3449,5 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
HtmlHelp(NULL, NULL, HH_UNINITIALIZE, (DWORD)dwCookie);
}
- return msg.wParam;
+ return (int)msg.wParam;
}
diff --git a/app/wlib/mswlib/mswmsg.c b/app/wlib/mswlib/mswmsg.c
index 6445299..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>
@@ -21,20 +20,15 @@
#define SCALE_LARGE 1.6
#define SCALE_SMALL 0.8
-#ifdef CONTROL3D
-static int messageHeight = 18;
-#endif
-
struct wMessage_t {
- WOBJ_COMMON
- long flags;
- const char * message;
- };
+ WOBJ_COMMON
+ long flags;
+ const char * message;
+};
-#ifndef CONTROL3D
static void repaintMessage(
- HWND hWnd,
- wControl_p b )
+ HWND hWnd,
+ wControl_p b )
{
wMessage_p bm = (wMessage_p)b;
HDC hDc;
@@ -46,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);
@@ -83,137 +73,107 @@ static void repaintMessage(
rect.left = bm->x;
SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) );
- ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2), ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, strlen( bm->message ), NULL );
+ ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2),
+ ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, (int)(strlen( bm->message )),
+ NULL );
if( scale != 1.0 )
/* in case we did create a new font earlier, delete it now */
+ {
DeleteObject( SelectObject( hDc, GetStockObject( DEFAULT_GUI_FONT )));
- else
- if ( !mswThickFont )
- SelectObject( hDc, hFont );
+ } else {
+ SelectObject( hDc, hFont );
+ }
ReleaseDC( hWnd, hDc );
}
-#endif
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;
-#ifdef CONTROL3D
- SetWindowText( b->hWnd, arg );
-#else
+ }
+
repaintMessage( ((wControl_p)(b->parent))->hWnd, (wControl_p)b );
-#endif
+
}
void wMessageSetWidth(
- wMessage_p b,
- wPos_t width )
+ wMessage_p b,
+ wWinPix_t width )
{
b->w = width;
-#ifdef CONTROL3D
- SetWindowPos( b->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
- width, messageHeight, SWP_NOMOVE );
-#endif
+
}
-wPos_t wMessageGetWidth(const char *string)
+wWinPix_t wMessageGetWidth(const char *string)
{
return(wLabelWidth(string));
}
-wPos_t wMessageGetHeight( long flags )
+wWinPix_t wMessageGetHeight( long flags )
{
-#ifdef CONTROL3D
- return messageHeight;
-#else
double scale = 1.0;
- if( flags & BM_LARGE )
+ if( flags & BM_LARGE ) {
scale = SCALE_LARGE;
- if( flags & BM_SMALL )
+ }
+ if( flags & BM_SMALL ) {
scale = SCALE_SMALL;
+ }
+
+ return((wWinPix_t)((mswEditHeight) * scale ));
- return((wPos_t)((mswEditHeight) * scale ));
-#endif
}
static void mswMessageSetBusy(
- wControl_p b,
- BOOL_T busy )
+ wControl_p b,
+ BOOL_T busy )
{
}
-#ifndef CONTROL3D
-static callBacks_t messageCallBacks = {
- repaintMessage,
- NULL,
- NULL,
- mswMessageSetBusy };
-#endif
+static callBacks_t messageCallBacks = {
+ repaintMessage,
+ NULL,
+ NULL,
+ mswMessageSetBusy
+};
wMessage_p wMessageCreateEx(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- POS_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;
-
-#ifdef CONTROL3D
- RECT rect;
-#endif
-
+
+
b = (wMessage_p)mswAlloc( parent, B_MESSAGE, NULL, sizeof *b, NULL, &index );
mswComputePos( (wControl_p)b, x, y );
b->option |= BO_READONLY;
b->message = mswStrdup( message );
b->flags = flags;
-#ifdef CONTROL3D
- if ( width <= 0 && strlen(b->message) > 0 ) {
- width = wLabelWidth( b->message );
- }
-
- b->hWnd = CreateWindow( "STATIC", NULL,
- SS_LEFTNOWORDWRAP | WS_CHILD | WS_VISIBLE,
- b->x, b->y,
- width, messageHeight,
- ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
- if (b->hWnd == NULL) {
- mswFail("CreateWindow(MESSAGE)");
- return b;
- }
-
- if ( !mswThickFont )
- SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
- SetWindowText( b->hWnd, message );
-
- GetWindowRect( b->hWnd, &rect );
- b->w = rect.right - rect.left;
- b->h = rect.bottom - rect.top;
-#else
b->w = width;
b->h = wMessageGetHeight( flags ) + 1;
repaintMessage( ((wControl_p)parent)->hWnd, (wControl_p)b );
-#endif
+
mswAddButton( (wControl_p)b, FALSE, helpStr );
-#ifndef CONTROL3D
mswCallBacks[B_MESSAGE] = &messageCallBacks;
-#endif
+
return b;
}
diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c
index 201171a..e65b0dd 100644
--- a/app/wlib/mswlib/mswpref.c
+++ b/app/wlib/mswlib/mswpref.c
@@ -1,17 +1,15 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
#include <stdio.h>
-#include "misc.h"
#include "mswint.h"
#include <shlobj.h>
#include <Shlwapi.h>
#if _MSC_VER >=1400
- #define stricmp _stricmp
+#define stricmp _stricmp
#endif
char * mswStrdup( const char * );
@@ -27,38 +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
- strcpy(appLibDirName, module_name);
- strcat(appLibDirName, "\\..\\share\\xtrkcad");
- _fullpath( appLibDirName, appLibDirName, MAX_PATH );
- return appLibDirName;
-#endif
-
- strcpy(appLibDirName, module_name);
- 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.
*
@@ -67,209 +68,302 @@ const char * wGetAppLibDir( void )
*/
const char * wGetAppWorkDir( void )
{
- char *cp;
- int rc;
- if ( appWorkDirName[0] != 0 ) {
- return appWorkDirName;
- }
- wGetAppLibDir();
- sprintf( mswTmpBuff, "%s\\xtrkcad0.ini", appLibDirName );
- rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, sizeof appWorkDirName, mswTmpBuff );
- if ( rc!=0 ) {
- if ( stricmp( appWorkDirName, "installdir" ) == 0 ) {
- strcpy( appWorkDirName, appLibDirName );
- } 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 {
- sprintf( 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;
-dynArr_t prefs_da;
+ 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);
+ }
+}
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];
-
- sprintf( 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];
- sprintf(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( void )
+void wPrefFlush( char * name )
{
- prefs_t * p;
-
- for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
- if ( p->dirty )
- WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile );
- }
- 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 13756c7..9a7f65b 100644
--- a/app/wlib/mswlib/mswprint.c
+++ b/app/wlib/mswlib/mswprint.c
@@ -1,12 +1,8 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
-#ifndef WIN32
-#include <print.h>
-#endif
#include "mswint.h"
/*
@@ -18,13 +14,9 @@
*/
-struct wDraw_t print_d;
+static struct wDraw_t print_d;
-#ifdef WIN32
-struct tagPDA printDlg;
-#else
-struct tagPD printDlg;
-#endif
+static struct tagPDA printDlg;
static int printStatus = FALSE;
static DOCINFO docInfo;
static double tBorder = 0.0, rBorder = 0.0, bBorder = 0.0, lBorder = 0.0;
@@ -35,7 +27,7 @@ static HPALETTE newPrintPalette;
static HPALETTE oldPrintPalette;
-void wPrintClip( wPos_t x, wPos_t y, wPos_t w, wPos_t h )
+void wPrintClip( wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h )
{
wDrawClip( &print_d, x, y, w, h );
}
@@ -49,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 );
@@ -122,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" );
@@ -141,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" );
@@ -167,7 +162,7 @@ static wBool_t printInit( void )
}
getPageDim( hDc );
DeleteDC( hDc );
-
+
FreeLibrary( hDriver );
#endif
printerOk = TRUE;
@@ -196,9 +191,9 @@ void wPrintSetup( wPrintSetupCallBack_p callback )
if (PrintDlg(&printDlg) != 0 && printDlg.hDC) {
getPageDim( printDlg.hDC );
}
- if ( callback ) {
- callback( TRUE );
- }
+ //if ( callback ) {
+ // callback( TRUE );
+ //}
}
const char* wPrintGetName()
@@ -208,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 );
@@ -218,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; }
}
@@ -247,16 +242,17 @@ 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;
+ }
}
static wBool_t printAbort = FALSE;
-HWND hAbortDlgWnd;
-FARPROC lpAbortDlg, lpAbortProc;
+static HWND hAbortDlgWnd;
+static FARPROC lpAbortDlg, lpAbortProc;
static int pageNumber;
int FAR PASCAL mswAbortDlg( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
@@ -297,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
@@ -374,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 );
@@ -401,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 172b563..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 )
{
- ULONG ul;
+ ULONGLONG ul;
- ul = (ULONG) 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;
@@ -148,61 +147,66 @@ wCreateSplash( char *appname, char *appver )
cyDlgUnit = HIWORD(GetDialogBaseUnits());
/* load the logo bitmap */
- sprintf( logoPath, "%s\\logo.bmp", wGetAppLibDir());
- hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE );
- if( !hBmp )
+ snprintf( logoPath, sizeof(logoPath), "%s\\logo.bmp", wGetAppLibDir());
+ 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 ) {
@@ -266,4 +271,5 @@ wDestroySplash(void)
{
DestroyWindow( hSplash );
return;
-} \ No newline at end of file
+}
+
diff --git a/app/wlib/mswlib/mswstatus.c b/app/wlib/mswlib/mswstatus.c
index f9d72f4..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,
- wPos_t x,
- wPos_t y,
- const char * labelStr,
- wPos_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);
}
/**
@@ -75,10 +75,10 @@ wStatus_p wStatusCreate(
* \return expected width of message box
*/
-wPos_t
+wWinPix_t
wStatusGetWidth(const char *testString)
{
- return (wMessageGetWidth(testString));
+ return (wMessageGetWidth(testString));
}
/**
@@ -88,10 +88,10 @@ wStatusGetWidth(const char *testString)
* \return text height
*/
-wPos_t wStatusGetHeight(
- long flags)
+wWinPix_t wStatusGetHeight(
+ long flags)
{
- return (wMessageGetHeight(flags));
+ return (wMessageGetHeight(flags));
}
/**
@@ -103,8 +103,8 @@ wPos_t wStatusGetHeight(
*/
void wStatusSetWidth(
- wStatus_p b,
- wPos_t width)
+ wStatus_p b,
+ wWinPix_t width)
{
- wMessageSetWidth((wMessage_p)b, width);
-} \ No newline at end of file
+ wMessageSetWidth((wMessage_p)b, width);
+}
diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c
index 0a0ce88..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,44 +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;
};
-BOOL_T textPrintAbort = FALSE;
-
void wTextClear(
- wText_p b)
+ wText_p b)
{
- long rc;
- rc = SendMessage(b->hWnd, EM_SETREADONLY, 0, 0L);
-#ifdef WIN32
- rc = SendMessage(b->hWnd, EM_SETSEL, 0, -1);
-#else
- rc = SendMessage(b->hWnd, EM_SETSEL, 1, MAKELONG(0, -1));
-#endif
- rc = SendMessage(b->hWnd, WM_CLEAR, 0, 0L);
+ LRESULT rc;
+ rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)0, (LPARAM)0);
+ rc = SendMessage(b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
+ rc = SendMessage(b->hWnd, WM_CLEAR, (WPARAM)0, (LPARAM)0);
- if (b->option&BO_READONLY) {
- rc = SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L);
- }
+ if (b->option&BO_READONLY) {
+ rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0);
+ }
}
/**
@@ -90,200 +83,200 @@ void wTextClear(
*/
void wTextAppend(
- wText_p b,
- const char * text)
+ wText_p b,
+ const char * text)
{
- char *cp;
- char *buffer;
- char *extText;
- int textSize;
- int 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, 1, 0L);
- }
+ 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, 0, 10000L);
+ SendMessage(b->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)10000);
}
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, 0, 0L);
-
- for (l=0; l<lc; l++) {
- *(WORD*)line = sizeof(line)-1;
- len = (int)SendMessage(b->hWnd, EM_GETLINE, l, (DWORD)(LPSTR)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, 0, 0L);
- IOStatus = 0;
-
- for (l=0; l<lc; l++) {
- *(WORD*)line = sizeof(line)-1;
- len = (int)SendMessage(b->hWnd, EM_GETLINE, l, (DWORD)(LPSTR)line);
- TextOut(hDc, 0, currentLine*lineSpace, line, len);
-
- if (++currentLine > linesPerPage) {
- IOStatus = EndPage(hDc);
- if (IOStatus < 0 || textPrintAbort) {
- 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 && !textPrintAbort) {
- 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, 0, 0L);
- 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;
@@ -302,157 +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, ro, 0L);
+ SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0);
}
void wTextSetSize(
- wText_p bt,
- wPos_t width,
- wPos_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,
- int rows,
- int lines,
- wPos_t * w,
- wPos_t * h)
+ wText_p bt,
+ wWinPix_t rows,
+ wWinPix_t lines,
+ wWinPix_t * w,
+ wWinPix_t * h)
{
- static wPos_t scrollV_w = -1;
- static wPos_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)
{
- long rc;
- rc = SendMessage(bt->hWnd, EM_LINESCROLL, 0, MAKELONG(-65535, 0));
+ LRESULT rc;
+ rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535,
+ 0));
}
static void textDoneProc(wControl_p b)
{
- 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,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- long option,
- POS_T width,
- POS_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)index, mswHInst, NULL);
-
- if (b->hWnd == NULL) {
- mswFail("CreateWindow(TEXT)");
- return b;
- }
-
-#ifdef CONTROL3D
- Ctl3dSubclassCtl(b->hWnd);
-#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 {
+ 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");
+ }
+ }
- 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, 0L);
- }
-
- b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, 0, 0L);
-
- if (option & BT_CHARUNITS) {
- wPos_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;
+ 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 412eece..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 = 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, 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 = 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, 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 62ada76..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 * (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 * (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;
+}