From d1a8285f818eb7e5c3d6a05709ea21a808490b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 19 Mar 2018 19:55:58 +0100 Subject: New upstream version 5.1.0 --- app/wlib/gtklib/CMakeLists.txt | 68 +- app/wlib/gtklib/ChangeLog | 250 -- app/wlib/gtklib/FindGTKUnixPrint.cmake | 49 - app/wlib/gtklib/bitmap.c | 1 + app/wlib/gtklib/boxes.c | 1 + app/wlib/gtklib/browserhelp.c | 137 + app/wlib/gtklib/button.c | 4 +- app/wlib/gtklib/control.c | 22 +- app/wlib/gtklib/droplist.c | 2 +- app/wlib/gtklib/font.c | 11 +- app/wlib/gtklib/gtkdraw-cairo.c | 47 +- app/wlib/gtklib/gtkint.h | 8 +- app/wlib/gtklib/ixhelp.c | 14 - app/wlib/gtklib/list.c | 2 + app/wlib/gtklib/liststore.c | 20 +- app/wlib/gtklib/main.c | 1 + app/wlib/gtklib/menu.c | 21 +- app/wlib/gtklib/message.c | 76 +- app/wlib/gtklib/notice.c | 3 +- app/wlib/gtklib/png.c | 1 + app/wlib/gtklib/print.c | 65 +- app/wlib/gtklib/statusbar.c | 211 ++ app/wlib/gtklib/text.c | 4 +- app/wlib/gtklib/tooltip.c | 31 +- app/wlib/gtklib/treeview.c | 1 + app/wlib/gtklib/util.c | 235 +- app/wlib/gtklib/window.c | 268 +- app/wlib/gtklib/wpref.c | 10 +- app/wlib/include/wcolors.h | 80 +- app/wlib/include/wlib.h | 57 +- app/wlib/mswlib/CMakeLists.txt | 1 + app/wlib/mswlib/ChangeLog | 146 - app/wlib/mswlib/mswbitmap.c | 26 +- app/wlib/mswlib/mswbutt.c | 22 + app/wlib/mswlib/mswdraw.c | 8 +- app/wlib/mswlib/mswedit.c | 2 +- app/wlib/mswlib/mswlist.c | 6 +- app/wlib/mswlib/mswmenu.c | 8 +- app/wlib/mswlib/mswmisc.c | 4811 ++++++++++++++++++-------------- app/wlib/mswlib/mswmsg.c | 4 + app/wlib/mswlib/mswpref.c | 10 +- app/wlib/mswlib/mswsplash.c | 9 +- app/wlib/mswlib/mswstatus.c | 110 + app/wlib/mswlib/mswtext.c | 636 +++-- 44 files changed, 4222 insertions(+), 3277 deletions(-) delete mode 100644 app/wlib/gtklib/ChangeLog delete mode 100644 app/wlib/gtklib/FindGTKUnixPrint.cmake create mode 100644 app/wlib/gtklib/browserhelp.c create mode 100644 app/wlib/gtklib/statusbar.c delete mode 100644 app/wlib/mswlib/ChangeLog create mode 100644 app/wlib/mswlib/mswstatus.c (limited to 'app/wlib') diff --git a/app/wlib/gtklib/CMakeLists.txt b/app/wlib/gtklib/CMakeLists.txt index a8cae9f..bf20e91 100644 --- a/app/wlib/gtklib/CMakeLists.txt +++ b/app/wlib/gtklib/CMakeLists.txt @@ -1,9 +1,7 @@ +# Setup GTK UI library... +file(GLOB headers *.h) -FILE(GLOB HEADERS *.h) - -INCLUDE (FindGTKUnixPrint.cmake) - -SET(SOURCES +set(sources bitmap.c boxes.c button.c @@ -25,6 +23,7 @@ SET(SOURCES print.c single.c splash.c + statusbar.c text.c timer.c tooltip.c @@ -32,32 +31,43 @@ SET(SOURCES util.c window.c wpref.c -# cproto and cppcheck - # end of refactored sources gtkdraw-cairo.c ) -IF(APPLE) - SET(SOURCES - ${SOURCES} - osxhelp.c) - -ELSE(APPLE) - SET(SOURCES - ${SOURCES} - ixhelp.c) -ENDIF(APPLE) - -SET_SOURCE_FILES_PROPERTIES(wpref.c PROPERTIES COMPILE_FLAGS -DEXPORT=) - -INCLUDE_DIRECTORIES(${XTrkCAD_BINARY_DIR}) -INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${GTK_UNIX_PRINT_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${GTK_WEBKIT_INCLUDE_DIRS}) - -ADD_LIBRARY(xtrkcad-wlib ${HEADERS} ${SOURCES}) -TARGET_LINK_LIBRARIES(xtrkcad-wlib ${GTK_LIBRARIES}) -TARGET_LINK_LIBRARIES(xtrkcad-wlib ${GTK_UNIX_PRINT_LIBRARIES}) -TARGET_LINK_LIBRARIES(xtrkcad-wlib ${GTK_WEBKIT_LIBRARIES}) +# help system is OS and build specific, add appropriate source files +if(APPLE) + set(sources + ${sources} + osxhelp.c) +else() + if(XTRKCAD_USE_BROWSER) + set(sources + ${sources} + browserhelp.c) + else() + set(sources + ${sources} + ixhelp.c) + endif() +endif() + +include_directories(${XTrkCAD_BINARY_DIR}) + +add_library(xtrkcad-wlib ${headers} ${sources}) + +# GTK +include_directories(${GTK_INCLUDE_DIRS}) +target_link_libraries(xtrkcad-wlib ${GTK_LIBRARIES}) + +# configure for GTK's native Unix print +find_package (GTKUnixPrint) +include_directories(${GTK_UNIX_PRINT_INCLUDE_DIRS}) +target_link_libraries(xtrkcad-wlib ${GTK_UNIX_PRINT_LIBRARIES}) + +# add dependency to webkit if configured +if(NOT XTRKCAD_USE_BROWSER) + include_directories(${GTK_WEBKIT_INCLUDE_DIRS}) + target_link_libraries(xtrkcad-wlib ${GTK_WEBKIT_LIBRARIES}) +endif() diff --git a/app/wlib/gtklib/ChangeLog b/app/wlib/gtklib/ChangeLog deleted file mode 100644 index ef2bd09..0000000 --- a/app/wlib/gtklib/ChangeLog +++ /dev/null @@ -1,250 +0,0 @@ -Apr 28, 2010 - FIX: Daniel Spagnol - gtkwindow.c, wpref.c: now, wGetAppLibDir can be called before - wWinMainCreate is called. - -Dec 12, 2009 - FIX: Martin Fischer - gtkint.h, gtkwindow.c: refactoring, remove unused globals and - added some comments. - -Dec 07, 2010 - FIX: Martin Fischer / Robert Heller - gtkfont.c: use newer Pango functions only after checking for correct - version at compile time. - -Oct 03, 2009 - FIX: Daniel Spagnol - gtkdraw-cairo.c: linux still crashed due to a cairo context access - after its drawable destruction - -Oct 03, 2009 - FIX: Daniel Spagnol - gtkbutton.c gtkint.h gtkmenu.c gtkmisc.c: workaround for OSX with - GTK-Quartz -> pixmaps are not rendered when using the mask; - and replaced gtk_pixmap_new deprecated function with - gtk_image_new_from_pixmap - -Oct 02, 2009 - FIX: Daniel Spagnol - gtkdraw-cairo.c: linux crashed due to a cairo context access after its - drawable destruction - -Sep 27, 2009 - FIX: Daniel Spagnol - gtkbitmap.c: image in about dialog box was not being displayed - -Sep 26, 2009 - FIX: Daniel Spagnol - gtkfont: deallocate PangoFontDescription using the right function - -Sep 25, 2009 - FIX: Daniel Spagnol - gtkbitmap.c: EXC_BAD_ACCESS when displaying about dialog - -Sep 25, 2009 - ENH: Daniel Spagnol - gtkdraw-cairo.c gtkdraw.c gtkfont.c gtkint.h gtksimple.c wlib.h: - replace the old font select dialog with the GTK standard one, and some - code cleanup - -Sep 23, 2009 - FIX: Martin Fischer - gtkbitmap.c gtkmisc.c: implement wCreateBitmap - -Sep 22, 2009 - FIX: Daniel Spagnol - gtkdraw-cairo.c: text in layout and selection were not aligned - -Sep 22, 2009 - FIX: Daniel Spagnol - CMakeLists.txt gtkbitmap.c gtkint.h: file created as a workaround to - get the source compiled under POSIX and OSX after wCreateBitmap - feature - -Aug 12, 2009 - ENH: Matthew Sheets - wpref.c: initialize with system default config from /etc - -Jul 29, 2009 - ENH: Martin Fischer - wpref.c: Create directory .xtrkcad silently - -Jun 24, 2009 - ENH: Martin Fischer - gtkwindow.c gtkmisc.c gtkint.h wpref.c: add option - to select configuration file - -Version 4.0.3a -============== - - -Jun 09, 2009 - FIX: Martin Fischer - gtkdraw.c: Fix compiler warning -May 31, 2009 - FIX: Martin Fischer - gtksplash.c: popups during startup are now shown above - splash screen - -May 31, 2009 - FIX: Martin Fischer - gtkmisc.c: fixed problem with some icons - -May 30, 2009 - FIX: Martin Fischer - gtklist.c: fixed the 'missing scrollbar' bug - finally! - -May 29, 2008 - FIX: Martin Fischer - gtkmisc.c: bug fix in wNoticeEx - -May 21, 2009 - ENH: Martin Fischer - gtkhelp.c: better error message - -May 15, 2009 - ENH: Martin Fischer - gtkwindow.c, gtkmisc.c, psprint.c, gtktext.c - gtkfilsel.c, gtksingle.c: new message box with icon - -Jul 11, 2008 - ENH: Martin Fischer - gtkwindow.c: closing app can now be canceled by the user - -Jul 11, 2008 - ENH: Steve DeCaux - gtdraw-cairo.c: convert strings to UTF8 - -Jul 01, 2008 - ENH: Martin Fischer - gtksplash.c: added #ifdef's for backward compatibility to GTK 2.4 - -Feb 01. 2008 - ENH: Martin Fischer - psprint.c, gtkint.h: added file selector for print to file, made - Postscript digit representation independent of current locale - -Jan 28, 2008 - ENH: Mikko Nissinen - gtkfilsel.c: Gettext support added. - -Jan 28, 2008 - FIX: Mikko Nissinen - gtkwindow.c: Dynamically allocate and form some global translatable - strings. - -Jan 27, 2008 - FIX: Mikko Nissinen - gtkhelp.c: String XTrkCad changed to XTrackCAD. - -Jan, 27, 2008 - FIX: Mikko Nissinen - gtkwindows.c: fixed problem with missing scroll bars - -Jan 24,2008 - IMPROVMENT: Martin Fischer - wpref.c: increase floting point precision when storing floats in rc - file - -Jan 22, 2008 - ENH: Mikko Nissinen - gtkwindow.c: wExit(): Free user locale before exit. - -Jan 21, 2008 - ENH: Gettext support added. Modified files: - gtkbutton.c - gtkfont.c - gtkhelp.c - gtklist.c - psprint.c - wpref.c - -Jan 20, 2008 - FIX: Mikko Nissinen - gtkdraw.c/gtkdraw-cairo.c: wDrawSetSize(): Return immediately, - if given width or height is negative. Negative values crashed - the program. This can be seen at least in Add Turnout and Add - Structure dialogs by resizing the dialog vertically smaller. - -Jan 16, 2008 - FIX: Mikko Nissinen - gtkmisc.c: gtkConvertInput(): If the input string is already - UTF-8 encoded, then return it untouched. - -Jan 15, 2008 - IMPROVEMENT: Mikko Nissinen - Basic gettext support added. - CMakeLists.txt - -Nov 30, 2007 - FIX: Timothy M. Shead - gtkfont.c: make sure that font initialization is run first - -Nov 29, 2007 - FIX: Martin Fischer - gtkhelp.c: an existing help window is now brought to the foreground - if the user selects Help - -Nov 12, 2007 - FIX: Mikko Nissinen - gtksimple.c: wMessageCreateEx -> Reset the pango font size back - to normal before returning the function. All dialogs created after - the tip of the day dialog had incorrectly positioned labels, - because the width of the text was calculated with the large font. - -Nov 12, 2007 - IMPROVEMENT: Martin Fischer - gtkhelp.c: Converted help system to gtkhtml-2. This allows to - us standard HTML files to be used for help documentation. - -Oct 28, 2007 - IMPROVEMENT: Martin Fischer - gtkmenu.c: Help drop-down is no longer right aligned. - -Sep 28, 2007 - IMPROVEMENT: Martin Fischer - gtksimple.c: wMessageCreate has been extended to - wMessageCreateEx. New function allows adding flags. Setting - a large or a small font are first uses. Added a compatibility - macro wMessageCreate for older code. - -Sep 15, 2007 - IMPROVEMENT: Martin Fischer - gtksplash.c: added splash window for program startup - -Jul 24, 2007 - IMPROVEMENT: Martin Fischer - gtkdraw.c: added support for wheel mouse - -Jun 16, 2007 - IMPROVEMENT: Martin Fischer - wpref.c: added wGetUserHomeDir() - -Feb 25, 2007 - BUGFIX: Martin Fischer - wpref.c: Rephrased error message for lib-directory not found - -Feb 23, 2007 - BUGFIX: Martin Fischer - gtkfont.c: Typo in window title corrected - -Version 4.0.1 -============= - -Mar, 30th 2006 - BUGFIX: Martin Fischer - gtkmisc.c: changed wPause to use SYSV signal handling funtions - -Mar, 29th 2006 - BUGFIX: Martin Fischer - gtkmisc.c, gtkbutton.c, gtksimple.c: small changes to help Solaris port - - IMPROVEMENT: Martin Fischer - wpref.c: Optimized the checking for directories in wGetAppLibDir and - rephrased the error message if initialization files cannot be found - - BUGFIX: Martin Fischer - gtkwindow.c: Fixed resizing problems when enlarging dialog boxes - - BUGFIX: diff --git a/app/wlib/gtklib/FindGTKUnixPrint.cmake b/app/wlib/gtklib/FindGTKUnixPrint.cmake deleted file mode 100644 index 06bc548..0000000 --- a/app/wlib/gtklib/FindGTKUnixPrint.cmake +++ /dev/null @@ -1,49 +0,0 @@ -# - Try to find gtk-unix-print -# Once done, this will define -# -# GTK_UNIX_PRINT_FOUND - system has gtk-unix-print -# GTK_UNIX_PRINT_INCLUDE_DIRS - the gtk-unix-print include directories -# GTK_UNIX_PRINT_LIBRARIES - link these to use gtk-unix-print -# -# Copyright (C) 2012 Raphael Kubo da Costa -# Copyright (C) 2014 Igalia S.L. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS -# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -find_package(PkgConfig) -pkg_check_modules(GTK_UNIX_PRINT gtk+-unix-print-2.0) -set(VERSION_OK TRUE) - -if (GTK_UNIX_PRINT_VERSION) - if (GTK_UNIX_PRINT_FIND_VERSION_EXACT) - if (NOT("${GTK_UNIX_PRINT_FIND_VERSION}" VERSION_EQUAL "${GTK_UNIX_PRINT_VERSION}")) - set(VERSION_OK FALSE) - endif () - else () - if ("${GTK_UNIX_PRINT_VERSION}" VERSION_LESS "${GTK_UNIX_PRINT_FIND_VERSION}") - set(VERSION_OK FALSE) - endif () - endif () -endif () - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK_UNIX_PRINT DEFAULT_MSG GTK_UNIX_PRINT_INCLUDE_DIRS GTK_UNIX_PRINT_LIBRARIES VERSION_OK) diff --git a/app/wlib/gtklib/bitmap.c b/app/wlib/gtklib/bitmap.c index dc7236b..eb5ef94 100644 --- a/app/wlib/gtklib/bitmap.c +++ b/app/wlib/gtklib/bitmap.c @@ -67,6 +67,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long options, wIcon_p iconP ) /* create the bitmap from supplied xpm data */ pixbuf = gdk_pixbuf_new_from_xpm_data( (const char **)iconP->bits ); + g_object_ref_sink(pixbuf); image = gtk_image_new_from_pixbuf( pixbuf ); gtk_widget_show( image ); g_object_unref( (gpointer)pixbuf ); diff --git a/app/wlib/gtklib/boxes.c b/app/wlib/gtklib/boxes.c index cce6649..cf419e6 100644 --- a/app/wlib/gtklib/boxes.c +++ b/app/wlib/gtklib/boxes.c @@ -129,6 +129,7 @@ void wlibDrawBox( cairo_stroke_preserve(cr); if (style < wBoxThickB) { + cairo_destroy(cr); return; } diff --git a/app/wlib/gtklib/browserhelp.c b/app/wlib/gtklib/browserhelp.c new file mode 100644 index 0000000..9351e86 --- /dev/null +++ b/app/wlib/gtklib/browserhelp.c @@ -0,0 +1,137 @@ +/** \file browserhelp.c + * use the default browser based help + */ + +/* XTrkCad - Model Railroad CAD + * Copyright (C) 2015 Martin Fischer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "gtkint.h" +#include "i18n.h" + +#include "dynstring.h" + +#define DEFAULTBROWSERCOMMAND "xdg-open" + +#define HELPERRORTEXT "Help Error - help information can not be found.\n" \ + "The help information you requested cannot be shown.\n" \ + "Usually this is an installation problem, Make sure that a default browser" \ + " is configured and that XTrackCAD and the included " \ + "HTML files are installed properly and can be found via the XTRKCADLIB environment " \ + "variable.\n Also make sure that the user has sufficient access rights to read these" \ + "files." +/** + * Create a fully qualified url froma topic + * + * \param helpUrl OUT pointer to url, free by caller + * \param topic IN the help topic + */ + +static void +TopicToUrl(char **helpUrl, const char *topic) +{ + DynString url; + DynStringMalloc(&url, 16); + + // build up the url line + DynStringCatCStrs(&url, + "file://", + wGetAppLibDir(), + "/html/", + topic, + ".html", + NULL); + + *helpUrl = strdup(DynStringToCStr(&url)); + DynStringFree(&url); +} +/** + * Extend the PATH variable inthe environment to include XTrackCAD's + * script directory. + * + * \return pointer to old path + */ + +static char * +ExtendPath(void) +{ + char *path = getenv("PATH"); + DynString newPath; + DynStringMalloc(&newPath, 16); + + // append XTrackCAD's directory to the path as a fallback + DynStringCatCStrs(&newPath, + path, + ":", + wGetAppLibDir(), + NULL); + + setenv("PATH", + DynStringToCStr(&newPath), + TRUE); + + DynStringFree(&newPath); + + return (path); +} + +/** + * Invoke the system's default browser to display help for . First the + * system's standard xdg-open command is attempted. If that is not available, the + * version included with the XTrackCAD installation is executed. + * + * \param topic IN topic string + */ + +void wHelp(const char * topic) +{ + int rc; + char *url; + DynString commandLine; + char *currentPath; + + assert(topic != NULL); + assert(strlen(topic)); + + currentPath = ExtendPath(); + TopicToUrl(&url, topic); + + DynStringMalloc(&commandLine, 16); + DynStringCatCStrs(&commandLine, + DEFAULTBROWSERCOMMAND, + " ", + url, + NULL); + + // the command should be found via the PATH + rc = system(DynStringToCStr(&commandLine)); + + if (rc) { + wNotice(HELPERRORTEXT, _("Cancel"), NULL); + } + + // restore the PATH + setenv("PATH", + currentPath, + TRUE); + + free(url); + DynStringFree(&commandLine); +} diff --git a/app/wlib/gtklib/button.c b/app/wlib/gtklib/button.c index d9f4880..b5fabe8 100644 --- a/app/wlib/gtklib/button.c +++ b/app/wlib/gtklib/button.c @@ -101,8 +101,8 @@ void wlibSetLabel( } else { gtk_image_set_from_pixbuf(GTK_IMAGE(*imageG), pixbuf); } - - g_object_unref(pixbuf); + g_object_ref_sink(pixbuf); + g_object_unref((gpointer)pixbuf); } else { if (*labelG==NULL) { *labelG = (GtkLabel*)gtk_label_new(wlibConvertInput(labelStr)); diff --git a/app/wlib/gtklib/control.c b/app/wlib/gtklib/control.c index e824c94..c891924 100644 --- a/app/wlib/gtklib/control.c +++ b/app/wlib/gtklib/control.c @@ -109,7 +109,9 @@ wPos_t wLabelWidth( GtkRequisition requisition; widget = gtk_label_new(wlibConvertInput(label)); gtk_widget_size_request(widget, &requisition); + g_object_ref_sink (widget); gtk_widget_destroy(widget); + g_object_unref(widget); return requisition.width+8; } @@ -162,7 +164,7 @@ wPos_t wControlGetPosX( wPos_t wControlGetPosY( wControl_p b) /* Control */ { - return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR)?MENUH:0); + return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0); } /** @@ -179,15 +181,21 @@ void wControlSetPos( wPos_t y) { b->realX = x; - b->realY = y + BORDERSIZE + ((b->parent->option&F_MENUBAR)?MENUH:0); + b->realY = y + BORDERSIZE + ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0); if (b->widget) { gtk_fixed_move(GTK_FIXED(b->parent->widget), b->widget, b->realX, b->realY); } if (b->label) { + GtkRequisition requisition, reqwidget; + gtk_widget_size_request(b->label, &requisition); + if (b->widget) + gtk_widget_size_request(b->widget, &reqwidget); + else + reqwidget.height = requisition.height; gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, b->realX-b->labelW, - b->realY+LABEL_OFFSET); + b->realY+(reqwidget.height/2 - requisition.height/2)); } } @@ -202,14 +210,18 @@ void wControlSetLabel( wControl_p b, const char * labelStr) { - GtkRequisition requisition; + GtkRequisition requisition,reqwidget; if (b->label) { gtk_label_set_text(GTK_LABEL(b->label), wlibConvertInput(labelStr)); gtk_widget_size_request(b->label, &requisition); + if (b->widget) + gtk_widget_size_request(b->widget, &reqwidget); + else + reqwidget.height = requisition.height; b->labelW = requisition.width+8; gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, b->realX-b->labelW, - b->realY+LABEL_OFFSET); + b->realY+(reqwidget.height/2 - requisition.height/2)); } else { b->labelW = wlibAddLabel(b, labelStr); } diff --git a/app/wlib/gtklib/droplist.c b/app/wlib/gtklib/droplist.c index 3252905..5fbdd17 100644 --- a/app/wlib/gtklib/droplist.c +++ b/app/wlib/gtklib/droplist.c @@ -416,7 +416,7 @@ wList_p wDropListCreate( if (b->widget == 0) { abort(); } - + g_object_ref_sink(b->listStore); g_object_unref(G_OBJECT(b->listStore)); wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS); diff --git a/app/wlib/gtklib/font.c b/app/wlib/gtklib/font.c index c54f7de..68ba87b 100644 --- a/app/wlib/gtklib/font.c +++ b/app/wlib/gtklib/font.c @@ -86,7 +86,7 @@ static void fontSelectionDialogCallback(GtkFontSelectionDialog *fontSelectionDialog, gint response, gpointer data) { if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) { - gchar *fontName; + gchar *fontName; fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog); wPrefSetString("font", "name", fontName); @@ -215,12 +215,14 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, pango_layout_set_font_description(layout, fontDescription); /* get layout measures */ pango_layout_get_pixel_size(layout, width_p, height_p); - context = gtk_widget_get_pango_context(widget); + context = gtk_widget_create_pango_context(widget); metrics = pango_context_get_metrics(context, fontDescription, pango_context_get_language(context)); *ascent_p = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics)); *descent_p = PANGO_PIXELS(pango_font_metrics_get_descent(metrics)); pango_font_metrics_unref(metrics); + g_object_ref_sink(context); + g_object_unref(context); #if WLIB_FONT_DEBUG >= 3 fprintf(stderr, "font layout created:\n"); fprintf(stderr, " widget: %p\n", widget); @@ -242,7 +244,8 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void wlibFontDestroyPangoLayout(PangoLayout *layout) { - g_object_unref(G_OBJECT(layout)); + g_object_ref_sink(layout); + g_object_unref(layout); } /** @@ -286,7 +289,7 @@ void wSelectFont( gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title); if (curFont != NULL) { - gchar *fontName; + gchar *fontName; /* the curFont description contains the latest font info * which is depended on the current scale diff --git a/app/wlib/gtklib/gtkdraw-cairo.c b/app/wlib/gtklib/gtkdraw-cairo.c index a19eb2b..4f3b1d2 100644 --- a/app/wlib/gtklib/gtkdraw-cairo.c +++ b/app/wlib/gtklib/gtkdraw-cairo.c @@ -174,8 +174,9 @@ static cairo_t* gtkDrawCreateCairoContext( } case wDrawLineDash: { - double dashes[] = { 5, 5 }; - cairo_set_dash(cairo, dashes, 2, 0); + double dashes[] = { 5, 3 }; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0); break; } } @@ -183,13 +184,14 @@ static cairo_t* gtkDrawCreateCairoContext( if(opts & wDrawOptTemp) { cairo_set_source_rgba(cairo, 0, 0, 0, 0); + cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); } else { GdkColor* const gcolor = wlibGetColor(color, TRUE); cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0); - cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); + cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); } return cairo; @@ -197,6 +199,7 @@ static cairo_t* gtkDrawCreateCairoContext( static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { cairo_destroy(cairo); + return NULL; } void wDrawDelayUpdate( @@ -442,7 +445,7 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { update_rect.x = (gint) x - ascent - descent - 1; update_rect.y = (gint) y - (gint) ascent - 1; update_rect.width = (gint) (w * cos( angle ) + 2 + ascent + descent); - update_rect.height = (gint) (w * sin( angle ) + ascent + descent + 2 ); + update_rect.height = (gint) (h * sin( angle ) + ascent + descent + 2 ); gtk_widget_draw(bd->widget, &update_rect); } @@ -469,8 +472,8 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { (int *) &ascent, (int *) &descent)); *w = (wPos_t) textWidth; - *h = (wPos_t) ascent; - *d = (wPos_t) descent; + *h = (wPos_t) textHeight; + *d = (wPos_t) textHeight-ascent; if (debugWindow >= 3) fprintf(stderr, "text metrics: w=%d, h=%d, d=%d\n", *w, *h, *d); @@ -693,7 +696,7 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { wDrawColor color, wDrawOpts opts ) { - GdkGC * gc; + //GdkGC * gc; GdkRectangle update_rect; int i, j, wb; wPos_t xx, yy; @@ -703,7 +706,8 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { x = INMAPX( bd, x-bm->x ); y = INMAPY( bd, y-bm->y )-bm->h; wb = (bm->w+7)/8; - gc = selectGC( bd, 0, wDrawLineSolid, color, opts ); + //gc = selectGC( bd, 0, wDrawLineSolid, color, opts ); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, 0, wDrawLineSolid, color, opts); for ( i=0; iw; i++ ) for ( j=0; jh; j++ ) @@ -732,7 +736,9 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { continue; } /*printf( "gdk_draw_point( %ld, gc, %d, %d )\n", (long)gdk_window, xx, yy );*/ - gdk_draw_point( gdk_window, gc, xx, yy ); + //gdk_draw_point( gdk_window, gc, xx, yy ); + cairo_rectangle(cairo, xx-0.5, yy-0.5, 1, 1); + cairo_fill(cairo); if ( b && b->type == B_DRAW ) { update_rect.x = xx-1; update_rect.y = yy-1; @@ -741,6 +747,7 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { gtk_widget_draw( b->widget, &update_rect ); } } + gtkDrawDestroyCairoContext(cairo); #ifdef LATER gdk_draw_pixmap(bd->pixmap, gc, bm->pixmap, @@ -836,9 +843,9 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { bd->pixmap = gdk_pixmap_new( bd->widget->window, w, h, -1 ); wDrawClear( bd ); - /*bd->redraw( bd, bd->context, w, h );*/ + bd->redraw( bd, bd->context, w, h ); } - /*wRedraw( bd );*/ + /*wRedraw( bd )*/; } @@ -996,7 +1003,8 @@ static gint draw_button_event( printf( "%s[%dx%d]\n", actionNames[action], bd->lastX, bd->lastY ); bd->action( bd, bd->context, action, bd->lastX, bd->lastY ); } - gtk_widget_grab_focus( bd->widget ); + if (!(bd->option & BD_NOFOCUS)) + gtk_widget_grab_focus( bd->widget ); return TRUE; } @@ -1032,7 +1040,8 @@ static gint draw_motion_event( if (drawVerbose >= 2) printf( "%lx: %s[%dx%d] %s\n", (long)bd, actionNames[action], bd->lastX, bd->lastY, event->is_hint?"":"<>" ); bd->action( bd, bd->context, action, bd->lastX, bd->lastY ); - gtk_widget_grab_focus( bd->widget ); + if (!(bd->option & BD_NOFOCUS)) + gtk_widget_grab_focus( bd->widget ); return TRUE; } @@ -1042,11 +1051,17 @@ static gint draw_char_event( GdkEventKey *event, wDraw_p bd ) { + GdkModifierType modifiers; guint key = event->keyval; wAccelKey_e extKey = wAccelKey_None; switch (key) { case GDK_KEY_Escape: key = 0x1B; break; - case GDK_KEY_Return: key = 0x0D; break; + case GDK_KEY_Return: + modifiers = gtk_accelerator_get_default_mod_mask(); + if (((event->state & modifiers)==GDK_CONTROL_MASK) || ((event->state & modifiers)==GDK_MOD1_MASK)) + extKey = wAccelKey_LineFeed; //If Return plus Control or Alt send in LineFeed + key = 0x0D; + break; case GDK_KEY_Linefeed: key = 0x0A; break; case GDK_KEY_Tab: key = 0x09; break; case GDK_KEY_BackSpace: key = 0x08; break; @@ -1141,7 +1156,9 @@ int xw, xh, cw, ch; (GtkSignalFunc) draw_char_event, bd); gtk_signal_connect (GTK_OBJECT (bd->widget), "leave_notify_event", (GtkSignalFunc) draw_leave_event, bd); - GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bd->widget), GTK_CAN_FOCUS); + gtk_widget_set_can_focus(bd->widget,!(option & BD_NOFOCUS)); + //if (!(option & BD_NOFOCUS)) + // GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bd->widget), GTK_CAN_FOCUS); gtk_widget_set_events (bd->widget, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK diff --git a/app/wlib/gtklib/gtkint.h b/app/wlib/gtklib/gtkint.h index da0d9ae..9f6be72 100644 --- a/app/wlib/gtklib/gtkint.h +++ b/app/wlib/gtklib/gtkint.h @@ -47,7 +47,7 @@ typedef enum { B_RADIO, B_TOGGLE, B_DRAW, B_MENU, B_MULTITEXT, B_MESSAGE, B_LINES, B_MENUITEM, B_BOX, - B_BITMAP } wType_e; + B_BITMAP, B_STATUS } wType_e; typedef void (*repaintProcCallback_p)( wControl_p ); typedef void (*doneProcCallback_p)( wControl_p b ); @@ -61,6 +61,7 @@ typedef void (*setTriggerCallback_p)( wControl_p b ); wPos_t realX, realY; \ wPos_t labelW; \ wPos_t w, h; \ + int maximize_initially; \ long option; \ const char * labelStr; \ repaintProcCallback_p repaintProc; \ @@ -78,9 +79,12 @@ struct wWin_t { wBool_t shown; /**< visibility state */ const char * nameStr; /**< window name (not title) */ GtkWidget * menubar; /**< menubar handle (if exists) */ + int menu_height; GdkGC * gc; /**< graphics context */ int gc_linewidth; /**< ??? */ wBool_t busy; + int resizeTimer; /** resizing **/ + int resizeW,resizeH; int modalLevel; }; @@ -113,7 +117,7 @@ struct wList_t { struct wListItem_t { wBool_t active; void * itemData; - const char * label; + char * label; GtkLabel * labelG; wBool_t selected; wList_p listP; diff --git a/app/wlib/gtklib/ixhelp.c b/app/wlib/gtklib/ixhelp.c index 6d85b2b..f1e3983 100644 --- a/app/wlib/gtklib/ixhelp.c +++ b/app/wlib/gtklib/ixhelp.c @@ -20,28 +20,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include #include -#include -#include -#include -#include -#include -#include #include -#include -#include - -#include #include "gtkint.h" #include "i18n.h" #include -#include "gtkint.h" -#include "i18n.h" - void load_into_view(char *file, int requested_view); // Prototype to please clang. diff --git a/app/wlib/gtklib/list.c b/app/wlib/gtklib/list.c index bf3a56e..8e99efe 100644 --- a/app/wlib/gtklib/list.c +++ b/app/wlib/gtklib/list.c @@ -486,6 +486,8 @@ wIndex_t wListAddValue( wlibTreeViewAddRow(b, (char *)labelStr, bm, id_p); } + free(id_p->label); + b->count++; b->recursion--; diff --git a/app/wlib/gtklib/liststore.c b/app/wlib/gtklib/liststore.c index eb53ea7..820366a 100644 --- a/app/wlib/gtklib/liststore.c +++ b/app/wlib/gtklib/liststore.c @@ -110,7 +110,8 @@ wlibListStoreGetContext(GtkListStore *ls, int inx) /** - * Clear the list store + * Clear the list store. All data in the list store will be automatically + * free'd when the list store is cleared. * * \param listStore IN */ @@ -118,9 +119,18 @@ wlibListStoreGetContext(GtkListStore *ls, int inx) void wlibListStoreClear(GtkListStore *listStore) { + wListItem_p id_p; + int i = 0; + assert(listStore != NULL); - /** \todo this looks like a memory leak. should probably free the id's */ + id_p = wlibListStoreGetContext(listStore, i++); + + while (id_p) { + g_free(id_p); + id_p = wlibListStoreGetContext(listStore, i++); + } + gtk_list_store_clear(listStore); } @@ -190,7 +200,9 @@ wlibListStoreUpdateIter(GtkListStore *ls, GtkTreeIter *iter, char *labels) } /** - * Add a pixbuf to the list store + * Add a pixbuf to the list store. So pixbuf is unref'ed so it will be freed + * with the list store. + * * \param ls IN list store * \param iter IN position * \param pixbuf IN pixbuf to add @@ -200,6 +212,8 @@ void wlibListStoreSetPixbuf(GtkListStore *ls, GtkTreeIter *iter, GdkPixbuf *pixbuf) { gtk_list_store_set(ls, iter, LISTCOL_BITMAP, pixbuf, -1); + g_object_ref_sink(pixbuf); + g_object_unref(pixbuf); } /** * Add a row to the list store diff --git a/app/wlib/gtklib/main.c b/app/wlib/gtklib/main.c index 9075687..470f17b 100644 --- a/app/wlib/gtklib/main.c +++ b/app/wlib/gtklib/main.c @@ -24,6 +24,7 @@ #include #include #include +#include #define GTK_DISABLE_SINGLE_INCLUDES #define GDK_DISABLE_DEPRECATED diff --git a/app/wlib/gtklib/menu.c b/app/wlib/gtklib/menu.c index fb115a3..d19805a 100644 --- a/app/wlib/gtklib/menu.c +++ b/app/wlib/gtklib/menu.c @@ -32,6 +32,7 @@ #include #include +#include #include "gtkint.h" #include "i18n.h" @@ -237,7 +238,14 @@ static wMenuItem_p createMenuItem( return mi; } - +/** + * Add a accelerator key to a widget + * + * @param w IN unused(?) + * @param menu IN unused(?) + * @param menu_item IN owning widget + * @param acclKey IN the accelerator key + */ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int acclKey ) { int mask; @@ -262,19 +270,12 @@ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int a mask = 0; if (acclKey) { - int len; - char acclStr[40]; - len = 0; if (acclKey&WALT) { mask |= GDK_MOD1_MASK; - strcpy( acclStr+len, "Meta+" ); - len += 5; } if (acclKey&WSHIFT) { mask |= GDK_SHIFT_MASK; - strcpy( acclStr+len, "Shift+" ); - len += 6; switch ( (acclKey&0xFF) ) { case '0': acclKey += ')'-'0'; break; case '1': acclKey += '!'-'1'; break; @@ -302,11 +303,7 @@ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int a } if (acclKey&WCTL) { mask |= GDK_CONTROL_MASK; - strcpy( acclStr+len, "Ctrl+" ); - len += 5; } - acclStr[len++] = (acclKey & 0xFF); - acclStr[len++] = '\0'; gtk_widget_add_accelerator( menu_item, "activate", (isalpha(acclKey&0xFF)?accel_alpha_group:accel_nonalpha_group), toupper(acclKey&0xFF), mask, GTK_ACCEL_VISIBLE|GTK_ACCEL_LOCKED ); diff --git a/app/wlib/gtklib/message.c b/app/wlib/gtklib/message.c index 396b696..af37d22 100644 --- a/app/wlib/gtklib/message.c +++ b/app/wlib/gtklib/message.c @@ -21,6 +21,7 @@ */ #include +#include #define GTK_DISABLE_SINGLE_INCLUDES #define GDK_DISABLE_DEPRECATED @@ -84,7 +85,6 @@ void wMessageSetWidth( /** * Get height of message text - * \todo Constant height doesn't make sense, change to use the window's properties and retrieve the real font size * * \param flags IN text properties (large or small size) * \return text height @@ -93,7 +93,45 @@ void wMessageSetWidth( wPos_t wMessageGetHeight( long flags) { - return 14; + GtkWidget * temp; + + if (!(flags&COMBOBOX)) { + temp = gtk_label_new("Test"); //To get size of text itself + } else { + temp = gtk_combo_box_text_new(); //to get max size of an object in infoBar + } + + if (wMessageSetFont(flags)) { + GtkStyle *style; + PangoFontDescription *fontDesc; + int fontSize; + /* get the current font descriptor */ + style = gtk_widget_get_style(temp); + fontDesc = style->font_desc; + /* get the current font size */ + fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); + + /* calculate the new font size */ + if (flags & BM_LARGE) { + pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); + } else { + pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); + } + + /* set the new font size */ + gtk_widget_modify_font(temp, fontDesc); + } + + if (flags&1L) { + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(temp),"Test"); + } + + GtkRequisition temp_requisition; + gtk_widget_size_request(temp,&temp_requisition); + g_object_ref_sink(temp); + gtk_widget_destroy(temp); + g_object_unref(temp); + return temp_requisition.height; } /** @@ -109,7 +147,7 @@ wPos_t wMessageGetHeight( * \return handle for created window */ - wMessage_p wMessageCreateEx( +wMessage_p wMessageCreateEx( wWin_p parent, wPos_t x, wPos_t y, @@ -147,7 +185,7 @@ wPos_t wMessageGetHeight( /* set the new font size */ gtk_widget_modify_font((GtkWidget *)b->labelWidget, fontDesc); } - + b->widget = gtk_fixed_new(); gtk_widget_size_request(GTK_WIDGET(b->labelWidget), &requisition); gtk_container_add(GTK_CONTAINER(b->widget), b->labelWidget); @@ -166,3 +204,33 @@ wPos_t wMessageGetHeight( return b; } + +/** + * 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 +wMessageGetWidth(const char *testString) +{ + GtkWidget *entry; + GtkRequisition requisition; + + return( wLabelWidth(testString)); +// entry = gtk_entry_new(); +// g_object_ref_sink(entry); +// +// gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE); +// gtk_entry_set_width_chars(GTK_ENTRY(entry), strlen(testString)); +// gtk_entry_set_max_length(GTK_ENTRY(entry), strlen(testString)); +// +// gtk_widget_size_request(entry, &requisition); +// +// gtk_widget_destroy(entry); +// g_object_unref(entry); +// +// return (requisition.width+8); +} + diff --git a/app/wlib/gtklib/notice.c b/app/wlib/gtklib/notice.c index cf4b59f..b72afd6 100644 --- a/app/wlib/gtklib/notice.c +++ b/app/wlib/gtklib/notice.c @@ -25,6 +25,7 @@ #include #include #include +#include #define GTK_DISABLE_SINGLE_INCLUDES #define GDK_DISABLE_DEPRECATED @@ -82,7 +83,7 @@ int wNoticeEx(int type, unsigned flag; char *headline; GtkWidget *dialog; - GtkWindow *parent = GTK_WINDOW_TOPLEVEL; + GtkWindow *parent = NULL; switch (type) { case NT_INFORMATION: diff --git a/app/wlib/gtklib/png.c b/app/wlib/gtklib/png.c index e11869e..809de6a 100644 --- a/app/wlib/gtklib/png.c +++ b/app/wlib/gtklib/png.c @@ -59,6 +59,7 @@ wBool_t wBitMapWriteFile(wDraw_p d, const char * fileName) return FALSE; } + g_object_ref_sink(pixbuf); g_object_unref(pixbuf); return TRUE; } diff --git a/app/wlib/gtklib/print.c b/app/wlib/gtklib/print.c index c0993f4..cad7e57 100644 --- a/app/wlib/gtklib/print.c +++ b/app/wlib/gtklib/print.c @@ -86,6 +86,8 @@ static double rBorder; /**< right margin */ static double lBorder; /**< left margin */ static double bBorder; /**< bottom margin */ +static double scale_adjust = 1.0; + static long printFormat = PRINT_LANDSCAPE; /***************************************************************************** @@ -118,7 +120,7 @@ WlibApplySettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { @@ -144,7 +146,7 @@ WlibApplySettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { @@ -193,7 +195,7 @@ WlibSaveSettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); g_error_free(err); gtk_dialog_run(GTK_DIALOG(dialog)); @@ -216,7 +218,7 @@ WlibSaveSettings(GtkPrintOperation *op) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); g_error_free(err); gtk_dialog_run(GTK_DIALOG(dialog)); @@ -279,21 +281,23 @@ static void setLineType( wDrawOpts opts) { cairo_t *cr = psPrint_d.printContext; - double dashLength = DASH_LENGTH; + + double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); if (lineWidth < 0.0) { - lineWidth = P2I(-lineWidth)*2.0; + lineWidth = P2I(-lineWidth)*2.0/scale_adjust; } // make sure that there is a minimum line width used - if (lineWidth == 0.0) { - lineWidth = 0.1; + if (lineWidth <= 0.09) { + lineWidth = 0.1/scale_adjust; } cairo_set_line_width(cr, lineWidth); if (lineType == wDrawLineDash) { - cairo_set_dash(cr, &dashLength, 1, 0.0); + cairo_set_dash(cr, dashes, len_dashes, 0.0); } else { cairo_set_dash(cr, NULL, 0, 0.0); } @@ -537,7 +541,7 @@ void psPrintFillCircle( /** * Print a string at the given position using specified font and text size. - * The orientatoion of the y-axis in XTrackCAD is wrong for cairo. So for + * The orientation of the y-axis in XTrackCAD is wrong for cairo. So for * all other print primitives a flip operation is done. As this would * also affect the string orientation, printing a string has to be * treated differently. The starting point is transformed, then the @@ -568,7 +572,8 @@ void psPrintString( { char * cp; double x0 = (double)x, y0 = (double)y; - double text_height; + int text_height, text_width; + double ascent; cairo_t *cr; cairo_matrix_t matrix; @@ -586,10 +591,13 @@ void psPrintString( // get the current transformation matrix and transform the starting // point of the string + + cairo_save(cr); + cairo_get_matrix(cr, &matrix); + cairo_matrix_transform_point(&matrix, &x0, &y0); - cairo_save(cr); layout = pango_cairo_create_layout(cr); @@ -597,26 +605,27 @@ void psPrintString( /** \todo use a getter function instead of double conversion */ desc = pango_font_description_from_string(wlibFontTranslate(fp)); - //don't know why the size has to be reduced to 75% :-( - pango_font_description_set_size(desc, fs * PANGO_SCALE *0.75); + pango_font_description_set_size(desc, fs * PANGO_SCALE ); // render the string to a Pango layout pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, s, -1); pango_layout_set_width(layout, -1); pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); + pango_layout_get_pixel_size(layout, &text_width, &text_height); // get the height of the string pcontext = pango_cairo_create_context(cr); metrics = pango_context_get_metrics(pcontext, desc, pango_context_get_language(pcontext)); - text_height = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; - // transform the string to the correct position + ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE * scale_adjust ; + cairo_identity_matrix(cr); - cairo_translate(cr, x0 + text_height * sin(-a * M_PI / 180.0) , - y0 - text_height * cos(a * M_PI / 180.0)); + cairo_translate(cr, x0 + ((ascent + (bBorder*scale_adjust)) * sin(-a * M_PI / 180.0))+((lBorder*scale_adjust)* cos(a * M_PI / 180.0)), + y0 - ((ascent + (bBorder*scale_adjust)) * cos( a * M_PI / 180.0))+((lBorder*scale_adjust)* sin(a * M_PI / 180.0))); + cairo_rotate(cr, -a * M_PI / 180.0); // set the color @@ -633,7 +642,7 @@ void psPrintString( } /** - * Create clipping retangle. + * Create clipping rectangle. * * \param x, y IN starting position * \param w, h IN width and height of rectangle @@ -800,6 +809,7 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) cairo_surface_type_t surface_type; cairo_matrix_t matrix; + printDialog = gtk_print_unix_dialog_new(title, GTK_WINDOW(gtkMainW->gtkwin)); // load the settings @@ -848,7 +858,10 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) if (surface_type == CAIRO_SURFACE_TYPE_PDF || surface_type == CAIRO_SURFACE_TYPE_PS || surface_type == CAIRO_SURFACE_TYPE_SVG) { - psPrint_d.dpi = 72; + double p_def=600; + cairo_surface_set_fallback_resolution (psPrint_d.curPrintSurface, p_def, p_def); + psPrint_d.dpi = p_def; + scale_adjust = 72/p_def; } else { psPrint_d.dpi = (double)gtk_print_settings_get_resolution(settings); } @@ -856,11 +869,13 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) // in XTrackCAD 0,0 is top left, in cairo bottom left. This is // corrected via the following transformations. // also the translate makes sure that the drawing is rendered - // within the paper margins + // within the paper margin + + cairo_translate(psPrint_d.printContext, lBorder*72, (paperHeight-bBorder)*72 ); + + cairo_scale(psPrint_d.printContext, 1.0 * scale_adjust, -1.0 * scale_adjust); - cairo_scale(psPrint_d.printContext, 1.0, -1.0); - cairo_translate(psPrint_d.printContext, lBorder * psPrint_d.dpi, - -(paperHeight-bBorder) *psPrint_d.dpi); + //cairo_translate(psPrint_d.printContext, 0, -paperHeight* psPrint_d.dpi); WlibSaveSettings(NULL); } @@ -900,7 +915,7 @@ doPrintJobFinished(GtkPrintJob *job, void *data, GError *err) dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - err->message); + "%s",err->message); } } diff --git a/app/wlib/gtklib/statusbar.c b/app/wlib/gtklib/statusbar.c new file mode 100644 index 0000000..3730eab --- /dev/null +++ b/app/wlib/gtklib/statusbar.c @@ -0,0 +1,211 @@ +/** \file statusbar.c + * Status bar + */ + +/* XTrkCad - Model Railroad CAD + * Copyright (C) 2005 Dave Bullis, + * 2017 Martin Fischer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + + +#include +#include + +#define GTK_DISABLE_SINGLE_INCLUDES +#define GDK_DISABLE_DEPRECATED +#define GTK_DISABLE_DEPRECATED +#define GSEAL_ENABLE + +#include +#include + +#include "gtkint.h" + +struct wStatus_t { + WOBJ_COMMON + GtkWidget * labelWidget; + const char * message; + wPos_t labelWidth; +}; + +/** + * Set the message text + * + * \param b IN widget + * \param arg IN new text + * \return + */ + +void wStatusSetValue( + wStatus_p b, + const char * arg) +{ + if (b->widget == 0) { + abort(); + } + + if (gtk_entry_get_max_length(GTK_ENTRY(b->labelWidget))labelWidget), strlen(arg)); + gtk_entry_set_width_chars(GTK_ENTRY(b->labelWidget), strlen(arg)); + } + + gtk_entry_set_text(GTK_ENTRY(b->labelWidget), wlibConvertInput(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) +{ + wStatus_p b; + GtkRequisition requisition; + b = (wStatus_p)wlibAlloc(parent, B_STATUS, x, y, NULL, sizeof *b, NULL); + wlibComputePos((wControl_p)b); + b->message = message; + b->labelWidth = width; + b->labelWidget = gtk_entry_new(); + gtk_editable_set_editable(GTK_EDITABLE(b->labelWidget), FALSE); + gtk_entry_set_has_frame(GTK_ENTRY(b->labelWidget), FALSE); + gtk_widget_set_can_focus(b->labelWidget, FALSE); + gtk_entry_set_text(GTK_ENTRY(b->labelWidget), + message?wlibConvertInput(message):""); + + b->widget = gtk_fixed_new(); + gtk_container_add(GTK_CONTAINER(b->widget), b->labelWidget); + wlibControlGetSize((wControl_p)b); + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + gtk_widget_show(b->widget); + gtk_widget_show(b->labelWidget); + wlibAddButton((wControl_p)b); + + return b; +} + +/** + * 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) +{ + GtkWidget *entry; + GtkRequisition requisition; + + entry = gtk_entry_new(); + g_object_ref_sink(entry); + + gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE); + gtk_entry_set_width_chars(GTK_ENTRY(entry), strlen(testString)); + gtk_entry_set_max_length(GTK_ENTRY(entry), strlen(testString)); + + gtk_widget_size_request(entry, &requisition); + + gtk_widget_destroy(entry); + g_object_unref(entry); + + return (requisition.width+8); +} + +/** + * Get height of message text + * + * \param flags IN text properties (large or small size) + * \return text height + */ + +wPos_t wStatusGetHeight( + long flags) +{ + GtkWidget * temp; + + if (!(flags&COMBOBOX)) { + temp = gtk_entry_new(); //To get size of text itself + gtk_entry_set_has_frame(GTK_ENTRY(temp), FALSE); + } else { + temp = gtk_combo_box_text_new(); //to get max size of an object in infoBar + } + g_object_ref_sink(temp); + + if (wMessageSetFont(flags)) { + GtkStyle *style; + PangoFontDescription *fontDesc; + int fontSize; + /* get the current font descriptor */ + style = gtk_widget_get_style(temp); + fontDesc = style->font_desc; + /* get the current font size */ + fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); + + /* calculate the new font size */ + if (flags & BM_LARGE) { + pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); + } else { + pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); + } + + /* set the new font size */ + gtk_widget_modify_font(temp, fontDesc); + } + + if (flags&1L) { + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(temp),"Test"); + } + + GtkRequisition temp_requisition; + gtk_widget_size_request(temp,&temp_requisition); + //g_object_ref_sink(temp); + //g_object_unref(temp); + gtk_widget_destroy(temp); + return temp_requisition.height; +} + +/** + * Set the width of the widget + * + * \param b IN widget + * \param width IN new width + * \return + */ + +void wStatusSetWidth( + wStatus_p b, + wPos_t width) +{ + b->labelWidth = width; + gtk_widget_set_size_request(b->widget, width, -1); +} diff --git a/app/wlib/gtklib/text.c b/app/wlib/gtklib/text.c index 5445984..f7ba288 100644 --- a/app/wlib/gtklib/text.c +++ b/app/wlib/gtklib/text.c @@ -360,12 +360,12 @@ wBool_t wTextPrint( dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - error->message); + "%s",error->message); g_error_free(error); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } - + g_object_ref_sink(operation); g_object_unref(operation); return TRUE; } diff --git a/app/wlib/gtklib/tooltip.c b/app/wlib/gtklib/tooltip.c index 15b46d2..20a1ba9 100644 --- a/app/wlib/gtklib/tooltip.c +++ b/app/wlib/gtklib/tooltip.c @@ -45,7 +45,7 @@ static int enableBalloonHelp = TRUE; static GtkWidget * balloonF; /**< balloon help control for hotbar item */ static GtkWidget * balloonPI; -static const char * balloonMsg = NULL; +static char balloonMsg[100] = ""; static wControl_p balloonB; static wPos_t balloonDx, balloonDy; static wBool_t balloonVisible = FALSE; @@ -136,54 +136,56 @@ void wControlSetBalloon( wControl_p b, wPos_t dx, wPos_t dy, const char * msg ) wPos_t w, h; wPos_t xx, yy; const char * msgConverted; - GtkAllocation size; + GtkRequisition size; /* return if there is nothing to do */ if (balloonVisible && balloonB == b && - balloonDx == dx && balloonDy == dy && msg != NULL && balloonMsg != NULL) + balloonDx == dx && balloonDy == dy && msg != NULL && !balloonMsg[0]) if (strcmp(msg,balloonMsg)==0) return; /* hide the tooltip */ if ( msg == NULL ) { - if ( balloonF != NULL ) { + if ( balloonF != NULL && balloonVisible) { gtk_widget_hide( balloonF ); balloonVisible = FALSE; } - balloonMsg = ""; + balloonMsg[0] = '\0'; return; } msgConverted = wlibConvertInput(msg); if ( balloonF == NULL ) { - GtkWidget *alignment; + //GtkWidget *alignment; - balloonF = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + balloonF = gtk_window_new( GTK_WINDOW_POPUP ); gtk_window_set_type_hint( GTK_WINDOW( balloonF), GDK_WINDOW_TYPE_HINT_TOOLTIP ); gtk_window_set_decorated (GTK_WINDOW (balloonF), FALSE ); gtk_window_set_resizable( GTK_WINDOW (balloonF), FALSE ); + gtk_window_set_accept_focus(GTK_WINDOW( balloonF), FALSE); - alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); + GtkWidget * alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); gtk_alignment_set_padding( GTK_ALIGNMENT(alignment), 6, 6, 6, 6 ); - + gtk_container_add (GTK_CONTAINER (balloonF), alignment); + gtk_widget_show (alignment); balloonPI = gtk_label_new(msgConverted); gtk_container_add( GTK_CONTAINER(alignment), balloonPI ); - gtk_widget_show( balloonPI ); + gtk_widget_show_all( balloonPI ); } gtk_label_set_text( GTK_LABEL(balloonPI), msgConverted ); balloonDx = dx; balloonDy = dy; balloonB = b; - balloonMsg = msg; - gtk_widget_get_allocation(balloonPI, &size ); + snprintf(balloonMsg, sizeof(balloonMsg), "%s", msg); + gtk_widget_get_requisition(balloonPI, &size ); w = size.width; h = size.height; - gdk_window_get_origin( gtk_widget_get_window( GTK_WIDGET(b->parent->gtkwin)), &x, &y ); + gtk_window_get_position( GTK_WINDOW(b->parent->gtkwin), &x, &y); x += b->realX + dx; y += b->realY + b->h - dy; @@ -200,7 +202,8 @@ void wControlSetBalloon( wControl_p b, wPos_t dx, wPos_t dy, const char * msg ) y = yy - h ; } gtk_window_move( GTK_WINDOW( balloonF ), x, y ); - gtk_widget_show( balloonF ); + gtk_widget_show_all( balloonF ); + gtk_widget_show( balloonPI ); balloonVisible = TRUE; } diff --git a/app/wlib/gtklib/treeview.c b/app/wlib/gtklib/treeview.c index e2f2259..2b743cb 100644 --- a/app/wlib/gtklib/treeview.c +++ b/app/wlib/gtklib/treeview.c @@ -326,6 +326,7 @@ wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf, gtk_tree_view_column_set_visible(column, TRUE); } + return 0; } diff --git a/app/wlib/gtklib/util.c b/app/wlib/gtklib/util.c index 61b5b95..e6587a0 100644 --- a/app/wlib/gtklib/util.c +++ b/app/wlib/gtklib/util.c @@ -23,6 +23,7 @@ #include #include #include +#include #define GTK_DISABLE_SINGLE_INCLUDES #define GDK_DISABLE_DEPRECATED @@ -74,7 +75,7 @@ static wBool_t reverseIcon = #endif - + /* ***************************************************************************** * @@ -91,7 +92,7 @@ static wBool_t reverseIcon = */ GdkPixbuf* wlibPixbufFromXBM( - wIcon_p ip ) + wIcon_p ip) { GdkPixbuf * pixbuf; @@ -99,39 +100,41 @@ GdkPixbuf* wlibPixbufFromXBM( char line2[40]; char ** pixmapData; - int row,col,wb; + int row, col, wb; long rgb; const char * bits; - wb = (ip->w+7)/8; - pixmapData = (char**)malloc((3+ip->h) * sizeof *pixmapData); + wb = (ip->w + 7) / 8; + pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData); pixmapData[0] = line0; rgb = wDrawGetRGB(ip->color); sprintf(line0, " %d %d 2 1", ip->w, ip->h); - sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb>>16)&0xFF, (rgb>>8)&0xFF, - rgb&0xFF); + sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb >> 16)&0xFF, (rgb >> 8)&0xFF, + rgb & 0xFF); pixmapData[1] = ". c None s None"; pixmapData[2] = line2; bits = ip->bits; - for (row = 0; rowh; row++) { - pixmapData[row+3] = (char*)malloc((ip->w+1) * sizeof **pixmapData); + for (row = 0; row < ip->h; row++) { + pixmapData[row + 3] = (char*) malloc((ip->w + 1) * sizeof **pixmapData); - for (col = 0; colw; col++) { - if (bits[ row*wb+(col>>3) ] & (1<<(col&07))) { - pixmapData[row+3][col] = '#'; - } else { - pixmapData[row+3][col] = '.'; + for (col = 0; col < ip->w; col++) { + if (bits[ row * wb + (col >> 3) ] & (1 << (col & 07))) { + pixmapData[row + 3][col] = '#'; + } + else { + pixmapData[row + 3][col] = '.'; } } - pixmapData[row+3][ip->w] = 0; + pixmapData[row + 3][ip->w] = 0; } - pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData); + pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) pixmapData); - for (row = 0; rowh; row++) { - free(pixmapData[row+3]); + for (row = 0; row < ip->h; row++) { + free(pixmapData[row + 3]); } + free(pixmapData); return pixbuf; } @@ -145,7 +148,7 @@ GdkPixbuf* wlibPixbufFromXBM( int wlibAddLabel(wControl_p b, const char * labelStr) { - GtkRequisition requisition; + GtkRequisition requisition, reqwidget; if (labelStr == NULL) { return 0; @@ -153,12 +156,15 @@ int wlibAddLabel(wControl_p b, const char * labelStr) b->label = gtk_label_new(wlibConvertInput(labelStr)); gtk_widget_size_request(b->label, &requisition); + if (b->widget) + gtk_widget_size_request(b->widget, &reqwidget); + else + reqwidget.height = requisition.height; gtk_container_add(GTK_CONTAINER(b->parent->widget), b->label); gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, - b->realX-requisition.width-8, b->realY+LABEL_OFFSET); - + b->realX - requisition.width - 8, b->realY + (reqwidget.height/2 - requisition.height/2)); gtk_widget_show(b->label); - return requisition.width+8; + return requisition.width + 8; } /** @@ -175,15 +181,15 @@ int wlibAddLabel(wControl_p b, const char * labelStr) */ void * wlibAlloc( - wWin_p parent, - wType_e type, - wPos_t origX, - wPos_t origY, - const char * labelStr, - int size, - void * data) + wWin_p parent, + wType_e type, + wPos_t origX, + wPos_t origY, + const char * labelStr, + int size, + void * data) { - wControl_p w = (wControl_p)malloc(size); + wControl_p w = (wControl_p) malloc(size); char * cp; memset(w, 0, size); @@ -197,7 +203,7 @@ void * wlibAlloc( w->origY = origY; if (labelStr) { - cp = (char*)malloc(strlen(labelStr)+1); + cp = (char*) malloc(strlen(labelStr) + 1); w->labelStr = cp; for (; *labelStr; labelStr++) @@ -220,19 +226,21 @@ void * wlibAlloc( */ void wlibComputePos( - wControl_p b) + wControl_p b) { wWin_p w = b->parent; if (b->origX >= 0) { b->realX = b->origX; - } else { + } + else { b->realX = w->lastX + (-b->origX) - 1; } if (b->origY >= 0) { - b->realY = b->origY + BORDERSIZE + ((w->option&F_MENUBAR)?MENUH:0); - } else { + b->realY = b->origY + BORDERSIZE + ((w->option & F_MENUBAR) ? w->menu_height : 0); + } + else { b->realY = w->lastY + (-b->origY) - 1; } } @@ -244,7 +252,7 @@ void wlibComputePos( */ void wlibControlGetSize( - wControl_p b) + wControl_p b) { GtkRequisition requisition; gtk_widget_size_request(b->widget, &requisition); @@ -258,14 +266,15 @@ void wlibControlGetSize( */ void wlibAddButton( - wControl_p b) + wControl_p b) { wWin_p win = b->parent; wBool_t resize = FALSE; if (win->first == NULL) { win->first = b; - } else { + } + else { win->last->next = b; } @@ -275,7 +284,7 @@ void wlibAddButton( win->lastX = b->realX + b->w; win->lastY = b->realY + b->h; - if (win->option&F_AUTOSIZE) { + if (win->option & F_AUTOSIZE) { if (win->lastX > win->realX) { win->realX = win->lastX; @@ -312,20 +321,20 @@ void wlibAddButton( */ wControl_p wlibGetControlFromPos( - wWin_p win, - wPos_t x, - wPos_t y) + wWin_p win, + wPos_t x, + wPos_t y) { wControl_p b; wPos_t xx, yy; - for (b=win->first; b != NULL; b = b->next) { + for (b = win->first; b != NULL; b = b->next) { if (b->widget && gtk_widget_get_visible(b->widget)) { xx = b->realX; yy = b->realY; - if (xx <= x && x < xx+b->w && - yy <= y && y < yy+b->h) { + if (xx <= x && x < xx + b->w && + yy <= y && y < yy + b->h) { return b; } } @@ -334,7 +343,7 @@ wControl_p wlibGetControlFromPos( return NULL; } - + /* ***************************************************************************** * @@ -352,13 +361,12 @@ void wBeep(void) gdk_display_beep(gdk_display_get_default()); } - /** * Flushs all commands to the Window. */ void wFlush( - void) + void) { while (gtk_events_pending()) { gtk_main_iteration(); @@ -427,36 +435,36 @@ char * wlibConvertInput(const char * inString) /* Already UTF-8 encoded? */ if (g_utf8_validate(inString, -1, NULL)) - /* Yes, do not double-convert */ - { - return (char*)inString; + /* Yes, do not double-convert */ { + return (char*) inString; } - for (cp=inString, extCharCnt=0; *cp; cp++) { + for (cp = inString, extCharCnt = 0; *cp; cp++) { if (((*cp)&0x80) != '\0') { extCharCnt++; } } - inCharCnt = cp-inString; + inCharCnt = cp - inString; if (extCharCnt == '\0') { - return (char*)inString; + return (char*) inString; } - DYNARR_SET(char, conversionBuffer_da, inCharCnt+extCharCnt+1); + DYNARR_SET(char, conversionBuffer_da, inCharCnt + extCharCnt + 1); - for (cp=inString, cq=(char*)conversionBuffer_da.ptr; *cp; cp++) { + for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) { if (((*cp)&0x80) != 0) { - *cq++ = 0xC0+(((*cp)&0xC0)>>6); - *cq++ = 0x80+((*cp)&0x3F); - } else { + *cq++ = 0xC0 + (((*cp)&0xC0) >> 6); + *cq++ = 0x80 + ((*cp)&0x3F); + } + else { *cq++ = *cp; } } *cq = 0; - return (char*)conversionBuffer_da.ptr; + return (char*) conversionBuffer_da.ptr; } /** @@ -472,31 +480,32 @@ char * wlibConvertOutput(const char * inString) char * cq; int extCharCnt, inCharCnt; - for (cp=inString, extCharCnt=0; *cp; cp++) { + for (cp = inString, extCharCnt = 0; *cp; cp++) { if (((*cp)&0xC0) == 0x80) { extCharCnt++; } } - inCharCnt = cp-inString; + inCharCnt = cp - inString; if (extCharCnt == '\0') { - return (char*)inString; + return (char*) inString; } - DYNARR_SET(char, conversionBuffer_da, inCharCnt+1); + DYNARR_SET(char, conversionBuffer_da, inCharCnt + 1); - for (cp=inString, cq=(char*)conversionBuffer_da.ptr; *cp; cp++) { + for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) { if (((*cp)&0x80) != 0) { - *cq++ = 0xC0+(((*cp)&0xC0)>>6); - *cq++ = 0x80+((*cp)&0x3F); - } else { + *cq++ = 0xC0 + (((*cp)&0xC0) >> 6); + *cq++ = 0x80 + ((*cp)&0x3F); + } + else { *cq++ = *cp; } } *cq = '\0'; - return (char*)conversionBuffer_da.ptr; + return (char*) conversionBuffer_da.ptr; } /*-----------------------------------------------------------------*/ @@ -506,30 +515,32 @@ static dynArr_t accelData_da; #define accelData(N) DYNARR_N( accelData_t, accelData_da, N ) static guint accelKeyMap[] = { - 0, /* wAccelKey_None, */ - GDK_KEY_Delete, /* wAccelKey_Del, */ - GDK_KEY_Insert, /* wAccelKey_Ins, */ - GDK_KEY_Home, /* wAccelKey_Home, */ - GDK_KEY_End, /* wAccelKey_End, */ - GDK_KEY_Page_Up, /* wAccelKey_Pgup, */ - GDK_KEY_Page_Down, /* wAccelKey_Pgdn, */ - GDK_KEY_Up, /* wAccelKey_Up, */ - GDK_KEY_Down, /* wAccelKey_Down, */ - GDK_KEY_Right, /* wAccelKey_Right, */ - GDK_KEY_Left, /* wAccelKey_Left, */ - GDK_KEY_BackSpace, /* wAccelKey_Back, */ - GDK_KEY_F1, /* wAccelKey_F1, */ - GDK_KEY_F2, /* wAccelKey_F2, */ - GDK_KEY_F3, /* wAccelKey_F3, */ - GDK_KEY_F4, /* wAccelKey_F4, */ - GDK_KEY_F5, /* wAccelKey_F5, */ - GDK_KEY_F6, /* wAccelKey_F6, */ - GDK_KEY_F7, /* wAccelKey_F7, */ - GDK_KEY_F8, /* wAccelKey_F8, */ - GDK_KEY_F9, /* wAccelKey_F9, */ - GDK_KEY_F10, /* wAccelKey_F10, */ - GDK_KEY_F11, /* wAccelKey_F11, */ - GDK_KEY_F12 /* wAccelKey_F12, */ + 0, /* wAccelKey_None, */ + GDK_KEY_Delete, /* wAccelKey_Del, */ + GDK_KEY_Insert, /* wAccelKey_Ins, */ + GDK_KEY_Home, /* wAccelKey_Home, */ + GDK_KEY_End, /* wAccelKey_End, */ + GDK_KEY_Page_Up, /* wAccelKey_Pgup, */ + GDK_KEY_Page_Down, /* wAccelKey_Pgdn, */ + GDK_KEY_Up, /* wAccelKey_Up, */ + GDK_KEY_Down, /* wAccelKey_Down, */ + GDK_KEY_Right, /* wAccelKey_Right, */ + GDK_KEY_Left, /* wAccelKey_Left, */ + GDK_KEY_BackSpace, /* wAccelKey_Back, */ + GDK_KEY_F1, /* wAccelKey_F1, */ + GDK_KEY_F2, /* wAccelKey_F2, */ + GDK_KEY_F3, /* wAccelKey_F3, */ + GDK_KEY_F4, /* wAccelKey_F4, */ + GDK_KEY_F5, /* wAccelKey_F5, */ + GDK_KEY_F6, /* wAccelKey_F6, */ + GDK_KEY_F7, /* wAccelKey_F7, */ + GDK_KEY_F8, /* wAccelKey_F8, */ + GDK_KEY_F9, /* wAccelKey_F9, */ + GDK_KEY_F10, /* wAccelKey_F10, */ + GDK_KEY_F11, /* wAccelKey_F11, */ + GDK_KEY_F12, /* wAccelKey_F12, */ + GDK_KEY_KP_Add, /* wAccelKey_Numpad_Add */ + GDK_KEY_KP_Subtract /* wAccelKey_Numpad_Subtract */ }; /** @@ -542,20 +553,20 @@ static guint accelKeyMap[] = { */ void wAttachAccelKey( - wAccelKey_e key, - int modifier, - wAccelKeyCallBack_p action, - void * data) + wAccelKey_e key, + int modifier, + wAccelKeyCallBack_p action, + void * data) { accelData_t * ad; - if (key < 1 || key > wAccelKey_F12) { - fprintf(stderr, "wAttachAccelKey(%d) out of range\n", (int)key); - return; - } +// if (key < 1 || key > wAccelKey_F12) { +// fprintf(stderr, "wAttachAccelKey(%d) out of range\n", (int) key); +// return; +// } DYNARR_APPEND(accelData_t, accelData_da, 10); - ad = &accelData(accelData_da.cnt-1); + ad = &accelData(accelData_da.cnt - 1); ad->key = key; ad->modifier = modifier; ad->action = action; @@ -570,7 +581,7 @@ void wAttachAccelKey( */ struct accelData_t * wlibFindAccelKey( - GdkEventKey * event) + GdkEventKey * event) { accelData_t * ad; int modifier = 0; @@ -587,9 +598,9 @@ struct accelData_t * wlibFindAccelKey( modifier |= WKEY_ALT; } - for (ad=&accelData(0); ad<&accelData(accelData_da.cnt); ad++) + for (ad = &accelData(0); ad<&accelData(accelData_da.cnt); ad++) if (event->keyval == accelKeyMap[ad->key] && - modifier == ad->modifier) { + modifier == ad->modifier) { return ad; } @@ -604,7 +615,7 @@ struct accelData_t * wlibFindAccelKey( */ wBool_t wlibHandleAccelKey( - GdkEventKey *event) + GdkEventKey *event) { accelData_t * ad = wlibFindAccelKey(event); @@ -615,7 +626,7 @@ wBool_t wlibHandleAccelKey( return FALSE; } - + /** * Add control to circular list of synonymous controls. Synonymous controls are kept in sync by * calling wControlLinkedActive for one member of the list @@ -652,8 +663,9 @@ void wControlLinkedActive(wControl_p b, int active) wControl_p savePtr = b; if (savePtr->type == B_MENUITEM) { - wMenuPushEnable((wMenuPush_p)savePtr, active); - } else { + wMenuPushEnable((wMenuPush_p) savePtr, active); + } + else { wControlActive(savePtr, active); } @@ -662,8 +674,9 @@ void wControlLinkedActive(wControl_p b, int active) while (savePtr && savePtr != b) { if (savePtr->type == B_MENUITEM) { - wMenuPushEnable((wMenuPush_p)savePtr, active); - } else { + wMenuPushEnable((wMenuPush_p) savePtr, active); + } + else { wControlActive(savePtr, active); } diff --git a/app/wlib/gtklib/window.c b/app/wlib/gtklib/window.c index 489f35e..65706fd 100644 --- a/app/wlib/gtklib/window.c +++ b/app/wlib/gtklib/window.c @@ -48,6 +48,7 @@ extern wBool_t listHelpStrings; static wControl_p firstWin = NULL, lastWin; static int keyState; static wBool_t gtkBlockEnabled = TRUE; +static wBool_t maximize_at_next_show = FALSE; /* ***************************************************************************** @@ -57,6 +58,44 @@ static wBool_t gtkBlockEnabled = TRUE; ***************************************************************************** */ +/** + * Get the "monitor" size for the window (strictly the nearest or most used monitor) + * Note in OSX there is one giant virtual monitor so this doesn't work to force resize down... + * + */ + +static GdkRectangle getMonitorDimensions(GtkWidget * widget) { + + GdkRectangle monitor_dimensions; + + GdkScreen *screen = NULL; + + int monitor; + + GtkWidget * toplevel = gtk_widget_get_toplevel(widget); + + if (gtk_widget_is_toplevel(GTK_WIDGET(toplevel)) && + gtk_widget_get_parent_window(GTK_WIDGET(toplevel))) { + + GdkWindow * window = GDK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(toplevel))); + + screen = gdk_window_get_screen(GDK_WINDOW(window)); + + monitor = gdk_screen_get_monitor_at_window(screen,GDK_WINDOW(window)); + + } else { + + screen = gdk_screen_get_default(); + + monitor = gdk_screen_get_primary_monitor(screen); + + } + + gdk_screen_get_monitor_geometry(screen,monitor,&monitor_dimensions); + + return monitor_dimensions; +} + /** * Get the window size from the resource (.rc) file. The size is saved under the key * SECTIONWINDOWSIZE.window name @@ -71,6 +110,16 @@ static void getWinSize(wWin_p win, const char * nameStr) const char *cp; char *cp1, *cp2; + /* + * Clamp window to be no bigger than one monitor size (to start - the user can always maximize) + */ + + GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); + + wPos_t maxDisplayWidth = monitor_dimensions.width-5; + wPos_t maxDisplayHeight = monitor_dimensions.height-25; + + if ((win->option&F_RESIZE) && (win->option&F_RECALLPOS) && (cp = wPrefGetString(SECTIONWINDOWSIZE, nameStr)) && @@ -84,6 +133,9 @@ static void getWinSize(wWin_p win, const char * nameStr) h = 10; } + if (w > maxDisplayWidth) w = maxDisplayWidth; + if (h > maxDisplayHeight) h = maxDisplayHeight; + win->w = win->origX = w; win->h = win->origY = h; win->option &= ~F_AUTOSIZE; @@ -103,7 +155,7 @@ static void saveSize(wWin_p win) if ((win->option&F_RESIZE) && (win->option&F_RECALLPOS) && gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) { - char pos_s[20]; + char pos_s[20]; sprintf(pos_s, "%d %d", win->w, win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0))); @@ -121,14 +173,13 @@ static void saveSize(wWin_p win) static void getPos(wWin_p win) { char *cp1, *cp2; - wPos_t gtkDisplayWidth = gdk_screen_width(); - wPos_t gtkDisplayHeight = gdk_screen_height(); + GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); if ((win->option&F_RECALLPOS) && (!win->shown)) { - const char *cp; + const char *cp; if ((cp = wPrefGetString(SECTIONWINDOWPOS, win->nameStr))) { - int x, y; + int x, y; x = strtod(cp, &cp1); @@ -142,12 +193,12 @@ static void getPos(wWin_p win) return; } - if (y > gtkDisplayHeight-win->h) { - y = gtkDisplayHeight-win->h; + if (y > monitor_dimensions.height+monitor_dimensions.y-win->h) { + y = monitor_dimensions.height+monitor_dimensions.y-win->h; } - if (x > gtkDisplayWidth-win->w) { - x = gtkDisplayWidth-win->w; + if (x > monitor_dimensions.width+monitor_dimensions.x-win->w) { + x = monitor_dimensions.width+monitor_dimensions.x-win->w; } if (x <= 0) { @@ -176,7 +227,7 @@ static void savePos(wWin_p win) int x, y; if ((win->option&F_RECALLPOS)) { - char pos_s[20]; + char pos_s[20]; gdk_window_get_position(gtk_widget_get_window(GTK_WIDGET(win->gtkwin)), &x, &y); x -= 5; @@ -216,7 +267,7 @@ void wWinGetSize( } *width = w; - *height = h - BORDERSIZE - ((win->option&F_MENUBAR)?MENUH:0); + *height = h - BORDERSIZE - ((win->option&F_MENUBAR)?win->menu_height:0); } /** @@ -234,8 +285,8 @@ void wWinSetSize( { win->busy = TRUE; win->w = width; - win->h = height + BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0); - gtk_widget_set_size_request(win->gtkwin, win->w, win->h); + win->h = height + BORDERSIZE + ((win->option&F_MENUBAR)?win->menu_height:0); + //gtk_widget_set_size_request(win->gtkwin, win->w, win->h); gtk_widget_set_size_request(win->widget, win->w, win->h); win->busy = FALSE; } @@ -271,11 +322,15 @@ void wWinShow( gtk_widget_size_request(win->gtkwin, &requisition); if (requisition.width != win->w || requisition.height != win->h) { - gtk_widget_set_size_request(win->gtkwin, win->w, win->h); - gtk_widget_set_size_request(win->widget, win->w, win->h); + //gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h); + gtk_widget_set_size_request(win->gtkwin, win->w, win->h); + gtk_widget_set_size_request(win->widget, win->w-20, win->h); if (win->option&F_MENUBAR) { - gtk_widget_set_size_request(win->menubar, win->w, MENUH); + gtk_widget_set_size_request(win->menubar, win->w-20, MENUH); + GtkAllocation allocation; + gtk_widget_get_allocation(win->menubar, &allocation); + win->menu_height = allocation.height; } } } @@ -299,6 +354,10 @@ void wWinShow( } else { wlibDoModal(win, TRUE); } + if (maximize_at_next_show) { + gtk_window_maximize(GTK_WINDOW(win->gtkwin)); + maximize_at_next_show = FALSE; + } } else { wFlush(); saveSize(win); @@ -339,6 +398,18 @@ wBool_t wWinIsVisible( return win->shown; } +/** + * Returns whether the window is maximized. + * + * \param win IN window + * \return TRUE if maximized, FALSE otherwise + */ + +wBool_t wWinIsMaximized(wWin_p win) +{ + return win->maximize_initially; +} + /** * Sets the title of to . * @@ -480,6 +551,25 @@ void wWinDoCancel( ****************************************************************************** */ +static int window_redraw( + wWin_p win, + wBool_t doWinProc) +{ + wControl_p b; + + if (win==NULL) { + return FALSE; + } + + for (b=win->first; b != NULL; b = b->next) { + if (b->repaintProc) { + b->repaintProc(b); + } + } + + return FALSE; +} + static gint window_delete_event( GtkWidget *widget, GdkEvent *event, @@ -511,25 +601,6 @@ static gint window_delete_event( return (TRUE); } -static int window_redraw( - wWin_p win, - wBool_t doWinProc) -{ - wControl_p b; - - if (win==NULL) { - return FALSE; - } - - for (b=win->first; b != NULL; b = b->next) { - if (b->repaintProc) { - b->repaintProc(b); - } - } - - return FALSE; -} - static int fixed_expose_event( GtkWidget * widget, GdkEventExpose * event, @@ -542,27 +613,37 @@ static int fixed_expose_event( } } +static int resizeTime(wWin_p win) { + + if (win->resizeW == win->w && win->resizeH == win->h) { // If hasn't changed since last + win->resizeTimer = 0; + return FALSE; //Stop Timer and don't resize + } + if (win->busy==FALSE && win->winProc) { //Always drive once + win->winProc(win, wResize_e, win->data); + win->resizeW = win->w; //Remember this one + win->resizeH = win->h; + } + return TRUE; //Will redrive after another timer interval +} + static int window_configure_event( GtkWidget * widget, GdkEventConfigure * event, wWin_p win) { -// wPos_t h; if (win==NULL) { return FALSE; } - //h = event->height - BORDERSIZE; - - //if (win->option&F_MENUBAR) { - //h -= MENUH; - //} - if (win->option&F_RESIZE) { if (event->width < 10 || event->height < 10) { return TRUE; } + int w = win->w; + int h = win->h; + if (win->w != event->width || win->h != event->height) { win->w = event->width; @@ -577,11 +658,18 @@ static int window_configure_event( } if (win->option&F_MENUBAR) { - gtk_widget_set_size_request(win->menubar, win->w, MENUH); + GtkAllocation allocation; + gtk_widget_get_allocation(win->menubar, &allocation); + win->menu_height= allocation.height; + gtk_widget_set_size_request(win->menubar, win->w-20, win->menu_height); } - - if (win->busy==FALSE && win->winProc) { - win->winProc(win, wResize_e, win->data); + if (win->resizeTimer) { // Already have a timer + return FALSE; + } else { + win->resizeW = w; //Remember where this started + win->resizeH = h; + win->resizeTimer = g_timeout_add(200,(GSourceFunc)resizeTime,win); // 200ms delay + return FALSE; } } } @@ -589,6 +677,38 @@ static int window_configure_event( return FALSE; } +/** + * Event handler for window state changes (maximize) + * Handles maximize event by storing the new state in the internal structure and + * calling the event handler + * + * \param widget gtk widget + * \param event event information + * \param win the wlib internal window data + * \return TRUE if win is valid, + */ + +gboolean window_state_event( + GtkWidget *widget, + GdkEventWindowState *event, + wWin_p win) +{ + if (!win) { + return (FALSE); + } + + win->maximize_initially = FALSE; + + if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) { + win->maximize_initially = TRUE; + } + + if (win->busy==FALSE && win->winProc) { + win->winProc(win, wState_e, win->data); + } + + return TRUE; +} /** * Get current state of shift, ctrl or alt keys. * @@ -680,19 +800,22 @@ static gint window_char_event( ******************************************************************************* */ + /** - * Create a window + * Create a window. + * Default width and height are replaced by values stored in the configuration + * file (.rc) * * \param parent IN parent window * \param winType IN type of window - * \param x IN x position - * \param y IN y position + * \param x IN default width + * \param y IN default height * \param labelStr IN window title - * \param nameStr IN - * \param option IN + * \param nameStr IN name of window + * \param option IN misc options for placement and sizing of window * \param winProc IN window procedure * \param data IN additional data to pass to the window procedure - * \return describe the return value + * \return the newly created window */ static wWin_p wWinCommonCreate( @@ -711,7 +834,9 @@ static wWin_p wWinCommonCreate( w = wlibAlloc(NULL, winType, x, y, labelStr, sizeof *w, data); w->busy = TRUE; w->option = option; - getWinSize(w, nameStr); + w->resizeTimer = 0; + + h = BORDERSIZE; if (w->option&F_MENUBAR) { @@ -728,6 +853,9 @@ static wWin_p wWinCommonCreate( GTK_WINDOW(gtkMainW->gtkwin)); } } + if (winType != W_MAIN) { + getWinSize(w, nameStr); + } if (option & F_HIDE) { gtk_widget_hide(w->gtkwin); @@ -738,6 +866,7 @@ static wWin_p wWinCommonCreate( gtk_window_set_position(GTK_WINDOW(w->gtkwin), GTK_WIN_POS_CENTER_ON_PARENT); } + w->widget = gtk_fixed_new(); if (w->widget == 0) { @@ -748,7 +877,10 @@ static wWin_p wWinCommonCreate( w->menubar = gtk_menu_bar_new(); gtk_container_add(GTK_CONTAINER(w->widget), w->menubar); gtk_widget_show(w->menubar); - gtk_widget_set_size_request(w->menubar, -1, MENUH); + GtkAllocation allocation; + gtk_widget_get_allocation(w->menubar, &allocation); + w->menu_height = allocation.height; + gtk_widget_set_size_request(w->menubar, -1, w->menu_height); } gtk_container_add(GTK_CONTAINER(w->gtkwin), w->widget); @@ -758,14 +890,14 @@ static wWin_p wWinCommonCreate( w->w = 0; w->realY = h; w->h = 0; - } else { + } else if (w->origX != 0){ w->w = w->realX = w->origX; w->h = w->realY = w->origY+h; - gtk_widget_set_size_request(w->gtkwin, w->w, w->h); - gtk_widget_set_size_request(w->widget, w->w, w->h); + gtk_window_set_default_size(GTK_WINDOW(w->gtkwin), w->w, w->h); + //gtk_widget_set_size_request(w->widget, w->w-20, w->h); if (w->option&F_MENUBAR) { - gtk_widget_set_size_request(w->menubar, w->w, MENUH); + gtk_widget_set_size_request(w->menubar, w->w-20, MENUH); } } @@ -777,6 +909,8 @@ static wWin_p wWinCommonCreate( G_CALLBACK(fixed_expose_event), w); g_signal_connect(GTK_OBJECT(w->gtkwin), "configure_event", G_CALLBACK(window_configure_event), w); + g_signal_connect(GTK_OBJECT(w->gtkwin), "window-state-event", + G_CALLBACK(window_state_event), w); g_signal_connect(GTK_OBJECT(w->gtkwin), "key_press_event", G_CALLBACK(window_char_event), w); g_signal_connect(GTK_OBJECT(w->gtkwin), "key_release_event", @@ -813,7 +947,16 @@ static wWin_p wWinCommonCreate( lastWin = (wControl_p)w; gtk_widget_show(w->widget); gtk_widget_realize(w->gtkwin); + GtkAllocation allocation; + gtk_widget_get_allocation(w->gtkwin, &allocation); + w->menu_height = allocation.height; + w->busy = FALSE; + + if (option&F_MAXIMIZE) { + maximize_at_next_show = TRUE; + } + return w; } @@ -846,8 +989,11 @@ wWin_p wWinMainCreate( void * data) /* User context */ { char *pos; + long isMaximized; - if (pos = strchr(name, ';')) { + pos = strchr(name, ';'); + + if (pos) { /* if found, split application name and configuration name */ strcpy(wConfigName, pos + 1); } else { @@ -855,8 +1001,12 @@ wWin_p wWinMainCreate( strcpy(wConfigName, name); } + wPrefGetInteger("draw", "maximized", &isMaximized, 0); + option = option | (isMaximized?F_MAXIMIZE:0); + gtkMainW = wWinCommonCreate(NULL, W_MAIN, x, y, labelStr, nameStr, option, winProc, data); + wDrawColorWhite = wDrawFindColor(0xFFFFFF); wDrawColorBlack = wDrawFindColor(0x000000); return gtkMainW; diff --git a/app/wlib/gtklib/wpref.c b/app/wlib/gtklib/wpref.c index effc2a5..c2541f9 100644 --- a/app/wlib/gtklib/wpref.c +++ b/app/wlib/gtklib/wpref.c @@ -312,7 +312,7 @@ void wPrefSetString( * \param name IN name of parameter */ -const char * wPrefGetString( +char * wPrefGetStringBasic( const char * section, /* Section */ const char * name ) /* Name */ { @@ -358,7 +358,7 @@ const char * wPrefGetString( * \return TRUE if value differs from default, FALSE if the same */ -wBool_t wPrefGetInteger( +wBool_t wPrefGetIntegerBasic( const char * section, /* Section */ const char * name, /* Name */ long * res, /* Address of result */ @@ -367,7 +367,7 @@ wBool_t wPrefGetInteger( const char * cp; char *cp1; - cp = wPrefGetString( section, name ); + cp = wPrefGetStringBasic( section, name ); if (cp == NULL) { *res = def; return FALSE; @@ -410,7 +410,7 @@ wBool_t wPrefGetInteger( */ -wBool_t wPrefGetFloat( +wBool_t wPrefGetFloatBasic( const char * section, /* Section */ const char * name, /* Name */ double * res, /* Address of result */ @@ -419,7 +419,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/include/wcolors.h b/app/wlib/include/wcolors.h index 46d15a8..525c98f 100644 --- a/app/wlib/include/wcolors.h +++ b/app/wlib/include/wcolors.h @@ -1,42 +1,42 @@ /* Some colors */ -#define wDrawColorWhite (0) -#define wDrawColorBlack (1) -#define wDrawColorRed (2) -#define wDrawColorGreen (3) -#define wDrawColorBlue (4) -#define wDrawColorYellow (5) -#define wDrawColorPurple (6) -#define wDrawColorAqua (7) -#define wDrawColorDkRed (8) -#define wDrawColorDkGreen (9) -#define wDrawColorDkBlue (10) -#define wDrawColorDkYellow (11) -#define wDrawColorDkPurple (12) -#define wDrawColorDkAqua (13) -#define wDrawColorRoyalBlue (14) -#define wDrawColorDeepSkyBlue (15) -#define wDrawColorLightSkyBlue (16) -#define wDrawColorSteelBlue (17) -#define wDrawColorPowderBlue (18) -#define wDrawColorAquamarine (19) -#define wDrawColorSeaGreen (20) -#define wDrawColorPaleGreen (21) -#define wDrawColorLawnGreen (22) -#define wDrawColorLimeGreen (23) -#define wDrawColorForestGreen (24) -#define wDrawColorGold (25) -#define wDrawColorRosyBrown (26) -#define wDrawColorSaddleBrown (27) -#define wDrawColorBeige (28) -#define wDrawColorTan (29) -#define wDrawColorChocolate (30) -#define wDrawColorBrown (31) -#define wDrawColorOrange (32) -#define wDrawColorCoral (33) -#define wDrawColorTomato (34) -#define wDrawColorHotPink (35) -#define wDrawColorPink (36) -#define wDrawColorMaroon (37) -#define wDrawColorViolet (38) -#define wDrawColorPurple2 (39) +//#define wDrawColorWhite (0) +//#define wDrawColorBlack (1) +//#define wDrawColorRed (2) +//#define wDrawColorGreen (3) +//#define wDrawColorBlue (4) +//#define wDrawColorYellow (5) +//#define wDrawColorPurple (6) +//#define wDrawColorAqua (7) +//#define wDrawColorDkRed (8) +//#define wDrawColorDkGreen (9) +//#define wDrawColorDkBlue (10) +//#define wDrawColorDkYellow (11) +//#define wDrawColorDkPurple (12) +//#define wDrawColorDkAqua (13) +//#define wDrawColorRoyalBlue (14) +//#define wDrawColorDeepSkyBlue (15) +//#define wDrawColorLightSkyBlue (16) +//#define wDrawColorSteelBlue (17) +//#define wDrawColorPowderBlue (18) +//#define wDrawColorAquamarine (19) +//#define wDrawColorSeaGreen (20) +//#define wDrawColorPaleGreen (21) +//#define wDrawColorLawnGreen (22) +//#define wDrawColorLimeGreen (23) +//#define wDrawColorForestGreen (24) +//#define wDrawColorGold (25) +//#define wDrawColorRosyBrown (26) +//#define wDrawColorSaddleBrown (27) +//#define wDrawColorBeige (28) +//#define wDrawColorTan (29) +//#define wDrawColorChocolate (30) +//#define wDrawColorBrown (31) +//#define wDrawColorOrange (32) +//#define wDrawColorCoral (33) +//#define wDrawColorTomato (34) +//#define wDrawColorHotPink (35) +//#define wDrawColorPink (36) +//#define wDrawColorMaroon (37) +//#define wDrawColorViolet (38) +//#define wDrawColorPurple2 (39) diff --git a/app/wlib/include/wlib.h b/app/wlib/include/wlib.h index fa07454..9d055d7 100644 --- a/app/wlib/include/wlib.h +++ b/app/wlib/include/wlib.h @@ -2,8 +2,8 @@ * Common definitions and declarations for the wlib library */ -#ifndef WIN_H -#define WIN_H +#ifndef HAVE_WLIB_H +#define HAVE_WLIB_H #ifdef WINDOWS #include <stdio.h> #define FILE_SEP_CHAR "\\" @@ -54,6 +54,7 @@ typedef struct wIcon_t * wIcon_p; typedef struct wDrawBitMap_t * wDrawBitMap_p; typedef struct wFont_t * wFont_p; typedef struct wBitmap_t * wBitmap_p; +typedef struct wStatus_t * wStatus_p; typedef int wDrawWidth; typedef int wDrawColor; @@ -204,6 +205,7 @@ FILE * wFileOpen( const char *, const char * ); typedef enum { wClose_e, wResize_e, + wState_e, wQuit_e, wRedraw_e } winProcEvent; @@ -220,7 +222,8 @@ typedef void (*wWinCallBack_p)( wWin_p, winProcEvent, void * ); #define F_RECALLSIZE (1L<<10) #define F_TOP (1L<<11) #define F_CENTER (1L<<12) -#define F_HIDE (1L<<12) +#define F_HIDE (1L<<13) +#define F_MAXIMIZE (1L<<14) wWin_p wWinMainCreate( const char *, wPos_t, wPos_t, const char *, const char *, const char *, long, wWinCallBack_p, void * ); @@ -232,6 +235,7 @@ void wWinSetBigIcon( wWin_p, wIcon_p ); void wWinSetSmallIcon( wWin_p, wIcon_p ); void wWinShow( wWin_p, wBool_t ); wBool_t wWinIsVisible( wWin_p ); +wBool_t wWinIsMaximized( wWin_p win); void wWinGetSize ( wWin_p, wPos_t *, wPos_t * ); void wWinSetSize( wWin_p, wPos_t, wPos_t ); void wWinSetTitle( wWin_p, const char * ); @@ -372,6 +376,7 @@ void wListSetEditable( wList_p, wBool_t ); #define BM_LARGE (1L<<24) #define BM_SMALL (1L<<25) +#define COMBOBOX (1L) #define wMessageSetFont( x ) ( x & (BM_LARGE | BM_SMALL )) @@ -381,6 +386,7 @@ wMessage_p wMessageCreateEx( wWin_p, wPos_t, wPos_t, const char *, void wMessageSetValue( wMessage_p, const char * ); void wMessageSetWidth( wMessage_p, wPos_t ); +wPos_t wMessageGetWidth( const char *testString ); wPos_t wMessageGetHeight( long ); @@ -466,7 +472,8 @@ typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wPos_t, wPos_t /* Creation Options */ #define BD_TICKS (1L<<25) #define BD_DIRECT (1L<<26) -#define BD_NOCAPTURE (1L<<27) +#define BD_NOCAPTURE (1L<<27) +#define BD_NOFOCUS (1L<<28) /* Create: */ wDraw_p wDrawCreate( wWin_p, wPos_t, wPos_t, const char *, long, @@ -594,7 +601,10 @@ typedef enum { wAccelKey_F9, wAccelKey_F10, wAccelKey_F11, - wAccelKey_F12 } + wAccelKey_F12, + wAccelKey_Numpad_Add, + wAccelKey_Numpad_Subtract, + wAccelKey_LineFeed } wAccelKey_e; /* Creation CallBacks */ @@ -677,16 +687,43 @@ wDrawColor wColorSelectButtonGetColor( wButton_p ); * Preferences */ -void wPrefSetString( const char *, const char *, const char * ); -const char * wPrefGetString( const char *, const char * ); -void wPrefSetInteger( const char *, const char *, long ); -wBool_t wPrefGetInteger( const char *, const char *, long *, long ); +void wPrefSetString(const char *, const char *, const char * ); +char * wPrefGetString(const char *section, const char *name); +char * wPrefGetStringBasic( const char *section, const char *name ); +char * wPrefGetStringExt(const char *section, const char *name); + +void wPrefSetInteger(const char *, const char *, long ); +wBool_t wPrefGetInteger(const char *section, const char *name, long *result, long defaultValue); +wBool_t wPrefGetIntegerBasic(const char *section, const char *name, long *result, long defaultValue); +wBool_t wPrefGetIntegerExt(const char *section, const char *name, long *result, long defaultValue); + void wPrefSetFloat( const char *, const char *, double ); -wBool_t wPrefGetFloat( const char *, const char *, double *, double ); +wBool_t wPrefGetFloat(const char *section, const char *name, double *result, double defaultValue); +wBool_t wPrefGetFloatBasic(const char *section, const char *name, double *result, double defaultValue); +wBool_t wPrefGetFloatExt(const char *section, const char *name, double *result, double defaultValue); + const char * wPrefGetSectionItem( const char * sectionName, wIndex_t * index, const char ** name ); void wPrefFlush( void ); void wPrefReset( void ); void CleanupCustom( void ); +/*------------------------------------------------------------------------------ + * + * Statusbar + */ + +wStatus_p wStatusCreate( + wWin_p parent, + wPos_t x, + wPos_t y, + const char * labelStr, + wPos_t width, + const char *message ); + +wPos_t wStatusGetWidth(const char *testString); +wPos_t wStatusGetHeight(long flags); + +void wStatusSetValue(wStatus_p b, const char * arg); +void wStatusSetWidth(wStatus_p b, wPos_t width); #endif 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; } -- cgit v1.2.3