diff options
Diffstat (limited to 'app/wlib')
54 files changed, 2163 insertions, 1717 deletions
diff --git a/app/wlib/gtklib/CMakeLists.txt b/app/wlib/gtklib/CMakeLists.txt index 97ab56f..117772a 100644 --- a/app/wlib/gtklib/CMakeLists.txt +++ b/app/wlib/gtklib/CMakeLists.txt @@ -20,7 +20,6 @@ set(sources notice.c opendocument.c pixbuf.c - png.c print.c single.c splash.c @@ -32,6 +31,7 @@ set(sources util.c window.c wpref.c + writebitmap.c # end of refactored sources gtkdraw-cairo.c ) diff --git a/app/wlib/gtklib/bitmap.c b/app/wlib/gtklib/bitmap.c index eb5ef94..7562e33 100644 --- a/app/wlib/gtklib/bitmap.c +++ b/app/wlib/gtklib/bitmap.c @@ -46,7 +46,7 @@ struct wBitmap_t { */ wControl_p -wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long options, wIcon_p iconP ) +wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long options, const struct wIcon_t * iconP ) { wBitmap_p bt; GdkPixbuf *pixbuf; @@ -93,7 +93,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long options, wIcon_p iconP ) * \returns icon handle */ -wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor color ) +wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawColor color ) { wIcon_p ip; ip = (wIcon_p)malloc( sizeof *ip ); diff --git a/app/wlib/gtklib/boxes.c b/app/wlib/gtklib/boxes.c index cf419e6..74dbb7b 100644 --- a/app/wlib/gtklib/boxes.c +++ b/app/wlib/gtklib/boxes.c @@ -61,8 +61,8 @@ struct wBox_t { void wBoxSetSize( wBox_p b, - wPos_t w, - wPos_t h) + wWinPix_t w, + wWinPix_t h) { b->w = w; b->h = h; @@ -84,12 +84,12 @@ void wBoxSetSize( void wlibDrawBox( wWin_p win, wBoxType_e style, - wPos_t x, - wPos_t y, - wPos_t w, - wPos_t h) + wWinPix_t x, + wWinPix_t y, + wWinPix_t w, + wWinPix_t h) { - wPos_t x0, y0, x1, y1; + wWinPix_t x0, y0, x1, y1; GdkDrawable * window; cairo_t *cr; static char colors[8][4][2] = { @@ -185,12 +185,12 @@ static void boxRepaint(wControl_p b) wBox_p wBoxCreate( wWin_p parent, - wPos_t bx, - wPos_t by, + wWinPix_t bx, + wWinPix_t by, const char * labelStr, wBoxType_e boxTyp, - wPos_t bw, - wPos_t bh) + wWinPix_t bw, + wWinPix_t bh) { wBox_p b; b = (wBox_p)wlibAlloc(parent, B_BOX, bx, by, labelStr, sizeof *b, NULL); diff --git a/app/wlib/gtklib/browserhelp.c b/app/wlib/gtklib/browserhelp.c index aa8f5c7..7d45ea5 100644 --- a/app/wlib/gtklib/browserhelp.c +++ b/app/wlib/gtklib/browserhelp.c @@ -24,11 +24,13 @@ #include <assert.h> #include <string.h> -#include "misc.h" +//#include "misc.h" #include "gtkint.h" #include "i18n.h" +extern wBool_t CheckHelpTopicExists(const char * topic); + #include "dynstring.h" #define debug 0 diff --git a/app/wlib/gtklib/button.c b/app/wlib/gtklib/button.c index 51106c8..9a8ec77 100644 --- a/app/wlib/gtklib/button.c +++ b/app/wlib/gtklib/button.c @@ -57,6 +57,13 @@ void wButtonSetBusy(wButton_p bb, int value) 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; + } } /** @@ -148,9 +155,10 @@ void wlibButtonDoAction( } } + /** * Signal handler for button push - * \param widget IN the widget + * \param widget IN the widget or NULL for autorepeat * \param value IN the button handle (same as widget???) */ @@ -168,17 +176,124 @@ static void pushButt( return; } + wlibStringUpdate(); if (b->action) { b->action(b->data); } - if (!b->busy) { - b->recursion++; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->widget), FALSE); - b->recursion--; - } + +} + +#define REPEAT_STAGE0_DELAY 500 +#define REPEAT_STAGE1_DELAY 150 +#define REPEAT_STAGE2_DELAY 100 + +/* Timer callback function! */ +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; + +} + +static gint pressButt( + GtkWidget *widget, + GdkEventButton *event, + wButton_p bb) { + + if ( debugWindow >= 1 ) + printf( "buttonPress: %s\n", bb->labelStr ); + if (bb->recursion) { + return TRUE; + + } + + + if (bb->option & BO_REPEAT) { + /* Remove an existing timer */ + 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; + + } + + if (!bb->busy) { + bb->recursion++; + int sensitive = gtk_widget_get_sensitive (GTK_WIDGET(bb->widget)); + if (sensitive) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), TRUE); + bb->recursion--; + } + + + return TRUE; + +} + +static gint releaseButt( + GtkWidget *widget, + GdkEventButton *event, + wButton_p bb) { + + 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; + } + + bb->timer_state = -1; + + pushButt(widget,bb); //Do here to simulate "clicked" + + if (!bb->busy) { + bb->recursion++; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), FALSE); + bb->recursion--; + } + return TRUE; } + /** * Called after expose event default hander - allows the button to be outlined */ @@ -208,12 +323,12 @@ static wBool_t exposeButt( wButton_p wButtonCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - wPos_t width, + wWinPix_t width, wButtonCallBack_p action, void * data) { @@ -227,8 +342,12 @@ wButton_p wButtonCreate( wlibComputePos((wControl_p)b); b->widget = gtk_toggle_button_new(); - g_signal_connect(GTK_OBJECT(b->widget), "clicked", - G_CALLBACK(pushButt), b); + 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) { @@ -476,18 +595,18 @@ static void choiceRepaint( wChoice_p wRadioCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data) { wChoice_p b; - const char ** label; + const char * const * label; GtkWidget *butt0=NULL, *butt; if ((option & BC_NOBORDER)==0) { @@ -584,18 +703,18 @@ wChoice_p wRadioCreate( wChoice_p wToggleCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const * labels, long *valueP, wChoiceCallBack_p action, void *data) { wChoice_p b; - const char ** label; + const char * const * label; if ((option & BC_NOBORDER)==0) { if (x>=0) { diff --git a/app/wlib/gtklib/color.c b/app/wlib/gtklib/color.c index e1689d2..fee4a80 100644 --- a/app/wlib/gtklib/color.c +++ b/app/wlib/gtklib/color.c @@ -414,12 +414,12 @@ wDrawColor wColorSelectButtonGetColor( wButton_p wColorSelectButtonCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - wPos_t width, + wWinPix_t width, wDrawColor *valueP, wColorSelectButtonCallBack_p action, void * data) diff --git a/app/wlib/gtklib/control.c b/app/wlib/gtklib/control.c index 07d9210..0332470 100644 --- a/app/wlib/gtklib/control.c +++ b/app/wlib/gtklib/control.c @@ -89,7 +89,17 @@ void wControlActive( abort(); } - gtk_widget_set_sensitive(GTK_WIDGET(b->widget), active); + 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); + + } else { + + gtk_widget_set_sensitive(GTK_WIDGET(b->widget), active); + + } } /** @@ -102,7 +112,7 @@ void wControlActive( * \returns width of label including some space */ -wPos_t wLabelWidth( +wWinPix_t wLabelWidth( const char * label) { GtkWidget * widget; @@ -122,7 +132,7 @@ wPos_t wLabelWidth( * \returns width */ -wPos_t wControlGetWidth( +wWinPix_t wControlGetWidth( wControl_p b) { return b->w; @@ -135,7 +145,7 @@ wPos_t wControlGetWidth( * \returns height */ -wPos_t wControlGetHeight( +wWinPix_t wControlGetHeight( wControl_p b) { return b->h; @@ -148,7 +158,7 @@ wPos_t wControlGetHeight( * \returns position */ -wPos_t wControlGetPosX( +wWinPix_t wControlGetPosX( wControl_p b) /* Control */ { return b->realX; @@ -161,7 +171,7 @@ wPos_t wControlGetPosX( * \returns position */ -wPos_t wControlGetPosY( +wWinPix_t wControlGetPosY( wControl_p b) /* Control */ { return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0); @@ -177,8 +187,8 @@ wPos_t wControlGetPosY( void wControlSetPos( wControl_p b, - wPos_t x, - wPos_t y) + wWinPix_t x, + wWinPix_t y) { b->realX = x; b->realY = y + BORDERSIZE + ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0); @@ -306,19 +316,12 @@ void wControlHilite( { cairo_t *cr; int off = GTKCONTROLHILITEWIDTH/2+1; + if ( debugWindow >= 1 ) + printf( "wControlHIlite( %s, %d )\n", b->labelStr, hilite ); if (b->widget == NULL) { return; } - - if (! gtk_widget_get_visible(b->widget)) { - return; - } - - if (! gtk_widget_get_visible(b->parent->widget)) { - return; - } - b->outline = hilite; if (b->widget) diff --git a/app/wlib/gtklib/droplist.c b/app/wlib/gtklib/droplist.c index 69a2efd..91406fc 100644 --- a/app/wlib/gtklib/droplist.c +++ b/app/wlib/gtklib/droplist.c @@ -353,13 +353,13 @@ wlibNewDropList(GtkListStore *ls, int editable) wList_p wDropListCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - wPos_t width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data) diff --git a/app/wlib/gtklib/filesel.c b/app/wlib/gtklib/filesel.c index a1fb7cc..7e27465 100644 --- a/app/wlib/gtklib/filesel.c +++ b/app/wlib/gtklib/filesel.c @@ -324,7 +324,7 @@ int wFilSelect( struct wFilSel_t * fs, const char * dirName ) extension = startDelimiter + 2; } } - file = g_realloc( file, strlen(file)+strlen(extension)); + file = g_realloc( file, strlen(file)+strlen(extension)+1); strcat( file, extension ); free( pattern ); } diff --git a/app/wlib/gtklib/font.c b/app/wlib/gtklib/font.c index e2f741b..29df04d 100644 --- a/app/wlib/gtklib/font.c +++ b/app/wlib/gtklib/font.c @@ -182,11 +182,11 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, wFont_p fp, wFontSize_t fs, const char *s, - int *width_p, - int *height_p, - int *ascent_p, - int *descent_p, - int *baseline_p) + wDrawPix_t *width_p, + wDrawPix_t *height_p, + wDrawPix_t *ascent_p, + wDrawPix_t *descent_p, + wDrawPix_t *baseline_p) { if (!fontInitted) { fontInit(); @@ -215,9 +215,10 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE); pango_layout_set_font_description(layout, fontDescription); /* get layout measures */ - pango_layout_get_size(layout, width_p, height_p); - *width_p = *width_p / PANGO_SCALE; - *height_p = *height_p / PANGO_SCALE; + 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)); diff --git a/app/wlib/gtklib/gtkdraw-cairo.c b/app/wlib/gtklib/gtkdraw-cairo.c index 4498a2c..033e0ec 100644 --- a/app/wlib/gtklib/gtkdraw-cairo.c +++ b/app/wlib/gtklib/gtkdraw-cairo.c @@ -72,14 +72,14 @@ struct wDrawBitMap_t { //GdkGC * gc; //wDrawWidth lineWidth; //wDrawOpts opts; - //wPos_t maxW; - //wPos_t maxH; + //wWinPix_t maxW; + //wWinPix_t maxH; //unsigned long lastColor; //wBool_t lastColorInverted; //const char * helpStr; - //wPos_t lastX; - //wPos_t lastY; + //wWinPix_t lastX; + //wWinPix_t lastY; //wBool_t delayUpdate; //}; @@ -326,7 +326,7 @@ static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { } #ifdef CURSOR_SURFACE -cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wPos_t height, wDrawColor color, wDrawOpts opts) { +cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, wWinPix_t height, wDrawColor color, wDrawOpts opts) { cairo_t * cairo = NULL; @@ -374,8 +374,8 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP void wDrawLine( wDraw_p bd, - wPos_t x0, wPos_t y0, - wPos_t x1, wPos_t y1, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t x1, wDrawPix_t y1, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, @@ -420,8 +420,8 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP void wDrawArc( wDraw_p bd, - wPos_t x0, wPos_t y0, - wPos_t r, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t r, wAngle_t angle0, wAngle_t angle1, int drawCenter, @@ -473,7 +473,7 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP void wDrawPoint( wDraw_p bd, - wPos_t x0, wPos_t y0, + wDrawPix_t x0, wDrawPix_t y0, wDrawColor color, wDrawOpts opts ) { @@ -502,7 +502,7 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP void wDrawString( wDraw_p bd, - wPos_t x, wPos_t y, + wDrawPix_t x, wDrawPix_t y, wAngle_t a, const char * s, wFont_p fp, @@ -512,11 +512,11 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP { PangoLayout *layout; GdkRectangle update_rect; - int w; - int h; - gint ascent; - gint descent; - gint baseline; + wDrawPix_t w; + wDrawPix_t h; + wDrawPix_t ascent; + wDrawPix_t descent; + wDrawPix_t baseline; double angle = -M_PI * a / 180.0; if ( bd == &psPrint_d ) { @@ -534,8 +534,8 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP cairo_identity_matrix(cairo); layout = wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s, - (int *) &w, (int *) &h, - (int *) &ascent, (int *) &descent, (int *) &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 */ @@ -571,20 +571,20 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP } void wDrawGetTextSize( - wPos_t *w, - wPos_t *h, - wPos_t *d, - wPos_t *a, + wDrawPix_t *w, + wDrawPix_t *h, + wDrawPix_t *d, + wDrawPix_t *a, wDraw_p bd, const char * s, wFont_p fp, wFontSize_t fs ) { - int textWidth; - int textHeight; - int ascent; - int descent; - int baseline; + wDrawPix_t textWidth; + wDrawPix_t textHeight; + wDrawPix_t ascent; + wDrawPix_t descent; + wDrawPix_t baseline; *w = 0; *h = 0; @@ -596,17 +596,17 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wPos_t width, wP wlibFontDestroyPangoLayout( wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s, - &textWidth, (int *) &textHeight, - (int *) &ascent, (int *) &descent, (int *) &baseline) ); + &textWidth, &textHeight, + &ascent, &descent, &baseline) ); - *w = (wPos_t) textWidth; - *h = (wPos_t) textHeight; - *a = (wPos_t) ascent; - //*d = (wPos_t) textHeight-ascent; - *d = (wPos_t) descent; + *w = textWidth; + *h = textHeight; + *a = ascent; + //*d = textHeight-ascent; + *d = descent; if (debugWindow >= 3) - fprintf(stderr, "text metrics: w=%d, h=%d, d=%d\n", *w, *h, *d); + fprintf(stderr, "text metrics: w=%0.1f, h=%0.1f, d=%0.1f\n", *w, *h, *d); gtkDrawDestroyCairoContext(cairo); } @@ -642,10 +642,10 @@ static void wlibDrawFilled( void wDrawFilledRectangle( wDraw_p bd, - wPos_t x, - wPos_t y, - wPos_t w, - wPos_t h, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h, wDrawColor color, wDrawOpts opt ) { @@ -676,7 +676,7 @@ static void wlibDrawFilled( void wDrawPolygon( wDraw_p bd, - wPos_t p[][2], + wDrawPix_t p[][2], wPolyLine_e type[], int cnt, wDrawColor color, @@ -704,12 +704,13 @@ static void wlibDrawFilled( abort(); maxCnt = cnt; } - wPos_t min_x,max_x,min_y,max_y; + 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]); @@ -802,9 +803,9 @@ static void wlibDrawFilled( void wDrawFilledCircle( wDraw_p bd, - wPos_t x0, - wPos_t y0, - wPos_t r, + wDrawPix_t x0, + wDrawPix_t y0, + wDrawPix_t r, wDrawColor color, wDrawOpts opt ) { @@ -905,12 +906,12 @@ static void wlibDrawFilled( void wDrawBitMap( wDraw_p bd, wDrawBitMap_p bm, - wPos_t x, wPos_t y, + wDrawPix_t x, wDrawPix_t y, wDrawColor color, wDrawOpts opts ) { int i, j, wb; - wPos_t xx, yy; + wDrawPix_t xx, yy; wControl_p b; wWin_p win; GdkDrawable * gdk_drawable, * cairo_surface; @@ -1066,8 +1067,8 @@ static void wlibDrawFilled( void wDrawSetSize( wDraw_p bd, - wPos_t w, - wPos_t h , void * redraw) + wWinPix_t w, + wWinPix_t h , void * redraw) { wBool_t repaint; if (bd == NULL) { @@ -1102,8 +1103,8 @@ static void wlibDrawFilled( void wDrawGetSize( wDraw_p bd, - wPos_t *w, - wPos_t *h ) + wWinPix_t *w, + wWinPix_t *h ) { if (bd->widget) wlibControlGetSize( (wControl_p)bd ); @@ -1140,16 +1141,16 @@ static void wlibDrawFilled( void wDrawClip( wDraw_p d, - wPos_t x, - wPos_t y, - wPos_t w, - wPos_t h ) + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h ) { GdkRectangle rect; - rect.width = w; - rect.height = h; - rect.x = INMAPX( d, x ); - rect.y = INMAPY( d, y ) - rect.height; + rect.width = (wWinPix_t)w; + rect.height = (wWinPix_t)h; + rect.x = (wWinPix_t)INMAPX( d, x ); + rect.y = (wWinPix_t)INMAPY( d, y ) - rect.height; gdk_gc_set_clip_rectangle( d->gc, &rect ); } @@ -1162,9 +1163,9 @@ static gint draw_expose_event( { static long cDEE = 0; if ( iDrawLog ) - printf( "draw_expose_event %ld %dx%d+%dx%d %dx%d+%dx%d\n", cDEE++, + 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, - 0, bd->w, 0, bd->h ); + 0L, bd->w, 0L, bd->h ); cairo_t* cairo = gdk_cairo_create (widget->window); gdk_cairo_set_source_pixmap(cairo,bd->pixmap,0,0); @@ -1223,7 +1224,7 @@ static int ScrollTimerPop(wDraw_p bd) { } if (drawVerbose >= 2) printf( "%s-Pop\n", actionNames[lastAction] ); - bd->action( bd, bd->context, lastAction, 0, 0 ); + bd->action( bd, bd->context, lastAction, (wDrawPix_t)0, (wDrawPix_t)0 ); return FALSE; } @@ -1310,8 +1311,8 @@ static gint draw_scroll_event( if (action != 0) { if (drawVerbose >= 2) - printf( "%s[%dx%d]\n", actionNames[action], bd->lastX, bd->lastY ); - bd->action( bd, bd->context, action, bd->lastX, bd->lastY ); + 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); } return TRUE; @@ -1332,12 +1333,16 @@ static gint draw_leave_event( * Handler for mouse button clicks. */ + + static gint draw_button_event( GtkWidget *widget, GdkEventButton *event, wDraw_p bd ) { + wAction_t action = 0; + if (bd->action == NULL) return TRUE; @@ -1346,20 +1351,22 @@ static gint draw_button_event( 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; - /*bd->action( bd, bd->context, event->type==GDK_BUTTON_PRESS?wActionLDown:wActionLUp, bd->lastX, bd->lastY );*/ + /*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 */ action = event->type==GDK_BUTTON_PRESS?wActionRDown:wActionRUp; - /*bd->action( bd, bd->context, event->type==GDK_BUTTON_PRESS?wActionRDown:wActionRUp, bd->lastX, bd->lastY );*/ + /*bd->action( bd, bd->context, event->type==GDK_BUTTON_PRESS?wActionRDown:wActionRUp, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );*/ break; } if (action != 0) { if (drawVerbose >= 2) - printf( "%s[%dx%d]\n", actionNames[action], bd->lastX, bd->lastY ); - bd->action( bd, bd->context, action, bd->lastX, bd->lastY ); + 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 ); } + if (!(bd->option & BD_NOFOCUS)) gtk_widget_grab_focus( bd->widget ); return TRUE; @@ -1387,16 +1394,18 @@ static gint draw_motion_event( if (state & GDK_BUTTON1_MASK) { action = wActionLDrag; + } else if (state & GDK_BUTTON2_MASK) { + action = wActionLDrag; } 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[%dx%d] %s\n", (long)bd, actionNames[action], bd->lastX, bd->lastY, event->is_hint?"<Hint>":"<>" ); - bd->action( bd, bd->context, action, bd->lastX, bd->lastY ); + 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; @@ -1421,7 +1430,7 @@ static gint draw_char_release_event( } if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) { - bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), bd->lastX, bd->lastY ); + 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; @@ -1485,23 +1494,23 @@ static gint draw_char_event( if (extKey != wAccelKey_None) { if ( wlibFindAccelKey( event ) == NULL ) { - bd->action( bd, bd->context, wActionExtKey + ((int)extKey<<8), bd->lastX, 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 ); return TRUE; } else if ((key >=wAccelKey_Up) && (key<=wAccelKey_Left) && bd->action) { - bd->action( bd, bd->context, wActionText+(key<<8), bd->lastX, bd->lastY ); + 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), bd->lastX, bd->lastY ); + 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), bd->lastX, bd->lastY ); + 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; @@ -1525,12 +1534,12 @@ int xw, xh, cw, ch; wDraw_p wDrawCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, long option, - wPos_t width, - wPos_t height, + wWinPix_t width, + wWinPix_t height, void * context, wDrawRedrawCallBack_p redraw, wDrawActionCallBack_p action ) @@ -1579,7 +1588,12 @@ int xw, xh, cw, ch; | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK ); bd->lastColor = -1; - bd->dpi = 75; + + double dpi; + + wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); + + bd->dpi = dpi; bd->maxW = bd->w = width; bd->maxH = bd->h = height; @@ -1614,14 +1628,19 @@ int xw, xh, cw, ch; * *******************************************************************************/ -wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int arg ) +wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int arg ) { wDraw_p bd; bd = (wDraw_p)wlibAlloc( gtkMainW, B_DRAW, 0, 0, NULL, sizeof *bd, NULL ); bd->lastColor = -1; - bd->dpi = 75; + + double dpi; + + wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); + + bd->dpi = dpi; bd->maxW = bd->w = w; bd->maxH = bd->h = h; @@ -1677,7 +1696,35 @@ int wDrawSetBackground( wDraw_p bd, char * path, char ** error) { } -void wDrawShowBackground( wDraw_p bd, wPos_t pos_x, wPos_t pos_y, wPos_t size, wAngle_t angle, int screen) { +/** + * Use a loaded background in another context. + * + * \param from context with 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; + } +} + +/** +* Draw background to screen. The background will be sized and rotated before being shown. The bitmap +* is scaled so that the width is equal to size. The height is changed proportionally. +* +* \param bd drawing context +* \param pos_x, pos_y bitmap position +* \param size desired width after scaling +* \param angle +* \param screen visibility of bitmap in percent +*/ + +void wDrawShowBackground( wDraw_p bd, 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 ); diff --git a/app/wlib/gtklib/gtkint.h b/app/wlib/gtklib/gtkint.h index 410fd7f..6d8a641 100644 --- a/app/wlib/gtklib/gtkint.h +++ b/app/wlib/gtklib/gtkint.h @@ -45,8 +45,8 @@ extern wWin_p gtkMainW; #ifdef CURSOR_SURFACE typedef struct { cairo_surface_t* surface; - wPos_t width; - wPos_t height; + wWinPix_t width; + wWinPix_t height; wBool_t show; } wCursorSurface_t, * wSurface_p; #endif @@ -69,11 +69,11 @@ typedef void (*setTriggerCallback_p)( wControl_p b ); wControl_p next; \ wControl_p synonym; \ wWin_p parent; \ - wPos_t origX, origY; \ - wPos_t realX, realY; \ - wPos_t default_size_x, default_size_y; \ - wPos_t labelW; \ - wPos_t w, h; \ + 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; \ long option; \ const char * labelStr; \ @@ -88,7 +88,7 @@ typedef void (*setTriggerCallback_p)( wControl_p b ); struct wWin_t { WOBJ_COMMON GtkWidget *gtkwin; /**< GTK window */ - wPos_t lastX, lastY; + wWinPix_t lastX, lastY; wControl_p first, last; wWinCallBack_p winProc; /**< window procedure */ wBool_t shown; /**< visibility state */ @@ -117,12 +117,12 @@ struct wList_t { int count; int number; int colCnt; - wPos_t *colWidths; + wWinPix_t *colWidths; wBool_t *colRightJust; GtkListStore *listStore; GtkWidget *treeView; int last; - wPos_t listX; + wWinPix_t listX; long * valueP; wListCallBack_p action; int recursion; @@ -144,8 +144,8 @@ struct wListItem_t { #define gtkIcon_pixmap (2) struct wIcon_t { int gtkIconType; - wPos_t w; - wPos_t h; + wWinPix_t w; + wWinPix_t h; wDrawColor color; const void * bits; }; @@ -157,7 +157,7 @@ extern wDrawColor wDrawColorBlack; /* boxes.c */ -void wlibDrawBox(wWin_p win, wBoxType_e style, wPos_t x, wPos_t y, wPos_t w, wPos_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); @@ -170,6 +170,9 @@ struct wButton_t { wButtonCallBack_p action; int busy; int recursion; + long timer_id; + int timer_count; + int timer_state; }; /* color.c */ @@ -202,12 +205,12 @@ 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, wPos_t x, wPos_t y, const char *helpStr, const char *labelStr, long option, long number, wPos_t width, long *valueP, wListCallBack_p action, void *data); +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, int *width_p, int *height_p, int *ascent_p, int *descent_p, int *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); @@ -245,11 +248,11 @@ typedef struct accelData_t { GdkPixbuf* wlibPixbufFromXBM(wIcon_p ip); int wlibAddLabel(wControl_p b, const char *labelStr); -void *wlibAlloc(wWin_p parent, wType_e type, wPos_t origX, wPos_t origY, const char *labelStr, int size, void *data); +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); -wControl_p wlibGetControlFromPos(wWin_p win, wPos_t x, wPos_t y); +wControl_p wlibGetControlFromPos(wWin_p win, wWinPix_t x, wWinPix_t y); char *wlibConvertInput(const char *inString); char *wlibConvertOutput(const char *inString); struct accelData_t *wlibFindAccelKey(GdkEventKey *event); @@ -278,14 +281,14 @@ struct wDraw_t { GdkGC * gc; wDrawWidth lineWidth; wDrawOpts opts; - wPos_t maxW; - wPos_t maxH; + wWinPix_t maxW; + wWinPix_t maxH; unsigned long lastColor; wBool_t lastColorInverted; const char * helpStr; - wPos_t lastX; - wPos_t lastY; + wWinPix_t lastX; + wWinPix_t lastY; wBool_t delayUpdate; cairo_t *printContext; @@ -297,15 +300,16 @@ struct wDraw_t { void WlibApplySettings(GtkPrintOperation *op); void WlibSaveSettings(GtkPrintOperation *op); -void psPrintLine(wPos_t x0, wPos_t y0, wPos_t x1, wPos_t y1, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts); -void psPrintArc(wPos_t x0, wPos_t y0, wPos_t r, double angle0, double angle1, wBool_t drawCenter, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts); -void psPrintFillRectangle(wPos_t x0, wPos_t y0, wPos_t x1, wPos_t y1, wDrawColor color, wDrawOpts opts); -void psPrintFillPolygon(wPos_t p[][2], wPolyLine_e type[], int cnt, wDrawColor color, wDrawOpts opts, int fill, int open); -void psPrintFillCircle(wPos_t x0, wPos_t y0, wPos_t r, wDrawColor color, wDrawOpts opts); -void psPrintString(wPos_t x, wPos_t y, double a, char *s, wFont_p fp, double fs, wDrawColor color, wDrawOpts opts); +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(); /* splash.c */ diff --git a/app/wlib/gtklib/help.c b/app/wlib/gtklib/help.c index 8f2766d..45d1813 100644 --- a/app/wlib/gtklib/help.c +++ b/app/wlib/gtklib/help.c @@ -28,7 +28,8 @@ #include <gtk/gtk.h> #include <gdk/gdk.h> -#include "misc.h" +//#include "misc.h" +extern const char * GetCurCommandName(); #include "gtkint.h" #include "i18n.h" @@ -51,7 +52,7 @@ DoHelpMenu(void *data) switch (func) { case 1: - wHelp("index"); + wHelp("contents"); break; case 3: diff --git a/app/wlib/gtklib/list.c b/app/wlib/gtklib/list.c index ac66aba..2080b9f 100644 --- a/app/wlib/gtklib/list.c +++ b/app/wlib/gtklib/list.c @@ -238,16 +238,20 @@ wIndex_t wListGetValues( 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; + item_data = NULL; inx = bl->last = -1; } else { - inx = bl->last; + //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; @@ -410,6 +414,9 @@ void wListDelete( b->count--; } + if (b->last == inx-1) b->last = -1; + else if (b->last >= inx) b->last = -1; + b->recursion--; return; } @@ -426,7 +433,7 @@ void wListDelete( int wListGetColumnWidths( wList_p bl, int colCnt, - wPos_t * colWidths) + wWinPix_t * colWidths) { int inx; @@ -510,7 +517,7 @@ wIndex_t wListAddValue( * \param h IN height (ignored for droplist) */ -void wListSetSize(wList_p bl, wPos_t w, wPos_t h) +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); @@ -534,13 +541,13 @@ void wListSetSize(wList_p bl, wPos_t w, wPos_t h) wList_p wComboListCreate( wWin_p parent, /* Parent window */ - wPos_t x, /* X-position */ - wPos_t y, /* Y-position */ + 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 */ - wPos_t width, /* Width */ + wWinPix_t width, /* Width */ long *valueP, /* Selected index */ wListCallBack_p action, /* Callback */ void *data) /* Context */ diff --git a/app/wlib/gtklib/menu.c b/app/wlib/gtklib/menu.c index 79695d4..754f88f 100644 --- a/app/wlib/gtklib/menu.c +++ b/app/wlib/gtklib/menu.c @@ -118,7 +118,7 @@ typedef struct wMenuListItem_t * wMenuListItem_p; struct wMenuToggle_t { WOBJ_COMMON MOBJ_COMMON m; - wMenuToggleCallBack_p action; + wMenuCallBack_p action; wBool_t enabled; wBool_t set; }; @@ -151,7 +151,7 @@ static void pushMenuItem( case M_TOGGLE: mt = (wMenuToggle_p)m; wMenuToggleSet( mt, !mt->set ); - mt->action( mt->set, mt->data ); + mt->action( mt->data ); break; case M_RADIO: /* NOTE: action is only called when radio button is activated, not when deactivated */ @@ -790,7 +790,7 @@ wMenuToggle_p wMenuToggleCreate( const char * labelStr, long acclKey, wBool_t set, - wMenuToggleCallBack_p action, + wMenuCallBack_p action, void * data ) { wMenuToggle_p mt; @@ -904,8 +904,8 @@ static gint pushMenu( wMenu_p wMenuCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option ) @@ -1067,7 +1067,7 @@ wBool_t wMenuAction( wBeep(); } else { wMenuToggleSet( mt, !mt->set ); - mt->action( mt->set, mt->data ); + mt->action( mt->data ); } break; case M_MENU: diff --git a/app/wlib/gtklib/message.c b/app/wlib/gtklib/message.c index af37d22..4ecfe6f 100644 --- a/app/wlib/gtklib/message.c +++ b/app/wlib/gtklib/message.c @@ -45,7 +45,7 @@ struct wMessage_t { WOBJ_COMMON GtkWidget * labelWidget; const char * message; - wPos_t labelWidth; + wWinPix_t labelWidth; }; /** @@ -77,7 +77,7 @@ void wMessageSetValue( void wMessageSetWidth( wMessage_p b, - wPos_t width) + wWinPix_t width) { b->labelWidth = width; gtk_widget_set_size_request(b->widget, width, -1); @@ -90,7 +90,7 @@ void wMessageSetWidth( * \return text height */ -wPos_t wMessageGetHeight( +wWinPix_t wMessageGetHeight( long flags) { GtkWidget * temp; @@ -149,10 +149,10 @@ wPos_t wMessageGetHeight( wMessage_p wMessageCreateEx( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * labelStr, - wPos_t width, + wWinPix_t width, const char *message, long flags) { @@ -212,7 +212,7 @@ wMessage_p wMessageCreateEx( * \return expected width of message box */ -wPos_t +wWinPix_t wMessageGetWidth(const char *testString) { GtkWidget *entry; diff --git a/app/wlib/gtklib/osxhelp.c b/app/wlib/gtklib/osxhelp.c index 4ec1f5e..2fed375 100644 --- a/app/wlib/gtklib/osxhelp.c +++ b/app/wlib/gtklib/osxhelp.c @@ -28,7 +28,6 @@ #include <errno.h> #include <fcntl.h> -#include "misc.h" #include "gtkint.h" #include "i18n.h" @@ -40,6 +39,7 @@ static pid_t pidOfChild; static int handleOfPipe; extern char *wExecutableName; +extern wBool_t CheckHelpTopicExists(const char *); /** * Create the fully qualified filename for the help helper diff --git a/app/wlib/gtklib/pixbuf.c b/app/wlib/gtklib/pixbuf.c index 7b8d7d1..a76e7f1 100644 --- a/app/wlib/gtklib/pixbuf.c +++ b/app/wlib/gtklib/pixbuf.c @@ -65,7 +65,7 @@ GdkPixbuf* wlibMakePixbuf( pixmapData = (char**)g_malloc((3+ip->h) * sizeof *pixmapData); pixmapData[0] = line0; rgb = wDrawGetRGB(ip->color); - sprintf(line0, " %d %d 2 1", ip->w, ip->h); + 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"; diff --git a/app/wlib/gtklib/print.c b/app/wlib/gtklib/print.c index 860a7c7..7f8f49e 100644 --- a/app/wlib/gtklib/print.c +++ b/app/wlib/gtklib/print.c @@ -423,8 +423,8 @@ static void psSetColor( */ void psPrintLine( - wPos_t x0, wPos_t y0, - wPos_t x1, wPos_t y1, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t x1, wDrawPix_t y1, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, @@ -462,8 +462,8 @@ void psPrintLine( */ void psPrintArc( - wPos_t x0, wPos_t y0, - wPos_t r, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t r, double angle0, double angle1, wBool_t drawCenter, @@ -534,8 +534,8 @@ void psPrintArc( */ void psPrintFillRectangle( - wPos_t x0, wPos_t y0, - wPos_t x1, wPos_t y1, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t x1, wDrawPix_t y1, wDrawColor color, wDrawOpts opts) { @@ -570,7 +570,7 @@ void psPrintFillRectangle( */ void psPrintFillPolygon( - wPos_t p[][2], + wDrawPix_t p[][2], wPolyLine_e type[], int cnt, wDrawColor color, @@ -591,7 +591,7 @@ void psPrintFillPolygon( psSetColor(color); - wPos_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; @@ -623,7 +623,7 @@ void psPrintFillPolygon( mid3[1] = (p[inx][1]-mid0[1])/2+mid0[1]; mid4[0] = (mid1[0]-p[inx][0])/2+p[inx][0]; mid4[1] = (mid1[1]-p[inx][1])/2+p[inx][1]; - wPos_t save[2]; + wDrawPix_t save[2]; if (inx==0) { if (!type || (type && type[0] == wPolyLineStraight) || open) { cairo_move_to(cr, p[ 0 ][ 0 ], p[ 0 ][ 1 ]); @@ -665,8 +665,8 @@ void psPrintFillPolygon( */ void psPrintFillCircle( - wPos_t x0, wPos_t y0, - wPos_t r, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t r, wDrawColor color, wDrawOpts opts) { @@ -710,7 +710,7 @@ void psPrintFillCircle( */ void psPrintString( - wPos_t x, wPos_t y, + wDrawPix_t x, wDrawPix_t y, double a, char * s, wFont_p fp, @@ -758,7 +758,10 @@ void psPrintString( // render the string to a Pango layout pango_layout_set_font_description(layout, desc); - pango_layout_set_text(layout, s, -1); + + 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); @@ -790,9 +793,11 @@ void psPrintString( // 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 ); pango_cairo_layout_line_path (cr, line); cairo_stroke( cr ); } @@ -811,7 +816,7 @@ void psPrintString( * \return */ -void wPrintClip(wPos_t x, wPos_t y, wPos_t w, wPos_t h) +void wPrintClip(wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h) { cairo_move_to(psPrint_d.printContext, x, y); cairo_rel_line_to(psPrint_d.printContext, w, 0); @@ -1019,28 +1024,50 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) /* * Override up-scaling for some printer drivers/Linux systems that don't support the latest CUPS - * - the user sets the environment variable XTRKCADPRINTSCALE to a value + * - 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 variable XTRKCADPRINTTEXTSCALE + * 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; + + double printScale,printTextScale; + + wPrefGetFloat(PREFSECTION, PRINTSCALE, &printScale, -1.0); + wPrefGetFloat(PREFSECTION, PRINTTEXTSCALE, &printTextScale, -1.0); + + + //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)); + } + } const char * sPrinterName = gtk_printer_get_name( selPrinter ); - if ((strcmp(sPrinterName,"Print to File") == 0) || getenv(sEnvScale) == NULL) { + 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; scale_adjust = 72/p_def; } else { - char * sEnvTextScale = PRODUCT "PRINTTEXTSCALE"; - if (getenv(sEnvTextScale) && (atof(getenv(sEnvTextScale)) != 0.0)) { - scale_text = atof(getenv(sEnvTextScale)); - } else scale_text = 1.0; - if (getenv(sEnvScale) && (atof(getenv(sEnvScale)) != 0.0)) { - scale_adjust = atof(getenv(sEnvScale)); - } else scale_adjust = 1.0; + if (printTextScale > 0.0) { + scale_text = printTextScale; + } + if (printScale > 0.0) { + scale_adjust = printScale; + } psPrint_d.dpi = 72; } diff --git a/app/wlib/gtklib/single.c b/app/wlib/gtklib/single.c index 600f1dd..3856a64 100644 --- a/app/wlib/gtklib/single.c +++ b/app/wlib/gtklib/single.c @@ -35,7 +35,6 @@ #include "gtkint.h" -#define TIMEOUT_INACTIVITY (500) /**< timeout for entry fields in millisecs */ /* ***************************************************************************** @@ -54,7 +53,6 @@ struct wString_t { wBool_t enter_pressed; /**< flag if enter was pressed */ wBool_t hasSignal; /** needs signal to be suppressed */ int count; /** number of 100ms since last entry **/ - guint timer; /**< timer source for inactivity timer */ }; /** @@ -93,7 +91,7 @@ void wStringSetValue( void wStringSetWidth( wString_p b, - wPos_t w) + wWinPix_t w) { gtk_widget_set_size_request(b->widget, w, -1); b->w = w; @@ -115,70 +113,21 @@ const char *wStringGetValue( return gtk_entry_get_text(GTK_ENTRY(b->widget)); } -/** - * Kill an active timer - * - * \param b IN entry field - * \return the entered text - */ - -static gboolean killTimer( - GtkEntry *widget, - GdkEvent *event, - wString_p b) -{ - - // remove all timers related to this widget - while( g_source_remove_by_user_data( b )) - ; - b->timer = 0; - - if (b->action) { - const char *s; - - s = gtk_entry_get_text(GTK_ENTRY(b->widget)); - b->action(s, b->data); - } - gtk_editable_select_region( GTK_EDITABLE( widget ), 0, 0 ); - return( FALSE ); -} /** - * Timer handler for string activity. This timer checks the input if the user - * doesn't change an entry value for the preset time (0.5s). + * Do the current active string's action when a button was pushed + * Used to validate input */ - -static gboolean -timeoutString( wString_p bs ) +static wString_p stringControl = NULL; +void wlibStringUpdate() { - const char *new_value; - if ( !bs ) - return( FALSE ); - if (bs->widget == 0) - abort(); - - bs->count--; - - if (bs->count==0) { - // get the currently entered value - new_value = wStringGetValue(bs); - if (bs->valueP != NULL) - strcpy(bs->valueP, new_value); - - if (bs->action) { - bs->enter_pressed = FALSE; //Normal input - if ( new_value ) - bs->action(new_value,bs->data); - } - } - if (bs->count<=0) { - bs->timer = 0; - return( FALSE ); //Stop timer - } else { - return TRUE; //Wait 100ms + if ( stringControl && stringControl->action ) { + stringControl->action( wStringGetValue(stringControl), stringControl->data ); + stringControl = NULL; } } + /** * Signal handler for 'activate' signal: enter pressed - callback with the current value and then * select the whole default value @@ -192,6 +141,8 @@ static gboolean stringActivated( GtkEntry *widget, wString_p b) { + if ( debugWindow >= 1 ) + printf( "stringActivated: %s\n", b->labelStr ); const char *s; const char * output = "\n"; @@ -228,37 +179,100 @@ static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event, gpointe * \return */ -static void stringChanged( +static int stringChanged( GtkEntry *widget, wString_p b) { - const char *new_value; - - if ( !b ) - return; - - b->count = 5; /* set ~500 ms from now */ - - // get the entered value - //new_value = wStringGetValue(b); - //if (b->valueP != NULL) - // strcpy(b->valueP, new_value); - // - // - if (b->action){ - // if one exists, remove the inactivity timer - if( !b->timer ) { - //g_source_remove( b->timer ); - - // create a new timer - b->timer = g_timeout_add( TIMEOUT_INACTIVITY/5, - (GSourceFunc)timeoutString, - b ); - } - } - return; + if ( debugWindow >= 1 ) + printf( "stringChanged: %s\n", b->labelStr); + stringControl = b; + return FALSE; } +static int stringPreeditChanged( + GtkEntry *widget, + wString_p b) +{ + if ( debugWindow >= 1 ) + printf( "stringPreeditChanged: %s\n", b->labelStr ); + return FALSE; +} +static int stringFocusOutEvent( + GtkEntry *widget, + GdkEvent * event, + wString_p b) +{ + if ( debugWindow >= 1 ) + printf( "stringFocusOut: %s\n", b->labelStr ); + if (b->action) { + const char *s; + s = gtk_entry_get_text(GTK_ENTRY(b->widget)); + b->action(s, b->data); + } + gtk_editable_select_region( GTK_EDITABLE( widget ), 0, 0 ); + return FALSE; +} +static int stringFocusInEvent( + GtkEntry *widget, + GdkEvent * event, + wString_p b) +{ + if ( debugWindow >= 1 ) + printf( "stringFocusIn: %s\n", b->labelStr ); + stringControl = b; + return FALSE; +} +static int stringLeaveNotifyEvent( + GtkEntry *widget, + GdkEvent * event, + wString_p b) +{ + if ( debugWindow >= 3 ) + printf( "stringLeaveNotfyEvent: %s\n", b->labelStr ); + return FALSE; +} +static int stringEventAfter( + GtkEntry *widget, + wString_p b) +{ + if ( debugWindow >= 3 ) + printf( "stringEventAfter: %s\n", b->labelStr ); + return FALSE; +} +static int stringEvent( + GtkEntry *widget, + wString_p b) +{ + if ( debugWindow >= 3 ) + printf( "stringEvent: %s\n", b->labelStr ); + return FALSE; +} +static int stringKeyPressEvent( + GtkEntry *widget, + GdkEvent * event, + wString_p b) +{ + if ( debugWindow >= 1 ) + printf( "stringKeyPressEvent: %s\n", b->labelStr ); + return FALSE; +} +static int stringStateChanged( + GtkEntry *widget, + int state, + wString_p b) +{ + if ( debugWindow >= 1 ) + printf( "stringStateChanged: %s\n", b->labelStr ); + return FALSE; +} +static int stringActivate( + GtkEntry *widget, + wString_p b) +{ + if ( debugWindow >= 1 ) + printf( "stringActivate: %s\n", b->labelStr ); + return stringChanged( widget, b ); +} /** * Create a single line entry field for a string value * @@ -278,12 +292,12 @@ static void stringChanged( wString_p wStringCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char *helpStr, const char *labelStr, long option, - wPos_t width, + wWinPix_t width, char *valueP, wIndex_t valueL, wStringCallBack_p action, @@ -297,7 +311,6 @@ wString_p wStringCreate( b->action = action; b->option = option; b->valueL = valueL; - b->timer = 0; b->hasSignal = 0; wlibComputePos((wControl_p)b); @@ -341,7 +354,17 @@ wString_p wStringCreate( // 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), "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); + //if (option&BO_ENTER) g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivated), b); b->hasSignal = 1; @@ -355,7 +378,6 @@ wString_p wStringCreate( } gtk_widget_add_events( b->widget, GDK_FOCUS_CHANGE_MASK ); - g_signal_connect(GTK_OBJECT(b->widget), "focus-out-event", G_CALLBACK(killTimer), b); return b; } diff --git a/app/wlib/gtklib/splash.c b/app/wlib/gtklib/splash.c index 5d56e9f..7b7613c 100644 --- a/app/wlib/gtklib/splash.c +++ b/app/wlib/gtklib/splash.c @@ -123,7 +123,6 @@ wSetSplashInfo(char *msg) if (!window) return FALSE; if (msg && message) { gtk_label_set_text(GTK_LABEL(message), msg); - wFlush(); return TRUE; } diff --git a/app/wlib/gtklib/statusbar.c b/app/wlib/gtklib/statusbar.c index 3a2fd0d..a71d021 100644 --- a/app/wlib/gtklib/statusbar.c +++ b/app/wlib/gtklib/statusbar.c @@ -42,7 +42,7 @@ struct wStatus_t { WOBJ_COMMON GtkWidget * labelWidget; const char * message; - wPos_t labelWidth; + wWinPix_t labelWidth; }; /** @@ -84,10 +84,10 @@ void wStatusSetValue( wStatus_p wStatusCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * labelStr, - wPos_t width, + wWinPix_t width, const char *message) { wStatus_p b; @@ -124,7 +124,7 @@ wStatus_p wStatusCreate( * \return expected width of message box */ -wPos_t +wWinPix_t wStatusGetWidth(const char *testString) { GtkWidget *entry; @@ -152,7 +152,7 @@ wStatusGetWidth(const char *testString) * \return text height */ -wPos_t wStatusGetHeight( +wWinPix_t wStatusGetHeight( long flags) { GtkWidget * temp; @@ -208,7 +208,7 @@ wPos_t wStatusGetHeight( void wStatusSetWidth( wStatus_p b, - wPos_t width) + wWinPix_t width) { b->labelWidth = width; gtk_widget_set_size_request(b->widget, width, -1); diff --git a/app/wlib/gtklib/text.c b/app/wlib/gtklib/text.c index 0812ace..cb811b6 100644 --- a/app/wlib/gtklib/text.c +++ b/app/wlib/gtklib/text.c @@ -59,7 +59,7 @@ struct PrintData { struct wText_t { WOBJ_COMMON - wPos_t width, height; + wWinPix_t width, height; int changed; GtkWidget *text; }; @@ -462,7 +462,7 @@ wBool_t wTextGetModified(wText_p bt) * \return */ -void wTextSetSize(wText_p bt, wPos_t w, wPos_t h) +void wTextSetSize(wText_p bt, wWinPix_t w, wWinPix_t h) { gtk_widget_set_size_request(bt->widget, w, h); bt->w = w; @@ -481,8 +481,8 @@ void wTextSetSize(wText_p bt, wPos_t w, wPos_t h) * \return */ -void wTextComputeSize(wText_p bt, int rows, int cols, wPos_t *width, - wPos_t *height) +void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols, wWinPix_t *width, + wWinPix_t *height) { *width = rows * 7; *height = cols * 14; @@ -498,7 +498,7 @@ void wTextComputeSize(wText_p bt, int rows, int cols, wPos_t *width, void wTextSetPosition(wText_p bt, int pos) { - /* TODO */ + /* TODO TextSetPosition */ } /** @@ -536,13 +536,13 @@ static void textChanged(GtkWidget *widget, wText_p bt) wText_p wTextCreate(wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char *helpStr, const char *labelStr, long option, - wPos_t width, - wPos_t height) + wWinPix_t width, + wWinPix_t height) { wText_p bt; GtkTextBuffer *tb; diff --git a/app/wlib/gtklib/tooltip.c b/app/wlib/gtklib/tooltip.c index 20a1ba9..cd12d0a 100644 --- a/app/wlib/gtklib/tooltip.c +++ b/app/wlib/gtklib/tooltip.c @@ -47,7 +47,7 @@ static GtkWidget * balloonPI; static char balloonMsg[100] = "";
static wControl_p balloonB;
-static wPos_t balloonDx, balloonDy;
+static wWinPix_t balloonDx, balloonDy;
static wBool_t balloonVisible = FALSE;
@@ -128,13 +128,13 @@ void wControlSetBalloonText( * \return
*/
-void wControlSetBalloon( wControl_p b, wPos_t dx, wPos_t dy, const char * msg )
+void wControlSetBalloon( wControl_p b, wWinPix_t dx, wWinPix_t dy, const char * msg )
{
PangoLayout * layout;
- wPos_t x, y;
- wPos_t w, h;
- wPos_t xx, yy;
+ gint x, y;
+ gint w, h;
+ wWinPix_t xx, yy;
const char * msgConverted;
GtkRequisition size;
@@ -157,12 +157,18 @@ void wControlSetBalloon( wControl_p b, wPos_t dx, wPos_t dy, const char * 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);
GtkWidget * alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
gtk_alignment_set_padding( GTK_ALIGNMENT(alignment), 6, 6, 6, 6 );
@@ -189,6 +195,9 @@ void wControlSetBalloon( wControl_p b, wPos_t dx, wPos_t dy, const char * msg ) x += b->realX + dx;
y += b->realY + b->h - dy;
+#ifdef __linux__
+ y += 7; // balloon popup overlaps the control
+#endif
xx = gdk_screen_width();
yy = gdk_screen_height();
if ( x < 0 ) {
diff --git a/app/wlib/gtklib/treeview.c b/app/wlib/gtklib/treeview.c index 2b743cb..e8e0625 100644 --- a/app/wlib/gtklib/treeview.c +++ b/app/wlib/gtklib/treeview.c @@ -445,15 +445,15 @@ changeSelection(GtkTreeSelection *selection, wList_p wListCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - wPos_t width, + wWinPix_t width, int colCnt, - wPos_t * colWidths, + wWinPix_t * colWidths, wBool_t * colRightJust, const char ** colTitles, long *valueP, @@ -462,7 +462,7 @@ wList_p wListCreate( { GtkTreeSelection *sel; wList_p bl; - static wPos_t zeroPos = 0; + static wWinPix_t zeroPos = 0; assert(width != 0); @@ -481,8 +481,8 @@ wList_p wListCreate( } bl->colCnt = colCnt; - bl->colWidths = (wPos_t*)malloc(colCnt * sizeof *(wPos_t*)0); - memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wPos_t*)0); + 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); diff --git a/app/wlib/gtklib/util.c b/app/wlib/gtklib/util.c index a265938..14ca689 100644 --- a/app/wlib/gtklib/util.c +++ b/app/wlib/gtklib/util.c @@ -37,7 +37,7 @@ #include "gtkint.h" #include "i18n.h" -wWin_p gtkMainW; +extern wWin_p gtkMainW; long debugWindow = 0; @@ -108,7 +108,7 @@ GdkPixbuf* wlibPixbufFromXBM( pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData); pixmapData[0] = line0; rgb = wDrawGetRGB(ip->color); - sprintf(line0, " %d %d 2 1", ip->w, ip->h); + sprintf(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"; @@ -183,8 +183,8 @@ int wlibAddLabel(wControl_p b, const char * labelStr) void * wlibAlloc( wWin_p parent, wType_e type, - wPos_t origX, - wPos_t origY, + wWinPix_t origX, + wWinPix_t origY, const char * labelStr, int size, void * data) @@ -324,11 +324,11 @@ void wlibAddButton( wControl_p wlibGetControlFromPos( wWin_p win, - wPos_t x, - wPos_t y) + wWinPix_t x, + wWinPix_t y) { wControl_p b; - wPos_t xx, yy; + wWinPix_t xx, yy; for (b = win->first; b != NULL; b = b->next) { if (b->widget && gtk_widget_get_visible(b->widget)) { @@ -386,6 +386,8 @@ void wWinTop(wWin_p win) { } +extern long dontHideCursor; + /** * Set the cursor in GTK * @@ -399,6 +401,7 @@ void wSetCursor(wDraw_p bd, wCursor_t cursor) //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 if (!gdkcursors[cursor]) { switch(cursor) { case wCursorAppStart: @@ -450,7 +453,8 @@ void wSetCursor(wDraw_p bd, wCursor_t cursor) gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW); break; case wCursorNone: - gdkcursor = gdk_cursor_new(GDK_BLANK_CURSOR); + gdkcursor = gdk_cursor_new(GDK_BLANK_CURSOR); + break; case wCursorNormal: default: //gdkcursor = gdk_cursor_new_from_name (display,"default"); @@ -481,7 +485,7 @@ const char * wMemStats(void) * \param h IN pointer to height */ -void wGetDisplaySize(wPos_t * w, wPos_t * h) +void wGetDisplaySize(wWinPix_t * w, wWinPix_t * h) { GdkScreen *screen = gdk_screen_get_default(); guint monitor = gdk_screen_get_primary_monitor(screen); diff --git a/app/wlib/gtklib/window.c b/app/wlib/gtklib/window.c index 1468c89..16a21a5 100644 --- a/app/wlib/gtklib/window.c +++ b/app/wlib/gtklib/window.c @@ -124,8 +124,8 @@ static void getWinSize(wWin_p win, const char * nameStr) GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); - wPos_t maxDisplayWidth = monitor_dimensions.width-10; - wPos_t maxDisplayHeight = monitor_dimensions.height-50; + wWinPix_t maxDisplayWidth = monitor_dimensions.width-10; + wWinPix_t maxDisplayHeight = monitor_dimensions.height-50; @@ -170,8 +170,8 @@ static void saveSize(wWin_p win) gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) { char pos_s[20]; - sprintf(pos_s, "%d %d", win->w, - win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0))); + sprintf(pos_s, "%ld %ld", win->w, + (win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0)))); wPrefSetString(SECTIONWINDOWSIZE, win->nameStr, pos_s); } } @@ -260,11 +260,11 @@ static void savePos(wWin_p win) void wWinGetSize( wWin_p win, /* Window */ - wPos_t * width, /* Returned window width */ - wPos_t * height) /* Returned window height */ + wWinPix_t * width, /* Returned window width */ + wWinPix_t * height) /* Returned window height */ { GtkRequisition requisition; - wPos_t w, h; + wWinPix_t w, h; gtk_widget_size_request(win->gtkwin, &requisition); w = win->w; h = win->h; @@ -293,8 +293,8 @@ void wWinGetSize( void wWinSetSize( wWin_p win, /* Window */ - wPos_t width, /* Window width */ - wPos_t height) /* Window height */ + wWinPix_t width, /* Window width */ + wWinPix_t height) /* Window height */ { win->busy = TRUE; win->w = width; @@ -561,10 +561,10 @@ const char * wWinGetTitle( void wWinClear( wWin_p win, - wPos_t x, - wPos_t y, - wPos_t width, - wPos_t height) + wWinPix_t x, + wWinPix_t y, + wWinPix_t width, + wWinPix_t height) { } @@ -858,7 +858,7 @@ static gint window_char_event( } } -void wSetGeometry(wWin_p win, int min_width, int max_width, int min_height, int max_height, int base_width, int base_height, double aspect_ratio ) { +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; @@ -913,8 +913,8 @@ void wSetGeometry(wWin_p win, int min_width, int max_width, int min_height, int static wWin_p wWinCommonCreate( wWin_p parent, int winType, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * labelStr, const char * nameStr, long option, @@ -999,7 +999,7 @@ static wWin_p wWinCommonCreate( gtk_widget_set_size_request(w->menubar, w->w-20, MENUH); } } - int scr_w, scr_h; + 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; @@ -1092,8 +1092,8 @@ static wWin_p wWinCommonCreate( wWin_p wWinMainCreate( const char * name, /* Application name */ - wPos_t x, /* Initial window width */ - wPos_t y, /* Initial window height */ + 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 */ @@ -1142,8 +1142,8 @@ wWin_p wWinMainCreate( wWin_p wWinPopupCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, const char * nameStr, @@ -1189,7 +1189,7 @@ void wExit( } } - wPrefFlush(); + wPrefFlush(""); if (gtkMainW && gtkMainW->winProc != NULL) { gtkMainW->winProc(gtkMainW, wQuit_e, NULL, gtkMainW->data); diff --git a/app/wlib/gtklib/wpref.c b/app/wlib/gtklib/wpref.c index 124305a..3494ba2 100644 --- a/app/wlib/gtklib/wpref.c +++ b/app/wlib/gtklib/wpref.c @@ -62,8 +62,8 @@ static char userHomeDir[BUFSIZ]; * The search order is: * 1. Directory specified by the XTRKCADLIB environment variable * 2. Directory specified by XTRKCAD_INSTALL_PREFIX/share/xtrkcad - * 3. /usr/lib/xtrkcad - * 4. /usr/local/lib/xtrkcad + * 3. /usr/share/xtrkcad + * 4. /usr/local/share/xtrkcad * * \return pointer to directory name */ @@ -86,39 +86,48 @@ const char * wGetAppLibDir( void ) if (ep != NULL) { if ((stat( ep, &buf) == 0 ) && S_ISDIR( buf.st_mode)) { strncpy( appLibDir, ep, sizeof appLibDir ); + //printf( "wAppLbDir=%s\n", appLibDir ); return appLibDir; } } - strcpy(appLibDir, XTRKCAD_INSTALL_PREFIX); - strcat(appLibDir, "/share/"); + strcpy(appLibDir, "../share/"); strcat(appLibDir, wlibGetAppName()); - if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) { + //printf( "wAppLbDir=%s\n", appLibDir ); return appLibDir; } - strcpy( appLibDir, "/usr/lib/" ); + char * dir1 = "/usr/share/"; + char * dir2 = "/usr/local/share/"; + if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) { + dir1 = "/usr/local/share/"; + dir2 = "/usr/share/"; + } + + strcpy( appLibDir, dir1 ); strcat( appLibDir, wlibGetAppName() ); if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) { + //printf( "wAppLbDir=%s\n", appLibDir ); return appLibDir; } - strcpy( appLibDir, "/usr/local/lib/" ); + strcpy( appLibDir, dir2 ); strcat( appLibDir, wlibGetAppName() ); if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) { + //printf( "wAppLbDir=%s\n", appLibDir ); return appLibDir; } 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" - " %s/share/xtrkcad or\n" - " /usr/lib/%s or\n" - " /usr/local/lib/%s\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."), - XTRKCAD_INSTALL_PREFIX, wlibGetAppName(), wlibGetAppName(), envvar ); + wlibGetAppName(), wlibGetAppName(), envvar ); wNoticeEx( NT_ERROR, msg, _("Ok"), NULL ); appLibDir[0] = '\0'; wExit(0); @@ -223,7 +232,7 @@ wBool_t prefInitted = FALSE; * Read the configuration file into memory */ -static void readPrefs( void ) +static void readPrefs( char * name, wBool_t update ) { char tmp[BUFSIZ], *np, *vp, *cp; const char * workDir; @@ -232,7 +241,10 @@ static void readPrefs( void ) prefInitted = TRUE; workDir = wGetAppWorkDir(); - sprintf( tmp, "%s/%s.rc", workDir, wConfigName ); + if (name && name[0]) + sprintf( tmp, "%s", name ); + else + sprintf( tmp, "%s/%s.rc", workDir, wConfigName ); prefFile = fopen( tmp, "r" ); if (prefFile == NULL) return; @@ -260,12 +272,23 @@ static void readPrefs( void ) cp = vp + strlen(vp) -1; while ( cp >= vp && (*cp=='\n' || *cp==' ' || *cp=='\t') ) cp--; cp[1] = '\0'; - DYNARR_APPEND( prefs_t, prefs_da, 10 ); - p = &prefs(prefs_da.cnt-1); - p->name = strdup(np); - p->section = strdup(sp); - p->dirty = FALSE; - p->val = strdup(vp); + if (update) { + 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); + p->dirty = TRUE; + break; + } + } + } else { + DYNARR_APPEND( prefs_t, prefs_da, 10 ); + p = &prefs(prefs_da.cnt-1); + p->name = strdup(np); + p->section = strdup(sp); + p->dirty = FALSE; + p->val = strdup(vp); + } } fclose( prefFile ); } @@ -286,7 +309,7 @@ void wPrefSetString( prefs_t * p; if (!prefInitted) - readPrefs(); + readPrefs("", FALSE); for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { @@ -319,7 +342,7 @@ char * wPrefGetStringBasic( prefs_t * p; if (!prefInitted) - readPrefs(); + readPrefs("", FALSE); for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { @@ -344,7 +367,7 @@ char * wPrefGetStringBasic( { char tmp[20]; - sprintf(tmp, "%ld", lval ); + snprintf(tmp, sizeof(tmp), "%ld", lval ); wPrefSetString( section, name, tmp ); } @@ -395,7 +418,7 @@ wBool_t wPrefGetIntegerBasic( { char tmp[20]; - sprintf(tmp, "%0.6f", lval ); + snprintf(tmp, sizeof(tmp), "%0.6f", lval ); wPrefSetString( section, name, tmp ); } @@ -432,6 +455,10 @@ wBool_t wPrefGetFloatBasic( return TRUE; } +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. @@ -439,7 +466,7 @@ wBool_t wPrefGetFloatBasic( */ void wPrefFlush( - void ) + char * name ) { prefs_t * p; char tmp[BUFSIZ]; @@ -450,7 +477,10 @@ void wPrefFlush( return; workDir = wGetAppWorkDir(); - sprintf( tmp, "%s/%s.rc", workDir, wConfigName ); + 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) return; diff --git a/app/wlib/gtklib/png.c b/app/wlib/gtklib/writebitmap.c index 809de6a..be9aa62 100644 --- a/app/wlib/gtklib/png.c +++ b/app/wlib/gtklib/writebitmap.c @@ -1,5 +1,5 @@ -/** \file png.c - * PNG creation +/** \file writebitmap.c + * Bitmap file creation */ /* XTrackCad - Model Railroad CAD @@ -25,10 +25,31 @@ #define GTK_DISABLE_DEPRECATED #define GSEAL_ENABLE +#include <string.h> #include <gtk/gtk.h> #include "gtkint.h" -#define BITMAPFILEFORMAT "png" +#define PNGFORMAT "png" +#define JPEGFORMAT "jpeg" + +/** + * 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); + + while (end > fname && *end != '.') { + --end; + } + return( end + 1 ); +} /** * Export as bitmap file. @@ -43,6 +64,22 @@ 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); @@ -52,7 +89,7 @@ wBool_t wBitMapWriteFile(wDraw_p d, const char * fileName) } error = NULL; - res = gdk_pixbuf_save(pixbuf, fileName, BITMAPFILEFORMAT, &error, NULL); + res = gdk_pixbuf_save(pixbuf, fileName, writeFormat, &error, NULL); if (res == FALSE) { wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_save failed", "Ok", NULL); diff --git a/app/wlib/include/wlib.h b/app/wlib/include/wlib.h index d3bfc18..7b89bdc 100644 --- a/app/wlib/include/wlib.h +++ b/app/wlib/include/wlib.h @@ -31,9 +31,15 @@ bool wIsUTF8(const char * string); * Interface types */ +// a big integer typedef long wInteger_t; -typedef int wPos_t; +// Position/Size of objects drawn on a WDraw canvas (fractional pixels) +typedef double wDrawPix_t; +// Position/Size of controls/windows (integral pixels) +typedef long wWinPix_t; +// Boolean typedef int wBool_t; +// index for lists etc typedef int wIndex_t; /* @@ -78,8 +84,8 @@ extern long wDebugFont; * Bitmap Controls bitmap.c */ -wControl_p wBitmapCreate(wWin_p parent, wPos_t x, wPos_t y, long options, wIcon_p iconP); -wIcon_p wIconCreateBitMap(wPos_t w, wPos_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); @@ -100,9 +106,9 @@ typedef enum { wBoxTrough } wBoxType_e; -void wBoxSetSize(wBox_p b, wPos_t w, wPos_t h); -void wlibDrawBox(wWin_p win, wBoxType_e style, wPos_t x, wPos_t y, wPos_t w, wPos_t h); -wBox_p wBoxCreate(wWin_p parent, wPos_t bx, wPos_t by, const char *labelStr, wBoxType_e boxTyp, wPos_t bw, wPos_t bh); +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); /*------------------------------------------------------------------------------ * @@ -129,13 +135,13 @@ 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, wPos_t x, wPos_t y, const char *helpStr, const char *labelStr, long option, wPos_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, wPos_t x, wPos_t y, const char *helpStr, const char *labelStr, long option, const char **labels, long *valueP, wChoiceCallBack_p action, void *data); -wChoice_p wToggleCreate(wWin_p parent, wPos_t x, wPos_t y, const char *helpStr, const char *labelStr, long option, const char **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); /*------------------------------------------------------------------------------ @@ -202,12 +208,12 @@ const char * wMemStats( void ); #define WKEY_ALT (1<<3) int wGetKeyState( void ); -void wGetDisplaySize( wPos_t*, wPos_t* ); +void wGetDisplaySize( wWinPix_t*, wWinPix_t* ); -wIcon_p wIconCreateBitMap( wPos_t, wPos_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, wPos_t x, wPos_t y ); +void wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y ); void wConvertToCharSet( char *, int ); void wConvertFromCharSet( char *, int ); @@ -246,9 +252,9 @@ typedef void (*wWinCallBack_p)( wWin_p, winProcEvent, void *, void * ); #define F_RESTRICT (1L<<15) #define F_NOTTRANSIENT (1L<<16) -wWin_p wWinMainCreate( const char *, wPos_t, wPos_t, const char *, const char *, const char *, +wWin_p wWinMainCreate( const char *, wWinPix_t, wWinPix_t, const char *, const char *, const char *, long, wWinCallBack_p, void * ); -wWin_p wWinPopupCreate( wWin_p, wPos_t, wPos_t, const char *, const char *, const char *, +wWin_p wWinPopupCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, const char *, const char *, long, wWinCallBack_p, void * ); wWin_p wMain( int, char *[] ); @@ -257,17 +263,17 @@ void wWinSetSmallIcon( wWin_p, wIcon_p ); void wWinShow( wWin_p, wBool_t ); wBool_t wWinIsVisible( wWin_p ); wBool_t wWinIsMaximized( wWin_p win); -void wWinGetSize ( wWin_p, wPos_t *, wPos_t * ); -void wWinSetSize( wWin_p, wPos_t, wPos_t ); +void wWinGetSize ( wWin_p, wWinPix_t *, wWinPix_t * ); +void wWinSetSize( wWin_p, wWinPix_t, wWinPix_t ); void wWinSetTitle( wWin_p, const char * ); void wWinSetBusy( wWin_p, wBool_t ); const char * wWinGetTitle( wWin_p ); -void wWinClear( wWin_p, wPos_t, wPos_t, wPos_t, wPos_t ); +void wWinClear( wWin_p, wWinPix_t, wWinPix_t, wWinPix_t, wWinPix_t ); void wMessage( wWin_p, const char *, wBool_t ); void wWinTop( wWin_p ); void wWinDoCancel( wWin_p ); void wWinBlockEnable( wBool_t ); -void wSetGeometry(wWin_p, int min_width, int max_width, int min_height, int max_height, int base_width, int 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 ); @@ -284,20 +290,22 @@ void wDestroySplash( void ); #define BO_READONLY (1L<<2) #define BO_NOTAB (1L<<8) #define BO_BORDER (1L<<9) -#define BO_ENTER (1L<<10) +//#define BO_ENTER (1L<<10) +#define BO_ENTER 0 +#define BO_REPEAT (1L<<11) -wPos_t wLabelWidth( const char * ); +wWinPix_t wLabelWidth( const char * ); const char * wControlGetHelp( wControl_p ); void wControlSetHelp( wControl_p, const char * ); void wControlShow( wControl_p, wBool_t ); -wPos_t wControlGetWidth( wControl_p ); -wPos_t wControlGetHeight( wControl_p ); -wPos_t wControlGetPosX( wControl_p ); -wPos_t wControlGetPosY( wControl_p ); -void wControlSetPos( wControl_p, wPos_t, wPos_t ); +wWinPix_t wControlGetWidth( wControl_p ); +wWinPix_t wControlGetHeight( wControl_p ); +wWinPix_t wControlGetPosX( wControl_p ); +wWinPix_t wControlGetPosY( wControl_p ); +void wControlSetPos( wControl_p, wWinPix_t, wWinPix_t ); void wControlSetFocus( wControl_p ); void wControlActive( wControl_p, wBool_t ); -void wControlSetBalloon( wControl_p, wPos_t, wPos_t, const char * ); +void wControlSetBalloon( wControl_p, wWinPix_t, wWinPix_t, const char * ); void wControlSetLabel( wControl_p, const char * ); void wControlSetBalloonText( wControl_p, const char * ); void wControlSetContext( wControl_p, void * ); @@ -314,11 +322,11 @@ 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, wPos_t, wPos_t, const char *, const char *, long, - wPos_t, char *, wIndex_t, wStringCallBack_p, +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, wPos_t ); +void wStringSetWidth( wString_p, wWinPix_t ); const char * wStringGetValue( wString_p ); @@ -330,11 +338,11 @@ 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, wPos_t, wPos_t, const char *, const char *, long, - wPos_t, wInteger_t, wInteger_t, wInteger_t *, +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, wPos_t, wPos_t, const char *, const char *, long, - wPos_t, double, double, double *, +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 ); @@ -364,12 +372,12 @@ typedef void (*wListCallBack_p)( wIndex_t, const char *, wIndex_t, void *, void /* lists, droplists and combo boxes */ -wList_p wListCreate( wWin_p, wPos_t, wPos_t, const char *, const char *, long, - long, wPos_t, int, wPos_t *, wBool_t *, const char **, long *, wListCallBack_p, void * ); -wList_p wDropListCreate( wWin_p, wPos_t, wPos_t, const char *, const char *, long, - long, wPos_t, long *, wListCallBack_p, void * ); +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, wPos_t x, wPos_t y, const char *helpStr, const char *labelStr, long option, long number, wPos_t width, long *valueP, wListCallBack_p action, void *data); +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); @@ -381,9 +389,9 @@ 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); void wListDelete(wList_p b, wIndex_t inx); -int wListGetColumnWidths(wList_p bl, int colCnt, wPos_t *colWidths); +int wListGetColumnWidths(wList_p bl, int colCnt, wWinPix_t *colWidths); wIndex_t wListAddValue(wList_p b, const char *labelStr, wIcon_p bm, void *itemData); -void wListSetSize(wList_p bl, wPos_t w, wPos_t h); +void wListSetSize(wList_p bl, wWinPix_t w, wWinPix_t h); wIndex_t wListGetValues( wList_p, char *, int, void * *, void * * ); /** \todo Check for the existance of following functions */ @@ -404,13 +412,13 @@ void wListSetEditable( wList_p, wBool_t ); #define wMessageSetFont( x ) ( x & (BM_LARGE | BM_SMALL )) #define wMessageCreate( w, p1, p2, l, p3, m ) wMessageCreateEx( w, p1, p2, l, p3, m, 0 ) -wMessage_p wMessageCreateEx( wWin_p, wPos_t, wPos_t, const char *, - wPos_t, const char *, long ); +wMessage_p wMessageCreateEx( wWin_p, wWinPix_t, wWinPix_t, const char *, + wWinPix_t, const char *, long ); void wMessageSetValue( wMessage_p, const char * ); -void wMessageSetWidth( wMessage_p, wPos_t ); -wPos_t wMessageGetWidth( const char *testString ); -wPos_t wMessageGetHeight( long ); +void wMessageSetWidth( wMessage_p, wWinPix_t ); +wWinPix_t wMessageGetWidth( const char *testString ); +wWinPix_t wMessageGetHeight( long ); /*------------------------------------------------------------------------------ @@ -439,8 +447,8 @@ 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, wPos_t, wPos_t, const char *, const char *, long, - wPos_t, wPos_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 ); @@ -450,8 +458,8 @@ wBool_t wTextGetModified( wText_p ); void wTextReadFile( wText_p, const char * ); wBool_t wTextSave( wText_p, const char * ); wBool_t wTextPrint( wText_p ); -void wTextSetSize( wText_p, wPos_t, wPos_t ); -void wTextComputeSize( wText_p, int, int, wPos_t *, wPos_t * ); +void wTextSetSize( wText_p, wWinPix_t, wWinPix_t ); +void wTextComputeSize( wText_p, wWinPix_t, wWinPix_t, wWinPix_t *, wWinPix_t * ); void wTextSetPosition( wText_p bt, int pos ); @@ -518,8 +526,8 @@ typedef int wAction_t; /* Creation CallBacks */ -typedef void (*wDrawRedrawCallBack_p)( wDraw_p, void *, wPos_t, wPos_t ); -typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wPos_t, wPos_t ); +typedef void (*wDrawRedrawCallBack_p)( wDraw_p, void *, wWinPix_t, wWinPix_t ); +typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wDrawPix_t, wDrawPix_t ); /* Creation Options */ #define BD_TICKS (1L<<25) @@ -529,38 +537,38 @@ typedef void (*wDrawActionCallBack_p)( wDraw_p, void*, wAction_t, wPos_t, wPos_t #define BD_MODKEYS (1L<<29) /* Create: */ -wDraw_p wDrawCreate( wWin_p, wPos_t, wPos_t, const char *, long, - wPos_t, wPos_t, void *, +wDraw_p wDrawCreate( wWin_p, wWinPix_t, wWinPix_t, const char *, long, + wWinPix_t, wWinPix_t, void *, wDrawRedrawCallBack_p, wDrawActionCallBack_p ); /* Draw: */ -void wDrawLine( wDraw_p, wPos_t, wPos_t, wPos_t, wPos_t, +void wDrawLine( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawWidth, wDrawLineType_e, wDrawColor, wDrawOpts ); #define double2wAngle_t( A ) (A) typedef double wAngle_t; -void wDrawArc( wDraw_p, wPos_t, wPos_t, wPos_t, wAngle_t, wAngle_t, +void wDrawArc( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wAngle_t, wAngle_t, int, wDrawWidth, wDrawLineType_e, wDrawColor, wDrawOpts ); -void wDrawPoint( wDraw_p, wPos_t, wPos_t, 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, wPos_t, wPos_t, wAngle_t, const char *, wFont_p, +void wDrawString( wDraw_p, wDrawPix_t, wDrawPix_t, wAngle_t, const char *, wFont_p, wFontSize_t, wDrawColor, wDrawOpts ); -void wDrawFilledRectangle( wDraw_p, wPos_t, wPos_t, wPos_t, wPos_t, +void wDrawFilledRectangle( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawColor, wDrawOpts ); -void wDrawPolygon( wDraw_p, wPos_t [][2], wPolyLine_e [], wIndex_t, wDrawColor, wDrawWidth, wDrawLineType_e, +void wDrawPolygon( wDraw_p, wDrawPix_t [][2], wPolyLine_e [], wIndex_t, wDrawColor, wDrawWidth, wDrawLineType_e, wDrawOpts, int, int ); -void wDrawFilledCircle( wDraw_p, wPos_t, wPos_t, wPos_t, wDrawColor, wDrawOpts ); +void wDrawFilledCircle( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawColor, wDrawOpts ); -void wDrawGetTextSize( wPos_t *, wPos_t *, wPos_t *, wPos_t *, wDraw_p, const char *, wFont_p, +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 ); void wDrawDelayUpdate( wDraw_p, wBool_t ); -void wDrawClip( wDraw_p, wPos_t, wPos_t, wPos_t, wPos_t ); +void wDrawClip( wDraw_p, wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawPix_t ); wDrawColor wDrawColorGray( int ); wDrawColor wDrawFindColor( long ); long wDrawGetRGB( wDrawColor ); @@ -568,15 +576,15 @@ long wDrawGetRGB( wDrawColor ); /* Geometry */ double wDrawGetDPI( wDraw_p ); double wDrawGetMaxRadius( wDraw_p ); -void wDrawSetSize( wDraw_p, wPos_t, wPos_t, void * ); -void wDrawGetSize( wDraw_p, wPos_t *, wPos_t * ); +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 * ); -void wDrawBitMap( wDraw_p, wDrawBitMap_p, wPos_t, wPos_t, +void wDrawBitMap( wDraw_p, wDrawBitMap_p, wDrawPix_t, wDrawPix_t, wDrawColor, wDrawOpts ); -wDraw_p wBitMapCreate( wPos_t, wPos_t, int ); +wDraw_p wBitMapCreate( wWinPix_t, wWinPix_t, int ); wBool_t wBitMapDelete( wDraw_p ); wBool_t wBitMapWriteFile( wDraw_p, const char * ); @@ -585,7 +593,8 @@ void * wDrawGetContext( wDraw_p ); void wDrawSaveImage( wDraw_p ); void wDrawRestoreImage( wDraw_p ); int wDrawSetBackground( wDraw_p, char * path, char ** error); -void wDrawShowBackground( wDraw_p, wPos_t pos_x, wPos_t pos_y, wPos_t width, wAngle_t angle, int screen); +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); /*------------------------------------------------------------------------------ * @@ -594,7 +603,7 @@ void wDrawShowBackground( wDraw_p, wPos_t pos_x, wPos_t pos_y, wPos_t width, w void wInitializeFonts(); void wSelectFont( const char * ); wFontSize_t wSelectedFontSize( void ); -void wSetSelectionFontSize(wFontSize_t); +void wSetSelectedFontSize(wFontSize_t size); #define F_TIMES (1) #define F_HELV (2) wFont_p wStandardFont( int, wBool_t, wBool_t ); @@ -616,7 +625,7 @@ wDraw_p wPrintPageStart( void ); wBool_t wPrintPageEnd( wDraw_p ); void wPrintDocEnd( void ); wBool_t wPrintQuit( void ); -void wPrintClip( wPos_t, wPos_t, wPos_t, wPos_t ); +void wPrintClip( wDrawPix_t, wDrawPix_t, wDrawPix_t, wDrawPix_t ); const char * wPrintGetName( void ); @@ -673,14 +682,14 @@ void wDoAccelHelp( wAccelKey_e key, void * ); /* Creation CallBacks */ typedef void (*wMenuCallBack_p)( void * ); typedef void (*wMenuListCallBack_p)( int, const char *, void * ); -typedef void (*wMenuToggleCallBack_p)( wBool_t , void * ); +typedef void (*wMenuCallBack_p)( void * ); typedef void (*wAccelKeyCallBack_p)( wAccelKey_e, void * ); typedef void (*wMenuTraceCallBack_p)( wMenu_p, const char *, void * ); /* Creation Options */ #define BM_ICON (1L<<0) -wMenu_p wMenuCreate( wWin_p, wPos_t, wPos_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, @@ -699,7 +708,7 @@ 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, wMenuToggleCallBack_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 ); @@ -741,8 +750,8 @@ int wFilSelect( struct wFilSel_t *, const char * ); typedef void (*wColorSelectButtonCallBack_p)( void *, wDrawColor ); wBool_t wColorSelect( const char *, wDrawColor * ); -wButton_p wColorSelectButtonCreate( wWin_p, wPos_t, wPos_t, const char *, const char *, - long, wPos_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 ); @@ -756,6 +765,8 @@ char * wPrefGetString(const char *section, const char *name); char * wPrefGetStringBasic( const char *section, const char *name ); char * wPrefGetStringExt(const char *section, const char *name); +void 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); @@ -767,7 +778,7 @@ wBool_t wPrefGetFloatBasic(const char *section, const char *name, double *result wBool_t wPrefGetFloatExt(const char *section, const char *name, double *result, double defaultValue); const char * wPrefGetSectionItem( const char * sectionName, wIndex_t * index, const char ** name ); -void wPrefFlush( void ); +void wPrefFlush( char * name); void wPrefReset( void ); void CleanupCustom( void ); @@ -779,17 +790,17 @@ void CleanupCustom( void ); wStatus_p wStatusCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * labelStr, - wPos_t width, + wWinPix_t width, const char *message ); -wPos_t wStatusGetWidth(const char *testString); -wPos_t wStatusGetHeight(long flags); +wWinPix_t wStatusGetWidth(const char *testString); +wWinPix_t wStatusGetHeight(long flags); void wStatusSetValue(wStatus_p b, const char * arg); -void wStatusSetWidth(wStatus_p b, wPos_t width); +void wStatusSetWidth(wStatus_p b, wWinPix_t width); /*------------------------------------------------------------------------------- * User Preferences @@ -797,4 +808,7 @@ void wStatusSetWidth(wStatus_p b, wPos_t width); #define PREFSECTION "Preference" #define LARGEICON "LargeIcons" +#define DPISET "ScreenDPI" +#define PRINTSCALE "PrintScale" +#define PRINTTEXTSCALE "PrintTextScale" #endif diff --git a/app/wlib/mswlib/CMakeLists.txt b/app/wlib/mswlib/CMakeLists.txt index 07558f9..99ac1d4 100644 --- a/app/wlib/mswlib/CMakeLists.txt +++ b/app/wlib/mswlib/CMakeLists.txt @@ -29,6 +29,7 @@ SET(SOURCES include_directories(${FREEIMAGE_INCLUDE_PATH}) INCLUDE_DIRECTORIES(${XTrkCAD_BINARY_DIR}) +# INCLUDE_DIRECTORIES(${help_BINARY_DIR}) IF(XTRKCAD_USE_GETTEXT) IF(WIN32) diff --git a/app/wlib/mswlib/backgnd.c b/app/wlib/mswlib/backgnd.c index d35f19a..9599beb 100644 --- a/app/wlib/mswlib/backgnd.c +++ b/app/wlib/mswlib/backgnd.c @@ -29,192 +29,215 @@ static char *lastErrorMessage; /**< store last message from FreeImage */ #define ERRORPUNCTUATION " : " -/**
- * FreeImage error handler
- * \param fif Format / Plugin responsible for the error
- * \param message Error message
+/** + * FreeImage error handler + * \param fif Format / Plugin responsible for the error + * \param message Error message */ -static void
-HandleFreeImageError(FREE_IMAGE_FORMAT fif, const char *message)
-{
- unsigned totalLength = strlen(message) + 1;
-
- if (fif != FIF_UNKNOWN) {
- totalLength += strlen(FreeImage_GetFormatFromFIF(fif)) + strlen(ERRORPUNCTUATION);
- }
-
- lastErrorMessage = malloc(totalLength);
-
- if (fif != FIF_UNKNOWN) {
- sprintf(lastErrorMessage,
- "%s" ERRORPUNCTUATION "%s",
- FreeImage_GetFormatFromFIF(fif),
- message);
- } else {
- strcpy(lastErrorMessage, message);
- }
+static void +HandleFreeImageError( FREE_IMAGE_FORMAT fif, const char *message ) +{ + size_t totalLength = strlen( message ) + 1; + + if( fif != FIF_UNKNOWN ) { + totalLength += strlen( FreeImage_GetFormatFromFIF( fif ) ) + strlen( + ERRORPUNCTUATION ); + } + + lastErrorMessage = malloc( totalLength ); + + if( fif != FIF_UNKNOWN ) { + sprintf( lastErrorMessage, + "%s" ERRORPUNCTUATION "%s", + FreeImage_GetFormatFromFIF( fif ), + message ); + } else { + strcpy( lastErrorMessage, message ); + } } -/**
-* Load the background image
-* \param bd drawing context
-* \param path filename for image file, if NULL the existing background will be removed
-* \param error returned error message
-* \return -1 unsupported or invalid file, 0 success, 1 background removed
+/** +* Load the background image +* \param bd drawing context +* \param path filename for image file, if NULL the existing background will be removed +* \param error returned error message +* \return -1 unsupported or invalid file, 0 success, 1 background removed */ int -wDrawSetBackground(wDraw_p bd, char * path, char ** error) +wDrawSetBackground( wDraw_p bd, char * path, char ** error ) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + FreeImage_SetOutputMessage( HandleFreeImageError ); - FreeImage_SetOutputMessage(HandleFreeImageError); -
- if (lastErrorMessage) {
- free(lastErrorMessage);
- lastErrorMessage = NULL;
+ if( lastErrorMessage ) { + free( lastErrorMessage ); + lastErrorMessage = NULL; } - if (path) { - // check the file signature and deduce its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(path, 0); - - if (fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(path); - } - - // check that the plugin has reading capabilities ... - if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // ok, let's load the file - bd->background = FreeImage_Load(fif, path, 0); - - // unless a bad file format, we are done ! - if (!bd->background) { - *error = lastErrorMessage; - return (-1); - } else { - return (0); - } - } else { - *error = strdup(_("Image file is invalid or cannot be read.")); - return (-1); - } - } else { - if (bd->background) { - FreeImage_Unload(bd->background); - bd->background = 0; - } - - return (1); - } + if( path ) { + // check the file signature and deduce its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType( path, 0 ); + + if( fif == FIF_UNKNOWN ) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename( path ); + } + + // check that the plugin has reading capabilities ... + if( ( fif != FIF_UNKNOWN ) && FreeImage_FIFSupportsReading( fif ) ) { + // ok, let's load the file + bd->background = FreeImage_Load( fif, path, 0 ); + + // unless a bad file format, we are done ! + if( !bd->background ) { + *error = lastErrorMessage; + return ( -1 ); + } else { + return ( 0 ); + } + } else { + *error = _strdup( _( "Image file is invalid or cannot be read." ) ); + return ( -1 ); + } + } else { + if( bd->background ) { + FreeImage_Unload( bd->background ); + bd->background = 0; + } + + return ( 1 ); + } } +/** + * Use a loaded background in another context. + * + * \param from context with background + * \param to context to get a reference to the existing background + */ -/**
-* Draw background to screen. The background will be sized and rotated before being shown. The bitmap
-* is scaled so that the width is equal to size. The height is changed proportionally.
-*
-* \param bd drawing context
-* \param pos_x, pos_y bitmap position
-* \param size desired width after scaling
-* \param angle
-* \param screen visibility of bitmap in percent
+void +wDrawCloneBackground( wDraw_p from, wDraw_p to ) +{ + if( from->background ) { + to->background = from->background; + } else { + to->background = NULL; + } +} + +/** +* Draw background to screen. The background will be sized and rotated before being shown. The bitmap +* is scaled so that the width is equal to size. The height is changed proportionally. +* +* \param bd drawing context +* \param pos_x, pos_y bitmap position +* \param size desired width after scaling +* \param angle +* \param screen visibility of bitmap in percent */ void -wDrawShowBackground(wDraw_p bd, wPos_t pos_x, wPos_t pos_y, wPos_t size, - wAngle_t angle, int screen) +wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, + wWinPix_t size, + wAngle_t angle, int screen ) { - if (bd->background) { - double scale; - FIBITMAP *tmp; - FIBITMAP *rotated; - - if (size == 0) { - scale = 1.0; - } else { - scale = (double)size / FreeImage_GetWidth(bd->background); - } - - tmp = FreeImage_RescaleRect(bd->background, - (int)((double)FreeImage_GetWidth(bd->background) * scale), - (int)((double)FreeImage_GetHeight(bd->background) * scale), - 0, - 0, - FreeImage_GetWidth(bd->background), - FreeImage_GetHeight(bd->background), - FILTER_BILINEAR, - 0); - FreeImage_AdjustColors(tmp, screen, -screen, 1.0, FALSE); - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(tmp); - - switch (image_type) { - case FIT_BITMAP: - switch (FreeImage_GetBPP(tmp)) { - case 8: { - BYTE color = 255; - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case 24: // we could also use 'RGBTRIPLE color' here - case 32: { - RGBQUAD color = { 255, 255, 255, 0 }; - // for 24-bit images, the first 3 bytes will be read - // for 32-bit images, the first 4 bytes will be read - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - } - - break; - - case FIT_UINT16: { - WORD color = 255; - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case FIT_RGB16: // we could also use 'FIRGB16 color' here - case FIT_RGBA16: { - FIRGBA16 color = { 255, 255, 255, 0 }; - // for RGB16 images, the first 3 WORD will be read - // for RGBA16 images, the first 4 WORD will be read - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case FIT_FLOAT: { - float color = 1.0F; - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - - case FIT_RGBF: // we could also use 'FIRGBF color' here - case FIT_RGBAF: { - FIRGBAF color = { 1, 1, 1, 0 }; - // for RGBF images, the first 3 float will be read - // for RGBAF images, the first 4 float will be read - rotated = FreeImage_Rotate(tmp, angle, &color); - } - break; - } - - SetDIBitsToDevice(bd->hDc, - pos_x, - bd->h - pos_y - FreeImage_GetHeight(rotated), - FreeImage_GetWidth(rotated), - FreeImage_GetHeight(rotated), - 0, 0, - 0, - FreeImage_GetHeight(rotated), - FreeImage_GetBits(rotated), - FreeImage_GetInfo(rotated), - DIB_RGB_COLORS); - FreeImage_Unload(tmp); - FreeImage_Unload(rotated); - } -}
\ No newline at end of file + if( bd->background ) { + double scale; + FIBITMAP *tmp; + FIBITMAP *rotated; + + if( size == 0 ) { + scale = 1.0; + } else { + scale = ( double )size / FreeImage_GetWidth( bd->background ); + } + + tmp = FreeImage_RescaleRect( bd->background, + ( int )( ( double )FreeImage_GetWidth( bd->background ) * scale ), + ( int )( ( double )FreeImage_GetHeight( bd->background ) * scale ), + 0, + 0, + FreeImage_GetWidth( bd->background ), + FreeImage_GetHeight( bd->background ), + FILTER_BILINEAR, + 0 ); + + if( tmp == NULL ) { + return; + } + + FreeImage_AdjustColors( tmp, screen, -screen, 1.0, FALSE ); + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType( tmp ); + + switch( image_type ) { + case FIT_BITMAP: + switch( FreeImage_GetBPP( tmp ) ) { + case 8: { + BYTE color = 255; + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case 24: // we could also use 'RGBTRIPLE color' here + case 32: { + RGBQUAD color = { 255, 255, 255, 0 }; + // for 24-bit images, the first 3 bytes will be read + // for 32-bit images, the first 4 bytes will be read + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + } + + break; + + case FIT_UINT16: { + WORD color = 255; + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case FIT_RGB16: // we could also use 'FIRGB16 color' here + case FIT_RGBA16: { + FIRGBA16 color = { 255, 255, 255, 0 }; + // for RGB16 images, the first 3 WORD will be read + // for RGBA16 images, the first 4 WORD will be read + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case FIT_FLOAT: { + float color = 1.0F; + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + + case FIT_RGBF: // we could also use 'FIRGBF color' here + case FIT_RGBAF: { + FIRGBAF color = { 1, 1, 1, 0 }; + // for RGBF images, the first 3 float will be read + // for RGBAF images, the first 4 float will be read + rotated = FreeImage_Rotate( tmp, angle, &color ); + } + break; + } + + SetDIBitsToDevice( bd->hDc, + pos_x, + bd->h - pos_y - FreeImage_GetHeight( rotated ), + FreeImage_GetWidth( rotated ), + FreeImage_GetHeight( rotated ), + 0, 0, + 0, + FreeImage_GetHeight( rotated ), + FreeImage_GetBits( rotated ), + FreeImage_GetInfo( rotated ), + DIB_RGB_COLORS ); + FreeImage_Unload( tmp ); + FreeImage_Unload( rotated ); + } +} diff --git a/app/wlib/mswlib/dynarr.h b/app/wlib/mswlib/dynarr.h index 5bd7a8e..e8a178e 100644 --- a/app/wlib/mswlib/dynarr.h +++ b/app/wlib/mswlib/dynarr.h @@ -31,10 +31,6 @@ typedef struct { #ifdef WINDOWS -#ifndef WIN32 -#define FAR _far -#endif -#define M_PI 3.14159 #define strcasecmp _stricmp #else #endif diff --git a/app/wlib/mswlib/gwin32.c b/app/wlib/mswlib/gwin32.c index 6b0c7f3..877c329 100644 --- a/app/wlib/mswlib/gwin32.c +++ b/app/wlib/mswlib/gwin32.c @@ -40,7 +40,7 @@ #include <errno.h> #include <ctype.h> #if defined(_MSC_VER) || defined(__DMC__) -# include <io.h> +#include <io.h> #endif /* _MSC_VER || __DMC__ */ #ifndef SUBLANG_SERBIAN_LATIN_BA diff --git a/app/wlib/mswlib/mswbitmap.c b/app/wlib/mswlib/mswbitmap.c index 95b8a69..d4ee83c 100644 --- a/app/wlib/mswlib/mswbitmap.c +++ b/app/wlib/mswlib/mswbitmap.c @@ -29,7 +29,6 @@ #include <commdlg.h> #include <stdio.h> #include <assert.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" @@ -49,8 +48,8 @@ HBITMAP mswCreateBitMap( COLORREF fgCol1, COLORREF fgCol2, COLORREF bgCol, - wPos_t w, - wPos_t h, + int w, + int h, const char * bits ) { HDC hDc; @@ -100,7 +99,7 @@ HBITMAP mswCreateBitMap( return hBitMap; } -dynArr_t bitmap_da; +static dynArr_t bitmap_da; #define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N) #define bitmap(N) DYNARR_N(HBITMAP,bitmap_da,N) @@ -252,7 +251,7 @@ void mswDrawIcon( * \return pointer to icon */ -wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor color ) +wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawColor color ) { int lineLength; int i, j; @@ -330,12 +329,13 @@ wIcon_p wIconCreateBitMap( wPos_t w, wPos_t h, const char * bits, wDrawColor col wIcon_p wIconCreatePixMap( char *pm[]) { wIcon_p ip; - int col, r, g, b, len; + int col, r, g, b; + size_t len; int width, height; char buff[3]; char * cp, * cq, * ptr; int i, j, k; - int lineLength; + size_t lineLength; unsigned *keys; unsigned numchars; unsigned pixel; @@ -473,7 +473,7 @@ void wIconSetColor( wIcon_p ip, wDrawColor color ) */ void -wIconDraw( wDraw_p d, wIcon_p bm, wPos_t x, wPos_t y ) +wIconDraw( wDraw_p d, wIcon_p bm, wWinPix_t x, wWinPix_t y ) { mswDrawIcon( d->hDc, (int)x, (int)y, bm, FALSE, 0, 0 ); } @@ -489,7 +489,7 @@ wIconDraw( wDraw_p d, wIcon_p bm, wPos_t x, wPos_t y ) */ wControl_p -wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP ) +wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long option, const struct wIcon_t * iconP ) { wBitmap_p control; int index; @@ -502,7 +502,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP ) control->hWnd = CreateWindow( "STATIC", NULL, style, control->x, control->y, iconP->w, iconP->h, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (control->hWnd == NULL) { mswFail("CreateWindow(BITMAP)"); @@ -510,7 +510,7 @@ wBitmapCreate( wWin_p parent, wPos_t x, wPos_t y, long option, wIcon_p iconP ) } control->h = iconP->h; control->w = iconP->w; - control->data = iconP; + control->data = (void*)iconP; return (wControl_p)control; } diff --git a/app/wlib/mswlib/mswbox.c b/app/wlib/mswlib/mswbox.c index 04b3656..4f90cf4 100644 --- a/app/wlib/mswlib/mswbox.c +++ b/app/wlib/mswlib/mswbox.c @@ -30,8 +30,8 @@ struct wBox_t { void wBoxSetSize( wBox_p bb, - wPos_t w, - wPos_t h ) + wWinPix_t w, + wWinPix_t h ) { bb->w = w; bb->h = h; @@ -42,7 +42,7 @@ static void repaintBox( HWND hWnd, wControl_p b ) { HDC hDc; wBox_p bb = (wBox_p)(b); - wPos_t x0, y0, x1, y1; + wWinPix_t x0, y0, x1, y1; char lastColor; int lastRop; static char colors[8][4][2] = { @@ -95,12 +95,12 @@ static callBacks_t boxCallBacks = { wBox_p wBoxCreate( wWin_p parent, - wPos_t origX, - wPos_t origY, + wWinPix_t origX, + wWinPix_t origY, const char * labelStr, wBoxType_e typ, - wPos_t width, - wPos_t height ) + wWinPix_t width, + wWinPix_t height ) { wBox_p b; int index; diff --git a/app/wlib/mswlib/mswbutt.c b/app/wlib/mswlib/mswbutt.c index 16f31c1..ac5bc87 100644 --- a/app/wlib/mswlib/mswbutt.c +++ b/app/wlib/mswlib/mswbutt.c @@ -27,7 +27,15 @@ #include <commdlg.h> #include <math.h> #include "mswint.h" -int kludge12 = 0; + +/** Macros for button repeat timers */ +#define REPEAT_STAGE0_DELAY 500 +#define REPEAT_STAGE1_DELAY 150 +#define REPEAT_STAGE2_DELAY 75 +#define STOP_TIMER (-1) +#define INITIAL_WAIT (0) +#define SLOW_REPEATS (1) +#define FAST_REPEATS (2) /* ***************************************************************************** @@ -45,6 +53,9 @@ struct wButton_t { wBool_t busy; wBool_t selected; wIcon_p icon; + UINT_PTR timer_id; + int timer_count; + int timer_state; }; @@ -75,7 +86,7 @@ static void drawButton( HPEN oldPen, newPen; RECT rect; COLORREF color1, color2; - POS_T offw=5, offh=5; + wWinPix_t offw=5, offh=5; TRIVERTEX vert[2] ; GRADIENT_RECT gRect; @@ -191,7 +202,7 @@ static void buttDrawIcon( HDC butt_hDc ) { wIcon_p bm = b->icon; - POS_T offw=5, offh=5; + wWinPix_t offw=5, offh=5; if (b->selected || b->busy) { offw++; offh++; @@ -204,14 +215,22 @@ static void buttDrawIcon( } void wButtonSetBusy( - wButton_p b, - int value ) + wButton_p b, + int value) { - b->busy = value; - if (!value) - b->selected = FALSE; - /*SendMessage( b->hWnd, BM_SETSTATE, (WPARAM)value, 0L );*/ - 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); } @@ -227,6 +246,60 @@ void wButtonSetLabel( } InvalidateRgn( b->hWnd, NULL, FALSE ); } + +/** + * Button timer: handle timer events for buttons. These are used for + * auto-repeating presses. Three phases used are + * - initial delay before repetitions begin + * - slow repeats for a few cycles + * - fast repeats therafter + * - stop timer + * + * \param hWnd Handle of the window, unused + * \param message The message, unused + * \param timer The timer id is the wlib widget . + * \param timepast The timepast, unused + */ + +void CALLBACK buttTimer(HWND hWnd, UINT message, UINT_PTR timer, + DWORD timepast) +{ + wButton_p b = (wButton_p)timer; + if (b->timer_id == 0) { + b->timer_state = STOP_TIMER; + return ; + } + + /* Autorepeat state machine */ + switch (b->timer_state) { + case INITIAL_WAIT: + b->timer_state = SLOW_REPEATS; + b->timer_count = 0; + KillTimer(hWnd, (UINT_PTR)b); + SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE1_DELAY, buttTimer); + break; + case SLOW_REPEATS: /* Enable slow auto-repeat */ + if (b->timer_count++ > 10) { + /* Start fast auto-repeat */ + b->timer_state = FAST_REPEATS; + KillTimer(hWnd, (UINT_PTR)b); + SetTimer(hWnd, (UINT_PTR)b, REPEAT_STAGE2_DELAY, buttTimer); + } + break; + case FAST_REPEATS: + break; + case STOP_TIMER: + default: + KillTimer(hWnd, (UINT_PTR)b); + b->timer_id = 0; + return; + break; + } + if (b->action) { + b->action(b->data); + } + return; +} static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) @@ -240,7 +313,7 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L case WM_COMMAND: if (bb->action /*&& !bb->busy*/) { bb->action( bb->data ); - return 0L; + return (LRESULT)0; } break; @@ -249,10 +322,10 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L if (bb->type != B_BUTTON || (bb->option & BO_ICON) == 0) break; mi->CtlType = ODT_BUTTON; - mi->CtlID = wParam; + mi->CtlID = (UINT)wParam; mi->itemWidth = (UINT)ceil(bb->w*scaleIcon); mi->itemHeight = (UINT)ceil(bb->h*scaleIcon); - } return 0L; + } return (LRESULT)0; case WM_DRAWITEM: if (bb->type == B_BUTTON && (bb->option & BO_ICON) != 0) { @@ -261,10 +334,9 @@ static LRESULT buttPush( wControl_p b, HWND hWnd, UINT message, WPARAM wParam, L bb->selected = selected; InvalidateRgn( bb->hWnd, NULL, FALSE ); } - return TRUE; + return (LRESULT)TRUE; } break; - } return DefWindowProc( hWnd, message, wParam, lParam ); } @@ -279,15 +351,12 @@ static void buttDone( LRESULT CALLBACK pushButt( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif + + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wButton_p b = (wButton_p)mswMapIndex( inx ); PAINTSTRUCT ps; @@ -297,7 +366,7 @@ LRESULT CALLBACK pushButt( BeginPaint( hWnd, &ps ); buttDrawIcon( (wButton_p)b, ps.hdc ); EndPaint( hWnd, &ps ); - return 1L; + return (LRESULT)1; } break; case WM_CHAR: @@ -311,18 +380,29 @@ LRESULT CALLBACK pushButt( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LONG_PTR)0; } } break; case WM_KILLFOCUS: if ( b ) InvalidateRect( b->hWnd, NULL, TRUE ); - return 0L; + return (LRESULT)0; + break; + case WM_LBUTTONDOWN: + if (b->option&BO_REPEAT) { + SetTimer(hWnd, (UINT_PTR)b,REPEAT_STAGE0_DELAY,buttTimer); + b->timer_state = INITIAL_WAIT; + b->timer_id = (UINT_PTR)b; + } break; - case WM_LBUTTONUP: - /* don't know why but this solves a problem with color selection */ - Sleep( 0 ); + case WM_LBUTTONUP: + /* don't know why but this solves a problem with color selection */ + Sleep( 0 ); + if (b->timer_id) + KillTimer(hWnd, (UINT_PTR)b); + b->timer_id = 0; + b->timer_state = STOP_TIMER; break; } return CallWindowProc( oldButtProc, hWnd, message, wParam, lParam ); @@ -335,12 +415,12 @@ static callBacks_t buttonCallBacks = { wButton_p wButtonCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - wPos_t width, + wWinPix_t width, wButtonCallBack_p action, void * data ) { @@ -366,11 +446,11 @@ wButton_p wButtonCreate( b->selected = 0; mswComputePos( (wControl_p)b, x, y ); if (b->option&BO_ICON) { - width = (wPos_t)ceil(bm->w*scaleIcon)+10; + width = (wWinPix_t)ceil(bm->w*scaleIcon)+10; h = (int)ceil(bm->h*scaleIcon)+10; b->icon = bm; } else { - width = (wPos_t)(width*mswScale); + width = (wWinPix_t)(width*mswScale); } style = ((b->option&BO_ICON)? BS_OWNERDRAW : BS_PUSHBUTTON) | WS_CHILD | WS_VISIBLE | @@ -379,7 +459,7 @@ wButton_p wButtonCreate( style |= BS_DEFPUSHBUTTON; b->hWnd = CreateWindow( "BUTTON", labelStr, style, b->x, b->y, /*CW_USEDEFAULT, CW_USEDEFAULT,*/ width, h, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(BUTTON)"); return b; @@ -393,7 +473,10 @@ wButton_p wButtonCreate( mswCallBacks[B_BUTTON] = &buttonCallBacks; mswChainFocus( (wControl_p)b ); - oldButtProc = (WNDPROC) SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt); + oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)&pushButt); +#ifdef _OLDCODE + oldButtProc = (WNDPROC)SetWindowLongPtr(b->hWnd, GWL_WNDPROC, (LONG_PTR)&pushButt); +#endif if (mswPalette) { hDc = GetDC( b->hWnd ); SelectPalette( hDc, mswPalette, 0 ); @@ -401,7 +484,7 @@ wButton_p wButtonCreate( ReleaseDC( b->hWnd, hDc ); } if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); InvalidateRect(b->hWnd, &rect, TRUE); diff --git a/app/wlib/mswlib/mswchoic.c b/app/wlib/mswlib/mswchoic.c index 2ac391a..55ed177 100644 --- a/app/wlib/mswlib/mswchoic.c +++ b/app/wlib/mswlib/mswchoic.c @@ -15,8 +15,8 @@ ***************************************************************************** */ -int CHOICE_HEIGHT=(17); -int CHOICE_MIN_WIDTH=25; +#define CHOICE_HEIGHT (17) +#define CHOICE_MIN_WIDTH (25) static XWNDPROC oldChoiceItemProc = NULL; static XWNDPROC newChoiceItemProc; @@ -28,7 +28,7 @@ typedef struct { struct wChoice_t { WOBJ_COMMON - const char * * labels; + const char * const * labels; wChoiceItem_p *buttList; long *valueP; long oldVal; @@ -42,14 +42,14 @@ void wRadioSetValue( wChoice_p bc, long val ) { - const char ** labels; + const char * const * labels; long cnt; wChoiceItem_p * butts; butts = (wChoiceItem_p*)bc->buttList; for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ ) SendMessage( (*butts)->hWnd, BM_SETCHECK, - (val==cnt)?1:0, 0L ); + (WPARAM)((val==cnt)?1:0), (LPARAM)0 ); bc->oldVal = val; if (bc->valueP) *bc->valueP = val; @@ -67,14 +67,14 @@ void wToggleSetValue( wChoice_p bc, long val ) { - const char ** labels; + const char * const * labels; long cnt; wChoiceItem_p * butts; butts = (wChoiceItem_p*)bc->buttList; for (labels = bc->labels, cnt=0; *labels; labels++, cnt++, butts++ ) SendMessage( (*butts)->hWnd, BM_SETCHECK, - (val & (1L<<cnt)) != 0, 0L ); + (WPARAM)((val & (1L<<cnt)) != 0), (LPARAM)0 ); bc->oldVal = val; if (bc->valueP) *bc->valueP = val; @@ -115,12 +115,12 @@ static void choiceShow( static void choiceSetPos( wControl_p b, - wPos_t x, - wPos_t y ) + wWinPix_t x, + wWinPix_t y ) { wChoice_p bc = (wChoice_p)b; wChoiceItem_p * butts; - wPos_t dx, dy; + wWinPix_t dx, dy; dx = x - bc->x; dy = y - bc->y; @@ -129,8 +129,10 @@ static void choiceSetPos( SWP_NOSIZE|SWP_NOZORDER ); for (butts = (wChoiceItem_p*)bc->buttList; *butts; butts++ ) { + (*butts)->x += dx; + (*butts)->y += dy; SetWindowPos( (*butts)->hWnd, HWND_TOP, - (*butts)->x+=dx, (*butts)->y+=dy, + (*butts)->x, (*butts)->y, CW_USEDEFAULT, CW_USEDEFAULT, SWP_NOSIZE|SWP_NOZORDER ); } @@ -138,19 +140,14 @@ static void choiceSetPos( bc->y = y; } -long FAR PASCAL _export pushChoiceItem( +LRESULT FAR PASCAL _export pushChoiceItem( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif - + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wControl_p b = mswMapIndex( inx ); switch (message) { @@ -165,7 +162,7 @@ long FAR PASCAL _export pushChoiceItem( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LRESULT)0; } } break; @@ -194,20 +191,20 @@ LRESULT choiceItemProc( for (rest = (wChoiceItem_p*)bc->buttList; *rest; rest++ ) { switch (bc->type) { case B_TOGGLE: - num = rest-(wChoiceItem_p*)bc->buttList; + num = (int)(rest-(wChoiceItem_p*)bc->buttList); if (*rest == me) { bc->oldVal ^= (1L<<num); } SendMessage( (*rest)->hWnd, BM_SETCHECK, - (bc->oldVal & (1L<<num)) != 0, 0L ); + (WPARAM)((bc->oldVal & (1L<<num)) != 0), (LPARAM)0 ); break; case B_RADIO: if (*rest != me) { - SendMessage( (*rest)->hWnd, BM_SETCHECK, 0, 0L ); + SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)0, (LPARAM)0 ); } else { - bc->oldVal = rest-(wChoiceItem_p*)bc->buttList; - SendMessage( (*rest)->hWnd, BM_SETCHECK, 1, 0L ); + bc->oldVal = (long)(rest-(wChoiceItem_p*)bc->buttList); + SendMessage( (*rest)->hWnd, BM_SETCHECK, (WPARAM)1, (LPARAM)0 ); } break; } @@ -259,25 +256,25 @@ static callBacks_t choiceItemCallBacks = { static wChoice_p choiceCreate( wType_e type, wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const * labels, long *valueP, wChoiceCallBack_p action, void *data ) { wChoice_p b; - const char ** lp; + const char * const * lp; int cnt; wChoiceItem_p * butts; - int ppx, ppy; + wWinPix_t ppx, ppy; int bs; HDC hDc; HWND hButt; - int lab_l; + size_t lab_l; DWORD dw; int w, maxW; int pw, ph; @@ -319,7 +316,7 @@ static wChoice_p choiceCreate( (*butts)->hWnd = hButt = CreateWindow( "BUTTON", (*butts)->labelStr, bs | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x+pw, b->y+ph, 80, CHOICE_HEIGHT, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if ( hButt == (HWND)0 ) { mswFail( "choiceCreate button" ); return b; @@ -334,7 +331,7 @@ static wChoice_p choiceCreate( lab_l = strlen((*butts)->labelStr); if (!mswThickFont) {hFont = SelectObject( hDc, mswLabelFont );} - dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), lab_l ); + dw = GetTextExtent( hDc, (char *)((*butts)->labelStr), (UINT)lab_l ); if (!mswThickFont) {SelectObject( hDc, hFont );} w = LOWORD(dw) + CHOICE_MIN_WIDTH; @@ -354,10 +351,14 @@ static wChoice_p choiceCreate( } mswChainFocus( (wControl_p)*butts ); newChoiceItemProc = MakeProcInstance( (XWNDPROC)pushChoiceItem, mswHInst ); - oldChoiceItemProc = (XWNDPROC)GetWindowLong( (*butts)->hWnd, GWL_WNDPROC ); - SetWindowLong( (*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc ); + oldChoiceItemProc = (XWNDPROC)GetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC); + SetWindowLongPtr((*butts)->hWnd, GWLP_WNDPROC, (LPARAM)newChoiceItemProc); +#ifdef _OLDCODE + oldChoiceItemProc = (XWNDPROC)GetWindowLong((*butts)->hWnd, GWL_WNDPROC); + SetWindowLong((*butts)->hWnd, GWL_WNDPROC, (LONG)newChoiceItemProc); +#endif if ( !mswThickFont ) - SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( (*butts)->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); } *butts = NULL; switch (b->type) { @@ -392,12 +393,12 @@ static wChoice_p choiceCreate( wChoice_p wRadioCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data ) @@ -408,12 +409,12 @@ wChoice_p wRadioCreate( wChoice_p wToggleCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - const char **labels, + const char * const *labels, long *valueP, wChoiceCallBack_p action, void *data ) diff --git a/app/wlib/mswlib/mswcolor.c b/app/wlib/mswlib/mswcolor.c index 41bf6a9..fb9b0ba 100644 --- a/app/wlib/mswlib/mswcolor.c +++ b/app/wlib/mswlib/mswcolor.c @@ -25,8 +25,8 @@ #define NUM_GRAYS (16) #define NUM_COLORS (256) -wDrawColor wDrawColorWhite = 0; -wDrawColor wDrawColorBlack = 1; +static wDrawColor wDrawColorWhite = 0; +static wDrawColor wDrawColorBlack = 1; #define MAX_COLOR_DISTANCE (3) @@ -45,8 +45,6 @@ static struct { { 0, 0, 0 } /* Black */ } }; -COLORREF mappedColors[NUM_COLORS]; - static long flipRGB( long rgb ) { @@ -236,6 +234,7 @@ static void mswGetCustomColors( void ) strcpy( colorName, "custom-" ); for ( inx=0; inx<16; inx++ ) { sprintf( colorName+7, "%d", inx ); + /** @prefs [mswcolor] custom-0=<rgb> to custom-15=<rgb> Set custom colors */ wPrefGetInteger( "mswcolor", colorName, &rgb, 0 ); aclrCust[inx] = flipRGB(rgb); } @@ -316,12 +315,12 @@ static void doColorButton( wButton_p wColorSelectButtonCreate( wWin_p win, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - wPos_t width, + wWinPix_t width, wDrawColor * color, wColorSelectButtonCallBack_p action, void * data ) diff --git a/app/wlib/mswlib/mswdraw.c b/app/wlib/mswlib/mswdraw.c index c2739e6..be5bcd6 100644 --- a/app/wlib/mswlib/mswdraw.c +++ b/app/wlib/mswlib/mswdraw.c @@ -29,13 +29,8 @@ #include <math.h> #include <winuser.h> -#ifdef WIN32 #define wFont_t tagLOGFONTA -#else -#define wFont_t tagLOGFONT -#endif -#include "misc.h" #include "mswint.h" #include <FreeImage.h> @@ -48,9 +43,9 @@ wBool_t wDrawDoTempDraw = TRUE; ***************************************************************************** */ -static wBool_t initted = FALSE; +#define M_PI 3.14159265358979323846 -long wDebugFont; +static wBool_t initted = FALSE; static FARPROC oldDrawProc; @@ -59,69 +54,53 @@ static long tmpOp = 0x990066; static long setOp = 0x8800c6; static long clrOp = 0xbb0226; -#define CENTERMARK_LENGTH 6 +#define CENTERMARK_LENGTH 4 -bool bDrawMainBM = 0; +static bool bDrawMainBM = 0; + +typedef struct { + double x, y; +} coOrd; #ifdef SLOW -static wPos_t XPIX2INCH( wDraw_p d, int ix ) +static wDrawPix_t XWINPIX2DRAWPIX( wDraw_p d, wWinPix_t ix ) { - return (wPos_t)ix; + return (wDrawPix_t)ix; } -static wPos_t YPIX2INCH( wDraw_p d, int iy ) +static wDrawPix_t YWINPIX2DRAWPIX( wDraw_p d, wWinPix_t iy ) { - wPos_t y; - y = (wPos_t)(d->h-2-iy); + wWinPix_t y; + y = (wDrawPix_t)(d->h-2-iy); return y; } -static int XINCH2PIX( wDraw_p d, wPos_t xx ) +static wWinPix_t XDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t xx ) { - int ix; - ix = (int)(xx); + wWinPix_t ix; + ix = (wWinPix_t)(xx); return ix; } -static int YINCH2PIX( wDraw_p d, wPos_t y ) +static wWinPix_t YDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t y ) { - int iy; - iy = d->h-2 - (int)(y); + wWinPix_t iy; + iy = (d->h)-2 - (wWinPix_t)(y); return iy; } - -static wPos_t XPIXELSTOINCH( wDraw_p d, int ix ) -{ - return (wPos_t)ix; -} - - -static wPos_t YPIXELSTOINCH( wDraw_p d, int iy ) -{ - return (wPos_t)iy; -} #else -#define XPIX2INCH( d, ix ) \ - ((wPos_t)ix) - -#define YPIX2INCH( d, iy ) \ - ((wPos_t)(d->h-2-iy)) - -#define XINCH2PIX( d, xx ) \ - ((int)(xx)) - -#define YINCH2PIX( d, y ) \ - (d->h-2 - (int)(y)) +#define XWINPIX2DRAWPIX( d, ix ) \ + ((wDrawPix_t)ix) +#define YWINPIX2DRAWPIX( d, iy ) \ + ((wDrawPix_t)(d->h-2-iy)) -#define XPIXELSTOINCH( d, ix ) \ - ((wPos_t)ix) - - -#define YPIXELSTOINCH( d, iy ) \ - ((wPos_t)iy) +#define XDRAWPIX2WINPIX( d, xx ) \ + ((wWinPix_t)(xx)) +#define YDRAWPIX2WINPIX( d, y ) \ + (d->h - 2 - (wWinPix_t)(y)) #endif /* @@ -134,7 +113,9 @@ static wPos_t YPIXELSTOINCH( wDraw_p d, int iy ) +/** @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( @@ -323,10 +304,10 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d ) void wDrawLine( wDraw_p d, - wPos_t p0x, - wPos_t p0y, - wPos_t p1x, - wPos_t p1y, + wDrawPix_t p0x, + wDrawPix_t p0y, + wDrawPix_t p1x, + wDrawPix_t p1y, wDrawWidth dw, wDrawLineType_e lt, wDrawColor dc, @@ -335,10 +316,10 @@ void wDrawLine( POINT p0, p1; RECT rect; setDrawMode( d, dw, lt, dc, dopt ); - p0.x = XINCH2PIX(d,p0x); - p0.y = YINCH2PIX(d,p0y); - p1.x = XINCH2PIX(d,p1x); - p1.y = YINCH2PIX(d,p1y); + p0.x = XDRAWPIX2WINPIX(d,p0x); + 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 ); @@ -365,6 +346,12 @@ void wDrawLine( } } +static double d2r(double angle) +{ + angle *= (M_PI / 180.0); + return angle; +} + static double mswsin( double angle ) { while (angle < 0.0) angle += 360.0; @@ -406,12 +393,12 @@ static double mswasin( double x, double h ) void wDrawArc( wDraw_p d, - wPos_t px, - wPos_t py, - wPos_t r, + wDrawPix_t px, + wDrawPix_t py, + wDrawPix_t r, double a0, double a1, - int drawCenter, + int sizeCenter, wDrawWidth dw, wDrawLineType_e lt, wDrawColor dc, @@ -419,19 +406,16 @@ void wDrawArc( { int i, cnt; POINT p0, p1, ps, pe, pp0, pp1, pp2, pc; - double psx, psy, pex, pey, len, aa; + wDrawPix_t psx, psy, pex, pey; + double len, aa, ai; RECT rect; int needMoveTo; wBool_t fakeArc = FALSE; - len = a1/360.0 * (2 * M_PI) * r; - if (len < 3) - return; - - p0.x = XINCH2PIX(d,px-r); - p0.y = YINCH2PIX(d,py+r)+1; - p1.x = XINCH2PIX(d,px+r); - p1.y = YINCH2PIX(d,py-r)+1; + p0.x = XDRAWPIX2WINPIX(d,px-r); + p0.y = YDRAWPIX2WINPIX(d,py+r); + p1.x = XDRAWPIX2WINPIX(d,px+r); + p1.y = YDRAWPIX2WINPIX(d,py-r); pex = px + r * mswsin(a0); pey = py + r * mswcos(a0); @@ -440,17 +424,18 @@ void wDrawArc( /*pointOnCircle( &pe, p, r, a0 ); pointOnCircle( &ps, p, r, a0+a1 );*/ - ps.x = XINCH2PIX(d,(wPos_t)psx); - ps.y = YINCH2PIX(d,(wPos_t)psy); - pe.x = XINCH2PIX(d,(wPos_t)pex); - pe.y = YINCH2PIX(d,(wPos_t)pey); + ps.x = XDRAWPIX2WINPIX(d,psx); + ps.y = YDRAWPIX2WINPIX(d,psy); + pe.x = XDRAWPIX2WINPIX(d,pex); + pe.y = YDRAWPIX2WINPIX(d,pey); setDrawMode( d, dw, lt, dc, dopt ); if (dw == 0) dw = 1; - if (r>4096) { + /* Windows drawing will overshoot the end of the arc for large radius */ + if (r > 500) { /* The book says 32K but experience says otherwise */ fakeArc = TRUE; } @@ -459,21 +444,23 @@ void wDrawArc( fakeArc = TRUE; } if ( fakeArc ) { - cnt = (int)a1; + cnt = (int)(a1 / 2); if ( cnt <= 0 ) cnt = 1; - if ( cnt > 360 ) cnt = 360; - aa = a1 / cnt; - psx = px + r * mswsin(a0); - psy = py + r * mswcos(a0); - pp0.x = XINCH2PIX( d, (wPos_t)psx ); - pp0.y = YINCH2PIX( d, (wPos_t)psy ); + if ( cnt > 180 ) cnt = 180; + // Convert a0 and a1 to radians here + 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++ ) { - a0 += aa; - psx = px + r * mswsin(a0); - psy = py + r * mswcos(a0); - pp2.x = pp1.x = XINCH2PIX( d, (wPos_t)psx ); - pp2.y = pp1.y = YINCH2PIX( d, (wPos_t)psy ); + aa += ai; + psx = px + r * sin(aa); + psy = py + r * cos(aa); + pp2.x = pp1.x = XDRAWPIX2WINPIX( d, psx ); + pp2.y = pp1.y = YDRAWPIX2WINPIX( d, psy ); if ( clip0( &pp0, &pp1, d ) ) { if (needMoveTo) { MoveTo( d->hDc, pp0.x, pp0.y ); @@ -487,30 +474,30 @@ void wDrawArc( } } else { if ( a0 == 0.0 && a1 == 360.0 ) { - Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p0.y-1, pe.x, p1.y-1 ); - Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y-1, pe.x, p0.y-1 ); + 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 ); } else { Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, ps.y, pe.x, pe.y ); } } // should the center of the arc be drawn? - if( drawCenter ) { + if( sizeCenter ) { // calculate the center coordinates - pc.x = XINCH2PIX( d, px ); - pc.y = YINCH2PIX( d, py ); + pc.x = XDRAWPIX2WINPIX( d, px ); + pc.y = YDRAWPIX2WINPIX( d, py ); // now draw the crosshair - MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH/2, pc.y ); - LineTo( d->hDc, pc.x + CENTERMARK_LENGTH/2, pc.y ); - MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH/2 ); - LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH/2 ); + 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 / 2 - 1; - rect.bottom = pc.y + CENTERMARK_LENGTH / 2 + 1; - rect.left = pc.x - CENTERMARK_LENGTH / 2 - 1; - rect.right = pc.x + CENTERMARK_LENGTH / 2 + 1; + 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 ); } @@ -544,16 +531,16 @@ void wDrawArc( void wDrawPoint( wDraw_p d, - wPos_t px, - wPos_t py, + wDrawPix_t px, + wDrawPix_t py, wDrawColor dc, wDrawOpts dopt ) { POINT p0; RECT rect; - p0.x = XINCH2PIX(d,px); - p0.y = YINCH2PIX(d,py); + p0.x = XDRAWPIX2WINPIX(d,px); + p0.y = YDRAWPIX2WINPIX(d,py); if ( p0.x < 0 || p0.y < 0 ) return; @@ -707,7 +694,9 @@ void mswFontInit( void ) { const char * face; long size; + /** @prefs [msw window font] face=FontName */ face = wPrefGetString( "msw window font", "face" ); + /** @prefs [msw window font] size=-24 */ wPrefGetInteger( "msw window font", "size", &size, -24 ); if (face) { strncpy( logFont.lfFaceName, face, LF_FACESIZE ); @@ -750,16 +739,16 @@ static int computeFontSize( wDraw_p d, double siz ) } void wDrawGetTextSize( - wPos_t *w, - wPos_t *h, - wPos_t *d, - wPos_t *a, + wDrawPix_t *w, + wDrawPix_t *h, + wDrawPix_t *d, + wDrawPix_t *a, wDraw_p bd, const char * text, wFont_p fp, double siz ) { - int x, y; + wWinPix_t x, y; HFONT newFont, prevFont; DWORD extent; int oldLfHeight; @@ -773,16 +762,16 @@ void wDrawGetTextSize( fp->lfWidth = 0; newFont = CreateFontIndirect( fp ); prevFont = SelectObject( bd->hDc, newFont ); - extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, strlen(text) ); + extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, (int)(strlen(text)) ); GetTextMetrics(bd->hDc, &textMetric); x = LOWORD(extent); y = HIWORD(extent); - *w = XPIXELSTOINCH( bd, x ); - *h = YPIXELSTOINCH( bd, y ); - *d = YPIXELSTOINCH(bd, textMetric.tmDescent ); - *a = YPIXELSTOINCH(bd, textMetric.tmAscent ); + *w = (wDrawPix_t)x; + *h = (wDrawPix_t)y; + *d = (wDrawPix_t)textMetric.tmDescent; + *a = (wDrawPix_t)textMetric.tmAscent; SelectObject( bd->hDc, prevFont ); DeleteObject( newFont ); @@ -803,8 +792,8 @@ void wDrawGetTextSize( */ void wDrawString( wDraw_p d, - wPos_t px, - wPos_t py, + wDrawPix_t px, + wDrawPix_t py, double angle, const char * text, wFont_p fp, @@ -828,8 +817,8 @@ void wDrawString( fp->lfHeight = computeFontSize(d, siz); fp->lfWidth = 0; newFont = CreateFontIndirect(fp); - x = XINCH2PIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5); - y = YINCH2PIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5); + 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); @@ -843,7 +832,7 @@ void wDrawString( if (dopts & wDrawOutlineFont) { HPEN oldPen; BeginPath(d->hDc); - TextOut(d->hDc, x, y, text, strlen(text)); + TextOut(d->hDc, x, y, text, (int)strlen(text)); EndPath(d->hDc); // Now draw outline text @@ -857,11 +846,11 @@ void wDrawString( old = SetTextColor(d->hDc, mswGetColor(d->hasPalette, dc)); - TextOut(d->hDc, x, y, text, strlen(text)); + TextOut(d->hDc, x, y, text, (int)(strlen(text))); SetTextColor(d->hDc, old); } - extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, strlen(text)); + extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text))); SelectObject(d->hDc, prevFont); w = LOWORD(extent); h = HIWORD(extent); @@ -925,10 +914,10 @@ void wSetSelectedFontSize(wFontSize_t size) void wDrawFilledRectangle( wDraw_p d, - wPos_t px, - wPos_t py, - wPos_t sx, - wPos_t sy, + wDrawPix_t px, + wDrawPix_t py, + wDrawPix_t sx, + wDrawPix_t sy, wDrawColor color, wDrawOpts opts ) { @@ -944,10 +933,10 @@ void wDrawFilledRectangle( mode = R2_COPYPEN; } SetROP2(d->hDc, mode); - rect.left = XINCH2PIX(d,px); - rect.right = XINCH2PIX(d,px+sx); - rect.top = YINCH2PIX(d,py+sy); - rect.bottom = YINCH2PIX(d,py); + rect.left = XDRAWPIX2WINPIX(d,px); + rect.right = XDRAWPIX2WINPIX(d,px+sx); + rect.top = YDRAWPIX2WINPIX(d,py+sy); + rect.bottom = YDRAWPIX2WINPIX(d,py); if ( rect.right < 0 || rect.bottom < 0 ) return; @@ -1000,8 +989,8 @@ static void addPoint( BYTE type, RECT * pr) { POINT p; - p.x = XINCH2PIX(d, pp->x); - p.y = YINCH2PIX(d, pp->y); + 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); @@ -1042,7 +1031,7 @@ static void addPoint( void wDrawPolygon( wDraw_p d, - wPos_t node[][2], + wDrawPix_t node[][2], wPolyLine_e type[], wIndex_t cnt, wDrawColor color, @@ -1088,8 +1077,8 @@ void wDrawPolygon( setDrawMode(d, dw, lt, color, opts); } - rect.left = rect.right = XINCH2PIX(d,node[cnt-1][0]-1); - rect.top = rect.bottom = YINCH2PIX(d,node[cnt-1][1]+1); + rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1); + rect.top = rect.bottom = YDRAWPIX2WINPIX(d,node[cnt-1][1]+1); #ifdef DRAWFILLPOLYLOG logF = fopen("log.txt", "a"); @@ -1110,10 +1099,10 @@ void wDrawPolygon( nextNode = (i == cnt - 1) ? 0 : i + 1; // calculate distance to neighboring nodes - int prevXDistance = node[i][0] - node[prevNode][0]; - int prevYDistance = node[i][1] - node[prevNode][1]; - int nextXDistance = node[nextNode][0]-node[i][0]; - int nextYDistance = node[nextNode][1]-node[i][1]; + 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]; @@ -1202,29 +1191,29 @@ void wDrawPolygon( #define MAX_FILLCIRCLE_POINTS (30) void wDrawFilledCircle( wDraw_p d, - wPos_t x, - wPos_t y, - wPos_t r, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t r, wDrawColor color, wDrawOpts opts ) { POINT p0, p1; RECT rect; - static wPos_t circlePts[MAX_FILLCIRCLE_POINTS][2]; + static wDrawPix_t circlePts[MAX_FILLCIRCLE_POINTS][2]; int inx, cnt; double dang; - p0.x = XINCH2PIX(d,x-r); - p0.y = YINCH2PIX(d,y+r)+1; - p1.x = XINCH2PIX(d,x+r); - p1.y = YINCH2PIX(d,y-r)+1; + 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 = r; + cnt = XDRAWPIX2WINPIX(d,r); else cnt = 8; dang = 360.0/cnt; @@ -1308,8 +1297,8 @@ void wDrawClear( wDraw_p d ) void wDrawSetSize( wDraw_p d, - wPos_t width, - wPos_t height, void * redraw) + wWinPix_t width, + wWinPix_t height, void * redraw) { d->w = width; d->h = height; @@ -1323,8 +1312,8 @@ void wDrawSetSize( void wDrawGetSize( wDraw_p d, - wPos_t * width, - wPos_t * height ) + wWinPix_t * width, + wWinPix_t * height ) { *width = d->w-2; *height = d->h-2; @@ -1349,17 +1338,17 @@ double wDrawGetMaxRadius( wDraw_p d ) void wDrawClip( wDraw_p d, - wPos_t x, - wPos_t y, - wPos_t w, - wPos_t h ) + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h ) { - int ix0, iy0, ix1, iy1; + wWinPix_t ix0, iy0, ix1, iy1; HRGN hRgnClip; - ix0 = XINCH2PIX(d,x); - iy0 = YINCH2PIX(d,y); - ix1 = XINCH2PIX(d,x+w); - iy1 = YINCH2PIX(d,y+h); + ix0 = XDRAWPIX2WINPIX(d,x); + iy0 = YDRAWPIX2WINPIX(d,y); + ix1 = XDRAWPIX2WINPIX(d,x+w); + iy1 = YDRAWPIX2WINPIX(d,y+h); /* Note: Ydim is upside down so iy1<iy0 */ hRgnClip = CreateRectRgn( ix0, iy1, ix1, iy0 ); SelectClipRgn( d->hDc, hRgnClip ); @@ -1384,22 +1373,24 @@ void wRedraw( wDraw_p d ) struct wDrawBitMap_t { wDrawBitMap_p next; - wPos_t x; - wPos_t y; - wPos_t w; - wPos_t h; + wDrawPix_t x; + wDrawPix_t y; + wDrawPix_t w; + wDrawPix_t h; char * bmx; wDrawColor color; HBITMAP bm; }; -wDrawBitMap_p bmRoot = NULL; +static wDrawBitMap_p bmRoot = NULL; +extern wDrawColor drawColorWhite; +extern wDrawColor drawColorBlack; void wDrawBitMap( wDraw_p d, wDrawBitMap_p bm, - wPos_t px, - wPos_t py, + wDrawPix_t px, + wDrawPix_t py, wDrawColor dc, wDrawOpts dopt ) { @@ -1409,15 +1400,15 @@ void wDrawBitMap( int x0, y0; RECT rect; - x0 = XINCH2PIX(d,px-bm->x); - y0 = YINCH2PIX(d,py-bm->y+bm->h); + x0 = XDRAWPIX2WINPIX(d,px-bm->x); + y0 = YDRAWPIX2WINPIX(d,py-bm->y+bm->h); #ifdef LATER if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) ) return; #endif - if (dc == wDrawColorWhite) { + if (dc == drawColorWhite) { mode = clrOp; - dc = wDrawColorBlack; + dc = drawColorBlack; } else { mode = setOp; } @@ -1426,21 +1417,21 @@ void wDrawBitMap( if ( bm->bm ) DeleteObject( bm->bm ); bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ), - RGB( 255, 255, 255 ), bm->w, bm->h, bm->bmx ); + RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx ); bm->color = dc; } bmDc = CreateCompatibleDC( d->hDc ); setDrawMode( d, 0, wDrawLineSolid, dc, dopt ); oldBm = SelectObject( bmDc, bm->bm ); - BitBlt( d->hDc, x0, y0, bm->w, bm->h, bmDc, 0, 0, mode ); + BitBlt( d->hDc, x0, y0, (wWinPix_t)bm->w, (wWinPix_t)bm->h, bmDc, 0, 0, mode ); SelectObject( bmDc, oldBm ); DeleteDC( bmDc ); if (d->hWnd) { rect.top = y0-1; - rect.bottom = rect.top+bm->h+1; + rect.bottom = rect.top+ (wWinPix_t)bm->h+1; rect.left = x0-1; - rect.right = rect.left+bm->w+1; + rect.right = rect.left+ (wWinPix_t)bm->w+1; myInvalidateRect( d, &rect ); } } @@ -1484,22 +1475,18 @@ wDrawBitMap_p wDrawBitMapCreate( ***************************************************************************** */ -int doSetFocus = 1; +static int doSetFocus = 1; -long FAR PASCAL XEXPORT mswDrawPush( +LRESULT FAR PASCAL XEXPORT mswDrawPush( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wDraw_p b; - short int ix, iy; - wPos_t x, y; + wWinPix_t ix, iy; + wDrawPix_t x, y; HDC hDc; PAINTSTRUCT ps; wAction_t action; @@ -1529,7 +1516,10 @@ long FAR PASCAL XEXPORT mswDrawPush( } b->wFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSX ); b->hFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSY ); - b->DPI = 96.0; /*min( b->wFactor, b->hFactor );*/ + double dpi; + /** @prefs [Preference] ScreenDPI=96.0 Sets DPI of screen */ + wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); + b->DPI = dpi; b->hWnd = hWnd; SetROP2( b->hDc, R2_WHITE ); Rectangle( b->hDc, 0, 0, b->w, b->h ); @@ -1564,7 +1554,7 @@ long FAR PASCAL XEXPORT mswDrawPush( b->drawResize( b, b->size );*/ if (b->drawRepaint) b->drawRepaint( b, b->data, 0, 0 ); - return 0; + return (LRESULT)0; case WM_MOUSEMOVE: activeWnd = GetActiveWindow(); focusWnd = GetFocus(); @@ -1613,15 +1603,15 @@ long FAR PASCAL XEXPORT mswDrawPush( } ix = LOWORD( lParam ); iy = HIWORD( lParam ); - x = XPIX2INCH( b, ix ); - y = YPIX2INCH( b, iy ); + x = XWINPIX2DRAWPIX( b, ix ); + y = YWINPIX2DRAWPIX( b, iy ); b->lastX = x; b->lastY = y; if (b->action) b->action( b, b->data, action, x, y ); if (b->hWnd) UpdateWindow(b->hWnd); - return 0; + return (LRESULT)0; case WM_CHAR: b = (wDraw_p)mswMapIndex( inx ); extChar = wAccelKey_None; @@ -1655,9 +1645,9 @@ long FAR PASCAL XEXPORT mswDrawPush( if (extChar != wAccelKey_None) b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX, b->lastY ); else - b->action( b, b->data, wActionText + ( wParam << 8 ), b->lastX, b->lastY ); + b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX, b->lastY ); } - return 0; + return (LRESULT)0; case WM_PAINT: b = (wDraw_p)mswMapIndex( inx ); @@ -1740,7 +1730,7 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L } if (b->action) b->action( b, b->data, action, b->lastX, b->lastY ); - return 0; + return (LRESULT)0; case WM_MOUSEHWHEEL: if ( GET_KEYSTATE_WPARAM(wParam) & (MK_SHIFT|MK_MBUTTON)) { if ( GET_WHEEL_DELTA_WPARAM(wParam) > 0 ) { @@ -1751,7 +1741,7 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L } if (b->action) b->action( b, b->data, action, b->lastX, b->lastY ); - return 0; + return (LRESULT)0; } return DefWindowProc( hWnd, message, wParam, lParam ); @@ -1799,7 +1789,7 @@ static callBacks_t drawCallBacks = { drawDoneProc, (messageCallback_p)drawMsgProc }; -wDraw_p drawList = NULL; +static wDraw_p drawList = NULL; void mswRedrawAll( void ) @@ -1841,12 +1831,12 @@ void mswRepaintAll( void ) wDraw_p wDrawCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, long option, - wPos_t w, - wPos_t h, + wWinPix_t w, + wWinPix_t h, void * data, wDrawRedrawCallBack_p redrawProc, wDrawActionCallBack_p action ) @@ -1872,7 +1862,7 @@ wDraw_p wDrawCreate( d->hWnd = CreateWindow( mswDrawWindowClassName, NULL, WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER, d->x, d->y, w, h, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (d->hWnd == (HWND)0) { mswFail( "CreateWindow(DRAW)" ); @@ -1909,7 +1899,7 @@ wDraw_p wDrawCreate( ***************************************************************************** */ -wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes ) +wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int planes ) { wDraw_p d; HDC hDc; @@ -1934,11 +1924,13 @@ wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes ) d->hBmMain = CreateCompatibleBitmap( hDc, d->w, d->h ); if ( d->hBmMain == (HBITMAP)0 ) { wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Main fails", "Ok", NULL ); + ReleaseDC(mswHWnd, hDc); return FALSE; } d->hBmTemp = CreateCompatibleBitmap( hDc, d->w, d->h ); if ( d->hBmTemp == (HBITMAP)0 ) { wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Temp fails", "Ok", NULL ); + ReleaseDC(mswHWnd, hDc); return FALSE; } d->hasPalette = (GetDeviceCaps(hDc,RASTERCAPS ) & RC_PALETTE) != 0; @@ -2043,8 +2035,19 @@ wBitMapWriteFile(wDraw_p d, const char * fileName) } if (bCanSave) { - bSuccess = FreeImage_Save(fif, dib2, fileName, PNG_DEFAULT); - return bSuccess; + int flags; + + switch (fif) { + case FIF_JPEG: + flags = JPEG_QUALITYNORMAL; + break; + case FIF_PNG: + flags = PNG_DEFAULT; + break; + default: + flags = 0; // whatver the default is for the file format + } + bSuccess = FreeImage_Save(fif, dib2, fileName, flags); } } FreeImage_Unload(dib2); diff --git a/app/wlib/mswlib/mswedit.c b/app/wlib/mswlib/mswedit.c index dc70ac3..b6da004 100644 --- a/app/wlib/mswlib/mswedit.c +++ b/app/wlib/mswlib/mswedit.c @@ -35,6 +35,7 @@ struct wString_t { char * valueP; wIndex_t valueL; wStringCallBack_p action; + wBool_t enter_pressed; /**< flag if enter was pressed */ }; #ifdef LATER @@ -58,26 +59,22 @@ struct wFloat_t { static XWNDPROC oldEditProc = NULL; static XWNDPROC newEditProc; -static void triggerString( wControl_p b ); +static void triggerString( wString_p b ); #ifdef LATER static void triggerInteger( wControl_p b ); static void triggerFloat( wControl_p b ); #endif -long FAR PASCAL _export pushEdit( +LRESULT FAR PASCAL _export pushEdit( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif - wControl_p b = mswMapIndex(inx); + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); + wString_p b = (wString_p)mswMapIndex(inx); switch (message) { @@ -86,14 +83,14 @@ long FAR PASCAL _export pushEdit( switch (wParam) { case VK_RETURN: triggerString(b); - return (0L); + 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 0L; + return (LRESULT)0; } } break; @@ -116,25 +113,21 @@ void wStringSetValue( const char * arg ) { WORD len = (WORD)strlen( arg ); - SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)arg ); -#ifdef WIN32 - SendMessage( b->hWnd, EM_SETSEL, 0, -1 ); - SendMessage( b->hWnd, EM_SCROLLCARET, 0, 0L ); -#else - SendMessage( b->hWnd, EM_SETSEL, 0, MAKELPARAM(len,len) ); -#endif - SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L ); + SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)arg ); + SendMessage( b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1 ); + SendMessage( b->hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0 ); + SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 ); } void wStringSetWidth( wString_p b, - wPos_t w ) + 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 ); } @@ -142,7 +135,7 @@ const char * wStringGetValue( wString_p b ) { static char buff[1024]; - SendMessage( b->hWnd, WM_GETTEXT, sizeof buff, (DWORD)buff ); + SendMessage( b->hWnd, WM_GETTEXT, (WPARAM)sizeof buff, (LPARAM)buff ); return buff; } @@ -157,13 +150,17 @@ const char * wStringGetValue( static char *getString(wString_p bs) { char *tmpBuffer = NULL; - UINT chars = SendMessage(bs->hWnd, EM_LINELENGTH, (WPARAM)0, 0L); + 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, 0, (LPARAM)tmpBuffer); + 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); @@ -177,19 +174,21 @@ static char *getString(wString_p bs) */ static void triggerString( - wControl_p b) + wString_p b) { - wString_p bs = (wString_p)b; + const char *output = "\n"; - char *enteredString = getString(bs); + char *enteredString = getString(b); if (enteredString) { - if (bs->valueP) { - strcpy(bs->valueP, enteredString); + if (b->valueP) { + strcpy(b->valueP, enteredString); } - if (bs->action) { - bs->action(enteredString, bs->data); + if (b->action) { + b->enter_pressed = TRUE; + b->action(output, b->data); } + free(enteredString); } } @@ -210,7 +209,7 @@ LRESULT stringProc( case WM_COMMAND: switch (WCMD_PARAM_NOTF) { case EN_KILLFOCUS: - modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, 0, 0L); + modified = (int)SendMessage(bs->hWnd, (UINT)EM_GETMODIFY, (WPARAM)0, (LPARAM)0); if (!modified) { break; } @@ -226,7 +225,7 @@ LRESULT stringProc( } free(enteredString); } - SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, FALSE, 0L); + SendMessage(bs->hWnd, (UINT)EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0); } break; } @@ -243,12 +242,12 @@ static callBacks_t stringCallBacks = { wString_p wStringCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, + wWinPix_t width, char *valueP, wIndex_t valueL, wStringCallBack_p action, @@ -269,34 +268,30 @@ wString_p wStringCreate( if (option & BO_READONLY) style |= ES_READONLY; -#ifdef WIN32 b->hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style, b->x, b->y, width, mswEditHeight, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); -#else - b->hWnd = CreateWindow( "EDIT", NULL, - ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | style, - b->x, b->y, - width, mswEditHeight, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); -#endif + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(STRING)"); return b; } newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); - oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); + oldEditProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); + SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newEditProc); +#ifdef _OLDCODE + oldEditProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWL_WNDPROC ); SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc ); +#endif // WIN64 if (b->valueP) { - SendMessage( b->hWnd, WM_SETTEXT, 0, (DWORD)b->valueP ); + SendMessage( b->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)b->valueP ); } - SendMessage( b->hWnd, EM_SETMODIFY, FALSE, 0L ); + SendMessage( b->hWnd, EM_SETMODIFY, (WPARAM)FALSE, (LPARAM)0 ); if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + 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; @@ -466,12 +461,12 @@ static callBacks_t integerCallBacks = { wInteger_p wIntegerCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, + wWinPix_t width, long low, long high, long *valueP, @@ -504,10 +499,7 @@ wInteger_p wIntegerCreate( return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl( b->hWnd); -#endif - + newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newEditProc ); @@ -690,12 +682,12 @@ static callBacks_t floatCallBacks = { wFloat_p wFloatCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, + wWinPix_t width, double low, double high, double *valueP, @@ -728,9 +720,6 @@ wFloat_p wFloatCreate( return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl( b->hWnd); -#endif newEditProc = MakeProcInstance( (XWNDPROC)pushEdit, mswHInst ); oldEditProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC ); diff --git a/app/wlib/mswlib/mswint.h b/app/wlib/mswlib/mswint.h index e560053..5fd5da9 100644 --- a/app/wlib/mswlib/mswint.h +++ b/app/wlib/mswlib/mswint.h @@ -1,15 +1,31 @@ +/** \file mswint.h + * Windows specific definitions and prototypes for wlib + */ + +/* XTrackCAD - Model Railroad CAD + * Copyright (C) 2005 Dave Bullis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include "wlib.h" #include "mswlib.h" -//#include "dynarr.h" -#include "common.h" -#ifndef WIN32 -/*#define CONTROL3D*/ -#endif -#include "stdio.h" +#include "dynarr.h" -#ifdef CONTROL3D -#include "ctl3d.h" -#endif +#include <FreeImage.h> +#include <stdio.h> #ifdef WIN32 #ifdef FAR @@ -40,39 +56,39 @@ #endif #ifndef CAST_AWAY_CONST - #define CAST_AWAY_CONST (char *) +#define CAST_AWAY_CONST (char *) #endif #define BOOL_T wBool_t -#define POS_T wPos_t #define INDEX_T wIndex_t #define INTEGER_T wInteger_t typedef enum { - W_MAIN, W_POPUP, - B_BUTTON, B_STRING, B_INTEGER, B_FLOAT, - B_LIST, B_DROPLIST, B_COMBOLIST, - B_RADIO, B_TOGGLE, - B_DRAW, B_TEXT, B_MESSAGE, B_LINES, - B_MENUITEM, B_CHOICEITEM, B_BOX, - B_BITMAP } wType_e; - -typedef void (*repaintProcCallback_p)( HWND, wControl_p ); -typedef void (*doneProcCallback_p)( wControl_p b ); -typedef LRESULT (*messageCallback_p)( wControl_p, HWND, UINT, WPARAM, LPARAM ); -typedef void (*setTriggerCallback_p)( wControl_p b ); -typedef void (*setBusyCallback_p)( wControl_p, BOOL_T ); -typedef void (*showCallback_p)( wControl_p, BOOL_T ); -typedef void (*setPosCallback_p)( wControl_p, wPos_t, wPos_t ); + W_MAIN, W_POPUP, + B_BUTTON, B_STRING, B_INTEGER, B_FLOAT, + B_LIST, B_DROPLIST, B_COMBOLIST, + B_RADIO, B_TOGGLE, + B_DRAW, B_TEXT, B_MESSAGE, B_LINES, + B_MENUITEM, B_CHOICEITEM, B_BOX, + B_BITMAP +} wType_e; + +typedef void ( *repaintProcCallback_p )( HWND, wControl_p ); +typedef void ( *doneProcCallback_p )( wControl_p b ); +typedef LRESULT( *messageCallback_p )( wControl_p, HWND, UINT, WPARAM, LPARAM ); +typedef void ( *setTriggerCallback_p )( wControl_p b ); +typedef void ( *setBusyCallback_p )( wControl_p, BOOL_T ); +typedef void ( *showCallback_p )( wControl_p, BOOL_T ); +typedef void ( *setPosCallback_p )( wControl_p, wWinPix_t, wWinPix_t ); typedef struct { - repaintProcCallback_p repaintProc; - doneProcCallback_p doneProc; - messageCallback_p messageProc; - setBusyCallback_p setBusyProc; - showCallback_p showProc; - setPosCallback_p setPosProc; - } callBacks_t; + repaintProcCallback_p repaintProc; + doneProcCallback_p doneProc; + messageCallback_p messageProc; + setBusyCallback_p setBusyProc; + showCallback_p showProc; + setPosCallback_p setPosProc; +} callBacks_t; #define CALLBACK_CNT (B_BOX+1) extern callBacks_t *mswCallBacks[CALLBACK_CNT]; @@ -83,67 +99,68 @@ extern callBacks_t *mswCallBacks[CALLBACK_CNT]; wControl_p next; \ wControl_p synonym; \ wWin_p parent; \ - POS_T x, y; \ - POS_T w, h; \ + wWinPix_t x, y; \ + wWinPix_t w, h; \ long option; \ - POS_T labelX, labelY; \ + wWinPix_t labelX, labelY; \ const char * labelStr; \ const char * helpStr; \ const char * tipStr; \ + char * errStr; \ HWND hWnd; \ void * data;\ wControl_p focusChainNext; \ - wBool_t shown; + wBool_t shown; \ + wBool_t hilite; struct wControl_t { - WOBJ_COMMON - }; + WOBJ_COMMON +}; typedef struct { - unsigned key; - wDrawColor color; - } wIconColorMap_t; + unsigned key; + wDrawColor color; +} wIconColorMap_t; #define mswIcon_bitmap (1) #define mswIcon_pixmap (2) struct wIcon_t { - int type; - wPos_t w; /**< width */ - wPos_t h; /**< height */ - wDrawColor color; - int colorcnt; /**< number of colors */ - RGBQUAD *colormap; - char *pixels; /**< pointer to pixel information */ - int transparent; /**< index of transparent color */ - }; + int type; + wWinPix_t w; /**< width */ + wWinPix_t h; /**< height */ + wDrawColor color; + int colorcnt; /**< number of colors */ + RGBQUAD *colormap; + char *pixels; /**< pointer to pixel information */ + int transparent; /**< index of transparent color */ +}; struct wDraw_t { - WOBJ_COMMON - HDC hDc; - double wFactor; - double hFactor; - double DPI; - wDrawRedrawCallBack_p drawRepaint; - wDrawActionCallBack_p action; - HBITMAP hBmMain; - HBITMAP hBmTemp; - HBITMAP hBmOld; - HPEN hPen; - HBRUSH hBrush; - wDraw_p drawNext; - wBool_t hasPalette; - int paletteClock; - HBITMAP hBmBackup; - HDC hDcBackup; - HBITMAP hBmBackupOld; - void *background; - wBool_t bTempMode; - wBool_t bCopiedMain; - - wPos_t lastX; - wPos_t lastY; - - }; + WOBJ_COMMON + HDC hDc; + double wFactor; + double hFactor; + double DPI; + wDrawRedrawCallBack_p drawRepaint; + wDrawActionCallBack_p action; + HBITMAP hBmMain; + HBITMAP hBmTemp; + HBITMAP hBmOld; + HPEN hPen; + HBRUSH hBrush; + wDraw_p drawNext; + wBool_t hasPalette; + int paletteClock; + HBITMAP hBmBackup; + HDC hDcBackup; + HBITMAP hBmBackupOld; + FIBITMAP *background; + wBool_t bTempMode; + wBool_t bCopiedMain; + wDrawPix_t lastX; + wDrawPix_t lastY; + +}; extern HINSTANCE mswHInst; extern char mswTmpBuff[1024]; @@ -168,7 +185,7 @@ void mswResize( wWin_p ); wControl_p mswMapIndex( INDEX_T ); void mswButtPush( wControl_p ); void * mswAlloc( wWin_p, wType_e, const char *, int, void *, int * ); -void mswComputePos( wControl_p, wPos_t, wPos_t ); +void mswComputePos( wControl_p, wWinPix_t, wWinPix_t ); void mswAddButton( wControl_p, BOOL_T, const char * ); void mswRepaintLabel( HWND, wControl_p ); int mswRegister( wControl_p ); @@ -178,7 +195,7 @@ void mswSetFocus( wControl_p ); void mswSetTrigger( wControl_p, setTriggerCallback_p ); void mswMenuPush( wControl_p ); void mswCreateCheckBitmaps( void ); -long FAR PASCAL XEXPORT mswDrawPush( HWND, UINT, UINT, LONG ); +LRESULT FAR PASCAL XEXPORT mswDrawPush( HWND, UINT, WPARAM, LPARAM ); #ifdef WIN32 DWORD GetTextExtent( HDC, CHAR *, UINT ); #endif @@ -186,7 +203,7 @@ void mswRedrawAll( void ); void mswRepaintAll( void ); HDC mswGetPrinterDC( void ); int mswMenuAccelerator( wWin_p, long ); -void mswMenuMove( wMenu_p, wPos_t, wPos_t ); +void mswMenuMove( wMenu_p, wWinPix_t, wWinPix_t ); void mswRegisterBitMap( HBITMAP ); void mswFontInit( void ); void mswInitColorPalette( void ); @@ -202,5 +219,5 @@ void deleteBitmaps( void ); void mswDrawIcon( HDC, int, int, wIcon_p, int, COLORREF, COLORREF ); /* gwin32.c*/ -char *g_win32_getlocale (void); +char *g_win32_getlocale( void ); diff --git a/app/wlib/mswlib/mswlines.c b/app/wlib/mswlib/mswlines.c index be1330d..f6bb574 100644 --- a/app/wlib/mswlib/mswlines.c +++ b/app/wlib/mswlib/mswlines.c @@ -58,7 +58,7 @@ wLine_p wLineCreate( { wLine_p b; wLines_p lp; - POS_T minX, maxX, minY, maxY; + wWinPix_t minX, maxX, minY, maxY; int index; if (count <= 0) diff --git a/app/wlib/mswlib/mswlist.c b/app/wlib/mswlib/mswlist.c index 95ecec3..836f4f0 100644 --- a/app/wlib/mswlib/mswlist.c +++ b/app/wlib/mswlib/mswlist.c @@ -27,16 +27,16 @@ struct wList_t { wListCallBack_p action; wBool_t editable; int colCnt; - wPos_t * colWidths; + wWinPix_t * colWidths; wBool_t * colRightJust; const char * * colTitles; - wPos_t maxWidth; - wPos_t scrollPos; + wWinPix_t maxWidth; + wWinPix_t scrollPos; HWND hScrollWnd; - wPos_t scrollH; - wPos_t dragPos; + wWinPix_t scrollH; + wWinPix_t dragPos; int dragCol; - wPos_t dragColWidth; + wWinPix_t dragColWidth; }; @@ -58,18 +58,18 @@ void wListClear( msg = LB_RESETCONTENT; else msg = CB_RESETCONTENT; - SendMessage( b->hWnd, msg, 0, 0 ); + SendMessage( b->hWnd, msg, (WPARAM)0, (LPARAM)0 ); b->last = -1; b->count = 0; } -void wListSetSize( wList_p bl, wPos_t w, wPos_t h ) +void wListSetSize( wList_p bl, wWinPix_t w, wWinPix_t h ) { int rc; RECT rect; - wPos_t y; + wWinPix_t y; bl->w = w; bl->h = h; @@ -109,24 +109,24 @@ void wListSetIndex( return; if ( bl->type==B_LIST && (bl->option&BL_MANY) != 0 ) { if ( bl->last != -1 ) - SendMessage( bl->hWnd, LB_SETSEL, 0, MAKELPARAM(bl->last,0) ); + SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)0, (LPARAM)bl->last ); if ( index >= 0 ) - SendMessage( bl->hWnd, LB_SETSEL, 1, MAKELPARAM(index, 0) ); + SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)1, (LPARAM)index ); } else { SendMessage( bl->hWnd, - bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, index, 0 ); + bl->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)index, (LPARAM)0 ); } if ( bl->last >= 0 ) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); if ( ldp && ldp!=(void*)LB_ERR ) ldp->selected = FALSE; } if ( index >= 0 ) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - index, 0L ); + (WPARAM)index, (LPARAM)0 ); if ( ldp && ldp!=(void*)LB_ERR ) ldp->selected = TRUE; } @@ -164,7 +164,7 @@ void wListSetValue( const char * val ) { if ( bl->type == B_DROPLIST ) { - SendMessage( bl->hWnd, WM_SETTEXT, 0, (DWORD)(LPSTR)val ); + SendMessage( bl->hWnd, WM_SETTEXT, (WPARAM)0, (LPARAM)val ); bl->last = -1; } } @@ -179,8 +179,8 @@ wIndex_t wListFindValue( wListGetCount(bl); for ( inx = 0; inx < bl->count ; inx++ ) { cnt = (int)SendMessage( bl->hWnd, - (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), inx, - (DWORD)(LPSTR)mswTmpBuff ); + (bl->type==B_LIST?LB_GETTEXT:CB_GETLBTEXT), (WPARAM)inx, + (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if ( strcmp( val, mswTmpBuff ) == 0 ) return inx; @@ -212,7 +212,7 @@ wIndex_t wListGetValues( msg = CB_GETLBTEXT; } } - cnt = (int)SendMessage( bl->hWnd, msg, inx, (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, msg, (WPARAM)inx, (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if (s) { strncpy(s, mswTmpBuff, siz); @@ -221,7 +221,7 @@ wIndex_t wListGetValues( if (bl->last >= 0) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); if ( ldp==(listData*)LB_ERR ) ldp = NULL; } else { @@ -252,24 +252,24 @@ wBool_t wListSetValues( curSel = (WORD)SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_GETCURSEL:CB_GETCURSEL, (WPARAM)0, - (DWORD)0L ); + (LPARAM)0 ); SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, (WPARAM)inx, - (DWORD)0L ); + (LPARAM)0 ); inx = (wIndex_t)SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_INSERTSTRING:CB_INSERTSTRING, (WPARAM)inx, - (DWORD)(LPSTR)labelStr ); + (LPARAM)labelStr ); SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, (WPARAM)inx, - (DWORD)ldp ); + (LPARAM)ldp ); if ( (b->option&BL_MANY) == 0 && curSel == (WORD)inx) SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)inx, - (DWORD)0L ); + (LPARAM)0 ); /*if (b->option&BL_ICON)*/ InvalidateRect( b->hWnd, NULL, FALSE ); return TRUE; @@ -283,7 +283,7 @@ void wListDelete( SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_DELETESTRING:CB_DELETESTRING, (WPARAM)inx, - (DWORD)0L ); + (LPARAM)0 ); } @@ -303,19 +303,19 @@ void wListSelectAll( wList_p bl ) SendMessage( bl->hWnd, LB_SETSEL, (WPARAM)TRUE, - (DWORD)-1L ); + (LPARAM)-1 ); // and synchronize the internal data structures wListGetCount(bl); for ( inx=0; inx<bl->count; inx++ ) { ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - inx, 0L ); + (WPARAM)inx, (LPARAM)0 ); ldp->selected = TRUE; SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, (WPARAM)inx, - (DWORD)ldp ); + (LPARAM)ldp ); } } @@ -323,7 +323,7 @@ void wListSelectAll( wList_p bl ) wIndex_t wListGetCount( wList_p bl ) { - bl->count = (int)SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, 0, 0L ); + bl->count = (int)SendMessage( bl->hWnd, (UINT)bl->type==B_LIST?LB_GETCOUNT:CB_GETCOUNT, (WPARAM)0, (LPARAM)0 ); return bl->count; } @@ -337,7 +337,7 @@ void * wListGetItemContext( if ( inx < 0 || inx >= bl->count ) return NULL; ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - inx, 0L ); + (WPARAM)inx, (LPARAM)0 ); return ((ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL); } @@ -351,7 +351,7 @@ wBool_t wListGetItemSelected( if ( inx < 0 || inx >= bl->count ) return FALSE; ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - inx, 0L ); + (WPARAM)inx, (LPARAM)0 ); return ((ldp&&ldp!=(void*)LB_ERR)?ldp->selected:FALSE); } @@ -389,18 +389,18 @@ wIndex_t wListAddValue( b->hWnd, (UINT)b->type==B_LIST?LB_ADDSTRING:CB_ADDSTRING, (WPARAM)0, - (DWORD)value ); + (LPARAM)value ); if (nindex == 0) { SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETCURSEL:CB_SETCURSEL, (WPARAM)nindex, - (DWORD)0 ); + (LPARAM)0 ); b->last = 0; } SendMessage( b->hWnd, (UINT)b->type==B_LIST?LB_SETITEMDATA:CB_SETITEMDATA, (WPARAM)nindex, - (DWORD)ldp ); + (LPARAM)ldp ); return nindex; } @@ -408,7 +408,7 @@ wIndex_t wListAddValue( int wListGetColumnWidths( wList_p bl, int colCnt, - wPos_t * colWidths ) + wWinPix_t * colWidths ) { wIndex_t inx; @@ -454,11 +454,11 @@ static void listShow( static void listSetPos( wControl_p b, - wPos_t x, - wPos_t y ) + wWinPix_t x, + wWinPix_t y ) { wList_p bl = (wList_p)b; - wPos_t x1, y1; + wWinPix_t x1, y1; RECT rect; bl->x = x1 = x; @@ -492,7 +492,7 @@ static void listRepaintLabel( const char * * title; int inx; int start; - wPos_t colWidth; + wWinPix_t colWidth; mswRepaintLabel( hWnd, b ); if ( bl->colTitles == NULL ) @@ -538,7 +538,7 @@ static void listRepaintLabel( rc.right = bl->x+bl->w-1; ExtTextOut( hDc, start+1, rc.top+0, ETO_CLIPPED|ETO_OPAQUE, &rc, - *title, strlen(*title), NULL ); + *title, (int)(strlen(*title)), NULL ); if ( start-bl->x >= 3 ) { SelectObject( hDc, hPen1 ); MoveTo( hDc, start-1, rc.top-1 ); @@ -589,7 +589,7 @@ LRESULT listProc( { wList_p bl = (wList_p)b; int cnt, inx, selected; - long len; + size_t len; listData * ldp; HDC hDc; LPMEASUREITEMSTRUCT lpmis; @@ -597,7 +597,8 @@ LRESULT listProc( LPDRAWITEMSTRUCT lpdis; RECT rc, rc1; char * cp0, * cp1; - wPos_t colWidth, x; + wWinPix_t x; + int colWidth; int nPos; HFONT hFont; HPEN hPen; @@ -621,14 +622,14 @@ LRESULT listProc( if ( (bl->option&BL_MANY) ) { wListGetCount(bl); for ( inx=0; inx<bl->count; inx++ ) { - ldp = (listData*)SendMessage( bl->hWnd, LB_GETITEMDATA, inx, 0L ); + 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, inx, 0L ) != 0L ); + 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, bl->last, (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, (WPARAM)bl->last, (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; } else { mswTmpBuff[0] = '\0'; @@ -641,13 +642,13 @@ LRESULT listProc( } } } else { - bl->last = (int)SendMessage( bl->hWnd, LB_GETCURSEL, 0, 0L ); - cnt = (int)SendMessage( bl->hWnd, LB_GETTEXT, bl->last, - (DWORD)(LPSTR)mswTmpBuff ); + 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, - bl->last, 0L ); + (WPARAM)bl->last, (LPARAM)0 ); bl->action( bl->last, mswTmpBuff, 1, bl->data, ((bl->last>=0&&ldp&&ldp!=(void*)LB_ERR)?ldp->itemContext:NULL) ); } @@ -659,8 +660,8 @@ LRESULT listProc( case LBN_KILLFOCUS: if ( ( bl->option&BL_MANY ) == 0 && - bl->last != (int)SendMessage( bl->hWnd, LB_GETCURSEL, 0, 0L ) ) - (void)SendMessage( bl->hWnd, LB_SETCURSEL, bl->last, 0L ); + 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; @@ -677,14 +678,14 @@ LRESULT listProc( break; case CBN_CLOSEUP: - bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, 0, 0L ); + bl->last = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); if (bl->last < 0) break; if (bl->action) { - cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT, bl->last, - (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, CB_GETLBTEXT, + (WPARAM)bl->last, (LPARAM)mswTmpBuff ); ldp = (listData*)SendMessage( bl->hWnd, CB_GETITEMDATA, - bl->last, 0L ); + (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) ); @@ -697,9 +698,9 @@ LRESULT listProc( break; case CBN_KILLFOCUS: - inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, 0, 0L ); + inx = (int)SendMessage( bl->hWnd, CB_GETCURSEL, (WPARAM)0, (LPARAM)0 ); if ( bl->last != inx ) - (void)SendMessage( bl->hWnd, CB_SETCURSEL, bl->last, 0L ); + (void)SendMessage( bl->hWnd, CB_SETCURSEL, (WPARAM)bl->last, (LPARAM)0 ); break; case CBN_DROPDOWN: @@ -709,8 +710,8 @@ LRESULT listProc( case CBN_EDITCHANGE: bl->last = -1; if (bl->action) { - cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, sizeof mswTmpBuff, - (DWORD)(LPSTR)mswTmpBuff ); + cnt = (int)SendMessage( bl->hWnd, WM_GETTEXT, (WPARAM)sizeof mswTmpBuff, + (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; bl->action( -1, mswTmpBuff, 1, bl->data, NULL ); } @@ -740,14 +741,14 @@ LRESULT listProc( } ldp = (listData*)SendMessage( bl->hWnd, (bl->type==B_LIST?LB_GETITEMDATA:CB_GETITEMDATA), - lpdis->itemID, 0L ); + (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), - lpdis->itemID, (LONG)(LPSTR)mswTmpBuff ); + (WPARAM)lpdis->itemID, (LPARAM)mswTmpBuff ); mswTmpBuff[cnt] = '\0'; if ( lpdis->itemState & ODS_SELECTED ) { SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); @@ -809,7 +810,7 @@ LRESULT listProc( } if ( bl->type == B_LIST) SelectObject( lpdis->hDC, hFont ); - return TRUE; + return (LRESULT)TRUE; } break; @@ -817,17 +818,17 @@ LRESULT listProc( case WM_HSCROLL: len = ((long)bl->maxWidth)-((long)bl->w); if ( len <= 0 ) - return 0; + return (LRESULT)0; switch ( WSCROLL_PARAM_CODE ) { case SB_LEFT: if ( bl->scrollPos == 0 ) - return 0; + return (LRESULT)0; bl->scrollPos = 0; break; case SB_LINELEFT: case SB_PAGELEFT: if ( bl->scrollPos == 0 ) - return 0; + return (LRESULT)0; for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { if ( colWidth+bl->colWidths[inx] >= bl->scrollPos ) { bl->scrollPos = colWidth; @@ -839,7 +840,7 @@ LRESULT listProc( case SB_LINERIGHT: case SB_PAGERIGHT: if ( bl->scrollPos >= len ) - return 0; + return (LRESULT)0; for ( inx=colWidth=0; inx<bl->colCnt; inx++ ) { if ( colWidth >= bl->scrollPos ) { bl->scrollPos = colWidth+bl->colWidths[inx]; @@ -850,17 +851,17 @@ LRESULT listProc( break; case SB_RIGHT: if ( bl->scrollPos >= len ) - return 0; + return (LRESULT)0; bl->scrollPos = (int)len; break; case SB_THUMBTRACK: - return 0; + return (LRESULT)0; case SB_THUMBPOSITION: nPos = (int)WSCROLL_PARAM_NPOS; bl->scrollPos = (int)(len*nPos/100); break; case SB_ENDSCROLL: - return 0; + return (LRESULT)0; } if ( bl->scrollPos > len ) bl->scrollPos = (int)len; if ( bl->scrollPos < 0 ) bl->scrollPos = 0; @@ -868,7 +869,7 @@ LRESULT listProc( SetScrollPos( bl->hScrollWnd, SB_CTL, nPos, TRUE ); InvalidateRect( bl->hWnd, NULL, FALSE ); listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); - return 0; + return (LRESULT)0; case WM_LBUTTONDOWN: if ( bl->type != B_LIST ) @@ -886,7 +887,7 @@ LRESULT listProc( } if ( bl->dragCol >= 0 ) bl->dragColWidth = bl->colWidths[inx]; - return 0L; + return (LRESULT)0; #ifdef LATER case WM_MOUSEMOVE: @@ -902,7 +903,7 @@ LRESULT listProc( if ( x <= 0 ) break; } - return 0L; + return (LRESULT)0; #endif case WM_MOUSEMOVE: @@ -933,26 +934,26 @@ LRESULT listProc( } InvalidateRect( bl->hWnd, NULL, FALSE ); listRepaintLabel( ((wControl_p)(bl->parent))->hWnd, (wControl_p)bl ); - return 0L; + return (LRESULT)0; } return DefWindowProc( hWnd, message, wParam, lParam ); } -long FAR PASCAL _export pushList( +LRESULT FAR PASCAL _export pushList( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 + wIndex_t inx = (wIndex_t)GetWindowLongPtr(hWnd, GWL_ID); + wControl_p b = mswMapIndex(inx); +#ifdef OLDCODE long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif wControl_p b = mswMapIndex( inx ); +#endif switch (message) { case WM_CHAR: @@ -966,7 +967,7 @@ long FAR PASCAL _export pushList( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LRESULT)0; } } break; @@ -974,18 +975,14 @@ long FAR PASCAL _export pushList( return CallWindowProc( oldListProc, hWnd, message, wParam, lParam ); } -long FAR PASCAL _export pushCombo( +LRESULT FAR PASCAL _export pushCombo( HWND hWnd, UINT message, - UINT wParam, - LONG lParam ) + WPARAM wParam, + LPARAM lParam ) { /* Catch <Return> and cause focus to leave control */ -#ifdef WIN32 - long inx = GetWindowLong( hWnd, GWL_ID ); -#else - short inx = GetWindowWord( hWnd, GWW_ID ); -#endif + wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID ); wControl_p b = mswMapIndex( inx ); switch (message) { @@ -1000,7 +997,7 @@ long FAR PASCAL _export pushCombo( wParam, lParam ); /*SendMessage( ((wControl_p)(b->parent))->hWnd, WM_COMMAND, inx, MAKELONG( hWnd, EN_KILLFOCUS ) );*/ - return 0L; + return (LRESULT)0; } } break; @@ -1022,13 +1019,13 @@ static wList_p listCreate( const char *className, long style, wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data, @@ -1056,16 +1053,12 @@ static wList_p listCreate( b->hWnd = CreateWindow( className, NULL, style | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), b->x, b->y, width, LIST_HEIGHT*(int)number, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL ); if (b->hWnd == NULL) { mswFail("CreateWindow(LIST)"); return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl( b->hWnd ); -#endif - GetWindowRect( b->hWnd, &rect ); b->w = rect.right - rect.left; b->h = rect.bottom - rect.top; @@ -1078,34 +1071,43 @@ static wList_p listCreate( if (addFocus) { mswChainFocus( (wControl_p)b ); if (b->type == B_LIST) { - newListProc = MakeProcInstance( (XWNDPROC)pushList, mswHInst ); - oldListProc = (XWNDPROC)GetWindowLong( b->hWnd, GWL_WNDPROC ); - SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newListProc ); - } else { - newComboProc = MakeProcInstance( (XWNDPROC)pushCombo, mswHInst ); - oldComboProc = (XWNDPROC)GetWindowLong( b->hWnd, GWL_WNDPROC ); - SetWindowLong( b->hWnd, GWL_WNDPROC, (LONG)newComboProc ); + newListProc = MakeProcInstance((XWNDPROC)pushList, mswHInst); + oldListProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); + SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newListProc); +#ifdef _OLDCODE + oldListProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC); + SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newListProc); +#endif + } + else { + newComboProc = MakeProcInstance((XWNDPROC)pushCombo, mswHInst); + oldComboProc = (XWNDPROC)GetWindowLongPtr(b->hWnd, GWLP_WNDPROC); + SetWindowLongPtr(b->hWnd, GWLP_WNDPROC, (LONG_PTR)newComboProc); +#ifdef _OLDCODE + oldComboProc = (XWNDPROC)GetWindowLong(b->hWnd, GWL_WNDPROC); + SetWindowLong(b->hWnd, GWL_WNDPROC, (LONG)newComboProc); +#endif } } if ( indexR ) *indexR = index; if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); + SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0 ); return b; } wList_p wListCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, int colCnt, - wPos_t * colWidths, + wWinPix_t * colWidths, wBool_t * colRightJust, const char * * colTitles, long *valueP, @@ -1138,7 +1140,7 @@ wList_p wListCreate( } if ( colCnt > 1 ) { bl->colCnt = colCnt; - bl->colWidths = (int*)malloc( colCnt * sizeof *bl->colWidths ); + bl->colWidths = (wWinPix_t*)malloc( colCnt * sizeof *bl->colWidths ); bl->colRightJust = (wBool_t*)malloc( colCnt * sizeof *bl->colRightJust ); bl->colTitles = colTitles; bl->maxWidth = 0; @@ -1150,7 +1152,7 @@ wList_p wListCreate( bl->hScrollWnd = CreateWindow( "ScrollBar", NULL, SBS_HORZ | SBS_BOTTOMALIGN | WS_CHILD | WS_VISIBLE | mswGetBaseStyle(parent), bl->x, bl->y, width, CW_USEDEFAULT, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); + ((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 ); @@ -1163,13 +1165,13 @@ wList_p wListCreate( wList_p wDropListCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data ) @@ -1189,13 +1191,13 @@ wList_p wDropListCreate( wList_p wComboListCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, long number, - POS_T width, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data ) diff --git a/app/wlib/mswlib/mswmenu.c b/app/wlib/mswlib/mswmenu.c index d56e24d..9e36c8b 100644 --- a/app/wlib/mswlib/mswmenu.c +++ b/app/wlib/mswlib/mswmenu.c @@ -31,7 +31,6 @@ #include <math.h> #include <ctype.h> #include <assert.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" @@ -94,7 +93,7 @@ struct wMenuRadio_t { struct wMenuToggle_t { MOBJ_COMMON wMenu_p mparent; - wMenuToggleCallBack_p action; + wMenuCallBack_p action; long acclKey; wBool_t enabled; }; @@ -174,7 +173,7 @@ static LRESULT menuPush( set = !set; wMenuToggleSet((wMenuToggle_p)m,set); if (((wMenuToggle_p)m)->action) - ((wMenuToggle_p)m)->action(set, ((wMenuPush_p)m)->data); + ((wMenuToggle_p)m)->action(((wMenuPush_p)m)->data); break; case M_LISTITEM: if (((wMenuListItem_p)m)->action) @@ -185,7 +184,7 @@ static LRESULT menuPush( ((wMenuRadio_p)m)->action(((wMenuRadio_p)m)->data); break; } - return 0L; + return (LRESULT)0; } if ( (m->parentMenu)->traceFunc ) { (m->parentMenu)->traceFunc( m->parentMenu, m->labelStr, ((wMenu_p)m->parentMenu)->traceData ); @@ -261,7 +260,7 @@ typedef struct { wAccelKey_e key; void * data; } acclTable_t, *acclTable_p; -dynArr_t acclTable_da; +static dynArr_t acclTable_da; #define acclTable(N) DYNARR_N( acclTable_t, acclTable_da, N ) @@ -364,7 +363,8 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) 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 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. */ @@ -383,6 +383,7 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); + wMenuH = GetSystemMetrics(SM_CYMENU); hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, wBitmapY); @@ -428,11 +429,11 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) case RADIOCHECK: rc.left = (bmCheckbox.bmWidth / 4); rc.right = (bmCheckbox.bmWidth / 4) * 2; - rc.top = (bmCheckbox.bmHeight / 3) + 1; + rc.top = (bmCheckbox.bmHeight / 3); rc.bottom = (bmCheckbox.bmHeight / 3) * 2; break; case RADIOUNCHECK: - rc.top = (bmCheckbox.bmHeight / 3) + 1; + rc.top = (bmCheckbox.bmHeight / 3); rc.bottom = (bmCheckbox.bmHeight / 3) * 2; rc.left = 0; rc.right = (bmCheckbox.bmWidth / 4); @@ -444,7 +445,6 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) 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)) { @@ -455,7 +455,9 @@ HBITMAP GetMyCheckBitmaps(UINT fuCheck) else { - BitBlt(hdcTarget, 0, 0, rc.right - rc.left, + // 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); } @@ -655,7 +657,7 @@ wMenu_p wMenuMenuCreate( /*mm->parent = (wControl_p)m;*/ mm->first = mm->last = NULL; - rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT)mm->menu, mm->labelStr ); + rc = AppendMenu( m->menu, MF_STRING|MF_ENABLED|MF_POPUP, (UINT_PTR)(mm->menu), mm->labelStr ); return mm; } @@ -857,7 +859,7 @@ wMenuToggle_p wMenuToggleCreate( const char * labelStr, long acclKey, wBool_t set, - wMenuToggleCallBack_p action, + wMenuCallBack_p action, void * data ) { wMenuToggle_p mt; @@ -958,8 +960,8 @@ void wMenuToggleEnable( void mswMenuMove( wMenu_p m, - wPos_t x, - wPos_t y ) + wWinPix_t x, + wWinPix_t y ) { wControl_p b; b = (wControl_p)m->parent; @@ -985,8 +987,8 @@ static void pushMenuButt( wMenu_p wMenuCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option ) @@ -1041,7 +1043,7 @@ wMenu_p wMenuBarAdd( m->mmtype = MM_BAR; m->first = m->last = NULL; - rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT)m->menu, labelStr ); + rc = AppendMenu( menu, MF_STRING|MF_POPUP|MF_ENABLED, (UINT_PTR)(m->menu), labelStr ); DrawMenuBar( ((wControl_p)w)->hWnd ); return m; @@ -1118,7 +1120,7 @@ wBool_t wMenuAction( } else { set = wMenuToggleGet( mt ); wMenuToggleSet( mt, !set ); - mt->action( set, mt->data ); + mt->action( mt->data ); } break; case M_MENU: diff --git a/app/wlib/mswlib/mswmisc.c b/app/wlib/mswlib/mswmisc.c index 6b5f1c9..5b45e2b 100644 --- a/app/wlib/mswlib/mswmisc.c +++ b/app/wlib/mswlib/mswmisc.c @@ -31,7 +31,6 @@ #include <stdio.h> #include <assert.h> #include <htmlhelp.h> -#include "misc.h" #include "mswint.h" #include "i18n.h" #include "FreeImage.h" @@ -45,6 +44,7 @@ #define OFN_LONGFILENAMES 0x00200000L char * mswStrdup(const char *); +const char * GetCurCommandName(void); #define PAUSE_TIMER (901) #define ALARM_TIMER (902) @@ -69,7 +69,6 @@ char * mswStrdup(const char *); * EXPORTED VARIABLES */ -long debugWindow = 0; HINSTANCE mswHInst; HWND mswHWnd = (HWND)0; @@ -77,18 +76,26 @@ const char *mswDrawWindowClassName = "DRAWWINDOW"; char mswTmpBuff[1024]; int mswEditHeight; int mswAllowBalloonHelp = TRUE; -int mswGroupStyle; HFONT mswOldTextFont; HFONT mswLabelFont; +/** @prefs [msw tweak] ThickFont=1 */ long mswThickFont = 1; double mswScale = 1.0; -double scaleIcon = 1.0; /**< Scaling factor for toolbar icons */ +/** @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(void); +void closeBalloonHelp(int inx); static wControl_p getControlFromCursor(HWND, wWin_p *); + +#ifdef BALLOON_TRACE +// To use: +// change logFile defn in lprintf.c from static to EXPORT +// Run with some debug flag set to ensure logFile is set +extern FILE * logFile; +#endif /* * LOCAL VARIABLES */ @@ -100,14 +107,14 @@ struct wWin_t { int max_width; int min_height; int max_height; - wPos_t lastX, lastY; - wPos_t padX, padY; + wWinPix_t lastX, lastY; + wWinPix_t padX, padY; wControl_p first, last; wWinCallBack_p winProc; BOOL_T busy; #ifdef OWNERICON HBITMAP wicon_bm; - wPos_t wicon_w, wicon_h; + wWinPix_t wicon_w, wicon_h; #endif DWORD baseStyle; wControl_p focusChainFirst; @@ -131,15 +138,15 @@ static int mResizeBorderH; static int mMenuH; static int screenWidth = 0, screenHeight = 0; -wWin_p mswWin = NULL; -wWin_p winFirst, winLast; +static wWin_p mswWin = NULL; +static wWin_p winFirst, winLast; static long count51 = 0; -static UINT alarmTimer; -static UINT pauseTimer; -static UINT balloonHelpTimer = (UINT)0; -static UINT triggerTimer; +static UINT_PTR alarmTimer; +static UINT_PTR pauseTimer; +static UINT_PTR balloonHelpTimer = (UINT_PTR)0; +static UINT_PTR triggerTimer; static UINT balloonHelpTimeOut = 500; static wControl_p balloonHelpButton = NULL; @@ -160,7 +167,7 @@ static DWORD dwCookie; typedef struct { wControl_p b; } controlMap_t; -dynArr_t controlMap_da; +static dynArr_t controlMap_da; #define controlMap(N) DYNARR_N(controlMap_t,controlMap_da,N) @@ -177,8 +184,6 @@ static FILE * helpStrF; #endif static int inMainWndProc = FALSE; -int newHelp = 1; - static wBool_t mswWinBlockEnabled = TRUE; static FILE * dumpControlsF; @@ -187,7 +192,7 @@ static int dumpControls; extern char *userLocale; // list of supported fileformats for image files -char * filterImageFiles[] = { N_("All image files"), +static char * filterImageFiles[] = { N_("All image files"), "*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff", N_("GIF files (*.gif)"), "*.gif", @@ -251,8 +256,8 @@ static void doDumpControls(void) b = controlMap(inx).b; if (b) { - fprintf(dumpControlsF, "[%0.3d] [%x] %s %s %s\n", inx, - (unsigned int)b->hWnd, + fprintf(dumpControlsF, "[%0.3d] [%p] %s %s %s\n", inx, + b->hWnd, (b->type>=0&&b->type<=B_BOX?controlNames[b->type]:"NOTYPE"), (b->labelStr?b->labelStr:"<NULL>"), (b->helpStr?b->helpStr:"<NULL>")); @@ -303,7 +308,7 @@ void mswRepaintLabel(HWND hWnd, wControl_p b) LABELFONTSELECT newBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); oldBrush = SelectObject(hDc, newBrush); - dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, strlen(b->labelStr)); + dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (int)(strlen(b->labelStr))); rect.left = b->labelX; rect.top = b->labelY; rect.right = b->labelX + LOWORD(dw); @@ -313,7 +318,7 @@ void mswRepaintLabel(HWND hWnd, wControl_p b) /*SetBkMode( hDc, OPAQUE );*/ SetBkColor(hDc, GetSysColor(COLOR_BTNFACE)); - if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, strlen(b->labelStr))) { + if (!TextOut(hDc, b->labelX, b->labelY, b->labelStr, (int)(strlen(b->labelStr)))) { mswFail("Repainting text label"); } @@ -376,14 +381,16 @@ void * mswAlloc( w->data = data; w->focusChainNext = NULL; w->shown = TRUE; + w->hilite = FALSE; + w->errStr = NULL; return w; } void mswComputePos( wControl_p b, - wPos_t origX, - wPos_t origY) + wWinPix_t origX, + wWinPix_t origY) { wWin_p w = b->parent; @@ -403,14 +410,14 @@ void mswComputePos( b->labelY = b->y+2; if (b->labelStr) { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(w->hWnd); LABELFONTSELECT lab_l = strlen(b->labelStr); - dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (UINT)lab_l); b->labelX -= LOWORD(dw) + 5; LABELFONTRESET ReleaseDC(w->hWnd, hDc); @@ -557,7 +564,7 @@ void mswSetFocus( b->parent->focusChainNext = b; } } - + /* ****************************************************************************** * @@ -569,10 +576,10 @@ void mswSetFocus( static void getSavedSizeAndPos( long option, const char * nameStr, - wPos_t *rw, - wPos_t *rh, - wPos_t *rx, - wPos_t *ry, + wWinPix_t *rw, + wWinPix_t *rh, + wWinPix_t *rx, + wWinPix_t *ry, int *showCmd) { char *cq; @@ -580,14 +587,31 @@ static void getSavedSizeAndPos( if ((option&F_RECALLPOS) && nameStr) { int x, y, w, h; + int xadj, yadj; const char *cp; int state; + w = h = 0; + xadj = 1; + yadj = mTitleH + 1; + if (option & F_RESIZE) { + xadj += mResizeBorderW * 2; + yadj += mResizeBorderH * 2; + } + else + { + xadj += mFixBorderW * 2; + yadj += mFixBorderH * 2; + } + //if (option & F_MENUBAR) { + // yadj += mMenuH; + //} + if ((option & F_RESIZE) && (cp = wPrefGetStringBasic("msw window size", nameStr)) && (state = (int)strtol(cp, &cq, 10), cp != cq) && // state is not used - (cp = cq, w = (wPos_t)strtod(cp, &cq), cp != cq) && - (cp = cq, h = (int)strtod(cp, &cq), cp != cq) + (cp = cq, w = (wWinPix_t)(strtod(cp, &cq)), cp != cq) && + (cp = cq, h = (wWinPix_t)(strtod(cp, &cq)), cp != cq) ) { if (w < 10) { w = 10; @@ -597,12 +621,12 @@ static void getSavedSizeAndPos( h = 10; } - if (w > screenWidth) { - w = screenWidth; + if (w > screenWidth - xadj) { + w = screenWidth - xadj; } - if (h > screenHeight) { - h = screenHeight; + if (h > screenHeight - yadj) { + h = screenHeight - yadj; } *rw = w; @@ -610,8 +634,8 @@ static void getSavedSizeAndPos( } if ((cp = wPrefGetStringBasic("msw window pos", nameStr)) && - (x = (wPos_t)strtod(cp, &cq), cp != cq) && - (cp = cq, y = (wPos_t)strtod(cp, &cq), cp != cq) + (x = (wWinPix_t)(strtod(cp, &cq)), cp != cq) && + (cp = cq, y = (wWinPix_t)(strtod(cp, &cq)), cp != cq) ) { if (y < 0) { y = 0; @@ -621,12 +645,12 @@ static void getSavedSizeAndPos( x = 0; } - if (y > screenHeight-40) { - y = screenHeight-40; + if (y + h > screenHeight - yadj) { + y = screenHeight - yadj - h; } - if (x > screenWidth-40) { - x = screenWidth-40; + if (x + w > screenWidth - xadj) { + x = screenWidth - xadj - w; } *rx = x; @@ -647,12 +671,12 @@ static void getSavedSizeAndPos( * \param aspect_ration IN unused on Windows */ void wSetGeometry(wWin_p win, - int min_width, - int max_width, - int min_height, - int max_height, - int base_width, - int base_height, + 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 @@ -690,15 +714,15 @@ static wWin_p winCommonCreate( long style, const char * labelStr, wWinCallBack_p winProc, - wPos_t w, - wPos_t h, + wWinPix_t w, + wWinPix_t h, void * data, const char * nameStr, int * pShowCmd) { wWin_p win; int index; - wPos_t ww, hh, xx, yy; + wWinPix_t ww, hh, xx, yy; RECT rect; win = (wWin_p)mswAlloc(NULL, typ, mswStrdup(labelStr), sizeof *win, data, &index); @@ -715,6 +739,8 @@ static wWin_p winCommonCreate( if (typ == W_MAIN) { *pShowCmd = ((option & F_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL); + } else { + *pShowCmd = SW_HIDE; //Make sure to hide first } if (xx != CW_USEDEFAULT) { @@ -806,8 +832,8 @@ void wInitAppName(char *_appName) wWin_p wWinMainCreate( const char * name, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, const char * nameStr, @@ -816,7 +842,6 @@ wWin_p wWinMainCreate( void * data) { wWin_p w; - RECT rect; const char * appDir; const char * libDir; int showCmd; @@ -877,26 +902,29 @@ 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(w->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L); - hDc = GetDC(w->hWnd); + SendMessage(mswHWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); + hDc = GetDC(mswHWnd); GetTextMetrics(hDc, &tm); mswEditHeight = tm.tmHeight+2; - ReleaseDC(w->hWnd, hDc); + ReleaseDC(mswHWnd, hDc); } - ShowWindow(w->hWnd, showCmd); - UpdateWindow(w->hWnd); - GetWindowRect(w->hWnd, &rect); - GetClientRect(w->hWnd, &rect); + ShowWindow(mswHWnd, showCmd); + UpdateWindow(mswHWnd); w->busy = FALSE; return w; } wWin_p wWinPopupCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, const char * nameStr, @@ -1077,7 +1105,7 @@ static wAccelKey_e translateExtKey(UINT wParam) } -long notModKey; +static long notModKey; int mswTranslateAccelerator( HWND hWnd, LPMSG pMsg) @@ -1091,7 +1119,7 @@ int mswTranslateAccelerator( return FALSE; } - acclKey = pMsg->wParam; + acclKey = (long)pMsg->wParam; b = getControlFromCursor(pMsg->hwnd, &win); if (win == NULL) { @@ -1112,7 +1140,7 @@ int mswTranslateAccelerator( } if (acclKey == (long)VK_F1) { - closeBalloonHelp(); + closeBalloonHelp(1); if (!b && win) { wHelp(win->helpStr); @@ -1162,14 +1190,14 @@ int mswTranslateAccelerator( -void wGetDisplaySize(POS_T * width, POS_T * height) +void wGetDisplaySize(wWinPix_t * width, wWinPix_t * height) { *width = screenWidth; *height = screenHeight; } -void wWinGetSize(wWin_p w, POS_T * width, POS_T * height) +void wWinGetSize(wWin_p w, wWinPix_t * width, wWinPix_t * height) { RECT rect; GetWindowRect(w->hWnd, &rect); @@ -1181,7 +1209,7 @@ void wWinGetSize(wWin_p w, POS_T * width, POS_T * height) } -void wWinSetSize(wWin_p w, POS_T width, POS_T height) +void wWinSetSize(wWin_p w, wWinPix_t width, wWinPix_t height) { RECT rect; w->w = width; @@ -1224,33 +1252,24 @@ static void blockingLoop(void) static void savePos(wWin_p win) { - WINDOWPLACEMENT windowPlace; - wPos_t w, h; + wWinPix_t w, h; RECT rect; if (win->nameStr && IsWindowVisible(win->hWnd) /*&& !IsIconic( win->hWnd )*/) { - windowPlace.length = sizeof windowPlace; - GetWindowPlacement(win->hWnd, &windowPlace); + GetWindowRect(win->hWnd, &rect); - if (win->option&F_RECALLPOS) { + if (win->option&F_RECALLPOS) { char posStr[20]; - wsprintf(posStr, "%d %d", - windowPlace.rcNormalPosition.left, - windowPlace.rcNormalPosition.top); - wPrefSetString("msw window pos", win->nameStr, posStr); + 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 = windowPlace.rcNormalPosition.right - windowPlace.rcNormalPosition.left; - h = windowPlace.rcNormalPosition.bottom - windowPlace.rcNormalPosition.top; - w -= mResizeBorderW*2; - h -= mResizeBorderH*2 + mTitleH; - - if (win->option&F_MENUBAR) { - h -= mMenuH; - } - + GetClientRect(win->hWnd, &rect); + w = rect.right - rect.left; + h = rect.bottom - rect.top; wsprintf(posStr, "%d %d %d", 0, // unused w, h); @@ -1265,7 +1284,7 @@ void wWinShow( wWin_p win, BOOL_T show) { - wPos_t x, y; + wWinPix_t x, y; wWin_p win1; win->busy = TRUE; @@ -1292,6 +1311,10 @@ void wWinShow( win->centerWin = FALSE; win->shown = TRUE; + // Clear hilites + for (wControl_p controlP = win->first; controlP; controlP = controlP->next) + controlP->hilite = FALSE; + if (mswHWnd == (HWND)0 || !IsIconic(mswHWnd)) { ShowWindow(win->hWnd, SW_SHOW); @@ -1429,13 +1452,15 @@ const char * wWinGetTitle( void wWinClear( wWin_p win, - wPos_t x, - wPos_t y, - wPos_t width, - wPos_t height) + wWinPix_t x, + wWinPix_t y, + wWinPix_t width, + wWinPix_t height) { } +extern long dontHideCursor; + void wSetCursor(wDraw_p win, wCursor_t cursor) { @@ -1492,6 +1517,11 @@ void wSetCursor(wDraw_p win, case wCursorAppStart: SetCursor(LoadCursor(NULL, IDC_APPSTARTING)); break; + + case wCursorNone: + if (!dontHideCursor) + SetCursor(NULL); + break; } curCursor = cursor; @@ -1667,44 +1697,44 @@ const char * wControlGetHelp(wControl_p b) } -wPos_t wLabelWidth(const char * labelStr) +wWinPix_t wLabelWidth(const char * labelStr) { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(mswHWnd); lab_l = strlen(labelStr); LABELFONTSELECT - dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, (UINT)lab_l); LABELFONTRESET ReleaseDC(mswHWnd, hDc); return LOWORD(dw) + 5; } -wPos_t wControlGetWidth( +wWinPix_t wControlGetWidth( wControl_p b) /* Control */ { return b->w; } -wPos_t wControlGetHeight( +wWinPix_t wControlGetHeight( wControl_p b) /* Control */ { return b->h; } -wPos_t wControlGetPosX( +wWinPix_t wControlGetPosX( wControl_p b) /* Control */ { return b->x; } -wPos_t wControlGetPosY( +wWinPix_t wControlGetPosY( wControl_p b) /* Control */ { return b->y; @@ -1713,21 +1743,21 @@ wPos_t wControlGetPosY( void wControlSetPos( wControl_p b, - wPos_t x, - wPos_t y) + wWinPix_t x, + wWinPix_t y) { b->labelX = x; b->labelY = y+2; if (b->labelStr) { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(b->parent->hWnd); LABELFONTSELECT lab_l = strlen(b->labelStr); - dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST b->labelStr, (UINT)lab_l); b->labelX -= LOWORD(dw) + 5; LABELFONTRESET ReleaseDC(b->parent->hWnd, hDc); @@ -1757,14 +1787,14 @@ void wControlSetLabel( if (b->type == B_RADIO ) { ; } else { - int lab_l; + size_t lab_l; HDC hDc; DWORD dw; LABELFONTDECL hDc = GetDC(b->parent->hWnd); lab_l = strlen(labelStr); LABELFONTSELECT - dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, lab_l); + dw = GetTextExtent(hDc, CAST_AWAY_CONST labelStr, (UINT)lab_l); LABELFONTRESET b->labelX = b->x - LOWORD(dw) - 5; ReleaseDC(b->parent->hWnd, hDc); @@ -1797,13 +1827,14 @@ void wControlHilite( return; } - if (!IsWindowVisible(b->parent->hWnd)) { + if ((b->parent==NULL) || (!IsWindowVisible(b->parent->hWnd)) || (!IsWindowVisible(b->hWnd))) { + b->hilite = FALSE; return; } - if (!IsWindowVisible(b->hWnd)) { - return; - } + 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, @@ -1840,7 +1871,7 @@ void wMessage( { HDC hDc; int oldRop; - POS_T h; + wWinPix_t h; RECT rect; LABELFONTDECL @@ -1855,7 +1886,7 @@ void wMessage( Rectangle(hDc, 0, h, w->w, h); SetROP2(hDc, oldRop); LABELFONTSELECT - TextOut(hDc, 0, h, msg, strlen(msg)); + TextOut(hDc, 0, h, msg, (int)(strlen(msg))); LABELFONTRESET ReleaseDC(w->hWnd, hDc); } @@ -1873,7 +1904,7 @@ unsigned wOpenFileExternal(char *file) res = ShellExecute(mswHWnd, "open", file, NULL, NULL, SW_SHOW); - if ((int)res <= 32) { + if ((UINT_PTR)res <= 32) { wNoticeEx(NT_ERROR, "Error when opening file!", "Cancel", NULL); return(FALSE); } @@ -1886,7 +1917,6 @@ void wExit(int rc) INDEX_T inx; wControl_p b; mswPutCustomColors(); - wPrefFlush(); for (inx=controlMap_da.cnt-1; inx>=0; inx--) { b = controlMap(inx).b; @@ -1903,7 +1933,9 @@ void wExit(int rc) } } - for (inx=controlMap_da.cnt-1; inx>=0; inx--) { + wPrefFlush(""); + + for (inx=controlMap_da.cnt-1; inx>=0; inx--) { b = controlMap(inx).b; if (b != NULL) { @@ -1916,14 +1948,14 @@ void wExit(int rc) controlMap(inx).b = NULL; } - deleteBitmaps(); + deleteBitmaps(); if (mswOldTextFont != (HFONT)0) { DeleteObject(mswOldTextFont); } if (helpInitted) { - WinHelp(mswHWnd, helpFile, HELP_QUIT, 0L); + WinHelp(mswHWnd, helpFile, HELP_QUIT, (DWORD)0); helpInitted = FALSE; } @@ -2165,14 +2197,14 @@ void wHelp( { char *pszHelpTopic; HWND hwndHelp; - char *theTopic = "index"; + const char *theTopic = "index"; if (topic) { theTopic = topic; } if (!helpInitted) { - HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ; + HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ; helpInitted = TRUE; } @@ -2199,11 +2231,12 @@ void doHelpMenu(void * context) HH_FTS_QUERY ftsQuery; if (!helpInitted) { - HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie) ; + HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie) ; helpInitted = TRUE; } - switch ((int)(long)context) { + const char * topic; + switch ((int)(INT_PTR)context) { case 1: /* Contents */ HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_TOC, (DWORD_PTR)NULL); break; @@ -2215,12 +2248,11 @@ void doHelpMenu(void * context) ftsQuery.fTitleOnly = FALSE; ftsQuery.pszSearchQuery = NULL; ftsQuery.pszWindow = NULL; - HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD)&ftsQuery); + HtmlHelp(mswHWnd, helpFile, HH_DISPLAY_SEARCH,(DWORD_PTR)&ftsQuery); break; case 3: /*Context*/ - const char * topic; topic = GetCurCommandName(); wHelp(topic); break; @@ -2267,149 +2299,132 @@ void wControlSetBalloonText(wControl_p b, const char * text) b->tipStr = mswStrdup(text); } - -void startBalloonHelp(void) +void openBalloonHelp(wControl_p b, int dx, int dy) { - HDC hDc; - DWORD extent; - RECT rect; - POINT pt; - wBalloonHelp_t * bh; - const char * hs; - HFONT hFont; - - if (!balloonHelpStrings) { - return; - } - - if (!balloonHelpEnable) { - return; - } - - if (balloonHelpHWnd) { - if (balloonHelpButton->tipStr) { - hs = balloonHelpButton->tipStr; - } else { - hs = balloonHelpButton->helpStr; - - if (!hs) { - return; - } - - for (bh = balloonHelpStrings; bh->name && strcmp(bh->name,hs) != 0; bh++); - - if (!bh->name || !bh->value) { - return; - } + 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); +#endif + return; + } + } +#ifdef BALLOON_TRACE + fprintf(logFile, "openBalloon %s state %d\n", msg, balloonHelpState); fflush(logFile); +#endif + if (!balloonHelpHWnd) + return; + int w, h; + hDc = GetDC(balloonHelpHWnd); + hFont = SelectObject(hDc, mswLabelFont); + extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, (int)(strlen(msg))); + w = LOWORD(extent); + h = HIWORD(extent); + + if (b->type == B_RADIO || + b->type == B_TOGGLE) { + pt.y = b->h; + } + else { + GetClientRect(b->hWnd, &rect); + pt.y = rect.bottom; + } - balloonHelpButton->tipStr = hs = bh->value; - } + pt.x = dx; + pt.y -= dy; + ClientToScreen(b->hWnd, &pt); - if (newHelp) { - wControlSetBalloon(balloonHelpButton, 0, 0, hs); - } else { - int w, h; - hDc = GetDC(balloonHelpHWnd); - hFont = SelectObject(hDc, mswLabelFont); - extent = GetTextExtent(hDc, CAST_AWAY_CONST hs, strlen(hs)); - w = LOWORD(extent); - h = HIWORD(extent); - pt.x = 0; - - if (balloonHelpButton->type == B_RADIO || - balloonHelpButton->type == B_TOGGLE) { - pt.y = balloonHelpButton->h; - } else { - GetClientRect(balloonHelpButton->hWnd, &rect); - pt.y = rect.bottom; - } + if (pt.x + w + 2 > screenWidth) { + pt.x = screenWidth - (w + 2); + } - ClientToScreen(balloonHelpButton->hWnd, &pt); + if (pt.x < 0) { + pt.x = 0; + } - if (pt.x + w+2 > screenWidth) { - pt.x = screenWidth-(w+2); - } + 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 (pt.x < 0) { - pt.x = 0; - } - SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w+6, h+4, - SWP_SHOWWINDOW|SWP_NOACTIVATE); - SetBkColor(hDc, GetSysColor(COLOR_INFOBK)); - TextOut(hDc, 2, 1, hs, strlen(hs)); - SelectObject(hDc, hFont); - ReleaseDC(balloonHelpHWnd, hDc); - } - } -} -void closeBalloonHelp(void) +void startBalloonHelp(void) { - if (balloonHelpTimer) { - KillTimer(mswHWnd, balloonHelpTimer); - balloonHelpTimer = 0; - } - - if (balloonHelpState == balloonHelpShow) - if (balloonHelpHWnd) { - ShowWindow(balloonHelpHWnd, SW_HIDE); - } + 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); + } - balloonHelpState = balloonHelpIdle; + openBalloonHelp(balloonHelpButton, 0, 0); } -void wControlSetBalloon(wControl_p b, wPos_t dx, wPos_t dy, const char * msg) +void closeBalloonHelp(int inx) { - HDC hDc; - DWORD extent; - RECT rect; - POINT pt; - HFONT hFont; - - if (msg) { - int w, h; - hDc = GetDC(balloonHelpHWnd); - hFont = SelectObject(hDc, mswLabelFont); - extent = GetTextExtent(hDc, CAST_AWAY_CONST msg, strlen(msg)); - w = LOWORD(extent); - h = HIWORD(extent); - - if (b->type == B_RADIO || - b->type == B_TOGGLE) { - pt.y = b->h; - } else { - GetClientRect(b->hWnd, &rect); - pt.y = rect.bottom; - } +#ifdef BALLOON_TRACE + fprintf(logFile, "closeBallonHelp %d state=%d\n", inx, balloonHelpState); fflush(logFile); +#endif + if (balloonHelpTimer) { + KillTimer(mswHWnd, balloonHelpTimer); + balloonHelpTimer = (UINT_PTR)0; + } - pt.x = dx; - pt.y -= dy; - ClientToScreen(b->hWnd, &pt); + if (balloonHelpState == balloonHelpShow) + if (balloonHelpHWnd) { + ShowWindow(balloonHelpHWnd, SW_HIDE); + } - if (pt.x + w+2 > screenWidth) { - pt.x = screenWidth-(w+2); - } + balloonHelpState = balloonHelpIdle; +} - if (pt.x < 0) { - pt.x = 0; - } - SetWindowPos(balloonHelpHWnd, HWND_TOPMOST, pt.x, pt.y, w+6, h+4, - SWP_SHOWWINDOW|SWP_NOACTIVATE); - SetBkColor(hDc, GetSysColor(COLOR_INFOBK)); - TextOut(hDc, 2, 1, msg, strlen(msg)); - SelectObject(hDc, hFont); - ReleaseDC(balloonHelpHWnd, hDc); - balloonHelpState = balloonHelpShow; - balloonControlButton = b; - } else { - closeBalloonHelp(); - } +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); + } } + int wGetKeyState(void) { int rc, keyState; @@ -2613,7 +2628,7 @@ struct wFilSel_t * wFilSelCreate( { char * cp; struct wFilSel_t * ret; - int len; + size_t len; ret = (struct wFilSel_t*)malloc(sizeof *ret); ret->parent = parent; ret->mode = mode; @@ -2671,7 +2686,7 @@ const char * wMemStats(void) ", Unknown Heap Status"); return msg; } - + /* ***************************************************************************** * @@ -2750,8 +2765,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) int inx; wWin_p w; wControl_p b, oldW; - int child = ((GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) != 0); - POS_T newW, newH; + wWinPix_t newW, newH; RECT rect; PAINTSTRUCT ps; HWND hWnd2; @@ -2759,9 +2773,10 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) HDC hDc; wAccelKey_e extChar; + LPMINMAXINFO pMMI; switch (message) { case WM_GETMINMAXINFO: - LPMINMAXINFO pMMI = (LPMINMAXINFO)lParam; + pMMI = (LPMINMAXINFO)lParam; inx = GetWindowWord(hWnd, 0); if (inx >= CONTROL_BASE && inx <= controlMap_da.cnt) { @@ -2775,7 +2790,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } } - return(0); + return (LRESULT)0; case WM_MOUSEWHEEL: inx = GetWindowWord(hWnd, 0); @@ -2787,12 +2802,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return mswCallBacks[b->type]->messageProc((wControl_p)b, hWnd, message, wParam, lParam); - return (0); + return (LRESULT)0; - case WM_DRAWITEM: - case WM_COMMAND: + case WM_COMMAND: + closeBalloonHelp(3); + case WM_DRAWITEM: case WM_MEASUREITEM: - closeBalloonHelp(); if (WCMD_PARAM_ID < CONTROL_BASE || WCMD_PARAM_ID > (WPARAM)controlMap_da.cnt) { break; @@ -2808,10 +2823,10 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) // draw the bitmap mswDrawIcon(((LPDRAWITEMSTRUCT)lParam)->hDC, 0, 0, (wIcon_p)(b->data), FALSE, (COLORREF)0, (COLORREF)0); - return (TRUE); + return (LRESULT)TRUE; } else { mswSetFocus(b); - ret = 0L; + ret = 0; if (!inMainWndProc) { inMainWndProc = TRUE; @@ -2824,7 +2839,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) inMainWndProc = FALSE; } - return ret; + return (LRESULT)ret; } case WM_PAINT: @@ -2846,7 +2861,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } EndPaint(hWnd, &ps); - return 1L; + return (LRESULT)1; } break; @@ -2942,9 +2957,19 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } b = getControlFromCursor(hWnd, NULL); - closeBalloonHelp(); + closeBalloonHelp(4); if (b && b->type == B_DRAW) { + // Change Num keypad to a special code to emulate cursor keys + if (wParam == VK_UP || + wParam == VK_DOWN || + wParam == VK_RIGHT || + wParam == VK_LEFT || + wParam == VK_INSERT || + wParam == VK_DELETE) + { + if ((lParam & 0x1000000) == 0) lParam |= 0x1000000; + } return SendMessage(b->hWnd, WM_CHAR, wParam, lParam); } @@ -2967,7 +2992,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - return 0L; + return (LRESULT)0; case 0x1B: @@ -2988,7 +3013,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } mswSetTrigger((wControl_p)TRIGGER_TIMER, NULL); - return 0L; + return (LRESULT)0; case 0x20: @@ -3010,7 +3035,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - return 0L; + return (LRESULT)0; case 0x09: @@ -3041,16 +3066,16 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - return 0L; + return (LRESULT)0; } /* Not a Draw control */ MessageBeep(MB_ICONHAND); - return 0L; + return (LRESULT)0; break; case WM_ENABLE: - if (wParam == 1) { /* WIN32??? */ + if (wParam == (WPARAM)1) { hWnd2 = SetFocus(hWnd); } @@ -3068,53 +3093,70 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } - closeBalloonHelp(); + closeBalloonHelp(5); wHelp(b->helpStr); - return 0L; + return (LRESULT)0; case WM_SETCURSOR: - /*if (any buttons down) - break;*/ - wSetCursor(NULL, curCursor); + if (hWnd == mswHWnd) + wSetCursor(NULL, curCursor); - if (!mswAllowBalloonHelp) { - return TRUE; - } - - if (IsIconic(mswHWnd)) { - return TRUE; - } + if (!mswAllowBalloonHelp) { + break; + } - b = getControlFromCursor(hWnd, NULL); + if (IsIconic(mswHWnd)) { + break; + } - if (b == balloonControlButton) { - return TRUE; - } + b = getControlFromCursor(hWnd, NULL); + +#ifdef BALLOON_TRACE + fprintf(logFile, "SETCURSOR %s\n", b ? b->helpStr : "NULL"); fflush(logFile); +#endif + if (b == balloonControlButton) { + //closeBalloonHelp(61); + break; + } - if (/*(!IsWindowEnabled(hWnd))*/ GetActiveWindow() != hWnd || - (!b) || b->type == B_DRAW || b->helpStr == NULL) { - closeBalloonHelp(); - return TRUE; - } + if (GetActiveWindow() != hWnd) { + closeBalloonHelp(62); + break; + } + if (!b) { + closeBalloonHelp(63); + break; + } + if (b->type == B_DRAW) { + closeBalloonHelp(64); + break; + } + if (b->helpStr == NULL) { + closeBalloonHelp(65); + break; + } - if (b != balloonHelpButton) { - closeBalloonHelp(); - } + if (b != balloonHelpButton) { + closeBalloonHelp(7); + } +#ifdef BALLOON_TRACE + fprintf(logFile, "SETCURSOR state %d\n", balloonHelpState); fflush(logFile); +#endif + if (balloonHelpState != balloonHelpIdle) { + break; + } - if (balloonHelpState != balloonHelpIdle) { - return TRUE; - } + balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, + balloonHelpTimeOut, NULL); - balloonHelpTimer = SetTimer(mswHWnd, BALLOONHELP_TIMER, - balloonHelpTimeOut, NULL); + if (balloonHelpTimer == (UINT_PTR)0) { + break; + } - if (balloonHelpTimer == (UINT)0) { - return TRUE; - } + balloonHelpState = balloonHelpWait; + balloonHelpButton = b; + break; - balloonHelpState = balloonHelpWait; - balloonHelpButton = b; - return TRUE; case WM_SYSCOMMAND: inx = GetWindowWord(hWnd, 0); @@ -3146,7 +3188,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } wWinShow(w, FALSE); - return 0L; + return (LRESULT)0; case WM_CLOSE: inx = GetWindowWord(hWnd, 0); @@ -3168,13 +3210,13 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) (w->winProc(w, wClose_e, NULL, NULL)); } - return 0L; + return (LRESULT)0; } case WM_DESTROY: if (hWnd == mswHWnd) { PostQuitMessage(0L); - return 0L; + return (LRESULT)0; } break; @@ -3192,15 +3234,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } else if (wParam == BALLOONHELP_TIMER) { KillTimer(hWnd, balloonHelpTimer); - balloonHelpTimer = (UINT)0; + balloonHelpTimer = (UINT_PTR)0; startBalloonHelp(); } - return 0L; + return (LRESULT)0; case WM_MENUSELECT: mswAllowBalloonHelp = TRUE; - closeBalloonHelp(); + closeBalloonHelp(8); break; case WM_WINDOWPOSCHANGED: @@ -3226,7 +3268,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_PALETTECHANGED: if (wParam == (WPARAM)hWnd) { - return 0L; + return (LRESULT)0; } case WM_QUERYNEWPALETTE: @@ -3240,12 +3282,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) InvalidateRect(hWnd, NULL, TRUE); } - return inx; + return (LRESULT)inx; } case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) { - closeBalloonHelp(); + closeBalloonHelp(9); } break; @@ -3272,7 +3314,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) inMainWndProc = FALSE; } - return ret; + return (LRESULT)ret; case WM_LBUTTONDOWN: case WM_MOUSEMOVE: @@ -3297,7 +3339,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) inMainWndProc = FALSE; } - return ret; + return (LRESULT)ret; default: ; @@ -3414,9 +3456,9 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, mResizeBorderW = GetSystemMetrics(SM_CXFRAME); mResizeBorderH = GetSystemMetrics(SM_CYFRAME); mMenuH = GetSystemMetrics(SM_CYMENU) + 1; - screenWidth = GetSystemMetrics(SM_CXSCREEN); - screenHeight = GetSystemMetrics(SM_CYSCREEN); - mswLabelFont = GetStockObject(DEFAULT_GUI_FONT); + screenWidth = GetSystemMetrics(SM_CXFULLSCREEN); + screenHeight = GetSystemMetrics(SM_CYFULLSCREEN); + mswLabelFont = GetStockObject(DEFAULT_GUI_FONT); hDc = GetDC(0); mswScale = GetDeviceCaps(hDc, LOGPIXELSX) / 96.0; @@ -3467,5 +3509,5 @@ int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, HtmlHelp(NULL, NULL, HH_UNINITIALIZE, (DWORD)dwCookie); } - return msg.wParam; + return (int)msg.wParam; } diff --git a/app/wlib/mswlib/mswmsg.c b/app/wlib/mswlib/mswmsg.c index 6445299..8487e31 100644 --- a/app/wlib/mswlib/mswmsg.c +++ b/app/wlib/mswlib/mswmsg.c @@ -21,17 +21,12 @@ #define SCALE_LARGE 1.6 #define SCALE_SMALL 0.8 -#ifdef CONTROL3D -static int messageHeight = 18; -#endif - struct wMessage_t { WOBJ_COMMON long flags; const char * message; }; -#ifndef CONTROL3D static void repaintMessage( HWND hWnd, wControl_p b ) @@ -83,7 +78,7 @@ static void repaintMessage( rect.left = bm->x; SetBkColor( hDc, GetSysColor( COLOR_BTNFACE ) ); - ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2), ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, strlen( bm->message ), NULL ); + ExtTextOut( hDc, bm->x, bm->y + ((bm->h + 2 - textMetrics.tmHeight) / 2), ETO_CLIPPED|ETO_OPAQUE, &rect, bm->message, (int)(strlen( bm->message )), NULL ); if( scale != 1.0 ) /* in case we did create a new font earlier, delete it now */ @@ -94,7 +89,6 @@ static void repaintMessage( ReleaseDC( hWnd, hDc ); } -#endif void wMessageSetValue( wMessage_p b, @@ -106,34 +100,26 @@ void wMessageSetValue( b->message = mswStrdup( arg ); else b->message = NULL; -#ifdef CONTROL3D - SetWindowText( b->hWnd, arg ); -#else + repaintMessage( ((wControl_p)(b->parent))->hWnd, (wControl_p)b ); -#endif + } void wMessageSetWidth( wMessage_p b, - wPos_t width ) + wWinPix_t width ) { b->w = width; -#ifdef CONTROL3D - SetWindowPos( b->hWnd, HWND_TOP, CW_USEDEFAULT, CW_USEDEFAULT, - width, messageHeight, SWP_NOMOVE ); -#endif + } -wPos_t wMessageGetWidth(const char *string) +wWinPix_t wMessageGetWidth(const char *string) { return(wLabelWidth(string)); } -wPos_t wMessageGetHeight( long flags ) +wWinPix_t wMessageGetHeight( long flags ) { -#ifdef CONTROL3D - return messageHeight; -#else double scale = 1.0; if( flags & BM_LARGE ) @@ -141,8 +127,8 @@ wPos_t wMessageGetHeight( long flags ) if( flags & BM_SMALL ) scale = SCALE_SMALL; - return((wPos_t)((mswEditHeight) * scale )); -#endif + return((wWinPix_t)((mswEditHeight) * scale )); + } static void mswMessageSetBusy( @@ -152,68 +138,39 @@ static void mswMessageSetBusy( } -#ifndef CONTROL3D + static callBacks_t messageCallBacks = { repaintMessage, NULL, NULL, mswMessageSetBusy }; -#endif - wMessage_p wMessageCreateEx( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, - POS_T width, + wWinPix_t width, const char *message, long flags ) { wMessage_p b; int index; -#ifdef CONTROL3D - RECT rect; -#endif - + b = (wMessage_p)mswAlloc( parent, B_MESSAGE, NULL, sizeof *b, NULL, &index ); mswComputePos( (wControl_p)b, x, y ); b->option |= BO_READONLY; b->message = mswStrdup( message ); b->flags = flags; -#ifdef CONTROL3D - if ( width <= 0 && strlen(b->message) > 0 ) { - width = wLabelWidth( b->message ); - } - - b->hWnd = CreateWindow( "STATIC", NULL, - SS_LEFTNOWORDWRAP | WS_CHILD | WS_VISIBLE, - b->x, b->y, - width, messageHeight, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL ); - if (b->hWnd == NULL) { - mswFail("CreateWindow(MESSAGE)"); - return b; - } - - if ( !mswThickFont ) - SendMessage( b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L ); - SetWindowText( b->hWnd, message ); - - GetWindowRect( b->hWnd, &rect ); - b->w = rect.right - rect.left; - b->h = rect.bottom - rect.top; -#else b->w = width; b->h = wMessageGetHeight( flags ) + 1; repaintMessage( ((wControl_p)parent)->hWnd, (wControl_p)b ); -#endif + mswAddButton( (wControl_p)b, FALSE, helpStr ); -#ifndef CONTROL3D mswCallBacks[B_MESSAGE] = &messageCallBacks; -#endif + return b; } diff --git a/app/wlib/mswlib/mswpref.c b/app/wlib/mswlib/mswpref.c index 201171a..55fedb4 100644 --- a/app/wlib/mswlib/mswpref.c +++ b/app/wlib/mswlib/mswpref.c @@ -5,7 +5,6 @@ #include <commdlg.h> #include <math.h> #include <stdio.h> -#include "misc.h" #include "mswint.h" #include <shlobj.h> #include <Shlwapi.h> @@ -40,13 +39,15 @@ const char * wGetAppLibDir( void ) *cp = '\0'; #ifdef XTRKCAD_CMAKE_BUILD - strcpy(appLibDirName, module_name); - strcat(appLibDirName, "\\..\\share\\xtrkcad"); + 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 - strcpy(appLibDirName, module_name); + strncpy(appLibDirName, module_name, sizeof(appLibDirName)); + appLibDirName[sizeof(appLibDirName)-1] = '\0'; return appLibDirName; } @@ -73,11 +74,12 @@ const char * wGetAppWorkDir( void ) return appWorkDirName; } wGetAppLibDir(); - sprintf( mswTmpBuff, "%s\\xtrkcad0.ini", appLibDirName ); + snprintf( mswTmpBuff, sizeof(mswTmpBuff), "%s\\xtrkcad0.ini", appLibDirName ); rc = GetPrivateProfileString( "workdir", "path", "", appWorkDirName, sizeof appWorkDirName, mswTmpBuff ); if ( rc!=0 ) { if ( stricmp( appWorkDirName, "installdir" ) == 0 ) { - strcpy( appWorkDirName, appLibDirName ); + strncpy( appWorkDirName, appLibDirName, sizeof(appWorkDirName) ); + appWorkDirName[sizeof(appWorkDirName)-1] = '\0'; } else { cp = &appWorkDirName[strlen(appWorkDirName)-1]; while (cp>appWorkDirName && *cp == '\\') *cp-- = 0; @@ -89,7 +91,7 @@ const char * wGetAppWorkDir( void ) wNoticeEx( NT_ERROR, "Cannot get user's profile directory", "Exit", NULL ); wExit(0); } else { - sprintf( appWorkDirName, "%s\\%s", mswTmpBuff, "XTrackCad" ); + 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 ); @@ -125,7 +127,8 @@ typedef struct { BOOL_T dirty; char * val; } prefs_t; -dynArr_t prefs_da; + +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 ) @@ -149,6 +152,17 @@ void wPrefSetString( const char * section, const char * name, const char * sval p->val = mswStrdup(sval); } +void wPrefsLoad(char * name) { + prefs_t *p; + for (int i= 0; i<prefs_da.cnt; i++) { + p = &prefs(i); + if (!name || !name[0]) name = mswProfileFile; + int rc = GetPrivateProfileString( p->section, p->name, "", mswTmpBuff, sizeof mswTmpBuff, name ); + if (rc==0) + continue; + p->val = mswStrdup(mswTmpBuff); + } +} char * wPrefGetStringBasic( const char * section, const char * name ) { @@ -160,6 +174,7 @@ char * wPrefGetStringBasic( const char * section, const char * name ) return p->val; } } + rc = GetPrivateProfileString( section, name, "", mswTmpBuff, sizeof mswTmpBuff, mswProfileFile ); if (rc==0) return NULL; @@ -177,7 +192,7 @@ void wPrefSetInteger( const char * section, const char * name, long lval ) { char tmp[20]; - sprintf( tmp, "%ld", lval ); + snprintf( tmp, sizeof(tmp), "%ld", lval ); wPrefSetString( section, name, tmp ); } @@ -214,7 +229,7 @@ void wPrefSetFloat( { char tmp[20]; - sprintf(tmp, "%0.6f", lval ); + snprintf(tmp, sizeof(tmp), "%0.6f", lval ); wPrefSetString( section, name, tmp ); } @@ -244,15 +259,20 @@ wBool_t wPrefGetFloatBasic( } -void wPrefFlush( void ) +void wPrefFlush( char * name ) { prefs_t * p; for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if ( p->dirty ) + if (name && name[0]) + WritePrivateProfileString( p->section, p->name, p->val, name ); + else if (p->dirty) WritePrivateProfileString( p->section, p->name, p->val, mswProfileFile ); } - WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); + if (name && name[0]) + WritePrivateProfileString( NULL, NULL, NULL, name ); + else + WritePrivateProfileString( NULL, NULL, NULL, mswProfileFile ); } @@ -273,3 +293,4 @@ void wPrefReset( } prefs_da.cnt = 0; } + diff --git a/app/wlib/mswlib/mswprint.c b/app/wlib/mswlib/mswprint.c index 13756c7..e38ca05 100644 --- a/app/wlib/mswlib/mswprint.c +++ b/app/wlib/mswlib/mswprint.c @@ -4,9 +4,6 @@ #include <stdlib.h> #include <commdlg.h> #include <math.h> -#ifndef WIN32 -#include <print.h> -#endif #include "mswint.h" /* @@ -18,13 +15,9 @@ */ -struct wDraw_t print_d; +static struct wDraw_t print_d; -#ifdef WIN32 -struct tagPDA printDlg; -#else -struct tagPD printDlg; -#endif +static struct tagPDA printDlg; static int printStatus = FALSE; static DOCINFO docInfo; static double tBorder = 0.0, rBorder = 0.0, bBorder = 0.0, lBorder = 0.0; @@ -35,7 +28,7 @@ static HPALETTE newPrintPalette; static HPALETTE oldPrintPalette; -void wPrintClip( wPos_t x, wPos_t y, wPos_t w, wPos_t h ) +void wPrintClip( wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h ) { wDrawClip( &print_d, x, y, w, h ); } @@ -196,9 +189,9 @@ void wPrintSetup( wPrintSetupCallBack_p callback ) if (PrintDlg(&printDlg) != 0 && printDlg.hDC) { getPageDim( printDlg.hDC ); } - if ( callback ) { - callback( TRUE ); - } + //if ( callback ) { + // callback( TRUE ); + //} } const char* wPrintGetName() @@ -255,8 +248,8 @@ HDC mswGetPrinterDC( void ) static wBool_t printAbort = FALSE; -HWND hAbortDlgWnd; -FARPROC lpAbortDlg, lpAbortProc; +static HWND hAbortDlgWnd; +static FARPROC lpAbortDlg, lpAbortProc; static int pageNumber; int FAR PASCAL mswAbortDlg( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) diff --git a/app/wlib/mswlib/mswsplash.c b/app/wlib/mswlib/mswsplash.c index 172b563..bd7644f 100644 --- a/app/wlib/mswlib/mswsplash.c +++ b/app/wlib/mswlib/mswsplash.c @@ -41,9 +41,9 @@ static HWND hSplash; static LPWORD lpwAlign( LPWORD lpIn ) { - ULONG ul; + ULONGLONG ul; - ul = (ULONG) lpIn; + ul = (ULONGLONG) lpIn; ul +=3; ul >>=2; ul <<=2; @@ -148,7 +148,7 @@ wCreateSplash( char *appname, char *appver ) cyDlgUnit = HIWORD(GetDialogBaseUnits()); /* load the logo bitmap */ - sprintf( logoPath, "%s\\logo.bmp", wGetAppLibDir()); + snprintf( logoPath, sizeof(logoPath), "%s\\logo.bmp", wGetAppLibDir()); hBmp = LoadImage( mswHInst, logoPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE ); if( !hBmp ) return( 0 ); @@ -266,4 +266,5 @@ wDestroySplash(void) { DestroyWindow( hSplash ); return; -}
\ No newline at end of file +} + diff --git a/app/wlib/mswlib/mswstatus.c b/app/wlib/mswlib/mswstatus.c index f9d72f4..1502a4e 100644 --- a/app/wlib/mswlib/mswstatus.c +++ b/app/wlib/mswlib/mswstatus.c @@ -59,10 +59,10 @@ void wStatusSetValue( wStatus_p wStatusCreate( wWin_p parent, - wPos_t x, - wPos_t y, + wWinPix_t x, + wWinPix_t y, const char * labelStr, - wPos_t width, + wWinPix_t width, const char *message) { return (wStatus_p)wMessageCreateEx(parent, x, y, labelStr, width, message, 0); @@ -75,7 +75,7 @@ wStatus_p wStatusCreate( * \return expected width of message box */ -wPos_t +wWinPix_t wStatusGetWidth(const char *testString) { return (wMessageGetWidth(testString)); @@ -88,7 +88,7 @@ wStatusGetWidth(const char *testString) * \return text height */ -wPos_t wStatusGetHeight( +wWinPix_t wStatusGetHeight( long flags) { return (wMessageGetHeight(flags)); @@ -104,7 +104,7 @@ wPos_t wStatusGetHeight( void wStatusSetWidth( wStatus_p b, - wPos_t width) + wWinPix_t width) { wMessageSetWidth((wMessage_p)b, width); -}
\ No newline at end of file +} diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c index 0a0ce88..b43a5d4 100644 --- a/app/wlib/mswlib/mswtext.c +++ b/app/wlib/mswlib/mswtext.c @@ -58,23 +58,17 @@ struct wText_t { HANDLE hText; }; -BOOL_T textPrintAbort = FALSE; - void wTextClear( wText_p b) { - long rc; - rc = SendMessage(b->hWnd, EM_SETREADONLY, 0, 0L); -#ifdef WIN32 - rc = SendMessage(b->hWnd, EM_SETSEL, 0, -1); -#else - rc = SendMessage(b->hWnd, EM_SETSEL, 1, MAKELONG(0, -1)); -#endif - rc = SendMessage(b->hWnd, WM_CLEAR, 0, 0L); + LRESULT rc; + rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)0, (LPARAM)0); + rc = SendMessage(b->hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)-1); + rc = SendMessage(b->hWnd, WM_CLEAR, (WPARAM)0, (LPARAM)0); if (b->option&BO_READONLY) { - rc = SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L); + rc = SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0); } } @@ -97,7 +91,7 @@ void wTextAppend( char *buffer; char *extText; int textSize; - int len = strlen(text); + size_t len = strlen(text); if (!len) { return; @@ -135,11 +129,11 @@ void wTextAppend( } if (b->option&BO_READONLY) { - SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L); + SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)1, (LPARAM)0); } // scroll to bottom of text box - SendMessage(b->hWnd, EM_LINESCROLL, 0, 10000L); + SendMessage(b->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)10000); } @@ -157,11 +151,11 @@ BOOL_T wTextSave( return FALSE; } - lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L); + 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, l, (DWORD)(LPSTR)line); + len = (int)SendMessage(b->hWnd, EM_GETLINE, (WPARAM)l, (LPARAM)line); line[len] = '\0'; fprintf(f, "%s\n", line); } @@ -213,17 +207,17 @@ BOOL_T wTextPrint( lineSpace = textMetric.tmHeight + textMetric.tmExternalLeading; linesPerPage = GetDeviceCaps(hDc, VERTRES) / lineSpace; currentLine = 1; - lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L); + 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, l, (DWORD)(LPSTR)line); + 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 || textPrintAbort) { + if (IOStatus < 0 ) { break; } StartPage(hDc); @@ -231,7 +225,7 @@ BOOL_T wTextPrint( } } - if (IOStatus >= 0 && !textPrintAbort) { + if (IOStatus >= 0 ) { EndPage(hDc); EndDoc(hDc); } @@ -246,7 +240,7 @@ wBool_t wTextGetModified( wText_p b) { int rc; - rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, 0, 0L); + rc = (int)SendMessage(b->hWnd, EM_GETMODIFY, (WPARAM)0, (LPARAM)0); return (wBool_t)rc; } @@ -311,14 +305,14 @@ void wTextSetReadonly( b->option &= ~BO_READONLY; } - SendMessage(b->hWnd, EM_SETREADONLY, ro, 0L); + SendMessage(b->hWnd, EM_SETREADONLY, (WPARAM)ro, (LPARAM)0); } void wTextSetSize( wText_p bt, - wPos_t width, - wPos_t height) + wWinPix_t width, + wWinPix_t height) { bt->w = width; bt->h = height; @@ -332,13 +326,13 @@ void wTextSetSize( void wTextComputeSize( wText_p bt, - int rows, - int lines, - wPos_t * w, - wPos_t * h) + wWinPix_t rows, + wWinPix_t lines, + wWinPix_t * w, + wWinPix_t * h) { - static wPos_t scrollV_w = -1; - static wPos_t scrollH_h = -1; + static wWinPix_t scrollV_w = -1; + static wWinPix_t scrollH_h = -1; HDC hDc; TEXTMETRIC metrics; @@ -366,8 +360,8 @@ void wTextSetPosition( wText_p bt, int pos) { - long rc; - rc = SendMessage(bt->hWnd, EM_LINESCROLL, 0, MAKELONG(-65535, 0)); + LRESULT rc; + rc = SendMessage(bt->hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)MAKELONG(-65535, 0)); } static void textDoneProc(wControl_p b) @@ -387,13 +381,13 @@ static callBacks_t textCallBacks = { wText_p wTextCreate( wWin_p parent, - POS_T x, - POS_T y, + wWinPix_t x, + wWinPix_t y, const char * helpStr, const char * labelStr, long option, - POS_T width, - POS_T height) + wWinPix_t width, + wWinPix_t height) { wText_p b; DWORD style; @@ -416,17 +410,13 @@ wText_p wTextCreate( b->hWnd = CreateWindow("EDIT", NULL, style, b->x, b->y, width, height, - ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL); + ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL); if (b->hWnd == NULL) { mswFail("CreateWindow(TEXT)"); return b; } -#ifdef CONTROL3D - Ctl3dSubclassCtl(b->hWnd); -#endif - if (option & BT_FIXEDFONT) { if (fixedTextFont == (HFONT)0) { fixedTextFont = CreateFontIndirect(&fixedFont); @@ -434,13 +424,13 @@ wText_p wTextCreate( SendMessage(b->hWnd, WM_SETFONT, (WPARAM)fixedTextFont, (LPARAM)MAKELONG(1, 0)); } else if (!mswThickFont) { - SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, 0L); + SendMessage(b->hWnd, WM_SETFONT, (WPARAM)mswLabelFont, (LPARAM)0); } - b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, 0, 0L); + b->hText = (HANDLE)SendMessage(b->hWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0); if (option & BT_CHARUNITS) { - wPos_t w, h; + wWinPix_t w, h; wTextComputeSize(b, width, height, &w, &h); if (!SetWindowPos(b->hWnd, HWND_TOP, 0, 0, diff --git a/app/wlib/mswlib/simple-gettext.c b/app/wlib/mswlib/simple-gettext.c index 412eece..951ce4c 100644 --- a/app/wlib/mswlib/simple-gettext.c +++ b/app/wlib/mswlib/simple-gettext.c @@ -224,7 +224,7 @@ load_domain( const char *filename ) to_read = size; read_ptr = (char *) data; do { - unsigned long int nb = fread( read_ptr, 1, to_read, fp ); + unsigned long int nb = (unsigned int)fread( read_ptr, 1, to_read, fp ); if( nb < to_read ) { fclose (fp); free(data); @@ -341,7 +341,7 @@ get_string( struct loaded_domain *domain, u32 idx ) domain->mapped[idx] = 1; plen = strlen (p); - buf = utf8_to_native (p, plen, -1); + buf = utf8_to_native (p, (unsigned int)plen, -1); buflen = strlen (buf); if (buflen <= plen){ strcpy (p, buf); @@ -392,7 +392,7 @@ gettext( const char *msgid ) /* Locate the MSGID and its translation. */ if( domain->hash_size > 2 && domain->hash_tab ) { /* Use the hashing table. */ - u32 len = strlen (msgid); + 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)); @@ -444,7 +444,7 @@ gettext( const char *msgid ) else if (cmp_val > 0) bottom = act + 1; else - return (char *)get_string( domain, act ); + return (char *)get_string( domain, (int)(act) ); } not_found: diff --git a/app/wlib/mswlib/utf8conv.c b/app/wlib/mswlib/utf8conv.c index 62ada76..5a39b34 100644 --- a/app/wlib/mswlib/utf8conv.c +++ b/app/wlib/mswlib/utf8conv.c @@ -43,7 +43,7 @@ bool wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength) { - unsigned int cnt = 2 * (strlen(inString) + 1); + unsigned int cnt = 2 * (unsigned int)(strlen(inString) + 1); char *tempBuffer = malloc(cnt); // convert to wide character (UTF16) @@ -81,7 +81,7 @@ wSystemToUTF8(const char *inString, char *outString, unsigned outStringLength) bool wUTF8ToSystem(const char *inString, char *outString, unsigned outStringLength) { - unsigned int cnt = 2 * (strlen(inString) + 1); + unsigned int cnt = 2 * (int)(strlen(inString) + 1); char *tempBuffer = malloc(cnt); // convert to wide character (UTF16) |