summaryrefslogtreecommitdiff
path: root/app/wlib
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2024-07-03 10:19:30 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2024-07-03 10:19:30 +0200
commita14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 (patch)
treee469179df67a0e0db49161a43cbf8076a189f6f4 /app/wlib
parent5d2c2b27a6323e2666378b986129b2a7c2c39e5c (diff)
New upstream version 5.3.0GAupstream/5.3.0GAupstream
Diffstat (limited to 'app/wlib')
-rw-r--r--app/wlib/CMakeLists.txt23
-rw-r--r--app/wlib/gtklib/CMakeLists.txt101
-rw-r--r--app/wlib/gtklib/bitmap.c38
-rw-r--r--app/wlib/gtklib/boxes.c194
-rw-r--r--app/wlib/gtklib/browserhelp.c65
-rw-r--r--app/wlib/gtklib/button.c903
-rw-r--r--app/wlib/gtklib/color.c512
-rw-r--r--app/wlib/gtklib/control.c248
-rw-r--r--app/wlib/gtklib/droplist.c441
-rw-r--r--app/wlib/gtklib/dynarr.h10
-rw-r--r--app/wlib/gtklib/filesel.c201
-rw-r--r--app/wlib/gtklib/font.c362
-rw-r--r--app/wlib/gtklib/gtkdraw-cairo.c1276
-rw-r--r--app/wlib/gtklib/gtkint.h299
-rw-r--r--app/wlib/gtklib/help.c40
-rw-r--r--app/wlib/gtklib/ixhelp.c424
-rw-r--r--app/wlib/gtklib/lines.c132
-rw-r--r--app/wlib/gtklib/list.c522
-rw-r--r--app/wlib/gtklib/liststore.c219
-rw-r--r--app/wlib/gtklib/main.c30
-rw-r--r--app/wlib/gtklib/menu.c487
-rw-r--r--app/wlib/gtklib/message.c220
-rw-r--r--app/wlib/gtklib/notice.c344
-rw-r--r--app/wlib/gtklib/opendocument.c88
-rw-r--r--app/wlib/gtklib/osxhelp.c167
-rw-r--r--app/wlib/gtklib/pixbuf.c96
-rw-r--r--app/wlib/gtklib/print.c1067
-rw-r--r--app/wlib/gtklib/single.c244
-rw-r--r--app/wlib/gtklib/splash.c112
-rw-r--r--app/wlib/gtklib/statusbar.c201
-rw-r--r--app/wlib/gtklib/sysinfo.c137
-rw-r--r--app/wlib/gtklib/text.c592
-rw-r--r--app/wlib/gtklib/timer.c95
-rw-r--r--app/wlib/gtklib/tooltip.c237
-rw-r--r--app/wlib/gtklib/treeview.c424
-rw-r--r--app/wlib/gtklib/uthash.h102
-rw-r--r--app/wlib/gtklib/util.c827
-rw-r--r--app/wlib/gtklib/window.c1339
-rw-r--r--app/wlib/gtklib/wpref.c310
-rw-r--r--app/wlib/gtklib/writebitmap.c94
-rw-r--r--app/wlib/include/CMakeLists.txt12
-rw-r--r--app/wlib/include/getline.h132
-rw-r--r--app/wlib/include/getopt.h2
-rw-r--r--app/wlib/include/wlib.h313
-rw-r--r--app/wlib/mswlib/CMakeLists.txt90
-rw-r--r--app/wlib/mswlib/backgnd.c2
-rw-r--r--app/wlib/mswlib/checksum.c14
-rw-r--r--app/wlib/mswlib/dynarr.h8
-rw-r--r--app/wlib/mswlib/getline/LICENSE25
-rw-r--r--app/wlib/mswlib/getline/README.md5
-rw-r--r--app/wlib/mswlib/getline/getline.c73
-rw-r--r--app/wlib/mswlib/getopt.c87
-rw-r--r--app/wlib/mswlib/gwin32.c153
-rw-r--r--app/wlib/mswlib/mswbitmap.c240
-rw-r--r--app/wlib/mswlib/mswbox.c43
-rw-r--r--app/wlib/mswlib/mswbutt.c346
-rw-r--r--app/wlib/mswlib/mswchoic.c320
-rw-r--r--app/wlib/mswlib/mswcolor.c124
-rw-r--r--app/wlib/mswlib/mswdraw.c1682
-rw-r--r--app/wlib/mswlib/mswedit.c539
-rw-r--r--app/wlib/mswlib/mswint.h4
-rw-r--r--app/wlib/mswlib/mswlines.c51
-rw-r--r--app/wlib/mswlib/mswlist.c1211
-rw-r--r--app/wlib/mswlib/mswmenu.c674
-rw-r--r--app/wlib/mswlib/mswmisc.c766
-rw-r--r--app/wlib/mswlib/mswmsg.c103
-rw-r--r--app/wlib/mswlib/mswpref.c453
-rw-r--r--app/wlib/mswlib/mswprint.c135
-rw-r--r--app/wlib/mswlib/mswsplash.c191
-rw-r--r--app/wlib/mswlib/mswstatus.c32
-rw-r--r--app/wlib/mswlib/mswtext.c560
-rw-r--r--app/wlib/mswlib/simple-gettext.c600
-rw-r--r--app/wlib/mswlib/sysinfo.c138
-rw-r--r--app/wlib/mswlib/unittest/CMakeLists.txt16
-rw-r--r--app/wlib/mswlib/utf8conv.c277
-rw-r--r--app/wlib/test/testapp.c2
76 files changed, 11870 insertions, 10776 deletions
diff --git a/app/wlib/CMakeLists.txt b/app/wlib/CMakeLists.txt
index 4fa7469..7f7ee82 100644
--- a/app/wlib/CMakeLists.txt
+++ b/app/wlib/CMakeLists.txt
@@ -1,10 +1,19 @@
-PROJECT(wlib)
+project(wlib)
-INCLUDE_DIRECTORIES("${wlib_SOURCE_DIR}/include")
+add_library( xtrkcad-wlib
+ "")
-IF(XTRKCAD_USE_GTK)
- ADD_SUBDIRECTORY(gtklib)
-ELSE(XTRKCAD_USE_GTK)
- ADD_SUBDIRECTORY(mswlib)
-ENDIF(XTRKCAD_USE_GTK)
+add_subdirectory(include)
+
+# add i18n.h to include path
+target_include_directories(xtrkcad-wlib
+ PRIVATE
+ ${xtrkcad-lib_SOURCE_DIR}
+)
+
+if(XTRKCAD_USE_GTK)
+ add_subdirectory(gtklib)
+else()
+ add_subdirectory(mswlib)
+endif()
diff --git a/app/wlib/gtklib/CMakeLists.txt b/app/wlib/gtklib/CMakeLists.txt
index 117772a..6c673d9 100644
--- a/app/wlib/gtklib/CMakeLists.txt
+++ b/app/wlib/gtklib/CMakeLists.txt
@@ -1,7 +1,12 @@
# Setup GTK UI library...
-file(GLOB headers *.h)
-set(sources
+target_include_directories(xtrkcad-wlib
+ PRIVATE
+ ${xtrkcad-lib_SOURCE_DIR}
+)
+
+target_sources(xtrkcad-wlib
+ PRIVATE
bitmap.c
boxes.c
button.c
@@ -24,6 +29,7 @@ set(sources
single.c
splash.c
statusbar.c
+ sysinfo.c
text.c
timer.c
tooltip.c
@@ -32,66 +38,79 @@ set(sources
window.c
wpref.c
writebitmap.c
-# end of refactored sources
gtkdraw-cairo.c
- )
+)
# help system is OS and build specific, add appropriate source files
if(APPLE)
if (XTRKCAD_USE_APPLEHELP)
- set(sources
- ${sources}
+ target_sources(xtrkcad-wlib
+ PRIVATE
osxhelp.c)
- else(XTRKCAD_USE_APPLEHELP)
+ else()
if(XTRKCAD_USE_BROWSER)
- set(sources
- ${sources}
- browserhelp.c)
- else(XTRKCAD_USE_BROWSER)
- PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" REQUIRED)
- set(sources
- ${sources}
- ixhelp.c)
- endif(XTRKCAD_USE_BROWSER)
- endif(XTRKCAD_USE_APPLEHELP)
-else(APPLE)
+ target_sources(xtrkcad-wlib
+ PRIVATE
+ browserhelp.c)
+ else()
+ PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" REQUIRED)
+ target_sources(xtrkcad-wlib
+ PRIVATE
+ ixhelp.c)
+ endif()
+ endif()
+else()
if(XTRKCAD_USE_BROWSER)
- set(sources
- ${sources}
- browserhelp.c)
- else(XTRKCAD_USE_BROWSER)
+ target_sources(xtrkcad-wlib
+ PRIVATE
+ browserhelp.c)
+ else()
PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" REQUIRED)
- set(sources
- ${sources}
- ixhelp.c)
- endif(XTRKCAD_USE_BROWSER)
-endif(APPLE)
-
-include_directories(${XTrkCAD_BINARY_DIR})
-
-add_library(xtrkcad-wlib ${headers} ${sources})
+ target_sources(xtrkcad-wlib
+ PRIVATE
+ ixhelp.c)
+ endif()
+endif()
# GTK
find_package (GTK2)
-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})
+
+target_include_directories(xtrkcad-wlib
+ PRIVATE
+ ${GTK_INCLUDE_DIRS}
+ ${GTK_UNIX_PRINT_INCLUDE_DIRS}
+)
+target_link_libraries(xtrkcad-wlib
+ PRIVATE
+ dynstring
+ ${GTK_UNIX_PRINT_LIBRARIES}
+ ${GTK_LIBRARIES}
+)
# add dependency to webkit if configured
if (APPLE)
if(NOT XTRKCAD_USE_APPLEHELP)
if(NOT XTRKCAD_USE_BROWSER)
- include_directories(${GTK_WEBKIT_INCLUDE_DIRS})
- target_link_libraries(xtrkcad-wlib ${GTK_WEBKIT_LIBRARIES})
+ target_include_directories(xtrkcad-wlib
+ ${GTK_WEBKIT_INCLUDE_DIRS}
+ )
+ target_link_libraries(xtrkcad-wlib
+ PRIVATE
+ ${GTK_WEBKIT_LIBRARIES}
+ )
endif()
endif()
-else (APPLE)
+else ()
if(NOT XTRKCAD_USE_BROWSER)
- include_directories(${GTK_WEBKIT_INCLUDE_DIRS})
- target_link_libraries(xtrkcad-wlib ${GTK_WEBKIT_LIBRARIES})
+ target_include_directories(xtrkcad-wlib
+ ${GTK_WEBKIT_INCLUDE_DIRS}
+ )
+ target_link_libraries(xtrkcad-wlib
+ PRIVATE
+ ${GTK_WEBKIT_LIBRARIES}
+ )
endif()
-endif(APPLE)
+endif()
diff --git a/app/wlib/gtklib/bitmap.c b/app/wlib/gtklib/bitmap.c
index 7562e33..b1ff2ed 100644
--- a/app/wlib/gtklib/bitmap.c
+++ b/app/wlib/gtklib/bitmap.c
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@@ -46,54 +46,57 @@ struct wBitmap_t {
*/
wControl_p
-wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long options, const struct wIcon_t * iconP )
+wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long options,
+ const struct wIcon_t * iconP )
{
wBitmap_p bt;
GdkPixbuf *pixbuf;
GtkWidget *image;
-
+
bt = wlibAlloc( parent, B_BITMAP, x, y, NULL, sizeof *bt, NULL );
bt->w = iconP->w;
bt->h = iconP->h;
bt->option = options;
-
+
/*
- * Depending on the platform, parent->widget->window might still be null
+ * Depending on the platform, parent->widget->window might still be null
* at this point. The window allocation should be forced before creating
* the pixmap.
*/
- if ( gtk_widget_get_window( parent->widget ) == NULL )
- gtk_widget_realize( parent->widget ); /* force allocation, if pending */
-
+ if ( gtk_widget_get_window( parent->widget ) == NULL ) {
+ gtk_widget_realize( parent->widget ); /* force allocation, if pending */
+ }
+
/* 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 );
-
+
bt->widget = gtk_fixed_new();
gtk_widget_show( bt->widget );
gtk_container_add( GTK_CONTAINER(bt->widget), image );
-
+
wlibComputePos( (wControl_p)bt );
wlibControlGetSize( (wControl_p)bt );
gtk_fixed_put( GTK_FIXED( parent->widget ), bt->widget, bt->realX, bt->realY );
-
+
return( (wControl_p)bt );
}
/**
* Create a two-tone icon
- *
+ *
* \param w IN width of icon
* \param h IN height of icon
* \param bits IN bitmap
- * \param color IN color
+ * \param color IN color
* \returns icon handle
*/
-wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawColor color )
+wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits,
+ wDrawColor color )
{
wIcon_p ip;
ip = (wIcon_p)malloc( sizeof *ip );
@@ -101,7 +104,10 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol
ip->w = w;
ip->h = h;
ip->color = color;
- ip->bits = bits;
+ // Copy bits
+ int nBytes = ( ( w + 7 ) / 8 ) * h;
+ ip->bits = (char*)malloc( nBytes );
+ memcpy( (void*)ip->bits, bits, nBytes );
return ip;
}
@@ -125,7 +131,7 @@ wIcon_p wIconCreatePixMap( char *pm[] )
/**
* Set the color a two-tone icon
- *
+ *
* \param ip IN icon handle
* \param color IN color to use
*/
diff --git a/app/wlib/gtklib/boxes.c b/app/wlib/gtklib/boxes.c
index 74dbb7b..3c0173b 100644
--- a/app/wlib/gtklib/boxes.c
+++ b/app/wlib/gtklib/boxes.c
@@ -36,8 +36,8 @@
#include "gtkint.h"
struct wBox_t {
- WOBJ_COMMON
- wBoxType_e boxTyp;
+ WOBJ_COMMON
+ wBoxType_e boxTyp;
};
#define B (1)
@@ -60,12 +60,12 @@ struct wBox_t {
*/
void wBoxSetSize(
- wBox_p b,
- wWinPix_t w,
- wWinPix_t h)
+ wBox_p b,
+ wWinPix_t w,
+ wWinPix_t h)
{
- b->w = w;
- b->h = h;
+ b->w = w;
+ b->h = h;
}
/**
@@ -82,78 +82,78 @@ void wBoxSetSize(
*/
void wlibDrawBox(
- wWin_p win,
- wBoxType_e style,
- wWinPix_t x,
- wWinPix_t y,
- wWinPix_t w,
- wWinPix_t h)
+ wWin_p win,
+ wBoxType_e style,
+ wWinPix_t x,
+ wWinPix_t y,
+ wWinPix_t w,
+ wWinPix_t h)
{
- wWinPix_t x0, y0, x1, y1;
- GdkDrawable * window;
- cairo_t *cr;
- static char colors[8][4][2] = {
- { /* ThinB */ {B,0}, {B,0}, {B,0}, {B,0} },
- { /* ThinW */ {W,0}, {W,0}, {W,0}, {W,0} },
- { /* AboveW */ {W,0}, {W,0}, {B,0}, {B,0} },
- { /* BelowW */ {B,0}, {B,0}, {W,0}, {W,0} },
- { /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} },
- { /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} },
- { /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} },
- { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} }
- };
- window = gtk_widget_get_window(win->widget);
- cr = gdk_cairo_create(window);
- cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
- cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
- cairo_set_line_width(cr, 1.0);
- x0 = x;
- x1 = x+w;
- y0 = y;
- y1 = y+h;
- SETCOLOR(style, 0, 0);
- cairo_move_to(cr, x0, y0);
- cairo_line_to(cr, x0, y1);
- cairo_stroke_preserve(cr);
- SETCOLOR(style, 1, 0);
- cairo_move_to(cr, x0, y0);
- cairo_line_to(cr, x1, y0);
- cairo_stroke_preserve(cr);
- SETCOLOR(style, 2, 0);
- cairo_move_to(cr, x1, y1);
- cairo_line_to(cr, x0+1, y1);
- cairo_stroke_preserve(cr);
- SETCOLOR(style, 3, 0);
- cairo_move_to(cr, x1, y1-1);
- cairo_line_to(cr, x1, y0+1);
- cairo_stroke_preserve(cr);
-
- if (style < wBoxThickB) {
- cairo_destroy(cr);
- return;
- }
-
- x0++;
- y0++;
- x1--;
- y1--;
- SETCOLOR(style, 0, 1);
- cairo_move_to(cr, x0, y0);
- cairo_line_to(cr, x0, y1);
- cairo_stroke_preserve(cr);
- SETCOLOR(style, 1, 1);
- cairo_move_to(cr, x0+1, y0);
- cairo_line_to(cr, x1, y0);
- cairo_stroke_preserve(cr);
- SETCOLOR(style, 2, 1);
- cairo_move_to(cr, x1, y1);
- cairo_line_to(cr, x0+1, y1);
- cairo_stroke_preserve(cr);
- SETCOLOR(style, 3, 1);
- cairo_move_to(cr, x1, y1-1);
- cairo_line_to(cr, x1, y0+1);
- cairo_stroke_preserve(cr);
- cairo_destroy(cr);
+ wWinPix_t x0, y0, x1, y1;
+ GdkDrawable * window;
+ cairo_t *cr;
+ static char colors[8][4][2] = {
+ { /* ThinB */ {B,0}, {B,0}, {B,0}, {B,0} },
+ { /* ThinW */ {W,0}, {W,0}, {W,0}, {W,0} },
+ { /* AboveW */ {W,0}, {W,0}, {B,0}, {B,0} },
+ { /* BelowW */ {B,0}, {B,0}, {W,0}, {W,0} },
+ { /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} },
+ { /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} },
+ { /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} },
+ { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} }
+ };
+ window = gtk_widget_get_window(win->widget);
+ cr = gdk_cairo_create(window);
+ cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
+ cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
+ cairo_set_line_width(cr, 1.0);
+ x0 = x;
+ x1 = x+w;
+ y0 = y;
+ y1 = y+h;
+ SETCOLOR(style, 0, 0);
+ cairo_move_to(cr, x0, y0);
+ cairo_line_to(cr, x0, y1);
+ cairo_stroke_preserve(cr);
+ SETCOLOR(style, 1, 0);
+ cairo_move_to(cr, x0, y0);
+ cairo_line_to(cr, x1, y0);
+ cairo_stroke_preserve(cr);
+ SETCOLOR(style, 2, 0);
+ cairo_move_to(cr, x1, y1);
+ cairo_line_to(cr, x0+1, y1);
+ cairo_stroke_preserve(cr);
+ SETCOLOR(style, 3, 0);
+ cairo_move_to(cr, x1, y1-1);
+ cairo_line_to(cr, x1, y0+1);
+ cairo_stroke_preserve(cr);
+
+ if (style < wBoxThickB) {
+ cairo_destroy(cr);
+ return;
+ }
+
+ x0++;
+ y0++;
+ x1--;
+ y1--;
+ SETCOLOR(style, 0, 1);
+ cairo_move_to(cr, x0, y0);
+ cairo_line_to(cr, x0, y1);
+ cairo_stroke_preserve(cr);
+ SETCOLOR(style, 1, 1);
+ cairo_move_to(cr, x0+1, y0);
+ cairo_line_to(cr, x1, y0);
+ cairo_stroke_preserve(cr);
+ SETCOLOR(style, 2, 1);
+ cairo_move_to(cr, x1, y1);
+ cairo_line_to(cr, x0+1, y1);
+ cairo_stroke_preserve(cr);
+ SETCOLOR(style, 3, 1);
+ cairo_move_to(cr, x1, y1-1);
+ cairo_line_to(cr, x1, y0+1);
+ cairo_stroke_preserve(cr);
+ cairo_destroy(cr);
}
/**
@@ -165,9 +165,9 @@ void wlibDrawBox(
static void boxRepaint(wControl_p b)
{
- wBox_p bb = (wBox_p)(b);
- wWin_p win = bb->parent;
- wlibDrawBox(win, bb->boxTyp, bb->realX, bb->realY, bb->w, bb->h);
+ wBox_p bb = (wBox_p)(b);
+ wWin_p win = bb->parent;
+ wlibDrawBox(win, bb->boxTyp, bb->realX, bb->realY, bb->w, bb->h);
}
/**
@@ -184,21 +184,21 @@ static void boxRepaint(wControl_p b)
*/
wBox_p wBoxCreate(
- wWin_p parent,
- wWinPix_t bx,
- wWinPix_t by,
- const char * labelStr,
- wBoxType_e boxTyp,
- wWinPix_t bw,
- wWinPix_t bh)
+ wWin_p parent,
+ wWinPix_t bx,
+ wWinPix_t by,
+ const char * labelStr,
+ wBoxType_e boxTyp,
+ wWinPix_t bw,
+ wWinPix_t bh)
{
- wBox_p b;
- b = (wBox_p)wlibAlloc(parent, B_BOX, bx, by, labelStr, sizeof *b, NULL);
- wlibComputePos((wControl_p)b);
- b->boxTyp = boxTyp;
- b->w = bw;
- b->h = bh;
- b->repaintProc = boxRepaint;
- wlibAddButton((wControl_p)b);
- return b;
+ wBox_p b;
+ b = (wBox_p)wlibAlloc(parent, B_BOX, bx, by, labelStr, sizeof *b, NULL);
+ wlibComputePos((wControl_p)b);
+ b->boxTyp = boxTyp;
+ b->w = bw;
+ b->h = bh;
+ b->repaintProc = boxRepaint;
+ wlibAddButton((wControl_p)b);
+ return b;
}
diff --git a/app/wlib/gtklib/browserhelp.c b/app/wlib/gtklib/browserhelp.c
index 7d45ea5..6d2ac5d 100644
--- a/app/wlib/gtklib/browserhelp.c
+++ b/app/wlib/gtklib/browserhelp.c
@@ -17,12 +17,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <assert.h>
#include <string.h>
+#include <limits.h>
//#include "misc.h"
@@ -45,7 +46,8 @@ extern wBool_t CheckHelpTopicExists(const char * topic);
"variable.\n Also make sure that the user has sufficient access rights to read these" \
"files."
/**
- * Create a fully qualified url from a topic
+ * Create a fully qualified url from a topic. The library path is converted to
+ * an absolute path first. The url is then created from that path.
*
* \param helpUrl OUT pointer to url, free by caller
* \param topic IN the help topic
@@ -54,20 +56,29 @@ extern wBool_t CheckHelpTopicExists(const char * 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);
+ DynString url;
+ DynStringMalloc(&url, 16);
+ char *realPath;
+
+ realPath = realpath(wGetAppLibDir(), NULL);
+
+ if(realPath) {
+ // build up the url line
+ DynStringCatCStrs(&url,
+ "file://",
+ realPath,
+ "/html/",
+ topic,
+ ".html",
+ NULL);
+
+ *helpUrl = strdup(DynStringToCStr(&url));
+ DynStringFree(&url);
+ free(realPath);
+ } else {
+ wNoticeEx( NT_ERROR, _("Not enough memory for realpath()"), _("Exit"), NULL);
+ wExit(0);
+ }
}
/**
* Invoke the system's default browser to display help for <topic>. First the
@@ -79,22 +90,22 @@ TopicToUrl(char **helpUrl, const char *topic)
void wHelp(const char * topic)
{
- int rc;
- char *url;
- char *currentPath;
+ int rc;
+ char *url;
+// char *currentPath;
- assert(topic != NULL);
- assert(strlen(topic));
+ assert(topic != NULL);
+ assert(strlen(topic));
- if (!CheckHelpTopicExists(topic)) return;
-
- TopicToUrl(&url, topic);
+ if (!CheckHelpTopicExists(topic)) { return; }
+ TopicToUrl(&url, topic);
+ printf(">%s<\n", url);
rc = wOpenFileExternal(url);
if (!rc) {
- wNotice(HELPERRORTEXT, _("Cancel"), NULL);
- }
+ wNotice(HELPERRORTEXT, _("Cancel"), NULL);
+ }
- free(url);
+ free(url);
}
diff --git a/app/wlib/gtklib/button.c b/app/wlib/gtklib/button.c
index 9a8ec77..7193b11 100644
--- a/app/wlib/gtklib/button.c
+++ b/app/wlib/gtklib/button.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -53,17 +53,17 @@
void wButtonSetBusy(wButton_p bb, int value)
{
- bb->recursion++;
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), value);
- bb->recursion--;
- bb->busy = value;
- if (!value) {
- if (bb->timer_id) {
- g_source_remove(bb->timer_id);
- bb->timer_id = 0;
- }
- bb->timer_state = -1;
- }
+ bb->recursion++;
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), value);
+ bb->recursion--;
+ bb->busy = value;
+ if (!value) {
+ if (bb->timer_id) {
+ g_source_remove(bb->timer_id);
+ bb->timer_id = 0;
+ }
+ bb->timer_state = -1;
+ }
}
/**
@@ -77,57 +77,58 @@ void wButtonSetBusy(wButton_p bb, int value)
*/
void wlibSetLabel(
- GtkWidget *widget,
- long option,
- const char * labelStr,
- GtkLabel * * labelG,
- GtkWidget * * imageG)
+ GtkWidget *widget,
+ long option,
+ const char * labelStr,
+ GtkLabel * * labelG,
+ GtkWidget * * imageG)
{
- wIcon_p bm;
- GdkBitmap * mask;
-
- if (widget == 0) {
- abort();
- }
-
- if (labelStr) {
- if (option&BO_ICON) {
- GdkPixbuf *pixbuf;
-
- bm = (wIcon_p)labelStr;
-
- if (bm->gtkIconType == gtkIcon_pixmap) {
- pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)bm->bits);
- } else {
- pixbuf = wlibPixbufFromXBM( bm );
- }
- double scaleicon;
- wPrefGetFloat(PREFSECTION, LARGEICON, &scaleicon, 1.0);
- if (scaleicon<1.0) scaleicon=1.0;
- if (scaleicon>2.0) scaleicon=2.0;
- GdkPixbuf *pixbuf2 =
- gdk_pixbuf_scale_simple(pixbuf, gdk_pixbuf_get_width(pixbuf)*scaleicon, gdk_pixbuf_get_height(pixbuf)*scaleicon, GDK_INTERP_BILINEAR);
- g_object_ref_sink(pixbuf);
- g_object_unref((gpointer)pixbuf);
- if (*imageG==NULL) {
- *imageG = gtk_image_new_from_pixbuf(pixbuf2);
- gtk_container_add(GTK_CONTAINER(widget), *imageG);
- gtk_widget_show(*imageG);
- } else {
- gtk_image_set_from_pixbuf(GTK_IMAGE(*imageG), pixbuf2);
- }
- g_object_ref_sink(pixbuf2);
- g_object_unref((gpointer)pixbuf2);
- } else {
- if (*labelG==NULL) {
- *labelG = (GtkLabel*)gtk_label_new(wlibConvertInput(labelStr));
- gtk_container_add(GTK_CONTAINER(widget), (GtkWidget*)*labelG);
- gtk_widget_show((GtkWidget*)*labelG);
- } else {
- gtk_label_set_text(*labelG, wlibConvertInput(labelStr));
- }
- }
- }
+ wIcon_p bm;
+// GdkBitmap * mask;
+
+ if (widget == 0) {
+ abort();
+ }
+
+ if (labelStr) {
+ if (option&BO_ICON) {
+ GdkPixbuf *pixbuf;
+
+ bm = (wIcon_p)labelStr;
+
+ if (bm->gtkIconType == gtkIcon_pixmap) {
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)bm->bits);
+ } else {
+ pixbuf = wlibPixbufFromXBM( bm );
+ }
+ double scaleicon;
+ wPrefGetFloat(PREFSECTION, LARGEICON, &scaleicon, 1.0);
+ if (scaleicon<1.0) { scaleicon=1.0; }
+ if (scaleicon>2.0) { scaleicon=2.0; }
+ GdkPixbuf *pixbuf2 =
+ gdk_pixbuf_scale_simple(pixbuf, gdk_pixbuf_get_width(pixbuf)*scaleicon,
+ gdk_pixbuf_get_height(pixbuf)*scaleicon, GDK_INTERP_BILINEAR);
+ g_object_ref_sink(pixbuf);
+ g_object_unref((gpointer)pixbuf);
+ if (*imageG==NULL) {
+ *imageG = gtk_image_new_from_pixbuf(pixbuf2);
+ gtk_container_add(GTK_CONTAINER(widget), *imageG);
+ gtk_widget_show(*imageG);
+ } else {
+ gtk_image_set_from_pixbuf(GTK_IMAGE(*imageG), pixbuf2);
+ }
+ g_object_ref_sink(pixbuf2);
+ g_object_unref((gpointer)pixbuf2);
+ } else {
+ if (*labelG==NULL) {
+ *labelG = (GtkLabel*)gtk_label_new(wlibConvertInput(labelStr));
+ gtk_container_add(GTK_CONTAINER(widget), (GtkWidget*)*labelG);
+ gtk_widget_show((GtkWidget*)*labelG);
+ } else {
+ gtk_label_set_text(*labelG, wlibConvertInput(labelStr));
+ }
+ }
+ }
}
/**
@@ -138,7 +139,7 @@ void wlibSetLabel(
void wButtonSetLabel(wButton_p bb, const char * labelStr)
{
- wlibSetLabel(bb->widget, bb->option, labelStr, &bb->labelG, &bb->imageG);
+ wlibSetLabel(bb->widget, bb->option, labelStr, &bb->labelG, &bb->imageG);
}
/**
@@ -148,11 +149,11 @@ void wButtonSetLabel(wButton_p bb, const char * labelStr)
*/
void wlibButtonDoAction(
- wButton_p bb)
+ wButton_p bb)
{
- if (bb->action) {
- bb->action(bb->data);
- }
+ if (bb->action) {
+ bb->action(bb->data);
+ }
}
@@ -163,23 +164,23 @@ void wlibButtonDoAction(
*/
static void pushButt(
- GtkWidget *widget,
- gpointer value)
+ GtkWidget *widget,
+ gpointer value)
{
- wButton_p b = (wButton_p)value;
+ wButton_p b = (wButton_p)value;
- if (debugWindow >= 2) {
- printf("%s button pushed\n", b->labelStr?b->labelStr:"No label");
- }
+ if (debugWindow >= 2) {
+ printf("%s button pushed\n", b->labelStr?b->labelStr:"No label");
+ }
- if (b->recursion) {
- return;
- }
+ if (b->recursion) {
+ return;
+ }
- wlibStringUpdate();
- if (b->action) {
- b->action(b->data);
- }
+ wlibStringUpdate();
+ if (b->action) {
+ b->action(b->data);
+ }
}
@@ -192,52 +193,55 @@ static void pushButt(
static int timer_func ( void * data)
{
wButton_p bb = (wButton_p)data;
- if (bb->timer_id == 0) {
- bb->timer_state = -1;
- return FALSE;
- }
- /* Autorepeat state machine */
- switch (bb->timer_state) {
- case 0: /* Enable slow auto-repeat */
- g_source_remove(bb->timer_id);
- bb->timer_id = 0;
- bb->timer_state = 1;
- bb->timer_id = g_timeout_add( REPEAT_STAGE1_DELAY, timer_func, bb);
- bb->timer_count = 0;
- break;
- case 1: /* Check if it's time for fast repeat yet */
- if (bb->timer_count++ > 10)
- bb->timer_state = 2;
- break;
- case 2: /* Start fast auto-repeat */
- g_source_remove(bb->timer_id);
- bb->timer_id = 0;
- bb->timer_state = 3;
- bb->timer_id = g_timeout_add( REPEAT_STAGE2_DELAY, timer_func, bb);
- break;
- case 3:
- break;
- default:
- g_source_remove(bb->timer_id);
- bb->timer_id = 0;
- bb->timer_state = -1;
- return FALSE;
- break;
- }
-
- pushButt(NULL,bb);
-
- return TRUE;
+ if (bb->timer_id == 0) {
+ bb->timer_state = -1;
+ return FALSE;
+ }
+ /* Autorepeat state machine */
+ switch (bb->timer_state) {
+ case 0: /* Enable slow auto-repeat */
+ g_source_remove(bb->timer_id);
+ bb->timer_id = 0;
+ bb->timer_state = 1;
+ bb->timer_id = g_timeout_add( REPEAT_STAGE1_DELAY, timer_func, bb);
+ bb->timer_count = 0;
+ break;
+ case 1: /* Check if it's time for fast repeat yet */
+ if (bb->timer_count++ > 10) {
+ bb->timer_state = 2;
+ }
+ break;
+ case 2: /* Start fast auto-repeat */
+ g_source_remove(bb->timer_id);
+ bb->timer_id = 0;
+ bb->timer_state = 3;
+ bb->timer_id = g_timeout_add( REPEAT_STAGE2_DELAY, timer_func, bb);
+ break;
+ case 3:
+ break;
+ default:
+ g_source_remove(bb->timer_id);
+ bb->timer_id = 0;
+ bb->timer_state = -1;
+ return FALSE;
+ break;
+ }
+
+ pushButt(NULL,bb);
+
+ return TRUE;
}
static gint pressButt(
- GtkWidget *widget,
- GdkEventButton *event,
- wButton_p bb) {
+ GtkWidget *widget,
+ GdkEventButton *event,
+ wButton_p bb)
+{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "buttonPress: %s\n", bb->labelStr );
+ }
if (bb->recursion) {
return TRUE;
@@ -246,20 +250,22 @@ static gint pressButt(
if (bb->option & BO_REPEAT) {
/* Remove an existing timer */
- if (bb->timer_id)
- g_source_remove(bb->timer_id);
+ if (bb->timer_id) {
+ g_source_remove(bb->timer_id);
+ }
- /* Setup a timer */
- bb->timer_id = g_timeout_add( REPEAT_STAGE0_DELAY, timer_func, bb);
- bb->timer_state = 0;
+ /* Setup a timer */
+ bb->timer_id = g_timeout_add( REPEAT_STAGE0_DELAY, timer_func, bb);
+ bb->timer_state = 0;
}
if (!bb->busy) {
bb->recursion++;
int sensitive = gtk_widget_get_sensitive (GTK_WIDGET(bb->widget));
- if (sensitive)
+ if (sensitive) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), TRUE);
+ }
bb->recursion--;
}
@@ -269,16 +275,18 @@ static gint pressButt(
}
static gint releaseButt(
- GtkWidget *widget,
- GdkEventButton *event,
- wButton_p bb) {
+ GtkWidget *widget,
+ GdkEventButton *event,
+ wButton_p bb)
+{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "buttonRelease: %s\n", bb->labelStr );
+ }
/* Remove any existing timer */
if (bb->timer_id) {
- g_source_remove(bb->timer_id);
- bb->timer_id = 0;
+ g_source_remove(bb->timer_id);
+ bb->timer_id = 0;
}
bb->timer_state = -1;
@@ -298,9 +306,9 @@ static gint releaseButt(
* Called after expose event default hander - allows the button to be outlined
*/
static wBool_t exposeButt(
- GtkWidget *widget,
- GdkEventExpose *event,
- gpointer g)
+ GtkWidget *widget,
+ GdkEventExpose *event,
+ gpointer g)
{
wControl_p b = (wControl_p)g;
return wControlExpose(widget,event,b);
@@ -322,61 +330,62 @@ static wBool_t exposeButt(
*/
wButton_p wButtonCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- wButtonCallBack_p action,
- void * data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ wButtonCallBack_p action,
+ void * data)
{
- wButton_p b;
- if (option&BO_ICON) //The labelStr here is a wIcon_p
- b = wlibAlloc(parent, B_BUTTON, x, y, " ", sizeof *b, data);
- else
- b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, data);
- b->option = option;
- b->action = action;
- wlibComputePos((wControl_p)b);
-
- b->widget = gtk_toggle_button_new();
- g_signal_connect(GTK_OBJECT(b->widget), "button_press_event",
- G_CALLBACK(pressButt), b);
- g_signal_connect(GTK_OBJECT(b->widget), "button_release_event",
- G_CALLBACK(releaseButt), b);
- //g_signal_connect(GTK_OBJECT(b->widget), "clicked",
- // G_CALLBACK(pushButt), b);
- g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
- G_CALLBACK(exposeButt), b);
- if (width > 0) {
- gtk_widget_set_size_request(b->widget, width, -1);
- }
-
- if( labelStr ){
- wButtonSetLabel(b, labelStr);
- }
-
- gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
-
- if (option & BB_DEFAULT) {
- gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT);
- gtk_widget_grab_default(b->widget);
- gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget);
- }
-
- wlibControlGetSize((wControl_p)b);
-
- if (width == 0 && b->w < MIN_BUTTON_WIDTH && (b->option&BO_ICON)==0) {
- b->w = MIN_BUTTON_WIDTH;
- gtk_widget_set_size_request(b->widget, b->w, b->h);
- }
-
- gtk_widget_show(b->widget);
- wlibAddButton((wControl_p)b);
- wlibAddHelpString(b->widget, helpStr);
- return b;
+ wButton_p b;
+ if (option&BO_ICON) { //The labelStr here is a wIcon_p
+ b = wlibAlloc(parent, B_BUTTON, x, y, " ", sizeof *b, data);
+ } else {
+ b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, data);
+ }
+ b->option = option;
+ b->action = action;
+ wlibComputePos((wControl_p)b);
+
+ b->widget = gtk_toggle_button_new();
+ g_signal_connect(GTK_OBJECT(b->widget), "button_press_event",
+ G_CALLBACK(pressButt), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "button_release_event",
+ G_CALLBACK(releaseButt), b);
+ //g_signal_connect(GTK_OBJECT(b->widget), "clicked",
+ // G_CALLBACK(pushButt), b);
+ g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
+ G_CALLBACK(exposeButt), b);
+ if (width > 0) {
+ gtk_widget_set_size_request(b->widget, width, -1);
+ }
+
+ if( labelStr ) {
+ wButtonSetLabel(b, labelStr);
+ }
+
+ gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
+
+ if (option & BB_DEFAULT) {
+ gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT);
+ gtk_widget_grab_default(b->widget);
+ gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget);
+ }
+
+ wlibControlGetSize((wControl_p)b);
+
+ if (width == 0 && b->w < MIN_BUTTON_WIDTH && (b->option&BO_ICON)==0) {
+ b->w = MIN_BUTTON_WIDTH;
+ gtk_widget_set_size_request(b->widget, b->w, b->h);
+ }
+
+ gtk_widget_show(b->widget);
+ wlibAddButton((wControl_p)b);
+ wlibAddHelpString(b->widget, helpStr);
+ return b;
}
@@ -389,10 +398,10 @@ wButton_p wButtonCreate(
*/
struct wChoice_t {
- WOBJ_COMMON
- long *valueP;
- wChoiceCallBack_p action;
- int recursion;
+ WOBJ_COMMON
+ long *valueP;
+ wChoiceCallBack_p action;
+ int recursion;
};
@@ -407,33 +416,33 @@ struct wChoice_t {
*/
static long choiceGetValue(
- wChoice_p bc)
+ wChoice_p bc)
{
- GList * child, * children;
- long value, inx;
-
- if (bc->type == B_TOGGLE) {
- value = 0;
- } else {
- value = -1;
- }
-
- for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0;
- child; child=child->next,inx++) {
- if (gtk_toggle_button_get_active(child->data)) {
- if (bc->type == B_TOGGLE) {
- value |= (1<<inx);
- } else {
- value = inx;
- }
- }
- }
-
- if (children) {
- g_list_free(children);
- }
-
- return value;
+ GList * child, * children;
+ long value, inx;
+
+ if (bc->type == B_TOGGLE) {
+ value = 0;
+ } else {
+ value = -1;
+ }
+
+ for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0;
+ child; child=child->next,inx++) {
+ if (gtk_toggle_button_get_active(child->data)) {
+ if (bc->type == B_TOGGLE) {
+ value |= (1<<inx);
+ } else {
+ value = inx;
+ }
+ }
+ }
+
+ if (children) {
+ g_list_free(children);
+ }
+
+ return value;
}
/**
@@ -444,24 +453,24 @@ static long choiceGetValue(
*/
void wRadioSetValue(
- wChoice_p bc, /* Radio box */
- long value) /* Value */
+ wChoice_p bc, /* Radio box */
+ long value) /* Value */
{
- GList * child, * children;
- long inx;
-
- for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0;
- child; child=child->next,inx++) {
- if (inx == value) {
- bc->recursion++;
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data), TRUE);
- bc->recursion--;
- }
- }
-
- if (children) {
- g_list_free(children);
- }
+ GList * child, * children;
+ long inx;
+
+ for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0;
+ child; child=child->next,inx++) {
+ if (inx == value) {
+ bc->recursion++;
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data), TRUE);
+ bc->recursion--;
+ }
+ }
+
+ if (children) {
+ g_list_free(children);
+ }
}
/**
@@ -472,9 +481,9 @@ void wRadioSetValue(
*/
long wRadioGetValue(
- wChoice_p bc) /* Radio box */
+ wChoice_p bc) /* Radio box */
{
- return choiceGetValue(bc);
+ return choiceGetValue(bc);
}
/**
@@ -485,24 +494,24 @@ long wRadioGetValue(
*/
void wToggleSetValue(
- wChoice_p bc, /* Toggle box */
- long value) /* Values */
+ wChoice_p bc, /* Toggle box */
+ long value) /* Values */
{
- GList * child, * children;
- long inx;
- bc->recursion++;
-
- for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0;
- child; child=child->next,inx++) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data),
- (value&(1<<inx))!=0);
- }
+ GList * child, * children;
+ long inx;
+ bc->recursion++;
+
+ for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0;
+ child; child=child->next,inx++) {
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data),
+ (value&(1<<inx))!=0);
+ }
- if (children) {
- g_list_free(children);
- }
+ if (children) {
+ g_list_free(children);
+ }
- bc->recursion--;
+ bc->recursion--;
}
@@ -514,9 +523,9 @@ void wToggleSetValue(
*/
long wToggleGetValue(
- wChoice_p b) /* Toggle box */
+ wChoice_p b) /* Toggle box */
{
- return choiceGetValue(b);
+ return choiceGetValue(b);
}
/**
@@ -529,35 +538,35 @@ long wToggleGetValue(
*/
static int pushChoice(
- GtkWidget *widget,
- gpointer b)
+ GtkWidget *widget,
+ gpointer b)
{
- wChoice_p bc = (wChoice_p)b;
- long value = choiceGetValue(bc);
+ wChoice_p bc = (wChoice_p)b;
+ long value = choiceGetValue(bc);
- if (debugWindow >= 2) {
- printf("%s choice pushed = %ld\n", bc->labelStr?bc->labelStr:"No label",
- value);
- }
+ if (debugWindow >= 2) {
+ printf("%s choice pushed = %ld\n", bc->labelStr?bc->labelStr:"No label",
+ value);
+ }
- if (bc->type == B_RADIO &&
- !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))) {
- return 1;
- }
+ if (bc->type == B_RADIO &&
+ !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))) {
+ return 1;
+ }
- if (bc->recursion) {
- return 1;
- }
+ if (bc->recursion) {
+ return 1;
+ }
- if (bc->valueP) {
- *bc->valueP = value;
- }
+ if (bc->valueP) {
+ *bc->valueP = value;
+ }
- if (bc->action) {
- bc->action(value, bc->data);
- }
+ if (bc->action) {
+ bc->action(value, bc->data);
+ }
- return 1;
+ return 1;
}
/**
@@ -568,13 +577,13 @@ static int pushChoice(
*/
static void choiceRepaint(
- wControl_p b)
+ wControl_p b)
{
- wChoice_p bc = (wChoice_p)b;
+ wChoice_p bc = (wChoice_p)b;
- if (gtk_widget_get_visible(b->widget)) {
- wlibDrawBox(bc->parent, wBoxBelow, bc->realX-1, bc->realY-1, bc->w+1, bc->h+1);
- }
+ if (gtk_widget_get_visible(b->widget)) {
+ wlibDrawBox(bc->parent, wBoxBelow, bc->realX-1, bc->realY-1, bc->w+1, bc->h+1);
+ }
}
/**
@@ -594,95 +603,95 @@ static void choiceRepaint(
*/
wChoice_p wRadioCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char * const *labels,
- long *valueP,
- wChoiceCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ const char * const *labels,
+ long *valueP,
+ wChoiceCallBack_p action,
+ void *data)
{
- wChoice_p b;
- const char * const * label;
- GtkWidget *butt0=NULL, *butt;
-
- if ((option & BC_NOBORDER)==0) {
- if (x>=0) {
- x++;
- } else {
- x--;
- }
-
- if (y>=0) {
- y++;
- } else {
- y--;
- }
- }
-
- b = wlibAlloc(parent, B_RADIO, x, y, labelStr, sizeof *b, data);
- b->option = option;
- b->action = action;
- b->valueP = valueP;
- wlibComputePos((wControl_p)b);
-
- ((wControl_p)b)->outline = FALSE;
-
- if (option&BC_HORZ) {
- b->widget = gtk_hbox_new(FALSE, 0);
- } else {
- b->widget = gtk_vbox_new(FALSE, 0);
- }
-
- if (b->widget == 0) {
- abort();
- }
-
- for (label=labels; *label; label++) {
- butt = gtk_radio_button_new_with_label(
- butt0?gtk_radio_button_get_group(GTK_RADIO_BUTTON(butt0)):NULL, _(*label));
-
- if (butt0==NULL) {
- butt0 = butt;
- }
-
- gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0);
- gtk_widget_show(butt);
- g_signal_connect(GTK_OBJECT(butt), "toggled",
- G_CALLBACK(pushChoice), b);
- g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
- G_CALLBACK(exposeButt), b);
- wlibAddHelpString(butt, helpStr);
- }
-
- if (option & BB_DEFAULT) {
- gtk_widget_set_can_default(b->widget, TRUE);
- gtk_widget_grab_default(b->widget);
- }
-
- if (valueP) {
- wRadioSetValue(b, *valueP);
- }
-
- if ((option & BC_NOBORDER)==0) {
- b->repaintProc = choiceRepaint;
- b->w += 2;
- b->h += 2;
- }
-
- gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
- wlibControlGetSize((wControl_p)b);
-
- if (labelStr) {
- b->labelW = wlibAddLabel((wControl_p)b, labelStr);
- }
-
- gtk_widget_show(b->widget);
- wlibAddButton((wControl_p)b);
- return b;
+ wChoice_p b;
+ const char * const * label;
+ GtkWidget *butt0=NULL, *butt;
+
+ if ((option & BC_NOBORDER)==0) {
+ if (x>=0) {
+ x++;
+ } else {
+ x--;
+ }
+
+ if (y>=0) {
+ y++;
+ } else {
+ y--;
+ }
+ }
+
+ b = wlibAlloc(parent, B_RADIO, x, y, labelStr, sizeof *b, data);
+ b->option = option;
+ b->action = action;
+ b->valueP = valueP;
+ wlibComputePos((wControl_p)b);
+
+ ((wControl_p)b)->outline = FALSE;
+
+ if (option&BC_HORZ) {
+ b->widget = gtk_hbox_new(FALSE, 0);
+ } else {
+ b->widget = gtk_vbox_new(FALSE, 0);
+ }
+
+ if (b->widget == 0) {
+ abort();
+ }
+
+ for (label=labels; *label; label++) {
+ butt = gtk_radio_button_new_with_label(
+ butt0?gtk_radio_button_get_group(GTK_RADIO_BUTTON(butt0)):NULL, _(*label));
+
+ if (butt0==NULL) {
+ butt0 = butt;
+ }
+
+ gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0);
+ gtk_widget_show(butt);
+ g_signal_connect(GTK_OBJECT(butt), "toggled",
+ G_CALLBACK(pushChoice), b);
+ g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
+ G_CALLBACK(exposeButt), b);
+ wlibAddHelpString(butt, helpStr);
+ }
+
+ if (option & BB_DEFAULT) {
+ gtk_widget_set_can_default(b->widget, TRUE);
+ gtk_widget_grab_default(b->widget);
+ }
+
+ if (valueP) {
+ wRadioSetValue(b, *valueP);
+ }
+
+ if ((option & BC_NOBORDER)==0) {
+ b->repaintProc = choiceRepaint;
+ b->w += 2;
+ b->h += 2;
+ }
+
+ gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
+ wlibControlGetSize((wControl_p)b);
+
+ if (labelStr) {
+ b->labelW = wlibAddLabel((wControl_p)b, labelStr);
+ }
+
+ gtk_widget_show(b->widget);
+ wlibAddButton((wControl_p)b);
+ return b;
}
/**
@@ -702,82 +711,82 @@ wChoice_p wRadioCreate(
*/
wChoice_p wToggleCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char * const * labels,
- long *valueP,
- wChoiceCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ const char * const * labels,
+ long *valueP,
+ wChoiceCallBack_p action,
+ void *data)
{
- wChoice_p b;
- const char * const * label;
-
- if ((option & BC_NOBORDER)==0) {
- if (x>=0) {
- x++;
- } else {
- x--;
- }
-
- if (y>=0) {
- y++;
- } else {
- y--;
- }
- }
-
- b = wlibAlloc(parent, B_TOGGLE, x, y, labelStr, sizeof *b, data);
- b->option = option;
- b->action = action;
- wlibComputePos((wControl_p)b);
-
- ((wControl_p)b)->outline = FALSE;
-
- if (option&BC_HORZ) {
- b->widget = gtk_hbox_new(FALSE, 0);
- } else {
- b->widget = gtk_vbox_new(FALSE, 0);
- }
-
- if (b->widget == 0) {
- abort();
- }
-
- for (label=labels; *label; label++) {
- GtkWidget *butt;
-
- butt = gtk_check_button_new_with_label(_(*label));
- gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0);
- gtk_widget_show(butt);
- g_signal_connect(GTK_OBJECT(butt), "toggled",
- G_CALLBACK(pushChoice), b);
- g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
- G_CALLBACK(exposeButt), b);
- wlibAddHelpString(butt, helpStr);
- }
-
- if (valueP) {
- wToggleSetValue(b, *valueP);
- }
-
- if ((option & BC_NOBORDER)==0) {
- b->repaintProc = choiceRepaint;
- b->w += 2;
- b->h += 2;
- }
-
- gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
- wlibControlGetSize((wControl_p)b);
-
- if (labelStr) {
- b->labelW = wlibAddLabel((wControl_p)b, labelStr);
- }
-
- gtk_widget_show(b->widget);
- wlibAddButton((wControl_p)b);
- return b;
+ wChoice_p b;
+ const char * const * label;
+
+ if ((option & BC_NOBORDER)==0) {
+ if (x>=0) {
+ x++;
+ } else {
+ x--;
+ }
+
+ if (y>=0) {
+ y++;
+ } else {
+ y--;
+ }
+ }
+
+ b = wlibAlloc(parent, B_TOGGLE, x, y, labelStr, sizeof *b, data);
+ b->option = option;
+ b->action = action;
+ wlibComputePos((wControl_p)b);
+
+ ((wControl_p)b)->outline = FALSE;
+
+ if (option&BC_HORZ) {
+ b->widget = gtk_hbox_new(FALSE, 0);
+ } else {
+ b->widget = gtk_vbox_new(FALSE, 0);
+ }
+
+ if (b->widget == 0) {
+ abort();
+ }
+
+ for (label=labels; *label; label++) {
+ GtkWidget *butt;
+
+ butt = gtk_check_button_new_with_label(_(*label));
+ gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0);
+ gtk_widget_show(butt);
+ g_signal_connect(GTK_OBJECT(butt), "toggled",
+ G_CALLBACK(pushChoice), b);
+ g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
+ G_CALLBACK(exposeButt), b);
+ wlibAddHelpString(butt, helpStr);
+ }
+
+ if (valueP) {
+ wToggleSetValue(b, *valueP);
+ }
+
+ if ((option & BC_NOBORDER)==0) {
+ b->repaintProc = choiceRepaint;
+ b->w += 2;
+ b->h += 2;
+ }
+
+ gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
+ wlibControlGetSize((wControl_p)b);
+
+ if (labelStr) {
+ b->labelW = wlibAddLabel((wControl_p)b, labelStr);
+ }
+
+ gtk_widget_show(b->widget);
+ wlibAddButton((wControl_p)b);
+ return b;
}
diff --git a/app/wlib/gtklib/color.c b/app/wlib/gtklib/color.c
index fee4a80..d193872 100644
--- a/app/wlib/gtklib/color.c
+++ b/app/wlib/gtklib/color.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <assert.h>
#include <stdlib.h>
@@ -45,62 +45,62 @@ wDrawColor wDrawColorBlack;
static GArray *colorMap_garray = NULL; // Change to use glib array
static colorMap_t colorMap[] = {
- { 255, 255, 255 }, /* White */
- { 0, 0, 0 }, /* Black */
- { 255, 0, 0 }, /* Red */
- { 0, 255, 0 }, /* Green */
- { 0, 0, 255 }, /* Blue */
- { 255, 255, 0 }, /* Yellow */
- { 255, 0, 255 }, /* Purple */
- { 0, 255, 255 }, /* Aqua */
- { 128, 0, 0 }, /* Dk. Red */
- { 0, 128, 0 }, /* Dk. Green */
- { 0, 0, 128 }, /* Dk. Blue */
- { 128, 128, 0 }, /* Dk. Yellow */
- { 128, 0, 128 }, /* Dk. Purple */
- { 0, 128, 128 }, /* Dk. Aqua */
- { 65, 105, 225 }, /* Royal Blue */
- { 0, 191, 255 }, /* DeepSkyBlue */
- { 125, 206, 250 }, /* LightSkyBlue */
- { 70, 130, 180 }, /* Steel Blue */
- { 176, 224, 230 }, /* Powder Blue */
- { 127, 255, 212 }, /* Aquamarine */
- { 46, 139, 87 }, /* SeaGreen */
- { 152, 251, 152 }, /* PaleGreen */
- { 124, 252, 0 }, /* LawnGreen */
- { 50, 205, 50 }, /* LimeGreen */
- { 34, 139, 34 }, /* ForestGreen */
- { 255, 215, 0 }, /* Gold */
- { 188, 143, 143 }, /* RosyBrown */
- { 139, 69, 19 }, /* SaddleBrown */
- { 245, 245, 220 }, /* Beige */
- { 210, 180, 140 }, /* Tan */
- { 210, 105, 30 }, /* Chocolate */
- { 165, 42, 42 }, /* Brown */
- { 255, 165, 0 }, /* Orange */
- { 255, 127, 80 }, /* Coral */
- { 255, 99, 71 }, /* Tomato */
- { 255, 105, 180 }, /* HotPink */
- { 255, 192, 203 }, /* Pink */
- { 176, 48, 96 }, /* Maroon */
- { 238, 130, 238 }, /* Violet */
- { 160, 32, 240 }, /* Purple */
- { 16, 16, 16 }, /* Gray */
- { 32, 32, 32 }, /* Gray */
- { 48, 48, 48 }, /* Gray */
- { 64, 64, 64 }, /* Gray */
- { 80, 80, 80 }, /* Gray */
- { 96, 96, 96 }, /* Gray */
- { 112, 112, 122 }, /* Gray */
- { 128, 128, 128 }, /* Gray */
- { 144, 144, 144 }, /* Gray */
- { 160, 160, 160 }, /* Gray */
- { 176, 176, 176 }, /* Gray */
- { 192, 192, 192 }, /* Gray */
- { 208, 208, 208 }, /* Gray */
- { 224, 224, 224 }, /* Gray */
- { 240, 240, 240 }, /* Gray */
- { 255, 255, 255 } /* WhitePixel */
+ { 255, 255, 255 }, /* White */
+ { 0, 0, 0 }, /* Black */
+ { 255, 0, 0 }, /* Red */
+ { 0, 255, 0 }, /* Green */
+ { 0, 0, 255 }, /* Blue */
+ { 255, 255, 0 }, /* Yellow */
+ { 255, 0, 255 }, /* Purple */
+ { 0, 255, 255 }, /* Aqua */
+ { 128, 0, 0 }, /* Dk. Red */
+ { 0, 128, 0 }, /* Dk. Green */
+ { 0, 0, 128 }, /* Dk. Blue */
+ { 128, 128, 0 }, /* Dk. Yellow */
+ { 128, 0, 128 }, /* Dk. Purple */
+ { 0, 128, 128 }, /* Dk. Aqua */
+ { 65, 105, 225 }, /* Royal Blue */
+ { 0, 191, 255 }, /* DeepSkyBlue */
+ { 125, 206, 250 }, /* LightSkyBlue */
+ { 70, 130, 180 }, /* Steel Blue */
+ { 176, 224, 230 }, /* Powder Blue */
+ { 127, 255, 212 }, /* Aquamarine */
+ { 46, 139, 87 }, /* SeaGreen */
+ { 152, 251, 152 }, /* PaleGreen */
+ { 124, 252, 0 }, /* LawnGreen */
+ { 50, 205, 50 }, /* LimeGreen */
+ { 34, 139, 34 }, /* ForestGreen */
+ { 255, 215, 0 }, /* Gold */
+ { 188, 143, 143 }, /* RosyBrown */
+ { 139, 69, 19 }, /* SaddleBrown */
+ { 245, 245, 220 }, /* Beige */
+ { 210, 180, 140 }, /* Tan */
+ { 210, 105, 30 }, /* Chocolate */
+ { 165, 42, 42 }, /* Brown */
+ { 255, 165, 0 }, /* Orange */
+ { 255, 127, 80 }, /* Coral */
+ { 255, 99, 71 }, /* Tomato */
+ { 255, 105, 180 }, /* HotPink */
+ { 255, 192, 203 }, /* Pink */
+ { 176, 48, 96 }, /* Maroon */
+ { 238, 130, 238 }, /* Violet */
+ { 160, 32, 240 }, /* Purple */
+ { 16, 16, 16 }, /* Gray */
+ { 32, 32, 32 }, /* Gray */
+ { 48, 48, 48 }, /* Gray */
+ { 64, 64, 64 }, /* Gray */
+ { 80, 80, 80 }, /* Gray */
+ { 96, 96, 96 }, /* Gray */
+ { 112, 112, 122 }, /* Gray */
+ { 128, 128, 128 }, /* Gray */
+ { 144, 144, 144 }, /* Gray */
+ { 160, 160, 160 }, /* Gray */
+ { 176, 176, 176 }, /* Gray */
+ { 192, 192, 192 }, /* Gray */
+ { 208, 208, 208 }, /* Gray */
+ { 224, 224, 224 }, /* Gray */
+ { 240, 240, 240 }, /* Gray */
+ { 255, 255, 255 } /* WhitePixel */
};
#define NUM_GRAYS (16)
@@ -117,21 +117,21 @@ static char lastColorChar = '!';
*/
wDrawColor wDrawColorGray(
- int percent)
+ int percent)
{
- int n;
- long rgb;
- n = (percent * (NUM_GRAYS+1)) / 100;
-
- if (n <= 0) {
- return wDrawColorBlack;
- } else if (n >= NUM_GRAYS) {
- return wDrawColorWhite;
- } else {
- n = (n*256)/NUM_GRAYS;
- rgb = RGB(n, n, n);
- return wDrawFindColor(rgb);
- }
+ int n;
+ long rgb;
+ n = (percent * (NUM_GRAYS+1)) / 100;
+
+ if (n <= 0) {
+ return wDrawColorBlack;
+ } else if (n >= NUM_GRAYS) {
+ return wDrawColorWhite;
+ } else {
+ n = (n*256)/NUM_GRAYS;
+ rgb = RGB(n, n, n);
+ return wDrawFindColor(rgb);
+ }
}
/**
@@ -142,12 +142,12 @@ wDrawColor wDrawColorGray(
void wlibGetColorMap(void)
{
- if (gtkColorMap) {
- return;
- }
+ if (gtkColorMap) {
+ return;
+ }
- gtkColorMap = gtk_widget_get_colormap(gtkMainW->widget);
- return;
+ gtkColorMap = gtk_widget_get_colormap(gtkMainW->widget);
+ return;
}
/**
@@ -160,21 +160,21 @@ void wlibGetColorMap(void)
static void init_colorMapValue(colorMap_t * t)
{
- t->rgb = RGB(t->red, t->green, t->blue);
- t->normalColor.red = t->red*65535/255;
- t->normalColor.green = t->green*65535/255;
- t->normalColor.blue = t->blue*65535/255;
- gdk_colormap_alloc_color(gtkColorMap, &t->normalColor, FALSE, TRUE);
- t->invertColor = t->normalColor;
- t->invertColor.pixel ^= g_array_index(colorMap_garray, colorMap_t,
- wDrawColorWhite).normalColor.pixel;
- t->colorChar = lastColorChar++;
-
- if (lastColorChar >= 0x7F) {
- lastColorChar = '!'+1;
- } else if (lastColorChar == '"') {
- lastColorChar++;
- }
+ t->rgb = RGB(t->red, t->green, t->blue);
+ t->normalColor.red = t->red*65535/255;
+ t->normalColor.green = t->green*65535/255;
+ t->normalColor.blue = t->blue*65535/255;
+ gdk_colormap_alloc_color(gtkColorMap, &t->normalColor, FALSE, TRUE);
+ t->invertColor = t->normalColor;
+ t->invertColor.pixel ^= g_array_index(colorMap_garray, colorMap_t,
+ wDrawColorWhite).normalColor.pixel;
+ t->colorChar = lastColorChar++;
+
+ if (lastColorChar >= 0x7F) {
+ lastColorChar = '!'+1;
+ } else if (lastColorChar == '"') {
+ lastColorChar++;
+ }
}
/**
@@ -185,15 +185,15 @@ static void init_colorMapValue(colorMap_t * t)
static void init_colorMap(void)
{
- int gint;
- colorMap_garray = g_array_sized_new(TRUE, TRUE, sizeof(colorMap_t),
- sizeof(colorMap)/sizeof(colorMap_t));
- g_array_append_vals(colorMap_garray, &colorMap,
- sizeof(colorMap)/sizeof(colorMap_t));
-
- for (gint=0; gint<colorMap_garray->len; gint++) {
- init_colorMapValue(&g_array_index(colorMap_garray, colorMap_t, gint));
- }
+ int gint;
+ colorMap_garray = g_array_sized_new(TRUE, TRUE, sizeof(colorMap_t),
+ sizeof(colorMap)/sizeof(colorMap_t));
+ g_array_append_vals(colorMap_garray, &colorMap,
+ sizeof(colorMap)/sizeof(colorMap_t));
+
+ for (gint=0; gint<colorMap_garray->len; gint++) {
+ init_colorMapValue(&g_array_index(colorMap_garray, colorMap_t, gint));
+ }
}
/**
@@ -206,57 +206,57 @@ static void init_colorMap(void)
*/
wDrawColor wDrawFindColor(
- long rgb0)
+ long rgb0)
{
- wDrawColor cc;
- int r0, g0, b0, r1, g1, b1;
- int d0;
- int i;
- colorMap_t tempMapValue;
- wlibGetColorMap();
- cc = wDrawColorBlack;
- r0 = (int)(rgb0>>16)&0xFF;
- g0 = (int)(rgb0>>8)&0xFF;
- b0 = (int)(rgb0)&0xFF;
- d0 = 256*3;
-
- // Initialize garray if needed
- if (colorMap_garray == NULL) {
- init_colorMap();
- }
-
- // Iterate over entire garray
- for (i=0; i<colorMap_garray->len; i++) {
- int d1;
- colorMap_t * cm_p;
-
- cm_p = &g_array_index(colorMap_garray, colorMap_t, i);
- r1 = (int)cm_p->red;
- g1 = (int)cm_p->green;
- b1 = (int)cm_p->blue;
- d1 = abs(r0-r1) + abs(g0-g1) + abs(b0-b1);
-
- if (d1 == 0) {
- return i;
- }
-
- if (d1 < d0) {
- d0 = d1;
- cc = i;
- }
- }
-
- if (d0 <= MAX_COLOR_DISTANCE) {
- return cc;
- }
-
- // No good value - so add one
- tempMapValue.red = r0;
- tempMapValue.green = g0;
- tempMapValue.blue = b0;
- init_colorMapValue(&tempMapValue);
- g_array_append_val(colorMap_garray,tempMapValue);
- return i;
+ wDrawColor cc;
+ int r0, g0, b0, r1, g1, b1;
+ int d0;
+ int i;
+ colorMap_t tempMapValue;
+ wlibGetColorMap();
+ cc = wDrawColorBlack;
+ r0 = (int)(rgb0>>16)&0xFF;
+ g0 = (int)(rgb0>>8)&0xFF;
+ b0 = (int)(rgb0)&0xFF;
+ d0 = 256*3;
+
+ // Initialize garray if needed
+ if (colorMap_garray == NULL) {
+ init_colorMap();
+ }
+
+ // Iterate over entire garray
+ for (i=0; i<colorMap_garray->len; i++) {
+ int d1;
+ colorMap_t * cm_p;
+
+ cm_p = &g_array_index(colorMap_garray, colorMap_t, i);
+ r1 = (int)cm_p->red;
+ g1 = (int)cm_p->green;
+ b1 = (int)cm_p->blue;
+ d1 = abs(r0-r1) + abs(g0-g1) + abs(b0-b1);
+
+ if (d1 == 0) {
+ return i;
+ }
+
+ if (d1 < d0) {
+ d0 = d1;
+ cc = i;
+ }
+ }
+
+ if (d0 <= MAX_COLOR_DISTANCE) {
+ return cc;
+ }
+
+ // No good value - so add one
+ tempMapValue.red = r0;
+ tempMapValue.green = g0;
+ tempMapValue.blue = b0;
+ init_colorMapValue(&tempMapValue);
+ g_array_append_val(colorMap_garray,tempMapValue);
+ return i;
}
/**
@@ -267,21 +267,21 @@ wDrawColor wDrawFindColor(
*/
long wDrawGetRGB(
- wDrawColor color)
+ wDrawColor color)
{
- colorMap_t * colorMap_e;
- wlibGetColorMap();
+ colorMap_t * colorMap_e;
+ wlibGetColorMap();
- if (colorMap_garray == NULL) {
- init_colorMap();
- }
+ if (colorMap_garray == NULL) {
+ init_colorMap();
+ }
- if (color < 0 || color > colorMap_garray->len) {
- abort();
- }
+ if (color < 0 || color > colorMap_garray->len) {
+ abort();
+ }
- colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color);
- return colorMap_e->rgb;
+ colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color);
+ return colorMap_e->rgb;
}
/**
@@ -293,27 +293,27 @@ long wDrawGetRGB(
*/
GdkColor* wlibGetColor(
- wDrawColor color,
- wBool_t normal)
+ wDrawColor color,
+ wBool_t normal)
{
- colorMap_t * colorMap_e;
- wlibGetColorMap();
+ colorMap_t * colorMap_e;
+ wlibGetColorMap();
- if (colorMap_garray == NULL) {
- init_colorMap();
- }
+ if (colorMap_garray == NULL) {
+ init_colorMap();
+ }
- if (color < 0 || color > colorMap_garray->len) {
- abort();
- }
+ if (color < 0 || color > colorMap_garray->len) {
+ abort();
+ }
- colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color);
+ colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color);
- if (normal) {
- return &colorMap_e->normalColor;
- } else {
- return &colorMap_e->invertColor;
- }
+ if (normal) {
+ return &colorMap_e->normalColor;
+ } else {
+ return &colorMap_e->invertColor;
+ }
}
@@ -326,12 +326,12 @@ GdkColor* wlibGetColor(
*/
typedef struct {
- wDrawColor * valueP;
- const char * labelStr;
- wColorSelectButtonCallBack_p action;
- void * data;
- wDrawColor color;
- wButton_p button;
+ wDrawColor * valueP;
+ const char * labelStr;
+ wColorSelectButtonCallBack_p action;
+ void * data;
+ wDrawColor color;
+ wButton_p button;
} colorData_t;
/**
@@ -344,23 +344,23 @@ typedef struct {
static void
colorChange(GtkColorButton *widget, gpointer user_data)
{
- colorData_t *cd = user_data;
- GdkColor newcolor;
- long rgb;
+ colorData_t *cd = user_data;
+ GdkColor newcolor;
+ long rgb;
- gtk_color_button_get_color(widget, &newcolor);
+ gtk_color_button_get_color(widget, &newcolor);
- rgb = RGB((int)(newcolor.red/256), (int)(newcolor.green/256),
- (int)(newcolor.blue/256));
- cd->color = wDrawFindColor(rgb);
+ rgb = RGB((int)(newcolor.red/256), (int)(newcolor.green/256),
+ (int)(newcolor.blue/256));
+ cd->color = wDrawFindColor(rgb);
- if (cd->valueP) {
- *(cd->valueP) = cd->color;
- }
+ if (cd->valueP) {
+ *(cd->valueP) = cd->color;
+ }
- if (cd->action) {
- cd->action(cd->data, cd->color);
- }
+ if (cd->action) {
+ cd->action(cd->data, cd->color);
+ }
}
/**
@@ -372,14 +372,14 @@ colorChange(GtkColorButton *widget, gpointer user_data)
*/
void wColorSelectButtonSetColor(
- wButton_p bb,
- wDrawColor color)
+ wButton_p bb,
+ wDrawColor color)
{
- GdkColor *colorOfButton = wlibGetColor(color, TRUE);
+ GdkColor *colorOfButton = wlibGetColor(color, TRUE);
- gtk_color_button_set_color(GTK_COLOR_BUTTON(bb->widget),
- colorOfButton);
- ((colorData_t*)((wControl_p)bb)->data)->color = color;
+ gtk_color_button_set_color(GTK_COLOR_BUTTON(bb->widget),
+ colorOfButton);
+ ((colorData_t*)((wControl_p)bb)->data)->color = color;
}
@@ -391,9 +391,9 @@ void wColorSelectButtonSetColor(
*/
wDrawColor wColorSelectButtonGetColor(
- wButton_p bb)
+ wButton_p bb)
{
- return ((colorData_t*)((wControl_p)bb)->data)->color;
+ return ((colorData_t*)((wControl_p)bb)->data)->color;
}
/**
@@ -413,57 +413,57 @@ wDrawColor wColorSelectButtonGetColor(
*/
wButton_p wColorSelectButtonCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- wDrawColor *valueP,
- wColorSelectButtonCallBack_p action,
- void * data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ wDrawColor *valueP,
+ wColorSelectButtonCallBack_p action,
+ void * data)
{
- wButton_p b;
- colorData_t * cd;
- cd = malloc(sizeof(colorData_t));
- cd->valueP = valueP;
- cd->action = action;
- cd->data = data;
- cd->labelStr = labelStr;
- cd->color = (valueP?*valueP:0);
-
- b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, cd);
- b->option = option;
- wlibComputePos((wControl_p)b);
-
- b->widget = gtk_color_button_new();
- GtkStyle *style;
- style = gtk_widget_get_style(b->widget);
- style->xthickness = 1;
- style->ythickness = 1;
- gtk_widget_set_style(b->widget, style);
- gtk_widget_set_size_request(GTK_WIDGET(b->widget), 22, 22);
- g_signal_connect(GTK_OBJECT(b->widget), "color-set",
- G_CALLBACK(colorChange), cd);
-
- gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
-
- if (option & BB_DEFAULT) {
- gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT);
- gtk_widget_grab_default(b->widget);
- gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget);
- }
-
- wlibControlGetSize((wControl_p)b);
-
- gtk_widget_show(b->widget);
- wlibAddButton((wControl_p)b);
- wlibAddHelpString(b->widget, helpStr);
- wColorSelectButtonSetColor(b, (valueP?*valueP:0));
-
- if (labelStr) {
- ((wControl_p)b)->labelW = wlibAddLabel((wControl_p)b, labelStr);
- }
- return b;
+ wButton_p b;
+ colorData_t * cd;
+ cd = malloc(sizeof(colorData_t));
+ cd->valueP = valueP;
+ cd->action = action;
+ cd->data = data;
+ cd->labelStr = labelStr;
+ cd->color = (valueP?*valueP:0);
+
+ b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, cd);
+ b->option = option;
+ wlibComputePos((wControl_p)b);
+
+ b->widget = gtk_color_button_new();
+ GtkStyle *style;
+ style = gtk_widget_get_style(b->widget);
+ style->xthickness = 1;
+ style->ythickness = 1;
+ gtk_widget_set_style(b->widget, style);
+ gtk_widget_set_size_request(GTK_WIDGET(b->widget), 22, 22);
+ g_signal_connect(GTK_OBJECT(b->widget), "color-set",
+ G_CALLBACK(colorChange), cd);
+
+ gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
+
+ if (option & BB_DEFAULT) {
+ gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT);
+ gtk_widget_grab_default(b->widget);
+ gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget);
+ }
+
+ wlibControlGetSize((wControl_p)b);
+
+ gtk_widget_show(b->widget);
+ wlibAddButton((wControl_p)b);
+ wlibAddHelpString(b->widget, helpStr);
+ wColorSelectButtonSetColor(b, (valueP?*valueP:0));
+
+ if (labelStr) {
+ ((wControl_p)b)->labelW = wlibAddLabel((wControl_p)b, labelStr);
+ }
+ return b;
}
diff --git a/app/wlib/gtklib/control.c b/app/wlib/gtklib/control.c
index 0332470..d43d2b6 100644
--- a/app/wlib/gtklib/control.c
+++ b/app/wlib/gtklib/control.c
@@ -1,7 +1,7 @@
/** \file control.c
* Control Utilities
*/
-/*
+/*
* Copyright 2016 Martin Fischer <m_fischer@sf.net>
*
* This program is free software; you can redistribute it and/or modify
@@ -46,31 +46,31 @@
*/
void wControlShow(
- wControl_p b,
- wBool_t show)
+ wControl_p b,
+ wBool_t show)
{
- if (b->type == B_LINES) {
- wlibLineShow((wLine_p)b, show);
- return;
- }
-
- if (b->widget == NULL) {
- abort();
- }
-
- if (show) {
- gtk_widget_show(b->widget);
-
- if (b->label) {
- gtk_widget_show(b->label);
- }
- } else {
- gtk_widget_hide(b->widget);
-
- if (b->label) {
- gtk_widget_hide(b->label);
- }
- }
+ if (b->type == B_LINES) {
+ wlibLineShow((wLine_p)b, show);
+ return;
+ }
+
+ if (b->widget == NULL) {
+ abort();
+ }
+
+ if (show) {
+ gtk_widget_show(b->widget);
+
+ if (b->label) {
+ gtk_widget_show(b->label);
+ }
+ } else {
+ gtk_widget_hide(b->widget);
+
+ if (b->label) {
+ gtk_widget_hide(b->label);
+ }
+ }
}
/**
@@ -82,24 +82,24 @@ void wControlShow(
*/
void wControlActive(
- wControl_p b,
- int active)
+ wControl_p b,
+ int active)
{
- if (b->widget == NULL) {
- abort();
- }
+ if (b->widget == NULL) {
+ abort();
+ }
- if (b->type == B_LIST || b->type == B_DROPLIST ) {
+ if (b->type == B_LIST || b->type == B_DROPLIST ) {
- gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(b->widget)), active);
- gtk_combo_box_set_button_sensitivity(GTK_COMBO_BOX(b->widget),
- active?GTK_SENSITIVITY_ON:GTK_SENSITIVITY_OFF);
+ gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(b->widget)), active);
+ gtk_combo_box_set_button_sensitivity(GTK_COMBO_BOX(b->widget),
+ active?GTK_SENSITIVITY_ON:GTK_SENSITIVITY_OFF);
- } else {
+ } else {
- gtk_widget_set_sensitive(GTK_WIDGET(b->widget), active);
+ gtk_widget_set_sensitive(GTK_WIDGET(b->widget), active);
- }
+ }
}
/**
@@ -113,16 +113,16 @@ void wControlActive(
*/
wWinPix_t wLabelWidth(
- const char * label)
+ const char * label)
{
- GtkWidget * widget;
- 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;
+ GtkWidget * widget;
+ 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;
}
/**
@@ -133,9 +133,9 @@ wWinPix_t wLabelWidth(
*/
wWinPix_t wControlGetWidth(
- wControl_p b)
+ wControl_p b)
{
- return b->w;
+ return b->w;
}
/**
@@ -146,9 +146,9 @@ wWinPix_t wControlGetWidth(
*/
wWinPix_t wControlGetHeight(
- wControl_p b)
+ wControl_p b)
{
- return b->h;
+ return b->h;
}
/**
@@ -159,9 +159,9 @@ wWinPix_t wControlGetHeight(
*/
wWinPix_t wControlGetPosX(
- wControl_p b) /* Control */
+ wControl_p b) /* Control */
{
- return b->realX;
+ return b->realX;
}
/**
@@ -172,9 +172,10 @@ wWinPix_t wControlGetPosX(
*/
wWinPix_t wControlGetPosY(
- wControl_p b) /* Control */
+ wControl_p b) /* Control */
{
- return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0);
+ return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR)
+ ?b->parent->menu_height:0);
}
/**
@@ -186,27 +187,29 @@ wWinPix_t wControlGetPosY(
*/
void wControlSetPos(
- wControl_p b,
- wWinPix_t x,
- wWinPix_t y)
+ wControl_p b,
+ wWinPix_t x,
+ wWinPix_t y)
{
- b->realX = x;
- 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+(reqwidget.height/2 - requisition.height/2));
- }
+ b->realX = x;
+ 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+(reqwidget.height/2 - requisition.height/2));
+ }
}
/**
@@ -217,24 +220,25 @@ void wControlSetPos(
*/
void wControlSetLabel(
- wControl_p b,
- const char * labelStr)
+ wControl_p b,
+ const char * labelStr)
{
- 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+(reqwidget.height/2 - requisition.height/2));
- } else {
- b->labelW = wlibAddLabel(b, labelStr);
- }
+ 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+(reqwidget.height/2 - requisition.height/2));
+ } else {
+ b->labelW = wlibAddLabel(b, labelStr);
+ }
}
/**
@@ -245,10 +249,10 @@ void wControlSetLabel(
*/
void wControlSetContext(
- wControl_p b,
- void * context)
+ wControl_p b,
+ void * context)
{
- b->data = context;
+ b->data = context;
}
/**
@@ -258,31 +262,21 @@ void wControlSetContext(
*/
void wControlSetFocus(
- wControl_p b)
+ wControl_p b)
{
}
wBool_t wControlExpose (
- GtkWidget * widget,
- GdkEventExpose * event,
- wControl_p b
- )
+ GtkWidget * widget,
+ GdkEventExpose * event,
+ wControl_p b
+)
{
GdkWindow * win = gtk_widget_get_window(b->widget);
cairo_t * cr = NULL;
if (win) {
cr = gdk_cairo_create(win);
- } else return TRUE;
-
-#ifdef CURSOR_SURFACE
- if (b && b->cursor_surface.surface && b->cursor_surface.show) {
- cairo_set_source_surface(cr,b->cursor_surface.surface,event->area.x, event->area.y);
- cairo_set_operator(cr,CAIRO_OPERATOR_OVER);
- cairo_rectangle(cr,event->area.x, event->area.y,
- event->area.width, event->area.height);
- cairo_fill(cr);
- }
-#endif
+ } else { return TRUE; }
if (b->outline) {
cairo_set_source_rgb(cr, 0.23, 0.37, 0.80);
@@ -291,7 +285,7 @@ wBool_t wControlExpose (
cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
cairo_rectangle(cr,event->area.x+2, event->area.y+2,
- event->area.width-4, event->area.height-4);
+ event->area.width-4, event->area.height-4);
cairo_stroke(cr);
}
@@ -299,7 +293,7 @@ wBool_t wControlExpose (
cairo_destroy(cr);
- return FALSE;
+ return FALSE;
}
/**
@@ -311,19 +305,21 @@ wBool_t wControlExpose (
*
*/
void wControlHilite(
- wControl_p b,
- wBool_t hilite)
+ wControl_p b,
+ wBool_t hilite)
{
- cairo_t *cr;
- int off = GTKCONTROLHILITEWIDTH/2+1;
- if ( debugWindow >= 1 )
- printf( "wControlHIlite( %s, %d )\n", b->labelStr, hilite );
-
- if (b->widget == NULL) {
- return;
- }
- b->outline = hilite;
-
- if (b->widget)
- gtk_widget_queue_draw(b->widget);
+// cairo_t *cr;
+// int off = GTKCONTROLHILITEWIDTH/2+1;
+ if ( debugWindow >= 1 ) {
+ printf( "wControlHIlite( %s, %d )\n", b->labelStr, hilite );
+ }
+
+ if (b->widget == NULL) {
+ return;
+ }
+ b->outline = hilite;
+
+ if (b->widget) {
+ gtk_widget_queue_draw(b->widget);
+ }
}
diff --git a/app/wlib/gtklib/droplist.c b/app/wlib/gtklib/droplist.c
index 91406fc..a4abced 100644
--- a/app/wlib/gtklib/droplist.c
+++ b/app/wlib/gtklib/droplist.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -51,30 +51,30 @@
int
wlibDropListAddColumns(GtkWidget *dropList, int columns)
{
- int i;
- int start = 0;
- GtkCellRenderer *cell;
-
- if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(dropList))) {
- start = 1;
- }
-
- /* Create cell renderer. */
- cell = gtk_cell_renderer_text_new();
-
- for (i = start; i < columns; i++) {
- /* Pack it into the droplist */
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropList), cell, TRUE);
-
- /* Connect renderer to data source */
- gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropList),
- cell,
- "text",
- LISTCOL_TEXT + i,
- NULL);
- }
-
- return (i);
+ int i;
+ int start = 0;
+ GtkCellRenderer *cell;
+
+ if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(dropList))) {
+ start = 1;
+ }
+
+ /* Create cell renderer. */
+ cell = gtk_cell_renderer_text_new();
+
+ for (i = start; i < columns; i++) {
+ /* Pack it into the droplist */
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropList), cell, TRUE);
+
+ /* Connect renderer to data source */
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropList),
+ cell,
+ "text",
+ LISTCOL_TEXT + i,
+ NULL);
+ }
+
+ return (i);
}
/**
@@ -86,7 +86,7 @@ wlibDropListAddColumns(GtkWidget *dropList, int columns)
wIndex_t wDropListGetCount(wList_p b)
{
- return (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(b->listStore), NULL));
+ return (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(b->listStore), NULL));
}
/**
@@ -99,7 +99,7 @@ wIndex_t wDropListGetCount(wList_p b)
void
wDropListClear(wList_p b)
{
- wlibListStoreClear(b->listStore);
+ wlibListStoreClear(b->listStore);
}
/**
@@ -111,22 +111,22 @@ wDropListClear(wList_p b)
void *wDropListGetItemContext(wList_p b, wIndex_t inx)
{
- GtkTreeIter iter;
- wListItem_p data = NULL;
-
- if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
- inx)) {
- gtk_tree_model_get(GTK_TREE_MODEL(b->listStore),
- &iter,
- LISTCOL_DATA, (void *)&data,
- -1);
- }
-
- if (data) {
- return (data->itemData);
- } else {
- return (NULL);
- }
+ GtkTreeIter iter;
+ wListItem_p data = NULL;
+
+ if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
+ inx)) {
+ gtk_tree_model_get(GTK_TREE_MODEL(b->listStore),
+ &iter,
+ LISTCOL_DATA, (void *)&data,
+ -1);
+ }
+
+ if (data) {
+ return (data->itemData);
+ } else {
+ return (NULL);
+ }
}
/**
@@ -138,21 +138,21 @@ void *wDropListGetItemContext(wList_p b, wIndex_t inx)
*/
void wDropListAddValue(
- wList_p b,
- char *text,
- wListItem_p data)
+ wList_p b,
+ char *text,
+ wListItem_p data)
{
- GtkTreeIter iter;
+ GtkTreeIter iter;
- assert(b != NULL);
- assert(text != NULL);
+ assert(b != NULL);
+ assert(text != NULL);
- gtk_list_store_append(b->listStore, &iter); // append new row to tree store
+ gtk_list_store_append(b->listStore, &iter); // append new row to tree store
- gtk_list_store_set(b->listStore, &iter,
- LISTCOL_TEXT, text,
- LISTCOL_DATA, (void *)data,
- -1);
+ gtk_list_store_set(b->listStore, &iter,
+ LISTCOL_TEXT, text,
+ LISTCOL_DATA, (void *)data,
+ -1);
}
/**
@@ -162,25 +162,25 @@ void wDropListAddValue(
*/
void wListSetValue(
- wList_p bl,
- const char * val)
+ wList_p bl,
+ const char * val)
{
- assert(bl->listStore!=NULL);
+ assert(bl->listStore!=NULL);
- bl->recursion++;
+ bl->recursion++;
- if (bl->type == B_DROPLIST) {
- bl->editted = TRUE;
- gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))), val);
+ if (bl->type == B_DROPLIST) {
+ bl->editted = TRUE;
+ gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))), val);
- if (bl->action) {
- bl->action(-1, val, 0, bl->data, NULL);
- }
- } else {
- assert(FALSE);
- }
+ if (bl->action) {
+ bl->action(-1, val, 0, bl->data, NULL);
+ }
+ } else {
+ assert(FALSE);
+ }
- bl->recursion--;
+ bl->recursion--;
}
/**
@@ -195,11 +195,11 @@ void wListSetValue(
void wDropListSetIndex(wList_p b, int val)
{
- if ((b->option&BL_NONE)!=0 && val < 0) {
- gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), -1);
- } else {
- gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), val);
- }
+ if ((b->option&BL_NONE)!=0 && val < 0) {
+ gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), -1);
+ } else {
+ gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), val);
+ }
}
/**
@@ -214,24 +214,24 @@ void wDropListSetIndex(wList_p b, int val)
*/
wBool_t wDropListSetValues(
- wList_p b,
- wIndex_t row,
- const char * labelStr,
- wIcon_p bm,
- void *itemData)
+ wList_p b,
+ wIndex_t row,
+ const char * labelStr,
+ wIcon_p bm,
+ void *itemData)
{
- GtkTreeIter iter;
-
- if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
- row)) {
- gtk_list_store_set(b->listStore,
- &iter,
- LISTCOL_TEXT, labelStr,
- -1);
- return (TRUE);
- } else {
- return (FALSE);
- }
+ GtkTreeIter iter;
+
+ if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
+ row)) {
+ gtk_list_store_set(b->listStore,
+ &iter,
+ LISTCOL_TEXT, labelStr,
+ -1);
+ return (TRUE);
+ } else {
+ return (FALSE);
+ }
}
/**
@@ -245,72 +245,75 @@ wBool_t wDropListSetValues(
*/
static int DropListChanged(
- GtkComboBox * comboBox,
- gpointer data)
+ GtkComboBox * comboBox,
+ gpointer data)
{
- wList_p bl = (wList_p)data;
- GtkTreeIter iter;
-
- wIndex_t inx = 0;
- gchar *string = NULL;
- wListItem_p listItemP = NULL;
-
- if (bl->recursion) {
- return 0;
- }
-
- /* Obtain currently selected item from combo box. */
- if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(comboBox), &iter)) {
- GtkTreeModel *model;
-
- /* Obtain data model from combo box. */
- model = gtk_combo_box_get_model(comboBox);
-
- /* get the selected row */
- string = gtk_tree_model_get_string_from_iter(model,
- &iter);
- inx = atoi(string);
- g_free(string);
- string = NULL;
-
- /* Obtain string from model. */
- gtk_tree_model_get(model, &iter,
- LISTCOL_TEXT, &string,
- LISTCOL_DATA, (void *)&listItemP,
- -1);
- bl->editted = FALSE;
-
- } else {
- /* Nothing selected, user is entering text directly */
- inx = -1;
- GtkEntry * entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget)));
- if ( entry == NULL )
- return 0;
- const char * string1 = gtk_entry_get_text(entry);
- if ( string1 == NULL )
- return 0;
- string = g_strdup(string1);
- bl->editted = TRUE;
- }
-
- /* selection changed, store new selections and call back */
- if (bl->last != inx || bl->editted == TRUE) {
-
- bl->last = inx;
-
- if (bl->valueP) {
- *bl->valueP = inx;
- }
-
- /* selection changed -> callback */
- if (string && bl->action) {
- bl->action(inx, string, 1, bl->data, listItemP?listItemP->itemData:NULL);
- }
- }
-
- if ( string )
- g_free(string);
- return 1;
+ wList_p bl = (wList_p)data;
+ GtkTreeIter iter;
+
+ wIndex_t inx = 0;
+ gchar *string = NULL;
+ wListItem_p listItemP = NULL;
+
+ if (bl->recursion) {
+ return 0;
+ }
+
+ /* Obtain currently selected item from combo box. */
+ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(comboBox), &iter)) {
+ GtkTreeModel *model;
+
+ /* Obtain data model from combo box. */
+ model = gtk_combo_box_get_model(comboBox);
+
+ /* get the selected row */
+ string = gtk_tree_model_get_string_from_iter(model,
+ &iter);
+ inx = atoi(string);
+ g_free(string);
+ string = NULL;
+
+ /* Obtain string from model. */
+ gtk_tree_model_get(model, &iter,
+ LISTCOL_TEXT, &string,
+ LISTCOL_DATA, (void *)&listItemP,
+ -1);
+ bl->editted = FALSE;
+
+ } else {
+ /* Nothing selected, user is entering text directly */
+ inx = -1;
+ GtkEntry * entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget)));
+ if ( entry == NULL ) {
+ return 0;
+ }
+ const char * string1 = gtk_entry_get_text(entry);
+ if ( string1 == NULL ) {
+ return 0;
+ }
+ string = g_strdup(string1);
+ bl->editted = TRUE;
+ }
+
+ /* selection changed, store new selections and call back */
+ if (bl->last != inx || bl->editted == TRUE) {
+
+ bl->last = inx;
+
+ if (bl->valueP) {
+ *bl->valueP = inx;
+ }
+
+ /* selection changed -> callback */
+ if (string && bl->action) {
+ bl->action(inx, string, 1, bl->data, listItemP?listItemP->itemData:NULL);
+ }
+ }
+
+ if ( string ) {
+ g_free(string);
+ }
+ return 1;
}
/**
@@ -324,15 +327,15 @@ static int DropListChanged(
GtkWidget *
wlibNewDropList(GtkListStore *ls, int editable)
{
- GtkWidget *widget;
+ GtkWidget *widget;
- if (editable) {
- widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(ls));
- } else {
- widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls));
- }
+ if (editable) {
+ widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(ls));
+ } else {
+ widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls));
+ }
- return (widget);
+ return (widget);
}
/**
@@ -352,80 +355,80 @@ wlibNewDropList(GtkListStore *ls, int editable)
*/
wList_p wDropListCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- long *valueP,
- wListCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ long *valueP,
+ wListCallBack_p action,
+ void *data)
{
- wList_p b;
+ wList_p b;
- b = (wList_p)wlibAlloc(parent, B_DROPLIST, x, y, labelStr, sizeof *b, data);
- b->option = option;
- b->number = number;
- b->count = 0;
- b->last = -1;
- b->valueP = valueP;
- b->action = action;
- b->listX = b->realX;
- b->colCnt = 0;
- b->colWidths = NULL;
- b->colRightJust = NULL;
- b->editable = ((option & BL_EDITABLE) != 0);
+ b = (wList_p)wlibAlloc(parent, B_DROPLIST, x, y, labelStr, sizeof *b, data);
+ b->option = option;
+ b->number = number;
+ b->count = 0;
+ b->last = -1;
+ b->valueP = valueP;
+ b->action = action;
+ b->listX = b->realX;
+ b->colCnt = 0;
+ b->colWidths = NULL;
+ b->colRightJust = NULL;
+ b->editable = ((option & BL_EDITABLE) != 0);
- assert(width != 0);
+ assert(width != 0);
- wlibComputePos((wControl_p)b);
+ wlibComputePos((wControl_p)b);
- // create tree store for storing the contents
- b->listStore = wlibNewListStore(DROPLIST_TEXTCOLUMNS);
+ // create tree store for storing the contents
+ b->listStore = wlibNewListStore(DROPLIST_TEXTCOLUMNS);
- if (!b->listStore) {
- abort();
- }
+ if (!b->listStore) {
+ abort();
+ }
- // create the droplist
- b->widget = wlibNewDropList(b->listStore,
- option & BL_EDITABLE);
+ // create the droplist
+ b->widget = wlibNewDropList(b->listStore,
+ option & BL_EDITABLE);
- if (b->widget == 0) {
- abort();
- }
- g_object_ref_sink(b->listStore);
- g_object_unref(G_OBJECT(b->listStore));
+ if (b->widget == 0) {
+ abort();
+ }
+ g_object_ref_sink(b->listStore);
+ g_object_unref(G_OBJECT(b->listStore));
- wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS);
+ wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS);
- gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(b->widget),
- LISTCOL_TEXT);
+ gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(b->widget),
+ LISTCOL_TEXT);
- // combo's style
- gtk_rc_parse_string("style \"my-style\" { GtkComboBox::appears-as-list = 1 } widget \"*.mycombo\" style \"my-style\" ");
- gtk_widget_set_name(b->widget,"mycombo");
+ // combo's style
+ gtk_rc_parse_string("style \"my-style\" { GtkComboBox::appears-as-list = 1 } widget \"*.mycombo\" style \"my-style\" ");
+ gtk_widget_set_name(b->widget,"mycombo");
- g_signal_connect(GTK_OBJECT(b->widget), "changed",
- G_CALLBACK(DropListChanged), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "changed",
+ G_CALLBACK(DropListChanged), b);
- gtk_widget_set_size_request(b->widget, width, -1);
+ gtk_widget_set_size_request(b->widget, width, -1);
- gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
- wlibControlGetSize((wControl_p)b);
+ gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
+ wlibControlGetSize((wControl_p)b);
- if (labelStr) {
- b->labelW = wlibAddLabel((wControl_p)b, labelStr);
- }
+ if (labelStr) {
+ b->labelW = wlibAddLabel((wControl_p)b, labelStr);
+ }
- gtk_widget_show(b->widget);
- wlibAddButton((wControl_p)b);
- wlibAddHelpString(b->widget, helpStr);
+ gtk_widget_show(b->widget);
+ wlibAddButton((wControl_p)b);
+ wlibAddHelpString(b->widget, helpStr);
- return b;
+ return b;
}
diff --git a/app/wlib/gtklib/dynarr.h b/app/wlib/gtklib/dynarr.h
index 2adf115..1eefd62 100644
--- a/app/wlib/gtklib/dynarr.h
+++ b/app/wlib/gtklib/dynarr.h
@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -22,10 +22,10 @@
#define DYNARR_H_SEEN
typedef struct {
- int cnt;
- int max;
- void * ptr;
- } dynArr_t;
+ int cnt;
+ int max;
+ void * ptr;
+} dynArr_t;
#define DYNARR_APPEND(T,DA,INCR) \
{ if ((DA).cnt >= (DA).max) { \
diff --git a/app/wlib/gtklib/filesel.c b/app/wlib/gtklib/filesel.c
index 7e27465..3d4fb85 100644
--- a/app/wlib/gtklib/filesel.c
+++ b/app/wlib/gtklib/filesel.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -41,114 +41,115 @@
#define MAX_ALLOWEDFILTERS 10
struct wFilSel_t {
- GtkWidget * window; /**< file selector handle*/
- wFilSelCallBack_p action; /**< */
- void * data; /**< */
- int pattCount; /**< number of file patterns*/
- wBool_t loadPatternsAdded; /** Already loaded */
- GtkFileFilter *filter[ MAX_ALLOWEDFILTERS ]; /**< array of file patterns */
- wFilSelMode_e mode; /**< used for load or save */
- int opt; /**< see FS_ options */
- const char * title; /**< dialog box title */
- wWin_p parent; /**< parent window */
- char *defaultExtension; /**< to use if no extension specified */
- };
+ GtkWidget * window; /**< file selector handle*/
+ wFilSelCallBack_p action; /**< */
+ void * data; /**< */
+ int pattCount; /**< number of file patterns*/
+ wBool_t loadPatternsAdded; /** Already loaded */
+ GtkFileFilter *filter[ MAX_ALLOWEDFILTERS ]; /**< array of file patterns */
+ wFilSelMode_e mode; /**< used for load or save */
+ int opt; /**< see FS_ options */
+ const char * title; /**< dialog box title */
+ wWin_p parent; /**< parent window */
+ char *defaultExtension; /**< to use if no extension specified */
+};
/**
* Signal handler for 'changed' signal of custom combo box. The filter
* is set accordinng to the file format active in the combo box
- *
- * \param comboBox the combo box
+ *
+ * \param comboBox the combo box
* \param fileSelector data of the file selector
- *
+ *
*/
-static void FileFormatChanged( GtkWidget *comboBox,
- struct wFilSel_t *fileSelector )
+static void FileFormatChanged( GtkWidget *comboBox,
+ struct wFilSel_t *fileSelector )
{
// get active entry
int entry = (int)gtk_combo_box_get_active (GTK_COMBO_BOX(comboBox));
-
+
if( entry>=0 ) {
- g_object_ref(G_OBJECT( (fileSelector->filter)[ entry ]));
- gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fileSelector->window ),
- (fileSelector->filter)[ entry ]);
+ g_object_ref(G_OBJECT( (fileSelector->filter)[ entry ]));
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fileSelector->window ),
+ (fileSelector->filter)[ entry ]);
}
}
/**
- * Create a widget containing a combo box for selecting a file format.
+ * Create a widget containing a combo box for selecting a file format.
* From an array of filters, the names are retrieved and used to populate
- * the combo box.
+ * the combo box.
* \param IN dialogBox
* \param patterns IN number of entries for combo
* \param filters IN
* \returns the newly created widget
*/
-
-static GtkWidget *CreateFileformatSelector(struct wFilSel_t *dialogBox,
- int patterns,
- GtkFileFilter **filters)
+
+static GtkWidget *CreateFileformatSelector(struct wFilSel_t *dialogBox,
+ int patterns,
+ GtkFileFilter **filters)
{
GtkWidget *hbox = gtk_hbox_new(FALSE, 12);
GtkWidget *text = gtk_label_new(_("Save format:"));
GtkWidget *combo = gtk_combo_box_text_new ();
- g_signal_connect(G_OBJECT(combo),
- "changed",
- (GCallback)FileFormatChanged,
- dialogBox );
+ g_signal_connect(G_OBJECT(combo),
+ "changed",
+ (GCallback)FileFormatChanged,
+ dialogBox );
gtk_box_pack_start (GTK_BOX(hbox),
- text,
- FALSE,
- FALSE,
- 0);
+ text,
+ FALSE,
+ FALSE,
+ 0);
gtk_box_pack_end (GTK_BOX(hbox),
- combo,
- TRUE,
- TRUE,
- 0);
+ combo,
+ TRUE,
+ TRUE,
+ 0);
for(int i=0; i < patterns; i++ ) {
const char *nameOfFilter = gtk_file_filter_get_name( filters[ i ] );
gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(combo), nameOfFilter );
}
gtk_combo_box_set_active (GTK_COMBO_BOX(combo), 0);
-
+
gtk_widget_show_all(hbox);
-
- return(hbox);
+
+ return(hbox);
}
/**
* Create a new file selector. Only the internal data structures are
- * set up, no dialog is created.
+ * set up, no dialog is created.
*
* \param w IN parent window
* \param mode IN ?
* \param opt IN ?
* \param title IN dialog title
* \param pattList IN list of selection patterns
- * \param action IN callback
+ * \param action IN callback
* \param data IN ?
* \return the newly created file selector structure
*/
-
+
struct wFilSel_t * wFilSelCreate(
- wWin_p w,
- wFilSelMode_e mode,
- int opt,
- const char * title,
- const char * pattList,
- wFilSelCallBack_p action,
- void * data )
+ wWin_p w,
+ wFilSelMode_e mode,
+ int opt,
+ const char * title,
+ const char * pattList,
+ wFilSelCallBack_p action,
+ void * data )
{
struct wFilSel_t *fs;
fs = (struct wFilSel_t*)malloc(sizeof *fs);
- if (!fs)
+ if (!fs) {
return NULL;
+ }
fs->parent = w;
fs->window = 0;
@@ -208,22 +209,24 @@ struct wFilSel_t * wFilSelCreate(
gtk_file_filter_add_pattern (fs->filter[ count ], cp1 );
cp1 = strtok_r(NULL, ";", &filterState );
}
- if (cp1s)
+ if (cp1s) {
free(cp1s);
+ }
}
// the first pattern is considered to match the default extension
if( count == 0 && !(opt&FS_PICTURES)) {
fs->defaultExtension = strdup( cp2 );
int i = 0;
- for (i=0; i<strlen(cp2) && cp2[i] != ' ' && cp2[i] != ';';i++) ;
- if (i<strlen(cp2)) fs->defaultExtension[i] = '\0';
+ for (i=0; i<strlen(cp2) && cp2[i] != ' ' && cp2[i] != ';'; i++) ;
+ if (i<strlen(cp2)) { fs->defaultExtension[i] = '\0'; }
}
fs->pattCount = ++count;
}
cp = strtok_r( NULL, ":", &patternState );
}
- if (cps)
+ if (cps) {
free(cps);
+ }
} else {
@@ -234,13 +237,13 @@ struct wFilSel_t * wFilSelCreate(
}
/**
- * Show and handle the file selection dialog.
+ * Show and handle the file selection dialog.
*
- * \param fs IN file selection
+ * \param fs IN file selection
* \param dirName IN starting directory
* \return always TRUE
*/
-
+
int wFilSelect( struct wFilSel_t * fs, const char * dirName )
{
char name[1024];
@@ -250,67 +253,71 @@ int wFilSelect( struct wFilSel_t * fs, const char * dirName )
GError *err = NULL;
if (fs->window == NULL) {
- fs->window = gtk_file_chooser_dialog_new( fs->title,
- GTK_WINDOW( fs->parent->gtkwin ),
- (fs->mode == FS_LOAD ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE ),
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- (fs->mode == FS_LOAD ? GTK_STOCK_OPEN : GTK_STOCK_SAVE ), GTK_RESPONSE_ACCEPT,
- NULL );
- if (fs->window==0) abort();
+ fs->window = gtk_file_chooser_dialog_new( fs->title,
+ GTK_WINDOW( fs->parent->gtkwin ),
+ (fs->mode == FS_LOAD ? GTK_FILE_CHOOSER_ACTION_OPEN :
+ GTK_FILE_CHOOSER_ACTION_SAVE ),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ (fs->mode == FS_LOAD ? GTK_STOCK_OPEN : GTK_STOCK_SAVE ), GTK_RESPONSE_ACCEPT,
+ NULL );
+ if (fs->window==0) { abort(); }
if ( fs->mode == FS_SAVE ) {
- // get confirmation before overwritting an existing file
- gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(fs->window), TRUE );
+ // get confirmation before overwritting an existing file
+ gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(fs->window),
+ TRUE );
}
-
+
/** \todo for loading a shortcut folder could be added linking to the example directory */
}
strcpy( name, dirName );
- gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(fs->window), name );
+ gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(fs->window), name );
if( fs->mode == FS_SAVE || fs->mode == FS_UPDATE ) {
- gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER(fs->window),
- CreateFileformatSelector(fs, fs->pattCount, fs->filter ));
- }
- // Add a current folder and a shortcut to it for Load/import dialogs
- if( fs->mode == FS_LOAD ) {
- gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER(fs->window), name, NULL );
+ gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER(fs->window),
+ CreateFileformatSelector(fs, fs->pattCount, fs->filter ));
+ }
+ // Add a current folder and a shortcut to it for Load/import dialogs
+ if( fs->mode == FS_LOAD ) {
+ gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER(fs->window), name,
+ NULL );
// allow selecting multiple files
if( fs->opt & FS_MULTIPLEFILES ) {
gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(fs->window), TRUE);
- }
+ }
// add the file filters to the dialog box
if( fs->pattCount && !fs->loadPatternsAdded) {
for( i = 0; i < fs->pattCount; i++ ) {
- gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( fs->window ), fs->filter[ i ] );
+ gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( fs->window ), fs->filter[ i ] );
}
fs->loadPatternsAdded = TRUE;
- }
- }
-
- int resp = gtk_dialog_run( GTK_DIALOG( fs->window ));
+ }
+ }
+
+ int resp = gtk_dialog_run( GTK_DIALOG( fs->window ));
if( resp == GTK_RESPONSE_ACCEPT || resp == GTK_RESPONSE_APPLY) {
- char **fileNames;
+ char **fileNames;
GSList *fileNameList;
-
+
fileNameList = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER(fs->window) );
- fileNames = calloc( sizeof(char *), g_slist_length (fileNameList) );
-
+ fileNames = calloc( sizeof(char *), g_slist_length (fileNameList) );
+
for (i=0; i < g_slist_length (fileNameList); i++ ) {
char *namePart;
file = g_filename_from_uri( g_slist_nth_data( fileNameList, i ), &host, &err );
-
+
// check for presence of file extension
// jump behind the last directory delimiter
namePart = strrchr( file, '/' ) + 1;
// is there a dot in the last part, yes->extension present
- if( !strchr( namePart, '.' ) ){
-
+ if( !strchr( namePart, '.' ) ) {
+
// else try to find the current filter and parse its name
- GtkFileFilter *currentFilter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER(fs->window) );
+ GtkFileFilter *currentFilter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER(
+ fs->window) );
if (currentFilter) {
const char *nameOfFilter = gtk_file_filter_get_name( currentFilter );
char *pattern = strdup( nameOfFilter );
@@ -328,24 +335,24 @@ int wFilSelect( struct wFilSel_t * fs, const char * dirName )
strcat( file, extension );
free( pattern );
}
- }
+ }
fileNames[ i ] = file;
g_free( g_slist_nth_data ( fileNameList, i));
}
-
+
gtk_widget_hide( GTK_WIDGET( fs->window ));
if (fs->action) {
fs->action( g_slist_length(fileNameList), fileNames, fs->data );
}
-
+
for(i=0; i < g_slist_length(fileNameList); i++) {
g_free( fileNames[ i ]);
}
free( fileNames );
- g_slist_free (fileNameList);
+ g_slist_free (fileNameList);
} else {
gtk_widget_hide( GTK_WIDGET( fs->window ));
}
-
+
return 1;
}
diff --git a/app/wlib/gtklib/font.c b/app/wlib/gtklib/font.c
index 29df04d..e89307c 100644
--- a/app/wlib/gtklib/font.c
+++ b/app/wlib/gtklib/font.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@@ -67,7 +67,7 @@ static GtkWidget *fontSelectionDialog;
int absoluteFontSize = 18;
struct wFont_t {
- PangoFontDescription *fontDescription;
+ PangoFontDescription *fontDescription;
};
static wFont_p standardFonts[F_HELV-F_TIMES+1][2][2];
@@ -85,76 +85,76 @@ static wFont_p curFont = NULL;
static void fontSelectionDialogCallback(GtkFontSelectionDialog
*fontSelectionDialog, gint response, gpointer data)
{
- if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) {
- gchar *fontName;
-
- fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog);
- wPrefSetString("font", "name", fontName);
- pango_font_description_free(curFont->fontDescription);
- curFont->fontDescription = pango_font_description_from_string(fontName);
- absoluteFontSize = (pango_font_description_get_size(
- curFont->fontDescription))/PANGO_SCALE;
+ if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) {
+ gchar *fontName;
+
+ fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog);
+ wPrefSetString("font", "name", fontName);
+ pango_font_description_free(curFont->fontDescription);
+ curFont->fontDescription = pango_font_description_from_string(fontName);
+ absoluteFontSize = (pango_font_description_get_size(
+ curFont->fontDescription))/PANGO_SCALE;
#if WLIB_FONT_DEBUG >= 2
- fprintf(stderr, "new font selection:\n");
- fprintf(stderr, " font name \"%s\"\n", fontName);
- fprintf(stderr, " font size is %d\n",
- pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE);
- fprintf(stderr, " font size is absolute %d\n",
- pango_font_description_get_size_is_absolute(curFont->fontDescription));
+ fprintf(stderr, "new font selection:\n");
+ fprintf(stderr, " font name \"%s\"\n", fontName);
+ fprintf(stderr, " font size is %d\n",
+ pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE);
+ fprintf(stderr, " font size is absolute %d\n",
+ pango_font_description_get_size_is_absolute(curFont->fontDescription));
#endif
- g_free(fontName);
- }
+ g_free(fontName);
+ }
- if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_CANCEL) {
- gtk_widget_hide(GTK_WIDGET(fontSelectionDialog));
- }
+ if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_CANCEL) {
+ gtk_widget_hide(GTK_WIDGET(fontSelectionDialog));
+ }
}
static wBool_t fontInitted = FALSE;
static wBool_t fontInit()
{
- const char *fontNames[] = {
- "times 18",
- "times italic 18",
- "times bold 18",
- "times bold italic 18",
- "helvetica 18",
- "helvetica oblique 18",
- "helvetica bold 18",
- "helvetica bold oblique 18",
- };
- int s = 0;
- int i, j, k;
-
- for (i = F_TIMES; i <= F_HELV; ++i) {
- for (j = FW_MEDIUM; j <= FW_BOLD; ++j) {
- for (k = FS_REGULAR; k <= FS_ITALIC; ++k) {
- PangoFontDescription *fontDescription = pango_font_description_from_string(
- fontNames[s++]);
- wFont_p standardFont = (wFont_p) malloc(sizeof(struct wFont_t));
- standardFont->fontDescription = fontDescription;
- standardFonts[i-F_TIMES][j][k] = standardFont;
- }
- }
- }
-
- if (curFont == NULL) {
- curFont = (wFont_p) malloc(sizeof(struct wFont_t));
-
- if (curFont == NULL) {
- return FALSE;
- }
-
- const char *fontName = wPrefGetString("font", "name");
- curFont->fontDescription = pango_font_description_from_string(
- fontName ? fontName : "helvetica 18");
- absoluteFontSize = (int) PANGO_PIXELS(pango_font_description_get_size(
- curFont->fontDescription));
- }
-
- fontInitted = TRUE;
- return TRUE;
+ const char *fontNames[] = {
+ "times 18",
+ "times italic 18",
+ "times bold 18",
+ "times bold italic 18",
+ "helvetica 18",
+ "helvetica oblique 18",
+ "helvetica bold 18",
+ "helvetica bold oblique 18",
+ };
+ int s = 0;
+ int i, j, k;
+
+ for (i = F_TIMES; i <= F_HELV; ++i) {
+ for (j = FW_MEDIUM; j <= FW_BOLD; ++j) {
+ for (k = FS_REGULAR; k <= FS_ITALIC; ++k) {
+ PangoFontDescription *fontDescription = pango_font_description_from_string(
+ fontNames[s++]);
+ wFont_p standardFont = (wFont_p) malloc(sizeof(struct wFont_t));
+ standardFont->fontDescription = fontDescription;
+ standardFonts[i-F_TIMES][j][k] = standardFont;
+ }
+ }
+ }
+
+ if (curFont == NULL) {
+ curFont = (wFont_p) malloc(sizeof(struct wFont_t));
+
+ if (curFont == NULL) {
+ return FALSE;
+ }
+
+ const char *fontName = wPrefGetString("font", "name");
+ curFont->fontDescription = pango_font_description_from_string(
+ fontName ? fontName : "helvetica 18");
+ absoluteFontSize = (int) PANGO_PIXELS(pango_font_description_get_size(
+ curFont->fontDescription));
+ }
+
+ fontInitted = TRUE;
+ return TRUE;
}
@@ -186,59 +186,59 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget,
wDrawPix_t *height_p,
wDrawPix_t *ascent_p,
wDrawPix_t *descent_p,
- wDrawPix_t *baseline_p)
+ wDrawPix_t *baseline_p)
{
- if (!fontInitted) {
- fontInit();
- }
-
- PangoLayout *layout = NULL;
- gchar *utf8 = wlibConvertInput(s);
- /* RPH -- pango_cairo_create_layout() is missing in CentOS 4.8.
- CentOS 4.8 only has GTK 2.4.13 and Pango 1.6.0 and does not have
- libpangocairo at all.
- pango_cairo_create_layout() was introduced with Pango 1.10. */
+ if (!fontInitted) {
+ fontInit();
+ }
+
+ PangoLayout *layout = NULL;
+ gchar *utf8 = wlibConvertInput(s);
+ /* RPH -- pango_cairo_create_layout() is missing in CentOS 4.8.
+ CentOS 4.8 only has GTK 2.4.13 and Pango 1.6.0 and does not have
+ libpangocairo at all.
+ pango_cairo_create_layout() was introduced with Pango 1.10. */
#if PANGO_VERSION_MAJOR >= 1 && PANGO_VERSION_MINOR >= 10
- if (cairo != NULL) {
- layout = pango_cairo_create_layout((cairo_t *) cairo);
- pango_layout_set_text(layout, utf8, -1);
- } else
+ if (cairo != NULL) {
+ layout = pango_cairo_create_layout((cairo_t *) cairo);
+ pango_layout_set_text(layout, utf8, -1);
+ } else
#endif
- layout = gtk_widget_create_pango_layout(widget, utf8);
-
- PangoFontDescription *fontDescription = (fp ? fp : curFont)->fontDescription;
- PangoContext *context;
- PangoFontMetrics *metrics;
- /* set attributes */
- pango_font_description_set_size(fontDescription,
- FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE);
- pango_layout_set_font_description(layout, fontDescription);
- /* get layout measures */
- gint width_i, height_i;
- pango_layout_get_size(layout, &width_i, &height_i);
- *width_p = width_i / PANGO_SCALE;
- *height_p = height_i / PANGO_SCALE;
- context = gtk_widget_create_pango_context(widget);
- metrics = pango_context_get_metrics(context, fontDescription,
- pango_context_get_language(context));
- *baseline_p = pango_layout_get_baseline(layout) / PANGO_SCALE;
- *ascent_p = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
- *descent_p = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
- pango_font_metrics_unref(metrics);
- g_object_unref(context);
+ layout = gtk_widget_create_pango_layout(widget, utf8);
+
+ PangoFontDescription *fontDescription = (fp ? fp : curFont)->fontDescription;
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ /* set attributes */
+ pango_font_description_set_size(fontDescription,
+ FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE);
+ pango_layout_set_font_description(layout, fontDescription);
+ /* get layout measures */
+ gint width_i, height_i;
+ pango_layout_get_size(layout, &width_i, &height_i);
+ *width_p = width_i / PANGO_SCALE;
+ *height_p = height_i / PANGO_SCALE;
+ context = gtk_widget_create_pango_context(widget);
+ metrics = pango_context_get_metrics(context, fontDescription,
+ pango_context_get_language(context));
+ *baseline_p = pango_layout_get_baseline(layout) / PANGO_SCALE;
+ *ascent_p = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
+ *descent_p = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
+ pango_font_metrics_unref(metrics);
+ g_object_unref(context);
#if WLIB_FONT_DEBUG >= 3
- fprintf(stderr, "font layout created:\n");
- fprintf(stderr, " widget: %p\n", widget);
- //fprintf(stderr, " font description:%p\n", fp);
- fprintf(stderr, " font size: %f\n", fs);
- fprintf(stderr, " layout text: \"%s\" (utf8)\n", utf8);
- fprintf(stderr, " layout width: %d\n", *width_p);
- fprintf(stderr, " layout height: %d\n", *height_p);
- fprintf(stderr, " layout ascent: %d (pixels)\n", *ascent_p);
- fprintf(stderr, " layout descent: %d (pixels)\n", *descent_p);
+ fprintf(stderr, "font layout created:\n");
+ fprintf(stderr, " widget: %p\n", widget);
+ //fprintf(stderr, " font description:%p\n", fp);
+ fprintf(stderr, " font size: %f\n", fs);
+ fprintf(stderr, " layout text: \"%s\" (utf8)\n", utf8);
+ fprintf(stderr, " layout width: %d\n", *width_p);
+ fprintf(stderr, " layout height: %d\n", *height_p);
+ fprintf(stderr, " layout ascent: %d (pixels)\n", *ascent_p);
+ fprintf(stderr, " layout descent: %d (pixels)\n", *descent_p);
#endif
- return layout;
+ return layout;
}
/**
@@ -248,7 +248,7 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget,
void wlibFontDestroyPangoLayout(PangoLayout *layout)
{
- g_object_ref_sink(layout);
+ g_object_ref_sink(layout);
g_object_unref(layout);
}
@@ -259,9 +259,9 @@ void wlibFontDestroyPangoLayout(PangoLayout *layout)
void wInitializeFonts()
{
- if (!fontInitted) {
- fontInit();
- }
+ if (!fontInitted) {
+ fontInit();
+ }
}
/**
@@ -272,41 +272,41 @@ void wInitializeFonts()
*/
void wSelectFont(
- const char * title)
+ const char * title)
{
- if (!fontInitted) {
- fontInit();
- }
-
- if (fontSelectionDialog == NULL) {
- fontSelectionDialog = gtk_font_selection_dialog_new(_("Font Select"));
- gtk_window_set_position(GTK_WINDOW(fontSelectionDialog), GTK_WIN_POS_MOUSE);
- gtk_window_set_modal(GTK_WINDOW(fontSelectionDialog), TRUE);
- gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(
- fontSelectionDialog), sampleText);
- g_signal_connect(G_OBJECT(fontSelectionDialog), "response",
- G_CALLBACK(fontSelectionDialogCallback), NULL);
- g_signal_connect(G_OBJECT(fontSelectionDialog), "destroy",
- G_CALLBACK(gtk_widget_destroyed), &fontSelectionDialog);
- }
-
- gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title);
-
- if (curFont != NULL) {
- gchar *fontName;
-
- /* the curFont description contains the latest font info
- * which is depended on the current scale
- * overwrite it with the absoluteFontSize */
- pango_font_description_set_size(curFont->fontDescription,
- FONTSIZE_TO_PANGOSIZE(absoluteFontSize) * PANGO_SCALE);
- fontName = pango_font_description_to_string(curFont->fontDescription);
- gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(
- fontSelectionDialog), fontName);
- g_free(fontName);
- }
-
- gtk_widget_show(fontSelectionDialog);
+ if (!fontInitted) {
+ fontInit();
+ }
+
+ if (fontSelectionDialog == NULL) {
+ fontSelectionDialog = gtk_font_selection_dialog_new(_("Font Select"));
+ gtk_window_set_position(GTK_WINDOW(fontSelectionDialog), GTK_WIN_POS_MOUSE);
+ gtk_window_set_modal(GTK_WINDOW(fontSelectionDialog), TRUE);
+ gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(
+ fontSelectionDialog), sampleText);
+ g_signal_connect(G_OBJECT(fontSelectionDialog), "response",
+ G_CALLBACK(fontSelectionDialogCallback), NULL);
+ g_signal_connect(G_OBJECT(fontSelectionDialog), "destroy",
+ G_CALLBACK(gtk_widget_destroyed), &fontSelectionDialog);
+ }
+
+ gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title);
+
+ if (curFont != NULL) {
+ gchar *fontName;
+
+ /* the curFont description contains the latest font info
+ * which is depended on the current scale
+ * overwrite it with the absoluteFontSize */
+ pango_font_description_set_size(curFont->fontDescription,
+ FONTSIZE_TO_PANGOSIZE(absoluteFontSize) * PANGO_SCALE);
+ fontName = pango_font_description_to_string(curFont->fontDescription);
+ gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(
+ fontSelectionDialog), fontName);
+ g_free(fontName);
+ }
+
+ gtk_widget_show(fontSelectionDialog);
}
/**
@@ -317,11 +317,11 @@ void wSelectFont(
static wFont_p wlibSelectedFont(void)
{
- if (!fontInitted) {
- fontInit();
- }
+ if (!fontInitted) {
+ fontInit();
+ }
- return curFont;
+ return curFont;
}
/**
@@ -332,16 +332,16 @@ static wFont_p wlibSelectedFont(void)
wFontSize_t wSelectedFontSize(void)
{
- if (!fontInitted) {
- fontInit();
- }
+ if (!fontInitted) {
+ fontInit();
+ }
#if WLIB_FONT_DEBUG >= 3
- fprintf(stderr, "the font size of current font description is: %d\n",
- pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE);
- fprintf(stderr, "the font size of absoluteFontSize is: %d\n",absoluteFontSize);
+ fprintf(stderr, "the font size of current font description is: %d\n",
+ pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE);
+ fprintf(stderr, "the font size of absoluteFontSize is: %d\n",absoluteFontSize);
#endif
- return absoluteFontSize;
+ return absoluteFontSize;
}
/**
@@ -353,7 +353,7 @@ wFontSize_t wSelectedFontSize(void)
void wSetSelectedFontSize(wFontSize_t size)
{
- absoluteFontSize = size;
+ absoluteFontSize = size;
}
/**
@@ -368,30 +368,30 @@ void wSetSelectedFontSize(wFontSize_t size)
const char *wlibFontTranslate(wFont_p fp)
{
- static gchar *fontName = NULL;
+ static gchar *fontName = NULL;
- if (fontName != NULL) {
- g_free(fontName);
- }
+ if (fontName != NULL) {
+ g_free(fontName);
+ }
- if (!fontInitted) {
- fontInit();
- }
+ if (!fontInitted) {
+ fontInit();
+ }
- if (fp == NULL) {
- fp = wlibSelectedFont();
- }
+ if (fp == NULL) {
+ fp = wlibSelectedFont();
+ }
- if (fp == NULL) {
- fp = standardFonts[0][FW_MEDIUM][FS_REGULAR];
- }
+ if (fp == NULL) {
+ fp = standardFonts[0][FW_MEDIUM][FS_REGULAR];
+ }
- fontName = pango_font_description_to_string(fp->fontDescription);
+ fontName = pango_font_description_to_string(fp->fontDescription);
#if WLIB_FONT_DEBUG >= 2
- fprintf(stderr, "font translation: ");
- fprintf(stderr, " \"%s\"\n", fontName);
+ fprintf(stderr, "font translation: ");
+ fprintf(stderr, " \"%s\"\n", fontName);
#endif
- return (const char *) fontName;
+ return (const char *) fontName;
}
/**
@@ -402,9 +402,9 @@ const char *wlibFontTranslate(wFont_p fp)
wFont_p wStandardFont(int face, wBool_t bold, wBool_t italic)
{
- if (!fontInitted) {
- fontInit();
- }
+ if (!fontInitted) {
+ fontInit();
+ }
- return standardFonts[face-F_TIMES][bold][italic];
+ return standardFonts[face-F_TIMES][bold][italic];
}
diff --git a/app/wlib/gtklib/gtkdraw-cairo.c b/app/wlib/gtklib/gtkdraw-cairo.c
index 033e0ec..f24bde6 100644
--- a/app/wlib/gtklib/gtkdraw-cairo.c
+++ b/app/wlib/gtklib/gtkdraw-cairo.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -49,40 +49,40 @@ static long drawVerbose = 0;
wBool_t wDrawDoTempDraw = TRUE;
struct wDrawBitMap_t {
- int w;
- int h;
- int x;
- int y;
- const unsigned char * bits;
- GdkPixmap * pixmap;
- GdkBitmap * mask;
- };
+ int w;
+ int h;
+ int x;
+ int y;
+ const unsigned char * bits;
+ GdkPixmap * pixmap;
+ GdkBitmap * mask;
+};
//struct wDraw_t {
- //WOBJ_COMMON
- //void * context;
- //wDrawActionCallBack_p action;
- //wDrawRedrawCallBack_p redraw;
+//WOBJ_COMMON
+//void * context;
+//wDrawActionCallBack_p action;
+//wDrawRedrawCallBack_p redraw;
- //GdkPixmap * pixmap;
- //GdkPixmap * pixmapBackup;
+//GdkPixmap * pixmap;
+//GdkPixmap * pixmapBackup;
- //double dpi;
+//double dpi;
- //GdkGC * gc;
- //wDrawWidth lineWidth;
- //wDrawOpts opts;
- //wWinPix_t maxW;
- //wWinPix_t maxH;
- //unsigned long lastColor;
- //wBool_t lastColorInverted;
- //const char * helpStr;
+//GdkGC * gc;
+//wDrawWidth lineWidth;
+//wDrawOpts opts;
+//wWinPix_t maxW;
+//wWinPix_t maxH;
+//unsigned long lastColor;
+//wBool_t lastColorInverted;
+//const char * helpStr;
- //wWinPix_t lastX;
- //wWinPix_t lastY;
+//wWinPix_t lastX;
+//wWinPix_t lastY;
- //wBool_t delayUpdate;
- //};
+//wBool_t delayUpdate;
+//};
struct wDraw_t psPrint_d;
@@ -109,95 +109,10 @@ struct wDraw_t psPrint_d;
*
*******************************************************************************/
-static cairo_t* gtkDrawCreateCairoCursorContext(
- wControl_p ct,
- cairo_surface_t * surf,
- wDrawWidth width,
- wDrawLineType_e lineType,
- wDrawColor color,
- wDrawOpts opts )
-{
- cairo_t* cairo;
-
- cairo = cairo_create(surf);
-
- width = width ? abs(width) : 1;
- cairo_set_line_width(cairo, width);
-
- cairo_set_line_cap(cairo, CAIRO_LINE_CAP_BUTT);
- cairo_set_line_join(cairo, CAIRO_LINE_JOIN_MITER);
-
- switch(lineType)
- {
- case wDrawLineSolid:
- {
- cairo_set_dash(cairo, 0, 0, 0);
- break;
- }
- case wDrawLineDash:
- {
- double dashes[] = { 5, 3 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineDot:
- {
- double dashes[] = { 1, 2 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineDashDot:
- {
- double dashes[] = { 5, 2, 1, 2 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineDashDotDot:
- {
- double dashes[] = { 5, 2, 1, 2, 1, 2 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineCenter:
- {
- double dashes[] = { 8, 3, 5, 3};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLinePhantom:
- {
- double dashes[] = { 8, 3, 5, 3, 5, 3};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0.0);
- break;
- }
-
- }
- GdkColor * gcolor;
-
-
- cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
- gcolor = wlibGetColor(color, TRUE);
-
- if (ct->type == B_DRAW) {
- wDraw_p bd = (wDraw_p)ct;
- bd->lastColor = color;
- }
-
- cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0, 1.0);
-
- return cairo;
-}
-
wBool_t wDrawSetTempMode(
- wDraw_p bd,
- wBool_t bTemp )
+ wDraw_p bd,
+ wBool_t bTemp )
{
wBool_t ret = bd->bTempMode;
bd->bTempMode = bTemp;
@@ -209,102 +124,99 @@ wBool_t wDrawSetTempMode(
}
static cairo_t* gtkDrawCreateCairoContext(
- wDraw_p bd,
- GdkDrawable * win,
- wDrawWidth width,
- wDrawLineType_e lineType,
- wDrawColor color,
- wDrawOpts opts )
+ wDraw_p bd,
+ GdkDrawable * win,
+ wDrawWidth width,
+ wDrawLineType_e lineType,
+ wDrawColor color,
+ wDrawOpts opts )
{
cairo_t* cairo;
- if (win)
+ if (win) {
cairo = gdk_cairo_create(win);
- else {
+ } else {
if (opts & wDrawOptTemp) {
- if ( ! bd->bTempMode )
- printf( "Temp draw in Main Mode. Contact Developers. See %s:%d\n", "gtkdraw-cario.c", __LINE__+1 );
-/* Temp Draw In Main Mode:
- You are seeing this message because there is a wDraw*() call on tempD but you are not in the context of TempRedraw()
- Typically this happens when Cmd<Object>() is processing a C_DOWN or C_MOVE action and it writes directly to tempD
- Instead it sould set some state which allows c_redraw to do the actual drawing
- If you set a break point on the printf you'll see the offending wDraw*() call in the traceback
- It should be sufficient to remove that draw code or move it to C_REDRAW
- This is not fatal but the draw will be ineffective because the next TempRedraw() will erase the temp surface
- before the expose event can copy (or bitblt) it
-*/
+ if ( ! bd->bTempMode ) {
+ printf( "Temp draw in Main Mode. Contact Developers. See %s:%d\n",
+ "gtkdraw-cario.c", __LINE__+1 );
+ }
+ /* Temp Draw In Main Mode:
+ You are seeing this message because there is a wDraw*() call on tempD but you are not in the context of TempRedraw()
+ Typically this happens when Cmd<Object>() is processing a C_DOWN or C_MOVE action and it writes directly to tempD
+ Instead it sould set some state which allows c_redraw to do the actual drawing
+ If you set a break point on the printf you'll see the offending wDraw*() call in the traceback
+ It should be sufficient to remove that draw code or move it to C_REDRAW
+ This is not fatal but the draw will be ineffective because the next TempRedraw() will erase the temp surface
+ before the expose event can copy (or bitblt) it
+ */
cairo = cairo_create(bd->temp_surface);
} else {
- if ( bd->bTempMode )
- printf( "Main draw in Temp Mode. Contact Developers. See %s:%d\n", "gtkdraw-cario.c", __LINE__+1 );
-/* Main Draw In Temp Mode:
- You are seeing this message because there is a wDraw*() call on mainD but you are in the context of TempRedraw()
- Typically this happens when C_REDRAW action calls wDraw*() on mainD, in which case it should be writing to tempD.
- Or the wDraw*() call should be removed if it is redundant.
- If you set a break point on the printf you'll see the offending wDraw*() call in the traceback
- This is not fatal but could result in garbage being left on the screen if the command is cancelled.
-*/
+ if ( bd->bTempMode ) {
+ printf( "Main draw in Temp Mode. Contact Developers. See %s:%d\n",
+ "gtkdraw-cario.c", __LINE__+1 );
+ }
+ /* Main Draw In Temp Mode:
+ You are seeing this message because there is a wDraw*() call on mainD but you are in the context of TempRedraw()
+ Typically this happens when C_REDRAW action calls wDraw*() on mainD, in which case it should be writing to tempD.
+ Or the wDraw*() call should be removed if it is redundant.
+ If you set a break point on the printf you'll see the offending wDraw*() call in the traceback
+ This is not fatal but could result in garbage being left on the screen if the command is cancelled.
+ */
cairo = gdk_cairo_create(bd->pixmap);
}
}
width = width ? abs(width) : 1;
- if ( color == wDrawColorWhite )
- width += 1; // Remove ghosts
+ if ( color == wDrawColorWhite ) {
+ width += 1; // Remove ghosts
+ }
cairo_set_line_width(cairo, width);
cairo_set_line_cap(cairo, CAIRO_LINE_CAP_BUTT);
cairo_set_line_join(cairo, CAIRO_LINE_JOIN_MITER);
- switch(lineType)
- {
- case wDrawLineSolid:
- {
- cairo_set_dash(cairo, 0, 0, 0);
- break;
- }
- case wDrawLineDash:
- {
- double dashes[] = { 5, 3 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineDot:
- {
- double dashes[] = { 1, 2 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineDashDot:
- {
- double dashes[] = { 5, 2, 1, 2 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineDashDotDot:
- {
- double dashes[] = { 5, 2, 1, 2, 1, 2 };
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0);
- break;
- }
- case wDrawLineCenter:
- {
- double dashes[] = { 8, 3, 5, 3};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLinePhantom:
- {
- double dashes[] = { 8, 3, 5, 3, 5, 3};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cairo, dashes, len_dashes, 0.0);
- break;
- }
+ switch(lineType) {
+ case wDrawLineSolid: {
+ cairo_set_dash(cairo, 0, 0, 0);
+ break;
+ }
+ case wDrawLineDash: {
+ double dashes[] = { 5, 3 };
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cairo, dashes, len_dashes, 0);
+ break;
+ }
+ case wDrawLineDot: {
+ double dashes[] = { 1, 2 };
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cairo, dashes, len_dashes, 0);
+ break;
+ }
+ case wDrawLineDashDot: {
+ double dashes[] = { 5, 2, 1, 2 };
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cairo, dashes, len_dashes, 0);
+ break;
+ }
+ case wDrawLineDashDotDot: {
+ double dashes[] = { 5, 2, 1, 2, 1, 2 };
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cairo, dashes, len_dashes, 0);
+ break;
+ }
+ case wDrawLineCenter: {
+ double dashes[] = { 8, 3, 5, 3};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cairo, dashes, len_dashes, 0.0);
+ break;
+ }
+ case wDrawLinePhantom: {
+ double dashes[] = { 8, 3, 5, 3, 5, 3};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cairo, dashes, len_dashes, 0.0);
+ break;
+ }
}
GdkColor * gcolor;
@@ -315,49 +227,22 @@ static cairo_t* gtkDrawCreateCairoContext(
bd->lastColor = color;
- cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0);
+ cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0,
+ gcolor->blue / 65535.0);
return cairo;
}
-static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) {
+static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo)
+{
cairo_destroy(cairo);
return NULL;
}
-#ifdef CURSOR_SURFACE
-cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, wWinPix_t height, wDrawColor color, wDrawOpts opts) {
- cairo_t * cairo = NULL;
-
- if ((opts&wDrawOptCursor) || (opts&wDrawOptCursorRmv)) {
-
- if (surface!=NULL || surface->width != width || surface->height != height) {
- if (surface->surface) cairo_surface_destroy(surface->surface);
- surface->surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width,height );
- surface->width = width;
- surface->height = height;
-
- }
-
- cairo = gtkDrawCreateCairoCursorContext(ct,surface->surface,0,wDrawLineSolid, color, opts);
- cairo_save(cairo);
- cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0);
- cairo_paint(cairo);
- cairo_restore(cairo);
- surface->show = TRUE;
- cairo_set_operator(cairo,CAIRO_OPERATOR_SOURCE);
-
- }
-
- return cairo;
-
-}
-#endif
-
- void wDrawDelayUpdate(
- wDraw_p bd,
- wBool_t delay )
+void wDrawDelayUpdate(
+ wDraw_p bd,
+ wBool_t delay )
{
GdkRectangle update_rect;
@@ -372,17 +257,17 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
}
- void wDrawLine(
- wDraw_p bd,
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawPix_t x1, wDrawPix_t y1,
- wDrawWidth width,
- wDrawLineType_e lineType,
- wDrawColor color,
- wDrawOpts opts )
+void wDrawLine(
+ wDraw_p bd,
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawPix_t x1, wDrawPix_t y1,
+ wDrawWidth width,
+ wDrawLineType_e lineType,
+ wDrawColor color,
+ wDrawOpts opts )
{
- GdkGC * gc;
- GdkRectangle update_rect;
+// GdkGC * gc;
+// GdkRectangle update_rect;
if ( bd == &psPrint_d ) {
psPrintLine( x0, y0, x1, y1, width, lineType, color, opts );
@@ -393,13 +278,15 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
x1 = INMAPX(bd,x1);
y1 = INMAPY(bd,y1);
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color, opts);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color,
+ opts);
cairo_move_to(cairo, x0 + 0.5, y0 + 0.5);
cairo_line_to(cairo, x1 + 0.5, y1 + 0.5);
cairo_stroke(cairo);
gtkDrawDestroyCairoContext(cairo);
- if (bd->widget)
- gtk_widget_queue_draw(GTK_WIDGET(bd->widget)); //,x0,y0+1,x1,y1+1);
+ if (bd->widget) {
+ gtk_widget_queue_draw(GTK_WIDGET(bd->widget)); //,x0,y0+1,x1,y1+1);
+ }
}
@@ -418,79 +305,86 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
*/
- void wDrawArc(
- wDraw_p bd,
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawPix_t r,
- wAngle_t angle0,
- wAngle_t angle1,
- int drawCenter,
- wDrawWidth width,
- wDrawLineType_e lineType,
- wDrawColor color,
- wDrawOpts opts )
+void wDrawArc(
+ wDraw_p bd,
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawPix_t r,
+ wAngle_t angle0,
+ wAngle_t angle1,
+ int drawCenter,
+ wDrawWidth width,
+ wDrawLineType_e lineType,
+ wDrawColor color,
+ wDrawOpts opts )
{
int x, y, w, h;
if ( bd == &psPrint_d ) {
- psPrintArc( x0, y0, r, angle0, angle1, drawCenter, width, lineType, color, opts );
+ psPrintArc( x0, y0, r, angle0, angle1, drawCenter, width, lineType, color,
+ opts );
return;
}
- if (r < 6.0/75.0) return;
+ if (r < 6.0/75.0) { return; }
x = INMAPX(bd,x0-r);
y = INMAPY(bd,y0+r);
w = 2*r;
h = 2*r;
// now create the new arc
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color, opts);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color,
+ opts);
cairo_new_path(cairo);
// its center point marker
- if(drawCenter)
- {
+ if(drawCenter) {
// draw a small crosshair to mark the center of the curve
- cairo_move_to(cairo, INMAPX(bd, x0 - (CENTERMARK_LENGTH / 2)), INMAPY(bd, y0 ));
+ cairo_move_to(cairo, INMAPX(bd, x0 - (CENTERMARK_LENGTH / 2)), INMAPY(bd,
+ y0 ));
cairo_line_to(cairo, INMAPX(bd, x0 + (CENTERMARK_LENGTH / 2)), INMAPY(bd, y0 ));
cairo_move_to(cairo, INMAPX(bd, x0), INMAPY(bd, y0 - (CENTERMARK_LENGTH / 2 )));
- cairo_line_to(cairo, INMAPX(bd, x0) , INMAPY(bd, y0 + (CENTERMARK_LENGTH / 2)));
+ cairo_line_to(cairo, INMAPX(bd, x0), INMAPY(bd, y0 + (CENTERMARK_LENGTH / 2)));
cairo_new_sub_path( cairo );
}
// draw the curve itself
- cairo_arc_negative(cairo, INMAPX(bd, x0), INMAPY(bd, y0), r, (angle0 - 90 + angle1) * (M_PI / 180.0), (angle0 - 90) * (M_PI / 180.0));
+ cairo_arc_negative(cairo, INMAPX(bd, x0), INMAPY(bd, y0), r,
+ (angle0 - 90 + angle1) * (M_PI / 180.0), (angle0 - 90) * (M_PI / 180.0));
cairo_stroke(cairo);
gtkDrawDestroyCairoContext(cairo);
- if (bd->widget && !bd->delayUpdate)
- gtk_widget_queue_draw_area(bd->widget,x,y,w,h);
+ if (bd->widget && !bd->delayUpdate) {
+ gtk_widget_queue_draw_area(bd->widget,x,y,w,h);
+ }
}
- void wDrawPoint(
- wDraw_p bd,
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawColor color,
- wDrawOpts opts )
+void wDrawPoint(
+ wDraw_p bd,
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawColor color,
+ wDrawOpts opts )
{
- GdkRectangle update_rect;
+// GdkRectangle update_rect;
if ( bd == &psPrint_d ) {
/*psPrintArc( x0, y0, r, angle0, angle1, drawCenter, width, lineType, color, opts );*/
return;
}
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color,
+ opts);
cairo_new_path(cairo);
cairo_arc(cairo, INMAPX(bd, x0), INMAPY(bd, y0), 0.75, 0, 2 * M_PI);
cairo_stroke(cairo);
gtkDrawDestroyCairoContext(cairo);
- if (bd->widget && !bd->delayUpdate)
- gtk_widget_queue_draw_area(bd->widget,INMAPX(bd,x0-0.75),INMAPY(bd,y0+0.75),2,2);
+ if (bd->widget && !bd->delayUpdate) {
+ gtk_widget_queue_draw_area(bd->widget,INMAPX(bd,x0-0.75),INMAPY(bd,y0+0.75),2,
+ 2);
+ }
}
@@ -500,15 +394,15 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
*
******************************************************************************/
- void wDrawString(
- wDraw_p bd,
- wDrawPix_t x, wDrawPix_t y,
- wAngle_t a,
- const char * s,
- wFont_p fp,
- wFontSize_t fs,
- wDrawColor color,
- wDrawOpts opts )
+void wDrawString(
+ wDraw_p bd,
+ wDrawPix_t x, wDrawPix_t y,
+ wAngle_t a,
+ const char * s,
+ wFont_p fp,
+ wFontSize_t fs,
+ wDrawColor color,
+ wDrawOpts opts )
{
PangoLayout *layout;
GdkRectangle update_rect;
@@ -528,19 +422,21 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
y = INMAPY(bd,y);
/* draw text */
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color,
+ opts);
cairo_save( cairo );
cairo_identity_matrix(cairo);
layout = wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s,
- &w, &h,
- &ascent, &descent, &baseline);
+ &w, &h,
+ &ascent, &descent, &baseline);
/* cairo does not support the old method of text removal by overwrite;
* if color is White, then overwrite old text with a White rectangle */
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_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0,
+ gcolor->blue / 65535.0);
cairo_translate( cairo, x, y );
cairo_rotate( cairo, angle );
@@ -554,7 +450,7 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
cairo_restore( cairo );
gtkDrawDestroyCairoContext(cairo);
- if (bd->delayUpdate || bd->widget == NULL) return;
+ if (bd->delayUpdate || bd->widget == NULL) { return; }
/* recalculate the area to be updated
* for simplicity sake I added plain text height ascent and descent,
@@ -565,20 +461,22 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
update_rect.width = (gint) (w * cos( angle ) + h * sin(angle))+2;
update_rect.height = (gint) (h * sin( angle ) + w * cos(angle))+2;
gtk_widget_draw(bd->widget, &update_rect);
- if (bd->widget && !bd->delayUpdate)
- gtk_widget_queue_draw_area(bd->widget, update_rect.x, update_rect.y, update_rect.width, update_rect.height);
-
+ if (bd->widget && !bd->delayUpdate) {
+ gtk_widget_queue_draw_area(bd->widget, update_rect.x, update_rect.y,
+ update_rect.width, update_rect.height);
+ }
+
}
- void wDrawGetTextSize(
- wDrawPix_t *w,
- wDrawPix_t *h,
- wDrawPix_t *d,
- wDrawPix_t *a,
- wDraw_p bd,
- const char * s,
- wFont_p fp,
- wFontSize_t fs )
+void wDrawGetTextSize(
+ wDrawPix_t *w,
+ wDrawPix_t *h,
+ wDrawPix_t *d,
+ wDrawPix_t *a,
+ wDraw_p bd,
+ const char * s,
+ wFont_p fp,
+ wFontSize_t fs )
{
wDrawPix_t textWidth;
wDrawPix_t textHeight;
@@ -590,14 +488,15 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
*h = 0;
/* draw text */
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, wDrawColorBlack, bd->bTempMode?wDrawOptTemp:0 );
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid,
+ wDrawColorBlack, bd->bTempMode?wDrawOptTemp:0 );
cairo_identity_matrix(cairo);
wlibFontDestroyPangoLayout(
- wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s,
- &textWidth, &textHeight,
- &ascent, &descent, &baseline) );
+ wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s,
+ &textWidth, &textHeight,
+ &ascent, &descent, &baseline) );
*w = textWidth;
*h = textHeight;
@@ -605,8 +504,9 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
//*d = textHeight-ascent;
*d = descent;
- if (debugWindow >= 3)
+ if (debugWindow >= 3) {
fprintf(stderr, "text metrics: w=%0.1f, h=%0.1f, d=%0.1f\n", *w, *h, *d);
+ }
gtkDrawDestroyCairoContext(cairo);
}
@@ -619,9 +519,9 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width,
*******************************************************************************/
static void wlibDrawFilled(
- cairo_t * cairo,
- wDrawColor color,
- wDrawOpts opt )
+ cairo_t * cairo,
+ wDrawColor color,
+ wDrawOpts opt )
{
if ( (opt & wDrawOptTransparent) != 0 ) {
if ( (opt & wDrawOptTemp) == 0 ) {
@@ -630,26 +530,28 @@ static void wlibDrawFilled(
cairo_fill_preserve(cairo);
}
GdkColor * gcolor = wlibGetColor(color, TRUE);
- cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0, 1.0);
+ cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0,
+ gcolor->blue / 65535.0, 1.0);
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
cairo_stroke_preserve(cairo);
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
- cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0, 0.3);
+ cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0,
+ gcolor->blue / 65535.0, 0.3);
}
cairo_fill(cairo);
}
- void wDrawFilledRectangle(
- wDraw_p bd,
- wDrawPix_t x,
- wDrawPix_t y,
- wDrawPix_t w,
- wDrawPix_t h,
- wDrawColor color,
- wDrawOpts opt )
+void wDrawFilledRectangle(
+ wDraw_p bd,
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t w,
+ wDrawPix_t h,
+ wDrawColor color,
+ wDrawOpts opt )
{
- GdkRectangle update_rect;
+// GdkRectangle update_rect;
if ( bd == &psPrint_d ) {
psPrintFillRectangle( x, y, w, h, color, opt );
@@ -659,7 +561,8 @@ static void wlibDrawFilled(
x = INMAPX(bd,x);
y = INMAPY(bd,y)-h;
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opt);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color,
+ opt);
cairo_move_to(cairo, x, y);
cairo_rel_line_to(cairo, w, 0);
@@ -669,22 +572,23 @@ static void wlibDrawFilled(
wlibDrawFilled( cairo, color, opt );
gtkDrawDestroyCairoContext(cairo);
- if (bd->widget && !bd->delayUpdate)
+ if (bd->widget && !bd->delayUpdate) {
gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),x,y,w,h);
+ }
}
- void wDrawPolygon(
- wDraw_p bd,
- wDrawPix_t p[][2],
- wPolyLine_e type[],
- int cnt,
- wDrawColor color,
- wDrawWidth dw,
- wDrawLineType_e lt,
- wDrawOpts opt,
- int fill,
- int open )
+void wDrawPolygon(
+ wDraw_p bd,
+ wDrawPix_t p[][2],
+ wPolyLine_e type[],
+ int cnt,
+ wDrawColor color,
+ wDrawWidth dw,
+ wDrawLineType_e lt,
+ wDrawOpts opt,
+ int fill,
+ int open )
{
static int maxCnt = 0;
static GdkPoint *points;
@@ -695,35 +599,37 @@ static void wlibDrawFilled(
return;
}
- if (cnt > maxCnt) {
- if (points == NULL)
+ if (cnt > maxCnt) {
+ if (points == NULL) {
points = (GdkPoint*)malloc( cnt*sizeof *points );
- else
+ } else {
points = (GdkPoint*)realloc( points, cnt*sizeof *points );
- if (points == NULL)
+ }
+ if (points == NULL) {
abort();
+ }
maxCnt = cnt;
}
wDrawPix_t min_x,max_x,min_y,max_y;
min_x = max_x = INMAPX(bd,p[0][0]);
min_y = max_y = INMAPY(bd,p[0][1]);
- for (i=0; i<cnt; i++) {
- points[i].x = INMAPX(bd,p[i][0]);
- if (points[i].x < min_x) min_x = points[i].x;
- if (points[i].y < min_y) min_y = points[i].y;
- if (points[i].x > max_x) max_x = points[i].x;
- if (points[i].y > max_y) max_y = points[i].y;
- points[i].y = INMAPY(bd,p[i][1]);
+ for (i=0; i<cnt; i++) {
+ points[i].x = INMAPX(bd,p[i][0]);
+ if (points[i].x < min_x) { min_x = points[i].x; }
+ if (points[i].y < min_y) { min_y = points[i].y; }
+ if (points[i].x > max_x) { max_x = points[i].x; }
+ if (points[i].y > max_y) { max_y = points[i].y; }
+ points[i].y = INMAPY(bd,p[i][1]);
}
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, fill?0:dw, fill?wDrawLineSolid:lt, color, opt);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, fill?0:dw,
+ fill?wDrawLineSolid:lt, color, opt);
- for(i = 0; i < cnt; ++i)
- {
+ for(i = 0; i < cnt; ++i) {
int j = i-1;
int k = i+1;
- if (j < 0) j = cnt-1;
- if (k > cnt-1) k = 0;
+ if (j < 0) { j = cnt-1; }
+ if (k > cnt-1) { k = 0; }
GdkPoint mid0, mid1, mid3, mid4;
// save is static because of an apparent compiler bug on Linux
// This happens with RelWithDebInfo target
@@ -771,20 +677,24 @@ static void wlibDrawFilled(
save = points[0];
} else {
cairo_move_to(cairo, mid0.x, mid0.y);
- if (type[i] == 1)
- cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y, mid1.x, mid1.y);
- else
+ if (type[i] == 1) {
+ cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y,
+ mid1.x, mid1.y);
+ } else {
cairo_curve_to(cairo, mid3.x, mid3.y, mid4.x, mid4.y, mid1.x, mid1.y);
+ }
save = mid0;
}
} else if (!type || type[i] == wPolyLineStraight || (open && (i==cnt-1))) {
cairo_line_to(cairo, points[i].x, points[i].y);
} else {
cairo_line_to(cairo, mid0.x, mid0.y);
- if (type[i] == wPolyLineSmooth)
- cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y, mid1.x, mid1.y);
- else
+ if (type[i] == wPolyLineSmooth) {
+ cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y,
+ mid1.x, mid1.y);
+ } else {
cairo_curve_to(cairo, mid3.x, mid3.y, mid4.x, mid4.y, mid1.x, mid1.y);
+ }
}
if ((i==cnt-1) && !open) {
cairo_line_to(cairo, save.x, save.y);
@@ -796,18 +706,20 @@ static void wlibDrawFilled(
cairo_stroke(cairo);
}
gtkDrawDestroyCairoContext(cairo);
- if (bd->widget && !bd->delayUpdate)
- gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),min_x,min_y,max_x-min_y,max_y-min_y);
+ if (bd->widget && !bd->delayUpdate) {
+ gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),min_x,min_y,max_x-min_y,
+ max_y-min_y);
+ }
}
- void wDrawFilledCircle(
- wDraw_p bd,
- wDrawPix_t x0,
- wDrawPix_t y0,
- wDrawPix_t r,
- wDrawColor color,
- wDrawOpts opt )
+void wDrawFilledCircle(
+ wDraw_p bd,
+ wDrawPix_t x0,
+ wDrawPix_t y0,
+ wDrawPix_t r,
+ wDrawColor color,
+ wDrawOpts opt )
{
int x, y, w, h;
@@ -821,22 +733,26 @@ static void wlibDrawFilled(
w = 2*r;
h = 2*r;
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opt);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color,
+ opt);
cairo_arc(cairo, INMAPX(bd, x0), INMAPY(bd, y0), r, 0, 2 * M_PI);
wlibDrawFilled( cairo, color, opt );
gtkDrawDestroyCairoContext(cairo);
- if (bd->widget)
- gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),x,y,w,h);
+ if (bd->widget && !bd->delayUpdate) {
+ gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),x,y,w,h);
+ }
}
- void wDrawClearTemp(wDraw_p bd) {
+void wDrawClearTemp(wDraw_p bd)
+{
//Wipe out temp space with 0 alpha (transparent)
static long cDCT = 0;
- if ( iDrawLog )
+ if ( iDrawLog ) {
printf( "wDrawClearTemp %ld\n", cDCT++ );
+ }
cairo_t* cairo = cairo_create(bd->temp_surface);
cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0);
@@ -848,29 +764,32 @@ static void wlibDrawFilled(
cairo_fill(cairo);
cairo_destroy(cairo);
- if (bd->widget && !bd->delayUpdate)
+ if (bd->widget && !bd->delayUpdate) {
gtk_widget_queue_draw(bd->widget);
- }
+ }
+}
- void wDrawClear(
- wDraw_p bd )
+void wDrawClear(
+ wDraw_p bd )
{
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, wDrawColorWhite, 0);
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid,
+ wDrawColorWhite, 0);
cairo_move_to(cairo, 0, 0);
cairo_rel_line_to(cairo, bd->w, 0);
cairo_rel_line_to(cairo, 0, bd->h);
cairo_rel_line_to(cairo, -bd->w, 0);
cairo_fill(cairo);
- if (bd->widget)
+ if (bd->widget) {
gtk_widget_queue_draw(bd->widget);
+ }
gtkDrawDestroyCairoContext(cairo);
wDrawClearTemp(bd);
}
- void * wDrawGetContext(
- wDraw_p bd )
+void * wDrawGetContext(
+ wDraw_p bd )
{
return bd->context;
}
@@ -882,13 +801,13 @@ static void wlibDrawFilled(
*******************************************************************************/
- wDrawBitMap_p wDrawBitMapCreate(
- wDraw_p bd,
- int w,
- int h,
- int x,
- int y,
- const unsigned char * fbits )
+wDrawBitMap_p wDrawBitMapCreate(
+ wDraw_p bd,
+ int w,
+ int h,
+ int x,
+ int y,
+ const unsigned char * fbits )
{
wDrawBitMap_p bm;
@@ -903,23 +822,21 @@ static void wlibDrawFilled(
}
- void wDrawBitMap(
- wDraw_p bd,
- wDrawBitMap_p bm,
- wDrawPix_t x, wDrawPix_t y,
- wDrawColor color,
- wDrawOpts opts )
+void wDrawBitMap(
+ wDraw_p bd,
+ wDrawBitMap_p bm,
+ wDrawPix_t x, wDrawPix_t y,
+ wDrawColor color,
+ wDrawOpts opts )
{
int i, j, wb;
wDrawPix_t xx, yy;
- wControl_p b;
- wWin_p win;
- GdkDrawable * gdk_drawable, * cairo_surface;
GtkWidget * widget = bd->widget;
-
+
static long cDBM = 0;
- if ( iDrawLog )
+ if ( iDrawLog ) {
printf( "wDrawBitMap %ld\n", cDBM++ );
+ }
x = INMAPX( bd, x-bm->x );
y = INMAPY( bd, y-bm->y )-bm->h;
@@ -927,32 +844,6 @@ static void wlibDrawFilled(
cairo_t* cairo;
-#ifdef CURSOR_SURFACE
- if (opts&wDrawOptCursorRmv) color = wDrawColorWhite; //Wipeout existing cursor draw (simplistic first)
-
-
- if ((opts&wDrawOptCursor) || (opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) {
-
- cairo = CreateCursorSurface((wControl_p)bd,&bd->cursor_surface, bd->w, bd->h, color, opts);
-
- if ((opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) {
- bd->cursor_surface.show = FALSE;
- } else bd->cursor_surface.show = TRUE;
-
- widget = bd->widget;
-
-
- } else {
- cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts);
- widget = bd->widget;
- }
-
- GtkWidget * new_widget = widget;
- GdkGC * gc = NULL;
- GdkWindow * gdk_window = NULL;
-
- win = bd->parent;
-#endif
cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts);
@@ -961,55 +852,15 @@ static void wlibDrawFilled(
if ( bm->bits[ j*wb+(i>>3) ] & (1<<(i&07)) ) {
xx = x+i;
yy = y+j;
-#ifdef CURSOR_SURFACE
- if ( 0 <= xx && xx < bd->w &&
- 0 <= yy && yy < bd->h ) {
- b = (wControl_p)bd;
- } else if ( (opts&wDrawOptNoClip) != 0 ) {
- xx += bd->realX;
- yy += bd->realY;
- b = wlibGetControlFromPos( bd->parent, xx, yy );
- if ( b) {
- xx -= b->realX;
- yy -= b->realY;
- new_widget = b->widget;
- } else {
- new_widget = bd->parent->widget;
- }
- } else {
- continue;
- }
-
- if (new_widget != widget) {
- if (cairo)
- cairo_destroy(cairo);
- cairo = NULL;
- if (widget && (widget != bd->parent->widget))
- gtk_widget_queue_draw(GTK_WIDGET(widget));
- if ( (opts&wDrawOptCursor) || (opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) {
- if (!b) b = (wControl_p)(bd->parent->widget);
- cairo = CreateCursorSurface(b,&b->cursor_surface, b->w, b->h, color, opts);
- widget = b->widget;
- gc = NULL;
- if ((opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit))
- b->cursor_surface.show = FALSE;
- else
- b->cursor_surface.show = TRUE;
- } else {
- continue;
- }
- widget = new_widget;
- }
- if ((opts&wDrawOptCursorQuit) || (opts&wDrawOptCursorQuit) ) continue;
-#endif
cairo_rectangle(cairo, xx, yy, 1, 1);
cairo_fill(cairo);
}
cairo_destroy(cairo);
- if (widget && !bd->delayUpdate)
+ if (widget && !bd->delayUpdate) {
gtk_widget_queue_draw_area(GTK_WIDGET(widget), x, y, bm->w, bm->h);
+ }
}
@@ -1022,8 +873,8 @@ static void wlibDrawFilled(
- void wDrawSaveImage(
- wDraw_p bd )
+void wDrawSaveImage(
+ wDraw_p bd )
{
cairo_t * cr;
if ( bd->pixmapBackup ) {
@@ -1033,7 +884,7 @@ static void wlibDrawFilled(
cr = gdk_cairo_create(bd->pixmapBackup);
gdk_cairo_set_source_pixmap(cr, bd->pixmap, 0, 0);
- cairo_paint(cr);
+ cairo_paint(cr);
cairo_destroy(cr);
cr = NULL;
@@ -1041,8 +892,8 @@ static void wlibDrawFilled(
}
- void wDrawRestoreImage(
- wDraw_p bd )
+void wDrawRestoreImage(
+ wDraw_p bd )
{
GdkRectangle update_rect;
if ( bd->pixmapBackup ) {
@@ -1055,7 +906,7 @@ static void wlibDrawFilled(
cr = NULL;
- if ( bd->delayUpdate || bd->widget == NULL ) return;
+ if ( bd->delayUpdate || bd->widget == NULL ) { return; }
update_rect.x = 0;
update_rect.y = 0;
update_rect.width = bd->w;
@@ -1065,10 +916,10 @@ static void wlibDrawFilled(
}
- void wDrawSetSize(
- wDraw_p bd,
- wWinPix_t w,
- wWinPix_t h , void * redraw)
+void wDrawSetSize(
+ wDraw_p bd,
+ wWinPix_t w,
+ wWinPix_t h, void * redraw)
{
wBool_t repaint;
if (bd == NULL) {
@@ -1077,37 +928,47 @@ static void wlibDrawFilled(
}
/* Negative values crashes the program */
- if (w < 0 || h < 0)
- return;
+ if ( w <= 0 || h <= 0 ) {
+ fprintf( stderr, "wDrawSetSize bad size %ldx%ld\n", w, h );
+ if ( w <= 0 ) {
+ w = 100;
+ }
+ if ( h <= 0 ) {
+ h = 100;
+ }
+ }
repaint = (w != bd->w || h != bd->h);
bd->w = w;
bd->h = h;
gtk_widget_set_size_request( bd->widget, w, h );
- if (repaint)
- {
- if (bd->pixmap)
+ if (repaint) {
+ if (bd->pixmap) {
gdk_pixmap_unref( bd->pixmap );
+ }
bd->pixmap = gdk_pixmap_new( bd->widget->window, w, h, -1 );
- if (bd->temp_surface)
+ if (bd->temp_surface) {
cairo_surface_destroy( bd->temp_surface);
+ }
bd->temp_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, w,h );
wDrawClear( bd );
- if (!redraw)
+ if (!redraw) {
bd->redraw( bd, bd->context, w, h );
+ }
}
/*wRedraw( bd )*/;
}
- void wDrawGetSize(
- wDraw_p bd,
- wWinPix_t *w,
- wWinPix_t *h )
+void wDrawGetSize(
+ wDraw_p bd,
+ wWinPix_t *w,
+ wWinPix_t *h )
{
- if (bd->widget)
+ if (bd->widget) {
wlibControlGetSize( (wControl_p)bd );
+ }
*w = bd->w-2;
*h = bd->h-2;
}
@@ -1119,32 +980,33 @@ static void wlibDrawFilled(
* \return the resolution in dpi
*/
- double wDrawGetDPI(
- wDraw_p d )
+double wDrawGetDPI(
+ wDraw_p d )
{
//if (d == &psPrint_d)
- //return 1440.0;
+ //return 1440.0;
//else
- return d->dpi;
+ return d->dpi;
}
- double wDrawGetMaxRadius(
- wDraw_p d )
+double wDrawGetMaxRadius(
+ wDraw_p d )
{
- if (d == &psPrint_d)
+ if (d == &psPrint_d) {
return 10e9;
- else
+ } else {
return 32767.0;
+ }
}
- void wDrawClip(
- wDraw_p d,
- wDrawPix_t x,
- wDrawPix_t y,
- wDrawPix_t w,
- wDrawPix_t h )
+void wDrawClip(
+ wDraw_p d,
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t w,
+ wDrawPix_t h )
{
GdkRectangle rect;
rect.width = (wWinPix_t)w;
@@ -1157,38 +1019,29 @@ static void wlibDrawFilled(
static gint draw_expose_event(
- GtkWidget *widget,
- GdkEventExpose *event,
- wDraw_p bd)
+ GtkWidget *widget,
+ GdkEventExpose *event,
+ wDraw_p bd)
{
static long cDEE = 0;
if ( iDrawLog )
printf( "draw_expose_event %ld %dx%d+%dx%d %ldx%ld+%ldx%ld\n", cDEE++,
- event->area.x, event->area.y, event->area.width, event->area.height,
- 0L, bd->w, 0L, bd->h );
+ event->area.x, event->area.y, event->area.width, event->area.height,
+ 0L, bd->w, 0L, bd->h );
cairo_t* cairo = gdk_cairo_create (widget->window);
gdk_cairo_set_source_pixmap(cairo,bd->pixmap,0,0);
cairo_rectangle(cairo,event->area.x, event->area.y,
- event->area.width, event->area.height);
+ event->area.width, event->area.height);
cairo_set_operator(cairo,CAIRO_OPERATOR_SOURCE);
cairo_fill(cairo);
cairo_set_source_surface(cairo,bd->temp_surface,0,0);
cairo_rectangle(cairo,event->area.x, event->area.y,
- event->area.width, event->area.height);
+ event->area.width, event->area.height);
cairo_set_operator(cairo,CAIRO_OPERATOR_OVER);
cairo_fill(cairo);
-#ifdef CURSOR_SURFACE
- if (bd->cursor_surface.surface && bd->cursor_surface.show) {
- cairo_set_source_surface(cairo,bd->cursor_surface.surface,0,0);
- cairo_set_operator(cairo,CAIRO_OPERATOR_OVER);
- cairo_rectangle(cairo,event->area.x, event->area.y,
- event->area.width, event->area.height);
- cairo_fill(cairo);
- }
-#endif
cairo_destroy(cairo);
return TRUE;
@@ -1196,14 +1049,14 @@ static gint draw_expose_event(
static gint draw_configure_event(
- GtkWidget *widget,
- GdkEventConfigure *event,
- wDraw_p bd)
+ GtkWidget *widget,
+ GdkEventConfigure *event,
+ wDraw_p bd)
{
return TRUE;
}
-static const char * actionNames[] = { "None", "Move", "LDown", "LDrag", "LUp", "RDown", "RDrag", "RUp", "Text", "ExtKey", "WUp", "WDown", "DblL", "ModK", "ScrU", "ScrD", "ScrL", "ScrR" };
+static const char * actionNames[] = { "None", "Move", "LDown", "LDrag", "LUp", "RDown", "RDrag", "RUp", "Text", "ExtKey", "WUp", "WDown", "DblL", "ModK", "ScrU", "ScrD", "ScrL", "ScrR", "MDown", "MDrag", "MUp" };
/**
* Handler for scroll events, ie mouse wheel activity
@@ -1212,30 +1065,35 @@ static const char * actionNames[] = { "None", "Move", "LDown", "LDrag", "LUp", "
static int scrollTimer;
static int timer_busy_count;
static wAction_t lastAction;
+static int timer_interval = 500; // Start at 0.5 secs
-static int ScrollTimerPop(wDraw_p bd) {
+static int ScrollTimerPop(wDraw_p bd)
+{
- if (timer_busy_count>1) {
- timer_busy_count = 0;
- scrollTimer = 0;
- } else {
- timer_busy_count++;
- return TRUE;
- }
- if (drawVerbose >= 2)
- printf( "%s-Pop\n", actionNames[lastAction] );
- bd->action( bd, bd->context, lastAction, (wDrawPix_t)0, (wDrawPix_t)0 );
+ if (timer_busy_count>4)
+ timer_interval = 250; //If lots of events 0.25 secs next time
+ if (timer_busy_count<1)
+ timer_interval = 500; //If few events 0.5 secs next time
- return FALSE;
+
+ if (drawVerbose >= 2) {
+ printf( "%s-Pop\n", actionNames[lastAction] );
+ }
+ scrollTimer = 0;
+ timer_busy_count = 0;
+ // Don't do the action as may no longer be scrolling
+ // bd->action( bd, bd->context, lastAction, (wDrawPix_t)0, (wDrawPix_t)0 );
+
+ return FALSE; //Stops timer re-popping
}
static gint draw_scroll_event(
- GtkWidget *widget,
- GdkEventScroll *event,
- wDraw_p bd)
+ GtkWidget *widget,
+ GdkEventScroll *event,
+ wDraw_p bd)
{
- wAction_t action;
+ wAction_t action = 0;
static int oldEventX = 0;
static int oldEventY = 0;
static int newEventX = 0;
@@ -1249,44 +1107,34 @@ static gint draw_scroll_event(
oldEventY = OUTMAPX(bd, event->y_root);
switch( event->direction ) {
- case GDK_SCROLL_UP:
- if (event->state & GDK_CONTROL_MASK)
- action = wActionScrollRight;
- else
- action = wActionScrollUp;
- break;
- case GDK_SCROLL_DOWN:
- if (event->state & GDK_CONTROL_MASK)
- action = wActionScrollLeft;
- else
- action = wActionScrollDown;
- break;
- case GDK_SCROLL_LEFT:
- action = wActionScrollLeft;
- break;
- case GDK_SCROLL_RIGHT:
+ case GDK_SCROLL_UP:
+ if (event->state & GDK_CONTROL_MASK) {
action = wActionScrollRight;
- break;
- default:
- return TRUE;
- break;
+ } else {
+ action = wActionScrollUp;
+ }
+ break;
+ case GDK_SCROLL_DOWN:
+ if (event->state & GDK_CONTROL_MASK) {
+ action = wActionScrollLeft;
+ } else {
+ action = wActionScrollDown;
+ }
+ break;
+ case GDK_SCROLL_LEFT:
+ action = wActionScrollLeft;
+ break;
+ case GDK_SCROLL_RIGHT:
+ action = wActionScrollRight;
+ break;
+ default:
+ return TRUE;
+ break;
}
if (drawVerbose >= 2)
printf( "%sNew[%dx%d]Delta[%dx%d]\n", actionNames[action],
- newEventX, newEventY, oldEventX, oldEventY );
-
-
-
- if (scrollTimer) { // Already have a timer
- lastAction = action;
- return TRUE;
- } else {
- lastAction = action;
- timer_busy_count = 0;
- scrollTimer = g_timeout_add(25,(GSourceFunc)ScrollTimerPop,bd); // 25ms delay
- return TRUE;
- }
+ newEventX, newEventY, oldEventX, oldEventY );
} else {
@@ -1307,12 +1155,27 @@ static gint draw_scroll_event(
default:
break;
}
+
}
+ if (event->time < GDK_CURRENT_TIME) return TRUE; //Ignore past events
+
+ if (scrollTimer) { // Already have a timer
+ timer_busy_count++;
+ lastAction = action;
+ return TRUE;
+ } else {
+ lastAction = action;
+ timer_busy_count = 0;
+ scrollTimer = g_timeout_add(timer_interval,(GSourceFunc)ScrollTimerPop,bd); // 250ms delay
+ }
+
if (action != 0) {
- if (drawVerbose >= 2)
+ if (drawVerbose >= 2) {
printf( "%s[%ldx%ld]\n", actionNames[action], bd->lastX, bd->lastY );
- bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY);
+ }
+ bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX,
+ (wDrawPix_t)bd->lastY);
}
return TRUE;
@@ -1321,8 +1184,8 @@ static gint draw_scroll_event(
static gint draw_leave_event(
- GtkWidget *widget,
- GdkEvent * event )
+ GtkWidget *widget,
+ GdkEvent * event )
{
wlibHelpHideBalloon();
return TRUE;
@@ -1336,24 +1199,27 @@ static gint draw_leave_event(
static gint draw_button_event(
- GtkWidget *widget,
- GdkEventButton *event,
- wDraw_p bd )
+ GtkWidget *widget,
+ GdkEventButton *event,
+ wDraw_p bd )
{
wAction_t action = 0;
- if (bd->action == NULL)
+ if (bd->action == NULL) {
return TRUE;
+ }
bd->lastX = OUTMAPX(bd, event->x);
bd->lastY = OUTMAPY(bd, event->y);
switch ( event->button ) {
case 1: /* left mouse button */
- case 2: /* middle mouse button */
action = event->type==GDK_BUTTON_PRESS?wActionLDown:wActionLUp;
- if (event->type==GDK_2BUTTON_PRESS) action = wActionLDownDouble;
+ if (event->type==GDK_2BUTTON_PRESS) { action = wActionLDownDouble; }
+ break;
+ case 2: /* middle mouse button */
+ action = event->type==GDK_BUTTON_PRESS?wActionMDown:wActionMUp;
/*bd->action( bd, bd->context, event->type==GDK_BUTTON_PRESS?wActionLDown:wActionLUp, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );*/
break;
case 3: /* right mouse button */
@@ -1362,27 +1228,31 @@ static gint draw_button_event(
break;
}
if (action != 0) {
- if (drawVerbose >= 2)
+ if (drawVerbose >= 2) {
printf( "%s[%ldx%ld]\n", actionNames[action], bd->lastX, bd->lastY );
- bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
+ }
+ bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX,
+ (wDrawPix_t)bd->lastY );
}
- if (!(bd->option & BD_NOFOCUS))
+ if (!(bd->option & BD_NOFOCUS)) {
gtk_widget_grab_focus( bd->widget );
+ }
return TRUE;
}
static gint draw_motion_event(
- GtkWidget *widget,
- GdkEventMotion *event,
- wDraw_p bd )
+ GtkWidget *widget,
+ GdkEventMotion *event,
+ wDraw_p bd )
{
int x, y;
GdkModifierType state;
wAction_t action;
- if (bd->action == NULL)
+ if (bd->action == NULL) {
return TRUE;
+ }
if (event->is_hint) {
gdk_window_get_pointer (event->window, &x, &y, &state);
@@ -1395,56 +1265,62 @@ static gint draw_motion_event(
if (state & GDK_BUTTON1_MASK) {
action = wActionLDrag;
} else if (state & GDK_BUTTON2_MASK) {
- action = wActionLDrag;
+ action = wActionMDrag;
} else if (state & GDK_BUTTON3_MASK) {
- action = wActionRDrag;
+ action = wActionRDrag;
} else {
action = wActionMove;
}
bd->lastX = OUTMAPX(bd, x);
bd->lastY = OUTMAPY(bd, y);
- if (drawVerbose >= 2)
- printf( "%lx: %s[%ldx%ld] %s\n", (long)bd, actionNames[action], bd->lastX, bd->lastY, event->is_hint?"<Hint>":"<>" );
- bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
- if (!(bd->option & BD_NOFOCUS))
+ if (drawVerbose >= 2) {
+ printf( "%lx: %s[%ldx%ld] %s\n", (long)bd, actionNames[action], bd->lastX,
+ bd->lastY, event->is_hint?"<Hint>":"<>" );
+ }
+ bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX,
+ (wDrawPix_t)bd->lastY );
+ if (!(bd->option & BD_NOFOCUS)) {
gtk_widget_grab_focus( bd->widget );
+ }
return TRUE;
}
static gint draw_char_release_event(
- GtkWidget * widget,
- GdkEventKey *event,
- wDraw_p bd )
+ GtkWidget * widget,
+ GdkEventKey *event,
+ wDraw_p bd )
{
- GdkModifierType modifiers;
- guint key = event->keyval;
- wModKey_e modKey = wModKey_None;
- switch (key) {
- case GDK_KEY_Alt_L: modKey = wModKey_Alt; break;
- case GDK_KEY_Alt_R: modKey = wModKey_Alt; break;
- case GDK_KEY_Shift_L: modKey = wModKey_Shift; break;
- case GDK_KEY_Shift_R: modKey = wModKey_Shift; break;
- case GDK_KEY_Control_L: modKey = wModKey_Ctrl; break;
- case GDK_KEY_Control_R: modKey = wModKey_Ctrl; break;
- default: ;
- }
+// GdkModifierType modifiers;
+ guint key = event->keyval;
+ wModKey_e modKey = wModKey_None;
+ switch (key) {
+ case GDK_KEY_Alt_L: modKey = wModKey_Alt; break;
+ case GDK_KEY_Alt_R: modKey = wModKey_Alt; break;
+ case GDK_KEY_Shift_L: modKey = wModKey_Shift; break;
+ case GDK_KEY_Shift_R: modKey = wModKey_Shift; break;
+ case GDK_KEY_Control_L: modKey = wModKey_Ctrl; break;
+ case GDK_KEY_Control_R: modKey = wModKey_Ctrl; break;
+ default: ;
+ }
- if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) {
- bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
- if (!(bd->option & BD_NOFOCUS))
- gtk_widget_grab_focus( bd->widget );
- return TRUE;
- } else {
- return FALSE;
+ if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) {
+ bd->action(bd, bd->context, wActionModKey+((int)modKey<<8),
+ (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
+ if (!(bd->option & BD_NOFOCUS)) {
+ gtk_widget_grab_focus( bd->widget );
}
+ return TRUE;
+ } else {
return FALSE;
+ }
+ return FALSE;
}
static gint draw_char_event(
- GtkWidget * widget,
- GdkEventKey *event,
- wDraw_p bd )
+ GtkWidget * widget,
+ GdkEventKey *event,
+ wDraw_p bd )
{
GdkModifierType modifiers;
guint key = event->keyval;
@@ -1453,9 +1329,12 @@ static gint draw_char_event(
switch (key) {
case GDK_KEY_Escape: key = 0x1B; break;
case GDK_KEY_Return:
+ case GDK_KP_Enter:
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
+ 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;
@@ -1489,31 +1368,40 @@ static gint draw_char_event(
case GDK_KEY_Shift_R: modKey = wModKey_Shift; break;
case GDK_KEY_Control_L: modKey = wModKey_Ctrl; break;
case GDK_KEY_Control_R: modKey = wModKey_Ctrl; break;
- default: ;
+ default: ;
}
if (extKey != wAccelKey_None) {
if ( wlibFindAccelKey( event ) == NULL ) {
- bd->action( bd, bd->context, wActionExtKey + ((int)extKey<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
+ bd->action( bd, bd->context, wActionExtKey + ((int)extKey<<8),
+ (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
+ }
+ if (!(bd->option & BD_NOFOCUS)) {
+ gtk_widget_grab_focus( bd->widget );
}
- if (!(bd->option & BD_NOFOCUS))
- gtk_widget_grab_focus( bd->widget );
return TRUE;
} else if ((key >=wAccelKey_Up) && (key<=wAccelKey_Left) && bd->action) {
- bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
- if (!(bd->option & BD_NOFOCUS))
+ bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX,
+ (wDrawPix_t)bd->lastY );
+ if (!(bd->option & BD_NOFOCUS)) {
gtk_widget_grab_focus( bd->widget );
+ }
return TRUE;
- } else if (key <= 0xFF && (event->state&(GDK_CONTROL_MASK|GDK_MOD1_MASK)) == 0 && bd->action) {
- bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
- if (!(bd->option & BD_NOFOCUS))
- gtk_widget_grab_focus( bd->widget );
+ } else if (key <= 0xFF && (event->state&(GDK_CONTROL_MASK|GDK_MOD1_MASK)) == 0
+ && bd->action) {
+ bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX,
+ (wDrawPix_t)bd->lastY );
+ if (!(bd->option & BD_NOFOCUS)) {
+ gtk_widget_grab_focus( bd->widget );
+ }
return TRUE;
} else if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) {
- bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
- if (!(bd->option & BD_NOFOCUS))
- gtk_widget_grab_focus( bd->widget );
- return TRUE;
+ bd->action(bd, bd->context, wActionModKey+((int)modKey<<8),
+ (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );
+ if (!(bd->option & BD_NOFOCUS)) {
+ gtk_widget_grab_focus( bd->widget );
+ }
+ return TRUE;
} else {
return FALSE;
}
@@ -1532,17 +1420,17 @@ int XW = 0;
int XH = 0;
int xw, xh, cw, ch;
- wDraw_p wDrawCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- long option,
- wWinPix_t width,
- wWinPix_t height,
- void * context,
- wDrawRedrawCallBack_p redraw,
- wDrawActionCallBack_p action )
+wDraw_p wDrawCreate(
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ long option,
+ wWinPix_t width,
+ wWinPix_t height,
+ void * context,
+ wDrawRedrawCallBack_p redraw,
+ wDrawActionCallBack_p action )
{
wDraw_p bd;
@@ -1558,41 +1446,50 @@ int xw, xh, cw, ch;
gtk_drawing_area_size( GTK_DRAWING_AREA(bd->widget), width, height );
gtk_widget_set_size_request( GTK_WIDGET(bd->widget), width, height );
gtk_signal_connect (GTK_OBJECT (bd->widget), "expose_event",
- (GtkSignalFunc) draw_expose_event, bd);
+ (GtkSignalFunc) draw_expose_event, bd);
gtk_signal_connect (GTK_OBJECT(bd->widget),"configure_event",
- (GtkSignalFunc) draw_configure_event, bd);
+ (GtkSignalFunc) draw_configure_event, bd);
gtk_signal_connect (GTK_OBJECT (bd->widget), "motion_notify_event",
- (GtkSignalFunc) draw_motion_event, bd);
+ (GtkSignalFunc) draw_motion_event, bd);
gtk_signal_connect (GTK_OBJECT (bd->widget), "button_press_event",
- (GtkSignalFunc) draw_button_event, bd);
+ (GtkSignalFunc) draw_button_event, bd);
gtk_signal_connect (GTK_OBJECT (bd->widget), "button_release_event",
- (GtkSignalFunc) draw_button_event, bd);
+ (GtkSignalFunc) draw_button_event, bd);
gtk_signal_connect (GTK_OBJECT (bd->widget), "scroll_event",
- (GtkSignalFunc) draw_scroll_event, bd);
+ (GtkSignalFunc) draw_scroll_event, bd);
gtk_signal_connect_after (GTK_OBJECT (bd->widget), "key_press_event",
- (GtkSignalFunc) draw_char_event, bd);
+ (GtkSignalFunc) draw_char_event, bd);
gtk_signal_connect_after (GTK_OBJECT (bd->widget), "key_release_event",
- (GtkSignalFunc) draw_char_release_event, bd);
+ (GtkSignalFunc) draw_char_release_event, bd);
gtk_signal_connect (GTK_OBJECT (bd->widget), "leave_notify_event",
- (GtkSignalFunc) draw_leave_event, bd);
+ (GtkSignalFunc) draw_leave_event, bd);
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
- | GDK_BUTTON_RELEASE_MASK
- | GDK_SCROLL_MASK
- | GDK_POINTER_MOTION_MASK
- | GDK_POINTER_MOTION_HINT_MASK
- | GDK_KEY_PRESS_MASK
- | GDK_KEY_RELEASE_MASK );
+ | GDK_LEAVE_NOTIFY_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_SCROLL_MASK
+ | GDK_POINTER_MOTION_MASK
+ | GDK_POINTER_MOTION_HINT_MASK
+ | GDK_KEY_PRESS_MASK
+ | GDK_KEY_RELEASE_MASK );
bd->lastColor = -1;
double dpi;
wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0);
+ if ( width <= 0 || height <= 0 ) {
+ fprintf( stderr, "wDrawCreate bad size %ldx%ld\n", width, height );
+ if ( width <= 0 ) {
+ width = 100;
+ }
+ if ( height <= 0 ) {
+ height = 100;
+ }
+ }
bd->dpi = dpi;
bd->maxW = bd->w = width;
bd->maxH = bd->h = height;
@@ -1601,19 +1498,21 @@ int xw, xh, cw, ch;
wlibControlGetSize( (wControl_p)bd );
gtk_widget_realize( bd->widget );
bd->pixmap = gdk_pixmap_new( bd->widget->window, width, height, -1 );
- bd->temp_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width,height );
+ bd->temp_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width,
+ height );
wDrawClear(bd);
bd->gc = gdk_gc_new( parent->gtkwin->window );
gdk_gc_copy( bd->gc, parent->gtkwin->style->base_gc[GTK_STATE_NORMAL] );
-{
- GdkCursor * cursor;
- cursor = gdk_cursor_new ( GDK_TCROSS );
- gdk_window_set_cursor ( bd->widget->window, cursor);
- gdk_cursor_destroy (cursor);
-}
+ {
+ GdkCursor * cursor;
+ cursor = gdk_cursor_new ( GDK_TCROSS );
+ gdk_window_set_cursor ( bd->widget->window, cursor);
+ gdk_cursor_destroy (cursor);
+ }
#ifdef LATER
- if (labelStr)
+ if (labelStr) {
bd->labelW = gtkAddLabel( (wControl_p)bd, labelStr );
+ }
#endif
gtk_widget_show( bd->widget );
wlibAddButton( (wControl_p)bd );
@@ -1638,7 +1537,7 @@ wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int arg )
double dpi;
- wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0);
+ wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0);
bd->dpi = dpi;
bd->maxW = bd->w = w;
@@ -1674,7 +1573,8 @@ wBool_t wBitMapDelete( wDraw_p d )
* Background
*
******************************************************************************/
-int wDrawSetBackground( wDraw_p bd, char * path, char ** error) {
+int wDrawSetBackground( wDraw_p bd, char * path, char ** error)
+{
GError *err = NULL;
@@ -1698,36 +1598,39 @@ int wDrawSetBackground( wDraw_p bd, char * path, char ** error) {
/**
* Use a loaded background in another context.
- *
+ *
* \param from context with background
- * \param to context to get a reference to the existing background
+ * \param to context to get a reference to the existing background
*/
void
wDrawCloneBackground(wDraw_p from, wDraw_p to)
{
- if (from->background) {
- to->background = from->background;
- } else {
- to->background = NULL;
- }
+ if (from->background) {
+ to->background = from->background;
+ } else {
+ to->background = NULL;
+ }
}
/**
-* Draw background to screen. The background will be sized and rotated before being shown. The bitmap
-* is scaled so that the width is equal to size. The height is changed proportionally.
+* Draw background to screen. The background will be sized and rotated before being shown. The bitmap
+* is scaled so that the width is equal to size. The height is changed proportionally.
*
* \param bd drawing context
* \param pos_x, pos_y bitmap position
* \param size desired width after scaling
-* \param angle
+* \param angle
* \param screen visibility of bitmap in percent
*/
-void wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, wWinPix_t size, wAngle_t angle, int screen) {
+void wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y,
+ wWinPix_t size, wAngle_t angle, int screen)
+{
if (bd->background) {
- cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, wDrawColorWhite, bd->bTempMode?wDrawOptTemp:0 );
+ cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid,
+ wDrawColorWhite, bd->bTempMode?wDrawOptTemp:0 );
cairo_save(cairo);
int pixels_width = gdk_pixbuf_get_width(bd->background);
int pixels_height = gdk_pixbuf_get_height(bd->background);
@@ -1744,19 +1647,24 @@ void wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, wWinPix_
}
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
double rad = M_PI*(angle/180);
- posy = (double)bd->h-((pixels_height*fabs(cos(rad))+pixels_width*fabs(sin(rad)))*scale)-posy;
+ posy = (double)bd->h-((pixels_height*fabs(cos(rad))+pixels_width*fabs(sin(
+ rad)))*scale)-posy;
//width = (double)(pixels_width*scale);
//height = (double)(pixels_height*scale);
cairo_translate(cairo,posx,posy);
cairo_scale(cairo, scale, scale);
- cairo_translate(cairo, fabs(pixels_width/2.0*cos(rad))+fabs(pixels_height/2.0*sin(rad)),
- fabs(pixels_width/2.0*sin(rad))+fabs(pixels_height/2.0*cos(rad)));
+ cairo_translate(cairo, fabs(pixels_width/2.0*cos(rad))+fabs(
+ pixels_height/2.0*sin(rad)),
+ fabs(pixels_width/2.0*sin(rad))+fabs(pixels_height/2.0*cos(rad)));
cairo_rotate(cairo, M_PI*(angle/180.0));
// We need to clip around the image, or cairo will paint garbage data
- cairo_rectangle(cairo, -pixels_width/2.0, -pixels_height/2.0, pixels_width, pixels_height);
+ cairo_rectangle(cairo, -pixels_width/2.0, -pixels_height/2.0, pixels_width,
+ pixels_height);
cairo_clip(cairo);
- gdk_cairo_set_source_pixbuf(cairo, bd->background, -pixels_width/2.0, -pixels_height/2.0);
- cairo_pattern_t *mask = cairo_pattern_create_rgba (1.0,1.0,1.0,(100.0-screen)/100.0);
+ gdk_cairo_set_source_pixbuf(cairo, bd->background, -pixels_width/2.0,
+ -pixels_height/2.0);
+ cairo_pattern_t *mask = cairo_pattern_create_rgba (1.0,1.0,1.0,
+ (100.0-screen)/100.0);
cairo_mask(cairo,mask);
cairo_pattern_destroy(mask);
cairo_restore(cairo);
diff --git a/app/wlib/gtklib/gtkint.h b/app/wlib/gtklib/gtkint.h
index 6d8a641..e3757a4 100644
--- a/app/wlib/gtklib/gtkint.h
+++ b/app/wlib/gtklib/gtkint.h
@@ -1,4 +1,4 @@
-/** \file gtkint.h
+/** \file gtkint.h
* Internal definitions for the gtk-library
*/
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GTKINT_H
@@ -42,24 +42,16 @@
extern wWin_p gtkMainW;
-#ifdef CURSOR_SURFACE
-typedef struct {
- cairo_surface_t* surface;
- wWinPix_t width;
- wWinPix_t height;
- wBool_t show;
-} wCursorSurface_t, * wSurface_p;
-#endif
-
typedef enum {
- W_MAIN, W_POPUP,
- B_BUTTON, B_CANCEL, B_POPUP, B_TEXT, B_INTEGER, B_FLOAT,
- B_LIST, B_DROPLIST, B_COMBOLIST,
- B_RADIO, B_TOGGLE,
- B_DRAW, B_MENU, B_MULTITEXT, B_MESSAGE, B_LINES,
- B_MENUITEM, B_BOX,
- B_BITMAP, B_STATUS } wType_e;
+ W_MAIN, W_POPUP,
+ B_BUTTON, B_CANCEL, B_POPUP, B_TEXT, B_INTEGER, B_FLOAT,
+ B_LIST, B_DROPLIST, B_COMBOLIST,
+ B_RADIO, B_TOGGLE,
+ B_DRAW, B_MENU, B_MULTITEXT, B_MESSAGE, B_LINES,
+ B_MENUITEM, B_BOX,
+ B_BITMAP, B_STATUS
+} wType_e;
typedef void (*repaintProcCallback_p)( wControl_p );
typedef void (*doneProcCallback_p)( wControl_p b );
@@ -71,7 +63,6 @@ typedef void (*setTriggerCallback_p)( wControl_p b );
wWin_p parent; \
wWinPix_t origX, origY; \
wWinPix_t realX, realY; \
- wWinPix_t default_size_x, default_size_y; \
wWinPix_t labelW; \
wWinPix_t w, h; \
int maximize_initially; \
@@ -81,74 +72,73 @@ typedef void (*setTriggerCallback_p)( wControl_p b );
GtkWidget * widget; \
GtkWidget * label; \
doneProcCallback_p doneProc; \
- /* CURSOR_SURFACE wCursorSurface_t cursor_surface;*/ \
wBool_t outline; \
void * data;
struct wWin_t {
- WOBJ_COMMON
- GtkWidget *gtkwin; /**< GTK window */
- wWinPix_t lastX, lastY;
- wControl_p first, last;
- wWinCallBack_p winProc; /**< window procedure */
- 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 timer_idle_count;
- int timer_busy_count;
- int modalLevel;
- };
+ WOBJ_COMMON
+ GtkWidget *gtkwin; /**< GTK window */
+ wWinPix_t lastX, lastY;
+ wControl_p first, last;
+ wWinCallBack_p winProc; /**< window procedure */
+ 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 timer_idle_count;
+ int timer_busy_count;
+ int modalLevel;
+};
struct wControl_t {
- WOBJ_COMMON
- };
-
+ WOBJ_COMMON
+};
+
typedef struct wListItem_t * wListItem_p;
struct wList_t {
- WOBJ_COMMON
+ WOBJ_COMMON
// GtkWidget *list;
- int count;
- int number;
- int colCnt;
- wWinPix_t *colWidths;
- wBool_t *colRightJust;
- GtkListStore *listStore;
- GtkWidget *treeView;
- int last;
- wWinPix_t listX;
- long * valueP;
- wListCallBack_p action;
- int recursion;
- int editted;
- int editable;
- };
+ int count;
+ int number;
+ int colCnt;
+ wWinPix_t *colWidths;
+ wBool_t *colRightJust;
+ GtkListStore *listStore;
+ GtkWidget *treeView;
+ int last;
+ wWinPix_t listX;
+ long * valueP;
+ wListCallBack_p action;
+ int recursion;
+ int editted;
+ int editable;
+};
struct wListItem_t {
- wBool_t active;
- void * itemData;
- char * label;
- GtkLabel * labelG;
- wBool_t selected;
- wList_p listP;
- };
+ wBool_t active;
+ void * itemData;
+ char * label;
+ GtkLabel * labelG;
+ wBool_t selected;
+ wList_p listP;
+};
#define gtkIcon_bitmap (1)
#define gtkIcon_pixmap (2)
struct wIcon_t {
- int gtkIconType;
- wWinPix_t w;
- wWinPix_t h;
- wDrawColor color;
- const void * bits;
- };
+ int gtkIconType;
+ wWinPix_t w;
+ wWinPix_t h;
+ wDrawColor color;
+ const void * bits;
+};
extern char wConfigName[];
extern wDrawColor wDrawColorWhite;
@@ -157,39 +147,42 @@ extern wDrawColor wDrawColorBlack;
/* boxes.c */
-void wlibDrawBox(wWin_p win, wBoxType_e style, wWinPix_t x, wWinPix_t y, wWinPix_t w, wWinPix_t h);
+void wlibDrawBox(wWin_p win, wBoxType_e style, wWinPix_t x, wWinPix_t y,
+ wWinPix_t w, wWinPix_t h);
/* button.c */
-void wlibSetLabel(GtkWidget *widget, long option, const char *labelStr, GtkLabel **labelG, GtkWidget **imageG);
+void wlibSetLabel(GtkWidget *widget, long option, const char *labelStr,
+ GtkLabel **labelG, GtkWidget **imageG);
void wlibButtonDoAction(wButton_p bb);
struct wButton_t {
- WOBJ_COMMON
- GtkLabel * labelG;
- GtkWidget * imageG;
- wButtonCallBack_p action;
- int busy;
- int recursion;
- long timer_id;
- int timer_count;
- int timer_state;
+ WOBJ_COMMON
+ GtkLabel * labelG;
+ GtkWidget * imageG;
+ wButtonCallBack_p action;
+ int busy;
+ int recursion;
+ long timer_id;
+ int timer_count;
+ int timer_state;
};
/* color.c */
typedef struct {
- unsigned char red;
- unsigned char green;
- unsigned char blue;
- GdkColor normalColor;
- GdkColor invertColor;
- long rgb;
- int colorChar;
+ unsigned char red;
+ unsigned char green;
+ unsigned char blue;
+ GdkColor normalColor;
+ GdkColor invertColor;
+ long rgb;
+ int colorChar;
} colorMap_t;
GdkColor *wlibGetColor(wDrawColor color, wBool_t normal);
/* control.c */
-wBool_t wControlExpose (GtkWidget * widget, GdkEventExpose * event, wControl_p b);
+wBool_t wControlExpose (GtkWidget * widget, GdkEventExpose * event,
+ wControl_p b);
/* droplist.c */
enum columns {
@@ -204,13 +197,19 @@ void wDropListClear(wList_p b);
void *wDropListGetItemContext(wList_p b, wIndex_t inx);
void wDropListAddValue(wList_p b, char *text, wListItem_p data);
void wDropListSetIndex(wList_p b, int val);
-wBool_t wDropListSetValues(wList_p b, wIndex_t row, const char *labelStr, wIcon_p bm, void *itemData);
-wList_p wDropListCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, const char *helpStr, const char *labelStr, long option, long number, wWinPix_t width, long *valueP, wListCallBack_p action, void *data);
+wBool_t wDropListSetValues(wList_p b, wIndex_t row, const char *labelStr,
+ wIcon_p bm, void *itemData);
+wList_p wDropListCreate(wWin_p parent, wWinPix_t x, wWinPix_t y,
+ const char *helpStr, const char *labelStr, long option, long number,
+ wWinPix_t width, long *valueP, wListCallBack_p action, void *data);
/* filesel.c */
/* font.c */
-PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void *cairo, wFont_p fp, wFontSize_t fs, const char *s, wDrawPix_t *width_p, wDrawPix_t *height_p, wDrawPix_t *ascent_p, wDrawPix_t *descent_p, wDrawPix_t *baseline_p);
+PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void *cairo,
+ wFont_p fp, wFontSize_t fs, const char *s, wDrawPix_t *width_p,
+ wDrawPix_t *height_p, wDrawPix_t *ascent_p, wDrawPix_t *descent_p,
+ wDrawPix_t *baseline_p);
void wlibFontDestroyPangoLayout(PangoLayout *layout);
const char *wlibFontTranslate(wFont_p fp);
@@ -220,16 +219,20 @@ const char *wlibFontTranslate(wFont_p fp);
void wlibLineShow(wLine_p bl, wBool_t visible);
/* list.c */
-int CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
+int CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
+ gpointer data);
/* liststore.c */
wListItem_p wlibListItemGet(GtkListStore *ls, wIndex_t inx, GList **childR);
void *wlibListStoreGetContext(GtkListStore *ls, int inx);
void wlibListStoreClear(GtkListStore *listStore);
GtkListStore *wlibNewListStore(int colCnt);
-void wlibListStoreSetPixbuf(GtkListStore *ls, GtkTreeIter *iter, GdkPixbuf *pixbuf);
-int wlibListStoreAddData(GtkListStore *ls, GdkPixbuf *pixbuf, int cols, wListItem_p id);
-int wlibListStoreUpdateValues(GtkListStore *ls, int row, int cols, char *labels, wIcon_p bm);
+void wlibListStoreSetPixbuf(GtkListStore *ls, GtkTreeIter *iter,
+ GdkPixbuf *pixbuf);
+int wlibListStoreAddData(GtkListStore *ls, GdkPixbuf *pixbuf, int cols,
+ wListItem_p id);
+int wlibListStoreUpdateValues(GtkListStore *ls, int row, int cols, char *labels,
+ wIcon_p bm);
/* main.c */
char *wlibGetAppName(void);
@@ -239,16 +242,17 @@ int getMlistOrigin(wMenuList_p ml, GList **pChildren);
/* misc.c */
typedef struct accelData_t {
- wAccelKey_e key;
- int modifier;
- wAccelKeyCallBack_p action;
- void * data;
+ wAccelKey_e key;
+ int modifier;
+ wAccelKeyCallBack_p action;
+ void * data;
} accelData_t;
GdkPixbuf* wlibPixbufFromXBM(wIcon_p ip);
int wlibAddLabel(wControl_p b, const char *labelStr);
-void *wlibAlloc(wWin_p parent, wType_e type, wWinPix_t origX, wWinPix_t origY, const char *labelStr, int size, void *data);
+void *wlibAlloc(wWin_p parent, wType_e type, wWinPix_t origX, wWinPix_t origY,
+ const char *labelStr, int size, void *data);
void wlibComputePos(wControl_p b);
void wlibControlGetSize(wControl_p b);
void wlibAddButton(wControl_p b);
@@ -267,46 +271,53 @@ GdkPixbuf *wlibMakePixbuf(wIcon_p ip);
/* print.c */
struct wDraw_t {
- WOBJ_COMMON
- void * context;
- wDrawActionCallBack_p action;
- wDrawRedrawCallBack_p redraw;
-
- GdkPixmap * pixmap;
- GdkPixmap * pixmapBackup;
- cairo_surface_t * temp_surface;
-
- double dpi;
-
- GdkGC * gc;
- wDrawWidth lineWidth;
- wDrawOpts opts;
- wWinPix_t maxW;
- wWinPix_t maxH;
- unsigned long lastColor;
- wBool_t lastColorInverted;
- const char * helpStr;
-
- wWinPix_t lastX;
- wWinPix_t lastY;
-
- wBool_t delayUpdate;
- cairo_t *printContext;
- cairo_surface_t *curPrintSurface;
- GdkPixbuf * background;
-
- wBool_t bTempMode;
- };
+ WOBJ_COMMON
+ void * context;
+ wDrawActionCallBack_p action;
+ wDrawRedrawCallBack_p redraw;
+
+ GdkPixmap * pixmap;
+ GdkPixmap * pixmapBackup;
+ cairo_surface_t * temp_surface;
+
+ double dpi;
+
+ GdkGC * gc;
+ wDrawWidth lineWidth;
+ wDrawOpts opts;
+ wWinPix_t maxW;
+ wWinPix_t maxH;
+ unsigned long lastColor;
+ wBool_t lastColorInverted;
+ const char * helpStr;
+
+ wWinPix_t lastX;
+ wWinPix_t lastY;
+
+ wBool_t delayUpdate;
+ cairo_t *printContext;
+ cairo_surface_t *curPrintSurface;
+ GdkPixbuf * background;
+
+ wBool_t bTempMode;
+};
void WlibApplySettings(GtkPrintOperation *op);
void WlibSaveSettings(GtkPrintOperation *op);
-void psPrintLine(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, wDrawPix_t y1, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts);
-void psPrintArc(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, double angle0, double angle1, wBool_t drawCenter, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts);
-void psPrintFillRectangle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, wDrawPix_t y1, wDrawColor color, wDrawOpts opts);
-void psPrintFillPolygon(wDrawPix_t p[][2], wPolyLine_e type[], int cnt, wDrawColor color, wDrawOpts opts, int fill, int open);
-void psPrintFillCircle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, wDrawColor color, wDrawOpts opts);
-void psPrintString(wDrawPix_t x, wDrawPix_t y, double a, char *s, wFont_p fp, double fs, wDrawColor color, wDrawOpts opts);
-static void WlibGetPaperSize(void);
+void psPrintLine(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, wDrawPix_t y1,
+ wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts);
+void psPrintArc(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, double angle0,
+ double angle1, wBool_t drawCenter, wDrawWidth width, wDrawLineType_e lineType,
+ wDrawColor color, wDrawOpts opts);
+void psPrintFillRectangle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1,
+ wDrawPix_t y1, wDrawColor color, wDrawOpts opts);
+void psPrintFillPolygon(wDrawPix_t p[][2], wPolyLine_e type[], int cnt,
+ wDrawColor color, wDrawOpts opts, int fill, int open);
+void psPrintFillCircle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r,
+ wDrawColor color, wDrawOpts opts);
+void psPrintString(wDrawPix_t x, wDrawPix_t y, double a, char *s, wFont_p fp,
+ double fs, wDrawColor color, wDrawOpts opts);
+//static void WlibGetPaperSize(void);
/* single.c */
void wlibStringUpdate();
@@ -325,12 +336,15 @@ void wlibHelpHideBalloon();
/* treeview.c */
void wlibTreeViewSetSelected(wList_p b, int index);
-GtkWidget *wlibNewTreeView(GtkListStore *ls, int showTitles, int multiSelection);
+GtkWidget *wlibNewTreeView(GtkListStore *ls, int showTitles,
+ int multiSelection);
int wlibTreeViewAddColumns(GtkWidget *tv, int count);
int wlibAddColumnTitles(GtkWidget *tv, const char **titles);
-int wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf, wListItem_p userData);
+int wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf,
+ wListItem_p userData);
void wlibTreeViewAddRow(wList_p b, char *label, wIcon_p bm, wListItem_p id_p);
-gboolean changeSelection(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data);
+gboolean changeSelection(GtkTreeSelection *selection, GtkTreeModel *model,
+ GtkTreePath *path, gboolean path_currently_selected, gpointer data);
int wTreeViewGetCount(wList_p b);
void wTreeViewClear(wList_p b);
@@ -338,7 +352,8 @@ void *wTreeViewGetItemContext(wList_p b, int row);
/* window.c */
void wlibDoModal(wWin_p win0, wBool_t modal);
-wBool_t catch_shift_ctrl_alt_keys(GtkWidget *widget, GdkEventKey *event, void *data);
+wBool_t catch_shift_ctrl_alt_keys(GtkWidget *widget, GdkEventKey *event,
+ void *data);
/* wpref.c */
diff --git a/app/wlib/gtklib/help.c b/app/wlib/gtklib/help.c
index 45d1813..f062b83 100644
--- a/app/wlib/gtklib/help.c
+++ b/app/wlib/gtklib/help.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define GTK_DISABLE_SINGLE_INCLUDES
@@ -46,29 +46,31 @@ extern const char * GetCurCommandName();
static void
DoHelpMenu(void *data)
{
- int func = (intptr_t)data;
+ int func = (intptr_t)data;
- const char * topic;
+ const char * topic;
- switch (func) {
- case 1:
- wHelp("contents");
- break;
+ switch (func) {
+ case 1:
+ wHelp("contents");
+ break;
- case 3:
- topic = GetCurCommandName();
- if (topic && topic[0])
- wHelp(topic);
- break;
+ case 3:
+ topic = GetCurCommandName();
+ if (topic && topic[0]) {
+ wHelp(topic);
+ }
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- return;
+ return;
}
-void wDoAccelHelp(wAccelKey_e key, void * context) {
+void wDoAccelHelp(wAccelKey_e key, void * context)
+{
DoHelpMenu(context);
}
@@ -81,6 +83,6 @@ void wDoAccelHelp(wAccelKey_e key, void * context) {
void wMenuAddHelp(wMenu_p m)
{
- wMenuPushCreate(m, NULL, _("&Contents"), 0, DoHelpMenu, (void*)1);
- wMenuPushCreate(m, NULL, _("Co&mmand Context help"), 0, DoHelpMenu, (void*)3);
+ wMenuPushCreate(m, NULL, _("&Contents"), 0, DoHelpMenu, (void*)1);
+ wMenuPushCreate(m, NULL, _("Co&mmand Context help"), 0, DoHelpMenu, (void*)3);
}
diff --git a/app/wlib/gtklib/ixhelp.c b/app/wlib/gtklib/ixhelp.c
index 5079f61..80b579c 100644
--- a/app/wlib/gtklib/ixhelp.c
+++ b/app/wlib/gtklib/ixhelp.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@@ -77,34 +77,34 @@ static GtkWidget *contents_view; /** handle for the help contents pane */
static GtkWidget*
lookup_widget(GtkWidget *widget, const gchar *widget_name)
{
- GtkWidget *parent, *found_widget;
+ GtkWidget *parent, *found_widget;
- for (;;) {
- if (GTK_IS_MENU(widget)) {
- parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
- } else {
- parent = widget->parent;
- }
+ for (;;) {
+ if (GTK_IS_MENU(widget)) {
+ parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
+ } else {
+ parent = widget->parent;
+ }
- if (!parent) {
- parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
- }
+ if (!parent) {
+ parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
+ }
- if (parent == NULL) {
- break;
- }
+ if (parent == NULL) {
+ break;
+ }
- widget = parent;
- }
+ widget = parent;
+ }
- found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget),
- widget_name);
+ found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget),
+ widget_name);
- if (!found_widget) {
- g_warning("Widget not found: %s", widget_name);
- }
+ if (!found_widget) {
+ g_warning("Widget not found: %s", widget_name);
+ }
- return found_widget;
+ return found_widget;
}
@@ -124,21 +124,21 @@ lookup_widget(GtkWidget *widget, const gchar *widget_name)
GtkWidget *
CreateHPaned(GtkBox *container, char *property)
{
- GtkWidget *hpaned;
- long posSlider;
+ GtkWidget *hpaned;
+ long posSlider;
- /* the horizontal slider */
- hpaned = gtk_hpaned_new();
- gtk_container_set_border_width(GTK_CONTAINER(hpaned), 6);
+ /* the horizontal slider */
+ hpaned = gtk_hpaned_new();
+ gtk_container_set_border_width(GTK_CONTAINER(hpaned), 6);
- wPrefGetInteger(HTMLHELPSECTION, SLIDERPREFNAME, &posSlider, SLIDERPOSDEFAULT);
- gtk_paned_set_position(GTK_PANED(hpaned), (int)posSlider);
+ wPrefGetInteger(HTMLHELPSECTION, SLIDERPREFNAME, &posSlider, SLIDERPOSDEFAULT);
+ gtk_paned_set_position(GTK_PANED(hpaned), (int)posSlider);
- /* pack the horizontal slider into the main window */
- gtk_box_pack_start(container, hpaned, TRUE, TRUE, 0);
- gtk_widget_show(hpaned);
+ /* pack the horizontal slider into the main window */
+ gtk_box_pack_start(container, hpaned, TRUE, TRUE, 0);
+ gtk_widget_show(hpaned);
- return (hpaned);
+ return (hpaned);
}
/**
@@ -155,69 +155,69 @@ CreateHPaned(GtkBox *container, char *property)
static gboolean
DestroyHelpWindow(GtkWidget *win, GdkEvent *event, void *ptr)
{
- int i;
- GtkWidget *widget;
- char tmp[ 20 ];
+ int i;
+ GtkWidget *widget;
+ char tmp[ 20 ];
- gint x, y;
+ gint x, y;
- /* get the slider position and save it */
- widget = lookup_widget(win, PANED);
- i = gtk_paned_get_position(GTK_PANED(widget));
- wPrefSetInteger(HTMLHELPSECTION, SLIDERPREFNAME, i);
+ /* get the slider position and save it */
+ widget = lookup_widget(win, PANED);
+ i = gtk_paned_get_position(GTK_PANED(widget));
+ wPrefSetInteger(HTMLHELPSECTION, SLIDERPREFNAME, i);
- /* get the window position */
- gtk_window_get_position((GtkWindow *)win, &x, &y);
- sprintf(tmp, "%d %d", x, y);
- wPrefSetString(HTMLHELPSECTION, WINDOWPOSPREFNAME, tmp);
+ /* get the window position */
+ gtk_window_get_position((GtkWindow *)win, &x, &y);
+ sprintf(tmp, "%d %d", x, y);
+ wPrefSetString(HTMLHELPSECTION, WINDOWPOSPREFNAME, tmp);
- /* get the window size */
- gtk_window_get_size((GtkWindow *)win , &x, &y);
- sprintf(tmp, "%d %d", x, y);
- wPrefSetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME, tmp);
+ /* get the window size */
+ gtk_window_get_size((GtkWindow *)win, &x, &y);
+ sprintf(tmp, "%d %d", x, y);
+ wPrefSetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME, tmp);
- gtk_widget_hide(win);
- return TRUE;
+ gtk_widget_hide(win);
+ return TRUE;
}
void back_button_clicked(GtkWidget *widget, gpointer data)
{
- webkit_web_view_go_back(WEBKIT_WEB_VIEW(data));
+ webkit_web_view_go_back(WEBKIT_WEB_VIEW(data));
}
void forward_button_clicked(GtkWidget *widget, gpointer data)
{
- webkit_web_view_go_forward(WEBKIT_WEB_VIEW(data));
+ webkit_web_view_go_forward(WEBKIT_WEB_VIEW(data));
}
void home_button_clicked(GtkWidget *widget, gpointer data)
{
- load_into_view("index.html", MAIN_VIEW);
+ load_into_view("index.html", MAIN_VIEW);
}
/* Toggles the contents pane */
void contents_button_clicked(GtkWidget *widget, gpointer data)
{
- if (gtk_paned_get_position(GTK_PANED(data)) < 50) {
- gtk_paned_set_position(GTK_PANED(data), 370);
- } else {
- gtk_paned_set_position(GTK_PANED(data), 0);
- }
+ if (gtk_paned_get_position(GTK_PANED(data)) < 50) {
+ gtk_paned_set_position(GTK_PANED(data), 370);
+ } else {
+ gtk_paned_set_position(GTK_PANED(data), 0);
+ }
}
gboolean contents_click_handler(
- WebKitWebView *web_view,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- WebKitWebNavigationAction *navigation_action,
- WebKitWebPolicyDecision *policy_decision,
- gpointer data)
+ WebKitWebView *web_view,
+ WebKitWebFrame *frame,
+ WebKitNetworkRequest *request,
+ WebKitWebNavigationAction *navigation_action,
+ WebKitWebPolicyDecision *policy_decision,
+ gpointer data)
{
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(data),
- webkit_network_request_get_uri(request));
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(data),
+ webkit_network_request_get_uri(request));
- return TRUE;
+ return TRUE;
}
/**
@@ -225,45 +225,45 @@ gboolean contents_click_handler(
*/
void initialize_buttons(GtkWidget *main_vbox, GtkWidget *content_hpane)
{
- GtkWidget *buttons_hbuttonbox;
- GtkWidget *back_button;
- GtkWidget *forward_button;
- GtkWidget *home_button;
- GtkWidget *contents_button;
-
- // define and attach signals to buttons
- back_button = gtk_button_new_with_label(_("Back"));
- g_signal_connect(back_button, "clicked", G_CALLBACK(back_button_clicked),
- G_OBJECT(main_view));
-
- forward_button = gtk_button_new_with_label(_("Forward"));
- g_signal_connect(forward_button, "clicked", G_CALLBACK(forward_button_clicked),
- G_OBJECT(main_view));
-
- home_button = gtk_button_new_with_label(_("Home"));
- g_signal_connect(home_button, "clicked", G_CALLBACK(home_button_clicked),
- G_OBJECT(main_view));
-
- contents_button = gtk_button_new_with_label(_("Contents"));
- g_signal_connect(contents_button, "clicked",
- G_CALLBACK(contents_button_clicked), G_OBJECT(content_hpane));
-
- // button layout
- buttons_hbuttonbox = gtk_hbutton_box_new();
- gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), back_button);
- gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), forward_button);
- gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), home_button);
- gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), contents_button);
- gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbuttonbox, FALSE, TRUE, 0);
- gtk_box_set_spacing(GTK_BOX(buttons_hbuttonbox), 6);
- gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons_hbuttonbox),
- GTK_BUTTONBOX_START);
-
- /* Store pointers to all widgets, for use by lookup_widget(). */
- GLADE_HOOKUP_OBJECT(main_view, back_button, BACKBUTTON);
- GLADE_HOOKUP_OBJECT(main_view, forward_button, FORWARDBUTTON);
- GLADE_HOOKUP_OBJECT(main_view, home_button, HOMEBUTTON);
- GLADE_HOOKUP_OBJECT(main_view, contents_button, CONTENTBUTTON);
+ GtkWidget *buttons_hbuttonbox;
+ GtkWidget *back_button;
+ GtkWidget *forward_button;
+ GtkWidget *home_button;
+ GtkWidget *contents_button;
+
+ // define and attach signals to buttons
+ back_button = gtk_button_new_with_label(_("Back"));
+ g_signal_connect(back_button, "clicked", G_CALLBACK(back_button_clicked),
+ G_OBJECT(main_view));
+
+ forward_button = gtk_button_new_with_label(_("Forward"));
+ g_signal_connect(forward_button, "clicked", G_CALLBACK(forward_button_clicked),
+ G_OBJECT(main_view));
+
+ home_button = gtk_button_new_with_label(_("Home"));
+ g_signal_connect(home_button, "clicked", G_CALLBACK(home_button_clicked),
+ G_OBJECT(main_view));
+
+ contents_button = gtk_button_new_with_label(_("Contents"));
+ g_signal_connect(contents_button, "clicked",
+ G_CALLBACK(contents_button_clicked), G_OBJECT(content_hpane));
+
+ // button layout
+ buttons_hbuttonbox = gtk_hbutton_box_new();
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), back_button);
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), forward_button);
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), home_button);
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), contents_button);
+ gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbuttonbox, FALSE, TRUE, 0);
+ gtk_box_set_spacing(GTK_BOX(buttons_hbuttonbox), 6);
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons_hbuttonbox),
+ GTK_BUTTONBOX_START);
+
+ /* Store pointers to all widgets, for use by lookup_widget(). */
+ GLADE_HOOKUP_OBJECT(main_view, back_button, BACKBUTTON);
+ GLADE_HOOKUP_OBJECT(main_view, forward_button, FORWARDBUTTON);
+ GLADE_HOOKUP_OBJECT(main_view, home_button, HOMEBUTTON);
+ GLADE_HOOKUP_OBJECT(main_view, contents_button, CONTENTBUTTON);
}
/**
@@ -275,123 +275,123 @@ void initialize_buttons(GtkWidget *main_vbox, GtkWidget *content_hpane)
GtkWidget*
CreateHelpWindow(void)
{
- GtkWidget *main_vbox;
- GtkWidget *main_view_scroller;
- GtkWidget *contents_view_scroller;
- GtkWidget *content_hpane;
+ GtkWidget *main_vbox;
+ GtkWidget *main_view_scroller;
+ GtkWidget *contents_view_scroller;
+ GtkWidget *content_hpane;
- int width;
- int height;
- int x, y;
- int w = 0, h = 0;
- const char *pref;
+ int width;
+ int height;
+ int x, y;
+ int w = 0, h = 0;
+ const char *pref;
- wHelpWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ wHelpWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- width = gdk_screen_get_width(gtk_window_get_screen((GtkWindow *)wHelpWindow));
- height = gdk_screen_get_height(gtk_window_get_screen((GtkWindow *)wHelpWindow));
+ width = gdk_screen_get_width(gtk_window_get_screen((GtkWindow *)wHelpWindow));
+ height = gdk_screen_get_height(gtk_window_get_screen((GtkWindow *)wHelpWindow));
- pref = wPrefGetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME);
+ pref = wPrefGetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME);
- if (pref) {
- sscanf(pref, "%d %d", &w, &h);
+ if (pref) {
+ sscanf(pref, "%d %d", &w, &h);
- if (w > width) {
- w = width;
- }
+ if (w > width) {
+ w = width;
+ }
- if (h > height) {
- h = height;
- }
- } else {
- w = (width * 2)/ 5;
- h = height - 100;
- }
+ if (h > height) {
+ h = height;
+ }
+ } else {
+ w = (width * 2)/ 5;
+ h = height - 100;
+ }
- pref = wPrefGetString(HTMLHELPSECTION, WINDOWPOSPREFNAME);
+ pref = wPrefGetString(HTMLHELPSECTION, WINDOWPOSPREFNAME);
- if (pref) {
- sscanf(pref, "%d %d", &x, &y);
+ if (pref) {
+ sscanf(pref, "%d %d", &x, &y);
- if (y > height - h) {
- y = height - h;
- }
+ if (y > height - h) {
+ y = height - h;
+ }
- if (x > width - w) {
- x = width - w;
- }
- } else {
- x = (width * 3) / 5 - 10;
- y = 70;
- }
+ if (x > width - w) {
+ x = width - w;
+ }
+ } else {
+ x = (width * 3) / 5 - 10;
+ y = 70;
+ }
- gtk_window_resize((GtkWindow *)wHelpWindow, w, h);
- gtk_window_move((GtkWindow *)wHelpWindow, x, y);
+ gtk_window_resize((GtkWindow *)wHelpWindow, w, h);
+ gtk_window_move((GtkWindow *)wHelpWindow, x, y);
- gtk_window_set_title(GTK_WINDOW(wHelpWindow), "XTrkCad Help");
+ gtk_window_set_title(GTK_WINDOW(wHelpWindow), "XTrkCad Help");
- g_signal_connect(G_OBJECT(wHelpWindow), "delete-event",
- G_CALLBACK(DestroyHelpWindow), NULL);
+ g_signal_connect(G_OBJECT(wHelpWindow), "delete-event",
+ G_CALLBACK(DestroyHelpWindow), NULL);
- main_view_scroller = gtk_scrolled_window_new(NULL, NULL);
- contents_view_scroller = gtk_scrolled_window_new(NULL, NULL);
- main_view = webkit_web_view_new();
- contents_view = webkit_web_view_new();
- // must be done here as it gets locked down later
- load_into_view("contents.html", CONTENTS_VIEW);
- gtk_widget_set_size_request(GTK_WIDGET(wHelpWindow), x, y);
+ main_view_scroller = gtk_scrolled_window_new(NULL, NULL);
+ contents_view_scroller = gtk_scrolled_window_new(NULL, NULL);
+ main_view = webkit_web_view_new();
+ contents_view = webkit_web_view_new();
+ // must be done here as it gets locked down later
+ load_into_view("contents.html", CONTENTS_VIEW);
+ gtk_widget_set_size_request(GTK_WIDGET(wHelpWindow), x, y);
- main_vbox = gtk_vbox_new(FALSE, 5);
- gtk_container_add(GTK_CONTAINER(wHelpWindow), main_vbox);
+ main_vbox = gtk_vbox_new(FALSE, 5);
+ gtk_container_add(GTK_CONTAINER(wHelpWindow), main_vbox);
- gtk_container_add(GTK_CONTAINER(main_view_scroller), main_view);
+ gtk_container_add(GTK_CONTAINER(main_view_scroller), main_view);
- gtk_container_add(GTK_CONTAINER(contents_view_scroller), contents_view);
+ gtk_container_add(GTK_CONTAINER(contents_view_scroller), contents_view);
- content_hpane = gtk_hpaned_new();
- initialize_buttons(main_vbox, content_hpane);
- gtk_container_add(GTK_CONTAINER(content_hpane), contents_view_scroller);
- gtk_container_add(GTK_CONTAINER(content_hpane), main_view_scroller);
- gtk_box_pack_start(GTK_BOX(main_vbox), content_hpane, TRUE, TRUE, 0);
+ content_hpane = gtk_hpaned_new();
+ initialize_buttons(main_vbox, content_hpane);
+ gtk_container_add(GTK_CONTAINER(content_hpane), contents_view_scroller);
+ gtk_container_add(GTK_CONTAINER(content_hpane), main_view_scroller);
+ gtk_box_pack_start(GTK_BOX(main_vbox), content_hpane, TRUE, TRUE, 0);
- gtk_paned_set_position(GTK_PANED(content_hpane), 370);
+ gtk_paned_set_position(GTK_PANED(content_hpane), 370);
- g_signal_connect(contents_view, "navigation-policy-decision-requested",
- G_CALLBACK(contents_click_handler), G_OBJECT(main_view));
+ g_signal_connect(contents_view, "navigation-policy-decision-requested",
+ G_CALLBACK(contents_click_handler), G_OBJECT(main_view));
- /* Store pointers to all widgets, for use by lookup_widget(). */
- GLADE_HOOKUP_OBJECT_NO_REF(wHelpWindow, wHelpWindow, "wHelpWindow");
- GLADE_HOOKUP_OBJECT(wHelpWindow, content_hpane, PANED);
- GLADE_HOOKUP_OBJECT(wHelpWindow, contents_view, TOCVIEW);
- GLADE_HOOKUP_OBJECT(wHelpWindow, main_view, CONTENTSVIEW);
+ /* Store pointers to all widgets, for use by lookup_widget(). */
+ GLADE_HOOKUP_OBJECT_NO_REF(wHelpWindow, wHelpWindow, "wHelpWindow");
+ GLADE_HOOKUP_OBJECT(wHelpWindow, content_hpane, PANED);
+ GLADE_HOOKUP_OBJECT(wHelpWindow, contents_view, TOCVIEW);
+ GLADE_HOOKUP_OBJECT(wHelpWindow, main_view, CONTENTSVIEW);
- return wHelpWindow;
+ return wHelpWindow;
}
void load_into_view(char *file, int requested_view)
{
- GtkWidget *view;
+ GtkWidget *view;
- switch (requested_view) {
- case MAIN_VIEW:
- view = main_view;
- break;
+ switch (requested_view) {
+ case MAIN_VIEW:
+ view = main_view;
+ break;
- case CONTENTS_VIEW:
- view = contents_view;
- break;
+ case CONTENTS_VIEW:
+ view = contents_view;
+ break;
- default:
- printf("*** error, could not find view");
- break;
- }
+ default:
+ printf("*** error, could not find view");
+ break;
+ }
- char fileToLoad[250] = "file://";
- strcat(fileToLoad,directory);
- strcat(fileToLoad,file);
+ char fileToLoad[250] = "file://";
+ strcat(fileToLoad,directory);
+ strcat(fileToLoad,file);
- //debug printf("*** loading %s into pane %d.\n", fileToLoad, requested_view);
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(view), fileToLoad);
+ //debug printf("*** loading %s into pane %d.\n", fileToLoad, requested_view);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(view), fileToLoad);
}
/**
@@ -402,36 +402,36 @@ void load_into_view(char *file, int requested_view)
void wHelp(const char * topic)
{
- char *htmlFile;
+ char *htmlFile;
- //Take off any topic characters after a '-'
+ //Take off any topic characters after a '-'
- if (!topic || !topic[0]) return;
+ if (!topic || !topic[0]) { return; }
- if (!CheckHelpTopicExists(topic)) return;
+ if (!CheckHelpTopicExists(topic)) { return; }
- if (!wHelpWindow) {
- directory = malloc(BUFSIZ);
- assert(directory != NULL);
+ if (!wHelpWindow) {
+ directory = malloc(BUFSIZ);
+ assert(directory != NULL);
- sprintf(directory, "%s/html/", wGetAppLibDir());
+ sprintf(directory, "%s/html/", wGetAppLibDir());
- wHelpWindow = CreateHelpWindow();
- /* load the default content */
- load_into_view("index.html", MAIN_VIEW);
- }
+ wHelpWindow = CreateHelpWindow();
+ /* load the default content */
+ load_into_view("index.html", MAIN_VIEW);
+ }
- /* need space for the 'html' extension plus dot plus \0 */
- htmlFile = malloc(strlen(topic) + 6);
+ /* need space for the 'html' extension plus dot plus \0 */
+ htmlFile = malloc(strlen(topic) + 6);
- assert(htmlFile != NULL);
+ assert(htmlFile != NULL);
- sprintf(htmlFile, "%s.html", topic);
+ sprintf(htmlFile, "%s.html", topic);
- load_into_view(htmlFile, MAIN_VIEW);
- gtk_widget_show_all(wHelpWindow);
- gtk_window_present(GTK_WINDOW(wHelpWindow));
+ load_into_view(htmlFile, MAIN_VIEW);
+ gtk_widget_show_all(wHelpWindow);
+ gtk_window_present(GTK_WINDOW(wHelpWindow));
- free(htmlFile);
+ free(htmlFile);
}
diff --git a/app/wlib/gtklib/lines.c b/app/wlib/gtklib/lines.c
index bd787a6..6ce7ac1 100644
--- a/app/wlib/gtklib/lines.c
+++ b/app/wlib/gtklib/lines.c
@@ -44,10 +44,10 @@
*/
struct wLine_t {
- WOBJ_COMMON
- wBool_t visible;
- int count;
- wLines_t * lines;
+ WOBJ_COMMON
+ wBool_t visible;
+ int count;
+ wLines_t * lines;
};
/**
@@ -59,30 +59,30 @@ struct wLine_t {
static void linesRepaint(wControl_p b)
{
- wLine_p bl = (wLine_p)(b);
- int i;
- wWin_p win = (wWin_p)(bl->parent);
- GdkDrawable * window;
- cairo_t *cr;
-
- if (!bl->visible) {
- return;
- }
-
- window = gtk_widget_get_window(win->widget);
- cr = gdk_cairo_create(window);
- cairo_set_source_rgb(cr, 0, 0, 0);
- cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
- cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
-
- for (i=0; i<bl->count; i++) {
- cairo_set_line_width(cr, bl->lines[i].width);
- cairo_move_to(cr, bl->lines[i].x0, bl->lines[i].y0);
- cairo_line_to(cr, bl->lines[i].x1, bl->lines[i].y1);
- cairo_stroke(cr);
- }
-
- cairo_destroy(cr);
+ wLine_p bl = (wLine_p)(b);
+ int i;
+ wWin_p win = (wWin_p)(bl->parent);
+ GdkDrawable * window;
+ cairo_t *cr;
+
+ if (!bl->visible) {
+ return;
+ }
+
+ window = gtk_widget_get_window(win->widget);
+ cr = gdk_cairo_create(window);
+ cairo_set_source_rgb(cr, 0, 0, 0);
+ cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
+ cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
+
+ for (i=0; i<bl->count; i++) {
+ cairo_set_line_width(cr, bl->lines[i].width);
+ cairo_move_to(cr, bl->lines[i].x0, bl->lines[i].y0);
+ cairo_line_to(cr, bl->lines[i].x1, bl->lines[i].y1);
+ cairo_stroke(cr);
+ }
+
+ cairo_destroy(cr);
}
/**
@@ -94,10 +94,10 @@ static void linesRepaint(wControl_p b)
*/
void wlibLineShow(
- wLine_p bl,
- wBool_t visible)
+ wLine_p bl,
+ wBool_t visible)
{
- bl->visible = visible;
+ bl->visible = visible;
}
/**
@@ -111,40 +111,40 @@ void wlibLineShow(
*/
wLine_p wLineCreate(
- wWin_p parent,
- const char * labelStr,
- int count,
- wLines_t * lines)
+ wWin_p parent,
+ const char * labelStr,
+ int count,
+ wLines_t * lines)
{
- wLine_p linesWindow;
- int i;
- linesWindow = (wLine_p)wlibAlloc(parent, B_LINES, 0, 0, labelStr,
- sizeof *linesWindow, NULL);
- linesWindow->visible = TRUE;
- linesWindow->count = count;
- linesWindow->lines = lines;
- linesWindow->w = linesWindow->h = 0;
-
- for (i=0; i<count; i++) {
- if (lines[i].x0 > linesWindow->w) {
- linesWindow->w = lines[i].x0;
- }
-
- if (lines[i].y0 > linesWindow->h) {
- linesWindow->h = lines[i].y0;
- }
-
- if (lines[i].x1 > linesWindow->w) {
- linesWindow->w = lines[i].x1;
- }
-
- if (lines[i].y1 > linesWindow->h) {
- linesWindow->h = lines[i].y1;
- }
- }
-
- linesWindow->repaintProc = linesRepaint;
- wlibAddButton((wControl_p)linesWindow);
- linesWindow->widget = NULL;
- return linesWindow;
+ wLine_p linesWindow;
+ int i;
+ linesWindow = (wLine_p)wlibAlloc(parent, B_LINES, 0, 0, labelStr,
+ sizeof *linesWindow, NULL);
+ linesWindow->visible = TRUE;
+ linesWindow->count = count;
+ linesWindow->lines = lines;
+ linesWindow->w = linesWindow->h = 0;
+
+ for (i=0; i<count; i++) {
+ if (lines[i].x0 > linesWindow->w) {
+ linesWindow->w = lines[i].x0;
+ }
+
+ if (lines[i].y0 > linesWindow->h) {
+ linesWindow->h = lines[i].y0;
+ }
+
+ if (lines[i].x1 > linesWindow->w) {
+ linesWindow->w = lines[i].x1;
+ }
+
+ if (lines[i].y1 > linesWindow->h) {
+ linesWindow->h = lines[i].y1;
+ }
+ }
+
+ linesWindow->repaintProc = linesRepaint;
+ wlibAddButton((wControl_p)linesWindow);
+ linesWindow->widget = NULL;
+ return linesWindow;
}
diff --git a/app/wlib/gtklib/list.c b/app/wlib/gtklib/list.c
index 2080b9f..92977dc 100644
--- a/app/wlib/gtklib/list.c
+++ b/app/wlib/gtklib/list.c
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -37,9 +37,9 @@
#include "i18n.h"
struct listSearch {
- const char *search;
- char *result;
- int row;
+ const char *search;
+ char *result;
+ int row;
};
@@ -59,21 +59,21 @@ struct listSearch {
*/
void wListClear(
- wList_p b)
+ wList_p b)
{
- assert(b!= NULL);
+ assert(b!= NULL);
- b->recursion++;
+ b->recursion++;
- if (b->type == B_DROPLIST) {
- wDropListClear(b);
- } else {
- wTreeViewClear(b);
- }
+ if (b->type == B_DROPLIST) {
+ wDropListClear(b);
+ } else {
+ wTreeViewClear(b);
+ }
- b->recursion--;
- b->last = -1;
- b->count = 0;
+ b->recursion--;
+ b->last = -1;
+ b->count = 0;
}
/**
@@ -84,23 +84,23 @@ void wListClear(
*/
void wListSetIndex(
- wList_p b,
- int element)
+ wList_p b,
+ int element)
{
- if (b->widget == 0) {
- abort();
- }
+ if (b->widget == 0) {
+ abort();
+ }
- b->recursion++;
+ b->recursion++;
- if (b->type == B_DROPLIST) {
- wDropListSetIndex(b, element);
- } else {
- wlibTreeViewSetSelected(b, element);
- }
+ if (b->type == B_DROPLIST) {
+ wDropListSetIndex(b, element);
+ } else {
+ wlibTreeViewSetSelected(b, element);
+ }
- b->last = element;
- b->recursion--;
+ b->last = element;
+ b->recursion--;
}
/**
@@ -121,23 +121,23 @@ int
CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
gpointer data)
{
- wListItem_p id_p;
- struct listSearch *search = (struct listSearch *)data;
-
- gtk_tree_model_get(model,
- iter,
- LISTCOL_DATA,
- &id_p,
- -1);
-
- if (id_p && id_p->label && !strcmp(id_p->label, search->search)) {
- search->result = (char *)id_p->label;
- return TRUE;
- } else {
- search->result = NULL;
- search->row++;
- return FALSE;
- }
+ wListItem_p id_p;
+ struct listSearch *search = (struct listSearch *)data;
+
+ gtk_tree_model_get(model,
+ iter,
+ LISTCOL_DATA,
+ &id_p,
+ -1);
+
+ if (id_p && id_p->label && !strcmp(id_p->label, search->search)) {
+ search->result = (char *)id_p->label;
+ return TRUE;
+ } else {
+ search->result = NULL;
+ search->row++;
+ return FALSE;
+ }
}
/**
@@ -149,25 +149,25 @@ CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
*/
wIndex_t wListFindValue(
- wList_p b,
- const char * val)
+ wList_p b,
+ const char * val)
{
- struct listSearch thisSearch;
+ struct listSearch thisSearch;
- assert(b!=NULL);
- assert(b->listStore!=NULL);
+ assert(b!=NULL);
+ assert(b->listStore!=NULL);
- thisSearch.search = val;
- thisSearch.row = 0;
+ thisSearch.search = val;
+ thisSearch.row = 0;
- gtk_tree_model_foreach(GTK_TREE_MODEL(b->listStore), CompareListData,
- (void *)&thisSearch);
+ gtk_tree_model_foreach(GTK_TREE_MODEL(b->listStore), CompareListData,
+ (void *)&thisSearch);
- if (!thisSearch.result) {
- return -1;
- } else {
- return thisSearch.row;
- }
+ if (!thisSearch.result) {
+ return -1;
+ } else {
+ return thisSearch.row;
+ }
}
/**
@@ -178,13 +178,13 @@ wIndex_t wListFindValue(
*/
wIndex_t wListGetCount(
- wList_p b)
+ wList_p b)
{
- if (b->type == B_DROPLIST) {
- return wDropListGetCount(b);
- } else {
- return wTreeViewGetCount(b);
- }
+ if (b->type == B_DROPLIST) {
+ return wDropListGetCount(b);
+ } else {
+ return wTreeViewGetCount(b);
+ }
}
/**
@@ -196,18 +196,18 @@ wIndex_t wListGetCount(
*/
void * wListGetItemContext(
- wList_p b,
- wIndex_t inx)
+ wList_p b,
+ wIndex_t inx)
{
- if (inx < 0) {
- return NULL;
- }
-
- if (b->type == B_DROPLIST) {
- return wDropListGetItemContext(b, inx);
- } else {
- return wTreeViewGetItemContext(b, inx);
- }
+ if (inx < 0) {
+ return NULL;
+ }
+
+ if (b->type == B_DROPLIST) {
+ return wDropListGetItemContext(b, inx);
+ } else {
+ return wTreeViewGetItemContext(b, inx);
+ }
}
/**
@@ -221,57 +221,57 @@ void * wListGetItemContext(
*/
wIndex_t wListGetValues(
- wList_p bl,
- char * labelStr,
- int labelSize,
- void * * listDataRet,
- void * * itemDataRet)
+ wList_p bl,
+ char * labelStr,
+ int labelSize,
+ void * * listDataRet,
+ void * * itemDataRet)
{
- wListItem_p id_p;
- wIndex_t inx = bl->last;
- const char * entry_value = "";
- void * item_data = NULL;
-
- assert(bl != NULL);
- assert(bl->listStore != NULL);
-
- if (bl->type == B_DROPLIST && bl->editted) {
- entry_value = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(
- bl->widget))));
- item_data = NULL;
- inx = bl->last = -1;
- } else {
- //Make sure in range
- if (bl->last > bl->count-1) bl->last = bl->count-1;
- inx = bl->last;
-
-
- if (inx >= 0) {
- id_p = wlibListStoreGetContext(bl->listStore, inx);
-
- if (id_p==NULL) {
- fprintf(stderr, "wListGetValues - id_p == NULL\n");
- bl->last = -1;
- } else {
- entry_value = id_p->label;
- item_data = id_p->itemData;
- }
- }
- }
-
- if (labelStr) {
- strncpy(labelStr, entry_value, labelSize);
- }
-
- if (listDataRet) {
- *listDataRet = bl->data;
- }
-
- if (itemDataRet) {
- *itemDataRet = item_data;
- }
-
- return bl->last;
+ wListItem_p id_p;
+ wIndex_t inx = bl->last;
+ const char * entry_value = "";
+ void * item_data = NULL;
+
+ assert(bl != NULL);
+ assert(bl->listStore != NULL);
+
+ if (bl->type == B_DROPLIST && bl->editted) {
+ entry_value = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(
+ bl->widget))));
+ item_data = NULL;
+ inx = bl->last = -1;
+ } else {
+ //Make sure in range
+ if (bl->last > bl->count-1) { bl->last = bl->count-1; }
+ inx = bl->last;
+
+
+ if (inx >= 0) {
+ id_p = wlibListStoreGetContext(bl->listStore, inx);
+
+ if (id_p==NULL) {
+ fprintf(stderr, "wListGetValues - id_p == NULL\n");
+ bl->last = -1;
+ } else {
+ entry_value = id_p->label;
+ item_data = id_p->itemData;
+ }
+ }
+ }
+
+ if (labelStr) {
+ strncpy(labelStr, entry_value, labelSize);
+ }
+
+ if (listDataRet) {
+ *listDataRet = bl->data;
+ }
+
+ if (itemDataRet) {
+ *itemDataRet = item_data;
+ }
+
+ return bl->last;
}
/**
@@ -282,22 +282,22 @@ wIndex_t wListGetValues(
*/
wBool_t wListGetItemSelected(
- wList_p b,
- wIndex_t inx)
+ wList_p b,
+ wIndex_t inx)
{
- wListItem_p id_p;
+ wListItem_p id_p;
- if (inx < 0) {
- return FALSE;
- }
+ if (inx < 0) {
+ return FALSE;
+ }
- id_p = wlibListStoreGetContext(b->listStore, inx);
+ id_p = wlibListStoreGetContext(b->listStore, inx);
- if (id_p) {
- return id_p->selected;
- } else {
- return FALSE;
- }
+ if (id_p) {
+ return id_p->selected;
+ } else {
+ return FALSE;
+ }
}
/**
@@ -308,16 +308,16 @@ wBool_t wListGetItemSelected(
*/
wIndex_t wListGetSelectedCount(
- wList_p b)
+ wList_p b)
{
- wIndex_t selcnt, inx;
+ wIndex_t selcnt, inx;
- for (selcnt=inx=0; inx<b->count; inx++)
- if (wListGetItemSelected(b, inx)) {
- selcnt++;
- }
+ for (selcnt=inx=0; inx<b->count; inx++)
+ if (wListGetItemSelected(b, inx)) {
+ selcnt++;
+ }
- return selcnt;
+ return selcnt;
}
/**
@@ -329,26 +329,26 @@ wIndex_t wListGetSelectedCount(
void wListSelectAll(wList_p bl)
{
- wIndex_t inx;
- GtkTreeSelection *selection;
+ wIndex_t inx;
+ GtkTreeSelection *selection;
- assert(bl != NULL);
- // mark all items selected
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView));
- gtk_tree_selection_select_all(selection);
+ assert(bl != NULL);
+ // mark all items selected
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView));
+ gtk_tree_selection_select_all(selection);
- // and synchronize the internal data structures
- wListGetCount(bl);
+ // and synchronize the internal data structures
+ wListGetCount(bl);
- for (inx=0; inx<bl->count; inx++) {
- wListItem_p ldp;
+ for (inx=0; inx<bl->count; inx++) {
+ wListItem_p ldp;
- ldp = wlibListStoreGetContext(bl->listStore, inx);
+ ldp = wlibListStoreGetContext(bl->listStore, inx);
- if (ldp) {
- ldp->selected = TRUE;
- }
- }
+ if (ldp) {
+ ldp->selected = TRUE;
+ }
+ }
}
/**
@@ -363,25 +363,25 @@ void wListSelectAll(wList_p bl)
*/
wBool_t wListSetValues(
- wList_p b,
- wIndex_t row,
- const char * labelStr,
- wIcon_p bm,
- void *itemData)
+ wList_p b,
+ wIndex_t row,
+ const char * labelStr,
+ wIcon_p bm,
+ void *itemData)
{
- assert(b->listStore != NULL);
+ assert(b->listStore != NULL);
- b->recursion++;
+ b->recursion++;
- if (b->type == B_DROPLIST) {
- wDropListSetValues(b, row, labelStr, bm, itemData);
- } else {
- wlibListStoreUpdateValues(b->listStore, row, b->colCnt, (char *)labelStr, bm);
- }
+ if (b->type == B_DROPLIST) {
+ wDropListSetValues(b, row, labelStr, bm, itemData);
+ } else {
+ wlibListStoreUpdateValues(b->listStore, row, b->colCnt, (char *)labelStr, bm);
+ }
- b->recursion--;
- return TRUE;
+ b->recursion--;
+ return TRUE;
}
/**
@@ -391,34 +391,34 @@ wBool_t wListSetValues(
*/
void wListDelete(
- wList_p b,
- wIndex_t inx)
+ wList_p b,
+ wIndex_t inx)
{
- GtkTreeIter iter;
+ GtkTreeIter iter;
- assert(b->listStore != 0);
- assert(b->type != B_DROPLIST);
- b->recursion++;
+ assert(b->listStore != 0);
+ assert(b->type != B_DROPLIST);
+ b->recursion++;
- if (b->type == B_DROPLIST) {
- wNotice("Deleting from dropboxes is not implemented!", "Continue", NULL);
- } else {
- gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore),
- &iter,
- NULL,
- inx);
- gtk_list_store_remove(b->listStore, &iter);
+ if (b->type == B_DROPLIST) {
+ wNotice("Deleting from dropboxes is not implemented!", "Continue", NULL);
+ } else {
+ gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore),
+ &iter,
+ NULL,
+ inx);
+ gtk_list_store_remove(b->listStore, &iter);
- b->count--;
- }
+ b->count--;
+ }
- if (b->last == inx-1) b->last = -1;
- else if (b->last >= inx) b->last = -1;
+ if (b->last == inx-1) { b->last = -1; }
+ else if (b->last >= inx) { b->last = -1; }
- b->recursion--;
- return;
+ b->recursion--;
+ return;
}
/**
@@ -431,29 +431,29 @@ void wListDelete(
*/
int wListGetColumnWidths(
- wList_p bl,
- int colCnt,
- wWinPix_t * colWidths)
+ wList_p bl,
+ int colCnt,
+ wWinPix_t * colWidths)
{
- int inx;
+ int inx;
- if (bl->type != B_LIST) {
- return 0;
- }
+ if (bl->type != B_LIST) {
+ return 0;
+ }
- if (bl->colWidths == NULL) {
- return 0;
- }
+ if (bl->colWidths == NULL) {
+ return 0;
+ }
- for (inx=0; inx<colCnt; inx++) {
- if (inx < bl->colCnt) {
- colWidths[inx] = bl->colWidths[inx];
- } else {
- colWidths[inx] = 0;
- }
- }
+ for (inx=0; inx<colCnt; inx++) {
+ if (inx < bl->colCnt) {
+ colWidths[inx] = bl->colWidths[inx];
+ } else {
+ colWidths[inx] = 0;
+ }
+ }
- return bl->colCnt;
+ return bl->colCnt;
}
/**
@@ -467,45 +467,45 @@ int wListGetColumnWidths(
*/
wIndex_t wListAddValue(
- wList_p b,
- const char * labelStr,
- wIcon_p bm,
- void * itemData)
+ wList_p b,
+ const char * labelStr,
+ wIcon_p bm,
+ void * itemData)
{
- wListItem_p id_p;
+ wListItem_p id_p;
- assert(b != NULL);
+ assert(b != NULL);
- b->recursion++;
+ b->recursion++;
- id_p = (wListItem_p)g_malloc(sizeof *id_p);
- memset(id_p, 0, sizeof *id_p);
- id_p->itemData = itemData;
- id_p->active = TRUE;
+ id_p = (wListItem_p)g_malloc(sizeof *id_p);
+ memset(id_p, 0, sizeof *id_p);
+ id_p->itemData = itemData;
+ id_p->active = TRUE;
- if (labelStr == NULL) {
- labelStr = "";
- }
+ if (labelStr == NULL) {
+ labelStr = "";
+ }
- id_p->label = strdup(labelStr);
- id_p->listP = b;
+ id_p->label = strdup(labelStr);
+ id_p->listP = b;
- if (b->type == B_DROPLIST) {
- wDropListAddValue(b, (char *)labelStr, id_p);
- } else {
- wlibTreeViewAddRow(b, (char *)labelStr, bm, id_p);
- }
+ if (b->type == B_DROPLIST) {
+ wDropListAddValue(b, (char *)labelStr, id_p);
+ } else {
+ wlibTreeViewAddRow(b, (char *)labelStr, bm, id_p);
+ }
- //free(id_p->label);
+ //free(id_p->label);
- b->count++;
- b->recursion--;
+ b->count++;
+ b->recursion--;
- if (b->count == 1) {
- b->last = 0;
- }
+ if (b->count == 1) {
+ b->last = 0;
+ }
- return b->count-1;
+ return b->count-1;
}
@@ -519,14 +519,14 @@ wIndex_t wListAddValue(
void wListSetSize(wList_p bl, wWinPix_t w, wWinPix_t h)
{
- if (bl->type == B_DROPLIST) {
- gtk_widget_set_size_request(bl->widget, w, -1);
- } else {
- gtk_widget_set_size_request(bl->widget, w, h);
- }
-
- bl->w = w;
- bl->h = h;
+ if (bl->type == B_DROPLIST) {
+ gtk_widget_set_size_request(bl->widget, w, -1);
+ } else {
+ gtk_widget_set_size_request(bl->widget, w, h);
+ }
+
+ bl->w = w;
+ bl->h = h;
}
/**
@@ -540,20 +540,20 @@ void wListSetSize(wList_p bl, wWinPix_t w, wWinPix_t h)
*/
wList_p wComboListCreate(
- wWin_p parent, /* Parent window */
- wWinPix_t x, /* X-position */
- wWinPix_t y, /* Y-position */
- const char * helpStr, /* Help string */
- const char * labelStr, /* Label */
- long option, /* Options */
- long number, /* Number of displayed list entries */
- wWinPix_t width, /* Width */
- long *valueP, /* Selected index */
- wListCallBack_p action, /* Callback */
- void *data) /* Context */
+ wWin_p parent, /* Parent window */
+ wWinPix_t x, /* X-position */
+ wWinPix_t y, /* Y-position */
+ const char * helpStr, /* Help string */
+ const char * labelStr, /* Label */
+ long option, /* Options */
+ long number, /* Number of displayed list entries */
+ wWinPix_t width, /* Width */
+ long *valueP, /* Selected index */
+ wListCallBack_p action, /* Callback */
+ void *data) /* Context */
{
- wNotice("ComboLists are not implemented!", "Abort", NULL);
- abort();
+ wNotice("ComboLists are not implemented!", "Abort", NULL);
+ abort();
}
diff --git a/app/wlib/gtklib/liststore.c b/app/wlib/gtklib/liststore.c
index 088bf33..b1b0f8a 100644
--- a/app/wlib/gtklib/liststore.c
+++ b/app/wlib/gtklib/liststore.c
@@ -47,25 +47,25 @@
*/
wListItem_p wlibListItemGet(
- GtkListStore *ls,
- wIndex_t inx,
- GList ** childR)
+ GtkListStore *ls,
+ wIndex_t inx,
+ GList ** childR)
{
- wListItem_p id_p;
+ wListItem_p id_p;
- assert(ls != NULL);
+ assert(ls != NULL);
- if (childR) {
- *childR = NULL;
- }
+ if (childR) {
+ *childR = NULL;
+ }
- if (inx < 0) {
- return NULL;
- }
+ if (inx < 0) {
+ return NULL;
+ }
- id_p = wlibListStoreGetContext(ls, inx);
+ id_p = wlibListStoreGetContext(ls, inx);
- return id_p;
+ return id_p;
}
/**
@@ -79,33 +79,33 @@ wListItem_p wlibListItemGet(
void *
wlibListStoreGetContext(GtkListStore *ls, int inx)
{
- GtkTreeIter iter;
- gchar *string = NULL;
- gboolean result;
- gint childs;
-
- childs = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(ls),
- NULL);
-
- if (inx < childs) {
- result = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls),
- &iter,
- NULL,
- inx);
-
- if (result) {
- gtk_tree_model_get(GTK_TREE_MODEL(ls),
- &iter,
- LISTCOL_DATA,
- &string,
- -1);
- } else {
- printf("Invalid index %d for list!\n", inx);
-
- }
- }
-
- return (string);
+ GtkTreeIter iter;
+ gchar *string = NULL;
+ gboolean result;
+ gint childs;
+
+ childs = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(ls),
+ NULL);
+
+ if (inx < childs) {
+ result = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls),
+ &iter,
+ NULL,
+ inx);
+
+ if (result) {
+ gtk_tree_model_get(GTK_TREE_MODEL(ls),
+ &iter,
+ LISTCOL_DATA,
+ &string,
+ -1);
+ } else {
+ printf("Invalid index %d for list!\n", inx);
+
+ }
+ }
+
+ return (string);
}
@@ -119,21 +119,22 @@ wlibListStoreGetContext(GtkListStore *ls, int inx)
void
wlibListStoreClear(GtkListStore *listStore)
{
- wListItem_p id_p;
- int i = 0;
+ wListItem_p id_p;
+ int i = 0;
- assert(listStore != NULL);
+ assert(listStore != NULL);
- id_p = wlibListStoreGetContext(listStore, i++);
+ id_p = wlibListStoreGetContext(listStore, i++);
- while (id_p) {
- if (id_p->label)
- g_free(id_p->label);
- g_free(id_p);
- id_p = wlibListStoreGetContext(listStore, i++);
- }
+ while (id_p) {
+ if (id_p->label) {
+ g_free(id_p->label);
+ }
+ g_free(id_p);
+ id_p = wlibListStoreGetContext(listStore, i++);
+ }
- gtk_list_store_clear(listStore);
+ gtk_list_store_clear(listStore);
}
/**
@@ -148,23 +149,23 @@ wlibListStoreClear(GtkListStore *listStore)
GtkListStore *
wlibNewListStore(int colCnt)
{
- GtkListStore *ls;
- GType *colTypes;
- int i;
+ GtkListStore *ls;
+ GType *colTypes;
+ int i;
- /* create the list store, using strings for all columns */
- colTypes = g_malloc(sizeof(GType) * (colCnt + LISTCOL_TEXT));
- colTypes[ LISTCOL_BITMAP ] = GDK_TYPE_PIXBUF;
- colTypes[ LISTCOL_DATA ] = G_TYPE_POINTER;
+ /* create the list store, using strings for all columns */
+ colTypes = g_malloc(sizeof(GType) * (colCnt + LISTCOL_TEXT));
+ colTypes[ LISTCOL_BITMAP ] = GDK_TYPE_PIXBUF;
+ colTypes[ LISTCOL_DATA ] = G_TYPE_POINTER;
- for (i = 0; i < colCnt; i++) {
- colTypes[ LISTCOL_TEXT + i ] = G_TYPE_STRING;
- }
+ for (i = 0; i < colCnt; i++) {
+ colTypes[ LISTCOL_TEXT + i ] = G_TYPE_STRING;
+ }
- ls = gtk_list_store_newv(colCnt + LISTCOL_TEXT, colTypes);
- g_free(colTypes);
+ ls = gtk_list_store_newv(colCnt + LISTCOL_TEXT, colTypes);
+ g_free(colTypes);
- return (ls);
+ return (ls);
}
/**
@@ -179,26 +180,26 @@ wlibNewListStore(int colCnt)
static int
wlibListStoreUpdateIter(GtkListStore *ls, GtkTreeIter *iter, char *labels)
{
- char *convertedLabels;
- char *text;
- char *start;
- int current = 0;
-
- convertedLabels = strdup(wlibConvertInput(labels));
- start = convertedLabels;
-
- while ((text = strchr(start, '\t')) != NULL) {
- *text = '\0';
- gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1);
- start = text + 1;
- current++;
- }
-
- /* add the last piece of the string */
- gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1);
-
- free(convertedLabels);
- return (current+1);
+ char *convertedLabels;
+ char *text;
+ char *start;
+ int current = 0;
+
+ convertedLabels = strdup(wlibConvertInput(labels));
+ start = convertedLabels;
+
+ while ((text = strchr(start, '\t')) != NULL) {
+ *text = '\0';
+ gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1);
+ start = text + 1;
+ current++;
+ }
+
+ /* add the last piece of the string */
+ gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1);
+
+ free(convertedLabels);
+ return (current+1);
}
/**
@@ -213,9 +214,9 @@ wlibListStoreUpdateIter(GtkListStore *ls, GtkTreeIter *iter, char *labels)
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);
+ 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
@@ -230,19 +231,19 @@ int
wlibListStoreAddData(GtkListStore *ls, GdkPixbuf *pixbuf, int cols,
wListItem_p id)
{
- GtkTreeIter iter;
- int count;
+ GtkTreeIter iter;
+ int count;
- gtk_list_store_append(ls, &iter);
- gtk_list_store_set(ls, &iter, LISTCOL_DATA, id, -1);
+ gtk_list_store_append(ls, &iter);
+ gtk_list_store_set(ls, &iter, LISTCOL_DATA, id, -1);
- if (pixbuf) {
- wlibListStoreSetPixbuf(ls, &iter, pixbuf);
- }
+ if (pixbuf) {
+ wlibListStoreSetPixbuf(ls, &iter, pixbuf);
+ }
- count = wlibListStoreUpdateIter(ls, &iter, (char *)id->label);
+ count = wlibListStoreUpdateIter(ls, &iter, (char *)id->label);
- return (count);
+ return (count);
}
/**
@@ -261,23 +262,23 @@ int
wlibListStoreUpdateValues(GtkListStore *ls, int row, int cols, char *labels,
wIcon_p bm)
{
- GtkTreeIter iter;
- int count;
+ GtkTreeIter iter;
+ int count;
- gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls),
- &iter,
- NULL,
- row);
+ gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls),
+ &iter,
+ NULL,
+ row);
- count = wlibListStoreUpdateIter(ls, &iter, labels);
+ count = wlibListStoreUpdateIter(ls, &iter, labels);
- if (bm) {
- GdkPixbuf *pixbuf;
+ if (bm) {
+ GdkPixbuf *pixbuf;
- pixbuf = wlibMakePixbuf(bm);
- wlibListStoreSetPixbuf(ls, &iter, pixbuf);
- }
+ pixbuf = wlibMakePixbuf(bm);
+ wlibListStoreSetPixbuf(ls, &iter, pixbuf);
+ }
- return (count);
+ return (count);
}
diff --git a/app/wlib/gtklib/main.c b/app/wlib/gtklib/main.c
index 470f17b..7022a0a 100644
--- a/app/wlib/gtklib/main.c
+++ b/app/wlib/gtklib/main.c
@@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -46,10 +46,10 @@ char *wExecutableName;
* Initialize the application name for later use
*
* \param _appName IN Name of application
- * \return
+ * \return
*/
-
-void
+
+void
wInitAppName(char *_appName)
{
appName = g_strdup( _appName );
@@ -59,7 +59,7 @@ char *
wlibGetAppName()
{
return( appName );
-}
+}
/*
*******************************************************************************
@@ -76,17 +76,19 @@ int main( int argc, char *argv[] )
wWin_p win;
const char *ld;
- if ( getenv( "GTKLIB_NOLOCALE" ) == 0 )
+ if ( getenv( "GTKLIB_NOLOCALE" ) == 0 ) {
setlocale( LC_ALL, "en_US" );
+ }
gtk_init( &argc, &argv );
- if ((win=wMain( argc, argv )) == NULL)
+ if ((win=wMain( argc, argv )) == NULL) {
exit(1);
- wExecutableName = argv[ 0 ];
+ }
+ wExecutableName = argv[ 0 ];
ld = wGetAppLibDir();
-
+
#ifdef WINDOWS
-
+
#else
// set up help search path on unix boxes
if (ld != NULL) {
@@ -94,14 +96,16 @@ int main( int argc, char *argv[] )
const char *hp;
sprintf( buff, "HELPPATH=/usr/lib/help:%s:", ld );
- if ( (hp = getenv("HELPPATH")) != NULL )
+ if ( (hp = getenv("HELPPATH")) != NULL ) {
strcat( buff, hp );
+ }
putenv( buff );
}
#endif
-
- if (!win->shown)
+
+ if (!win->shown) {
wWinShow( win, TRUE );
+ }
gtk_main();
exit(0);
diff --git a/app/wlib/gtklib/menu.c b/app/wlib/gtklib/menu.c
index 754f88f..8646f15 100644
--- a/app/wlib/gtklib/menu.c
+++ b/app/wlib/gtklib/menu.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -50,28 +50,29 @@
typedef enum { M_MENU, M_SEPARATOR, M_PUSH, M_LIST, M_LISTITEM, M_TOGGLE, M_RADIO } mtype_e;
typedef enum { MM_BUTT, MM_MENU, MM_BAR, MM_POPUP } mmtype_e;
-typedef struct{ mtype_e mtype; /**< menu entry type */
- GtkWidget *menu_item;
- wMenu_p parentMenu;
- int recursion; /**< recursion counter */
- } MOBJ_COMMON; /**< menu item specific data */
-
-
+typedef struct {
+ mtype_e mtype; /**< menu entry type */
+ GtkWidget *menu_item;
+ wMenu_p parentMenu;
+ int recursion; /**< recursion counter */
+} MOBJ_COMMON; /**< menu item specific data */
+
+
struct wMenuItem_t {
WOBJ_COMMON
MOBJ_COMMON m;
- };
+};
typedef struct wMenuItem_t * wMenuItem_p;
-// a few macros to make access to members easier
-//#define PTR2M( ptr ) ((ptr)->m)
-#define MMENUITEM( ptr ) (((ptr)->m).menu_item)
+// a few macros to make access to members easier
+//#define PTR2M( ptr ) ((ptr)->m)
+#define MMENUITEM( ptr ) (((ptr)->m).menu_item)
#define MPARENT( ptr ) (((ptr)->m).parentMenu)
#define MITEMTYPE( ptr ) (((ptr)->m).mtype)
-#define MRECURSION( ptr ) (((ptr)->m).recursion)
-
-
+#define MRECURSION( ptr ) (((ptr)->m).recursion)
+
+
struct wMenu_t {
WOBJ_COMMON
MOBJ_COMMON m;
@@ -83,21 +84,21 @@ struct wMenu_t {
void * traceData;
GtkLabel * labelG;
GtkWidget * imageG;
- };
+};
struct wMenuPush_t {
WOBJ_COMMON
MOBJ_COMMON m;
wMenuCallBack_p action;
wBool_t enabled;
- };
+};
struct wMenuRadio_t {
WOBJ_COMMON
MOBJ_COMMON m;
wMenuCallBack_p action;
wBool_t enabled;
- };
+};
struct wMenuList_t {
WOBJ_COMMON
@@ -105,44 +106,45 @@ struct wMenuList_t {
int max;
int count;
wMenuListCallBack_p action;
- };
+};
struct wMenuListItem_t {
WOBJ_COMMON
MOBJ_COMMON m;
wMenuList_p mlist;
- };
+};
typedef struct wMenuListItem_t * wMenuListItem_p;
-
+
struct wMenuToggle_t {
WOBJ_COMMON
MOBJ_COMMON m;
wMenuCallBack_p action;
wBool_t enabled;
wBool_t set;
- };
+};
/*-----------------------------------------------------------------*/
-
+
/**
* Handle activate event for menu items.
*
* \param widget IN widget that emitted the signal
* \param value IN application data
- * \return
+ * \return
*/
-
+
static void pushMenuItem(
- GtkWidget * widget,
- gpointer value )
+ GtkWidget * widget,
+ gpointer value )
{
wMenuItem_p m = (wMenuItem_p)value;
wMenuToggle_p mt;
- if (MRECURSION( m ))
+ if (MRECURSION( m )) {
return;
+ }
switch MITEMTYPE( m ) {
case M_PUSH:
@@ -155,9 +157,10 @@ static void pushMenuItem(
break;
case M_RADIO:
/* NOTE: action is only called when radio button is activated, not when deactivated */
- if( gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget ) == TRUE )
+ if( gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget ) == TRUE ) {
((wMenuRadio_p)m)->action( ((wMenuRadio_p)m)->data );
- break;
+ }
+ break;
case M_MENU:
return;
default:
@@ -167,57 +170,63 @@ static void pushMenuItem(
if( MPARENT(m)->traceFunc ) {
MPARENT(m)->traceFunc( MPARENT( m ), m->labelStr, MPARENT(m)->traceData );
}
-}
+}
/**
* Create a new menu element, add to the parent menu and to help
*
* \param m IN parent menu
* \param mtype IN type of new entry
- * \param helpStr IN help topic
+ * \param helpStr IN help topic
* \param labelStr IN display label
* \param size IN size of additional data?
* \return the newly created menu element
*/
static wMenuItem_p createMenuItem(
- wMenu_p m,
- mtype_e mtype,
- const char * helpStr,
- const char * labelStr,
- int size )
+ wMenu_p m,
+ mtype_e mtype,
+ const char * helpStr,
+ const char * labelStr,
+ int size )
{
wMenuItem_p mi;
mi = (wMenuItem_p)wlibAlloc( NULL, B_MENUITEM, 0, 0, labelStr, size, NULL );
MITEMTYPE( mi )= mtype;
-
+
switch ( mtype ) {
case M_LIST:
- MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput(mi->labelStr)); // NULL; //PTR2M(m).menu_item
+ MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput(
+ mi->labelStr)); // NULL; //PTR2M(m).menu_item
break;
case M_SEPARATOR:
MMENUITEM( mi ) = gtk_separator_menu_item_new();
break;
case M_TOGGLE:
- MMENUITEM( mi ) = gtk_check_menu_item_new_with_mnemonic(wlibConvertInput(mi->labelStr));
+ MMENUITEM( mi ) = gtk_check_menu_item_new_with_mnemonic(wlibConvertInput(
+ mi->labelStr));
break;
case M_RADIO:
- MMENUITEM( mi ) = gtk_radio_menu_item_new_with_mnemonic(m->radioGroup, wlibConvertInput(mi->labelStr));
- m->radioGroup = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (MMENUITEM( mi )));
- break;
+ MMENUITEM( mi ) = gtk_radio_menu_item_new_with_mnemonic(m->radioGroup,
+ wlibConvertInput(mi->labelStr));
+ m->radioGroup = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (MMENUITEM(
+ mi )));
+ break;
default:
- MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput(mi->labelStr));
+ MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput(
+ mi->labelStr));
break;
}
if (MMENUITEM( mi )) {
- if (m)
+ if (m) {
gtk_menu_shell_append( (GtkMenuShell *)(m->menu), MMENUITEM( mi ) );
+ }
g_signal_connect( GTK_OBJECT(MMENUITEM( mi )), "activate",
- G_CALLBACK(pushMenuItem), mi );
- gtk_widget_show(MMENUITEM( mi ));
+ G_CALLBACK(pushMenuItem), mi );
+ gtk_widget_show(MMENUITEM( mi ));
}
-
+
// this is a link list of all menu items belonging to a specific menu
// is used in automatic processing (macro)??
if (m) {
@@ -229,8 +238,8 @@ static wMenuItem_p createMenuItem(
m->last = mi;
}
mi->next = NULL;
-
-
+
+
if (helpStr != NULL) {
wlibAddHelpString( MMENUITEM( mi ), helpStr );
}
@@ -240,13 +249,14 @@ static wMenuItem_p createMenuItem(
/**
* 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 )
+static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item,
+ int acclKey )
{
int mask;
static GtkAccelGroup * accel_alpha_group = NULL;
@@ -267,10 +277,10 @@ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int a
gtk_window_add_accel_group(GTK_WINDOW(gtkMainW->gtkwin), accel_nonalpha_group );
gtk_accelerator_set_default_mod_mask( oldmods );
}
-
+
mask = 0;
if (acclKey) {
-
+
if (acclKey&WALT) {
mask |= GDK_MOD1_MASK;
}
@@ -305,38 +315,38 @@ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int a
mask |= GDK_CONTROL_MASK;
}
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 );
+ (isalpha(acclKey&0xFF)?accel_alpha_group:accel_nonalpha_group),
+ toupper(acclKey&0xFF), mask, GTK_ACCEL_VISIBLE|GTK_ACCEL_LOCKED );
}
}
/*-----------------------------------------------------------------*/
/**
- * Create a radio button as a menu entry
+ * Create a radio button as a menu entry
*
* \param m IN menu to be extended
* \param helpStr IN reference into help
* \param labelStr IN text for entry
* \param acclKey IN accelerator key to add
- * \param action IN callback function
+ * \param action IN callback function
* \param data IN application data
* \param helpStr IN
* \return menu entry
*/
wMenuRadio_p wMenuRadioCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wMenuCallBack_p action,
- void *data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wMenuCallBack_p action,
+ void *data )
{
wMenuRadio_p mi;
mi = (wMenuRadio_p)createMenuItem( m, M_RADIO, helpStr, labelStr, sizeof *mi );
//~ if (m->mmtype == MM_POPUP && !testMenuPopup)
- //~ return mi;
+ //~ return mi;
setAcclKey( m->parent, m->menu, MMENUITEM( mi ), acclKey );
mi->action = action;
mi->data = data;
@@ -351,37 +361,38 @@ wMenuRadio_p wMenuRadioCreate(
* \return
*/
-void wMenuRadioSetActive(
- wMenuRadio_p mi )
+void wMenuRadioSetActive(
+ wMenuRadio_p mi )
{
- gtk_check_menu_item_set_active( (GtkCheckMenuItem *)MMENUITEM(mi), TRUE );
-}
+ gtk_check_menu_item_set_active( (GtkCheckMenuItem *)MMENUITEM(mi), TRUE );
+}
/*-----------------------------------------------------------------*/
/**
- * Create a menu entry
+ * Create a menu entry
*
* \param m IN menu to be extended
* \param helpStr IN reference into help
* \param labelStr IN text for entry
* \param acclKey IN acceleratoor key to add
- * \param action IN callback function
+ * \param action IN callback function
* \param data IN application data
* \return menu entry
*/
wMenuPush_p wMenuPushCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wMenuCallBack_p action,
- void *data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wMenuCallBack_p action,
+ void *data )
{
wMenuPush_p mi;
- mi = (wMenuPush_p)createMenuItem( m, M_PUSH, helpStr, labelStr, sizeof( struct wMenuPush_t ));
+ mi = (wMenuPush_p)createMenuItem( m, M_PUSH, helpStr, labelStr,
+ sizeof( struct wMenuPush_t ));
setAcclKey( m->parent, m->menu, MMENUITEM( mi ), acclKey );
@@ -395,13 +406,13 @@ wMenuPush_p wMenuPushCreate(
* Enable menu entry
*
* \param mi IN menu entry
- * \param enable IN new state
+ * \param enable IN new state
* \return
*/
void wMenuPushEnable(
- wMenuPush_p mi,
- wBool_t enable )
+ wMenuPush_p mi,
+ wBool_t enable )
{
mi->enabled = enable;
gtk_widget_set_sensitive( GTK_WIDGET(MMENUITEM( mi )), enable );
@@ -419,12 +430,13 @@ void wMenuPushEnable(
*/
wMenu_p wMenuMenuCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr )
{
wMenu_p mi;
- mi = (wMenu_p)createMenuItem( m, M_MENU, helpStr, labelStr, sizeof( struct wMenu_t ));
+ mi = (wMenu_p)createMenuItem( m, M_MENU, helpStr, labelStr,
+ sizeof( struct wMenu_t ));
mi->mmtype = MM_MENU;
mi->menu = gtk_menu_new();
@@ -442,7 +454,7 @@ wMenu_p wMenuMenuCreate(
*/
void wMenuSeparatorCreate(
- wMenu_p m )
+ wMenu_p m )
{
createMenuItem( m, M_SEPARATOR, NULL, "", sizeof( struct wMenuItem_t ));
}
@@ -464,46 +476,48 @@ int getMlistOrigin( wMenuList_p ml, GList **pChildren )
int count = 0;
int found = -1;
GtkWidget *mitem = MMENUITEM( ml );
-
+
*pChildren = gtk_container_get_children( GTK_CONTAINER( MPARENT( ml )->menu ));
- if( !*pChildren )
+ if( !*pChildren ) {
return( -1 );
-
+ }
+
while( (mi = g_list_nth_data( *pChildren, count ))) {
if( mi == mitem ) {
found = TRUE;
break;
- }
- else {
+ } else {
count++;
- }
+ }
}
-
- if( found )
+
+ if( found ) {
return( count );
- else
+ } else {
return( -1 );
+ }
}
/**
- * Signal handler for clicking onto a menu list item.
+ * Signal handler for clicking onto a menu list item.
* Parameters are the GtkWidget as expected and the pointer to the MenuListItem
*
* \param widget IN the GtkWidget
- * \param value IN the menu list item
+ * \param value IN the menu list item
* \return
*/
static void pushMenuList(
- GtkWidget * widget,
- gpointer value )
+ GtkWidget * widget,
+ gpointer value )
{
// pointer to the list item
wMenuListItem_p ml = (wMenuListItem_p)value;
- if (MRECURSION( ml ))
+ if (MRECURSION( ml )) {
return;
-
+ }
+
if (ml->mlist->count <= 0) {
// this should never happen
fprintf( stderr, "pushMenuItem: empty list\n" );
@@ -514,31 +528,32 @@ static void pushMenuList(
const char * itemLabel;
itemLabel = gtk_menu_item_get_label( GTK_MENU_ITEM( widget ));
-
- ml->mlist->action( 0, itemLabel, ml->data );
+
+ ml->mlist->action( 0, itemLabel, ml->data );
return;
}
fprintf( stderr, "pushMenuItem: item (%lx) not found\n", (long)widget );
}
/**
- * Create a list menu entry
+ * Create a list menu entry
*
* \param m IN menu to be extended
* \param helpStr IN reference into help
* \param max IN maximum number of elements
- * \param action IN callback function
+ * \param action IN callback function
* \return menu entry
*/
wMenuList_p wMenuListCreate(
- wMenu_p m,
- const char * helpStr,
- int max,
- wMenuListCallBack_p action )
+ wMenu_p m,
+ const char * helpStr,
+ int max,
+ wMenuListCallBack_p action )
{
wMenuList_p mi;
- mi = (wMenuList_p)createMenuItem( m, M_LIST, NULL, _("<Empty List>"), sizeof( struct wMenuList_t ));
+ mi = (wMenuList_p)createMenuItem( m, M_LIST, NULL, _("<Empty List>"),
+ sizeof( struct wMenuList_t ));
gtk_widget_set_sensitive( GTK_WIDGET(MMENUITEM( mi )), FALSE );
mi->next = NULL;
mi->count = 0;
@@ -551,90 +566,96 @@ wMenuList_p wMenuListCreate(
/**
* Add a new item to a list of menu entries
- * The placeholder for the list is looked up. Then the new item is added immediately
+ * The placeholder for the list is looked up. Then the new item is added immediately
* behind it. In case the maximum number of items is reached the last item is removed.
*
* \param ml IN handle for the menu list - the placeholder item
* \param index IN position of new menu item
- * \param labelStr IN the menu label for the new item
+ * \param labelStr IN the menu label for the new item
* \param data IN application data for the new item
- * \return
+ * \return
*/
void wMenuListAdd(
- wMenuList_p ml,
- int index,
- const char * labelStr,
- const void * data )
+ wMenuList_p ml,
+ int index,
+ const char * labelStr,
+ const void * data )
{
int i = 0;
GList * children;
i = getMlistOrigin( ml, &children );
-
+
if( i > -1 ) {
wMenuListItem_p mi;
// we're adding an item, so hide the default placeholder
gtk_widget_hide( MMENUITEM( ml ));
-
+
// delete an earlier entry with the same label
- wMenuListDelete( ml, labelStr );
+ wMenuListDelete( ml, labelStr );
// a new item
ml->count ++;
-
+
// is there a maximum number of items set and reached with the new item?
if(( ml->max != -1 ) && ( ml->count > ml-> max )) {
wMenuListItem_p mold;
GtkWidget * item;
-
+
// get the last item in the list
item = g_list_nth_data( children, i + ml->max );
// get the pointer to the data structure
mold = g_object_get_data( G_OBJECT( item ), WLISTITEM );
// kill the menu entry
gtk_widget_destroy( item );
- // free the data
+ // free the data
free( (void *)mold->labelStr );
free( (void *)mold );
ml->count--;
- }
-
+ }
+
// create the new menu item and initialize the data fields
- mi = (wMenuListItem_p)wlibAlloc( NULL, B_MENUITEM, 0, 0, labelStr, sizeof( struct wMenuListItem_t ), NULL );
+ mi = (wMenuListItem_p)wlibAlloc( NULL, B_MENUITEM, 0, 0, labelStr,
+ sizeof( struct wMenuListItem_t ), NULL );
MITEMTYPE( mi ) = M_LISTITEM;
MMENUITEM( mi ) = gtk_menu_item_new_with_label(wlibConvertInput(mi->labelStr));
mi->data = (void *)data;
mi->mlist = ml;
g_object_set_data( G_OBJECT(MMENUITEM( mi )), WLISTITEM, mi );
-
+
// add the item to the menu
- if ( index < 0 )
+ if ( index < 0 ) {
index = 0;
- if ( index >= ml->count )
+ }
+ if ( index >= ml->count ) {
index = ml->count - 1;
- gtk_menu_shell_insert((GtkMenuShell *)(MPARENT( ml )->menu), MMENUITEM( mi ), i + index + 1 );
- g_signal_connect( GTK_OBJECT(MMENUITEM( mi )), "activate", G_CALLBACK(pushMenuList), mi );
-
+ }
+ gtk_menu_shell_insert((GtkMenuShell *)(MPARENT( ml )->menu), MMENUITEM( mi ),
+ i + index + 1 );
+ g_signal_connect( GTK_OBJECT(MMENUITEM( mi )), "activate",
+ G_CALLBACK(pushMenuList), mi );
+
gtk_widget_show(MMENUITEM( mi ));
}
-
- if( children )
+
+ if( children ) {
g_list_free( children );
+ }
}
/**
* Remove the menu entry identified by a given label.
*
* \param ml IN menu list
- * \param labelStr IN label string of item
+ * \param labelStr IN label string of item
*/
void wMenuListDelete(
- wMenuList_p ml,
- const char * labelStr )
+ wMenuList_p ml,
+ const char * labelStr )
{
int i;
int found = FALSE;
@@ -642,30 +663,31 @@ void wMenuListDelete(
// find the placeholder for the list in the menu
i = getMlistOrigin( ml, &children );
-
+
if( i > -1 ) {
int origin;
- GtkWidget * item;
+ GtkWidget * item;
char * labelStrConverted;
-
+
// starting from the placeholder, find the menu item with the correct text
found = FALSE;
labelStrConverted = wlibConvertInput( labelStr );
origin = i;
-
+
// get menu item
// get label of item
// compare items
// if identical, leave loop
while( i <= origin + ml->count && !found ) {
const char * itemLabel;
-
+
item = g_list_nth_data( children, i );
itemLabel = gtk_menu_item_get_label( GTK_MENU_ITEM( item ));
- if( !g_utf8_collate (itemLabel, labelStrConverted ))
+ if( !g_utf8_collate (itemLabel, labelStrConverted )) {
found = TRUE;
- else
+ } else {
i++;
+ }
}
if( found ) {
wMenuListItem_p mold;
@@ -673,45 +695,47 @@ void wMenuListDelete(
mold = g_object_get_data( G_OBJECT( item ), WLISTITEM );
// kill the menu entry
gtk_widget_destroy( item );
- // free the data
+ // free the data
free( (void *)mold->labelStr );
free( (void *)mold );
- ml->count--;
+ ml->count--;
}
- }
-
- if( children )
+ }
+
+ if( children ) {
g_list_free( children );
+ }
}
/**
* Get the label and the application data of a specific menu list item
*
- * \param ml IN menu list
+ * \param ml IN menu list
* \param index IN item within list
* \param data OUT application data
* \return item label
*/
-const char *
+const char *
wMenuListGet( wMenuList_p ml, int index, void ** data )
{
int i;
GList * children;
const char * itemLabel = NULL;
-
+
// check whether index is in range, if not return immediately
if ( index >= ml->count || ml->count <= 0 ) {
- if (data)
+ if (data) {
*data = NULL;
+ }
return NULL;
}
-
+
// find the placeholder for the list in the menu
i = getMlistOrigin( ml, &children );
-
+
if( i > -1 ) {
GtkWidget * item;
wMenuListItem_p mold;
@@ -721,10 +745,11 @@ wMenuListGet( wMenuList_p ml, int index, void ** data )
mold = g_object_get_data( G_OBJECT( GTK_MENU_ITEM( item ) ), WLISTITEM );
*data = mold->data;
}
-
- if( children )
+
+ if( children ) {
g_list_free( children );
-
+ }
+
return itemLabel;
}
@@ -735,16 +760,17 @@ wMenuListGet( wMenuList_p ml, int index, void ** data )
*/
void wMenuListClear(
- wMenuList_p ml )
+ wMenuList_p ml )
{
int origin;
GList * children;
- if (ml->count == 0)
+ if (ml->count == 0) {
return;
+ }
origin = getMlistOrigin( ml, &children );
-
+
if( origin > -1 ) {
int i;
@@ -752,23 +778,24 @@ void wMenuListClear(
while( i < origin + ml->count ) {
wMenuListItem_p mold;
GtkWidget * item;
-
+
item = g_list_nth_data( children, i + 1 );
mold = g_object_get_data( G_OBJECT( item ), WLISTITEM );
// kill the menu entry
gtk_widget_destroy( item );
- // free the data
+ // free the data
free( (void *)mold->labelStr );
free( (void *)mold );
i++;
- }
- }
+ }
+ }
ml->count = 0;
gtk_widget_show( MMENUITEM( ml ));
-
- if( children )
+
+ if( children ) {
g_list_free( children );
+ }
}
/*-----------------------------------------------------------------*/
/**
@@ -779,30 +806,31 @@ void wMenuListClear(
* \param labelStr IN text for entry
* \param acclKey IN acceleratoor key to add
* \param set IN initial state
- * \param action IN callback function
+ * \param action IN callback function
* \param data IN application data
* \return menu entry
*/
wMenuToggle_p wMenuToggleCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wBool_t set,
- wMenuCallBack_p action,
- void * data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wBool_t set,
+ wMenuCallBack_p action,
+ void * data )
{
wMenuToggle_p mt;
- mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, sizeof( struct wMenuToggle_t ));
+ mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr,
+ sizeof( struct wMenuToggle_t ));
setAcclKey( m->parent, m->menu, MMENUITEM( mt ), acclKey );
mt->action = action;
mt->data = data;
mt->enabled = TRUE;
MPARENT( mt ) = m;
wMenuToggleSet( mt, set );
-
+
return mt;
}
@@ -814,7 +842,7 @@ wMenuToggle_p wMenuToggleCreate(
*/
wBool_t wMenuToggleGet(
- wMenuToggle_p mt )
+ wMenuToggle_p mt )
{
return mt->set;
}
@@ -828,11 +856,11 @@ wBool_t wMenuToggleGet(
*/
wBool_t wMenuToggleSet(
- wMenuToggle_p mt,
- wBool_t set )
+ wMenuToggle_p mt,
+ wBool_t set )
{
wBool_t rc;
- if (mt==NULL) return 0;
+ if (mt==NULL) { return 0; }
MRECURSION( mt )++;
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(MMENUITEM( mt )), set );
MRECURSION( mt )--;
@@ -845,13 +873,13 @@ wBool_t wMenuToggleSet(
* Enable menu entry containing a check box
*
* \param mi IN menu entry
- * \param enable IN new state
+ * \param enable IN new state
* \return
*/
void wMenuToggleEnable(
- wMenuToggle_p mt,
- wBool_t enable )
+ wMenuToggle_p mt,
+ wBool_t enable )
{
mt->enabled = enable;
}
@@ -860,29 +888,30 @@ void wMenuToggleEnable(
/*-----------------------------------------------------------------*/
/**
- * Set the text for a menu
+ * Set the text for a menu
*
* \param m IN menu entry
* \param labelStr IN new text
* \return
*/
-void wMenuSetLabel( wMenu_p m, const char * labelStr) {
+void wMenuSetLabel( wMenu_p m, const char * labelStr)
+{
wlibSetLabel( m->widget, m->option, labelStr, &m->labelG, &m->imageG );
}
/**
- * Signal handler for menu items. Parameters are the GtkWidget as
+ * Signal handler for menu items. Parameters are the GtkWidget as
* expected and the pointer to the MenuListItem
*
* \param widget IN the GtkWidget
- * \param value IN the menu list item
+ * \param value IN the menu list item
* \return
*/
static gint pushMenu(
- GtkWidget * widget,
- wMenu_p m )
+ GtkWidget * widget,
+ wMenu_p m )
{
gtk_menu_popup( GTK_MENU(m->menu), NULL, NULL, NULL, NULL, 0, 0 );
/* Tell calling code that we have handled this event; the buck
@@ -903,12 +932,12 @@ static gint pushMenu(
*/
wMenu_p wMenuCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option )
{
wMenu_p m;
m = wlibAlloc( parent, B_MENU, x, y, labelStr, sizeof( struct wMenu_t ), NULL );
@@ -920,12 +949,12 @@ wMenu_p wMenuCreate(
m->widget = gtk_button_new();
g_signal_connect (GTK_OBJECT(m->widget), "clicked",
- G_CALLBACK(pushMenu), m );
+ G_CALLBACK(pushMenu), m );
m->menu = gtk_menu_new();
wMenuSetLabel( m, labelStr );
-
+
gtk_fixed_put( GTK_FIXED(parent->widget), m->widget, m->realX, m->realY );
wlibControlGetSize( (wControl_p)m );
if ( m->w < 80 && (m->option&BO_ICON)==0) {
@@ -939,27 +968,27 @@ wMenu_p wMenuCreate(
}
/**
- * Add a drop-down menu to the menu bar.
+ * Add a drop-down menu to the menu bar.
*
- * \param w IN main window handle
+ * \param w IN main window handle
* \param helpStr IN unused (should be help topic )
- * \param labelStr IN label for the drop-down menu
+ * \param labelStr IN label for the drop-down menu
* \return pointer to the created drop-down menu
*/
wMenu_p wMenuBarAdd(
- wWin_p w,
- const char * helpStr,
- const char * labelStr )
+ wWin_p w,
+ const char * helpStr,
+ const char * labelStr )
{
wMenu_p m;
GtkWidget * menuItem;
-
+
m = wlibAlloc( w, B_MENU, 0, 0, labelStr, sizeof( struct wMenu_t ), NULL );
m->mmtype = MM_BAR;
m->realX = 0;
m->realY = 0;
-
+
menuItem = gtk_menu_item_new_with_mnemonic( wlibConvertInput(m->labelStr) );
m->menu = gtk_menu_new();
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), m->menu );
@@ -968,10 +997,10 @@ wMenu_p wMenuBarAdd(
m->w = 0;
m->h = 0;
-
+
/* TODO: why is help not supported here? */
/*gtkAddHelpString( m->panel_item, helpStr );*/
-
+
return m;
}
@@ -982,13 +1011,13 @@ wMenu_p wMenuBarAdd(
* Create a popup menu (context menu)
*
* \param w IN parent window
- * \param labelStr IN label
+ * \param labelStr IN label
* \return the created menu
*/
wMenu_p wMenuPopupCreate(
- wWin_p w,
- const char * labelStr )
+ wWin_p w,
+ const char * labelStr )
{
wMenu_p b;
b = wlibAlloc( w, B_MENU, 0, 0, labelStr, sizeof *b, NULL );
@@ -999,10 +1028,11 @@ wMenu_p wMenuPopupCreate(
b->w = 0;
b->h = 0;
g_signal_connect( GTK_OBJECT (b->menu), "key_press_event",
- G_CALLBACK(catch_shift_ctrl_alt_keys), b);
+ G_CALLBACK(catch_shift_ctrl_alt_keys), b);
g_signal_connect( GTK_OBJECT (b->menu), "key_release_event",
- G_CALLBACK (catch_shift_ctrl_alt_keys), b);
- gtk_widget_set_events ( GTK_WIDGET(b->menu), GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK );
+ G_CALLBACK (catch_shift_ctrl_alt_keys), b);
+ gtk_widget_set_events ( GTK_WIDGET(b->menu),
+ GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK );
return b;
}
@@ -1023,30 +1053,30 @@ void wMenuPopupShow( wMenu_p mp )
/**
* ?? Seems to be related to macro / automatic playback functionality
*
- * \param m IN
- * \param func IN
- * \param data IN
+ * \param m IN
+ * \param func IN
+ * \param data IN
*/
void wMenuSetTraceCallBack(
- wMenu_p m,
- wMenuTraceCallBack_p func,
- void * data )
+ wMenu_p m,
+ wMenuTraceCallBack_p func,
+ void * data )
{
m->traceFunc = func;
m->traceData = data;
}
/**
- * ??? same as above
- * \param m IN
- * \param label IN
+ * ??? same as above
+ * \param m IN
+ * \param label IN
* \return describe the return value
*/
wBool_t wMenuAction(
- wMenu_p m,
- const char * label )
+ wMenu_p m,
+ const char * label )
{
wMenuItem_p mi;
wMenuToggle_p mt;
@@ -1056,10 +1086,11 @@ wBool_t wMenuAction(
case M_SEPARATOR:
break;
case M_PUSH:
- if ( ((wMenuPush_p)mi)->enabled == FALSE )
+ if ( ((wMenuPush_p)mi)->enabled == FALSE ) {
wBeep();
- else
+ } else {
((wMenuPush_p)mi)->action( ((wMenuPush_p)mi)->data );
+ }
break;
case M_TOGGLE:
mt = (wMenuToggle_p)mi;
@@ -1076,7 +1107,7 @@ wBool_t wMenuAction(
break;
default:
/*fprintf(stderr, "Oops: wMenuAction\n");*/
- break;
+ break;
}
return TRUE;
}
diff --git a/app/wlib/gtklib/message.c b/app/wlib/gtklib/message.c
index 4ecfe6f..6a63434 100644
--- a/app/wlib/gtklib/message.c
+++ b/app/wlib/gtklib/message.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@@ -42,10 +42,10 @@
*/
struct wMessage_t {
- WOBJ_COMMON
- GtkWidget * labelWidget;
- const char * message;
- wWinPix_t labelWidth;
+ WOBJ_COMMON
+ GtkWidget * labelWidget;
+ const char * message;
+ wWinPix_t labelWidth;
};
/**
@@ -57,14 +57,14 @@ struct wMessage_t {
*/
void wMessageSetValue(
- wMessage_p b,
- const char * arg)
+ wMessage_p b,
+ const char * arg)
{
- if (b->widget == 0) {
- abort();
- }
+ if (b->widget == 0) {
+ abort();
+ }
- gtk_label_set_text(GTK_LABEL(b->labelWidget), wlibConvertInput(arg));
+ gtk_label_set_text(GTK_LABEL(b->labelWidget), wlibConvertInput(arg));
}
/**
@@ -76,11 +76,11 @@ void wMessageSetValue(
*/
void wMessageSetWidth(
- wMessage_p b,
- wWinPix_t width)
+ wMessage_p b,
+ wWinPix_t width)
{
- b->labelWidth = width;
- gtk_widget_set_size_request(b->widget, width, -1);
+ b->labelWidth = width;
+ gtk_widget_set_size_request(b->widget, width, -1);
}
/**
@@ -91,47 +91,47 @@ void wMessageSetWidth(
*/
wWinPix_t wMessageGetHeight(
- long flags)
+ long flags)
{
- GtkWidget * temp;
+ GtkWidget * temp;
- if (!(flags&COMBOBOX)) {
+ 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;
+ } 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;
}
/**
@@ -148,61 +148,61 @@ wWinPix_t wMessageGetHeight(
*/
wMessage_p wMessageCreateEx(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * labelStr,
- wWinPix_t width,
- const char *message,
- long flags)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * labelStr,
+ wWinPix_t width,
+ const char *message,
+ long flags)
{
- wMessage_p b;
- GtkRequisition requisition;
- GtkStyle *style;
- PangoFontDescription *fontDesc;
- int fontSize;
- b = (wMessage_p)wlibAlloc(parent, B_MESSAGE, x, y, NULL, sizeof *b, NULL);
- wlibComputePos((wControl_p)b);
- b->message = message;
- b->labelWidth = width;
- b->labelWidget = gtk_label_new(message?wlibConvertInput(message):"");
-
- /* do we need to set a special font? */
- if (wMessageSetFont(flags)) {
- /* get the current font descriptor */
- style = gtk_widget_get_style(GTK_WIDGET(b->labelWidget));
- 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((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);
- gtk_widget_set_size_request(b->widget, width?width:requisition.width,
- requisition.height);
- 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);
-
- /* Reset font size to normal */
- if (wMessageSetFont(flags)) {
- pango_font_description_set_size(fontDesc, fontSize * PANGO_SCALE);
- }
-
- return b;
+ wMessage_p b;
+ GtkRequisition requisition;
+ GtkStyle *style;
+ PangoFontDescription *fontDesc;
+ int fontSize;
+ b = (wMessage_p)wlibAlloc(parent, B_MESSAGE, x, y, NULL, sizeof *b, NULL);
+ wlibComputePos((wControl_p)b);
+ b->message = message;
+ b->labelWidth = width;
+ b->labelWidget = gtk_label_new(message?wlibConvertInput(message):"");
+
+ /* do we need to set a special font? */
+ if (wMessageSetFont(flags)) {
+ /* get the current font descriptor */
+ style = gtk_widget_get_style(GTK_WIDGET(b->labelWidget));
+ 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((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);
+ gtk_widget_set_size_request(b->widget, width?width:requisition.width,
+ requisition.height);
+ 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);
+
+ /* Reset font size to normal */
+ if (wMessageSetFont(flags)) {
+ pango_font_description_set_size(fontDesc, fontSize * PANGO_SCALE);
+ }
+
+ return b;
}
/**
@@ -215,10 +215,10 @@ wMessage_p wMessageCreateEx(
wWinPix_t
wMessageGetWidth(const char *testString)
{
- GtkWidget *entry;
- GtkRequisition requisition;
+// GtkWidget *entry;
+// GtkRequisition requisition;
- return( wLabelWidth(testString));
+ return( wLabelWidth(testString));
// entry = gtk_entry_new();
// g_object_ref_sink(entry);
//
diff --git a/app/wlib/gtklib/notice.c b/app/wlib/gtklib/notice.c
index 0134b4f..5ab352b 100644
--- a/app/wlib/gtklib/notice.c
+++ b/app/wlib/gtklib/notice.c
@@ -41,9 +41,9 @@
static char * wlibChgMnemonic(char *label);
typedef struct {
- GtkWidget * win;
- GtkWidget * label;
- GtkWidget * butt[3];
+ GtkWidget * win;
+ GtkWidget * label;
+ GtkWidget * butt[3];
} notice_win;
static notice_win noticeW;
static long noticeValue;
@@ -55,17 +55,17 @@ static long noticeValue;
*/
static void doNotice(
- GtkWidget * widget,
- long value)
+ GtkWidget * widget,
+ long value)
{
- if (value != 2) {
- // event not from from closing the window but from a button press
- // Close the Notice dialog
- gtk_widget_destroy(noticeW.win);
- // Remember the button
- noticeValue = value;
- }
- wlibDoModal(NULL, FALSE);
+ if (value != 2) {
+ // event not from from closing the window but from a button press
+ // Close the Notice dialog
+ gtk_widget_destroy(noticeW.win);
+ // Remember the button
+ noticeValue = value;
+ }
+ wlibDoModal(NULL, FALSE);
}
/**
@@ -84,48 +84,48 @@ int wNoticeEx(int type,
const char * no)
{
- int res;
- unsigned flag;
- char *headline;
- GtkWidget *dialog;
- GtkWindow *parent = NULL;
+ int res;
+ unsigned flag = GTK_MESSAGE_ERROR;
+ char *headline = _("Error");
+ GtkWidget *dialog;
+ GtkWindow *parent = NULL;
- switch (type) {
- case NT_INFORMATION:
- flag = GTK_MESSAGE_INFO;
- headline = _("Information");
- break;
+ switch (type) {
+ case NT_INFORMATION:
+ flag = GTK_MESSAGE_INFO;
+ headline = _("Information");
+ break;
- case NT_WARNING:
- flag = GTK_MESSAGE_WARNING;
- headline = _("Warning");
- break;
+ case NT_WARNING:
+ flag = GTK_MESSAGE_WARNING;
+ headline = _("Warning");
+ break;
- case NT_ERROR:
- flag = GTK_MESSAGE_ERROR;
- headline = _("Error");
- break;
- }
+ case NT_ERROR:
+ flag = GTK_MESSAGE_ERROR;
+ headline = _("Error");
+ break;
+ }
- if (gtkMainW) {
- parent = GTK_WINDOW(gtkMainW->gtkwin);
- }
+ if (gtkMainW) {
+ parent = GTK_WINDOW(gtkMainW->gtkwin);
+ }
- wDestroySplash();
+ wDestroySplash();
- dialog = gtk_message_dialog_new(parent,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- flag,
- ((no==NULL)?GTK_BUTTONS_OK:GTK_BUTTONS_YES_NO),
- "%s", msg);
- gtk_window_set_title(GTK_WINDOW(dialog), headline);
+ dialog = gtk_message_dialog_new(parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ flag,
+ ((no==NULL)?GTK_BUTTONS_OK:GTK_BUTTONS_YES_NO),
+ "%s", msg);
+ gtk_window_set_title(GTK_WINDOW(dialog), headline);
- gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
- res = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
+ res = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
- return res == GTK_RESPONSE_OK || res == GTK_RESPONSE_YES;
+ return res == GTK_RESPONSE_OK || res == GTK_RESPONSE_YES;
}
@@ -141,11 +141,11 @@ int wNoticeEx(int type,
*/
int wNotice(
- const char * msg, /* Message */
- const char * yes, /* First button label */
- const char * no) /* Second label (or 'NULL') */
+ const char * msg, /* Message */
+ const char * yes, /* First button label */
+ const char * no) /* Second label (or 'NULL') */
{
- return wNotice3(msg, yes, no, NULL);
+ return wNotice3(msg, yes, no, NULL);
}
/** \brief Popup a notice box with three buttons.
@@ -167,121 +167,121 @@ int wNotice(
*/
int wNotice3(
- const char * msg, /* Message */
- const char * affirmative, /* First button label */
- const char * cancel, /* Second label (or 'NULL') */
- const char * alternate)
+ const char * msg, /* Message */
+ const char * affirmative, /* First button label */
+ const char * cancel, /* Second label (or 'NULL') */
+ const char * alternate)
{
- notice_win *nw;
- GtkWidget * vbox;
- GtkWidget * hbox;
- GtkWidget * hbox1;
- GtkWidget * image;
- nw = &noticeW;
-
- char *aff = NULL;
- char *can = NULL;
- char *alt = NULL;
-
- wDestroySplash();
-
- nw->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- gtk_window_set_position(GTK_WINDOW(nw->win), GTK_WIN_POS_CENTER);
- gtk_container_set_border_width(GTK_CONTAINER(nw->win), 0);
- gtk_window_set_resizable(GTK_WINDOW(nw->win), FALSE);
- gtk_window_set_modal(GTK_WINDOW(nw->win), TRUE);
- gtk_window_set_type_hint(GTK_WINDOW(nw->win), GDK_WINDOW_TYPE_HINT_DIALOG);
-
- vbox = gtk_vbox_new(FALSE, 12);
- gtk_widget_show(vbox);
- gtk_container_add(GTK_CONTAINER(nw->win), vbox);
- gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
-
- hbox = gtk_hbox_new(FALSE, 12);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
- gtk_widget_show(hbox);
-
- image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
- GTK_ICON_SIZE_DIALOG);
- gtk_widget_show(image);
- gtk_box_pack_start(GTK_BOX(hbox), image, TRUE, TRUE, 0);
- gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
-
- /* create the text label, allow GTK to wrap and allow for markup (for future enhancements) */
- nw->label = gtk_label_new(msg);
- gtk_widget_show(nw->label);
- gtk_box_pack_end(GTK_BOX(hbox), nw->label, TRUE, TRUE, 0);
- gtk_label_set_use_markup(GTK_LABEL(nw->label), FALSE);
- gtk_label_set_line_wrap(GTK_LABEL(nw->label), TRUE);
- gtk_misc_set_alignment(GTK_MISC(nw->label), 0, 0);
-
- /* this hbox will include the button bar */
- hbox1 = gtk_hbox_new(TRUE, 0);
- gtk_widget_show(hbox1);
- gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, TRUE, 0);
-
- /* add the respective buttons */
- aff = wlibChgMnemonic((char *) affirmative);
- nw->butt[ 0 ] = gtk_button_new_with_mnemonic(aff);
- gtk_widget_show(nw->butt[ 0 ]);
- gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 0 ], TRUE, TRUE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 0 ]), 3);
- g_signal_connect(GTK_OBJECT(nw->butt[0]), "clicked", G_CALLBACK(doNotice),
- (void*)1);
- gtk_widget_set_can_default(nw->butt[ 0 ], TRUE);
-
- if (cancel) {
- can = wlibChgMnemonic((char *) cancel);
- nw->butt[ 1 ] = gtk_button_new_with_mnemonic(can);
- gtk_widget_show(nw->butt[ 1 ]);
- gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 1 ], TRUE, TRUE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 1 ]), 3);
- g_signal_connect(GTK_OBJECT(nw->butt[1]), "clicked", G_CALLBACK(doNotice),
- (void*)0);
- gtk_widget_set_can_default(nw->butt[ 1 ], TRUE);
-
- if (alternate) {
- alt = wlibChgMnemonic((char *) alternate);
- nw->butt[ 2 ] = gtk_button_new_with_mnemonic(alt);
- gtk_widget_show(nw->butt[ 2 ]);
- gtk_box_pack_start(GTK_BOX(hbox1), nw->butt[ 2 ], TRUE, TRUE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 2 ]), 3);
- g_signal_connect(GTK_OBJECT(nw->butt[2]), "clicked", G_CALLBACK(doNotice),
- (void*)-1);
- gtk_widget_set_can_default(nw->butt[ 2 ], TRUE);
- }
- }
-
- g_signal_connect(GTK_WINDOW(nw->win),
- "destroy", G_CALLBACK(doNotice), (void*)2);
-
- gtk_widget_grab_default(nw->butt[ 0 ]);
- gtk_widget_grab_focus(nw->butt[ 0 ]);
-
- gtk_widget_show(nw->win);
-
- if (gtkMainW) {
- gtk_window_set_transient_for(GTK_WINDOW(nw->win), GTK_WINDOW(gtkMainW->gtkwin));
- /* gdk_window_set_group( nw->win->window, gtkMainW->gtkwin->window ); */
- }
-
- noticeValue = 0; // Default: Cancel
- wlibDoModal(NULL, TRUE);
-
- if (aff) {
- free(aff);
- }
-
- if (can) {
- free(can);
- }
-
- if (alt) {
- free(alt);
- }
-
- return noticeValue;
+ notice_win *nw;
+ GtkWidget * vbox;
+ GtkWidget * hbox;
+ GtkWidget * hbox1;
+ GtkWidget * image;
+ nw = &noticeW;
+
+ char *aff = NULL;
+ char *can = NULL;
+ char *alt = NULL;
+
+ wDestroySplash();
+
+ nw->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_position(GTK_WINDOW(nw->win), GTK_WIN_POS_CENTER);
+ gtk_container_set_border_width(GTK_CONTAINER(nw->win), 0);
+ gtk_window_set_resizable(GTK_WINDOW(nw->win), FALSE);
+ gtk_window_set_modal(GTK_WINDOW(nw->win), TRUE);
+ gtk_window_set_type_hint(GTK_WINDOW(nw->win), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+ vbox = gtk_vbox_new(FALSE, 12);
+ gtk_widget_show(vbox);
+ gtk_container_add(GTK_CONTAINER(nw->win), vbox);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
+
+ hbox = gtk_hbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
+ gtk_widget_show(hbox);
+
+ image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_widget_show(image);
+ gtk_box_pack_start(GTK_BOX(hbox), image, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
+
+ /* create the text label, allow GTK to wrap and allow for markup (for future enhancements) */
+ nw->label = gtk_label_new(msg);
+ gtk_widget_show(nw->label);
+ gtk_box_pack_end(GTK_BOX(hbox), nw->label, TRUE, TRUE, 0);
+ gtk_label_set_use_markup(GTK_LABEL(nw->label), FALSE);
+ gtk_label_set_line_wrap(GTK_LABEL(nw->label), TRUE);
+ gtk_misc_set_alignment(GTK_MISC(nw->label), 0, 0);
+
+ /* this hbox will include the button bar */
+ hbox1 = gtk_hbox_new(TRUE, 0);
+ gtk_widget_show(hbox1);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, TRUE, 0);
+
+ /* add the respective buttons */
+ aff = wlibChgMnemonic((char *) affirmative);
+ nw->butt[ 0 ] = gtk_button_new_with_mnemonic(aff);
+ gtk_widget_show(nw->butt[ 0 ]);
+ gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 0 ], TRUE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 0 ]), 3);
+ g_signal_connect(GTK_OBJECT(nw->butt[0]), "clicked", G_CALLBACK(doNotice),
+ (void*)1);
+ gtk_widget_set_can_default(nw->butt[ 0 ], TRUE);
+
+ if (cancel) {
+ can = wlibChgMnemonic((char *) cancel);
+ nw->butt[ 1 ] = gtk_button_new_with_mnemonic(can);
+ gtk_widget_show(nw->butt[ 1 ]);
+ gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 1 ], TRUE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 1 ]), 3);
+ g_signal_connect(GTK_OBJECT(nw->butt[1]), "clicked", G_CALLBACK(doNotice),
+ (void*)0);
+ gtk_widget_set_can_default(nw->butt[ 1 ], TRUE);
+
+ if (alternate) {
+ alt = wlibChgMnemonic((char *) alternate);
+ nw->butt[ 2 ] = gtk_button_new_with_mnemonic(alt);
+ gtk_widget_show(nw->butt[ 2 ]);
+ gtk_box_pack_start(GTK_BOX(hbox1), nw->butt[ 2 ], TRUE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 2 ]), 3);
+ g_signal_connect(GTK_OBJECT(nw->butt[2]), "clicked", G_CALLBACK(doNotice),
+ (void*)-1);
+ gtk_widget_set_can_default(nw->butt[ 2 ], TRUE);
+ }
+ }
+
+ g_signal_connect(GTK_WINDOW(nw->win),
+ "destroy", G_CALLBACK(doNotice), (void*)2);
+
+ gtk_widget_grab_default(nw->butt[ 0 ]);
+ gtk_widget_grab_focus(nw->butt[ 0 ]);
+
+ gtk_widget_show(nw->win);
+
+ if (gtkMainW) {
+ gtk_window_set_transient_for(GTK_WINDOW(nw->win), GTK_WINDOW(gtkMainW->gtkwin));
+ /* gdk_window_set_group( nw->win->window, gtkMainW->gtkwin->window ); */
+ }
+
+ noticeValue = 0; // Default: Cancel
+ wlibDoModal(NULL, TRUE);
+
+ if (aff) {
+ free(aff);
+ }
+
+ if (can) {
+ free(can);
+ }
+
+ if (alt) {
+ free(alt);
+ }
+
+ return noticeValue;
}
/* \brief Convert label string from Windows mnemonic to GTK
@@ -295,18 +295,18 @@ int wNotice3(
static
char * wlibChgMnemonic(char *label)
{
- char *ptr;
- char *cp;
+ char *ptr;
+ char *cp;
- cp = strdup(label);
+ cp = strdup(label);
- ptr = strchr(cp, '&');
+ ptr = strchr(cp, '&');
- if (ptr) {
- *ptr = '_';
- }
+ if (ptr) {
+ *ptr = '_';
+ }
- return (cp);
+ return (cp);
}
diff --git a/app/wlib/gtklib/opendocument.c b/app/wlib/gtklib/opendocument.c
index c03f9cb..5c057ec 100644
--- a/app/wlib/gtklib/opendocument.c
+++ b/app/wlib/gtklib/opendocument.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@@ -55,24 +55,24 @@
static char *
ExtendPath(void)
{
- char *path = strdup(getenv("PATH"));
- DynString newPath;
- DynStringMalloc(&newPath, 16);
+ char *path = strdup(getenv("PATH"));
+ DynString newPath;
+ DynStringMalloc(&newPath, 16);
- // append XTrackCAD's directory to the path as a fallback
- DynStringCatCStrs(&newPath,
- path,
- ":",
- wGetAppLibDir(),
- NULL);
+ // append XTrackCAD's directory to the path as a fallback
+ DynStringCatCStrs(&newPath,
+ path,
+ ":",
+ wGetAppLibDir(),
+ NULL);
- setenv("PATH",
- DynStringToCStr(&newPath),
- TRUE);
+ setenv("PATH",
+ DynStringToCStr(&newPath),
+ TRUE);
- DynStringFree(&newPath);
+ DynStringFree(&newPath);
- return (path);
+ return (path);
}
/**
@@ -85,33 +85,33 @@ ExtendPath(void)
unsigned wOpenFileExternal(char * filename)
{
- int rc;
- DynString commandLine;
- char *currentPath;
-
- assert(filename != NULL);
- assert(strlen(filename));
-
- currentPath = ExtendPath();
-
- DynStringMalloc(&commandLine, 16);
- DynStringCatCStrs(&commandLine,
- DEFAULTOPENCOMMAND,
- " \"",
- filename,
- "\"",
- NULL);
-
- // the command should be found via the PATH
- rc = system(DynStringToCStr(&commandLine));
-
- // restore the PATH
- setenv("PATH",
- currentPath,
- TRUE);
-
- free(currentPath);
- DynStringFree(&commandLine);
-
- return(rc==0);
+ int rc;
+ DynString commandLine;
+ char *currentPath;
+
+ assert(filename != NULL);
+ assert(strlen(filename));
+
+ currentPath = ExtendPath();
+
+ DynStringMalloc(&commandLine, 16);
+ DynStringCatCStrs(&commandLine,
+ DEFAULTOPENCOMMAND,
+ " \"",
+ filename,
+ "\"",
+ NULL);
+
+ // the command should be found via the PATH
+ rc = system(DynStringToCStr(&commandLine));
+
+ // restore the PATH
+ setenv("PATH",
+ currentPath,
+ TRUE);
+
+ free(currentPath);
+ DynStringFree(&commandLine);
+
+ return(rc==0);
}
diff --git a/app/wlib/gtklib/osxhelp.c b/app/wlib/gtklib/osxhelp.c
index 2fed375..b508961 100644
--- a/app/wlib/gtklib/osxhelp.c
+++ b/app/wlib/gtklib/osxhelp.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -51,15 +51,15 @@ extern wBool_t CheckHelpTopicExists(const char *);
static
char *ChildProgramFile(char *parentProgram)
{
- char *startOfFilename;
- char *childProgram;
+ char *startOfFilename;
+ char *childProgram;
- childProgram = malloc(strlen(parentProgram)+ sizeof(HELPERPROGRAM) + 1);
- strcpy(childProgram, parentProgram);
- startOfFilename = strrchr(childProgram, '/');
- strcpy(startOfFilename + 1, HELPERPROGRAM);
+ childProgram = malloc(strlen(parentProgram)+ sizeof(HELPERPROGRAM) + 1);
+ strcpy(childProgram, parentProgram);
+ startOfFilename = strrchr(childProgram, '/');
+ strcpy(startOfFilename + 1, HELPERPROGRAM);
- return (childProgram);
+ return (childProgram);
}
@@ -71,92 +71,93 @@ char *ChildProgramFile(char *parentProgram)
void wHelp(const char * topic)
{
- pid_t newPid;
- int status;
- const char html[] = ".html";
- static char *directory; /**< base directory for HTML files */
- char * htmlFile;
-
- struct {
- int length;
- char *page;
- } buffer;
-
- if (!CheckHelpTopicExists(topic)) return;
-
- // check whether child already exists
- if (pidOfChild != 0) {
- if (waitpid(pidOfChild, &status, WNOHANG) < 0) {
- // child exited -> clean up
- close(handleOfPipe);
- unlink(HELPCOMMANDPIPE);
- handleOfPipe = 0;
- pidOfChild = 0; // child exited
- }
- }
-
- // (re)start child
- if (pidOfChild == 0) {
- unlink(HELPCOMMANDPIPE);
- int rc = mkfifo(HELPCOMMANDPIPE, 0666);
- newPid = fork(); /* New process starts here */
-
- if (newPid > 0) {
- pidOfChild = newPid;
- } else if (newPid == 0) {
+ pid_t newPid;
+ int status;
+ const char html[] = ".html";
+ static char *directory; /**< base directory for HTML files */
+ char * htmlFile;
+
+ struct {
+ int length;
+ char *page;
+ } buffer;
+
+ if (!CheckHelpTopicExists(topic)) { return; }
+
+ // check whether child already exists
+ if (pidOfChild != 0) {
+ if (waitpid(pidOfChild, &status, WNOHANG) < 0) {
+ // child exited -> clean up
+ close(handleOfPipe);
+ unlink(HELPCOMMANDPIPE);
+ handleOfPipe = 0;
+ pidOfChild = 0; // child exited
+ }
+ }
+
+ // (re)start child
+ if (pidOfChild == 0) {
+ unlink(HELPCOMMANDPIPE);
+ int rc = mkfifo(HELPCOMMANDPIPE, 0666);
+ newPid = fork(); /* New process starts here */
+
+ if (newPid > 0) {
+ pidOfChild = newPid;
+ } else if (newPid == 0) {
char *child = ChildProgramFile(wExecutableName);
-
- if (execlp(child, child, NULL) < 0) { /* never normally returns */
- exit(8);
- }
-
- free(child);
- } else { /* -1 signifies fork failure */
- pidOfChild = 0;
- return;
- }
- }
-
- buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1);
-
- if (!buffer.page) {
- return;
- }
-
- strcpy(buffer.page, topic);
- strcat(buffer.page, html);
- buffer.length = strlen(buffer.page);
-
- if (buffer.length>255) {
- printf("Help Topic too long %s", buffer.page);
- return;
- }
-
- if (!handleOfPipe) {
+
+ if (execlp(child, child, NULL) < 0) { /* never normally returns */
+ exit(8);
+ }
+
+ free(child);
+ } else { /* -1 signifies fork failure */
+ pidOfChild = 0;
+ return;
+ }
+ }
+
+ buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1);
+
+ if (!buffer.page) {
+ return;
+ }
+
+ strcpy(buffer.page, topic);
+ strcat(buffer.page, html);
+ buffer.length = strlen(buffer.page);
+
+ if (buffer.length>255) {
+ printf("Help Topic too long %s", buffer.page);
+ return;
+ }
+
+ if (!handleOfPipe) {
handleOfPipe = open(HELPCOMMANDPIPE, O_WRONLY);
if (handleOfPipe < 0) {
- if (pidOfChild)
- kill(pidOfChild, SIGKILL); /* tidy up on next call */
+ if (pidOfChild) {
+ kill(pidOfChild, SIGKILL); /* tidy up on next call */
+ }
handleOfPipe = 0;
return;
}
}
- int written = 0;
- int towrite = sizeof(int);
+ int written = 0;
+ int towrite = sizeof(int);
- while (written < towrite){
- written += write(handleOfPipe, &buffer.length, sizeof(int));
- }
- written =0;
- towrite = strlen(buffer.page);
- while (written < towrite){
- written += write(handleOfPipe, buffer.page+written, towrite-written);
- }
+ while (written < towrite) {
+ written += write(handleOfPipe, &buffer.length, sizeof(int));
+ }
+ written =0;
+ towrite = strlen(buffer.page);
+ while (written < towrite) {
+ written += write(handleOfPipe, buffer.page+written, towrite-written);
+ }
- fsync(handleOfPipe);
+ fsync(handleOfPipe);
- free(buffer.page);
+ free(buffer.page);
}
diff --git a/app/wlib/gtklib/pixbuf.c b/app/wlib/gtklib/pixbuf.c
index a76e7f1..0d6e8b7 100644
--- a/app/wlib/gtklib/pixbuf.c
+++ b/app/wlib/gtklib/pixbuf.c
@@ -45,55 +45,55 @@
*/
GdkPixbuf* wlibMakePixbuf(
- wIcon_p ip)
+ wIcon_p ip)
{
- GdkPixbuf * pixbuf;
- char line0[40];
- char line2[40];
-
- assert(ip != NULL);
-
- if (ip->gtkIconType == gtkIcon_pixmap) {
- pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)ip->bits);
- } else {
- const char * bits;
- long rgb;
- int row,col,wb;
- char ** pixmapData;
-
- wb = (ip->w+7)/8;
- pixmapData = (char**)g_malloc((3+ip->h) * sizeof *pixmapData);
- pixmapData[0] = line0;
- rgb = wDrawGetRGB(ip->color);
- sprintf(line0, " %ld %ld 2 1", ip->w, ip->h);
- 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; row<ip->h; row++) {
- pixmapData[row+3] = (char*)g_malloc((ip->w+1) * sizeof **pixmapData);
-
- 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;
- }
-
- pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData);
-
- for (row = 0; row<ip->h; row++) {
- g_free(pixmapData[row+3]);
- }
- }
-
- return pixbuf;
+ GdkPixbuf * pixbuf;
+ char line0[40];
+ char line2[40];
+
+ assert(ip != NULL);
+
+ if (ip->gtkIconType == gtkIcon_pixmap) {
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)ip->bits);
+ } else {
+ const char * bits;
+ long rgb;
+ int row,col,wb;
+ char ** pixmapData;
+
+ wb = (ip->w+7)/8;
+ pixmapData = (char**)g_malloc((3+ip->h) * sizeof *pixmapData);
+ pixmapData[0] = line0;
+ rgb = wDrawGetRGB(ip->color);
+ sprintf(line0, " %ld %ld 2 1", ip->w, ip->h);
+ 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; row<ip->h; row++) {
+ pixmapData[row+3] = (char*)g_malloc((ip->w+1) * sizeof **pixmapData);
+
+ 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;
+ }
+
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData);
+
+ for (row = 0; row<ip->h; row++) {
+ g_free(pixmapData[row+3]);
+ }
+ }
+
+ return pixbuf;
}
diff --git a/app/wlib/gtklib/print.c b/app/wlib/gtklib/print.c
index 7f8f49e..609efa9 100644
--- a/app/wlib/gtklib/print.c
+++ b/app/wlib/gtklib/print.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@@ -79,8 +79,7 @@ extern struct wDraw_t psPrint_d;
static wBool_t printContinue; /**< control print job, FALSE for cancelling */
static wIndex_t pageCount; /**< unused, could be used for progress indicator */
-static wIndex_t
-totalPageCount; /**< unused, could be used for progress indicator */
+//static wIndex_t totalPageCount; /**< unused, could be used for progress indicator */
static double paperWidth; /**< physical paper width */
static double paperHeight; /**< physical paper height */
@@ -92,7 +91,7 @@ static double bBorder; /**< bottom margin */
static double scale_adjust = 1.0;
static double scale_text = 1.0;
-static long printFormat = PRINT_LANDSCAPE;
+//static long printFormat = PRINT_LANDSCAPE;
/*****************************************************************************
*
@@ -112,61 +111,61 @@ static void WlibGetPaperSize(void);
void
WlibApplySettings(GtkPrintOperation *op)
{
- gchar *filename;
- GError *err = NULL;
- GtkWidget *dialog;
-
- filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL);
-
- if (!(settings = gtk_print_settings_new_from_file(filename, &err))) {
- if (err->code != G_FILE_ERROR_NOENT) {
- // ignore file not found error as defaults will be used
- dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%s",err->message);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- } else {
- // create default print settings
- settings = gtk_print_settings_new();
- }
- g_error_free(err);
- }
-
- g_free(filename);
-
- if (settings && op) {
- gtk_print_operation_set_print_settings(op, settings);
- }
-
- err = NULL;
- filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL);
-
- if (!(page_setup = gtk_page_setup_new_from_file(filename, &err))) {
- // ignore file not found error as defaults will be used
- if (err->code != G_FILE_ERROR_NOENT) {
- dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%s",err->message);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- } else {
- page_setup = gtk_page_setup_new();
- }
-
- g_error_free(err);
- } else {
- // on success get the paper dimensions
- WlibGetPaperSize();
- }
-
- g_free(filename);
-
- if (page_setup && op) {
- gtk_print_operation_set_default_page_setup(op, page_setup);
- }
+ gchar *filename;
+ GError *err = NULL;
+ GtkWidget *dialog;
+
+ filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL);
+
+ if (!(settings = gtk_print_settings_new_from_file(filename, &err))) {
+ if (err->code != G_FILE_ERROR_NOENT) {
+ // ignore file not found error as defaults will be used
+ dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s",err->message);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ } else {
+ // create default print settings
+ settings = gtk_print_settings_new();
+ }
+ g_error_free(err);
+ }
+
+ g_free(filename);
+
+ if (settings && op) {
+ gtk_print_operation_set_print_settings(op, settings);
+ }
+
+ err = NULL;
+ filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL);
+
+ if (!(page_setup = gtk_page_setup_new_from_file(filename, &err))) {
+ // ignore file not found error as defaults will be used
+ if (err->code != G_FILE_ERROR_NOENT) {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s",err->message);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ } else {
+ page_setup = gtk_page_setup_new();
+ }
+
+ g_error_free(err);
+ } else {
+ // on success get the paper dimensions
+ WlibGetPaperSize();
+ }
+
+ g_free(filename);
+
+ if (page_setup && op) {
+ gtk_print_operation_set_default_page_setup(op, page_setup);
+ }
}
@@ -180,55 +179,55 @@ WlibApplySettings(GtkPrintOperation *op)
void
WlibSaveSettings(GtkPrintOperation *op)
{
- GError *err = NULL;
- gchar *filename;
- GtkWidget *dialog;
+ GError *err = NULL;
+ gchar *filename;
+ GtkWidget *dialog;
- if (op) {
- if (settings != NULL) {
- g_object_unref(settings);
- }
+ if (op) {
+ if (settings != NULL) {
+ g_object_unref(settings);
+ }
- settings = g_object_ref(gtk_print_operation_get_print_settings(op));
- }
+ settings = g_object_ref(gtk_print_operation_get_print_settings(op));
+ }
- filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL);
+ filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL);
- if (!gtk_print_settings_to_file(settings, filename, &err)) {
- dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%s",err->message);
+ if (!gtk_print_settings_to_file(settings, filename, &err)) {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s",err->message);
- g_error_free(err);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- }
+ g_error_free(err);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ }
- g_free(filename);
+ g_free(filename);
- if (op) {
- if (page_setup != NULL) {
- g_object_unref(page_setup);
- }
+ if (op) {
+ if (page_setup != NULL) {
+ g_object_unref(page_setup);
+ }
- page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(op));
- }
+ page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(op));
+ }
- filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL);
+ filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL);
- if (!gtk_page_setup_to_file(page_setup, filename, &err)) {
- dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%s",err->message);
+ if (!gtk_page_setup_to_file(page_setup, filename, &err)) {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s",err->message);
- g_error_free(err);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- }
+ g_error_free(err);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ }
- g_free(filename);
+ g_free(filename);
}
@@ -241,30 +240,32 @@ WlibSaveSettings(GtkPrintOperation *op)
void wPrintSetup(wPrintSetupCallBack_p callback)
{
- GtkPageSetup *new_page_setup;
- gchar *filename;
- GError *err;
- GtkWidget *dialog;
+ GtkPageSetup *new_page_setup;
+// gchar *filename;
+// GError *err;
+// GtkWidget *dialog;
- if ( !settings )
- WlibApplySettings(NULL);
+ if ( !settings ) {
+ WlibApplySettings(NULL);
+ }
- new_page_setup = gtk_print_run_page_setup_dialog(GTK_WINDOW(gtkMainW->gtkwin),
- page_setup, settings);
+ new_page_setup = gtk_print_run_page_setup_dialog(GTK_WINDOW(gtkMainW->gtkwin),
+ page_setup, settings);
- if (page_setup && (page_setup != new_page_setup)) { //Can be the same if no mods...
- g_object_unref(page_setup);
- }
+ if (page_setup
+ && (page_setup != new_page_setup)) { //Can be the same if no mods...
+ g_object_unref(page_setup);
+ }
- page_setup = new_page_setup;
+ page_setup = new_page_setup;
- WlibGetPaperSize();
- WlibSaveSettings(NULL);
+ WlibGetPaperSize();
+ WlibSaveSettings(NULL);
}
/*****************************************************************************
*
- *
+ *
*
*/
@@ -272,7 +273,7 @@ void wPrintSetup(wPrintSetupCallBack_p callback)
static GtkPrinter * pDefaultPrinter = NULL;
gboolean isDefaultPrinter( GtkPrinter * printer, gpointer data )
{
-const char * pPrinterName = gtk_printer_get_name( printer );
+//const char * pPrinterName = gtk_printer_get_name( printer );
if ( gtk_printer_is_default( printer ) ) {
pDefaultPrinter = printer;
return TRUE;
@@ -284,18 +285,19 @@ static void getDefaultPrinter()
{
pDefaultPrinter = NULL;
gtk_enumerate_printers( isDefaultPrinter, NULL, NULL, TRUE );
-}
+}
const char * wPrintGetName()
{
static char sPrinterName[100];
WlibApplySettings( NULL );
- const char * pPrinterName =
- gtk_print_settings_get( settings, "format-for-printer" );
+ const char * pPrinterName =
+ gtk_print_settings_get( settings, "format-for-printer" );
if ( pPrinterName == NULL ) {
getDefaultPrinter();
- if ( pDefaultPrinter )
+ if ( pDefaultPrinter ) {
pPrinterName = gtk_printer_get_name( pDefaultPrinter );
+ }
}
if ( pPrinterName == NULL ) {
pPrinterName = "";
@@ -303,8 +305,9 @@ const char * wPrintGetName()
strncpy (sPrinterName, pPrinterName, sizeof sPrinterName - 1 );
sPrinterName[ sizeof sPrinterName - 1 ] = '\0';
for ( char * cp = sPrinterName; *cp; cp++ )
- if ( *cp == ':' )
+ if ( *cp == ':' ) {
*cp = '-';
+ }
return sPrinterName;
}
/*****************************************************************************
@@ -325,71 +328,65 @@ const char * wPrintGetName()
static void setLineType(
- double lineWidth,
- wDrawLineType_e lineType,
- wDrawOpts opts)
+ double lineWidth,
+ wDrawLineType_e lineType,
+ wDrawOpts opts)
{
- cairo_t *cr = psPrint_d.printContext;
-
- 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/scale_adjust;
- }
-
- // make sure that there is a minimum line width used
- if (lineWidth <= 0.09) {
- lineWidth = 0.1/scale_adjust;
- }
-
- cairo_set_line_width(cr, lineWidth);
- switch(lineType) {
- case wDrawLineDot:
- {
- double dashes[] = { 1, 2 , 1, 2};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cr, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLineDash:
- {
- double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cr, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLineDashDot:
- {
- double dashes[] = { 3, 2, 1, 2};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cr, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLineDashDotDot:
- {
- double dashes[] = { 3, 2, 1, 2, 1, 2};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cr, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLineCenter:
- {
- double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cr, dashes, len_dashes, 0.0);
- break;
- }
- case wDrawLinePhantom:
- {
- double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3, DASH_LENGTH, 3};
- static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
- cairo_set_dash(cr, dashes, len_dashes, 0.0);
- break;
- }
- default:
- cairo_set_dash(cr, NULL, 0, 0.0);
- }
+ cairo_t *cr = psPrint_d.printContext;
+
+// 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/scale_adjust;
+ }
+
+ // make sure that there is a minimum line width used
+ if (lineWidth <= 0.09) {
+ lineWidth = 0.1/scale_adjust;
+ }
+
+ cairo_set_line_width(cr, lineWidth);
+ switch(lineType) {
+ case wDrawLineDot: {
+ double dashes[] = { 1, 2, 1, 2};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cr, dashes, len_dashes, 0.0);
+ break;
+ }
+ case wDrawLineDash: {
+ double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cr, dashes, len_dashes, 0.0);
+ break;
+ }
+ case wDrawLineDashDot: {
+ double dashes[] = { 3, 2, 1, 2};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cr, dashes, len_dashes, 0.0);
+ break;
+ }
+ case wDrawLineDashDotDot: {
+ double dashes[] = { 3, 2, 1, 2, 1, 2};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cr, dashes, len_dashes, 0.0);
+ break;
+ }
+ case wDrawLineCenter: {
+ double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cr, dashes, len_dashes, 0.0);
+ break;
+ }
+ case wDrawLinePhantom: {
+ double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3, DASH_LENGTH, 3};
+ static int len_dashes = sizeof(dashes) / sizeof(dashes[0]);
+ cairo_set_dash(cr, dashes, len_dashes, 0.0);
+ break;
+ }
+ default:
+ cairo_set_dash(cr, NULL, 0, 0.0);
+ }
}
@@ -401,14 +398,14 @@ static void setLineType(
*/
static void psSetColor(
- wDrawColor color)
+ wDrawColor color)
{
- cairo_t *cr = psPrint_d.printContext;
- GdkColor* const gcolor = wlibGetColor(color, TRUE);
+ cairo_t *cr = psPrint_d.printContext;
+ GdkColor* const gcolor = wlibGetColor(color, TRUE);
- cairo_set_source_rgb(cr, gcolor->red / 65535.0,
- gcolor->green / 65535.0,
- gcolor->blue / 65535.0);
+ cairo_set_source_rgb(cr, gcolor->red / 65535.0,
+ gcolor->green / 65535.0,
+ gcolor->blue / 65535.0);
}
/**
@@ -423,29 +420,29 @@ static void psSetColor(
*/
void psPrintLine(
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawPix_t x1, wDrawPix_t y1,
- wDrawWidth width,
- wDrawLineType_e lineType,
- wDrawColor color,
- wDrawOpts opts)
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawPix_t x1, wDrawPix_t y1,
+ wDrawWidth width,
+ wDrawLineType_e lineType,
+ wDrawColor color,
+ wDrawOpts opts)
{
- if (color == wDrawColorWhite) {
- return;
- }
-
- if (opts&wDrawOptTemp) {
- return;
- }
-
- psSetColor(color);
- setLineType(width, lineType, opts);
-
- cairo_move_to(psPrint_d.printContext,
- x0, y0);
- cairo_line_to(psPrint_d.printContext,
- x1, y1);
- cairo_stroke(psPrint_d.printContext);
+ if (color == wDrawColorWhite) {
+ return;
+ }
+
+ if (opts&wDrawOptTemp) {
+ return;
+ }
+
+ psSetColor(color);
+ setLineType(width, lineType, opts);
+
+ cairo_move_to(psPrint_d.printContext,
+ x0, y0);
+ cairo_line_to(psPrint_d.printContext,
+ x1, y1);
+ cairo_stroke(psPrint_d.printContext);
}
/**
@@ -462,65 +459,65 @@ void psPrintLine(
*/
void psPrintArc(
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawPix_t r,
- double angle0,
- double angle1,
- wBool_t drawCenter,
- wDrawWidth width,
- wDrawLineType_e lineType,
- wDrawColor color,
- wDrawOpts opts)
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawPix_t r,
+ double angle0,
+ double angle1,
+ wBool_t drawCenter,
+ wDrawWidth width,
+ wDrawLineType_e lineType,
+ wDrawColor color,
+ wDrawOpts opts)
{
- cairo_t *cr = psPrint_d.printContext;
+ cairo_t *cr = psPrint_d.printContext;
- if (color == wDrawColorWhite) {
- return;
- }
+ if (color == wDrawColorWhite) {
+ return;
+ }
- if (opts&wDrawOptTemp) {
- return;
- }
+ if (opts&wDrawOptTemp) {
+ return;
+ }
- psSetColor(color);
- setLineType(width, lineType, opts);
+ psSetColor(color);
+ setLineType(width, lineType, opts);
- if (angle1 >= 360.0) {
- angle1 = 359.999;
- }
+ if (angle1 >= 360.0) {
+ angle1 = 359.999;
+ }
- angle1 = 90.0-(angle0+angle1);
+ angle1 = 90.0-(angle0+angle1);
- while (angle1 < 0.0) {
- angle1 += 360.0;
- }
+ while (angle1 < 0.0) {
+ angle1 += 360.0;
+ }
- while (angle1 >= 360.0) {
- angle1 -= 360.0;
- }
+ while (angle1 >= 360.0) {
+ angle1 -= 360.0;
+ }
- angle0 = 90.0-angle0;
+ angle0 = 90.0-angle0;
- while (angle0 < 0.0) {
- angle0 += 360.0;
- }
+ while (angle0 < 0.0) {
+ angle0 += 360.0;
+ }
- while (angle0 >= 360.0) {
- angle0 -= 360.0;
- }
+ while (angle0 >= 360.0) {
+ angle0 -= 360.0;
+ }
- // draw the curve
- cairo_arc(cr, x0, y0, r, angle1 * M_PI / 180.0, angle0 * M_PI / 180.0);
+ // draw the curve
+ cairo_arc(cr, x0, y0, r, angle1 * M_PI / 180.0, angle0 * M_PI / 180.0);
- if (drawCenter) {
- // draw crosshair for center of curve
- cairo_move_to(cr, x0 - CENTERMARK_LENGTH / 2, y0);
- cairo_line_to(cr, x0 + CENTERMARK_LENGTH / 2, y0);
- cairo_move_to(cr, x0, y0 - CENTERMARK_LENGTH / 2);
- cairo_line_to(cr, x0, y0 + CENTERMARK_LENGTH / 2);
- }
+ if (drawCenter) {
+ // draw crosshair for center of curve
+ cairo_move_to(cr, x0 - CENTERMARK_LENGTH / 2, y0);
+ cairo_line_to(cr, x0 + CENTERMARK_LENGTH / 2, y0);
+ cairo_move_to(cr, x0, y0 - CENTERMARK_LENGTH / 2);
+ cairo_line_to(cr, x0, y0 + CENTERMARK_LENGTH / 2);
+ }
- cairo_stroke(psPrint_d.printContext);
+ cairo_stroke(psPrint_d.printContext);
}
/**
@@ -534,28 +531,28 @@ void psPrintArc(
*/
void psPrintFillRectangle(
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawPix_t x1, wDrawPix_t y1,
- wDrawColor color,
- wDrawOpts opts)
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawPix_t x1, wDrawPix_t y1,
+ wDrawColor color,
+ wDrawOpts opts)
{
- cairo_t *cr = psPrint_d.printContext;
- double width = x0 - x1;
- double height = y0 - y1;
+ cairo_t *cr = psPrint_d.printContext;
+ double width = x0 - x1;
+ double height = y0 - y1;
- if (color == wDrawColorWhite) {
- return;
- }
+ if (color == wDrawColorWhite) {
+ return;
+ }
- if (opts&wDrawOptTemp) {
- return;
- }
+ if (opts&wDrawOptTemp) {
+ return;
+ }
- psSetColor(color);
+ psSetColor(color);
- cairo_rectangle(cr, x0, y0, width, height);
+ cairo_rectangle(cr, x0, y0, width, height);
- cairo_fill(cr);
+ cairo_fill(cr);
}
/**
@@ -570,34 +567,34 @@ void psPrintFillRectangle(
*/
void psPrintFillPolygon(
- wDrawPix_t p[][2],
- wPolyLine_e type[],
- int cnt,
- wDrawColor color,
- wDrawOpts opts,
- int fill,
- int open )
+ wDrawPix_t p[][2],
+ wPolyLine_e type[],
+ int cnt,
+ wDrawColor color,
+ wDrawOpts opts,
+ int fill,
+ int open )
{
- int inx;
- cairo_t *cr = psPrint_d.printContext;
+ int inx;
+ cairo_t *cr = psPrint_d.printContext;
- if (color == wDrawColorWhite) {
- return;
- }
+ if (color == wDrawColorWhite) {
+ return;
+ }
- if (opts&wDrawOptTemp) {
- return;
- }
+ if (opts&wDrawOptTemp) {
+ return;
+ }
- psSetColor(color);
+ psSetColor(color);
- wDrawPix_t mid0[2], mid1[2], mid2[2], mid3[2], mid4[2];
+ wDrawPix_t mid0[2], mid1[2], /*mid2[2],*/ mid3[2], mid4[2];
- for (inx=0; inx<cnt; inx++) {
- int j = inx-1;
- int k = inx+1;
- if (j < 0) j = cnt-1;
- if (k > cnt-1) k = 0;
+ for (inx=0; inx<cnt; inx++) {
+ int j = inx-1;
+ int k = inx+1;
+ if (j < 0) { j = cnt-1; }
+ if (k > cnt-1) { k = 0; }
double len0, len1;
double d0x = (p[inx][0]-p[j][0]);
double d0y = (p[inx][1]-p[j][1]);
@@ -625,33 +622,37 @@ void psPrintFillPolygon(
mid4[1] = (mid1[1]-p[inx][1])/2+p[inx][1];
wDrawPix_t save[2];
if (inx==0) {
- if (!type || (type && type[0] == wPolyLineStraight) || open) {
- cairo_move_to(cr, p[ 0 ][ 0 ], p[ 0 ][ 1 ]);
- save[0] = p[0][0]; save[1] = p[0][1];
- } else {
- cairo_move_to(cr, mid0[0], mid0[1]);
- if (type[inx] == wPolyLineSmooth)
- cairo_curve_to(cr, p[inx][0], p[inx][1], p[inx][0], p[inx][1], mid1[0], mid1[1]);
- else
- cairo_curve_to(cr, mid3[0], mid3[1], mid4[0], mid4[1], mid1[0], mid1[1]);
- save[0] = mid0[0]; save[1] = mid0[1];
- }
- } else if (!type || (type && type[inx] == wPolyLineStraight) || (open && (inx==cnt-1)) ) {
+ if (!type || (type && type[0] == wPolyLineStraight) || open) {
+ cairo_move_to(cr, p[ 0 ][ 0 ], p[ 0 ][ 1 ]);
+ save[0] = p[0][0]; save[1] = p[0][1];
+ } else {
+ cairo_move_to(cr, mid0[0], mid0[1]);
+ if (type[inx] == wPolyLineSmooth) {
+ cairo_curve_to(cr, p[inx][0], p[inx][1], p[inx][0], p[inx][1], mid1[0],
+ mid1[1]);
+ } else {
+ cairo_curve_to(cr, mid3[0], mid3[1], mid4[0], mid4[1], mid1[0], mid1[1]);
+ }
+ save[0] = mid0[0]; save[1] = mid0[1];
+ }
+ } else if (!type || (type && type[inx] == wPolyLineStraight) || (open
+ && (inx==cnt-1)) ) {
cairo_line_to(cr, p[ inx ][ 0 ], p[ inx ][ 1 ]);
} else {
cairo_line_to(cr, mid0[ 0 ], mid0[ 1 ]);
- if (type && type[inx] == wPolyLineSmooth)
+ if (type && type[inx] == wPolyLineSmooth) {
cairo_curve_to(cr, p[inx][0],p[inx][1],p[inx][0],p[inx][1],mid1[0],mid1[1]);
- else
+ } else {
cairo_curve_to(cr, mid3[0],mid3[1],mid4[0],mid4[1],mid1[0],mid1[1]);
+ }
}
if ((inx==cnt-1) && !open) {
cairo_line_to(cr, save[0], save[1]);
}
- }
+ }
- if (fill && !open) cairo_fill(cr);
- else cairo_stroke(cr);
+ if (fill && !open) { cairo_fill(cr); }
+ else { cairo_stroke(cr); }
}
/**
@@ -665,25 +666,25 @@ void psPrintFillPolygon(
*/
void psPrintFillCircle(
- wDrawPix_t x0, wDrawPix_t y0,
- wDrawPix_t r,
- wDrawColor color,
- wDrawOpts opts)
+ wDrawPix_t x0, wDrawPix_t y0,
+ wDrawPix_t r,
+ wDrawColor color,
+ wDrawOpts opts)
{
- if (color == wDrawColorWhite) {
- return;
- }
+ if (color == wDrawColorWhite) {
+ return;
+ }
- if (opts&wDrawOptTemp) {
- return;
- }
+ if (opts&wDrawOptTemp) {
+ return;
+ }
- psSetColor(color);
+ psSetColor(color);
- cairo_arc(psPrint_d.printContext,
- x0, y0, r, 0.0, 2 * M_PI);
+ cairo_arc(psPrint_d.printContext,
+ x0, y0, r, 0.0, 2 * M_PI);
- cairo_fill(psPrint_d.printContext);
+ cairo_fill(psPrint_d.printContext);
}
@@ -710,102 +711,102 @@ void psPrintFillCircle(
*/
void psPrintString(
- wDrawPix_t x, wDrawPix_t y,
- double a,
- char * s,
- wFont_p fp,
- double fs,
- wDrawColor color,
- wDrawOpts opts)
+ wDrawPix_t x, wDrawPix_t y,
+ double a,
+ char * s,
+ wFont_p fp,
+ double fs,
+ wDrawColor color,
+ wDrawOpts opts)
{
- char * cp;
- double x0 = (double)x, y0 = (double)y;
- int text_height, text_width;
- double ascent;
+// char * cp;
+ double x0 = (double)x, y0 = (double)y;
+ int text_height, text_width;
+// double ascent;
- cairo_t *cr;
- cairo_matrix_t matrix;
+ cairo_t *cr;
+ cairo_matrix_t matrix;
- PangoLayout *layout;
- PangoFontDescription *desc;
- PangoFontMetrics *metrics;
- PangoContext *pcontext;
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+// PangoFontMetrics *metrics;
+ PangoContext *pcontext;
- if (color == wDrawColorWhite) {
- return;
- }
+ if (color == wDrawColorWhite) {
+ return;
+ }
- cr = psPrint_d.printContext;
+ cr = psPrint_d.printContext;
- // get the current transformation matrix and transform the starting
- // point of the string
+ // get the current transformation matrix and transform the starting
+ // point of the string
- cairo_save(cr);
+ cairo_save(cr);
- cairo_get_matrix(cr, &matrix);
+ cairo_get_matrix(cr, &matrix);
- cairo_matrix_transform_point(&matrix, &x0, &y0);
+ cairo_matrix_transform_point(&matrix, &x0, &y0);
- cairo_identity_matrix(cr);
+ cairo_identity_matrix(cr);
- layout = pango_cairo_create_layout(cr);
+ layout = pango_cairo_create_layout(cr);
- // set the correct font and size
- /** \todo use a getter function instead of double conversion */
- desc = pango_font_description_from_string(wlibFontTranslate(fp));
+ // set the correct font and size
+ /** \todo use a getter function instead of double conversion */
+ desc = pango_font_description_from_string(wlibFontTranslate(fp));
- pango_font_description_set_size(desc, fs * PANGO_SCALE * scale_text);
+ pango_font_description_set_size(desc, fs * PANGO_SCALE * scale_text);
- // render the string to a Pango layout
- pango_layout_set_font_description(layout, desc);
+ // render the string to a Pango layout
+ pango_layout_set_font_description(layout, desc);
- gchar *utf8 = wlibConvertInput(s);
+ gchar *utf8 = wlibConvertInput(s);
- pango_layout_set_text(layout, utf8, -1);
- pango_layout_set_width(layout, -1);
- pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
- pango_layout_get_size(layout, &text_width, &text_height);
+ pango_layout_set_text(layout, utf8, -1);
+ pango_layout_set_width(layout, -1);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
+ pango_layout_get_size(layout, &text_width, &text_height);
- text_width = text_width / PANGO_SCALE;
- text_height = text_height / PANGO_SCALE;
+ text_width = text_width / PANGO_SCALE;
+ text_height = text_height / PANGO_SCALE;
- // get the height of the string
- pcontext = pango_cairo_create_context(cr);
- metrics = pango_context_get_metrics(pcontext, desc,
- pango_context_get_language(pcontext));
+ // get the height of the string
+ pcontext = pango_cairo_create_context(cr);
+// metrics = pango_context_get_metrics(pcontext, desc,
+// pango_context_get_language(pcontext));
- ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
+// ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
- int baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
+ int baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
- cairo_translate(cr, x0, y0 );
- cairo_rotate(cr, -a * M_PI / 180.0);
- cairo_translate( cr, 0, -baseline );
+ cairo_translate(cr, x0, y0 );
+ cairo_rotate(cr, -a * M_PI / 180.0);
+ cairo_translate( cr, 0, -baseline );
- cairo_move_to(cr,0,0);
+ cairo_move_to(cr,0,0);
- pango_cairo_update_layout(cr, layout);
+ pango_cairo_update_layout(cr, layout);
- // set the color
- psSetColor(color);
+ // set the color
+ psSetColor(color);
- // and show the string
- if(!(opts & wDrawOutlineFont)) {
+ // and show the string
+ if(!(opts & wDrawOutlineFont)) {
pango_cairo_show_layout(cr, layout);
cairo_stroke( cr );
} else {
PangoLayoutLine *line;
line = pango_layout_get_line_readonly (layout, 0);
- setLineType( wDrawLineSolid, 0, 0 );
+ setLineType( wDrawLineSolid, 0, 0 );
pango_cairo_layout_line_path (cr, line);
- cairo_stroke( cr );
+ cairo_stroke( cr );
}
- // free unused objects
- g_object_unref(layout);
- g_object_unref(pcontext);
+ // free unused objects
+ g_object_unref(layout);
+ g_object_unref(pcontext);
- cairo_restore(cr);
+ cairo_restore(cr);
}
/**
@@ -818,12 +819,12 @@ void psPrintString(
void wPrintClip(wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h)
{
- cairo_move_to(psPrint_d.printContext, x, y);
- cairo_rel_line_to(psPrint_d.printContext, w, 0);
- cairo_rel_line_to(psPrint_d.printContext, 0, h);
- cairo_rel_line_to(psPrint_d.printContext, -w, 0);
- cairo_close_path(psPrint_d.printContext);
- cairo_clip(psPrint_d.printContext);
+ cairo_move_to(psPrint_d.printContext, x, y);
+ cairo_rel_line_to(psPrint_d.printContext, w, 0);
+ cairo_rel_line_to(psPrint_d.printContext, 0, h);
+ cairo_rel_line_to(psPrint_d.printContext, -w, 0);
+ cairo_close_path(psPrint_d.printContext);
+ cairo_clip(psPrint_d.printContext);
}
/*****************************************************************************
@@ -840,22 +841,22 @@ void wPrintClip(wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h)
static void
WlibGetPaperSize(void)
{
- double temp;
-
- bBorder = gtk_page_setup_get_bottom_margin(page_setup, GTK_UNIT_INCH);
- tBorder = gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH);
- lBorder = gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH);
- rBorder = gtk_page_setup_get_right_margin(page_setup, GTK_UNIT_INCH);
- paperHeight = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH);
- paperWidth = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH);
-
- // XTrackCAD does page orientation itself. Basic assumption is that the
- // paper is always oriented in portrait mode. Ignore settings by user
- if (paperHeight < paperWidth) {
- temp = paperHeight;
- paperHeight = paperWidth;
- paperWidth = temp;
- }
+ double temp;
+
+ bBorder = gtk_page_setup_get_bottom_margin(page_setup, GTK_UNIT_INCH);
+ tBorder = gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH);
+ lBorder = gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH);
+ rBorder = gtk_page_setup_get_right_margin(page_setup, GTK_UNIT_INCH);
+ paperHeight = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH);
+ paperWidth = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH);
+
+ // XTrackCAD does page orientation itself. Basic assumption is that the
+ // paper is always oriented in portrait mode. Ignore settings by user
+ if (paperHeight < paperWidth) {
+ temp = paperHeight;
+ paperHeight = paperWidth;
+ paperWidth = temp;
+ }
}
/**
@@ -868,15 +869,15 @@ WlibGetPaperSize(void)
void wPrintGetMargins(
- double * tMargin,
- double * rMargin,
- double * bMargin,
- double * lMargin )
+ double * tMargin,
+ double * rMargin,
+ double * bMargin,
+ double * lMargin )
{
- if ( tMargin ) *tMargin = tBorder;
- if ( rMargin ) *rMargin = rBorder;
- if ( bMargin ) *bMargin = bBorder;
- if ( lMargin ) *lMargin = lBorder;
+ if ( tMargin ) { *tMargin = tBorder; }
+ if ( rMargin ) { *rMargin = rBorder; }
+ if ( bMargin ) { *bMargin = bBorder; }
+ if ( lMargin ) { *lMargin = lBorder; }
}
@@ -889,18 +890,18 @@ void wPrintGetMargins(
*/
void wPrintGetPageSize(
- double * w,
- double * h)
+ double * w,
+ double * h)
{
- // if necessary load the settings
- if (!settings) {
- WlibApplySettings(NULL);
- }
+ // if necessary load the settings
+ if (!settings) {
+ WlibApplySettings(NULL);
+ }
- WlibGetPaperSize();
+ WlibGetPaperSize();
- *w = paperWidth;
- *h = paperHeight;
+ *w = paperWidth;
+ *h = paperHeight;
}
/**
@@ -909,11 +910,11 @@ void wPrintGetPageSize(
* \param context IN unused
* \return
*/
-static void printAbort(void * context)
-{
- printContinue = FALSE;
+//static void printAbort(void * context)
+//{
+// printContinue = FALSE;
// wWinShow( printAbortW, FALSE );
-}
+//}
/**
* Initialize new page.
@@ -925,11 +926,11 @@ static void printAbort(void * context)
*/
wDraw_p wPrintPageStart(void)
{
- pageCount++;
+ pageCount++;
- cairo_save(psPrint_d.printContext);
+ cairo_save(psPrint_d.printContext);
- return &psPrint_d;
+ return &psPrint_d;
}
/**
@@ -945,11 +946,11 @@ wDraw_p wPrintPageStart(void)
wBool_t wPrintPageEnd(wDraw_p p)
{
- cairo_show_page(psPrint_d.printContext);
+ cairo_show_page(psPrint_d.printContext);
- cairo_restore(psPrint_d.printContext);
+ cairo_restore(psPrint_d.printContext);
- return printContinue;
+ return printContinue;
}
/*****************************************************************************
@@ -970,93 +971,93 @@ wBool_t wPrintPageEnd(wDraw_p p)
wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP)
{
- GtkWidget *printDialog;
- gint res;
- cairo_surface_type_t surface_type;
- cairo_matrix_t matrix;
+ GtkWidget *printDialog;
+ gint res;
+// cairo_surface_type_t surface_type;
+// cairo_matrix_t matrix;
- printDialog = gtk_print_unix_dialog_new(title, GTK_WINDOW(gtkMainW->gtkwin));
+ printDialog = gtk_print_unix_dialog_new(title, GTK_WINDOW(gtkMainW->gtkwin));
- // load the settings
- WlibApplySettings(NULL);
+ // load the settings
+ WlibApplySettings(NULL);
- // and apply them to the printer dialog
- gtk_print_unix_dialog_set_settings((GtkPrintUnixDialog *)printDialog, settings);
- gtk_print_unix_dialog_set_page_setup((GtkPrintUnixDialog *)printDialog,
- page_setup);
+ // and apply them to the printer dialog
+ gtk_print_unix_dialog_set_settings((GtkPrintUnixDialog *)printDialog, settings);
+ gtk_print_unix_dialog_set_page_setup((GtkPrintUnixDialog *)printDialog,
+ page_setup);
- res = gtk_dialog_run((GtkDialog *)printDialog);
+ res = gtk_dialog_run((GtkDialog *)printDialog);
- if (res == GTK_RESPONSE_OK) {
- selPrinter = gtk_print_unix_dialog_get_selected_printer((
- GtkPrintUnixDialog *)printDialog);
+ if (res == GTK_RESPONSE_OK) {
+ selPrinter = gtk_print_unix_dialog_get_selected_printer((
+ GtkPrintUnixDialog *)printDialog);
- if (settings) {
- g_object_unref(settings);
- }
+ if (settings) {
+ g_object_unref(settings);
+ }
- settings = gtk_print_unix_dialog_get_settings((GtkPrintUnixDialog *)
- printDialog);
+ settings = gtk_print_unix_dialog_get_settings((GtkPrintUnixDialog *)
+ printDialog);
- if (page_setup) {
- g_object_unref(page_setup);
- }
+ if (page_setup) {
+ g_object_unref(page_setup);
+ }
- page_setup = gtk_print_unix_dialog_get_page_setup((GtkPrintUnixDialog *)
- printDialog);
+ page_setup = gtk_print_unix_dialog_get_page_setup((GtkPrintUnixDialog *)
+ printDialog);
- curPrintJob = gtk_print_job_new(title,
- selPrinter,
- settings,
- page_setup);
+ curPrintJob = gtk_print_job_new(title,
+ selPrinter,
+ settings,
+ page_setup);
- psPrint_d.curPrintSurface = gtk_print_job_get_surface(curPrintJob,
- NULL);
- psPrint_d.printContext = cairo_create(psPrint_d.curPrintSurface);
+ psPrint_d.curPrintSurface = gtk_print_job_get_surface(curPrintJob,
+ NULL);
+ psPrint_d.printContext = cairo_create(psPrint_d.curPrintSurface);
- WlibApplySettings( NULL );
- //update the paper dimensions
- WlibGetPaperSize();
+ WlibApplySettings( NULL );
+ //update the paper dimensions
+ WlibGetPaperSize();
- /* for all surfaces including files the resolution is always 72 ppi (as all GTK uses PDF) */
- surface_type = cairo_surface_get_type(psPrint_d.curPrintSurface);
+ /* for all surfaces including files the resolution is always 72 ppi (as all GTK uses PDF) */
+ /*surface_type = */cairo_surface_get_type(psPrint_d.curPrintSurface);
- /*
- * Override up-scaling for some printer drivers/Linux systems that don't support the latest CUPS
- * - the user either sets preferences or the environment variable XTRKCADPRINTSCALE to a value
- * and we just let the dpi default to 72ppi and set scaling to that value.
- * And for PangoText we allow an override via preferences or variable XTRKCADPRINTTEXTSCALE
- * Note - doing this will introduce differing artifacts.
- *
- */
- char * sEnvScale = PRODUCT "PRINTSCALE";
- char * sEnvTextScale = PRODUCT "PRINTTEXTSCALE";
+ /*
+ * Override up-scaling for some printer drivers/Linux systems that don't support the latest CUPS
+ * - the user either sets preferences or the environment variable XTRKCADPRINTSCALE to a value
+ * and we just let the dpi default to 72ppi and set scaling to that value.
+ * And for PangoText we allow an override via preferences or variable XTRKCADPRINTTEXTSCALE
+ * Note - doing this will introduce differing artifacts.
+ *
+ */
+ char * sEnvScale = PRODUCT "PRINTSCALE";
+ char * sEnvTextScale = PRODUCT "PRINTTEXTSCALE";
- scale_text = 1.0;
- scale_adjust = 1.0;
+ scale_text = 1.0;
+ scale_adjust = 1.0;
- double printScale,printTextScale;
+ double printScale,printTextScale;
- wPrefGetFloat(PREFSECTION, PRINTSCALE, &printScale, -1.0);
- wPrefGetFloat(PREFSECTION, PRINTTEXTSCALE, &printTextScale, -1.0);
+ wPrefGetFloat(PREFSECTION, PRINTSCALE, &printScale, -1.0);
+ wPrefGetFloat(PREFSECTION, PRINTTEXTSCALE, &printTextScale, -1.0);
- //If the preferences are not set, look at environmental variables
+ //If the preferences are not set, look at environmental variables
- if (printScale < 0.0 ) {
- if (getenv(sEnvScale) && (atof(getenv(sEnvScale)) > 0.0)) {
- printScale = atof(getenv(sEnvScale));
- }
- }
- if (printTextScale < 0.0 ) {
- if (getenv(sEnvTextScale) && (atof(getenv(sEnvTextScale)) > 0.0)) {
- printTextScale = atof(getenv(sEnvTextScale));
- }
- }
+ if (printScale < 0.0 ) {
+ if (getenv(sEnvScale) && (atof(getenv(sEnvScale)) > 0.0)) {
+ printScale = atof(getenv(sEnvScale));
+ }
+ }
+ if (printTextScale < 0.0 ) {
+ if (getenv(sEnvTextScale) && (atof(getenv(sEnvTextScale)) > 0.0)) {
+ printTextScale = atof(getenv(sEnvTextScale));
+ }
+ }
- const char * sPrinterName = gtk_printer_get_name( selPrinter );
- if ((strcmp(sPrinterName,"Print to File") == 0) || printScale < 0.0) {
+ const char * sPrinterName = gtk_printer_get_name( selPrinter );
+ if ((strcmp(sPrinterName,"Print to File") == 0) || printScale < 0.0) {
double p_def = 600;
cairo_surface_set_fallback_resolution(psPrint_d.curPrintSurface, p_def, p_def);
psPrint_d.dpi = p_def;
@@ -1071,33 +1072,33 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP)
psPrint_d.dpi = 72;
}
- // 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 margin
+ // 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 margin
- cairo_translate(psPrint_d.printContext, lBorder*72, (paperHeight-bBorder)*72 );
+ 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 * scale_adjust, -1.0 * scale_adjust);
- //cairo_translate(psPrint_d.printContext, 0, -paperHeight* psPrint_d.dpi);
+ //cairo_translate(psPrint_d.printContext, 0, -paperHeight* psPrint_d.dpi);
- WlibSaveSettings(NULL);
- }
+ WlibSaveSettings(NULL);
+ }
- gtk_widget_destroy(printDialog);
+ gtk_widget_destroy(printDialog);
- if (copiesP) {
- *copiesP = 1;
- }
+ if (copiesP) {
+ *copiesP = 1;
+ }
- printContinue = TRUE;
+ printContinue = TRUE;
- if (res != GTK_RESPONSE_OK) {
- return FALSE;
- } else {
- return TRUE;
- }
+ if (res != GTK_RESPONSE_OK) {
+ return FALSE;
+ } else {
+ return TRUE;
+ }
}
/**
@@ -1112,16 +1113,16 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP)
void
doPrintJobFinished(GtkPrintJob *job, void *data, GError *err)
{
- GtkWidget *dialog;
+// GtkWidget *dialog;
- cairo_destroy(psPrint_d.printContext);
+ cairo_destroy(psPrint_d.printContext);
- if (err) {
- dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%s",err->message);
- }
+ if (err) {
+ /*dialog = */gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s",err->message);
+ }
}
/**
@@ -1131,12 +1132,12 @@ doPrintJobFinished(GtkPrintJob *job, void *data, GError *err)
void wPrintDocEnd(void)
{
- cairo_surface_finish(psPrint_d.curPrintSurface);
+ cairo_surface_finish(psPrint_d.curPrintSurface);
- gtk_print_job_send(curPrintJob,
- doPrintJobFinished,
- NULL,
- NULL);
+ gtk_print_job_send(curPrintJob,
+ doPrintJobFinished,
+ NULL,
+ NULL);
// wWinShow( printAbortW, FALSE );
}
@@ -1144,11 +1145,11 @@ void wPrintDocEnd(void)
wBool_t wPrintQuit(void)
{
- return FALSE;
+ return FALSE;
}
wBool_t wPrintInit(void)
{
- return TRUE;
+ return TRUE;
}
diff --git a/app/wlib/gtklib/single.c b/app/wlib/gtklib/single.c
index 3856a64..6204ed5 100644
--- a/app/wlib/gtklib/single.c
+++ b/app/wlib/gtklib/single.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define GTK_DISABLE_SINGLE_INCLUDES
@@ -60,24 +60,27 @@ struct wString_t {
*
* \param b IN widget to be updated
* \param arg IN new string value
- * \return
+ * \return
*/
void wStringSetValue(
- wString_p b,
- const char *arg)
+ wString_p b,
+ const char *arg)
{
- if (b->widget == NULL)
+ if (b->widget == NULL) {
abort();
-
+ }
+
// the contents should not be changed programatically while
// the user is editing it
- if( !(gtk_widget_has_focus(b->widget))) {
- if (b->hasSignal)
- gtk_signal_handler_block_by_data(GTK_OBJECT(b->widget), b);
+ if( (b->option&BO_IGNFOCUS) || !(gtk_widget_has_focus(b->widget))) {
+ if (b->hasSignal) {
+ gtk_signal_handler_block_by_data(GTK_OBJECT(b->widget), b);
+ }
gtk_entry_set_text(GTK_ENTRY(b->widget), arg);
- if (b->hasSignal)
+ if (b->hasSignal) {
gtk_signal_handler_unblock_by_data(GTK_OBJECT(b->widget), b);
+ }
}
}
@@ -86,12 +89,12 @@ void wStringSetValue(
*
* \param b IN widget to be updated
* \param w IN new width
- * \return
+ * \return
*/
void wStringSetWidth(
- wString_p b,
- wWinPix_t w)
+ wString_p b,
+ wWinPix_t w)
{
gtk_widget_set_size_request(b->widget, w, -1);
b->w = w;
@@ -105,11 +108,12 @@ void wStringSetWidth(
*/
const char *wStringGetValue(
- wString_p b)
+ wString_p b)
{
- if ( !b->widget )
+ if ( !b->widget ) {
abort();
-
+ }
+
return gtk_entry_get_text(GTK_ENTRY(b->widget));
}
@@ -134,37 +138,41 @@ void wlibStringUpdate()
*
* \param widget IN the edit field
* \param b IN the widget data structure
- * \return
+ * \return
*/
static gboolean stringActivated(
- GtkEntry *widget,
- wString_p b)
+ GtkEntry *widget,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringActivated: %s\n", b->labelStr );
+ }
const char *s;
const char * output = "\n";
- if ( !b )
+ if ( !b ) {
return( FALSE );
-
+ }
+
s = wStringGetValue(b);
- if (b->valueP)
+ if (b->valueP) {
strcpy(b->valueP, s);
+ }
if (b->action) {
b->enter_pressed = TRUE;
b->action( output, b->data);
}
-
+
// select the complete default value to make editing it easier
gtk_editable_select_region( GTK_EDITABLE( widget ), 0, -1 );
return( TRUE );
}
-static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event, gpointer g )
+static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event,
+ gpointer g )
{
wControl_p b = (wControl_p)g;
return wControlExpose(widget,event,b);
@@ -176,34 +184,37 @@ static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event, gpointe
*
* \param widget IN
* \param entry field IN
- * \return
+ * \return
*/
static int stringChanged(
- GtkEntry *widget,
- wString_p b)
+ GtkEntry *widget,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringChanged: %s\n", b->labelStr);
+ }
stringControl = b;
return FALSE;
}
static int stringPreeditChanged(
- GtkEntry *widget,
- wString_p b)
+ GtkEntry *widget,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringPreeditChanged: %s\n", b->labelStr );
+ }
return FALSE;
}
static int stringFocusOutEvent(
- GtkEntry *widget,
- GdkEvent * event,
- wString_p b)
+ GtkEntry *widget,
+ GdkEvent * event,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringFocusOut: %s\n", b->labelStr );
+ }
if (b->action) {
const char *s;
s = gtk_entry_get_text(GTK_ENTRY(b->widget));
@@ -213,64 +224,71 @@ static int stringFocusOutEvent(
return FALSE;
}
static int stringFocusInEvent(
- GtkEntry *widget,
- GdkEvent * event,
- wString_p b)
+ GtkEntry *widget,
+ GdkEvent * event,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringFocusIn: %s\n", b->labelStr );
+ }
stringControl = b;
return FALSE;
}
static int stringLeaveNotifyEvent(
- GtkEntry *widget,
- GdkEvent * event,
- wString_p b)
+ GtkEntry *widget,
+ GdkEvent * event,
+ wString_p b)
{
- if ( debugWindow >= 3 )
+ if ( debugWindow >= 3 ) {
printf( "stringLeaveNotfyEvent: %s\n", b->labelStr );
+ }
return FALSE;
}
static int stringEventAfter(
- GtkEntry *widget,
- wString_p b)
+ GtkEntry *widget,
+ wString_p b)
{
- if ( debugWindow >= 3 )
+ if ( debugWindow >= 3 ) {
printf( "stringEventAfter: %s\n", b->labelStr );
+ }
return FALSE;
}
static int stringEvent(
- GtkEntry *widget,
- wString_p b)
+ GtkEntry *widget,
+ wString_p b)
{
- if ( debugWindow >= 3 )
+ if ( debugWindow >= 3 ) {
printf( "stringEvent: %s\n", b->labelStr );
+ }
return FALSE;
}
static int stringKeyPressEvent(
- GtkEntry *widget,
- GdkEvent * event,
- wString_p b)
+ GtkEntry *widget,
+ GdkEvent * event,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringKeyPressEvent: %s\n", b->labelStr );
+ }
return FALSE;
}
static int stringStateChanged(
- GtkEntry *widget,
- int state,
- wString_p b)
+ GtkEntry *widget,
+ int state,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringStateChanged: %s\n", b->labelStr );
+ }
return FALSE;
}
static int stringActivate(
- GtkEntry *widget,
- wString_p b)
+ GtkEntry *widget,
+ wString_p b)
{
- if ( debugWindow >= 1 )
+ if ( debugWindow >= 1 ) {
printf( "stringActivate: %s\n", b->labelStr );
+ }
return stringChanged( widget, b );
}
/**
@@ -282,30 +300,30 @@ static int stringActivate(
* \param helpStr IN help anchor
* \param labelStr IN label
* \param option IN option (supported BO_READONLY )
- * \param width IN width of entry field
+ * \param width IN width of entry field
* \param valueP IN default value
- * \param valueL IN maximum length of entry
+ * \param valueL IN maximum length of entry
* \param action IN application callback function
* \param data IN application data
* \return the created widget
*/
wString_p wStringCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char *helpStr,
- const char *labelStr,
- long option,
- wWinPix_t width,
- char *valueP,
- wIndex_t valueL,
- wStringCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char *helpStr,
+ const char *labelStr,
+ long option,
+ wWinPix_t width,
+ char *valueP,
+ wIndex_t valueL,
+ wStringCallBack_p action,
+ void *data)
{
wString_p b;
- // create and initialize the widget
+ // create and initialize the widget
b = (wString_p)wlibAlloc(parent, B_TEXT, x, y, labelStr, sizeof *b, data);
b->valueP = valueP;
b->action = action;
@@ -314,63 +332,77 @@ wString_p wStringCreate(
b->hasSignal = 0;
wlibComputePos((wControl_p)b);
- // create the gtk entry field and set maximum length if desired
+ // create the gtk entry field and set maximum length if desired
b->widget = (GtkWidget *)gtk_entry_new();
- if (b->widget == NULL) abort();
+ if (b->widget == NULL) { abort(); }
- if( valueL )
+ if( valueL ) {
gtk_entry_set_max_length( GTK_ENTRY( b->widget ), valueL );
-
+ }
+
// it is assumed that the parent is a fixed layout widget and the entry can
// be placed at a specific position
gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
-
- // set minimum size for widget
- if (width)
+
+ // set minimum size for widget
+ if (width) {
gtk_widget_set_size_request(b->widget, width, -1);
-
+ }
+
// get the resulting size
wlibControlGetSize((wControl_p)b);
// if desired, place a label in front of the created widget
- if (labelStr)
+ if (labelStr) {
b->labelW = wlibAddLabel((wControl_p)b, labelStr);
-
- if (option & BO_READONLY)
+ }
+
+ if (option & BO_READONLY) {
gtk_editable_set_editable(GTK_EDITABLE(b->widget), FALSE);
-
+ }
+
// set the default text and select it to make replacing it easier
if (b->valueP) {
wStringSetValue(b, b->valueP);
// select the text only if text is editable
}
-
+
// show
gtk_widget_show(b->widget);
-
+
// add the new widget to the list of created widgets
wlibAddButton((wControl_p)b);
-
- // link into help
+
+ // link into help
wlibAddHelpString(b->widget, helpStr);
-
- g_signal_connect(GTK_OBJECT(b->widget), "changed", G_CALLBACK(stringChanged), b);
- g_signal_connect(GTK_OBJECT(b->widget), "preedit-changed", G_CALLBACK(stringPreeditChanged), b);
- g_signal_connect(GTK_OBJECT(b->widget), "focus-out-event", G_CALLBACK(stringFocusOutEvent), b);
- g_signal_connect(GTK_OBJECT(b->widget), "focus-in-event", G_CALLBACK(stringFocusInEvent), b);
- g_signal_connect(GTK_OBJECT(b->widget), "leave-notify-event", G_CALLBACK(stringLeaveNotifyEvent), b);
+
+ g_signal_connect(GTK_OBJECT(b->widget), "changed", G_CALLBACK(stringChanged),
+ b);
+ g_signal_connect(GTK_OBJECT(b->widget), "preedit-changed",
+ G_CALLBACK(stringPreeditChanged), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "focus-out-event",
+ G_CALLBACK(stringFocusOutEvent), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "focus-in-event",
+ G_CALLBACK(stringFocusInEvent), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "leave-notify-event",
+ G_CALLBACK(stringLeaveNotifyEvent), b);
g_signal_connect(GTK_OBJECT(b->widget), "event", G_CALLBACK(stringEvent), b);
- g_signal_connect(GTK_OBJECT(b->widget), "event-after", G_CALLBACK(stringEventAfter), b);
- g_signal_connect(GTK_OBJECT(b->widget), "key-press-event", G_CALLBACK(stringKeyPressEvent), b);
- g_signal_connect(GTK_OBJECT(b->widget), "state-changed", G_CALLBACK(stringStateChanged), b);
- g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivate), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "event-after",
+ G_CALLBACK(stringEventAfter), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "key-press-event",
+ G_CALLBACK(stringKeyPressEvent), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "state-changed",
+ G_CALLBACK(stringStateChanged), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivate),
+ b);
//if (option&BO_ENTER)
- g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivated), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivated),
+ b);
b->hasSignal = 1;
- g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
- G_CALLBACK(stringExposed), b);
-
+ g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event",
+ G_CALLBACK(stringExposed), b);
+
// set the default text and select it to make replacing it easier
if (b->valueP) {
wStringSetValue(b, b->valueP);
@@ -378,6 +410,6 @@ wString_p wStringCreate(
}
gtk_widget_add_events( b->widget, GDK_FOCUS_CHANGE_MASK );
-
+
return b;
}
diff --git a/app/wlib/gtklib/splash.c b/app/wlib/gtklib/splash.c
index 7b7613c..d42b7c0 100644
--- a/app/wlib/gtklib/splash.c
+++ b/app/wlib/gtklib/splash.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
@@ -50,65 +50,65 @@ static GtkWidget *message; /**< window handle for progress message */
int
wCreateSplash(char *appName, char *appVer)
{
- GtkWidget *vbox;
- GtkWidget *image;
- GtkWidget *label;
- char *temp;
- char logoPath[BUFSIZ];
-
- /* create the basic window */
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
- gtk_window_set_title(GTK_WINDOW(window), appName);
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
- gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
- gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
+ GtkWidget *vbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ char *temp;
+ char logoPath[BUFSIZ];
+
+ /* create the basic window */
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
+ gtk_window_set_title(GTK_WINDOW(window), appName);
+ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+ gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
+ gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
#if GTK_MAJOR_VERSION > 1 || GTK_MINOR_VERSION > 5
- gtk_window_set_focus_on_map(GTK_WINDOW(window), FALSE);
+ gtk_window_set_focus_on_map(GTK_WINDOW(window), FALSE);
#endif
- vbox = gtk_vbox_new(FALSE, 0);
- gtk_widget_show(vbox);
- gtk_container_add(GTK_CONTAINER(window), vbox);
+ vbox = gtk_vbox_new(FALSE, 0);
+ gtk_widget_show(vbox);
+ gtk_container_add(GTK_CONTAINER(window), vbox);
- /* add the logo image to the top of the splash window */
- sprintf(logoPath, "%s/" LOGOFILENAME, wGetAppLibDir());
- image = gtk_image_new_from_file(logoPath);
- gtk_widget_show(image);
- gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE, 0);
- gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
+ /* add the logo image to the top of the splash window */
+ sprintf(logoPath, "%s/" LOGOFILENAME, wGetAppLibDir());
+ image = gtk_image_new_from_file(logoPath);
+ gtk_widget_show(image);
+ gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
- /* put the product name into the window */
+ /* put the product name into the window */
- temp = malloc(strlen(appName) + strlen(appVer) + 2);
+ temp = malloc(strlen(appName) + strlen(appVer) + 2);
- if (!temp) {
- return (FALSE);
- }
+ if (!temp) {
+ return (FALSE);
+ }
- sprintf(temp, "%s %s", appName, appVer);
+ sprintf(temp, "%s %s", appName, appVer);
- label = gtk_label_new(temp);
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL);
- gtk_label_set_selectable(GTK_LABEL(label), FALSE);
- gtk_misc_set_padding(GTK_MISC(label), 6, 2);
+ label = gtk_label_new(temp);
+ gtk_widget_show(label);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL);
+ gtk_label_set_selectable(GTK_LABEL(label), FALSE);
+ gtk_misc_set_padding(GTK_MISC(label), 6, 2);
- free(temp);
+ free(temp);
- label = gtk_label_new("Application is starting...");
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_label_set_line_wrap(GTK_LABEL(label), FALSE);
- gtk_misc_set_padding(GTK_MISC(label), 6, 2);
+ label = gtk_label_new("Application is starting...");
+ gtk_widget_show(label);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_label_set_line_wrap(GTK_LABEL(label), FALSE);
+ gtk_misc_set_padding(GTK_MISC(label), 6, 2);
#if GTK_MINOR_VERSION > 5
- gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_START);
+ gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_START);
#endif
- message = label;
+ message = label;
- gtk_widget_show(window);
- return (TRUE);
+ gtk_widget_show(window);
+ return (TRUE);
}
/**
@@ -120,13 +120,13 @@ wCreateSplash(char *appName, char *appVer)
int
wSetSplashInfo(char *msg)
{
- if (!window) return FALSE;
- if (msg && message) {
- gtk_label_set_text(GTK_LABEL(message), msg);
- return TRUE;
- }
+ if (!window) { return FALSE; }
+ if (msg && message) {
+ gtk_label_set_text(GTK_LABEL(message), msg);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
/**
@@ -137,9 +137,9 @@ wSetSplashInfo(char *msg)
void
wDestroySplash(void)
{
- /* kill window */
- if (window) gtk_widget_destroy(window);
- window = NULL;
+ /* kill window */
+ if (window) { gtk_widget_destroy(window); }
+ window = NULL;
- return;
+ return;
}
diff --git a/app/wlib/gtklib/statusbar.c b/app/wlib/gtklib/statusbar.c
index a71d021..78d54ac 100644
--- a/app/wlib/gtklib/statusbar.c
+++ b/app/wlib/gtklib/statusbar.c
@@ -39,10 +39,10 @@
#include "gtkint.h"
struct wStatus_t {
- WOBJ_COMMON
- GtkWidget * labelWidget;
- const char * message;
- wWinPix_t labelWidth;
+ WOBJ_COMMON
+ GtkWidget * labelWidget;
+ const char * message;
+ wWinPix_t labelWidth;
};
/**
@@ -54,20 +54,20 @@ struct wStatus_t {
*/
void wStatusSetValue(
- wStatus_p b,
- const char * arg)
+ wStatus_p b,
+ const char * arg)
{
- if (b->widget == 0) {
- abort();
- }
+ if (b->widget == 0) {
+ abort();
+ }
- if (gtk_entry_get_max_length(GTK_ENTRY(b->labelWidget))<strlen(arg)) {
- gtk_entry_set_max_length(GTK_ENTRY(b->labelWidget), strlen(arg));
- gtk_entry_set_width_chars(GTK_ENTRY(b->labelWidget), strlen(arg));
- }
+ if (gtk_entry_get_max_length(GTK_ENTRY(b->labelWidget))<strlen(arg)) {
+ gtk_entry_set_max_length(GTK_ENTRY(b->labelWidget), strlen(arg));
+ gtk_entry_set_width_chars(GTK_ENTRY(b->labelWidget), strlen(arg));
+ }
- gtk_entry_set_text(GTK_ENTRY(b->labelWidget), wlibConvertInput(arg));
- gtk_widget_queue_draw (GTK_WIDGET(b->labelWidget));
+ gtk_entry_set_text(GTK_ENTRY(b->labelWidget), wlibConvertInput(arg));
+ gtk_widget_queue_draw (GTK_WIDGET(b->labelWidget));
}
/**
* Create a window for a simple text.
@@ -83,38 +83,37 @@ void wStatusSetValue(
*/
wStatus_p wStatusCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * labelStr,
- wWinPix_t width,
- const char *message)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * labelStr,
+ wWinPix_t width,
+ const char *message)
{
- 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_widget_set_sensitive(b->labelWidget, FALSE);
- GdkColor black = {0, 0x0000, 0x0000, 0x0000};
- gtk_widget_modify_text(b->labelWidget,GTK_STATE_INSENSITIVE,&black);
- 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;
+ wStatus_p b;
+ 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_widget_set_sensitive(b->labelWidget, FALSE);
+ GdkColor black = {0, 0x0000, 0x0000, 0x0000};
+ gtk_widget_modify_text(b->labelWidget,GTK_STATE_INSENSITIVE,&black);
+ 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;
}
/**
@@ -127,22 +126,22 @@ wStatus_p wStatusCreate(
wWinPix_t
wStatusGetWidth(const char *testString)
{
- GtkWidget *entry;
- GtkRequisition requisition;
+ GtkWidget *entry;
+ GtkRequisition requisition;
- entry = gtk_entry_new();
- g_object_ref_sink(entry);
+ 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_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_size_request(entry, &requisition);
- gtk_widget_destroy(entry);
- g_object_unref(entry);
+ gtk_widget_destroy(entry);
+ g_object_unref(entry);
- return (requisition.width);
+ return (requisition.width);
}
/**
@@ -153,49 +152,49 @@ wStatusGetWidth(const char *testString)
*/
wWinPix_t wStatusGetHeight(
- long flags)
+ long flags)
{
- GtkWidget * temp;
+ GtkWidget * temp;
- if (!(flags&COMBOBOX)) {
+ 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;
+ 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;
}
/**
@@ -207,9 +206,9 @@ wWinPix_t wStatusGetHeight(
*/
void wStatusSetWidth(
- wStatus_p b,
- wWinPix_t width)
+ wStatus_p b,
+ wWinPix_t width)
{
- b->labelWidth = width;
- gtk_widget_set_size_request(b->widget, width, -1);
+ b->labelWidth = width;
+ gtk_widget_set_size_request(b->widget, width, -1);
}
diff --git a/app/wlib/gtklib/sysinfo.c b/app/wlib/gtklib/sysinfo.c
new file mode 100644
index 0000000..eccd67f
--- /dev/null
+++ b/app/wlib/gtklib/sysinfo.c
@@ -0,0 +1,137 @@
+/** \file sysinfo.c
+ * Collect info about runtime environment
+*/
+
+/* XTrkCad - Model Railroad CAD
+ * Copyright (C) 2024 Martin Fischer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <wlib.h>
+#include "gtkint.h"
+
+
+static char *buffer;
+
+/**
+ * Return the path to a temporary directory. The directory is not created.
+ * The result is put into a buffer and is only valid immediately after the call.
+ *
+ * \return pointer to fully qualified directory path
+ */
+
+char *
+wGetTempPath()
+{
+ gchar const *tempDir = g_get_tmp_dir();
+ gchar *path;
+ gchar pidString[20];
+
+ g_snprintf(pidString, 20, "xtc%d", getpid());
+ path = g_build_path("/", tempDir, pidString, (char *)0);
+
+ if(buffer) {
+ g_free(buffer);
+ }
+
+ buffer = g_strdup(path);
+ g_free(path);
+
+ return(buffer);
+}
+
+/**
+ * Get the Windows version. This function uses the Windows ver command to
+ * retrieve the OS version. The result is put into a buffer and is only
+ * valid immediately after the call.
+ *
+ * \return buffer containing the zero terminated string
+ *
+ */
+
+char *
+wGetOSVersion()
+{
+ FILE* pPipe;
+ size_t bufferSize = 80;
+
+ if(buffer) {
+ free(buffer);
+ buffer = NULL;
+ }
+
+ buffer = malloc(bufferSize);
+// pPipe = _popen("cat /etc/*-release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g'", "r");
+ pPipe = popen("uname -sr", "r");
+
+ while (fgets(buffer, bufferSize, pPipe))
+ ;
+
+ if (buffer[strlen(buffer) -1] == '\n')
+ buffer[strlen(buffer) -1 ] = '\0';
+ pclose(pPipe);
+
+ return(buffer);
+}
+
+
+
+/**
+ * Get the name of the current user. The result is put into a buffer and is only
+ * valid immediately after the call.
+ *
+ * \return buffer containing the zero terminated string
+ *
+ */
+
+char *
+wGetUserID()
+{
+ const gchar *name;
+
+ name = g_get_user_name();
+
+ if(buffer) {
+ g_free(buffer);
+ }
+ buffer = g_strdup( name );
+ return(buffer);
+}
+
+/** Get the user's profile directory. Other than on UNIX Windows differentiates
+ * between the home directory and and the profile directory.
+ *
+ * \return pointer to the user's profile directory
+ */
+
+const char* wGetUserHomeRootDir(void)
+{
+ return(wGetUserHomeDir());
+}
+
+const char* wGetPlatformVersion()
+{
+ if(buffer) {
+ g_free(buffer);
+ }
+
+ buffer = g_strdup_printf("%d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version );
+ return(buffer);
+}
+
diff --git a/app/wlib/gtklib/text.c b/app/wlib/gtklib/text.c
index cb811b6..69a7ecc 100644
--- a/app/wlib/gtklib/text.c
+++ b/app/wlib/gtklib/text.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -37,12 +37,12 @@
#include "gtkint.h"
struct PrintData {
- wText_p tb;
- gint lines_per_page;
- gdouble font_size;
- gchar **lines;
- gint total_lines;
- gint total_pages;
+ wText_p tb;
+ gint lines_per_page;
+ gdouble font_size;
+ gchar **lines;
+ gint total_lines;
+ gint total_pages;
};
#define HEADER_HEIGHT 20.0
@@ -58,10 +58,10 @@ struct PrintData {
*/
struct wText_t {
- WOBJ_COMMON
- wWinPix_t width, height;
- int changed;
- GtkWidget *text;
+ WOBJ_COMMON
+ wWinPix_t width, height;
+ int changed;
+ GtkWidget *text;
};
/**
@@ -74,15 +74,15 @@ struct wText_t {
void wTextClear(wText_p bt)
{
- GtkTextBuffer *tb;
- tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
- gtk_text_buffer_set_text(tb, "", -1);
+ GtkTextBuffer *tb;
+ tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
+ gtk_text_buffer_set_text(tb, "", -1);
- if (bt->option & BO_READONLY) {
- gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE);
- }
+ if (bt->option & BO_READONLY) {
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE);
+ }
- bt->changed = FALSE;
+ bt->changed = FALSE;
}
/**
@@ -96,34 +96,34 @@ void wTextClear(wText_p bt)
void wTextAppend(wText_p bt,
const char *text)
{
- GtkTextBuffer *tb;
- GtkTextIter ti1;
- GtkTextMark *tm;
-
-
- if (bt->text == 0) {
- abort();
- }
-
- tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
- // convert to utf-8
- text = wlibConvertInput(text);
- // append to end of buffer
- gtk_text_buffer_get_end_iter(tb, &ti1);
- gtk_text_buffer_insert(tb, &ti1, text, -1);
-
- if ( bt->option & BT_TOP ) {
- // and scroll to start of text
- gtk_text_buffer_get_start_iter(tb, &ti1);
- } else {
- // and scroll to end of text
- gtk_text_buffer_get_end_iter(tb, &ti1);
- }
- tm = gtk_text_buffer_create_mark(tb, NULL, &ti1, TRUE );
- gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW(bt->text), tm );
- gtk_text_buffer_delete_mark( tb, tm );
-
- bt->changed = FALSE;
+ GtkTextBuffer *tb;
+ GtkTextIter ti1;
+ GtkTextMark *tm;
+
+
+ if (bt->text == 0) {
+ abort();
+ }
+
+ tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
+ // convert to utf-8
+ text = wlibConvertInput(text);
+ // append to end of buffer
+ gtk_text_buffer_get_end_iter(tb, &ti1);
+ gtk_text_buffer_insert(tb, &ti1, text, -1);
+
+ if ( bt->option & BT_TOP ) {
+ // and scroll to start of text
+ gtk_text_buffer_get_start_iter(tb, &ti1);
+ } else {
+ // and scroll to end of text
+ gtk_text_buffer_get_end_iter(tb, &ti1);
+ }
+ tm = gtk_text_buffer_create_mark(tb, NULL, &ti1, TRUE );
+ gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW(bt->text), tm );
+ gtk_text_buffer_delete_mark( tb, tm );
+
+ bt->changed = FALSE;
}
/**
@@ -138,21 +138,22 @@ void wTextAppend(wText_p bt,
static char *wlibGetText(wText_p bt)
{
- GtkTextBuffer *tb;
- GtkTextIter ti1, ti2;
- char *cp, *cp1, *res;
-
- if (bt->text == 0) {
- abort();
- }
-
- tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
- gtk_text_buffer_get_bounds(tb, &ti1, &ti2);
- cp = gtk_text_buffer_get_text(tb, &ti1, &ti2, FALSE);
- //cp1 = wlibConvertOutput(cp);
- res = strdup(cp);
- g_free(cp);
- return res;
+ GtkTextBuffer *tb;
+ GtkTextIter ti1, ti2;
+ char *cp, *res;
+ //char *cp1;
+
+ if (bt->text == 0) {
+ abort();
+ }
+
+ tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
+ gtk_text_buffer_get_bounds(tb, &ti1, &ti2);
+ cp = gtk_text_buffer_get_text(tb, &ti1, &ti2, FALSE);
+ //cp1 = wlibConvertOutput(cp);
+ res = strdup(cp);
+ g_free(cp);
+ return res;
}
/**
@@ -165,20 +166,20 @@ static char *wlibGetText(wText_p bt)
wBool_t wTextSave(wText_p bt, const char *fileName)
{
- FILE *f;
- char *cp;
- f = fopen(fileName, "w");
-
- if (f==NULL) {
- wNoticeEx(NT_ERROR, fileName, "Ok", NULL);
- return FALSE;
- }
-
- cp = wlibGetText(bt);
- fwrite(cp, 1, strlen(cp), f);
- free(cp);
- fclose(f);
- return TRUE;
+ FILE *f;
+ char *cp;
+ f = fopen(fileName, "w");
+
+ if (f==NULL) {
+ wNoticeEx(NT_ERROR, fileName, "Ok", NULL);
+ return FALSE;
+ }
+
+ cp = wlibGetText(bt);
+ fwrite(cp, 1, strlen(cp), f);
+ free(cp);
+ fclose(f);
+ return TRUE;
}
/**
@@ -196,28 +197,28 @@ begin_print(GtkPrintOperation *operation,
GtkPrintContext *context,
struct PrintData *pd)
{
- gchar *contents;
- gdouble height;
- contents = wlibGetText(pd->tb);
- pd->lines = g_strsplit(contents, "\n", 0);
- /* Count the total number of lines in the file. */
- /* ignore the header lines */
- pd->total_lines = 6;
-
- while (pd->lines[pd->total_lines] != NULL) {
- pd->total_lines++;
- }
-
- /* Based on the height of the page and font size, calculate how many lines can be
- * rendered on a single page. A padding of 3 is placed between lines as well.
- * Space for page header, table header and footer lines is subtracted from the total size
- */
- height = gtk_print_context_get_height(context) - (pd->font_size + 3) - 2 *
- (HEADER_HEIGHT + HEADER_GAP);
- pd->lines_per_page = floor(height / (pd->font_size + 3));
- pd->total_pages = (pd->total_lines - 1) / pd->lines_per_page + 1;
- gtk_print_operation_set_n_pages(operation, pd->total_pages);
- free(contents);
+ gchar *contents;
+ gdouble height;
+ contents = wlibGetText(pd->tb);
+ pd->lines = g_strsplit(contents, "\n", 0);
+ /* Count the total number of lines in the file. */
+ /* ignore the header lines */
+ pd->total_lines = 6;
+
+ while (pd->lines[pd->total_lines] != NULL) {
+ pd->total_lines++;
+ }
+
+ /* Based on the height of the page and font size, calculate how many lines can be
+ * rendered on a single page. A padding of 3 is placed between lines as well.
+ * Space for page header, table header and footer lines is subtracted from the total size
+ */
+ height = gtk_print_context_get_height(context) - (pd->font_size + 3) - 2 *
+ (HEADER_HEIGHT + HEADER_GAP);
+ pd->lines_per_page = floor(height / (pd->font_size + 3));
+ pd->total_pages = (pd->total_lines - 1) / pd->lines_per_page + 1;
+ gtk_print_operation_set_n_pages(operation, pd->total_pages);
+ free(contents);
}
/**
@@ -238,76 +239,76 @@ draw_page(GtkPrintOperation *operation,
gint page_nr,
struct PrintData *pd)
{
- cairo_t *cr;
- PangoLayout *layout;
- gdouble width, text_height, height;
- gint line, i, text_width, layout_height;
- PangoFontDescription *desc;
- gchar *page_str;
- cr = gtk_print_context_get_cairo_context(context);
- width = gtk_print_context_get_width(context);
- layout = gtk_print_context_create_pango_layout(context);
- desc = pango_font_description_from_string("Monospace");
- pango_font_description_set_size(desc, pd->font_size * PANGO_SCALE);
- /*
- * render the header line with document type parts list on left and
- * first line of layout title on right
- */
- pango_layout_set_font_description(layout, desc);
- pango_layout_set_text(layout, pd->lines[ 0 ], -1); // document type
- pango_layout_set_width(layout, -1);
- pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
- pango_layout_get_size(layout, NULL, &layout_height);
- text_height = (gdouble) layout_height / PANGO_SCALE;
- cairo_move_to(cr, 0, (HEADER_HEIGHT - text_height) / 2);
- pango_cairo_show_layout(cr, layout);
- pango_layout_set_text(layout, pd->lines[ 2 ], -1); // layout title
- pango_layout_get_size(layout, &text_width, NULL);
- pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
- cairo_move_to(cr, width - (text_width / PANGO_SCALE),
- (HEADER_HEIGHT - text_height) / 2);
- pango_cairo_show_layout(cr, layout);
- /* Render the column header */
- cairo_move_to(cr, 0, HEADER_HEIGHT + HEADER_GAP + pd->font_size + 3);
- pango_layout_set_text(layout, pd->lines[ 6 ], -1);
- pango_cairo_show_layout(cr, layout);
- cairo_rel_move_to(cr, 0, pd->font_size + 3);
- pango_layout_set_text(layout, pd->lines[ 7 ], -1);
- pango_cairo_show_layout(cr, layout);
- /* Render the page text with the specified font and size. */
- cairo_rel_move_to(cr, 0, pd->font_size + 3);
- line = page_nr * pd->lines_per_page + 8;
-
- for (i = 0; i < pd->lines_per_page && line < pd->total_lines; i++) {
- pango_layout_set_text(layout, pd->lines[line], -1);
- pango_cairo_show_layout(cr, layout);
- cairo_rel_move_to(cr, 0, pd->font_size + 3);
- line++;
- }
-
- /*
- * Render the footer line with date on the left and page number
- * on the right
- */
- pango_layout_set_text(layout, pd->lines[ 5 ], -1); // date
- pango_layout_set_width(layout, -1);
- pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
- pango_layout_get_size(layout, NULL, &layout_height);
- text_height = (gdouble) layout_height / PANGO_SCALE;
- height = gtk_print_context_get_height(context);
- cairo_move_to(cr, 0, height - ((HEADER_HEIGHT - text_height) / 2));
- pango_cairo_show_layout(cr, layout);
- page_str = g_strdup_printf(_("%d of %d"), page_nr + 1,
- pd->total_pages); // page number
- pango_layout_set_text(layout, page_str, -1);
- pango_layout_get_size(layout, &text_width, NULL);
- pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
- cairo_move_to(cr, width - (text_width / PANGO_SCALE),
- height - ((HEADER_HEIGHT - text_height) / 2));
- pango_cairo_show_layout(cr, layout);
- g_free(page_str);
- g_object_unref(layout);
- pango_font_description_free(desc);
+ cairo_t *cr;
+ PangoLayout *layout;
+ gdouble width, text_height, height;
+ gint line, i, text_width, layout_height;
+ PangoFontDescription *desc;
+ gchar *page_str;
+ cr = gtk_print_context_get_cairo_context(context);
+ width = gtk_print_context_get_width(context);
+ layout = gtk_print_context_create_pango_layout(context);
+ desc = pango_font_description_from_string("Monospace");
+ pango_font_description_set_size(desc, pd->font_size * PANGO_SCALE);
+ /*
+ * render the header line with document type parts list on left and
+ * first line of layout title on right
+ */
+ pango_layout_set_font_description(layout, desc);
+ pango_layout_set_text(layout, pd->lines[ 0 ], -1); // document type
+ pango_layout_set_width(layout, -1);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
+ pango_layout_get_size(layout, NULL, &layout_height);
+ text_height = (gdouble) layout_height / PANGO_SCALE;
+ cairo_move_to(cr, 0, (HEADER_HEIGHT - text_height) / 2);
+ pango_cairo_show_layout(cr, layout);
+ pango_layout_set_text(layout, pd->lines[ 2 ], -1); // layout title
+ pango_layout_get_size(layout, &text_width, NULL);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
+ cairo_move_to(cr, width - (text_width / PANGO_SCALE),
+ (HEADER_HEIGHT - text_height) / 2);
+ pango_cairo_show_layout(cr, layout);
+ /* Render the column header */
+ cairo_move_to(cr, 0, HEADER_HEIGHT + HEADER_GAP + pd->font_size + 3);
+ pango_layout_set_text(layout, pd->lines[ 6 ], -1);
+ pango_cairo_show_layout(cr, layout);
+ cairo_rel_move_to(cr, 0, pd->font_size + 3);
+ pango_layout_set_text(layout, pd->lines[ 7 ], -1);
+ pango_cairo_show_layout(cr, layout);
+ /* Render the page text with the specified font and size. */
+ cairo_rel_move_to(cr, 0, pd->font_size + 3);
+ line = page_nr * pd->lines_per_page + 8;
+
+ for (i = 0; i < pd->lines_per_page && line < pd->total_lines; i++) {
+ pango_layout_set_text(layout, pd->lines[line], -1);
+ pango_cairo_show_layout(cr, layout);
+ cairo_rel_move_to(cr, 0, pd->font_size + 3);
+ line++;
+ }
+
+ /*
+ * Render the footer line with date on the left and page number
+ * on the right
+ */
+ pango_layout_set_text(layout, pd->lines[ 5 ], -1); // date
+ pango_layout_set_width(layout, -1);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
+ pango_layout_get_size(layout, NULL, &layout_height);
+ text_height = (gdouble) layout_height / PANGO_SCALE;
+ height = gtk_print_context_get_height(context);
+ cairo_move_to(cr, 0, height - ((HEADER_HEIGHT - text_height) / 2));
+ pango_cairo_show_layout(cr, layout);
+ page_str = g_strdup_printf(_("%d of %d"), page_nr + 1,
+ pd->total_pages); // page number
+ pango_layout_set_text(layout, page_str, -1);
+ pango_layout_get_size(layout, &text_width, NULL);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
+ cairo_move_to(cr, width - (text_width / PANGO_SCALE),
+ height - ((HEADER_HEIGHT - text_height) / 2));
+ pango_cairo_show_layout(cr, layout);
+ g_free(page_str);
+ g_object_unref(layout);
+ pango_font_description_free(desc);
}
/**
@@ -324,8 +325,8 @@ end_print(GtkPrintOperation *operation,
GtkPrintContext *context,
struct PrintData *pd)
{
- g_strfreev(pd->lines);
- free(pd);
+ g_strfreev(pd->lines);
+ free(pd);
}
/**
@@ -341,47 +342,47 @@ end_print(GtkPrintOperation *operation,
*/
wBool_t wTextPrint(
- wText_p bt)
+ wText_p bt)
{
- GtkPrintOperation *operation;
- GtkWidget *dialog;
- GError *error = NULL;
- gint res;
- struct PrintData *data;
- /* Create a new print operation, applying saved print settings if they exist. */
- operation = gtk_print_operation_new();
- WlibApplySettings(operation);
- data = malloc(sizeof(struct PrintData));
- data->font_size = 10.0;
- data->tb = bt;
- g_signal_connect(G_OBJECT(operation), "begin_print",
- G_CALLBACK(begin_print), (gpointer) data);
- g_signal_connect(G_OBJECT(operation), "draw_page",
- G_CALLBACK(draw_page), (gpointer) data);
- g_signal_connect(G_OBJECT(operation), "end_print",
- G_CALLBACK(end_print), (gpointer) data);
- /* Run the default print operation that will print the selected file. */
- res = gtk_print_operation_run(operation,
- GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- GTK_WINDOW(gtkMainW->gtkwin), &error);
-
- /* If the print operation was accepted, save the new print settings. */
- if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
- WlibSaveSettings(operation);
- }
- /* Otherwise, report that the print operation has failed. */
- else if (error) {
- dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%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;
+ GtkPrintOperation *operation;
+ GtkWidget *dialog;
+ GError *error = NULL;
+ gint res;
+ struct PrintData *data;
+ /* Create a new print operation, applying saved print settings if they exist. */
+ operation = gtk_print_operation_new();
+ WlibApplySettings(operation);
+ data = malloc(sizeof(struct PrintData));
+ data->font_size = 10.0;
+ data->tb = bt;
+ g_signal_connect(G_OBJECT(operation), "begin_print",
+ G_CALLBACK(begin_print), (gpointer) data);
+ g_signal_connect(G_OBJECT(operation), "draw_page",
+ G_CALLBACK(draw_page), (gpointer) data);
+ g_signal_connect(G_OBJECT(operation), "end_print",
+ G_CALLBACK(end_print), (gpointer) data);
+ /* Run the default print operation that will print the selected file. */
+ res = gtk_print_operation_run(operation,
+ GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ GTK_WINDOW(gtkMainW->gtkwin), &error);
+
+ /* If the print operation was accepted, save the new print settings. */
+ if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
+ WlibSaveSettings(operation);
+ }
+ /* Otherwise, report that the print operation has failed. */
+ else if (error) {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%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;
}
@@ -394,10 +395,10 @@ wBool_t wTextPrint(
int wTextGetSize(wText_p bt)
{
- char *cp = wlibGetText(bt);
- int len = strlen(cp);
- free(cp);
- return len + 1;
+ char *cp = wlibGetText(bt);
+ int len = strlen(cp);
+ free(cp);
+ return len + 1;
}
/**
@@ -411,15 +412,15 @@ int wTextGetSize(wText_p bt)
void wTextGetText(wText_p bt, char *text, int len)
{
- char *cp;
- cp = wlibGetText(bt);
- strncpy(text, cp, len);
+ char *cp;
+ cp = wlibGetText(bt);
+ strncpy(text, cp, len);
- if (len > 0) {
- text[len - 1] = '\0';
- }
+ if (len > 0) {
+ text[len - 1] = '\0';
+ }
- free(cp);
+ free(cp);
}
/**
@@ -432,13 +433,13 @@ void wTextGetText(wText_p bt, char *text, int len)
void wTextSetReadonly(wText_p bt, wBool_t ro)
{
- gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), !ro);
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), !ro);
- if (ro) {
- bt->option |= BO_READONLY;
- } else {
- bt->option &= ~BO_READONLY;
- }
+ if (ro) {
+ bt->option |= BO_READONLY;
+ } else {
+ bt->option &= ~BO_READONLY;
+ }
}
/**
@@ -450,7 +451,7 @@ void wTextSetReadonly(wText_p bt, wBool_t ro)
wBool_t wTextGetModified(wText_p bt)
{
- return bt->changed;
+ return bt->changed;
}
/**
@@ -464,9 +465,9 @@ wBool_t wTextGetModified(wText_p bt)
void wTextSetSize(wText_p bt, wWinPix_t w, wWinPix_t h)
{
- gtk_widget_set_size_request(bt->widget, w, h);
- bt->w = w;
- bt->h = h;
+ gtk_widget_set_size_request(bt->widget, w, h);
+ bt->w = w;
+ bt->h = h;
}
/**
@@ -481,11 +482,12 @@ void wTextSetSize(wText_p bt, wWinPix_t w, wWinPix_t h)
* \return
*/
-void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols, wWinPix_t *width,
+void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols,
+ wWinPix_t *width,
wWinPix_t *height)
{
- *width = rows * 7;
- *height = cols * 14;
+ *width = rows * 7;
+ *height = cols * 14;
}
/**
@@ -498,7 +500,7 @@ void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols, wWinPix_t *wid
void wTextSetPosition(wText_p bt, int pos)
{
- /* TODO TextSetPosition */
+ /* TODO TextSetPosition */
}
/**
@@ -511,11 +513,11 @@ void wTextSetPosition(wText_p bt, int pos)
static void textChanged(GtkWidget *widget, wText_p bt)
{
- if (bt == 0) {
- return;
- }
+ if (bt == 0) {
+ return;
+ }
- bt->changed = TRUE;
+ bt->changed = TRUE;
}
/**
@@ -544,61 +546,61 @@ wTextCreate(wWin_p parent,
wWinPix_t width,
wWinPix_t height)
{
- wText_p bt;
- GtkTextBuffer *tb;
- // create the widget
- bt = wlibAlloc(parent, B_MULTITEXT, x, y, labelStr, sizeof *bt, NULL);
- bt->width = width;
- bt->height = height;
- bt->option = option;
- wlibComputePos((wControl_p)bt);
- // create a scroll window with scroll bars that are automatically created
- bt->widget = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bt->widget),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- // create a text view and place it inside the scroll widget
- bt->text = gtk_text_view_new();
-
- if (bt->text == 0) {
- abort();
- }
-
- gtk_container_add(GTK_CONTAINER(bt->widget), bt->text);
- // get the text buffer and add a bold tag to it
- tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
- gtk_text_buffer_create_tag(tb, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
-
- // this seems to assume some fixed size fonts, not really helpful
- if (option&BT_CHARUNITS) {
- width *= 7;
- height *= 14;
- }
-
- // show the widgets
- gtk_widget_show(bt->text);
- gtk_widget_show(bt->widget);
- // set the size???
- gtk_widget_set_size_request(GTK_WIDGET(bt->widget),
- width+15/*requisition.width*/, height);
-
- // configure read-only mode
- if (bt->option&BO_READONLY) {
- gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE);
- gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(bt->text), FALSE);
- }
-
- if (labelStr) {
- bt->labelW = wlibAddLabel((wControl_p)bt, labelStr);
- }
-
- wlibAddHelpString(bt->widget, helpStr);
- gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(bt->text), GTK_WRAP_WORD);
- g_signal_connect(G_OBJECT(tb), "changed", G_CALLBACK(textChanged), bt);
- // place the widget in a fixed position of the parent
- gtk_fixed_put(GTK_FIXED(parent->widget), bt->widget, bt->realX, bt->realY);
- wlibControlGetSize((wControl_p)bt);
- wlibAddButton((wControl_p)bt);
- // done, return the finished widget
- return bt;
+ wText_p bt;
+ GtkTextBuffer *tb;
+ // create the widget
+ bt = wlibAlloc(parent, B_MULTITEXT, x, y, labelStr, sizeof *bt, NULL);
+ bt->width = width;
+ bt->height = height;
+ bt->option = option;
+ wlibComputePos((wControl_p)bt);
+ // create a scroll window with scroll bars that are automatically created
+ bt->widget = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bt->widget),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ // create a text view and place it inside the scroll widget
+ bt->text = gtk_text_view_new();
+
+ if (bt->text == 0) {
+ abort();
+ }
+
+ gtk_container_add(GTK_CONTAINER(bt->widget), bt->text);
+ // get the text buffer and add a bold tag to it
+ tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text));
+ gtk_text_buffer_create_tag(tb, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
+
+ // this seems to assume some fixed size fonts, not really helpful
+ if (option&BT_CHARUNITS) {
+ width *= 7;
+ height *= 14;
+ }
+
+ // show the widgets
+ gtk_widget_show(bt->text);
+ gtk_widget_show(bt->widget);
+ // set the size???
+ gtk_widget_set_size_request(GTK_WIDGET(bt->widget),
+ width+15/*requisition.width*/, height);
+
+ // configure read-only mode
+ if (bt->option&BO_READONLY) {
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE);
+ gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(bt->text), FALSE);
+ }
+
+ if (labelStr) {
+ bt->labelW = wlibAddLabel((wControl_p)bt, labelStr);
+ }
+
+ wlibAddHelpString(bt->widget, helpStr);
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(bt->text), GTK_WRAP_WORD);
+ g_signal_connect(G_OBJECT(tb), "changed", G_CALLBACK(textChanged), bt);
+ // place the widget in a fixed position of the parent
+ gtk_fixed_put(GTK_FIXED(parent->widget), bt->widget, bt->realX, bt->realY);
+ wlibControlGetSize((wControl_p)bt);
+ wlibAddButton((wControl_p)bt);
+ // done, return the finished widget
+ return bt;
}
diff --git a/app/wlib/gtklib/timer.c b/app/wlib/gtklib/timer.c
index 80c71fb..9e70458 100644
--- a/app/wlib/gtklib/timer.c
+++ b/app/wlib/gtklib/timer.c
@@ -52,14 +52,14 @@ static setTriggerCallback_p triggerFunc = NULL;
*/
static gint doAlarm(
- gpointer data)
+ gpointer data)
{
- wAlarmCallBack_p func = (wAlarmCallBack_p)data;
+ wAlarmCallBack_p func = (wAlarmCallBack_p)data;
- func();
+ func();
- alarmTimer = 0;
- return FALSE;
+ alarmTimer = 0;
+ return FALSE;
}
/**
@@ -70,34 +70,34 @@ static gint doAlarm(
*/
void wAlarm(
- long count,
- wAlarmCallBack_p func) /* milliseconds */
+ long count,
+ wAlarmCallBack_p func) /* milliseconds */
{
- gtkPaused = TRUE;
+ gtkPaused = TRUE;
- if (alarmTimer) {
- g_source_remove(alarmTimer);
- }
+ if (alarmTimer) {
+ g_source_remove(alarmTimer);
+ }
- alarmTimer = g_timeout_add(count, doAlarm, (void *)(GSourceFunc)func);
+ alarmTimer = g_timeout_add(count, doAlarm, (void *)(GSourceFunc)func);
}
static void doTrigger(void)
{
- if (triggerControl && triggerFunc) {
- triggerFunc(triggerControl);
- triggerFunc = NULL;
- triggerControl = NULL;
- }
+ if (triggerControl && triggerFunc) {
+ triggerFunc(triggerControl);
+ triggerFunc = NULL;
+ triggerControl = NULL;
+ }
}
void wlibSetTrigger(
- wControl_p b,
- setTriggerCallback_p trigger)
+ wControl_p b,
+ setTriggerCallback_p trigger)
{
- triggerControl = b;
- triggerFunc = trigger;
- wAlarm(500, doTrigger);
+ triggerControl = b;
+ triggerFunc = trigger;
+ wAlarm(500, doTrigger);
}
/**
@@ -107,27 +107,28 @@ void wlibSetTrigger(
*/
void wPause(
- long count) /* milliseconds */
+ long count) /* milliseconds */
{
- while (gtk_events_pending())
- gtk_main_iteration(); //Allow GTK to finish before pausing
-
- struct timeval timeout;
- sigset_t signal_mask;
- sigset_t oldsignal_mask;
- gdk_display_sync(gdk_display_get_default());
- timeout.tv_sec = count/1000;
- timeout.tv_usec = (count%1000)*1000;
- sigemptyset(&signal_mask);
- sigaddset(&signal_mask, SIGIO);
- sigaddset(&signal_mask, SIGALRM);
- sigprocmask(SIG_BLOCK, &signal_mask, &oldsignal_mask);
-
- if (select(0, NULL, NULL, NULL, &timeout) == -1) {
- perror("wPause:select");
- }
-
- sigprocmask(SIG_BLOCK, &oldsignal_mask, NULL);
+ while (gtk_events_pending()) {
+ gtk_main_iteration(); //Allow GTK to finish before pausing
+ }
+
+ struct timeval timeout;
+ sigset_t signal_mask;
+ sigset_t oldsignal_mask;
+ gdk_display_sync(gdk_display_get_default());
+ timeout.tv_sec = count/1000;
+ timeout.tv_usec = (count%1000)*1000;
+ sigemptyset(&signal_mask);
+ sigaddset(&signal_mask, SIGIO);
+ sigaddset(&signal_mask, SIGALRM);
+ sigprocmask(SIG_BLOCK, &signal_mask, &oldsignal_mask);
+
+ if (select(0, NULL, NULL, NULL, &timeout) == -1) {
+ perror("wPause:select");
+ }
+
+ sigprocmask(SIG_BLOCK, &oldsignal_mask, NULL);
}
/**
@@ -139,9 +140,9 @@ void wPause(
unsigned long wGetTimer(void)
{
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday(&tv, &tz);
- return (tv.tv_sec-startTime.tv_sec+1) * 1000 + tv.tv_usec /1000;
+ struct timeval tv;
+ struct timezone tz;
+
+ gettimeofday(&tv, &tz);
+ return (tv.tv_sec-startTime.tv_sec+1) * 1000 + tv.tv_usec /1000;
}
diff --git a/app/wlib/gtklib/tooltip.c b/app/wlib/gtklib/tooltip.c
index cd12d0a..75c8870 100644
--- a/app/wlib/gtklib/tooltip.c
+++ b/app/wlib/gtklib/tooltip.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -54,11 +54,11 @@ static wBool_t balloonVisible = FALSE;
/**
* Hide the currently displayed Balloon Help.
*/
-
+
void
wlibHelpHideBalloon()
{
- wControlSetBalloon( balloonB, 0, 0, NULL );
+ wControlSetBalloon( balloonB, 0, 0, NULL );
}
/**
@@ -70,7 +70,7 @@ wlibHelpHideBalloon()
void wSetBalloonHelp( wBalloonHelp_t * bh )
{
- balloonHelpStrings = bh;
+ balloonHelpStrings = bh;
}
/**
@@ -82,7 +82,7 @@ void wSetBalloonHelp( wBalloonHelp_t * bh )
void wEnableBalloonHelp( int enable )
{
- enableBalloonHelp = enable;
+ enableBalloonHelp = enable;
}
/**
@@ -93,10 +93,10 @@ void wEnableBalloonHelp( int enable )
*/
void wControlSetHelp(
- wControl_p b,
- const char * help )
+ wControl_p b,
+ const char * help )
{
- wControlSetBalloonText( b, help );
+ wControlSetBalloonText( b, help );
}
/**
@@ -107,13 +107,13 @@ void wControlSetHelp(
*/
void wControlSetBalloonText(
- wControl_p b,
- const char * label )
+ wControl_p b,
+ const char * label )
{
- assert(b->widget != NULL);
+ assert(b->widget != NULL);
- gtk_widget_set_tooltip_text( b->widget, label );
+ gtk_widget_set_tooltip_text( b->widget, label );
}
/**
@@ -128,93 +128,93 @@ void wControlSetBalloonText(
* \return
*/
-void wControlSetBalloon( wControl_p b, wWinPix_t dx, wWinPix_t dy, const char * msg )
+void wControlSetBalloon( wControl_p b, wWinPix_t dx, wWinPix_t dy,
+ const char * msg )
{
- PangoLayout * layout;
-
- gint x, y;
- gint w, h;
- wWinPix_t xx, yy;
- const char * msgConverted;
- GtkRequisition size;
-
- /* return if there is nothing to do */
- if (balloonVisible && balloonB == b &&
- balloonDx == dx && balloonDy == dy && msg != NULL && !balloonMsg[0])
- if (strcmp(msg,balloonMsg)==0)
- return;
-
- /* hide the tooltip */
- if ( msg == NULL ) {
- if ( balloonF != NULL && balloonVisible) {
- gtk_widget_hide( balloonF );
- balloonVisible = FALSE;
- }
- balloonMsg[0] = '\0';
- return;
- }
- msgConverted = wlibConvertInput(msg);
-
- if ( balloonF == NULL ) {
+ gint x, y;
+ gint w, h;
+ wWinPix_t xx, yy;
+ const char * msgConverted;
+ GtkRequisition size;
+
+ /* return if there is nothing to do */
+ if (balloonVisible && balloonB == b &&
+ balloonDx == dx && balloonDy == dy && msg != NULL && !balloonMsg[0])
+ if (strcmp(msg,balloonMsg)==0) {
+ return;
+ }
+
+ /* hide the tooltip */
+ if ( msg == NULL ) {
+ if ( balloonF != NULL && balloonVisible) {
+ gtk_widget_hide( balloonF );
+ balloonVisible = FALSE;
+ }
+ balloonMsg[0] = '\0';
+ return;
+ }
+ msgConverted = wlibConvertInput(msg);
+
+ if ( balloonF == NULL ) {
//GtkWidget *alignment;
- GdkColor color;
- color.red = 0x00C5 * 65536/255;
- color.green = 0x006F * 65536/255;
- color.blue = 0x0078 * 65536/255;
-
- 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);
- gtk_widget_modify_bg(GTK_WIDGET(balloonF), GTK_STATE_NORMAL, &color);
-
+ GdkColor color;
+ color.red = 0x00C5 * 65536/255;
+ color.green = 0x006F * 65536/255;
+ color.blue = 0x0078 * 65536/255;
+
+ 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);
+ gtk_widget_modify_bg(GTK_WIDGET(balloonF), GTK_STATE_NORMAL, &color);
+
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_all( balloonPI );
- }
- gtk_label_set_text( GTK_LABEL(balloonPI), msgConverted );
-
- balloonDx = dx;
- balloonDy = dy;
- balloonB = b;
- snprintf(balloonMsg, sizeof(balloonMsg), "%s", msg);
- gtk_widget_get_requisition(balloonPI, &size );
- w = size.width;
- h = size.height;
-
- gtk_window_get_position( GTK_WINDOW(b->parent->gtkwin), &x, &y);
-
- x += b->realX + dx;
- y += b->realY + b->h - dy;
+
+ balloonPI = gtk_label_new(msgConverted);
+ gtk_container_add( GTK_CONTAINER(alignment), balloonPI );
+ gtk_widget_show_all( balloonPI );
+ }
+ gtk_label_set_text( GTK_LABEL(balloonPI), msgConverted );
+
+ balloonDx = dx;
+ balloonDy = dy;
+ balloonB = b;
+ snprintf(balloonMsg, sizeof(balloonMsg), "%s", msg);
+ gtk_widget_get_requisition(balloonPI, &size );
+ w = size.width;
+ h = size.height;
+
+ gtk_window_get_position( GTK_WINDOW(b->parent->gtkwin), &x, &y);
+
+ x += b->realX + dx;
+ y += b->realY + b->h - dy;
#ifdef __linux__
- y += 7; // balloon popup overlaps the control
+ y += 7; // balloon popup overlaps the control
#endif
- xx = gdk_screen_width();
- yy = gdk_screen_height();
- if ( x < 0 ) {
- x = 0;
- } else if ( x+w > xx ) {
- x = xx - w;
- }
- if ( y < 0 ) {
- y = 0;
- } else if ( y+h > yy ) {
- y = yy - h ;
- }
- gtk_window_move( GTK_WINDOW( balloonF ), x, y );
- gtk_widget_show_all( balloonF );
- gtk_widget_show( balloonPI );
-
- balloonVisible = TRUE;
+ xx = gdk_screen_width();
+ yy = gdk_screen_height();
+ if ( x < 0 ) {
+ x = 0;
+ } else if ( x+w > xx ) {
+ x = xx - w;
+ }
+ if ( y < 0 ) {
+ y = 0;
+ } else if ( y+h > yy ) {
+ y = yy - h ;
+ }
+ gtk_window_move( GTK_WINDOW( balloonF ), x, y );
+ gtk_widget_show_all( balloonF );
+ gtk_widget_show( balloonPI );
+
+ balloonVisible = TRUE;
}
/**
@@ -232,36 +232,41 @@ void wBalloonHelpUpdate( void )
*/
void wlibAddHelpString(
- GtkWidget * widget,
- const char * helpStr )
+ GtkWidget * widget,
+ const char * helpStr )
{
- char *string;
- char *wAppName = wlibGetAppName();
- wBalloonHelp_t * bhp;
-
- if (helpStr==NULL || *helpStr==0)
- return;
- if ( balloonHelpStrings == NULL )
- return;
-
- // search for the helpStr, bhp points to the entry when found
- for ( bhp = balloonHelpStrings; bhp->name && strcmp(bhp->name,helpStr) != 0; bhp++ )
- ;
-
- if (listMissingHelpStrings && !bhp->name) {
- printf( "Missing Help String: %s\n", helpStr );
- return;
- }
-
- string = malloc( strlen(wAppName) + 5 + strlen(helpStr) + 1 );
- sprintf( string, "%sHelp/%s", wAppName, helpStr );
-
- if(bhp->value)
+ char *string;
+ char *wAppName = wlibGetAppName();
+ wBalloonHelp_t * bhp;
+
+ if (helpStr==NULL || *helpStr==0) {
+ return;
+ }
+ if ( balloonHelpStrings == NULL ) {
+ return;
+ }
+
+ // search for the helpStr, bhp points to the entry when found
+ for ( bhp = balloonHelpStrings; bhp->name
+ && strcmp(bhp->name,helpStr) != 0; bhp++ )
+ ;
+
+ if (listMissingHelpStrings && !bhp->name) {
+ printf( "Missing Help String: %s\n", helpStr );
+ return;
+ }
+
+ string = malloc( strlen(wAppName) + 5 + strlen(helpStr) + 1 );
+ sprintf( string, "%sHelp/%s", wAppName, helpStr );
+
+ if(bhp->value) {
gtk_widget_set_tooltip_text( widget, wlibConvertInput(_(bhp->value)) );
+ }
- g_object_set_data( G_OBJECT( widget ), HELPDATAKEY, string );
+ g_object_set_data( G_OBJECT( widget ), HELPDATAKEY, string );
- if (listHelpStrings)
- printf( "HELPSTR - %s\n", string );
+ if (listHelpStrings) {
+ printf( "HELPSTR - %s\n", string );
+ }
}
diff --git a/app/wlib/gtklib/treeview.c b/app/wlib/gtklib/treeview.c
index e8e0625..b3f2d77 100644
--- a/app/wlib/gtklib/treeview.c
+++ b/app/wlib/gtklib/treeview.c
@@ -53,7 +53,7 @@
int
wTreeViewGetCount(wList_p b)
{
- return b->count;
+ return b->count;
}
/**
@@ -65,9 +65,9 @@ wTreeViewGetCount(wList_p b)
void
wTreeViewClear(wList_p b)
{
- assert(b != NULL);
+ assert(b != NULL);
- wlibListStoreClear(b->listStore);
+ wlibListStoreClear(b->listStore);
}
/**
@@ -81,15 +81,15 @@ wTreeViewClear(wList_p b)
void *
wTreeViewGetItemContext(wList_p b, int row)
{
- wListItem_p id_p;
+ wListItem_p id_p;
- id_p = wlibListItemGet(b->listStore, row, NULL);
+ id_p = wlibListItemGet(b->listStore, row, NULL);
- if (id_p) {
- return id_p->itemData;
- } else {
- return NULL;
- }
+ if (id_p) {
+ return id_p->itemData;
+ } else {
+ return NULL;
+ }
}
/**
@@ -101,11 +101,11 @@ wTreeViewGetItemContext(wList_p b, int row)
*/
wIndex_t wListGetIndex(
- wList_p b)
+ wList_p b)
{
- assert(b!=NULL);
+ assert(b!=NULL);
- return b->last;
+ return b->last;
}
/**
@@ -119,48 +119,48 @@ wIndex_t wListGetIndex(
void
wlibTreeViewSetSelected(wList_p b, int index)
{
- GtkTreeSelection *sel;
- GtkTreeIter iter;
+ GtkTreeSelection *sel;
+ GtkTreeIter iter;
- wListItem_p id_p;
+ wListItem_p id_p;
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->treeView));
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->treeView));
- if (gtk_tree_selection_count_selected_rows(sel)) {
+ if (gtk_tree_selection_count_selected_rows(sel)) {
int inx;
-
- gtk_tree_selection_unselect_all(sel);
- // and synchronize the internal data structures
- wTreeViewGetCount(b);
+ gtk_tree_selection_unselect_all(sel);
- for (inx=0; inx<b->count; inx++) {
- id_p = wlibListItemGet(b->listStore, inx, NULL);
- id_p->selected = FALSE;
- }
- }
+ // and synchronize the internal data structures
+ wTreeViewGetCount(b);
- if (index != -1) {
+ for (inx=0; inx<b->count; inx++) {
+ id_p = wlibListItemGet(b->listStore, inx, NULL);
+ id_p->selected = FALSE;
+ }
+ }
+
+ if (index != -1) {
gint childs;
-
+
childs = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(b->listStore),
- NULL );
+ NULL );
if(index < childs) {
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore),
- &iter,
- NULL,
- index);
+ &iter,
+ NULL,
+ index);
gtk_tree_selection_select_iter(sel,
- &iter);
+ &iter);
id_p = wlibListItemGet(b->listStore, index, NULL);
-
+
if (id_p) {
id_p->selected = TRUE;
}
- }
- }
+ }
+ }
}
/**
@@ -175,35 +175,37 @@ wlibTreeViewSetSelected(wList_p b, int index)
GtkWidget *
wlibNewTreeView(GtkListStore *ls, int showTitles, int multiSelection)
{
- GtkWidget *treeView;
- GtkTreeSelection *sel;
- assert(ls != NULL);
+ GtkWidget *treeView;
+ GtkTreeSelection *sel;
+ assert(ls != NULL);
- /* create and configure the tree view */
- treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), showTitles);
+ /* create and configure the tree view */
+ treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), showTitles);
- /* set up selection handling */
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
- gtk_tree_selection_set_mode(sel,
- (multiSelection)?GTK_SELECTION_MULTIPLE:GTK_SELECTION_BROWSE);
+ /* set up selection handling */
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
+ gtk_tree_selection_set_mode(sel,
+ (multiSelection)?GTK_SELECTION_MULTIPLE:GTK_SELECTION_BROWSE);
- return (treeView);
+ return (treeView);
}
+#if 0
static int changeListColumnWidth(
- GtkTreeViewColumn * column,
- void * width)
+ GtkTreeViewColumn * column,
+ void * width)
{
- //wList_p bl = (wList_p)data;
+ //wList_p bl = (wList_p)data;
- //if (bl->recursion)
- //return 0;
- //if ( col >= 0 && col < bl->colCnt )
- //bl->colWidths[col] = width;
- return 0;
+ //if (bl->recursion)
+ //return 0;
+ //if ( col >= 0 && col < bl->colCnt )
+ //bl->colWidths[col] = width;
+ return 0;
}
+#endif
/**
* Create and initialize a column in treeview. Initially all columns are
@@ -220,17 +222,17 @@ static void
wlibAddColumn(GtkWidget *tv, int visibility, GtkCellRenderer *renderer,
char *attribute, int value)
{
- GtkTreeViewColumn *column;
+ GtkTreeViewColumn *column;
- column = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start(column,
- renderer,
- TRUE);
- gtk_tree_view_column_add_attribute(column, renderer, attribute, value);
- gtk_tree_view_column_set_visible(column, visibility);
- gtk_tree_view_column_set_resizable(column, TRUE);
+ column = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start(column,
+ renderer,
+ TRUE);
+ gtk_tree_view_column_add_attribute(column, renderer, attribute, value);
+ gtk_tree_view_column_set_visible(column, visibility);
+ gtk_tree_view_column_set_resizable(column, TRUE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
// g_signal_connect( column, "notify::width", G_CALLBACK(changeListColumnWidth), tv );
}
@@ -247,22 +249,22 @@ wlibAddColumn(GtkWidget *tv, int visibility, GtkCellRenderer *renderer,
int
wlibTreeViewAddColumns(GtkWidget *tv, int count)
{
- GtkCellRenderer *renderer;
- int i;
+ GtkCellRenderer *renderer;
+ int i;
- assert(tv != NULL);
- renderer = gtk_cell_renderer_pixbuf_new();
- /* first visible column is used for bitmaps */
- wlibAddColumn(tv, FALSE, renderer, "pixbuf", LISTCOL_BITMAP);
+ assert(tv != NULL);
+ renderer = gtk_cell_renderer_pixbuf_new();
+ /* first visible column is used for bitmaps */
+ wlibAddColumn(tv, FALSE, renderer, "pixbuf", LISTCOL_BITMAP);
- renderer = gtk_cell_renderer_text_new();
+ renderer = gtk_cell_renderer_text_new();
- /* add renderers to all columns */
- for (i = 0; i < count; i++) {
- wlibAddColumn(tv, TRUE, renderer, "text", i + LISTCOL_TEXT);
- }
+ /* add renderers to all columns */
+ for (i = 0; i < count; i++) {
+ wlibAddColumn(tv, TRUE, renderer, "text", i + LISTCOL_TEXT);
+ }
- return i;
+ return i;
}
/**
@@ -276,26 +278,26 @@ wlibTreeViewAddColumns(GtkWidget *tv, int count)
int
wlibAddColumnTitles(GtkWidget *tv, const char **titles)
{
- int i = 0;
-
- assert(tv != NULL);
-
- if (titles) {
- while (*titles) {
- GtkTreeViewColumn *column;
-
- column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), i + 1);
-
- if (column) {
- gtk_tree_view_column_set_title(column, titles[ i ]);
- i++;
- } else {
- break;
- }
- }
- }
-
- return i;
+ int i = 0;
+
+ assert(tv != NULL);
+
+ if (titles) {
+ while (*titles) {
+ GtkTreeViewColumn *column;
+
+ column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), i + 1);
+
+ if (column) {
+ gtk_tree_view_column_set_title(column, titles[ i ]);
+ i++;
+ } else {
+ break;
+ }
+ }
+ }
+
+ return i;
}
/**
@@ -313,20 +315,20 @@ int
wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf,
wListItem_p userData)
{
- GtkListStore *listStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(
- tv)));
+ GtkListStore *listStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(
+ tv)));
+
+ wlibListStoreAddData(listStore, pixbuf, cols, userData);
- wlibListStoreAddData(listStore, pixbuf, cols, userData);
+ if (pixbuf) {
+ GtkTreeViewColumn *column;
- if (pixbuf) {
- GtkTreeViewColumn *column;
-
- // first column in list store has pixbuf
- column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), 0);
- gtk_tree_view_column_set_visible(column,
- TRUE);
- }
- return 0;
+ // first column in list store has pixbuf
+ column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), 0);
+ gtk_tree_view_column_set_visible(column,
+ TRUE);
+ }
+ return 0;
}
@@ -344,28 +346,28 @@ wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf,
void
wlibTreeViewAddRow(wList_p b, char *label, wIcon_p bm, wListItem_p id_p)
{
- GtkAdjustment *adj;
- GdkPixbuf *pixbuf = NULL;
+ GtkAdjustment *adj;
+ GdkPixbuf *pixbuf = NULL;
- if (bm) {
- pixbuf = wlibMakePixbuf(bm);
- }
+ if (bm) {
+ pixbuf = wlibMakePixbuf(bm);
+ }
- wlibTreeViewAddData(b->treeView, b->colCnt, (char *)label, pixbuf, id_p);
+ wlibTreeViewAddData(b->treeView, b->colCnt, (char *)label, pixbuf, id_p);
- adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(b->widget));
+ adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(b->widget));
- if (gtk_adjustment_get_upper(adj) < gtk_adjustment_get_step_increment(adj) *
- (b->count+1)) {
- gtk_adjustment_set_upper(adj,
- gtk_adjustment_get_upper(adj) +
- gtk_adjustment_get_step_increment(adj));
- gtk_adjustment_changed(adj);
- }
+ if (gtk_adjustment_get_upper(adj) < gtk_adjustment_get_step_increment(adj) *
+ (b->count+1)) {
+ gtk_adjustment_set_upper(adj,
+ gtk_adjustment_get_upper(adj) +
+ gtk_adjustment_get_step_increment(adj));
+ gtk_adjustment_changed(adj);
+ }
- b->last = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW(
- b->treeView)),
- NULL);
+ b->last = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW(
+ b->treeView)),
+ NULL);
}
@@ -390,36 +392,34 @@ changeSelection(GtkTreeSelection *selection,
gboolean path_currently_selected,
gpointer data)
{
- GtkTreeIter iter;
- GValue value = { 0 };
- wListItem_p id_p = NULL;
- wList_p bl = (wList_p)data;
- int row;
- char *text;
+ GtkTreeIter iter;
+ GValue value = { 0 };
+ wListItem_p id_p = NULL;
+ wList_p bl = (wList_p)data;
+ int row;
+ char *text;
- text = gtk_tree_path_to_string(path);
- row = atoi(text);
- g_free(text);
+ text = gtk_tree_path_to_string(path);
+ row = atoi(text);
+ g_free(text);
- gtk_tree_model_get_iter(model, &iter, path);
- gtk_tree_model_get_value(model, &iter, LISTCOL_DATA, &value);
+ gtk_tree_model_get_iter(model, &iter, path);
+ gtk_tree_model_get_value(model, &iter, LISTCOL_DATA, &value);
- id_p = g_value_get_pointer(&value);
- id_p->selected = !path_currently_selected;
+ id_p = g_value_get_pointer(&value);
+ id_p->selected = !path_currently_selected;
- if (id_p->selected) {
- bl->last = row;
+ bl->last = row;
- if (bl->valueP) {
- *bl->valueP = row;
- }
+ if (bl->valueP) {
+ *bl->valueP = row;
+ }
- if (bl->action) {
- bl->action(row, id_p->label, 1, bl->data, id_p->itemData);
- }
- }
+ if (bl->action) {
+ bl->action(row, id_p->label, id_p->selected, bl->data, id_p->itemData);
+ }
- return TRUE;
+ return TRUE;
}
/**
@@ -444,88 +444,88 @@ changeSelection(GtkTreeSelection *selection,
*/
wList_p wListCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- int colCnt,
- wWinPix_t * colWidths,
- wBool_t * colRightJust,
- const char ** colTitles,
- long *valueP,
- wListCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ int colCnt,
+ wWinPix_t * colWidths,
+ wBool_t * colRightJust,
+ const char ** colTitles,
+ long *valueP,
+ wListCallBack_p action,
+ void *data)
{
- GtkTreeSelection *sel;
- wList_p bl;
- static wWinPix_t zeroPos = 0;
+ GtkTreeSelection *sel;
+ wList_p bl;
+ static wWinPix_t zeroPos = 0;
- assert(width != 0);
+ assert(width != 0);
- bl = (wList_p)wlibAlloc(parent, B_LIST, x, y, labelStr, sizeof *bl, data);
- bl->option = option;
- bl->number = number;
- bl->count = 0;
- bl->last = -1;
- bl->valueP = valueP;
- bl->action = action;
- bl->listX = bl->realX;
+ bl = (wList_p)wlibAlloc(parent, B_LIST, x, y, labelStr, sizeof *bl, data);
+ bl->option = option;
+ bl->number = number;
+ bl->count = 0;
+ bl->last = -1;
+ bl->valueP = valueP;
+ bl->action = action;
+ bl->listX = bl->realX;
- if (colCnt <= 0) {
- colCnt = 1;
- colWidths = &zeroPos;
- }
+ if (colCnt <= 0) {
+ colCnt = 1;
+ colWidths = &zeroPos;
+ }
- bl->colCnt = colCnt;
- bl->colWidths = (wWinPix_t*)malloc(colCnt * sizeof *(wWinPix_t*)0);
- memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wWinPix_t*)0);
+ bl->colCnt = colCnt;
+ bl->colWidths = (wWinPix_t*)malloc(colCnt * sizeof *(wWinPix_t*)0);
+ memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wWinPix_t*)0);
- /* create the data structure for data */
- bl->listStore = wlibNewListStore(colCnt);
- /* create the widget for the list store */
- bl->treeView = wlibNewTreeView(bl->listStore,
- colTitles != NULL,
- option & BL_MANY);
+ /* create the data structure for data */
+ bl->listStore = wlibNewListStore(colCnt);
+ /* create the widget for the list store */
+ bl->treeView = wlibNewTreeView(bl->listStore,
+ colTitles != NULL,
+ option & BL_MANY);
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView));
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView));
- gtk_tree_selection_set_select_function(sel,
- changeSelection,
- bl,
- NULL);
+ gtk_tree_selection_set_select_function(sel,
+ changeSelection,
+ bl,
+ NULL);
- wlibTreeViewAddColumns(bl->treeView, colCnt);
+ wlibTreeViewAddColumns(bl->treeView, colCnt);
- wlibAddColumnTitles(bl->treeView, colTitles);
+ wlibAddColumnTitles(bl->treeView, colTitles);
- wlibComputePos((wControl_p)bl);
+ wlibComputePos((wControl_p)bl);
- bl->widget = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bl->widget),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(bl->widget),
- bl->treeView);
+ bl->widget = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bl->widget),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(bl->widget),
+ bl->treeView);
- gtk_widget_set_size_request(bl->widget, width, (number+1)*ROW_HEIGHT);
+ gtk_widget_set_size_request(bl->widget, width, (number+1)*ROW_HEIGHT);
/// g_signal_connect( GTK_OBJECT(bl->list), "resize_column", G_CALLBACK(changeListColumnWidth), bl );
- gtk_widget_show_all(bl->widget);
+ gtk_widget_show_all(bl->widget);
- gtk_fixed_put(GTK_FIXED(parent->widget), bl->widget, bl->realX, bl->realY);
- wlibControlGetSize((wControl_p)bl);
+ gtk_fixed_put(GTK_FIXED(parent->widget), bl->widget, bl->realX, bl->realY);
+ wlibControlGetSize((wControl_p)bl);
- if (labelStr) {
- bl->labelW = wlibAddLabel((wControl_p)bl, labelStr);
- }
+ if (labelStr) {
+ bl->labelW = wlibAddLabel((wControl_p)bl, labelStr);
+ }
- wlibAddButton((wControl_p)bl);
- wlibAddHelpString(bl->widget, helpStr);
+ wlibAddButton((wControl_p)bl);
+ wlibAddHelpString(bl->widget, helpStr);
- return bl;
+ return bl;
}
diff --git a/app/wlib/gtklib/uthash.h b/app/wlib/gtklib/uthash.h
index 39fd891..bf74f7b 100644
--- a/app/wlib/gtklib/uthash.h
+++ b/app/wlib/gtklib/uthash.h
@@ -890,22 +890,22 @@ for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL);
#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0)
typedef struct UT_hash_bucket {
- struct UT_hash_handle *hh_head;
- unsigned count;
-
- /* expand_mult is normally set to 0. In this situation, the max chain length
- * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If
- * the bucket's chain exceeds this length, bucket expansion is triggered).
- * However, setting expand_mult to a non-zero value delays bucket expansion
- * (that would be triggered by additions to this particular bucket)
- * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.
- * (The multiplier is simply expand_mult+1). The whole idea of this
- * multiplier is to reduce bucket expansions, since they are expensive, in
- * situations where we know that a particular bucket tends to be overused.
- * It is better to let its chain length grow to a longer yet-still-bounded
- * value, than to do an O(n) bucket expansion too often.
- */
- unsigned expand_mult;
+ struct UT_hash_handle *hh_head;
+ unsigned count;
+
+ /* expand_mult is normally set to 0. In this situation, the max chain length
+ * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If
+ * the bucket's chain exceeds this length, bucket expansion is triggered).
+ * However, setting expand_mult to a non-zero value delays bucket expansion
+ * (that would be triggered by additions to this particular bucket)
+ * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.
+ * (The multiplier is simply expand_mult+1). The whole idea of this
+ * multiplier is to reduce bucket expansions, since they are expensive, in
+ * situations where we know that a particular bucket tends to be overused.
+ * It is better to let its chain length grow to a longer yet-still-bounded
+ * value, than to do an O(n) bucket expansion too often.
+ */
+ unsigned expand_mult;
} UT_hash_bucket;
@@ -914,47 +914,47 @@ typedef struct UT_hash_bucket {
#define HASH_BLOOM_SIGNATURE 0xb12220f2
typedef struct UT_hash_table {
- UT_hash_bucket *buckets;
- unsigned num_buckets, log2_num_buckets;
- unsigned num_items;
- struct UT_hash_handle *tail; /* tail hh in app order, for fast append */
- ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */
-
- /* in an ideal situation (all buckets used equally), no bucket would have
- * more than ceil(#items/#buckets) items. that's the ideal chain length. */
- unsigned ideal_chain_maxlen;
-
- /* nonideal_items is the number of items in the hash whose chain position
- * exceeds the ideal chain maxlen. these items pay the penalty for an uneven
- * hash distribution; reaching them in a chain traversal takes >ideal steps */
- unsigned nonideal_items;
-
- /* ineffective expands occur when a bucket doubling was performed, but
- * afterward, more than half the items in the hash had nonideal chain
- * positions. If this happens on two consecutive expansions we inhibit any
- * further expansion, as it's not helping; this happens when the hash
- * function isn't a good fit for the key domain. When expansion is inhibited
- * the hash will still work, albeit no longer in constant time. */
- unsigned ineff_expands, noexpand;
-
- uint32_t signature; /* used only to find hash tables in external analysis */
+ UT_hash_bucket *buckets;
+ unsigned num_buckets, log2_num_buckets;
+ unsigned num_items;
+ struct UT_hash_handle *tail; /* tail hh in app order, for fast append */
+ ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */
+
+ /* in an ideal situation (all buckets used equally), no bucket would have
+ * more than ceil(#items/#buckets) items. that's the ideal chain length. */
+ unsigned ideal_chain_maxlen;
+
+ /* nonideal_items is the number of items in the hash whose chain position
+ * exceeds the ideal chain maxlen. these items pay the penalty for an uneven
+ * hash distribution; reaching them in a chain traversal takes >ideal steps */
+ unsigned nonideal_items;
+
+ /* ineffective expands occur when a bucket doubling was performed, but
+ * afterward, more than half the items in the hash had nonideal chain
+ * positions. If this happens on two consecutive expansions we inhibit any
+ * further expansion, as it's not helping; this happens when the hash
+ * function isn't a good fit for the key domain. When expansion is inhibited
+ * the hash will still work, albeit no longer in constant time. */
+ unsigned ineff_expands, noexpand;
+
+ uint32_t signature; /* used only to find hash tables in external analysis */
#ifdef HASH_BLOOM
- uint32_t bloom_sig; /* used only to test bloom exists in external analysis */
- uint8_t *bloom_bv;
- char bloom_nbits;
+ uint32_t bloom_sig; /* used only to test bloom exists in external analysis */
+ uint8_t *bloom_bv;
+ char bloom_nbits;
#endif
} UT_hash_table;
typedef struct UT_hash_handle {
- struct UT_hash_table *tbl;
- void *prev; /* prev element in app order */
- void *next; /* next element in app order */
- struct UT_hash_handle *hh_prev; /* previous hh in bucket order */
- struct UT_hash_handle *hh_next; /* next hh in bucket order */
- void *key; /* ptr to enclosing struct's key */
- unsigned keylen; /* enclosing struct's key len */
- unsigned hashv; /* result of hash-fcn(key) */
+ struct UT_hash_table *tbl;
+ void *prev; /* prev element in app order */
+ void *next; /* next element in app order */
+ struct UT_hash_handle *hh_prev; /* previous hh in bucket order */
+ struct UT_hash_handle *hh_next; /* next hh in bucket order */
+ void *key; /* ptr to enclosing struct's key */
+ unsigned keylen; /* enclosing struct's key len */
+ unsigned hashv; /* result of hash-fcn(key) */
} UT_hash_handle;
#endif /* UTHASH_H */
diff --git a/app/wlib/gtklib/util.c b/app/wlib/gtklib/util.c
index 14ca689..3f746e6 100644
--- a/app/wlib/gtklib/util.c
+++ b/app/wlib/gtklib/util.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -44,34 +44,36 @@ long debugWindow = 0;
char wConfigName[ 256 ];
const char * wNames[] = {
- "MAIN",
- "POPUP",
- "BUTT",
- "CANCEL",
- "POPUP",
- "TEXT",
- "INTEGER",
- "FLOAT",
- "LIST",
- "DROPLIST",
- "COMBOLIST",
- "RADIO",
- "TOGGLE",
- "DRAW",
- "MENU"
- "MULTITEXT",
- "MESSAGE",
- "LINES",
- "MENUITEM",
- "BOX"
+ "MAIN",
+ "POPUP",
+ "BUTT",
+ "CANCEL",
+ "POPUP",
+ "TEXT",
+ "INTEGER",
+ "FLOAT",
+ "LIST",
+ "DROPLIST",
+ "COMBOLIST",
+ "RADIO",
+ "TOGGLE",
+ "DRAW",
+ "MENU"
+ "MULTITEXT",
+ "MESSAGE",
+ "LINES",
+ "MENUITEM",
+ "BOX"
};
+#if 0
static wBool_t reverseIcon =
#if defined(linux)
- FALSE;
+ FALSE;
#else
- TRUE;
+ TRUE;
+#endif
#endif
@@ -92,50 +94,49 @@ static wBool_t reverseIcon =
*/
GdkPixbuf* wlibPixbufFromXBM(
- wIcon_p ip)
+ wIcon_p ip)
{
- GdkPixbuf * pixbuf;
-
- char line0[40];
- char line2[40];
-
- char ** pixmapData;
- int row, col, wb;
- long rgb;
- const char * bits;
-
- wb = (ip->w + 7) / 8;
- pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData);
- pixmapData[0] = line0;
- rgb = wDrawGetRGB(ip->color);
- sprintf(line0, " %ld %ld 2 1", ip->w, ip->h);
- 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; row < ip->h; row++) {
- pixmapData[row + 3] = (char*) malloc((ip->w + 1) * sizeof **pixmapData);
-
- 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;
- }
-
- pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) pixmapData);
-
- for (row = 0; row < ip->h; row++) {
- free(pixmapData[row + 3]);
- }
- free(pixmapData);
- return pixbuf;
+ GdkPixbuf * pixbuf;
+
+ char line0[40];
+ char line2[40];
+
+ char ** pixmapData;
+ int row, col, wb;
+ long rgb;
+ const char * bits;
+
+ wb = (ip->w + 7) / 8;
+ pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData);
+ pixmapData[0] = line0;
+ rgb = wDrawGetRGB(ip->color);
+ sprintf(line0, " %ld %ld 2 1", ip->w, ip->h);
+ 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; row < ip->h; row++) {
+ pixmapData[row + 3] = (char*) malloc((ip->w + 1) * sizeof **pixmapData);
+
+ 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;
+ }
+
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) pixmapData);
+
+ for (row = 0; row < ip->h; row++) {
+ free(pixmapData[row + 3]);
+ }
+ free(pixmapData);
+ return pixbuf;
}
/**
@@ -148,23 +149,25 @@ GdkPixbuf* wlibPixbufFromXBM(
int wlibAddLabel(wControl_p b, const char * labelStr)
{
- GtkRequisition requisition, reqwidget;
-
- if (labelStr == NULL) {
- return 0;
- }
-
- 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 + (reqwidget.height/2 - requisition.height/2));
- gtk_widget_show(b->label);
- return requisition.width + 8;
+ GtkRequisition requisition, reqwidget;
+
+ if (labelStr == NULL) {
+ return 0;
+ }
+
+ 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 + (reqwidget.height/2 - requisition.height/2));
+ gtk_widget_show(b->label);
+ return requisition.width + 8;
}
/**
@@ -181,44 +184,44 @@ int wlibAddLabel(wControl_p b, const char * labelStr)
*/
void * wlibAlloc(
- wWin_p parent,
- wType_e type,
- wWinPix_t origX,
- wWinPix_t origY,
- const char * labelStr,
- int size,
- void * data)
+ wWin_p parent,
+ wType_e type,
+ wWinPix_t origX,
+ wWinPix_t origY,
+ const char * labelStr,
+ int size,
+ void * data)
{
- wControl_p w = (wControl_p) malloc(size);
- char * cp;
- memset(w, 0, size);
+ wControl_p w = (wControl_p) malloc(size);
+ char * cp;
+ memset(w, 0, size);
- if (w == NULL) {
- abort();
- }
+ if (w == NULL) {
+ abort();
+ }
- w->outline = FALSE;
+ w->outline = FALSE;
- w->type = type;
- w->parent = parent;
- w->origX = origX;
- w->origY = origY;
+ w->type = type;
+ w->parent = parent;
+ w->origX = origX;
+ w->origY = origY;
- if (labelStr) {
- cp = (char*) malloc(strlen(labelStr) + 1);
- w->labelStr = cp;
+ if (labelStr) {
+ cp = (char*) malloc(strlen(labelStr) + 1);
+ w->labelStr = cp;
- for (; *labelStr; labelStr++)
- if (*labelStr != '&') {
- *cp++ = *labelStr;
- }
+ for (; *labelStr; labelStr++)
+ if (*labelStr != '&') {
+ *cp++ = *labelStr;
+ }
- *cp = 0;
- }
+ *cp = 0;
+ }
- w->doneProc = NULL;
- w->data = data;
- return w;
+ w->doneProc = NULL;
+ w->data = data;
+ return w;
}
/**
@@ -228,23 +231,22 @@ void * wlibAlloc(
*/
void wlibComputePos(
- wControl_p b)
+ wControl_p b)
{
- wWin_p w = b->parent;
-
- if (b->origX >= 0) {
- b->realX = b->origX;
- }
- else {
- b->realX = w->lastX + (-b->origX) - 1;
- }
-
- if (b->origY >= 0) {
- b->realY = b->origY + BORDERSIZE + ((w->option & F_MENUBAR) ? w->menu_height : 0);
- }
- else {
- b->realY = w->lastY + (-b->origY) - 1;
- }
+ wWin_p w = b->parent;
+
+ if (b->origX >= 0) {
+ b->realX = b->origX;
+ } else {
+ b->realX = w->lastX + (-b->origX) - 1;
+ }
+
+ if (b->origY >= 0) {
+ b->realY = b->origY + BORDERSIZE + ((w->option & F_MENUBAR) ? w->menu_height :
+ 0);
+ } else {
+ b->realY = w->lastY + (-b->origY) - 1;
+ }
}
/**
@@ -254,12 +256,12 @@ void wlibComputePos(
*/
void wlibControlGetSize(
- wControl_p b)
+ wControl_p b)
{
- GtkRequisition requisition;
- gtk_widget_size_request(b->widget, &requisition);
- b->w = requisition.width;
- b->h = requisition.height;
+ GtkRequisition requisition;
+ gtk_widget_size_request(b->widget, &requisition);
+ b->w = requisition.width;
+ b->h = requisition.height;
}
/**
@@ -268,50 +270,49 @@ 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 {
- win->last->next = b;
- }
-
- win->last = b;
- b->next = NULL;
- b->parent = win;
- win->lastX = b->realX + b->w;
- win->lastY = b->realY + b->h;
-
- if (win->option & F_AUTOSIZE) {
- if (win->lastX > win->realX) {
- win->realX = win->lastX;
-
- if (win->w != (win->realX + win->origX)) {
- resize = TRUE;
- win->w = (win->realX + win->origX);
- }
- }
-
- if (win->lastY > win->realY) {
- win->realY = win->lastY;
-
- if (win->h != (win->realY + win->origY)) {
- resize = TRUE;
- win->h = (win->realY + win->origY);
- }
- }
-
- if (win->shown) {
- if (resize) {
- gtk_widget_set_size_request(win->gtkwin, win->w, win->h);
- gtk_widget_set_size_request(win->widget, win->w, win->h);
- }
- }
- }
+ wWin_p win = b->parent;
+ wBool_t resize = FALSE;
+
+ if (win->first == NULL) {
+ win->first = b;
+ } else {
+ win->last->next = b;
+ }
+
+ win->last = b;
+ b->next = NULL;
+ b->parent = win;
+ win->lastX = b->realX + b->w;
+ win->lastY = b->realY + b->h;
+
+ if (win->option & F_AUTOSIZE) {
+ if (win->lastX > win->realX) {
+ win->realX = win->lastX;
+
+ if (win->w != (win->realX + win->origX)) {
+ resize = TRUE;
+ win->w = (win->realX + win->origX);
+ }
+ }
+
+ if (win->lastY > win->realY) {
+ win->realY = win->lastY;
+
+ if (win->h != (win->realY + win->origY)) {
+ resize = TRUE;
+ win->h = (win->realY + win->origY);
+ }
+ }
+
+ if (win->shown) {
+ if (resize) {
+ gtk_widget_set_size_request(win->gtkwin, win->w, win->h);
+ gtk_widget_set_size_request(win->widget, win->w, win->h);
+ }
+ }
+ }
}
/**
@@ -323,26 +324,26 @@ void wlibAddButton(
*/
wControl_p wlibGetControlFromPos(
- wWin_p win,
- wWinPix_t x,
- wWinPix_t y)
+ wWin_p win,
+ wWinPix_t x,
+ wWinPix_t y)
{
- wControl_p b;
- wWinPix_t xx, yy;
-
- 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) {
- return b;
- }
- }
- }
-
- return NULL;
+ wControl_p b;
+ wWinPix_t xx, yy;
+
+ 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) {
+ return b;
+ }
+ }
+ }
+
+ return NULL;
}
@@ -360,7 +361,7 @@ wControl_p wlibGetControlFromPos(
*/
void wBeep(void)
{
- gdk_display_beep(gdk_display_get_default());
+ gdk_display_beep(gdk_display_get_default());
}
/**
@@ -368,13 +369,13 @@ void wBeep(void)
*/
void wFlush(
- void)
+ void)
{
- while (gtk_events_pending()) {
- gtk_main_iteration_do(FALSE);
- }
+ while (gtk_events_pending()) {
+ gtk_main_iteration_do(FALSE);
+ }
- gdk_display_sync(gdk_display_get_default());
+ gdk_display_sync(gdk_display_get_default());
}
/**
@@ -399,71 +400,71 @@ void wSetCursor(wDraw_p bd, wCursor_t cursor)
static GdkCursor * gdkcursors[wCursorQuestion+1];
GdkCursor * gdkcursor;
//GdkWindow * gdkwindow = gtk_widget_get_window(GTK_WIDGET(win->gtkwin));;
- GdkWindow * gdkwindow = gdk_get_default_root_window();
- GdkDisplay * display = gdk_window_get_display(gdkwindow);
- if ((cursor == wCursorNone) && dontHideCursor) return; //Ignore if we dont want to suppress
+// GdkWindow * gdkwindow = gdk_get_default_root_window();
+// GdkDisplay * display = gdk_window_get_display(gdkwindow);
+ if ((cursor == wCursorNone) && dontHideCursor) { return; } //Ignore if we dont want to suppress
if (!gdkcursors[cursor]) {
switch(cursor) {
- case wCursorAppStart:
- //gdkcursor = gdk_cursor_new_from_name (display,"progress");
- gdkcursor = gdk_cursor_new(GDK_WATCH);
- break;
- case wCursorHand:
- //gdkcursor = gdk_cursor_new_from_name (display,"pointer");
- gdkcursor = gdk_cursor_new(GDK_HAND2);
- break;
- case wCursorNo:
- //gdkcursor = gdk_cursor_new_from_name (display,"not-allowed");
- gdkcursor = gdk_cursor_new(GDK_X_CURSOR);
- break;
- case wCursorSizeAll:
- //gdkcursor = gdk_cursor_new_from_name (display,"move");
- gdkcursor = gdk_cursor_new(GDK_FLEUR);
- break;
- case wCursorSizeNESW:
- //gdkcursor = gdk_cursor_new_from_name (display,"nesw-resize");
- gdkcursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
- break;
- case wCursorSizeNS:
- //gdkcursor = gdk_cursor_new_from_name (display,"ns-resize");
- gdkcursor = gdk_cursor_new(GDK_DOUBLE_ARROW);
- break;
- case wCursorSizeNWSE:
- //gdkcursor = gdk_cursor_new_from_name (display,"nwse-resize");
- gdkcursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
- break;
- case wCursorSizeWE:
- //gdkcursor = gdk_cursor_new_from_name (display,"ew-resize");
- gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
- break;
- case wCursorWait:
- //gdkcursor = gdk_cursor_new_from_name (display,"wait");
- gdkcursor = gdk_cursor_new(GDK_WATCH);
- break;
- case wCursorIBeam:
- //gdkcursor = gdk_cursor_new_from_name (display,"text");
- gdkcursor = gdk_cursor_new(GDK_XTERM);
- break;
- case wCursorCross:
- //gdkcursor = gdk_cursor_new_from_name (display,"crosshair");
- gdkcursor = gdk_cursor_new(GDK_TCROSS);
- break;
- case wCursorQuestion:
- //gdkcursor = gdk_cursor_new_from_name (display,"help");
- gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW);
- break;
- case wCursorNone:
- gdkcursor = gdk_cursor_new(GDK_BLANK_CURSOR);
- break;
- case wCursorNormal:
- default:
- //gdkcursor = gdk_cursor_new_from_name (display,"default");
- gdkcursor = gdk_cursor_new(GDK_LEFT_PTR);
- break;
+ case wCursorAppStart:
+ //gdkcursor = gdk_cursor_new_from_name (display,"progress");
+ gdkcursor = gdk_cursor_new(GDK_WATCH);
+ break;
+ case wCursorHand:
+ //gdkcursor = gdk_cursor_new_from_name (display,"pointer");
+ gdkcursor = gdk_cursor_new(GDK_HAND2);
+ break;
+ case wCursorNo:
+ //gdkcursor = gdk_cursor_new_from_name (display,"not-allowed");
+ gdkcursor = gdk_cursor_new(GDK_X_CURSOR);
+ break;
+ case wCursorSizeAll:
+ //gdkcursor = gdk_cursor_new_from_name (display,"move");
+ gdkcursor = gdk_cursor_new(GDK_FLEUR);
+ break;
+ case wCursorSizeNESW:
+ //gdkcursor = gdk_cursor_new_from_name (display,"nesw-resize");
+ gdkcursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
+ break;
+ case wCursorSizeNS:
+ //gdkcursor = gdk_cursor_new_from_name (display,"ns-resize");
+ gdkcursor = gdk_cursor_new(GDK_DOUBLE_ARROW);
+ break;
+ case wCursorSizeNWSE:
+ //gdkcursor = gdk_cursor_new_from_name (display,"nwse-resize");
+ gdkcursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
+ break;
+ case wCursorSizeWE:
+ //gdkcursor = gdk_cursor_new_from_name (display,"ew-resize");
+ gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
+ break;
+ case wCursorWait:
+ //gdkcursor = gdk_cursor_new_from_name (display,"wait");
+ gdkcursor = gdk_cursor_new(GDK_WATCH);
+ break;
+ case wCursorIBeam:
+ //gdkcursor = gdk_cursor_new_from_name (display,"text");
+ gdkcursor = gdk_cursor_new(GDK_XTERM);
+ break;
+ case wCursorCross:
+ //gdkcursor = gdk_cursor_new_from_name (display,"crosshair");
+ gdkcursor = gdk_cursor_new(GDK_TCROSS);
+ break;
+ case wCursorQuestion:
+ //gdkcursor = gdk_cursor_new_from_name (display,"help");
+ gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW);
+ break;
+ case wCursorNone:
+ gdkcursor = gdk_cursor_new(GDK_BLANK_CURSOR);
+ break;
+ case wCursorNormal:
+ default:
+ //gdkcursor = gdk_cursor_new_from_name (display,"default");
+ gdkcursor = gdk_cursor_new(GDK_LEFT_PTR);
+ break;
}
gdkcursors[cursor] = gdkcursor;
- } else gdkcursor = gdkcursors[cursor];
+ } else { gdkcursor = gdkcursors[cursor]; }
gdk_window_set_cursor ( gtk_widget_get_window(bd->widget), gdkcursor);
}
@@ -475,7 +476,7 @@ void wSetCursor(wDraw_p bd, wCursor_t cursor)
const char * wMemStats(void)
{
- return "No stats available";
+ return "No stats available";
}
/**
@@ -490,9 +491,9 @@ void wGetDisplaySize(wWinPix_t * w, wWinPix_t * h)
GdkScreen *screen = gdk_screen_get_default();
guint monitor = gdk_screen_get_primary_monitor(screen);
GdkRectangle screen_geometry = { 0, 0, 0, 0 };
-
+
gdk_screen_get_monitor_geometry( screen, monitor, &screen_geometry );
-
+
*w = screen_geometry.width;
*h = screen_geometry.height;
}
@@ -509,42 +510,41 @@ static dynArr_t conversionBuffer_da;
char * wlibConvertInput(const char * inString)
{
- const char * cp;
- char * cq;
- int extCharCnt, inCharCnt;
-
- /* Already UTF-8 encoded? */
- if (g_utf8_validate(inString, -1, NULL))
- /* Yes, do not double-convert */ {
- return (char*) inString;
- }
-
- for (cp = inString, extCharCnt = 0; *cp; cp++) {
- if (((*cp)&0x80) != '\0') {
- extCharCnt++;
- }
- }
-
- inCharCnt = cp - inString;
-
- if (extCharCnt == '\0') {
- return (char*) inString;
- }
-
- DYNARR_SET(char, conversionBuffer_da, inCharCnt + extCharCnt + 1);
-
- 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++ = *cp;
- }
- }
-
- *cq = 0;
- return (char*) conversionBuffer_da.ptr;
+ const char * cp;
+ char * cq;
+ int extCharCnt, inCharCnt;
+
+ /* Already UTF-8 encoded? */
+ if (g_utf8_validate(inString, -1, NULL))
+ /* Yes, do not double-convert */ {
+ return (char*) inString;
+ }
+
+ for (cp = inString, extCharCnt = 0; *cp; cp++) {
+ if (((*cp)&0x80) != '\0') {
+ extCharCnt++;
+ }
+ }
+
+ inCharCnt = cp - inString;
+
+ if (extCharCnt == '\0') {
+ return (char*) inString;
+ }
+
+ DYNARR_SET(char, conversionBuffer_da, inCharCnt + extCharCnt + 1);
+
+ 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++ = *cp;
+ }
+ }
+
+ *cq = 0;
+ return (char*) conversionBuffer_da.ptr;
}
/**
@@ -556,36 +556,35 @@ char * wlibConvertInput(const char * inString)
char * wlibConvertOutput(const char * inString)
{
- const char * cp;
- char * cq;
- int extCharCnt, inCharCnt;
-
- for (cp = inString, extCharCnt = 0; *cp; cp++) {
- if (((*cp)&0xC0) == 0x80) {
- extCharCnt++;
- }
- }
-
- inCharCnt = cp - inString;
-
- if (extCharCnt == '\0') {
- return (char*) inString;
- }
-
- DYNARR_SET(char, conversionBuffer_da, inCharCnt + 1);
-
- 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++ = *cp;
- }
- }
-
- *cq = '\0';
- return (char*) conversionBuffer_da.ptr;
+ const char * cp;
+ char * cq;
+ int extCharCnt, inCharCnt;
+
+ for (cp = inString, extCharCnt = 0; *cp; cp++) {
+ if (((*cp)&0xC0) == 0x80) {
+ extCharCnt++;
+ }
+ }
+
+ inCharCnt = cp - inString;
+
+ if (extCharCnt == '\0') {
+ return (char*) inString;
+ }
+
+ DYNARR_SET(char, conversionBuffer_da, inCharCnt + 1);
+
+ 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++ = *cp;
+ }
+ }
+
+ *cq = '\0';
+ return (char*) conversionBuffer_da.ptr;
}
/*-----------------------------------------------------------------*/
@@ -595,32 +594,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, */
- GDK_KEY_KP_Add, /* wAccelKey_Numpad_Add */
- GDK_KEY_KP_Subtract /* wAccelKey_Numpad_Subtract */
+ 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 */
};
/**
@@ -633,24 +632,24 @@ 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;
+ accelData_t * ad;
// 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->key = key;
- ad->modifier = modifier;
- ad->action = action;
- ad->data = data;
+ DYNARR_APPEND(accelData_t, accelData_da, 10);
+ ad = &accelData(accelData_da.cnt - 1);
+ ad->key = key;
+ ad->modifier = modifier;
+ ad->action = action;
+ ad->data = data;
}
/**
@@ -661,30 +660,30 @@ void wAttachAccelKey(
*/
struct accelData_t * wlibFindAccelKey(
- GdkEventKey * event)
+ GdkEventKey * event)
{
- accelData_t * ad;
- int modifier = 0;
+ accelData_t * ad;
+ int modifier = 0;
- if ((event->state & GDK_SHIFT_MASK)) {
- modifier |= WKEY_SHIFT;
- }
+ if ((event->state & GDK_SHIFT_MASK)) {
+ modifier |= WKEY_SHIFT;
+ }
- if ((event->state & GDK_CONTROL_MASK)) {
- modifier |= WKEY_CTRL;
- }
+ if ((event->state & GDK_CONTROL_MASK)) {
+ modifier |= WKEY_CTRL;
+ }
- if ((event->state & GDK_MOD1_MASK)) {
- modifier |= WKEY_ALT;
- }
+ if ((event->state & GDK_MOD1_MASK)) {
+ modifier |= WKEY_ALT;
+ }
- for (ad = &accelData(0); ad<&accelData(accelData_da.cnt); ad++)
- if (event->keyval == accelKeyMap[ad->key] &&
- modifier == ad->modifier) {
- return ad;
- }
+ for (ad = &accelData(0); ad<&accelData(accelData_da.cnt); ad++)
+ if (event->keyval == accelKeyMap[ad->key] &&
+ modifier == ad->modifier) {
+ return ad;
+ }
- return NULL;
+ return NULL;
}
/**
@@ -695,16 +694,16 @@ struct accelData_t * wlibFindAccelKey(
*/
wBool_t wlibHandleAccelKey(
- GdkEventKey *event)
+ GdkEventKey *event)
{
- accelData_t * ad = wlibFindAccelKey(event);
+ accelData_t * ad = wlibFindAccelKey(event);
- if (ad) {
- ad->action(ad->key, ad->data);
- return TRUE;
- }
+ if (ad) {
+ ad->action(ad->key, ad->data);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
/**
@@ -721,13 +720,13 @@ wBool_t wlibHandleAccelKey(
void wControlLinkedSet(wControl_p b1, wControl_p b2)
{
- b2->synonym = b1->synonym;
+ b2->synonym = b1->synonym;
- if (b2->synonym == NULL) {
- b2->synonym = b1;
- }
+ if (b2->synonym == NULL) {
+ b2->synonym = b1;
+ }
- b1->synonym = b2;
+ b1->synonym = b2;
}
/**
@@ -740,26 +739,24 @@ void wControlLinkedSet(wControl_p b1, wControl_p b2)
void wControlLinkedActive(wControl_p b, int active)
{
- wControl_p savePtr = b;
+ wControl_p savePtr = b;
- if (savePtr->type == B_MENUITEM) {
- wMenuPushEnable((wMenuPush_p) savePtr, active);
- }
- else {
- wControlActive(savePtr, active);
- }
+ if (savePtr->type == B_MENUITEM) {
+ wMenuPushEnable((wMenuPush_p) savePtr, active);
+ } else {
+ wControlActive(savePtr, active);
+ }
- savePtr = savePtr->synonym;
+ savePtr = savePtr->synonym;
- while (savePtr && savePtr != b) {
+ while (savePtr && savePtr != b) {
- if (savePtr->type == B_MENUITEM) {
- wMenuPushEnable((wMenuPush_p) savePtr, active);
- }
- else {
- wControlActive(savePtr, active);
- }
+ if (savePtr->type == B_MENUITEM) {
+ wMenuPushEnable((wMenuPush_p) savePtr, active);
+ } else {
+ wControlActive(savePtr, active);
+ }
- savePtr = savePtr->synonym;
- }
+ savePtr = savePtr->synonym;
+ }
}
diff --git a/app/wlib/gtklib/window.c b/app/wlib/gtklib/window.c
index 16a21a5..b8a3cdf 100644
--- a/app/wlib/gtklib/window.c
+++ b/app/wlib/gtklib/window.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -40,11 +40,8 @@
wWin_p gtkMainW;
-#define MIN_WIN_WIDTH 150
-#define MIN_WIN_HEIGHT 150
-
-#define MIN_WIN_WIDTH_MAIN 400
-#define MIN_WIN_HEIGHT_MAIN 400
+#define MIN_WIN_WIDTH 50
+#define MIN_WIN_HEIGHT 50
#define SECTIONWINDOWSIZE "gtklib window size"
#define SECTIONWINDOWPOS "gtklib window pos"
@@ -55,6 +52,9 @@ static wControl_p firstWin = NULL, lastWin;
static int keyState;
static wBool_t gtkBlockEnabled = TRUE;
static wBool_t maximize_at_next_show = FALSE;
+
+#include "../../bin/bitmaps/xtc.xpm"
+static GdkPixbuf *windowIconPixbuf = NULL;
/*
*****************************************************************************
@@ -70,7 +70,8 @@ static wBool_t maximize_at_next_show = FALSE;
*
*/
-static GdkRectangle getMonitorDimensions(GtkWidget * widget) {
+static GdkRectangle getMonitorDimensions(GtkWidget * widget)
+{
GdkRectangle monitor_dimensions;
@@ -81,9 +82,10 @@ static GdkRectangle getMonitorDimensions(GtkWidget * widget) {
GtkWidget * toplevel = gtk_widget_get_toplevel(widget);
if (gtk_widget_is_toplevel(GTK_WIDGET(toplevel)) &&
- gtk_widget_get_parent_window(GTK_WIDGET(toplevel))) {
+ gtk_widget_get_parent_window(GTK_WIDGET(toplevel))) {
- GdkWindow * window = GDK_WINDOW(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));
@@ -113,46 +115,39 @@ static GdkRectangle getMonitorDimensions(GtkWidget * widget) {
static void getWinSize(wWin_p win, const char * nameStr)
{
- int w=50, h=50;
- 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));
-
- wWinPix_t maxDisplayWidth = monitor_dimensions.width-10;
- wWinPix_t maxDisplayHeight = monitor_dimensions.height-50;
-
-
-
- if ((win->option&F_RECALLSIZE) &&
- (win->option&F_RECALLPOS) &&
- (cp = wPrefGetString(SECTIONWINDOWSIZE, nameStr)) &&
- (w = strtod(cp, &cp1), cp != cp1) &&
- (h = strtod(cp1, &cp2), cp1 != cp2)) {
- win->option &= ~F_AUTOSIZE;
-
- if (w < 50) {
- w = 50;
- }
-
- if (h < 50) {
- h = 50;
- }
- }
-
- if (w > maxDisplayWidth) w = maxDisplayWidth;
- if (h > maxDisplayHeight) h = maxDisplayHeight;
-
- if (w<MIN_WIDTH) w = MIN_WIDTH;
- if (h<MIN_HEIGHT) h = MIN_HEIGHT;
-
- win->w = win->origX = w;
- win->h = win->origY = h;
+ /*
+ * original w/h values in .origX/Y
+ */
+ int w = win->w = win->origX;
+ int h = win->h = win->origY;
+
+ /*
+ * Take values from Prefs if possible
+ */
+ const char *cp;
+ char *cp1, *cp2;
+ if ((win->option&F_RESIZE) &&
+ (win->option&F_RECALLSIZE) &&
+ (cp = wPrefGetString(SECTIONWINDOWSIZE, nameStr)) &&
+ (w = strtod(cp, &cp1), cp != cp1) &&
+ (h = strtod(cp1, &cp2), cp1 != cp2)) {
+ win->option &= ~F_AUTOSIZE;
+
+ /*
+ * 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));
+ wWinPix_t maxDisplayWidth = monitor_dimensions.width-10;
+ wWinPix_t maxDisplayHeight = monitor_dimensions.height-50;
+ if (w > maxDisplayWidth) { w = maxDisplayWidth; }
+ if (h > maxDisplayHeight) { h = maxDisplayHeight; }
+
+ if (w<MIN_WIDTH) { w = MIN_WIDTH; }
+ if (h<MIN_HEIGHT) { h = MIN_HEIGHT; }
+
+ win->w = win->origX = w;
+ win->h = win->origY = h;
+ }
}
@@ -166,14 +161,14 @@ static void getWinSize(wWin_p win, const char * nameStr)
static void saveSize(wWin_p win)
{
- if ((win->option&F_RECALLSIZE) &&
- gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) {
- char pos_s[20];
+ if ((win->option&F_RECALLSIZE) &&
+ gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) {
+ char pos_s[32];
- sprintf(pos_s, "%ld %ld", win->w,
- (win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0))));
- wPrefSetString(SECTIONWINDOWSIZE, win->nameStr, pos_s);
- }
+ sprintf(pos_s, "%ld %ld", win->w,
+ (win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0))));
+ wPrefSetString(SECTIONWINDOWSIZE, win->nameStr, pos_s);
+ }
}
/**
@@ -185,47 +180,46 @@ static void saveSize(wWin_p win)
static void getPos(wWin_p win)
{
- char *cp1, *cp2;
- GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin));
+ char *cp1, *cp2;
+ GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin));
- if ((win->option&F_RECALLPOS) && (!win->shown)) {
- const char *cp;
+ if ((win->option&F_RECALLPOS) && (!win->shown)) {
+ const char *cp;
- if ((cp = wPrefGetString(SECTIONWINDOWPOS, win->nameStr))) {
- int x, y;
+ if ((cp = wPrefGetString(SECTIONWINDOWPOS, win->nameStr))) {
+ int x, y;
- x = strtod(cp, &cp1);
+ x = strtod(cp, &cp1);
- if (cp == cp1) {
- return;
- }
+ if (cp == cp1) {
+ return;
+ }
- y = strtod(cp1, &cp2);
+ y = strtod(cp1, &cp2);
- if (cp2 == cp1) {
- return;
- }
+ if (cp2 == cp1) {
+ return;
+ }
- if (y > monitor_dimensions.height+monitor_dimensions.y-win->h) {
- y = monitor_dimensions.height+monitor_dimensions.y-win->h;
- }
+ if (y > monitor_dimensions.height+monitor_dimensions.y-win->h) {
+ y = monitor_dimensions.height+monitor_dimensions.y-win->h;
+ }
- if (x > monitor_dimensions.width+monitor_dimensions.x-win->w) {
- x = monitor_dimensions.width+monitor_dimensions.x-win->w;
- }
+ if (x > monitor_dimensions.width+monitor_dimensions.x-win->w) {
+ x = monitor_dimensions.width+monitor_dimensions.x-win->w;
+ }
- if (x <= 0) {
- x = 1;
- }
+ if (x <= 0) {
+ x = 1;
+ }
- if (y <= 0) {
- y = 1;
- }
+ if (y <= 0) {
+ y = 1;
+ }
- gtk_window_move(GTK_WINDOW(win->gtkwin), x, y);
- //gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h);
- }
- }
+ gtk_window_move(GTK_WINDOW(win->gtkwin), x, y);
+ }
+ }
}
/**
@@ -237,17 +231,17 @@ static void getPos(wWin_p win)
static void savePos(wWin_p win)
{
- int x, y;
+ int x, y;
- if ((win->option&F_RECALLPOS)) {
- char pos_s[20];
+ if ((win->option&F_RECALLPOS)) {
+ char pos_s[32];
- gdk_window_get_position(gtk_widget_get_window(GTK_WIDGET(win->gtkwin)), &x, &y);
- x -= 5;
- y -= 25;
- sprintf(pos_s, "%d %d", x, y);
- wPrefSetString(SECTIONWINDOWPOS, win->nameStr, pos_s);
- }
+ gdk_window_get_position(gtk_widget_get_window(GTK_WIDGET(win->gtkwin)), &x, &y);
+ x -= 5;
+ y -= 25;
+ sprintf(pos_s, "%d %d", x, y);
+ wPrefSetString(SECTIONWINDOWPOS, win->nameStr, pos_s);
+ }
}
/**
@@ -259,28 +253,17 @@ static void savePos(wWin_p win)
*/
void wWinGetSize(
- wWin_p win, /* Window */
- wWinPix_t * width, /* Returned window width */
- wWinPix_t * height) /* Returned window height */
+ wWin_p win, /* Window */
+ wWinPix_t * width, /* Returned window width */
+ wWinPix_t * height) /* Returned window height */
{
- GtkRequisition requisition;
- wWinPix_t w, h;
- gtk_widget_size_request(win->gtkwin, &requisition);
- w = win->w;
- h = win->h;
-
- if (win->option&F_AUTOSIZE) {
- if (win->realX > w) {
- w = win->realX;
- }
-
- if (win->realY > h) {
- h = win->realY;
- }
- }
-
- *width = w;
- *height = h - BORDERSIZE - ((win->option&F_MENUBAR)?win->menu_height:0);
+ GtkRequisition requisition;
+ wWinPix_t w, h;
+ gtk_widget_size_request(win->gtkwin, &requisition);
+ w = win->w;
+ h = win->h;
+ *width = w;
+ *height = h - BORDERSIZE - ((win->option&F_MENUBAR)?win->menu_height:0);
}
/**
@@ -292,24 +275,23 @@ void wWinGetSize(
*/
void wWinSetSize(
- wWin_p win, /* Window */
- wWinPix_t width, /* Window width */
- wWinPix_t height) /* Window height */
+ wWin_p win, /* Window */
+ wWinPix_t width, /* Window width */
+ wWinPix_t height) /* Window height */
{
- win->busy = TRUE;
- win->w = width;
- win->h = height + BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0);
- if (win->option&F_RESIZE) {
- gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h);
- gtk_widget_set_size_request(win->widget, win->w-10, win->h-10);
- }
- else {
- 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;
+ win->busy = TRUE;
+ win->w = width;
+ win->h = height + BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0);
+ if (win->option&F_RESIZE) {
+ gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h);
+ gtk_widget_set_size_request(win->widget, win->w-10, win->h-10);
+ } else {
+ 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;
}
/**
@@ -322,93 +304,93 @@ void wWinSetSize(
*/
void wWinShow(
- wWin_p win, /* Window */
- wBool_t show) /* Command */
+ wWin_p win, /* Window */
+ wBool_t show) /* Command */
{
- //GtkRequisition min_req, pref_req;
+ //GtkRequisition min_req, pref_req;
- if (debugWindow >= 2) {
- printf("Set Show %s\n", win->labelStr?win->labelStr:"No label");
- }
+ if (debugWindow >= 2) {
+ printf("Set Show %s\n", win->labelStr?win->labelStr:"No label");
+ }
- if (win->widget == 0) {
- abort();
- }
+ if (win->widget == 0) {
+ abort();
+ }
- int width, height;
+ int width, height;
- if (show) {
- keyState = 0;
- getPos(win);
+ if (show) {
+ keyState = 0;
+ getPos(win);
- if (!win->shown) {
+ if (!win->shown) {
gtk_widget_show(win->gtkwin);
gtk_widget_show(win->widget);
}
- if (win->option & F_AUTOSIZE) {
- GtkAllocation allocation;
- GtkRequisition requistion;
- gtk_widget_size_request(win->widget,&requistion);
+ if (win->option & F_AUTOSIZE) {
+ GtkAllocation allocation;
+ GtkRequisition requistion;
+ gtk_widget_size_request(win->widget,&requistion);
- width = win->w;
- height = win->h;
+ width = win->w;
+ height = win->h;
- if (requistion.width != width || requistion.height != height ) {
+ if (requistion.width != width || requistion.height != height ) {
width = requistion.width;
height = requistion.height;
- win->w = width;
- win->h = height;
+ win->w = width;
+ win->h = height;
- gtk_window_set_resizable(GTK_WINDOW(win->gtkwin),TRUE);
+ gtk_window_set_resizable(GTK_WINDOW(win->gtkwin),TRUE);
- if (win->option&F_MENUBAR) {
- gtk_widget_set_size_request(win->menubar, win->w-20, MENUH);
+ if (win->option&F_MENUBAR) {
+ gtk_widget_set_size_request(win->menubar, win->w-20, MENUH);
- gtk_widget_get_allocation(win->menubar, &allocation);
- win->menu_height = allocation.height;
- }
- }
- gtk_window_resize(GTK_WINDOW(win->gtkwin), width+10, height+10);
- }
+ gtk_widget_get_allocation(win->menubar, &allocation);
+ win->menu_height = allocation.height;
+ }
+ }
+ gtk_window_resize(GTK_WINDOW(win->gtkwin), width+10, height+10);
+ }
- gtk_window_present(GTK_WINDOW(win->gtkwin));
+ gtk_window_present(GTK_WINDOW(win->gtkwin));
- gdk_window_raise(gtk_widget_get_window(win->gtkwin));
+ gdk_window_raise(gtk_widget_get_window(win->gtkwin));
- if (win->shown && win->modalLevel > 0) {
- gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE);
- }
+ if (win->shown && win->modalLevel > 0) {
+ gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE);
+ }
- win->shown = show;
- win->modalLevel = 0;
+ win->shown = show;
+ win->modalLevel = 0;
- if ((!gtkBlockEnabled) || (win->option & F_BLOCK) == 0) {
- wFlush();
- } 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);
- savePos(win);
- win->shown = show;
+ if ((!gtkBlockEnabled) || (win->option & F_BLOCK) == 0) {
+ wFlush();
+ } 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);
+ savePos(win);
+ win->shown = show;
- if (gtkBlockEnabled && (win->option & F_BLOCK) != 0) {
- wlibDoModal(win, FALSE);
- }
+ if (gtkBlockEnabled && (win->option & F_BLOCK) != 0) {
+ wlibDoModal(win, FALSE);
+ }
- gtk_widget_hide(win->gtkwin);
- gtk_widget_hide(win->widget);
- }
+ gtk_widget_hide(win->gtkwin);
+ gtk_widget_hide(win->widget);
+ }
}
/**
@@ -418,9 +400,9 @@ void wWinShow(
*/
void wWinBlockEnable(
- wBool_t enabled)
+ wBool_t enabled)
{
- gtkBlockEnabled = enabled;
+ gtkBlockEnabled = enabled;
}
/**
@@ -431,9 +413,9 @@ void wWinBlockEnable(
*/
wBool_t wWinIsVisible(
- wWin_p win)
+ wWin_p win)
{
- return win->shown;
+ return win->shown;
}
/**
@@ -445,7 +427,7 @@ wBool_t wWinIsVisible(
wBool_t wWinIsMaximized(wWin_p win)
{
- return win->maximize_initially;
+ return win->maximize_initially;
}
/**
@@ -456,10 +438,10 @@ wBool_t wWinIsMaximized(wWin_p win)
*/
void wWinSetTitle(
- wWin_p win, /* Window */
- const char * title) /* New title */
+ wWin_p win, /* Window */
+ const char * title) /* New title */
{
- gtk_window_set_title(GTK_WINDOW(win->gtkwin), title);
+ gtk_window_set_title(GTK_WINDOW(win->gtkwin), title);
}
/**
@@ -470,28 +452,28 @@ void wWinSetTitle(
*/
void wWinSetBusy(
- wWin_p win, /* Window */
- wBool_t busy) /* Command */
+ wWin_p win, /* Window */
+ wBool_t busy) /* Command */
{
- GdkCursor * cursor;
+ GdkCursor * cursor;
- if (win->gtkwin == 0) {
- abort();
- }
+ if (win->gtkwin == 0) {
+ abort();
+ }
- if (busy) {
- cursor = gdk_cursor_new(GDK_WATCH);
- } else {
- cursor = NULL;
- }
+ if (busy) {
+ cursor = gdk_cursor_new(GDK_WATCH);
+ } else {
+ cursor = NULL;
+ }
- gdk_window_set_cursor(gtk_widget_get_window(win->gtkwin), cursor);
+ gdk_window_set_cursor(gtk_widget_get_window(win->gtkwin), cursor);
- if (cursor) {
- gdk_cursor_unref(cursor);
- }
+ if (cursor) {
+ gdk_cursor_unref(cursor);
+ }
- gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), busy==0);
+ gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), busy==0);
}
/**
@@ -507,42 +489,42 @@ void wWinSetBusy(
*/
void wlibDoModal(
- wWin_p win0,
- wBool_t modal)
+ wWin_p win0,
+ wBool_t modal)
{
- wWin_p win;
-
- for (win=(wWin_p)firstWin; win; win=(wWin_p)win->next) {
- if (win->shown && win != win0) {
- if (modal) {
- if (win->modalLevel == 0) {
- gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), FALSE);
- }
-
- win->modalLevel++;
- } else {
- if (win->modalLevel > 0) {
- win->modalLevel--;
-
- if (win->modalLevel == 0) {
- gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE);
- }
- }
- }
-
- if (win->modalLevel < 0) {
- fprintf(stderr, "DoModal: %s modalLevel < 0",
- win->nameStr?win->nameStr:"<NULL>");
- abort();
- }
- }
- }
-
- if (modal) {
- gtk_main();
- } else {
- gtk_main_quit();
- }
+ wWin_p win;
+
+ for (win=(wWin_p)firstWin; win; win=(wWin_p)win->next) {
+ if (win->shown && win != win0) {
+ if (modal) {
+ if (win->modalLevel == 0) {
+ gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), FALSE);
+ }
+
+ win->modalLevel++;
+ } else {
+ if (win->modalLevel > 0) {
+ win->modalLevel--;
+
+ if (win->modalLevel == 0) {
+ gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE);
+ }
+ }
+ }
+
+ if (win->modalLevel < 0) {
+ fprintf(stderr, "DoModal: %s modalLevel < 0",
+ win->nameStr?win->nameStr:"<NULL>");
+ abort();
+ }
+ }
+ }
+
+ if (modal) {
+ gtk_main();
+ } else {
+ gtk_main_quit();
+ }
}
/**
@@ -553,32 +535,32 @@ void wlibDoModal(
*/
const char * wWinGetTitle(
- wWin_p win) /* Window */
+ wWin_p win) /* Window */
{
- return win->labelStr;
+ return win->labelStr;
}
void wWinClear(
- wWin_p win,
- wWinPix_t x,
- wWinPix_t y,
- wWinPix_t width,
- wWinPix_t height)
+ wWin_p win,
+ wWinPix_t x,
+ wWinPix_t y,
+ wWinPix_t width,
+ wWinPix_t height)
{
}
void wWinDoCancel(
- wWin_p win)
+ wWin_p win)
{
- wControl_p b;
+ wControl_p b;
- for (b=win->first; b; b=b->next) {
- if ((b->type == B_BUTTON) && (b->option & BB_CANCEL)) {
- wlibButtonDoAction((wButton_p)b);
- }
- }
+ for (b=win->first; b; b=b->next) {
+ if ((b->type == B_BUTTON) && (b->option & BB_CANCEL)) {
+ wlibButtonDoAction((wButton_p)b);
+ }
+ }
}
/*
@@ -590,155 +572,161 @@ void wWinDoCancel(
*/
static int window_redraw(
- wWin_p win,
- wBool_t doWinProc)
+ wWin_p win,
+ wBool_t doWinProc)
{
- wControl_p b;
+ wControl_p b;
- if (win==NULL) {
- return FALSE;
- }
+ if (win==NULL) {
+ return FALSE;
+ }
- for (b=win->first; b != NULL; b = b->next) {
- if (b->repaintProc) {
- b->repaintProc(b);
- }
- }
+ for (b=win->first; b != NULL; b = b->next) {
+ if (b->repaintProc) {
+ b->repaintProc(b);
+ }
+ }
- return FALSE;
+ return FALSE;
}
static gint window_delete_event(
- GtkWidget *widget,
- GdkEvent *event,
- wWin_p win)
+ GtkWidget *widget,
+ GdkEvent *event,
+ wWin_p win)
{
- wControl_p b;
- /* if you return FALSE in the "delete_event" signal handler,
- * GTK will emit the "destroy" signal. Returning TRUE means
- * you don't want the window to be destroyed.
- * This is useful for popping up 'are you sure you want to quit ?'
- * type dialogs. */
-
- /* Change TRUE to FALSE and the main window will be destroyed with
- * a "delete_event". */
-
- for (b = win->first; b; b=b->next)
- if (b->doneProc) {
- b->doneProc(b);
- }
-
- if (win->winProc) {
- win->winProc(win, wClose_e, NULL, win->data);
-
- if (win != gtkMainW) {
- wWinShow(win, FALSE);
- }
- }
-
- return (TRUE);
+ wControl_p b;
+ /* if you return FALSE in the "delete_event" signal handler,
+ * GTK will emit the "destroy" signal. Returning TRUE means
+ * you don't want the window to be destroyed.
+ * This is useful for popping up 'are you sure you want to quit ?'
+ * type dialogs. */
+
+ /* Change TRUE to FALSE and the main window will be destroyed with
+ * a "delete_event". */
+
+ for (b = win->first; b; b=b->next)
+ if (b->doneProc) {
+ b->doneProc(b);
+ }
+
+ if (win->winProc) {
+ win->winProc(win, wClose_e, NULL, win->data);
+
+ if (win != gtkMainW) {
+ wWinShow(win, FALSE);
+ }
+ }
+
+ return (TRUE);
}
static int fixed_expose_event(
- GtkWidget * widget,
- GdkEventExpose * event,
- wWin_p win)
+ GtkWidget * widget,
+ GdkEventExpose * event,
+ wWin_p win)
{
int rc;
- if (event->count==0) {
- rc = window_redraw(win, TRUE);
- } else {
- rc = FALSE;
- }
- cairo_t* cr = gdk_cairo_create (gtk_widget_get_window(widget));
-#ifdef CURSOR_SURFACE
- if (win && win->cursor_surface.surface && win->cursor_surface.show) {
- cairo_set_source_surface(cr,win->cursor_surface.surface,event->area.x, event->area.y);
- cairo_set_operator(cr,CAIRO_OPERATOR_OVER);
- cairo_rectangle(cr,event->area.x, event->area.y,
- event->area.width, event->area.height);
- cairo_fill(cr);
+ if (event->count==0) {
+ rc = window_redraw(win, TRUE);
+ } else {
+ rc = FALSE;
}
-#endif
- return rc;
+ return rc;
}
-static int resizeTime(wWin_p win) {
+static int resizeTime(wWin_p win)
+{
- if (win->resizeW == win->w && win->resizeH == win->h) { // If hasn't changed since last
+ if (debugWindow >= 2) {
+ printf( "resizeTime idleCnt %d, busyCnt %d [%d %d] [%ld %ld]\n",
+ win->timer_idle_count, win->timer_busy_count,
+ win->resizeW, win->resizeH, win->w, win->h );
+ }
+ if (win->resizeW == win->w
+ && win->resizeH == win->h) { // If hasn't changed since last
if (win->timer_idle_count>3) {
- win->winProc(win, wResize_e, NULL, win->data); //Trigger Redraw on last occasion if one-third of a second has elapsed
+ win->winProc(win, wResize_e, NULL,
+ win->data); //Trigger Redraw on last occasion if one-third of a second has elapsed
win->timer_idle_count = 0;
win->resizeTimer = 0;
win->timer_busy_count = 0;
return FALSE; //Stop Timer and don't resize
- } else win->timer_idle_count++;
+ } else { win->timer_idle_count++; }
}
if (win->busy==FALSE && win->winProc) { //Always drive once
if (win->timer_busy_count>10) {
- win->winProc(win, wResize_e, NULL, win->data); //Redraw if ten times we saw a change (1 sec)
- win->timer_busy_count = 0;
+ win->winProc(win, wResize_e, NULL,
+ win->data); //Redraw if ten times we saw a change (1 sec)
+ win->timer_busy_count = 0;
} else {
win->winProc(win, wResize_e, (void*) 1, win->data); //No Redraw
win->timer_busy_count++;
}
- win->resizeW = win->w; //Remember this one
- win->resizeH = win->h;
+ 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)
+ GtkWidget * widget,
+ GdkEventConfigure * event,
+ wWin_p win)
{
- if (win==NULL) {
- return FALSE;
- }
-
- 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;
- win->h = event->height;
-
- if (win->w < MIN_WIN_WIDTH) {
- win->w = MIN_WIN_WIDTH;
- }
-
- if (win->h < MIN_WIN_HEIGHT) {
- win->h = MIN_WIN_HEIGHT;
- }
-
- if (win->option&F_MENUBAR) {
- 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->resizeTimer) { // Already have a timer
- return FALSE;
- } else {
- win->resizeW = w; //Remember where this started
- win->resizeH = h;
- win->timer_idle_count = 0; //Start background timer on redraw
- win->timer_busy_count = 0;
- win->resizeTimer = g_timeout_add(100,(GSourceFunc)resizeTime,win); // 100ms delay
- return FALSE;
- }
- }
- }
-
- return FALSE;
+ if (win==NULL) {
+ return FALSE;
+ }
+
+ if (debugWindow >= 2) {
+ printf( "config/resize: [%d %d]\n", event->width, event->height );
+ }
+ 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) {
+ if (debugWindow >= 2) {
+ printf( " Update [%ld %ld]\n", event->width-win->w, event->height-win->h );
+ }
+ win->w = event->width;
+ win->h = event->height;
+
+ if (win->w < MIN_WIN_WIDTH) {
+ win->w = MIN_WIN_WIDTH;
+ }
+
+ if (win->h < MIN_WIN_HEIGHT) {
+ win->h = MIN_WIN_HEIGHT;
+ }
+
+ if (win->option&F_MENUBAR) {
+ 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->resizeTimer) { // Already have a timer
+ return FALSE;
+ } else {
+ win->resizeW = w; //Remember where this started
+ win->resizeH = h;
+ win->timer_idle_count = 0; //Start background timer on redraw
+ win->timer_busy_count = 0;
+ win->resizeTimer = g_timeout_add(100,(GSourceFunc)resizeTime,
+ win); // 100ms delay
+ return FALSE;
+ }
+ }
+ }
+
+ return FALSE;
}
/**
@@ -753,25 +741,25 @@ static int window_configure_event(
*/
gboolean window_state_event(
- GtkWidget *widget,
- GdkEventWindowState *event,
- wWin_p win)
+ GtkWidget *widget,
+ GdkEventWindowState *event,
+ wWin_p win)
{
- if (!win) {
- return (FALSE);
- }
+ if (!win) {
+ return (FALSE);
+ }
- win->maximize_initially = FALSE;
+ win->maximize_initially = FALSE;
- if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
- win->maximize_initially = TRUE;
- }
+ if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
+ win->maximize_initially = TRUE;
+ }
- if (win->busy==FALSE && win->winProc) {
- win->winProc(win, wState_e, NULL, win->data);
- }
+ if (win->busy==FALSE && win->winProc) {
+ win->winProc(win, wState_e, NULL, win->data);
+ }
- return TRUE;
+ return TRUE;
}
/**
* Get current state of shift, ctrl or alt keys.
@@ -781,87 +769,90 @@ gboolean window_state_event(
int wGetKeyState(void)
{
- return keyState;
+ return keyState;
}
wBool_t catch_shift_ctrl_alt_keys(
- GtkWidget * widget,
- GdkEventKey *event,
- void * data)
+ GtkWidget * widget,
+ GdkEventKey *event,
+ void * data)
{
- int state = 0;
- switch (event->keyval ) {
- case GDK_KEY_Shift_L:
- case GDK_KEY_Shift_R:
- state |= WKEY_SHIFT;
- break;
-
- case GDK_KEY_Control_L:
- case GDK_KEY_Control_R:
- state |= WKEY_CTRL;
- break;
-
- case GDK_KEY_Alt_L:
- case GDK_KEY_Alt_R:
- state |= WKEY_ALT;
- break;
-
- case GDK_KEY_Meta_L:
- case GDK_KEY_Meta_R:
- // Pressing SHIFT and then ALT generates a Meta key
- //printf( "Meta\n" );
- state |= WKEY_ALT;
- break;
- }
-
- if (state != 0) {
- if (event->type == GDK_KEY_PRESS) {
- keyState |= state;
- } else {
- keyState &= ~state;
- }
- return TRUE;
- }
- return FALSE;
+ int state = 0;
+ switch (event->keyval ) {
+ case GDK_KEY_Shift_L:
+ case GDK_KEY_Shift_R:
+ state |= WKEY_SHIFT;
+ break;
+
+ case GDK_KEY_Control_L:
+ case GDK_KEY_Control_R:
+ state |= WKEY_CTRL;
+ break;
+
+ case GDK_KEY_Alt_L:
+ case GDK_KEY_Alt_R:
+ state |= WKEY_ALT;
+ break;
+
+ case GDK_KEY_Meta_L:
+ case GDK_KEY_Meta_R:
+ // Pressing SHIFT and then ALT generates a Meta key
+ //printf( "Meta\n" );
+ state |= WKEY_ALT;
+ break;
+ }
+
+ if (state != 0) {
+ if (event->type == GDK_KEY_PRESS) {
+ keyState |= state;
+ } else {
+ keyState &= ~state;
+ }
+ return TRUE;
+ }
+ return FALSE;
}
static gint window_char_event(
- GtkWidget * widget,
- GdkEventKey *event,
- wWin_p win)
+ GtkWidget * widget,
+ GdkEventKey *event,
+ wWin_p win)
{
- wControl_p bb;
-
- if (catch_shift_ctrl_alt_keys(widget, event, win)) {
- return FALSE;
- }
-
- if (event->type == GDK_KEY_RELEASE) {
- return FALSE;
- }
-
- if ( ( event->state & GDK_MODIFIER_MASK ) == 0 ) {
- if (event->keyval == GDK_KEY_Escape) {
- for (bb=win->first; bb; bb=bb->next) {
- if (bb->type == B_BUTTON && (bb->option&BB_CANCEL)) {
- wlibButtonDoAction((wButton_p)bb);
- return TRUE;
- }
- }
- }
- }
-
- if (wlibHandleAccelKey(event)) {
- return TRUE;
- } else {
- return FALSE;
- }
+ wControl_p bb;
+
+ if (catch_shift_ctrl_alt_keys(widget, event, win)) {
+ return FALSE;
+ }
+
+ if (event->type == GDK_KEY_RELEASE) {
+ return FALSE;
+ }
+
+ if ( ( event->state & GDK_MODIFIER_MASK ) == 0 ) {
+ if (event->keyval == GDK_KEY_Escape) {
+ for (bb=win->first; bb; bb=bb->next) {
+ if (bb->type == B_BUTTON && (bb->option&BB_CANCEL)) {
+ wlibButtonDoAction((wButton_p)bb);
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ if (wlibHandleAccelKey(event)) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
}
-void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, wWinPix_t min_height, wWinPix_t max_height, wWinPix_t base_width, wWinPix_t base_height, double aspect_ratio ) {
+void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width,
+ wWinPix_t min_height, wWinPix_t max_height, wWinPix_t base_width,
+ wWinPix_t base_height, double aspect_ratio )
+{
GdkGeometry hints;
GdkWindowHints hintMask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE;
- hints.min_width = min_width;
+ hints.min_width = min_width;
hints.max_width = max_width;
hints.min_height = min_height;
hints.max_height = max_height;
@@ -871,16 +862,16 @@ void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, wWinPix_
if( base_width != -1 && base_height != -1 ) {
hintMask |= GDK_HINT_BASE_SIZE;
}
-
+
if(aspect_ratio > -1.0 ) {
hintMask |= GDK_HINT_ASPECT;
- }
+ }
gtk_window_set_geometry_hints(
- GTK_WINDOW(win->gtkwin),
- win->gtkwin,
- &hints,
- hintMask);
+ GTK_WINDOW(win->gtkwin),
+ win->gtkwin,
+ &hints,
+ hintMask);
}
@@ -911,166 +902,158 @@ void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, wWinPix_
*/
static wWin_p wWinCommonCreate(
- wWin_p parent,
- int winType,
- wWinPix_t x,
- wWinPix_t y,
- const char * labelStr,
- const char * nameStr,
- long option,
- wWinCallBack_p winProc,
- void * data)
+ wWin_p parent,
+ int winType,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * labelStr,
+ const char * nameStr,
+ long option,
+ wWinCallBack_p winProc,
+ void * data)
{
- wWin_p w;
- int h;
- w = wlibAlloc(NULL, winType, x, y, labelStr, sizeof *w, data);
- w->busy = TRUE;
- w->option = option;
+ wWin_p w;
+ int h;
+ w = wlibAlloc(NULL, winType, x, y, labelStr, sizeof *w, data);
+ w->busy = TRUE;
+ w->option = option;
w->resizeTimer = 0;
- h = BORDERSIZE;
-
- if (w->option&F_MENUBAR) {
- h += MENUH;
- }
-
- if (winType == W_MAIN) {
- w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- } else {
- w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- if (gtkMainW) {
- if (!(w->option&F_NOTTRANSIENT))
- gtk_window_set_transient_for(GTK_WINDOW(w->gtkwin),
- GTK_WINDOW(gtkMainW->gtkwin));
- }
- }
- getWinSize(w, nameStr);
- if (winType != W_MAIN) {
- gtk_widget_set_app_paintable (w->gtkwin,TRUE);
- }
-
- if (option & F_HIDE) {
- gtk_widget_hide(w->gtkwin);
- }
-
- /* center window on top of parent window */
- if (option & F_CENTER) {
- gtk_window_set_position(GTK_WINDOW(w->gtkwin), GTK_WIN_POS_CENTER_ON_PARENT);
- }
-
-
- w->widget = gtk_fixed_new();
-
- if (w->widget == 0) {
- abort();
- }
-
- if (w->option&F_MENUBAR) {
- w->menubar = gtk_menu_bar_new();
- gtk_container_add(GTK_CONTAINER(w->widget), w->menubar);
- gtk_widget_show(w->menubar);
- 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);
-
-
-
-
- if (w->option&F_AUTOSIZE) {
- w->realX = 0;
- w->w = MIN_WIN_WIDTH+20;
- w->realY = h;
- w->h = MIN_WIN_HEIGHT;
- } else if (w->origX != 0){
- w->realX = w->origX;
- w->realY = w->origY+h;
-
- w->default_size_x = w->w;
- w->default_size_y = 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-20, MENUH);
- }
- }
- wWinPix_t scr_w, scr_h;
- wGetDisplaySize(&scr_w, &scr_h);
- if (scr_w < MIN_WIN_WIDTH) scr_w = MIN_WIN_WIDTH+10;
- if (scr_h < MIN_WIN_HEIGHT) scr_h = MIN_WIN_HEIGHT;
+ h = BORDERSIZE;
+
+ if (w->option&F_MENUBAR) {
+ h += MENUH;
+ }
+
+ if (winType == W_MAIN) {
+ w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ } else {
+ w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ if (gtkMainW) {
+ if (!(w->option&F_NOTTRANSIENT))
+ gtk_window_set_transient_for(GTK_WINDOW(w->gtkwin),
+ GTK_WINDOW(gtkMainW->gtkwin));
+ }
+ }
+ getWinSize(w, nameStr);
if (winType != W_MAIN) {
- wSetGeometry(w, MIN_WIN_WIDTH, scr_w-10, MIN_WIN_HEIGHT, scr_h, -1, -1, -1);
+ gtk_widget_set_app_paintable (w->gtkwin,TRUE);
+ }
+
+ if (option & F_HIDE) {
+ gtk_widget_hide(w->gtkwin);
+ }
+
+ /* center window on top of parent window */
+ if (option & F_CENTER) {
+ gtk_window_set_position(GTK_WINDOW(w->gtkwin), GTK_WIN_POS_CENTER_ON_PARENT);
+ }
+
+
+ w->widget = gtk_fixed_new();
+
+ if (w->widget == 0) {
+ abort();
+ }
+
+ if (w->option&F_MENUBAR) {
+ w->menubar = gtk_menu_bar_new();
+ gtk_container_add(GTK_CONTAINER(w->widget), w->menubar);
+ gtk_widget_show(w->menubar);
+ 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);
+
+
+
+
+ if (w->option&F_AUTOSIZE) {
+ w->realX = 0;
+ w->w = 0;
+ w->realY = h;
+ w->h = 0;
+ } else if (w->origX != 0) {
+ w->realX = w->origX;
+ w->realY = w->origY+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-20, MENUH);
+ }
+ }
+
+ w->first = w->last = NULL;
+ w->winProc = winProc;
+ g_signal_connect(GTK_OBJECT(w->gtkwin), "delete_event",
+ G_CALLBACK(window_delete_event), w);
+ g_signal_connect(GTK_OBJECT(w->widget), "expose_event",
+ 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",
+ G_CALLBACK(window_char_event), w);
+ gtk_widget_set_events(w->widget, GDK_EXPOSURE_MASK);
+ gtk_widget_set_events(GTK_WIDGET(w->gtkwin),
+ GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
+
+ if (w->option & F_RESIZE) {
+ gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), TRUE);
+ if ( ( w->option & F_AUTOSIZE ) == 0 ) {
+ gtk_window_resize(GTK_WINDOW(w->gtkwin), w->w, w->h);
+ }
} else {
- if (scr_w < MIN_WIN_WIDTH_MAIN+10) scr_w = MIN_WIN_WIDTH_MAIN+200;
- if (scr_h < MIN_WIN_HEIGHT_MAIN+10) scr_h = MIN_WIN_HEIGHT_MAIN+200;
- wSetGeometry(w, MIN_WIN_WIDTH_MAIN, scr_w-10, MIN_WIN_HEIGHT_MAIN, scr_h-10, -1, -1, -1);
- }
-
-
-
- w->first = w->last = NULL;
- w->winProc = winProc;
- g_signal_connect(GTK_OBJECT(w->gtkwin), "delete_event",
- G_CALLBACK(window_delete_event), w);
- g_signal_connect(GTK_OBJECT(w->widget), "expose_event",
- 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",
- G_CALLBACK(window_char_event), w);
- gtk_widget_set_events(w->widget, GDK_EXPOSURE_MASK);
- gtk_widget_set_events(GTK_WIDGET(w->gtkwin),
- GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
-
- if (w->option & F_RESIZE) {
- gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), TRUE);
- gtk_window_resize(GTK_WINDOW(w->gtkwin), w->w, w->h);
- } else {
- gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), FALSE);
- }
-
- w->lastX = 0;
- w->lastY = h;
- w->shown = FALSE;
- w->nameStr = nameStr?strdup(nameStr):NULL;
-
- if (labelStr) {
- gtk_window_set_title(GTK_WINDOW(w->gtkwin), labelStr);
- }
-
- if (listHelpStrings) {
- printf("WINDOW - %s\n", nameStr?nameStr:"<NULL>");
- }
-
- if (firstWin) {
- lastWin->next = (wControl_p)w;
- } else {
- firstWin = (wControl_p)w;
- }
-
- 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;
+ gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), FALSE);
+ }
+
+ w->lastX = 0;
+ w->lastY = h;
+ w->shown = FALSE;
+ w->nameStr = nameStr?strdup(nameStr):NULL;
+
+ if (labelStr) {
+ gtk_window_set_title(GTK_WINDOW(w->gtkwin), labelStr);
+ }
+
+ if (listHelpStrings) {
+ printf("WINDOW - %s\n", nameStr?nameStr:"<NULL>");
+ }
+
+ if (firstWin) {
+ lastWin->next = (wControl_p)w;
+ } else {
+ firstWin = (wControl_p)w;
+ }
+
+ 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;
+ }
+
+ if ( windowIconPixbuf == NULL ) {
+ windowIconPixbuf = gdk_pixbuf_new_from_xpm_data((const char**)&xtc_xpm);
+ }
+ gtk_window_set_icon( GTK_WINDOW(w->gtkwin), windowIconPixbuf );
+
+ return w;
}
@@ -1091,38 +1074,38 @@ static wWin_p wWinCommonCreate(
*/
wWin_p wWinMainCreate(
- const char * name, /* Application name */
- wWinPix_t x, /* Initial window width */
- wWinPix_t y, /* Initial window height */
- const char * helpStr, /* Help topic string */
- const char * labelStr, /* Window title */
- const char * nameStr, /* Window name */
- long option, /* Options */
- wWinCallBack_p winProc, /* Call back function */
- void * data) /* User context */
+ const char * name, /* Application name */
+ wWinPix_t x, /* Initial window width */
+ wWinPix_t y, /* Initial window height */
+ const char * helpStr, /* Help topic string */
+ const char * labelStr, /* Window title */
+ const char * nameStr, /* Window name */
+ long option, /* Options */
+ wWinCallBack_p winProc, /* Call back function */
+ void * data) /* User context */
{
- char *pos;
- long isMaximized;
+ char *pos;
+ long isMaximized;
- pos = strchr(name, ';');
+ pos = strchr(name, ';');
- if (pos) {
- /* if found, split application name and configuration name */
- strcpy(wConfigName, pos + 1);
- } else {
- /* if not found, application name and configuration name are same */
- strcpy(wConfigName, name);
- }
+ if (pos) {
+ /* if found, split application name and configuration name */
+ strcpy(wConfigName, pos + 1);
+ } else {
+ /* if not found, application name and configuration name are same */
+ strcpy(wConfigName, name);
+ }
- wPrefGetInteger("draw", "maximized", &isMaximized, 0);
- option = option | (isMaximized?F_MAXIMIZE:0);
+ wPrefGetInteger("draw", "maximized", &isMaximized, 0);
+ option = option | (isMaximized?F_MAXIMIZE:0);
- gtkMainW = wWinCommonCreate(NULL, W_MAIN, x, y, labelStr, nameStr, option,
- winProc, data);
+ gtkMainW = wWinCommonCreate(NULL, W_MAIN, x, y, labelStr, nameStr, option,
+ winProc, data);
- wDrawColorWhite = wDrawFindColor(0xFFFFFF);
- wDrawColorBlack = wDrawFindColor(0x000000);
- return gtkMainW;
+ wDrawColorWhite = wDrawFindColor(0xFFFFFF);
+ wDrawColorBlack = wDrawFindColor(0x000000);
+ return gtkMainW;
}
/**
@@ -1141,29 +1124,29 @@ wWin_p wWinMainCreate(
*/
wWin_p wWinPopupCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- const char * nameStr,
- long option,
- wWinCallBack_p winProc,
- void * data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ const char * nameStr,
+ long option,
+ wWinCallBack_p winProc,
+ void * data)
{
- wWin_p win;
+ wWin_p win;
- if (parent == NULL) {
- if (gtkMainW == NULL) {
- abort();
- }
+ if (parent == NULL) {
+ if (gtkMainW == NULL) {
+ abort();
+ }
- parent = gtkMainW;
- }
+ parent = gtkMainW;
+ }
- win = wWinCommonCreate(parent, W_POPUP, x, y, labelStr, nameStr, option,
- winProc, data);
- return win;
+ win = wWinCommonCreate(parent, W_POPUP, x, y, labelStr, nameStr, option,
+ winProc, data);
+ return win;
}
@@ -1178,22 +1161,22 @@ wWin_p wWinPopupCreate(
void wExit(
- int rc) /* Application return code */
+ int rc) /* Application return code */
{
- wWin_p win;
+ wWin_p win;
- for (win = (wWin_p)firstWin; win; win = (wWin_p)win->next) {
- if (gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) {
- saveSize(win);
- savePos(win);
- }
- }
+ for (win = (wWin_p)firstWin; win; win = (wWin_p)win->next) {
+ if (gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) {
+ saveSize(win);
+ savePos(win);
+ }
+ }
- wPrefFlush("");
+ wPrefFlush("");
- if (gtkMainW && gtkMainW->winProc != NULL) {
- gtkMainW->winProc(gtkMainW, wQuit_e, NULL, gtkMainW->data);
- }
+ if (gtkMainW && gtkMainW->winProc != NULL) {
+ gtkMainW->winProc(gtkMainW, wQuit_e, NULL, gtkMainW->data);
+ }
- exit(rc);
+ exit(rc);
}
diff --git a/app/wlib/gtklib/wpref.c b/app/wlib/gtklib/wpref.c
index 3494ba2..356dd95 100644
--- a/app/wlib/gtklib/wpref.c
+++ b/app/wlib/gtklib/wpref.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -26,6 +26,7 @@
#include <ctype.h>
#include <dirent.h>
#include <sys/stat.h>
+#include <errno.h>
#define GTK_DISABLE_SINGLE_INCLUDES
#define GDK_DISABLE_DEPRECATED
@@ -47,6 +48,8 @@ extern char wConfigName[];
static char appLibDir[BUFSIZ];
static char appWorkDir[BUFSIZ];
static char userHomeDir[BUFSIZ];
+
+static char *profileFile;
/*
@@ -58,13 +61,13 @@ static char userHomeDir[BUFSIZ];
*/
-/** Find the directory where configuration files, help, demos etc are installed.
+/** Find the directory where configuration files, help, demos etc are installed.
* The search order is:
* 1. Directory specified by the XTRKCADLIB environment variable
* 2. Directory specified by XTRKCAD_INSTALL_PREFIX/share/xtrkcad
* 3. /usr/share/xtrkcad
* 4. /usr/local/share/xtrkcad
- *
+ *
* \return pointer to directory name
*/
@@ -79,13 +82,19 @@ const char * wGetAppLibDir( void )
return appLibDir;
}
- for (cp=wlibGetAppName(),ep=envvar; *cp; cp++,ep++)
+ for (cp=wlibGetAppName(),ep=envvar; *cp; cp++,ep++) {
*ep = toupper(*cp);
- strcpy( ep, "LIB" );
+ }
+#ifndef __APPLE__
+ if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) {
+ strcat( ep, "BETA" );
+ }
+#endif
+ strcat( ep, "LIB" );
ep = getenv( envvar );
if (ep != NULL) {
if ((stat( ep, &buf) == 0 ) && S_ISDIR( buf.st_mode)) {
- strncpy( appLibDir, ep, sizeof appLibDir );
+ strncpy( appLibDir, ep, sizeof(appLibDir) -1 );
//printf( "wAppLbDir=%s\n", appLibDir );
return appLibDir;
}
@@ -100,13 +109,18 @@ const char * wGetAppLibDir( void )
char * dir1 = "/usr/share/";
char * dir2 = "/usr/local/share/";
+ char * beta = "";
if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) {
dir1 = "/usr/local/share/";
dir2 = "/usr/share/";
+#ifndef __APPLE__
+ beta = "-beta";
+#endif
}
strcpy( appLibDir, dir1 );
strcat( appLibDir, wlibGetAppName() );
+ strcat( appLibDir, beta );
if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) {
//printf( "wAppLbDir=%s\n", appLibDir );
return appLibDir;
@@ -120,14 +134,14 @@ const char * wGetAppLibDir( void )
}
sprintf( msg,
- _("The required configuration files could not be located in the expected location.\n\n"
- "Usually this is an installation problem. Make sure that these files are installed in either \n"
- " ../share/xtrkcad or\n"
- " /usr/share/%s or\n"
- " /usr/local/share/%s\n"
- "If this is not possible, the environment variable %s must contain "
- "the name of the correct directory."),
- wlibGetAppName(), wlibGetAppName(), envvar );
+ _("The required configuration files could not be located in the expected location.\n\n"
+ "Usually this is an installation problem. Make sure that these files are installed in either \n"
+ " ../share/xtrkcad or\n"
+ " /usr/share/%s or\n"
+ " /usr/local/share/%s\n"
+ "If this is not possible, the environment variable %s must contain "
+ "the name of the correct directory."),
+ wlibGetAppName(), wlibGetAppName(), envvar );
wNoticeEx( NT_ERROR, msg, _("Ok"), NULL );
appLibDir[0] = '\0';
wExit(0);
@@ -144,20 +158,26 @@ const char * wGetAppLibDir( void )
const char * wGetAppWorkDir(
- void )
+ void )
{
char tmp[BUFSIZ+20];
char * homeDir;
DIR *dirp;
-
- if (appWorkDir[0] != '\0')
+
+ if (appWorkDir[0] != '\0') {
return appWorkDir;
+ }
if ((homeDir = getenv( "HOME" )) == NULL) {
wNoticeEx( NT_ERROR, _("HOME is not set"), _("Exit"), NULL);
wExit(0);
}
sprintf( appWorkDir, "%s/.%s", homeDir, wlibGetAppName() );
+#ifndef __APPLE__
+ if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) {
+ strcat( appWorkDir, "-beta" );
+ }
+#endif
if ( (dirp = opendir(appWorkDir)) != NULL ) {
closedir(dirp);
} else {
@@ -166,18 +186,18 @@ const char * wGetAppWorkDir(
wNoticeEx( NT_ERROR, tmp, _("Exit"), NULL );
wExit(0);
} else {
- /*
- * check for default configuration file and copy to
+ /*
+ * check for default configuration file and copy to
* the workdir if it exists
*/
struct stat stFileInfo;
char appEtcConfig[BUFSIZ];
sprintf( appEtcConfig, "/etc/%s.rc", wlibGetAppName());
-
+
if ( stat( appEtcConfig, &stFileInfo ) == 0 ) {
char copyConfigCmd[(BUFSIZ * 2) + 3];
sprintf( copyConfigCmd, "cp %s %s", appEtcConfig, appWorkDir );
- int rc = system( copyConfigCmd );
+ system( copyConfigCmd );
}
}
}
@@ -194,16 +214,17 @@ const char * wGetAppWorkDir(
const char *wGetUserHomeDir( void )
{
char *homeDir;
-
- if( userHomeDir[ 0 ] != '\0' )
+
+ if( userHomeDir[ 0 ] != '\0' ) {
return userHomeDir;
-
+ }
+
if ((homeDir = getenv( "HOME" )) == NULL) {
wNoticeEx( NT_ERROR, _("HOME is not set"), _("Exit"), NULL);
wExit(0);
} else {
strcpy( userHomeDir, homeDir );
- }
+ }
return userHomeDir;
}
@@ -218,62 +239,101 @@ const char *wGetUserHomeDir( void )
*/
typedef struct {
- char * section;
- char * name;
- wBool_t present;
- wBool_t dirty;
- char * val;
- } prefs_t;
+ char * section;
+ char * name;
+ wBool_t present;
+ wBool_t dirty;
+ char * val;
+} prefs_t;
dynArr_t prefs_da;
#define prefs(N) DYNARR_N(prefs_t,prefs_da,N)
wBool_t prefInitted = FALSE;
/**
+ * Define the name of the configuration file. Needed size is calculated, allocated and
+ * initialized with the filename
+ *
+ * \param name overwrite default configuration
+ */
+
+void static
+wlibSetProfileFilename(char *name)
+{
+ const char *workDir;
+
+ workDir = wGetAppWorkDir();
+ if (name && name[0]) {
+ size_t length;
+ length = snprintf(profileFile, 0, "%s", name);
+ profileFile = malloc(length + sizeof(NULL));
+ snprintf( profileFile, length, "%s", name );
+ } else {
+ size_t length;
+ length = snprintf(profileFile, 0, "%s/%s.rc", workDir, wConfigName );
+ profileFile = malloc(length + sizeof(NULL));
+ length = snprintf(profileFile, length+sizeof(NULL), "%s/%s.rc", workDir, wConfigName );
+ }
+}
+
+
+/**
+ * Get the name of the configuration file.
+ *
+ * \return pointer to the filename.
+ *
+ */
+
+char *
+wGetProfileFilename()
+{
+ return(profileFile);
+}
+
+/**
* Read the configuration file into memory
*/
static void readPrefs( char * name, wBool_t update )
{
- char tmp[BUFSIZ], *np, *vp, *cp;
- const char * workDir;
+ char tmp[BUFSIZ+32], *np, *vp, *cp;
FILE * prefFile;
prefs_t * p;
prefInitted = TRUE;
- workDir = wGetAppWorkDir();
- if (name && name[0])
- sprintf( tmp, "%s", name );
- else
- sprintf( tmp, "%s/%s.rc", workDir, wConfigName );
- prefFile = fopen( tmp, "r" );
- if (prefFile == NULL)
+ wlibSetProfileFilename(name);
+
+ prefFile = fopen( profileFile, "r" );
+ if (prefFile == NULL) {
+ // First run, no .rc file yet
return;
+ }
while ( ( fgets(tmp, sizeof tmp, prefFile) ) != NULL ) {
char *sp;
-
+
sp = tmp;
- while ( *sp==' ' || *sp=='\t' ) sp++;
- if ( *sp == '\n' || *sp == '#' )
+ while ( *sp==' ' || *sp=='\t' ) { sp++; }
+ if ( *sp == '\n' || *sp == '#' ) {
continue;
+ }
np = strchr( sp, '.' );
if (np == NULL) {
wNoticeEx( NT_INFORMATION, tmp, _("Continue"), NULL );
continue;
}
*np++ = '\0';
- while ( *np==' ' || *np=='\t' ) np++;
+ while ( *np==' ' || *np=='\t' ) { np++; }
vp = strchr( np, ':' );
if (vp == NULL) {
wNoticeEx( NT_INFORMATION, tmp, _("Continue"), NULL );
continue;
}
*vp++ = '\0';
- while ( *vp==' ' || *vp=='\t' ) vp++;
+ while ( *vp==' ' || *vp=='\t' ) { vp++; }
cp = vp + strlen(vp) -1;
- while ( cp >= vp && (*cp=='\n' || *cp==' ' || *cp=='\t') ) cp--;
+ while ( cp >= vp && (*cp=='\n' || *cp==' ' || *cp=='\t') ) { cp--; }
cp[1] = '\0';
if (update) {
- for (int i=0;i<prefs_da.cnt;i++) {
+ for (int i=0; i<prefs_da.cnt; i++) {
p = &DYNARR_N(prefs_t,prefs_da,i);
if (strcmp(p->name,np)==0 && strcmp(p->section,sp)==0) {
p->val = strdup(vp);
@@ -302,19 +362,21 @@ static void readPrefs( char * name, wBool_t update )
*/
void wPrefSetString(
- const char * section, /* Section */
- const char * name, /* Name */
- const char * sval ) /* Value */
+ const char * section, /* Section */
+ const char * name, /* Name */
+ const char * sval ) /* Value */
{
prefs_t * p;
- if (!prefInitted)
+ if (!prefInitted) {
readPrefs("", FALSE);
-
+ }
+
for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
- if (p->val)
+ if (p->val) {
free(p->val);
+ }
p->dirty = TRUE;
p->val = (sval?strdup( sval ):NULL);
return;
@@ -336,14 +398,15 @@ void wPrefSetString(
*/
char * wPrefGetStringBasic(
- const char * section, /* Section */
- const char * name ) /* Name */
+ const char * section, /* Section */
+ const char * name ) /* Name */
{
prefs_t * p;
- if (!prefInitted)
+ if (!prefInitted) {
readPrefs("", FALSE);
-
+ }
+
for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
return p->val;
@@ -360,10 +423,10 @@ char * wPrefGetStringBasic(
* \param lval IN value to save
*/
- void wPrefSetInteger(
- const char * section, /* Section */
- const char * name, /* Name */
- long lval ) /* Value */
+void wPrefSetInteger(
+ const char * section, /* Section */
+ const char * name, /* Name */
+ long lval ) /* Value */
{
char tmp[20];
@@ -382,13 +445,13 @@ char * wPrefGetStringBasic(
*/
wBool_t wPrefGetIntegerBasic(
- const char * section, /* Section */
- const char * name, /* Name */
- long * res, /* Address of result */
- long def ) /* Default value */
+ const char * section, /* Section */
+ const char * name, /* Name */
+ long * res, /* Address of result */
+ long def ) /* Default value */
{
const char * cp;
- char *cp1;
+ char *cp1;
cp = wPrefGetStringBasic( section, name );
if (cp == NULL) {
@@ -404,17 +467,17 @@ wBool_t wPrefGetIntegerBasic(
}
/**
- * Save a float value in the preferences file.
+ * Save a float value in the preferences file.
*
* \param section IN the file section into which the value should be saved
* \param name IN the name of the preference
* \param lval IN the value
*/
- void wPrefSetFloat(
- const char * section, /* Section */
- const char * name, /* Name */
- double lval ) /* Value */
+void wPrefSetFloat(
+ const char * section, /* Section */
+ const char * name, /* Name */
+ double lval ) /* Value */
{
char tmp[20];
@@ -434,13 +497,13 @@ wBool_t wPrefGetIntegerBasic(
wBool_t wPrefGetFloatBasic(
- const char * section, /* Section */
- const char * name, /* Name */
- double * res, /* Address of result */
- double def ) /* Default value */
+ const char * section, /* Section */
+ const char * name, /* Name */
+ double * res, /* Address of result */
+ double def ) /* Default value */
{
const char * cp;
- char *cp1;
+ char *cp1;
cp = wPrefGetStringBasic( section, name );
if (cp == NULL) {
@@ -455,62 +518,117 @@ wBool_t wPrefGetFloatBasic(
return TRUE;
}
-void wPrefsLoad(char * name) {
+void wPrefsLoad(char * name)
+{
readPrefs(name,TRUE);
}
/**
* Save the configuration to a file. The config parameters are held and updated in an array.
- * To make the settings persistant, this function has to be called.
+ * To make the settings persistant, this function has to be called.
*
*/
void wPrefFlush(
- char * name )
+ char * name )
{
prefs_t * p;
- char tmp[BUFSIZ];
- const char *workDir;
+ char tmp[BUFSIZ+32];
FILE * prefFile;
- if (!prefInitted)
+ if (!prefInitted) {
return;
-
- workDir = wGetAppWorkDir();
- if (name && name[0])
- snprintf( tmp, sizeof(tmp), "%s", name );
- else
- snprintf( tmp, sizeof(tmp), "%s/%s.rc", workDir, wConfigName );
- prefFile = fopen( tmp, "w" );
- if (prefFile == NULL)
+ }
+
+ wlibSetProfileFilename(name);
+
+ prefFile = fopen( profileFile, "w" );
+ if (prefFile == NULL) {
+ // Can not write pref file
+ size_t n = BUFSIZ+32-1-strlen(tmp);
+ strncat( tmp, ": ", n );
+ strncat( tmp, strerror(errno), n-2 );
+ wNoticeEx( NT_ERROR, tmp, "Ok", NULL );
return;
+ }
for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
if(p->val) {
fprintf( prefFile, "%s.%s: %s\n", p->section, p->name, p->val );
- }
+ }
}
fclose( prefFile );
}
/**
* Clear the preferences from memory
- * \return
+ * \return
*/
void wPrefReset(
- void )
+ void )
{
prefs_t * p;
prefInitted = FALSE;
for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
- if (p->section)
+ if (p->section) {
free( p->section );
- if (p->name)
+ }
+ if (p->name) {
free( p->name );
- if (p->val)
+ }
+ if (p->val) {
free( p->val );
+ }
}
prefs_da.cnt = 0;
}
+
+/**
+ * Split a line from the config file ie. rc ini-file into separate tokens. The
+ * line is split into sections, name of value and value following. Pointers
+ * to the respective token are returned. These are zero-terminated.
+ * If a token is not present, NULL is returned instead.
+ * The input line is modified.
+ *
+ * \param line input line, modified during excution of function
+ * \param section section if present
+ * \param name name of config value if present
+ * \param value name of value if present
+ */
+void
+wPrefTokenize(char* line, char** section, char** name, char** value)
+{
+ *section = NULL;
+ *name = NULL;
+ *value = NULL;
+
+ *section = strtok(line, ".");
+ *name = strtok(NULL, ":");
+ *value = strtok(NULL, "\n");
+ if(*value)
+ g_strstrip(*value);
+
+}
+
+/**
+ * A valid line for a config file is created from the individual elements.
+ * Values not need for specific statement are ignored. Eg. when section is
+ * present, name and value are not used.
+ * The caller has to make sure, that the return buffer is large enough.
+ *
+ * \param section section, first token, dellimited with '.'
+ * \param name name, left side of ':'
+ * \param value value, right side of ':'
+ * \param result pointer to buffer for formated line.
+ */
+
+void
+wPrefFormatLine(const char* section, const char* name, const char* value, char* result)
+{
+ if (!value || *value == '\0') {
+ value = "";
+ }
+ sprintf(result, "%s.%s: %s", section, name, value);
+} \ No newline at end of file
diff --git a/app/wlib/gtklib/writebitmap.c b/app/wlib/gtklib/writebitmap.c
index be9aa62..0f5041a 100644
--- a/app/wlib/gtklib/writebitmap.c
+++ b/app/wlib/gtklib/writebitmap.c
@@ -1,5 +1,5 @@
/** \file writebitmap.c
- * Bitmap file creation
+ * Bitmap file creation
*/
/* XTrackCad - Model Railroad CAD
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define GTK_DISABLE_SINGLE_INCLUDES
@@ -34,21 +34,21 @@
/**
* Get the Extension part of a filename
- *
+ *
* /param fname the filename
- *
+ *
* /return char* point to the extension
*/
static const char *
GetExtension(const char *fname)
{
- const char *end = fname + strlen(fname);
+ const char *end = fname + strlen(fname);
- while (end > fname && *end != '.') {
- --end;
- }
- return( end + 1 );
+ while (end > fname && *end != '.') {
+ --end;
+ }
+ return( end + 1 );
}
/**
@@ -61,42 +61,42 @@ GetExtension(const char *fname)
wBool_t wBitMapWriteFile(wDraw_p d, const char * fileName)
{
- GdkPixbuf *pixbuf;
- GError *error;
- gboolean res;
- const char *fileFormat = GetExtension(fileName);
- char *writeFormat = NULL;
-
- if(!strcasecmp(fileFormat, PNGFORMAT )){
- writeFormat = PNGFORMAT;
- }
- if( !strcasecmp(fileFormat, "jpg") ||
- !strcasecmp(fileFormat, "jpeg")){
- writeFormat = JPEGFORMAT;
- }
-
- if(!writeFormat) {
- wNoticeEx(NT_ERROR, "WriteBitMap: invalid file format!", "Ok", NULL);
- return FALSE;
- }
-
- pixbuf = gdk_pixbuf_get_from_drawable(NULL, (GdkWindow*)d->pixmap, NULL, 0, 0,
- 0, 0, d->w, d->h);
-
- if (!pixbuf) {
- wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_get failed", "Ok", NULL);
- return FALSE;
- }
-
- error = NULL;
- res = gdk_pixbuf_save(pixbuf, fileName, writeFormat, &error, NULL);
-
- if (res == FALSE) {
- wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_save failed", "Ok", NULL);
- return FALSE;
- }
-
- g_object_ref_sink(pixbuf);
- g_object_unref(pixbuf);
- return TRUE;
+ GdkPixbuf *pixbuf;
+ GError *error;
+ gboolean res;
+ const char *fileFormat = GetExtension(fileName);
+ char *writeFormat = NULL;
+
+ if(!strcasecmp(fileFormat, PNGFORMAT )) {
+ writeFormat = PNGFORMAT;
+ }
+ if( !strcasecmp(fileFormat, "jpg") ||
+ !strcasecmp(fileFormat, "jpeg")) {
+ writeFormat = JPEGFORMAT;
+ }
+
+ if(!writeFormat) {
+ wNoticeEx(NT_ERROR, "WriteBitMap: invalid file format!", "Ok", NULL);
+ return FALSE;
+ }
+
+ pixbuf = gdk_pixbuf_get_from_drawable(NULL, (GdkWindow*)d->pixmap, NULL, 0, 0,
+ 0, 0, d->w, d->h);
+
+ if (!pixbuf) {
+ wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_get failed", "Ok", NULL);
+ return FALSE;
+ }
+
+ error = NULL;
+ res = gdk_pixbuf_save(pixbuf, fileName, writeFormat, &error, NULL);
+
+ if (res == FALSE) {
+ wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_save failed", "Ok", NULL);
+ return FALSE;
+ }
+
+ g_object_ref_sink(pixbuf);
+ g_object_unref(pixbuf);
+ return TRUE;
}
diff --git a/app/wlib/include/CMakeLists.txt b/app/wlib/include/CMakeLists.txt
new file mode 100644
index 0000000..5891b02
--- /dev/null
+++ b/app/wlib/include/CMakeLists.txt
@@ -0,0 +1,12 @@
+
+target_include_directories(xtrkcad-wlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+
+target_sources(xtrkcad-wlib
+ PUBLIC
+ wlib.h)
+
+if(WIN32)
+ target_sources(xtrkcad-wlib
+ PRIVATE
+ getopt.h)
+endif() \ No newline at end of file
diff --git a/app/wlib/include/getline.h b/app/wlib/include/getline.h
new file mode 100644
index 0000000..ffbb699
--- /dev/null
+++ b/app/wlib/include/getline.h
@@ -0,0 +1,132 @@
+#ifndef GETLINE_H
+#define GETLINE_H
+
+#include <stdio.h>
+
+#define restrict __restrict
+typedef long long ssize_t;
+
+ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict stream);
+ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim, FILE *restrict stream);
+
+/*
+~$ export MANWIDTH=80
+~$ man getline | col -b
+GETLINE(3) Linux Programmer's Manual GETLINE(3)
+
+NAME
+ getline, getdelim - delimited string input
+
+SYNOPSIS
+ #include <stdio.h>
+
+ ssize_t getline(char **lineptr, size_t *n, FILE *stream);
+
+ ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
+
+ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
+
+ getline(), getdelim():
+ Since glibc 2.10:
+ _POSIX_C_SOURCE >= 200809L
+ Before glibc 2.10:
+ _GNU_SOURCE
+
+DESCRIPTION
+ getline() reads an entire line from stream, storing the address of the
+ buffer containing the text into *lineptr. The buffer is null-termi-
+ nated and includes the newline character, if one was found.
+
+ If *lineptr is set to NULL and *n is set 0 before the call, then get-
+ line() will allocate a buffer for storing the line. This buffer should
+ be freed by the user program even if getline() failed.
+
+ Alternatively, before calling getline(), *lineptr can contain a pointer
+ to a malloc(3)-allocated buffer *n bytes in size. If the buffer is not
+ large enough to hold the line, getline() resizes it with realloc(3),
+ updating *lineptr and *n as necessary.
+
+ In either case, on a successful call, *lineptr and *n will be updated
+ to reflect the buffer address and allocated size respectively.
+
+ getdelim() works like getline(), except that a line delimiter other
+ than newline can be specified as the delimiter argument. As with get-
+ line(), a delimiter character is not added if one was not present in
+ the input before end of file was reached.
+
+RETURN VALUE
+ On success, getline() and getdelim() return the number of characters
+ read, including the delimiter character, but not including the termi-
+ nating null byte ('\0'). This value can be used to handle embedded
+ null bytes in the line read.
+
+ Both functions return -1 on failure to read a line (including end-of-
+ file condition). In the event of an error, errno is set to indicate
+ the cause.
+
+ERRORS
+ EINVAL Bad arguments (n or lineptr is NULL, or stream is not valid).
+
+ ENOMEM Allocation or reallocation of the line buffer failed.
+
+ATTRIBUTES
+ For an explanation of the terms used in this section, see at-
+ tributes(7).
+
+ +------------------------------------------------+
+ ¦Interface ¦ Attribute ¦ Value ¦
+ +----------------------+---------------+---------¦
+ ¦getline(), getdelim() ¦ Thread safety ¦ MT-Safe ¦
+ +------------------------------------------------+
+
+CONFORMING TO
+ Both getline() and getdelim() were originally GNU extensions. They
+ were standardized in POSIX.1-2008.
+
+EXAMPLE
+ #define _GNU_SOURCE
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int
+ main(int argc, char *argv[])
+ {
+ FILE *stream;
+ char *line = NULL;
+ size_t len = 0;
+ ssize_t nread;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <file>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ stream = fopen(argv[1], "r");
+ if (stream == NULL) {
+ perror("fopen");
+ exit(EXIT_FAILURE);
+ }
+
+ while ((nread = getline(&line, &len, stream)) != -1) {
+ printf("Retrieved line of length %zu:\n", nread);
+ fwrite(line, nread, 1, stdout);
+ }
+
+ free(line);
+ fclose(stream);
+ exit(EXIT_SUCCESS);
+ }
+
+SEE ALSO
+ read(2), fgets(3), fopen(3), fread(3), scanf(3)
+
+COLOPHON
+ This page is part of release 5.05 of the Linux man-pages project. A
+ description of the project, information about reporting bugs, and the
+ latest version of this page, can be found at
+ https://www.kernel.org/doc/man-pages/.
+
+GNU 2019-03-06 GETLINE(3)
+*/
+
+#endif /* GETLINE_H */
diff --git a/app/wlib/include/getopt.h b/app/wlib/include/getopt.h
index e9a8354..4a3ced4 100644
--- a/app/wlib/include/getopt.h
+++ b/app/wlib/include/getopt.h
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with ASPEX; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
extern char *optarg;
diff --git a/app/wlib/include/wlib.h b/app/wlib/include/wlib.h
index 7b89bdc..88b2806 100644
--- a/app/wlib/include/wlib.h
+++ b/app/wlib/include/wlib.h
@@ -7,6 +7,7 @@
#ifdef WINDOWS
#include <stdio.h>
#define FILE_SEP_CHAR "\\"
+#include "getline.h"
#else
#define FILE_SEP_CHAR "/"
#endif
@@ -23,8 +24,10 @@ char *g_win32_getlocale (void);
#endif
// conversion routines to and from UTF-8
-bool wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength);
-bool wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength);
+bool wSystemToUTF8(const char *inString, char *outString,
+ unsigned outStringLength);
+bool wUTF8ToSystem(const char *inString, char *outString,
+ unsigned outStringLength);
bool wIsUTF8(const char * string);
/*
@@ -74,7 +77,7 @@ typedef int wDrawColor;
typedef struct {
const char * name;
const char * value;
- } wBalloonHelp_t;
+} wBalloonHelp_t;
extern long debugWindow;
extern long wDebugFont;
@@ -84,8 +87,10 @@ extern long wDebugFont;
* Bitmap Controls bitmap.c
*/
-wControl_p wBitmapCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, long options, const struct wIcon_t * iconP);
-wIcon_p wIconCreateBitMap(wWinPix_t w, wWinPix_t h, const char *bits, wDrawColor color);
+wControl_p wBitmapCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, long options,
+ const struct wIcon_t * iconP);
+wIcon_p wIconCreateBitMap(wWinPix_t w, wWinPix_t h, const char *bits,
+ wDrawColor color);
wIcon_p wIconCreatePixMap(char *pm[]);
void wIconSetColor(wIcon_p ip, wDrawColor color);
@@ -103,12 +108,15 @@ typedef enum {
wBoxThickB,
wBoxThickW,
wBoxRidge,
- wBoxTrough }
- wBoxType_e;
+ wBoxTrough
+}
+wBoxType_e;
void wBoxSetSize(wBox_p b, wWinPix_t w, wWinPix_t h);
-void wlibDrawBox(wWin_p win, wBoxType_e style, wWinPix_t x, wWinPix_t y, wWinPix_t w, wWinPix_t h);
-wBox_p wBoxCreate(wWin_p parent, wWinPix_t bx, wWinPix_t by, const char *labelStr, wBoxType_e boxTyp, wWinPix_t bw, wWinPix_t bh);
+void wlibDrawBox(wWin_p win, wBoxType_e style, wWinPix_t x, wWinPix_t y,
+ wWinPix_t w, wWinPix_t h);
+wBox_p wBoxCreate(wWin_p parent, wWinPix_t bx, wWinPix_t by,
+ const char *labelStr, wBoxType_e boxTyp, wWinPix_t bw, wWinPix_t bh);
/*------------------------------------------------------------------------------
*
@@ -135,13 +143,19 @@ typedef void (*wChoiceCallBack_p)( long, void * );
void wButtonSetLabel(wButton_p bb, const char *labelStr);
void wButtonSetBusy(wButton_p bb, int value);
-wButton_p wButtonCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, const char *helpStr, const char *labelStr, long option, wWinPix_t width, wButtonCallBack_p action, void *data);
+wButton_p wButtonCreate(wWin_p parent, wWinPix_t x, wWinPix_t y,
+ const char *helpStr, const char *labelStr, long option, wWinPix_t width,
+ wButtonCallBack_p action, void *data);
void wRadioSetValue(wChoice_p bc, long value);
long wRadioGetValue(wChoice_p bc);
void wToggleSetValue(wChoice_p bc, long value);
long wToggleGetValue(wChoice_p b);
-wChoice_p wRadioCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, const char *helpStr, const char *labelStr, long option, const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data);
-wChoice_p wToggleCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, const char *helpStr, const char *labelStr, long option, const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data);
+wChoice_p wRadioCreate(wWin_p parent, wWinPix_t x, wWinPix_t y,
+ const char *helpStr, const char *labelStr, long option,
+ const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data);
+wChoice_p wToggleCreate(wWin_p parent, wWinPix_t x, wWinPix_t y,
+ const char *helpStr, const char *labelStr, long option,
+ const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data);
/*------------------------------------------------------------------------------
@@ -166,7 +180,8 @@ void wHelp( const char * );
#define NT_WARNING 2
#define NT_ERROR 4
-wBool_t wNoticeEx( int type, const char * msg, const char * yes, const char * no );
+wBool_t wNoticeEx( int type, const char * msg, const char * yes,
+ const char * no );
unsigned wOpenFileExternal(char *filename);
@@ -185,19 +200,20 @@ unsigned long wGetTimer( void );
void wExit( int );
typedef enum { wCursorNormal,
- wCursorNone,
- wCursorAppStart,
- wCursorHand,
- wCursorNo,
- wCursorSizeAll,
- wCursorSizeNESW,
- wCursorSizeNS,
- wCursorSizeNWSE,
- wCursorSizeWE,
- wCursorWait,
- wCursorIBeam,
- wCursorCross,
- wCursorQuestion } wCursor_t;
+ wCursorNone,
+ wCursorAppStart,
+ wCursorHand,
+ wCursorNo,
+ wCursorSizeAll,
+ wCursorSizeNESW,
+ wCursorSizeNS,
+ wCursorSizeNWSE,
+ wCursorSizeWE,
+ wCursorWait,
+ wCursorIBeam,
+ wCursorCross,
+ wCursorQuestion
+ } wCursor_t;
void wSetCursor( wDraw_p, wCursor_t );
#define defaultCursor wCursorCross
@@ -210,7 +226,8 @@ int wGetKeyState( void );
void wGetDisplaySize( wWinPix_t*, wWinPix_t* );
-wIcon_p wIconCreateBitMap( wWinPix_t, wWinPix_t, const char * bits, wDrawColor );
+wIcon_p wIconCreateBitMap( wWinPix_t, wWinPix_t, const char * bits,
+ wDrawColor );
wIcon_p wIconCreatePixMap( char *[] );
void wIconSetColor( wIcon_p, wDrawColor );
void wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y );
@@ -232,8 +249,9 @@ typedef enum {
wResize_e,
wState_e,
wQuit_e,
- wRedraw_e }
- winProcEvent;
+ wRedraw_e
+}
+winProcEvent;
typedef void (*wWinCallBack_p)( wWin_p, winProcEvent, void *, void * );
/* Creation Options */
@@ -252,10 +270,12 @@ typedef void (*wWinCallBack_p)( wWin_p, winProcEvent, void *, void * );
#define F_RESTRICT (1L<<15)
#define F_NOTTRANSIENT (1L<<16)
-wWin_p wWinMainCreate( const char *, wWinPix_t, wWinPix_t, const char *, const char *, const char *,
- long, wWinCallBack_p, void * );
-wWin_p wWinPopupCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, const char *,
- long, wWinCallBack_p, void * );
+wWin_p wWinMainCreate( const char *, wWinPix_t, wWinPix_t, const char *,
+ const char *, const char *,
+ long, wWinCallBack_p, void * );
+wWin_p wWinPopupCreate( wWin_p, wWinPix_t, wWinPix_t, const char *,
+ const char *, const char *,
+ long, wWinCallBack_p, void * );
wWin_p wMain( int, char *[] );
void wWinSetBigIcon( wWin_p, wIcon_p );
@@ -273,7 +293,9 @@ void wMessage( wWin_p, const char *, wBool_t );
void wWinTop( wWin_p );
void wWinDoCancel( wWin_p );
void wWinBlockEnable( wBool_t );
-void wSetGeometry(wWin_p, wWinPix_t min_width, wWinPix_t max_width, wWinPix_t min_height, wWinPix_t max_height, wWinPix_t base_width, wWinPix_t base_height, double aspect_ratio);
+void wSetGeometry(wWin_p, wWinPix_t min_width, wWinPix_t max_width,
+ wWinPix_t min_height, wWinPix_t max_height, wWinPix_t base_width,
+ wWinPix_t base_height, double aspect_ratio);
int wCreateSplash( char *appName, char *appVer );
int wSetSplashInfo( char *msg );
@@ -293,6 +315,7 @@ void wDestroySplash( void );
//#define BO_ENTER (1L<<10)
#define BO_ENTER 0
#define BO_REPEAT (1L<<11)
+#define BO_IGNFOCUS (1L<<12)
wWinPix_t wLabelWidth( const char * );
const char * wControlGetHelp( wControl_p );
@@ -322,9 +345,10 @@ void wControlLinkedActive( wControl_p b, int active );
#define BS_TRIM (1<<12)
/* Creation CallBacks */
typedef void (*wStringCallBack_p)( const char *, void *);
-wString_p wStringCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long,
- wWinPix_t, char *, wIndex_t, wStringCallBack_p,
- void * );
+wString_p wStringCreate( wWin_p, wWinPix_t, wWinPix_t, const char *,
+ const char *, long,
+ wWinPix_t, char *, wIndex_t, wStringCallBack_p,
+ void * );
void wStringSetValue( wString_p, const char * );
void wStringSetWidth( wString_p, wWinPix_t );
const char * wStringGetValue( wString_p );
@@ -336,14 +360,16 @@ const char * wStringGetValue( wString_p );
*/
/* Creation CallBacks */
-typedef void (*wIntegerCallBack_p)( long, void * , int);
-typedef void (*wFloatCallBack_p)( double, void * , int);
-wInteger_p wIntegerCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long,
- wWinPix_t, wInteger_t, wInteger_t, wInteger_t *,
- wIntegerCallBack_p, void * );
-wFloat_p wFloatCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long,
- wWinPix_t, double, double, double *,
- wFloatCallBack_p, void * );
+typedef void (*wIntegerCallBack_p)( long, void *, int);
+typedef void (*wFloatCallBack_p)( double, void *, int);
+wInteger_p wIntegerCreate( wWin_p, wWinPix_t, wWinPix_t, const char *,
+ const char *, long,
+ wWinPix_t, wInteger_t, wInteger_t, wInteger_t *,
+ wIntegerCallBack_p, void * );
+wFloat_p wFloatCreate( wWin_p, wWinPix_t, wWinPix_t, const char *,
+ const char *, long,
+ wWinPix_t, double, double, double *,
+ wFloatCallBack_p, void * );
void wIntegerSetValue( wInteger_p, wInteger_t );
void wFloatSetValue( wFloat_p, double );
wInteger_t wIntegerGetValue( wInteger_p );
@@ -356,7 +382,8 @@ double wFloatGetValue( wFloat_p );
*/
/* Creation CallBacks */
-typedef void (*wListCallBack_p)( wIndex_t, const char *, wIndex_t, void *, void * );
+typedef void (*wListCallBack_p)( wIndex_t, const char *, wIndex_t, void *,
+ void * );
/* Creation Options */
#define BL_DUP (1L<<16)
@@ -372,12 +399,17 @@ typedef void (*wListCallBack_p)( wIndex_t, const char *, wIndex_t, void *, void
/* lists, droplists and combo boxes */
-wList_p wListCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long,
- long, wWinPix_t, int, wWinPix_t *, wBool_t *, const char **, long *, wListCallBack_p, void * );
-wList_p wDropListCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long,
- long, wWinPix_t, long *, wListCallBack_p, void * );
-
-wList_p wComboListCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, const char *helpStr, const char *labelStr, long option, long number, wWinPix_t width, long *valueP, wListCallBack_p action, void *data);
+wList_p wListCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *,
+ long,
+ long, wWinPix_t, int, wWinPix_t *, wBool_t *, const char **, long *,
+ wListCallBack_p, void * );
+wList_p wDropListCreate( wWin_p, wWinPix_t, wWinPix_t, const char *,
+ const char *, long,
+ long, wWinPix_t, long *, wListCallBack_p, void * );
+
+wList_p wComboListCreate(wWin_p parent, wWinPix_t x, wWinPix_t y,
+ const char *helpStr, const char *labelStr, long option, long number,
+ wWinPix_t width, long *valueP, wListCallBack_p action, void *data);
void wListClear(wList_p b);
void wListSetIndex(wList_p b, int element);
wIndex_t wListFindValue(wList_p b, const char *val);
@@ -387,10 +419,12 @@ void *wListGetItemContext(wList_p b, wIndex_t inx);
wBool_t wListGetItemSelected(wList_p b, wIndex_t inx);
wIndex_t wListGetSelectedCount(wList_p b);
void wListSelectAll(wList_p bl);
-wBool_t wListSetValues(wList_p b, wIndex_t row, const char *labelStr, wIcon_p bm, void *itemData);
+wBool_t wListSetValues(wList_p b, wIndex_t row, const char *labelStr,
+ wIcon_p bm, void *itemData);
void wListDelete(wList_p b, wIndex_t inx);
int wListGetColumnWidths(wList_p bl, int colCnt, wWinPix_t *colWidths);
-wIndex_t wListAddValue(wList_p b, const char *labelStr, wIcon_p bm, void *itemData);
+wIndex_t wListAddValue(wList_p b, const char *labelStr, wIcon_p bm,
+ void *itemData);
void wListSetSize(wList_p bl, wWinPix_t w, wWinPix_t h);
wIndex_t wListGetValues( wList_p, char *, int, void * *, void * * );
@@ -413,7 +447,7 @@ void wListSetEditable( wList_p, wBool_t );
#define wMessageCreate( w, p1, p2, l, p3, m ) wMessageCreateEx( w, p1, p2, l, p3, m, 0 )
wMessage_p wMessageCreateEx( wWin_p, wWinPix_t, wWinPix_t, const char *,
- wWinPix_t, const char *, long );
+ wWinPix_t, const char *, long );
void wMessageSetValue( wMessage_p, const char * );
void wMessageSetWidth( wMessage_p, wWinPix_t );
@@ -430,7 +464,7 @@ typedef struct {
int width;
int x0, y0;
int x1, y1;
- } wLines_t, * wLines_p;
+} wLines_t, * wLines_p;
wLine_p wLineCreate( wWin_p, const char *, int, wLines_t *);
@@ -447,8 +481,9 @@ wLine_p wLineCreate( wWin_p, const char *, int, wLines_t *);
#define BT_DOBOLD (1L<<21)
#define BT_TOP (1L<<20) /* Show the top of the text */
-wText_p wTextCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long,
- wWinPix_t, wWinPix_t );
+wText_p wTextCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *,
+ long,
+ wWinPix_t, wWinPix_t );
void wTextClear( wText_p );
void wTextAppend( wText_p, const char * );
void wTextSetReadonly( wText_p, wBool_t );
@@ -459,7 +494,8 @@ void wTextReadFile( wText_p, const char * );
wBool_t wTextSave( wText_p, const char * );
wBool_t wTextPrint( wText_p );
void wTextSetSize( wText_p, wWinPix_t, wWinPix_t );
-void wTextComputeSize( wText_p, wWinPix_t, wWinPix_t, wWinPix_t *, wWinPix_t * );
+void wTextComputeSize( wText_p, wWinPix_t, wWinPix_t, wWinPix_t *,
+ wWinPix_t * );
void wTextSetPosition( wText_p bt, int pos );
@@ -491,14 +527,16 @@ typedef enum {
wDrawLineDashDot,
wDrawLineDashDotDot,
wDrawLineCenter,
- wDrawLinePhantom}
- wDrawLineType_e;
+ wDrawLinePhantom
+}
+wDrawLineType_e;
typedef enum {
wPolyLineStraight,
wPolyLineSmooth,
- wPolyLineRound}
- wPolyLine_e;
+ wPolyLineRound
+}
+wPolyLine_e;
typedef int wAction_t;
#define wActionMove (1)
@@ -518,7 +556,10 @@ typedef int wAction_t;
#define wActionScrollDown (15)
#define wActionScrollLeft (16)
#define wActionScrollRight (17)
-#define wActionLast wActionScrollRight
+#define wActionMDown (18)
+#define wActionMDrag (19)
+#define wActionMUp (20)
+#define wActionLast wActionMUp
#define wRGB(R,G,B)\
@@ -527,7 +568,8 @@ typedef int wAction_t;
/* Creation CallBacks */
typedef void (*wDrawRedrawCallBack_p)( wDraw_p, void *, wWinPix_t, wWinPix_t );
-typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wDrawPix_t, wDrawPix_t );
+typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wDrawPix_t,
+ wDrawPix_t );
/* Creation Options */
#define BD_TICKS (1L<<25)
@@ -538,31 +580,37 @@ typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wDrawPix_t, wD
/* Create: */
wDraw_p wDrawCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, long,
- wWinPix_t, wWinPix_t, void *,
- wDrawRedrawCallBack_p, wDrawActionCallBack_p );
+ wWinPix_t, wWinPix_t, void *,
+ wDrawRedrawCallBack_p, wDrawActionCallBack_p );
/* Draw: */
void wDrawLine( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawPix_t,
- wDrawWidth, wDrawLineType_e, wDrawColor,
- wDrawOpts );
+ wDrawWidth, wDrawLineType_e, wDrawColor,
+ wDrawOpts );
#define double2wAngle_t( A ) (A)
typedef double wAngle_t;
-void wDrawArc( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wAngle_t, wAngle_t,
- int, wDrawWidth, wDrawLineType_e, wDrawColor,
- wDrawOpts );
+void wDrawArc( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wAngle_t,
+ wAngle_t,
+ int, wDrawWidth, wDrawLineType_e, wDrawColor,
+ wDrawOpts );
void wDrawPoint( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawColor, wDrawOpts );
#define double2wFontSize_t( FS ) (FS)
typedef double wFontSize_t;
-void wDrawString( wDraw_p, wDrawPix_t, wDrawPix_t, wAngle_t, const char *, wFont_p,
- wFontSize_t, wDrawColor, wDrawOpts );
-void wDrawFilledRectangle( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawPix_t,
- wDrawColor, wDrawOpts );
-void wDrawPolygon( wDraw_p, wDrawPix_t [][2], wPolyLine_e [], wIndex_t, wDrawColor, wDrawWidth, wDrawLineType_e,
- wDrawOpts, int, int );
-void wDrawFilledCircle( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawColor, wDrawOpts );
-
-void wDrawGetTextSize( wDrawPix_t *, wDrawPix_t *, wDrawPix_t *, wDrawPix_t *, wDraw_p, const char *, wFont_p,
- wFontSize_t );
+void wDrawString( wDraw_p, wDrawPix_t, wDrawPix_t, wAngle_t, const char *,
+ wFont_p,
+ wFontSize_t, wDrawColor, wDrawOpts );
+void wDrawFilledRectangle( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t,
+ wDrawPix_t,
+ wDrawColor, wDrawOpts );
+void wDrawPolygon( wDraw_p, wDrawPix_t [][2], wPolyLine_e [], wIndex_t,
+ wDrawColor, wDrawWidth, wDrawLineType_e,
+ wDrawOpts, int, int );
+void wDrawFilledCircle( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t,
+ wDrawColor, wDrawOpts );
+
+void wDrawGetTextSize( wDrawPix_t *, wDrawPix_t *, wDrawPix_t *, wDrawPix_t *,
+ wDraw_p, const char *, wFont_p,
+ wFontSize_t );
void wDrawClear( wDraw_p );
void wDrawClearTemp( wDraw_p );
wBool_t wDrawSetTempMode( wDraw_p, wBool_t );
@@ -580,9 +628,10 @@ void wDrawSetSize( wDraw_p, wWinPix_t, wWinPix_t, void * );
void wDrawGetSize( wDraw_p, wWinPix_t *, wWinPix_t * );
/* Bitmaps */
-wDrawBitMap_p wDrawBitMapCreate( wDraw_p, int, int, int, int, const unsigned char * );
+wDrawBitMap_p wDrawBitMapCreate( wDraw_p, int, int, int, int,
+ const unsigned char * );
void wDrawBitMap( wDraw_p, wDrawBitMap_p, wDrawPix_t, wDrawPix_t,
- wDrawColor, wDrawOpts );
+ wDrawColor, wDrawOpts );
wDraw_p wBitMapCreate( wWinPix_t, wWinPix_t, int );
wBool_t wBitMapDelete( wDraw_p );
@@ -594,7 +643,8 @@ void wDrawSaveImage( wDraw_p );
void wDrawRestoreImage( wDraw_p );
int wDrawSetBackground( wDraw_p, char * path, char ** error);
void wDrawCloneBackground(wDraw_p from, wDraw_p to);
-void wDrawShowBackground( wDraw_p, wWinPix_t pos_x, wWinPix_t pos_y, wWinPix_t width, wAngle_t angle, int screen);
+void wDrawShowBackground( wDraw_p, wWinPix_t pos_x, wWinPix_t pos_y,
+ wWinPix_t width, wAngle_t angle, int screen);
/*------------------------------------------------------------------------------
*
@@ -665,17 +715,19 @@ typedef enum {
wAccelKey_F10,
wAccelKey_F11,
wAccelKey_F12,
- wAccelKey_Numpad_Add,
- wAccelKey_Numpad_Subtract,
- wAccelKey_LineFeed }
- wAccelKey_e;
+ wAccelKey_Numpad_Add,
+ wAccelKey_Numpad_Subtract,
+ wAccelKey_LineFeed
+}
+wAccelKey_e;
typedef enum {
wModKey_None,
wModKey_Alt,
wModKey_Shift,
- wModKey_Ctrl }
- wModKey_e;
+ wModKey_Ctrl
+}
+wModKey_e;
void wDoAccelHelp( wAccelKey_e key, void * );
@@ -689,13 +741,14 @@ typedef void (*wMenuTraceCallBack_p)( wMenu_p, const char *, void * );
/* Creation Options */
#define BM_ICON (1L<<0)
-wMenu_p wMenuCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, long );
+wMenu_p wMenuCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *,
+ long );
wMenu_p wMenuBarAdd( wWin_p, const char *, const char * );
wMenuPush_p wMenuPushCreate( wMenu_p, const char *, const char *, long,
- wMenuCallBack_p, void * );
+ wMenuCallBack_p, void * );
wMenuRadio_p wMenuRadioCreate( wMenu_p, const char *, const char *, long,
- wMenuCallBack_p, void * );
+ wMenuCallBack_p, void * );
wMenu_p wMenuMenuCreate( wMenu_p, const char *, const char * );
wMenu_p wMenuPopupCreate( wWin_p, const char * );
@@ -708,7 +761,8 @@ void wMenuListDelete( wMenuList_p, const char * );
const char * wMenuListGet( wMenuList_p, int, void ** );
void wMenuListClear( wMenuList_p );
-wMenuToggle_p wMenuToggleCreate( wMenu_p, const char *, const char *, long, wBool_t, wMenuCallBack_p, void * );
+wMenuToggle_p wMenuToggleCreate( wMenu_p, const char *, const char *, long,
+ wBool_t, wMenuCallBack_p, void * );
wBool_t wMenuToggleSet( wMenuToggle_p, wBool_t );
wBool_t wMenuToggleGet( wMenuToggle_p );
void wMenuToggleEnable( wMenuToggle_p, wBool_t );
@@ -734,11 +788,13 @@ struct wFilSel_t;
typedef enum {
FS_SAVE,
FS_LOAD,
- FS_UPDATE }
- wFilSelMode_e;
+ FS_UPDATE
+}
+wFilSelMode_e;
typedef int (*wFilSelCallBack_p)( int files, char ** fileName, void * );
-struct wFilSel_t * wFilSelCreate(wWin_p, wFilSelMode_e, int, const char *, const char *,
- wFilSelCallBack_p, void * );
+struct wFilSel_t * wFilSelCreate(wWin_p, wFilSelMode_e, int, const char *,
+ const char *,
+ wFilSelCallBack_p, void * );
int wFilSelect( struct wFilSel_t *, const char * );
@@ -750,8 +806,9 @@ int wFilSelect( struct wFilSel_t *, const char * );
typedef void (*wColorSelectButtonCallBack_p)( void *, wDrawColor );
wBool_t wColorSelect( const char *, wDrawColor * );
-wButton_p wColorSelectButtonCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *,
- long, wWinPix_t, wDrawColor *, wColorSelectButtonCallBack_p, void * );
+wButton_p wColorSelectButtonCreate( wWin_p, wWinPix_t, wWinPix_t, const char *,
+ const char *,
+ long, wWinPix_t, wDrawColor *, wColorSelectButtonCallBack_p, void * );
void wColorSelectButtonSetColor( wButton_p, wDrawColor );
wDrawColor wColorSelectButtonGetColor( wButton_p );
@@ -768,20 +825,30 @@ char * wPrefGetStringExt(const char *section, const char *name);
void wPrefsLoad(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);
+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 *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 );
+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( char * name);
-void wPrefReset( void );
+void wPrefReset( void );
+void wPrefTokenize(char* line, char** section, char** name, char** value);
+void wPrefFormatLine(const char* section, const char* name,
+ const char* value, char* result);
-void CleanupCustom( void );
+//void CleanupCustom( void );
/*------------------------------------------------------------------------------
*
@@ -789,12 +856,12 @@ void CleanupCustom( void );
*/
wStatus_p wStatusCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * labelStr,
- wWinPix_t width,
- const char *message );
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * labelStr,
+ wWinPix_t width,
+ const char *message );
wWinPix_t wStatusGetWidth(const char *testString);
wWinPix_t wStatusGetHeight(long flags);
@@ -802,6 +869,18 @@ wWinPix_t wStatusGetHeight(long flags);
void wStatusSetValue(wStatus_p b, const char * arg);
void wStatusSetWidth(wStatus_p b, wWinPix_t width);
+/*------------------------------------------------------------------------------
+ *
+ * System-Information
+ */
+
+char* wGetTempPath(void);
+char* wGetOSVersion(void);
+char* wGetProfileFilename(void);
+char* wGetUserID(void);
+const char* wGetUserHomeRootDir(void);
+const char *wGetPlatformVersion(void);
+
/*-------------------------------------------------------------------------------
* User Preferences
*/
diff --git a/app/wlib/mswlib/CMakeLists.txt b/app/wlib/mswlib/CMakeLists.txt
index 99ac1d4..1d8464a 100644
--- a/app/wlib/mswlib/CMakeLists.txt
+++ b/app/wlib/mswlib/CMakeLists.txt
@@ -1,51 +1,57 @@
-find_package(FreeImage REQUIRED)
-
-FILE(GLOB HEADERS *.h)
-
-SET(SOURCES
- backgnd.c
- getopt.c
- mswbox.c
- mswbutt.c
- mswbitmap.c
- mswchoic.c
- mswcolor.c
- mswdraw.c
- mswedit.c
- mswlines.c
- mswlist.c
- mswmenu.c
- mswmisc.c
- mswmsg.c
- mswpref.c
- mswprint.c
- mswsplash.c
- mswstatus.c
- mswtext.c
- gwin32.c
- simple-gettext.c
- utf8conv.c
+#
+# build the Win32 variant of the wlib
+#
+
+
+
+if(XTRKCAD_USE_GETTEXT)
+ if(WIN32)
+ add_definitions(-DUSE_SIMPLE_GETTEXT )
+ endif(WIN32)
+endif(XTRKCAD_USE_GETTEXT)
+
+target_sources(xtrkcad-wlib
+ PRIVATE
+ backgnd.c
+ getopt.c
+ mswbox.c
+ mswbutt.c
+ mswbitmap.c
+ mswchoic.c
+ mswcolor.c
+ mswdraw.c
+ mswedit.c
+ mswlines.c
+ mswlist.c
+ mswmenu.c
+ mswmisc.c
+ mswmsg.c
+ mswpref.c
+ mswprint.c
+ mswsplash.c
+ mswstatus.c
+ mswtext.c
+ gwin32.c
+ simple-gettext.c
+ sysinfo.c
+ utf8conv.c
+ mswint.h
+ dynarr.h
+ getline/getline.c
)
-include_directories(${FREEIMAGE_INCLUDE_PATH})
-INCLUDE_DIRECTORIES(${XTrkCAD_BINARY_DIR})
-# INCLUDE_DIRECTORIES(${help_BINARY_DIR})
-
-IF(XTRKCAD_USE_GETTEXT)
- IF(WIN32)
- ADD_DEFINITIONS(-DUSE_SIMPLE_GETTEXT )
- ENDIF(WIN32)
-ENDIF(XTRKCAD_USE_GETTEXT)
-
-ADD_LIBRARY(xtrkcad-wlib ${HEADERS} ${SOURCES})
-
-TARGET_LINK_LIBRARIES(xtrkcad-wlib Htmlhelp msimg32 shlwapi)
-target_link_libraries(xtrkcad-wlib ${FREEIMAGE_LIBRARY})
+target_link_libraries(xtrkcad-wlib
+ PRIVATE
+ Htmlhelp
+ msimg32
+ shlwapi
+ FreeImage::FreeImage
+)
install(FILES
${FREEIMAGE_SHAREDLIB}
DESTINATION ${XTRKCAD_BIN_INSTALL_DIR}
- )
+)
if(XTRKCAD_TESTING AND CMOCKA_FOUND)
add_subdirectory( unittest )
diff --git a/app/wlib/mswlib/backgnd.c b/app/wlib/mswlib/backgnd.c
index 9599beb..f10e0f0 100644
--- a/app/wlib/mswlib/backgnd.c
+++ b/app/wlib/mswlib/backgnd.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <windows.h>
diff --git a/app/wlib/mswlib/checksum.c b/app/wlib/mswlib/checksum.c
index f19d15b..52d8453 100644
--- a/app/wlib/mswlib/checksum.c
+++ b/app/wlib/mswlib/checksum.c
@@ -20,15 +20,19 @@ int main( int argc, char *argv[] )
set = 0;
fp = openfile( argv[1], "rb", &FileSize );
}
- if (fp == NULL)
+ if (fp == NULL) {
exit(1);
-
+ }
+
fprintf( stderr, "File Size = %ld (%lx)\n", FileSize, FileSize );
sum16computed = mswCheck16( fp, FileSize, &sum16stored );
- if (!mswCheck32( fp, FileSize, &sum32off, &sum32computed, &sum32stored ))
+ if (!mswCheck32( fp, FileSize, &sum32off, &sum32computed, &sum32stored )) {
fprintf( stderr, "mswCheck32 error\n" );
- fprintf( stderr, "sum16: stored = %x, computed = %x, sum = %x, expected FFFF\n", sum16stored, sum16computed, sum16stored+sum16computed );
- fprintf( stderr, "sum32: stored = %lx, computed = %lx, expected %lx\n", sum32stored, sum32computed, sum32stored );
+ }
+ fprintf( stderr, "sum16: stored = %x, computed = %x, sum = %x, expected FFFF\n",
+ sum16stored, sum16computed, sum16stored+sum16computed );
+ fprintf( stderr, "sum32: stored = %lx, computed = %lx, expected %lx\n",
+ sum32stored, sum32computed, sum32stored );
if (set) {
fseek( fp, 0x12, SEEK_SET );
sum16computed = 0xFFFF - sum16computed;
diff --git a/app/wlib/mswlib/dynarr.h b/app/wlib/mswlib/dynarr.h
index e8a178e..8c79933 100644
--- a/app/wlib/mswlib/dynarr.h
+++ b/app/wlib/mswlib/dynarr.h
@@ -1,8 +1,8 @@
typedef struct {
- int cnt;
- int max;
- void * ptr;
- } dynArr_t;
+ int cnt;
+ int max;
+ void * ptr;
+} dynArr_t;
#define DYNARR_APPEND(T,DA,INCR) \
{ if ((DA).cnt >= (DA).max) { \
diff --git a/app/wlib/mswlib/getline/LICENSE b/app/wlib/mswlib/getline/LICENSE
new file mode 100644
index 0000000..22df455
--- /dev/null
+++ b/app/wlib/mswlib/getline/LICENSE
@@ -0,0 +1,25 @@
+BSD 2-Clause License
+
+Copyright (c) 2022, Costantino Grana
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/app/wlib/mswlib/getline/README.md b/app/wlib/mswlib/getline/README.md
new file mode 100644
index 0000000..60f0dae
--- /dev/null
+++ b/app/wlib/mswlib/getline/README.md
@@ -0,0 +1,5 @@
+A POSIX getdelim() and getline() implementation for MSVC
+
+Tired of always having problems in reading arbitrary length lines from file under Windows, I tried to write a POSIX getdelim() and getline() implementation for MSVC. Let me know if you have any suggestion for improving this.
+
+This probably needs a test suite.
diff --git a/app/wlib/mswlib/getline/getline.c b/app/wlib/mswlib/getline/getline.c
new file mode 100644
index 0000000..202c7e2
--- /dev/null
+++ b/app/wlib/mswlib/getline/getline.c
@@ -0,0 +1,73 @@
+#include "getline.h"
+
+#include <stdlib.h>
+#include <errno.h>
+
+// MSVC specific implementation
+static void fseterr(FILE *fp)
+{
+ struct file { // Undocumented implementation detail
+ unsigned char *_ptr;
+ unsigned char *_base;
+ int _cnt;
+ int _flag;
+ int _file;
+ int _charbuf;
+ int _bufsiz;
+ };
+ #define _IOERR 0x10
+
+ ((struct file *)fp)->_flag |= _IOERR;
+}
+
+ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim, FILE *restrict stream)
+{
+ if (lineptr == NULL || n == NULL || stream == NULL || (*lineptr == NULL && *n != 0)) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (feof(stream) || ferror(stream)) {
+ return -1;
+ }
+
+ if (*lineptr == NULL) {
+ *n = 256;
+ *lineptr = malloc(*n);
+ if (*lineptr == NULL) {
+ fseterr(stream);
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+ ssize_t nread = 0;
+ int c = EOF;
+ while (c != delim) {
+ c = fgetc(stream);
+ if (c == EOF) {
+ break;
+ }
+ if (nread >= (ssize_t)(*n - 1)) {
+ size_t newn = *n * 2;
+ char *newptr = realloc(*lineptr, newn);
+ if (newptr == NULL) {
+ fseterr(stream);
+ errno = ENOMEM;
+ return -1;
+ }
+ *lineptr = newptr;
+ *n = newn;
+ }
+ (*lineptr)[nread++] = c;
+ }
+ if (c == EOF && nread == 0) {
+ return -1;
+ }
+ (*lineptr)[nread] = 0;
+ return nread;
+}
+
+ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict stream)
+{
+ return getdelim(lineptr, n, '\n', stream);
+}
+
diff --git a/app/wlib/mswlib/getopt.c b/app/wlib/mswlib/getopt.c
index 888f5f8..48ffca9 100644
--- a/app/wlib/mswlib/getopt.c
+++ b/app/wlib/mswlib/getopt.c
@@ -20,7 +20,7 @@
You should have received a copy of the GNU General Public License
along with ASPEX; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
----------------------------------------------------------------------*/
@@ -39,49 +39,50 @@ int optind = 1, opterr, optopt;
int getopt(int argc, char *argv[], const char *optstring)
{
- static int pos = 0;
- char *str;
-
- if (pos == 0) {
- if ((optind >= argc) || (*argv[optind] != OPTCHAR))
- return EOF;
- pos = 1;
- if (argv[optind][pos] == '\0')
- return EOF;
- }
-
- str = strchr(optstring, argv[optind][pos]);
- if (str == NULL) {
- optopt = argv[optind][pos];
- if (opterr)
- fprintf(stderr, "%s: illegal option -- %c\n", argv[0],
- optopt);
- return '?';
- }
-
- if (str[1] == ':') {
- if (argv[optind][pos+1] != '\0') {
- optarg = &argv[optind][pos+1];
- return *str;
+ static int pos = 0;
+ char *str;
+
+ if (pos == 0) {
+ if ((optind >= argc) || (*argv[optind] != OPTCHAR)) {
+ return EOF;
+ }
+ pos = 1;
+ if (argv[optind][pos] == '\0') {
+ return EOF;
+ }
}
- optind++;
- if (optind >= argc) {
- optopt = *str;
- if (opterr)
- fprintf(stderr, "%s: option requires an argument -- %c\n",
- argv[0], optopt);
- return '?';
+
+ str = strchr(optstring, argv[optind][pos]);
+ if (str == NULL) {
+ optopt = argv[optind][pos];
+ if (opterr)
+ fprintf(stderr, "%s: illegal option -- %c\n", argv[0],
+ optopt);
+ return '?';
}
- optarg = argv[optind];
- optind++; pos = 0;
- return *str;
- }
- else {
- pos++;
- if (argv[optind][pos] == '\0') {
- optind++;
- pos = 0;
+
+ if (str[1] == ':') {
+ if (argv[optind][pos+1] != '\0') {
+ optarg = &argv[optind][pos+1];
+ return *str;
+ }
+ optind++;
+ if (optind >= argc) {
+ optopt = *str;
+ if (opterr)
+ fprintf(stderr, "%s: option requires an argument -- %c\n",
+ argv[0], optopt);
+ return '?';
+ }
+ optarg = argv[optind];
+ optind++; pos = 0;
+ return *str;
+ } else {
+ pos++;
+ if (argv[optind][pos] == '\0') {
+ optind++;
+ pos = 0;
+ }
+ return *str;
}
- return *str;
- }
}
diff --git a/app/wlib/mswlib/gwin32.c b/app/wlib/mswlib/gwin32.c
index 877c329..c537439 100644
--- a/app/wlib/mswlib/gwin32.c
+++ b/app/wlib/mswlib/gwin32.c
@@ -13,16 +13,15 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
*
* Ported to standard C by Martin Fischer 2009
*
@@ -48,17 +47,17 @@
#endif
#if _MSC_VER > 1300
- #define stricmp _stricmp
- #define strnicmp _strnicmp
- #define strdup _strdup
+#define stricmp _stricmp
+#define strnicmp _strnicmp
+#define strdup _strdup
#endif
/**
- * This function gets the current thread locale from Windows - without any
+ * This function gets the current thread locale from Windows - without any
* encoding info - and returns it as a string of the above form for use in forming
* file names etc. The setlocale() function in the Microsoft C library uses locale
* names of the form "English_United States.1252" etc. We want the
- * UNIXish standard form "en_US", "zh_TW" etc. The returned string should be
+ * UNIXish standard form "en_US", "zh_TW" etc. The returned string should be
* deallocated with free().
*
* \return newly-allocated locale name.
@@ -67,80 +66,80 @@
char *
g_win32_getlocale (void)
{
- LCID lcid;
- LANGID langid;
- char *ev;
- char *loc;
- int primary, sub;
- char iso639[10];
- char iso3166[10];
- const char *script = NULL;
+ LCID lcid;
+ LANGID langid;
+ char *ev;
+ char *loc;
+ int primary, sub;
+ char iso639[10];
+ char iso3166[10];
+ const char *script = NULL;
- /* Let the user override the system settings through environment
- * variables, as on POSIX systems. Note that in GTK+ applications
- * since GTK+ 2.10.7 setting either LC_ALL or LANG also sets the
- * Win32 locale and C library locale through code in gtkmain.c.
- */
- if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0')
- || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0')
- || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0'))
- return strdup (ev);
+ /* Let the user override the system settings through environment
+ * variables, as on POSIX systems. Note that in GTK+ applications
+ * since GTK+ 2.10.7 setting either LC_ALL or LANG also sets the
+ * Win32 locale and C library locale through code in gtkmain.c.
+ */
+ if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0')
+ || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0')
+ || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0')) {
+ return strdup (ev);
+ }
- lcid = GetThreadLocale ();
+ lcid = GetThreadLocale ();
- if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) ||
- !GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166)))
- return strdup ("C");
-
- /* Strip off the sorting rules, keep only the language part. */
- langid = LANGIDFROMLCID (lcid);
+ if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) ||
+ !GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166))) {
+ return strdup ("C");
+ }
- /* Split into language and territory part. */
- primary = PRIMARYLANGID (langid);
- sub = SUBLANGID (langid);
+ /* Strip off the sorting rules, keep only the language part. */
+ langid = LANGIDFROMLCID (lcid);
- /* Handle special cases */
- switch (primary)
- {
- case LANG_AZERI:
- switch (sub)
- {
- case SUBLANG_AZERI_LATIN:
- script = "@Latn";
- break;
- case SUBLANG_AZERI_CYRILLIC:
- script = "@Cyrl";
- break;
- }
- break;
- case LANG_SERBIAN: /* LANG_CROATIAN == LANG_SERBIAN */
- switch (sub)
- {
- case SUBLANG_SERBIAN_LATIN:
- case 0x06: /* Serbian (Latin) - Bosnia and Herzegovina */
- script = "@Latn";
- break;
+ /* Split into language and territory part. */
+ primary = PRIMARYLANGID (langid);
+ sub = SUBLANGID (langid);
+
+ /* Handle special cases */
+ switch (primary) {
+ case LANG_AZERI:
+ switch (sub) {
+ case SUBLANG_AZERI_LATIN:
+ script = "@Latn";
+ break;
+ case SUBLANG_AZERI_CYRILLIC:
+ script = "@Cyrl";
+ break;
+ }
+ break;
+ case LANG_SERBIAN: /* LANG_CROATIAN == LANG_SERBIAN */
+ switch (sub) {
+ case SUBLANG_SERBIAN_LATIN:
+ case 0x06: /* Serbian (Latin) - Bosnia and Herzegovina */
+ script = "@Latn";
+ break;
+ }
+ break;
+ case LANG_UZBEK:
+ switch (sub) {
+ case SUBLANG_UZBEK_LATIN:
+ script = "@Latn";
+ break;
+ case SUBLANG_UZBEK_CYRILLIC:
+ script = "@Cyrl";
+ break;
+ }
+ break;
}
- break;
- case LANG_UZBEK:
- switch (sub)
- {
- case SUBLANG_UZBEK_LATIN:
- script = "@Latn";
- break;
- case SUBLANG_UZBEK_CYRILLIC:
- script = "@Cyrl";
- break;
+
+ loc = malloc( strlen( iso639 ) + strlen( iso3166 ) + (script ? strlen(
+ script ) : 0) + 2 );
+ strcpy( loc, iso639 );
+ strcat( loc, "_" );
+ strcat( loc, iso3166 );
+ if( script ) {
+ strcat( loc, script );
}
- break;
- }
-
- loc = malloc( strlen( iso639 ) + strlen( iso3166 ) + (script ? strlen( script ) : 0) + 2 );
- strcpy( loc, iso639 );
- strcat( loc, "_" );
- strcat( loc, iso3166 );
- if( script )
- strcat( loc, script );
- return loc;
+ return loc;
}
diff --git a/app/wlib/mswlib/mswbitmap.c b/app/wlib/mswlib/mswbitmap.c
index d4ee83c..9069c35 100644
--- a/app/wlib/mswlib/mswbitmap.c
+++ b/app/wlib/mswlib/mswbitmap.c
@@ -18,12 +18,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include <commdlg.h>
@@ -33,24 +32,24 @@
#include "i18n.h"
#if _MSC_VER > 1300
- #define stricmp _stricmp
- #define strnicmp _strnicmp
- #define strdup _strdup
+#define stricmp _stricmp
+#define strnicmp _strnicmp
+#define strdup _strdup
#endif
struct wBitmap_t {
- WOBJ_COMMON
- };
+ WOBJ_COMMON
+};
HPALETTE hOldPal;
HBITMAP mswCreateBitMap(
- COLORREF fgCol1,
- COLORREF fgCol2,
- COLORREF bgCol,
- int w,
- int h,
- const char * bits )
+ COLORREF fgCol1,
+ COLORREF fgCol2,
+ COLORREF bgCol,
+ int w,
+ int h,
+ const char * bits )
{
HDC hDc;
HDC hButtDc;
@@ -69,7 +68,7 @@ HBITMAP mswCreateBitMap(
if (mswPalette) {
hOldPal = SelectPalette( hButtDc, mswPalette, 0 );
}
-
+
/*PatBlt( hButtDc, 0, 0, w, h, WHITENESS );*/
newBrush = CreateSolidBrush( bgCol );
oldBrush = SelectObject( hButtDc, newBrush );
@@ -84,8 +83,9 @@ HBITMAP mswCreateBitMap(
for ( j = 0; j < h; j++ ) {
byt = (0xFF & *byts_p++) | 0x100;
for ( i = 0; i < w; i++ ) {
- if (byt == 1)
+ if (byt == 1) {
byt = (0xFF & *byts_p++) | 0x100;
+ }
if ( byt & 0x1 ) {
SetPixel( hButtDc, i, j, fgCol1 );
SetPixel( hButtDc, i+1, j+1, fgCol2 );
@@ -104,7 +104,7 @@ static dynArr_t bitmap_da;
#define bitmap(N) DYNARR_N(HBITMAP,bitmap_da,N)
void mswRegisterBitMap(
- HBITMAP hBm )
+ HBITMAP hBm )
{
DYNARR_APPEND( HBITMAP, bitmap_da, 10 );
bitmap(bitmap_da.cnt-1) = hBm;
@@ -113,14 +113,15 @@ void mswRegisterBitMap(
void deleteBitmaps( void )
{
int inx;
- for ( inx=0; inx<bitmap_da.cnt; inx++ )
+ for ( inx=0; inx<bitmap_da.cnt; inx++ ) {
DeleteObject( bitmap(inx) );
+ }
}
/**
* Draw a bitmap to the screen.
*
- * \param hDc IN device context
+ * \param hDc IN device context
* \param offw IN horizontal offset
* \param offh IN vertical offset
* \param bm IN icon to draw
@@ -131,46 +132,48 @@ void deleteBitmaps( void )
*/
void mswDrawIcon(
- HDC hDc,
- int offw,
- int offh,
- wIcon_p bm,
- int disabled,
- COLORREF color1,
- COLORREF color2 )
+ HDC hDc,
+ int offw,
+ int offh,
+ wIcon_p bm,
+ int disabled,
+ COLORREF color1,
+ COLORREF color2 )
{
int i;
int byt;
BITMAPINFO *bmiInfo;
COLORREF col;
- /* draw the bitmap by dynamically creating a Windows DIB in memory */
+ /* draw the bitmap by dynamically creating a Windows DIB in memory */
/* BITMAPINFO already has one RGBQUAD color struct, so only allocate the rest */
- bmiInfo = malloc( sizeof( BITMAPINFO ) + (bm->colorcnt - 1) * sizeof( RGBQUAD ));
- if( !bmiInfo ) {
- fprintf( stderr, "could not allocate memory for bmiInfo\n" );
- abort();
- }
-
- /* initialize bitmap header from XPM information */
- bmiInfo->bmiHeader.biSize = sizeof( bmiInfo->bmiHeader );
- bmiInfo->bmiHeader.biWidth = bm->w;
- bmiInfo->bmiHeader.biHeight = bm->h;
- bmiInfo->bmiHeader.biPlanes = 1;
- if( bm->type == mswIcon_bitmap )
- bmiInfo->bmiHeader.biBitCount = 1;
- else
- bmiInfo->bmiHeader.biBitCount = 8; /* up to 256 colors */
- bmiInfo->bmiHeader.biCompression = BI_RGB; /* no compression */
- bmiInfo->bmiHeader.biSizeImage = 0;
- bmiInfo->bmiHeader.biXPelsPerMeter = 0;
- bmiInfo->bmiHeader.biYPelsPerMeter = 0;
- bmiInfo->bmiHeader.biClrUsed = bm->colorcnt; /* number of colors used */
- bmiInfo->bmiHeader.biClrImportant = bm->colorcnt;
+ bmiInfo = malloc( sizeof( BITMAPINFO ) + (bm->colorcnt - 1) * sizeof(
+ RGBQUAD ));
+ if( !bmiInfo ) {
+ fprintf( stderr, "could not allocate memory for bmiInfo\n" );
+ abort();
+ }
+
+ /* initialize bitmap header from XPM information */
+ bmiInfo->bmiHeader.biSize = sizeof( bmiInfo->bmiHeader );
+ bmiInfo->bmiHeader.biWidth = bm->w;
+ bmiInfo->bmiHeader.biHeight = bm->h;
+ bmiInfo->bmiHeader.biPlanes = 1;
+ if( bm->type == mswIcon_bitmap ) {
+ bmiInfo->bmiHeader.biBitCount = 1;
+ } else {
+ bmiInfo->bmiHeader.biBitCount = 8; /* up to 256 colors */
+ }
+ bmiInfo->bmiHeader.biCompression = BI_RGB; /* no compression */
+ bmiInfo->bmiHeader.biSizeImage = 0;
+ bmiInfo->bmiHeader.biXPelsPerMeter = 0;
+ bmiInfo->bmiHeader.biYPelsPerMeter = 0;
+ bmiInfo->bmiHeader.biClrUsed = bm->colorcnt; /* number of colors used */
+ bmiInfo->bmiHeader.biClrImportant = bm->colorcnt;
/*
* create a transparency mask and paint to screen
- */
+ */
if( bm->type == mswIcon_bitmap ) {
memset( &bmiInfo->bmiColors[ 0 ], 0xFF, sizeof( RGBQUAD ));
memset( &bmiInfo->bmiColors[ 1 ], 0, sizeof( RGBQUAD ));
@@ -180,69 +183,71 @@ void mswDrawIcon(
}
StretchDIBits(hDc, offw, offh,
- (int)ceil(bmiInfo->bmiHeader.biWidth*scaleIcon),
- (int)ceil(bmiInfo->bmiHeader.biHeight*scaleIcon),
+ bmiInfo->bmiHeader.biWidth,
+ bmiInfo->bmiHeader.biHeight,
0, 0,
bmiInfo->bmiHeader.biWidth,
bmiInfo->bmiHeader.biHeight,
bm->pixels, bmiInfo,
DIB_RGB_COLORS, SRCAND);
-
+
/* now paint the bitmap with transparent set to black */
if( bm->type == mswIcon_bitmap ) {
- if( disabled ) {
+ if( disabled ) {
col = color2;
} else {
col = color1;
}
memset( &bmiInfo->bmiColors[ 0 ], 0, sizeof( RGBQUAD ));
- bmiInfo->bmiColors[ 1 ].rgbRed = GetRValue( col );
- bmiInfo->bmiColors[ 1 ].rgbGreen = GetGValue( col );
- bmiInfo->bmiColors[ 1 ].rgbBlue = GetBValue( col );
- } else {
+ bmiInfo->bmiColors[ 1 ].rgbRed = GetRValue( col );
+ bmiInfo->bmiColors[ 1 ].rgbGreen = GetGValue( col );
+ bmiInfo->bmiColors[ 1 ].rgbBlue = GetBValue( col );
+ } else {
if( disabled ) {
/* create a gray scale palette */
for( i = 0; i < bm->colorcnt; i ++ ) {
if (i != bm->transparent) {
byt = (30 * bm->colormap[i].rgbRed +
- 59 * bm->colormap[i].rgbGreen +
- 11 * bm->colormap[i].rgbBlue) / 100;
+ 59 * bm->colormap[i].rgbGreen +
+ 11 * bm->colormap[i].rgbBlue) / 100;
/* if totally black, use a dark gray */
- if (byt == 0)
+ if (byt == 0) {
byt = 0x66;
+ }
bmiInfo->bmiColors[i].rgbRed = byt;
bmiInfo->bmiColors[i].rgbGreen = byt;
bmiInfo->bmiColors[i].rgbBlue = byt;
}
}
- } else {
- /* copy the palette */
- memcpy( (void *)bmiInfo->bmiColors, (void *)bm->colormap, bm->colorcnt * sizeof( RGBQUAD ));
- }
+ } else {
+ /* copy the palette */
+ memcpy( (void *)bmiInfo->bmiColors, (void *)bm->colormap,
+ bm->colorcnt * sizeof( RGBQUAD ));
+ }
memset( &bmiInfo->bmiColors[ bm->transparent ], 0, sizeof( RGBQUAD ));
- }
-
- /* show the bitmap */
- StretchDIBits(hDc, offw, offh,
- (int)ceil(bmiInfo->bmiHeader.biWidth*scaleIcon),
- (int)ceil(bmiInfo->bmiHeader.biHeight*scaleIcon),
- 0, 0,
- bmiInfo->bmiHeader.biWidth,
- bmiInfo->bmiHeader.biHeight,
- bm->pixels, bmiInfo,
- DIB_RGB_COLORS, SRCPAINT);
-
- /* forget the data */
- free( bmiInfo );
+ }
+
+ /* show the bitmap */
+ StretchDIBits(hDc, offw, offh,
+ bmiInfo->bmiHeader.biWidth,
+ bmiInfo->bmiHeader.biHeight,
+ 0, 0,
+ bmiInfo->bmiHeader.biWidth,
+ bmiInfo->bmiHeader.biHeight,
+ bm->pixels, bmiInfo,
+ DIB_RGB_COLORS, SRCPAINT);
+
+ /* forget the data */
+ free( bmiInfo );
}
/**
- * Create a two color bitmap. This creates a two color icon. Pixels set to 1 are painted
+ * Create a two color bitmap. This creates a two color icon. Pixels set to 1 are painted
* in the specified color, pixels set to 0 are transparent
- * in order to convert the format, a lot of bit fiddling is necessary. The order of
- * scanlines needs to be reversed and the bit order (high order - low order) is reversed
+ * in order to convert the format, a lot of bit fiddling is necessary. The order of
+ * scanlines needs to be reversed and the bit order (high order - low order) is reversed
* as well.
* \param w IN width in pixels
* \param h IN height in pixels
@@ -251,12 +256,13 @@ void mswDrawIcon(
* \return pointer to icon
*/
-wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawColor color )
+wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits,
+ wDrawColor color )
{
int lineLength;
int i, j;
unsigned char *dest;
- static unsigned char revbits[] = { 0, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F };
+ static unsigned char revbits[] = { 0, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F };
unsigned long col = wDrawGetRGB( color );
wIcon_p ip;
@@ -278,13 +284,13 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol
ip->colormap[ 1 ].rgbBlue = col & 0xFF;
ip->colormap[ 1 ].rgbRed = (col>>16) & 0xFF;
ip->colormap[ 1 ].rgbGreen = (col>>8) & 0xFF;
- ip->colormap[ 1 ].rgbReserved = 0;
+ ip->colormap[ 1 ].rgbReserved = 0;
color = GetSysColor( COLOR_BTNFACE );
ip->colormap[ 0 ].rgbBlue = GetBValue( color );
ip->colormap[ 0 ].rgbRed = GetRValue( color );
ip->colormap[ 0 ].rgbGreen = GetGValue( color );
- ip->colormap[ 0 ].rgbReserved = 0;
+ ip->colormap[ 0 ].rgbReserved = 0;
lineLength = (((( ip->w + 7 ) / 8 ) + 3 ) >> 2 ) << 2;
ip->pixels = malloc( lineLength * ip->h );
@@ -293,19 +299,19 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol
abort();
}
- /*
+ /*
* copy the bits from source to the buffer, at this time the order of
* scanlines is reversed by starting with the last source line.
*/
for( i = 0; i < ip->h; i++ ) {
dest = ip->pixels + i * lineLength;
- memcpy( dest, bits + ( ip->h - i - 1 ) * (( ip->w + 7) / 8), ( ip->w + 7 ) / 8 );
+ memcpy( dest, bits + ( ip->h - i - 1 ) * (( ip->w + 7) / 8),
+ ( ip->w + 7 ) / 8 );
/*
* and now, the bit order is changed, this is done via a lookup table
*/
- for( j = 0; j < lineLength; j++ )
- {
+ for( j = 0; j < lineLength; j++ ) {
unsigned byte = dest[ j ];
unsigned low = byte & 0x0F;
unsigned high = (byte & 0xF0) >> 4;
@@ -323,7 +329,7 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol
* transparency, other symbolic names are not supported.
*
* \param pm IN XPM variable
- * \return pointer to icon, call free() if not needed anymore.
+ * \return pointer to icon, call free() if not needed anymore.
*/
wIcon_p wIconCreatePixMap( char *pm[])
@@ -355,9 +361,9 @@ wIcon_p wIconCreatePixMap( char *pm[])
height = (int)strtol(cq, &cq, 10 ); /* height of image */
col = (int)strtol(cq, &cq, 10 ); /* number of colors used */
numchars = (int)strtol(cq, &cq, 10 ); /* get number of chars per pixel */
-
+
ip->colormap = malloc( col * sizeof( RGBQUAD ));
- ip->w = width;
+ ip->w = width;
ip->h = height;
ip->colorcnt = col; /* number of colors used */
@@ -368,19 +374,19 @@ wIcon_p wIconCreatePixMap( char *pm[])
if( numchars == 1 ) {
keys[ col ] = (unsigned)ptr[0];
+ } else if( numchars == 2 ) {
+ keys[ col ] = (unsigned) ( ptr[ 0 ] + ptr[ 1 ] * 256 );
}
- else if( numchars == 2 ) {
- keys[ col ] = (unsigned) ( ptr[ 0 ] + ptr[ 1 ] * 256 );
- }
-
+
cp = strtok( ptr + numchars, "\t " ); /* cp points to color type */
assert( *cp == 'c' ); /* should always be color */
-
- cp = strtok( NULL, "\t " ); /* go to next token, the color definition itself */
+
+ cp = strtok( NULL,
+ "\t " ); /* go to next token, the color definition itself */
if( *cp == '#' ) { /* is this a hex RGB specification? */
len = strlen( cp+1 ) / 3;
- assert( len == 4 || len == 2 ); /* expecting three 2 char or 4 char values */
+ assert( len == 4 || len == 2 ); /* expecting three 2 char or 4 char values */
buff[2] = 0; /* if yes, extract the values */
memcpy( buff, cp + 1, 2 );
r = (int)strtol(buff, &cq, 16);
@@ -397,9 +403,9 @@ wIcon_p wIconCreatePixMap( char *pm[])
} else {
if( !stricmp( cp, "none" )) { /* special case transparency*/
ip->transparent = col;
+ } else {
+ assert( *cp == '#' ); /* if no, abort for the moment */
}
- else
- assert( *cp == '#' ); /* if no, abort for the moment */
}
free( ptr );
}
@@ -413,32 +419,34 @@ wIcon_p wIconCreatePixMap( char *pm[])
abort();
}
- /*
+ /*
convert the XPM pixel data to indexes into color table
- at the same time the order of rows is reversed
+ at the same time the order of rows is reversed
Win32 should be able to do that but I couldn't find out
- how, so this is coded by hand.
+ how, so this is coded by hand.
*/
/* for all rows */
for( i = 0; i < ip->h; i++ ) {
-
+
cq = ip->pixels + lineLength * i;
/* get the next row */
cp = pm[ ip->h - i + ip->colorcnt ];
/* for all pixels in row */
for( j = 0; j < ip->w; j++ ) {
/* get the pixel info */
- if( numchars == 1 )
+ if( numchars == 1 ) {
pixel = ( unsigned )*cp;
- else
+ } else {
pixel = (unsigned) (*cp + *(cp+1)*256);
+ }
cp += numchars;
/* look up pixel info in color table */
k = 0;
- while(k < col && pixel != keys[ k ] )
+ while(k < col && pixel != keys[ k ] ) {
k++;
+ }
if (pixel == keys[k]) {
/* save the index into color table */
*(cq + j) = k;
@@ -446,9 +454,9 @@ wIcon_p wIconCreatePixMap( char *pm[])
*(cq + j) = 0;
}
}
- }
+ }
free( keys );
-
+
return ip;
}
@@ -468,7 +476,7 @@ void wIconSetColor( wIcon_p ip, wDrawColor color )
*
* \param d IN drawing area
* \param bm IN bitmap to draw
- * \param x IN x position
+ * \param x IN x position
* \param y IN y position
*/
@@ -489,20 +497,22 @@ wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y )
*/
wControl_p
-wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option, const struct wIcon_t * iconP )
+wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option,
+ const struct wIcon_t * iconP )
{
wBitmap_p control;
int index;
DWORD style = SS_OWNERDRAW | WS_VISIBLE | WS_CHILD;
- control = mswAlloc( parent, B_BITMAP, NULL, sizeof( struct wBitmap_t ), NULL, &index );
+ control = mswAlloc( parent, B_BITMAP, NULL, sizeof( struct wBitmap_t ), NULL,
+ &index );
mswComputePos( (wControl_p)control, x, y );
control->option = option;
control->hWnd = CreateWindow( "STATIC", NULL,
- style, control->x, control->y,
- iconP->w, iconP->h,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ style, control->x, control->y,
+ iconP->w, iconP->h,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
if (control->hWnd == NULL) {
mswFail("CreateWindow(BITMAP)");
diff --git a/app/wlib/mswlib/mswbox.c b/app/wlib/mswlib/mswbox.c
index 4f90cf4..5698ae4 100644
--- a/app/wlib/mswlib/mswbox.c
+++ b/app/wlib/mswlib/mswbox.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -15,9 +14,9 @@
*/
struct wBox_t {
- WOBJ_COMMON
- wBoxType_e boxTyp;
- };
+ WOBJ_COMMON
+ wBoxType_e boxTyp;
+};
#define B (1)
#define W (2)
@@ -29,9 +28,9 @@ struct wBox_t {
void wBoxSetSize(
- wBox_p bb,
- wWinPix_t w,
- wWinPix_t h )
+ wBox_p bb,
+ wWinPix_t w,
+ wWinPix_t h )
{
bb->w = w;
bb->h = h;
@@ -39,7 +38,7 @@ void wBoxSetSize(
static void repaintBox( HWND hWnd, wControl_p b )
-{
+{
HDC hDc;
wBox_p bb = (wBox_p)(b);
wWinPix_t x0, y0, x1, y1;
@@ -53,7 +52,8 @@ static void repaintBox( HWND hWnd, wControl_p b )
{ /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} },
{ /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} },
{ /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} },
- { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} } };
+ { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} }
+ };
x0 = bb->x;
x1 = bb->x+bb->w;
@@ -89,18 +89,19 @@ static void repaintBox( HWND hWnd, wControl_p b )
static callBacks_t boxCallBacks = {
- repaintBox,
- NULL,
- NULL };
+ repaintBox,
+ NULL,
+ NULL
+};
wBox_p wBoxCreate(
- wWin_p parent,
- wWinPix_t origX,
- wWinPix_t origY,
- const char * labelStr,
- wBoxType_e typ,
- wWinPix_t width,
- wWinPix_t height )
+ wWin_p parent,
+ wWinPix_t origX,
+ wWinPix_t origY,
+ const char * labelStr,
+ wBoxType_e typ,
+ wWinPix_t width,
+ wWinPix_t height )
{
wBox_p b;
int index;
@@ -113,7 +114,7 @@ wBox_p wBoxCreate(
b->w = width;
b->h = height;
mswAddButton( (wControl_p)b, FALSE, NULL );
- mswCallBacks[B_BOX] = &boxCallBacks;
+ mswCallBacks[B_BOX] = &boxCallBacks;
repaintBox( ((wControl_p)parent)->hWnd, (wControl_p)b );
return b;
-}
+}
diff --git a/app/wlib/mswlib/mswbutt.c b/app/wlib/mswlib/mswbutt.c
index ac5bc87..be72257 100644
--- a/app/wlib/mswlib/mswbutt.c
+++ b/app/wlib/mswlib/mswbutt.c
@@ -17,12 +17,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -48,28 +47,29 @@
static XWNDPROC oldButtProc = NULL;
struct wButton_t {
- WOBJ_COMMON
- wButtonCallBack_p action;
- wBool_t busy;
- wBool_t selected;
- wIcon_p icon;
- UINT_PTR timer_id;
- int timer_count;
- int timer_state;
- };
+ WOBJ_COMMON
+ wButtonCallBack_p action;
+ wBool_t busy;
+ wBool_t selected;
+ wIcon_p icon;
+ UINT_PTR timer_id;
+ int timer_count;
+ int timer_state;
+};
void mswButtPush(
- wControl_p b )
+ wControl_p b )
{
- if ( ((wButton_p)b)->action )
+ if ( ((wButton_p)b)->action ) {
((wButton_p)b)->action( ((wButton_p)b)->data );
+ }
}
/**
* Paint function for toolbar buttons
- *
+ *
* \param hButtDc IN valid device context
* \param bm IN bitmap to add to button
* \param selected IN selected state of button
@@ -77,27 +77,25 @@ void mswButtPush(
*/
static void drawButton(
- HDC hButtDc,
- wIcon_p bm,
- BOOL_T selected,
- BOOL_T disabled )
+ HDC hButtDc,
+ wIcon_p bm,
+ BOOL_T selected,
+ BOOL_T disabled )
{
HGDIOBJ oldBrush, newBrush;
HPEN oldPen, newPen;
RECT rect;
COLORREF color1, color2;
wWinPix_t offw=5, offh=5;
- TRIVERTEX vert[2] ;
- GRADIENT_RECT gRect;
COLORREF colL;
COLORREF colD;
COLORREF colF;
#define LEFT (0)
-#define RIGHT (LONG)ceil(bm->w*scaleIcon+10)
+#define RIGHT (bm->w+9)
#define TOP (0)
-#define BOTTOM (LONG)ceil(bm->h*scaleIcon+10)
+#define BOTTOM (bm->h+9)
/* get the lightest and the darkest color to use */
colL = GetSysColor( COLOR_BTNHIGHLIGHT );
@@ -117,8 +115,7 @@ static void drawButton(
DeleteObject( SelectObject( hButtDc, oldBrush ) );
/* disabled button remain flat */
- if( !disabled )
- {
+ if( !disabled ) {
/* select colors for the gradient */
if( selected ) {
color1 = colD;
@@ -128,67 +125,27 @@ static void drawButton(
color2 = colD;
}
-#define GRADIENT_WIDTH 6
-
- /*
- first draw the top gradient
- this always ends in the button face color
- starting color depends on button state (selected or not)
- */
- vert [0] .x = LEFT;
- vert [0] .y = TOP;
- vert [0] .Red = GetRValue( color1 )* 256;
- vert [0] .Green = GetGValue( color1 )* 256;
- vert [0] .Blue = GetBValue( color1 )* 256;
- vert [0] .Alpha = 0x0000;
- vert [1] .x = RIGHT;
- vert [1] .y = TOP + GRADIENT_WIDTH;
- vert [1] .Red = GetRValue( colF )* 256;
- vert [1] .Green = GetGValue( colF )* 256;
- vert [1] .Blue = GetBValue( colF )* 256;
- vert [1] .Alpha = 0x0000;
-
- gRect.UpperLeft = 0;
- gRect.LowerRight = 1;
-
- GradientFill(hButtDc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
-
- /*
- now draw the bottom gradient
- this always starts with the button face color
- ending color depends on button state (selected or not)
- */
- vert [0] .x = LEFT;
- vert [0] .y = BOTTOM - GRADIENT_WIDTH;
- vert [0] .Red = GetRValue( colF )* 256;
- vert [0] .Green = GetGValue( colF )* 256;
- vert [0] .Blue = GetBValue( colF )* 256;
- vert [0] .Alpha = 0x0000;
- vert [1] .x = RIGHT;
- vert [1] .y = BOTTOM;
- vert [1] .Red = GetRValue( color2 )* 256;
- vert [1] .Green = GetGValue( color2 )* 256;
- vert [1] .Blue = GetBValue( color2 )* 256;
- vert [1] .Alpha = 0x0000;
- gRect.UpperLeft = 0;
- gRect.LowerRight = 1;
- GradientFill(hButtDc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
+ /* draw delimiting lines in shadow color */
+ newPen = CreatePen( PS_SOLID, 0, color1 );
+ oldPen = SelectObject( hButtDc, newPen );
+
+ MoveTo( hButtDc, RIGHT-1, TOP );
+ LineTo( hButtDc, LEFT, TOP );
+ LineTo( hButtDc, LEFT, BOTTOM );
+ DeleteObject( SelectObject( hButtDc, oldPen ) );
+
+ newPen = CreatePen( PS_SOLID, 0, color2 );
+ oldPen = SelectObject( hButtDc, newPen );
+ MoveTo( hButtDc, RIGHT, TOP+1 );
+ LineTo( hButtDc, RIGHT, BOTTOM );
+ LineTo( hButtDc, LEFT, BOTTOM );
+ DeleteObject( SelectObject( hButtDc, oldPen ) );
}
- /* draw delimiting lines in shadow color */
- newPen = CreatePen( PS_SOLID, 0, colD );
- oldPen = SelectObject( hButtDc, newPen );
-
- MoveTo( hButtDc, LEFT, TOP );
- LineTo( hButtDc, LEFT, BOTTOM );
- MoveTo( hButtDc, RIGHT, TOP );
- LineTo( hButtDc, RIGHT, BOTTOM );
-
- DeleteObject( SelectObject( hButtDc, oldPen ) );
-
color2 = GetSysColor( COLOR_BTNSHADOW );
- color1 = RGB( bm->colormap[ 1 ].rgbRed, bm->colormap[ 1 ].rgbGreen, bm->colormap[ 1 ].rgbBlue );
+ color1 = RGB( bm->colormap[ 1 ].rgbRed, bm->colormap[ 1 ].rgbGreen,
+ bm->colormap[ 1 ].rgbBlue );
if (selected) {
offw++; offh++;
@@ -198,45 +155,46 @@ static void drawButton(
static void buttDrawIcon(
- wButton_p b,
- HDC butt_hDc )
+ wButton_p b,
+ HDC butt_hDc )
{
- wIcon_p bm = b->icon;
- wWinPix_t offw=5, offh=5;
+ wIcon_p bm = b->icon;
+ wWinPix_t offw=5, offh=5;
- if (b->selected || b->busy) {
- offw++; offh++;
- } else if ( (b->option & BO_DISABLED) != 0 ) {
- ;
- } else {
- ;
- }
- drawButton( butt_hDc, bm, b->selected || b->busy, (b->option & BO_DISABLED) != 0 );
+ if (b->selected || b->busy) {
+ offw++; offh++;
+ } else if ( (b->option & BO_DISABLED) != 0 ) {
+ ;
+ } else {
+ ;
+ }
+ drawButton( butt_hDc, bm, b->selected
+ || b->busy, (b->option & BO_DISABLED) != 0 );
}
void wButtonSetBusy(
- wButton_p b,
- int value)
+ wButton_p b,
+ int value)
{
- b->busy = value;
- if (!value) {
- b->selected = FALSE;
- }
-
- // in case a timer is associated with the button, kill it
- if (b->timer_id) {
- KillTimer(b->hWnd, b->timer_id);
- b->timer_id = 0;
- b->timer_state = STOP_TIMER;
- }
-
- InvalidateRgn(b->hWnd, NULL, FALSE);
+ b->busy = value;
+ if (!value) {
+ b->selected = FALSE;
+ }
+
+ // in case a timer is associated with the button, kill it
+ if (b->timer_id) {
+ KillTimer(b->hWnd, b->timer_id);
+ b->timer_id = 0;
+ b->timer_state = STOP_TIMER;
+ }
+
+ InvalidateRgn(b->hWnd, NULL, FALSE);
}
void wButtonSetLabel(
- wButton_p b,
- const char * label )
+ wButton_p b,
+ const char * label )
{
if ((b->option&BO_ICON) == 0) {
/*b->labelStr = label;*/
@@ -248,11 +206,11 @@ void wButtonSetLabel(
}
/**
- * Button timer: handle timer events for buttons. These are used for
+ * Button timer: handle timer events for buttons. These are used for
* auto-repeating presses. Three phases used are
- * - initial delay before repetitions begin
- * - slow repeats for a few cycles
- * - fast repeats therafter
+ * - initial delay before repetitions begin
+ * - slow repeats for a few cycles
+ * - fast repeats therafter
* - stop timer
*
* \param hWnd Handle of the window, unused
@@ -264,45 +222,46 @@ void wButtonSetLabel(
void CALLBACK buttTimer(HWND hWnd, UINT message, UINT_PTR timer,
DWORD timepast)
{
- wButton_p b = (wButton_p)timer;
- if (b->timer_id == 0) {
- b->timer_state = STOP_TIMER;
- return ;
- }
-
- /* Autorepeat state machine */
- switch (b->timer_state) {
- case INITIAL_WAIT:
- b->timer_state = SLOW_REPEATS;
- b->timer_count = 0;
- KillTimer(hWnd, (UINT_PTR)b);
- SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE1_DELAY, buttTimer);
- break;
- case SLOW_REPEATS: /* Enable slow auto-repeat */
- if (b->timer_count++ > 10) {
- /* Start fast auto-repeat */
- b->timer_state = FAST_REPEATS;
- KillTimer(hWnd, (UINT_PTR)b);
- SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE2_DELAY, buttTimer);
- }
- break;
- case FAST_REPEATS:
- break;
- case STOP_TIMER:
- default:
- KillTimer(hWnd, (UINT_PTR)b);
- b->timer_id = 0;
- return;
- break;
- }
- if (b->action) {
- b->action(b->data);
- }
- return;
+ wButton_p b = (wButton_p)timer;
+ if (b->timer_id == 0) {
+ b->timer_state = STOP_TIMER;
+ return ;
+ }
+
+ /* Autorepeat state machine */
+ switch (b->timer_state) {
+ case INITIAL_WAIT:
+ b->timer_state = SLOW_REPEATS;
+ b->timer_count = 0;
+ KillTimer(hWnd, (UINT_PTR)b);
+ SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE1_DELAY, buttTimer);
+ break;
+ case SLOW_REPEATS: /* Enable slow auto-repeat */
+ if (b->timer_count++ > 10) {
+ /* Start fast auto-repeat */
+ b->timer_state = FAST_REPEATS;
+ KillTimer(hWnd, (UINT_PTR)b);
+ SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE2_DELAY, buttTimer);
+ }
+ break;
+ case FAST_REPEATS:
+ break;
+ case STOP_TIMER:
+ default:
+ KillTimer(hWnd, (UINT_PTR)b);
+ b->timer_id = 0;
+ return;
+ break;
+ }
+ if (b->action) {
+ b->action(b->data);
+ }
+ return;
}
-
-static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+
+static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam,
+ LPARAM lParam )
{
wButton_p bb = (wButton_p)b;
DRAWITEMSTRUCT * di = (DRAWITEMSTRUCT *)lParam;
@@ -319,13 +278,14 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L
case WM_MEASUREITEM: {
MEASUREITEMSTRUCT * mi = (MEASUREITEMSTRUCT *)lParam;
- if (bb->type != B_BUTTON || (bb->option & BO_ICON) == 0)
+ if (bb->type != B_BUTTON || (bb->option & BO_ICON) == 0) {
break;
+ }
mi->CtlType = ODT_BUTTON;
mi->CtlID = (UINT)wParam;
- mi->itemWidth = (UINT)ceil(bb->w*scaleIcon);
- mi->itemHeight = (UINT)ceil(bb->h*scaleIcon);
- } return (LRESULT)0;
+ mi->itemWidth = (UINT)bb->w;
+ mi->itemHeight = (UINT)bb->h;
+ } return (LRESULT)0;
case WM_DRAWITEM:
if (bb->type == B_BUTTON && (bb->option & BO_ICON) != 0) {
@@ -343,16 +303,16 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L
static void buttDone(
- wControl_p b )
+ wControl_p b )
{
free(b);
}
LRESULT CALLBACK pushButt(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
@@ -377,7 +337,7 @@ LRESULT CALLBACK pushButt(
case 0x09:
/*SetFocus( ((wControl_p)(b->parent))->hWnd );*/
SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR,
- wParam, lParam );
+ wParam, lParam );
/*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND,
inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/
return (LONG_PTR)0;
@@ -385,8 +345,9 @@ LRESULT CALLBACK pushButt(
}
break;
case WM_KILLFOCUS:
- if ( b )
+ if ( b ) {
InvalidateRect( b->hWnd, NULL, TRUE );
+ }
return (LRESULT)0;
break;
case WM_LBUTTONDOWN:
@@ -396,11 +357,12 @@ LRESULT CALLBACK pushButt(
b->timer_id = (UINT_PTR)b;
}
break;
- case WM_LBUTTONUP:
- /* don't know why but this solves a problem with color selection */
- Sleep( 0 );
- if (b->timer_id)
+ case WM_LBUTTONUP:
+ /* don't know why but this solves a problem with color selection */
+ Sleep( 0 );
+ if (b->timer_id) {
KillTimer(hWnd, (UINT_PTR)b);
+ }
b->timer_id = 0;
b->timer_state = STOP_TIMER;
break;
@@ -409,20 +371,21 @@ LRESULT CALLBACK pushButt(
}
static callBacks_t buttonCallBacks = {
- mswRepaintLabel,
- buttDone,
- buttPush };
+ mswRepaintLabel,
+ buttDone,
+ buttPush
+};
wButton_p wButtonCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- wButtonCallBack_p action,
- void * data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ wButtonCallBack_p action,
+ void * data )
{
wButton_p b;
RECT rect;
@@ -432,8 +395,9 @@ wButton_p wButtonCreate(
HDC hDc;
wIcon_p bm;
- if (width <= 0)
+ if (width <= 0) {
width = 80;
+ }
if ((option&BO_ICON) == 0) {
labelStr = mswStrdup( labelStr );
} else {
@@ -446,20 +410,21 @@ wButton_p wButtonCreate(
b->selected = 0;
mswComputePos( (wControl_p)b, x, y );
if (b->option&BO_ICON) {
- width = (wWinPix_t)ceil(bm->w*scaleIcon)+10;
- h = (int)ceil(bm->h*scaleIcon)+10;
+ width = (wWinPix_t)(bm->w+10);
+ h = bm->h+10;
b->icon = bm;
} else {
width = (wWinPix_t)(width*mswScale);
}
style = ((b->option&BO_ICON)? BS_OWNERDRAW : BS_PUSHBUTTON) |
- WS_CHILD | WS_VISIBLE |
- mswGetBaseStyle(parent);
- if ((b->option&BB_DEFAULT) != 0)
+ WS_CHILD | WS_VISIBLE |
+ mswGetBaseStyle(parent);
+ if ((b->option&BB_DEFAULT) != 0) {
style |= BS_DEFPUSHBUTTON;
+ }
b->hWnd = CreateWindow( "BUTTON", labelStr, style, b->x, b->y,
- /*CW_USEDEFAULT, CW_USEDEFAULT,*/ width, h,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ /*CW_USEDEFAULT, CW_USEDEFAULT,*/ width, h,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
if (b->hWnd == NULL) {
mswFail("CreateWindow(BUTTON)");
return b;
@@ -473,19 +438,16 @@ wButton_p wButtonCreate(
mswCallBacks[B_BUTTON] = &buttonCallBacks;
mswChainFocus( (wControl_p)b );
- oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)&pushButt);
-#ifdef _OLDCODE
- oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt);
-#endif
+ oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC,
+ (LONG_PTR)&pushButt);
if (mswPalette) {
hDc = GetDC( b->hWnd );
SelectPalette( hDc, mswPalette, 0 );
RealizePalette( hDc );
ReleaseDC( b->hWnd, hDc );
}
- if ( !mswThickFont )
- SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
+ SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
InvalidateRect(b->hWnd, &rect, TRUE);
diff --git a/app/wlib/mswlib/mswchoic.c b/app/wlib/mswlib/mswchoic.c
index 55ed177..ac58023 100644
--- a/app/wlib/mswlib/mswchoic.c
+++ b/app/wlib/mswlib/mswchoic.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -22,25 +21,25 @@ static XWNDPROC oldChoiceItemProc = NULL;
static XWNDPROC newChoiceItemProc;
typedef struct {
- WOBJ_COMMON
- wChoice_p owner;
- } wChoiceItem_t, * wChoiceItem_p;
+ WOBJ_COMMON
+ wChoice_p owner;
+} wChoiceItem_t, * wChoiceItem_p;
struct wChoice_t {
- WOBJ_COMMON
- const char * const * labels;
- wChoiceItem_p *buttList;
- long *valueP;
- long oldVal;
- wChoiceCallBack_p action;
- HWND hBorder;
- };
+ WOBJ_COMMON
+ const char * const * labels;
+ wChoiceItem_p *buttList;
+ long *valueP;
+ long oldVal;
+ wChoiceCallBack_p action;
+ HWND hBorder;
+};
static FARPROC oldChoiceProc;
void wRadioSetValue(
- wChoice_p bc,
- long val )
+ wChoice_p bc,
+ long val )
{
const char * const * labels;
long cnt;
@@ -49,14 +48,15 @@ void wRadioSetValue(
butts = (wChoiceItem_p*)bc->buttList;
for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ )
SendMessage( (*butts)->hWnd, BM_SETCHECK,
- (WPARAM)((val==cnt)?1:0), (LPARAM)0 );
+ (WPARAM)((val==cnt)?1:0), (LPARAM)0 );
bc->oldVal = val;
- if (bc->valueP)
+ if (bc->valueP) {
*bc->valueP = val;
+ }
}
long wRadioGetValue(
- wChoice_p bc )
+ wChoice_p bc )
{
return bc->oldVal;
}
@@ -64,8 +64,8 @@ long wRadioGetValue(
void wToggleSetValue(
- wChoice_p bc,
- long val )
+ wChoice_p bc,
+ long val )
{
const char * const * labels;
long cnt;
@@ -74,49 +74,53 @@ void wToggleSetValue(
butts = (wChoiceItem_p*)bc->buttList;
for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ )
SendMessage( (*butts)->hWnd, BM_SETCHECK,
- (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 );
+ (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 );
bc->oldVal = val;
- if (bc->valueP)
+ if (bc->valueP) {
*bc->valueP = val;
+ }
}
long wToggleGetValue(
- wChoice_p bc )
+ wChoice_p bc )
{
return bc->oldVal;
}
static void choiceSetBusy(
- wControl_p b,
- BOOL_T busy)
+ wControl_p b,
+ BOOL_T busy)
{
wChoiceItem_p * butts;
wChoice_p bc = (wChoice_p)b;
- for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ )
+ for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) {
EnableWindow( (*butts)->hWnd, !(BOOL)busy );
+ }
}
static void choiceShow(
- wControl_p b,
- BOOL_T show)
+ wControl_p b,
+ BOOL_T show)
{
wChoice_p bc = (wChoice_p)b;
wChoiceItem_p * butts;
- if ((bc->option & BC_NOBORDER)==0)
+ if ((bc->option & BC_NOBORDER)==0) {
ShowWindow( bc->hBorder, show?SW_SHOW:SW_HIDE );
+ }
- for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ )
+ for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) {
ShowWindow( (*butts)->hWnd, show?SW_SHOW:SW_HIDE );
+ }
}
static void choiceSetPos(
- wControl_p b,
- wWinPix_t x,
- wWinPix_t y )
+ wControl_p b,
+ wWinPix_t x,
+ wWinPix_t y )
{
wChoice_p bc = (wChoice_p)b;
wChoiceItem_p * butts;
@@ -126,25 +130,25 @@ static void choiceSetPos(
dy = y - bc->y;
if ((bc->option & BC_NOBORDER)==0)
SetWindowPos( bc->hBorder, HWND_TOP, x, y, CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER );
+ SWP_NOSIZE|SWP_NOZORDER );
for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) {
(*butts)->x += dx;
(*butts)->y += dy;
SetWindowPos( (*butts)->hWnd, HWND_TOP,
- (*butts)->x, (*butts)->y,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER );
+ (*butts)->x, (*butts)->y,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER );
}
bc->x = x;
bc->y = y;
}
LRESULT FAR PASCAL _export pushChoiceItem(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
@@ -157,9 +161,9 @@ LRESULT FAR PASCAL _export pushChoiceItem(
case 0x0D:
case 0x1B:
case 0x09:
- SetFocus( ((wControl_p)(b->parent))->hWnd );
+ SetFocus( ((wControl_p)(b->parent))->hWnd );
SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR,
- wParam, lParam );
+ wParam, lParam );
/*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND,
inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/
return (LRESULT)0;
@@ -171,18 +175,18 @@ LRESULT FAR PASCAL _export pushChoiceItem(
}
LRESULT choiceItemProc(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
-{
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
+{
wChoiceItem_p me = (wChoiceItem_p)b, *rest;
wChoice_p bc;
int num;
switch( message ) {
-
+
case WM_COMMAND:
switch (WCMD_PARAM_NOTF) {
case BN_CLICKED:
@@ -196,9 +200,9 @@ LRESULT choiceItemProc(
bc->oldVal ^= (1L<<num);
}
SendMessage( (*rest)->hWnd, BM_SETCHECK,
- (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 );
+ (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 );
break;
-
+
case B_RADIO:
if (*rest != me) {
SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)0, (LPARAM)0 );
@@ -209,35 +213,39 @@ LRESULT choiceItemProc(
break;
}
}
- if (bc->valueP)
+ if (bc->valueP) {
*bc->valueP = bc->oldVal;
- if (bc->action)
+ }
+ if (bc->action) {
bc->action( bc->oldVal, bc->data );
+ }
break;
}
break;
- }
-
+ }
+
return DefWindowProc( hWnd, message, wParam, lParam );
-}
+}
static callBacks_t choiceCallBacks = {
- mswRepaintLabel,
- NULL,
- NULL,
- choiceSetBusy,
- choiceShow,
- choiceSetPos };
+ mswRepaintLabel,
+ NULL,
+ NULL,
+ choiceSetBusy,
+ choiceShow,
+ choiceSetPos
+};
static callBacks_t choiceItemCallBacks = {
- NULL,
- NULL,
- choiceItemProc };
+ NULL,
+ NULL,
+ choiceItemProc
+};
/**
- * Creates choice buttons. This function is used to create a group of
+ * Creates choice buttons. This function is used to create a group of
* radio buttons and checkboxes.
*
* \param type IN type of button
@@ -254,17 +262,17 @@ static callBacks_t choiceItemCallBacks = {
*/
static wChoice_p choiceCreate(
- wType_e type,
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char * const * labels,
- long *valueP,
- wChoiceCallBack_p action,
- void *data )
+ wType_e type,
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ const char * const * labels,
+ long *valueP,
+ wChoiceCallBack_p action,
+ void *data )
{
wChoice_p b;
const char * const * lp;
@@ -289,17 +297,17 @@ static wChoice_p choiceCreate(
b->action = action;
b->labels = labels;
b->labelY += 6;
-
+
ppx = b->x;
ppy = b->y;
switch (b->type) {
case B_TOGGLE:
- bs = BS_CHECKBOX;
- break;
+ bs = BS_CHECKBOX;
+ break;
case B_RADIO:
- bs = BS_RADIOBUTTON;
- break;
+ bs = BS_RADIOBUTTON;
+ break;
}
for (lp = b->labels,cnt=0; *lp; lp++,cnt++ );
butts = (wChoiceItem_p*)malloc( (cnt+1) * sizeof *butts );
@@ -307,58 +315,60 @@ static wChoice_p choiceCreate(
b->oldVal = (b->valueP?*b->valueP:0);
ph = pw = 2;
maxW = 0;
- if (helpStr)
+ if (helpStr) {
helpStrCopy = mswStrdup( helpStr );
- for (lp = b->labels, cnt=0; *lp; lp++, cnt++, butts++ ) {
- *butts = (wChoiceItem_p)mswAlloc( parent, B_CHOICEITEM,
- mswStrdup(_((char *)*lp)), sizeof( wChoiceItem_t ), data, &index );
- (*butts)->owner = b;
- (*butts)->hWnd = hButt = CreateWindow( "BUTTON", (*butts)->labelStr,
- bs | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x+pw, b->y+ph,
- 80, CHOICE_HEIGHT,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
- if ( hButt == (HWND)0 ) {
- mswFail( "choiceCreate button" );
- return b;
- }
- (*butts)->x = b->x+pw;
- (*butts)->y = b->y+ph;
- if (b->hWnd == 0)
- b->hWnd = (*butts)->hWnd;
- (*butts)->helpStr = helpStrCopy;
-
- hDc = GetDC( hButt );
- lab_l = strlen((*butts)->labelStr);
-
- if (!mswThickFont) {hFont = SelectObject( hDc, mswLabelFont );}
- dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), (UINT)lab_l );
- if (!mswThickFont) {SelectObject( hDc, hFont );}
-
- w = LOWORD(dw) + CHOICE_MIN_WIDTH;
-
- if (w > maxW)
- maxW = w;
- SetBkMode( hDc, TRANSPARENT );
- ReleaseDC( hButt, hDc );
- if (b->option & BC_HORZ) {
- pw += w;
- } else {
- ph += CHOICE_HEIGHT;
- }
- if (!SetWindowPos( hButt, HWND_TOP, 0, 0,
- w, CHOICE_HEIGHT, SWP_NOMOVE|SWP_NOZORDER)) {
- mswFail("Create CHOICE: SetWindowPos");
- }
- mswChainFocus( (wControl_p)*butts );
- newChoiceItemProc = MakeProcInstance( (XWNDPROC)pushChoiceItem, mswHInst );
- oldChoiceItemProc = (XWNDPROC)GetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC);
- SetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC, (LPARAM)newChoiceItemProc);
+ }
+ for (lp = b->labels, cnt=0; *lp; lp++, cnt++, butts++ ) {
+ *butts = (wChoiceItem_p)mswAlloc( parent, B_CHOICEITEM,
+ mswStrdup(_((char *)*lp)), sizeof( wChoiceItem_t ), data, &index );
+ (*butts)->owner = b;
+ (*butts)->hWnd = hButt = CreateWindow( "BUTTON", (*butts)->labelStr,
+ bs | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x+pw, b->y+ph,
+ 80, CHOICE_HEIGHT,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ if ( hButt == (HWND)0 ) {
+ mswFail( "choiceCreate button" );
+ return b;
+ }
+ (*butts)->x = b->x+pw;
+ (*butts)->y = b->y+ph;
+ if (b->hWnd == 0) {
+ b->hWnd = (*butts)->hWnd;
+ }
+ (*butts)->helpStr = helpStrCopy;
+
+ hDc = GetDC( hButt );
+ lab_l = strlen((*butts)->labelStr);
+
+ hFont = SelectObject( hDc, mswLabelFont );
+ dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), (UINT)lab_l );
+ SelectObject( hDc, hFont );
+
+ w = LOWORD(dw) + CHOICE_MIN_WIDTH;
+
+ if (w > maxW) {
+ maxW = w;
+ }
+ SetBkMode( hDc, TRANSPARENT );
+ ReleaseDC( hButt, hDc );
+ if (b->option & BC_HORZ) {
+ pw += w;
+ } else {
+ ph += CHOICE_HEIGHT;
+ }
+ if (!SetWindowPos( hButt, HWND_TOP, 0, 0,
+ w, CHOICE_HEIGHT, SWP_NOMOVE|SWP_NOZORDER)) {
+ mswFail("Create CHOICE: SetWindowPos");
+ }
+ mswChainFocus( (wControl_p)*butts );
+ newChoiceItemProc = MakeProcInstance( (XWNDPROC)pushChoiceItem, mswHInst );
+ oldChoiceItemProc = (XWNDPROC)GetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC);
+ SetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC, (LPARAM)newChoiceItemProc);
#ifdef _OLDCODE
- oldChoiceItemProc = (XWNDPROC)GetWindowLong((*butts)->hWnd, GWL_WNDPROC);
- SetWindowLong((*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc);
+ oldChoiceItemProc = (XWNDPROC)GetWindowLong((*butts)->hWnd, GWL_WNDPROC);
+ SetWindowLong((*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc);
#endif
- if ( !mswThickFont )
- SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
+ SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
}
*butts = NULL;
switch (b->type) {
@@ -376,13 +386,13 @@ static wChoice_p choiceCreate(
}
pw += 4; ph += 4;
b->w = pw;
- b->h = ph;
+ b->h = ph;
#define FRAME_STYLE SS_ETCHEDFRAME
if ((b->option & BC_NOBORDER)==0) {
b->hBorder = CreateWindow( "STATIC", NULL, WS_CHILD | WS_VISIBLE | FRAME_STYLE,
- b->x, b->y, pw, ph, ((wControl_p)parent)->hWnd, 0, mswHInst, NULL );
+ b->x, b->y, pw, ph, ((wControl_p)parent)->hWnd, 0, mswHInst, NULL );
}
mswAddButton( (wControl_p)b, TRUE, helpStr );
mswCallBacks[ B_CHOICEITEM ] = &choiceItemCallBacks;
@@ -392,33 +402,33 @@ static wChoice_p choiceCreate(
wChoice_p wRadioCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char * const *labels,
- long *valueP,
- wChoiceCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ const char * const *labels,
+ long *valueP,
+ wChoiceCallBack_p action,
+ void *data )
{
return choiceCreate( B_RADIO, parent, x, y, helpStr, labelStr,
- option, labels, valueP, action, data );
+ option, labels, valueP, action, data );
}
wChoice_p wToggleCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- const char * const *labels,
- long *valueP,
- wChoiceCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ const char * const *labels,
+ long *valueP,
+ wChoiceCallBack_p action,
+ void *data )
{
return choiceCreate( B_TOGGLE, parent, x, y, helpStr, labelStr,
- option, labels, valueP, action, data );
+ option, labels, valueP, action, data );
}
diff --git a/app/wlib/mswlib/mswcolor.c b/app/wlib/mswlib/mswcolor.c
index fb9b0ba..f28e298 100644
--- a/app/wlib/mswlib/mswcolor.c
+++ b/app/wlib/mswlib/mswcolor.c
@@ -4,7 +4,6 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -34,16 +33,17 @@ static void mswGetCustomColors( void );
static struct {
- WORD palVersion;
- WORD palNumEntries;
- PALETTEENTRY palPalEntry[NUM_COLORS];
- } colorPalette = {
- 0x300,
- 2,
- {
+ WORD palVersion;
+ WORD palNumEntries;
+ PALETTEENTRY palPalEntry[NUM_COLORS];
+} colorPalette = {
+ 0x300,
+ 2,
+ {
{ 255, 255, 255 }, /* White */
{ 0, 0, 0 } /* Black */
- } };
+ }
+};
static long flipRGB( long rgb )
@@ -68,8 +68,10 @@ static void getpalette( void )
cnt = GetDeviceCaps(hdc, SIZEPALETTE);
GetSystemPaletteEntries( hdc, 0, cnt, pe );
f = fopen( "palette.txt", "w" );
- for (inx=0;inx<cnt;inx++)
- fprintf(f, "%d [ %d %d %d %d ]\n", inx, pe[inx].peRed, pe[inx].peGreen, pe[inx].peBlue, pe[inx].peFlags );
+ for (inx=0; inx<cnt; inx++) {
+ fprintf(f, "%d [ %d %d %d %d ]\n", inx, pe[inx].peRed, pe[inx].peGreen,
+ pe[inx].peBlue, pe[inx].peFlags );
+ }
fclose(f);
ReleaseDC( mswHWnd, hdc );
}
@@ -91,8 +93,9 @@ static int findColor( int r0, int g0, int b0 )
b1 = pal[c].peBlue;
g1 = pal[c].peGreen;
d1 = abs(r0-r1) + abs(g0-g1) + abs(b0-b1);
- if (d1 == 0)
+ if (d1 == 0) {
return c;
+ }
if (d1 < d0) {
d0 = d1;
cc = c;
@@ -104,7 +107,8 @@ static int findColor( int r0, int g0, int b0 )
pal[colorPalette.palNumEntries].peBlue = b0;
if ( mswPalette ) {
ResizePalette( mswPalette, colorPalette.palNumEntries+1 );
- SetPaletteEntries( mswPalette, colorPalette.palNumEntries, 1, &pal[colorPalette.palNumEntries] );
+ SetPaletteEntries( mswPalette, colorPalette.palNumEntries, 1,
+ &pal[colorPalette.palNumEntries] );
}
return colorPalette.palNumEntries++;
}
@@ -130,8 +134,9 @@ void mswInitColorPalette( void )
PALETTEENTRY palPalEntry[256];
} pe;
- if (initted)
+ if (initted) {
return;
+ }
initted = TRUE;
mswGetCustomColors();
@@ -158,7 +163,7 @@ HPALETTE mswCreatePalette( void )
int mswGetColorList( RGBQUAD * colors )
{
int i;
- for (i=0;i<(int)colorPalette.palNumEntries;i++) {
+ for (i=0; i<(int)colorPalette.palNumEntries; i++) {
colors[i].rgbBlue = colorPalette.palPalEntry[i].peBlue;
colors[i].rgbGreen = colorPalette.palPalEntry[i].peGreen;
colors[i].rgbRed = colorPalette.palPalEntry[i].peRed;
@@ -170,37 +175,41 @@ int mswGetColorList( RGBQUAD * colors )
COLORREF mswGetColor( wBool_t hasPalette, wDrawColor color )
{
- if ( hasPalette )
+ if ( hasPalette ) {
return PALETTEINDEX(color);
- else
- return RGB( colorPalette.palPalEntry[color].peRed, colorPalette.palPalEntry[color].peGreen, colorPalette.palPalEntry[color].peBlue );
+ } else {
+ return RGB( colorPalette.palPalEntry[color].peRed,
+ colorPalette.palPalEntry[color].peGreen,
+ colorPalette.palPalEntry[color].peBlue );
+ }
}
wDrawColor wDrawColorGray(
- int percent )
+ int percent )
{
int n;
n = (percent * NUM_GRAYS) / 100;
- if ( n <= 0 )
+ if ( n <= 0 ) {
return wDrawColorBlack;
- else if ( n > NUM_GRAYS )
+ } else if ( n > NUM_GRAYS ) {
return wDrawColorWhite;
- else {
+ } else {
n = (n*256)/NUM_GRAYS;
return wDrawFindColor( wRGB(n,n,n) );
}
}
wDrawColor wDrawFindColor(
- long rgb0 )
+ long rgb0 )
{
static long saved_rgb = wRGB(255,255,255);
static wDrawColor saved_color = 0;
int r0, g0, b0;
- if (rgb0 == saved_rgb)
+ if (rgb0 == saved_rgb) {
return saved_color;
+ }
r0 = (int)(rgb0>>16)&0xFF;
g0 = (int)(rgb0>>8)&0xFF;
b0 = (int)(rgb0)&0xFF;
@@ -210,7 +219,7 @@ wDrawColor wDrawFindColor(
long wDrawGetRGB(
- wDrawColor color )
+ wDrawColor color )
{
long rgb;
int r, g, b;
@@ -259,8 +268,8 @@ void mswPutCustomColors( void )
wBool_t wColorSelect(
- const char * title,
- wDrawColor * color )
+ const char * title,
+ wDrawColor * color )
{
long rgb;
@@ -285,18 +294,18 @@ wBool_t wColorSelect(
typedef struct {
- wDrawColor * valueP;
- wColorSelectButtonCallBack_p action;
- const char * labelStr;
- void * data;
- wDrawColor color;
- wButton_p button;
- wIcon_p bm;
- } colorData_t;
+ wDrawColor * valueP;
+ wColorSelectButtonCallBack_p action;
+ const char * labelStr;
+ void * data;
+ wDrawColor color;
+ wButton_p button;
+ wIcon_p bm;
+} colorData_t;
static void doColorButton(
- void * data )
+ void * data )
{
colorData_t * cd = (colorData_t*)data;
wDrawColor newColor;
@@ -305,30 +314,33 @@ static void doColorButton(
if (wColorSelect( cd->labelStr, &newColor )) {
cd->color = newColor;
wColorSelectButtonSetColor( cd->button, newColor );
- if (cd->valueP)
+ if (cd->valueP) {
*cd->valueP = newColor;
- if (cd->action)
+ }
+ if (cd->action) {
cd->action( cd->data, newColor );
+ }
}
}
wButton_p wColorSelectButtonCreate(
- wWin_p win,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- wDrawColor * color,
- wColorSelectButtonCallBack_p action,
- void * data )
+ wWin_p win,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ wDrawColor * color,
+ wColorSelectButtonCallBack_p action,
+ void * data )
{
wButton_p bb;
wIcon_p bm;
colorData_t * cd;
- bm = wIconCreateBitMap( square10_width, square10_height, square10_bits, (color?*color:0) );
+ bm = wIconCreateBitMap( square10_width, square10_height, square10_bits,
+ (color?*color:0) );
cd = malloc( sizeof *cd );
cd->valueP = color;
cd->action = action;
@@ -336,17 +348,19 @@ wButton_p wColorSelectButtonCreate(
cd->labelStr = labelStr;
cd->color = (color?*color:0);
cd->bm = bm;
- bb = wButtonCreate( win, x, y, helpStr, (char*)bm, option|BO_ICON, width, doColorButton, cd );
+ bb = wButtonCreate( win, x, y, helpStr, (char*)bm, option|BO_ICON, width,
+ doColorButton, cd );
cd->button = bb;
- if ( labelStr )
- wControlSetLabel( (wControl_p)bb, labelStr );
+ if ( labelStr ) {
+ wControlSetLabel( (wControl_p)bb, labelStr );
+ }
return bb;
}
void wColorSelectButtonSetColor(
- wButton_p bb,
- wDrawColor color )
+ wButton_p bb,
+ wDrawColor color )
{
((colorData_t*)((wControl_p)bb)->data)->color = color;
wIconSetColor( ((colorData_t*)((wControl_p)bb)->data)->bm, color );
@@ -355,7 +369,7 @@ void wColorSelectButtonSetColor(
wDrawColor wColorSelectButtonGetColor(
- wButton_p bb )
+ wButton_p bb )
{
return ((colorData_t*)((wControl_p)bb)->data)->color;
}
diff --git a/app/wlib/mswlib/mswdraw.c b/app/wlib/mswlib/mswdraw.c
index be5bcd6..7ab38ac 100644
--- a/app/wlib/mswlib/mswdraw.c
+++ b/app/wlib/mswlib/mswdraw.c
@@ -17,13 +17,12 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#define _WIN32_WINNT 0x0600 /* for wheel mouse supposrt */
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -113,20 +112,15 @@ static wWinPix_t YDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t y )
-/** @prefs [msw tweak] NoNegDrawArgs=1 Suppress drawing if x < 0 or y < 0 (-1 value causes preference read) */
-static long noNegDrawArgs = -1;
-/** @prefs [msw tweak] NoFlatEndCaps=1 Suppress EndCap Flat pen style */
-static long noFlatEndCaps = 0;
-
void wDrawDelayUpdate(
- wDraw_p d,
- wBool_t delay )
+ wDraw_p d,
+ wBool_t delay )
{
}
wBool_t wDrawSetTempMode(
- wDraw_p bd,
- wBool_t bTemp )
+ wDraw_p bd,
+ wBool_t bTemp )
{
wBool_t rc = bd->bTempMode;
bd->bTempMode = bTemp;
@@ -134,14 +128,14 @@ wBool_t wDrawSetTempMode(
// Main to Temp drawing
// Copy mainBM to tempBM
wDrawClearTemp( bd );
- if (bDrawMainBM) return rc;
+ if (bDrawMainBM) { return rc; }
HDC hDcOld = CreateCompatibleDC(bd->hDc);
HBITMAP hBmOld = SelectObject(hDcOld, bd->hBmMain);
SelectObject(bd->hDc, bd->hBmTemp);
BitBlt(bd->hDc, 0, 0,
- bd->w, bd->h,
- hDcOld, 0, 0,
- SRCCOPY);
+ bd->w, bd->h,
+ hDcOld, 0, 0,
+ SRCCOPY);
SelectObject(hDcOld, hBmOld);
DeleteDC(hDcOld);
bd->bCopiedMain = TRUE;
@@ -151,21 +145,20 @@ wBool_t wDrawSetTempMode(
/**
* Sets the proper pen and composition for the next drawing operation
- *
*
- * \param hDc IN device context
- * \param d IN ???
+ *
+ * \param d IN drawing context
* \param dw IN line width
* \param lt IN line type (dashed, solid, ...)
* \param dc IN color
- * \param dopt IN ????
+ * \param dopt IN drawing options
*/
static void setDrawMode(
- wDraw_p d,
- wDrawWidth dw,
- wDrawLineType_e lt,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawWidth dw,
+ wDrawLineType_e lt,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
long centerPen[] = {40,10,20,10};
long phantomPen[] = {40,10,20,10,20,10};
@@ -178,10 +171,11 @@ static void setDrawMode(
static LOGBRUSH logBrush = { 0, 0, 0 };
DWORD penStyle;
- if ( wDrawDoTempDraw && (dopt & wDrawOptTemp) )
+ if ( wDrawDoTempDraw && (dopt & wDrawOptTemp) ) {
SelectObject(d->hDc, d->hBmTemp);
- else
+ } else {
SelectObject(d->hDc, d->hBmMain);
+ }
if ( d->hasPalette ) {
int winPaletteClock = mswGetPaletteClock();
@@ -192,12 +186,14 @@ static void setDrawMode(
}
SetROP2( d->hDc, R2_COPYPEN );
- if ( d == d0 && dw0 == dw && lt == lt0 && dc == dc0 )
+ if ( d == d0 && dw0 == dw && lt == lt0 && dc == dc0 ) {
return;
+ }
// make sure that the line width is at least 1!
- if( !dw )
+ if( !dw ) {
dw++;
+ }
d0 = d; dw0 = dw; lt0 = lt; dc0 = dc;
@@ -206,16 +202,14 @@ static void setDrawMode(
logBrush.lbColor = mswGetColor(d->hasPalette,dc);
if ( lt==wDrawLineSolid ) {
- penStyle = PS_GEOMETRIC | PS_SOLID;
- if ( noFlatEndCaps == FALSE )
- penStyle |= PS_ENDCAP_FLAT;
+ penStyle = PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT;
} else if (lt == wDrawLineDot) {
penStyle = PS_GEOMETRIC | PS_DOT;
} else if (lt == wDrawLineDash) {
penStyle = PS_GEOMETRIC | PS_DASH;
} else if (lt == wDrawLineDashDot) {
penStyle = PS_GEOMETRIC | PS_DASHDOT;
- } else if ( lt == wDrawLineDashDotDot){
+ } else if ( lt == wDrawLineDashDotDot) {
penStyle = PS_GEOMETRIC | PS_DASHDOTDOT;
} else if ( lt == wDrawLineCenter) {
penStyle = PS_GEOMETRIC | PS_USERSTYLE;
@@ -225,47 +219,49 @@ static void setDrawMode(
penStyle = PS_GEOMETRIC | PS_USERSTYLE;
penarray = &phantomPen;
penarray_size = sizeof(phantomPen) / sizeof(long);
- } else
+ } else {
penStyle = PS_GEOMETRIC | PS_SOLID;
+ }
d->hPen = ExtCreatePen( penStyle,
- dw,
- &logBrush,
- penarray_size,
- penarray );
+ dw,
+ &logBrush,
+ penarray_size,
+ penarray );
hOldPen = SelectObject( d->hDc, d->hPen );
DeleteObject( hOldPen );
}
static void setDrawBrush(
- wDraw_p d,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
HBRUSH hOldBrush;
static wDraw_p d0;
static wDrawColor dc0 = -1;
setDrawMode( d, 0, wDrawLineSolid, dc, dopt );
- if ( d == d0 && dc == dc0 )
+ if ( d == d0 && dc == dc0 ) {
return;
+ }
d0 = d; dc0 = dc;
- d->hBrush = CreateSolidBrush(
- mswGetColor(d->hasPalette,dc) );
+ d->hBrush = CreateSolidBrush(
+ mswGetColor(d->hasPalette,dc) );
hOldBrush = SelectObject( d->hDc, d->hBrush );
DeleteObject( hOldBrush );
}
static void myInvalidateRect(
- wDraw_p d,
- RECT * prect )
+ wDraw_p d,
+ RECT * prect )
{
- if ( prect->top < 0 ) prect->top = 0;
- if ( prect->left < 0 ) prect->left = 0;
- if ( prect->bottom > d->h ) prect->bottom = d->h;
- if ( prect->right > d->w ) prect->right = d->w;
+ if ( prect->top < 0 ) { prect->top = 0; }
+ if ( prect->left < 0 ) { prect->left = 0; }
+ if ( prect->bottom > d->h ) { prect->bottom = d->h; }
+ if ( prect->right > d->w ) { prect->right = d->w; }
InvalidateRect( d->hWnd, prect, FALSE );
}
@@ -274,8 +270,8 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d )
{
long int x0=p0->x, y0=p0->y, x1=p1->x, y1=p1->y;
long int dx, dy;
- if ( x0<0 && x1<0 ) return 0;
- if ( y0<0 && y1<0 ) return 0;
+ if ( x0<0 && x1<0 ) { return 0; }
+ if ( y0<0 && y1<0 ) { return 0; }
dx=x1-x0;
dy=y1-y0;
if ( x0 < 0 ) {
@@ -283,7 +279,7 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d )
x0 = 0;
}
if ( y0 < 0 ) {
- if ( (x0 -= y0*dx/dy) < 0 ) return 0;
+ if ( (x0 -= y0*dx/dy) < 0 ) { return 0; }
y0 = 0;
}
if ( x1 < 0 ) {
@@ -291,7 +287,7 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d )
x1 = 0;
}
if ( y1 < 0 ) {
- if ( (x1 -= y1*dx/dy) < 0 ) return 0;
+ if ( (x1 -= y1*dx/dy) < 0 ) { return 0; }
y1 = 0;
}
p0->x = (int)x0;
@@ -303,15 +299,15 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d )
void wDrawLine(
- wDraw_p d,
- wDrawPix_t p0x,
- wDrawPix_t p0y,
- wDrawPix_t p1x,
- wDrawPix_t p1y,
- wDrawWidth dw,
- wDrawLineType_e lt,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawPix_t p0x,
+ wDrawPix_t p0y,
+ wDrawPix_t p1x,
+ wDrawPix_t p1y,
+ wDrawWidth dw,
+ wDrawLineType_e lt,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
POINT p0, p1;
RECT rect;
@@ -320,29 +316,29 @@ void wDrawLine(
p0.y = YDRAWPIX2WINPIX(d,p0y);
p1.x = XDRAWPIX2WINPIX(d,p1x);
p1.y = YDRAWPIX2WINPIX(d,p1y);
- if ( noNegDrawArgs>0 && !clip0( &p0, &p1, d ) )
- return;
+
MoveTo( d->hDc, p0.x, p0.y );
LineTo( d->hDc, p1.x, p1.y );
if (d->hWnd) {
- if (dw==0)
+ if (dw==0) {
dw = 1;
+ }
dw++;
- if (p0.y<p1.y) {
- rect.top = p0.y-dw;
- rect.bottom = p1.y+dw;
- } else {
- rect.top = p1.y-dw;
- rect.bottom = p0.y+dw;
- }
- if (p0.x<p1.x) {
- rect.left = p0.x-dw;
- rect.right = p1.x+dw;
- } else {
- rect.left = p1.x-dw;
- rect.right = p0.x+dw;
- }
- myInvalidateRect( d, &rect );
+ if (p0.y<p1.y) {
+ rect.top = p0.y-dw;
+ rect.bottom = p1.y+dw;
+ } else {
+ rect.top = p1.y-dw;
+ rect.bottom = p0.y+dw;
+ }
+ if (p0.x<p1.x) {
+ rect.left = p0.x-dw;
+ rect.right = p1.x+dw;
+ } else {
+ rect.left = p1.x-dw;
+ rect.right = p0.x+dw;
+ }
+ myInvalidateRect( d, &rect );
}
}
@@ -354,16 +350,16 @@ static double d2r(double angle)
static double mswsin( double angle )
{
- while (angle < 0.0) angle += 360.0;
- while (angle >= 360.0) angle -= 360.0;
+ while (angle < 0.0) { angle += 360.0; }
+ while (angle >= 360.0) { angle -= 360.0; }
angle *= (M_PI*2.0)/360.0;
return sin( angle );
}
static double mswcos( double angle )
{
- while (angle < 0.0) angle += 360.0;
- while (angle >= 360.0) angle -= 360.0;
+ while (angle < 0.0) { angle += 360.0; }
+ while (angle >= 360.0) { angle -= 360.0; }
angle *= (M_PI*2.0)/360.0;
return cos( angle );
}
@@ -376,6 +372,13 @@ static double mswasin( double x, double h )
return angle;
}
+static double mswNormalizeAngle( double a )
+{
+ while (a<0.0) { a += 360.0; }
+ while (a>=360.0) { a -= 360.0; }
+ return a;
+}
+
/**
* Draw an arc around a specified center
*
@@ -392,26 +395,30 @@ static double mswasin( double x, double h )
void wDrawArc(
- wDraw_p d,
- wDrawPix_t px,
- wDrawPix_t py,
- wDrawPix_t r,
- double a0,
- double a1,
- int sizeCenter,
- wDrawWidth dw,
- wDrawLineType_e lt,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawPix_t r,
+ double a0,
+ double a1,
+ int sizeCenter,
+ wDrawWidth dw,
+ wDrawLineType_e lt,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
int i, cnt;
POINT p0, p1, ps, pe, pp0, pp1, pp2, pc;
wDrawPix_t psx, psy, pex, pey;
- double len, aa, ai;
+ double aa, ai;
RECT rect;
int needMoveTo;
wBool_t fakeArc = FALSE;
+ // calculate the center coordinates
+ pc.x = XDRAWPIX2WINPIX( d, px );
+ pc.y = YDRAWPIX2WINPIX( d, py );
+
p0.x = XDRAWPIX2WINPIX(d,px-r);
p0.y = YDRAWPIX2WINPIX(d,py+r);
p1.x = XDRAWPIX2WINPIX(d,px+r);
@@ -431,30 +438,30 @@ void wDrawArc(
setDrawMode( d, dw, lt, dc, dopt );
- if (dw == 0)
+ if (dw == 0) {
dw = 1;
+ }
- /* Windows drawing will overshoot the end of the arc for large radius */
- if (r > 500) {
+ if ( r > 30000 || a1 < 1.0 ) {
/* The book says 32K but experience says otherwise */
fakeArc = TRUE;
}
- if ( noNegDrawArgs > 0 ) {
- if ( p0.x < 0 || p0.y < 0 || p1.x < 0 || p1.y < 0 )
- fakeArc = TRUE;
- }
+
+ // Starting point
+ psx = px + r * mswsin(a0);
+ psy = py + r * mswcos(a0);
+ pp0.x = XDRAWPIX2WINPIX( d, psx );
+ pp0.y = YDRAWPIX2WINPIX( d, psy );
+
if ( fakeArc ) {
cnt = (int)(a1 / 2);
- if ( cnt <= 0 ) cnt = 1;
- if ( cnt > 180 ) cnt = 180;
- // Convert a0 and a1 to radians here
+ if ( cnt <= 0 ) { cnt = 1; }
+ if ( cnt > 180 ) { cnt = 180; }
+
ai = d2r(a1) / cnt;
aa = d2r(a0);
- psx = px + r * sin(aa);
- psy = py + r * cos(aa);
- pp0.x = XDRAWPIX2WINPIX( d, psx );
- pp0.y = YDRAWPIX2WINPIX( d, psy );
needMoveTo = TRUE;
+
for ( i=0; i<cnt; i++ ) {
aa += ai;
psx = px + r * sin(aa);
@@ -473,53 +480,68 @@ void wDrawArc(
pp0.x = pp2.x; pp0.y = pp2.y;
}
} else {
- if ( a0 == 0.0 && a1 == 360.0 ) {
- Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p0.y, pe.x, p1.y );
- Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y, pe.x, p0.y );
+ DWORD rr = XDRAWPIX2WINPIX( d, r );
+ SetArcDirection( d->hDc,AD_CLOCKWISE );
+
+ // Draw two arcs from the center to eliminate the odd pie-shaped end artifact
+ if ( dw > 2.0 ) {
+ double a2 = a1 / 2.0;
+ pp2.x = XDRAWPIX2WINPIX( d, px + r * mswsin(a0+a2) );
+ pp2.y = YDRAWPIX2WINPIX( d, py + r * mswcos(a0+a2) );
+
+ MoveTo( d->hDc, pp2.x, pp2.y );
+ AngleArc( d->hDc, pc.x, pc.y, rr, (float)mswNormalizeAngle(90 - (a0+a2)),
+ (float)(-a2) );
+ MoveTo( d->hDc, pp2.x, pp2.y );
+ AngleArc( d->hDc, pc.x, pc.y, rr, (float)mswNormalizeAngle(90 - (a0+a2)),
+ (float)(a2) );
} else {
- Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, ps.y, pe.x, pe.y );
+ MoveTo( d->hDc, pp0.x, pp0.y );
+ AngleArc( d->hDc, pc.x, pc.y, rr, (float)mswNormalizeAngle(90 - a0),
+ (float)(-a1) );
}
}
// should the center of the arc be drawn?
if( sizeCenter ) {
-
- // calculate the center coordinates
- pc.x = XDRAWPIX2WINPIX( d, px );
- pc.y = YDRAWPIX2WINPIX( d, py );
- // now draw the crosshair
- MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH*sizeCenter, pc.y );
- LineTo( d->hDc, pc.x + CENTERMARK_LENGTH*sizeCenter, pc.y );
- MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH*sizeCenter );
- LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH*sizeCenter );
-
- // invalidate the area of the crosshair
- rect.top = pc.y - CENTERMARK_LENGTH*sizeCenter - 1;
- rect.bottom = pc.y + CENTERMARK_LENGTH*sizeCenter + 1;
- rect.left = pc.x - CENTERMARK_LENGTH*sizeCenter - 1;
- rect.right = pc.x + CENTERMARK_LENGTH*sizeCenter + 1;
- myInvalidateRect( d, &rect );
+
+ // now draw the crosshair
+ MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH*sizeCenter, pc.y );
+ LineTo( d->hDc, pc.x + CENTERMARK_LENGTH*sizeCenter, pc.y );
+ MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH*sizeCenter );
+ LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH*sizeCenter );
+
+ // invalidate the area of the crosshair
+ rect.top = pc.y - CENTERMARK_LENGTH*sizeCenter - 1;
+ rect.bottom = pc.y + CENTERMARK_LENGTH*sizeCenter + 1;
+ rect.left = pc.x - CENTERMARK_LENGTH*sizeCenter - 1;
+ rect.right = pc.x + CENTERMARK_LENGTH*sizeCenter + 1;
+ myInvalidateRect( d, &rect );
}
if (d->hWnd) {
dw++;
a1 += a0;
- if (a1>360.0)
+ if (a1>360.0) {
rect.top = p0.y;
- else
+ } else {
rect.top = min(pe.y,ps.y);
- if (a1>(a0>180?360.0:0.0)+180)
+ }
+ if (a1>(a0>180?360.0:0.0)+180) {
rect.bottom = p1.y;
- else
+ } else {
rect.bottom = max(pe.y,ps.y);
- if (a1>(a0>270?360.0:0.0)+270)
+ }
+ if (a1>(a0>270?360.0:0.0)+270) {
rect.left = p0.x;
- else
+ } else {
rect.left = min(pe.x,ps.x);
- if (a1>(a0>90?360.0:0.0)+90)
+ }
+ if (a1>(a0>90?360.0:0.0)+90) {
rect.right = p1.x;
- else
+ } else {
rect.right = max(pe.x,ps.x);
+ }
rect.top -= dw;
rect.bottom += dw;
rect.left -= dw;
@@ -530,11 +552,11 @@ void wDrawArc(
}
void wDrawPoint(
- wDraw_p d,
- wDrawPix_t px,
- wDrawPix_t py,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
POINT p0;
RECT rect;
@@ -542,13 +564,16 @@ void wDrawPoint(
p0.x = XDRAWPIX2WINPIX(d,px);
p0.y = YDRAWPIX2WINPIX(d,py);
- if ( p0.x < 0 || p0.y < 0 )
+ if ( p0.x < 0 || p0.y < 0 ) {
return;
- if ( p0.x >= d->w || p0.y >= d->h )
+ }
+ if ( p0.x >= d->w || p0.y >= d->h ) {
return;
+ }
setDrawMode( d, 0, wDrawLineSolid, dc, dopt );
- SetPixel( d->hDc, p0.x, p0.y, mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/ );
+ SetPixel( d->hDc, p0.x, p0.y, mswGetColor(d->hasPalette,
+ dc) /*colorPalette.palPalEntry[dc]*/ );
if (d->hWnd) {
rect.top = p0.y-1;
rect.bottom = p0.y+1;
@@ -568,126 +593,141 @@ void wDrawPoint(
static LOGFONT logFont = {
- /* Initial default values */
- -24, 0, /* H, W */
- 0, /* A */
- 0,
- FW_REGULAR,
- 0, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Arial" };
+ /* Initial default values */
+ -24, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_REGULAR,
+ 0, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Arial"
+ };
static LOGFONT timesFont[2][2] = {
- { {
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_REGULAR,
- 0, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Times" },
+ { {
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_REGULAR,
+ 0, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Times"
+ },
{
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_REGULAR,
- 1, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Times" } },
- { {
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_BOLD,
- 0, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Times" },
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_REGULAR,
+ 1, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Times"
+ }
+ },
+ { {
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_BOLD,
+ 0, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Times"
+ },
{
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_BOLD,
- 1, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Times" } } };
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_BOLD,
+ 1, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Times"
+ }
+ }
+};
static LOGFONT helvFont[2][2] = {
- { {
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_REGULAR,
- 0, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Arial" },
+ { {
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_REGULAR,
+ 0, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Arial"
+ },
{
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_REGULAR,
- 1, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Arial" } },
- { {
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_BOLD,
- 0, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Arial" },
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_REGULAR,
+ 1, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Arial"
+ }
+ },
+ { {
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_BOLD,
+ 0, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Arial"
+ },
{
- /* Initial default values */
- 0, 0, /* H, W */
- 0, /* A */
- 0,
- FW_BOLD,
- 1, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- 0, /* P&F */
- "Hevletica" } } };
+ /* Initial default values */
+ 0, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_BOLD,
+ 1, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ 0, /* P&F */
+ "Hevletica"
+ }
+ }
+};
void mswFontInit( void )
@@ -721,8 +761,9 @@ static void doChooseFont( void )
rc = ChooseFont( &chooseFont );
if (rc) {
fontSize = (wFontSize_t)(-logFont.lfHeight * 72) / 96.0 / fontFactor;
- if (fontSize < 1)
+ if (fontSize < 1) {
fontSize = 1;
+ }
wPrefSetString( "msw window font", "face", logFont.lfFaceName );
wPrefSetInteger( "msw window font", "size", logFont.lfHeight );
}
@@ -733,20 +774,21 @@ static int computeFontSize( wDraw_p d, double siz )
int ret;
siz = (siz * d->DPI) / 72.0;
ret = (int)(siz * fontFactor);
- if (ret < 1)
+ if (ret < 1) {
ret = 1;
+ }
return -ret;
}
void wDrawGetTextSize(
- wDrawPix_t *w,
- wDrawPix_t *h,
- wDrawPix_t *d,
- wDrawPix_t *a,
- wDraw_p bd,
- const char * text,
- wFont_p fp,
- double siz )
+ wDrawPix_t *w,
+ wDrawPix_t *h,
+ wDrawPix_t *d,
+ wDrawPix_t *a,
+ wDraw_p bd,
+ const char * text,
+ wFont_p fp,
+ double siz )
{
wWinPix_t x, y;
HFONT newFont, prevFont;
@@ -754,8 +796,9 @@ void wDrawGetTextSize(
int oldLfHeight;
TEXTMETRIC textMetric;
- if (fp == NULL)
+ if (fp == NULL) {
fp = &logFont;
+ }
fp->lfEscapement = 0;
oldLfHeight = fp->lfHeight;
fp->lfHeight = computeFontSize( bd, siz );
@@ -779,7 +822,7 @@ void wDrawGetTextSize(
}
/**
* Draw text
- *
+ *
* \param d device context
* \param px position x
* \param py position y
@@ -791,80 +834,74 @@ void wDrawGetTextSize(
* \param dopts drawing options
*/
void wDrawString(
- wDraw_p d,
- wDrawPix_t px,
- wDrawPix_t py,
- double angle,
- const char * text,
- wFont_p fp,
- double siz,
- wDrawColor dc,
- wDrawOpts dopts)
+ wDraw_p d,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ double angle,
+ const char * text,
+ wFont_p fp,
+ double siz,
+ wDrawColor dc,
+ wDrawOpts dopts)
{
- int x, y;
- HFONT newFont, prevFont;
- DWORD extent;
- int w, h;
- RECT rect;
- int oldLfHeight;
-
- if (fp == NULL) {
- fp = &logFont;
- }
-
- oldLfHeight = fp->lfHeight;
- fp->lfEscapement = (int)(angle*10.0);
- fp->lfHeight = computeFontSize(d, siz);
- fp->lfWidth = 0;
- newFont = CreateFontIndirect(fp);
- x = XDRAWPIX2WINPIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5);
- y = YDRAWPIX2WINPIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5);
-
- if (noNegDrawArgs > 0 && (x < 0 || y < 0)) {
- DeleteObject(newFont);
- return;
- }
-
- setDrawMode( d, 0, wDrawLineSolid, dc, dopts );
- prevFont = SelectObject(d->hDc, newFont);
- SetBkMode(d->hDc, TRANSPARENT);
-
- if (dopts & wDrawOutlineFont) {
- HPEN oldPen;
- BeginPath(d->hDc);
- TextOut(d->hDc, x, y, text, (int)strlen(text));
- EndPath(d->hDc);
-
- // Now draw outline text
- oldPen = SelectObject(d->hDc,
- CreatePen(PS_SOLID, 1,
- mswGetColor(d->hasPalette, dc)));
- StrokePath(d->hDc);
- SelectObject(d->hDc, oldPen);
- } else {
- COLORREF old;
-
- old = SetTextColor(d->hDc, mswGetColor(d->hasPalette,
- dc));
- TextOut(d->hDc, x, y, text, (int)(strlen(text)));
- SetTextColor(d->hDc, old);
- }
-
- extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text)));
- SelectObject(d->hDc, prevFont);
- w = LOWORD(extent);
- h = HIWORD(extent);
-
- if (d->hWnd) {
- rect.top = y - (w + h + 1);
- rect.bottom = y + (w + h + 1);
- rect.left = x - (w + h + 1);
- rect.right = x + (w + h + 1);
- myInvalidateRect(d, &rect);
- }
-
- DeleteObject(newFont);
- fp->lfHeight = oldLfHeight;
+ int x, y;
+ HFONT newFont, prevFont;
+ DWORD extent;
+ int w, h;
+ RECT rect;
+ int oldLfHeight;
+
+ if (fp == NULL) {
+ fp = &logFont;
+ }
+
+ oldLfHeight = fp->lfHeight;
+ fp->lfEscapement = (int)(angle*10.0);
+ fp->lfHeight = computeFontSize(d, siz);
+ fp->lfWidth = 0;
+ newFont = CreateFontIndirect(fp);
+ x = XDRAWPIX2WINPIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5);
+ y = YDRAWPIX2WINPIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5);
+
+ setDrawMode( d, 0, wDrawLineSolid, dc, dopts );
+ prevFont = SelectObject(d->hDc, newFont);
+ SetBkMode(d->hDc, TRANSPARENT);
+
+ if (dopts & wDrawOutlineFont) {
+ HPEN oldPen;
+ BeginPath(d->hDc);
+ TextOut(d->hDc, x, y, text, (int)strlen(text));
+ EndPath(d->hDc);
+
+ // Now draw outline text
+ oldPen = SelectObject(d->hDc,
+ CreatePen(PS_SOLID, 1,
+ mswGetColor(d->hasPalette, dc)));
+ StrokePath(d->hDc);
+ SelectObject(d->hDc, oldPen);
+ } else {
+ COLORREF old;
+
+ old = SetTextColor(d->hDc, mswGetColor(d->hasPalette, dc));
+ TextOut(d->hDc, x, y, text, (int)(strlen(text)));
+ SetTextColor(d->hDc, old);
+ }
+
+ extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text)));
+ SelectObject(d->hDc, prevFont);
+ w = LOWORD(extent);
+ h = HIWORD(extent);
+
+ if (d->hWnd) {
+ rect.top = y - (w + h + 1);
+ rect.bottom = y + (w + h + 1);
+ rect.left = x - (w + h + 1);
+ rect.right = x + (w + h + 1);
+ myInvalidateRect(d, &rect);
+ }
+
+ DeleteObject(newFont);
+ fp->lfHeight = oldLfHeight;
}
static const char * wCurFont( void )
@@ -878,12 +915,13 @@ void wInitializeFonts()
wFont_p wStandardFont( int family, wBool_t bold, wBool_t italic )
{
- if (family == F_TIMES)
+ if (family == F_TIMES) {
return &timesFont[bold][italic];
- else if (family == F_HELV)
+ } else if (family == F_HELV) {
return &helvFont[bold][italic];
- else
+ } else {
return NULL;
+ }
}
void wSelectFont( const char * title )
@@ -913,23 +951,23 @@ void wSetSelectedFontSize(wFontSize_t size)
void wDrawFilledRectangle(
- wDraw_p d,
- wDrawPix_t px,
- wDrawPix_t py,
- wDrawPix_t sx,
- wDrawPix_t sy,
- wDrawColor color,
- wDrawOpts opts )
+ wDraw_p d,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawPix_t sx,
+ wDrawPix_t sy,
+ wDrawColor color,
+ wDrawOpts opts )
{
int mode;
RECT rect;
- if (d == NULL)
+ if (d == NULL) {
return;
+ }
setDrawBrush( d, color, opts );
if (opts & wDrawOptTransparent) {
mode = R2_NOTXORPEN;
- }
- else {
+ } else {
mode = R2_COPYPEN;
}
SetROP2(d->hDc, mode);
@@ -938,19 +976,25 @@ void wDrawFilledRectangle(
rect.top = YDRAWPIX2WINPIX(d,py+sy);
rect.bottom = YDRAWPIX2WINPIX(d,py);
if ( rect.right < 0 ||
- rect.bottom < 0 )
+ rect.bottom < 0 ) {
return;
- if ( rect.left < 0 )
+ }
+ if ( rect.left < 0 ) {
rect.left = 0;
- if ( rect.top < 0 )
+ }
+ if ( rect.top < 0 ) {
rect.top = 0;
+ }
if ( rect.left > d->w ||
- rect.top > d->h )
+ rect.top > d->h ) {
return;
- if ( rect.right > d->w )
+ }
+ if ( rect.right > d->w ) {
rect.right = d->w;
- if ( rect.bottom > d->h )
+ }
+ if ( rect.bottom > d->h ) {
rect.bottom = d->h;
+ }
Rectangle( d->hDc, rect.left, rect.top, rect.right, rect.bottom );
if (d->hWnd) {
rect.top--;
@@ -962,7 +1006,7 @@ void wDrawFilledRectangle(
}
#ifdef DRAWFILLPOLYLOG
- static FILE * logF;
+static FILE * logF;
#endif
static dynArr_t wFillPoints_da;
@@ -983,34 +1027,34 @@ static dynArr_t wFillType_da;
*/
static void addPoint(
- wDraw_p d,
- int pk,
- coOrd * pp,
- BYTE type, RECT * pr)
+ wDraw_p d,
+ int pk,
+ coOrd * pp,
+ BYTE type, RECT * pr)
{
- POINT p;
- p.x = XDRAWPIX2WINPIX(d, pp->x);
- p.y = YDRAWPIX2WINPIX(d, pp->y);
+ POINT p;
+ p.x = XDRAWPIX2WINPIX(d, pp->x);
+ p.y = YDRAWPIX2WINPIX(d, pp->y);
#ifdef DRAWFILLPOLYLOG
- fprintf(logF, " q[%d] = {%d,%d}\n", pk, p.x, p.y);
+ fprintf(logF, " q[%d] = {%d,%d}\n", pk, p.x, p.y);
#endif
- DYNARR_N(POINT, wFillPoints_da, pk) = p;
- DYNARR_N(BYTE, wFillType_da, pk) = type;
-
- if (p.x < pr->left) {
- pr->left = p.x;
- }
- if (p.x > pr->right) {
- pr->right = p.x;
- }
- if (p.y < pr->top) {
- pr->top = p.y;
- }
- if (p.y > pr->bottom) {
- pr->bottom = p.y;
- }
+ DYNARR_N(POINT, wFillPoints_da, pk) = p;
+ DYNARR_N(BYTE, wFillType_da, pk) = type;
+
+ if (p.x < pr->left) {
+ pr->left = p.x;
+ }
+ if (p.x > pr->right) {
+ pr->right = p.x;
+ }
+ if (p.y < pr->top) {
+ pr->top = p.y;
+ }
+ if (p.y > pr->bottom) {
+ pr->bottom = p.y;
+ }
}
/**
@@ -1030,208 +1074,190 @@ static void addPoint(
*/
void wDrawPolygon(
- wDraw_p d,
- wDrawPix_t node[][2],
- wPolyLine_e type[],
- wIndex_t cnt,
- wDrawColor color,
- wDrawWidth dw,
- wDrawLineType_e lt,
- wDrawOpts opts,
- int fill,
- int open)
+ wDraw_p d,
+ wDrawPix_t node[][2],
+ wPolyLine_e type[],
+ wIndex_t cnt,
+ wDrawColor color,
+ wDrawWidth dw,
+ wDrawLineType_e lt,
+ wDrawOpts opts,
+ int fill,
+ int open)
{
- RECT rect;
- int i, prevNode, nextNode;
- int pointCount = 0;
- coOrd endPoint0, endPoint1, controlPoint0, controlPoint1;
- coOrd point, startingPoint;
- BOOL rc;
- int closed = 0;
-
- if (d == NULL) {
- return;
- }
-
- // make sure the array for the points is large enough
- // worst case are rounded corners that require 4 points
- DYNARR_RESET(POINT,wFillPoints_da);
- DYNARR_SET(POINT,wFillPoints_da,(cnt + 1) * 4);
- DYNARR_RESET(BYTE,wFillType_da);
- DYNARR_SET(POINT,wFillType_da, (cnt + 1) * 4);
-
- BeginPath(d->hDc);
-
- if (fill) {
+ RECT rect;
+ int i, prevNode, nextNode;
+ int pointCount = 0;
+ coOrd endPoint0, endPoint1, controlPoint0, controlPoint1;
+ coOrd point, startingPoint;
+ BOOL rc;
+ int closed = 0;
+
+ if (d == NULL) {
+ return;
+ }
+
+ // make sure the array for the points is large enough
+ // worst case are rounded corners that require 4 points
+ DYNARR_RESET(POINT,wFillPoints_da);
+ DYNARR_SET(POINT,wFillPoints_da,(cnt + 1) * 4);
+ DYNARR_RESET(BYTE,wFillType_da);
+ DYNARR_SET(POINT,wFillType_da, (cnt + 1) * 4);
+
+ BeginPath(d->hDc);
+
+ if (fill) {
int mode;
- setDrawBrush(d, color, opts);
+ setDrawBrush(d, color, opts);
if (opts & wDrawOptTransparent) {
mode = R2_NOTXORPEN;
- }
- else {
+ } else {
mode = R2_COPYPEN;
}
SetROP2(d->hDc, mode);
- } else {
- setDrawMode(d, dw, lt, color, opts);
- }
+ } else {
+ setDrawMode(d, dw, lt, color, opts);
+ }
- rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1);
- rect.top = rect.bottom = YDRAWPIX2WINPIX(d,node[cnt-1][1]+1);
+ rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1);
+ rect.top = rect.bottom = YDRAWPIX2WINPIX(d,node[cnt-1][1]+1);
#ifdef DRAWFILLPOLYLOG
- logF = fopen("log.txt", "a");
- fprintf(logF, "\np[%d] = {%d,%d}\n", cnt-1, node[0][0], node[0][1]);
+ logF = fopen("log.txt", "a");
+ fprintf(logF, "\np[%d] = {%d,%d}\n", cnt-1, node[0][0], node[0][1]);
#endif
- for (i=0; i<cnt; i++) {
- wPolyLine_e type1;
- point.x = node[i][0];
- point.y = node[i][1];
- if (type != NULL)
+ for (i=0; i<cnt; i++) {
+ wPolyLine_e type1;
+ point.x = node[i][0];
+ point.y = node[i][1];
+ if (type != NULL) {
type1 = type[i];
- else
+ } else {
type1 = wPolyLineStraight;
+ }
- if (type1 == wPolyLineRound || type1 == wPolyLineSmooth) {
- prevNode = (i == 0) ? cnt - 1 : i - 1;
- nextNode = (i == cnt - 1) ? 0 : i + 1;
-
- // calculate distance to neighboring nodes
- int prevXDistance = (wWinPix_t)(node[i][0] - node[prevNode][0]);
- int prevYDistance = (wWinPix_t)(node[i][1] - node[prevNode][1]);
- int nextXDistance = (wWinPix_t)(node[nextNode][0]-node[i][0]);
- int nextYDistance = (wWinPix_t)(node[nextNode][1]-node[i][1]);
-
- // distance from node to endpoints of curve is half the line length
- endPoint0.x = (prevXDistance/2)+node[prevNode][0];
- endPoint0.y = (prevYDistance/2)+node[prevNode][1];
- endPoint1.x = (nextXDistance/2)+node[i][0];
- endPoint1.y = (nextYDistance/2)+node[i][1];
-
- if (type1 == wPolyLineRound) {
- double distNext = (nextXDistance*nextXDistance + nextYDistance * nextYDistance);
- double distPrev = (prevXDistance*prevXDistance + prevYDistance * prevYDistance);
- // but should be half of the shortest line length (equidistant from node) for round
- if ((distPrev > 0) && (distNext > 0)) {
- double ratio = sqrt(distPrev / distNext);
- if (distPrev < distNext) {
- endPoint1.x = ((nextXDistance*ratio) / 2) + node[i][0];
- endPoint1.y = ((nextYDistance*ratio) / 2) + node[i][1];
- } else {
- endPoint0.x = node[i][0] - (prevXDistance / (2 * ratio));
- endPoint0.y = node[i][1] - (prevYDistance / (2 * ratio));
- }
- }
- // experience says that the best look is achieved if the
- // control points are in the middle between end point and node
- controlPoint0.x = (node[i][0] - endPoint0.x) / 2 + endPoint0.x;
- controlPoint0.y = (node[i][1] - endPoint0.y) / 2 + endPoint0.y;
-
- controlPoint1.x = (endPoint1.x - node[i][0]) / 2 + node[i][0];
- controlPoint1.y = (endPoint1.y - node[i][1]) / 2 + node[i][1];
- } else {
- controlPoint0 = point;
- controlPoint1 = point;
- }
- }
-
- if (i==0) {
- if (type1 == wPolyLineStraight || open) {
- // for straight lines or open shapes use the starting point as passed
- addPoint(d, pointCount++, &point, PT_MOVETO, &rect);
- startingPoint = point;
- } else {
- // for Bezier begin with the calculated starting point
- addPoint(d, pointCount++, &endPoint0, PT_MOVETO, &rect);
- addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect);
- addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect);
- addPoint(d, pointCount++, &endPoint1, PT_BEZIERTO, &rect);
- startingPoint = endPoint0;
- }
- } else {
- if (type1 == wPolyLineStraight || (open && (i==cnt-1))) {
- addPoint(d, pointCount++, &point, PT_LINETO, &rect);
- } else {
- if (i==cnt-1 && !open) {
- closed = TRUE;
- }
- addPoint(d, pointCount++, &endPoint0, PT_LINETO, &rect);
- addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect);
- addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect);
- addPoint(d, pointCount++, &endPoint1,
- PT_BEZIERTO | (closed ? PT_CLOSEFIGURE : 0), &rect);
- }
- }
- }
-
- if (!open && !closed) {
- addPoint(d, pointCount++, &startingPoint, PT_LINETO, &rect);
- }
- rc = PolyDraw(d->hDc, wFillPoints_da.ptr, wFillType_da.ptr, pointCount);
-
- EndPath(d->hDc);
-
- if (fill && !open) {
- FillPath(d->hDc);
- } else {
- StrokePath(d->hDc);
- }
-
- if (d->hWnd) {
- rect.top--;
- rect.left--;
- rect.bottom++;
- rect.right++;
- myInvalidateRect(d, &rect);
- }
+ if (type1 == wPolyLineRound || type1 == wPolyLineSmooth) {
+ prevNode = (i == 0) ? cnt - 1 : i - 1;
+ nextNode = (i == cnt - 1) ? 0 : i + 1;
+
+ // calculate distance to neighboring nodes
+ int prevXDistance = (wWinPix_t)(node[i][0] - node[prevNode][0]);
+ int prevYDistance = (wWinPix_t)(node[i][1] - node[prevNode][1]);
+ int nextXDistance = (wWinPix_t)(node[nextNode][0]-node[i][0]);
+ int nextYDistance = (wWinPix_t)(node[nextNode][1]-node[i][1]);
+
+ // distance from node to endpoints of curve is half the line length
+ endPoint0.x = (prevXDistance/2)+node[prevNode][0];
+ endPoint0.y = (prevYDistance/2)+node[prevNode][1];
+ endPoint1.x = (nextXDistance/2)+node[i][0];
+ endPoint1.y = (nextYDistance/2)+node[i][1];
+
+ if (type1 == wPolyLineRound) {
+ double distNext = (nextXDistance*nextXDistance + nextYDistance * nextYDistance);
+ double distPrev = (prevXDistance*prevXDistance + prevYDistance * prevYDistance);
+ // but should be half of the shortest line length (equidistant from node) for round
+ if ((distPrev > 0) && (distNext > 0)) {
+ double ratio = sqrt(distPrev / distNext);
+ if (distPrev < distNext) {
+ endPoint1.x = ((nextXDistance*ratio) / 2) + node[i][0];
+ endPoint1.y = ((nextYDistance*ratio) / 2) + node[i][1];
+ } else {
+ endPoint0.x = node[i][0] - (prevXDistance / (2 * ratio));
+ endPoint0.y = node[i][1] - (prevYDistance / (2 * ratio));
+ }
+ }
+ // experience says that the best look is achieved if the
+ // control points are in the middle between end point and node
+ controlPoint0.x = (node[i][0] - endPoint0.x) / 2 + endPoint0.x;
+ controlPoint0.y = (node[i][1] - endPoint0.y) / 2 + endPoint0.y;
+
+ controlPoint1.x = (endPoint1.x - node[i][0]) / 2 + node[i][0];
+ controlPoint1.y = (endPoint1.y - node[i][1]) / 2 + node[i][1];
+ } else {
+ controlPoint0 = point;
+ controlPoint1 = point;
+ }
+ }
+
+ if (i==0) {
+ if (type1 == wPolyLineStraight || open) {
+ // for straight lines or open shapes use the starting point as passed
+ addPoint(d, pointCount++, &point, PT_MOVETO, &rect);
+ startingPoint = point;
+ } else {
+ // for Bezier begin with the calculated starting point
+ addPoint(d, pointCount++, &endPoint0, PT_MOVETO, &rect);
+ addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect);
+ addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect);
+ addPoint(d, pointCount++, &endPoint1, PT_BEZIERTO, &rect);
+ startingPoint = endPoint0;
+ }
+ } else {
+ if (type1 == wPolyLineStraight || (open && (i==cnt-1))) {
+ addPoint(d, pointCount++, &point, PT_LINETO, &rect);
+ } else {
+ if (i==cnt-1 && !open) {
+ closed = TRUE;
+ }
+ addPoint(d, pointCount++, &endPoint0, PT_LINETO, &rect);
+ addPoint(d, pointCount++, &controlPoint0, PT_BEZIERTO, &rect);
+ addPoint(d, pointCount++, &controlPoint1, PT_BEZIERTO, &rect);
+ addPoint(d, pointCount++, &endPoint1,
+ PT_BEZIERTO | (closed ? PT_CLOSEFIGURE : 0), &rect);
+ }
+ }
+ }
+
+ if (!open && !closed) {
+ addPoint(d, pointCount++, &startingPoint, PT_LINETO, &rect);
+ }
+ rc = PolyDraw(d->hDc, wFillPoints_da.ptr, wFillType_da.ptr, pointCount);
+
+ EndPath(d->hDc);
+
+ if (fill && !open) {
+ FillPath(d->hDc);
+ } else {
+ StrokePath(d->hDc);
+ }
+
+ if (d->hWnd) {
+ rect.top--;
+ rect.left--;
+ rect.bottom++;
+ rect.right++;
+ myInvalidateRect(d, &rect);
+ }
}
#define MAX_FILLCIRCLE_POINTS (30)
void wDrawFilledCircle(
- wDraw_p d,
- wDrawPix_t x,
- wDrawPix_t y,
- wDrawPix_t r,
- wDrawColor color,
- wDrawOpts opts )
+ wDraw_p d,
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t r,
+ wDrawColor color,
+ wDrawOpts opts )
{
POINT p0, p1;
RECT rect;
static wDrawPix_t circlePts[MAX_FILLCIRCLE_POINTS][2];
- int inx, cnt;
- double dang;
p0.x = XDRAWPIX2WINPIX(d,x-r);
p0.y = YDRAWPIX2WINPIX(d,y+r);
p1.x = XDRAWPIX2WINPIX(d,x+r);
p1.y = YDRAWPIX2WINPIX(d,y-r);
-
- setDrawBrush( d, color, opts );
- if ( noNegDrawArgs > 0 && ( p0.x < 0 || p0.y < 0 ) ) {
- if ( r > MAX_FILLCIRCLE_POINTS )
- cnt = MAX_FILLCIRCLE_POINTS;
- else if ( r > 8 )
- cnt = XDRAWPIX2WINPIX(d,r);
- else
- cnt = 8;
- dang = 360.0/cnt;
- for ( inx=0; inx<cnt; inx++ ) {
- circlePts[inx][0] = x + (int)(r * mswcos( inx*dang ) + 0.5 );
- circlePts[inx][1] = y + (int)(r * mswsin( inx*dang ) + 0.5 );
- }
- //wDrawFilledPolygon( d, circlePts, NULL, cnt, color, opts );
- wDrawPolygon(d, circlePts, NULL, cnt, color, 1, wDrawLineSolid,opts, TRUE, FALSE );
- } else {
- Ellipse( d->hDc, p0.x, p0.y, p1.x, p1.y );
- if (d->hWnd) {
- rect.top = p0.y;
- rect.bottom = p1.y;
- rect.left = p0.x;
- rect.right = p1.x;
- myInvalidateRect( d, &rect );
- }
+
+ setDrawBrush( d, color, opts );
+ Ellipse( d->hDc, p0.x, p0.y, p1.x, p1.y );
+ if (d->hWnd) {
+ rect.top = p0.y;
+ rect.bottom = p1.y;
+ rect.left = p0.x;
+ rect.right = p1.x;
+ myInvalidateRect( d, &rect );
}
}
@@ -1245,22 +1271,23 @@ void wDrawFilledCircle(
void wDrawSaveImage(
- wDraw_p bd )
+ wDraw_p bd )
{
- if ( bd->hBmBackup ) {
+ if ( bd->hBmBackup ) {
SelectObject( bd->hDcBackup, bd->hBmBackupOld );
DeleteObject( bd->hBmBackup );
bd->hBmBackup = (HBITMAP)0;
}
- if ( bd->hDcBackup == (HDC)0 )
- bd->hDcBackup = CreateCompatibleDC( bd->hDc );
+ if ( bd->hDcBackup == (HDC)0 ) {
+ bd->hDcBackup = CreateCompatibleDC( bd->hDc );
+ }
bd->hBmBackup = CreateCompatibleBitmap( bd->hDc, bd->w, bd->h );
bd->hBmBackupOld = SelectObject( bd->hDcBackup, bd->hBmBackup );
BitBlt( bd->hDcBackup, 0, 0, bd->w, bd->h, bd->hDc, 0, 0, SRCCOPY );
}
void wDrawRestoreImage(
- wDraw_p bd )
+ wDraw_p bd )
{
if ( bd->hBmBackup == (HBITMAP)0 ) {
mswFail( "wDrawRestoreImage: hBmBackup == 0" );
@@ -1296,14 +1323,14 @@ void wDrawClear( wDraw_p d )
void wDrawSetSize(
- wDraw_p d,
- wWinPix_t width,
- wWinPix_t height, void * redraw)
+ wDraw_p d,
+ wWinPix_t width,
+ wWinPix_t height, void * redraw)
{
d->w = width;
d->h = height;
if (!SetWindowPos( d->hWnd, HWND_TOP, 0, 0,
- d->w, d->h, SWP_NOMOVE|SWP_NOZORDER)) {
+ d->w, d->h, SWP_NOMOVE|SWP_NOZORDER)) {
mswFail("wDrawSetSize: SetWindowPos");
}
/*wRedraw( d );*/
@@ -1311,9 +1338,9 @@ void wDrawSetSize(
void wDrawGetSize(
- wDraw_p d,
- wWinPix_t * width,
- wWinPix_t * height )
+ wDraw_p d,
+ wWinPix_t * width,
+ wWinPix_t * height )
{
*width = d->w-2;
*height = d->h-2;
@@ -1337,11 +1364,11 @@ double wDrawGetMaxRadius( wDraw_p d )
}
void wDrawClip(
- wDraw_p d,
- wDrawPix_t x,
- wDrawPix_t y,
- wDrawPix_t w,
- wDrawPix_t h )
+ wDraw_p d,
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t w,
+ wDrawPix_t h )
{
wWinPix_t ix0, iy0, ix1, iy1;
HRGN hRgnClip;
@@ -1359,9 +1386,96 @@ void wDrawClip(
void wRedraw( wDraw_p d )
{
wDrawClear( d );
- if (d->drawRepaint)
+ if (d->drawRepaint) {
d->drawRepaint( d, d->data, 0, 0 );
+ }
}
+
+/*
+ *****************************************************************************
+ *
+ * Cursor handling
+ *
+ *****************************************************************************
+ */
+
+
+extern long dontHideCursor;
+static wCursor_t curCursor = wCursorNormal;
+
+void DoSetCursor()
+{
+ switch (curCursor) {
+ case wCursorNormal:
+ default:
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+ break;
+
+ case wCursorWait:
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
+ break;
+
+ case wCursorCross:
+ SetCursor(LoadCursor(NULL, IDC_CROSS));
+ break;
+
+ case wCursorIBeam:
+ SetCursor(LoadCursor(NULL, IDC_IBEAM));
+ break;
+
+ case wCursorQuestion:
+ SetCursor(LoadCursor(NULL, IDC_HELP));
+ break;
+
+ case wCursorHand:
+ SetCursor(LoadCursor(NULL, IDC_HAND));
+ break;
+
+ case wCursorNo:
+ SetCursor(LoadCursor(NULL, IDC_NO));
+ break;
+
+ case wCursorSizeAll:
+ SetCursor(LoadCursor(NULL, IDC_SIZEALL));
+ break;
+
+ case wCursorSizeNESW:
+ SetCursor(LoadCursor(NULL, IDC_SIZENESW));
+ break;
+
+ case wCursorSizeNWSE:
+ SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
+ break;
+
+ case wCursorSizeNS:
+ SetCursor(LoadCursor(NULL, IDC_SIZENS));
+ break;
+
+ case wCursorSizeWE:
+ SetCursor(LoadCursor(NULL, IDC_SIZEWE));
+ break;
+
+ case wCursorAppStart:
+ SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
+ break;
+
+ case wCursorNone:
+ if (!dontHideCursor) {
+ SetCursor(NULL);
+ }
+ break;
+ }
+
+}
+
+void wSetCursor(wDraw_p win,
+ wCursor_t cursor)
+{
+ curCursor = cursor;
+ DoSetCursor();
+}
+
+
/*
*****************************************************************************
@@ -1372,27 +1486,27 @@ void wRedraw( wDraw_p d )
*/
struct wDrawBitMap_t {
- wDrawBitMap_p next;
- wDrawPix_t x;
- wDrawPix_t y;
- wDrawPix_t w;
- wDrawPix_t h;
- char * bmx;
- wDrawColor color;
- HBITMAP bm;
- };
+ wDrawBitMap_p next;
+ wDrawPix_t x;
+ wDrawPix_t y;
+ wDrawPix_t w;
+ wDrawPix_t h;
+ char * bmx;
+ wDrawColor color;
+ HBITMAP bm;
+};
static wDrawBitMap_p bmRoot = NULL;
extern wDrawColor drawColorWhite;
extern wDrawColor drawColorBlack;
void wDrawBitMap(
- wDraw_p d,
- wDrawBitMap_p bm,
- wDrawPix_t px,
- wDrawPix_t py,
- wDrawColor dc,
- wDrawOpts dopt )
+ wDraw_p d,
+ wDrawBitMap_p bm,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawColor dc,
+ wDrawOpts dopt )
{
HDC bmDc;
HBITMAP oldBm;
@@ -1403,8 +1517,9 @@ void wDrawBitMap(
x0 = XDRAWPIX2WINPIX(d,px-bm->x);
y0 = YDRAWPIX2WINPIX(d,py-bm->y+bm->h);
#ifdef LATER
- if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) )
+ if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) ) {
return;
+ }
#endif
if (dc == drawColorWhite) {
mode = clrOp;
@@ -1414,10 +1529,12 @@ void wDrawBitMap(
}
if ( bm->color != dc ) {
- if ( bm->bm )
+ if ( bm->bm ) {
DeleteObject( bm->bm );
- bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ),
- RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx );
+ }
+ bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette,
+ dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ),
+ RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx );
bm->color = dc;
}
@@ -1428,22 +1545,22 @@ void wDrawBitMap(
SelectObject( bmDc, oldBm );
DeleteDC( bmDc );
if (d->hWnd) {
- rect.top = y0-1;
- rect.bottom = rect.top+ (wWinPix_t)bm->h+1;
- rect.left = x0-1;
- rect.right = rect.left+ (wWinPix_t)bm->w+1;
- myInvalidateRect( d, &rect );
+ rect.top = y0-1;
+ rect.bottom = rect.top+ (wWinPix_t)bm->h+1;
+ rect.left = x0-1;
+ rect.right = rect.left+ (wWinPix_t)bm->w+1;
+ myInvalidateRect( d, &rect );
}
}
wDrawBitMap_p wDrawBitMapCreate(
- wDraw_p d,
- int w,
- int h,
- int x,
- int y,
- const unsigned char * bits )
+ wDraw_p d,
+ int w,
+ int h,
+ int x,
+ int y,
+ const unsigned char * bits )
{
wDrawBitMap_p bm;
int bmSize = ((w+7)/8) * h;
@@ -1478,10 +1595,10 @@ wDrawBitMap_p wDrawBitMapCreate(
static int doSetFocus = 1;
LRESULT FAR PASCAL XEXPORT mswDrawPush(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wDraw_p b;
@@ -1505,7 +1622,7 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush(
b->hBmTemp = 0;
b->hBmOld = 0;
} else {
- b->hDc = CreateCompatibleDC( hDc );
+ b->hDc = CreateCompatibleDC( hDc );
b->hBmMain = CreateCompatibleBitmap( hDc, b->w, b->h );
b->hBmTemp = CreateCompatibleBitmap( hDc, b->w, b->h );
b->hBmOld = SelectObject( b->hDc, b->hBmMain );
@@ -1538,68 +1655,84 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush(
if (b->hWnd) {
if ( b->option & BD_DIRECT ) {
} else {
- hDc = GetDC( b->hWnd );
+ hDc = GetDC( b->hWnd );
//- DeleteObject( b->hBmOld );
- DeleteObject( b->hBmMain );
- DeleteObject( b->hBmTemp );
- b->hBmMain = CreateCompatibleBitmap( hDc, b->w, b->h );
- b->hBmTemp = CreateCompatibleBitmap( hDc, b->w, b->h );
+ DeleteObject( b->hBmMain );
+ DeleteObject( b->hBmTemp );
+ b->hBmMain = CreateCompatibleBitmap( hDc, b->w, b->h );
+ b->hBmTemp = CreateCompatibleBitmap( hDc, b->w, b->h );
//- b->hBmOld = SelectObject( b->hDc, b->hBmMain );
- ReleaseDC( b->hWnd, hDc );
- SetROP2( b->hDc, R2_WHITE );
- Rectangle( b->hDc, 0, 0, b->w, b->h );
+ ReleaseDC( b->hWnd, hDc );
+ SetROP2( b->hDc, R2_WHITE );
+ Rectangle( b->hDc, 0, 0, b->w, b->h );
}
}
/*if (b->drawResize)
b->drawResize( b, b->size );*/
- if (b->drawRepaint)
+ if (b->drawRepaint) {
b->drawRepaint( b, b->data, 0, 0 );
+ }
return (LRESULT)0;
case WM_MOUSEMOVE:
activeWnd = GetActiveWindow();
focusWnd = GetFocus();
if (focusWnd != hWnd) {
b = (wDraw_p)mswMapIndex( inx );
- if (!b)
+ if (!b) {
break;
- if ( !((wControl_p)b->parent) )
+ }
+ if ( !((wControl_p)b->parent) ) {
break;
- if ( ((wControl_p)b->parent)->hWnd != activeWnd )
+ }
+ if ( ((wControl_p)b->parent)->hWnd != activeWnd ) {
break;
+ }
}
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_LBUTTONDBLCLK:
- if (message == WM_LBUTTONDOWN)
+ case WM_MBUTTONUP:
+ case WM_MBUTTONDOWN:
+ if (message == WM_LBUTTONDOWN) {
action = wActionLDown;
- else if (message == WM_RBUTTONDOWN)
+ } else if (message == WM_RBUTTONDOWN) {
action = wActionRDown;
- else if (message == WM_LBUTTONUP)
+ } else if (message == WM_LBUTTONUP) {
action = wActionLUp;
- else if (message == WM_RBUTTONUP)
+ } else if (message == WM_RBUTTONUP) {
action = wActionRUp;
- else if (message == WM_LBUTTONDBLCLK)
+ } else if (message == WM_MBUTTONUP) {
+ action = wActionMUp;
+ } else if (message == WM_MBUTTONDOWN) {
+ action = wActionMDown;
+ } else if (message == WM_LBUTTONDBLCLK) {
action = wActionLDownDouble;
- else {
- if ( (wParam & MK_LBUTTON) != 0)
+ } else {
+ if ( (wParam & MK_LBUTTON) != 0) {
action = wActionLDrag;
- else if ( (wParam & MK_RBUTTON) != 0)
+ } else if ( (wParam & MK_RBUTTON) != 0) {
action = wActionRDrag;
- else
+ } else if ( (wParam & MK_MBUTTON) != 0) {
+ action = wActionMDrag;
+ } else {
action = wActionMove;
+ }
}
b = (wDraw_p)mswMapIndex( inx );
- if (!b)
+ if (!b) {
break;
- if (doSetFocus && message != WM_MOUSEMOVE)
+ }
+ if (doSetFocus && message != WM_MOUSEMOVE) {
SetFocus( ((wControl_p)b->parent)->hWnd );
+ }
if ( (b->option&BD_NOCAPTURE) == 0 ) {
- if (message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN)
+ if (message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN) {
SetCapture( b->hWnd );
- else if (message == WM_LBUTTONUP || message == WM_RBUTTONUP)
+ } else if (message == WM_LBUTTONUP || message == WM_RBUTTONUP) {
ReleaseCapture();
+ }
}
ix = LOWORD( lParam );
iy = HIWORD( lParam );
@@ -1607,45 +1740,50 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush(
y = YWINPIX2DRAWPIX( b, iy );
b->lastX = x;
b->lastY = y;
- if (b->action)
+ if (b->action) {
b->action( b, b->data, action, x, y );
- if (b->hWnd)
+ }
+ if (b->hWnd) {
UpdateWindow(b->hWnd);
+ }
return (LRESULT)0;
case WM_CHAR:
b = (wDraw_p)mswMapIndex( inx );
extChar = wAccelKey_None;
if (lParam & 0x01000000L)
- switch( wParam ) {
- case VK_DELETE: extChar = wAccelKey_Del; break;
- case VK_INSERT: extChar = wAccelKey_Ins; break;
- case VK_HOME: extChar = wAccelKey_Home; break;
- case VK_END: extChar = wAccelKey_End; break;
- case VK_PRIOR: extChar = wAccelKey_Pgup; break;
- case VK_NEXT: extChar = wAccelKey_Pgdn; break;
- case VK_UP: extChar = wAccelKey_Up; break;
- case VK_DOWN: extChar = wAccelKey_Down; break;
- case VK_RIGHT: extChar = wAccelKey_Right; break;
- case VK_LEFT: extChar = wAccelKey_Left; break;
- case VK_BACK: extChar = wAccelKey_Back; break;
- case VK_F1: extChar = wAccelKey_F1; break;
- case VK_F2: extChar = wAccelKey_F2; break;
- case VK_F3: extChar = wAccelKey_F3; break;
- case VK_F4: extChar = wAccelKey_F4; break;
- case VK_F5: extChar = wAccelKey_F5; break;
- case VK_F6: extChar = wAccelKey_F6; break;
- case VK_F7: extChar = wAccelKey_F7; break;
- case VK_F8: extChar = wAccelKey_F8; break;
- case VK_F9: extChar = wAccelKey_F9; break;
- case VK_F10: extChar = wAccelKey_F10; break;
- case VK_F11: extChar = wAccelKey_F11; break;
- case VK_F12: extChar = wAccelKey_F12; break;
- }
+ switch( wParam ) {
+ case VK_DELETE: extChar = wAccelKey_Del; break;
+ case VK_INSERT: extChar = wAccelKey_Ins; break;
+ case VK_HOME: extChar = wAccelKey_Home; break;
+ case VK_END: extChar = wAccelKey_End; break;
+ case VK_PRIOR: extChar = wAccelKey_Pgup; break;
+ case VK_NEXT: extChar = wAccelKey_Pgdn; break;
+ case VK_UP: extChar = wAccelKey_Up; break;
+ case VK_DOWN: extChar = wAccelKey_Down; break;
+ case VK_RIGHT: extChar = wAccelKey_Right; break;
+ case VK_LEFT: extChar = wAccelKey_Left; break;
+ case VK_BACK: extChar = wAccelKey_Back; break;
+ case VK_F1: extChar = wAccelKey_F1; break;
+ case VK_F2: extChar = wAccelKey_F2; break;
+ case VK_F3: extChar = wAccelKey_F3; break;
+ case VK_F4: extChar = wAccelKey_F4; break;
+ case VK_F5: extChar = wAccelKey_F5; break;
+ case VK_F6: extChar = wAccelKey_F6; break;
+ case VK_F7: extChar = wAccelKey_F7; break;
+ case VK_F8: extChar = wAccelKey_F8; break;
+ case VK_F9: extChar = wAccelKey_F9; break;
+ case VK_F10: extChar = wAccelKey_F10; break;
+ case VK_F11: extChar = wAccelKey_F11; break;
+ case VK_F12: extChar = wAccelKey_F12; break;
+ }
if (b && b->action) {
- if (extChar != wAccelKey_None)
- b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX, b->lastY );
- else
- b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX, b->lastY );
+ if (extChar != wAccelKey_None) {
+ b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX,
+ b->lastY );
+ } else {
+ b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX,
+ b->lastY );
+ }
}
return (LRESULT)0;
@@ -1663,17 +1801,17 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush(
}
HBITMAP hBmOld = SelectObject( b->hDc, b->hBmMain );
- if (bDrawMainBM) {
- BitBlt(hDc, rect.left, rect.top,
- rect.right - rect.left, rect.bottom - rect.top,
- b->hDc, rect.left, rect.top,
- SRCCOPY);
- }
+ if (bDrawMainBM) {
+ BitBlt(hDc, rect.left, rect.top,
+ rect.right - rect.left, rect.bottom - rect.top,
+ b->hDc, rect.left, rect.top,
+ SRCCOPY);
+ }
SelectObject( b->hDc, b->bCopiedMain?b->hBmTemp:b->hBmMain );
BitBlt( hDc, rect.left, rect.top,
- rect.right-rect.left, rect.bottom-rect.top,
- b->hDc, rect.left, rect.top,
- bDrawMainBM?SRCAND:SRCCOPY);
+ rect.right-rect.left, rect.bottom-rect.top,
+ b->hDc, rect.left, rect.top,
+ bDrawMainBM?SRCAND:SRCCOPY);
SelectObject( b->hDc, hBmOld );
EndPaint( hWnd, &ps );
b->bCopiedMain = FALSE;
@@ -1693,6 +1831,13 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush(
}
}
break;
+
+ case WM_SETCURSOR:
+ // Set cursor based on wSetCursor
+ DoSetCursor();
+ // return TRUE to suppress my parent from overriding me
+ return TRUE;
+
default:
break;
}
@@ -1700,10 +1845,11 @@ LRESULT FAR PASCAL XEXPORT mswDrawPush(
}
-static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam,
+ LPARAM lParam )
{
wAction_t action;
-
+
switch( message ) {
case WM_MOUSEWHEEL:
/* handle mouse wheel events */
@@ -1728,8 +1874,9 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L
action = wActionWheelDown;
}
}
- if (b->action)
+ if (b->action) {
b->action( b, b->data, action, b->lastX, b->lastY );
+ }
return (LRESULT)0;
case WM_MOUSEHWHEEL:
if ( GET_KEYSTATE_WPARAM(wParam) & (MK_SHIFT|MK_MBUTTON)) {
@@ -1739,8 +1886,9 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L
action = wActionScrollLeft;
}
}
- if (b->action)
+ if (b->action) {
b->action( b, b->data, action, b->lastX, b->lastY );
+ }
return (LRESULT)0;
}
@@ -1777,17 +1925,19 @@ static void drawDoneProc( wControl_p b )
d->hDcBackup = (HDC)0;
}
while (bmRoot) {
- if (bmRoot->bm)
+ if (bmRoot->bm) {
DeleteObject( bmRoot->bm );
+ }
bmRoot = bmRoot->next;
}
}
static callBacks_t drawCallBacks = {
- NULL,
- drawDoneProc,
- (messageCallback_p)drawMsgProc };
+ NULL,
+ drawDoneProc,
+ (messageCallback_p)drawMsgProc
+};
static wDraw_p drawList = NULL;
@@ -1796,8 +1946,9 @@ void mswRedrawAll( void )
{
wDraw_p p;
for ( p=drawList; p; p=p->drawNext ) {
- if (p->drawRepaint)
+ if (p->drawRepaint) {
p->drawRepaint( p, p->data, 0, 0 );
+ }
}
}
@@ -1814,14 +1965,14 @@ void mswRepaintAll( void )
hDc = BeginPaint( b->hWnd, &ps );
HBITMAP hBmOld = SelectObject( b->hDc, b->hBmMain );
BitBlt( hDc, rect.left, rect.top,
- rect.right-rect.left, rect.bottom-rect.top,
- b->hDc, rect.left, rect.top,
- SRCCOPY );
+ rect.right-rect.left, rect.bottom-rect.top,
+ b->hDc, rect.left, rect.top,
+ SRCCOPY );
SelectObject( b->hDc, b->hBmTemp );
BitBlt( hDc, rect.left, rect.top,
- rect.right-rect.left, rect.bottom-rect.top,
- b->hDc, rect.left, rect.top,
- SRCAND );
+ rect.right-rect.left, rect.bottom-rect.top,
+ b->hDc, rect.left, rect.top,
+ SRCAND );
SelectObject( b->hDc, hBmOld );
EndPaint( b->hWnd, &ps );
}
@@ -1830,27 +1981,22 @@ void mswRepaintAll( void )
wDraw_p wDrawCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- long option,
- wWinPix_t w,
- wWinPix_t h,
- void * data,
- wDrawRedrawCallBack_p redrawProc,
- wDrawActionCallBack_p action )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ long option,
+ wWinPix_t w,
+ wWinPix_t h,
+ void * data,
+ wDrawRedrawCallBack_p redrawProc,
+ wDrawActionCallBack_p action )
{
wDraw_p d;
RECT rect;
int index;
HDC hDc;
- if ( noNegDrawArgs < 0 ) {
- wPrefGetInteger( "msw tweak", "NoNegDrawArgs", &noNegDrawArgs, 0 );
- wPrefGetInteger( "msw tweak", "NoFlatEndCaps", &noFlatEndCaps, 0 );
- }
-
d = mswAlloc( parent, B_DRAW, NULL, sizeof *d, data, &index );
mswComputePos( (wControl_p)d, x, y );
d->w = w;
@@ -1860,9 +2006,9 @@ wDraw_p wDrawCreate(
d->option = option;
d->hWnd = CreateWindow( mswDrawWindowClassName, NULL,
- WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER,
- d->x, d->y, w, h,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER,
+ d->x, d->y, w, h,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
if (d->hWnd == (HWND)0) {
mswFail( "CreateWindow(DRAW)" );
@@ -1916,7 +2062,7 @@ wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int planes )
d->option = 0;
hDc = GetDC(mswHWnd);
- d->hDc = CreateCompatibleDC( hDc );
+ d->hDc = CreateCompatibleDC( hDc );
if ( d->hDc == (HDC)0 ) {
wNoticeEx( NT_ERROR, "CreateBitMap: CreateDC fails", "Ok", NULL );
return FALSE;
@@ -1984,57 +2130,57 @@ wBool_t wBitMapDelete( wDraw_p d )
wBool_t
wBitMapWriteFile(wDraw_p d, const char * fileName)
{
- FIBITMAP *dib = NULL;
- FIBITMAP *dib2 = NULL;
- FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
- BOOL bSuccess = FALSE;
-
- if (d->hBmMain) {
-
- BITMAP bm;
- GetObject(d->hBmMain, sizeof(BITMAP), (LPSTR)&bm);
- dib = FreeImage_Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0);
- // The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why)
- // So we save these infos below. This is needed for palettized images only.
- int nColors = FreeImage_GetColorsUsed(dib);
- HDC dc = GetDC(NULL);
- GetDIBits(dc,
- d->hBmMain,
- 0,
- FreeImage_GetHeight(dib),
- FreeImage_GetBits(dib),
- FreeImage_GetInfo(dib),
- DIB_RGB_COLORS);
- ReleaseDC(NULL, dc);
-
- // restore BITMAPINFO members
- FreeImage_GetInfoHeader(dib)->biClrUsed = nColors;
- FreeImage_GetInfoHeader(dib)->biClrImportant = nColors;
- // we will get a 32 bit bitmap on Windows systems with invalid alpha
- // so it needs to be converted to 24 bits.
- // (see: https://sourceforge.net/p/freeimage/discussion/36110/thread/0699ce8e/ )
- dib2 = FreeImage_ConvertTo24Bits(dib);
- FreeImage_Unload(dib);
- }
-
- // Try to guess the file format from the file extension
- fif = FreeImage_GetFIFFromFilename(fileName);
- if (fif != FIF_UNKNOWN) {
- // Check that the dib can be saved in this format
- BOOL bCanSave;
-
- FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib2);
- if (image_type == FIT_BITMAP) {
- // standard bitmap type
- WORD bpp = FreeImage_GetBPP(dib2);
- bCanSave = (FreeImage_FIFSupportsWriting(fif) &&
- FreeImage_FIFSupportsExportBPP(fif, bpp));
- } else {
- // special bitmap type
- bCanSave = FreeImage_FIFSupportsExportType(fif, image_type);
- }
-
- if (bCanSave) {
+ FIBITMAP *dib = NULL;
+ FIBITMAP *dib2 = NULL;
+ FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
+ BOOL bSuccess = FALSE;
+
+ if (d->hBmMain) {
+
+ BITMAP bm;
+ GetObject(d->hBmMain, sizeof(BITMAP), (LPSTR)&bm);
+ dib = FreeImage_Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0);
+ // The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why)
+ // So we save these infos below. This is needed for palettized images only.
+ int nColors = FreeImage_GetColorsUsed(dib);
+ HDC dc = GetDC(NULL);
+ GetDIBits(dc,
+ d->hBmMain,
+ 0,
+ FreeImage_GetHeight(dib),
+ FreeImage_GetBits(dib),
+ FreeImage_GetInfo(dib),
+ DIB_RGB_COLORS);
+ ReleaseDC(NULL, dc);
+
+ // restore BITMAPINFO members
+ FreeImage_GetInfoHeader(dib)->biClrUsed = nColors;
+ FreeImage_GetInfoHeader(dib)->biClrImportant = nColors;
+ // we will get a 32 bit bitmap on Windows systems with invalid alpha
+ // so it needs to be converted to 24 bits.
+ // (see: https://sourceforge.net/p/freeimage/discussion/36110/thread/0699ce8e/ )
+ dib2 = FreeImage_ConvertTo24Bits(dib);
+ FreeImage_Unload(dib);
+ }
+
+ // Try to guess the file format from the file extension
+ fif = FreeImage_GetFIFFromFilename(fileName);
+ if (fif != FIF_UNKNOWN) {
+ // Check that the dib can be saved in this format
+ BOOL bCanSave;
+
+ FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib2);
+ if (image_type == FIT_BITMAP) {
+ // standard bitmap type
+ WORD bpp = FreeImage_GetBPP(dib2);
+ bCanSave = (FreeImage_FIFSupportsWriting(fif) &&
+ FreeImage_FIFSupportsExportBPP(fif, bpp));
+ } else {
+ // special bitmap type
+ bCanSave = FreeImage_FIFSupportsExportType(fif, image_type);
+ }
+
+ if (bCanSave) {
int flags;
switch (fif) {
@@ -2047,11 +2193,11 @@ wBitMapWriteFile(wDraw_p d, const char * fileName)
default:
flags = 0; // whatver the default is for the file format
}
- bSuccess = FreeImage_Save(fif, dib2, fileName, flags);
- }
- }
- FreeImage_Unload(dib2);
+ bSuccess = FreeImage_Save(fif, dib2, fileName, flags);
+ }
+ }
+ FreeImage_Unload(dib2);
- return bSuccess;
+ return bSuccess;
}
diff --git a/app/wlib/mswlib/mswedit.c b/app/wlib/mswlib/mswedit.c
index b6da004..db7409e 100644
--- a/app/wlib/mswlib/mswedit.c
+++ b/app/wlib/mswlib/mswedit.c
@@ -1,7 +1,7 @@
/** \file mswedit.c
* Text entry widgets
*/
-
+
/* XTrackCAD - Model Railroad CAD
* Copyright (C) 2005 Dave Bullis
*
@@ -17,12 +17,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
+
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <commdlg.h>
@@ -31,29 +30,29 @@
struct wString_t {
- WOBJ_COMMON
- char * valueP;
- wIndex_t valueL;
- wStringCallBack_p action;
- wBool_t enter_pressed; /**< flag if enter was pressed */
- };
+ WOBJ_COMMON
+ char * valueP;
+ wIndex_t valueL;
+ wStringCallBack_p action;
+ wBool_t enter_pressed; /**< flag if enter was pressed */
+};
#ifdef LATER
struct wInteger_t {
- WOBJ_COMMON
- long low, high;
- long * valueP;
- long oldValue;
- wIntegerCallBack_p action;
- };
+ WOBJ_COMMON
+ long low, high;
+ long * valueP;
+ long oldValue;
+ wIntegerCallBack_p action;
+};
struct wFloat_t {
- WOBJ_COMMON
- double low, high;
- double * valueP;
- double oldValue;
- wFloatCallBack_p action;
- };
+ WOBJ_COMMON
+ double low, high;
+ double * valueP;
+ double oldValue;
+ wFloatCallBack_p action;
+};
#endif // LATER
@@ -67,33 +66,32 @@ static void triggerFloat( wControl_p b );
LRESULT FAR PASCAL _export pushEdit(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wString_p b = (wString_p)mswMapIndex(inx);
- switch (message)
- {
+ switch (message) {
case WM_CHAR:
- if (b != NULL) {
- switch (wParam) {
- case VK_RETURN:
- triggerString(b);
- return (LRESULT)0;
- break;
- case 0x1B:
- case 0x09:
- SetFocus(((wControl_p)(b->parent))->hWnd);
- SendMessage(((wControl_p)(b->parent))->hWnd, WM_CHAR,
- wParam, lParam);
- return (LRESULT)0;
- }
- }
- break;
+ if (b != NULL) {
+ switch (wParam) {
+ case VK_RETURN:
+ triggerString(b);
+ return (LRESULT)0;
+ break;
+ case 0x1B:
+ case 0x09:
+ SetFocus(((wControl_p)(b->parent))->hWnd);
+ SendMessage(((wControl_p)(b->parent))->hWnd, WM_CHAR,
+ wParam, lParam);
+ return (LRESULT)0;
+ }
+ }
+ break;
}
return CallWindowProc(oldEditProc, hWnd, message, wParam, lParam);
@@ -109,8 +107,8 @@ LRESULT FAR PASCAL _export pushEdit(
void wStringSetValue(
- wString_p b,
- const char * arg )
+ wString_p b,
+ const char * arg )
{
WORD len = (WORD)strlen( arg );
SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)arg );
@@ -121,18 +119,18 @@ void wStringSetValue(
void wStringSetWidth(
- wString_p b,
- wWinPix_t w )
+ wString_p b,
+ wWinPix_t w )
{
int rc;
b->w = w;
rc = SetWindowPos( b->hWnd, HWND_TOP, 0, 0,
- b->w, b->h, SWP_NOMOVE|SWP_NOZORDER );
+ b->w, b->h, SWP_NOMOVE|SWP_NOZORDER );
}
const char * wStringGetValue(
- wString_p b )
+ wString_p b )
{
static char buff[1024];
SendMessage( b->hWnd, WM_GETTEXT, (WPARAM)sizeof buff, (LPARAM)buff );
@@ -141,29 +139,29 @@ const char * wStringGetValue(
/**
* Get the string from a entry field. The returned pointer has to be free() after processing is complete.
- *
+ *
* \param bs IN string entry field
- *
+ *
* \return pointer to entered string or NULL if entry field is empty.
*/
static char *getString(wString_p bs)
{
- char *tmpBuffer = NULL;
- UINT chars = (UINT)SendMessage(bs->hWnd, EM_LINELENGTH, (WPARAM)0, (LPARAM)0);
-
- if (chars) {
- tmpBuffer = malloc(chars > sizeof(WORD)? chars + 1 : sizeof(WORD) + 1);
- *(WORD *)tmpBuffer = chars;
- SendMessage(bs->hWnd, (UINT)EM_GETLINE, (WPARAM)0, (LPARAM)tmpBuffer);
- tmpBuffer[chars] = '\0';
- } else {
- tmpBuffer = malloc(2);
- tmpBuffer[0] = '\n';
- tmpBuffer[1] = '\0';
- }
-
- return (tmpBuffer);
+ char *tmpBuffer = NULL;
+ UINT chars = (UINT)SendMessage(bs->hWnd, EM_LINELENGTH, (WPARAM)0, (LPARAM)0);
+
+ if (chars) {
+ tmpBuffer = malloc(chars > sizeof(WORD)? chars + 1 : sizeof(WORD) + 1);
+ *(WORD *)tmpBuffer = chars;
+ SendMessage(bs->hWnd, (UINT)EM_GETLINE, (WPARAM)0, (LPARAM)tmpBuffer);
+ tmpBuffer[chars] = '\0';
+ } else {
+ tmpBuffer = malloc(2);
+ tmpBuffer[0] = '\n';
+ tmpBuffer[1] = '\0';
+ }
+
+ return (tmpBuffer);
}
/**
@@ -174,20 +172,19 @@ static char *getString(wString_p bs)
*/
static void triggerString(
- wString_p b)
+ wString_p b)
{
const char *output = "\n";
- char *enteredString = getString(b);
- if (enteredString)
- {
- if (b->valueP) {
- strcpy(b->valueP, enteredString);
- }
+ char *enteredString = getString(b);
+ if (enteredString) {
+ if (b->valueP) {
+ strcpy(b->valueP, enteredString);
+ }
if (b->action) {
b->enter_pressed = TRUE;
b->action(output, b->data);
- }
+ }
free(enteredString);
}
@@ -195,84 +192,87 @@ static void triggerString(
LRESULT stringProc(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam)
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam)
{
- wString_p bs = (wString_p)b;
- int modified;
-
- switch (message) {
-
- case WM_COMMAND:
- switch (WCMD_PARAM_NOTF) {
- case EN_KILLFOCUS:
- modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, (WPARAM)0, (LPARAM)0);
- if (!modified) {
- break;
- }
-
- char *enteredString = getString(bs);
- if (enteredString) {
- if (bs->valueP) {
- strcpy(bs->valueP, enteredString);
- }
- if (bs->action) {
- bs->action(enteredString, bs->data);
- mswSetTrigger(NULL, NULL);
- }
- free(enteredString);
- }
- SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0);
- }
- break;
- }
-
- return DefWindowProc(hWnd, message, wParam, lParam);
+ wString_p bs = (wString_p)b;
+ int modified;
+
+ switch (message) {
+
+ case WM_COMMAND:
+ switch (WCMD_PARAM_NOTF) {
+ case EN_KILLFOCUS:
+ modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, (WPARAM)0, (LPARAM)0);
+ if (!modified) {
+ break;
+ }
+
+ char *enteredString = getString(bs);
+ if (enteredString) {
+ if (bs->valueP) {
+ strcpy(bs->valueP, enteredString);
+ }
+ if (bs->action) {
+ bs->action(enteredString, bs->data);
+ mswSetTrigger(NULL, NULL);
+ }
+ free(enteredString);
+ }
+ SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0);
+ }
+ break;
+ }
+
+ return DefWindowProc(hWnd, message, wParam, lParam);
}
static callBacks_t stringCallBacks = {
- mswRepaintLabel,
- NULL,
- stringProc };
+ mswRepaintLabel,
+ NULL,
+ stringProc
+};
wString_p wStringCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- char *valueP,
- wIndex_t valueL,
- wStringCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ char *valueP,
+ wIndex_t valueL,
+ wStringCallBack_p action,
+ void *data )
{
wString_p b;
RECT rect;
int index;
DWORD style = 0;
- b = (wString_p)mswAlloc( parent, B_STRING, mswStrdup(labelStr), sizeof *b, data, &index );
+ b = (wString_p)mswAlloc( parent, B_STRING, mswStrdup(labelStr), sizeof *b, data,
+ &index );
mswComputePos( (wControl_p)b, x, y );
b->option = option;
b->valueP = valueP;
b->valueL = valueL;
b->labelY += 2;
b->action = action;
- if (option & BO_READONLY)
+ if (option & BO_READONLY) {
style |= ES_READONLY;
+ }
b->hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL,
- ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
- b->x, b->y,
- width, mswEditHeight,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
+ b->x, b->y,
+ width, mswEditHeight,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
if (b->hWnd == NULL) {
mswFail("CreateWindow(STRING)");
return b;
@@ -290,8 +290,8 @@ wString_p wStringCreate(
SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)b->valueP );
}
SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 );
- if ( !mswThickFont )
- SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
+ SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
+
GetWindowRect( b->hWnd, &rect );
b->w = rect.right - rect.left;
b->h = rect.bottom - rect.top;
@@ -317,8 +317,8 @@ wString_p wStringCreate(
void wIntegerSetValue(
- wInteger_p b,
- long arg )
+ wInteger_p b,
+ long arg )
{
b->oldValue = arg;
wsprintf( mswTmpBuff, "%ld", arg );
@@ -328,14 +328,14 @@ void wIntegerSetValue(
long wIntegerGetValue(
- wInteger_p b )
+ wInteger_p b )
{
return b->oldValue;
}
static void triggerInteger(
- wControl_p b )
+ wControl_p b )
{
wInteger_p bi = (wInteger_p)b;
int cnt;
@@ -344,17 +344,22 @@ static void triggerInteger(
if (bi->action) {
*(WPARAM*)&mswTmpBuff[0] = 78;
- cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0, (DWORD)(LPSTR)mswTmpBuff );
+ cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0,
+ (DWORD)(LPSTR)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
- if (strcmp( mswTmpBuff, "-" )==0 )
+ if (strcmp( mswTmpBuff, "-" )==0 ) {
return;
+ }
value = strtol( mswTmpBuff, &cp, 10 );
- if (*cp != '\0' || value < bi->low || value > bi->high )
+ if (*cp != '\0' || value < bi->low || value > bi->high ) {
return;
- if (bi->oldValue == value)
+ }
+ if (bi->oldValue == value) {
return;
- if (bi->valueP)
+ }
+ if (bi->valueP) {
*bi->valueP = value;
+ }
bi->oldValue = value;
bi->action( value, bi->data );
}
@@ -362,31 +367,33 @@ static void triggerInteger(
LRESULT integerProc(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
-{
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
+{
wInteger_p bi = (wInteger_p)b;
int inx;
int cnt;
long value;
- char * cp;
+ char * cp;
wBool_t ok;
int modified;
-
+
switch( message ) {
-
+
case WM_COMMAND:
switch (WCMD_PARAM_NOTF) {
case EN_KILLFOCUS:
ok = TRUE;
modified = (int)SendMessage( bi->hWnd, (UINT)EM_GETMODIFY, 0, 0L );
- if (!modified)
+ if (!modified) {
break;
+ }
*(WPARAM*)&mswTmpBuff[0] = 78;
- cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0, (DWORD)(LPSTR)mswTmpBuff );
+ cnt = (int)SendMessage( bi->hWnd, (UINT)EM_GETLINE, 0,
+ (DWORD)(LPSTR)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
if (strcmp( mswTmpBuff, "-" )==0 && 0 >= bi->low && 0 <= bi->high ) {
value = 0;
@@ -395,23 +402,25 @@ LRESULT integerProc(
if (*cp != '\0' || value < bi->low || value > bi->high ) {
inx = GetWindowWord( bi->hWnd, GWW_ID );
if (wWinIsVisible(bi->parent)) {
- PostMessage( ((wControl_p)(bi->parent))->hWnd,
- WM_NOTVALID, inx, 0L );
+ PostMessage( ((wControl_p)(bi->parent))->hWnd,
+ WM_NOTVALID, inx, 0L );
return TRUE;
} else {
- if (value < bi->low)
+ if (value < bi->low) {
value = bi->low;
- else
+ } else {
value = bi->high;
+ }
sprintf( mswTmpBuff, "%ld", value );
SendMessage( bi->hWnd, (UINT)WM_SETTEXT, 0,
- (DWORD)(LPSTR)mswTmpBuff );
+ (DWORD)(LPSTR)mswTmpBuff );
}
}
}
bi->oldValue = value;
- if (bi->valueP)
+ if (bi->valueP) {
*bi->valueP = value;
+ }
if (bi->action) {
bi->action( value, bi->data );
mswSetTrigger( NULL, NULL );
@@ -422,21 +431,22 @@ LRESULT integerProc(
case WM_NOTVALID:
wsprintf( mswTmpBuff, "Please enter a value between %ld and %ld",
- bi->low, bi->high );
+ bi->low, bi->high );
if (bi->low > MININT && bi->high < MAXINT)
sprintf( mswTmpBuff,
- "Please enter an integer value between %ld and %ld",
- bi->low, bi->high );
+ "Please enter an integer value between %ld and %ld",
+ bi->low, bi->high );
else if (bi->low > MININT)
sprintf( mswTmpBuff,
- "Please enter an integer value greater or equal to %ld",
- bi->low );
+ "Please enter an integer value greater or equal to %ld",
+ bi->low );
else if (bi->high < MAXINT)
sprintf( mswTmpBuff,
- "Please enter an integer value less or equal to %ld",
- bi->high );
- else
+ "Please enter an integer value less or equal to %ld",
+ bi->high );
+ else {
strcpy( mswTmpBuff, "Please enter an integer value" );
+ }
MessageBox( bi->hWnd, mswTmpBuff, "Invalid entry", MB_OK );
SetFocus( bi->hWnd );
#ifdef WIN32
@@ -447,31 +457,32 @@ LRESULT integerProc(
#endif
return TRUE;
- }
-
+ }
+
return DefWindowProc( hWnd, message, wParam, lParam );
-}
+}
static callBacks_t integerCallBacks = {
- mswRepaintLabel,
- NULL,
- integerProc };
+ mswRepaintLabel,
+ NULL,
+ integerProc
+};
wInteger_p wIntegerCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- long low,
- long high,
- long *valueP,
- wIntegerCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ long low,
+ long high,
+ long *valueP,
+ wIntegerCallBack_p action,
+ void *data )
{
wInteger_p b;
RECT rect;
@@ -486,32 +497,35 @@ wInteger_p wIntegerCreate(
b->valueP = valueP;
b->labelY += 2;
b->action = action;
- if (option & BO_READONLY)
+ if (option & BO_READONLY) {
style |= ES_READONLY;
+ }
b->hWnd = CreateWindow( "EDIT", NULL,
- ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
- b->x, b->y,
- width, mswEditHeight,
- ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
+ ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
+ b->x, b->y,
+ width, mswEditHeight,
+ ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
if (b->hWnd == NULL) {
mswFail("CreateWindow(INTEGER)");
return b;
}
-
+
newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst );
oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC );
SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc );
- if ( !mswThickFont )
+ if ( !mswThickFont ) {
SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
+ }
if (b->valueP) {
wsprintf( mswTmpBuff, "%ld", *b->valueP );
SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)(LPSTR)mswTmpBuff );
b->oldValue = *b->valueP;
- } else
+ } else {
b->oldValue = 0;
+ }
SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L );
GetWindowRect( b->hWnd, &rect );
@@ -539,8 +553,8 @@ wInteger_p wIntegerCreate(
void wFloatSetValue(
- wFloat_p b,
- double arg )
+ wFloat_p b,
+ double arg )
{
b->oldValue = arg;
sprintf( mswTmpBuff, "%0.3f", arg );
@@ -550,67 +564,72 @@ void wFloatSetValue(
double wFloatGetValue(
- wFloat_p b )
+ wFloat_p b )
{
return b->oldValue;
}
static void triggerFloat(
- wControl_p b )
+ wControl_p b )
{
wFloat_p bf = (wFloat_p)b;
int cnt;
double value;
- char * cp;
+ char * cp;
if (bf->action) {
*(WPARAM*)&mswTmpBuff[0] = 78;
cnt = (int)SendMessage( bf->hWnd, (UINT)EM_GETLINE, 0,
- (DWORD)(LPSTR)mswTmpBuff );
+ (DWORD)(LPSTR)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
- if (strcmp( mswTmpBuff, "-" )==0)
+ if (strcmp( mswTmpBuff, "-" )==0) {
return;
+ }
value = strtod( mswTmpBuff, &cp );
- if (*cp != '\0' || value < bf->low || value > bf->high )
+ if (*cp != '\0' || value < bf->low || value > bf->high ) {
return;
- if (bf->oldValue == value)
+ }
+ if (bf->oldValue == value) {
return;
+ }
bf->oldValue = value;
- if (bf->valueP)
- *bf->valueP = value;
+ if (bf->valueP) {
+ *bf->valueP = value;
+ }
bf->action( wFloatGetValue(bf), bf->data );
}
}
LRESULT floatProc(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
-{
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
+{
wFloat_p bf = (wFloat_p)b;
int inx;
int cnt;
double value;
- char * cp;
+ char * cp;
wBool_t ok;
int modified;
switch( message ) {
-
+
case WM_COMMAND:
switch (HIWORD(lParam)) {
case EN_KILLFOCUS:
ok = TRUE;
modified = (int)SendMessage( bf->hWnd, (UINT)EM_GETMODIFY, 0, 0L );
- if (!modified)
+ if (!modified) {
break;
+ }
*(WPARAM*)&mswTmpBuff[0] = 78;
cnt = (int)SendMessage( bf->hWnd, (UINT)EM_GETLINE, 0,
- (DWORD)(LPSTR)mswTmpBuff );
+ (DWORD)(LPSTR)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
if (strcmp( mswTmpBuff, "-" )==0 && 0 >= bf->low && 0 <= bf->high ) {
value = 0;
@@ -619,23 +638,25 @@ LRESULT floatProc(
if (*cp != '\0' || value < bf->low || value > bf->high ) {
inx = GetWindowWord( bf->hWnd, GWW_ID );
if (wWinIsVisible(bf->parent)) {
- PostMessage( ((wControl_p)(bf->parent))->hWnd,
- WM_NOTVALID, inx, 0L );
+ PostMessage( ((wControl_p)(bf->parent))->hWnd,
+ WM_NOTVALID, inx, 0L );
return TRUE;
} else {
- if (value < bf->low)
+ if (value < bf->low) {
value = bf->low;
- else
+ } else {
value = bf->high;
+ }
sprintf( mswTmpBuff, "%0.3f", value );
SendMessage( bf->hWnd, (UINT)WM_SETTEXT, 0,
- (DWORD)(LPSTR)mswTmpBuff );
+ (DWORD)(LPSTR)mswTmpBuff );
}
}
}
bf->oldValue = value;
- if (bf->valueP)
+ if (bf->valueP) {
*bf->valueP = value;
+ }
if (bf->action) {
bf->action( value, bf->data );
mswSetTrigger( NULL, NULL );
@@ -647,18 +668,19 @@ LRESULT floatProc(
case WM_NOTVALID:
if (bf->low > MINFLT && bf->high < MAXFLT)
sprintf( mswTmpBuff,
- "Please enter an float value between %0.3f and %0.3f",
- bf->low, bf->high );
+ "Please enter an float value between %0.3f and %0.3f",
+ bf->low, bf->high );
else if (bf->low > MINFLT)
sprintf( mswTmpBuff,
- "Please enter an float value greater or equal to %0.3f",
- bf->low );
+ "Please enter an float value greater or equal to %0.3f",
+ bf->low );
else if (bf->high < MAXFLT)
sprintf( mswTmpBuff,
- "Please enter an float value less or equal to %0.3f",
- bf->high );
- else
+ "Please enter an float value less or equal to %0.3f",
+ bf->high );
+ else {
strcpy( mswTmpBuff, "Please enter an float value" );
+ }
MessageBox( bf->hWnd, mswTmpBuff, "Invalid entry", MB_OK );
SetFocus( bf->hWnd );
#ifdef WIN32
@@ -669,30 +691,31 @@ LRESULT floatProc(
#endif
return TRUE;
- }
+ }
return DefWindowProc( hWnd, message, wParam, lParam );
-}
+}
static callBacks_t floatCallBacks = {
- mswRepaintLabel,
- NULL,
- floatProc };
+ mswRepaintLabel,
+ NULL,
+ floatProc
+};
wFloat_p wFloatCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- double low,
- double high,
- double *valueP,
- wFloatCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ double low,
+ double high,
+ double *valueP,
+ wFloatCallBack_p action,
+ void *data )
{
wFloat_p b;
RECT rect;
@@ -707,34 +730,38 @@ wFloat_p wFloatCreate(
b->valueP = valueP;
b->labelY += 2;
b->action = action;
- if (option & BO_READONLY)
+ if (option & BO_READONLY) {
style |= ES_READONLY;
+ }
b->hWnd = CreateWindow( "EDIT", NULL,
- ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
- b->x, b->y,
- width, mswEditHeight,
- ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
+ ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style,
+ b->x, b->y,
+ width, mswEditHeight,
+ ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
if (b->hWnd == NULL) {
mswFail("CreateWindow(FLOAT)");
return b;
}
-
+
newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst );
oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC );
SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc );
if (b->valueP) {
- b->oldValue = *b->valueP;
- } else
- b->oldValue = 0.0;
- if (b->valueP)
- sprintf( mswTmpBuff, "%0.3f", *b->valueP );
- else
- strcpy( mswTmpBuff, "0.000" );
- if ( !mswThickFont )
+ b->oldValue = *b->valueP;
+ } else {
+ b->oldValue = 0.0;
+ }
+ if (b->valueP) {
+ sprintf( mswTmpBuff, "%0.3f", *b->valueP );
+ } else {
+ strcpy( mswTmpBuff, "0.000" );
+ }
+ if ( !mswThickFont ) {
SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L );
+ }
SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)(LPSTR)mswTmpBuff );
SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L );
diff --git a/app/wlib/mswlib/mswint.h b/app/wlib/mswlib/mswint.h
index 5fd5da9..525a37c 100644
--- a/app/wlib/mswlib/mswint.h
+++ b/app/wlib/mswlib/mswint.h
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "wlib.h"
@@ -173,9 +173,7 @@ extern HFONT mswOldTextFont;
extern HFONT mswLabelFont;
extern wDrawColor wDrawColorWhite;
extern wDrawColor wDrawColorBlack;
-extern long mswThickFont;
extern double mswScale;
-extern double scaleIcon;
DWORD mswGetBaseStyle( wWin_p );
char * mswStrdup( const char * );
diff --git a/app/wlib/mswlib/mswlines.c b/app/wlib/mswlib/mswlines.c
index f6bb574..a55618e 100644
--- a/app/wlib/mswlib/mswlines.c
+++ b/app/wlib/mswlib/mswlines.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -15,10 +14,10 @@
*/
struct wLine_t {
- WOBJ_COMMON
- int count;
- wLines_t * lines;
- };
+ WOBJ_COMMON
+ int count;
+ wLines_t * lines;
+};
static void repaintLines( HWND hWnd, wControl_p b )
{
@@ -45,24 +44,26 @@ static void repaintLines( HWND hWnd, wControl_p b )
static callBacks_t linesCallBacks = {
- repaintLines,
- NULL,
- NULL };
+ repaintLines,
+ NULL,
+ NULL
+};
wLine_p wLineCreate(
- wWin_p parent,
- const char * labelStr,
- int count,
- wLines_t * lines )
+ wWin_p parent,
+ const char * labelStr,
+ int count,
+ wLines_t * lines )
{
wLine_p b;
wLines_p lp;
wWinPix_t minX, maxX, minY, maxY;
int index;
- if (count <= 0)
+ if (count <= 0) {
return NULL;
+ }
b = (wLine_p)mswAlloc( parent, B_LINES, labelStr, sizeof *b, NULL, &index );
b->count = count;
b->lines = lines;
@@ -71,22 +72,30 @@ wLine_p wLineCreate(
minX = maxX = lp->x0;
minY = maxY = lp->y0;
for (lp=lines; lp<&b->lines[count]; lp++) {
- if (minX > lp->x0)
+ if (minX > lp->x0) {
minX = lp->x0;
- if (maxX < lp->x0)
+ }
+ if (maxX < lp->x0) {
maxX = lp->x0;
- if (minY > lp->y0)
+ }
+ if (minY > lp->y0) {
minY = lp->y0;
- if (maxY < lp->y0)
+ }
+ if (maxY < lp->y0) {
maxY = lp->y0;
- if (minX > lp->x1)
+ }
+ if (minX > lp->x1) {
minX = lp->x1;
- if (maxX < lp->x1)
+ }
+ if (maxX < lp->x1) {
maxX = lp->x1;
- if (minY > lp->y1)
+ }
+ if (minY > lp->y1) {
minY = lp->y1;
- if (maxY < lp->y1)
+ }
+ if (maxY < lp->y1) {
maxY = lp->y1;
+ }
}
b->x = minX;
b->y = minY;
diff --git a/app/wlib/mswlib/mswlist.c b/app/wlib/mswlib/mswlist.c
index 836f4f0..c955c25 100644
--- a/app/wlib/mswlib/mswlist.c
+++ b/app/wlib/mswlib/mswlist.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -20,44 +19,45 @@ static XWNDPROC oldComboProc = NULL;
static XWNDPROC newComboProc;
struct wList_t {
- WOBJ_COMMON
- int count;
- int last;
- long * valueP;
- wListCallBack_p action;
- wBool_t editable;
- int colCnt;
- wWinPix_t * colWidths;
- wBool_t * colRightJust;
- const char * * colTitles;
- wWinPix_t maxWidth;
- wWinPix_t scrollPos;
- HWND hScrollWnd;
- wWinPix_t scrollH;
- wWinPix_t dragPos;
- int dragCol;
- wWinPix_t dragColWidth;
- };
+ WOBJ_COMMON
+ int count;
+ int last;
+ long * valueP;
+ wListCallBack_p action;
+ wBool_t editable;
+ int colCnt;
+ wWinPix_t * colWidths;
+ wBool_t * colRightJust;
+ const char * * colTitles;
+ wWinPix_t maxWidth;
+ wWinPix_t scrollPos;
+ HWND hScrollWnd;
+ wWinPix_t scrollH;
+ wWinPix_t dragPos;
+ int dragCol;
+ wWinPix_t dragColWidth;
+};
typedef struct {
- void * itemContext;
- wIcon_p bm;
- wBool_t selected;
- } listData;
+ void * itemContext;
+ wIcon_p bm;
+ wBool_t selected;
+} listData;
static int LIST_HEIGHT = 19;
static int listTitleHeight = 16;
void wListClear(
- wList_p b )
+ wList_p b )
{
UINT msg;
- if (b->type==B_LIST)
+ if (b->type==B_LIST) {
msg = LB_RESETCONTENT;
- else
+ } else {
msg = CB_RESETCONTENT;
+ }
SendMessage( b->hWnd, msg, (WPARAM)0, (LPARAM)0 );
b->last = -1;
b->count = 0;
@@ -73,20 +73,21 @@ void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h )
bl->w = w;
bl->h = h;
- y = bl->y;
- if ( bl->hScrollWnd && bl->maxWidth > bl->w )
+ y = bl->y;
+ if ( bl->hScrollWnd && bl->maxWidth > bl->w ) {
h -= bl->scrollH;
+ }
if ( bl->colTitles ) {
h -= listTitleHeight;
y += listTitleHeight;
}
rc = SetWindowPos( bl->hWnd, HWND_TOP, 0, 0,
- w, h, SWP_NOMOVE|SWP_NOZORDER);
+ w, h, SWP_NOMOVE|SWP_NOZORDER);
if ( bl->hScrollWnd ) {
if ( bl->maxWidth > bl->w ) {
GetClientRect( bl->hWnd, &rect );
rc = SetWindowPos( bl->hScrollWnd, HWND_TOP, bl->x, y+rect.bottom+2,
- bl->w, bl->scrollH, SWP_NOZORDER);
+ bl->w, bl->scrollH, SWP_NOZORDER);
ShowWindow( bl->hScrollWnd, SW_SHOW );
} else {
ShowWindow( bl->hScrollWnd, SW_HIDE );
@@ -97,71 +98,77 @@ void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h )
void wListSetIndex(
- wList_p bl,
- int index )
+ wList_p bl,
+ int index )
{
listData * ldp;
wListGetCount(bl);
- if ( index >= bl->count )
+ if ( index >= bl->count ) {
index = bl->count-1;
- if ( bl->last == index && index == -1 )
+ }
+ if ( bl->last == index && index == -1 ) {
return;
+ }
if ( bl->type==B_LIST && (bl->option&BL_MANY) != 0 ) {
- if ( bl->last != -1 )
+ if ( bl->last != -1 ) {
SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)0, (LPARAM)bl->last );
- if ( index >= 0 )
+ }
+ if ( index >= 0 ) {
SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)1, (LPARAM)index );
+ }
} else {
SendMessage( bl->hWnd,
- bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)index, (LPARAM)0 );
+ bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)index, (LPARAM)0 );
}
if ( bl->last >= 0 ) {
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)bl->last, (LPARAM)0 );
- if ( ldp && ldp!=(void*)LB_ERR )
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)bl->last, (LPARAM)0 );
+ if ( ldp && ldp!=(void*)LB_ERR ) {
ldp->selected = FALSE;
+ }
}
if ( index >= 0 ) {
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)index, (LPARAM)0 );
- if ( ldp && ldp!=(void*)LB_ERR )
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)index, (LPARAM)0 );
+ if ( ldp && ldp!=(void*)LB_ERR ) {
ldp->selected = TRUE;
+ }
}
/*if (b->option&BL_ICON)*/
- InvalidateRect( bl->hWnd, NULL, FALSE );
+ InvalidateRect( bl->hWnd, NULL, FALSE );
bl->last = index;
}
wIndex_t wListGetIndex(
- wList_p b )
+ wList_p b )
{
return b->last;
}
void wListSetActive(
- wList_p b,
- int inx,
- wBool_t active )
+ wList_p b,
+ int inx,
+ wBool_t active )
{
}
void wListSetEditable(
- wList_p b,
- wBool_t editable )
+ wList_p b,
+ wBool_t editable )
{
b->editable = editable;
}
void wListSetValue(
- wList_p bl,
- const char * val )
+ wList_p bl,
+ const char * val )
{
if ( bl->type == B_DROPLIST ) {
SendMessage( bl->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)val );
@@ -171,30 +178,31 @@ void wListSetValue(
wIndex_t wListFindValue(
- wList_p bl,
- const char * val )
+ wList_p bl,
+ const char * val )
{
wIndex_t inx;
WORD cnt;
wListGetCount(bl);
for ( inx = 0; inx < bl->count ; inx++ ) {
cnt = (int)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), (WPARAM)inx,
- (LPARAM)mswTmpBuff );
+ (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), (WPARAM)inx,
+ (LPARAM)mswTmpBuff );
mswTmpBuff[cnt] = '\0';
- if ( strcmp( val, mswTmpBuff ) == 0 )
+ if ( strcmp( val, mswTmpBuff ) == 0 ) {
return inx;
+ }
}
return -1;
}
wIndex_t wListGetValues(
- wList_p bl,
- char * s,
- int siz,
- void * * listContextRef,
- void * * itemContextRef )
+ wList_p bl,
+ char * s,
+ int siz,
+ void * * listContextRef,
+ void * * itemContextRef )
{
WORD cnt;
WORD msg;
@@ -204,8 +212,9 @@ wIndex_t wListGetValues(
msg = WM_GETTEXT;
inx = sizeof mswTmpBuff;
} else {
- if ( bl->last < 0 )
+ if ( bl->last < 0 ) {
goto EMPTY;
+ }
if ( bl->type==B_LIST ) {
msg = LB_GETTEXT;
} else {
@@ -220,29 +229,32 @@ wIndex_t wListGetValues(
}
if (bl->last >= 0) {
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)bl->last, (LPARAM)0 );
- if ( ldp==(listData*)LB_ERR )
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)bl->last, (LPARAM)0 );
+ if ( ldp==(listData*)LB_ERR ) {
ldp = NULL;
+ }
} else {
ldp = NULL;
}
EMPTY:
- if (itemContextRef)
+ if (itemContextRef) {
*itemContextRef = (ldp?ldp->itemContext:NULL);
- if (listContextRef)
+ }
+ if (listContextRef) {
*listContextRef = bl->data;
+ }
return bl->last;
}
wBool_t wListSetValues(
- wList_p b,
- wIndex_t inx,
- const char * labelStr,
- wIcon_p bm,
- void * itemData )
+ wList_p b,
+ wIndex_t inx,
+ const char * labelStr,
+ wIcon_p bm,
+ void * itemData )
{
- listData * ldp;
+ listData * ldp;
WORD curSel = -1;
ldp = (listData*)malloc( sizeof *ldp );
ldp->itemContext = itemData;
@@ -250,40 +262,40 @@ wBool_t wListSetValues(
ldp->selected = FALSE;
if ( (b->option&BL_MANY) == 0 )
curSel = (WORD)SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_GETCURSEL:CB_GETCURSEL,
- (WPARAM)0,
- (LPARAM)0 );
+ (UINT)b->type==B_LIST?LB_GETCURSEL:CB_GETCURSEL,
+ (WPARAM)0,
+ (LPARAM)0 );
SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING,
- (WPARAM)inx,
- (LPARAM)0 );
+ (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING,
+ (WPARAM)inx,
+ (LPARAM)0 );
inx = (wIndex_t)SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_INSERTSTRING:CB_INSERTSTRING,
- (WPARAM)inx,
- (LPARAM)labelStr );
+ (UINT)b->type==B_LIST?LB_INSERTSTRING:CB_INSERTSTRING,
+ (WPARAM)inx,
+ (LPARAM)labelStr );
SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
- (WPARAM)inx,
- (LPARAM)ldp );
+ (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
+ (WPARAM)inx,
+ (LPARAM)ldp );
if ( (b->option&BL_MANY) == 0 && curSel == (WORD)inx)
- SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL,
- (WPARAM)inx,
- (LPARAM)0 );
+ SendMessage( b->hWnd,
+ (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL,
+ (WPARAM)inx,
+ (LPARAM)0 );
/*if (b->option&BL_ICON)*/
- InvalidateRect( b->hWnd, NULL, FALSE );
+ InvalidateRect( b->hWnd, NULL, FALSE );
return TRUE;
}
void wListDelete(
- wList_p b,
- wIndex_t inx )
+ wList_p b,
+ wIndex_t inx )
{
SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING,
- (WPARAM)inx,
- (LPARAM)0 );
+ (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING,
+ (WPARAM)inx,
+ (LPARAM)0 );
}
@@ -301,69 +313,71 @@ void wListSelectAll( wList_p bl )
// mark all items selected
SendMessage( bl->hWnd,
- LB_SETSEL,
- (WPARAM)TRUE,
- (LPARAM)-1 );
+ LB_SETSEL,
+ (WPARAM)TRUE,
+ (LPARAM)-1 );
- // and synchronize the internal data structures
+ // and synchronize the internal data structures
wListGetCount(bl);
for ( inx=0; inx<bl->count; inx++ ) {
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)inx, (LPARAM)0 );
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)inx, (LPARAM)0 );
ldp->selected = TRUE;
SendMessage( bl->hWnd,
- (UINT)bl->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
- (WPARAM)inx,
- (LPARAM)ldp );
+ (UINT)bl->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
+ (WPARAM)inx,
+ (LPARAM)ldp );
}
}
wIndex_t wListGetCount(
- wList_p bl )
-{
- bl->count = (int)SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, (WPARAM)0, (LPARAM)0 );
+ wList_p bl )
+{
+ bl->count = (int)SendMessage( bl->hWnd,
+ (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, (WPARAM)0, (LPARAM)0 );
return bl->count;
}
void * wListGetItemContext(
- wList_p bl,
- wIndex_t inx )
+ wList_p bl,
+ wIndex_t inx )
{
listData * ldp;
wListGetCount(bl);
- if ( inx < 0 || inx >= bl->count ) return NULL;
+ if ( inx < 0 || inx >= bl->count ) { return NULL; }
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)inx, (LPARAM)0 );
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)inx, (LPARAM)0 );
return ((ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL);
}
wBool_t wListGetItemSelected(
- wList_p bl,
- wIndex_t inx )
+ wList_p bl,
+ wIndex_t inx )
{
listData * ldp;
wListGetCount(bl);
- if ( inx < 0 || inx >= bl->count ) return FALSE;
+ if ( inx < 0 || inx >= bl->count ) { return FALSE; }
ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)inx, (LPARAM)0 );
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)inx, (LPARAM)0 );
return ((ldp&&ldp!=(void*)LB_ERR)?ldp->selected:FALSE);
}
wIndex_t wListGetSelectedCount(
- wList_p bl )
+ wList_p bl )
{
wIndex_t selcnt, inx;
wListGetCount(bl);
for ( selcnt=inx=0; inx<bl->count; inx++ )
- if ( wListGetItemSelected( bl, inx ) )
+ if ( wListGetItemSelected( bl, inx ) ) {
selcnt++;
+ }
return selcnt;
}
@@ -371,10 +385,10 @@ wIndex_t wListGetSelectedCount(
wIndex_t wListAddValue(
- wList_p b,
- const char * value,
- wIcon_p bm,
- void * itemContext )
+ wList_p b,
+ const char * value,
+ wIcon_p bm,
+ void * itemContext )
{
int nindex;
listData * ldp;
@@ -382,106 +396,116 @@ wIndex_t wListAddValue(
ldp->itemContext = itemContext;
ldp->bm = bm;
ldp->selected = FALSE;
- if ( value == NULL )
+ if ( value == NULL ) {
value = "";
+ }
b->count++;
nindex = (int)SendMessage(
- b->hWnd,
- (UINT)b->type==B_LIST?LB_ADDSTRING:CB_ADDSTRING,
- (WPARAM)0,
- (LPARAM)value );
+ b->hWnd,
+ (UINT)b->type==B_LIST?LB_ADDSTRING:CB_ADDSTRING,
+ (WPARAM)0,
+ (LPARAM)value );
if (nindex == 0) {
SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL,
- (WPARAM)nindex,
- (LPARAM)0 );
+ (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL,
+ (WPARAM)nindex,
+ (LPARAM)0 );
b->last = 0;
}
SendMessage( b->hWnd,
- (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
- (WPARAM)nindex,
- (LPARAM)ldp );
+ (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA,
+ (WPARAM)nindex,
+ (LPARAM)ldp );
return nindex;
}
int wListGetColumnWidths(
- wList_p bl,
- int colCnt,
- wWinPix_t * colWidths )
+ wList_p bl,
+ int colCnt,
+ wWinPix_t * colWidths )
{
wIndex_t inx;
- if ( bl->type != B_LIST )
+ if ( bl->type != B_LIST ) {
return 0;
- if ( bl->colWidths == NULL )
+ }
+ if ( bl->colWidths == NULL ) {
return 0;
+ }
for ( inx=0; inx<colCnt; inx++ ) {
- if ( inx < bl->colCnt )
+ if ( inx < bl->colCnt ) {
colWidths[inx] = bl->colWidths[inx];
- else
+ } else {
colWidths[inx] = 0;
+ }
}
return bl->colCnt;
}
static void listSetBusy(
- wControl_p b,
- BOOL_T busy)
+ wControl_p b,
+ BOOL_T busy)
{
wList_p bl = (wList_p)b;
EnableWindow( bl->hWnd, !(BOOL)busy );
- if ( bl->hScrollWnd )
+ if ( bl->hScrollWnd ) {
EnableWindow( bl->hScrollWnd, !(BOOL)busy );
+ }
}
static void listShow(
- wControl_p b,
- BOOL_T show)
+ wControl_p b,
+ BOOL_T show)
{
wList_p bl = (wList_p)b;
ShowWindow( bl->hWnd, show?SW_SHOW:SW_HIDE );
- if ( bl->hScrollWnd && bl->maxWidth > bl->w )
+ if ( bl->hScrollWnd && bl->maxWidth > bl->w ) {
ShowWindow( bl->hScrollWnd, show?SW_SHOW:SW_HIDE );
+ }
#ifdef SHOW_DOES_SETFOCUS
- if ( show && (bl->option&BO_READONLY)==0 )
+ if ( show && (bl->option&BO_READONLY)==0 ) {
hWnd = SetFocus( bl->hWnd );
+ }
#endif
}
static void listSetPos(
- wControl_p b,
- wWinPix_t x,
- wWinPix_t y )
+ wControl_p b,
+ wWinPix_t x,
+ wWinPix_t y )
{
wList_p bl = (wList_p)b;
wWinPix_t x1, y1;
RECT rect;
-
+
bl->x = x1 = x;
bl->y = y1 = y;
- if ( bl->colTitles )
+ if ( bl->colTitles ) {
y1 += listTitleHeight;
+ }
if (!SetWindowPos( b->hWnd, HWND_TOP, x1, y1,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER))
- mswFail("listSetPos");
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER)) {
+ mswFail("listSetPos");
+ }
if ( bl->hScrollWnd && bl->maxWidth > bl->w ) {
GetClientRect( bl->hWnd, &rect );
if (!SetWindowPos( bl->hScrollWnd, HWND_TOP, x1, y1+rect.bottom+2,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER))
- mswFail("listSetPos2");
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER)) {
+ mswFail("listSetPos2");
+ }
}
}
static void listRepaintLabel(
- HWND hWnd,
- wControl_p b )
+ HWND hWnd,
+ wControl_p b )
{
wList_p bl = (wList_p)b;
HDC hDc;
@@ -495,8 +519,9 @@ static void listRepaintLabel(
wWinPix_t colWidth;
mswRepaintLabel( hWnd, b );
- if ( bl->colTitles == NULL )
+ if ( bl->colTitles == NULL ) {
return;
+ }
hDc = GetDC( hWnd );
start = bl->x-bl->scrollPos+2;
rc.top = bl->y;
@@ -506,7 +531,7 @@ static void listRepaintLabel(
hBrush = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) );
FillRect( hDc, &rc, hBrush );
SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) );
-
+
hFont = SelectObject( hDc, mswLabelFont );
hPen1 = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNTEXT ) );
hPen2 = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNHIGHLIGHT ) );
@@ -527,28 +552,31 @@ static void listRepaintLabel(
LineTo( hDc, rc.right-1, rc.top+1 );
rc.top += 2;
rc.bottom -= 1;
- for ( inx=0,title=bl->colTitles; inx<bl->colCnt&&*title&&start<bl->x+bl->w; inx++ ) {
+ for ( inx=0,title=bl->colTitles; inx<bl->colCnt&&*title
+ &&start<bl->x+bl->w; inx++ ) {
colWidth = bl->colWidths[inx];
if ( start+colWidth >= 3 ) {
rc.left = start;
- if ( rc.left < bl->x+2 )
+ if ( rc.left < bl->x+2 ) {
rc.left = bl->x+2;
+ }
rc.right = start+colWidth;
- if ( rc.right > bl->x+bl->w-1 )
+ if ( rc.right > bl->x+bl->w-1 ) {
rc.right = bl->x+bl->w-1;
+ }
ExtTextOut( hDc, start+1, rc.top+0,
- ETO_CLIPPED|ETO_OPAQUE, &rc,
- *title, (int)(strlen(*title)), NULL );
+ ETO_CLIPPED|ETO_OPAQUE, &rc,
+ *title, (int)(strlen(*title)), NULL );
if ( start-bl->x >= 3 ) {
- SelectObject( hDc, hPen1 );
- MoveTo( hDc, start-1, rc.top-1 );
- LineTo( hDc, start-1, rc.bottom+3 );
- SelectObject( hDc, hPen2 );
- MoveTo( hDc, start, rc.top );
- LineTo( hDc, start, rc.bottom+1 );
- SelectObject( hDc, hPen3 );
- MoveTo( hDc, start-2, rc.top );
- LineTo( hDc, start-2, rc.bottom+1 );
+ SelectObject( hDc, hPen1 );
+ MoveTo( hDc, start-1, rc.top-1 );
+ LineTo( hDc, start-1, rc.bottom+3 );
+ SelectObject( hDc, hPen2 );
+ MoveTo( hDc, start, rc.top );
+ LineTo( hDc, start, rc.bottom+1 );
+ SelectObject( hDc, hPen3 );
+ MoveTo( hDc, start-2, rc.top );
+ LineTo( hDc, start-2, rc.bottom+1 );
}
}
title++;
@@ -581,12 +609,12 @@ static void listHandleFocusState( LPDRAWITEMSTRUCT lpdis, LPRECT rc )
LRESULT listProc(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
-{
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
+{
wList_p bl = (wList_p)b;
int cnt, inx, selected;
size_t len;
@@ -607,345 +635,380 @@ LRESULT listProc(
COLORREF col;
if (bl) switch( message ) {
-
- case WM_COMMAND:
- notification = WCMD_PARAM_NOTF;
- switch (bl->type) {
- case B_LIST:
- switch (notification) {
- case LBN_SELCHANGE:
- case LBN_DBLCLK:
- if ( (bl->option&BL_DBLCLICK)!=0 ?
- notification!=LBN_DBLCLK :
- notification==LBN_DBLCLK )
- break;
- if ( (bl->option&BL_MANY) ) {
- wListGetCount(bl);
- for ( inx=0; inx<bl->count; inx++ ) {
- ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA, (WPARAM)inx, (LPARAM)0 );
- if ( ldp != NULL && ldp != (void*)LB_ERR ) {
- selected = ((long)SendMessage( bl->hWnd, LB_GETSEL, (WPARAM)inx, (LPARAM)0 ) != 0L );
- if ( selected != ldp->selected ) {
- ldp->selected = selected;
- if ( selected ) {
- bl->last = inx;
- cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last, (LPARAM)mswTmpBuff );
- mswTmpBuff[cnt] = '\0';
- } else {
- mswTmpBuff[0] = '\0';
+
+ case WM_COMMAND:
+ notification = WCMD_PARAM_NOTF;
+ switch (bl->type) {
+ case B_LIST:
+ switch (notification) {
+ case LBN_SELCHANGE:
+ case LBN_DBLCLK:
+ if ( (bl->option&BL_DBLCLICK)!=0 ?
+ notification!=LBN_DBLCLK :
+ notification==LBN_DBLCLK ) {
+ break;
+ }
+ if ( (bl->option&BL_MANY) ) {
+ wListGetCount(bl);
+ for ( inx=0; inx<bl->count; inx++ ) {
+ ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA, (WPARAM)inx,
+ (LPARAM)0 );
+ if ( ldp != NULL && ldp != (void*)LB_ERR ) {
+ selected = ((long)SendMessage( bl->hWnd, LB_GETSEL, (WPARAM)inx,
+ (LPARAM)0 ) != 0L );
+ if ( selected != ldp->selected ) {
+ ldp->selected = selected;
+ if ( selected ) {
+ bl->last = inx;
+ cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last,
+ (LPARAM)mswTmpBuff );
+ mswTmpBuff[cnt] = '\0';
+ } else {
+ mswTmpBuff[0] = '\0';
+ }
+ if ( bl->action ) {
+ bl->action( inx, mswTmpBuff, selected?1:2, bl->data, ldp->itemContext );
+ }
+ if ( selected && bl->valueP ) {
+ *bl->valueP = bl->last;
+ }
+ }
}
- if ( bl->action )
- bl->action( inx, mswTmpBuff, selected?1:2, bl->data, ldp->itemContext );
- if ( selected && bl->valueP )
- *bl->valueP = bl->last;
}
+ } else {
+ bl->last = (int)SendMessage( bl->hWnd, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
+ cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last,
+ (LPARAM)mswTmpBuff );
+ mswTmpBuff[cnt] = '\0';
+ if (bl->action) {
+ ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA,
+ (WPARAM)bl->last, (LPARAM)0 );
+ bl->action( bl->last, mswTmpBuff, 1, bl->data,
+ ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) );
+ }
+ if (bl->valueP) {
+ *bl->valueP = bl->last;
+ }
+ }
+ break;
+
+ case LBN_KILLFOCUS:
+ if ( ( bl->option&BL_MANY ) == 0 &&
+ bl->last != (int)SendMessage( bl->hWnd, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 ) ) {
+ (void)SendMessage( bl->hWnd, LB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 );
+ }
+ break;
+ }
+ break;
+
+ case B_DROPLIST:
+ case B_COMBOLIST:
+ switch (notification) {
+ case CBN_SELCHANGE:
+ case CBN_DBLCLK:
+ if ( (bl->type == B_DROPLIST) ||
+ ( (bl->option&BL_DBLCLICK)!=0 ?
+ notification!=CBN_DBLCLK :
+ notification==CBN_DBLCLK) ) {
+ break;
}
+
+ case CBN_CLOSEUP:
+ bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
+ if (bl->last < 0) {
+ break;
}
- } else {
- bl->last = (int)SendMessage( bl->hWnd, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
- cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last,
- (LPARAM)mswTmpBuff );
- mswTmpBuff[cnt] = '\0';
if (bl->action) {
- ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA,
- (WPARAM)bl->last, (LPARAM)0 );
+ cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT,
+ (WPARAM)bl->last, (LPARAM)mswTmpBuff );
+ ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA,
+ (WPARAM)bl->last, (LPARAM)0 );
+ mswTmpBuff[cnt] = '\0';
bl->action( bl->last, mswTmpBuff, 1, bl->data,
- ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) );
+ ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) );
}
if (bl->valueP) {
*bl->valueP = bl->last;
}
- }
- break;
-
- case LBN_KILLFOCUS:
- if ( ( bl->option&BL_MANY ) == 0 &&
- bl->last != (int)SendMessage( bl->hWnd, LB_GETCURSEL, (WPARAM)0, (LPARAM)0 ) )
- (void)SendMessage( bl->hWnd, LB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 );
- break;
- }
- break;
-
- case B_DROPLIST:
- case B_COMBOLIST:
- switch (notification) {
- case CBN_SELCHANGE:
- case CBN_DBLCLK:
- if ( (bl->type == B_DROPLIST) ||
- ( (bl->option&BL_DBLCLICK)!=0 ?
- notification!=CBN_DBLCLK :
- notification==CBN_DBLCLK) )
+ mswAllowBalloonHelp = TRUE;
+ /*SendMessage( bl->bWnd, CB_SETCURSEL, bl->last, 0L );*/
break;
- case CBN_CLOSEUP:
- bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
- if (bl->last < 0)
+ case CBN_KILLFOCUS:
+ inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
+ if ( bl->last != inx ) {
+ (void)SendMessage( bl->hWnd, CB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 );
+ }
break;
- if (bl->action) {
- cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT,
- (WPARAM)bl->last, (LPARAM)mswTmpBuff );
- ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA,
- (WPARAM)bl->last, (LPARAM)0 );
- mswTmpBuff[cnt] = '\0';
- bl->action( bl->last, mswTmpBuff, 1, bl->data,
- ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) );
- }
- if (bl->valueP) {
- *bl->valueP = bl->last;
- }
- mswAllowBalloonHelp = TRUE;
- /*SendMessage( bl->bWnd, CB_SETCURSEL, bl->last, 0L );*/
- break;
- case CBN_KILLFOCUS:
- inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 );
- if ( bl->last != inx )
- (void)SendMessage( bl->hWnd, CB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 );
- break;
-
- case CBN_DROPDOWN:
- mswAllowBalloonHelp = FALSE;
- break;
+ case CBN_DROPDOWN:
+ mswAllowBalloonHelp = FALSE;
+ break;
- case CBN_EDITCHANGE:
- bl->last = -1;
- if (bl->action) {
- cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, (WPARAM)sizeof mswTmpBuff,
- (LPARAM)mswTmpBuff );
- mswTmpBuff[cnt] = '\0';
- bl->action( -1, mswTmpBuff, 1, bl->data, NULL );
+ case CBN_EDITCHANGE:
+ bl->last = -1;
+ if (bl->action) {
+ cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, (WPARAM)sizeof mswTmpBuff,
+ (LPARAM)mswTmpBuff );
+ mswTmpBuff[cnt] = '\0';
+ bl->action( -1, mswTmpBuff, 1, bl->data, NULL );
+ }
+ break;
}
break;
}
break;
- }
- break;
- case WM_MEASUREITEM:
- lpmis = (LPMEASUREITEMSTRUCT)lParam;
- hDc = GetDC( hWnd );
- if ( bl->type == B_LIST )
- hFont = SelectObject( hDc, mswLabelFont );
- GetTextMetrics( hDc, &tm );
- lpmis->itemHeight = tm.tmHeight;
- if ( bl->type == B_LIST )
- SelectObject( hDc, hFont );
- ReleaseDC( hWnd, hDc );
- break;
+ case WM_MEASUREITEM:
+ lpmis = (LPMEASUREITEMSTRUCT)lParam;
+ hDc = GetDC( hWnd );
+ if ( bl->type == B_LIST ) {
+ hFont = SelectObject( hDc, mswLabelFont );
+ }
+ GetTextMetrics( hDc, &tm );
+ lpmis->itemHeight = tm.tmHeight;
+ if ( bl->type == B_LIST ) {
+ SelectObject( hDc, hFont );
+ }
+ ReleaseDC( hWnd, hDc );
+ break;
- case WM_DRAWITEM:
- lpdis = (LPDRAWITEMSTRUCT)lParam;
- if (lpdis->itemID == -1) {
- listHandleFocusState(lpdis, &lpdis->rcItem);
- return TRUE;
- }
- ldp = (listData*)SendMessage( bl->hWnd,
- (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
- (WPARAM)lpdis->itemID, (LPARAM)0);
- rc = lpdis->rcItem;
- if (lpdis->itemAction & (ODA_DRAWENTIRE|ODA_SELECT|ODA_FOCUS)) {
- if( bl->type == B_LIST )
- hFont = SelectObject( lpdis->hDC, mswLabelFont );
- cnt = (int)SendMessage( lpdis->hwndItem,
- (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT),
- (WPARAM)lpdis->itemID, (LPARAM)mswTmpBuff );
- mswTmpBuff[cnt] = '\0';
- if ( lpdis->itemState & ODS_SELECTED ) {
- SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
- SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
- } else {
- SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) );
- SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) );
+ case WM_DRAWITEM:
+ lpdis = (LPDRAWITEMSTRUCT)lParam;
+ if (lpdis->itemID == -1) {
+ listHandleFocusState(lpdis, &lpdis->rcItem);
+ return TRUE;
}
- rc1 = rc;
- rc1.left -= bl->scrollPos;
- for ( inx=0,cp0=mswTmpBuff; inx<bl->colCnt&&cp0&&rc1.left<rc.right; inx++ ) {
- if ( inx>=bl->colCnt-1 || (cp1=strchr(cp0,'\t')) == NULL ) {
- len = strlen( cp0 );
- cp1=cp0 + len; // JBB, to avoid an MSC error below where cp1 has not been defined.
- } else {
- len = cp1-cp0;
- cp1 ++;
+ ldp = (listData*)SendMessage( bl->hWnd,
+ (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA),
+ (WPARAM)lpdis->itemID, (LPARAM)0);
+ rc = lpdis->rcItem;
+ if (lpdis->itemAction & (ODA_DRAWENTIRE|ODA_SELECT|ODA_FOCUS)) {
+ if( bl->type == B_LIST ) {
+ hFont = SelectObject( lpdis->hDC, mswLabelFont );
}
- if ( bl->colWidths ) {
- colWidth = bl->colWidths[inx];
+ cnt = (int)SendMessage( lpdis->hwndItem,
+ (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT),
+ (WPARAM)lpdis->itemID, (LPARAM)mswTmpBuff );
+ mswTmpBuff[cnt] = '\0';
+ if ( lpdis->itemState & ODS_SELECTED ) {
+ SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
+ SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
} else {
- colWidth = rc.right;
+ SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) );
+ SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) );
}
- if ( inx == 0 && ldp && ldp!=(void*)LB_ERR && ldp->bm ) {
- if (mswPalette) {
- SelectPalette( lpdis->hDC, mswPalette, 0 );
- cnt = RealizePalette( lpdis->hDC );
+ rc1 = rc;
+ rc1.left -= bl->scrollPos;
+ for ( inx=0,cp0=mswTmpBuff; inx<bl->colCnt&&cp0&&rc1.left<rc.right; inx++ ) {
+ if ( inx>=bl->colCnt-1 || (cp1=strchr(cp0,'\t')) == NULL ) {
+ len = strlen( cp0 );
+ cp1=cp0 + len; // JBB, to avoid an MSC error below where cp1 has not been defined.
+ } else {
+ len = cp1-cp0;
+ cp1 ++;
+ }
+ if ( bl->colWidths ) {
+ colWidth = bl->colWidths[inx];
+ } else {
+ colWidth = rc.right;
+ }
+ if ( inx == 0 && ldp && ldp!=(void*)LB_ERR && ldp->bm ) {
+ if (mswPalette) {
+ SelectPalette( lpdis->hDC, mswPalette, 0 );
+ cnt = RealizePalette( lpdis->hDC );
+ }
+ hPen = SelectObject( lpdis->hDC, CreatePen( PS_SOLID, 0,
+ GetSysColor( COLOR_WINDOW ) ) );
+ hBrush = SelectObject( lpdis->hDC,
+ CreateSolidBrush( GetSysColor( COLOR_WINDOW ) ) );
+ Rectangle( lpdis->hDC, rc1.left, rc1.top, rc1.right, rc1.bottom );
+ DeleteObject( SelectObject( lpdis->hDC, hPen ) );
+ DeleteObject( SelectObject( lpdis->hDC, hBrush ) );
+
+ col = RGB( (ldp->bm->colormap[ 1 ]).rgbRed,
+ (ldp->bm->colormap[ 1 ]).rgbGreen,
+ (ldp->bm->colormap[ 1 ]).rgbBlue );
+ mswDrawIcon( lpdis->hDC, rc1.left+2, rc.top+0, ldp->bm, 0, col, col);
+
+ rc1.left += ldp->bm->w+6;
+ colWidth -= ldp->bm->w+6;
}
- hPen = SelectObject( lpdis->hDC, CreatePen( PS_SOLID, 0, GetSysColor( COLOR_WINDOW ) ) );
- hBrush = SelectObject( lpdis->hDC, CreateSolidBrush( GetSysColor( COLOR_WINDOW ) ) );
- Rectangle( lpdis->hDC, rc1.left, rc1.top, rc1.right, rc1.bottom );
- DeleteObject( SelectObject( lpdis->hDC, hPen ) );
- DeleteObject( SelectObject( lpdis->hDC, hBrush ) );
-
- col = RGB( (ldp->bm->colormap[ 1 ]).rgbRed,
- (ldp->bm->colormap[ 1 ]).rgbGreen,
- (ldp->bm->colormap[ 1 ]).rgbBlue );
- mswDrawIcon( lpdis->hDC, rc1.left+2, rc.top+0, ldp->bm, 0, col, col);
-
- rc1.left += ldp->bm->w+6;
- colWidth -= ldp->bm->w+6;
+ if ( inx>=bl->colCnt-1 || (rc1.right = rc1.left + colWidth) > rc.right ) {
+ rc1.right = rc.right;
+ }
+ if ( rc1.right > 0 && rc1.left+3 < rc.right ) {
+ ExtTextOut( lpdis->hDC, rc1.left+3, rc1.top+1,
+ ETO_CLIPPED | ETO_OPAQUE, &rc1,
+ (LPSTR)cp0, (int)len, NULL );
+ }
+ rc1.left = rc1.right;
+ cp0 = cp1;
}
- if ( inx>=bl->colCnt-1 || (rc1.right = rc1.left + colWidth) > rc.right )
- rc1.right = rc.right;
- if ( rc1.right > 0 && rc1.left+3 < rc.right ) {
- ExtTextOut( lpdis->hDC, rc1.left+3, rc1.top+1,
- ETO_CLIPPED | ETO_OPAQUE, &rc1,
- (LPSTR)cp0, (int)len, NULL );
+ if ( lpdis->itemState & ODS_SELECTED ) {
+ SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) );
+ SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) );
}
- rc1.left = rc1.right;
- cp0 = cp1;
- }
- if ( lpdis->itemState & ODS_SELECTED ) {
- SetTextColor( lpdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) );
- SetBkColor( lpdis->hDC, GetSysColor( COLOR_WINDOW ) );
- }
- if (lpdis->itemState & ODS_FOCUS) {
- DrawFocusRect( lpdis->hDC, &rc );
+ if (lpdis->itemState & ODS_FOCUS) {
+ DrawFocusRect( lpdis->hDC, &rc );
+ }
+ if ( bl->type == B_LIST) {
+ SelectObject( lpdis->hDC, hFont );
+ }
+ return (LRESULT)TRUE;
}
- if ( bl->type == B_LIST)
- SelectObject( lpdis->hDC, hFont );
- return (LRESULT)TRUE;
- }
-
- break;
- case WM_HSCROLL:
- len = ((long)bl->maxWidth)-((long)bl->w);
- if ( len <= 0 )
- return (LRESULT)0;
- switch ( WSCROLL_PARAM_CODE ) {
- case SB_LEFT:
- if ( bl->scrollPos == 0 )
- return (LRESULT)0;
- bl->scrollPos = 0;
break;
- case SB_LINELEFT:
- case SB_PAGELEFT:
- if ( bl->scrollPos == 0 )
+
+ case WM_HSCROLL:
+ len = ((long)bl->maxWidth)-((long)bl->w);
+ if ( len <= 0 ) {
return (LRESULT)0;
- for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) {
- if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) {
- bl->scrollPos = colWidth;
- break;
- }
- colWidth += bl->colWidths[inx];
}
- break;
- case SB_LINERIGHT:
- case SB_PAGERIGHT:
- if ( bl->scrollPos >= len )
- return (LRESULT)0;
- for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) {
- if ( colWidth >= bl->scrollPos ) {
- bl->scrollPos = colWidth+bl->colWidths[inx];
- break;
+ switch ( WSCROLL_PARAM_CODE ) {
+ case SB_LEFT:
+ if ( bl->scrollPos == 0 ) {
+ return (LRESULT)0;
}
- colWidth += bl->colWidths[inx];
- }
- break;
- case SB_RIGHT:
- if ( bl->scrollPos >= len )
+ bl->scrollPos = 0;
+ break;
+ case SB_LINELEFT:
+ case SB_PAGELEFT:
+ if ( bl->scrollPos == 0 ) {
+ return (LRESULT)0;
+ }
+ for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) {
+ if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) {
+ bl->scrollPos = colWidth;
+ break;
+ }
+ colWidth += bl->colWidths[inx];
+ }
+ break;
+ case SB_LINERIGHT:
+ case SB_PAGERIGHT:
+ if ( bl->scrollPos >= len ) {
+ return (LRESULT)0;
+ }
+ for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) {
+ if ( colWidth >= bl->scrollPos ) {
+ bl->scrollPos = colWidth+bl->colWidths[inx];
+ break;
+ }
+ colWidth += bl->colWidths[inx];
+ }
+ break;
+ case SB_RIGHT:
+ if ( bl->scrollPos >= len ) {
+ return (LRESULT)0;
+ }
+ bl->scrollPos = (int)len;
+ break;
+ case SB_THUMBTRACK:
return (LRESULT)0;
- bl->scrollPos = (int)len;
- break;
- case SB_THUMBTRACK:
+ case SB_THUMBPOSITION:
+ nPos = (int)WSCROLL_PARAM_NPOS;
+ bl->scrollPos = (int)(len*nPos/100);
+ break;
+ case SB_ENDSCROLL:
+ return (LRESULT)0;
+ }
+ if ( bl->scrollPos > len ) { bl->scrollPos = (int)len; }
+ if ( bl->scrollPos < 0 ) { bl->scrollPos = 0; }
+ nPos = (int)(((long)bl->scrollPos)*100L/len+0.5);
+ SetScrollPos( bl->hScrollWnd, SB_CTL, nPos, TRUE );
+ InvalidateRect( bl->hWnd, NULL, FALSE );
+ listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl );
return (LRESULT)0;
- case SB_THUMBPOSITION:
- nPos = (int)WSCROLL_PARAM_NPOS;
- bl->scrollPos = (int)(len*nPos/100);
- break;
- case SB_ENDSCROLL:
+
+ case WM_LBUTTONDOWN:
+ if ( bl->type != B_LIST ) {
+ break;
+ }
+ if ( bl->colCnt <= 1 ) {
+ break;
+ }
+ x = bl->dragPos = LOWORD(lParam)+bl->scrollPos-4;
+ bl->dragCol = -1;
+ for ( inx=0; inx<bl->colCnt; inx++ ) {
+ x -= bl->colWidths[inx];
+ if ( x < -5 ) { break; }
+ if ( x <= 0 ) { bl->dragCol = inx; break; }
+ if ( x > bl->colWidths[inx+1] ) { continue; }
+ if ( x <= 10 ) { bl->dragCol = inx; break; }
+ }
+ if ( bl->dragCol >= 0 ) {
+ bl->dragColWidth = bl->colWidths[inx];
+ }
return (LRESULT)0;
- }
- if ( bl->scrollPos > len ) bl->scrollPos = (int)len;
- if ( bl->scrollPos < 0 ) bl->scrollPos = 0;
- nPos = (int)(((long)bl->scrollPos)*100L/len+0.5);
- SetScrollPos( bl->hScrollWnd, SB_CTL, nPos, TRUE );
- InvalidateRect( bl->hWnd, NULL, FALSE );
- listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl );
- return (LRESULT)0;
-
- case WM_LBUTTONDOWN:
- if ( bl->type != B_LIST )
- break;
- if ( bl->colCnt <= 1 )
- break;
- x = bl->dragPos = LOWORD(lParam)+bl->scrollPos-4;
- bl->dragCol = -1;
- for ( inx=0; inx<bl->colCnt; inx++ ) {
- x -= bl->colWidths[inx];
- if ( x < -5 ) break;
- if ( x <= 0 ) { bl->dragCol = inx; break; }
- if ( x > bl->colWidths[inx+1] ) continue;
- if ( x <= 10 ) { bl->dragCol = inx; break; }
- }
- if ( bl->dragCol >= 0 )
- bl->dragColWidth = bl->colWidths[inx];
- return (LRESULT)0;
#ifdef LATER
- case WM_MOUSEMOVE:
- if ( (wParam&MK_LBUTTON) == 0 )
- break;
- if ( bl->type != B_LIST )
- break;
- if ( bl->colCnt <= 1 )
- break;
- x = LOWORD(lParam)+bl->scrolPos;
- for ( inx=0; inx<bl->colCnt; inx++ ) {
- x -= bl->colWidths[inx];
- if ( x <= 0 )
+ case WM_MOUSEMOVE:
+ if ( (wParam&MK_LBUTTON) == 0 ) {
break;
- }
- return (LRESULT)0;
+ }
+ if ( bl->type != B_LIST ) {
+ break;
+ }
+ if ( bl->colCnt <= 1 ) {
+ break;
+ }
+ x = LOWORD(lParam)+bl->scrolPos;
+ for ( inx=0; inx<bl->colCnt; inx++ ) {
+ x -= bl->colWidths[inx];
+ if ( x <= 0 ) {
+ break;
+ }
+ }
+ return (LRESULT)0;
#endif
- case WM_MOUSEMOVE:
- if ( (wParam&MK_LBUTTON) == 0 )
- break;
- case WM_LBUTTONUP:
- if ( bl->type != B_LIST )
- break;
- if ( bl->colCnt <= 1 )
- break;
- if ( bl->dragCol < 0 )
- break;
- x = LOWORD(lParam)+bl->scrollPos-4-bl->dragPos; /* WIN32??? */
- bl->colWidths[bl->dragCol] = bl->dragColWidth+x;
- if ( bl->colWidths[bl->dragCol] < 0 )
- bl->colWidths[bl->dragCol] = 0;
- for ( bl->maxWidth=inx=0; inx<bl->colCnt; inx++ )
- bl->maxWidth += bl->colWidths[inx];
- if ( bl->maxWidth <= bl->w ) {
- x = bl->w - bl->maxWidth;
- bl->colWidths[bl->colCnt-1] += x;
- bl->maxWidth = bl->w;
- bl->scrollPos = 0;
- } else {
- if ( bl->scrollPos+bl->w > bl->maxWidth ) {
- bl->scrollPos = bl->maxWidth - bl->w;
+ case WM_MOUSEMOVE:
+ if ( (wParam&MK_LBUTTON) == 0 ) {
+ break;
+ }
+ case WM_LBUTTONUP:
+ if ( bl->type != B_LIST ) {
+ break;
+ }
+ if ( bl->colCnt <= 1 ) {
+ break;
}
+ if ( bl->dragCol < 0 ) {
+ break;
+ }
+ x = LOWORD(lParam)+bl->scrollPos-4-bl->dragPos; /* WIN32??? */
+ bl->colWidths[bl->dragCol] = bl->dragColWidth+x;
+ if ( bl->colWidths[bl->dragCol] < 0 ) {
+ bl->colWidths[bl->dragCol] = 0;
+ }
+ for ( bl->maxWidth=inx=0; inx<bl->colCnt; inx++ ) {
+ bl->maxWidth += bl->colWidths[inx];
+ }
+ if ( bl->maxWidth <= bl->w ) {
+ x = bl->w - bl->maxWidth;
+ bl->colWidths[bl->colCnt-1] += x;
+ bl->maxWidth = bl->w;
+ bl->scrollPos = 0;
+ } else {
+ if ( bl->scrollPos+bl->w > bl->maxWidth ) {
+ bl->scrollPos = bl->maxWidth - bl->w;
+ }
+ }
+ InvalidateRect( bl->hWnd, NULL, FALSE );
+ listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl );
+ return (LRESULT)0;
+
}
- InvalidateRect( bl->hWnd, NULL, FALSE );
- listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl );
- return (LRESULT)0;
- }
-
return DefWindowProc( hWnd, message, wParam, lParam );
-}
+}
LRESULT FAR PASCAL _export pushList(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
wIndex_t inx = (wIndex_t)GetWindowLongPtr(hWnd, GWL_ID);
@@ -962,9 +1025,9 @@ LRESULT FAR PASCAL _export pushList(
case 0x0D:
case 0x1B:
case 0x09:
- SetFocus( ((wControl_p)(b->parent))->hWnd );
+ SetFocus( ((wControl_p)(b->parent))->hWnd );
SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR,
- wParam, lParam );
+ wParam, lParam );
/*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND,
inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/
return (LRESULT)0;
@@ -976,10 +1039,10 @@ LRESULT FAR PASCAL _export pushList(
}
LRESULT FAR PASCAL _export pushCombo(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
/* Catch <Return> and cause focus to leave control */
wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
@@ -992,9 +1055,9 @@ LRESULT FAR PASCAL _export pushCombo(
case 0x0D:
case 0x1B:
case 0x09:
- SetFocus( ((wControl_p)(b->parent))->hWnd );
+ SetFocus( ((wControl_p)(b->parent))->hWnd );
SendMessage( ((wControl_p)(b->parent))->hWnd, WM_CHAR,
- wParam, lParam );
+ wParam, lParam );
/*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND,
inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/
return (LRESULT)0;
@@ -1006,37 +1069,39 @@ LRESULT FAR PASCAL _export pushCombo(
}
static callBacks_t listCallBacks = {
- listRepaintLabel,
- NULL,
- listProc,
- listSetBusy,
- listShow,
- listSetPos };
+ listRepaintLabel,
+ NULL,
+ listProc,
+ listSetBusy,
+ listShow,
+ listSetPos
+};
static wList_p listCreate(
- int typ,
- const char *className,
- long style,
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- long *valueP,
- wListCallBack_p action,
- void *data,
- wBool_t addFocus,
- int *indexR )
-{
+ int typ,
+ const char *className,
+ long style,
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ long *valueP,
+ wListCallBack_p action,
+ void *data,
+ wBool_t addFocus,
+ int *indexR )
+{
wList_p b;
- RECT rect;
+ RECT rect;
int index;
- b = (wList_p)mswAlloc( parent, typ, mswStrdup(labelStr), sizeof *b, data, &index );
+ b = (wList_p)mswAlloc( parent, typ, mswStrdup(labelStr), sizeof *b, data,
+ &index );
mswComputePos( (wControl_p)b, x, y );
b->option = option;
b->count = 0;
@@ -1051,9 +1116,9 @@ static wList_p listCreate(
b->dragCol = -1;
b->hWnd = CreateWindow( className, NULL,
- style | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x, b->y,
- width, LIST_HEIGHT*(int)number,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ style | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x, b->y,
+ width, LIST_HEIGHT*(int)number,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
if (b->hWnd == NULL) {
mswFail("CreateWindow(LIST)");
return b;
@@ -1078,8 +1143,7 @@ static wList_p listCreate(
oldListProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC);
SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newListProc);
#endif
- }
- else {
+ } else {
newComboProc = MakeProcInstance((XWNDPROC)pushCombo, mswHInst);
oldComboProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC);
SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newComboProc);
@@ -1089,31 +1153,32 @@ static wList_p listCreate(
#endif
}
}
- if ( indexR )
+ if ( indexR ) {
*indexR = index;
- if ( !mswThickFont )
- SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
+ }
+
+ SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 );
return b;
}
wList_p wListCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- int colCnt,
- wWinPix_t * colWidths,
- wBool_t * colRightJust,
- const char * * colTitles,
- long *valueP,
- wListCallBack_p action,
- void *data )
-{
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ int colCnt,
+ wWinPix_t * colWidths,
+ wBool_t * colRightJust,
+ const char * * colTitles,
+ long *valueP,
+ wListCallBack_p action,
+ void *data )
+{
long bs;
wList_p bl;
static int dbu = 0;
@@ -1122,22 +1187,25 @@ wList_p wListCreate(
int i;
bs = LBS_NOTIFY | WS_VSCROLL | WS_BORDER | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS;
- if (option & BL_MANY)
+ if (option & BL_MANY) {
bs |= LBS_MULTIPLESEL|LBS_EXTENDEDSEL;
- if (option & BL_SORT)
+ }
+ if (option & BL_SORT) {
bs |= LBS_SORT;
- if ( colCnt > 1 )
+ }
+ if ( colCnt > 1 ) {
bs |= WS_HSCROLL;
+ }
if ( colTitles ) {
y += listTitleHeight;
number -= 1;
}
bl = listCreate( B_LIST, "LISTBOX", bs, parent, x, y, helpStr,
- labelStr, option, number, width, valueP, action, data, TRUE, &index );
+ labelStr, option, number, width, valueP, action, data, TRUE, &index );
if ( colTitles ) {
bl->y -= listTitleHeight;
bl->h += listTitleHeight;
- }
+ }
if ( colCnt > 1 ) {
bl->colCnt = colCnt;
bl->colWidths = (wWinPix_t*)malloc( colCnt * sizeof *bl->colWidths );
@@ -1150,11 +1218,13 @@ wList_p wListCreate(
bl->maxWidth += bl->colWidths[i];
}
bl->hScrollWnd = CreateWindow( "ScrollBar", NULL,
- SBS_HORZ | SBS_BOTTOMALIGN | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), bl->x, bl->y,
- width, CW_USEDEFAULT,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
- if (bl->hScrollWnd == NULL)
+ SBS_HORZ | SBS_BOTTOMALIGN | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent),
+ bl->x, bl->y,
+ width, CW_USEDEFAULT,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
+ if (bl->hScrollWnd == NULL) {
mswFail("CreateWindow(LISTSCROLL)");
+ }
SetScrollRange( bl->hScrollWnd, SB_CTL, 0, 100, TRUE );
GetWindowRect( bl->hScrollWnd, &rect );
bl->scrollH = rect.bottom - rect.top+2;
@@ -1164,49 +1234,52 @@ wList_p wListCreate(
wList_p wDropListCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- long *valueP,
- wListCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ long *valueP,
+ wListCallBack_p action,
+ void *data )
{
long bs;
- if ( (option&BL_EDITABLE) != 0 )
+ if ( (option&BL_EDITABLE) != 0 ) {
bs = CBS_DROPDOWN;
- else
+ } else {
bs = CBS_DROPDOWNLIST;
+ }
bs |= WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS;
- if (option & BL_SORT)
+ if (option & BL_SORT) {
bs |= CBS_SORT;
+ }
return listCreate( B_DROPLIST, "COMBOBOX", bs, parent, x, y, helpStr,
- labelStr, option, number, width, valueP, action, data, TRUE, NULL );
+ labelStr, option, number, width, valueP, action, data, TRUE, NULL );
}
wList_p wComboListCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- long *valueP,
- wListCallBack_p action,
- void *data )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ long *valueP,
+ wListCallBack_p action,
+ void *data )
{
long bs;
bs = CBS_SIMPLE | WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS;
- if (option & BL_SORT)
+ if (option & BL_SORT) {
bs |= CBS_SORT;
+ }
return listCreate( B_COMBOLIST, "COMBOBOX", bs, parent, x, y, helpStr,
- labelStr, option, number, width, valueP, action, data, FALSE, NULL );
+ labelStr, option, number, width, valueP, action, data, FALSE, NULL );
}
diff --git a/app/wlib/mswlib/mswmenu.c b/app/wlib/mswlib/mswmenu.c
index 9e36c8b..0a2851d 100644
--- a/app/wlib/mswlib/mswmenu.c
+++ b/app/wlib/mswlib/mswmenu.c
@@ -18,14 +18,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define OEMRESOURCE
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -48,8 +47,8 @@ typedef enum { MM_BUTT, MM_MENU, MM_BAR, MM_POPUP } mmtype_e;
typedef struct wMenuItem_t * wMenuItem_p;
struct radioButtonGroup {
- int firstButton; /* id of first button in group */
- int lastButton; /* id of last button in group */
+ int firstButton; /* id of first button in group */
+ int lastButton; /* id of last button in group */
};
/* NOTE: first field must be the same as WOBJ_COMMON */
@@ -61,58 +60,58 @@ struct radioButtonGroup {
wMenuItem_p mnext;
struct wMenuItem_t {
- MOBJ_COMMON
- };
+ MOBJ_COMMON
+};
struct wMenu_t {
- MOBJ_COMMON
- mmtype_e mmtype;
- wMenuItem_p first, last;
- struct radioButtonGroup *radioGroup;
- HMENU menu;
- wButton_p button;
- wMenuTraceCallBack_p traceFunc;
- void * traceData;
- };
+ MOBJ_COMMON
+ mmtype_e mmtype;
+ wMenuItem_p first, last;
+ struct radioButtonGroup *radioGroup;
+ HMENU menu;
+ wButton_p button;
+ wMenuTraceCallBack_p traceFunc;
+ void * traceData;
+};
struct wMenuPush_t {
- MOBJ_COMMON
- wMenu_p mparent;
- wMenuCallBack_p action;
- long acclKey;
- wBool_t enabled;
- };
+ MOBJ_COMMON
+ wMenu_p mparent;
+ wMenuCallBack_p action;
+ long acclKey;
+ wBool_t enabled;
+};
struct wMenuRadio_t {
- MOBJ_COMMON
- wMenu_p mparent;
- wMenuCallBack_p action;
- long acclKey;
- wBool_t enabled;
- };
+ MOBJ_COMMON
+ wMenu_p mparent;
+ wMenuCallBack_p action;
+ long acclKey;
+ wBool_t enabled;
+};
struct wMenuToggle_t {
- MOBJ_COMMON
- wMenu_p mparent;
- wMenuCallBack_p action;
- long acclKey;
- wBool_t enabled;
- };
+ MOBJ_COMMON
+ wMenu_p mparent;
+ wMenuCallBack_p action;
+ long acclKey;
+ wBool_t enabled;
+};
typedef struct wMenuListItem_t * wMenuListItem_p;
struct wMenuList_t {
- MOBJ_COMMON
- wMenuListItem_p left, right;
- wMenu_p mlparent;
- int max;
- int count;
- wMenuListCallBack_p action;
- };
+ MOBJ_COMMON
+ wMenuListItem_p left, right;
+ wMenu_p mlparent;
+ int max;
+ int count;
+ wMenuListCallBack_p action;
+};
struct wMenuListItem_t {
- MOBJ_COMMON
- wMenuListItem_p left, right;
- wMenuListCallBack_p action;
- };
+ MOBJ_COMMON
+ wMenuListItem_p left, right;
+ wMenuListCallBack_p action;
+};
#define UNCHECK (0)
#define CHECK (1)
@@ -139,17 +138,18 @@ char * mswStrdup( const char * str )
if (str) {
ret = (char*)malloc( strlen(str)+1 );
strcpy( ret, str );
- } else
+ } else {
ret = NULL;
+ }
return ret;
}
static LRESULT menuPush(
- wControl_p b,
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
+ wControl_p b,
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam )
{
wMenuItem_p m = (wMenuItem_p)b;
wBool_t set;
@@ -165,29 +165,34 @@ static LRESULT menuPush(
mswFail( "pushMenu" );
break;
case M_PUSH:
- if (((wMenuPush_p)m)->action)
+ if (((wMenuPush_p)m)->action) {
((wMenuPush_p)m)->action(((wMenuPush_p)m)->data);
+ }
break;
case M_TOGGLE:
set = wMenuToggleGet((wMenuToggle_p)m);
set = !set;
wMenuToggleSet((wMenuToggle_p)m,set);
- if (((wMenuToggle_p)m)->action)
+ if (((wMenuToggle_p)m)->action) {
((wMenuToggle_p)m)->action(((wMenuPush_p)m)->data);
+ }
break;
case M_LISTITEM:
- if (((wMenuListItem_p)m)->action)
+ if (((wMenuListItem_p)m)->action) {
((wMenuListItem_p)m)->action(0, "", ((wMenuListItem_p)m)->data);
+ }
break;
case M_RADIO:
- if (((wMenuRadio_p)m)->action)
+ if (((wMenuRadio_p)m)->action) {
((wMenuRadio_p)m)->action(((wMenuRadio_p)m)->data);
+ }
break;
}
return (LRESULT)0;
}
if ( (m->parentMenu)->traceFunc ) {
- (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, ((wMenu_p)m->parentMenu)->traceData );
+ (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr,
+ ((wMenu_p)m->parentMenu)->traceData );
}
return DefWindowProc( hWnd, message, wParam, lParam );
}
@@ -198,24 +203,26 @@ static void menuDone( wControl_p b )
switch ( m->mtype ) {
case M_MENU:
if ( ((wMenu_p)m)->mmtype == MM_BUTT ||
- ((wMenu_p)m)->mmtype == MM_POPUP )
+ ((wMenu_p)m)->mmtype == MM_POPUP ) {
DestroyMenu( ((wMenu_p)m)->menu );
+ }
break;
}
}
static callBacks_t menuItemCallBacks = {
- NULL,
- menuDone,
- menuPush };
+ NULL,
+ menuDone,
+ menuPush
+};
static wMenuItem_p createMenuItem(
- wMenu_p m,
- mtype_e mtype,
- const char * helpStr,
- const char * labelStr,
- int size )
+ wMenu_p m,
+ mtype_e mtype,
+ const char * helpStr,
+ const char * labelStr,
+ int size )
{
wMenuItem_p mi;
@@ -254,29 +261,31 @@ static wMenuItem_p createMenuItem(
typedef struct {
- long acclKey;
- wMenuPush_p mp;
- wAccelKeyCallBack_p action;
- wAccelKey_e key;
- void * data;
- } acclTable_t, *acclTable_p;
+ long acclKey;
+ wMenuPush_p mp;
+ wAccelKeyCallBack_p action;
+ wAccelKey_e key;
+ void * data;
+} acclTable_t, *acclTable_p;
static dynArr_t acclTable_da;
#define acclTable(N) DYNARR_N( acclTable_t, acclTable_da, N )
int mswMenuAccelerator(
- wWin_p win,
- long acclKey )
+ wWin_p win,
+ long acclKey )
{
acclTable_p at;
if ( ((wControl_p)win)->type != W_MAIN &&
- ((wControl_p)win)->type != W_POPUP )
+ ((wControl_p)win)->type != W_POPUP ) {
return 0;
+ }
for ( at = &acclTable(0); at<&acclTable(acclTable_da.cnt); at++ ) {
if (at->acclKey == acclKey) {
if (at->mp) {
- if (at->mp->enabled && at->mp->action)
+ if (at->mp->enabled && at->mp->action) {
at->mp->action(at->mp->data);
+ }
return 1;
} else if (at->action) {
at->action( at->key, at->data );
@@ -292,40 +301,40 @@ int mswMenuAccelerator(
static long acclKeyMap[] = {
- 0, /* wAccelKey_None, */
- VK_DELETE, /* wAccelKey_Del, */
- VK_INSERT, /* wAccelKey_Ins, */
- VK_HOME, /* wAccelKey_Home, */
- VK_END, /* wAccelKey_End, */
- VK_PRIOR, /* wAccelKey_Pgup, */
- VK_NEXT, /* wAccelKey_Pgdn, */
- VK_UP, /* wAccelKey_Up, */
- VK_DOWN, /* wAccelKey_Down, */
- VK_RIGHT, /* wAccelKey_Right, */
- VK_LEFT, /* wAccelKey_Left, */
- VK_BACK, /* wAccelKey_Back, */
- VK_F1, /* wAccelKey_F1, */
- VK_F2, /* wAccelKey_F2, */
- VK_F3, /* wAccelKey_F3, */
- VK_F4, /* wAccelKey_F4, */
- VK_F5, /* wAccelKey_F5, */
- VK_F6, /* wAccelKey_F6, */
- VK_F7, /* wAccelKey_F7, */
- VK_F8, /* wAccelKey_F8, */
- VK_F9, /* wAccelKey_F9, */
- VK_F10, /* wAccelKey_F10, */
- VK_F11, /* wAccelKey_F11, */
- VK_F12, /* wAccelKey_F12, */
- VK_ADD, /* wAccelKey_Numpad_Add, */
- VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */
- };
+ 0, /* wAccelKey_None, */
+ VK_DELETE, /* wAccelKey_Del, */
+ VK_INSERT, /* wAccelKey_Ins, */
+ VK_HOME, /* wAccelKey_Home, */
+ VK_END, /* wAccelKey_End, */
+ VK_PRIOR, /* wAccelKey_Pgup, */
+ VK_NEXT, /* wAccelKey_Pgdn, */
+ VK_UP, /* wAccelKey_Up, */
+ VK_DOWN, /* wAccelKey_Down, */
+ VK_RIGHT, /* wAccelKey_Right, */
+ VK_LEFT, /* wAccelKey_Left, */
+ VK_BACK, /* wAccelKey_Back, */
+ VK_F1, /* wAccelKey_F1, */
+ VK_F2, /* wAccelKey_F2, */
+ VK_F3, /* wAccelKey_F3, */
+ VK_F4, /* wAccelKey_F4, */
+ VK_F5, /* wAccelKey_F5, */
+ VK_F6, /* wAccelKey_F6, */
+ VK_F7, /* wAccelKey_F7, */
+ VK_F8, /* wAccelKey_F8, */
+ VK_F9, /* wAccelKey_F9, */
+ VK_F10, /* wAccelKey_F10, */
+ VK_F11, /* wAccelKey_F11, */
+ VK_F12, /* wAccelKey_F12, */
+ VK_ADD, /* wAccelKey_Numpad_Add, */
+ VK_SUBTRACT /* wAccelKey_Numpad_Subtract, */
+};
void wAttachAccelKey(
- wAccelKey_e key,
- int modifier,
- wAccelKeyCallBack_p action,
- void * data )
+ wAccelKey_e key,
+ int modifier,
+ wAccelKeyCallBack_p action,
+ void * data )
{
acclTable_t * ad;
if ( key < 1 || key > wAccelKey_Numpad_Subtract ) {
@@ -349,135 +358,133 @@ void wAttachAccelKey(
*****************************************************************************
*/
-HBITMAP GetMyCheckBitmaps(UINT fuCheck)
-{
- COLORREF crBackground; /* background color */
- HBRUSH hbrBackground; /* background brush */
- HBRUSH hbrTargetOld; /* original background brush */
- HDC hdcSource; /* source device context */
- HDC hdcTarget; /* target device context */
- HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */
- BITMAP bmCheckbox; /* structure for bitmap data */
- HBITMAP hbmpSourceOld; /* handle to original source bitmap */
- HBITMAP hbmpTargetOld; /* handle to original target bitmap */
- HBITMAP hbmpCheck; /* handle to check-mark bitmap */
- RECT rc; /* rectangle for check-box bitmap */
- WORD wBitmapX; /* width of check-mark bitmap */
- WORD wBitmapY; /* height of check-mark bitmap */
+HBITMAP GetMyCheckBitmaps(UINT fuCheck)
+{
+ COLORREF crBackground; /* background color */
+ HBRUSH hbrBackground; /* background brush */
+ HBRUSH hbrTargetOld; /* original background brush */
+ HDC hdcSource; /* source device context */
+ HDC hdcTarget; /* target device context */
+ HBITMAP hbmpCheckboxes; /* handle to check-box bitmap */
+ BITMAP bmCheckbox; /* structure for bitmap data */
+ HBITMAP hbmpSourceOld; /* handle to original source bitmap */
+ HBITMAP hbmpTargetOld; /* handle to original target bitmap */
+ HBITMAP hbmpCheck; /* handle to check-mark bitmap */
+ RECT rc; /* rectangle for check-box bitmap */
+ WORD wBitmapX; /* width of check-mark bitmap */
+ WORD wBitmapY; /* height of check-mark bitmap */
WORD wMenuH; /* height of menu line */
-
- /* Get the menu background color and create a solid brush
- with that color. */
-
- crBackground = GetSysColor(COLOR_MENU);
- hbrBackground = CreateSolidBrush(crBackground);
-
- /* Create memory device contexts for the source and
- destination bitmaps. */
-
- hdcSource = CreateCompatibleDC((HDC) NULL);
- hdcTarget = CreateCompatibleDC(hdcSource);
-
- /* Get the size of the system default check-mark bitmap and
- create a compatible bitmap of the same size. */
-
- wBitmapX = GetSystemMetrics(SM_CXMENUCHECK);
- wBitmapY = GetSystemMetrics(SM_CYMENUCHECK);
+
+ /* Get the menu background color and create a solid brush
+ with that color. */
+
+ crBackground = GetSysColor(COLOR_MENU);
+ hbrBackground = CreateSolidBrush(crBackground);
+
+ /* Create memory device contexts for the source and
+ destination bitmaps. */
+
+ hdcSource = CreateCompatibleDC((HDC) NULL);
+ hdcTarget = CreateCompatibleDC(hdcSource);
+
+ /* Get the size of the system default check-mark bitmap and
+ create a compatible bitmap of the same size. */
+
+ wBitmapX = GetSystemMetrics(SM_CXMENUCHECK);
+ wBitmapY = GetSystemMetrics(SM_CYMENUCHECK);
wMenuH = GetSystemMetrics(SM_CYMENU);
-
- hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX,
- wBitmapY);
-
- /* Select the background brush and bitmap into the target DC. */
-
- hbrTargetOld = SelectObject(hdcTarget, hbrBackground);
- hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck);
-
- /* Use the selected brush to initialize the background color
- of the bitmap in the target device context. */
-
- PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY);
-
- /* Load the predefined check box bitmaps and select it
- into the source DC. */
-
- hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL,
- (LPTSTR) OBM_CHECKBOXES);
-
- hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes);
-
- /* Fill a BITMAP structure with information about the
- check box bitmaps, and then find the upper-left corner of
- the unchecked check box or the checked check box. */
-
- GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox);
-
+
+ hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX,
+ wBitmapY);
+
+ /* Select the background brush and bitmap into the target DC. */
+
+ hbrTargetOld = SelectObject(hdcTarget, hbrBackground);
+ hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck);
+
+ /* Use the selected brush to initialize the background color
+ of the bitmap in the target device context. */
+
+ PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY);
+
+ /* Load the predefined check box bitmaps and select it
+ into the source DC. */
+
+ hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL,
+ (LPTSTR) OBM_CHECKBOXES);
+
+ hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes);
+
+ /* Fill a BITMAP structure with information about the
+ check box bitmaps, and then find the upper-left corner of
+ the unchecked check box or the checked check box. */
+
+ GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox);
+
switch( fuCheck ) {
-
+
case UNCHECK:
- rc.left = 0;
- rc.right = (bmCheckbox.bmWidth / 4);
- rc.top = 0;
- rc.bottom = (bmCheckbox.bmHeight / 3);
- break;
- case CHECK:
- rc.left = (bmCheckbox.bmWidth / 4);
- rc.right = (bmCheckbox.bmWidth / 4) * 2;
- rc.top = 0;
- rc.bottom = (bmCheckbox.bmHeight / 3);
+ rc.left = 0;
+ rc.right = (bmCheckbox.bmWidth / 4);
+ rc.top = 0;
+ rc.bottom = (bmCheckbox.bmHeight / 3);
+ break;
+ case CHECK:
+ rc.left = (bmCheckbox.bmWidth / 4);
+ rc.right = (bmCheckbox.bmWidth / 4) * 2;
+ rc.top = 0;
+ rc.bottom = (bmCheckbox.bmHeight / 3);
break;
case RADIOCHECK:
- rc.left = (bmCheckbox.bmWidth / 4);
- rc.right = (bmCheckbox.bmWidth / 4) * 2;
+ rc.left = (bmCheckbox.bmWidth / 4);
+ rc.right = (bmCheckbox.bmWidth / 4) * 2;
rc.top = (bmCheckbox.bmHeight / 3);
- rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
+ rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
break;
case RADIOUNCHECK:
rc.top = (bmCheckbox.bmHeight / 3);
- rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
- rc.left = 0;
- rc.right = (bmCheckbox.bmWidth / 4);
+ rc.bottom = (bmCheckbox.bmHeight / 3) * 2;
+ rc.left = 0;
+ rc.right = (bmCheckbox.bmWidth / 4);
break;
}
-
- /* Copy the appropriate bitmap into the target DC. If the
- check-box bitmap is larger than the default check-mark
- bitmap, use StretchBlt to make it fit; otherwise, just
- copy it. */
- if (((rc.right - rc.left) > (int) wBitmapX) ||
- ((rc.bottom - rc.top) > (int) wBitmapY))
- {
- StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY,
- hdcSource, rc.left, rc.top, rc.right - rc.left,
- rc.bottom - rc.top, SRCCOPY);
- }
-
- else
- {
+
+ /* Copy the appropriate bitmap into the target DC. If the
+ check-box bitmap is larger than the default check-mark
+ bitmap, use StretchBlt to make it fit; otherwise, just
+ copy it. */
+ if (((rc.right - rc.left) > (int) wBitmapX) ||
+ ((rc.bottom - rc.top) > (int) wBitmapY)) {
+ StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY,
+ hdcSource, rc.left, rc.top, rc.right - rc.left,
+ rc.bottom - rc.top, SRCCOPY);
+ }
+
+ else {
// Center it vertically
WORD dy = (wMenuH > wBitmapY) ? (wMenuH - wBitmapY) / 2 : 0;
BitBlt(hdcTarget, 0, dy, rc.right - rc.left,
- rc.bottom - rc.top,
- hdcSource, rc.left, rc.top, SRCCOPY);
- }
-
- /* Select the old source and destination bitmaps into the
- source and destination DCs, and then delete the DCs and
- the background brush. */
-
- SelectObject(hdcSource, hbmpSourceOld);
- SelectObject(hdcTarget, hbrTargetOld);
- hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld);
-
- DeleteObject(hbrBackground);
- DeleteObject(hdcSource);
- DeleteObject(hdcTarget);
-
- /* Return a handle to the new check-mark bitmap. */
-
- return hbmpCheck;
-}
+ rc.bottom - rc.top,
+ hdcSource, rc.left, rc.top, SRCCOPY);
+ }
+
+ /* Select the old source and destination bitmaps into the
+ source and destination DCs, and then delete the DCs and
+ the background brush. */
+
+ SelectObject(hdcSource, hbmpSourceOld);
+ SelectObject(hdcTarget, hbrTargetOld);
+ hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld);
+
+ DeleteObject(hbrBackground);
+ DeleteObject(hdcSource);
+ DeleteObject(hdcTarget);
+
+ /* Return a handle to the new check-mark bitmap. */
+
+ return hbmpCheck;
+}
void mswCreateCheckBitmaps()
{
@@ -489,12 +496,12 @@ void mswCreateCheckBitmaps()
}
wMenuRadio_p wMenuRadioCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wMenuCallBack_p action,
- void *data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wMenuCallBack_p action,
+ void *data )
{
wMenuRadio_p mi;
int rc;
@@ -538,8 +545,9 @@ wMenuRadio_p wMenuRadioCreate(
ac = tolower( ac );
}
vk = VkKeyScan( ac );
- if ( vk & 0xFF00 )
+ if ( vk & 0xFF00 ) {
modifier |= WKEY_SHIFT;
+ }
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mi;
}
@@ -547,7 +555,8 @@ wMenuRadio_p wMenuRadioCreate(
/* add the correct bitmaps for radio buttons */
- rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio, checkedRadio );
+ rc = SetMenuItemBitmaps(m->menu, mi->index, FALSE, uncheckedRadio,
+ checkedRadio );
if( m->radioGroup == NULL ) {
m->radioGroup = malloc( sizeof( struct radioButtonGroup ));
@@ -564,25 +573,26 @@ void wMenuRadioSetActive(wMenuRadio_p mi )
{
BOOL rc;
- rc = CheckMenuRadioItem( mi->mparent->menu,
- mi->mparent->radioGroup->firstButton,
- mi->mparent->radioGroup->lastButton,
- mi->index,
- MF_BYCOMMAND );
-}
+ rc = CheckMenuRadioItem( mi->mparent->menu,
+ mi->mparent->radioGroup->firstButton,
+ mi->mparent->radioGroup->lastButton,
+ mi->index,
+ MF_BYCOMMAND );
+}
wMenuPush_p wMenuPushCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wMenuCallBack_p action,
- void *data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wMenuCallBack_p action,
+ void *data )
{
wMenuPush_p mi;
int rc;
- char *label = malloc(strlen(labelStr) + 30 ); /**< The label and sufficient space for the keyboard shortcut */
+ char *label = malloc(strlen(labelStr) +
+ 30 ); /**< The label and sufficient space for the keyboard shortcut */
char *cp;
char ac;
UINT vk;
@@ -622,8 +632,9 @@ wMenuPush_p wMenuPushCreate(
ac = tolower( ac );
}
vk = VkKeyScan( ac );
- if ( vk & 0xFF00 )
+ if ( vk & 0xFF00 ) {
modifier |= WKEY_SHIFT;
+ }
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
acclTable(acclTable_da.cnt-1).mp = mi;
}
@@ -634,19 +645,19 @@ wMenuPush_p wMenuPushCreate(
void wMenuPushEnable(
- wMenuPush_p mi,
- BOOL_T enable )
+ wMenuPush_p mi,
+ BOOL_T enable )
{
EnableMenuItem( mi->mparent->menu, mi->index,
- MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
+ MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
mi->enabled = enable;
}
wMenu_p wMenuMenuCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr )
{
wMenu_p mm;
int rc;
@@ -657,13 +668,14 @@ wMenu_p wMenuMenuCreate(
/*mm->parent = (wControl_p)m;*/
mm->first = mm->last = NULL;
- rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu), mm->labelStr );
+ rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu),
+ mm->labelStr );
return mm;
}
void wMenuSeparatorCreate(
- wMenu_p m )
+ wMenu_p m )
{
int rc;
createMenuItem( m, M_SEPARATOR, NULL, NULL, sizeof *(wMenuItem_p)NULL );
@@ -680,8 +692,8 @@ void wMenuSeparatorCreate(
static void appendItem(
- wMenuListItem_p ml,
- wMenuListItem_p mi )
+ wMenuListItem_p ml,
+ wMenuListItem_p mi )
{
mi->right = ml->right;
ml->right->left = mi;
@@ -691,7 +703,7 @@ static void appendItem(
static void removeItem(
- wMenuListItem_p mi )
+ wMenuListItem_p mi )
{
mi->left->right = mi->right;
mi->right->left = mi->left;
@@ -700,10 +712,10 @@ static void removeItem(
wMenuList_p wMenuListCreate(
- wMenu_p m,
- const char * helpStr,
- int max,
- wMenuListCallBack_p action )
+ wMenu_p m,
+ const char * helpStr,
+ int max,
+ wMenuListCallBack_p action )
{
wMenuList_p mi;
mi = (wMenuList_p)createMenuItem( m, M_LIST, helpStr, NULL, sizeof *mi );
@@ -729,8 +741,9 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml )
count++;
break;
case M_LIST:
- if (mi == (wMenuItem_p)ml)
+ if (mi == (wMenuItem_p)ml) {
return count;
+ }
count += ((wMenuList_p)mi)->count;
break;
default:
@@ -742,10 +755,10 @@ int getMlistOrigin( wMenu_p m, wMenuList_p ml )
void wMenuListAdd(
- wMenuList_p ml,
- int index,
- const char * labelStr,
- void * data )
+ wMenuList_p ml,
+ int index,
+ const char * labelStr,
+ void * data )
{
int origin;
wMenuListItem_p wl_p;
@@ -754,7 +767,8 @@ void wMenuListAdd(
int rc;
origin = getMlistOrigin(ml->mlparent, ml);
- for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) {
+ for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml;
+ count++,wl_p=wl_p->right ) {
if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) {
/* move item */
if (count != index) {
@@ -772,34 +786,37 @@ void wMenuListAdd(
removeItem( ml->left );
add:
ml->count--;
- if (wl_p->labelStr )
+ if (wl_p->labelStr ) {
free( CAST_AWAY_CONST wl_p->labelStr );
+ }
wl_p->labelStr = mswStrdup( labelStr );
} else {
wl_p = (wMenuListItem_p)createMenuItem( NULL, M_LISTITEM, NULL,
- labelStr, sizeof *wl_p );
+ labelStr, sizeof *wl_p );
}
((wMenuListItem_p)wl_p)->data = data;
((wMenuListItem_p)wl_p)->action = ml->action;
- if (index < 0 || index > ml->count)
+ if (index < 0 || index > ml->count) {
index = ml->count;
+ }
for ( mi=(wMenuListItem_p)ml,count=0; count<index; mi=mi->right,count++);
rc = InsertMenu( ml->mlparent->menu, origin+index,
- MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr );
+ MF_BYPOSITION|MF_STRING, wl_p->index, wl_p->labelStr );
appendItem( mi, wl_p );
ml->count++;
}
void wMenuListDelete(
- wMenuList_p ml,
- const char * labelStr )
+ wMenuList_p ml,
+ const char * labelStr )
{
int origin, count;
wMenuListItem_p wl_p;
origin = getMlistOrigin(ml->mlparent, ml);
- for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml; count++,wl_p=wl_p->right ) {
+ for ( count=0,wl_p=ml->right; wl_p!=(wMenuListItem_p)ml;
+ count++,wl_p=wl_p->right ) {
if (wl_p->labelStr != NULL && strcmp( labelStr, wl_p->labelStr ) == 0) {
/* delete item */
mswUnregister( wl_p->index );
@@ -814,27 +831,30 @@ void wMenuListDelete(
const char * wMenuListGet(
- wMenuList_p ml,
- int index,
- void ** data )
+ wMenuList_p ml,
+ int index,
+ void ** data )
{
int origin, count;
wMenuListItem_p wl_p;
- if (index >= ml->count)
+ if (index >= ml->count) {
return NULL;
+ }
origin = getMlistOrigin(ml->mlparent, ml);
for ( count=0,wl_p=ml->right; wl_p&&count<index; count++,wl_p=wl_p->right );
- if (wl_p==NULL)
+ if (wl_p==NULL) {
return NULL;
- if ( data )
+ }
+ if ( data ) {
*data = wl_p->data;
+ }
return wl_p->labelStr;
}
void wMenuListClear(
- wMenuList_p ml )
+ wMenuList_p ml )
{
int origin, count;
wMenuListItem_p wl_p, wl_q;
@@ -854,13 +874,13 @@ void wMenuListClear(
wMenuToggle_p wMenuToggleCreate(
- wMenu_p m,
- const char * helpStr,
- const char * labelStr,
- long acclKey,
- wBool_t set,
- wMenuCallBack_p action,
- void * data )
+ wMenu_p m,
+ const char * helpStr,
+ const char * labelStr,
+ long acclKey,
+ wBool_t set,
+ wMenuCallBack_p action,
+ void * data )
{
wMenuToggle_p mt;
int rc;
@@ -870,7 +890,8 @@ wMenuToggle_p wMenuToggleCreate(
UINT vk;
long modifier;
- mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, sizeof *mt );
+ mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr,
+ sizeof *mt );
/*setAcclKey( m->parent, m->menu, mt->menu_item, acclKey );*/
mt->action = action;
mt->data = data;
@@ -911,8 +932,9 @@ wMenuToggle_p wMenuToggleCreate(
ac = tolower( ac );
}
vk = VkKeyScan( ac );
- if ( vk & 0xFF00 )
+ if ( vk & 0xFF00 ) {
modifier |= WKEY_SHIFT;
+ }
acclTable(acclTable_da.cnt-1).acclKey = (modifier<<8) | (vk&0x00FF);
acclTable(acclTable_da.cnt-1).mp = (wMenuPush_p)mt;
}
@@ -924,30 +946,33 @@ wMenuToggle_p wMenuToggleCreate(
wBool_t wMenuToggleGet(
- wMenuToggle_p mt )
+ wMenuToggle_p mt )
{
- return (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0;
+ return (GetMenuState( mt->mparent->menu, mt->index,
+ MF_BYCOMMAND ) & MF_CHECKED) != 0;
}
wBool_t wMenuToggleSet(
- wMenuToggle_p mt,
- wBool_t set )
+ wMenuToggle_p mt,
+ wBool_t set )
{
wBool_t rc;
- CheckMenuItem( mt->mparent->menu, mt->index, MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) );
- rc = (GetMenuState( mt->mparent->menu, mt->index, MF_BYCOMMAND ) & MF_CHECKED) != 0;
+ CheckMenuItem( mt->mparent->menu, mt->index,
+ MF_BYCOMMAND|(set?MF_CHECKED:MF_UNCHECKED) );
+ rc = (GetMenuState( mt->mparent->menu, mt->index,
+ MF_BYCOMMAND ) & MF_CHECKED) != 0;
return rc;
}
void wMenuToggleEnable(
- wMenuToggle_p mt,
- wBool_t enable )
+ wMenuToggle_p mt,
+ wBool_t enable )
{
EnableMenuItem( mt->mparent->menu, mt->index,
- MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
+ MF_BYCOMMAND|(enable?MF_ENABLED:(MF_DISABLED|MF_GRAYED)) );
mt->enabled = enable;
-}
+}
/*
*****************************************************************************
@@ -959,39 +984,40 @@ void wMenuToggleEnable(
void mswMenuMove(
- wMenu_p m,
- wWinPix_t x,
- wWinPix_t y )
+ wMenu_p m,
+ wWinPix_t x,
+ wWinPix_t y )
{
wControl_p b;
b = (wControl_p)m->parent;
if (b && b->hWnd)
if (!SetWindowPos( b->hWnd, HWND_TOP, x, y,
- CW_USEDEFAULT, CW_USEDEFAULT,
- SWP_NOSIZE|SWP_NOZORDER))
- mswFail("mswMenuMove");
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ SWP_NOSIZE|SWP_NOZORDER)) {
+ mswFail("mswMenuMove");
+ }
}
static void pushMenuButt(
- void * data )
+ void * data )
{
wMenu_p m = (wMenu_p)data;
RECT rect;
mswAllowBalloonHelp = FALSE;
GetWindowRect( m->hWnd, &rect );
TrackPopupMenu( m->menu, TPM_LEFTALIGN, rect.left, rect.bottom,
- 0, ((wControl_p)(m->parent))->hWnd, NULL );
+ 0, ((wControl_p)(m->parent))->hWnd, NULL );
}
wMenu_p wMenuCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option )
{
wMenu_p m;
wControl_p b;
@@ -1004,7 +1030,7 @@ wMenu_p wMenuCreate(
}
m = (wMenu_p)createMenuItem( NULL, M_MENU, helpStr, label, sizeof *m );
m->button = wButtonCreate( parent, x, y, helpStr, labelStr,
- buttOption, 0, pushMenuButt, (void*)m );
+ buttOption, 0, pushMenuButt, (void*)m );
b = (wControl_p)m->button;
m->parent = b->parent;
m->x = b->x;
@@ -1023,9 +1049,9 @@ wMenu_p wMenuCreate(
wMenu_p wMenuBarAdd(
- wWin_p w,
- const char * helpStr,
- const char * labelStr )
+ wWin_p w,
+ const char * helpStr,
+ const char * labelStr )
{
HMENU menu;
wMenu_p m;
@@ -1043,7 +1069,8 @@ wMenu_p wMenuBarAdd(
m->mmtype = MM_BAR;
m->first = m->last = NULL;
- rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu), labelStr );
+ rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu),
+ labelStr );
DrawMenuBar( ((wControl_p)w)->hWnd );
return m;
@@ -1052,8 +1079,8 @@ wMenu_p wMenuBarAdd(
wMenu_p wMenuPopupCreate(
- wWin_p w,
- const char * labelStr )
+ wWin_p w,
+ const char * labelStr )
{
wMenu_p m;
long buttOption = 0;
@@ -1083,21 +1110,21 @@ void wMenuPopupShow( wMenu_p mp )
GetCursorPos( &pt );
TrackPopupMenu( mp->menu, TPM_LEFTALIGN, pt.x, pt.y, 0, mp->hWnd, NULL );
}
-
+
/*-----------------------------------------------------------------*/
void wMenuSetTraceCallBack(
- wMenu_p m,
- wMenuTraceCallBack_p func,
- void * data )
+ wMenu_p m,
+ wMenuTraceCallBack_p func,
+ void * data )
{
m->traceFunc = func;
m->traceData = data;
}
wBool_t wMenuAction(
- wMenu_p m,
- const char * label )
+ wMenu_p m,
+ const char * label )
{
wMenuItem_p mi;
wMenuToggle_p mt;
@@ -1108,10 +1135,11 @@ wBool_t wMenuAction(
case M_SEPARATOR:
break;
case M_PUSH:
- if ( ((wMenuPush_p)mi)->enabled == FALSE )
+ if ( ((wMenuPush_p)mi)->enabled == FALSE ) {
wBeep();
- else
+ } else {
((wMenuPush_p)mi)->action( ((wMenuPush_p)mi)->data );
+ }
break;
case M_TOGGLE:
mt = (wMenuToggle_p)mi;
diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c
index 5b45e2b..4bf9481 100644
--- a/app/wlib/mswlib/mswmisc.c
+++ b/app/wlib/mswlib/mswmisc.c
@@ -17,14 +17,14 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <shellapi.h>
#include <string.h>
-#include <malloc.h>
+#include <malloc.h> // required for heapinfo in function wMemStats
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -61,8 +61,8 @@ const char * GetCurCommandName(void);
#define LABELFONTRESET
#else
#define LABELFONTDECL HFONT hFont;
-#define LABELFONTRESET if (!mswThickFont) {SelectObject( hDc, hFont );}
-#define LABELFONTSELECT if (!mswThickFont) {hFont = SelectObject( hDc, mswLabelFont );}
+#define LABELFONTRESET SelectObject( hDc, hFont );
+#define LABELFONTSELECT hFont = SelectObject( hDc, mswLabelFont );
#endif
/*
@@ -78,13 +78,8 @@ int mswEditHeight;
int mswAllowBalloonHelp = TRUE;
HFONT mswOldTextFont;
HFONT mswLabelFont;
-/** @prefs [msw tweak] ThickFont=1 */
-long mswThickFont = 1;
double mswScale = 1.0;
-/** @prefs [Preference] LargeIcons=1.5 Set toolbar icon scaling. Limited 1.0 to 2.0 */
-double scaleIcon = 1.0; /** Scaling factor for toolbar icons */
-
callBacks_t *mswCallBacks[CALLBACK_CNT];
void closeBalloonHelp(int inx);
@@ -101,12 +96,12 @@ extern FILE * logFile;
*/
struct wWin_t {
- WOBJ_COMMON
- int validGeometry;
- int min_width;
- int max_width;
- int min_height;
- int max_height;
+ WOBJ_COMMON
+ int validGeometry;
+ int min_width;
+ int max_width;
+ int min_height;
+ int max_height;
wWinPix_t lastX, lastY;
wWinPix_t padX, padY;
wControl_p first, last;
@@ -177,8 +172,6 @@ char *mswProfileFile;
static wBalloonHelp_t * balloonHelpStrings;
-static wCursor_t curCursor = wCursorNormal;
-
#ifdef HELPSTR
static FILE * helpStrF;
#endif
@@ -193,18 +186,20 @@ extern char *userLocale;
// list of supported fileformats for image files
static char * filterImageFiles[] = { N_("All image files"),
- "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff",
- N_("GIF files (*.gif)"),
- "*.gif",
- N_("JPEG files (*.jpeg,*.jpg)"),
- "*.jpg;*.jpeg",
- N_("PNG files (*.png)"),
- "*.png",
- N_("TIFF files (*.tiff, *.tif)"),
- "*.tif;*.tiff",
- N_("All files (*)"),
- "*",
- };
+ "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff",
+ N_("GIF files (*.gif)"),
+ "*.gif",
+ N_("JPEG files (*.jpeg,*.jpg)"),
+ "*.jpg;*.jpeg",
+ N_("PNG files (*.png)"),
+ "*.png",
+ N_("TIFF files (*.tiff, *.tif)"),
+ "*.tif;*.tiff",
+ N_("All files (*)"),
+ "*",
+ };
+
+static HICON hWindowIcon;
/*
*****************************************************************************
@@ -308,7 +303,8 @@ void mswRepaintLabel(HWND hWnd, wControl_p b)
LABELFONTSELECT
newBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
oldBrush = SelectObject(hDc, newBrush);
- dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (int)(strlen(b->labelStr)));
+ dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr,
+ (int)(strlen(b->labelStr)));
rect.left = b->labelX;
rect.top = b->labelY;
rect.right = b->labelX + LOWORD(dw);
@@ -318,7 +314,8 @@ void mswRepaintLabel(HWND hWnd, wControl_p b)
/*SetBkMode( hDc, OPAQUE );*/
SetBkColor(hDc, GetSysColor(COLOR_BTNFACE));
- if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, (int)(strlen(b->labelStr)))) {
+ if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr,
+ (int)(strlen(b->labelStr)))) {
mswFail("Repainting text label");
}
@@ -381,8 +378,8 @@ void * mswAlloc(
w->data = data;
w->focusChainNext = NULL;
w->shown = TRUE;
- w->hilite = FALSE;
- w->errStr = NULL;
+ w->hilite = FALSE;
+ w->errStr = NULL;
return w;
}
@@ -587,29 +584,27 @@ static void getSavedSizeAndPos(
if ((option&F_RECALLPOS) && nameStr) {
int x, y, w, h;
- int xadj, yadj;
+ int xadj, yadj;
const char *cp;
int state;
- w = h = 0;
- xadj = 1;
- yadj = mTitleH + 1;
- if (option & F_RESIZE) {
- xadj += mResizeBorderW * 2;
- yadj += mResizeBorderH * 2;
- }
- else
- {
- xadj += mFixBorderW * 2;
- yadj += mFixBorderH * 2;
- }
- //if (option & F_MENUBAR) {
- // yadj += mMenuH;
- //}
+ w = h = 0;
+ xadj = 1;
+ yadj = mTitleH + 1;
+ if (option & F_RESIZE) {
+ xadj += mResizeBorderW * 2;
+ yadj += mResizeBorderH * 2;
+ } else {
+ xadj += mFixBorderW * 2;
+ yadj += mFixBorderH * 2;
+ }
+ //if (option & F_MENUBAR) {
+ // yadj += mMenuH;
+ //}
if ((option & F_RESIZE) &&
(cp = wPrefGetStringBasic("msw window size", nameStr)) &&
- (state = (int)strtol(cp, &cq, 10), cp != cq) && // state is not used
+ (state = (int)strtol(cp, &cq, 10), cp != cq) && // state is not used
(cp = cq, w = (wWinPix_t)(strtod(cp, &cq)), cp != cq) &&
(cp = cq, h = (wWinPix_t)(strtod(cp, &cq)), cp != cq)
) {
@@ -645,6 +640,11 @@ static void getSavedSizeAndPos(
x = 0;
}
+ // Make sure we can see the dialog
+ xadj += 100;
+ yadj += 100;
+
+
if (y + h > screenHeight - yadj) {
y = screenHeight - yadj - h;
}
@@ -660,7 +660,7 @@ static void getSavedSizeAndPos(
}
/**
- * Set min and max dimensions for a window.
+ * Set min and max dimensions for a window.
*
* \param min_width IN minimum width of window
* \param max_width IN maximum width of window
@@ -671,21 +671,21 @@ static void getSavedSizeAndPos(
* \param aspect_ration IN unused on Windows
*/
void wSetGeometry(wWin_p win,
- wWinPix_t min_width,
- wWinPix_t max_width,
- wWinPix_t min_height,
- wWinPix_t max_height,
- wWinPix_t base_width,
- wWinPix_t base_height,
- double aspect_ratio)
+ wWinPix_t min_width,
+ wWinPix_t max_width,
+ wWinPix_t min_height,
+ wWinPix_t max_height,
+ wWinPix_t base_width,
+ wWinPix_t base_height,
+ double aspect_ratio)
{
- win->validGeometry = TRUE; //remember that geometry was set
- win->min_width = min_width;
- win->max_width = max_width;
- win->min_height = min_height;
- win->max_height = max_height;
+ win->validGeometry = TRUE; //remember that geometry was set
+ win->min_width = min_width;
+ win->max_width = max_width;
+ win->min_height = min_height;
+ win->max_height = max_height;
- return;
+ return;
}
/**
@@ -695,13 +695,13 @@ void wSetGeometry(wWin_p win,
* \param typ IN type of window (W_MAIN or W_POPUP)
* \param option IN options for window creation
* \param classname IN pre-registered window class
- * \param style IN
+ * \param style IN
* \param labelStr IN window title
* \param winProc IN callback procedure
* \param w IN default window width
* \param h IN default window height
* \param data IN ??
- * \param nameStr IN name of window
+ * \param nameStr IN name of window
* \param pShowCmd IN/OUT window show option (maximize or show normal)
* \return window data structure
*/
@@ -740,7 +740,7 @@ static wWin_p winCommonCreate(
if (typ == W_MAIN) {
*pShowCmd = ((option & F_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
} else {
- *pShowCmd = SW_HIDE; //Make sure to hide first
+ *pShowCmd = SW_HIDE; //Make sure to hide first
}
if (xx != CW_USEDEFAULT) {
@@ -800,6 +800,10 @@ static wWin_p winCommonCreate(
win->nameStr = mswStrdup(nameStr);
+ //HICON hIcon1 = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(101), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
+ SendMessage(win->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon);
+ SendMessage(win->hWnd, WM_SETICON, ICON_BIG, (LPARAM)hWindowIcon);
+
if (typ == W_MAIN) {
mswInitColorPalette();
}
@@ -850,7 +854,7 @@ wWin_p wWinMainCreate(
TEXTMETRIC tm;
char *pos;
char * configName;
- long maximize;
+ long maximize;
/* check for configuration name */
if (pos = strchr(name, ';')) {
@@ -887,14 +891,9 @@ wWin_p wWinMainCreate(
/* length of path + \ + length of filename + . + length of extension + \0 */
helpFile = (char*)malloc(strlen(libDir) + 1 + strlen(appName) + 1 + 3 + 1);
wsprintf(helpFile, "%s\\%s.chm", libDir, appName);
- wPrefGetInteger("msw tweak", "ThickFont", &mswThickFont, 0);
-
- wPrefGetInteger("draw", "maximized", &maximize, 0L);
- option |= (maximize ? F_MAXIMIZE : 0);
- wPrefGetFloat(PREFSECTION, LARGEICON, &scaleIcon, 1.0);
- if (scaleIcon < 1.0) scaleIcon = 1.0;
- if (scaleIcon > 2.0) scaleIcon = 2.0;
+ wPrefGetInteger("draw", "maximized", &maximize, 0L);
+ option |= (maximize ? F_MAXIMIZE : 0);
showCmd = SW_SHOW;
w = winCommonCreate(NULL, W_MAIN, option|F_RESIZE, "MswMainWindow",
@@ -902,18 +901,11 @@ wWin_p wWinMainCreate(
nameStr, &showCmd);
mswHWnd = w->hWnd;
- //HICON hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(0), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
- //HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(0));
- //SendMessage(mswHWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
- //SendMessage(mswHWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
-
- if (!mswThickFont) {
- SendMessage(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0);
- hDc = GetDC(mswHWnd);
- GetTextMetrics(hDc, &tm);
- mswEditHeight = tm.tmHeight+2;
- ReleaseDC(mswHWnd, hDc);
- }
+ SendMessage(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0);
+ hDc = GetDC(mswHWnd);
+ GetTextMetrics(hDc, &tm);
+ mswEditHeight = tm.tmHeight+2;
+ ReleaseDC(mswHWnd, hDc);
ShowWindow(mswHWnd, showCmd);
UpdateWindow(mswHWnd);
@@ -1257,19 +1249,19 @@ static void savePos(wWin_p win)
if (win->nameStr &&
IsWindowVisible(win->hWnd) /*&& !IsIconic( win->hWnd )*/) {
- GetWindowRect(win->hWnd, &rect);
+ GetWindowRect(win->hWnd, &rect);
- if (win->option&F_RECALLPOS) {
+ if (win->option&F_RECALLPOS) {
char posStr[20];
- wsprintf(posStr, "%d %d",
- rect.left,
- rect.top);
- wPrefSetString("msw window pos", win->nameStr, posStr);
+ wsprintf(posStr, "%d %d",
+ rect.left,
+ rect.top);
+ wPrefSetString("msw window pos", win->nameStr, posStr);
if (win->option&F_RESIZE) {
- GetClientRect(win->hWnd, &rect);
- w = rect.right - rect.left;
- h = rect.bottom - rect.top;
+ GetClientRect(win->hWnd, &rect);
+ w = rect.right - rect.left;
+ h = rect.bottom - rect.top;
wsprintf(posStr, "%d %d %d",
0, // unused
w, h);
@@ -1311,9 +1303,10 @@ void wWinShow(
win->centerWin = FALSE;
win->shown = TRUE;
- // Clear hilites
- for (wControl_p controlP = win->first; controlP; controlP = controlP->next)
- controlP->hilite = FALSE;
+ // Clear hilites
+ for (wControl_p controlP = win->first; controlP; controlP = controlP->next) {
+ controlP->hilite = FALSE;
+ }
if (mswHWnd == (HWND)0 || !IsIconic(mswHWnd)) {
ShowWindow(win->hWnd, SW_SHOW);
@@ -1459,73 +1452,6 @@ void wWinClear(
{
}
-extern long dontHideCursor;
-
-void wSetCursor(wDraw_p win,
- wCursor_t cursor)
-{
- switch (cursor) {
- case wCursorNormal:
- default:
- SetCursor(LoadCursor(NULL, IDC_ARROW));
- break;
-
- case wCursorWait:
- SetCursor(LoadCursor(NULL, IDC_WAIT));
- break;
-
- case wCursorCross:
- SetCursor(LoadCursor(NULL, IDC_CROSS));
- break;
-
- case wCursorIBeam:
- SetCursor(LoadCursor(NULL, IDC_IBEAM));
- break;
-
- case wCursorQuestion:
- SetCursor(LoadCursor(NULL, IDC_HELP));
- break;
-
- case wCursorHand:
- SetCursor(LoadCursor(NULL, IDC_HAND));
- break;
-
- case wCursorNo:
- SetCursor(LoadCursor(NULL, IDC_NO));
- break;
-
- case wCursorSizeAll:
- SetCursor(LoadCursor(NULL, IDC_SIZEALL));
- break;
-
- case wCursorSizeNESW:
- SetCursor(LoadCursor(NULL, IDC_SIZENESW));
- break;
-
- case wCursorSizeNWSE:
- SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
- break;
-
- case wCursorSizeNS:
- SetCursor(LoadCursor(NULL, IDC_SIZENS));
- break;
-
- case wCursorSizeWE:
- SetCursor(LoadCursor(NULL, IDC_SIZEWE));
- break;
-
- case wCursorAppStart:
- SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
- break;
-
- case wCursorNone:
- if (!dontHideCursor)
- SetCursor(NULL);
- break;
- }
-
- curCursor = cursor;
-}
void wWinDoCancel(wWin_p win)
{
@@ -1821,34 +1747,36 @@ void wControlHilite(
HDC hDc;
HPEN oldPen, newPen;
int oldMode;
- LOGBRUSH logBrush = { BS_SOLID, CONTROLHILITECOLOR, (ULONG_PTR)NULL };
+ LOGBRUSH logBrush = { BS_SOLID, CONTROLHILITECOLOR, (ULONG_PTR)NULL };
if (b == NULL) {
return;
}
- if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd)) || (!IsWindowVisible(b->hWnd))) {
- b->hilite = FALSE;
+ if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd))
+ || (!IsWindowVisible(b->hWnd))) {
+ b->hilite = FALSE;
return;
}
- if (b->hilite == hilite)
- return;
- b->hilite = hilite;
+ if (b->hilite == hilite) {
+ return;
+ }
+ b->hilite = hilite;
hDc = GetDC(b->parent->hWnd);
- newPen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND | PS_JOIN_BEVEL,
- CONTROLHILITEWIDTH,
- &logBrush,
- 0,
- NULL);
+ newPen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND | PS_JOIN_BEVEL,
+ CONTROLHILITEWIDTH,
+ &logBrush,
+ 0,
+ NULL);
oldPen = SelectObject(hDc, newPen);
oldMode = SetROP2(hDc, R2_NOTXORPEN);
- Rectangle(hDc,
- b->x - CONTROLHILITEWIDTH - 1,
- b->y - CONTROLHILITEWIDTH - 1,
- b->x + b->w + CONTROLHILITEWIDTH + 1,
- b->y + b->h + CONTROLHILITEWIDTH + 1);
+ Rectangle(hDc,
+ b->x - CONTROLHILITEWIDTH - 1,
+ b->y - CONTROLHILITEWIDTH - 1,
+ b->x + b->w + CONTROLHILITEWIDTH + 1,
+ b->y + b->h + CONTROLHILITEWIDTH + 1);
SetROP2(hDc, oldMode);
SelectObject(hDc, oldPen);
DeleteObject(newPen);
@@ -1893,23 +1821,23 @@ void wMessage(
/**
* Open a document using an external application
- *
+ *
* \param file
* \return TRUE on success, FALSE on error
- *
+ *
*/
unsigned wOpenFileExternal(char *file)
{
- HINSTANCE res;
+ HINSTANCE res;
- res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW);
+ res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW);
- if ((UINT_PTR)res <= 32) {
- wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL);
- return(FALSE);
- }
+ if ((UINT_PTR)res <= 32) {
+ wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL);
+ return(FALSE);
+ }
- return(TRUE);
+ return(TRUE);
}
void wExit(int rc)
@@ -1933,9 +1861,9 @@ void wExit(int rc)
}
}
- wPrefFlush("");
+ wPrefFlush("");
- for (inx=controlMap_da.cnt-1; inx>=0; inx--) {
+ for (inx=controlMap_da.cnt-1; inx>=0; inx--) {
b = controlMap(inx).b;
if (b != NULL) {
@@ -1948,7 +1876,7 @@ void wExit(int rc)
controlMap(inx).b = NULL;
}
- deleteBitmaps();
+ deleteBitmaps();
if (mswOldTextFont != (HFONT)0) {
DeleteObject(mswOldTextFont);
@@ -2187,7 +2115,7 @@ int wNotice3(
}
/**
- * Show help text for the given topic.
+ * Show help text for the given topic.
*
* \param topic The topic. if NULL the index page is shown.
*/
@@ -2197,11 +2125,11 @@ void wHelp(
{
char *pszHelpTopic;
HWND hwndHelp;
- const char *theTopic = "index";
+ const char *theTopic = "index";
- if (topic) {
- theTopic = topic;
- }
+ if (topic) {
+ theTopic = topic;
+ }
if (!helpInitted) {
HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ;
@@ -2235,7 +2163,7 @@ void doHelpMenu(void * context)
helpInitted = TRUE;
}
- const char * topic;
+ const char * topic;
switch ((int)(INT_PTR)context) {
case 1: /* Contents */
HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL);
@@ -2253,9 +2181,9 @@ void doHelpMenu(void * context)
case 3: /*Context*/
- topic = GetCurCommandName();
- wHelp(topic);
- break;
+ topic = GetCurCommandName();
+ wHelp(topic);
+ break;
default:
return;
@@ -2264,8 +2192,9 @@ void doHelpMenu(void * context)
helpInitted = TRUE;
}
-void wDoAccelHelp(wAccelKey_e key, void * context) {
- doHelpMenu(context);
+void wDoAccelHelp(wAccelKey_e key, void * context)
+{
+ doHelpMenu(context);
}
void wMenuAddHelp(
@@ -2301,126 +2230,133 @@ void wControlSetBalloonText(wControl_p b, const char * text)
void openBalloonHelp(wControl_p b, int dx, int dy)
{
- HDC hDc;
- DWORD extent;
- RECT rect;
- POINT pt;
- HFONT hFont;
- const char * msg;
- if (b->errStr) {
- msg = b->errStr;
- }
- else {
- msg = b->tipStr;
- if (!balloonHelpEnable) {
+ HDC hDc;
+ DWORD extent;
+ RECT rect;
+ POINT pt;
+ HFONT hFont;
+ const char * msg;
+ if (b->errStr) {
+ msg = b->errStr;
+ } else {
+ msg = b->tipStr;
+ if (!balloonHelpEnable) {
#ifdef BALLOON_TRACE
- fprintf(logFile, "openBalloon !Enable state %d\n", balloonHelpState); fflush(logFile);
+ fprintf(logFile, "openBalloon !Enable state %d\n", balloonHelpState);
+ fflush(logFile);
#endif
- return;
- }
- }
+ return;
+ }
+ }
#ifdef BALLOON_TRACE
- fprintf(logFile, "openBalloon %s state %d\n", msg, balloonHelpState); fflush(logFile);
+ fprintf(logFile, "openBalloon %s state %d\n", msg, balloonHelpState);
+ fflush(logFile);
#endif
- if (!balloonHelpHWnd)
- return;
- int w, h;
- hDc = GetDC(balloonHelpHWnd);
- hFont = SelectObject(hDc, mswLabelFont);
- extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, (int)(strlen(msg)));
- w = LOWORD(extent);
- h = HIWORD(extent);
-
- if (b->type == B_RADIO ||
- b->type == B_TOGGLE) {
- pt.y = b->h;
- }
- else {
- GetClientRect(b->hWnd, &rect);
- pt.y = rect.bottom;
- }
-
- pt.x = dx;
- pt.y -= dy;
- ClientToScreen(b->hWnd, &pt);
-
- if (pt.x + w + 2 > screenWidth) {
- pt.x = screenWidth - (w + 2);
- }
-
- if (pt.x < 0) {
- pt.x = 0;
- }
-
- SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w + 6, h + 4,
- SWP_SHOWWINDOW | SWP_NOACTIVATE);
- if (!b->errStr) {
- SetBkColor(hDc, GetSysColor(COLOR_INFOBK));
- SetTextColor(hDc, GetSysColor(COLOR_INFOTEXT));
- } else {
- SetBkColor(hDc, GetSysColor(COLOR_HIGHLIGHT));
- SetTextColor(hDc, GetSysColor(COLOR_HIGHLIGHTTEXT));
- }
- TextOut(hDc, 2, 1, msg, (int)(strlen(msg)));
- SelectObject(hDc, hFont);
- ReleaseDC(balloonHelpHWnd, hDc);
- balloonHelpState = balloonHelpShow;
- balloonControlButton = b;
+ if (!balloonHelpHWnd) {
+ return;
+ }
+ int w, h;
+ hDc = GetDC(balloonHelpHWnd);
+ hFont = SelectObject(hDc, mswLabelFont);
+ extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, (int)(strlen(msg)));
+ w = LOWORD(extent);
+ h = HIWORD(extent);
+
+ if (b->type == B_RADIO ||
+ b->type == B_TOGGLE) {
+ pt.y = b->h;
+ } else {
+ GetClientRect(b->hWnd, &rect);
+ pt.y = rect.bottom;
+ }
+
+ pt.x = dx;
+ pt.y -= dy;
+ ClientToScreen(b->hWnd, &pt);
+
+ if (pt.x + w + 2 > screenWidth) {
+ pt.x = screenWidth - (w + 2);
+ }
+
+ if (pt.x < 0) {
+ pt.x = 0;
+ }
+
+ SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w + 6, h + 4,
+ SWP_SHOWWINDOW | SWP_NOACTIVATE);
+ if (!b->errStr) {
+ SetBkColor(hDc, GetSysColor(COLOR_INFOBK));
+ SetTextColor(hDc, GetSysColor(COLOR_INFOTEXT));
+ } else {
+ SetBkColor(hDc, GetSysColor(COLOR_HIGHLIGHT));
+ SetTextColor(hDc, GetSysColor(COLOR_HIGHLIGHTTEXT));
+ }
+ TextOut(hDc, 2, 1, msg, (int)(strlen(msg)));
+ SelectObject(hDc, hFont);
+ ReleaseDC(balloonHelpHWnd, hDc);
+ balloonHelpState = balloonHelpShow;
+ balloonControlButton = b;
}
void startBalloonHelp(void)
{
- wBalloonHelp_t * bh;
-
- if (!balloonHelpButton->tipStr) {
- if (!balloonHelpStrings)
- return;
- for (bh = balloonHelpStrings; bh->name && strcmp(bh->name, balloonHelpButton->helpStr) != 0; bh++);
- if (!bh->name || !bh->value)
- balloonHelpButton->tipStr = _(balloonHelpButton->helpStr);
- else
- balloonHelpButton->tipStr = _(bh->value);
- }
+ wBalloonHelp_t * bh;
- openBalloonHelp(balloonHelpButton, 0, 0);
+ if (!balloonHelpButton->tipStr) {
+ if (!balloonHelpStrings) {
+ return;
+ }
+ for (bh = balloonHelpStrings; bh->name
+ && strcmp(bh->name, balloonHelpButton->helpStr) != 0; bh++);
+ if (!bh->name || !bh->value) {
+ balloonHelpButton->tipStr = _(balloonHelpButton->helpStr);
+ } else {
+ balloonHelpButton->tipStr = _(bh->value);
+ }
+ }
+
+ openBalloonHelp(balloonHelpButton, 0, 0);
}
void closeBalloonHelp(int inx)
{
#ifdef BALLOON_TRACE
- fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState); fflush(logFile);
+ fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState);
+ fflush(logFile);
#endif
- if (balloonHelpTimer) {
- KillTimer(mswHWnd, balloonHelpTimer);
- balloonHelpTimer = (UINT_PTR)0;
- }
+ if (balloonHelpTimer) {
+ KillTimer(mswHWnd, balloonHelpTimer);
+ balloonHelpTimer = (UINT_PTR)0;
+ }
- if (balloonHelpState == balloonHelpShow)
- if (balloonHelpHWnd) {
- ShowWindow(balloonHelpHWnd, SW_HIDE);
- }
+ if (balloonHelpState == balloonHelpShow)
+ if (balloonHelpHWnd) {
+ ShowWindow(balloonHelpHWnd, SW_HIDE);
+ }
- balloonHelpState = balloonHelpIdle;
+ balloonHelpState = balloonHelpIdle;
}
-void wControlSetBalloon(wControl_p b, wWinPix_t dx, wWinPix_t dy, const char * msg)
+void wControlSetBalloon(wControl_p b, wWinPix_t dx, wWinPix_t dy,
+ const char * msg)
{
- if (msg) {
- if (b->errStr)
- free(b->errStr);
- b->errStr = mswStrdup(msg);
- openBalloonHelp(b, dx, dy);
- }
- else {
- if (b->errStr)
- free(b->errStr);
- b->errStr = NULL;
- closeBalloonHelp(2);
- }
+ if (msg) {
+ if (b->errStr) {
+ free(b->errStr);
+ }
+ b->errStr = mswStrdup(msg);
+ openBalloonHelp(b, dx, dy);
+ } else {
+ if (b->errStr) {
+ free(b->errStr);
+ }
+ b->errStr = NULL;
+ closeBalloonHelp(2);
+ }
}
@@ -2482,19 +2418,20 @@ struct wFilSel_t {
char *
GetImageFileFormats(void)
{
- char *filter = malloc(2048);
- char *current = filter;
- char *message;
+ char *filter = malloc(2048);
+ char *current = filter;
+ char *message;
- for (int i = 0; i < sizeof(filterImageFiles) / sizeof(filterImageFiles[0]); i += 2) {
- message = gettext(filterImageFiles[i]);
- strcpy(current, message);
- current += strlen(message) + 1;
- strcpy(current, filterImageFiles[i + 1]);
- current += strlen(current) + 1;
- }
- *current = '\0';
- return(filter);
+ for (int i = 0; i < sizeof(filterImageFiles) / sizeof(filterImageFiles[0]);
+ i += 2) {
+ message = gettext(filterImageFiles[i]);
+ strcpy(current, message);
+ current += strlen(message) + 1;
+ strcpy(current, filterImageFiles[i + 1]);
+ current += strlen(current) + 1;
+ }
+ *current = '\0';
+ return(filter);
}
/**
@@ -2530,12 +2467,11 @@ int wFilSelect(
memset(&ofn, 0, sizeof ofn);
ofn.lStructSize = sizeof ofn;
ofn.hwndOwner = mswHWnd;
- if (fs->option == FS_PICTURES) {
- ofn.lpstrFilter = GetImageFileFormats();
- }
- else {
- ofn.lpstrFilter = fs->extList;
- }
+ if (fs->option == FS_PICTURES) {
+ ofn.lpstrFilter = GetImageFileFormats();
+ } else {
+ ofn.lpstrFilter = fs->extList;
+ }
ofn.nFilterIndex = 0;
selFileName = malloc(SELECTEDFILENAME_BUFFERSIZE);
@@ -2773,24 +2709,24 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HDC hDc;
wAccelKey_e extChar;
- LPMINMAXINFO pMMI;
+ LPMINMAXINFO pMMI;
switch (message) {
- case WM_GETMINMAXINFO:
- pMMI = (LPMINMAXINFO)lParam;
- inx = GetWindowWord(hWnd, 0);
-
- if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) {
- w = (wWin_p)controlMap(inx - CONTROL_BASE).b;
- if (w != NULL) {
- if (w->validGeometry) {
- pMMI->ptMaxTrackSize.x = w->max_width;
- pMMI->ptMaxTrackSize.y = w->max_height;
- pMMI->ptMinTrackSize.x = w->min_width;
- pMMI->ptMinTrackSize.y = w->min_height;
- }
- }
- }
- return (LRESULT)0;
+ case WM_GETMINMAXINFO:
+ pMMI = (LPMINMAXINFO)lParam;
+ inx = GetWindowWord(hWnd, 0);
+
+ if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) {
+ w = (wWin_p)controlMap(inx - CONTROL_BASE).b;
+ if (w != NULL) {
+ if (w->validGeometry) {
+ pMMI->ptMaxTrackSize.x = w->max_width;
+ pMMI->ptMaxTrackSize.y = w->max_height;
+ pMMI->ptMinTrackSize.x = w->min_width;
+ pMMI->ptMinTrackSize.y = w->min_height;
+ }
+ }
+ }
+ return (LRESULT)0;
case WM_MOUSEWHEEL:
inx = GetWindowWord(hWnd, 0);
@@ -2800,13 +2736,13 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (mswCallBacks[b->type] != NULL &&
mswCallBacks[b->type]->messageProc)
return mswCallBacks[b->type]->messageProc((wControl_p)b, hWnd,
- message, wParam, lParam);
+ message, wParam, lParam);
return (LRESULT)0;
- case WM_COMMAND:
+ case WM_COMMAND:
closeBalloonHelp(3);
- case WM_DRAWITEM:
+ case WM_DRAWITEM:
case WM_MEASUREITEM:
if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) {
@@ -2891,8 +2827,8 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case SIZE_MAXIMIZED:
case SIZE_MINIMIZED:
case SIZE_RESTORED:
- newW = LOWORD(lParam);
- newH = HIWORD(lParam);
+ newW = LOWORD(lParam);
+ newH = HIWORD(lParam);
if (newW <= 0 || newH <= 0) {
break;
@@ -2910,8 +2846,8 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (w->winProc) {
w->winProc(w, wResize_e, NULL, w->data);
- w->winProc(w, wState_e, NULL, w->data);
- }
+ w->winProc(w, wState_e, NULL, w->data);
+ }
break;
@@ -2939,7 +2875,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (mswCallBacks[w->type] != NULL &&
mswCallBacks[w->type]->messageProc)
return mswCallBacks[w->type]->messageProc((wControl_p)w, hWnd,
- message, wParam, lParam);
+ message, wParam, lParam);
break;
}
@@ -2961,14 +2897,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (b && b->type == B_DRAW) {
// Change Num keypad to a special code to emulate cursor keys
- if (wParam == VK_UP ||
- wParam == VK_DOWN ||
- wParam == VK_RIGHT ||
- wParam == VK_LEFT ||
- wParam == VK_INSERT ||
- wParam == VK_DELETE)
- {
- if ((lParam & 0x1000000) == 0) lParam |= 0x1000000;
+ if (wParam == VK_UP ||
+ wParam == VK_DOWN ||
+ wParam == VK_RIGHT ||
+ wParam == VK_LEFT ||
+ wParam == VK_INSERT ||
+ wParam == VK_DELETE) {
+ if ((lParam & 0x1000000) == 0) {
+ lParam |= 0x1000000;
+ }
}
return SendMessage(b->hWnd, WM_CHAR, wParam, lParam);
}
@@ -2984,7 +2921,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (mswCallBacks[B_BUTTON] != NULL &&
mswCallBacks[B_BUTTON]->messageProc) {
ret = mswCallBacks[B_BUTTON]->messageProc(b, b->hWnd,
- WM_COMMAND, wParam, lParam);
+ WM_COMMAND, wParam, lParam);
}
inMainWndProc = FALSE;
@@ -3004,7 +2941,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (mswCallBacks[B_BUTTON] != NULL &&
mswCallBacks[B_BUTTON]->messageProc) {
ret = mswCallBacks[B_BUTTON]->messageProc(b, b->hWnd,
- WM_COMMAND, wParam, lParam);
+ WM_COMMAND, wParam, lParam);
}
inMainWndProc = FALSE;
@@ -3027,7 +2964,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (mswCallBacks[b->type] != NULL &&
mswCallBacks[b->type]->messageProc) {
ret = mswCallBacks[b->type]->messageProc(b, b->hWnd,
- WM_COMMAND, MAKELPARAM(LOWORD(wParam), BN_CLICKED), (LPARAM)(b->hWnd));
+ WM_COMMAND, MAKELPARAM(LOWORD(wParam), BN_CLICKED), (LPARAM)(b->hWnd));
}
inMainWndProc = FALSE;
@@ -3098,64 +3035,66 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return (LRESULT)0;
case WM_SETCURSOR:
- if (hWnd == mswHWnd)
- wSetCursor(NULL, curCursor);
+ // Set normal Arrow cursor, DefWindowProc can override it
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+
+ if (!mswAllowBalloonHelp) {
+ break;
+ }
- if (!mswAllowBalloonHelp) {
- break;
- }
+ if (IsIconic(mswHWnd)) {
+ break;
+ }
- if (IsIconic(mswHWnd)) {
- break;
- }
+ b = getControlFromCursor(hWnd, NULL);
- b = getControlFromCursor(hWnd, NULL);
-
#ifdef BALLOON_TRACE
- fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL"); fflush(logFile);
+ fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL");
+ fflush(logFile);
#endif
- if (b == balloonControlButton) {
- //closeBalloonHelp(61);
- break;
- }
-
- if (GetActiveWindow() != hWnd) {
- closeBalloonHelp(62);
- break;
- }
- if (!b) {
- closeBalloonHelp(63);
- break;
- }
- if (b->type == B_DRAW) {
- closeBalloonHelp(64);
- break;
- }
- if (b->helpStr == NULL) {
- closeBalloonHelp(65);
- break;
- }
-
- if (b != balloonHelpButton) {
- closeBalloonHelp(7);
- }
+ if (b == balloonControlButton) {
+ //closeBalloonHelp(61);
+ break;
+ }
+
+ if (GetActiveWindow() != hWnd) {
+ closeBalloonHelp(62);
+ break;
+ }
+ if (!b) {
+ closeBalloonHelp(63);
+ break;
+ }
+ if (b->type == B_DRAW) {
+ closeBalloonHelp(64);
+ break;
+ }
+ if (b->helpStr == NULL) {
+ closeBalloonHelp(65);
+ break;
+ }
+
+ if (b != balloonHelpButton) {
+ closeBalloonHelp(7);
+ }
#ifdef BALLOON_TRACE
- fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState); fflush(logFile);
+ fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState);
+ fflush(logFile);
#endif
- if (balloonHelpState != balloonHelpIdle) {
- break;
- }
+ if (balloonHelpState != balloonHelpIdle) {
+ break;
+ }
- balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER,
- balloonHelpTimeOut, NULL);
+ balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER,
+ balloonHelpTimeOut, NULL);
- if (balloonHelpTimer == (UINT_PTR)0) {
- break;
- }
+ if (balloonHelpTimer == (UINT_PTR)0) {
+ break;
+ }
- balloonHelpState = balloonHelpWait;
- balloonHelpButton = b;
- break;
+ balloonHelpState = balloonHelpWait;
+ balloonHelpButton = b;
+ break;
case WM_SYSCOMMAND:
@@ -3263,7 +3202,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case 51:
count51++;
- /*return NULL;*/
+ /*return NULL;*/
case WM_PALETTECHANGED:
@@ -3421,7 +3360,7 @@ static BOOL InitApplication(HINSTANCE hinstCurrent)
wc.cbWndExtra = 4;
if (!RegisterClass(&wc)) {
- mswFail("RegisterClass(drawClass)");
+ mswFail("RegisterClass(drawClass)");
return FALSE;
}
@@ -3443,11 +3382,11 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
char **argv;
int argc;
- if (!hinstPrevious) {
- if (!InitApplication(hinstCurrent)) {
- return FALSE;
- }
- }
+ if (!hinstPrevious) {
+ if (!InitApplication(hinstCurrent)) {
+ return FALSE;
+ }
+ }
mswHInst = hinstCurrent;
mTitleH = GetSystemMetrics(SM_CYCAPTION) - 1;
@@ -3456,11 +3395,12 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
mResizeBorderW = GetSystemMetrics(SM_CXFRAME);
mResizeBorderH = GetSystemMetrics(SM_CYFRAME);
mMenuH = GetSystemMetrics(SM_CYMENU) + 1;
- screenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
- screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
- mswLabelFont = GetStockObject(DEFAULT_GUI_FONT);
+ screenWidth = GetSystemMetrics(SM_CXSCREEN);
+ screenHeight = GetSystemMetrics(SM_CYSCREEN);
+ mswLabelFont = GetStockObject(DEFAULT_GUI_FONT);
hDc = GetDC(0);
mswScale = GetDeviceCaps(hDc, LOGPIXELSX) / 96.0;
+ hWindowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(101));
if (mswScale < 1.0) {
mswScale = 1.0;
diff --git a/app/wlib/mswlib/mswmsg.c b/app/wlib/mswlib/mswmsg.c
index 8487e31..154d89d 100644
--- a/app/wlib/mswlib/mswmsg.c
+++ b/app/wlib/mswlib/mswmsg.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -22,14 +21,14 @@
#define SCALE_SMALL 0.8
struct wMessage_t {
- WOBJ_COMMON
- long flags;
- const char * message;
- };
+ WOBJ_COMMON
+ long flags;
+ const char * message;
+};
static void repaintMessage(
- HWND hWnd,
- wControl_p b )
+ HWND hWnd,
+ wControl_p b )
{
wMessage_p bm = (wMessage_p)b;
HDC hDc;
@@ -41,33 +40,29 @@ static void repaintMessage(
hDc = GetDC( hWnd );
- if ( !mswThickFont )
- hFont = SelectObject( hDc, mswLabelFont );
+ hFont = SelectObject( hDc, mswLabelFont );
- switch( wMessageSetFont( ((wMessage_p)b)->flags ))
- {
- case BM_LARGE:
- scale = SCALE_LARGE;
- break;
- case BM_SMALL:
- scale = SCALE_SMALL;
- break;
+ switch( wMessageSetFont( ((wMessage_p)b)->flags )) {
+ case BM_LARGE:
+ scale = SCALE_LARGE;
+ break;
+ case BM_SMALL:
+ scale = SCALE_SMALL;
+ break;
}
- /* is a non-standard text height required? */
- if( scale != 1.0 )
- {
+ /* is a non-standard text height required? */
+ if( scale != 1.0 ) {
/* if yes, get information about the standard font used */
GetObject( GetStockObject( DEFAULT_GUI_FONT ), sizeof( LOGFONT ), &msgFont );
/* change the height */
- msgFont.lfHeight = (long)((double)msgFont.lfHeight * scale);
+ msgFont.lfHeight = (long)((double)msgFont.lfHeight * scale);
/* create and activate the new font */
hFont = SelectObject( hDc, CreateFontIndirect( &msgFont ) );
} else {
- if ( !mswThickFont )
- hFont = SelectObject( hDc, mswLabelFont );
+ hFont = SelectObject( hDc, mswLabelFont );
}
GetTextMetrics(hDc, &textMetrics);
@@ -78,36 +73,41 @@ static void repaintMessage(
rect.left = bm->x;
SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) );
- ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2), ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, (int)(strlen( bm->message )), NULL );
+ ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2),
+ ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, (int)(strlen( bm->message )),
+ NULL );
if( scale != 1.0 )
/* in case we did create a new font earlier, delete it now */
+ {
DeleteObject( SelectObject( hDc, GetStockObject( DEFAULT_GUI_FONT )));
- else
- if ( !mswThickFont )
- SelectObject( hDc, hFont );
+ } else {
+ SelectObject( hDc, hFont );
+ }
ReleaseDC( hWnd, hDc );
}
void wMessageSetValue(
- wMessage_p b,
- const char * arg )
+ wMessage_p b,
+ const char * arg )
{
- if (b->message)
+ if (b->message) {
free( CAST_AWAY_CONST b->message );
- if (arg)
+ }
+ if (arg) {
b->message = mswStrdup( arg );
- else
+ } else {
b->message = NULL;
+ }
repaintMessage( ((wControl_p)(b->parent))->hWnd, (wControl_p)b );
}
void wMessageSetWidth(
- wMessage_p b,
- wWinPix_t width )
+ wMessage_p b,
+ wWinPix_t width )
{
b->w = width;
@@ -122,41 +122,44 @@ wWinPix_t wMessageGetHeight( long flags )
{
double scale = 1.0;
- if( flags & BM_LARGE )
+ if( flags & BM_LARGE ) {
scale = SCALE_LARGE;
- if( flags & BM_SMALL )
+ }
+ if( flags & BM_SMALL ) {
scale = SCALE_SMALL;
+ }
return((wWinPix_t)((mswEditHeight) * scale ));
}
static void mswMessageSetBusy(
- wControl_p b,
- BOOL_T busy )
+ wControl_p b,
+ BOOL_T busy )
{
}
static callBacks_t messageCallBacks = {
- repaintMessage,
- NULL,
- NULL,
- mswMessageSetBusy };
+ repaintMessage,
+ NULL,
+ NULL,
+ mswMessageSetBusy
+};
wMessage_p wMessageCreateEx(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- wWinPix_t width,
- const char *message,
- long flags )
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ wWinPix_t width,
+ const char *message,
+ long flags )
{
wMessage_p b;
int index;
-
+
b = (wMessage_p)mswAlloc( parent, B_MESSAGE, NULL, sizeof *b, NULL, &index );
mswComputePos( (wControl_p)b, x, y );
diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c
index 55fedb4..e65b0dd 100644
--- a/app/wlib/mswlib/mswpref.c
+++ b/app/wlib/mswlib/mswpref.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -10,7 +9,7 @@
#include <Shlwapi.h>
#if _MSC_VER >=1400
- #define stricmp _stricmp
+#define stricmp _stricmp
#endif
char * mswStrdup( const char * );
@@ -26,40 +25,41 @@ static char appWorkDirName[MAX_PATH];
const char * wGetAppLibDir( void )
{
- char *cp;
- char module_name[MAX_PATH];
+ char *cp;
+ char module_name[MAX_PATH];
- if (appLibDirName[0] != '\0') {
- return appLibDirName;
- }
+ if (appLibDirName[0] != '\0') {
+ return appLibDirName;
+ }
- GetModuleFileName( mswHInst, module_name, sizeof module_name );
- cp = strrchr( module_name, '\\' );
- if (cp)
- *cp = '\0';
+ GetModuleFileName( mswHInst, module_name, sizeof module_name );
+ cp = strrchr( module_name, '\\' );
+ if (cp) {
+ *cp = '\0';
+ }
#ifdef XTRKCAD_CMAKE_BUILD
- strncpy(appLibDirName, module_name, sizeof(appLibDirName));
- size_t len = sizeof(appLibDirName)-strlen(appLibDirName)-1;
- strncat(appLibDirName, "\\..\\share\\xtrkcad", len);
- _fullpath( appLibDirName, appLibDirName, MAX_PATH );
- return appLibDirName;
-#endif
-
- strncpy(appLibDirName, module_name, sizeof(appLibDirName));
- appLibDirName[sizeof(appLibDirName)-1] = '\0';
- return appLibDirName;
+ strncpy(appLibDirName, module_name, sizeof(appLibDirName));
+ size_t len = sizeof(appLibDirName)-strlen(appLibDirName)-1;
+ strncat(appLibDirName, "\\..\\share\\xtrkcad", len);
+ _fullpath( appLibDirName, appLibDirName, MAX_PATH );
+ return appLibDirName;
+#endif
+
+ strncpy(appLibDirName, module_name, sizeof(appLibDirName));
+ appLibDirName[sizeof(appLibDirName)-1] = '\0';
+ return appLibDirName;
}
/**
- * Gets the working directory for the application. At least the INI file is stored here.
+ * Gets the working directory for the application. At least the INI file is stored here.
* The working directory can be specified manually by creating a file called xtrkcad0.ini
- * in the application lib dir (the directory where the .EXE is located).
+ * in the application lib dir (the directory where the .EXE is located).
*
* [workdir]
* path=somepath
- *
+ *
* when somepath is set to the keyword "installdir", the install directory for the EXE is
* used.
*
@@ -68,229 +68,302 @@ const char * wGetAppLibDir( void )
*/
const char * wGetAppWorkDir( void )
{
- char *cp;
- int rc;
- if ( appWorkDirName[0] != 0 ) {
- return appWorkDirName;
- }
- wGetAppLibDir();
- snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName );
- rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, sizeof appWorkDirName, mswTmpBuff );
- if ( rc!=0 ) {
- if ( stricmp( appWorkDirName, "installdir" ) == 0 ) {
- strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) );
- appWorkDirName[sizeof(appWorkDirName)-1] = '\0';
- } else {
- cp = &appWorkDirName[strlen(appWorkDirName)-1];
- while (cp>appWorkDirName && *cp == '\\') *cp-- = 0;
- }
- return appWorkDirName;
- }
-
- if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_APPDATA, 0 ) == 0 ) {
- wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL );
- wExit(0);
- } else {
- snprintf( appWorkDirName, sizeof(appWorkDirName), "%s\\%s", mswTmpBuff, "XTrackCad" );
- if( !PathIsDirectory( appWorkDirName )) {
- if( !CreateDirectory( appWorkDirName, NULL )) {
- wNoticeEx( NT_ERROR, "Cannot create user's profile directory", "Exit", NULL );
- wExit(0);
- }
- }
- }
-
- return appWorkDirName;
+ char *cp;
+ int rc;
+ if ( appWorkDirName[0] != 0 ) {
+ return appWorkDirName;
+ }
+ wGetAppLibDir();
+ snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName );
+ rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName,
+ sizeof appWorkDirName, mswTmpBuff );
+ if ( rc!=0 ) {
+ if ( stricmp( appWorkDirName, "installdir" ) == 0 ) {
+ strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) );
+ appWorkDirName[sizeof(appWorkDirName)-1] = '\0';
+ } else {
+ cp = &appWorkDirName[strlen(appWorkDirName)-1];
+ while (cp>appWorkDirName && *cp == '\\') {
+ *cp-- = 0;
+ }
+ }
+ return appWorkDirName;
+ }
+
+ if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_APPDATA, 0 ) == 0 ) {
+ wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL );
+ wExit(0);
+ } else {
+ snprintf( appWorkDirName, sizeof(appWorkDirName), "%s\\%s", mswTmpBuff,
+ "XTrackCad" );
+ if( !PathIsDirectory( appWorkDirName )) {
+ if( !CreateDirectory( appWorkDirName, NULL )) {
+ wNoticeEx( NT_ERROR, "Cannot create user's profile directory", "Exit", NULL );
+ wExit(0);
+ }
+ }
+ }
+
+ return appWorkDirName;
}
-/** Get the user's home directory. The environment variable HOME is
- * assumed to contain the proper directory.
+/** Get the user's Documents directory.
*
- * \return pointer to the user's home directory
+ * \return pointer to the user's Documents directory
*/
const char *wGetUserHomeDir( void )
{
- if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_PERSONAL, 0 ) == 0 ) {
- wNoticeEx( NT_ERROR, "Cannot get user's home directory", "Exit", NULL );
- wExit(0);
- return( NULL );
- } else {
- return( mswTmpBuff );
- }
+ if (SHGetSpecialFolderPath( NULL, mswTmpBuff, CSIDL_PERSONAL, 0 ) == 0 ) {
+ wNoticeEx( NT_ERROR, "Cannot get user's documents directory", "Exit", NULL );
+ wExit(0);
+ return( NULL );
+ } else {
+ return( mswTmpBuff );
+ }
}
typedef struct {
- char * section;
- char * name;
- BOOL_T present;
- BOOL_T dirty;
- char * val;
- } prefs_t;
+ char * section;
+ char * name;
+ BOOL_T present;
+ BOOL_T dirty;
+ char * val;
+} prefs_t;
static dynArr_t prefs_da;
#define prefs(N) DYNARR_N(prefs_t,prefs_da,N)
-void wPrefSetString( const char * section, const char * name, const char * sval )
+void wPrefSetString( const char * section, const char * name,
+ const char * sval )
{
- prefs_t * p;
-
- for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
- if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
- if (p->val)
- free(p->val);
- p->dirty = TRUE;
- p->val = mswStrdup( sval );
- return;
- }
- }
- DYNARR_APPEND( prefs_t, prefs_da, 10 );
- p = &prefs(prefs_da.cnt-1);
- p->name = mswStrdup(name);
- p->section = mswStrdup(section);
- p->dirty = TRUE;
- p->val = mswStrdup(sval);
+ prefs_t * p;
+
+ for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
+ if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
+ if (p->val) {
+ free(p->val);
+ }
+ p->dirty = TRUE;
+ p->val = mswStrdup( sval );
+ return;
+ }
+ }
+ DYNARR_APPEND( prefs_t, prefs_da, 10 );
+ p = &prefs(prefs_da.cnt-1);
+ p->name = mswStrdup(name);
+ p->section = mswStrdup(section);
+ p->dirty = TRUE;
+ p->val = mswStrdup(sval);
}
-void wPrefsLoad(char * name) {
- prefs_t *p;
- for (int i= 0; i<prefs_da.cnt; i++) {
- p = &prefs(i);
- if (!name || !name[0]) name = mswProfileFile;
- int rc = GetPrivateProfileString( p->section, p->name, "", mswTmpBuff, sizeof mswTmpBuff, name );
- if (rc==0)
- continue;
- p->val = mswStrdup(mswTmpBuff);
- }
+void wPrefsLoad(char * name)
+{
+ prefs_t *p;
+ for (int i= 0; i<prefs_da.cnt; i++) {
+ p = &prefs(i);
+ if (!name || !name[0]) {
+ name = mswProfileFile;
+ }
+ int rc = GetPrivateProfileString( p->section, p->name, "", mswTmpBuff,
+ sizeof mswTmpBuff, name );
+ if (rc==0) {
+ continue;
+ }
+ p->val = mswStrdup(mswTmpBuff);
+ }
}
char * wPrefGetStringBasic( const char * section, const char * name )
{
- prefs_t * p;
- int rc;
-
- for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
- if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
- return p->val;
- }
- }
-
- rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff, mswProfileFile );
- if (rc==0)
- return NULL;
- DYNARR_APPEND( prefs_t, prefs_da, 10 );
- p = &prefs(prefs_da.cnt-1);
- p->name = mswStrdup(name);
- p->section = mswStrdup(section);
- p->dirty = FALSE;
- p->val = mswStrdup(mswTmpBuff);
- return p->val;
+ prefs_t * p;
+ int rc;
+
+ for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
+ if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
+ return p->val;
+ }
+ }
+
+ rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff,
+ mswProfileFile );
+ if (rc==0) {
+ return NULL;
+ }
+ DYNARR_APPEND( prefs_t, prefs_da, 10 );
+ p = &prefs(prefs_da.cnt-1);
+ p->name = mswStrdup(name);
+ p->section = mswStrdup(section);
+ p->dirty = FALSE;
+ p->val = mswStrdup(mswTmpBuff);
+ return p->val;
}
void wPrefSetInteger( const char * section, const char * name, long lval )
{
- char tmp[20];
-
- snprintf( tmp, sizeof(tmp), "%ld", lval );
- wPrefSetString( section, name, tmp );
+ char tmp[20];
+
+ snprintf( tmp, sizeof(tmp), "%ld", lval );
+ wPrefSetString( section, name, tmp );
}
wBool_t wPrefGetIntegerBasic(
- const char * section,
- const char * name,
- long *res,
- long def )
+ const char * section,
+ const char * name,
+ long *res,
+ long def )
{
- const char * cp;
- char * cp1;
-
- cp = wPrefGetStringBasic( section, name );
- if (cp == NULL) {
- *res = def;
- return FALSE;
- }
- *res = strtol(cp,&cp1,0);
- if (cp==cp1) {
- *res = def;
- return FALSE;
- }
- return TRUE;
+ const char * cp;
+ char * cp1;
+
+ cp = wPrefGetStringBasic( section, name );
+ if (cp == NULL) {
+ *res = def;
+ return FALSE;
+ }
+ *res = strtol(cp,&cp1,0);
+ if (cp==cp1) {
+ *res = def;
+ return FALSE;
+ }
+ return TRUE;
}
void wPrefSetFloat(
- const char * section, /* Section */
- const char * name, /* Name */
- double lval ) /* Value */
+ const char * section, /* Section */
+ const char * name, /* Name */
+ double lval ) /* Value */
/*
*/
{
- char tmp[20];
+ char tmp[20];
- snprintf(tmp, sizeof(tmp), "%0.6f", lval );
- wPrefSetString( section, name, tmp );
+ snprintf(tmp, sizeof(tmp), "%0.6f", lval );
+ wPrefSetString( section, name, tmp );
}
wBool_t wPrefGetFloatBasic(
- const char * section, /* Section */
- const char * name, /* Name */
- double * res, /* Address of result */
- double def ) /* Default value */
+ const char * section, /* Section */
+ const char * name, /* Name */
+ double * res, /* Address of result */
+ double def ) /* Default value */
/*
*/
{
- const char * cp;
- char * cp1;
-
- cp = wPrefGetStringBasic( section, name );
- if (cp == NULL) {
- *res = def;
- return FALSE;
- }
- *res = strtod(cp, &cp1);
- if (cp == cp1) {
- *res = def;
- return FALSE;
- }
- return TRUE;
+ const char * cp;
+ char * cp1;
+
+ cp = wPrefGetStringBasic( section, name );
+ if (cp == NULL) {
+ *res = def;
+ return FALSE;
+ }
+ *res = strtod(cp, &cp1);
+ if (cp == cp1) {
+ *res = def;
+ return FALSE;
+ }
+ return TRUE;
}
void wPrefFlush( char * name )
{
- prefs_t * p;
-
- for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
- if (name && name[0])
- WritePrivateProfileString( p->section, p->name, p->val, name );
- else if (p->dirty)
- WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile );
- }
- if (name && name[0])
- WritePrivateProfileString( NULL, NULL, NULL, name );
- else
- WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile );
+ prefs_t * p;
+
+ for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
+ if (name && name[0]) {
+ WritePrivateProfileString( p->section, p->name, p->val, name );
+ } else if (p->dirty) {
+ WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile );
+ }
+ }
+ if (name && name[0]) {
+ WritePrivateProfileString( NULL, NULL, NULL, name );
+ } else {
+ WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile );
+ }
}
void wPrefReset(
- void )
+ void )
/*
*/
{
- prefs_t * p;
-
- for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
- if (p->section)
- free( p->section );
- if (p->name)
- free( p->name );
- if (p->val)
- free( p->val );
- }
- prefs_da.cnt = 0;
+ prefs_t * p;
+
+ for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
+ if (p->section) {
+ free( p->section );
+ }
+ if (p->name) {
+ free( p->name );
+ }
+ if (p->val) {
+ free( p->val );
+ }
+ }
+ prefs_da.cnt = 0;
+}
+
+/**
+ * Split a line from the config file ie. an ini-file into separate tokens. The
+ * line is split into sections, name of value and value following. Pointers
+ * to the respective token are returned. These are zero-terminated.
+ * If a token is not present, NULL is returned instead.
+ * The input line is modified.
+ *
+ * \param line input line, modified during excution of function
+ * \param section section if present
+ * \param name name of config value if present
+ * \param value name of value if present
+ */
+
+void
+wPrefTokenize(char* line, char** section, char** name, char** value)
+{
+ *section = NULL;
+ *name = NULL;
+ *value = NULL;
+
+ if (*line == '[') {
+ *section = strtok(line, "[]");
+ } else {
+ *name = strtok(line, "=");
+ *value = strtok(NULL, "\n");
+ }
+}
+
+/**
+ * A valid line for a config file is created from the individual elements.
+ * Values not need for specific statement are ignored. Eg. when section is
+ * present, name and value are not used.
+ * The caller has to make sure, that the return buffer is large enough.
+ *
+ * \param section section, returned inside squared brackets
+ * \param name name, left side of '='
+ * \param value value, right side of '='
+ * \param result pointer to buffer for formated line.
+ */
+
+void
+wPrefFormatLine(const char* section, const char* name,
+ const char* value, char* result)
+{
+ if (!value || *value == '\0') {
+ value = "";
+ }
+
+ if (section) {
+ sprintf(result, "[%s]", section);
+ }
+ else {
+ sprintf(result, "%s=%s", name, value);
+ }
}
diff --git a/app/wlib/mswlib/mswprint.c b/app/wlib/mswlib/mswprint.c
index e38ca05..9a7f65b 100644
--- a/app/wlib/mswlib/mswprint.c
+++ b/app/wlib/mswlib/mswprint.c
@@ -1,6 +1,5 @@
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -42,11 +41,11 @@ void getPageDim( HDC hDc )
int res_w, res_h, size_w, size_h;
rc = Escape( hDc, GETPHYSPAGESIZE, 0, NULL, (LPPOINT)&dims );
if (rc <0) {
- mswFail( "GETPHYPAGESIZE" );
+ mswFail( "GETPHYPAGESIZE" );
}
rc = Escape( hDc, GETPRINTINGOFFSET, 0, NULL, (LPPOINT)&offs );
if (rc <0) {
- mswFail( "GETPRINTINGOFFSET" );
+ mswFail( "GETPRINTINGOFFSET" );
}
print_d.wFactor = (double)GetDeviceCaps( hDc, LOGPIXELSX );
print_d.hFactor = (double)GetDeviceCaps( hDc, LOGPIXELSY );
@@ -115,17 +114,18 @@ static wBool_t printInit( void )
while (*temp) {
if (*temp == ',') {
*temp++ = 0;
- while( *temp == ' ' )
+ while( *temp == ' ' ) {
temp++;
- if (!ptrDrvr)
+ }
+ if (!ptrDrvr) {
ptrDrvr = temp;
- else {
+ } else {
ptrPort = temp;
break;
}
- }
- else
+ } else {
temp = AnsiNext(temp);
+ }
}
strcpy( ptrDrvrDvr, ptrDrvr );
strcat( ptrDrvrDvr, ".drv" );
@@ -134,9 +134,11 @@ static wBool_t printInit( void )
return FALSE;
}
if (( extDeviceMode = GetProcAddress( hDriver, "ExtDeviceMode" )) != NULL) {
- size = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)NULL, (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, 0 );
+ size = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)NULL,
+ (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, 0 );
printMode = (DEVMODE*)malloc( size );
- rc = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)printMode, (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, DM_OUT_BUFFER );
+ rc = extDeviceMode( mswHWnd, (HANDLE)hDriver, (LPDEVMODE)printMode,
+ (LPSTR)ptrDevice, (LPSTR)ptrPort, (LPDEVMODE)NULL, (LPSTR)NULL, DM_OUT_BUFFER );
#ifdef LATER
if (rc != IDOK && rc != IDCANCEL) {
mswFail( "printInit: extDeviceMode" );
@@ -160,7 +162,7 @@ static wBool_t printInit( void )
}
getPageDim( hDc );
DeleteDC( hDc );
-
+
FreeLibrary( hDriver );
#endif
printerOk = TRUE;
@@ -201,9 +203,9 @@ const char* wPrintGetName()
DEVNAMES* pDevNames = GlobalLock(hDevNames);
if (pDevNames == NULL) {
strcpy(sPrinterName, "Printer");
- }
- else {
- strncpy(sPrinterName, (char*)pDevNames + pDevNames->wDeviceOffset, sizeof sPrinterName - 1);
+ } else {
+ strncpy(sPrinterName, (char*)pDevNames + pDevNames->wDeviceOffset,
+ sizeof sPrinterName - 1);
sPrinterName[sizeof sPrinterName - 1] = '\0';
}
GlobalUnlock( hDevNames );
@@ -211,15 +213,15 @@ const char* wPrintGetName()
}
void wPrintGetMargins(
- double * tMargin,
- double * rMargin,
- double * bMargin,
- double * lMargin )
+ double * tMargin,
+ double * rMargin,
+ double * bMargin,
+ double * lMargin )
{
- if ( tMargin ) *tMargin = tBorder;
- if ( rMargin ) *rMargin = rBorder;
- if ( bMargin ) *bMargin = bBorder;
- if ( lMargin ) *lMargin = lBorder;
+ if ( tMargin ) { *tMargin = tBorder; }
+ if ( rMargin ) { *rMargin = rBorder; }
+ if ( bMargin ) { *bMargin = bBorder; }
+ if ( lMargin ) { *lMargin = lBorder; }
}
@@ -240,10 +242,11 @@ HDC mswGetPrinterDC( void )
printDlg.lStructSize = sizeof printDlg;
printDlg.hwndOwner = NULL;
printDlg.Flags = PD_RETURNDC|PD_NOPAGENUMS|PD_NOSELECTION;
- if (PrintDlg(&printDlg) != 0)
+ if (PrintDlg(&printDlg) != 0) {
return printDlg.hDC;
- else
+ } else {
return (HDC)0;
+ }
}
@@ -290,51 +293,55 @@ wBool_t wPrintDocStart( const char * title, int fpageCount, int * copiesP )
if (print_d.hDc == (HDC)0) {
return FALSE;
}
- printStatus = TRUE;
- docInfo.cbSize = sizeof docInfo;
- docInfo.lpszDocName = title;
- docInfo.lpszOutput = NULL;
- lpAbortDlg = MakeProcInstance( (FARPROC)mswAbortDlg, mswHInst );
- lpAbortProc = MakeProcInstance( (FARPROC)mswAbortProc, mswHInst );
- SetAbortProc( print_d.hDc, (ABORTPROC)lpAbortProc );
- if (StartDoc( print_d.hDc, &docInfo ) < 0) {
- MessageBox( mswHWnd, "Unable to start print job",
- NULL, MB_OK|MB_ICONHAND );
- FreeProcInstance( lpAbortDlg );
- FreeProcInstance( lpAbortProc );
- DeleteDC( print_d.hDc );
- return FALSE;
- }
- printAbort = FALSE;
- hAbortDlgWnd = CreateDialog( mswHInst, "MswAbortDlg", mswHWnd,
- (DLGPROC)lpAbortDlg );
- /*SetDlgItemText( hAbortDlgWnd, IDM_PRINTAPP, title );*/
- SetWindowText( hAbortDlgWnd, title );
- ShowWindow( hAbortDlgWnd, SW_NORMAL );
- UpdateWindow( hAbortDlgWnd );
- EnableWindow( mswHWnd, FALSE );
- if (copiesP)
- *copiesP = printDlg.nCopies;
- if (printDlg.nCopies>1)
- pageCount *= printDlg.nCopies;
- if ( (GetDeviceCaps( printDlg.hDC, RASTERCAPS ) & RC_PALETTE) ) {
- newPrintPalette = mswCreatePalette();
- oldPrintPalette = SelectPalette( printDlg.hDC, newPrintPalette, 0 );
- RealizePalette( printDlg.hDC );
- }
- return TRUE;
+ printStatus = TRUE;
+ docInfo.cbSize = sizeof docInfo;
+ docInfo.lpszDocName = title;
+ docInfo.lpszOutput = NULL;
+ lpAbortDlg = MakeProcInstance( (FARPROC)mswAbortDlg, mswHInst );
+ lpAbortProc = MakeProcInstance( (FARPROC)mswAbortProc, mswHInst );
+ SetAbortProc( print_d.hDc, (ABORTPROC)lpAbortProc );
+ if (StartDoc( print_d.hDc, &docInfo ) < 0) {
+ MessageBox( mswHWnd, "Unable to start print job",
+ NULL, MB_OK|MB_ICONHAND );
+ FreeProcInstance( lpAbortDlg );
+ FreeProcInstance( lpAbortProc );
+ DeleteDC( print_d.hDc );
+ return FALSE;
+ }
+ printAbort = FALSE;
+ hAbortDlgWnd = CreateDialog( mswHInst, "MswAbortDlg", mswHWnd,
+ (DLGPROC)lpAbortDlg );
+ /*SetDlgItemText( hAbortDlgWnd, IDM_PRINTAPP, title );*/
+ SetWindowText( hAbortDlgWnd, title );
+ ShowWindow( hAbortDlgWnd, SW_NORMAL );
+ UpdateWindow( hAbortDlgWnd );
+ EnableWindow( mswHWnd, FALSE );
+ if (copiesP) {
+ *copiesP = printDlg.nCopies;
+ }
+ if (printDlg.nCopies>1) {
+ pageCount *= printDlg.nCopies;
+ }
+ if ( (GetDeviceCaps( printDlg.hDC, RASTERCAPS ) & RC_PALETTE) ) {
+ newPrintPalette = mswCreatePalette();
+ oldPrintPalette = SelectPalette( printDlg.hDC, newPrintPalette, 0 );
+ RealizePalette( printDlg.hDC );
+ }
+ return TRUE;
}
wDraw_p wPrintPageStart( void )
{
char pageL[80];
- if (!printStatus)
+ if (!printStatus) {
return NULL;
+ }
pageNumber++;
- if (pageCount > 0)
+ if (pageCount > 0) {
wsprintf( pageL, "Page %d of %d", pageNumber, pageCount );
- else
+ } else {
wsprintf( pageL, "Page %d", pageNumber );
+ }
SetDlgItemText( hAbortDlgWnd, IDM_PRINTPAGE, pageL );
StartPage( printDlg.hDC );
#ifdef LATER
@@ -367,15 +374,16 @@ wBool_t wPrintQuit( void )
void wPrintDocEnd( void )
{
- if (!printStatus)
+ if (!printStatus) {
return;
+ }
EndDoc( printDlg.hDC );
if ( newPrintPalette ) {
SelectPalette( printDlg.hDC, oldPrintPalette, 0 );
DeleteObject( newPrintPalette );
newPrintPalette = (HPALETTE)0;
}
-
+
EnableWindow( mswHWnd, TRUE );
DestroyWindow( hAbortDlgWnd );
FreeProcInstance( lpAbortDlg );
@@ -394,7 +402,8 @@ wBool_t wPrintNewPrinter( const char * printer )
return TRUE;
}
-wBool_t wPrintNewMargin( const char * name, double t, double b, double l, double r )
+wBool_t wPrintNewMargin( const char * name, double t, double b, double l,
+ double r )
{
return TRUE;
}
diff --git a/app/wlib/mswlib/mswsplash.c b/app/wlib/mswlib/mswsplash.c
index bd7644f..848bd00 100644
--- a/app/wlib/mswlib/mswsplash.c
+++ b/app/wlib/mswlib/mswsplash.c
@@ -2,27 +2,26 @@
* Splash window for Windows
*/
- /* XTrkCad - Model Railroad CAD
- * Copyright (C) 2007 Martin Fischer
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
+/* XTrkCad - Model Railroad CAD
+* Copyright (C) 2007 Martin Fischer
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -41,13 +40,13 @@ static HWND hSplash;
static LPWORD lpwAlign( LPWORD lpIn )
{
- ULONGLONG ul;
+ ULONGLONG ul;
- ul = (ULONGLONG) lpIn;
- ul +=3;
- ul >>=2;
- ul <<=2;
- return (LPWORD) ul;
+ ul = (ULONGLONG) lpIn;
+ ul +=3;
+ ul >>=2;
+ ul <<=2;
+ return (LPWORD) ul;
}
/**
@@ -57,7 +56,7 @@ static LPWORD lpwAlign( LPWORD lpIn )
BOOL
PaintBitmap( HWND hWnd, HBITMAP hBmp )
{
- HDC hdc, hdcMem;
+ HDC hdc, hdcMem;
RECT rect;
HGDIOBJ oldObject;
@@ -66,19 +65,19 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp )
/* get device context for destination window ( the dialog control ) */
hdc = GetDC( hWnd );
GetClientRect( hWnd, &rect );
-
+
/* create a memory dc holding the bitmap */
hdcMem = CreateCompatibleDC( hdc );
oldObject = SelectObject( hdcMem, hBmp );
- /*
- show it in the upper left corner
- the window is created with the size of the bitmap, so there is no need
- for any special transformation
+ /*
+ show it in the upper left corner
+ the window is created with the size of the bitmap, so there is no need
+ for any special transformation
*/
BitBlt( hdc, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
- hdcMem, 0, 0, SRCCOPY );
+ hdcMem, 0, 0, SRCCOPY );
/* release the DCs that are not needed any more */
SelectObject(hdcMem, oldObject);
@@ -89,31 +88,31 @@ PaintBitmap( HWND hWnd, HBITMAP hBmp )
}
/**
- * This is the dialog procedure for the splash window. Main activity is to
+ * This is the dialog procedure for the splash window. Main activity is to
* catch the WM_PAINT message and draw the logo bitmap into that area.
*/
-BOOL CALLBACK
+BOOL CALLBACK
SplashDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND hWndBmp;
static HBITMAP hBmp;
switch( msg ) {
- case WM_INITDIALOG:
- /* bitmap handle is passed at dialog creation */
- hBmp = (HBITMAP)lParam;
-
- hWndBmp = GetDlgItem( hDlg, IDBITMAP );
- return TRUE;
- case WM_PAINT:
- /* paint the logo bitmap */
- PaintBitmap( hWndBmp, hBmp );
- break;
- case WM_DESTROY:
- /* destroy the bitmap */
- DeleteObject( hBmp );
- break;
+ case WM_INITDIALOG:
+ /* bitmap handle is passed at dialog creation */
+ hBmp = (HBITMAP)lParam;
+
+ hWndBmp = GetDlgItem( hDlg, IDBITMAP );
+ return TRUE;
+ case WM_PAINT:
+ /* paint the logo bitmap */
+ PaintBitmap( hWndBmp, hBmp );
+ break;
+ case WM_DESTROY:
+ /* destroy the bitmap */
+ DeleteObject( hBmp );
+ break;
}
return FALSE;
}
@@ -133,7 +132,7 @@ int
wCreateSplash( char *appname, char *appver )
{
HGLOBAL hgbl;
- LPDLGTEMPLATE lpdt;
+ LPDLGTEMPLATE lpdt;
LPWORD lpw;
LPDLGITEMTEMPLATE lpdit;
int cxDlgUnit, cyDlgUnit;
@@ -149,60 +148,65 @@ wCreateSplash( char *appname, char *appver )
/* load the logo bitmap */
snprintf( logoPath, sizeof(logoPath), "%s\\logo.bmp", wGetAppLibDir());
- hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE );
- if( !hBmp )
+ hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0,
+ LR_DEFAULTCOLOR | LR_LOADFROMFILE );
+ if( !hBmp ) {
return( 0 );
+ }
- /* get info about the loaded logo file */
+ /* get info about the loaded logo file */
GetObject( hBmp, sizeof(BITMAP), (LPVOID)&bmp );
/* calculate the size of dialog box */
cx = (bmp.bmWidth * 4) / cxDlgUnit; /* start with the size of the bitmap */
- cy = (bmp.bmHeight * 8) / cyDlgUnit + 20; /* 20 is enough for two lines of text and some room */
+ cy = (bmp.bmHeight * 8) / cyDlgUnit +
+ 20; /* 20 is enough for two lines of text and some room */
/* allocate memory block for dialog template */
hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);
- if (!hgbl)
+ if (!hgbl) {
return -1;
- lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
+ }
+ lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
- /* Define a dialog box. */
- lpdt->style = WS_POPUP | WS_BORDER | WS_VISIBLE | DS_MODALFRAME | DS_CENTER;
- lpdt->cdit = 3; // number of controls
- lpdt->x = 0; lpdt->y = 0;
- lpdt->cx = cx; lpdt->cy = cy;
+ /* Define a dialog box. */
+ lpdt->style = WS_POPUP | WS_BORDER | WS_VISIBLE | DS_MODALFRAME | DS_CENTER;
+ lpdt->cdit = 3; // number of controls
+ lpdt->x = 0; lpdt->y = 0;
+ lpdt->cx = cx; lpdt->cy = cy;
- lpw = (LPWORD) (lpdt + 1);
- *lpw++ = 0; /* no menu */
- *lpw++ = 0; /* predefined dialog box class (by default) */
- *lpw++ = 0;
+ lpw = (LPWORD) (lpdt + 1);
+ *lpw++ = 0; /* no menu */
+ *lpw++ = 0; /* predefined dialog box class (by default) */
+ *lpw++ = 0;
/* add the static control for the logo bitmap */
lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw);
lpdit->x = 0; lpdit->y = 0;
- lpdit->cx = (SHORT)((bmp.bmWidth * 4) / cxDlgUnit);
+ lpdit->cx = (SHORT)((bmp.bmWidth * 4) / cxDlgUnit);
lpdit->cy = (SHORT)((bmp.bmHeight * 8) / cyDlgUnit);
- lpdit->id = IDBITMAP;
- lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT;
- lpw = (LPWORD) (lpdit + 1);
- *lpw++ = 0xFFFF;
- *lpw++ = 0x0082; /* static class */
+ lpdit->id = IDBITMAP;
+ lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0082; /* static class */
- lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Logo should be here...", -1, (LPWSTR)lpw, 50);
+ lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Logo should be here...", -1,
+ (LPWSTR)lpw, 50);
/* add the static control for the program title */
lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw);
lpdit->x = 2; lpdit->y = (short)( 1 + (bmp.bmHeight * 8) / cyDlgUnit );
- lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit;
- lpdit->id = IDAPPNAME;
- lpdit->style = WS_CHILD | WS_VISIBLE | SS_CENTER;
- lpw = (LPWORD) (lpdit + 1);
- *lpw++ = 0xFFFF;
- *lpw++ = 0x0082; /* static class */
-
- /* create the title string */
+ lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit;
+ lpdit->id = IDAPPNAME;
+ lpdit->style = WS_CHILD | WS_VISIBLE | SS_CENTER;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0082; /* static class */
+
+ /* create the title string */
pszBuf = malloc( strlen( appname ) + strlen( appver ) + 2 );
if (!pszBuf) {
GlobalUnlock(hgbl);
@@ -216,26 +220,27 @@ wCreateSplash( char *appname, char *appver )
/* add the static control for the loading message */
lpdit = (LPDLGITEMTEMPLATE)lpwAlign(lpw);
lpdit->x = 2; lpdit->y = (short)(bmp.bmHeight * 8) / cyDlgUnit + 10;
- lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit;
- lpdit->id = IDMESSAGE;
- lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT;
- lpw = (LPWORD) (lpdit + 1);
- *lpw++ = 0xFFFF;
- *lpw++ = 0x0082; /* static class */
+ lpdit->cx = cx - 2; lpdit->cy = cyDlgUnit;
+ lpdit->id = IDMESSAGE;
+ lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT;
+ lpw = (LPWORD) (lpdit + 1);
+ *lpw++ = 0xFFFF;
+ *lpw++ = 0x0082; /* static class */
- lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Starting Application...", -1, (LPWSTR)lpw, 50);
+ lpw += 1+MultiByteToWideChar (CP_ACP, 0, "Starting Application...", -1,
+ (LPWSTR)lpw, 50);
/* create the dialog */
- GlobalUnlock(hgbl);
- hSplash = CreateDialogIndirectParam( mswHInst, (LPDLGTEMPLATE) hgbl,
- mswHWnd, (DLGPROC)SplashDlgProc, (LPARAM)hBmp );
-
+ GlobalUnlock(hgbl);
+ hSplash = CreateDialogIndirectParam( mswHInst, (LPDLGTEMPLATE) hgbl,
+ mswHWnd, (DLGPROC)SplashDlgProc, (LPARAM)hBmp );
+
/* free allocated memory */
- GlobalFree(hgbl);
+ GlobalFree(hgbl);
free( pszBuf );
/* that's it */
- return 1;
+ return 1;
}
@@ -243,9 +248,9 @@ wCreateSplash( char *appname, char *appver )
* Update the progress message inside the splash window
* msg text message to display
* return nonzero if ok
- */
+ */
-int
+int
wSetSplashInfo( char *msg )
{
if( msg ) {
diff --git a/app/wlib/mswlib/mswstatus.c b/app/wlib/mswlib/mswstatus.c
index 1502a4e..7473ec8 100644
--- a/app/wlib/mswlib/mswstatus.c
+++ b/app/wlib/mswlib/mswstatus.c
@@ -39,10 +39,10 @@
*/
void wStatusSetValue(
- wStatus_p b,
- const char * arg)
+ wStatus_p b,
+ const char * arg)
{
- wMessageSetValue((wMessage_p)b, arg);
+ wMessageSetValue((wMessage_p)b, arg);
}
/**
* Create a window for a simple text.
@@ -58,14 +58,14 @@ void wStatusSetValue(
*/
wStatus_p wStatusCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * labelStr,
- wWinPix_t width,
- const char *message)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * labelStr,
+ wWinPix_t width,
+ const char *message)
{
- return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0);
+ return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0);
}
/**
@@ -78,7 +78,7 @@ wStatus_p wStatusCreate(
wWinPix_t
wStatusGetWidth(const char *testString)
{
- return (wMessageGetWidth(testString));
+ return (wMessageGetWidth(testString));
}
/**
@@ -89,9 +89,9 @@ wStatusGetWidth(const char *testString)
*/
wWinPix_t wStatusGetHeight(
- long flags)
+ long flags)
{
- return (wMessageGetHeight(flags));
+ return (wMessageGetHeight(flags));
}
/**
@@ -103,8 +103,8 @@ wWinPix_t wStatusGetHeight(
*/
void wStatusSetWidth(
- wStatus_p b,
- wWinPix_t width)
+ wStatus_p b,
+ wWinPix_t width)
{
- wMessageSetWidth((wMessage_p)b, width);
+ wMessageSetWidth((wMessage_p)b, width);
}
diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c
index b43a5d4..93c97b8 100644
--- a/app/wlib/mswlib/mswtext.c
+++ b/app/wlib/mswlib/mswtext.c
@@ -17,12 +17,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <windows.h>
#include <string.h>
-#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
@@ -38,38 +37,38 @@
*/
static LOGFONT fixedFont = {
- /* Initial default values */
- -18, 0, /* H, W */
- 0, /* A */
- 0,
- FW_REGULAR,
- 0, 0, 0,/* I, U, SO */
- ANSI_CHARSET,
- 0, /* OP */
- 0, /* CP */
- 0, /* Q */
- FIXED_PITCH|FF_MODERN, /* P&F */
- "Courier"
-};
+ /* Initial default values */
+ -18, 0, /* H, W */
+ 0, /* A */
+ 0,
+ FW_REGULAR,
+ 0, 0, 0,/* I, U, SO */
+ ANSI_CHARSET,
+ 0, /* OP */
+ 0, /* CP */
+ 0, /* Q */
+ FIXED_PITCH|FF_MODERN, /* P&F */
+ "Courier"
+ };
static HFONT fixedTextFont, prevTextFont;
struct wText_t {
- WOBJ_COMMON
- HANDLE hText;
+ WOBJ_COMMON
+ HANDLE hText;
};
void wTextClear(
- wText_p b)
+ wText_p b)
{
- LRESULT rc;
- rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)0, (LPARAM)0);
- rc = SendMessage(b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
- rc = SendMessage(b->hWnd, WM_CLEAR, (WPARAM)0, (LPARAM)0);
-
- if (b->option&BO_READONLY) {
- rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0);
- }
+ LRESULT rc;
+ rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)0, (LPARAM)0);
+ rc = SendMessage(b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
+ rc = SendMessage(b->hWnd, WM_CLEAR, (WPARAM)0, (LPARAM)0);
+
+ if (b->option&BO_READONLY) {
+ rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0);
+ }
}
/**
@@ -84,53 +83,53 @@ void wTextClear(
*/
void wTextAppend(
- wText_p b,
- const char * text)
+ wText_p b,
+ const char * text)
{
- char *cp;
- char *buffer;
- char *extText;
- int textSize;
- size_t len = strlen(text);
-
- if (!len) {
- return;
- }
-
- for (cp = (char *)text; *cp; cp++) {
- if (*cp == '\n') {
- len++;
- }
- }
-
- extText = malloc(len + 1 + 10);
-
- for (cp=extText; *text; cp++,text++) {
- if (*text == '\n') {
- *cp++ = '\r';
- *cp = '\n';
- } else {
- *cp = *text;
- }
- }
-
- *cp = '\0';
- textSize = GetWindowTextLength(b->hWnd);
- buffer = malloc((textSize + len + 1) * sizeof(char));
-
- if (buffer) {
- GetWindowText(b->hWnd, buffer, textSize + 1);
- strcat(buffer, extText);
- SetWindowText(b->hWnd, buffer);
- free(extText);
- free(buffer);
- } else {
- abort();
- }
-
- if (b->option&BO_READONLY) {
- SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0);
- }
+ char *cp;
+ char *buffer;
+ char *extText;
+ int textSize;
+ size_t len = strlen(text);
+
+ if (!len) {
+ return;
+ }
+
+ for (cp = (char *)text; *cp; cp++) {
+ if (*cp == '\n') {
+ len++;
+ }
+ }
+
+ extText = malloc(len + 1 + 10);
+
+ for (cp=extText; *text; cp++,text++) {
+ if (*text == '\n') {
+ *cp++ = '\r';
+ *cp = '\n';
+ } else {
+ *cp = *text;
+ }
+ }
+
+ *cp = '\0';
+ textSize = GetWindowTextLength(b->hWnd);
+ buffer = malloc((textSize + len + 1) * sizeof(char));
+
+ if (buffer) {
+ GetWindowText(b->hWnd, buffer, textSize + 1);
+ strcat(buffer, extText);
+ SetWindowText(b->hWnd, buffer);
+ free(extText);
+ free(buffer);
+ } else {
+ abort();
+ }
+
+ if (b->option&BO_READONLY) {
+ SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0);
+ }
// scroll to bottom of text box
SendMessage(b->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)10000);
@@ -138,146 +137,146 @@ void wTextAppend(
BOOL_T wTextSave(
- wText_p b,
- const char * fileName)
+ wText_p b,
+ const char * fileName)
{
- FILE * f;
- int lc, l, len;
- char line[255];
- f = wFileOpen(fileName, "w");
-
- if (f == NULL) {
- MessageBox(((wControl_p)(b->parent))->hWnd, "TextSave", "", MB_OK|MB_ICONHAND);
- return FALSE;
- }
-
- lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
-
- for (l=0; l<lc; l++) {
- *(WORD*)line = sizeof(line)-1;
- len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line);
- line[len] = '\0';
- fprintf(f, "%s\n", line);
- }
-
- fclose(f);
- return TRUE;
+ FILE * f;
+ int lc, l, len;
+ char line[255];
+ f = wFileOpen(fileName, "w");
+
+ if (f == NULL) {
+ MessageBox(((wControl_p)(b->parent))->hWnd, "TextSave", "", MB_OK|MB_ICONHAND);
+ return FALSE;
+ }
+
+ lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
+
+ for (l=0; l<lc; l++) {
+ *(WORD*)line = sizeof(line)-1;
+ len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line);
+ line[len] = '\0';
+ fprintf(f, "%s\n", line);
+ }
+
+ fclose(f);
+ return TRUE;
}
BOOL_T wTextPrint(
- wText_p b)
+ wText_p b)
{
- int lc, l, len;
- char line[255];
- HDC hDc;
- int lineSpace;
- int linesPerPage;
- int currentLine;
- int IOStatus;
- TEXTMETRIC textMetric;
- DOCINFO docInfo;
- hDc = mswGetPrinterDC();
+ int lc, l, len;
+ char line[255];
+ HDC hDc;
+ int lineSpace;
+ int linesPerPage;
+ int currentLine;
+ int IOStatus;
+ TEXTMETRIC textMetric;
+ DOCINFO docInfo;
+ hDc = mswGetPrinterDC();
HFONT hFont, hOldFont;
- if (hDc == (HDC)0) {
- MessageBox(((wControl_p)(b->parent))->hWnd, "Print", "Cannot print",
- MB_OK|MB_ICONHAND);
- return FALSE;
- }
+ if (hDc == (HDC)0) {
+ MessageBox(((wControl_p)(b->parent))->hWnd, "Print", "Cannot print",
+ MB_OK|MB_ICONHAND);
+ return FALSE;
+ }
- docInfo.cbSize = sizeof(DOCINFO);
- docInfo.lpszDocName = "XTrkcad Log";
- docInfo.lpszOutput = (LPSTR)NULL;
+ docInfo.cbSize = sizeof(DOCINFO);
+ docInfo.lpszDocName = "XTrkcad Log";
+ docInfo.lpszOutput = (LPSTR)NULL;
- // Retrieve a handle to the monospaced stock font.
+ // Retrieve a handle to the monospaced stock font.
hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
hOldFont = (HFONT)SelectObject(hDc, hFont);
- if (StartDoc(hDc, &docInfo) < 0) {
- MessageBox(((wControl_p)(b->parent))->hWnd, "Unable to start print job", NULL,
- MB_OK|MB_ICONHAND);
- DeleteDC(hDc);
- return FALSE;
- }
-
- StartPage(hDc);
-
- GetTextMetrics(hDc, &textMetric);
- lineSpace = textMetric.tmHeight + textMetric.tmExternalLeading;
- linesPerPage = GetDeviceCaps(hDc, VERTRES) / lineSpace;
- currentLine = 1;
- lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
- IOStatus = 0;
-
- for (l=0; l<lc; l++) {
- *(WORD*)line = sizeof(line)-1;
- len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line);
- TextOut(hDc, 0, currentLine*lineSpace, line, len);
-
- if (++currentLine > linesPerPage) {
- IOStatus = EndPage(hDc);
- if (IOStatus < 0 ) {
- break;
- }
- StartPage(hDc);
+ if (StartDoc(hDc, &docInfo) < 0) {
+ MessageBox(((wControl_p)(b->parent))->hWnd, "Unable to start print job", NULL,
+ MB_OK|MB_ICONHAND);
+ DeleteDC(hDc);
+ return FALSE;
+ }
+
+ StartPage(hDc);
+
+ GetTextMetrics(hDc, &textMetric);
+ lineSpace = textMetric.tmHeight + textMetric.tmExternalLeading;
+ linesPerPage = GetDeviceCaps(hDc, VERTRES) / lineSpace;
+ currentLine = 1;
+ lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
+ IOStatus = 0;
+
+ for (l=0; l<lc; l++) {
+ *(WORD*)line = sizeof(line)-1;
+ len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line);
+ TextOut(hDc, 0, currentLine*lineSpace, line, len);
+
+ if (++currentLine > linesPerPage) {
+ IOStatus = EndPage(hDc);
+ if (IOStatus < 0 ) {
+ break;
+ }
+ StartPage(hDc);
currentLine = 1;
}
- }
+ }
- if (IOStatus >= 0 ) {
- EndPage(hDc);
- EndDoc(hDc);
- }
+ if (IOStatus >= 0 ) {
+ EndPage(hDc);
+ EndDoc(hDc);
+ }
SelectObject(hDc, hOldFont);
- DeleteDC(hDc);
- return TRUE;
+ DeleteDC(hDc);
+ return TRUE;
}
wBool_t wTextGetModified(
- wText_p b)
+ wText_p b)
{
- int rc;
- rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, (WPARAM)0, (LPARAM)0);
- return (wBool_t)rc;
+ int rc;
+ rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, (WPARAM)0, (LPARAM)0);
+ return (wBool_t)rc;
}
/**
* Get the size of the text in the text control including terminating '\0'. Note that
* the text actually might be shorter if the text includes CRs.
- *
+ *
* \param b IN text control
* \return required buffer size
*/
int wTextGetSize(
- wText_p b)
+ wText_p b)
{
int len;
len = GetWindowTextLength(b->hWnd);
- return len + 1;
+ return len + 1;
}
-/**
+/**
* Get the text from a textentry. The buffer must be large enough for the text and
* the terminating \0.
* In case the string contains carriage returns these are removed. The returned string
- * will be shortened accordingly.
+ * will be shortened accordingly.
* To get the complete contents the buffer size must be equal or greater then the return
* value of wTextGetSize()
- *
+ *
* \param b IN text entry
* \param t IN/OUT buffer for text
- * \param s IN size of buffer
+ * \param s IN size of buffer
*/
-
+
void wTextGetText(
- wText_p b,
- char * t,
- int s)
+ wText_p b,
+ char * t,
+ int s)
{
char *buffer = malloc(s);
char *ptr = buffer;
@@ -296,153 +295,154 @@ void wTextGetText(
void wTextSetReadonly(
- wText_p b,
- wBool_t ro)
+ wText_p b,
+ wBool_t ro)
{
- if (ro) {
- b->option |= BO_READONLY;
- } else {
- b->option &= ~BO_READONLY;
- }
+ if (ro) {
+ b->option |= BO_READONLY;
+ } else {
+ b->option &= ~BO_READONLY;
+ }
- SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0);
+ SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0);
}
void wTextSetSize(
- wText_p bt,
- wWinPix_t width,
- wWinPix_t height)
+ wText_p bt,
+ wWinPix_t width,
+ wWinPix_t height)
{
- bt->w = width;
- bt->h = height;
+ bt->w = width;
+ bt->h = height;
- if (!SetWindowPos(bt->hWnd, HWND_TOP, 0, 0,
- bt->w, bt->h, SWP_NOMOVE|SWP_NOZORDER)) {
- mswFail("wTextSetSize: SetWindowPos");
- }
+ if (!SetWindowPos(bt->hWnd, HWND_TOP, 0, 0,
+ bt->w, bt->h, SWP_NOMOVE|SWP_NOZORDER)) {
+ mswFail("wTextSetSize: SetWindowPos");
+ }
}
void wTextComputeSize(
- wText_p bt,
- wWinPix_t rows,
- wWinPix_t lines,
- wWinPix_t * w,
- wWinPix_t * h)
+ wText_p bt,
+ wWinPix_t rows,
+ wWinPix_t lines,
+ wWinPix_t * w,
+ wWinPix_t * h)
{
- static wWinPix_t scrollV_w = -1;
- static wWinPix_t scrollH_h = -1;
- HDC hDc;
- TEXTMETRIC metrics;
-
- if (scrollV_w < 0) {
- scrollV_w = GetSystemMetrics(SM_CXVSCROLL);
- }
-
- if (scrollH_h < 0) {
- scrollH_h = GetSystemMetrics(SM_CYHSCROLL);
- }
-
- hDc = GetDC(bt->hWnd);
- GetTextMetrics(hDc, &metrics);
- *w = rows * metrics.tmAveCharWidth + scrollV_w;
- *h = lines * (metrics.tmHeight + metrics.tmExternalLeading);
- ReleaseDC(bt->hWnd, hDc);
-
- if (bt->option&BT_HSCROLL) {
- *h += scrollH_h;
- }
+ static wWinPix_t scrollV_w = -1;
+ static wWinPix_t scrollH_h = -1;
+ HDC hDc;
+ TEXTMETRIC metrics;
+
+ if (scrollV_w < 0) {
+ scrollV_w = GetSystemMetrics(SM_CXVSCROLL);
+ }
+
+ if (scrollH_h < 0) {
+ scrollH_h = GetSystemMetrics(SM_CYHSCROLL);
+ }
+
+ hDc = GetDC(bt->hWnd);
+ GetTextMetrics(hDc, &metrics);
+ *w = rows * metrics.tmAveCharWidth + scrollV_w;
+ *h = lines * (metrics.tmHeight + metrics.tmExternalLeading);
+ ReleaseDC(bt->hWnd, hDc);
+
+ if (bt->option&BT_HSCROLL) {
+ *h += scrollH_h;
+ }
}
void wTextSetPosition(
- wText_p bt,
- int pos)
+ wText_p bt,
+ int pos)
{
- LRESULT rc;
- rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535, 0));
+ LRESULT rc;
+ rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535,
+ 0));
}
static void textDoneProc(wControl_p b)
{
- wText_p t = (wText_p)b;
- HDC hDc;
- hDc = GetDC(t->hWnd);
- SelectObject(hDc, mswOldTextFont);
- ReleaseDC(t->hWnd, hDc);
+ wText_p t = (wText_p)b;
+ HDC hDc;
+ hDc = GetDC(t->hWnd);
+ SelectObject(hDc, mswOldTextFont);
+ ReleaseDC(t->hWnd, hDc);
}
static callBacks_t textCallBacks = {
- mswRepaintLabel,
- textDoneProc,
- NULL
+ mswRepaintLabel,
+ textDoneProc,
+ NULL
};
wText_p wTextCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- wWinPix_t width,
- wWinPix_t height)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ wWinPix_t width,
+ wWinPix_t height)
{
- wText_p b;
- DWORD style;
- RECT rect;
- int index;
- b = mswAlloc(parent, B_TEXT, labelStr, sizeof *b, NULL, &index);
- mswComputePos((wControl_p)b, x, y);
- b->option = option;
- style = ES_MULTILINE | ES_LEFT | ES_AUTOVSCROLL | ES_WANTRETURN |
- WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL;
+ wText_p b;
+ DWORD style;
+ RECT rect;
+ int index;
+ b = mswAlloc(parent, B_TEXT, labelStr, sizeof *b, NULL, &index);
+ mswComputePos((wControl_p)b, x, y);
+ b->option = option;
+ style = ES_MULTILINE | ES_LEFT | ES_AUTOVSCROLL | ES_WANTRETURN |
+ WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL;
#ifdef BT_HSCROLL
- if (option & BT_HSCROLL) {
- style |= WS_HSCROLL | ES_AUTOHSCROLL;
- }
+ if (option & BT_HSCROLL) {
+ style |= WS_HSCROLL | ES_AUTOHSCROLL;
+ }
#endif
- /* if (option & BO_READONLY)
- style |= ES_READONLY;*/
- b->hWnd = CreateWindow("EDIT", NULL,
- style, b->x, b->y,
- width, height,
- ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL);
-
- if (b->hWnd == NULL) {
- mswFail("CreateWindow(TEXT)");
- return b;
- }
-
- if (option & BT_FIXEDFONT) {
- if (fixedTextFont == (HFONT)0) {
- fixedTextFont = CreateFontIndirect(&fixedFont);
- }
-
- SendMessage(b->hWnd, WM_SETFONT, (WPARAM)fixedTextFont, (LPARAM)MAKELONG(1, 0));
- } else if (!mswThickFont) {
- SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0);
- }
-
- b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0);
-
- if (option & BT_CHARUNITS) {
- wWinPix_t w, h;
- wTextComputeSize(b, width, height, &w, &h);
-
- if (!SetWindowPos(b->hWnd, HWND_TOP, 0, 0,
- w, h, SWP_NOMOVE|SWP_NOZORDER)) {
- mswFail("wTextCreate: SetWindowPos");
- }
- }
-
- GetWindowRect(b->hWnd, &rect);
- b->w = rect.right - rect.left;
- b->h = rect.bottom - rect.top;
- mswAddButton((wControl_p)b, FALSE, helpStr);
- mswCallBacks[B_TEXT] = &textCallBacks;
- return b;
+ /* if (option & BO_READONLY)
+ style |= ES_READONLY;*/
+ b->hWnd = CreateWindow("EDIT", NULL,
+ style, b->x, b->y,
+ width, height,
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL);
+
+ if (b->hWnd == NULL) {
+ mswFail("CreateWindow(TEXT)");
+ return b;
+ }
+
+ if (option & BT_FIXEDFONT) {
+ if (fixedTextFont == (HFONT)0) {
+ fixedTextFont = CreateFontIndirect(&fixedFont);
+ }
+
+ SendMessage(b->hWnd, WM_SETFONT, (WPARAM)fixedTextFont, (LPARAM)MAKELONG(1, 0));
+ } else {
+ SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0);
+ }
+
+ b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0);
+
+ if (option & BT_CHARUNITS) {
+ wWinPix_t w, h;
+ wTextComputeSize(b, width, height, &w, &h);
+
+ if (!SetWindowPos(b->hWnd, HWND_TOP, 0, 0,
+ w, h, SWP_NOMOVE|SWP_NOZORDER)) {
+ mswFail("wTextCreate: SetWindowPos");
+ }
+ }
+
+ GetWindowRect(b->hWnd, &rect);
+ b->w = rect.right - rect.left;
+ b->h = rect.bottom - rect.top;
+ mswAddButton((wControl_p)b, FALSE, helpStr);
+ mswCallBacks[B_TEXT] = &textCallBacks;
+ return b;
}
diff --git a/app/wlib/mswlib/simple-gettext.c b/app/wlib/mswlib/simple-gettext.c
index 951ce4c..592e3a3 100644
--- a/app/wlib/mswlib/simple-gettext.c
+++ b/app/wlib/mswlib/simple-gettext.c
@@ -1,4 +1,4 @@
-/* \file simple-gettext.c
+/* \file simple-gettext.c
* a simplified version of gettext.
* Copyright (C) 1995, 1996, 1997, 1999,
* 2005 Free Software Foundation, Inc.
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* This is a simplified version of gettext written by Ulrich Drepper.
@@ -28,8 +28,8 @@
*/
/*
- * Based on the simple-gettext from GnuPG a version appropriate for the
- * needs of XTrackCAD was derived. This is a workaround for any compiler
+ * Based on the simple-gettext from GnuPG a version appropriate for the
+ * needs of XTrackCAD was derived. This is a workaround for any compiler
* specifics or runtime library dependencies. mf 26.07.09
*/
@@ -50,10 +50,10 @@
#include "mswint.h"
#if _MSC_VER > 1300
- #define stricmp _stricmp
- #define strnicmp _strnicmp
- #define strdup _strdup
- #define fileno _fileno
+#define stricmp _stricmp
+#define strnicmp _strnicmp
+#define strdup _strdup
+#define fileno _fileno
#endif
typedef unsigned long u32;
@@ -67,60 +67,56 @@ typedef unsigned long u32;
/* Header for binary .mo file format. */
-struct mo_file_header
-{
- /* The magic number. */
- u32 magic;
- /* The revision number of the file format. */
- u32 revision;
- /* The number of strings pairs. */
- u32 nstrings;
- /* Offset of table with start offsets of original strings. */
- u32 orig_tab_offset;
- /* Offset of table with start offsets of translation strings. */
- u32 trans_tab_offset;
- /* Size of hashing table. */
- u32 hash_tab_size;
- /* Offset of first hashing entry. */
- u32 hash_tab_offset;
+struct mo_file_header {
+ /* The magic number. */
+ u32 magic;
+ /* The revision number of the file format. */
+ u32 revision;
+ /* The number of strings pairs. */
+ u32 nstrings;
+ /* Offset of table with start offsets of original strings. */
+ u32 orig_tab_offset;
+ /* Offset of table with start offsets of translation strings. */
+ u32 trans_tab_offset;
+ /* Size of hashing table. */
+ u32 hash_tab_size;
+ /* Offset of first hashing entry. */
+ u32 hash_tab_offset;
};
-struct string_desc
-{
- /* Length of addressed string. */
- u32 length;
- /* Offset of string in file. */
- u32 offset;
+struct string_desc {
+ /* Length of addressed string. */
+ u32 length;
+ /* Offset of string in file. */
+ u32 offset;
};
-struct overflow_space_s
-{
- struct overflow_space_s *next;
- u32 idx;
- char d[1];
+struct overflow_space_s {
+ struct overflow_space_s *next;
+ u32 idx;
+ char d[1];
};
-struct loaded_domain
-{
- char *data;
- int must_swap;
- u32 nstrings;
- char *mapped; /* 0 = not yet mapped, 1 = mapped,
+struct loaded_domain {
+ char *data;
+ int must_swap;
+ u32 nstrings;
+ char *mapped; /* 0 = not yet mapped, 1 = mapped,
2 = mapped to
overflow space */
- struct overflow_space_s *overflow_space;
- struct string_desc *orig_tab;
- struct string_desc *trans_tab;
- u32 hash_size;
- u32 *hash_tab;
+ struct overflow_space_s *overflow_space;
+ struct string_desc *orig_tab;
+ struct string_desc *trans_tab;
+ u32 hash_size;
+ u32 *hash_tab;
};
static struct loaded_domain *the_domain;
/**
* Translate the input string from UTF8 to Windows codepage.
- *
+ *
* \param str IN string in UTF-8 format to translate.
* \param len IN number of chars to translate
* \param dummy IN ?
@@ -129,7 +125,7 @@ static struct loaded_domain *the_domain;
char *
utf8_to_native( char *str, unsigned int len, int dummy )
{
- /* maximum output length is size of string * 2 */
+ /* maximum output length is size of string * 2 */
int buflen = (len + 1) * 2;
char *buf = malloc( buflen );
int wcharLen;
@@ -143,22 +139,24 @@ utf8_to_native( char *str, unsigned int len, int dummy )
/* the system codepage, we need to take two steps */
/* 1. convert from UTF-8 to UTF-16 */
- wcharLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, (LPWSTR)buf, buflen / 2 );
-
+ wcharLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, (LPWSTR)buf,
+ buflen / 2 );
+
/* 2. convert from UTF-8 to system codepage */
- WideCharToMultiByte(CP_ACP, 0, (LPWSTR)buf, wcharLen, resBuffer, len + 1, NULL, NULL );
+ WideCharToMultiByte(CP_ACP, 0, (LPWSTR)buf, wcharLen, resBuffer, len + 1, NULL,
+ NULL );
}
free(buf);
- return( resBuffer );
+ return( resBuffer );
}
static u32
do_swap_u32( u32 i )
{
- return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
+ return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
}
#define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data) )
@@ -174,205 +172,203 @@ do_swap_u32( u32 i )
static unsigned long
hash_string( const char *str_param )
{
- unsigned long int hval, g;
- const char *str = str_param;
-
- hval = 0;
- while (*str != '\0')
- {
- hval <<= 4;
- hval += (unsigned long int) *str++;
- g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
- if (g != 0)
- {
- hval ^= g >> (HASHWORDBITS - 8);
- hval ^= g;
+ unsigned long int hval, g;
+ const char *str = str_param;
+
+ hval = 0;
+ while (*str != '\0') {
+ hval <<= 4;
+ hval += (unsigned long int) *str++;
+ g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
+ if (g != 0) {
+ hval ^= g >> (HASHWORDBITS - 8);
+ hval ^= g;
+ }
}
- }
- return hval;
+ return hval;
}
static struct loaded_domain *
load_domain( const char *filename )
{
- FILE *fp;
- size_t size;
- struct stat st;
- struct mo_file_header *data = NULL;
- struct loaded_domain *domain = NULL;
- size_t to_read;
- char *read_ptr;
-
- fp = fopen( filename, "rb" );
- if( !fp )
- return NULL; /* can't open the file */
- /* we must know about the size of the file */
- if( fstat( fileno(fp ), &st )
- || (size = (size_t)st.st_size) != st.st_size
- || size < sizeof (struct mo_file_header) ) {
- fclose( fp );
- return NULL;
- }
-
- data = malloc( size );
- if( !data ) {
- fclose( fp );
- return NULL; /* out of memory */
- }
-
- to_read = size;
- read_ptr = (char *) data;
- do {
- unsigned long int nb = (unsigned int)fread( read_ptr, 1, to_read, fp );
- if( nb < to_read ) {
- fclose (fp);
- free(data);
- return NULL; /* read error */
+ FILE *fp;
+ size_t size;
+ struct stat st;
+ struct mo_file_header *data = NULL;
+ struct loaded_domain *domain = NULL;
+ size_t to_read;
+ char *read_ptr;
+
+ fp = fopen( filename, "rb" );
+ if( !fp ) {
+ return NULL; /* can't open the file */
}
- read_ptr += nb;
- to_read -= nb;
- } while( to_read > 0 );
- fclose (fp);
-
- /* Using the magic number we can test whether it really is a message
- * catalog file. */
- if( data->magic != MAGIC && data->magic != MAGIC_SWAPPED ) {
- /* The magic number is wrong: not a message catalog file. */
- free( data );
- return NULL;
- }
-
- domain = calloc( 1, sizeof *domain );
- if( !domain ) {
- free( data );
- return NULL;
- }
- domain->data = (char *) data;
- domain->must_swap = data->magic != MAGIC;
-
- /* Fill in the information about the available tables. */
- switch( SWAPIT(domain->must_swap, data->revision) ) {
- case 0:
- domain->nstrings = SWAPIT(domain->must_swap, data->nstrings);
- domain->orig_tab = (struct string_desc *)
- ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset));
- domain->trans_tab = (struct string_desc *)
- ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset));
- domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size);
- domain->hash_tab = (u32 *)
- ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset));
- break;
-
- default: /* This is an invalid revision. */
- free( data );
- free( domain );
- return NULL;
- }
-
- /* Allocate an array to keep track of code page mappings. */
- domain->mapped = calloc( 1, domain->nstrings );
- if( !domain->mapped ) {
- free( data );
- free( domain );
- return NULL;
- }
-
- return domain;
+ /* we must know about the size of the file */
+ if( fstat( fileno(fp ), &st )
+ || (size = (size_t)st.st_size) != st.st_size
+ || size < sizeof (struct mo_file_header) ) {
+ fclose( fp );
+ return NULL;
+ }
+
+ data = malloc( size );
+ if( !data ) {
+ fclose( fp );
+ return NULL; /* out of memory */
+ }
+
+ to_read = size;
+ read_ptr = (char *) data;
+ do {
+ unsigned long int nb = (unsigned int)fread( read_ptr, 1, to_read, fp );
+ if( nb < to_read ) {
+ fclose (fp);
+ free(data);
+ return NULL; /* read error */
+ }
+ read_ptr += nb;
+ to_read -= nb;
+ } while( to_read > 0 );
+ fclose (fp);
+
+ /* Using the magic number we can test whether it really is a message
+ * catalog file. */
+ if( data->magic != MAGIC && data->magic != MAGIC_SWAPPED ) {
+ /* The magic number is wrong: not a message catalog file. */
+ free( data );
+ return NULL;
+ }
+
+ domain = calloc( 1, sizeof *domain );
+ if( !domain ) {
+ free( data );
+ return NULL;
+ }
+ domain->data = (char *) data;
+ domain->must_swap = data->magic != MAGIC;
+
+ /* Fill in the information about the available tables. */
+ switch( SWAPIT(domain->must_swap, data->revision) ) {
+ case 0:
+ domain->nstrings = SWAPIT(domain->must_swap, data->nstrings);
+ domain->orig_tab = (struct string_desc *)
+ ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset));
+ domain->trans_tab = (struct string_desc *)
+ ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset));
+ domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size);
+ domain->hash_tab = (u32 *)
+ ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset));
+ break;
+
+ default: /* This is an invalid revision. */
+ free( data );
+ free( domain );
+ return NULL;
+ }
+
+ /* Allocate an array to keep track of code page mappings. */
+ domain->mapped = calloc( 1, domain->nstrings );
+ if( !domain->mapped ) {
+ free( data );
+ free( domain );
+ return NULL;
+ }
+
+ return domain;
}
/**
* Set the file used for translations. Pass a NULL to disable
- * translation. A new filename may be set at anytime. WARNING:
- * After changing the filename you should not access any data
+ * translation. A new filename may be set at anytime. WARNING:
+ * After changing the filename you should not access any data
* retrieved by gettext().
*/
int
set_gettext_file ( const char *filename, const char *regkey )
{
- struct loaded_domain *domain = NULL;
-
- if( filename && *filename ) {
- if( filename[0] == '/'
- || ( isalpha(filename[0])
- && filename[1] == ':'
- && (filename[2] == '/' || filename[2] == '\\') )
- ) {
- /* absolute path - use it as is */
- domain = load_domain( filename );
+ struct loaded_domain *domain = NULL;
+
+ if( filename && *filename ) {
+ if( filename[0] == '/'
+ || ( isalpha(filename[0])
+ && filename[1] == ':'
+ && (filename[2] == '/' || filename[2] == '\\') )
+ ) {
+ /* absolute path - use it as is */
+ domain = load_domain( filename );
+ }
+ if (!domain) {
+ return -1;
+ }
+ }
+
+ if( the_domain ) {
+ struct overflow_space_s *os, *os2;
+ free( the_domain->data );
+ free( the_domain->mapped );
+ for (os=the_domain->overflow_space; os; os = os2) {
+ os2 = os->next;
+ free (os);
+ }
+ free( the_domain );
+ the_domain = NULL;
}
- if (!domain)
- return -1;
- }
-
- if( the_domain ) {
- struct overflow_space_s *os, *os2;
- free( the_domain->data );
- free( the_domain->mapped );
- for (os=the_domain->overflow_space; os; os = os2) {
- os2 = os->next;
- free (os);
- }
- free( the_domain );
- the_domain = NULL;
- }
- the_domain = domain;
- return 0;
+ the_domain = domain;
+ return 0;
}
/**
- * Return the required string from the message table. Before returning the result,
+ * Return the required string from the message table. Before returning the result,
* codepage translation from UTF8 to current codepage is performed.
*/
static const char*
get_string( struct loaded_domain *domain, u32 idx )
{
- struct overflow_space_s *os;
- char *p;
-
- p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset);
- if (!domain->mapped[idx])
- {
- size_t plen, buflen;
- char *buf;
-
- domain->mapped[idx] = 1;
-
- plen = strlen (p);
- buf = utf8_to_native (p, (unsigned int)plen, -1);
- buflen = strlen (buf);
- if (buflen <= plen){
- strcpy (p, buf);
- free( buf );
- } else {
- /* There is not enough space for the translation - store it
- in the overflow_space else and mark that in the mapped
- array. Because we expect that this won't happen too
- often, we use a simple linked list. */
- os = malloc (sizeof *os + buflen);
- if (os)
- {
- os->idx = idx;
- strcpy (os->d, buf);
- os->next = domain->overflow_space;
- domain->overflow_space = os;
- p = os->d;
- }
- else
- p = "ERROR in GETTEXT MALLOC";
- free (buf);
- }
- }
- else if (domain->mapped[idx] == 2)
- { /* We need to get the string from the overflow_space. */
- for (os=domain->overflow_space; os; os = os->next)
- if (os->idx == idx)
- return (const char*)os->d;
- p = "ERROR in GETTEXT\n";
- }
- return (const char*)p;
+ struct overflow_space_s *os;
+ char *p;
+
+ p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset);
+ if (!domain->mapped[idx]) {
+ size_t plen, buflen;
+ char *buf;
+
+ domain->mapped[idx] = 1;
+
+ plen = strlen (p);
+ buf = utf8_to_native (p, (unsigned int)plen, -1);
+ buflen = strlen (buf);
+ if (buflen <= plen) {
+ strcpy (p, buf);
+ free( buf );
+ } else {
+ /* There is not enough space for the translation - store it
+ in the overflow_space else and mark that in the mapped
+ array. Because we expect that this won't happen too
+ often, we use a simple linked list. */
+ os = malloc (sizeof *os + buflen);
+ if (os) {
+ os->idx = idx;
+ strcpy (os->d, buf);
+ os->next = domain->overflow_space;
+ domain->overflow_space = os;
+ p = os->d;
+ } else {
+ p = "ERROR in GETTEXT MALLOC";
+ }
+ free (buf);
+ }
+ } else if (domain->mapped[idx] == 2) {
+ /* We need to get the string from the overflow_space. */
+ for (os=domain->overflow_space; os; os = os->next)
+ if (os->idx == idx) {
+ return (const char*)os->d;
+ }
+ p = "ERROR in GETTEXT\n";
+ }
+ return (const char*)p;
}
/**
@@ -382,78 +378,85 @@ get_string( struct loaded_domain *domain, u32 idx )
char *
gettext( const char *msgid )
{
- struct loaded_domain *domain;
- size_t act = 0;
- size_t top, bottom;
-
- if( !(domain = the_domain) )
- goto not_found;
-
- /* Locate the MSGID and its translation. */
- if( domain->hash_size > 2 && domain->hash_tab ) {
- /* Use the hashing table. */
- u32 len = (u32)strlen (msgid);
- u32 hash_val = hash_string (msgid);
- u32 idx = hash_val % domain->hash_size;
- u32 incr = 1 + (hash_val % (domain->hash_size - 2));
- u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]);
-
- if ( !nstr ) /* Hash table entry is empty. */
- goto not_found;
-
- if( SWAPIT(domain->must_swap,
- domain->orig_tab[nstr - 1].length) == len
- && !strcmp( msgid,
- domain->data + SWAPIT(domain->must_swap,
- domain->orig_tab[nstr - 1].offset)) )
- return (char *)get_string( domain, nstr - 1 );
-
- for(;;) {
- if (idx >= domain->hash_size - incr)
- idx -= domain->hash_size - incr;
- else
- idx += incr;
-
- nstr = SWAPIT(domain->must_swap, domain->hash_tab[idx]);
- if( !nstr )
- goto not_found; /* Hash table entry is empty. */
-
- if ( SWAPIT(domain->must_swap,
- domain->orig_tab[nstr - 1].length) == len
- && !strcmp (msgid,
- domain->data + SWAPIT(domain->must_swap,
- domain->orig_tab[nstr - 1].offset)))
- return (char *)get_string( domain, nstr-1 );
+ struct loaded_domain *domain;
+ size_t act = 0;
+ size_t top, bottom;
+
+ if( !(domain = the_domain) ) {
+ goto not_found;
+ }
+
+ /* Locate the MSGID and its translation. */
+ if( domain->hash_size > 2 && domain->hash_tab ) {
+ /* Use the hashing table. */
+ u32 len = (u32)strlen (msgid);
+ u32 hash_val = hash_string (msgid);
+ u32 idx = hash_val % domain->hash_size;
+ u32 incr = 1 + (hash_val % (domain->hash_size - 2));
+ u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]);
+
+ if ( !nstr ) { /* Hash table entry is empty. */
+ goto not_found;
+ }
+
+ if( SWAPIT(domain->must_swap,
+ domain->orig_tab[nstr - 1].length) == len
+ && !strcmp( msgid,
+ domain->data + SWAPIT(domain->must_swap,
+ domain->orig_tab[nstr - 1].offset)) ) {
+ return (char *)get_string( domain, nstr - 1 );
+ }
+
+ for(;;) {
+ if (idx >= domain->hash_size - incr) {
+ idx -= domain->hash_size - incr;
+ } else {
+ idx += incr;
+ }
+
+ nstr = SWAPIT(domain->must_swap, domain->hash_tab[idx]);
+ if( !nstr ) {
+ goto not_found; /* Hash table entry is empty. */
+ }
+
+ if ( SWAPIT(domain->must_swap,
+ domain->orig_tab[nstr - 1].length) == len
+ && !strcmp (msgid,
+ domain->data + SWAPIT(domain->must_swap,
+ domain->orig_tab[nstr - 1].offset))) {
+ return (char *)get_string( domain, nstr-1 );
+ }
+ }
+ /* NOTREACHED */
+ }
+
+ /* Now we try the default method: binary search in the sorted
+ array of messages. */
+ bottom = 0;
+ top = domain->nstrings;
+ while( bottom < top ) {
+ int cmp_val;
+
+ act = (bottom + top) / 2;
+ cmp_val = strcmp(msgid, domain->data
+ + SWAPIT(domain->must_swap,
+ domain->orig_tab[act].offset));
+ if (cmp_val < 0) {
+ top = act;
+ } else if (cmp_val > 0) {
+ bottom = act + 1;
+ } else {
+ return (char *)get_string( domain, (int)(act) );
+ }
}
- /* NOTREACHED */
- }
-
- /* Now we try the default method: binary search in the sorted
- array of messages. */
- bottom = 0;
- top = domain->nstrings;
- while( bottom < top ) {
- int cmp_val;
-
- act = (bottom + top) / 2;
- cmp_val = strcmp(msgid, domain->data
- + SWAPIT(domain->must_swap,
- domain->orig_tab[act].offset));
- if (cmp_val < 0)
- top = act;
- else if (cmp_val > 0)
- bottom = act + 1;
- else
- return (char *)get_string( domain, (int)(act) );
- }
-
- not_found:
- return (char *)msgid;
+
+not_found:
+ return (char *)msgid;
}
/**
- * This is the main initialization function for simple gettext. The message file is
- * opened and read into memory. The function must be called once before translating
+ * This is the main initialization function for simple gettext. The message file is
+ * opened and read into memory. The function must be called once before translating
* a string.
*
* The message files are expected to be in a directory named in the UNIXish form en_US
@@ -474,12 +477,13 @@ bindtextdomain( char *domainname, char *dirname )
loc = g_win32_getlocale();
/* make sure that path does not end with trailing slash */
- if( dirname[ strlen(dirname) ] == '/' )
+ if( dirname[ strlen(dirname) ] == '/' ) {
dirname[ strlen(dirname) ] = '\0';
+ }
/* allocate buffer for filename, 20 bytes should be enough for extension etc. */
dir = malloc( strlen( domainname ) + strlen( dirname ) + strlen( loc ) + 20 );
-
+
if( dir ) {
/* create the full filename */
sprintf( dir, "%s/%s/LC_MESSAGES/%s.mo", dirname, loc, domainname );
@@ -487,18 +491,18 @@ bindtextdomain( char *domainname, char *dirname )
set_gettext_file( dir, NULL );
free( dir );
}
-
+
free( loc );
return( NULL );
}
/**
- * This is a dummy function to maintain source code compatibility
+ * This is a dummy function to maintain source code compatibility
* with other implementations of gettext.
* For this implementation, UTF-8 input encoding is assumed
*
* \param domainname IN domain
- * \param codeset In codeset
+ * \param codeset In codeset
* \return always NULL
*/
@@ -509,7 +513,7 @@ bind_textdomain_codeset(char *domainname, char *codeset )
}
/**
- * This is a dummy function to maintain source code compatibility
+ * This is a dummy function to maintain source code compatibility
* with other implementations of gettext.
*
* \param domainname IN domain
diff --git a/app/wlib/mswlib/sysinfo.c b/app/wlib/mswlib/sysinfo.c
new file mode 100644
index 0000000..b4745f5
--- /dev/null
+++ b/app/wlib/mswlib/sysinfo.c
@@ -0,0 +1,138 @@
+/** \file sysinfo.c
+ * Collect info about runtime environment
+*/
+
+/* XTrkCad - Model Railroad CAD
+ * Copyright (C) 2024 Martin Fischer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <process.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <Windows.h>
+#include <fileapi.h>
+#include <shlobj.h>
+#include <Shlwapi.h>
+
+#include <wlib.h>
+#include "mswint.h"
+
+#ifdef WINDOWS
+#define itoa(a,b,c) _itoa(a,b,c)
+#define getpid() _getpid()
+#endif
+
+static char buffer[MAX_PATH + 1];
+
+/**
+ * Return the path to a temporary directory. The directory is not created.
+ * The result is put into a buffer and is only valid immediately after the call.
+ *
+ * \return pointer to fully qualified directory path
+ */
+
+char *
+wGetTempPath()
+{
+ unsigned retChars;
+
+ retChars = GetTempPath(MAX_PATH + 1, buffer);
+
+ if (retChars <= MAX_PATH + 1) {
+ char str[20];
+ strcat(buffer, "xtc");
+ itoa(getpid(), str, 10);
+ strcat(buffer, str);
+ }
+
+ return(buffer);
+}
+
+/**
+ * Get the Windows version. This function uses the Windows ver command to
+ * retrieve the OS version. The result is put into a buffer and is only
+ * valid immediately after the call.
+ *
+ * \return buffer containing the zero terminated string
+ *
+ */
+
+char *
+wGetOSVersion()
+{
+ FILE* pPipe;
+ pPipe = _popen("ver", "r");
+
+ while (fgets(buffer, sizeof(buffer), pPipe))
+ ;
+
+ if (buffer[strlen(buffer) -1] == '\n')
+ buffer[strlen(buffer) -1 ] = '\0';
+ _pclose(pPipe);
+
+ return(buffer);
+}
+
+/**
+ * Get the name of the configuration file.
+ *
+ * \return pointer to the filename.
+ *
+ */
+
+char *
+wGetProfileFilename()
+{
+ return(mswProfileFile);
+}
+
+/**
+ * Get the name of the current user. The result is put into a buffer and is only
+ * valid immediately after the call.
+ *
+ * \return buffer containing the zero terminated string
+ *
+ */
+
+char *
+wGetUserID()
+{
+ DWORD bufferSize = sizeof(buffer);
+
+ GetUserName(buffer, &bufferSize);
+
+ return(buffer);
+}
+
+/** Get the user's profile directory. Other than on UNIX Windows differentiates
+ * between the home directory and and the profile directory.
+ *
+ * \return pointer to the user's profile directory
+ */
+
+const char* wGetUserHomeRootDir(void)
+{
+ if (SHGetSpecialFolderPath(NULL, mswTmpBuff, CSIDL_PROFILE, 0) == 0) {
+ wNoticeEx(NT_ERROR, "Cannot get user's profile directory", "Exit", NULL);
+ wExit(0);
+ return(NULL);
+ }
+ else {
+ return(mswTmpBuff);
+ }
+}
diff --git a/app/wlib/mswlib/unittest/CMakeLists.txt b/app/wlib/mswlib/unittest/CMakeLists.txt
index b91c1ff..9bebe2b 100644
--- a/app/wlib/mswlib/unittest/CMakeLists.txt
+++ b/app/wlib/mswlib/unittest/CMakeLists.txt
@@ -1,11 +1,23 @@
# build unit tests for the xtrkcad Windows library
add_executable(utf8test
+ "")
+
+target_sources(utf8test
+ PRIVATE
utf8test.c
../utf8conv.c
- )
+)
target_link_libraries(utf8test
- ${LIBS})
+ PRIVATE
+ xtrkcad-wlib
+ ${CMOCKA_LIBRARIES}
+)
add_test(UTF8ConversionTest utf8test)
+
+set_target_properties(
+ utf8test
+ PROPERTIES FOLDER UnitTests
+ )
diff --git a/app/wlib/mswlib/utf8conv.c b/app/wlib/mswlib/utf8conv.c
index 5a39b34..2363df9 100644
--- a/app/wlib/mswlib/utf8conv.c
+++ b/app/wlib/mswlib/utf8conv.c
@@ -19,10 +19,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <malloc.h>
#include <stdbool.h>
#include <string.h>
@@ -43,29 +42,29 @@
bool
wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength)
{
- unsigned int cnt = 2 * (unsigned int)(strlen(inString) + 1);
- char *tempBuffer = malloc(cnt);
-
- // convert to wide character (UTF16)
- MultiByteToWideChar(CP_ACP,
- 0,
- inString,
- -1,
- (LPWSTR)tempBuffer,
- cnt);
-
- // convert from wide char to UTF-8
- WideCharToMultiByte(CP_UTF8,
- 0,
- (LPCWCH)tempBuffer,
- -1,
- (LPSTR)outString,
- outStringLength,
- NULL,
- NULL);
-
- free(tempBuffer);
- return true;
+ unsigned int cnt = 2 * (unsigned int)(strlen(inString) + 1);
+ char *tempBuffer = malloc(cnt);
+
+ // convert to wide character (UTF16)
+ MultiByteToWideChar(CP_ACP,
+ 0,
+ inString,
+ -1,
+ (LPWSTR)tempBuffer,
+ cnt);
+
+ // convert from wide char to UTF-8
+ WideCharToMultiByte(CP_UTF8,
+ 0,
+ (LPCWCH)tempBuffer,
+ -1,
+ (LPSTR)outString,
+ outStringLength,
+ NULL,
+ NULL);
+
+ free(tempBuffer);
+ return true;
}
/**
@@ -81,43 +80,43 @@ wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength)
bool
wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength)
{
- unsigned int cnt = 2 * (int)(strlen(inString) + 1);
- char *tempBuffer = malloc(cnt);
-
- // convert to wide character (UTF16)
- MultiByteToWideChar(CP_UTF8,
- 0,
- inString,
- -1,
- (LPWSTR)tempBuffer,
- cnt);
-
-
- cnt = WideCharToMultiByte(CP_ACP,
- 0,
- (LPCWCH)tempBuffer,
- -1,
- (LPSTR)outString,
- 0L,
- NULL,
- NULL);
-
- if (outStringLength <= cnt) {
- return (false);
- }
-
- // convert from wide char to system codepage
- WideCharToMultiByte(CP_ACP,
- 0,
- (LPCWCH)tempBuffer,
- -1,
- (LPSTR)outString,
- outStringLength,
- NULL,
- NULL);
-
- free(tempBuffer);
- return true;
+ unsigned int cnt = 2 * (int)(strlen(inString) + 1);
+ char *tempBuffer = malloc(cnt);
+
+ // convert to wide character (UTF16)
+ MultiByteToWideChar(CP_UTF8,
+ 0,
+ inString,
+ -1,
+ (LPWSTR)tempBuffer,
+ cnt);
+
+
+ cnt = WideCharToMultiByte(CP_ACP,
+ 0,
+ (LPCWCH)tempBuffer,
+ -1,
+ (LPSTR)outString,
+ 0L,
+ NULL,
+ NULL);
+
+ if (outStringLength <= cnt) {
+ return (false);
+ }
+
+ // convert from wide char to system codepage
+ WideCharToMultiByte(CP_ACP,
+ 0,
+ (LPCWCH)tempBuffer,
+ -1,
+ (LPSTR)outString,
+ outStringLength,
+ NULL,
+ NULL);
+
+ free(tempBuffer);
+ return true;
}
/**
@@ -131,80 +130,80 @@ wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength)
bool wIsUTF8(const char * string)
{
- if (!string) {
- return 0;
- }
-
- const unsigned char * bytes = (const unsigned char *)string;
- while (*bytes) {
- if ((// ASCII
- // use bytes[0] <= 0x7F to allow ASCII control characters
- bytes[0] == 0x09 ||
- bytes[0] == 0x0A ||
- bytes[0] == 0x0D ||
- (0x20 <= bytes[0] && bytes[0] <= 0x7E)
- )
- ) {
- bytes += 1;
- continue;
- }
-
- if ((// non-overlong 2-byte
- (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
- (0x80 <= bytes[1] && bytes[1] <= 0xBF)
- )
- ) {
- bytes += 2;
- continue;
- }
-
- if ((// excluding overlongs
- bytes[0] == 0xE0 &&
- (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
- (0x80 <= bytes[2] && bytes[2] <= 0xBF)
- ) ||
- (// straight 3-byte
- ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
- bytes[0] == 0xEE ||
- bytes[0] == 0xEF) &&
- (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
- (0x80 <= bytes[2] && bytes[2] <= 0xBF)
- ) ||
- (// excluding surrogates
- bytes[0] == 0xED &&
- (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
- (0x80 <= bytes[2] && bytes[2] <= 0xBF)
- )
- ) {
- bytes += 3;
- continue;
- }
-
- if ((// planes 1-3
- bytes[0] == 0xF0 &&
- (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
- (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
- (0x80 <= bytes[3] && bytes[3] <= 0xBF)
- ) ||
- (// planes 4-15
- (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
- (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
- (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
- (0x80 <= bytes[3] && bytes[3] <= 0xBF)
- ) ||
- (// plane 16
- bytes[0] == 0xF4 &&
- (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
- (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
- (0x80 <= bytes[3] && bytes[3] <= 0xBF)
- )
- ) {
- bytes += 4;
- continue;
- }
-
- return false;
- }
-
- return true;
-} \ No newline at end of file
+ if (!string) {
+ return 0;
+ }
+
+ const unsigned char * bytes = (const unsigned char *)string;
+ while (*bytes) {
+ if ((// ASCII
+ // use bytes[0] <= 0x7F to allow ASCII control characters
+ bytes[0] == 0x09 ||
+ bytes[0] == 0x0A ||
+ bytes[0] == 0x0D ||
+ (0x20 <= bytes[0] && bytes[0] <= 0x7E)
+ )
+ ) {
+ bytes += 1;
+ continue;
+ }
+
+ if ((// non-overlong 2-byte
+ (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
+ (0x80 <= bytes[1] && bytes[1] <= 0xBF)
+ )
+ ) {
+ bytes += 2;
+ continue;
+ }
+
+ if ((// excluding overlongs
+ bytes[0] == 0xE0 &&
+ (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
+ (0x80 <= bytes[2] && bytes[2] <= 0xBF)
+ ) ||
+ (// straight 3-byte
+ ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
+ bytes[0] == 0xEE ||
+ bytes[0] == 0xEF) &&
+ (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
+ (0x80 <= bytes[2] && bytes[2] <= 0xBF)
+ ) ||
+ (// excluding surrogates
+ bytes[0] == 0xED &&
+ (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
+ (0x80 <= bytes[2] && bytes[2] <= 0xBF)
+ )
+ ) {
+ bytes += 3;
+ continue;
+ }
+
+ if ((// planes 1-3
+ bytes[0] == 0xF0 &&
+ (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
+ (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
+ (0x80 <= bytes[3] && bytes[3] <= 0xBF)
+ ) ||
+ (// planes 4-15
+ (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
+ (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
+ (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
+ (0x80 <= bytes[3] && bytes[3] <= 0xBF)
+ ) ||
+ (// plane 16
+ bytes[0] == 0xF4 &&
+ (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
+ (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
+ (0x80 <= bytes[3] && bytes[3] <= 0xBF)
+ )
+ ) {
+ bytes += 4;
+ continue;
+ }
+
+ return false;
+ }
+
+ return true;
+}
diff --git a/app/wlib/test/testapp.c b/app/wlib/test/testapp.c
index 6342801..3754a85 100644
--- a/app/wlib/test/testapp.c
+++ b/app/wlib/test/testapp.c
@@ -19,7 +19,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/