summaryrefslogtreecommitdiff
path: root/app/wlib/mswlib
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/mswlib')
-rw-r--r--app/wlib/mswlib/CMakeLists.txt1
-rw-r--r--app/wlib/mswlib/ChangeLog146
-rw-r--r--app/wlib/mswlib/mswbitmap.c26
-rw-r--r--app/wlib/mswlib/mswbutt.c22
-rw-r--r--app/wlib/mswlib/mswdraw.c8
-rw-r--r--app/wlib/mswlib/mswedit.c2
-rw-r--r--app/wlib/mswlib/mswlist.c6
-rw-r--r--app/wlib/mswlib/mswmenu.c8
-rw-r--r--app/wlib/mswlib/mswmisc.c4811
-rw-r--r--app/wlib/mswlib/mswmsg.c4
-rw-r--r--app/wlib/mswlib/mswpref.c10
-rw-r--r--app/wlib/mswlib/mswsplash.c9
-rw-r--r--app/wlib/mswlib/mswstatus.c110
-rw-r--r--app/wlib/mswlib/mswtext.c636
14 files changed, 3179 insertions, 2620 deletions
diff --git a/app/wlib/mswlib/CMakeLists.txt b/app/wlib/mswlib/CMakeLists.txt
index 0c69610..82d8371 100644
--- a/app/wlib/mswlib/CMakeLists.txt
+++ b/app/wlib/mswlib/CMakeLists.txt
@@ -19,6 +19,7 @@ SET(SOURCES
mswpref.c
mswprint.c
mswsplash.c
+ mswstatus.c
mswtext.c
gwin32.c
simple-gettext.c
diff --git a/app/wlib/mswlib/ChangeLog b/app/wlib/mswlib/ChangeLog
deleted file mode 100644
index 84c17a7..0000000
--- a/app/wlib/mswlib/ChangeLog
+++ /dev/null
@@ -1,146 +0,0 @@
-Apr 28, 2010
- FIX: Daniel Spagnol
- mswmisc.c: now, wGetAppLibDir can be called before wWinMainCreate is
- called.
-
-Jan 09, 2010
- ENH: Martin Fischer
- mswmisc.c: get command line parameter handling correct
- plus some refactoring
-
-Dec 12, 2009
- FIX: Martin Fischer
- mswmisc.c: minor refactoring to stay compatible with the
- work on gtkwindow.c
-
-Sep 20. 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- CMakeLists.txt, mswbitmap.c, mswmisc.c, mswint.h:
- new source file for bitmap functions, added bitmap
- control to controls available to the application
-
-Sep 02, 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswbutt.c, mswint.h, mswlist.c mswmisc.c:
- improved XPM reading including true transparency
-
-Aug 16, 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- gwin32.c mswchoic.c mswint.h simple-gettext.c CMakeLists.txt:
- add simple gettext support
-
-Jul 24, 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: correct initialization for argv, add option
- to select configuration file, remove obsolete Win16 code
-
-Jul 10, 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: initialize the argument array properly
- CMakeLists.txt, getopt.c: add getopt()
-
-Version 4.0.3a
-==============
-
-Jun 05, 2009
- FIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: GPF when loading XPM icons fixed
-
-May 28, 2009
- FIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: wrong options for wNotice fixed
-
-May 15, 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswdraw.c, mswmisc.c, mswpref.c: more message boxes with icon
-
- May 08, 2009
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c, wlib.h: add new message box with icon
-
-Sep 05, 2008
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: enhance look of tooltip
-
-Jul 11, 2008
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswchoic.c: i18n support
- mswmenu.c, mswmisc.c: code cleanup and added comments
-
-Jul 10, 2008
- ENH: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: allow user to cancel window close request
-
-Jun 12, 2008
- FIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmsg.c: redraw problem for large font fixed
-
-Apr 05, 2008
- IMPROVEMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc,.c mswint.c: improved XPM support
-
-Mar 29, 2008
- IMPROVEMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswbutt.c: new look for toolbar buttons
-
-Mar 17, 2008
- FIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswchoic.c: Label size was not calculated correctly for radio button
- options.
-
-Feb 23,2008
- FIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswpref.c: Create the correct full path for shared data directory
-
-Jan 24,2008
- FIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswdraw.c, mswmisc.c: fixed some compiler warnings
-
-Jan 28, 2008
- FIX: Mikko Nissinen <mni77@users.sourceforge.net>
- mswmisc.c: Dynamically allocate and form some global translatable
- strings.
-
-Jan 24,2008
- IMPROVEMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswpref.c: increase floting point precision when storing floats in INI
- file
-
-Jan 22, 2008
- ENH: Mikko Nissinen <mni77@users.sourceforge.net>
- mswmisc.c: WinMain(): Free user locale before exit.
-
-Dec 16, 2007
- IMPROVMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswpref.c: use XTrackCad as directory name for configuration files
-
-Aug 03, 2007
- IMPROVMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c: use HTML Help as the help system
-
-Jul 22, 2007
- IMPROVMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswdraw.c, mswmisc.c: added support for mouse wheel in
- the drawing area
-
-Jun 17, 2007
- IMPROVMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswpref.c: added wGetUserHomeDir()
-
-Jun, 16 2007
- IMPROVEMENT: Martin Fischer <m_fischer@users.sourceforge.net>
- mswpref.c working directory is in the user profile directory tree now
-
-Feb, 05th 2007
- BUGFIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c fixed protection fault when pressing ESC in describe dialog
-
-Feb, 04th 2007
- BUGFIX: Martin Fischer <m_fischer@users.sourceforge.net>
- mswmisc.c fixed protection fault when Tabbing through describe dialog
- See xtrkcad-fork Bug 1651117
-
-Oct, 13 2006 mswmisc.c
- BUGFIX Bob Blackwell
- Fixed a problem with 'No' and 'Cancel' buttons being mixed up
-
diff --git a/app/wlib/mswlib/mswbitmap.c b/app/wlib/mswlib/mswbitmap.c
index 7371834..e369e78 100644
--- a/app/wlib/mswlib/mswbitmap.c
+++ b/app/wlib/mswlib/mswbitmap.c
@@ -144,7 +144,7 @@ void mswDrawIcon(
COLORREF col;
/* 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" );
@@ -201,17 +201,19 @@ void mswDrawIcon(
if( disabled ) {
/* create a gray scale palette */
for( i = 0; i < bm->colorcnt; i ++ ) {
- byt = ( 30 * bm->colormap[ i ].rgbRed +
- 59 * bm->colormap[ i ].rgbGreen +
- 11 * bm->colormap[ i ].rgbBlue )/100;
-
- /* if totally black, use a dark gray */
- if( byt == 0 )
- byt = 0x66;
-
- bmiInfo->bmiColors[ i ].rgbRed = byt;
- bmiInfo->bmiColors[ i ].rgbGreen = byt;
- bmiInfo->bmiColors[ i ].rgbBlue = byt;
+ if (i != bm->transparent) {
+ byt = (30 * bm->colormap[i].rgbRed +
+ 59 * bm->colormap[i].rgbGreen +
+ 11 * bm->colormap[i].rgbBlue) / 100;
+
+ /* if totally black, use a dark gray */
+ if (byt == 0)
+ byt = 0x66;
+
+ bmiInfo->bmiColors[i].rgbRed = byt;
+ bmiInfo->bmiColors[i].rgbGreen = byt;
+ bmiInfo->bmiColors[i].rgbBlue = byt;
+ }
}
} else {
/* copy the palette */
diff --git a/app/wlib/mswlib/mswbutt.c b/app/wlib/mswlib/mswbutt.c
index 24e669f..d213695 100644
--- a/app/wlib/mswlib/mswbutt.c
+++ b/app/wlib/mswlib/mswbutt.c
@@ -1,3 +1,25 @@
+/** \file mswbutt.c
+* Buttons
+*/
+
+/* XTrkCad - Model Railroad CAD
+* Copyright (C)
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
#include <windows.h>
#include <string.h>
#include <malloc.h>
diff --git a/app/wlib/mswlib/mswdraw.c b/app/wlib/mswlib/mswdraw.c
index 498b49e..652dde3 100644
--- a/app/wlib/mswlib/mswdraw.c
+++ b/app/wlib/mswlib/mswdraw.c
@@ -698,6 +698,8 @@ void wDrawGetTextSize(
HFONT newFont, prevFont;
DWORD extent;
int oldLfHeight;
+ TEXTMETRIC textMetric;
+
if (fp == NULL)
fp = &logFont;
fp->lfEscapement = 0;
@@ -707,11 +709,15 @@ void wDrawGetTextSize(
newFont = CreateFontIndirect( fp );
prevFont = SelectObject( bd->hDc, newFont );
extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, strlen(text) );
+
+ GetTextMetrics(bd->hDc, &textMetric);
+
x = LOWORD(extent);
y = HIWORD(extent);
*w = XPIXELSTOINCH( bd, x );
*h = YPIXELSTOINCH( bd, y );
- *d = 0;
+ *d = YPIXELSTOINCH(bd, textMetric.tmDescent );
+
SelectObject( bd->hDc, prevFont );
DeleteObject( newFont );
fp->lfHeight = oldLfHeight;
diff --git a/app/wlib/mswlib/mswedit.c b/app/wlib/mswlib/mswedit.c
index 937a83e..fbae89f 100644
--- a/app/wlib/mswlib/mswedit.c
+++ b/app/wlib/mswlib/mswedit.c
@@ -135,7 +135,7 @@ void wStringSetWidth(
const char * wStringGetValue(
wString_p b )
{
- static char buff[256];
+ static char buff[1024];
SendMessage( b->hWnd, WM_GETTEXT, sizeof buff, (DWORD)buff );
return buff;
}
diff --git a/app/wlib/mswlib/mswlist.c b/app/wlib/mswlib/mswlist.c
index 18fa92d..2453a5e 100644
--- a/app/wlib/mswlib/mswlist.c
+++ b/app/wlib/mswlib/mswlist.c
@@ -214,8 +214,10 @@ wIndex_t wListGetValues(
}
cnt = (int)SendMessage( bl->hWnd, msg, inx, (DWORD)(LPSTR)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
- if (s)
- strncpy( s, mswTmpBuff, siz );
+ if (s) {
+ strncpy(s, mswTmpBuff, siz);
+ s[siz-1] = '\0';
+ }
if (bl->last >= 0) {
ldp = (listData*)SendMessage( bl->hWnd,
(bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
diff --git a/app/wlib/mswlib/mswmenu.c b/app/wlib/mswlib/mswmenu.c
index de49742..815752a 100644
--- a/app/wlib/mswlib/mswmenu.c
+++ b/app/wlib/mswlib/mswmenu.c
@@ -315,7 +315,9 @@ static long acclKeyMap[] = {
VK_F9, /* wAccelKey_F9, */
VK_F10, /* wAccelKey_F10, */
VK_F11, /* wAccelKey_F11, */
- VK_F12 /* wAccelKey_F12, */
+ VK_F12, /* wAccelKey_F12, */
+ VK_ADD, /* wAccelKey_Numpad_Add, */
+ VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */
};
@@ -326,7 +328,7 @@ void wAttachAccelKey(
void * data )
{
acclTable_t * ad;
- if ( key < 1 || key > wAccelKey_F12 ) {
+ if ( key < 1 || key > wAccelKey_Numpad_Subtract ) {
mswFail( "wAttachAccelKey: key out of range" );
return;
}
@@ -908,7 +910,7 @@ wMenuToggle_p wMenuToggleCreate(
if ( vk & 0xFF00 )
modifier |= WKEY_SHIFT;
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
- acclTable(acclTable_da.cnt-1).mp = mt;
+ acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mt;
}
rc = AppendMenu( m->menu, MF_STRING, mt->index, label );
diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c
index cc46e4e..b9383a2 100644
--- a/app/wlib/mswlib/mswmisc.c
+++ b/app/wlib/mswlib/mswmisc.c
@@ -34,14 +34,14 @@
#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
#define OFN_LONGFILENAMES 0x00200000L
-char * mswStrdup( const char * );
+char * mswStrdup(const char *);
#define PAUSE_TIMER (901)
#define ALARM_TIMER (902)
@@ -80,33 +80,33 @@ double mswScale = 1.0;
callBacks_t *mswCallBacks[CALLBACK_CNT];
-void closeBalloonHelp( void );
-static wControl_p getControlFromCursor( HWND, wWin_p * );
+void closeBalloonHelp(void);
+static wControl_p getControlFromCursor(HWND, wWin_p *);
/*
* LOCAL VARIABLES
*/
struct wWin_t {
- WOBJ_COMMON
- wPos_t lastX, lastY;
- wPos_t padX, padY;
- wControl_p first, last;
- wWinCallBack_p winProc;
- BOOL_T busy;
+ WOBJ_COMMON
+ wPos_t lastX, lastY;
+ wPos_t padX, padY;
+ wControl_p first, last;
+ wWinCallBack_p winProc;
+ BOOL_T busy;
#ifdef OWNERICON
- HBITMAP wicon_bm;
- wPos_t wicon_w, wicon_h;
+ HBITMAP wicon_bm;
+ wPos_t wicon_w, wicon_h;
#endif
- DWORD baseStyle;
- wControl_p focusChainFirst;
- wControl_p focusChainLast;
- char * nameStr;
- wBool_t centerWin;
- DWORD style;
- int isBusy;
- int pendingShow;
- int modalLevel;
- };
+ DWORD baseStyle;
+ wControl_p focusChainFirst;
+ wControl_p focusChainLast;
+ char * nameStr;
+ wBool_t centerWin;
+ DWORD style;
+ int isBusy;
+ int pendingShow;
+ int modalLevel;
+};
static needToDoPendingShow = FALSE;
@@ -131,13 +131,14 @@ static UINT triggerTimer;
static UINT balloonHelpTimeOut = 500;
static wControl_p balloonHelpButton = NULL;
-static enum { balloonHelpIdle , balloonHelpWait, balloonHelpShow } balloonHelpState = balloonHelpIdle;
+static enum { balloonHelpIdle, balloonHelpWait, balloonHelpShow } balloonHelpState
+ = balloonHelpIdle;
static HWND balloonHelpHWnd = (HWND)0;
static int balloonHelpFontSize = 8;
static char balloonHelpFaceName[] = "MS Sans Serif";
static HFONT balloonHelpOldFont;
static HFONT balloonHelpNewFont;
-static int balloonHelpEnable = TRUE;
+static int balloonHelpEnable = TRUE;
static wControl_p balloonControlButton = NULL;
static BOOL_T helpInitted = FALSE;
@@ -145,8 +146,8 @@ static DWORD dwCookie;
#define CONTROL_BASE (1)
typedef struct {
- wControl_p b;
- } controlMap_t;
+ wControl_p b;
+} controlMap_t;
dynArr_t controlMap_da;
#define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N)
@@ -184,57 +185,66 @@ extern char *userLocale;
DWORD GetTextExtent(
- HDC hDc,
- CHAR * str,
- UINT len )
+ HDC hDc,
+ CHAR * str,
+ UINT len)
{
- SIZE size;
- GetTextExtentPoint( hDc, str, len, &size );
- return size.cx + (size.cy<<16);
+ SIZE size;
+ GetTextExtentPoint(hDc, str, len, &size);
+ return size.cx + (size.cy<<16);
}
static char * controlNames[] = {
- "MAIN", "POPUP",
- "BUTTON", "STRING", "INTEGER", "FLOAT",
- "LIST", "DROPLIST", "COMBOLIST",
- "RADIO", "TOGGLE",
- "DRAW", "TEXT", "MESSAGE", "LINES",
- "MENUITEM", "CHOICEITEM", "BOX" };
+ "MAIN", "POPUP",
+ "BUTTON", "STRING", "INTEGER", "FLOAT",
+ "LIST", "DROPLIST", "COMBOLIST",
+ "RADIO", "TOGGLE",
+ "DRAW", "TEXT", "MESSAGE", "LINES",
+ "MENUITEM", "CHOICEITEM", "BOX"
+};
static void doDumpControls(void)
{
- wControl_p b;
- int inx;
- if ( !dumpControls )
- return;
- if ( !dumpControlsF ) {
- dumpControlsF = fopen( "controls.lst", "w" );
- if ( !dumpControlsF )
- abort();
- }
- for ( inx=0; inx<controlMap_da.cnt-1; inx++ ) {
- b = controlMap(inx).b;
- if ( b ) {
- fprintf( dumpControlsF, "[%0.3d] [%x] %s %s %s\n", inx,
- (unsigned int)b->hWnd,
- (b->type>=0&&b->type<=B_BOX?controlNames[b->type]:"NOTYPE"),
- (b->labelStr?b->labelStr:"<NULL>"),
- (b->helpStr?b->helpStr:"<NULL>") );
- } else {
- fprintf( dumpControlsF, "[%0.3d] <NULL>\n", inx );
- }
- }
- fflush( dumpControlsF );
- fclose( dumpControlsF );
- dumpControls = 0;
+ wControl_p b;
+ int inx;
+
+ if (!dumpControls) {
+ return;
+ }
+
+ if (!dumpControlsF) {
+ dumpControlsF = fopen("controls.lst", "w");
+
+ if (!dumpControlsF) {
+ abort();
+ }
+ }
+
+ for (inx=0; inx<controlMap_da.cnt-1; inx++) {
+ b = controlMap(inx).b;
+
+ if (b) {
+ fprintf(dumpControlsF, "[%0.3d] [%x] %s %s %s\n", inx,
+ (unsigned int)b->hWnd,
+ (b->type>=0&&b->type<=B_BOX?controlNames[b->type]:"NOTYPE"),
+ (b->labelStr?b->labelStr:"<NULL>"),
+ (b->helpStr?b->helpStr:"<NULL>"));
+ } else {
+ fprintf(dumpControlsF, "[%0.3d] <NULL>\n", inx);
+ }
+ }
+
+ fflush(dumpControlsF);
+ fclose(dumpControlsF);
+ dumpControls = 0;
}
-void mswFail( const char * where )
+void mswFail(const char * where)
{
- sprintf( mswTmpBuff, "%s\n# Controls %d", where, controlMap_da.cnt );
- MessageBox( NULL, mswTmpBuff, "FAIL", MB_TASKMODAL|MB_OK );
- doDumpControls();
+ sprintf(mswTmpBuff, "%s\n# Controls %d", where, controlMap_da.cnt);
+ MessageBox(NULL, mswTmpBuff, "FAIL", MB_TASKMODAL|MB_OK);
+ doDumpControls();
}
/*
static UINT curSysRes = 100;
@@ -243,252 +253,283 @@ static UINT curUsrRes = 100;
static UINT curMinRes = 100;
*/
-wControl_p mswMapIndex( INDEX_T inx )
+wControl_p mswMapIndex(INDEX_T inx)
{
- if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
- mswFail("mswMapIndex- bad index");
- exit(1);
- }
- return controlMap(inx-CONTROL_BASE).b;
-}
-
-
-void mswRepaintLabel( HWND hWnd, wControl_p b )
-{
- HDC hDc;
- HBRUSH oldBrush, newBrush;
- RECT rect;
- DWORD dw;
- LABELFONTDECL
-
-
- if (b->labelStr) {
- hDc = GetDC( hWnd );
- LABELFONTSELECT
- newBrush = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) );
- oldBrush = SelectObject( hDc, newBrush );
- dw = GetTextExtent( hDc, CAST_AWAY_CONST b->labelStr, strlen(b->labelStr) );
- rect.left = b->labelX;
- rect.top = b->labelY;
- rect.right = b->labelX + LOWORD(dw);
- rect.bottom = b->labelY + HIWORD(dw);
- FillRect( hDc, &rect, newBrush );
- DeleteObject( SelectObject( hDc, oldBrush ) );
- /*SetBkMode( hDc, OPAQUE );*/
- SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) );
- if (!TextOut( hDc, b->labelX, b->labelY, b->labelStr, strlen(b->labelStr) ) )
- mswFail( "Repainting text label" );
- LABELFONTRESET
- ReleaseDC( hWnd, hDc );
- }
+ if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
+ mswFail("mswMapIndex- bad index");
+ exit(1);
+ }
+
+ return controlMap(inx-CONTROL_BASE).b;
+}
+
+
+void mswRepaintLabel(HWND hWnd, wControl_p b)
+{
+ HDC hDc;
+ HBRUSH oldBrush, newBrush;
+ RECT rect;
+ DWORD dw;
+ LABELFONTDECL
+
+ if (b->labelStr) {
+ hDc = GetDC(hWnd);
+ LABELFONTSELECT
+ newBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
+ oldBrush = SelectObject(hDc, newBrush);
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, strlen(b->labelStr));
+ rect.left = b->labelX;
+ rect.top = b->labelY;
+ rect.right = b->labelX + LOWORD(dw);
+ rect.bottom = b->labelY + HIWORD(dw);
+ FillRect(hDc, &rect, newBrush);
+ DeleteObject(SelectObject(hDc, oldBrush));
+ /*SetBkMode( hDc, OPAQUE );*/
+ SetBkColor(hDc, GetSysColor(COLOR_BTNFACE));
+
+ if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, strlen(b->labelStr))) {
+ mswFail("Repainting text label");
+ }
+
+ LABELFONTRESET
+ ReleaseDC(hWnd, hDc);
+ }
}
int mswRegister(
- wControl_p w )
+ wControl_p w)
{
- int index;
- DYNARR_APPEND( controlMap_t, controlMap_da, 25 );
- index = controlMap_da.cnt-1+CONTROL_BASE;
- controlMap(controlMap_da.cnt-1).b = (wControl_p)w;
- return index;
+ int index;
+ DYNARR_APPEND(controlMap_t, controlMap_da, 25);
+ index = controlMap_da.cnt-1+CONTROL_BASE;
+ controlMap(controlMap_da.cnt-1).b = (wControl_p)w;
+ return index;
}
void mswUnregister(
- int index )
+ int index)
{
- if (index < 0 || index > controlMap_da.cnt) {
- mswFail("mswMapIndex- bad index");
- exit(1);
- }
- controlMap(index-CONTROL_BASE).b = NULL;
+ if (index < 0 || index > controlMap_da.cnt) {
+ mswFail("mswMapIndex- bad index");
+ exit(1);
+ }
+
+ controlMap(index-CONTROL_BASE).b = NULL;
}
void * mswAlloc(
- wWin_p parent,
- wType_e type,
- const char * labelStr,
- int size,
- void * data,
- int * index )
-{
- wControl_p w = (wControl_p)calloc( 1, size );
-
- if (w == NULL)
- abort();
- *index = mswRegister( w );
- w->type = type;
- w->next = NULL;
- w->parent = parent;
- w->x = 0;
- w->y = 0;
- w->w = 0;
- w->h = 0;
- w->option = 0;
- w->labelX = w->labelY = 0;
- w->labelStr = labelStr;
- w->helpStr = NULL;
- w->hWnd = (HWND)0;
- w->data = data;
- w->focusChainNext = NULL;
- w->shown = TRUE;
- return w;
+ wWin_p parent,
+ wType_e type,
+ const char * labelStr,
+ int size,
+ void * data,
+ int * index)
+{
+ wControl_p w = (wControl_p)calloc(1, size);
+
+ if (w == NULL) {
+ abort();
+ }
+
+ *index = mswRegister(w);
+ w->type = type;
+ w->next = NULL;
+ w->parent = parent;
+ w->x = 0;
+ w->y = 0;
+ w->w = 0;
+ w->h = 0;
+ w->option = 0;
+ w->labelX = w->labelY = 0;
+ w->labelStr = labelStr;
+ w->helpStr = NULL;
+ w->hWnd = (HWND)0;
+ w->data = data;
+ w->focusChainNext = NULL;
+ w->shown = TRUE;
+ return w;
}
void mswComputePos(
- wControl_p b,
- wPos_t origX,
- wPos_t origY )
-{
- wWin_p w = b->parent;
-
- if (origX >= 0)
- b->x = origX;
- else
- b->x = w->lastX + (-origX) - 1;
- if (origY >= 0)
- b->y = origY;
- else
- b->y = w->lastY + (-origY) - 1;
-
- b->labelX = b->x;
- b->labelY = b->y+2;
-
- if (b->labelStr) {
- int 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 );
- b->labelX -= LOWORD(dw) + 5;
- LABELFONTRESET
- ReleaseDC( w->hWnd, hDc );
- }
+ wControl_p b,
+ wPos_t origX,
+ wPos_t origY)
+{
+ wWin_p w = b->parent;
+
+ if (origX >= 0) {
+ b->x = origX;
+ } else {
+ b->x = w->lastX + (-origX) - 1;
+ }
+
+ if (origY >= 0) {
+ b->y = origY;
+ } else {
+ b->y = w->lastY + (-origY) - 1;
+ }
+
+ b->labelX = b->x;
+ b->labelY = b->y+2;
+
+ if (b->labelStr) {
+ int 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);
+ b->labelX -= LOWORD(dw) + 5;
+ LABELFONTRESET
+ ReleaseDC(w->hWnd, hDc);
+ }
}
void mswAddButton(
- wControl_p b,
- BOOL_T paintLabel,
- const char * helpStr )
-{
- wWin_p w = b->parent;
- BOOL_T resize = FALSE;
- RECT rect;
-
- if (w->first == NULL) {
- w->first = b;
- } else {
- w->last->next = b;
- }
- w->last = b;
- b->next = NULL;
- b->parent = w;
- w->lastX = b->x + b->w;
- w->lastY = b->y + b->h;
- if ((w->option&F_AUTOSIZE)!=0 && w->lastX > w->w) {
- w->w = w->lastX;
- resize = TRUE;
- }
- if ((w->option&F_AUTOSIZE)!=0 && w->lastY > w->h) {
- w->h = w->lastY;
- resize = TRUE;
- }
-
- if (resize) {
- w->busy = TRUE;
- rect.left = 0;
- rect.top = 0;
- rect.right = w->w+w->padX;
- rect.bottom = w->h+w->padY;
- AdjustWindowRect( &rect, w->style, (w->option&F_MENUBAR)?1:0 );
- rect.bottom += mFixBorderH;
- if (!SetWindowPos( w->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
- rect.right-rect.left, rect.bottom-rect.top,
- SWP_NOMOVE))
- mswFail("SetWindowPos");
- w->busy = FALSE;
- }
+ wControl_p b,
+ BOOL_T paintLabel,
+ const char * helpStr)
+{
+ wWin_p w = b->parent;
+ BOOL_T resize = FALSE;
+ RECT rect;
+
+ if (w->first == NULL) {
+ w->first = b;
+ } else {
+ w->last->next = b;
+ }
+
+ w->last = b;
+ b->next = NULL;
+ b->parent = w;
+ w->lastX = b->x + b->w;
+ w->lastY = b->y + b->h;
+
+ if ((w->option&F_AUTOSIZE)!=0 && w->lastX > w->w) {
+ w->w = w->lastX;
+ resize = TRUE;
+ }
+
+ if ((w->option&F_AUTOSIZE)!=0 && w->lastY > w->h) {
+ w->h = w->lastY;
+ resize = TRUE;
+ }
+
+ if (resize) {
+ w->busy = TRUE;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = w->w+w->padX;
+ rect.bottom = w->h+w->padY;
+ AdjustWindowRect(&rect, w->style, (w->option&F_MENUBAR)?1:0);
+ rect.bottom += mFixBorderH;
+
+ if (!SetWindowPos(w->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
+ rect.right-rect.left, rect.bottom-rect.top,
+ SWP_NOMOVE)) {
+ mswFail("SetWindowPos");
+ }
+
+ w->busy = FALSE;
+ }
+
+ if (paintLabel) {
+ mswRepaintLabel(w->hWnd, (wControl_p)b);
+ }
+
+ if (helpStr == NULL) {
+ return;
+ }
+
+ b->helpStr = mswStrdup(helpStr);
+#ifdef HELPSTR
- if (paintLabel)
- mswRepaintLabel( w->hWnd, (wControl_p)b );
+ if (helpStrF) {
+ fprintf(helpStrF, "HELPSTR - %s\n", helpStr?helpStr:"<>");
+ }
- if (helpStr == NULL)
- return;
- b->helpStr = mswStrdup( helpStr );
-
-#ifdef HELPSTR
- if (helpStrF)
- fprintf( helpStrF, "HELPSTR - %s\n", helpStr?helpStr:"<>" );
#endif
}
void mswResize(
- wWin_p w )
-{
- wControl_p b;
- RECT rect;
-
- w->lastX = 0;
- w->lastY = 0;
- for (b=w->first; b; b=b->next) {
- if (w->lastX < (b->x + b->w))
- w->lastX = b->x + b->w;
- if (w->lastY < (b->y + b->h))
- w->lastY = b->y + b->h;
- }
+ wWin_p w)
+{
+ wControl_p b;
+ RECT rect;
+ w->lastX = 0;
+ w->lastY = 0;
- if (w->option&F_AUTOSIZE) {
- w->w = w->lastX;
- w->h = w->lastY;
- w->busy = TRUE;
- rect.left = 0;
- rect.top = 0;
- rect.right = w->w + w->padX;
- rect.bottom = w->h + w->padY;
- AdjustWindowRect( &rect, w->style, (w->option&F_MENUBAR)?1:0 );
- rect.bottom += mFixBorderH;
- if (!SetWindowPos( w->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
- rect.right-rect.left, rect.bottom-rect.top,
- SWP_NOMOVE|SWP_NOZORDER))
- mswFail("SetWindowPos");
- w->busy = FALSE;
- }
+ for (b=w->first; b; b=b->next) {
+ if (w->lastX < (b->x + b->w)) {
+ w->lastX = b->x + b->w;
+ }
+
+ if (w->lastY < (b->y + b->h)) {
+ w->lastY = b->y + b->h;
+ }
+ }
+
+ if (w->option&F_AUTOSIZE) {
+ w->w = w->lastX;
+ w->h = w->lastY;
+ w->busy = TRUE;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = w->w + w->padX;
+ rect.bottom = w->h + w->padY;
+ AdjustWindowRect(&rect, w->style, (w->option&F_MENUBAR)?1:0);
+ rect.bottom += mFixBorderH;
+
+ if (!SetWindowPos(w->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
+ rect.right-rect.left, rect.bottom-rect.top,
+ SWP_NOMOVE|SWP_NOZORDER)) {
+ mswFail("SetWindowPos");
+ }
+
+ w->busy = FALSE;
+ }
}
void mswChainFocus(
- wControl_p b )
-{
- wWin_p w;
- w = b->parent;
- if (w->option&F_NOTAB)
- return;
- if (b->option&BO_NOTAB)
- return;
- if (w->focusChainFirst == NULL) {
- w->focusChainFirst = w->focusChainLast = w->focusChainNext = b;
- b->focusChainNext = b;
- } else {
- w->focusChainLast->focusChainNext = b;
- w->focusChainLast = b;
- b->focusChainNext = w->focusChainFirst;
- }
+ wControl_p b)
+{
+ wWin_p w;
+ w = b->parent;
+
+ if (w->option&F_NOTAB) {
+ return;
+ }
+
+ if (b->option&BO_NOTAB) {
+ return;
+ }
+
+ if (w->focusChainFirst == NULL) {
+ w->focusChainFirst = w->focusChainLast = w->focusChainNext = b;
+ b->focusChainNext = b;
+ } else {
+ w->focusChainLast->focusChainNext = b;
+ w->focusChainLast = b;
+ b->focusChainNext = w->focusChainFirst;
+ }
}
void mswSetFocus(
- wControl_p b )
+ wControl_p b)
{
- if (b && b->type != B_MENUITEM && b->focusChainNext)
- b->parent->focusChainNext = b;
+ if (b && b->type != B_MENUITEM && b->focusChainNext) {
+ b->parent->focusChainNext = b;
+ }
}
/*
@@ -500,171 +541,205 @@ void mswSetFocus(
*/
static void getSavedSizeAndPos(
- long option,
- const char * nameStr,
- wPos_t *rw,
- wPos_t *rh,
- wPos_t *rx,
- wPos_t *ry,
- int *showCmd )
-{
- int x, y, w, h;
- const char *cp;
+ long option,
+ const char * nameStr,
+ wPos_t *rw,
+ wPos_t *rh,
+ wPos_t *rx,
+ wPos_t *ry,
+ int *showCmd)
+{
char *cq;
- int state;
-
- *showCmd = SW_SHOWNORMAL;
-
- if ( (option&F_RECALLPOS) && nameStr ) {
- if ( (option & F_RESIZE) &&
- (cp = wPrefGetString( "msw window size", nameStr)) &&
- (state = (int)strtol( cp, &cq, 10 ), cp != cq) &&
- (cp = cq, w = (wPos_t)strtod( cp, &cq ), cp != cq ) &&
- (cp = cq, h = (int)strtod( cp, &cq ), cp != cq)
- ) {
- if (state == 1)
- *showCmd = SW_SHOWMINIMIZED;
- else if (state == 2)
- *showCmd = SW_SHOWMAXIMIZED;
- if (w < 10)
- w = 10;
- if (h < 10)
- h = 10;
- if (w > screenWidth)
- w = screenWidth;
- if (h > screenHeight)
- h = screenHeight;
- *rw = w;
- *rh = h;
- }
-
- if ((cp = wPrefGetString( "msw window pos", nameStr)) &&
- (x = (wPos_t)strtod( cp, &cq ), cp != cq) &&
- (cp = cq, y = (wPos_t)strtod( cp, &cq ), cp != cq)
- ) {
- if (y < 0)
- y = 0;
- if (x < 0)
- x = 0;
- if ( y > screenHeight-40 )
- y = screenHeight-40;
- if ( x > screenWidth-40 )
- x = screenWidth-40;
- *rx = x;
- *ry = y;
- }
- }
+ *showCmd = SW_SHOWNORMAL;
+
+ if ((option&F_RECALLPOS) && nameStr) {
+ int x, y, w, h;
+ const char *cp;
+ int state;
+
+ 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)
+ ) {
+ if (w < 10) {
+ w = 10;
+ }
+
+ if (h < 10) {
+ h = 10;
+ }
+
+ if (w > screenWidth) {
+ w = screenWidth;
+ }
+
+ if (h > screenHeight) {
+ h = screenHeight;
+ }
+
+ *rw = w;
+ *rh = h;
+ }
+
+ 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)
+ ) {
+ if (y < 0) {
+ y = 0;
+ }
+
+ if (x < 0) {
+ x = 0;
+ }
+
+ if (y > screenHeight-40) {
+ y = screenHeight-40;
+ }
+
+ if (x > screenWidth-40) {
+ x = screenWidth-40;
+ }
+
+ *rx = x;
+ *ry = y;
+ }
+ }
}
+/**
+ * Create a window. Retrieves the saved size and position and restores the created window accordingly.
+ *
+ * \param hWnd IN parent window
+ * \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 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 pShowCmd IN/OUT window show option (maximize or show normal)
+ * \return window data structure
+ */
static wWin_p winCommonCreate(
- HWND hWnd,
- int typ,
- long option,
- const char * className,
- long style,
- const char * labelStr,
- wWinCallBack_p winProc,
- wPos_t w,
- wPos_t h,
- void * data,
- const char * nameStr,
- int * showCmd )
-{
- wWin_p win;
- int index;
- wPos_t ww, hh, xx, yy;
- RECT rect;
-
- win = (wWin_p)mswAlloc( NULL, typ, mswStrdup(labelStr), sizeof *win, data, &index );
- win->option = option;
- win->first = win->last = NULL;
- win->lastX = 0;
- win->lastY = 0;
- win->winProc = winProc;
- win->centerWin = TRUE;
- win->modalLevel = 0;
-#ifdef OWNERICON
- win->wicon_bm = (HBITMAP)0;
-#endif
- win->busy = TRUE;
- ww = hh = xx = yy = CW_USEDEFAULT;
- getSavedSizeAndPos( option, nameStr, &ww, &hh, &xx, &yy, showCmd );
- if (xx != CW_USEDEFAULT)
- win->centerWin = FALSE;
- if (option & F_RESIZE) {
- style |= WS_THICKFRAME;
- if ( ww != CW_USEDEFAULT ) {
- w = ww;
- h = hh;
- option &= ~F_AUTOSIZE;
- win->option = option;
- }
- }
-
- if ( option & F_AUTOSIZE ) {
- win->padX = w;
- win->padY = h;
- } else {
- win->padX = 0;
- win->padY = 0;
- win->w = w;
- win->h = h;
- }
- win->style = style;
- rect.left = 0;
- rect.top = 0;
- rect.right = win->w + win->padX;
- rect.bottom = win->h + win->padY;
- AdjustWindowRect( &rect, win->style, (win->option&F_MENUBAR)?1:0 );
- rect.bottom += mFixBorderH;
- win->hWnd = CreateWindow( className, labelStr, style,
- xx, yy,
- rect.right-rect.left, rect.bottom-rect.top,
- hWnd, NULL,
- mswHInst, NULL );
- if (win->hWnd == (HWND)0) {
- mswFail( "CreateWindow(POPUP)" );
- } else {
- SetWindowWord( win->hWnd, 0, (WORD)index );
- }
- win->baseStyle = WS_GROUP;
- win->focusChainFirst = win->focusChainLast = win->focusChainNext = NULL;
- if (winFirst == NULL) {
- winFirst = winLast = win;
- } else {
- winLast->next = (wControl_p)win;
- winLast = win;
- }
-#ifdef HELPSTR
- if (helpStrF)
- fprintf( helpStrF, "WINDOW - %s\n", labelStr );
-#endif
- win->nameStr = mswStrdup( nameStr );
- if (typ == W_MAIN)
- mswInitColorPalette();
-#ifdef LATER
- hDc = GetDC( win->hWnd );
- oldHPal = SelectPalette( hDc, mswPalette, 0 );
- ReleaseDC( win->hWnd, hDc );
-#endif
- return win;
+ HWND hWnd,
+ int typ,
+ long option,
+ const char * className,
+ long style,
+ const char * labelStr,
+ wWinCallBack_p winProc,
+ wPos_t w,
+ wPos_t h,
+ void * data,
+ const char * nameStr,
+ int * pShowCmd)
+{
+ wWin_p win;
+ int index;
+ wPos_t ww, hh, xx, yy;
+ RECT rect;
+ win = (wWin_p)mswAlloc(NULL, typ, mswStrdup(labelStr), sizeof *win, data,
+ &index);
+ win->option = option;
+ win->first = win->last = NULL;
+ win->lastX = 0;
+ win->lastY = 0;
+ win->winProc = winProc;
+ win->centerWin = TRUE;
+ win->modalLevel = 0;
+ win->busy = TRUE;
+ ww = hh = xx = yy = CW_USEDEFAULT;
+ getSavedSizeAndPos(option, nameStr, &ww, &hh, &xx, &yy, pShowCmd);
+
+ if (typ == W_MAIN) {
+ *pShowCmd = ((option & F_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
+ }
+
+ if (xx != CW_USEDEFAULT) {
+ win->centerWin = FALSE;
+ }
+
+ if (option & F_RESIZE) {
+ style |= WS_THICKFRAME;
+
+ if (ww != CW_USEDEFAULT) {
+ w = ww;
+ h = hh;
+ option &= ~F_AUTOSIZE;
+ win->option = option;
+ }
+ }
+
+ if (option & F_AUTOSIZE) {
+ win->padX = w;
+ win->padY = h;
+ } else {
+ win->padX = 0;
+ win->padY = 0;
+ win->w = w;
+ win->h = h;
+ }
+
+ win->style = style;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = win->w + win->padX;
+ rect.bottom = win->h + win->padY;
+ AdjustWindowRect(&rect, win->style, (win->option&F_MENUBAR)?1:0);
+ rect.bottom += mFixBorderH;
+ win->hWnd = CreateWindow(className, labelStr, style,
+ xx, yy,
+ rect.right-rect.left, rect.bottom-rect.top,
+ hWnd, NULL,
+ mswHInst, NULL);
+
+ if (win->hWnd == (HWND)0) {
+ mswFail("CreateWindow(POPUP)");
+ } else {
+ SetWindowWord(win->hWnd, 0, (WORD)index);
+ }
+
+ ShowWindow(win->hWnd, *pShowCmd);
+ win->baseStyle = WS_GROUP;
+ win->focusChainFirst = win->focusChainLast = win->focusChainNext = NULL;
+
+ if (winFirst == NULL) {
+ winFirst = winLast = win;
+ } else {
+ winLast->next = (wControl_p)win;
+ winLast = win;
+ }
+
+ win->nameStr = mswStrdup(nameStr);
+
+ if (typ == W_MAIN) {
+ mswInitColorPalette();
+ }
+
+ return win;
}
void wInitAppName(char *_appName)
{
- appName = (char *)malloc( strlen(_appName) + 1 );
- strcpy(appName, _appName);
+ appName = (char *)malloc(strlen(_appName) + 1);
+ strcpy(appName, _appName);
}
/**
- * Initialize the application's main window. This function does the necessary initialization
+ * Initialize the application's main window. This function does the necessary initialization
* of the application including creation of the main window.
*
- * \param name IN internal name of the application. Used for filenames etc.
- * \param x IN size
- * \param y IN size
+ * \param name IN internal name of the application. Used for filenames etc.
+ * \param x IN default width
+ * \param y IN default height
* \param helpStr IN ??
* \param labelStr IN window title
* \param nameStr IN ??
@@ -675,257 +750,350 @@ void wInitAppName(char *_appName)
*/
wWin_p wWinMainCreate(
- const char * name,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- const char * nameStr,
- long option,
- wWinCallBack_p winProc,
- void * data )
-{
- wWin_p w;
- RECT rect;
- const char * appDir;
- const char * libDir;
- int showCmd;
- int error;
- HDC hDc;
- TEXTMETRIC tm;
- char *pos;
- char * configName;
-
- /* check for configuration name */
- if( pos = strchr( name, ';' )) {
- /* if found, split application name and configuration name */
- configName = (char *)malloc( strlen( name ) + 1 );
- strcpy( configName, pos + 1 );
- } else {
- /* if not found, application name and configuration name are same */
- configName = (char*)malloc( strlen(name)+1 );
- strcpy( configName, name );
- }
-
- appDir = wGetAppWorkDir();
- if ( appDir == NULL ) {
- free( configName );
- return NULL;
- }
- mswProfileFile = (char*)malloc( strlen(appDir)+1+strlen(configName)+1+3+1 );
- wsprintf( mswProfileFile, "%s\\%s.ini", appDir, configName );
- free( configName );
-
- error = WritePrivateProfileString( "mswtest", "test", "ok", mswProfileFile );
- if ( error <= 0 ) {
- sprintf( mswTmpBuff, "Can not write to %s.\nPlease make sure the directory exists and is writable", mswProfileFile );
- wNoticeEx( NT_ERROR, mswTmpBuff, "Ok", NULL );
- return NULL;
- }
- libDir = wGetAppLibDir();
- /* 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 );
-
- showCmd = SW_SHOW;
- w = winCommonCreate( NULL, W_MAIN, option|F_RESIZE, "MswMainWindow",
- WS_OVERLAPPEDWINDOW, labelStr, winProc, x, y, data,
- nameStr, &showCmd );
- mswHWnd = w->hWnd;
- if ( !mswThickFont ) {
- DWORD dw;
- SendMessage( w->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
- hDc = GetDC( w->hWnd );
- GetTextMetrics( hDc, &tm );
- mswEditHeight = tm.tmHeight+2;
- dw = GetTextExtent( hDc, "AXqypj", 6 );
- mswEditHeight = HIWORD(dw)+2;
- ReleaseDC( w->hWnd, hDc );
- }
- ShowWindow( w->hWnd, showCmd );
- UpdateWindow( w->hWnd );
- GetWindowRect( w->hWnd, &rect );
- GetClientRect( w->hWnd, &rect );
- w->busy = FALSE;
-
-
- return w;
+ const char * name,
+ POS_T x,
+ POS_T y,
+ const char * helpStr,
+ const char * labelStr,
+ const char * nameStr,
+ long option,
+ wWinCallBack_p winProc,
+ void * data)
+{
+ wWin_p w;
+ RECT rect;
+ const char * appDir;
+ const char * libDir;
+ int showCmd;
+ int error;
+ HDC hDc;
+ TEXTMETRIC tm;
+ char *pos;
+ char * configName;
+ long maximize;
+
+ /* check for configuration name */
+ if (pos = strchr(name, ';')) {
+ /* if found, split application name and configuration name */
+ configName = (char *)malloc(strlen(name) + 1);
+ strcpy(configName, pos + 1);
+ } else {
+ /* if not found, application name and configuration name are same */
+ configName = (char*)malloc(strlen(name)+1);
+ strcpy(configName, name);
+ }
+
+ appDir = wGetAppWorkDir();
+
+ if (appDir == NULL) {
+ free(configName);
+ return NULL;
+ }
+
+ mswProfileFile = (char*)malloc(strlen(appDir)+1+strlen(configName)+1+3+1);
+ wsprintf(mswProfileFile, "%s\\%s.ini", appDir, configName);
+ free(configName);
+ error = WritePrivateProfileString("mswtest", "test", "ok", mswProfileFile);
+
+ if (error <= 0) {
+ sprintf(mswTmpBuff,
+ "Can not write to %s.\nPlease make sure the directory exists and is writable",
+ mswProfileFile);
+ wNoticeEx(NT_ERROR, mswTmpBuff, "Ok", NULL);
+ return NULL;
+ }
+
+ libDir = wGetAppLibDir();
+ /* 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);
+
+ showCmd = SW_SHOW;
+ w = winCommonCreate(NULL, W_MAIN, option|F_RESIZE, "MswMainWindow",
+ WS_OVERLAPPEDWINDOW, labelStr, winProc, x, y, data,
+ nameStr, &showCmd);
+ mswHWnd = w->hWnd;
+
+ if (!mswThickFont) {
+ DWORD dw;
+ SendMessage(w->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L);
+ hDc = GetDC(w->hWnd);
+ GetTextMetrics(hDc, &tm);
+ mswEditHeight = tm.tmHeight+2;
+ dw = GetTextExtent(hDc, "AXqypj", 6);
+ mswEditHeight = HIWORD(dw)+2;
+ ReleaseDC(w->hWnd, hDc);
+ }
+
+ ShowWindow(w->hWnd, showCmd);
+ UpdateWindow(w->hWnd);
+ GetWindowRect(w->hWnd, &rect);
+ GetClientRect(w->hWnd, &rect);
+ w->busy = FALSE;
+ return w;
}
wWin_p wWinPopupCreate(
- wWin_p parent,
- POS_T x,
- POS_T y,
- const char * helpStr,
- const char * labelStr,
- const char * nameStr,
- long option,
- wWinCallBack_p winProc,
- void * data )
-{
- wWin_p w;
- DWORD style;
- HMENU sysMenu;
- int showCmd;
- static DWORD overlapped = WS_OVERLAPPED;
- static DWORD popup = WS_POPUP;
-
- style = popup;
- style |= WS_BORDER | WS_CAPTION | WS_SYSMENU;
- w = winCommonCreate( parent?parent->hWnd:mswHWnd, W_POPUP, option,
- "MswPopUpWindow",
- style, labelStr, winProc, x, y, data, nameStr, &showCmd );
-
- w->helpStr = mswStrdup( helpStr );
-
- sysMenu = GetSystemMenu( w->hWnd, FALSE );
- if (sysMenu) {
- DeleteMenu( sysMenu, SC_RESTORE, MF_BYCOMMAND );
- /*DeleteMenu( sysMenu, SC_MOVE, MF_BYCOMMAND );*/
- /*DeleteMenu( sysMenu, SC_SIZE, MF_BYCOMMAND );*/
- DeleteMenu( sysMenu, SC_MINIMIZE, MF_BYCOMMAND );
- DeleteMenu( sysMenu, SC_MAXIMIZE, MF_BYCOMMAND );
- DeleteMenu( sysMenu, SC_TASKLIST, MF_BYCOMMAND );
- DeleteMenu( sysMenu, 4, MF_BYPOSITION );
- }
- w->busy = FALSE;
- return w;
+ wWin_p parent,
+ POS_T x,
+ POS_T y,
+ const char * helpStr,
+ const char * labelStr,
+ const char * nameStr,
+ long option,
+ wWinCallBack_p winProc,
+ void * data)
+{
+ wWin_p w;
+ DWORD style;
+ HMENU sysMenu;
+ int showCmd;
+ static DWORD popup = WS_POPUP;
+ style = popup;
+ style |= WS_BORDER | WS_CAPTION | WS_SYSMENU;
+ w = winCommonCreate(parent?parent->hWnd:mswHWnd, W_POPUP, option,
+ "MswPopUpWindow",
+ style, labelStr, winProc, x, y, data, nameStr, &showCmd);
+ w->helpStr = mswStrdup(helpStr);
+ sysMenu = GetSystemMenu(w->hWnd, FALSE);
+
+ if (sysMenu) {
+ DeleteMenu(sysMenu, SC_RESTORE, MF_BYCOMMAND);
+ /*DeleteMenu( sysMenu, SC_MOVE, MF_BYCOMMAND );*/
+ /*DeleteMenu( sysMenu, SC_SIZE, MF_BYCOMMAND );*/
+ DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
+ DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
+ DeleteMenu(sysMenu, SC_TASKLIST, MF_BYCOMMAND);
+ DeleteMenu(sysMenu, 4, MF_BYPOSITION);
+ }
+
+ w->busy = FALSE;
+ return w;
}
void wWinSetBigIcon(
- wWin_p win,
- wIcon_p bm )
+ wWin_p win,
+ wIcon_p bm)
{
#ifdef OWNERICON
- win->wicon_w = bm->w;
- win->wicon_h = bm->h;
- win->wicon_bm = mswCreateBitMap(
- GetSysColor(COLOR_BTNTEXT), RGB( 255, 255, 255 ), RGB( 255, 255, 255 ),
- bm->w, bm->h, bm->bits );
+ win->wicon_w = bm->w;
+ win->wicon_h = bm->h;
+ win->wicon_bm = mswCreateBitMap(
+ GetSysColor(COLOR_BTNTEXT), RGB(255, 255, 255), RGB(255, 255, 255),
+ bm->w, bm->h, bm->bits);
#endif
}
void wWinSetSmallIcon(
- wWin_p win,
- wIcon_p bm )
+ wWin_p win,
+ wIcon_p bm)
{
#ifdef OWNERICON
- win->wicon_w = bm->w;
- win->wicon_h = bm->h;
- win->wicon_bm = mswCreateBitMap(
- GetSysColor(COLOR_BTNTEXT), RGB( 255, 255, 255 ), RGB( 255, 255, 255 ),
- bm->w, bm->h, bm->bits );
+ win->wicon_w = bm->w;
+ win->wicon_h = bm->h;
+ win->wicon_bm = mswCreateBitMap(
+ GetSysColor(COLOR_BTNTEXT), RGB(255, 255, 255), RGB(255, 255, 255),
+ bm->w, bm->h, bm->bits);
#endif
}
void wWinTop(
- wWin_p win )
-{
- /*BringWindowToTop( win->hWnd );*/
- SetWindowPos( win->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
- SetFocus( win->hWnd );
-}
-
-
-DWORD mswGetBaseStyle( wWin_p win )
-{
- DWORD style;
- style = win->baseStyle;
- win->baseStyle = 0;
- return style;
-}
-
-
-static wAccelKey_e translateExtKey( UINT wParam )
-{
- wAccelKey_e extChar;
- extChar = wAccelKey_None;
- 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;
- }
- return extChar;
+ wWin_p win)
+{
+ /*BringWindowToTop( win->hWnd );*/
+ SetWindowPos(win->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
+ SetFocus(win->hWnd);
+}
+
+
+DWORD mswGetBaseStyle(wWin_p win)
+{
+ DWORD style;
+ style = win->baseStyle;
+ win->baseStyle = 0;
+ return style;
+}
+
+
+static wAccelKey_e translateExtKey(UINT wParam)
+{
+ wAccelKey_e extChar;
+ extChar = wAccelKey_None;
+
+ 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;
+ }
+
+ return extChar;
}
long notModKey;
int mswTranslateAccelerator(
- HWND hWnd,
- LPMSG pMsg )
-{
- long acclKey;
- long state;
- wWin_p win;
- wControl_p b;
-
- if ( pMsg->message != WM_KEYDOWN )
- return FALSE;
- acclKey = pMsg->wParam;
- b = getControlFromCursor( pMsg->hwnd, &win );
- if ( win == NULL )
- return 0;
- if ( b != NULL ) {
- switch (b->type) {
- case B_STRING:
- case B_INTEGER:
- case B_FLOAT:
- case B_LIST:
- case B_DROPLIST:
- case B_COMBOLIST:
- case B_TEXT:
- return 0;
- }
- }
- if ( acclKey == (long)VK_F1 ) {
- closeBalloonHelp();
- if (!b && win) {
- wHelp( win->helpStr );
- } else {
- if (b->helpStr)
- wHelp( b->helpStr );
- else if (b->parent)
- wHelp( b->parent->nameStr );
- }
- return 1;
- }
- /*acclKey = translateExtKey( (WORD)acclKey );*/
- state = 0;
- if ( GetKeyState(VK_CONTROL) & 0x1000 )
- state |= WKEY_CTRL;
- if ( GetKeyState(VK_MENU) & 0x1000 )
- state |= WKEY_ALT;
- if ( GetKeyState(VK_SHIFT) & 0x1000 )
- state |= WKEY_SHIFT;
- state <<= 8;
- acclKey |= state;
- if (pMsg->wParam > 0x12)
- notModKey = TRUE;
- return mswMenuAccelerator( win, acclKey );
+ HWND hWnd,
+ LPMSG pMsg)
+{
+ long acclKey;
+ long state;
+ wWin_p win;
+ wControl_p b;
+
+ if (pMsg->message != WM_KEYDOWN) {
+ return FALSE;
+ }
+
+ acclKey = pMsg->wParam;
+ b = getControlFromCursor(pMsg->hwnd, &win);
+
+ if (win == NULL) {
+ return 0;
+ }
+
+ if (b != NULL) {
+ switch (b->type) {
+ case B_STRING:
+ case B_INTEGER:
+ case B_FLOAT:
+ case B_LIST:
+ case B_DROPLIST:
+ case B_COMBOLIST:
+ case B_TEXT:
+ return 0;
+ }
+ }
+
+ if (acclKey == (long)VK_F1) {
+ closeBalloonHelp();
+
+ if (!b && win) {
+ wHelp(win->helpStr);
+ } else {
+ if (b->helpStr) {
+ wHelp(b->helpStr);
+ } else if (b->parent) {
+ wHelp(b->parent->nameStr);
+ }
+ }
+
+ return 1;
+ }
+
+ /*acclKey = translateExtKey( (WORD)acclKey );*/
+ state = 0;
+
+ if (GetKeyState(VK_CONTROL) & 0x1000) {
+ state |= WKEY_CTRL;
+ }
+
+ if (GetKeyState(VK_MENU) & 0x1000) {
+ state |= WKEY_ALT;
+ }
+
+ if (GetKeyState(VK_SHIFT) & 0x1000) {
+ state |= WKEY_SHIFT;
+ }
+
+ state <<= 8;
+ acclKey |= state;
+
+ if (pMsg->wParam > 0x12) {
+ notModKey = TRUE;
+ }
+
+ return mswMenuAccelerator(win, acclKey);
}
/*
@@ -938,272 +1106,320 @@ int mswTranslateAccelerator(
-void wGetDisplaySize( POS_T * width, POS_T * height )
+void wGetDisplaySize(POS_T * width, POS_T * height)
{
- *width = screenWidth;
- *height = screenHeight;
+ *width = screenWidth;
+ *height = screenHeight;
}
-void wWinGetSize( wWin_p w, POS_T * width, POS_T * height )
+void wWinGetSize(wWin_p w, POS_T * width, POS_T * height)
{
- RECT rect;
- GetWindowRect( w->hWnd, &rect );
- GetClientRect( w->hWnd, &rect );
- w->w = rect.right - rect.left;
- w->h = rect.bottom - rect.top;
- *width = w->w;
- *height = w->h;
+ RECT rect;
+ GetWindowRect(w->hWnd, &rect);
+ GetClientRect(w->hWnd, &rect);
+ w->w = rect.right - rect.left;
+ w->h = rect.bottom - rect.top;
+ *width = w->w;
+ *height = w->h;
}
-void wWinSetSize( wWin_p w, POS_T width, POS_T height )
+void wWinSetSize(wWin_p w, POS_T width, POS_T height)
{
- RECT rect;
- w->w = width;
- w->h = height;
- rect.left = 0;
- rect.top = 0;
- rect.right = w->w /*+w->padX*/;
- rect.bottom = w->h /*+w->padY*/;
- AdjustWindowRect( &rect, w->style, (w->option&F_MENUBAR)?1:0 );
- rect.bottom += mFixBorderH;
- if (!SetWindowPos( w->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
- rect.right-rect.left, rect.bottom-rect.top,
- SWP_NOMOVE|SWP_NOZORDER))
- mswFail("wWinSetSize");
- InvalidateRect( w->hWnd, NULL, TRUE );
+ RECT rect;
+ w->w = width;
+ w->h = height;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = w->w /*+w->padX*/;
+ rect.bottom = w->h /*+w->padY*/;
+ AdjustWindowRect(&rect, w->style, (w->option&F_MENUBAR)?1:0);
+ rect.bottom += mFixBorderH;
+
+ if (!SetWindowPos(w->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT,
+ rect.right-rect.left, rect.bottom-rect.top,
+ SWP_NOMOVE|SWP_NOZORDER)) {
+ mswFail("wWinSetSize");
+ }
+
+ InvalidateRect(w->hWnd, NULL, TRUE);
}
static int blocking;
-static void blockingLoop( void )
+static void blockingLoop(void)
{
- MSG msg;
- int myBlocking=blocking;
- while (blocking>=myBlocking && GetMessage( &msg, NULL, 0, 0 )) {
- if (
+ MSG msg;
+ int myBlocking=blocking;
+
+ while (blocking>=myBlocking && GetMessage(&msg, NULL, 0, 0)) {
+ if (
#ifdef DOTRANSACCEL
- (!TranslateAccelerator( mswWin->hWnd, hMswAccel, &msg )) &&
+ (!TranslateAccelerator(mswWin->hWnd, hMswAccel, &msg)) &&
#endif
- (!mswTranslateAccelerator( mswWin->hWnd, &msg )) ) {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
- }
+ (!mswTranslateAccelerator(mswWin->hWnd, &msg))) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
}
-static void savePos( wWin_p win )
-{
- char posStr[20];
- WINDOWPLACEMENT windowPlace;
- wPos_t w, h;
- RECT rect;
-
- if ( win->nameStr &&
- IsWindowVisible( win->hWnd) /*&& !IsIconic( win->hWnd )*/ ) {
- windowPlace.length = sizeof windowPlace;
- GetWindowPlacement( win->hWnd, &windowPlace );
- if (win->option&F_RECALLPOS) {
- wsprintf( posStr, "%d %d",
- windowPlace.rcNormalPosition.left,
- windowPlace.rcNormalPosition.top );
- wPrefSetString( "msw window pos", win->nameStr, posStr );
- if (win->option&F_RESIZE) {
- GetClientRect( win->hWnd, &rect );
- w = rect.right - rect.left;
- h = rect.bottom - rect.top;
- 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;
- wsprintf( posStr, "%d %d %d",
- ( windowPlace.showCmd == SW_SHOWMINIMIZED ? 1 :
- (windowPlace.showCmd == SW_SHOWMAXIMIZED ? 2 : 0 ) ),
- w, h );
- wPrefSetString( "msw window size", win->nameStr, posStr );
- }
- }
- }
+static void savePos(wWin_p win)
+{
+ WINDOWPLACEMENT windowPlace;
+ wPos_t w, h;
+ RECT rect;
+
+ if (win->nameStr &&
+ IsWindowVisible(win->hWnd) /*&& !IsIconic( win->hWnd )*/) {
+ windowPlace.length = sizeof windowPlace;
+ GetWindowPlacement(win->hWnd, &windowPlace);
+
+ if (win->option&F_RECALLPOS) {
+ char posStr[20];
+ wsprintf(posStr, "%d %d",
+ windowPlace.rcNormalPosition.left,
+ windowPlace.rcNormalPosition.top);
+ wPrefSetString("msw window pos", win->nameStr, posStr);
+
+ 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;
+ }
+
+ wsprintf(posStr, "%d %d %d",
+ 0, // unused
+ w, h);
+ wPrefSetString("msw window size", win->nameStr, posStr);
+ }
+ }
+ }
}
void wWinShow(
- wWin_p win,
- BOOL_T show )
-{
- wPos_t x, y;
- wWin_p win1;
-
- win->busy = TRUE;
- if (show) {
- if (win->centerWin) {
- x = (screenWidth-win->w)/2;
- y = (screenHeight-win->h)/2;
- if (x<0)
- y = 0;
- if (x<0)
- y = 0;
- if (!SetWindowPos( win->hWnd, HWND_TOP, x, y,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER))
- mswFail( "wWinShow:SetWindowPos()" );
- }
- win->centerWin = FALSE;
- win->shown = TRUE;
- if (mswHWnd == (HWND)0 || !IsIconic(mswHWnd) ) {
- ShowWindow( win->hWnd, SW_SHOW );
- if (win->focusChainFirst) {
- SetFocus( win->focusChainFirst->hWnd );
- }
- win->pendingShow = FALSE;
- if ( mswWinBlockEnabled && (win->option & F_BLOCK) ) {
- blocking++;
- inMainWndProc = FALSE;
- for ( win1 = winFirst; win1; win1=(wWin_p)win1->next ) {
- if ( win1->shown && win1 != win ) {
- if (win1->modalLevel == 0 )
- EnableWindow( win1->hWnd, FALSE );
- win1->modalLevel++;
- }
- }
- win->busy = FALSE;
- blockingLoop();
- }
- } else {
- win->pendingShow = TRUE;
- needToDoPendingShow = TRUE;
- }
- } else {
- savePos( win );
- ShowWindow( win->hWnd, SW_HIDE );
- /*SetWindowPos( win->hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW );*/
- if ( mswWinBlockEnabled && (win->option & F_BLOCK) ) {
- blocking--;
- for ( win1 = winFirst; win1; win1=(wWin_p)win1->next ) {
- if ( win1->shown && win1 != win ) {
- if ( win1->modalLevel > 0 )
- win1->modalLevel--;
- if (win1->modalLevel == 0 )
- EnableWindow( win1->hWnd, TRUE );
- }
- }
- }
- savePos( win );
- win->pendingShow = FALSE;
- win->shown = FALSE;
- }
- win->busy = FALSE;
+ wWin_p win,
+ BOOL_T show)
+{
+ wPos_t x, y;
+ wWin_p win1;
+ win->busy = TRUE;
+
+ if (show) {
+ if (win->centerWin) {
+ x = (screenWidth-win->w)/2;
+ y = (screenHeight-win->h)/2;
+
+ if (x<0) {
+ y = 0;
+ }
+
+ if (x<0) {
+ y = 0;
+ }
+
+ if (!SetWindowPos(win->hWnd, HWND_TOP, x, y,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER)) {
+ mswFail("wWinShow:SetWindowPos()");
+ }
+ }
+
+ win->centerWin = FALSE;
+ win->shown = TRUE;
+
+ if (mswHWnd == (HWND)0 || !IsIconic(mswHWnd)) {
+ ShowWindow(win->hWnd, SW_SHOW);
+
+ if (win->focusChainFirst) {
+ SetFocus(win->focusChainFirst->hWnd);
+ }
+
+ win->pendingShow = FALSE;
+
+ if (mswWinBlockEnabled && (win->option & F_BLOCK)) {
+ blocking++;
+ inMainWndProc = FALSE;
+
+ for (win1 = winFirst; win1; win1=(wWin_p)win1->next) {
+ if (win1->shown && win1 != win) {
+ if (win1->modalLevel == 0) {
+ EnableWindow(win1->hWnd, FALSE);
+ }
+
+ win1->modalLevel++;
+ }
+ }
+
+ win->busy = FALSE;
+ blockingLoop();
+ }
+ } else {
+ win->pendingShow = TRUE;
+ needToDoPendingShow = TRUE;
+ }
+ } else {
+ savePos(win);
+ ShowWindow(win->hWnd, SW_HIDE);
+
+ /*SetWindowPos( win->hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW );*/
+ if (mswWinBlockEnabled && (win->option & F_BLOCK)) {
+ blocking--;
+
+ for (win1 = winFirst; win1; win1=(wWin_p)win1->next) {
+ if (win1->shown && win1 != win) {
+ if (win1->modalLevel > 0) {
+ win1->modalLevel--;
+ }
+
+ if (win1->modalLevel == 0) {
+ EnableWindow(win1->hWnd, TRUE);
+ }
+ }
+ }
+ }
+
+ savePos(win);
+ win->pendingShow = FALSE;
+ win->shown = FALSE;
+ }
+
+ win->busy = FALSE;
}
void wWinBlockEnable(
- wBool_t enabled )
+ wBool_t enabled)
{
- mswWinBlockEnabled = enabled;
+ mswWinBlockEnabled = enabled;
}
wBool_t wWinIsVisible(
- wWin_p w )
+ wWin_p w)
{
- return IsWindowVisible(w->hWnd);
+ return IsWindowVisible(w->hWnd);
}
+/**
+* Returns whether the window is maximized.
+*
+* \param win IN window
+* \return TRUE if maximized, FALSE otherwise
+*/
+
+wBool_t wWinIsMaximized(wWin_p w)
+{
+ return (IsZoomed(w->hWnd));
+}
void wWinSetTitle(
- wWin_p w,
- const char * title )
+ wWin_p w,
+ const char * title)
{
- SetWindowText( w->hWnd, title );
+ SetWindowText(w->hWnd, title);
}
void wWinSetBusy(
- wWin_p w,
- BOOL_T busy )
-{
- HMENU menuH;
- UINT uEnable;
- int cnt, inx;
- wControl_p b;
-
- w->isBusy = busy;
- menuH = GetMenu( w->hWnd );
- if (menuH) {
- uEnable = MF_BYPOSITION|(busy?MF_DISABLED:MF_ENABLED);
- cnt = GetMenuItemCount(menuH);
- for (inx=0; inx<cnt; inx++)
- EnableMenuItem( menuH, inx, uEnable );
- }
- for (b=w->first; b; b=b->next) {
- if ( (b->option&BO_DISABLED)==0) {
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->setBusyProc) {
- mswCallBacks[b->type]->setBusyProc( b, busy );
- } else {
- if (b->hWnd)
- EnableWindow( b->hWnd, (BOOL)!busy );
- }
- }
- }
+ wWin_p w,
+ BOOL_T busy)
+{
+ HMENU menuH;
+ UINT uEnable;
+ wControl_p b;
+ w->isBusy = busy;
+ menuH = GetMenu(w->hWnd);
+
+ if (menuH) {
+ int cnt, inx;
+ uEnable = MF_BYPOSITION|(busy?MF_DISABLED:MF_ENABLED);
+ cnt = GetMenuItemCount(menuH);
+
+ for (inx=0; inx<cnt; inx++) {
+ EnableMenuItem(menuH, inx, uEnable);
+ }
+ }
+
+ for (b=w->first; b; b=b->next) {
+ if ((b->option&BO_DISABLED)==0) {
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->setBusyProc) {
+ mswCallBacks[b->type]->setBusyProc(b, busy);
+ } else {
+ if (b->hWnd) {
+ EnableWindow(b->hWnd, (BOOL)!busy);
+ }
+ }
+ }
+ }
}
const char * wWinGetTitle(
- wWin_p w )
+ wWin_p w)
{
- return w->labelStr;
+ return w->labelStr;
}
void wWinClear(
- wWin_p win,
- wPos_t x,
- wPos_t y,
- wPos_t width,
- wPos_t height )
+ wWin_p win,
+ wPos_t x,
+ wPos_t y,
+ wPos_t width,
+ wPos_t height)
{
}
void wSetCursor(
- wCursor_t cursor )
-{
- switch ( cursor ) {
- case wCursorNormal:
- case wCursorQuestion:
- 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;
- }
- curCursor = cursor;
+ wCursor_t cursor)
+{
+ switch (cursor) {
+ case wCursorNormal:
+ case wCursorQuestion:
+ 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;
+ }
+
+ curCursor = cursor;
}
-void wWinDoCancel( wWin_p win )
+void wWinDoCancel(wWin_p win)
{
- wControl_p b;
- for (b=win->first; b; b=b->next) {
- if ((b->type == B_BUTTON) && (b->option & BB_CANCEL) ) {
- mswButtPush( b );
- }
- }
+ wControl_p b;
+
+ for (b=win->first; b; b=b->next) {
+ if ((b->type == B_BUTTON) && (b->option & BB_CANCEL)) {
+ mswButtPush(b);
+ }
+ }
}
-unsigned long wGetTimer( void )
+unsigned long wGetTimer(void)
{
- return (unsigned long)GetTickCount();
+ return (unsigned long)GetTickCount();
}
@@ -1218,35 +1434,40 @@ unsigned long wGetTimer( void )
void wControlSetHelp(
- wControl_p b,
- const char * help )
+ wControl_p b,
+ const char * help)
{
- if (b->helpStr)
- free(CAST_AWAY_CONST b->helpStr);
- if (help)
- b->helpStr = mswStrdup( help );
- else
- b->helpStr = NULL;
+ if (b->helpStr) {
+ free(CAST_AWAY_CONST b->helpStr);
+ }
+
+ if (help) {
+ b->helpStr = mswStrdup(help);
+ } else {
+ b->helpStr = NULL;
+ }
}
/**
- * Add control to circular list of synonymous controls. Synonymous controls are kept in sync by
- * calling wControlLinkedActive for one member of the list
+ * Add control to circular list of synonymous controls. Synonymous controls are kept in sync by
+ * calling wControlLinkedActive for one member of the list
*
* \param IN first control
* \param IN second control
* \return none
*/
-
-void wControlLinkedSet( wControl_p b1, wControl_p b2 )
+
+void wControlLinkedSet(wControl_p b1, wControl_p b2)
{
- b2->synonym = b1->synonym;
- if( b2->synonym == NULL )
- b2->synonym = b1;
-
- b1->synonym = b2;
-}
+ b2->synonym = b1->synonym;
+
+ if (b2->synonym == NULL) {
+ b2->synonym = b1;
+ }
+
+ b1->synonym = b2;
+}
/**
* Activate/deactivate a group of synonymous controls.
@@ -1255,340 +1476,379 @@ void wControlLinkedSet( wControl_p b1, wControl_p b2 )
* \param IN state
* \return none
*/
-
-void wControlLinkedActive( wControl_p b, int active )
-{
- wControl_p savePtr = b;
-
- if( savePtr->type == B_MENUITEM )
- wMenuPushEnable( (wMenuPush_p)savePtr, active );
- else
- wControlActive( savePtr, active );
-
- savePtr = savePtr->synonym;
- while( savePtr && savePtr != b ) {
-
- if( savePtr->type == B_MENUITEM )
- wMenuPushEnable( (wMenuPush_p)savePtr, active );
- else
- wControlActive( savePtr, active );
+void wControlLinkedActive(wControl_p b, int active)
+{
+ wControl_p savePtr = b;
+
+ if (savePtr->type == B_MENUITEM) {
+ wMenuPushEnable((wMenuPush_p)savePtr, active);
+ } else {
+ wControlActive(savePtr, active);
+ }
+
+ savePtr = savePtr->synonym;
+
+ while (savePtr && savePtr != b) {
+ if (savePtr->type == B_MENUITEM) {
+ wMenuPushEnable((wMenuPush_p)savePtr, active);
+ } else {
+ wControlActive(savePtr, active);
+ }
+
+ savePtr = savePtr->synonym;
+ }
+}
+
+void wControlShow(wControl_p b, BOOL_T show)
+{
+ RECT rc;
+
+ if (show) {
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->repaintProc) {
+ mswCallBacks[b->type]->repaintProc(b->parent->hWnd, b);
+ }
+ } else {
+ if (b->labelStr) {
+ rc.left = b->labelX;
+ rc.right = b->x;
+ rc.top = b->labelY;
+ rc.bottom = b->labelY+b->h;
+ InvalidateRect(((wControl_p)b->parent)->hWnd, &rc, TRUE);
+ }
+ }
+
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->showProc) {
+ mswCallBacks[b->type]->showProc(b, show);
+ } else {
+ ShowWindow(b->hWnd, show?SW_SHOW:SW_HIDE);
+#ifdef SHOW_DOES_SETFOCUS
- savePtr = savePtr->synonym;
- }
-}
+ if (show && (b->option&BO_READONLY)==0 && b->hWnd != GetFocus()) {
+ hWnd = SetFocus(b->hWnd);
+ }
-void wControlShow( wControl_p b, BOOL_T show )
-{
- RECT rc;
- if (show) {
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->repaintProc)
- mswCallBacks[b->type]->repaintProc( b->parent->hWnd, b );
- } else {
- if( b->labelStr ) {
- rc.left = b->labelX;
- rc.right = b->x;
- rc.top = b->labelY;
- rc.bottom = b->labelY+b->h;
- InvalidateRect( ((wControl_p)b->parent)->hWnd, &rc, TRUE );
- }
- }
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->showProc) {
- mswCallBacks[b->type]->showProc( b, show );
- } else {
- ShowWindow( b->hWnd, show?SW_SHOW:SW_HIDE );
-#ifdef SHOW_DOES_SETFOCUS
- if (show && (b->option&BO_READONLY)==0 && b->hWnd != GetFocus() ) {
- hWnd = SetFocus( b->hWnd );
- }
#endif
- }
- b->shown = show;
+ }
+
+ b->shown = show;
}
void wControlSetFocus(
- wControl_p b )
+ wControl_p b)
{
- if ( b->hWnd )
- SetFocus( b->hWnd );
+ if (b->hWnd) {
+ SetFocus(b->hWnd);
+ }
}
void wControlActive(
- wControl_p b,
- int active )
-{
- if (active)
- b->option &= ~BO_DISABLED;
- else
- b->option |= BO_DISABLED;
- if (b->parent->isBusy)
- return;
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->setBusyProc) {
- mswCallBacks[b->type]->setBusyProc( b, !active );
- } else {
- EnableWindow( b->hWnd, (BOOL)active );
- InvalidateRect( b->hWnd, NULL, TRUE );
- }
+ wControl_p b,
+ int active)
+{
+ if (active) {
+ b->option &= ~BO_DISABLED;
+ } else {
+ b->option |= BO_DISABLED;
+ }
+
+ if (b->parent->isBusy) {
+ return;
+ }
+
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->setBusyProc) {
+ mswCallBacks[b->type]->setBusyProc(b, !active);
+ } else {
+ EnableWindow(b->hWnd, (BOOL)active);
+ InvalidateRect(b->hWnd, NULL, TRUE);
+ }
}
-const char * wControlGetHelp( wControl_p b )
+const char * wControlGetHelp(wControl_p b)
{
- return b->helpStr;
+ return b->helpStr;
}
-wPos_t wLabelWidth( const char * labelStr )
+wPos_t wLabelWidth(const char * labelStr)
{
- int lab_l;
- HDC hDc;
- DWORD dw;
- LABELFONTDECL
-
- hDc = GetDC( mswHWnd );
- lab_l = strlen(labelStr);
- LABELFONTSELECT
- dw = GetTextExtent( hDc, CAST_AWAY_CONST labelStr, lab_l );
- LABELFONTRESET
- ReleaseDC( mswHWnd, hDc );
- return LOWORD(dw) + 5;
+ int lab_l;
+ HDC hDc;
+ DWORD dw;
+ LABELFONTDECL
+ hDc = GetDC(mswHWnd);
+ lab_l = strlen(labelStr);
+ LABELFONTSELECT
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l);
+ LABELFONTRESET
+ ReleaseDC(mswHWnd, hDc);
+ return LOWORD(dw) + 5;
}
wPos_t wControlGetWidth(
- wControl_p b) /* Control */
+ wControl_p b) /* Control */
{
- return b->w;
+ return b->w;
}
wPos_t wControlGetHeight(
- wControl_p b) /* Control */
+ wControl_p b) /* Control */
{
- return b->h;
+ return b->h;
}
wPos_t wControlGetPosX(
- wControl_p b) /* Control */
+ wControl_p b) /* Control */
{
- return b->x;
+ return b->x;
}
wPos_t wControlGetPosY(
- wControl_p b) /* Control */
+ wControl_p b) /* Control */
{
- return b->y;
+ return b->y;
}
void wControlSetPos(
- wControl_p b,
- wPos_t x,
- wPos_t y )
-{
- b->labelX = x;
- b->labelY = y+2;
-
- if (b->labelStr) {
- int 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 );
- b->labelX -= LOWORD(dw) + 5;
- LABELFONTRESET
- ReleaseDC( b->parent->hWnd, hDc );
- }
-
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->setPosProc) {
- mswCallBacks[b->type]->setPosProc( b, x, y );
- } else {
- b->x = x;
- b->y = y;
- if (b->hWnd)
- if (!SetWindowPos( b->hWnd, HWND_TOP, x, y,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER))
- mswFail("wControlSetPos");
- }
+ wControl_p b,
+ wPos_t x,
+ wPos_t y)
+{
+ b->labelX = x;
+ b->labelY = y+2;
+
+ if (b->labelStr) {
+ int 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);
+ b->labelX -= LOWORD(dw) + 5;
+ LABELFONTRESET
+ ReleaseDC(b->parent->hWnd, hDc);
+ }
+
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->setPosProc) {
+ mswCallBacks[b->type]->setPosProc(b, x, y);
+ } else {
+ b->x = x;
+ b->y = y;
+
+ if (b->hWnd)
+ if (!SetWindowPos(b->hWnd, HWND_TOP, x, y,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER)) {
+ mswFail("wControlSetPos");
+ }
+ }
}
void wControlSetLabel(
- wControl_p b,
- const char * labelStr )
-{
- if ( b->type == B_RADIO || b->type == B_TOGGLE ) {
- ;
- } else {
- int 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 );
- LABELFONTRESET
- b->labelX = b->x - LOWORD(dw) - 5;
- ReleaseDC( b->parent->hWnd, hDc );
- b->labelStr = mswStrdup( labelStr );
- if (b->type == B_BUTTON)
- SetWindowText( b->hWnd, labelStr );
- }
+ wControl_p b,
+ const char * labelStr)
+{
+ if (b->type == B_RADIO || b->type == B_TOGGLE) {
+ ;
+ } else {
+ int 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);
+ LABELFONTRESET
+ b->labelX = b->x - LOWORD(dw) - 5;
+ ReleaseDC(b->parent->hWnd, hDc);
+ b->labelStr = mswStrdup(labelStr);
+
+ if (b->type == B_BUTTON) {
+ SetWindowText(b->hWnd, labelStr);
+ }
+ }
}
void wControlSetContext(
- wControl_p b,
- void * context )
+ wControl_p b,
+ void * context)
{
- b->data = context;
+ b->data = context;
}
static int controlHiliteWidth = 5;
static int controlHiliteWidth2 = 3;
void wControlHilite(
- wControl_p b,
- wBool_t hilite )
-{
- HDC hDc;
- HPEN oldPen, newPen;
- int oldMode;
-
- if ( b == NULL ) return;
- if ( !IsWindowVisible(b->parent->hWnd) ) return;
- if ( !IsWindowVisible(b->hWnd) ) return;
- hDc = GetDC( b->parent->hWnd );
- newPen = CreatePen( PS_SOLID, controlHiliteWidth, RGB(0,0,0) );
- oldPen = SelectObject( hDc, newPen );
- oldMode = SetROP2( hDc, R2_NOTXORPEN );
- MoveTo( hDc, b->x-controlHiliteWidth2, b->y-controlHiliteWidth2 );
- LineTo( hDc, b->x+b->w+controlHiliteWidth2, b->y-controlHiliteWidth2 );
- LineTo( hDc, b->x+b->w+controlHiliteWidth2, b->y+b->h+controlHiliteWidth2 );
- LineTo( hDc, b->x-controlHiliteWidth2, b->y+b->h+controlHiliteWidth2 );
- LineTo( hDc, b->x-controlHiliteWidth2, b->y-controlHiliteWidth2 );
- SetROP2( hDc, oldMode );
- SelectObject( hDc, oldPen );
- DeleteObject( newPen );
- ReleaseDC( b->parent->hWnd, hDc );
+ wControl_p b,
+ wBool_t hilite)
+{
+ HDC hDc;
+ HPEN oldPen, newPen;
+ int oldMode;
+
+ if (b == NULL) {
+ return;
+ }
+
+ if (!IsWindowVisible(b->parent->hWnd)) {
+ return;
+ }
+
+ if (!IsWindowVisible(b->hWnd)) {
+ return;
+ }
+
+ hDc = GetDC(b->parent->hWnd);
+ newPen = CreatePen(PS_SOLID, controlHiliteWidth, RGB(0,0,0));
+ oldPen = SelectObject(hDc, newPen);
+ oldMode = SetROP2(hDc, R2_NOTXORPEN);
+ MoveTo(hDc, b->x-controlHiliteWidth2, b->y-controlHiliteWidth2);
+ LineTo(hDc, b->x+b->w+controlHiliteWidth2, b->y-controlHiliteWidth2);
+ LineTo(hDc, b->x+b->w+controlHiliteWidth2, b->y+b->h+controlHiliteWidth2);
+ LineTo(hDc, b->x-controlHiliteWidth2, b->y+b->h+controlHiliteWidth2);
+ LineTo(hDc, b->x-controlHiliteWidth2, b->y-controlHiliteWidth2);
+ SetROP2(hDc, oldMode);
+ SelectObject(hDc, oldPen);
+ DeleteObject(newPen);
+ ReleaseDC(b->parent->hWnd, hDc);
}
/*
*****************************************************************************
*
- * Exported Utility Functions
+ * Exported Utility Functions
*
*****************************************************************************
*/
void wMessage(
- wWin_p w,
- const char * msg,
- int beep )
-{
- HDC hDc;
- int oldRop;
- POS_T h;
- RECT rect;
- LABELFONTDECL
-
- if (beep)
- MessageBeep(0);
- GetClientRect( w->hWnd, &rect );
- hDc = GetDC( w->hWnd );
- oldRop = SetROP2( hDc, R2_WHITE );
- h = w->h+2;
- Rectangle( hDc, 0, h, w->w, h );
- SetROP2( hDc, oldRop );
- LABELFONTSELECT
- TextOut( hDc, 0, h, msg, strlen(msg) );
- LABELFONTRESET
- ReleaseDC( w->hWnd, hDc );
-}
-
-
-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;
- if (b != NULL) {
- if (b->type == W_MAIN || b->type == W_POPUP) {
- wWin_p w = (wWin_p)b;
- savePos( w );
- if (w->winProc != NULL)
- w->winProc( w, wQuit_e, w->data );
- }
- }
- }
- for ( inx=controlMap_da.cnt-1; inx>=0; inx-- ) {
- b = controlMap(inx).b;
- if (b != NULL) {
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->doneProc != NULL)
- mswCallBacks[b->type]->doneProc( b );
- }
- controlMap(inx).b = NULL;
- }
- deleteBitmaps();
- if (mswOldTextFont != (HFONT)0)
- DeleteObject( mswOldTextFont );
- if (helpInitted) {
- WinHelp(mswHWnd, helpFile, HELP_QUIT, 0L );
- helpInitted = FALSE;
- }
- if (balloonHelpHWnd) {
- HDC hDc;
- hDc = GetDC( balloonHelpHWnd );
- SelectObject( hDc, balloonHelpOldFont );
- DeleteObject( balloonHelpNewFont );
- ReleaseDC( balloonHelpHWnd, hDc );
- }
+ wWin_p w,
+ const char * msg,
+ int beep)
+{
+ HDC hDc;
+ int oldRop;
+ POS_T h;
+ RECT rect;
+ LABELFONTDECL
+
+ if (beep) {
+ MessageBeep(0);
+ }
+
+ GetClientRect(w->hWnd, &rect);
+ hDc = GetDC(w->hWnd);
+ oldRop = SetROP2(hDc, R2_WHITE);
+ h = w->h+2;
+ Rectangle(hDc, 0, h, w->w, h);
+ SetROP2(hDc, oldRop);
+ LABELFONTSELECT
+ TextOut(hDc, 0, h, msg, strlen(msg));
+ LABELFONTRESET
+ ReleaseDC(w->hWnd, hDc);
+}
+
+
+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;
+
+ if (b != NULL) {
+ if (b->type == W_MAIN || b->type == W_POPUP) {
+ wWin_p w = (wWin_p)b;
+ savePos(w);
+
+ if (w->winProc != NULL) {
+ w->winProc(w, wQuit_e, w->data);
+ }
+ }
+ }
+ }
+
+ for (inx=controlMap_da.cnt-1; inx>=0; inx--) {
+ b = controlMap(inx).b;
+
+ if (b != NULL) {
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->doneProc != NULL) {
+ mswCallBacks[b->type]->doneProc(b);
+ }
+ }
+
+ controlMap(inx).b = NULL;
+ }
+
+ deleteBitmaps();
+
+ if (mswOldTextFont != (HFONT)0) {
+ DeleteObject(mswOldTextFont);
+ }
+
+ if (helpInitted) {
+ WinHelp(mswHWnd, helpFile, HELP_QUIT, 0L);
+ helpInitted = FALSE;
+ }
+
+ if (balloonHelpHWnd) {
+ HDC hDc;
+ hDc = GetDC(balloonHelpHWnd);
+ SelectObject(hDc, balloonHelpOldFont);
+ DeleteObject(balloonHelpNewFont);
+ ReleaseDC(balloonHelpHWnd, hDc);
+ }
+
#ifdef HELPSTR
- fclose( helpStrF );
+ fclose(helpStrF);
#endif
- DestroyWindow( mswHWnd );
- if (mswPalette) {
- DeleteObject( mswPalette );
- /*DeleteObject( mswPrintPalette );*/
- }
+ DestroyWindow(mswHWnd);
+
+ if (mswPalette) {
+ DeleteObject(mswPalette);
+ /*DeleteObject( mswPrintPalette );*/
+ }
}
void wFlush(
- void )
+ void)
{
- wWin_p win;
+ wWin_p win;
+ inMainWndProc = FALSE;
+ mswRepaintAll();
- inMainWndProc = FALSE;
- mswRepaintAll();
- for (win=winFirst; win; win=(wWin_p)win->next)
- UpdateWindow( win->hWnd );
+ for (win=winFirst; win; win=(wWin_p)win->next) {
+ UpdateWindow(win->hWnd);
+ }
}
void wUpdate(
- wWin_p win )
+ wWin_p win)
{
- UpdateWindow( win->hWnd );
+ UpdateWindow(win->hWnd);
}
static wBool_t paused;
@@ -1598,85 +1858,103 @@ static wControl_p triggerControl;
/**
* Wait until the pause timer expires. During that time, the message loop is
- * handled and queued messages are processed
+ * handled and queued messages are processed
*/
-static void pausedLoop( void )
+static void pausedLoop(void)
{
- MSG msg;
- while (paused && GetMessage( &msg, NULL, 0, 0 )) {
- if ( (mswWin) && (!mswTranslateAccelerator( mswWin->hWnd, &msg )) ) {
- TranslateMessage( &msg );
- }
- DispatchMessage( &msg );
- }
+ MSG msg;
+
+ while (paused && GetMessage(&msg, NULL, 0, 0)) {
+ if ((mswWin) && (!mswTranslateAccelerator(mswWin->hWnd, &msg))) {
+ TranslateMessage(&msg);
+ }
+
+ DispatchMessage(&msg);
+ }
}
/**
- * Timer callback function for the pause timer. The only purpose of this
+ * Timer callback function for the pause timer. The only purpose of this
* timer proc is to clear the waiting flag and kill the timer itself.
*/
-void CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
+void CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
- if (idEvent == PAUSE_TIMER) {
- paused = FALSE;
- KillTimer( hWnd, PAUSE_TIMER );
- }
+ if (idEvent == PAUSE_TIMER) {
+ paused = FALSE;
+ KillTimer(hWnd, PAUSE_TIMER);
+ }
}
/**
- * Pause the application for a specified time.
+ * Pause the application for a specified time.
*/
-void wPause( long msec )
+void wPause(long msec)
{
- paused = TRUE;
- if (msec > 65000L)
- msec = 65000L;
- pauseTimer = SetTimer( mswHWnd, PAUSE_TIMER, (UINT)msec, TimerProc );
- if (pauseTimer == 0)
- mswFail("wPause: No timers");
- else
- pausedLoop();
+ paused = TRUE;
+
+ if (msec > 65000L) {
+ msec = 65000L;
+ }
+
+ pauseTimer = SetTimer(mswHWnd, PAUSE_TIMER, (UINT)msec, TimerProc);
+
+ if (pauseTimer == 0) {
+ mswFail("wPause: No timers");
+ } else {
+ pausedLoop();
+ }
}
void wAlarm(
- long msec,
- wAlarmCallBack_p func )
+ long msec,
+ wAlarmCallBack_p func)
{
- alarmFunc = func;
- if (msec > 65000L)
- msec = 65000L;
- alarmTimer = SetTimer( mswHWnd, ALARM_TIMER, (UINT)msec, NULL );
- if (alarmTimer == 0)
- mswFail("wAlarm: No timers");
+ alarmFunc = func;
+
+ if (msec > 65000L) {
+ msec = 65000L;
+ }
+
+ alarmTimer = SetTimer(mswHWnd, ALARM_TIMER, (UINT)msec, NULL);
+
+ if (alarmTimer == 0) {
+ mswFail("wAlarm: No timers");
+ }
}
void mswSetTrigger(
- wControl_p control,
- setTriggerCallback_p func )
-{
- UINT msec = (UINT)500;
- triggerControl = control;
- triggerFunc = func;
- if (func == NULL && triggerTimer != 0) {
- KillTimer( mswHWnd, triggerTimer );
- triggerTimer = 0;
- return;
- }
- if (msec > 65000L)
- msec = 65000L;
- triggerTimer = SetTimer( mswHWnd, TRIGGER_TIMER, (UINT)msec, NULL );
- if (triggerTimer == 0)
- mswFail("wAlarm: No timers");
+ wControl_p control,
+ setTriggerCallback_p func)
+{
+ UINT msec = (UINT)500;
+ triggerControl = control;
+ triggerFunc = func;
+
+ if (func == NULL && triggerTimer != 0) {
+ KillTimer(mswHWnd, triggerTimer);
+ triggerTimer = 0;
+ return;
+ }
+
+ if (msec > 65000L) {
+ msec = 65000L;
+ }
+
+ triggerTimer = SetTimer(mswHWnd, TRIGGER_TIMER, (UINT)msec, NULL);
+
+ if (triggerTimer == 0) {
+ mswFail("wAlarm: No timers");
+ }
}
-void wBeep( void )
+void wBeep(void)
{
- MessageBeep( MB_OK );
+ MessageBeep(MB_OK);
}
/**
@@ -1690,41 +1968,46 @@ void wBeep( void )
*/
int wNoticeEx(
- int type,
- const char * msg,
- const char * yes,
- const char * no )
-{
- int res;
- UINT flag;
- char *headline;
-
- switch( type ) {
- case NT_INFORMATION:
- flag = MB_ICONINFORMATION;
- headline = _("Information");
- break;
- case NT_WARNING:
- flag = MB_ICONWARNING;
- headline = _("Warning");
- break;
- case NT_ERROR:
- flag = MB_ICONERROR;
- headline = _("Error");
- break;
- }
- res = MessageBox( mswHWnd, msg, headline, flag | MB_TASKMODAL|((no==NULL)?MB_OK:MB_YESNO) );
- return res == IDOK || res == IDYES;
+ int type,
+ const char * msg,
+ const char * yes,
+ const char * no)
+{
+ int res;
+ UINT flag;
+ char *headline;
+
+ switch (type) {
+ case NT_INFORMATION:
+ flag = MB_ICONINFORMATION;
+ headline = _("Information");
+ break;
+
+ case NT_WARNING:
+ flag = MB_ICONWARNING;
+ headline = _("Warning");
+ break;
+
+ case NT_ERROR:
+ flag = MB_ICONERROR;
+ headline = _("Error");
+ break;
+ }
+
+ res = MessageBox(mswHWnd, msg, headline,
+ flag | MB_TASKMODAL|((no==NULL)?MB_OK:MB_YESNO));
+ return res == IDOK || res == IDYES;
}
int wNotice(
- const char * msg,
- const char * yes,
- const char * no )
+ const char * msg,
+ const char * yes,
+ const char * no)
{
- int res;
- res = MessageBox( mswHWnd, msg, "Notice", MB_TASKMODAL|((no==NULL)?MB_OK:MB_YESNO) );
- return res == IDOK || res == IDYES;
+ int res;
+ res = MessageBox(mswHWnd, msg, "Notice",
+ MB_TASKMODAL|((no==NULL)?MB_OK:MB_YESNO));
+ return res == IDOK || res == IDYES;
}
/**
@@ -1739,235 +2022,279 @@ int wNotice(
int wNotice3(
- const char * msg,
- const char * yes,
- const char * no,
- const char * cancel )
+ const char * msg,
+ const char * yes,
+ const char * no,
+ const char * cancel)
{
- int res;
- res = MessageBox( mswHWnd, msg, _("Warning"), MB_ICONWARNING | MB_TASKMODAL|MB_YESNOCANCEL );
- if ( res == IDOK || res == IDYES )
- return 1;
- else if ( res == IDNO )
- return -1;
- else
- return 0;
+ int res;
+ res = MessageBox(mswHWnd, msg, _("Warning"),
+ MB_ICONWARNING | MB_TASKMODAL|MB_YESNOCANCEL);
+
+ if (res == IDOK || res == IDYES) {
+ return 1;
+ } else if (res == IDNO) {
+ return -1;
+ } else {
+ return 0;
+ }
}
void wHelp(
- const char * topic )
+ const char * topic)
{
- char *pszHelpTopic;
- HWND hwndHelp;
+ char *pszHelpTopic;
+ HWND hwndHelp;
- if (!helpInitted) {
- HtmlHelp( NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ;
- helpInitted = TRUE;
- }
-/* "c:\\help.chm::/intro.htm>mainwin", */
- /* attention: always adapt constant value (10) to needed number of formatting characters */
- pszHelpTopic = malloc( strlen( helpFile ) + strlen( topic ) + 10 );
- assert( pszHelpTopic != NULL );
+ if (!helpInitted) {
+ HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ;
+ helpInitted = TRUE;
+ }
+
+ /* "c:\\help.chm::/intro.htm>mainwin", */
+ /* attention: always adapt constant value (10) to needed number of formatting characters */
+ pszHelpTopic = malloc(strlen(helpFile) + strlen(topic) + 10);
+ assert(pszHelpTopic != NULL);
+ sprintf(pszHelpTopic, "/%s.html", topic);
+ hwndHelp = HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOPIC,
+ (DWORD_PTR)pszHelpTopic);
- sprintf( pszHelpTopic, "/%s.html", topic );
- hwndHelp = HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOPIC, (DWORD_PTR)pszHelpTopic);
- if( !hwndHelp )
- wNoticeEx( NT_ERROR, pszHelpTopic, "Ok", NULL );
+ if (!hwndHelp) {
+ wNoticeEx(NT_ERROR, pszHelpTopic, "Ok", NULL);
+ }
- free( pszHelpTopic );
+ free(pszHelpTopic);
}
-void doHelpMenu( void * context )
+void doHelpMenu(void * context)
{
- HH_FTS_QUERY ftsQuery;
-
- if( !helpInitted ) {
- HtmlHelp( NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ;
- helpInitted = TRUE;
- }
-
- switch ((int)(long)context) {
- case 1: /* Contents */
- HtmlHelp( mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL );
- break;
- case 2: /* Search */
- ftsQuery.cbStruct = sizeof( ftsQuery );
- ftsQuery.fExecute = FALSE;
- ftsQuery.fStemmedSearch = FALSE;
- ftsQuery.fTitleOnly = FALSE;
- ftsQuery.pszSearchQuery = NULL;
- ftsQuery.pszWindow = NULL;
-
- HtmlHelp( mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD)&ftsQuery );
- break;
- default:
- return;
- }
- helpInitted = TRUE;
+ HH_FTS_QUERY ftsQuery;
+
+ if (!helpInitted) {
+ HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ;
+ helpInitted = TRUE;
+ }
+
+ switch ((int)(long)context) {
+ case 1: /* Contents */
+ HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL);
+ break;
+
+ case 2: /* Search */
+ ftsQuery.cbStruct = sizeof(ftsQuery);
+ ftsQuery.fExecute = FALSE;
+ ftsQuery.fStemmedSearch = FALSE;
+ ftsQuery.fTitleOnly = FALSE;
+ ftsQuery.pszSearchQuery = NULL;
+ ftsQuery.pszWindow = NULL;
+ HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD)&ftsQuery);
+ break;
+
+ default:
+ return;
+ }
+
+ helpInitted = TRUE;
}
void wMenuAddHelp(
- wMenu_p m )
+ wMenu_p m)
{
- wMenuPushCreate( m, NULL, "&Contents", 0, doHelpMenu, (void*)1 );
- wMenuPushCreate( m, NULL, "&Search for Help on...", 0, doHelpMenu, (void*)2 );
+ wMenuPushCreate(m, NULL, "&Contents", 0, doHelpMenu, (void*)1);
+ wMenuPushCreate(m, NULL, "&Search for Help on...", 0, doHelpMenu, (void*)2);
}
-void wSetBalloonHelp( wBalloonHelp_t * bh )
+void wSetBalloonHelp(wBalloonHelp_t * bh)
{
- balloonHelpStrings = bh;
+ balloonHelpStrings = bh;
}
-void wEnableBalloonHelp( int enable )
+void wEnableBalloonHelp(int enable)
{
- balloonHelpEnable = enable;
+ balloonHelpEnable = enable;
}
-void wBalloonHelpUpdate ( void )
+void wBalloonHelpUpdate(void)
{
}
-void wControlSetBalloonText( wControl_p b, const char * text )
+void wControlSetBalloonText(wControl_p b, const char * text)
{
- b->tipStr = mswStrdup( text );
+ b->tipStr = mswStrdup(text);
}
-void startBalloonHelp( void )
+void startBalloonHelp(void)
{
- HDC hDc;
- DWORD extent;
- int w, h;
- RECT rect;
- POINT pt;
- wBalloonHelp_t * bh;
- const char * hs;
- HFONT hFont;
+ HDC hDc;
+ DWORD extent;
+ RECT rect;
+ POINT pt;
+ wBalloonHelp_t * bh;
+ const char * hs;
+ HFONT hFont;
- if (!balloonHelpStrings)
- return;
- if (!balloonHelpEnable)
- return;
- if (balloonHelpHWnd) {
- if ( balloonHelpButton->tipStr ) {
- hs = balloonHelpButton->tipStr;
- } else {
- hs = balloonHelpButton->helpStr;
- if (!hs)
- return;
- for ( bh = balloonHelpStrings; bh->name && strcmp(bh->name,hs) != 0; bh++ );
- if (!bh->name || !bh->value)
- return;
- balloonHelpButton->tipStr = hs = bh->value;
- }
-if (newHelp) {
- wControlSetBalloon( balloonHelpButton, 0, 0, hs );
-} else {
- 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;
- }
- ClientToScreen( balloonHelpButton->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, hs, strlen(hs) );
- SelectObject( hDc, hFont );
- ReleaseDC( balloonHelpHWnd, hDc );
+ if (!balloonHelpStrings) {
+ return;
+ }
+
+ if (!balloonHelpEnable) {
+ return;
+ }
+
+ if (balloonHelpHWnd) {
+ if (balloonHelpButton->tipStr) {
+ hs = balloonHelpButton->tipStr;
+ } else {
+ hs = balloonHelpButton->helpStr;
+
+ if (!hs) {
+ return;
+ }
+
+ for (bh = balloonHelpStrings; bh->name && strcmp(bh->name,hs) != 0; bh++);
+
+ if (!bh->name || !bh->value) {
+ return;
+ }
+
+ balloonHelpButton->tipStr = hs = bh->value;
+ }
+
+ 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;
+ }
+
+ ClientToScreen(balloonHelpButton->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, hs, strlen(hs));
+ SelectObject(hDc, hFont);
+ ReleaseDC(balloonHelpHWnd, hDc);
+ }
+ }
}
- }
+
+void closeBalloonHelp(void)
+{
+ if (balloonHelpTimer) {
+ KillTimer(mswHWnd, balloonHelpTimer);
+ balloonHelpTimer = 0;
+ }
+
+ if (balloonHelpState == balloonHelpShow)
+ if (balloonHelpHWnd) {
+ ShowWindow(balloonHelpHWnd, SW_HIDE);
+ }
+
+ balloonHelpState = balloonHelpIdle;
}
-void closeBalloonHelp( void )
+
+void wControlSetBalloon(wControl_p b, wPos_t dx, wPos_t dy, const char * msg)
{
- if (balloonHelpTimer) {
- KillTimer( mswHWnd, balloonHelpTimer );
- balloonHelpTimer = 0;
- }
- if (balloonHelpState == balloonHelpShow)
- if (balloonHelpHWnd)
- ShowWindow( balloonHelpHWnd, SW_HIDE );
- balloonHelpState = balloonHelpIdle;
-}
-
-
-void wControlSetBalloon( wControl_p b, wPos_t dx, wPos_t dy, const char * msg )
-{
- HDC hDc;
- DWORD extent;
- int w, h;
- RECT rect;
- POINT pt;
- HFONT hFont;
-
- if ( msg ) {
- 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;
- }
- 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;
- } else {
- closeBalloonHelp();
- }
+ 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;
+ }
+
+ 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;
+ } else {
+ closeBalloonHelp();
+ }
}
-int wGetKeyState( void )
+int wGetKeyState(void)
{
- int rc, keyState;
- rc = 0;
- keyState = GetAsyncKeyState( VK_SHIFT );
- if (keyState & 0x8000)
- rc |= WKEY_SHIFT;
- keyState = GetAsyncKeyState( VK_CONTROL );
- if (keyState & 0x8000)
- rc |= WKEY_CTRL;
- keyState = GetAsyncKeyState( VK_MENU );
- if (keyState & 0x8000)
- rc |= WKEY_ALT;
- return rc;
+ int rc, keyState;
+ rc = 0;
+ keyState = GetAsyncKeyState(VK_SHIFT);
+
+ if (keyState & 0x8000) {
+ rc |= WKEY_SHIFT;
+ }
+
+ keyState = GetAsyncKeyState(VK_CONTROL);
+
+ if (keyState & 0x8000) {
+ rc |= WKEY_CTRL;
+ }
+
+ keyState = GetAsyncKeyState(VK_MENU);
+
+ if (keyState & 0x8000) {
+ rc |= WKEY_ALT;
+ }
+
+ return rc;
}
@@ -1980,30 +2307,28 @@ int wGetKeyState( void )
*/
FILE * wFileOpen(
- const char * fileName,
- const char * mode )
+ const char * fileName,
+ const char * mode)
{
- return fopen( fileName, mode );
+ return fopen(fileName, mode);
}
struct wFilSel_t {
- wWin_p parent;
- wFilSelMode_e mode;
- int option;
- const char * title;
- char * extList;
- wFilSelCallBack_p action;
- void * data;
- };
-
-static char selFileName[1024];
-static char selFileTitle[1024];
-static char sysDirName[1024];
+ wWin_p parent;
+ wFilSelMode_e mode;
+ int option;
+ const char * title;
+ char * extList;
+ wFilSelCallBack_p action;
+ void * data;
+};
+
+#define SELECTEDFILENAME_BUFFERSIZE (8*1024) /**<estimated size in case all param files are selected */
/**
* Run the file selector. After the selector is finished an array of filenames is
- * created. Each filename will be fully qualified. The array and the number of
+ * created. Each filename will be fully qualified. The array and the number of
* filenames are passed to a callback function. This is similar to the argc argv c
* convention in C. Once the callback returns, the allocated strings are free'd.
*
@@ -2013,163 +2338,177 @@ static char sysDirName[1024];
*/
int wFilSelect(
- struct wFilSel_t * fs,
- const char * dirName )
-{
- int rc;
- OPENFILENAME ofn;
- char **fileName;
- char *nextFileName;
- int cntFiles;
- const char * ext;
- char defExt[4];
- int i;
-
- if (dirName == NULL ||
- dirName[0] == '\0' ||
- strcmp(dirName, ".") == 0 ) {
- GetSystemDirectory( CAST_AWAY_CONST (dirName = sysDirName), sizeof sysDirName );
- }
- memset( &ofn, 0, sizeof ofn );
- ofn.lStructSize = sizeof ofn;
- ofn.hwndOwner = mswHWnd;
- ofn.lpstrFilter = fs->extList;
- ofn.nFilterIndex = 0;
- memset( selFileName, '\0', sizeof(selFileName));
- ofn.lpstrFile = selFileName;
- ofn.nMaxFile = sizeof selFileName;
- selFileTitle[0] = '\0';
- ofn.lpstrFileTitle = selFileTitle;
- ofn.nMaxFileTitle = sizeof selFileTitle;
- ofn.lpstrInitialDir = dirName;
- ofn.lpstrTitle = fs->title;
- ext = fs->extList + strlen(fs->extList)+1;
- if (*ext++ == '*' && *ext++ == '.') {
- for ( i=0; i<3 && ext[i] && ext[i]!=';'; i++ )
- defExt[i] = ext[i];
- defExt[i] = '\0';
- } else {
- defExt[0] = '\0';
- }
- ofn.lpstrDefExt = defExt;
-
- if ( fs->option & FS_MULTIPLEFILES ) {
- ofn.Flags = OFN_ALLOWMULTISELECT | OFN_LONGFILENAMES | OFN_EXPLORER;
- } else {
- ofn.Flags = OFN_LONGFILENAMES;
- }
-
- if (fs->mode == FS_LOAD) {
- ofn.Flags |= OFN_FILEMUSTEXIST;
- rc = GetOpenFileName( &ofn );
- } else if (fs->mode == FS_SAVE) {
- ofn.Flags |= OFN_OVERWRITEPROMPT;
- rc = GetSaveFileName( &ofn );
- } else if (fs->mode == FS_UPDATE) {
- rc = GetSaveFileName( &ofn );
- } else
- return FALSE;
- if (!rc)
- return FALSE;
-
- nextFileName = selFileName;
- selFileName[ofn.nFileOffset - 1] = '\0';
- cntFiles = 0;
-
- while (*nextFileName) {
- cntFiles++;
- nextFileName = nextFileName + strlen( nextFileName ) + 1;
- }
-
- // strings were counted including the path on its own so reduce the count
- cntFiles--;
-
- // build up the array of filenames
- fileName = malloc(sizeof(nextFileName) * cntFiles);
- nextFileName = selFileName + ofn.nFileOffset;
- for ( i=0; i < cntFiles; i++) {
- fileName[ i ] = malloc(strlen(selFileName) + strlen(nextFileName) + 2 );
- strcpy(fileName[ i ], selFileName);
- strcat(fileName[ i ], FILE_SEP_CHAR);
- strcat(fileName[ i ], nextFileName);
- nextFileName = nextFileName + strlen( nextFileName ) + 1;
- }
-
- fs->action( cntFiles, fileName, fs->data );
-
- for (i=0; i < cntFiles; i++) {
- free( fileName[ i ] );
- }
- free( fileName );
-
- return TRUE;
+ struct wFilSel_t * fs,
+ const char * dirName)
+{
+ int rc;
+ OPENFILENAME ofn;
+ char **fileName;
+ char *nextFileName;
+ char *selFileName;
+ int cntFiles;
+ const char * ext;
+ char defExt[4];
+ int i;
+
+ if (dirName == NULL ||
+ dirName[0] == '\0' ||
+ strcmp(dirName, ".") == 0) {
+ dirName = wGetUserHomeDir();
+ }
+
+ memset(&ofn, 0, sizeof ofn);
+ ofn.lStructSize = sizeof ofn;
+ ofn.hwndOwner = mswHWnd;
+ ofn.lpstrFilter = fs->extList;
+ ofn.nFilterIndex = 0;
+ selFileName = malloc(SELECTEDFILENAME_BUFFERSIZE);
+ memset(selFileName, '\0', SELECTEDFILENAME_BUFFERSIZE);
+ ofn.lpstrFile = selFileName;
+ ofn.nMaxFile = SELECTEDFILENAME_BUFFERSIZE;
+ ofn.lpstrFileTitle = NULL;
+ ofn.nMaxFileTitle = 0;
+ ofn.lpstrInitialDir = dirName;
+ ofn.lpstrTitle = fs->title;
+ ext = fs->extList + strlen(fs->extList)+1;
+
+ if (*ext++ == '*' && *ext++ == '.') {
+ for (i=0; i<3 && ext[i] && ext[i]!=';'; i++) {
+ defExt[i] = ext[i];
+ }
+
+ defExt[i] = '\0';
+ } else {
+ defExt[0] = '\0';
+ }
+
+ ofn.lpstrDefExt = defExt;
+
+ if (fs->option & FS_MULTIPLEFILES) {
+ ofn.Flags = OFN_ALLOWMULTISELECT | OFN_LONGFILENAMES | OFN_EXPLORER;
+ } else {
+ ofn.Flags = OFN_LONGFILENAMES;
+ }
+
+ if (fs->mode == FS_LOAD) {
+ ofn.Flags |= OFN_FILEMUSTEXIST;
+ rc = GetOpenFileName(&ofn);
+ } else if (fs->mode == FS_SAVE) {
+ ofn.Flags |= OFN_OVERWRITEPROMPT;
+ rc = GetSaveFileName(&ofn);
+ } else if (fs->mode == FS_UPDATE) {
+ rc = GetSaveFileName(&ofn);
+ } else {
+ return FALSE;
+ }
+
+ if (!rc) {
+ return FALSE;
+ }
+
+ nextFileName = selFileName;
+ selFileName[ofn.nFileOffset - 1] = '\0';
+ cntFiles = 0;
+
+ while (*nextFileName) {
+ cntFiles++;
+ nextFileName = nextFileName + strlen(nextFileName) + 1;
+ }
+
+ // strings were counted including the path on its own so reduce the count
+ cntFiles--;
+ // build up the array of filenames
+ fileName = malloc(sizeof(nextFileName) * cntFiles);
+ nextFileName = selFileName + ofn.nFileOffset;
+
+ for (i=0; i < cntFiles; i++) {
+ fileName[ i ] = malloc(strlen(selFileName) + strlen(nextFileName) + 2);
+ strcpy(fileName[ i ], selFileName);
+ strcat(fileName[ i ], FILE_SEP_CHAR);
+ strcat(fileName[ i ], nextFileName);
+ nextFileName = nextFileName + strlen(nextFileName) + 1;
+ }
+
+ fs->action(cntFiles, fileName, fs->data);
+
+ for (i=0; i < cntFiles; i++) {
+ free(fileName[ i ]);
+ }
+
+ free(fileName);
+ free(selFileName);
+ return TRUE;
}
struct wFilSel_t * wFilSelCreate(
- wWin_p parent,
- wFilSelMode_e mode,
- int option,
- const char * title,
- const char * extList,
- wFilSelCallBack_p action,
- void * data )
-{
- char * cp;
- struct wFilSel_t * ret;
- int len;
- ret = (struct wFilSel_t*)malloc(sizeof *ret);
- ret->parent = parent;
- ret->mode = mode;
- ret->option = option;
- ret->title = mswStrdup(title);
- len = strlen(extList);
- ret->extList = (char*)malloc(len+2);
- strcpy(ret->extList,extList);
- for ( cp=ret->extList; *cp; cp++ ) {
- if (*cp == '|')
- *cp = '\0';
- }
- *++cp = '\0';
- ret->action = action;
- ret->data = data;
- return ret;
-}
-
-
-const char * wMemStats( void )
-{
- int rc;
- static char msg[80];
- long usedSize = 0;
- long usedCnt = 0;
- long freeSize = 0;
- long freeCnt = 0;
- _HEAPINFO heapinfo;
- heapinfo._pentry = NULL;
-
- while ( (rc=_heapwalk( &heapinfo )) == _HEAPOK ) {
- switch (heapinfo._useflag) {
- case _FREEENTRY:
- freeSize += (long)heapinfo._size;
- freeCnt++;
- break;
- case _USEDENTRY:
- usedSize += (long)heapinfo._size;
- usedCnt++;
- break;
- }
- }
-
- sprintf( msg, "Used: %ld(%ld), Free %ld(%ld)%s",
- usedSize, usedCnt, freeSize, freeCnt,
- (rc==_HEAPOK)?"":
- (rc==_HEAPEMPTY)?"":
- (rc==_HEAPBADBEGIN)?", BADBEGIN":
- (rc==_HEAPEND)?"":
- (rc==_HEAPBADPTR)?", BADPTR":
- ", Unknown Heap Status" );
- return msg;
+ wWin_p parent,
+ wFilSelMode_e mode,
+ int option,
+ const char * title,
+ const char * extList,
+ wFilSelCallBack_p action,
+ void * data)
+{
+ char * cp;
+ struct wFilSel_t * ret;
+ int len;
+ ret = (struct wFilSel_t*)malloc(sizeof *ret);
+ ret->parent = parent;
+ ret->mode = mode;
+ ret->option = option;
+ ret->title = mswStrdup(title);
+ len = strlen(extList);
+ ret->extList = (char*)malloc(len+2);
+ strcpy(ret->extList,extList);
+
+ for (cp=ret->extList; *cp; cp++) {
+ if (*cp == '|') {
+ *cp = '\0';
+ }
+ }
+
+ *++cp = '\0';
+ ret->action = action;
+ ret->data = data;
+ return ret;
+}
+
+
+const char * wMemStats(void)
+{
+ int rc;
+ static char msg[80];
+ long usedSize = 0;
+ long usedCnt = 0;
+ long freeSize = 0;
+ long freeCnt = 0;
+ _HEAPINFO heapinfo;
+ heapinfo._pentry = NULL;
+
+ while ((rc=_heapwalk(&heapinfo)) == _HEAPOK) {
+ switch (heapinfo._useflag) {
+ case _FREEENTRY:
+ freeSize += (long)heapinfo._size;
+ freeCnt++;
+ break;
+
+ case _USEDENTRY:
+ usedSize += (long)heapinfo._size;
+ usedCnt++;
+ break;
+ }
+ }
+
+ sprintf(msg, "Used: %ld(%ld), Free %ld(%ld)%s",
+ usedSize, usedCnt, freeSize, freeCnt,
+ (rc==_HEAPOK)?"":
+ (rc==_HEAPEMPTY)?"":
+ (rc==_HEAPBADBEGIN)?", BADBEGIN":
+ (rc==_HEAPEND)?"":
+ (rc==_HEAPBADPTR)?", BADPTR":
+ ", Unknown Heap Status");
+ return msg;
}
/*
@@ -2180,480 +2519,629 @@ const char * wMemStats( void )
*****************************************************************************
*/
-static wControl_p getControlFromCursor( HWND hWnd, wWin_p * winR )
-{
- POINT pt;
- wWin_p w;
- wControl_p b;
- wIndex_t inx;
- HWND hTopWnd;
-
- if (winR)
- *winR = NULL;
- GetCursorPos( &pt );
- hTopWnd = GetActiveWindow();
- inx = GetWindowWord( hWnd, 0 );
- if ( inx < CONTROL_BASE || inx > controlMap_da.cnt ) {
- /* Unknown control */
- /*MessageBeep( MB_ICONEXCLAMATION );*/
- return NULL;
- }
- w=(wWin_p)controlMap(inx-CONTROL_BASE).b;
- if (!w)
- return NULL;
- if (w->type != W_MAIN && w->type != W_POPUP)
- return NULL;
- if ( winR )
- *winR = w;
- ScreenToClient( hWnd, &pt );
- for (b = w->first; b; b=b->next) {
- if (b->type == B_BOX || b->type == B_LINES)
- continue;
- if (b->hWnd == NULL)
- continue;
- if (IsWindowVisible( b->hWnd ) == FALSE)
- continue;
- if (pt.x > b->x && pt.x < b->x+b->w &&
- pt.y > b->y && pt.y < b->y+b->h )
- return b;
- }
- return b;
+static wControl_p getControlFromCursor(HWND hWnd, wWin_p * winR)
+{
+ POINT pt;
+ wWin_p w;
+ wControl_p b;
+ wIndex_t inx;
+
+ if (winR) {
+ *winR = NULL;
+ }
+
+ GetCursorPos(&pt);
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
+ /* Unknown control */
+ return NULL;
+ }
+
+ w=(wWin_p)controlMap(inx-CONTROL_BASE).b;
+
+ if (!w) {
+ return NULL;
+ }
+
+ if (w->type != W_MAIN && w->type != W_POPUP) {
+ return NULL;
+ }
+
+ if (winR) {
+ *winR = w;
+ }
+
+ ScreenToClient(hWnd, &pt);
+
+ for (b = w->first; b; b=b->next) {
+ if (b->type == B_BOX || b->type == B_LINES) {
+ continue;
+ }
+
+ if (b->hWnd == NULL) {
+ continue;
+ }
+
+ if (IsWindowVisible(b->hWnd) == FALSE) {
+ continue;
+ }
+
+ if (pt.x > b->x && pt.x < b->x+b->w &&
+ pt.y > b->y && pt.y < b->y+b->h) {
+ return b;
+ }
+ }
+
+ return b;
}
/**
- * Window function for the main window and all popup windows.
+ * Window function for the main window and all popup windows.
*
*/
-LRESULT
-FAR
-PASCAL
-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;
- RECT rect;
- PAINTSTRUCT ps;
- HWND hWnd2;
- LRESULT ret;
- HDC hDc;
- wAccelKey_e extChar;
-
- switch (message) {
-
- case WM_MOUSEWHEEL:
- inx = GetWindowWord( hWnd, 0 );
- b = getControlFromCursor( hWnd, NULL );
- if( b && b->type == B_DRAW )
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->messageProc)
- return mswCallBacks[b->type]->messageProc( (wControl_p)b, hWnd,
- message, wParam, lParam );
- return( 0 );
- case WM_DRAWITEM:
- case WM_COMMAND:
- case WM_MEASUREITEM:
- case WM_NOTVALID:
- if (WCMD_PARAM_ID == IDM_DOHELP) {
- b = getControlFromCursor( hWnd, NULL );
- closeBalloonHelp();
- if (!b)
- return 0L;
- if (b->helpStr)
- wHelp( b->helpStr );
- return 0L;
- }
- closeBalloonHelp();
- if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt)
- break;
- b = controlMap(WCMD_PARAM_ID-CONTROL_BASE).b;
- if (!b)
- break;
- if( b->type == B_BITMAP ) {
- // draw the bitmap
- mswDrawIcon(((LPDRAWITEMSTRUCT)lParam)->hDC, 0, 0, (wIcon_p)(b->data), FALSE, (COLORREF)0, (COLORREF)0 );
- return( TRUE );
- } else {
- mswSetFocus( b );
- ret = 0L;
- if (!inMainWndProc) {
- inMainWndProc = TRUE;
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->messageProc) {
- ret = mswCallBacks[b->type]->messageProc( b, hWnd, message, wParam, lParam );
- }
- inMainWndProc = FALSE;
- }
- return ret;
- }
- case WM_PAINT:
- inx = GetWindowWord( hWnd, 0 );
- if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt &&
- (w = (wWin_p)controlMap(inx-CONTROL_BASE).b) &&
- (w->type == W_MAIN || w->type == W_POPUP) &&
- (!IsIconic(mswHWnd)) &&
- (GetUpdateRect( hWnd, &rect, FALSE ) ) ) {
- BeginPaint( hWnd, &ps );
- for (b=w->first; b; b=b->next ) {
- if (b->shown &&
- mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->repaintProc)
- mswCallBacks[b->type]->repaintProc( hWnd, b );
- }
- EndPaint( hWnd, &ps );
- return 1L;
- }
- break;
-
- case WM_SIZE:
- inx = GetWindowWord( hWnd, 0 );
- if (inx < CONTROL_BASE || inx > controlMap_da.cnt)
- break;
- w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
- if (!w)
- break;
- if (w->type != W_MAIN && w->type != W_POPUP)
- break;
- if (w->busy)
- break;
- switch( wParam ) {
- case SIZE_MAXIMIZED:
- case SIZE_MINIMIZED:
- case SIZE_RESTORED:
- newW = LOWORD( lParam ); /* WIN32?? */
- newH = HIWORD( lParam ); /* WIN32?? */
- if (newW <= 0 || newH <= 0)
- break;
- if (newW == w->w && newH == w->h)
- break;
- GetWindowRect( w->hWnd, &rect );
- GetClientRect( w->hWnd, &rect );
- InvalidateRect( w->hWnd, NULL, TRUE );
- w->w = newW;
- w->h = newH;
- if (w->winProc)
- w->winProc( w, wResize_e, w->data );
- break;
- default:
- break;
- }
- break;
-
- case WM_CHAR:
- case WM_KEYUP:
- inx = GetWindowWord( hWnd, 0 );
- if ( inx < CONTROL_BASE || inx > controlMap_da.cnt )
- break;
- w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
- if (!w)
- break;
- if (w->type != W_MAIN && w->type != W_POPUP) {
- if (mswCallBacks[w->type] != NULL &&
- mswCallBacks[w->type]->messageProc)
- return mswCallBacks[w->type]->messageProc( (wControl_p)w, hWnd,
- message, wParam, lParam );
- break;
- }
- extChar = translateExtKey( WCMD_PARAM_ID );
- if (message == WM_KEYUP ) {
- if (extChar == wAccelKey_None)
- break;
- if (extChar == wAccelKey_Back)
- break;
- }
- b = getControlFromCursor( hWnd, NULL );
- closeBalloonHelp();
- if (b && b->type == B_DRAW) {
- return SendMessage( b->hWnd, WM_CHAR, wParam, lParam );
- }
- switch (WCMD_PARAM_ID) {
- case 0x0D:
- /* CR - push default button */
- for (b=w->first; b; b=b->next) {
- if (b->type == B_BUTTON && (b->option & BB_DEFAULT) != 0) {
- inMainWndProc = TRUE;
- if (mswCallBacks[B_BUTTON] != NULL &&
- mswCallBacks[B_BUTTON]->messageProc) {
- ret = mswCallBacks[B_BUTTON]->messageProc( b, b->hWnd,
- WM_COMMAND, wParam, lParam );
- }
- inMainWndProc = FALSE;
- break;
- }
- }
- return 0L;
- case 0x1B:
- /* ESC - push cancel button */
- for (b=w->first; b; b=b->next) {
- if (b->type == B_BUTTON && (b->option & BB_CANCEL) != 0) {
- inMainWndProc = TRUE;
- if (mswCallBacks[B_BUTTON] != NULL &&
- mswCallBacks[B_BUTTON]->messageProc) {
- ret = mswCallBacks[B_BUTTON]->messageProc( b, b->hWnd,
- WM_COMMAND, wParam, lParam );
- }
- inMainWndProc = FALSE;
- break;
- }
- }
- mswSetTrigger( (wControl_p)TRIGGER_TIMER, NULL );
- return 0L;
- case 0x20:
- /* SPC - push current button with focus */
- if ( (b=w->focusChainNext) != NULL ) {
- switch (b->type) {
- case B_BUTTON:
- case B_CHOICEITEM:
- inMainWndProc = TRUE;
- 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) );
- }
- inMainWndProc = FALSE;
- break;
- }
+LRESULT
+FAR
+PASCAL
+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;
+ RECT rect;
+ PAINTSTRUCT ps;
+ HWND hWnd2;
+ LRESULT ret;
+ HDC hDc;
+ wAccelKey_e extChar;
+
+ switch (message) {
+ case WM_MOUSEWHEEL:
+ inx = GetWindowWord(hWnd, 0);
+ b = getControlFromCursor(hWnd, NULL);
+
+ if (b && b->type == B_DRAW)
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->messageProc)
+ return mswCallBacks[b->type]->messageProc((wControl_p)b, hWnd,
+ message, wParam, lParam);
+
+ return (0);
+
+ case WM_DRAWITEM:
+ case WM_COMMAND:
+ case WM_MEASUREITEM:
+ case WM_NOTVALID:
+ if (WCMD_PARAM_ID == IDM_DOHELP) {
+ b = getControlFromCursor(hWnd, NULL);
+ closeBalloonHelp();
+
+ if (!b) {
+ return 0L;
+ }
+
+ if (b->helpStr) {
+ wHelp(b->helpStr);
+ }
+
+ return 0L;
+ }
+
+ closeBalloonHelp();
+
+ if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) {
+ break;
+ }
+
+ b = controlMap(WCMD_PARAM_ID-CONTROL_BASE).b;
+
+ if (!b) {
+ break;
+ }
+
+ if (b->type == B_BITMAP) {
+ // draw the bitmap
+ mswDrawIcon(((LPDRAWITEMSTRUCT)lParam)->hDC, 0, 0, (wIcon_p)(b->data), FALSE,
+ (COLORREF)0, (COLORREF)0);
+ return (TRUE);
+ } else {
+ mswSetFocus(b);
+ ret = 0L;
+
+ if (!inMainWndProc) {
+ inMainWndProc = TRUE;
+
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->messageProc) {
+ ret = mswCallBacks[b->type]->messageProc(b, hWnd, message, wParam, lParam);
+ }
+
+ inMainWndProc = FALSE;
+ }
+
+ return ret;
+ }
+
+ case WM_PAINT:
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt &&
+ (w = (wWin_p)controlMap(inx-CONTROL_BASE).b) &&
+ (w->type == W_MAIN || w->type == W_POPUP) &&
+ (!IsIconic(mswHWnd)) &&
+ (GetUpdateRect(hWnd, &rect, FALSE))) {
+ BeginPaint(hWnd, &ps);
+
+ for (b=w->first; b; b=b->next) {
+ if (b->shown &&
+ mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->repaintProc) {
+ mswCallBacks[b->type]->repaintProc(hWnd, b);
+ }
+ }
+
+ EndPaint(hWnd, &ps);
+ return 1L;
+ }
+
+ break;
+
+ case WM_SIZE:
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
+ break;
+ }
+
+ w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
+
+ if (!w) {
+ break;
+ }
+
+ if (w->type != W_MAIN && w->type != W_POPUP) {
+ break;
+ }
+
+ if (w->busy) {
+ break;
+ }
+
+ switch (wParam) {
+ case SIZE_MAXIMIZED:
+ case SIZE_MINIMIZED:
+ case SIZE_RESTORED:
+ newW = LOWORD(lParam);
+ newH = HIWORD(lParam);
+
+ if (newW <= 0 || newH <= 0) {
+ break;
+ }
+
+ if (newW == w->w && newH == w->h) {
+ break;
+ }
+
+ GetWindowRect(w->hWnd, &rect);
+ GetClientRect(w->hWnd, &rect);
+ InvalidateRect(w->hWnd, NULL, TRUE);
+ w->w = newW;
+ w->h = newH;
+
+ if (w->winProc) {
+ w->winProc(w, wResize_e, w->data);
+ w->winProc(w, wState_e, w->data);
}
- return 0L;
- case 0x09:
- /* TAB - jump to next control */
- if ( w->focusChainNext ) {
- for ( b = w->focusChainNext->focusChainNext;
- b!=w->focusChainNext;
- b=b->focusChainNext ) {
- if( IsWindowVisible(b->hWnd) && IsWindowEnabled(b->hWnd))
- break;
- }
- oldW = w->focusChainNext;
- w->focusChainNext = b;
- if (!inMainWndProc) {
- inMainWndProc = TRUE;
- SetFocus( b->hWnd );
-/* if( b->type == B_BUTTON)
- InvalidateRect( b->hWnd, NULL, TRUE ); */
- if( oldW->type == B_BUTTON)
- InvalidateRect( oldW->hWnd, NULL, TRUE );
-
- inMainWndProc = FALSE;
- }
- }
- return 0L;
- }
- /* Not a Draw control */
- MessageBeep( MB_ICONHAND );
- return 0L;
- break;
-
- case WM_ENABLE:
- if (wParam == 1) { /* WIN32??? */
- hWnd2 = SetFocus( hWnd );
- }
- break;
-
- case WM_F1DOWN:
- if ((hWnd2 = GetActiveWindow()) == hWnd ||
- (inx=GetWindowWord(hWnd2,0)) < CONTROL_BASE || inx > controlMap_da.cnt )
- return DefWindowProc( hWnd, message, wParam, lParam );
- b=controlMap(inx-CONTROL_BASE).b;
- if (!b)
- break;
- closeBalloonHelp();
- wHelp( b->helpStr );
- return 0L;
-
- case WM_SETCURSOR:
- /*if (any buttons down)
- break;*/
- wSetCursor( curCursor );
- if (!mswAllowBalloonHelp)
- break;
- if (IsIconic(mswHWnd))
- break;
- b = getControlFromCursor(hWnd, NULL);
- if ( b == balloonControlButton )
- break;
- if ( /*(!IsWindowEnabled(hWnd))*/ GetActiveWindow() != hWnd ||
- (!b) || b->type == B_DRAW || b->helpStr == NULL ) {
- closeBalloonHelp();
- break;
- }
- if ( b != balloonHelpButton )
- closeBalloonHelp();
- if (balloonHelpState != balloonHelpIdle) {
- break;
- }
- balloonHelpTimer = SetTimer( mswHWnd, BALLOONHELP_TIMER,
- balloonHelpTimeOut, NULL );
- if (balloonHelpTimer == (UINT)0)
- break;
- balloonHelpState = balloonHelpWait;
- balloonHelpButton = b;
- break;
-
- case WM_SYSCOMMAND:
- inx = GetWindowWord( hWnd, 0 );
- if (inx < CONTROL_BASE || inx > controlMap_da.cnt)
- break;
- w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
- if (!w)
- break;
- if (w->type != W_POPUP)
- break;
- if (w->busy)
- break;
- if ( (wParam&0xFFF0) != SC_CLOSE )
- break;
- if (w->winProc)
- w->winProc( w, wClose_e, w->data );
- wWinShow( w, FALSE );
- return 0L;
-
-
-
- case WM_CLOSE:
- inx = GetWindowWord( hWnd, 0 );
- if (inx < CONTROL_BASE || inx > controlMap_da.cnt)
- break;
- w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
- if (!w)
- break;
- if (w->type == W_MAIN) {
- /* It's the big one! */
- /* call main window procedure for processing of shutdown */
- if( w->winProc )
- (w->winProc( w, wClose_e, NULL ));
- return 0L;
- }
- case WM_DESTROY:
- if ( hWnd == mswHWnd ) {
- PostQuitMessage(0L);
- return 0L;
- }
- break;
-
- case WM_TIMER:
- if (wParam == ALARM_TIMER) {
- KillTimer( mswHWnd, alarmTimer );
- alarmFunc();
- } else if (wParam == TRIGGER_TIMER) {
- KillTimer( mswHWnd, triggerTimer );
- triggerTimer = 0;
- if (triggerFunc)
- triggerFunc( triggerControl );
- } else if (wParam == BALLOONHELP_TIMER) {
- KillTimer( hWnd, balloonHelpTimer );
- balloonHelpTimer = (UINT)0;
- startBalloonHelp();
- }
- return 0L;
-
- case WM_MENUSELECT:
- mswAllowBalloonHelp = TRUE;
- closeBalloonHelp();
- break;
-
- case WM_WINDOWPOSCHANGED:
- if (hWnd == mswHWnd && !IsIconic(hWnd) && needToDoPendingShow) {
- for (w=winFirst; w; w=(wWin_p)w->next) {
- if (w->hWnd != mswHWnd &&
- w->pendingShow )
- ShowWindow( w->hWnd, SW_SHOW );
- w->pendingShow = FALSE;
- }
- needToDoPendingShow = FALSE;
- }
- break;
-
- case 51:
- count51++;
- /*return NULL;*/
-
-#ifdef LATER
- case WM_SETFOCUS:
- hDc = GetDC( hWnd );
- rc = RealizePalette( hDc );
- ReleaseDC( hWnd, hDc );
- inx = GetWindowWord( hWnd, 0 );
- if ( inx < CONTROL_BASE || inx > controlMap_da.cnt )
- break;
- w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
- if (!w)
- break;
- if (w->type != W_MAIN && w->type != W_POPUP)
- break;
- for (b=w->first; b; b=b->next) {
- if (b->hWnd && (b->type == B_BUTTON || b->type==B_DRAW)) {
- hDc = GetDC( b->hWnd );
- rc = RealizePalette( hDc );
- ReleaseDC( b->hWnd, hDc );
- }
- }
- break;
-#endif
+ break;
- case WM_PALETTECHANGED:
- if (wParam == (WPARAM)hWnd)
- return 0L;
-
- case WM_QUERYNEWPALETTE:
- if (mswPalette) {
- hDc = GetDC( hWnd );
- SelectPalette( hDc, mswPalette, 0 );
- inx = RealizePalette( hDc );
- ReleaseDC( hWnd, hDc );
- if (inx>0)
- InvalidateRect( hWnd, NULL, TRUE );
- return inx;
- }
+ default:
+ break;
+ }
- case WM_ACTIVATE:
- if ( LOWORD(wParam) == WA_INACTIVE )
- closeBalloonHelp();
- break;
-
- case WM_HSCROLL:
- case WM_VSCROLL:
- b = getControlFromCursor( hWnd, NULL );
- if (!b)
- break;
- /*mswSetFocus( b );*/
- ret = 0L;
- if (!inMainWndProc) {
- inMainWndProc = TRUE;
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->messageProc) {
- ret = mswCallBacks[b->type]->messageProc( b, hWnd, message, wParam, lParam );
- }
- inMainWndProc = FALSE;
- }
- return ret;
-
- case WM_LBUTTONDOWN:
- case WM_MOUSEMOVE:
- case WM_LBUTTONUP:
- b = getControlFromCursor( hWnd, NULL );
- if (!b)
- break;
- /*mswSetFocus( b );*/
- ret = 0L;
- if (!inMainWndProc) {
- inMainWndProc = TRUE;
- if (mswCallBacks[b->type] != NULL &&
- mswCallBacks[b->type]->messageProc) {
- ret = mswCallBacks[b->type]->messageProc( b, hWnd, message, wParam, lParam );
- }
- inMainWndProc = FALSE;
- }
- return ret;
-
- default:
- ;
- }
- return DefWindowProc( hWnd, message, wParam, lParam );
+ break;
+
+ case WM_CHAR:
+ case WM_KEYUP:
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
+ break;
+ }
+
+ w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
+
+ if (!w) {
+ break;
+ }
+
+ if (w->type != W_MAIN && w->type != W_POPUP) {
+ if (mswCallBacks[w->type] != NULL &&
+ mswCallBacks[w->type]->messageProc)
+ return mswCallBacks[w->type]->messageProc((wControl_p)w, hWnd,
+ message, wParam, lParam);
+
+ break;
+ }
+
+ extChar = translateExtKey(WCMD_PARAM_ID);
+
+ if (message == WM_KEYUP) {
+ if (extChar == wAccelKey_None) {
+ break;
+ }
+
+ if (extChar == wAccelKey_Back) {
+ break;
+ }
+ }
+
+ b = getControlFromCursor(hWnd, NULL);
+ closeBalloonHelp();
+
+ if (b && b->type == B_DRAW) {
+ return SendMessage(b->hWnd, WM_CHAR, wParam, lParam);
+ }
+
+ switch (WCMD_PARAM_ID) {
+ case 0x0D:
+
+ /* CR - push default button */
+ for (b=w->first; b; b=b->next) {
+ if (b->type == B_BUTTON && (b->option & BB_DEFAULT) != 0) {
+ inMainWndProc = TRUE;
+
+ if (mswCallBacks[B_BUTTON] != NULL &&
+ mswCallBacks[B_BUTTON]->messageProc) {
+ ret = mswCallBacks[B_BUTTON]->messageProc(b, b->hWnd,
+ WM_COMMAND, wParam, lParam);
+ }
+
+ inMainWndProc = FALSE;
+ break;
+ }
+ }
+
+ return 0L;
+
+ case 0x1B:
+
+ /* ESC - push cancel button */
+ for (b=w->first; b; b=b->next) {
+ if (b->type == B_BUTTON && (b->option & BB_CANCEL) != 0) {
+ inMainWndProc = TRUE;
+
+ if (mswCallBacks[B_BUTTON] != NULL &&
+ mswCallBacks[B_BUTTON]->messageProc) {
+ ret = mswCallBacks[B_BUTTON]->messageProc(b, b->hWnd,
+ WM_COMMAND, wParam, lParam);
+ }
+
+ inMainWndProc = FALSE;
+ break;
+ }
+ }
+
+ mswSetTrigger((wControl_p)TRIGGER_TIMER, NULL);
+ return 0L;
+
+ case 0x20:
+
+ /* SPC - push current button with focus */
+ if ((b=w->focusChainNext) != NULL) {
+ switch (b->type) {
+ case B_BUTTON:
+ case B_CHOICEITEM:
+ inMainWndProc = TRUE;
+
+ 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));
+ }
+
+ inMainWndProc = FALSE;
+ break;
+ }
+ }
+
+ return 0L;
+
+ case 0x09:
+
+ /* TAB - jump to next control */
+ if (w->focusChainNext) {
+ for (b = w->focusChainNext->focusChainNext;
+ b!=w->focusChainNext;
+ b=b->focusChainNext) {
+ if (IsWindowVisible(b->hWnd) && IsWindowEnabled(b->hWnd)) {
+ break;
+ }
+ }
+
+ oldW = w->focusChainNext;
+ w->focusChainNext = b;
+
+ if (!inMainWndProc) {
+ inMainWndProc = TRUE;
+ SetFocus(b->hWnd);
+
+ /* if( b->type == B_BUTTON)
+ InvalidateRect( b->hWnd, NULL, TRUE ); */
+ if (oldW->type == B_BUTTON) {
+ InvalidateRect(oldW->hWnd, NULL, TRUE);
+ }
+
+ inMainWndProc = FALSE;
+ }
+ }
+
+ return 0L;
+ }
+
+ /* Not a Draw control */
+ MessageBeep(MB_ICONHAND);
+ return 0L;
+ break;
+
+ case WM_ENABLE:
+ if (wParam == 1) { /* WIN32??? */
+ hWnd2 = SetFocus(hWnd);
+ }
+
+ break;
+
+ case WM_F1DOWN:
+ if ((hWnd2 = GetActiveWindow()) == hWnd ||
+ (inx=GetWindowWord(hWnd2,0)) < CONTROL_BASE || inx > controlMap_da.cnt) {
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+
+ b=controlMap(inx-CONTROL_BASE).b;
+
+ if (!b) {
+ break;
+ }
+
+ closeBalloonHelp();
+ wHelp(b->helpStr);
+ return 0L;
+
+ case WM_SETCURSOR:
+ /*if (any buttons down)
+ break;*/
+ wSetCursor(curCursor);
+
+ if (!mswAllowBalloonHelp) {
+ break;
+ }
+
+ if (IsIconic(mswHWnd)) {
+ break;
+ }
+
+ b = getControlFromCursor(hWnd, NULL);
+
+ if (b == balloonControlButton) {
+ break;
+ }
+
+ if (/*(!IsWindowEnabled(hWnd))*/ GetActiveWindow() != hWnd ||
+ (!b) || b->type == B_DRAW || b->helpStr == NULL) {
+ closeBalloonHelp();
+ break;
+ }
+
+ if (b != balloonHelpButton) {
+ closeBalloonHelp();
+ }
+
+ if (balloonHelpState != balloonHelpIdle) {
+ break;
+ }
+
+ balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER,
+ balloonHelpTimeOut, NULL);
+
+ if (balloonHelpTimer == (UINT)0) {
+ break;
+ }
+
+ balloonHelpState = balloonHelpWait;
+ balloonHelpButton = b;
+ break;
+
+ case WM_SYSCOMMAND:
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
+ break;
+ }
+
+ w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
+
+ if (!w) {
+ break;
+ }
+
+ if (w->type != W_POPUP) {
+ break;
+ }
+
+ if (w->busy) {
+ break;
+ }
+
+ if ((wParam&0xFFF0) != SC_CLOSE) {
+ break;
+ }
+
+ if (w->winProc) {
+ w->winProc(w, wClose_e, w->data);
+ }
+
+ wWinShow(w, FALSE);
+ return 0L;
+
+ case WM_CLOSE:
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx < CONTROL_BASE || inx > controlMap_da.cnt) {
+ break;
+ }
+
+ w = (wWin_p)controlMap(inx-CONTROL_BASE).b;
+
+ if (!w) {
+ break;
+ }
+
+ if (w->type == W_MAIN) {
+ /* It's the big one! */
+ /* call main window procedure for processing of shutdown */
+ if (w->winProc) {
+ (w->winProc(w, wClose_e, NULL));
+ }
+
+ return 0L;
+ }
+
+ case WM_DESTROY:
+ if (hWnd == mswHWnd) {
+ PostQuitMessage(0L);
+ return 0L;
+ }
+
+ break;
+
+ case WM_TIMER:
+ if (wParam == ALARM_TIMER) {
+ KillTimer(mswHWnd, alarmTimer);
+ alarmFunc();
+ } else if (wParam == TRIGGER_TIMER) {
+ KillTimer(mswHWnd, triggerTimer);
+ triggerTimer = 0;
+
+ if (triggerFunc) {
+ triggerFunc(triggerControl);
+ }
+ } else if (wParam == BALLOONHELP_TIMER) {
+ KillTimer(hWnd, balloonHelpTimer);
+ balloonHelpTimer = (UINT)0;
+ startBalloonHelp();
+ }
+
+ return 0L;
+
+ case WM_MENUSELECT:
+ mswAllowBalloonHelp = TRUE;
+ closeBalloonHelp();
+ break;
+
+ case WM_WINDOWPOSCHANGED:
+ if (hWnd == mswHWnd && !IsIconic(hWnd) && needToDoPendingShow) {
+ for (w=winFirst; w; w=(wWin_p)w->next) {
+ if (w->hWnd != mswHWnd &&
+ w->pendingShow) {
+ ShowWindow(w->hWnd, SW_SHOW);
+ }
+
+ w->pendingShow = FALSE;
+ }
+
+ needToDoPendingShow = FALSE;
+ }
+
+ break;
+
+ case 51:
+ count51++;
+ /*return NULL;*/
+
+
+ case WM_PALETTECHANGED:
+ if (wParam == (WPARAM)hWnd) {
+ return 0L;
+ }
+
+ case WM_QUERYNEWPALETTE:
+ if (mswPalette) {
+ hDc = GetDC(hWnd);
+ SelectPalette(hDc, mswPalette, 0);
+ inx = RealizePalette(hDc);
+ ReleaseDC(hWnd, hDc);
+
+ if (inx>0) {
+ InvalidateRect(hWnd, NULL, TRUE);
+ }
+
+ return inx;
+ }
+
+ case WM_ACTIVATE:
+ if (LOWORD(wParam) == WA_INACTIVE) {
+ closeBalloonHelp();
+ }
+
+ break;
+
+ case WM_HSCROLL:
+ case WM_VSCROLL:
+ b = getControlFromCursor(hWnd, NULL);
+
+ if (!b) {
+ break;
+ }
+
+ /*mswSetFocus( b );*/
+ ret = 0L;
+
+ if (!inMainWndProc) {
+ inMainWndProc = TRUE;
+
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->messageProc) {
+ ret = mswCallBacks[b->type]->messageProc(b, hWnd, message, wParam, lParam);
+ }
+
+ inMainWndProc = FALSE;
+ }
+
+ return ret;
+
+ case WM_LBUTTONDOWN:
+ case WM_MOUSEMOVE:
+ case WM_LBUTTONUP:
+ b = getControlFromCursor(hWnd, NULL);
+
+ if (!b) {
+ break;
+ }
+
+ /*mswSetFocus( b );*/
+ ret = 0L;
+
+ if (!inMainWndProc) {
+ inMainWndProc = TRUE;
+
+ if (mswCallBacks[b->type] != NULL &&
+ mswCallBacks[b->type]->messageProc) {
+ ret = mswCallBacks[b->type]->messageProc(b, hWnd, message, wParam, lParam);
+ }
+
+ inMainWndProc = FALSE;
+ }
+
+ return ret;
+
+ default:
+ ;
+ }
+
+ return DefWindowProc(hWnd, message, wParam, lParam);
}
/*
@@ -2665,156 +3153,163 @@ MainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
*/
/**
- * Register window classes used by the application. These are the main window,
- * the popup windows, the tooltip window and the drawing area.
+ * Register window classes used by the application. These are the main window,
+ * the popup windows, the tooltip window and the drawing area.
*
* \param hinstCurrent IN application instance
* \return FALSE in case of error, else TRUE
*/
-static BOOL InitApplication( HINSTANCE hinstCurrent )
-{
- WNDCLASS wc;
-
- wc.style = 0L;
- wc.lpfnWndProc = MainWndProc;
-
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 4;
- wc.hInstance = hinstCurrent;
- wc.hIcon = LoadIcon( hinstCurrent, "MSWAPPICON" );
- wc.hCursor = NULL;
- wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "MswMainWindow";
- if (!RegisterClass(&wc)) {
- mswFail("RegisterClass(MainWindow)");
- return FALSE;
- }
-
- wc.style = CS_SAVEBITS;
- wc.lpfnWndProc = MainWndProc;
-
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 8;
- wc.hInstance = hinstCurrent;
- wc.hIcon = LoadIcon( NULL, "wAppIcon" );
- wc.hCursor = NULL;
- wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
- wc.lpszMenuName = "GenericMenu";
- wc.lpszClassName = "MswPopUpWindow";
- if (!RegisterClass(&wc)) {
- mswFail("RegisterClass(PopUpWindow)");
- return FALSE;
- }
-
- wc.style = CS_SAVEBITS;
- wc.lpfnWndProc = DefWindowProc;
-
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 4;
- wc.hInstance = hinstCurrent;
- wc.hIcon = 0;
- wc.hCursor = 0;
- wc.hbrBackground = CreateSolidBrush( GetSysColor( COLOR_INFOBK ) );
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "MswBalloonHelp";
- if (!RegisterClass(&wc)) {
- mswFail("RegisterClass(BalloonHelp)");
- return FALSE;
- }
-
- wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
- wc.lpfnWndProc = mswDrawPush;
- wc.lpszClassName = mswDrawWindowClassName;
- wc.cbWndExtra = 4;
- if (!RegisterClass(&wc)) {
- mswFail("RegisterClass(drawClass)");
- return FALSE;
- }
- return TRUE;
+static BOOL InitApplication(HINSTANCE hinstCurrent)
+{
+ WNDCLASS wc;
+ wc.style = 0L;
+ wc.lpfnWndProc = MainWndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 4;
+ wc.hInstance = hinstCurrent;
+ wc.hIcon = LoadIcon(hinstCurrent, "MSWAPPICON");
+ wc.hCursor = NULL;
+ wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "MswMainWindow";
+
+ if (!RegisterClass(&wc)) {
+ mswFail("RegisterClass(MainWindow)");
+ return FALSE;
+ }
+
+ wc.style = CS_SAVEBITS;
+ wc.lpfnWndProc = MainWndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 8;
+ wc.hInstance = hinstCurrent;
+ wc.hIcon = LoadIcon(NULL, "wAppIcon");
+ wc.hCursor = NULL;
+ wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
+ wc.lpszMenuName = "GenericMenu";
+ wc.lpszClassName = "MswPopUpWindow";
+
+ if (!RegisterClass(&wc)) {
+ mswFail("RegisterClass(PopUpWindow)");
+ return FALSE;
+ }
+
+ wc.style = CS_SAVEBITS;
+ wc.lpfnWndProc = DefWindowProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 4;
+ wc.hInstance = hinstCurrent;
+ wc.hIcon = 0;
+ wc.hCursor = 0;
+ wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_INFOBK));
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "MswBalloonHelp";
+
+ if (!RegisterClass(&wc)) {
+ mswFail("RegisterClass(BalloonHelp)");
+ return FALSE;
+ }
+
+ wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
+ wc.lpfnWndProc = mswDrawPush;
+ wc.lpszClassName = mswDrawWindowClassName;
+ wc.cbWndExtra = 4;
+
+ if (!RegisterClass(&wc)) {
+ mswFail("RegisterClass(drawClass)");
+ return FALSE;
+ }
+
+ return TRUE;
}
/**
- * Standard entry point for the app. Nothing special,
- * create some window classes, initialize some global
+ * Standard entry point for the app. Nothing special,
+ * create some window classes, initialize some global
* variables with system information, call the application main
* and finally process the message queue.
*/
-int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow )
+int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
+ LPSTR lpszCmdLine, int nCmdShow)
{
- MSG msg;
- HDC hDc;
- char **argv;
- int argc;
- TEXTMETRIC tm;
- DWORD dw;
+ MSG msg;
+ HDC hDc;
+ char **argv;
+ int argc;
+ TEXTMETRIC tm;
+ DWORD dw;
- if (!hinstPrevious)
- if (!InitApplication(hinstCurrent))
+ if (!hinstPrevious) {
+ if (!InitApplication(hinstCurrent)) {
return FALSE;
-
- mswHInst = hinstCurrent;
-
- mTitleH = GetSystemMetrics( SM_CYCAPTION ) - 1;
- mFixBorderW = GetSystemMetrics( SM_CXBORDER );
- mFixBorderH = GetSystemMetrics( SM_CYBORDER );
- mResizeBorderW = GetSystemMetrics( SM_CXFRAME );
- mResizeBorderH = GetSystemMetrics( SM_CYFRAME );
- mMenuH = GetSystemMetrics( SM_CYMENU ) + 1;
- screenWidth = GetSystemMetrics( SM_CXSCREEN );
- screenHeight = GetSystemMetrics( SM_CYSCREEN );
- mswLabelFont = GetStockObject( DEFAULT_GUI_FONT );
-
- hDc = GetDC( 0 );
- mswScale = GetDeviceCaps( hDc, LOGPIXELSX ) / 96.0;
- if ( mswScale < 1.0 )
- mswScale = 1.0;
- GetTextMetrics( hDc, &tm );
- mswEditHeight = tm.tmHeight + 8;
- dw = GetTextExtent( hDc, "AXqypj", 6 );
- mswEditHeight = HIWORD(dw)+2;
- ReleaseDC( 0, hDc );
-
- mswCreateCheckBitmaps();
-
- /*
- get the command line parameters in standard C style and pass them to the main function. The
- globals are predefined by Visual C
- */
- argc = __argc;
- argv = __argv;
-
- mswWin = wMain( argc, (char**)argv );
- if (mswWin == NULL)
- return 0;
-
- balloonHelpHWnd = CreateWindow( "MswBalloonHelp", "BalloonHelp",
- WS_POPUP|WS_BORDER,
- 0, 0, 80, 40, mswHWnd, NULL, mswHInst, NULL );
- if (balloonHelpHWnd == (HWND)0) {
- mswFail( "CreateWindow(BALLOONHELP)" );
- } else {
- hDc = GetDC( balloonHelpHWnd );
- /* We need to remember this because the hDc gets changed somehow,
- /* and we when we select the oldFont back in we don't get newFont */
- balloonHelpNewFont = CreateFont( - balloonHelpFontSize, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, balloonHelpFaceName );
- balloonHelpOldFont = SelectObject( hDc, balloonHelpNewFont );
- ReleaseDC( balloonHelpHWnd, hDc );
- }
-
- SetCursor( LoadCursor( NULL, IDC_ARROW ) );
- while (GetMessage( &msg, NULL, 0, 0 )) {
- if (!mswTranslateAccelerator( mswWin->hWnd, &msg )) {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
}
}
- if( helpInitted == TRUE )
- HtmlHelp( NULL, NULL, HH_UNINITIALIZE, (DWORD)dwCookie);
-
- return msg.wParam;
+ mswHInst = hinstCurrent;
+ mTitleH = GetSystemMetrics(SM_CYCAPTION) - 1;
+ mFixBorderW = GetSystemMetrics(SM_CXBORDER);
+ mFixBorderH = GetSystemMetrics(SM_CYBORDER);
+ mResizeBorderW = GetSystemMetrics(SM_CXFRAME);
+ mResizeBorderH = GetSystemMetrics(SM_CYFRAME);
+ mMenuH = GetSystemMetrics(SM_CYMENU) + 1;
+ screenWidth = GetSystemMetrics(SM_CXSCREEN);
+ screenHeight = GetSystemMetrics(SM_CYSCREEN);
+ mswLabelFont = GetStockObject(DEFAULT_GUI_FONT);
+ hDc = GetDC(0);
+ mswScale = GetDeviceCaps(hDc, LOGPIXELSX) / 96.0;
+
+ if (mswScale < 1.0) {
+ mswScale = 1.0;
+ }
+
+ GetTextMetrics(hDc, &tm);
+ mswEditHeight = tm.tmHeight + 8;
+ dw = GetTextExtent(hDc, "AXqypj", 6);
+ mswEditHeight = HIWORD(dw)+2;
+ ReleaseDC(0, hDc);
+ mswCreateCheckBitmaps();
+ /*
+ get the command line parameters in standard C style and pass them to the main function. The
+ globals are predefined by Visual C
+ */
+ argc = __argc;
+ argv = __argv;
+ mswWin = wMain(argc, (char**)argv);
+
+ if (mswWin == NULL) {
+ return 0;
+ }
+
+ balloonHelpHWnd = CreateWindow("MswBalloonHelp", "BalloonHelp",
+ WS_POPUP|WS_BORDER,
+ 0, 0, 80, 40, mswHWnd, NULL, mswHInst, NULL);
+
+ if (balloonHelpHWnd == (HWND)0) {
+ mswFail("CreateWindow(BALLOONHELP)");
+ } else {
+ hDc = GetDC(balloonHelpHWnd);
+ /* We need to remember this because the hDc gets changed somehow,
+ /* and we when we select the oldFont back in we don't get newFont */
+ balloonHelpNewFont = CreateFont(- balloonHelpFontSize, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, balloonHelpFaceName);
+ balloonHelpOldFont = SelectObject(hDc, balloonHelpNewFont);
+ ReleaseDC(balloonHelpHWnd, hDc);
+ }
+
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ if (!mswTranslateAccelerator(mswWin->hWnd, &msg)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+
+ if (helpInitted == TRUE) {
+ HtmlHelp(NULL, NULL, HH_UNINITIALIZE, (DWORD)dwCookie);
+ }
+
+ return msg.wParam;
}
diff --git a/app/wlib/mswlib/mswmsg.c b/app/wlib/mswlib/mswmsg.c
index b128534..4a21921 100644
--- a/app/wlib/mswlib/mswmsg.c
+++ b/app/wlib/mswlib/mswmsg.c
@@ -121,6 +121,10 @@ void wMessageSetWidth(
#endif
}
+wPos_t wMessageGetWidth(const char *string)
+{
+ return(wLabelWidth(string));
+}
wPos_t wMessageGetHeight( long flags )
{
diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c
index 90cf8fc..eaa39fe 100644
--- a/app/wlib/mswlib/mswpref.c
+++ b/app/wlib/mswlib/mswpref.c
@@ -149,7 +149,7 @@ void wPrefSetString( const char * section, const char * name, const char * sval
}
-const char * wPrefGetString( const char * section, const char * name )
+char * wPrefGetStringBasic( const char * section, const char * name )
{
prefs_t * p;
int rc;
@@ -181,7 +181,7 @@ void wPrefSetInteger( const char * section, const char * name, long lval )
}
-wBool_t wPrefGetInteger(
+wBool_t wPrefGetIntegerBasic(
const char * section,
const char * name,
long *res,
@@ -190,7 +190,7 @@ wBool_t wPrefGetInteger(
const char * cp;
char * cp1;
- cp = wPrefGetString( section, name );
+ cp = wPrefGetStringBasic( section, name );
if (cp == NULL) {
*res = def;
return FALSE;
@@ -218,7 +218,7 @@ void wPrefSetFloat(
}
-wBool_t wPrefGetFloat(
+wBool_t wPrefGetFloatBasic(
const char * section, /* Section */
const char * name, /* Name */
double * res, /* Address of result */
@@ -229,7 +229,7 @@ wBool_t wPrefGetFloat(
const char * cp;
char * cp1;
- cp = wPrefGetString( section, name );
+ cp = wPrefGetStringBasic( section, name );
if (cp == NULL) {
*res = def;
return FALSE;
diff --git a/app/wlib/mswlib/mswsplash.c b/app/wlib/mswlib/mswsplash.c
index bddd081..47df6b7 100644
--- a/app/wlib/mswlib/mswsplash.c
+++ b/app/wlib/mswlib/mswsplash.c
@@ -1,6 +1,5 @@
-/**
+/** \file mswsplash.c
* Splash window for Windows
- * $header$
*/
/* XTrkCad - Model Railroad CAD
@@ -60,6 +59,7 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp )
{
HDC hdc, hdcMem;
RECT rect;
+ HGDIOBJ oldObject;
UpdateWindow( hWnd );
@@ -69,10 +69,10 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp )
/* create a memory dc holding the bitmap */
hdcMem = CreateCompatibleDC( hdc );
- SelectObject( hdcMem, hBmp );
+ oldObject = SelectObject( hdcMem, hBmp );
/*
- show it in the uppler left corner
+ 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
*/
@@ -81,6 +81,7 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp )
hdcMem, 0, 0, SRCCOPY );
/* release the DCs that are not needed any more */
+ SelectObject(hdcMem, oldObject);
DeleteDC( hdcMem );
ReleaseDC( hWnd, hdc );
diff --git a/app/wlib/mswlib/mswstatus.c b/app/wlib/mswlib/mswstatus.c
new file mode 100644
index 0000000..f9d72f4
--- /dev/null
+++ b/app/wlib/mswlib/mswstatus.c
@@ -0,0 +1,110 @@
+/** \file mswstatus.c
+ * Status bar
+ */
+
+/* XTrkCad - Model Railroad CAD
+ * Copyright (C) 2005 Dave Bullis,
+ * 2017 Martin Fischer <m_fischer@sf.net>
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+#include "mswint.h"
+
+/**
+ * Set the message text
+ *
+ * \param b IN widget
+ * \param arg IN new text
+ * \return
+ */
+
+void wStatusSetValue(
+ wStatus_p b,
+ const char * arg)
+{
+ wMessageSetValue((wMessage_p)b, arg);
+}
+/**
+ * Create a window for a simple text.
+ *
+ * \param IN parent Handle of parent window
+ * \param IN x position in x direction
+ * \param IN y position in y direction
+ * \param IN labelStr ???
+ * \param IN width horizontal size of window
+ * \param IN message message to display ( null terminated )
+ * \param IN flags display options
+ * \return handle for created window
+ */
+
+wStatus_p wStatusCreate(
+ wWin_p parent,
+ wPos_t x,
+ wPos_t y,
+ const char * labelStr,
+ wPos_t width,
+ const char *message)
+{
+ return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0);
+}
+
+/**
+ * Get the anticipated length of a message field
+ *
+ * \param testString IN string that should fit into the message box
+ * \return expected width of message box
+ */
+
+wPos_t
+wStatusGetWidth(const char *testString)
+{
+ return (wMessageGetWidth(testString));
+}
+
+/**
+ * Get height of message text
+ *
+ * \param flags IN text properties (large or small size)
+ * \return text height
+ */
+
+wPos_t wStatusGetHeight(
+ long flags)
+{
+ return (wMessageGetHeight(flags));
+}
+
+/**
+ * Set the width of the widget
+ *
+ * \param b IN widget
+ * \param width IN new width
+ * \return
+ */
+
+void wStatusSetWidth(
+ wStatus_p b,
+ wPos_t width)
+{
+ wMessageSetWidth((wMessage_p)b, width);
+} \ No newline at end of file
diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c
index 95f6268..293e2b4 100644
--- a/app/wlib/mswlib/mswtext.c
+++ b/app/wlib/mswlib/mswtext.c
@@ -1,3 +1,25 @@
+/** \file mswtext.c
+* Text entry field
+*/
+
+/* XTrkCad - Model Railroad CAD
+* Copyright (C) 2005 Dave Bullis
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
#include <windows.h>
#include <string.h>
#include <malloc.h>
@@ -16,368 +38,406 @@
*/
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 );
+ long rc;
+ rc = SendMessage(b->hWnd, EM_SETREADONLY, 0, 0L);
#ifdef WIN32
- rc = SendMessage( b->hWnd, EM_SETSEL, 0, -1 );
+ rc = SendMessage(b->hWnd, EM_SETSEL, 0, -1);
#else
- rc = SendMessage( b->hWnd, EM_SETSEL, 1, MAKELONG( 0, -1 ) );
+ rc = SendMessage(b->hWnd, EM_SETSEL, 1, MAKELONG(0, -1));
#endif
- rc = SendMessage( b->hWnd, WM_CLEAR, 0, 0L );
- if ( b->option&BO_READONLY )
- rc = SendMessage( b->hWnd, EM_SETREADONLY, 1, 0L );
+ rc = SendMessage(b->hWnd, WM_CLEAR, 0, 0L);
+
+ if (b->option&BO_READONLY) {
+ rc = SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L);
+ }
}
+/**
+ * Append text to a multiline text box:
+ * For every \n a \r is added
+ * the current text is retrieved from the control
+ * the new text is appended and then set
+ *
+ * \param b IN text box handle
+ * \param text IN text to add to text box
+ * \return
+ */
void wTextAppend(
- wText_p b,
- const char * text )
+ wText_p b,
+ const char * text)
{
- HANDLE hMem;
- char * pMem, *cp;
- int len, textSize;
- long rc;
- long lc;
- len = strlen(text);
- if (len <= 0)
- return;
- for (cp= CAST_AWAY_CONST text; *cp; cp++) {
- if ( *cp == '\n' )
- len++;
- }
- hMem = GlobalAlloc( GHND, (DWORD)len+10+1 );
- pMem = (char*)GlobalLock( hMem );
- for (cp=pMem; *text; cp++,text++) {
- if (*text == '\n') {
- *cp++ = '\r';
- *cp = '\n';
- } else
- *cp = *text;
- }
- textSize = LocalSize( b->hText );
- if ((long)textSize+(long)len > 10000L) {
- if (len < 1024)
- len = 1024;
-#ifdef WIN32
- rc = SendMessage( b->hWnd, EM_SETSEL, 0, len );
-#else
- rc = SendMessage( b->hWnd, EM_SETSEL, 0, MAKELONG( 0, len ) );
-#endif
- rc = SendMessage( b->hWnd, WM_CLEAR, 0, 0L );
-#ifdef WIN32
- rc = SendMessage( b->hWnd, EM_SCROLLCARET, 0, 0 );
-#else
- rc = SendMessage( b->hWnd, EM_SETSEL, 0, MAKELONG( 32767, 32767 ) );
-#endif
- }
- lc = SendMessage( b->hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L );
- if ( lc < 0 )
- lc = 0;
- GlobalUnlock( hMem );
- rc = OpenClipboard( b->hWnd );
- rc = EmptyClipboard();
- rc = (long)SetClipboardData( CF_TEXT, hMem );
- rc = CloseClipboard();
- rc = SendMessage( b->hWnd, EM_SETREADONLY, 0, 0L );
- rc = SendMessage( b->hWnd, WM_PASTE, 0, 0L );
- lc -= SendMessage( b->hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L );
-#ifdef LATER
- if ( lc < 0 )
- SendMessage( b->hWnd, EM_LINESCROLL, 0, MAKELPARAM((WPARAM)lc,0) );
-#endif
- lc = GetWindowTextLength( b->hWnd );
- if ( b->option&BO_READONLY )
- rc = SendMessage( b->hWnd, EM_SETREADONLY, 1, 0L );
+ 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);
+ }
}
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, 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;
}
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();
- 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;
- 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) {
- EndPage( hDc );
+ 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;
+ }
+
+ docInfo.cbSize = sizeof(DOCINFO);
+ docInfo.lpszDocName = "XTrkcad Log";
+ docInfo.lpszOutput = (LPSTR)NULL;
+
+ // 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);
currentLine = 1;
- IOStatus = EndPage(hDc);
- if (IOStatus < 0 || textPrintAbort )
- break;
- StartPage( hDc );
}
- }
- if (IOStatus >= 0 && !textPrintAbort ) {
- EndPage( hDc );
- EndDoc( hDc );
- }
- DeleteDC( hDc );
- return TRUE;
+ }
+
+ if (IOStatus >= 0 && !textPrintAbort) {
+ EndPage(hDc);
+ EndDoc(hDc);
+ }
+
+ SelectObject(hDc, hOldFont);
+ 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, 0, 0L);
+ return (wBool_t)rc;
}
int wTextGetSize(
- wText_p b )
+ wText_p b)
{
- int lc, l, li, len=0;
- lc = (int)SendMessage( b->hWnd, EM_GETLINECOUNT, 0, 0L );
- for ( l=0; l<lc ; l++ ) {
- li = (int)SendMessage( b->hWnd, EM_LINEINDEX, l, 0L );
- len += (int)SendMessage( b->hWnd, EM_LINELENGTH, l, 0L ) + 1;
- }
- if ( len == 1 )
- len = 0;
- return len;
+ int lc, l, len=0;
+ lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L);
+
+ for (l=0; l<lc ; l++) {
+ int charIndex = (int)SendMessage(b->hWnd, EM_LINEINDEX, l, 0L);
+ len += (int)SendMessage(b->hWnd, EM_LINELENGTH, charIndex, 0L) + 1;
+ }
+
+ if (len == 1) {
+ len = 0;
+ }
+
+ return len;
}
void wTextGetText(
- wText_p b,
- char * t,
- int s )
+ wText_p b,
+ char * t,
+ int s)
{
- int lc, l, len;
- s--;
- lc = (int)SendMessage( b->hWnd, EM_GETLINECOUNT, 0, 0L );
- for ( l=0; l<lc && s>=0; l++ ) {
- *(WORD*)t = s;
- len = (int)SendMessage( b->hWnd, EM_GETLINE, l, (DWORD)(LPSTR)t );
- t += len;
- *t++ = '\n';
- s -= len+1;
- }
- *t++ = '\0';
+ int lc, l, len;
+ s--;
+ lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L);
+
+ for (l=0; l<lc && s>=0; l++) {
+ *(WORD*)t = s;
+ len = (int)SendMessage(b->hWnd, EM_GETLINE, l, (LPARAM)t);
+ t += len;
+ *t++ = '\n';
+ s -= len+1;
+ }
+
+ *(t - 1) = '\0'; // overwrite the last \n added
}
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;
- SendMessage( b->hWnd, EM_SETREADONLY, ro, 0L );
+ if (ro) {
+ b->option |= BO_READONLY;
+ } else {
+ b->option &= ~BO_READONLY;
+ }
+
+ SendMessage(b->hWnd, EM_SETREADONLY, ro, 0L);
}
void wTextSetSize(
- wText_p bt,
- wPos_t width,
- wPos_t height )
+ wText_p bt,
+ wPos_t width,
+ wPos_t 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");
- }
+ 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");
+ }
}
void wTextComputeSize(
- wText_p bt,
- int rows,
- int lines,
- wPos_t * w,
- wPos_t * h )
+ wText_p bt,
+ int rows,
+ int lines,
+ wPos_t * w,
+ wPos_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 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;
+ }
}
void wTextSetPosition(
- wText_p bt,
- int pos )
+ wText_p bt,
+ int pos)
{
- long rc;
- rc = SendMessage( bt->hWnd, EM_LINESCROLL, 0, MAKELONG( -65535, 0 ) );
+ long rc;
+ rc = SendMessage(bt->hWnd, EM_LINESCROLL, 0, MAKELONG(-65535, 0));
}
-static void textDoneProc( wControl_p b )
+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,
+ POS_T x,
+ POS_T y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ POS_T width,
+ POS_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;
- }
+ /* 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 );
+ Ctl3dSubclassCtl(b->hWnd);
#endif
- 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;
+ 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;
}