diff options
Diffstat (limited to 'app/wlib/gtklib')
29 files changed, 718 insertions, 406 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); |