diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-07-03 10:19:36 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-07-03 10:19:36 +0200 |
commit | b6bd52cd7330a90fc0e44dbe6022551a8dd768a1 (patch) | |
tree | 9804282102f8c40d27407b9c94119b35eeb5013c /app/wlib/gtklib | |
parent | c9d0740841fbe0539e42e66d3865672bfcd3ac02 (diff) | |
parent | a14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 (diff) |
Update upstream source from tag 'upstream/5.3.0GA'
Update to upstream version '5.3.0GA'
with Debian dir dfd14d63b0238e276ade6f54dd9100325df5b2f9
Diffstat (limited to 'app/wlib/gtklib')
39 files changed, 6744 insertions, 6456 deletions
diff --git a/app/wlib/gtklib/CMakeLists.txt b/app/wlib/gtklib/CMakeLists.txt index 117772a..6c673d9 100644 --- a/app/wlib/gtklib/CMakeLists.txt +++ b/app/wlib/gtklib/CMakeLists.txt @@ -1,7 +1,12 @@ # Setup GTK UI library... -file(GLOB headers *.h) -set(sources +target_include_directories(xtrkcad-wlib + PRIVATE + ${xtrkcad-lib_SOURCE_DIR} +) + +target_sources(xtrkcad-wlib + PRIVATE bitmap.c boxes.c button.c @@ -24,6 +29,7 @@ set(sources single.c splash.c statusbar.c + sysinfo.c text.c timer.c tooltip.c @@ -32,66 +38,79 @@ set(sources window.c wpref.c writebitmap.c -# end of refactored sources gtkdraw-cairo.c - ) +) # help system is OS and build specific, add appropriate source files if(APPLE) if (XTRKCAD_USE_APPLEHELP) - set(sources - ${sources} + target_sources(xtrkcad-wlib + PRIVATE osxhelp.c) - else(XTRKCAD_USE_APPLEHELP) + else() if(XTRKCAD_USE_BROWSER) - set(sources - ${sources} - browserhelp.c) - else(XTRKCAD_USE_BROWSER) - PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" REQUIRED) - set(sources - ${sources} - ixhelp.c) - endif(XTRKCAD_USE_BROWSER) - endif(XTRKCAD_USE_APPLEHELP) -else(APPLE) + target_sources(xtrkcad-wlib + PRIVATE + browserhelp.c) + else() + PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" REQUIRED) + target_sources(xtrkcad-wlib + PRIVATE + ixhelp.c) + endif() + endif() +else() if(XTRKCAD_USE_BROWSER) - set(sources - ${sources} - browserhelp.c) - else(XTRKCAD_USE_BROWSER) + target_sources(xtrkcad-wlib + PRIVATE + browserhelp.c) + else() PKG_CHECK_MODULES(GTK_WEBKIT "webkit-1.0" REQUIRED) - set(sources - ${sources} - ixhelp.c) - endif(XTRKCAD_USE_BROWSER) -endif(APPLE) - -include_directories(${XTrkCAD_BINARY_DIR}) - -add_library(xtrkcad-wlib ${headers} ${sources}) + target_sources(xtrkcad-wlib + PRIVATE + ixhelp.c) + endif() +endif() # GTK find_package (GTK2) -include_directories(${GTK_INCLUDE_DIRS}) -target_link_libraries(xtrkcad-wlib ${GTK_LIBRARIES}) # configure for GTK's native Unix print find_package (GTKUnixPrint) -include_directories(${GTK_UNIX_PRINT_INCLUDE_DIRS}) -target_link_libraries(xtrkcad-wlib ${GTK_UNIX_PRINT_LIBRARIES}) + +target_include_directories(xtrkcad-wlib + PRIVATE + ${GTK_INCLUDE_DIRS} + ${GTK_UNIX_PRINT_INCLUDE_DIRS} +) +target_link_libraries(xtrkcad-wlib + PRIVATE + dynstring + ${GTK_UNIX_PRINT_LIBRARIES} + ${GTK_LIBRARIES} +) # add dependency to webkit if configured if (APPLE) if(NOT XTRKCAD_USE_APPLEHELP) if(NOT XTRKCAD_USE_BROWSER) - include_directories(${GTK_WEBKIT_INCLUDE_DIRS}) - target_link_libraries(xtrkcad-wlib ${GTK_WEBKIT_LIBRARIES}) + target_include_directories(xtrkcad-wlib + ${GTK_WEBKIT_INCLUDE_DIRS} + ) + target_link_libraries(xtrkcad-wlib + PRIVATE + ${GTK_WEBKIT_LIBRARIES} + ) endif() endif() -else (APPLE) +else () if(NOT XTRKCAD_USE_BROWSER) - include_directories(${GTK_WEBKIT_INCLUDE_DIRS}) - target_link_libraries(xtrkcad-wlib ${GTK_WEBKIT_LIBRARIES}) + target_include_directories(xtrkcad-wlib + ${GTK_WEBKIT_INCLUDE_DIRS} + ) + target_link_libraries(xtrkcad-wlib + PRIVATE + ${GTK_WEBKIT_LIBRARIES} + ) endif() -endif(APPLE) +endif() diff --git a/app/wlib/gtklib/bitmap.c b/app/wlib/gtklib/bitmap.c index 7562e33..b1ff2ed 100644 --- a/app/wlib/gtklib/bitmap.c +++ b/app/wlib/gtklib/bitmap.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -46,54 +46,57 @@ struct wBitmap_t { */ wControl_p -wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long options, const struct wIcon_t * iconP ) +wBitmapCreate( wWin_p parent, wWinPix_t x, wWinPix_t y, long options, + const struct wIcon_t * iconP ) { wBitmap_p bt; GdkPixbuf *pixbuf; GtkWidget *image; - + bt = wlibAlloc( parent, B_BITMAP, x, y, NULL, sizeof *bt, NULL ); bt->w = iconP->w; bt->h = iconP->h; bt->option = options; - + /* - * Depending on the platform, parent->widget->window might still be null + * Depending on the platform, parent->widget->window might still be null * at this point. The window allocation should be forced before creating * the pixmap. */ - if ( gtk_widget_get_window( parent->widget ) == NULL ) - gtk_widget_realize( parent->widget ); /* force allocation, if pending */ - + if ( gtk_widget_get_window( parent->widget ) == NULL ) { + gtk_widget_realize( parent->widget ); /* force allocation, if pending */ + } + /* create the bitmap from supplied xpm data */ pixbuf = gdk_pixbuf_new_from_xpm_data( (const char **)iconP->bits ); g_object_ref_sink(pixbuf); image = gtk_image_new_from_pixbuf( pixbuf ); gtk_widget_show( image ); g_object_unref( (gpointer)pixbuf ); - + bt->widget = gtk_fixed_new(); gtk_widget_show( bt->widget ); gtk_container_add( GTK_CONTAINER(bt->widget), image ); - + wlibComputePos( (wControl_p)bt ); wlibControlGetSize( (wControl_p)bt ); gtk_fixed_put( GTK_FIXED( parent->widget ), bt->widget, bt->realX, bt->realY ); - + return( (wControl_p)bt ); } /** * Create a two-tone icon - * + * * \param w IN width of icon * \param h IN height of icon * \param bits IN bitmap - * \param color IN color + * \param color IN color * \returns icon handle */ -wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawColor color ) +wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, + wDrawColor color ) { wIcon_p ip; ip = (wIcon_p)malloc( sizeof *ip ); @@ -101,7 +104,10 @@ wIcon_p wIconCreateBitMap( wWinPix_t w, wWinPix_t h, const char * bits, wDrawCol ip->w = w; ip->h = h; ip->color = color; - ip->bits = bits; + // Copy bits + int nBytes = ( ( w + 7 ) / 8 ) * h; + ip->bits = (char*)malloc( nBytes ); + memcpy( (void*)ip->bits, bits, nBytes ); return ip; } @@ -125,7 +131,7 @@ wIcon_p wIconCreatePixMap( char *pm[] ) /** * Set the color a two-tone icon - * + * * \param ip IN icon handle * \param color IN color to use */ diff --git a/app/wlib/gtklib/boxes.c b/app/wlib/gtklib/boxes.c index 74dbb7b..3c0173b 100644 --- a/app/wlib/gtklib/boxes.c +++ b/app/wlib/gtklib/boxes.c @@ -36,8 +36,8 @@ #include "gtkint.h" struct wBox_t { - WOBJ_COMMON - wBoxType_e boxTyp; + WOBJ_COMMON + wBoxType_e boxTyp; }; #define B (1) @@ -60,12 +60,12 @@ struct wBox_t { */ void wBoxSetSize( - wBox_p b, - wWinPix_t w, - wWinPix_t h) + wBox_p b, + wWinPix_t w, + wWinPix_t h) { - b->w = w; - b->h = h; + b->w = w; + b->h = h; } /** @@ -82,78 +82,78 @@ void wBoxSetSize( */ void wlibDrawBox( - wWin_p win, - wBoxType_e style, - wWinPix_t x, - wWinPix_t y, - wWinPix_t w, - wWinPix_t h) + wWin_p win, + wBoxType_e style, + wWinPix_t x, + wWinPix_t y, + wWinPix_t w, + wWinPix_t h) { - wWinPix_t x0, y0, x1, y1; - GdkDrawable * window; - cairo_t *cr; - static char colors[8][4][2] = { - { /* ThinB */ {B,0}, {B,0}, {B,0}, {B,0} }, - { /* ThinW */ {W,0}, {W,0}, {W,0}, {W,0} }, - { /* AboveW */ {W,0}, {W,0}, {B,0}, {B,0} }, - { /* BelowW */ {B,0}, {B,0}, {W,0}, {W,0} }, - { /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} }, - { /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} }, - { /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} }, - { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} } - }; - window = gtk_widget_get_window(win->widget); - cr = gdk_cairo_create(window); - cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); - cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); - cairo_set_line_width(cr, 1.0); - x0 = x; - x1 = x+w; - y0 = y; - y1 = y+h; - SETCOLOR(style, 0, 0); - cairo_move_to(cr, x0, y0); - cairo_line_to(cr, x0, y1); - cairo_stroke_preserve(cr); - SETCOLOR(style, 1, 0); - cairo_move_to(cr, x0, y0); - cairo_line_to(cr, x1, y0); - cairo_stroke_preserve(cr); - SETCOLOR(style, 2, 0); - cairo_move_to(cr, x1, y1); - cairo_line_to(cr, x0+1, y1); - cairo_stroke_preserve(cr); - SETCOLOR(style, 3, 0); - cairo_move_to(cr, x1, y1-1); - cairo_line_to(cr, x1, y0+1); - cairo_stroke_preserve(cr); - - if (style < wBoxThickB) { - cairo_destroy(cr); - return; - } - - x0++; - y0++; - x1--; - y1--; - SETCOLOR(style, 0, 1); - cairo_move_to(cr, x0, y0); - cairo_line_to(cr, x0, y1); - cairo_stroke_preserve(cr); - SETCOLOR(style, 1, 1); - cairo_move_to(cr, x0+1, y0); - cairo_line_to(cr, x1, y0); - cairo_stroke_preserve(cr); - SETCOLOR(style, 2, 1); - cairo_move_to(cr, x1, y1); - cairo_line_to(cr, x0+1, y1); - cairo_stroke_preserve(cr); - SETCOLOR(style, 3, 1); - cairo_move_to(cr, x1, y1-1); - cairo_line_to(cr, x1, y0+1); - cairo_stroke_preserve(cr); - cairo_destroy(cr); + wWinPix_t x0, y0, x1, y1; + GdkDrawable * window; + cairo_t *cr; + static char colors[8][4][2] = { + { /* ThinB */ {B,0}, {B,0}, {B,0}, {B,0} }, + { /* ThinW */ {W,0}, {W,0}, {W,0}, {W,0} }, + { /* AboveW */ {W,0}, {W,0}, {B,0}, {B,0} }, + { /* BelowW */ {B,0}, {B,0}, {W,0}, {W,0} }, + { /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} }, + { /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} }, + { /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} }, + { /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} } + }; + window = gtk_widget_get_window(win->widget); + cr = gdk_cairo_create(window); + cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); + cairo_set_line_width(cr, 1.0); + x0 = x; + x1 = x+w; + y0 = y; + y1 = y+h; + SETCOLOR(style, 0, 0); + cairo_move_to(cr, x0, y0); + cairo_line_to(cr, x0, y1); + cairo_stroke_preserve(cr); + SETCOLOR(style, 1, 0); + cairo_move_to(cr, x0, y0); + cairo_line_to(cr, x1, y0); + cairo_stroke_preserve(cr); + SETCOLOR(style, 2, 0); + cairo_move_to(cr, x1, y1); + cairo_line_to(cr, x0+1, y1); + cairo_stroke_preserve(cr); + SETCOLOR(style, 3, 0); + cairo_move_to(cr, x1, y1-1); + cairo_line_to(cr, x1, y0+1); + cairo_stroke_preserve(cr); + + if (style < wBoxThickB) { + cairo_destroy(cr); + return; + } + + x0++; + y0++; + x1--; + y1--; + SETCOLOR(style, 0, 1); + cairo_move_to(cr, x0, y0); + cairo_line_to(cr, x0, y1); + cairo_stroke_preserve(cr); + SETCOLOR(style, 1, 1); + cairo_move_to(cr, x0+1, y0); + cairo_line_to(cr, x1, y0); + cairo_stroke_preserve(cr); + SETCOLOR(style, 2, 1); + cairo_move_to(cr, x1, y1); + cairo_line_to(cr, x0+1, y1); + cairo_stroke_preserve(cr); + SETCOLOR(style, 3, 1); + cairo_move_to(cr, x1, y1-1); + cairo_line_to(cr, x1, y0+1); + cairo_stroke_preserve(cr); + cairo_destroy(cr); } /** @@ -165,9 +165,9 @@ void wlibDrawBox( static void boxRepaint(wControl_p b) { - wBox_p bb = (wBox_p)(b); - wWin_p win = bb->parent; - wlibDrawBox(win, bb->boxTyp, bb->realX, bb->realY, bb->w, bb->h); + wBox_p bb = (wBox_p)(b); + wWin_p win = bb->parent; + wlibDrawBox(win, bb->boxTyp, bb->realX, bb->realY, bb->w, bb->h); } /** @@ -184,21 +184,21 @@ static void boxRepaint(wControl_p b) */ wBox_p wBoxCreate( - wWin_p parent, - wWinPix_t bx, - wWinPix_t by, - const char * labelStr, - wBoxType_e boxTyp, - wWinPix_t bw, - wWinPix_t bh) + wWin_p parent, + wWinPix_t bx, + wWinPix_t by, + const char * labelStr, + wBoxType_e boxTyp, + wWinPix_t bw, + wWinPix_t bh) { - wBox_p b; - b = (wBox_p)wlibAlloc(parent, B_BOX, bx, by, labelStr, sizeof *b, NULL); - wlibComputePos((wControl_p)b); - b->boxTyp = boxTyp; - b->w = bw; - b->h = bh; - b->repaintProc = boxRepaint; - wlibAddButton((wControl_p)b); - return b; + wBox_p b; + b = (wBox_p)wlibAlloc(parent, B_BOX, bx, by, labelStr, sizeof *b, NULL); + wlibComputePos((wControl_p)b); + b->boxTyp = boxTyp; + b->w = bw; + b->h = bh; + b->repaintProc = boxRepaint; + wlibAddButton((wControl_p)b); + return b; } diff --git a/app/wlib/gtklib/browserhelp.c b/app/wlib/gtklib/browserhelp.c index 7d45ea5..6d2ac5d 100644 --- a/app/wlib/gtklib/browserhelp.c +++ b/app/wlib/gtklib/browserhelp.c @@ -17,12 +17,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> #include <assert.h> #include <string.h> +#include <limits.h> //#include "misc.h" @@ -45,7 +46,8 @@ extern wBool_t CheckHelpTopicExists(const char * topic); "variable.\n Also make sure that the user has sufficient access rights to read these" \ "files." /** - * Create a fully qualified url from a topic + * Create a fully qualified url from a topic. The library path is converted to + * an absolute path first. The url is then created from that path. * * \param helpUrl OUT pointer to url, free by caller * \param topic IN the help topic @@ -54,20 +56,29 @@ extern wBool_t CheckHelpTopicExists(const char * topic); static void TopicToUrl(char **helpUrl, const char *topic) { - DynString url; - DynStringMalloc(&url, 16); - - // build up the url line - DynStringCatCStrs(&url, - "file://", - wGetAppLibDir(), - "/html/", - topic, - ".html", - NULL); - - *helpUrl = strdup(DynStringToCStr(&url)); - DynStringFree(&url); + DynString url; + DynStringMalloc(&url, 16); + char *realPath; + + realPath = realpath(wGetAppLibDir(), NULL); + + if(realPath) { + // build up the url line + DynStringCatCStrs(&url, + "file://", + realPath, + "/html/", + topic, + ".html", + NULL); + + *helpUrl = strdup(DynStringToCStr(&url)); + DynStringFree(&url); + free(realPath); + } else { + wNoticeEx( NT_ERROR, _("Not enough memory for realpath()"), _("Exit"), NULL); + wExit(0); + } } /** * Invoke the system's default browser to display help for <topic>. First the @@ -79,22 +90,22 @@ TopicToUrl(char **helpUrl, const char *topic) void wHelp(const char * topic) { - int rc; - char *url; - char *currentPath; + int rc; + char *url; +// char *currentPath; - assert(topic != NULL); - assert(strlen(topic)); + assert(topic != NULL); + assert(strlen(topic)); - if (!CheckHelpTopicExists(topic)) return; - - TopicToUrl(&url, topic); + if (!CheckHelpTopicExists(topic)) { return; } + TopicToUrl(&url, topic); + printf(">%s<\n", url); rc = wOpenFileExternal(url); if (!rc) { - wNotice(HELPERRORTEXT, _("Cancel"), NULL); - } + wNotice(HELPERRORTEXT, _("Cancel"), NULL); + } - free(url); + free(url); } diff --git a/app/wlib/gtklib/button.c b/app/wlib/gtklib/button.c index 9a8ec77..7193b11 100644 --- a/app/wlib/gtklib/button.c +++ b/app/wlib/gtklib/button.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -53,17 +53,17 @@ void wButtonSetBusy(wButton_p bb, int value) { - bb->recursion++; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), value); - bb->recursion--; - bb->busy = value; - if (!value) { - if (bb->timer_id) { - g_source_remove(bb->timer_id); - bb->timer_id = 0; - } - bb->timer_state = -1; - } + bb->recursion++; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), value); + bb->recursion--; + bb->busy = value; + if (!value) { + if (bb->timer_id) { + g_source_remove(bb->timer_id); + bb->timer_id = 0; + } + bb->timer_state = -1; + } } /** @@ -77,57 +77,58 @@ void wButtonSetBusy(wButton_p bb, int value) */ void wlibSetLabel( - GtkWidget *widget, - long option, - const char * labelStr, - GtkLabel * * labelG, - GtkWidget * * imageG) + GtkWidget *widget, + long option, + const char * labelStr, + GtkLabel * * labelG, + GtkWidget * * imageG) { - wIcon_p bm; - GdkBitmap * mask; - - if (widget == 0) { - abort(); - } - - if (labelStr) { - if (option&BO_ICON) { - GdkPixbuf *pixbuf; - - bm = (wIcon_p)labelStr; - - if (bm->gtkIconType == gtkIcon_pixmap) { - pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)bm->bits); - } else { - pixbuf = wlibPixbufFromXBM( bm ); - } - double scaleicon; - wPrefGetFloat(PREFSECTION, LARGEICON, &scaleicon, 1.0); - if (scaleicon<1.0) scaleicon=1.0; - if (scaleicon>2.0) scaleicon=2.0; - GdkPixbuf *pixbuf2 = - gdk_pixbuf_scale_simple(pixbuf, gdk_pixbuf_get_width(pixbuf)*scaleicon, gdk_pixbuf_get_height(pixbuf)*scaleicon, GDK_INTERP_BILINEAR); - g_object_ref_sink(pixbuf); - g_object_unref((gpointer)pixbuf); - if (*imageG==NULL) { - *imageG = gtk_image_new_from_pixbuf(pixbuf2); - gtk_container_add(GTK_CONTAINER(widget), *imageG); - gtk_widget_show(*imageG); - } else { - gtk_image_set_from_pixbuf(GTK_IMAGE(*imageG), pixbuf2); - } - g_object_ref_sink(pixbuf2); - g_object_unref((gpointer)pixbuf2); - } else { - if (*labelG==NULL) { - *labelG = (GtkLabel*)gtk_label_new(wlibConvertInput(labelStr)); - gtk_container_add(GTK_CONTAINER(widget), (GtkWidget*)*labelG); - gtk_widget_show((GtkWidget*)*labelG); - } else { - gtk_label_set_text(*labelG, wlibConvertInput(labelStr)); - } - } - } + wIcon_p bm; +// GdkBitmap * mask; + + if (widget == 0) { + abort(); + } + + if (labelStr) { + if (option&BO_ICON) { + GdkPixbuf *pixbuf; + + bm = (wIcon_p)labelStr; + + if (bm->gtkIconType == gtkIcon_pixmap) { + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)bm->bits); + } else { + pixbuf = wlibPixbufFromXBM( bm ); + } + double scaleicon; + wPrefGetFloat(PREFSECTION, LARGEICON, &scaleicon, 1.0); + if (scaleicon<1.0) { scaleicon=1.0; } + if (scaleicon>2.0) { scaleicon=2.0; } + GdkPixbuf *pixbuf2 = + gdk_pixbuf_scale_simple(pixbuf, gdk_pixbuf_get_width(pixbuf)*scaleicon, + gdk_pixbuf_get_height(pixbuf)*scaleicon, GDK_INTERP_BILINEAR); + g_object_ref_sink(pixbuf); + g_object_unref((gpointer)pixbuf); + if (*imageG==NULL) { + *imageG = gtk_image_new_from_pixbuf(pixbuf2); + gtk_container_add(GTK_CONTAINER(widget), *imageG); + gtk_widget_show(*imageG); + } else { + gtk_image_set_from_pixbuf(GTK_IMAGE(*imageG), pixbuf2); + } + g_object_ref_sink(pixbuf2); + g_object_unref((gpointer)pixbuf2); + } else { + if (*labelG==NULL) { + *labelG = (GtkLabel*)gtk_label_new(wlibConvertInput(labelStr)); + gtk_container_add(GTK_CONTAINER(widget), (GtkWidget*)*labelG); + gtk_widget_show((GtkWidget*)*labelG); + } else { + gtk_label_set_text(*labelG, wlibConvertInput(labelStr)); + } + } + } } /** @@ -138,7 +139,7 @@ void wlibSetLabel( void wButtonSetLabel(wButton_p bb, const char * labelStr) { - wlibSetLabel(bb->widget, bb->option, labelStr, &bb->labelG, &bb->imageG); + wlibSetLabel(bb->widget, bb->option, labelStr, &bb->labelG, &bb->imageG); } /** @@ -148,11 +149,11 @@ void wButtonSetLabel(wButton_p bb, const char * labelStr) */ void wlibButtonDoAction( - wButton_p bb) + wButton_p bb) { - if (bb->action) { - bb->action(bb->data); - } + if (bb->action) { + bb->action(bb->data); + } } @@ -163,23 +164,23 @@ void wlibButtonDoAction( */ static void pushButt( - GtkWidget *widget, - gpointer value) + GtkWidget *widget, + gpointer value) { - wButton_p b = (wButton_p)value; + wButton_p b = (wButton_p)value; - if (debugWindow >= 2) { - printf("%s button pushed\n", b->labelStr?b->labelStr:"No label"); - } + if (debugWindow >= 2) { + printf("%s button pushed\n", b->labelStr?b->labelStr:"No label"); + } - if (b->recursion) { - return; - } + if (b->recursion) { + return; + } - wlibStringUpdate(); - if (b->action) { - b->action(b->data); - } + wlibStringUpdate(); + if (b->action) { + b->action(b->data); + } } @@ -192,52 +193,55 @@ static void pushButt( static int timer_func ( void * data) { wButton_p bb = (wButton_p)data; - if (bb->timer_id == 0) { - bb->timer_state = -1; - return FALSE; - } - /* Autorepeat state machine */ - switch (bb->timer_state) { - case 0: /* Enable slow auto-repeat */ - g_source_remove(bb->timer_id); - bb->timer_id = 0; - bb->timer_state = 1; - bb->timer_id = g_timeout_add( REPEAT_STAGE1_DELAY, timer_func, bb); - bb->timer_count = 0; - break; - case 1: /* Check if it's time for fast repeat yet */ - if (bb->timer_count++ > 10) - bb->timer_state = 2; - break; - case 2: /* Start fast auto-repeat */ - g_source_remove(bb->timer_id); - bb->timer_id = 0; - bb->timer_state = 3; - bb->timer_id = g_timeout_add( REPEAT_STAGE2_DELAY, timer_func, bb); - break; - case 3: - break; - default: - g_source_remove(bb->timer_id); - bb->timer_id = 0; - bb->timer_state = -1; - return FALSE; - break; - } - - pushButt(NULL,bb); - - return TRUE; + if (bb->timer_id == 0) { + bb->timer_state = -1; + return FALSE; + } + /* Autorepeat state machine */ + switch (bb->timer_state) { + case 0: /* Enable slow auto-repeat */ + g_source_remove(bb->timer_id); + bb->timer_id = 0; + bb->timer_state = 1; + bb->timer_id = g_timeout_add( REPEAT_STAGE1_DELAY, timer_func, bb); + bb->timer_count = 0; + break; + case 1: /* Check if it's time for fast repeat yet */ + if (bb->timer_count++ > 10) { + bb->timer_state = 2; + } + break; + case 2: /* Start fast auto-repeat */ + g_source_remove(bb->timer_id); + bb->timer_id = 0; + bb->timer_state = 3; + bb->timer_id = g_timeout_add( REPEAT_STAGE2_DELAY, timer_func, bb); + break; + case 3: + break; + default: + g_source_remove(bb->timer_id); + bb->timer_id = 0; + bb->timer_state = -1; + return FALSE; + break; + } + + pushButt(NULL,bb); + + return TRUE; } static gint pressButt( - GtkWidget *widget, - GdkEventButton *event, - wButton_p bb) { + GtkWidget *widget, + GdkEventButton *event, + wButton_p bb) +{ - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "buttonPress: %s\n", bb->labelStr ); + } if (bb->recursion) { return TRUE; @@ -246,20 +250,22 @@ static gint pressButt( if (bb->option & BO_REPEAT) { /* Remove an existing timer */ - if (bb->timer_id) - g_source_remove(bb->timer_id); + if (bb->timer_id) { + g_source_remove(bb->timer_id); + } - /* Setup a timer */ - bb->timer_id = g_timeout_add( REPEAT_STAGE0_DELAY, timer_func, bb); - bb->timer_state = 0; + /* Setup a timer */ + bb->timer_id = g_timeout_add( REPEAT_STAGE0_DELAY, timer_func, bb); + bb->timer_state = 0; } if (!bb->busy) { bb->recursion++; int sensitive = gtk_widget_get_sensitive (GTK_WIDGET(bb->widget)); - if (sensitive) + if (sensitive) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bb->widget), TRUE); + } bb->recursion--; } @@ -269,16 +275,18 @@ static gint pressButt( } static gint releaseButt( - GtkWidget *widget, - GdkEventButton *event, - wButton_p bb) { + GtkWidget *widget, + GdkEventButton *event, + wButton_p bb) +{ - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "buttonRelease: %s\n", bb->labelStr ); + } /* Remove any existing timer */ if (bb->timer_id) { - g_source_remove(bb->timer_id); - bb->timer_id = 0; + g_source_remove(bb->timer_id); + bb->timer_id = 0; } bb->timer_state = -1; @@ -298,9 +306,9 @@ static gint releaseButt( * Called after expose event default hander - allows the button to be outlined */ static wBool_t exposeButt( - GtkWidget *widget, - GdkEventExpose *event, - gpointer g) + GtkWidget *widget, + GdkEventExpose *event, + gpointer g) { wControl_p b = (wControl_p)g; return wControlExpose(widget,event,b); @@ -322,61 +330,62 @@ static wBool_t exposeButt( */ wButton_p wButtonCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - wButtonCallBack_p action, - void * data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + wButtonCallBack_p action, + void * data) { - wButton_p b; - if (option&BO_ICON) //The labelStr here is a wIcon_p - b = wlibAlloc(parent, B_BUTTON, x, y, " ", sizeof *b, data); - else - b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, data); - b->option = option; - b->action = action; - wlibComputePos((wControl_p)b); - - b->widget = gtk_toggle_button_new(); - g_signal_connect(GTK_OBJECT(b->widget), "button_press_event", - G_CALLBACK(pressButt), b); - g_signal_connect(GTK_OBJECT(b->widget), "button_release_event", - G_CALLBACK(releaseButt), b); - //g_signal_connect(GTK_OBJECT(b->widget), "clicked", - // G_CALLBACK(pushButt), b); - g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", - G_CALLBACK(exposeButt), b); - if (width > 0) { - gtk_widget_set_size_request(b->widget, width, -1); - } - - if( labelStr ){ - wButtonSetLabel(b, labelStr); - } - - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - - if (option & BB_DEFAULT) { - gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT); - gtk_widget_grab_default(b->widget); - gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget); - } - - wlibControlGetSize((wControl_p)b); - - if (width == 0 && b->w < MIN_BUTTON_WIDTH && (b->option&BO_ICON)==0) { - b->w = MIN_BUTTON_WIDTH; - gtk_widget_set_size_request(b->widget, b->w, b->h); - } - - gtk_widget_show(b->widget); - wlibAddButton((wControl_p)b); - wlibAddHelpString(b->widget, helpStr); - return b; + wButton_p b; + if (option&BO_ICON) { //The labelStr here is a wIcon_p + b = wlibAlloc(parent, B_BUTTON, x, y, " ", sizeof *b, data); + } else { + b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, data); + } + b->option = option; + b->action = action; + wlibComputePos((wControl_p)b); + + b->widget = gtk_toggle_button_new(); + g_signal_connect(GTK_OBJECT(b->widget), "button_press_event", + G_CALLBACK(pressButt), b); + g_signal_connect(GTK_OBJECT(b->widget), "button_release_event", + G_CALLBACK(releaseButt), b); + //g_signal_connect(GTK_OBJECT(b->widget), "clicked", + // G_CALLBACK(pushButt), b); + g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", + G_CALLBACK(exposeButt), b); + if (width > 0) { + gtk_widget_set_size_request(b->widget, width, -1); + } + + if( labelStr ) { + wButtonSetLabel(b, labelStr); + } + + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + + if (option & BB_DEFAULT) { + gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT); + gtk_widget_grab_default(b->widget); + gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget); + } + + wlibControlGetSize((wControl_p)b); + + if (width == 0 && b->w < MIN_BUTTON_WIDTH && (b->option&BO_ICON)==0) { + b->w = MIN_BUTTON_WIDTH; + gtk_widget_set_size_request(b->widget, b->w, b->h); + } + + gtk_widget_show(b->widget); + wlibAddButton((wControl_p)b); + wlibAddHelpString(b->widget, helpStr); + return b; } @@ -389,10 +398,10 @@ wButton_p wButtonCreate( */ struct wChoice_t { - WOBJ_COMMON - long *valueP; - wChoiceCallBack_p action; - int recursion; + WOBJ_COMMON + long *valueP; + wChoiceCallBack_p action; + int recursion; }; @@ -407,33 +416,33 @@ struct wChoice_t { */ static long choiceGetValue( - wChoice_p bc) + wChoice_p bc) { - GList * child, * children; - long value, inx; - - if (bc->type == B_TOGGLE) { - value = 0; - } else { - value = -1; - } - - for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0; - child; child=child->next,inx++) { - if (gtk_toggle_button_get_active(child->data)) { - if (bc->type == B_TOGGLE) { - value |= (1<<inx); - } else { - value = inx; - } - } - } - - if (children) { - g_list_free(children); - } - - return value; + GList * child, * children; + long value, inx; + + if (bc->type == B_TOGGLE) { + value = 0; + } else { + value = -1; + } + + for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0; + child; child=child->next,inx++) { + if (gtk_toggle_button_get_active(child->data)) { + if (bc->type == B_TOGGLE) { + value |= (1<<inx); + } else { + value = inx; + } + } + } + + if (children) { + g_list_free(children); + } + + return value; } /** @@ -444,24 +453,24 @@ static long choiceGetValue( */ void wRadioSetValue( - wChoice_p bc, /* Radio box */ - long value) /* Value */ + wChoice_p bc, /* Radio box */ + long value) /* Value */ { - GList * child, * children; - long inx; - - for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0; - child; child=child->next,inx++) { - if (inx == value) { - bc->recursion++; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data), TRUE); - bc->recursion--; - } - } - - if (children) { - g_list_free(children); - } + GList * child, * children; + long inx; + + for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0; + child; child=child->next,inx++) { + if (inx == value) { + bc->recursion++; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data), TRUE); + bc->recursion--; + } + } + + if (children) { + g_list_free(children); + } } /** @@ -472,9 +481,9 @@ void wRadioSetValue( */ long wRadioGetValue( - wChoice_p bc) /* Radio box */ + wChoice_p bc) /* Radio box */ { - return choiceGetValue(bc); + return choiceGetValue(bc); } /** @@ -485,24 +494,24 @@ long wRadioGetValue( */ void wToggleSetValue( - wChoice_p bc, /* Toggle box */ - long value) /* Values */ + wChoice_p bc, /* Toggle box */ + long value) /* Values */ { - GList * child, * children; - long inx; - bc->recursion++; - - for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0; - child; child=child->next,inx++) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data), - (value&(1<<inx))!=0); - } + GList * child, * children; + long inx; + bc->recursion++; + + for (children=child=gtk_container_get_children(GTK_CONTAINER(bc->widget)),inx=0; + child; child=child->next,inx++) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(child->data), + (value&(1<<inx))!=0); + } - if (children) { - g_list_free(children); - } + if (children) { + g_list_free(children); + } - bc->recursion--; + bc->recursion--; } @@ -514,9 +523,9 @@ void wToggleSetValue( */ long wToggleGetValue( - wChoice_p b) /* Toggle box */ + wChoice_p b) /* Toggle box */ { - return choiceGetValue(b); + return choiceGetValue(b); } /** @@ -529,35 +538,35 @@ long wToggleGetValue( */ static int pushChoice( - GtkWidget *widget, - gpointer b) + GtkWidget *widget, + gpointer b) { - wChoice_p bc = (wChoice_p)b; - long value = choiceGetValue(bc); + wChoice_p bc = (wChoice_p)b; + long value = choiceGetValue(bc); - if (debugWindow >= 2) { - printf("%s choice pushed = %ld\n", bc->labelStr?bc->labelStr:"No label", - value); - } + if (debugWindow >= 2) { + printf("%s choice pushed = %ld\n", bc->labelStr?bc->labelStr:"No label", + value); + } - if (bc->type == B_RADIO && - !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))) { - return 1; - } + if (bc->type == B_RADIO && + !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))) { + return 1; + } - if (bc->recursion) { - return 1; - } + if (bc->recursion) { + return 1; + } - if (bc->valueP) { - *bc->valueP = value; - } + if (bc->valueP) { + *bc->valueP = value; + } - if (bc->action) { - bc->action(value, bc->data); - } + if (bc->action) { + bc->action(value, bc->data); + } - return 1; + return 1; } /** @@ -568,13 +577,13 @@ static int pushChoice( */ static void choiceRepaint( - wControl_p b) + wControl_p b) { - wChoice_p bc = (wChoice_p)b; + wChoice_p bc = (wChoice_p)b; - if (gtk_widget_get_visible(b->widget)) { - wlibDrawBox(bc->parent, wBoxBelow, bc->realX-1, bc->realY-1, bc->w+1, bc->h+1); - } + if (gtk_widget_get_visible(b->widget)) { + wlibDrawBox(bc->parent, wBoxBelow, bc->realX-1, bc->realY-1, bc->w+1, bc->h+1); + } } /** @@ -594,95 +603,95 @@ static void choiceRepaint( */ wChoice_p wRadioCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - const char * const *labels, - long *valueP, - wChoiceCallBack_p action, - void *data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + const char * const *labels, + long *valueP, + wChoiceCallBack_p action, + void *data) { - wChoice_p b; - const char * const * label; - GtkWidget *butt0=NULL, *butt; - - if ((option & BC_NOBORDER)==0) { - if (x>=0) { - x++; - } else { - x--; - } - - if (y>=0) { - y++; - } else { - y--; - } - } - - b = wlibAlloc(parent, B_RADIO, x, y, labelStr, sizeof *b, data); - b->option = option; - b->action = action; - b->valueP = valueP; - wlibComputePos((wControl_p)b); - - ((wControl_p)b)->outline = FALSE; - - if (option&BC_HORZ) { - b->widget = gtk_hbox_new(FALSE, 0); - } else { - b->widget = gtk_vbox_new(FALSE, 0); - } - - if (b->widget == 0) { - abort(); - } - - for (label=labels; *label; label++) { - butt = gtk_radio_button_new_with_label( - butt0?gtk_radio_button_get_group(GTK_RADIO_BUTTON(butt0)):NULL, _(*label)); - - if (butt0==NULL) { - butt0 = butt; - } - - gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0); - gtk_widget_show(butt); - g_signal_connect(GTK_OBJECT(butt), "toggled", - G_CALLBACK(pushChoice), b); - g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", - G_CALLBACK(exposeButt), b); - wlibAddHelpString(butt, helpStr); - } - - if (option & BB_DEFAULT) { - gtk_widget_set_can_default(b->widget, TRUE); - gtk_widget_grab_default(b->widget); - } - - if (valueP) { - wRadioSetValue(b, *valueP); - } - - if ((option & BC_NOBORDER)==0) { - b->repaintProc = choiceRepaint; - b->w += 2; - b->h += 2; - } - - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - wlibControlGetSize((wControl_p)b); - - if (labelStr) { - b->labelW = wlibAddLabel((wControl_p)b, labelStr); - } - - gtk_widget_show(b->widget); - wlibAddButton((wControl_p)b); - return b; + wChoice_p b; + const char * const * label; + GtkWidget *butt0=NULL, *butt; + + if ((option & BC_NOBORDER)==0) { + if (x>=0) { + x++; + } else { + x--; + } + + if (y>=0) { + y++; + } else { + y--; + } + } + + b = wlibAlloc(parent, B_RADIO, x, y, labelStr, sizeof *b, data); + b->option = option; + b->action = action; + b->valueP = valueP; + wlibComputePos((wControl_p)b); + + ((wControl_p)b)->outline = FALSE; + + if (option&BC_HORZ) { + b->widget = gtk_hbox_new(FALSE, 0); + } else { + b->widget = gtk_vbox_new(FALSE, 0); + } + + if (b->widget == 0) { + abort(); + } + + for (label=labels; *label; label++) { + butt = gtk_radio_button_new_with_label( + butt0?gtk_radio_button_get_group(GTK_RADIO_BUTTON(butt0)):NULL, _(*label)); + + if (butt0==NULL) { + butt0 = butt; + } + + gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0); + gtk_widget_show(butt); + g_signal_connect(GTK_OBJECT(butt), "toggled", + G_CALLBACK(pushChoice), b); + g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", + G_CALLBACK(exposeButt), b); + wlibAddHelpString(butt, helpStr); + } + + if (option & BB_DEFAULT) { + gtk_widget_set_can_default(b->widget, TRUE); + gtk_widget_grab_default(b->widget); + } + + if (valueP) { + wRadioSetValue(b, *valueP); + } + + if ((option & BC_NOBORDER)==0) { + b->repaintProc = choiceRepaint; + b->w += 2; + b->h += 2; + } + + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + wlibControlGetSize((wControl_p)b); + + if (labelStr) { + b->labelW = wlibAddLabel((wControl_p)b, labelStr); + } + + gtk_widget_show(b->widget); + wlibAddButton((wControl_p)b); + return b; } /** @@ -702,82 +711,82 @@ wChoice_p wRadioCreate( */ wChoice_p wToggleCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - const char * const * labels, - long *valueP, - wChoiceCallBack_p action, - void *data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + const char * const * labels, + long *valueP, + wChoiceCallBack_p action, + void *data) { - wChoice_p b; - const char * const * label; - - if ((option & BC_NOBORDER)==0) { - if (x>=0) { - x++; - } else { - x--; - } - - if (y>=0) { - y++; - } else { - y--; - } - } - - b = wlibAlloc(parent, B_TOGGLE, x, y, labelStr, sizeof *b, data); - b->option = option; - b->action = action; - wlibComputePos((wControl_p)b); - - ((wControl_p)b)->outline = FALSE; - - if (option&BC_HORZ) { - b->widget = gtk_hbox_new(FALSE, 0); - } else { - b->widget = gtk_vbox_new(FALSE, 0); - } - - if (b->widget == 0) { - abort(); - } - - for (label=labels; *label; label++) { - GtkWidget *butt; - - butt = gtk_check_button_new_with_label(_(*label)); - gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0); - gtk_widget_show(butt); - g_signal_connect(GTK_OBJECT(butt), "toggled", - G_CALLBACK(pushChoice), b); - g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", - G_CALLBACK(exposeButt), b); - wlibAddHelpString(butt, helpStr); - } - - if (valueP) { - wToggleSetValue(b, *valueP); - } - - if ((option & BC_NOBORDER)==0) { - b->repaintProc = choiceRepaint; - b->w += 2; - b->h += 2; - } - - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - wlibControlGetSize((wControl_p)b); - - if (labelStr) { - b->labelW = wlibAddLabel((wControl_p)b, labelStr); - } - - gtk_widget_show(b->widget); - wlibAddButton((wControl_p)b); - return b; + wChoice_p b; + const char * const * label; + + if ((option & BC_NOBORDER)==0) { + if (x>=0) { + x++; + } else { + x--; + } + + if (y>=0) { + y++; + } else { + y--; + } + } + + b = wlibAlloc(parent, B_TOGGLE, x, y, labelStr, sizeof *b, data); + b->option = option; + b->action = action; + wlibComputePos((wControl_p)b); + + ((wControl_p)b)->outline = FALSE; + + if (option&BC_HORZ) { + b->widget = gtk_hbox_new(FALSE, 0); + } else { + b->widget = gtk_vbox_new(FALSE, 0); + } + + if (b->widget == 0) { + abort(); + } + + for (label=labels; *label; label++) { + GtkWidget *butt; + + butt = gtk_check_button_new_with_label(_(*label)); + gtk_box_pack_start(GTK_BOX(b->widget), butt, TRUE, TRUE, 0); + gtk_widget_show(butt); + g_signal_connect(GTK_OBJECT(butt), "toggled", + G_CALLBACK(pushChoice), b); + g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", + G_CALLBACK(exposeButt), b); + wlibAddHelpString(butt, helpStr); + } + + if (valueP) { + wToggleSetValue(b, *valueP); + } + + if ((option & BC_NOBORDER)==0) { + b->repaintProc = choiceRepaint; + b->w += 2; + b->h += 2; + } + + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + wlibControlGetSize((wControl_p)b); + + if (labelStr) { + b->labelW = wlibAddLabel((wControl_p)b, labelStr); + } + + gtk_widget_show(b->widget); + wlibAddButton((wControl_p)b); + return b; } diff --git a/app/wlib/gtklib/color.c b/app/wlib/gtklib/color.c index fee4a80..d193872 100644 --- a/app/wlib/gtklib/color.c +++ b/app/wlib/gtklib/color.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <assert.h> #include <stdlib.h> @@ -45,62 +45,62 @@ wDrawColor wDrawColorBlack; static GArray *colorMap_garray = NULL; // Change to use glib array static colorMap_t colorMap[] = { - { 255, 255, 255 }, /* White */ - { 0, 0, 0 }, /* Black */ - { 255, 0, 0 }, /* Red */ - { 0, 255, 0 }, /* Green */ - { 0, 0, 255 }, /* Blue */ - { 255, 255, 0 }, /* Yellow */ - { 255, 0, 255 }, /* Purple */ - { 0, 255, 255 }, /* Aqua */ - { 128, 0, 0 }, /* Dk. Red */ - { 0, 128, 0 }, /* Dk. Green */ - { 0, 0, 128 }, /* Dk. Blue */ - { 128, 128, 0 }, /* Dk. Yellow */ - { 128, 0, 128 }, /* Dk. Purple */ - { 0, 128, 128 }, /* Dk. Aqua */ - { 65, 105, 225 }, /* Royal Blue */ - { 0, 191, 255 }, /* DeepSkyBlue */ - { 125, 206, 250 }, /* LightSkyBlue */ - { 70, 130, 180 }, /* Steel Blue */ - { 176, 224, 230 }, /* Powder Blue */ - { 127, 255, 212 }, /* Aquamarine */ - { 46, 139, 87 }, /* SeaGreen */ - { 152, 251, 152 }, /* PaleGreen */ - { 124, 252, 0 }, /* LawnGreen */ - { 50, 205, 50 }, /* LimeGreen */ - { 34, 139, 34 }, /* ForestGreen */ - { 255, 215, 0 }, /* Gold */ - { 188, 143, 143 }, /* RosyBrown */ - { 139, 69, 19 }, /* SaddleBrown */ - { 245, 245, 220 }, /* Beige */ - { 210, 180, 140 }, /* Tan */ - { 210, 105, 30 }, /* Chocolate */ - { 165, 42, 42 }, /* Brown */ - { 255, 165, 0 }, /* Orange */ - { 255, 127, 80 }, /* Coral */ - { 255, 99, 71 }, /* Tomato */ - { 255, 105, 180 }, /* HotPink */ - { 255, 192, 203 }, /* Pink */ - { 176, 48, 96 }, /* Maroon */ - { 238, 130, 238 }, /* Violet */ - { 160, 32, 240 }, /* Purple */ - { 16, 16, 16 }, /* Gray */ - { 32, 32, 32 }, /* Gray */ - { 48, 48, 48 }, /* Gray */ - { 64, 64, 64 }, /* Gray */ - { 80, 80, 80 }, /* Gray */ - { 96, 96, 96 }, /* Gray */ - { 112, 112, 122 }, /* Gray */ - { 128, 128, 128 }, /* Gray */ - { 144, 144, 144 }, /* Gray */ - { 160, 160, 160 }, /* Gray */ - { 176, 176, 176 }, /* Gray */ - { 192, 192, 192 }, /* Gray */ - { 208, 208, 208 }, /* Gray */ - { 224, 224, 224 }, /* Gray */ - { 240, 240, 240 }, /* Gray */ - { 255, 255, 255 } /* WhitePixel */ + { 255, 255, 255 }, /* White */ + { 0, 0, 0 }, /* Black */ + { 255, 0, 0 }, /* Red */ + { 0, 255, 0 }, /* Green */ + { 0, 0, 255 }, /* Blue */ + { 255, 255, 0 }, /* Yellow */ + { 255, 0, 255 }, /* Purple */ + { 0, 255, 255 }, /* Aqua */ + { 128, 0, 0 }, /* Dk. Red */ + { 0, 128, 0 }, /* Dk. Green */ + { 0, 0, 128 }, /* Dk. Blue */ + { 128, 128, 0 }, /* Dk. Yellow */ + { 128, 0, 128 }, /* Dk. Purple */ + { 0, 128, 128 }, /* Dk. Aqua */ + { 65, 105, 225 }, /* Royal Blue */ + { 0, 191, 255 }, /* DeepSkyBlue */ + { 125, 206, 250 }, /* LightSkyBlue */ + { 70, 130, 180 }, /* Steel Blue */ + { 176, 224, 230 }, /* Powder Blue */ + { 127, 255, 212 }, /* Aquamarine */ + { 46, 139, 87 }, /* SeaGreen */ + { 152, 251, 152 }, /* PaleGreen */ + { 124, 252, 0 }, /* LawnGreen */ + { 50, 205, 50 }, /* LimeGreen */ + { 34, 139, 34 }, /* ForestGreen */ + { 255, 215, 0 }, /* Gold */ + { 188, 143, 143 }, /* RosyBrown */ + { 139, 69, 19 }, /* SaddleBrown */ + { 245, 245, 220 }, /* Beige */ + { 210, 180, 140 }, /* Tan */ + { 210, 105, 30 }, /* Chocolate */ + { 165, 42, 42 }, /* Brown */ + { 255, 165, 0 }, /* Orange */ + { 255, 127, 80 }, /* Coral */ + { 255, 99, 71 }, /* Tomato */ + { 255, 105, 180 }, /* HotPink */ + { 255, 192, 203 }, /* Pink */ + { 176, 48, 96 }, /* Maroon */ + { 238, 130, 238 }, /* Violet */ + { 160, 32, 240 }, /* Purple */ + { 16, 16, 16 }, /* Gray */ + { 32, 32, 32 }, /* Gray */ + { 48, 48, 48 }, /* Gray */ + { 64, 64, 64 }, /* Gray */ + { 80, 80, 80 }, /* Gray */ + { 96, 96, 96 }, /* Gray */ + { 112, 112, 122 }, /* Gray */ + { 128, 128, 128 }, /* Gray */ + { 144, 144, 144 }, /* Gray */ + { 160, 160, 160 }, /* Gray */ + { 176, 176, 176 }, /* Gray */ + { 192, 192, 192 }, /* Gray */ + { 208, 208, 208 }, /* Gray */ + { 224, 224, 224 }, /* Gray */ + { 240, 240, 240 }, /* Gray */ + { 255, 255, 255 } /* WhitePixel */ }; #define NUM_GRAYS (16) @@ -117,21 +117,21 @@ static char lastColorChar = '!'; */ wDrawColor wDrawColorGray( - int percent) + int percent) { - int n; - long rgb; - n = (percent * (NUM_GRAYS+1)) / 100; - - if (n <= 0) { - return wDrawColorBlack; - } else if (n >= NUM_GRAYS) { - return wDrawColorWhite; - } else { - n = (n*256)/NUM_GRAYS; - rgb = RGB(n, n, n); - return wDrawFindColor(rgb); - } + int n; + long rgb; + n = (percent * (NUM_GRAYS+1)) / 100; + + if (n <= 0) { + return wDrawColorBlack; + } else if (n >= NUM_GRAYS) { + return wDrawColorWhite; + } else { + n = (n*256)/NUM_GRAYS; + rgb = RGB(n, n, n); + return wDrawFindColor(rgb); + } } /** @@ -142,12 +142,12 @@ wDrawColor wDrawColorGray( void wlibGetColorMap(void) { - if (gtkColorMap) { - return; - } + if (gtkColorMap) { + return; + } - gtkColorMap = gtk_widget_get_colormap(gtkMainW->widget); - return; + gtkColorMap = gtk_widget_get_colormap(gtkMainW->widget); + return; } /** @@ -160,21 +160,21 @@ void wlibGetColorMap(void) static void init_colorMapValue(colorMap_t * t) { - t->rgb = RGB(t->red, t->green, t->blue); - t->normalColor.red = t->red*65535/255; - t->normalColor.green = t->green*65535/255; - t->normalColor.blue = t->blue*65535/255; - gdk_colormap_alloc_color(gtkColorMap, &t->normalColor, FALSE, TRUE); - t->invertColor = t->normalColor; - t->invertColor.pixel ^= g_array_index(colorMap_garray, colorMap_t, - wDrawColorWhite).normalColor.pixel; - t->colorChar = lastColorChar++; - - if (lastColorChar >= 0x7F) { - lastColorChar = '!'+1; - } else if (lastColorChar == '"') { - lastColorChar++; - } + t->rgb = RGB(t->red, t->green, t->blue); + t->normalColor.red = t->red*65535/255; + t->normalColor.green = t->green*65535/255; + t->normalColor.blue = t->blue*65535/255; + gdk_colormap_alloc_color(gtkColorMap, &t->normalColor, FALSE, TRUE); + t->invertColor = t->normalColor; + t->invertColor.pixel ^= g_array_index(colorMap_garray, colorMap_t, + wDrawColorWhite).normalColor.pixel; + t->colorChar = lastColorChar++; + + if (lastColorChar >= 0x7F) { + lastColorChar = '!'+1; + } else if (lastColorChar == '"') { + lastColorChar++; + } } /** @@ -185,15 +185,15 @@ static void init_colorMapValue(colorMap_t * t) static void init_colorMap(void) { - int gint; - colorMap_garray = g_array_sized_new(TRUE, TRUE, sizeof(colorMap_t), - sizeof(colorMap)/sizeof(colorMap_t)); - g_array_append_vals(colorMap_garray, &colorMap, - sizeof(colorMap)/sizeof(colorMap_t)); - - for (gint=0; gint<colorMap_garray->len; gint++) { - init_colorMapValue(&g_array_index(colorMap_garray, colorMap_t, gint)); - } + int gint; + colorMap_garray = g_array_sized_new(TRUE, TRUE, sizeof(colorMap_t), + sizeof(colorMap)/sizeof(colorMap_t)); + g_array_append_vals(colorMap_garray, &colorMap, + sizeof(colorMap)/sizeof(colorMap_t)); + + for (gint=0; gint<colorMap_garray->len; gint++) { + init_colorMapValue(&g_array_index(colorMap_garray, colorMap_t, gint)); + } } /** @@ -206,57 +206,57 @@ static void init_colorMap(void) */ wDrawColor wDrawFindColor( - long rgb0) + long rgb0) { - wDrawColor cc; - int r0, g0, b0, r1, g1, b1; - int d0; - int i; - colorMap_t tempMapValue; - wlibGetColorMap(); - cc = wDrawColorBlack; - r0 = (int)(rgb0>>16)&0xFF; - g0 = (int)(rgb0>>8)&0xFF; - b0 = (int)(rgb0)&0xFF; - d0 = 256*3; - - // Initialize garray if needed - if (colorMap_garray == NULL) { - init_colorMap(); - } - - // Iterate over entire garray - for (i=0; i<colorMap_garray->len; i++) { - int d1; - colorMap_t * cm_p; - - cm_p = &g_array_index(colorMap_garray, colorMap_t, i); - r1 = (int)cm_p->red; - g1 = (int)cm_p->green; - b1 = (int)cm_p->blue; - d1 = abs(r0-r1) + abs(g0-g1) + abs(b0-b1); - - if (d1 == 0) { - return i; - } - - if (d1 < d0) { - d0 = d1; - cc = i; - } - } - - if (d0 <= MAX_COLOR_DISTANCE) { - return cc; - } - - // No good value - so add one - tempMapValue.red = r0; - tempMapValue.green = g0; - tempMapValue.blue = b0; - init_colorMapValue(&tempMapValue); - g_array_append_val(colorMap_garray,tempMapValue); - return i; + wDrawColor cc; + int r0, g0, b0, r1, g1, b1; + int d0; + int i; + colorMap_t tempMapValue; + wlibGetColorMap(); + cc = wDrawColorBlack; + r0 = (int)(rgb0>>16)&0xFF; + g0 = (int)(rgb0>>8)&0xFF; + b0 = (int)(rgb0)&0xFF; + d0 = 256*3; + + // Initialize garray if needed + if (colorMap_garray == NULL) { + init_colorMap(); + } + + // Iterate over entire garray + for (i=0; i<colorMap_garray->len; i++) { + int d1; + colorMap_t * cm_p; + + cm_p = &g_array_index(colorMap_garray, colorMap_t, i); + r1 = (int)cm_p->red; + g1 = (int)cm_p->green; + b1 = (int)cm_p->blue; + d1 = abs(r0-r1) + abs(g0-g1) + abs(b0-b1); + + if (d1 == 0) { + return i; + } + + if (d1 < d0) { + d0 = d1; + cc = i; + } + } + + if (d0 <= MAX_COLOR_DISTANCE) { + return cc; + } + + // No good value - so add one + tempMapValue.red = r0; + tempMapValue.green = g0; + tempMapValue.blue = b0; + init_colorMapValue(&tempMapValue); + g_array_append_val(colorMap_garray,tempMapValue); + return i; } /** @@ -267,21 +267,21 @@ wDrawColor wDrawFindColor( */ long wDrawGetRGB( - wDrawColor color) + wDrawColor color) { - colorMap_t * colorMap_e; - wlibGetColorMap(); + colorMap_t * colorMap_e; + wlibGetColorMap(); - if (colorMap_garray == NULL) { - init_colorMap(); - } + if (colorMap_garray == NULL) { + init_colorMap(); + } - if (color < 0 || color > colorMap_garray->len) { - abort(); - } + if (color < 0 || color > colorMap_garray->len) { + abort(); + } - colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color); - return colorMap_e->rgb; + colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color); + return colorMap_e->rgb; } /** @@ -293,27 +293,27 @@ long wDrawGetRGB( */ GdkColor* wlibGetColor( - wDrawColor color, - wBool_t normal) + wDrawColor color, + wBool_t normal) { - colorMap_t * colorMap_e; - wlibGetColorMap(); + colorMap_t * colorMap_e; + wlibGetColorMap(); - if (colorMap_garray == NULL) { - init_colorMap(); - } + if (colorMap_garray == NULL) { + init_colorMap(); + } - if (color < 0 || color > colorMap_garray->len) { - abort(); - } + if (color < 0 || color > colorMap_garray->len) { + abort(); + } - colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color); + colorMap_e = &g_array_index(colorMap_garray, colorMap_t, color); - if (normal) { - return &colorMap_e->normalColor; - } else { - return &colorMap_e->invertColor; - } + if (normal) { + return &colorMap_e->normalColor; + } else { + return &colorMap_e->invertColor; + } } @@ -326,12 +326,12 @@ GdkColor* wlibGetColor( */ typedef struct { - wDrawColor * valueP; - const char * labelStr; - wColorSelectButtonCallBack_p action; - void * data; - wDrawColor color; - wButton_p button; + wDrawColor * valueP; + const char * labelStr; + wColorSelectButtonCallBack_p action; + void * data; + wDrawColor color; + wButton_p button; } colorData_t; /** @@ -344,23 +344,23 @@ typedef struct { static void colorChange(GtkColorButton *widget, gpointer user_data) { - colorData_t *cd = user_data; - GdkColor newcolor; - long rgb; + colorData_t *cd = user_data; + GdkColor newcolor; + long rgb; - gtk_color_button_get_color(widget, &newcolor); + gtk_color_button_get_color(widget, &newcolor); - rgb = RGB((int)(newcolor.red/256), (int)(newcolor.green/256), - (int)(newcolor.blue/256)); - cd->color = wDrawFindColor(rgb); + rgb = RGB((int)(newcolor.red/256), (int)(newcolor.green/256), + (int)(newcolor.blue/256)); + cd->color = wDrawFindColor(rgb); - if (cd->valueP) { - *(cd->valueP) = cd->color; - } + if (cd->valueP) { + *(cd->valueP) = cd->color; + } - if (cd->action) { - cd->action(cd->data, cd->color); - } + if (cd->action) { + cd->action(cd->data, cd->color); + } } /** @@ -372,14 +372,14 @@ colorChange(GtkColorButton *widget, gpointer user_data) */ void wColorSelectButtonSetColor( - wButton_p bb, - wDrawColor color) + wButton_p bb, + wDrawColor color) { - GdkColor *colorOfButton = wlibGetColor(color, TRUE); + GdkColor *colorOfButton = wlibGetColor(color, TRUE); - gtk_color_button_set_color(GTK_COLOR_BUTTON(bb->widget), - colorOfButton); - ((colorData_t*)((wControl_p)bb)->data)->color = color; + gtk_color_button_set_color(GTK_COLOR_BUTTON(bb->widget), + colorOfButton); + ((colorData_t*)((wControl_p)bb)->data)->color = color; } @@ -391,9 +391,9 @@ void wColorSelectButtonSetColor( */ wDrawColor wColorSelectButtonGetColor( - wButton_p bb) + wButton_p bb) { - return ((colorData_t*)((wControl_p)bb)->data)->color; + return ((colorData_t*)((wControl_p)bb)->data)->color; } /** @@ -413,57 +413,57 @@ wDrawColor wColorSelectButtonGetColor( */ wButton_p wColorSelectButtonCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - wWinPix_t width, - wDrawColor *valueP, - wColorSelectButtonCallBack_p action, - void * data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + wWinPix_t width, + wDrawColor *valueP, + wColorSelectButtonCallBack_p action, + void * data) { - wButton_p b; - colorData_t * cd; - cd = malloc(sizeof(colorData_t)); - cd->valueP = valueP; - cd->action = action; - cd->data = data; - cd->labelStr = labelStr; - cd->color = (valueP?*valueP:0); - - b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, cd); - b->option = option; - wlibComputePos((wControl_p)b); - - b->widget = gtk_color_button_new(); - GtkStyle *style; - style = gtk_widget_get_style(b->widget); - style->xthickness = 1; - style->ythickness = 1; - gtk_widget_set_style(b->widget, style); - gtk_widget_set_size_request(GTK_WIDGET(b->widget), 22, 22); - g_signal_connect(GTK_OBJECT(b->widget), "color-set", - G_CALLBACK(colorChange), cd); - - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - - if (option & BB_DEFAULT) { - gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT); - gtk_widget_grab_default(b->widget); - gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget); - } - - wlibControlGetSize((wControl_p)b); - - gtk_widget_show(b->widget); - wlibAddButton((wControl_p)b); - wlibAddHelpString(b->widget, helpStr); - wColorSelectButtonSetColor(b, (valueP?*valueP:0)); - - if (labelStr) { - ((wControl_p)b)->labelW = wlibAddLabel((wControl_p)b, labelStr); - } - return b; + wButton_p b; + colorData_t * cd; + cd = malloc(sizeof(colorData_t)); + cd->valueP = valueP; + cd->action = action; + cd->data = data; + cd->labelStr = labelStr; + cd->color = (valueP?*valueP:0); + + b = wlibAlloc(parent, B_BUTTON, x, y, labelStr, sizeof *b, cd); + b->option = option; + wlibComputePos((wControl_p)b); + + b->widget = gtk_color_button_new(); + GtkStyle *style; + style = gtk_widget_get_style(b->widget); + style->xthickness = 1; + style->ythickness = 1; + gtk_widget_set_style(b->widget, style); + gtk_widget_set_size_request(GTK_WIDGET(b->widget), 22, 22); + g_signal_connect(GTK_OBJECT(b->widget), "color-set", + G_CALLBACK(colorChange), cd); + + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + + if (option & BB_DEFAULT) { + gtk_widget_set_can_default(b->widget, GTK_CAN_DEFAULT); + gtk_widget_grab_default(b->widget); + gtk_window_set_default(GTK_WINDOW(parent->gtkwin), b->widget); + } + + wlibControlGetSize((wControl_p)b); + + gtk_widget_show(b->widget); + wlibAddButton((wControl_p)b); + wlibAddHelpString(b->widget, helpStr); + wColorSelectButtonSetColor(b, (valueP?*valueP:0)); + + if (labelStr) { + ((wControl_p)b)->labelW = wlibAddLabel((wControl_p)b, labelStr); + } + return b; } diff --git a/app/wlib/gtklib/control.c b/app/wlib/gtklib/control.c index 0332470..d43d2b6 100644 --- a/app/wlib/gtklib/control.c +++ b/app/wlib/gtklib/control.c @@ -1,7 +1,7 @@ /** \file control.c * Control Utilities */ -/* +/* * Copyright 2016 Martin Fischer <m_fischer@sf.net> * * This program is free software; you can redistribute it and/or modify @@ -46,31 +46,31 @@ */ void wControlShow( - wControl_p b, - wBool_t show) + wControl_p b, + wBool_t show) { - if (b->type == B_LINES) { - wlibLineShow((wLine_p)b, show); - return; - } - - if (b->widget == NULL) { - abort(); - } - - if (show) { - gtk_widget_show(b->widget); - - if (b->label) { - gtk_widget_show(b->label); - } - } else { - gtk_widget_hide(b->widget); - - if (b->label) { - gtk_widget_hide(b->label); - } - } + if (b->type == B_LINES) { + wlibLineShow((wLine_p)b, show); + return; + } + + if (b->widget == NULL) { + abort(); + } + + if (show) { + gtk_widget_show(b->widget); + + if (b->label) { + gtk_widget_show(b->label); + } + } else { + gtk_widget_hide(b->widget); + + if (b->label) { + gtk_widget_hide(b->label); + } + } } /** @@ -82,24 +82,24 @@ void wControlShow( */ void wControlActive( - wControl_p b, - int active) + wControl_p b, + int active) { - if (b->widget == NULL) { - abort(); - } + if (b->widget == NULL) { + abort(); + } - if (b->type == B_LIST || b->type == B_DROPLIST ) { + if (b->type == B_LIST || b->type == B_DROPLIST ) { - gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(b->widget)), active); - gtk_combo_box_set_button_sensitivity(GTK_COMBO_BOX(b->widget), - active?GTK_SENSITIVITY_ON:GTK_SENSITIVITY_OFF); + gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(b->widget)), active); + gtk_combo_box_set_button_sensitivity(GTK_COMBO_BOX(b->widget), + active?GTK_SENSITIVITY_ON:GTK_SENSITIVITY_OFF); - } else { + } else { - gtk_widget_set_sensitive(GTK_WIDGET(b->widget), active); + gtk_widget_set_sensitive(GTK_WIDGET(b->widget), active); - } + } } /** @@ -113,16 +113,16 @@ void wControlActive( */ wWinPix_t wLabelWidth( - const char * label) + const char * label) { - GtkWidget * widget; - GtkRequisition requisition; - widget = gtk_label_new(wlibConvertInput(label)); - gtk_widget_size_request(widget, &requisition); - g_object_ref_sink (widget); - gtk_widget_destroy(widget); - g_object_unref(widget); - return requisition.width+8; + GtkWidget * widget; + GtkRequisition requisition; + widget = gtk_label_new(wlibConvertInput(label)); + gtk_widget_size_request(widget, &requisition); + g_object_ref_sink (widget); + gtk_widget_destroy(widget); + g_object_unref(widget); + return requisition.width+8; } /** @@ -133,9 +133,9 @@ wWinPix_t wLabelWidth( */ wWinPix_t wControlGetWidth( - wControl_p b) + wControl_p b) { - return b->w; + return b->w; } /** @@ -146,9 +146,9 @@ wWinPix_t wControlGetWidth( */ wWinPix_t wControlGetHeight( - wControl_p b) + wControl_p b) { - return b->h; + return b->h; } /** @@ -159,9 +159,9 @@ wWinPix_t wControlGetHeight( */ wWinPix_t wControlGetPosX( - wControl_p b) /* Control */ + wControl_p b) /* Control */ { - return b->realX; + return b->realX; } /** @@ -172,9 +172,10 @@ wWinPix_t wControlGetPosX( */ wWinPix_t wControlGetPosY( - wControl_p b) /* Control */ + wControl_p b) /* Control */ { - return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0); + return b->realY - BORDERSIZE - ((b->parent->option&F_MENUBAR) + ?b->parent->menu_height:0); } /** @@ -186,27 +187,29 @@ wWinPix_t wControlGetPosY( */ void wControlSetPos( - wControl_p b, - wWinPix_t x, - wWinPix_t y) + wControl_p b, + wWinPix_t x, + wWinPix_t y) { - b->realX = x; - b->realY = y + BORDERSIZE + ((b->parent->option&F_MENUBAR)?b->parent->menu_height:0); - - if (b->widget) { - gtk_fixed_move(GTK_FIXED(b->parent->widget), b->widget, b->realX, b->realY); - } - - if (b->label) { - GtkRequisition requisition, reqwidget; - gtk_widget_size_request(b->label, &requisition); - if (b->widget) - gtk_widget_size_request(b->widget, &reqwidget); - else - reqwidget.height = requisition.height; - gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, b->realX-b->labelW, - b->realY+(reqwidget.height/2 - requisition.height/2)); - } + b->realX = x; + b->realY = y + BORDERSIZE + ((b->parent->option&F_MENUBAR) + ?b->parent->menu_height:0); + + if (b->widget) { + gtk_fixed_move(GTK_FIXED(b->parent->widget), b->widget, b->realX, b->realY); + } + + if (b->label) { + GtkRequisition requisition, reqwidget; + gtk_widget_size_request(b->label, &requisition); + if (b->widget) { + gtk_widget_size_request(b->widget, &reqwidget); + } else { + reqwidget.height = requisition.height; + } + gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, b->realX-b->labelW, + b->realY+(reqwidget.height/2 - requisition.height/2)); + } } /** @@ -217,24 +220,25 @@ void wControlSetPos( */ void wControlSetLabel( - wControl_p b, - const char * labelStr) + wControl_p b, + const char * labelStr) { - GtkRequisition requisition,reqwidget; - - if (b->label) { - gtk_label_set_text(GTK_LABEL(b->label), wlibConvertInput(labelStr)); - gtk_widget_size_request(b->label, &requisition); - if (b->widget) - gtk_widget_size_request(b->widget, &reqwidget); - else - reqwidget.height = requisition.height; - b->labelW = requisition.width+8; - gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, b->realX-b->labelW, - b->realY+(reqwidget.height/2 - requisition.height/2)); - } else { - b->labelW = wlibAddLabel(b, labelStr); - } + GtkRequisition requisition,reqwidget; + + if (b->label) { + gtk_label_set_text(GTK_LABEL(b->label), wlibConvertInput(labelStr)); + gtk_widget_size_request(b->label, &requisition); + if (b->widget) { + gtk_widget_size_request(b->widget, &reqwidget); + } else { + reqwidget.height = requisition.height; + } + b->labelW = requisition.width+8; + gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, b->realX-b->labelW, + b->realY+(reqwidget.height/2 - requisition.height/2)); + } else { + b->labelW = wlibAddLabel(b, labelStr); + } } /** @@ -245,10 +249,10 @@ void wControlSetLabel( */ void wControlSetContext( - wControl_p b, - void * context) + wControl_p b, + void * context) { - b->data = context; + b->data = context; } /** @@ -258,31 +262,21 @@ void wControlSetContext( */ void wControlSetFocus( - wControl_p b) + wControl_p b) { } wBool_t wControlExpose ( - GtkWidget * widget, - GdkEventExpose * event, - wControl_p b - ) + GtkWidget * widget, + GdkEventExpose * event, + wControl_p b +) { GdkWindow * win = gtk_widget_get_window(b->widget); cairo_t * cr = NULL; if (win) { cr = gdk_cairo_create(win); - } else return TRUE; - -#ifdef CURSOR_SURFACE - if (b && b->cursor_surface.surface && b->cursor_surface.show) { - cairo_set_source_surface(cr,b->cursor_surface.surface,event->area.x, event->area.y); - cairo_set_operator(cr,CAIRO_OPERATOR_OVER); - cairo_rectangle(cr,event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_fill(cr); - } -#endif + } else { return TRUE; } if (b->outline) { cairo_set_source_rgb(cr, 0.23, 0.37, 0.80); @@ -291,7 +285,7 @@ wBool_t wControlExpose ( cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); cairo_rectangle(cr,event->area.x+2, event->area.y+2, - event->area.width-4, event->area.height-4); + event->area.width-4, event->area.height-4); cairo_stroke(cr); } @@ -299,7 +293,7 @@ wBool_t wControlExpose ( cairo_destroy(cr); - return FALSE; + return FALSE; } /** @@ -311,19 +305,21 @@ wBool_t wControlExpose ( * */ void wControlHilite( - wControl_p b, - wBool_t hilite) + wControl_p b, + wBool_t hilite) { - cairo_t *cr; - int off = GTKCONTROLHILITEWIDTH/2+1; - if ( debugWindow >= 1 ) - printf( "wControlHIlite( %s, %d )\n", b->labelStr, hilite ); - - if (b->widget == NULL) { - return; - } - b->outline = hilite; - - if (b->widget) - gtk_widget_queue_draw(b->widget); +// cairo_t *cr; +// int off = GTKCONTROLHILITEWIDTH/2+1; + if ( debugWindow >= 1 ) { + printf( "wControlHIlite( %s, %d )\n", b->labelStr, hilite ); + } + + if (b->widget == NULL) { + return; + } + b->outline = hilite; + + if (b->widget) { + gtk_widget_queue_draw(b->widget); + } } diff --git a/app/wlib/gtklib/droplist.c b/app/wlib/gtklib/droplist.c index 91406fc..a4abced 100644 --- a/app/wlib/gtklib/droplist.c +++ b/app/wlib/gtklib/droplist.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -51,30 +51,30 @@ int wlibDropListAddColumns(GtkWidget *dropList, int columns) { - int i; - int start = 0; - GtkCellRenderer *cell; - - if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(dropList))) { - start = 1; - } - - /* Create cell renderer. */ - cell = gtk_cell_renderer_text_new(); - - for (i = start; i < columns; i++) { - /* Pack it into the droplist */ - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropList), cell, TRUE); - - /* Connect renderer to data source */ - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropList), - cell, - "text", - LISTCOL_TEXT + i, - NULL); - } - - return (i); + int i; + int start = 0; + GtkCellRenderer *cell; + + if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(dropList))) { + start = 1; + } + + /* Create cell renderer. */ + cell = gtk_cell_renderer_text_new(); + + for (i = start; i < columns; i++) { + /* Pack it into the droplist */ + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropList), cell, TRUE); + + /* Connect renderer to data source */ + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropList), + cell, + "text", + LISTCOL_TEXT + i, + NULL); + } + + return (i); } /** @@ -86,7 +86,7 @@ wlibDropListAddColumns(GtkWidget *dropList, int columns) wIndex_t wDropListGetCount(wList_p b) { - return (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(b->listStore), NULL)); + return (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(b->listStore), NULL)); } /** @@ -99,7 +99,7 @@ wIndex_t wDropListGetCount(wList_p b) void wDropListClear(wList_p b) { - wlibListStoreClear(b->listStore); + wlibListStoreClear(b->listStore); } /** @@ -111,22 +111,22 @@ wDropListClear(wList_p b) void *wDropListGetItemContext(wList_p b, wIndex_t inx) { - GtkTreeIter iter; - wListItem_p data = NULL; - - if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL, - inx)) { - gtk_tree_model_get(GTK_TREE_MODEL(b->listStore), - &iter, - LISTCOL_DATA, (void *)&data, - -1); - } - - if (data) { - return (data->itemData); - } else { - return (NULL); - } + GtkTreeIter iter; + wListItem_p data = NULL; + + if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL, + inx)) { + gtk_tree_model_get(GTK_TREE_MODEL(b->listStore), + &iter, + LISTCOL_DATA, (void *)&data, + -1); + } + + if (data) { + return (data->itemData); + } else { + return (NULL); + } } /** @@ -138,21 +138,21 @@ void *wDropListGetItemContext(wList_p b, wIndex_t inx) */ void wDropListAddValue( - wList_p b, - char *text, - wListItem_p data) + wList_p b, + char *text, + wListItem_p data) { - GtkTreeIter iter; + GtkTreeIter iter; - assert(b != NULL); - assert(text != NULL); + assert(b != NULL); + assert(text != NULL); - gtk_list_store_append(b->listStore, &iter); // append new row to tree store + gtk_list_store_append(b->listStore, &iter); // append new row to tree store - gtk_list_store_set(b->listStore, &iter, - LISTCOL_TEXT, text, - LISTCOL_DATA, (void *)data, - -1); + gtk_list_store_set(b->listStore, &iter, + LISTCOL_TEXT, text, + LISTCOL_DATA, (void *)data, + -1); } /** @@ -162,25 +162,25 @@ void wDropListAddValue( */ void wListSetValue( - wList_p bl, - const char * val) + wList_p bl, + const char * val) { - assert(bl->listStore!=NULL); + assert(bl->listStore!=NULL); - bl->recursion++; + bl->recursion++; - if (bl->type == B_DROPLIST) { - bl->editted = TRUE; - gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))), val); + if (bl->type == B_DROPLIST) { + bl->editted = TRUE; + gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))), val); - if (bl->action) { - bl->action(-1, val, 0, bl->data, NULL); - } - } else { - assert(FALSE); - } + if (bl->action) { + bl->action(-1, val, 0, bl->data, NULL); + } + } else { + assert(FALSE); + } - bl->recursion--; + bl->recursion--; } /** @@ -195,11 +195,11 @@ void wListSetValue( void wDropListSetIndex(wList_p b, int val) { - if ((b->option&BL_NONE)!=0 && val < 0) { - gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), -1); - } else { - gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), val); - } + if ((b->option&BL_NONE)!=0 && val < 0) { + gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), -1); + } else { + gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), val); + } } /** @@ -214,24 +214,24 @@ void wDropListSetIndex(wList_p b, int val) */ wBool_t wDropListSetValues( - wList_p b, - wIndex_t row, - const char * labelStr, - wIcon_p bm, - void *itemData) + wList_p b, + wIndex_t row, + const char * labelStr, + wIcon_p bm, + void *itemData) { - GtkTreeIter iter; - - if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL, - row)) { - gtk_list_store_set(b->listStore, - &iter, - LISTCOL_TEXT, labelStr, - -1); - return (TRUE); - } else { - return (FALSE); - } + GtkTreeIter iter; + + if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL, + row)) { + gtk_list_store_set(b->listStore, + &iter, + LISTCOL_TEXT, labelStr, + -1); + return (TRUE); + } else { + return (FALSE); + } } /** @@ -245,72 +245,75 @@ wBool_t wDropListSetValues( */ static int DropListChanged( - GtkComboBox * comboBox, - gpointer data) + GtkComboBox * comboBox, + gpointer data) { - wList_p bl = (wList_p)data; - GtkTreeIter iter; - - wIndex_t inx = 0; - gchar *string = NULL; - wListItem_p listItemP = NULL; - - if (bl->recursion) { - return 0; - } - - /* Obtain currently selected item from combo box. */ - if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(comboBox), &iter)) { - GtkTreeModel *model; - - /* Obtain data model from combo box. */ - model = gtk_combo_box_get_model(comboBox); - - /* get the selected row */ - string = gtk_tree_model_get_string_from_iter(model, - &iter); - inx = atoi(string); - g_free(string); - string = NULL; - - /* Obtain string from model. */ - gtk_tree_model_get(model, &iter, - LISTCOL_TEXT, &string, - LISTCOL_DATA, (void *)&listItemP, - -1); - bl->editted = FALSE; - - } else { - /* Nothing selected, user is entering text directly */ - inx = -1; - GtkEntry * entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))); - if ( entry == NULL ) - return 0; - const char * string1 = gtk_entry_get_text(entry); - if ( string1 == NULL ) - return 0; - string = g_strdup(string1); - bl->editted = TRUE; - } - - /* selection changed, store new selections and call back */ - if (bl->last != inx || bl->editted == TRUE) { - - bl->last = inx; - - if (bl->valueP) { - *bl->valueP = inx; - } - - /* selection changed -> callback */ - if (string && bl->action) { - bl->action(inx, string, 1, bl->data, listItemP?listItemP->itemData:NULL); - } - } - - if ( string ) - g_free(string); - return 1; + wList_p bl = (wList_p)data; + GtkTreeIter iter; + + wIndex_t inx = 0; + gchar *string = NULL; + wListItem_p listItemP = NULL; + + if (bl->recursion) { + return 0; + } + + /* Obtain currently selected item from combo box. */ + if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(comboBox), &iter)) { + GtkTreeModel *model; + + /* Obtain data model from combo box. */ + model = gtk_combo_box_get_model(comboBox); + + /* get the selected row */ + string = gtk_tree_model_get_string_from_iter(model, + &iter); + inx = atoi(string); + g_free(string); + string = NULL; + + /* Obtain string from model. */ + gtk_tree_model_get(model, &iter, + LISTCOL_TEXT, &string, + LISTCOL_DATA, (void *)&listItemP, + -1); + bl->editted = FALSE; + + } else { + /* Nothing selected, user is entering text directly */ + inx = -1; + GtkEntry * entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))); + if ( entry == NULL ) { + return 0; + } + const char * string1 = gtk_entry_get_text(entry); + if ( string1 == NULL ) { + return 0; + } + string = g_strdup(string1); + bl->editted = TRUE; + } + + /* selection changed, store new selections and call back */ + if (bl->last != inx || bl->editted == TRUE) { + + bl->last = inx; + + if (bl->valueP) { + *bl->valueP = inx; + } + + /* selection changed -> callback */ + if (string && bl->action) { + bl->action(inx, string, 1, bl->data, listItemP?listItemP->itemData:NULL); + } + } + + if ( string ) { + g_free(string); + } + return 1; } /** @@ -324,15 +327,15 @@ static int DropListChanged( GtkWidget * wlibNewDropList(GtkListStore *ls, int editable) { - GtkWidget *widget; + GtkWidget *widget; - if (editable) { - widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(ls)); - } else { - widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls)); - } + if (editable) { + widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(ls)); + } else { + widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls)); + } - return (widget); + return (widget); } /** @@ -352,80 +355,80 @@ wlibNewDropList(GtkListStore *ls, int editable) */ wList_p wDropListCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - long number, - wWinPix_t width, - long *valueP, - wListCallBack_p action, - void *data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + long number, + wWinPix_t width, + long *valueP, + wListCallBack_p action, + void *data) { - wList_p b; + wList_p b; - b = (wList_p)wlibAlloc(parent, B_DROPLIST, x, y, labelStr, sizeof *b, data); - b->option = option; - b->number = number; - b->count = 0; - b->last = -1; - b->valueP = valueP; - b->action = action; - b->listX = b->realX; - b->colCnt = 0; - b->colWidths = NULL; - b->colRightJust = NULL; - b->editable = ((option & BL_EDITABLE) != 0); + b = (wList_p)wlibAlloc(parent, B_DROPLIST, x, y, labelStr, sizeof *b, data); + b->option = option; + b->number = number; + b->count = 0; + b->last = -1; + b->valueP = valueP; + b->action = action; + b->listX = b->realX; + b->colCnt = 0; + b->colWidths = NULL; + b->colRightJust = NULL; + b->editable = ((option & BL_EDITABLE) != 0); - assert(width != 0); + assert(width != 0); - wlibComputePos((wControl_p)b); + wlibComputePos((wControl_p)b); - // create tree store for storing the contents - b->listStore = wlibNewListStore(DROPLIST_TEXTCOLUMNS); + // create tree store for storing the contents + b->listStore = wlibNewListStore(DROPLIST_TEXTCOLUMNS); - if (!b->listStore) { - abort(); - } + if (!b->listStore) { + abort(); + } - // create the droplist - b->widget = wlibNewDropList(b->listStore, - option & BL_EDITABLE); + // create the droplist + b->widget = wlibNewDropList(b->listStore, + option & BL_EDITABLE); - if (b->widget == 0) { - abort(); - } - g_object_ref_sink(b->listStore); - g_object_unref(G_OBJECT(b->listStore)); + if (b->widget == 0) { + abort(); + } + g_object_ref_sink(b->listStore); + g_object_unref(G_OBJECT(b->listStore)); - wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS); + wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS); - gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(b->widget), - LISTCOL_TEXT); + gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(b->widget), + LISTCOL_TEXT); - // combo's style - gtk_rc_parse_string("style \"my-style\" { GtkComboBox::appears-as-list = 1 } widget \"*.mycombo\" style \"my-style\" "); - gtk_widget_set_name(b->widget,"mycombo"); + // combo's style + gtk_rc_parse_string("style \"my-style\" { GtkComboBox::appears-as-list = 1 } widget \"*.mycombo\" style \"my-style\" "); + gtk_widget_set_name(b->widget,"mycombo"); - g_signal_connect(GTK_OBJECT(b->widget), "changed", - G_CALLBACK(DropListChanged), b); + g_signal_connect(GTK_OBJECT(b->widget), "changed", + G_CALLBACK(DropListChanged), b); - gtk_widget_set_size_request(b->widget, width, -1); + gtk_widget_set_size_request(b->widget, width, -1); - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - wlibControlGetSize((wControl_p)b); + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + wlibControlGetSize((wControl_p)b); - if (labelStr) { - b->labelW = wlibAddLabel((wControl_p)b, labelStr); - } + if (labelStr) { + b->labelW = wlibAddLabel((wControl_p)b, labelStr); + } - gtk_widget_show(b->widget); - wlibAddButton((wControl_p)b); - wlibAddHelpString(b->widget, helpStr); + gtk_widget_show(b->widget); + wlibAddButton((wControl_p)b); + wlibAddHelpString(b->widget, helpStr); - return b; + return b; } diff --git a/app/wlib/gtklib/dynarr.h b/app/wlib/gtklib/dynarr.h index 2adf115..1eefd62 100644 --- a/app/wlib/gtklib/dynarr.h +++ b/app/wlib/gtklib/dynarr.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -22,10 +22,10 @@ #define DYNARR_H_SEEN typedef struct { - int cnt; - int max; - void * ptr; - } dynArr_t; + int cnt; + int max; + void * ptr; +} dynArr_t; #define DYNARR_APPEND(T,DA,INCR) \ { if ((DA).cnt >= (DA).max) { \ diff --git a/app/wlib/gtklib/filesel.c b/app/wlib/gtklib/filesel.c index 7e27465..3d4fb85 100644 --- a/app/wlib/gtklib/filesel.c +++ b/app/wlib/gtklib/filesel.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -41,114 +41,115 @@ #define MAX_ALLOWEDFILTERS 10 struct wFilSel_t { - GtkWidget * window; /**< file selector handle*/ - wFilSelCallBack_p action; /**< */ - void * data; /**< */ - int pattCount; /**< number of file patterns*/ - wBool_t loadPatternsAdded; /** Already loaded */ - GtkFileFilter *filter[ MAX_ALLOWEDFILTERS ]; /**< array of file patterns */ - wFilSelMode_e mode; /**< used for load or save */ - int opt; /**< see FS_ options */ - const char * title; /**< dialog box title */ - wWin_p parent; /**< parent window */ - char *defaultExtension; /**< to use if no extension specified */ - }; + GtkWidget * window; /**< file selector handle*/ + wFilSelCallBack_p action; /**< */ + void * data; /**< */ + int pattCount; /**< number of file patterns*/ + wBool_t loadPatternsAdded; /** Already loaded */ + GtkFileFilter *filter[ MAX_ALLOWEDFILTERS ]; /**< array of file patterns */ + wFilSelMode_e mode; /**< used for load or save */ + int opt; /**< see FS_ options */ + const char * title; /**< dialog box title */ + wWin_p parent; /**< parent window */ + char *defaultExtension; /**< to use if no extension specified */ +}; /** * Signal handler for 'changed' signal of custom combo box. The filter * is set accordinng to the file format active in the combo box - * - * \param comboBox the combo box + * + * \param comboBox the combo box * \param fileSelector data of the file selector - * + * */ -static void FileFormatChanged( GtkWidget *comboBox, - struct wFilSel_t *fileSelector ) +static void FileFormatChanged( GtkWidget *comboBox, + struct wFilSel_t *fileSelector ) { // get active entry int entry = (int)gtk_combo_box_get_active (GTK_COMBO_BOX(comboBox)); - + if( entry>=0 ) { - g_object_ref(G_OBJECT( (fileSelector->filter)[ entry ])); - gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fileSelector->window ), - (fileSelector->filter)[ entry ]); + g_object_ref(G_OBJECT( (fileSelector->filter)[ entry ])); + gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fileSelector->window ), + (fileSelector->filter)[ entry ]); } } /** - * Create a widget containing a combo box for selecting a file format. + * Create a widget containing a combo box for selecting a file format. * From an array of filters, the names are retrieved and used to populate - * the combo box. + * the combo box. * \param IN dialogBox * \param patterns IN number of entries for combo * \param filters IN * \returns the newly created widget */ - -static GtkWidget *CreateFileformatSelector(struct wFilSel_t *dialogBox, - int patterns, - GtkFileFilter **filters) + +static GtkWidget *CreateFileformatSelector(struct wFilSel_t *dialogBox, + int patterns, + GtkFileFilter **filters) { GtkWidget *hbox = gtk_hbox_new(FALSE, 12); GtkWidget *text = gtk_label_new(_("Save format:")); GtkWidget *combo = gtk_combo_box_text_new (); - g_signal_connect(G_OBJECT(combo), - "changed", - (GCallback)FileFormatChanged, - dialogBox ); + g_signal_connect(G_OBJECT(combo), + "changed", + (GCallback)FileFormatChanged, + dialogBox ); gtk_box_pack_start (GTK_BOX(hbox), - text, - FALSE, - FALSE, - 0); + text, + FALSE, + FALSE, + 0); gtk_box_pack_end (GTK_BOX(hbox), - combo, - TRUE, - TRUE, - 0); + combo, + TRUE, + TRUE, + 0); for(int i=0; i < patterns; i++ ) { const char *nameOfFilter = gtk_file_filter_get_name( filters[ i ] ); gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(combo), nameOfFilter ); } gtk_combo_box_set_active (GTK_COMBO_BOX(combo), 0); - + gtk_widget_show_all(hbox); - - return(hbox); + + return(hbox); } /** * Create a new file selector. Only the internal data structures are - * set up, no dialog is created. + * set up, no dialog is created. * * \param w IN parent window * \param mode IN ? * \param opt IN ? * \param title IN dialog title * \param pattList IN list of selection patterns - * \param action IN callback + * \param action IN callback * \param data IN ? * \return the newly created file selector structure */ - + struct wFilSel_t * wFilSelCreate( - wWin_p w, - wFilSelMode_e mode, - int opt, - const char * title, - const char * pattList, - wFilSelCallBack_p action, - void * data ) + wWin_p w, + wFilSelMode_e mode, + int opt, + const char * title, + const char * pattList, + wFilSelCallBack_p action, + void * data ) { struct wFilSel_t *fs; fs = (struct wFilSel_t*)malloc(sizeof *fs); - if (!fs) + if (!fs) { return NULL; + } fs->parent = w; fs->window = 0; @@ -208,22 +209,24 @@ struct wFilSel_t * wFilSelCreate( gtk_file_filter_add_pattern (fs->filter[ count ], cp1 ); cp1 = strtok_r(NULL, ";", &filterState ); } - if (cp1s) + if (cp1s) { free(cp1s); + } } // the first pattern is considered to match the default extension if( count == 0 && !(opt&FS_PICTURES)) { fs->defaultExtension = strdup( cp2 ); int i = 0; - for (i=0; i<strlen(cp2) && cp2[i] != ' ' && cp2[i] != ';';i++) ; - if (i<strlen(cp2)) fs->defaultExtension[i] = '\0'; + for (i=0; i<strlen(cp2) && cp2[i] != ' ' && cp2[i] != ';'; i++) ; + if (i<strlen(cp2)) { fs->defaultExtension[i] = '\0'; } } fs->pattCount = ++count; } cp = strtok_r( NULL, ":", &patternState ); } - if (cps) + if (cps) { free(cps); + } } else { @@ -234,13 +237,13 @@ struct wFilSel_t * wFilSelCreate( } /** - * Show and handle the file selection dialog. + * Show and handle the file selection dialog. * - * \param fs IN file selection + * \param fs IN file selection * \param dirName IN starting directory * \return always TRUE */ - + int wFilSelect( struct wFilSel_t * fs, const char * dirName ) { char name[1024]; @@ -250,67 +253,71 @@ int wFilSelect( struct wFilSel_t * fs, const char * dirName ) GError *err = NULL; if (fs->window == NULL) { - fs->window = gtk_file_chooser_dialog_new( fs->title, - GTK_WINDOW( fs->parent->gtkwin ), - (fs->mode == FS_LOAD ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE ), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - (fs->mode == FS_LOAD ? GTK_STOCK_OPEN : GTK_STOCK_SAVE ), GTK_RESPONSE_ACCEPT, - NULL ); - if (fs->window==0) abort(); + fs->window = gtk_file_chooser_dialog_new( fs->title, + GTK_WINDOW( fs->parent->gtkwin ), + (fs->mode == FS_LOAD ? GTK_FILE_CHOOSER_ACTION_OPEN : + GTK_FILE_CHOOSER_ACTION_SAVE ), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + (fs->mode == FS_LOAD ? GTK_STOCK_OPEN : GTK_STOCK_SAVE ), GTK_RESPONSE_ACCEPT, + NULL ); + if (fs->window==0) { abort(); } if ( fs->mode == FS_SAVE ) { - // get confirmation before overwritting an existing file - gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(fs->window), TRUE ); + // get confirmation before overwritting an existing file + gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(fs->window), + TRUE ); } - + /** \todo for loading a shortcut folder could be added linking to the example directory */ } strcpy( name, dirName ); - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(fs->window), name ); + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(fs->window), name ); if( fs->mode == FS_SAVE || fs->mode == FS_UPDATE ) { - gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER(fs->window), - CreateFileformatSelector(fs, fs->pattCount, fs->filter )); - } - // Add a current folder and a shortcut to it for Load/import dialogs - if( fs->mode == FS_LOAD ) { - gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER(fs->window), name, NULL ); + gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER(fs->window), + CreateFileformatSelector(fs, fs->pattCount, fs->filter )); + } + // Add a current folder and a shortcut to it for Load/import dialogs + if( fs->mode == FS_LOAD ) { + gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER(fs->window), name, + NULL ); // allow selecting multiple files if( fs->opt & FS_MULTIPLEFILES ) { gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER(fs->window), TRUE); - } + } // add the file filters to the dialog box if( fs->pattCount && !fs->loadPatternsAdded) { for( i = 0; i < fs->pattCount; i++ ) { - gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( fs->window ), fs->filter[ i ] ); + gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( fs->window ), fs->filter[ i ] ); } fs->loadPatternsAdded = TRUE; - } - } - - int resp = gtk_dialog_run( GTK_DIALOG( fs->window )); + } + } + + int resp = gtk_dialog_run( GTK_DIALOG( fs->window )); if( resp == GTK_RESPONSE_ACCEPT || resp == GTK_RESPONSE_APPLY) { - char **fileNames; + char **fileNames; GSList *fileNameList; - + fileNameList = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER(fs->window) ); - fileNames = calloc( sizeof(char *), g_slist_length (fileNameList) ); - + fileNames = calloc( sizeof(char *), g_slist_length (fileNameList) ); + for (i=0; i < g_slist_length (fileNameList); i++ ) { char *namePart; file = g_filename_from_uri( g_slist_nth_data( fileNameList, i ), &host, &err ); - + // check for presence of file extension // jump behind the last directory delimiter namePart = strrchr( file, '/' ) + 1; // is there a dot in the last part, yes->extension present - if( !strchr( namePart, '.' ) ){ - + if( !strchr( namePart, '.' ) ) { + // else try to find the current filter and parse its name - GtkFileFilter *currentFilter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER(fs->window) ); + GtkFileFilter *currentFilter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER( + fs->window) ); if (currentFilter) { const char *nameOfFilter = gtk_file_filter_get_name( currentFilter ); char *pattern = strdup( nameOfFilter ); @@ -328,24 +335,24 @@ int wFilSelect( struct wFilSel_t * fs, const char * dirName ) strcat( file, extension ); free( pattern ); } - } + } fileNames[ i ] = file; g_free( g_slist_nth_data ( fileNameList, i)); } - + gtk_widget_hide( GTK_WIDGET( fs->window )); if (fs->action) { fs->action( g_slist_length(fileNameList), fileNames, fs->data ); } - + for(i=0; i < g_slist_length(fileNameList); i++) { g_free( fileNames[ i ]); } free( fileNames ); - g_slist_free (fileNameList); + g_slist_free (fileNameList); } else { gtk_widget_hide( GTK_WIDGET( fs->window )); } - + return 1; } diff --git a/app/wlib/gtklib/font.c b/app/wlib/gtklib/font.c index 29df04d..e89307c 100644 --- a/app/wlib/gtklib/font.c +++ b/app/wlib/gtklib/font.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -67,7 +67,7 @@ static GtkWidget *fontSelectionDialog; int absoluteFontSize = 18; struct wFont_t { - PangoFontDescription *fontDescription; + PangoFontDescription *fontDescription; }; static wFont_p standardFonts[F_HELV-F_TIMES+1][2][2]; @@ -85,76 +85,76 @@ static wFont_p curFont = NULL; static void fontSelectionDialogCallback(GtkFontSelectionDialog *fontSelectionDialog, gint response, gpointer data) { - if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) { - gchar *fontName; - - fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog); - wPrefSetString("font", "name", fontName); - pango_font_description_free(curFont->fontDescription); - curFont->fontDescription = pango_font_description_from_string(fontName); - absoluteFontSize = (pango_font_description_get_size( - curFont->fontDescription))/PANGO_SCALE; + if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) { + gchar *fontName; + + fontName = gtk_font_selection_dialog_get_font_name(fontSelectionDialog); + wPrefSetString("font", "name", fontName); + pango_font_description_free(curFont->fontDescription); + curFont->fontDescription = pango_font_description_from_string(fontName); + absoluteFontSize = (pango_font_description_get_size( + curFont->fontDescription))/PANGO_SCALE; #if WLIB_FONT_DEBUG >= 2 - fprintf(stderr, "new font selection:\n"); - fprintf(stderr, " font name \"%s\"\n", fontName); - fprintf(stderr, " font size is %d\n", - pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); - fprintf(stderr, " font size is absolute %d\n", - pango_font_description_get_size_is_absolute(curFont->fontDescription)); + fprintf(stderr, "new font selection:\n"); + fprintf(stderr, " font name \"%s\"\n", fontName); + fprintf(stderr, " font size is %d\n", + pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); + fprintf(stderr, " font size is absolute %d\n", + pango_font_description_get_size_is_absolute(curFont->fontDescription)); #endif - g_free(fontName); - } + g_free(fontName); + } - if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_CANCEL) { - gtk_widget_hide(GTK_WIDGET(fontSelectionDialog)); - } + if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_CANCEL) { + gtk_widget_hide(GTK_WIDGET(fontSelectionDialog)); + } } static wBool_t fontInitted = FALSE; static wBool_t fontInit() { - const char *fontNames[] = { - "times 18", - "times italic 18", - "times bold 18", - "times bold italic 18", - "helvetica 18", - "helvetica oblique 18", - "helvetica bold 18", - "helvetica bold oblique 18", - }; - int s = 0; - int i, j, k; - - for (i = F_TIMES; i <= F_HELV; ++i) { - for (j = FW_MEDIUM; j <= FW_BOLD; ++j) { - for (k = FS_REGULAR; k <= FS_ITALIC; ++k) { - PangoFontDescription *fontDescription = pango_font_description_from_string( - fontNames[s++]); - wFont_p standardFont = (wFont_p) malloc(sizeof(struct wFont_t)); - standardFont->fontDescription = fontDescription; - standardFonts[i-F_TIMES][j][k] = standardFont; - } - } - } - - if (curFont == NULL) { - curFont = (wFont_p) malloc(sizeof(struct wFont_t)); - - if (curFont == NULL) { - return FALSE; - } - - const char *fontName = wPrefGetString("font", "name"); - curFont->fontDescription = pango_font_description_from_string( - fontName ? fontName : "helvetica 18"); - absoluteFontSize = (int) PANGO_PIXELS(pango_font_description_get_size( - curFont->fontDescription)); - } - - fontInitted = TRUE; - return TRUE; + const char *fontNames[] = { + "times 18", + "times italic 18", + "times bold 18", + "times bold italic 18", + "helvetica 18", + "helvetica oblique 18", + "helvetica bold 18", + "helvetica bold oblique 18", + }; + int s = 0; + int i, j, k; + + for (i = F_TIMES; i <= F_HELV; ++i) { + for (j = FW_MEDIUM; j <= FW_BOLD; ++j) { + for (k = FS_REGULAR; k <= FS_ITALIC; ++k) { + PangoFontDescription *fontDescription = pango_font_description_from_string( + fontNames[s++]); + wFont_p standardFont = (wFont_p) malloc(sizeof(struct wFont_t)); + standardFont->fontDescription = fontDescription; + standardFonts[i-F_TIMES][j][k] = standardFont; + } + } + } + + if (curFont == NULL) { + curFont = (wFont_p) malloc(sizeof(struct wFont_t)); + + if (curFont == NULL) { + return FALSE; + } + + const char *fontName = wPrefGetString("font", "name"); + curFont->fontDescription = pango_font_description_from_string( + fontName ? fontName : "helvetica 18"); + absoluteFontSize = (int) PANGO_PIXELS(pango_font_description_get_size( + curFont->fontDescription)); + } + + fontInitted = TRUE; + return TRUE; } @@ -186,59 +186,59 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, wDrawPix_t *height_p, wDrawPix_t *ascent_p, wDrawPix_t *descent_p, - wDrawPix_t *baseline_p) + wDrawPix_t *baseline_p) { - if (!fontInitted) { - fontInit(); - } - - PangoLayout *layout = NULL; - gchar *utf8 = wlibConvertInput(s); - /* RPH -- pango_cairo_create_layout() is missing in CentOS 4.8. - CentOS 4.8 only has GTK 2.4.13 and Pango 1.6.0 and does not have - libpangocairo at all. - pango_cairo_create_layout() was introduced with Pango 1.10. */ + if (!fontInitted) { + fontInit(); + } + + PangoLayout *layout = NULL; + gchar *utf8 = wlibConvertInput(s); + /* RPH -- pango_cairo_create_layout() is missing in CentOS 4.8. + CentOS 4.8 only has GTK 2.4.13 and Pango 1.6.0 and does not have + libpangocairo at all. + pango_cairo_create_layout() was introduced with Pango 1.10. */ #if PANGO_VERSION_MAJOR >= 1 && PANGO_VERSION_MINOR >= 10 - if (cairo != NULL) { - layout = pango_cairo_create_layout((cairo_t *) cairo); - pango_layout_set_text(layout, utf8, -1); - } else + if (cairo != NULL) { + layout = pango_cairo_create_layout((cairo_t *) cairo); + pango_layout_set_text(layout, utf8, -1); + } else #endif - layout = gtk_widget_create_pango_layout(widget, utf8); - - PangoFontDescription *fontDescription = (fp ? fp : curFont)->fontDescription; - PangoContext *context; - PangoFontMetrics *metrics; - /* set attributes */ - pango_font_description_set_size(fontDescription, - FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE); - pango_layout_set_font_description(layout, fontDescription); - /* get layout measures */ - gint width_i, height_i; - pango_layout_get_size(layout, &width_i, &height_i); - *width_p = width_i / PANGO_SCALE; - *height_p = height_i / PANGO_SCALE; - context = gtk_widget_create_pango_context(widget); - metrics = pango_context_get_metrics(context, fontDescription, - pango_context_get_language(context)); - *baseline_p = pango_layout_get_baseline(layout) / PANGO_SCALE; - *ascent_p = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; - *descent_p = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; - pango_font_metrics_unref(metrics); - g_object_unref(context); + layout = gtk_widget_create_pango_layout(widget, utf8); + + PangoFontDescription *fontDescription = (fp ? fp : curFont)->fontDescription; + PangoContext *context; + PangoFontMetrics *metrics; + /* set attributes */ + pango_font_description_set_size(fontDescription, + FONTSIZE_TO_PANGOSIZE(fs) * PANGO_SCALE); + pango_layout_set_font_description(layout, fontDescription); + /* get layout measures */ + gint width_i, height_i; + pango_layout_get_size(layout, &width_i, &height_i); + *width_p = width_i / PANGO_SCALE; + *height_p = height_i / PANGO_SCALE; + context = gtk_widget_create_pango_context(widget); + metrics = pango_context_get_metrics(context, fontDescription, + pango_context_get_language(context)); + *baseline_p = pango_layout_get_baseline(layout) / PANGO_SCALE; + *ascent_p = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; + *descent_p = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; + pango_font_metrics_unref(metrics); + g_object_unref(context); #if WLIB_FONT_DEBUG >= 3 - fprintf(stderr, "font layout created:\n"); - fprintf(stderr, " widget: %p\n", widget); - //fprintf(stderr, " font description:%p\n", fp); - fprintf(stderr, " font size: %f\n", fs); - fprintf(stderr, " layout text: \"%s\" (utf8)\n", utf8); - fprintf(stderr, " layout width: %d\n", *width_p); - fprintf(stderr, " layout height: %d\n", *height_p); - fprintf(stderr, " layout ascent: %d (pixels)\n", *ascent_p); - fprintf(stderr, " layout descent: %d (pixels)\n", *descent_p); + fprintf(stderr, "font layout created:\n"); + fprintf(stderr, " widget: %p\n", widget); + //fprintf(stderr, " font description:%p\n", fp); + fprintf(stderr, " font size: %f\n", fs); + fprintf(stderr, " layout text: \"%s\" (utf8)\n", utf8); + fprintf(stderr, " layout width: %d\n", *width_p); + fprintf(stderr, " layout height: %d\n", *height_p); + fprintf(stderr, " layout ascent: %d (pixels)\n", *ascent_p); + fprintf(stderr, " layout descent: %d (pixels)\n", *descent_p); #endif - return layout; + return layout; } /** @@ -248,7 +248,7 @@ PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void wlibFontDestroyPangoLayout(PangoLayout *layout) { - g_object_ref_sink(layout); + g_object_ref_sink(layout); g_object_unref(layout); } @@ -259,9 +259,9 @@ void wlibFontDestroyPangoLayout(PangoLayout *layout) void wInitializeFonts() { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } } /** @@ -272,41 +272,41 @@ void wInitializeFonts() */ void wSelectFont( - const char * title) + const char * title) { - if (!fontInitted) { - fontInit(); - } - - if (fontSelectionDialog == NULL) { - fontSelectionDialog = gtk_font_selection_dialog_new(_("Font Select")); - gtk_window_set_position(GTK_WINDOW(fontSelectionDialog), GTK_WIN_POS_MOUSE); - gtk_window_set_modal(GTK_WINDOW(fontSelectionDialog), TRUE); - gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG( - fontSelectionDialog), sampleText); - g_signal_connect(G_OBJECT(fontSelectionDialog), "response", - G_CALLBACK(fontSelectionDialogCallback), NULL); - g_signal_connect(G_OBJECT(fontSelectionDialog), "destroy", - G_CALLBACK(gtk_widget_destroyed), &fontSelectionDialog); - } - - gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title); - - if (curFont != NULL) { - gchar *fontName; - - /* the curFont description contains the latest font info - * which is depended on the current scale - * overwrite it with the absoluteFontSize */ - pango_font_description_set_size(curFont->fontDescription, - FONTSIZE_TO_PANGOSIZE(absoluteFontSize) * PANGO_SCALE); - fontName = pango_font_description_to_string(curFont->fontDescription); - gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG( - fontSelectionDialog), fontName); - g_free(fontName); - } - - gtk_widget_show(fontSelectionDialog); + if (!fontInitted) { + fontInit(); + } + + if (fontSelectionDialog == NULL) { + fontSelectionDialog = gtk_font_selection_dialog_new(_("Font Select")); + gtk_window_set_position(GTK_WINDOW(fontSelectionDialog), GTK_WIN_POS_MOUSE); + gtk_window_set_modal(GTK_WINDOW(fontSelectionDialog), TRUE); + gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG( + fontSelectionDialog), sampleText); + g_signal_connect(G_OBJECT(fontSelectionDialog), "response", + G_CALLBACK(fontSelectionDialogCallback), NULL); + g_signal_connect(G_OBJECT(fontSelectionDialog), "destroy", + G_CALLBACK(gtk_widget_destroyed), &fontSelectionDialog); + } + + gtk_window_set_title(GTK_WINDOW(fontSelectionDialog), title); + + if (curFont != NULL) { + gchar *fontName; + + /* the curFont description contains the latest font info + * which is depended on the current scale + * overwrite it with the absoluteFontSize */ + pango_font_description_set_size(curFont->fontDescription, + FONTSIZE_TO_PANGOSIZE(absoluteFontSize) * PANGO_SCALE); + fontName = pango_font_description_to_string(curFont->fontDescription); + gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG( + fontSelectionDialog), fontName); + g_free(fontName); + } + + gtk_widget_show(fontSelectionDialog); } /** @@ -317,11 +317,11 @@ void wSelectFont( static wFont_p wlibSelectedFont(void) { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } - return curFont; + return curFont; } /** @@ -332,16 +332,16 @@ static wFont_p wlibSelectedFont(void) wFontSize_t wSelectedFontSize(void) { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } #if WLIB_FONT_DEBUG >= 3 - fprintf(stderr, "the font size of current font description is: %d\n", - pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); - fprintf(stderr, "the font size of absoluteFontSize is: %d\n",absoluteFontSize); + fprintf(stderr, "the font size of current font description is: %d\n", + pango_font_description_get_size(curFont->fontDescription)/PANGO_SCALE); + fprintf(stderr, "the font size of absoluteFontSize is: %d\n",absoluteFontSize); #endif - return absoluteFontSize; + return absoluteFontSize; } /** @@ -353,7 +353,7 @@ wFontSize_t wSelectedFontSize(void) void wSetSelectedFontSize(wFontSize_t size) { - absoluteFontSize = size; + absoluteFontSize = size; } /** @@ -368,30 +368,30 @@ void wSetSelectedFontSize(wFontSize_t size) const char *wlibFontTranslate(wFont_p fp) { - static gchar *fontName = NULL; + static gchar *fontName = NULL; - if (fontName != NULL) { - g_free(fontName); - } + if (fontName != NULL) { + g_free(fontName); + } - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } - if (fp == NULL) { - fp = wlibSelectedFont(); - } + if (fp == NULL) { + fp = wlibSelectedFont(); + } - if (fp == NULL) { - fp = standardFonts[0][FW_MEDIUM][FS_REGULAR]; - } + if (fp == NULL) { + fp = standardFonts[0][FW_MEDIUM][FS_REGULAR]; + } - fontName = pango_font_description_to_string(fp->fontDescription); + fontName = pango_font_description_to_string(fp->fontDescription); #if WLIB_FONT_DEBUG >= 2 - fprintf(stderr, "font translation: "); - fprintf(stderr, " \"%s\"\n", fontName); + fprintf(stderr, "font translation: "); + fprintf(stderr, " \"%s\"\n", fontName); #endif - return (const char *) fontName; + return (const char *) fontName; } /** @@ -402,9 +402,9 @@ const char *wlibFontTranslate(wFont_p fp) wFont_p wStandardFont(int face, wBool_t bold, wBool_t italic) { - if (!fontInitted) { - fontInit(); - } + if (!fontInitted) { + fontInit(); + } - return standardFonts[face-F_TIMES][bold][italic]; + return standardFonts[face-F_TIMES][bold][italic]; } diff --git a/app/wlib/gtklib/gtkdraw-cairo.c b/app/wlib/gtklib/gtkdraw-cairo.c index 033e0ec..f24bde6 100644 --- a/app/wlib/gtklib/gtkdraw-cairo.c +++ b/app/wlib/gtklib/gtkdraw-cairo.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -49,40 +49,40 @@ static long drawVerbose = 0; wBool_t wDrawDoTempDraw = TRUE; struct wDrawBitMap_t { - int w; - int h; - int x; - int y; - const unsigned char * bits; - GdkPixmap * pixmap; - GdkBitmap * mask; - }; + int w; + int h; + int x; + int y; + const unsigned char * bits; + GdkPixmap * pixmap; + GdkBitmap * mask; +}; //struct wDraw_t { - //WOBJ_COMMON - //void * context; - //wDrawActionCallBack_p action; - //wDrawRedrawCallBack_p redraw; +//WOBJ_COMMON +//void * context; +//wDrawActionCallBack_p action; +//wDrawRedrawCallBack_p redraw; - //GdkPixmap * pixmap; - //GdkPixmap * pixmapBackup; +//GdkPixmap * pixmap; +//GdkPixmap * pixmapBackup; - //double dpi; +//double dpi; - //GdkGC * gc; - //wDrawWidth lineWidth; - //wDrawOpts opts; - //wWinPix_t maxW; - //wWinPix_t maxH; - //unsigned long lastColor; - //wBool_t lastColorInverted; - //const char * helpStr; +//GdkGC * gc; +//wDrawWidth lineWidth; +//wDrawOpts opts; +//wWinPix_t maxW; +//wWinPix_t maxH; +//unsigned long lastColor; +//wBool_t lastColorInverted; +//const char * helpStr; - //wWinPix_t lastX; - //wWinPix_t lastY; +//wWinPix_t lastX; +//wWinPix_t lastY; - //wBool_t delayUpdate; - //}; +//wBool_t delayUpdate; +//}; struct wDraw_t psPrint_d; @@ -109,95 +109,10 @@ struct wDraw_t psPrint_d; * *******************************************************************************/ -static cairo_t* gtkDrawCreateCairoCursorContext( - wControl_p ct, - cairo_surface_t * surf, - wDrawWidth width, - wDrawLineType_e lineType, - wDrawColor color, - wDrawOpts opts ) -{ - cairo_t* cairo; - - cairo = cairo_create(surf); - - width = width ? abs(width) : 1; - cairo_set_line_width(cairo, width); - - cairo_set_line_cap(cairo, CAIRO_LINE_CAP_BUTT); - cairo_set_line_join(cairo, CAIRO_LINE_JOIN_MITER); - - switch(lineType) - { - case wDrawLineSolid: - { - cairo_set_dash(cairo, 0, 0, 0); - break; - } - case wDrawLineDash: - { - double dashes[] = { 5, 3 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineDot: - { - double dashes[] = { 1, 2 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineDashDot: - { - double dashes[] = { 5, 2, 1, 2 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineDashDotDot: - { - double dashes[] = { 5, 2, 1, 2, 1, 2 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineCenter: - { - double dashes[] = { 8, 3, 5, 3}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0.0); - break; - } - case wDrawLinePhantom: - { - double dashes[] = { 8, 3, 5, 3, 5, 3}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0.0); - break; - } - - } - GdkColor * gcolor; - - - cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); - gcolor = wlibGetColor(color, TRUE); - - if (ct->type == B_DRAW) { - wDraw_p bd = (wDraw_p)ct; - bd->lastColor = color; - } - - cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0, 1.0); - - return cairo; -} - wBool_t wDrawSetTempMode( - wDraw_p bd, - wBool_t bTemp ) + wDraw_p bd, + wBool_t bTemp ) { wBool_t ret = bd->bTempMode; bd->bTempMode = bTemp; @@ -209,102 +124,99 @@ wBool_t wDrawSetTempMode( } static cairo_t* gtkDrawCreateCairoContext( - wDraw_p bd, - GdkDrawable * win, - wDrawWidth width, - wDrawLineType_e lineType, - wDrawColor color, - wDrawOpts opts ) + wDraw_p bd, + GdkDrawable * win, + wDrawWidth width, + wDrawLineType_e lineType, + wDrawColor color, + wDrawOpts opts ) { cairo_t* cairo; - if (win) + if (win) { cairo = gdk_cairo_create(win); - else { + } else { if (opts & wDrawOptTemp) { - if ( ! bd->bTempMode ) - printf( "Temp draw in Main Mode. Contact Developers. See %s:%d\n", "gtkdraw-cario.c", __LINE__+1 ); -/* Temp Draw In Main Mode: - You are seeing this message because there is a wDraw*() call on tempD but you are not in the context of TempRedraw() - Typically this happens when Cmd<Object>() is processing a C_DOWN or C_MOVE action and it writes directly to tempD - Instead it sould set some state which allows c_redraw to do the actual drawing - If you set a break point on the printf you'll see the offending wDraw*() call in the traceback - It should be sufficient to remove that draw code or move it to C_REDRAW - This is not fatal but the draw will be ineffective because the next TempRedraw() will erase the temp surface - before the expose event can copy (or bitblt) it -*/ + if ( ! bd->bTempMode ) { + printf( "Temp draw in Main Mode. Contact Developers. See %s:%d\n", + "gtkdraw-cario.c", __LINE__+1 ); + } + /* Temp Draw In Main Mode: + You are seeing this message because there is a wDraw*() call on tempD but you are not in the context of TempRedraw() + Typically this happens when Cmd<Object>() is processing a C_DOWN or C_MOVE action and it writes directly to tempD + Instead it sould set some state which allows c_redraw to do the actual drawing + If you set a break point on the printf you'll see the offending wDraw*() call in the traceback + It should be sufficient to remove that draw code or move it to C_REDRAW + This is not fatal but the draw will be ineffective because the next TempRedraw() will erase the temp surface + before the expose event can copy (or bitblt) it + */ cairo = cairo_create(bd->temp_surface); } else { - if ( bd->bTempMode ) - printf( "Main draw in Temp Mode. Contact Developers. See %s:%d\n", "gtkdraw-cario.c", __LINE__+1 ); -/* Main Draw In Temp Mode: - You are seeing this message because there is a wDraw*() call on mainD but you are in the context of TempRedraw() - Typically this happens when C_REDRAW action calls wDraw*() on mainD, in which case it should be writing to tempD. - Or the wDraw*() call should be removed if it is redundant. - If you set a break point on the printf you'll see the offending wDraw*() call in the traceback - This is not fatal but could result in garbage being left on the screen if the command is cancelled. -*/ + if ( bd->bTempMode ) { + printf( "Main draw in Temp Mode. Contact Developers. See %s:%d\n", + "gtkdraw-cario.c", __LINE__+1 ); + } + /* Main Draw In Temp Mode: + You are seeing this message because there is a wDraw*() call on mainD but you are in the context of TempRedraw() + Typically this happens when C_REDRAW action calls wDraw*() on mainD, in which case it should be writing to tempD. + Or the wDraw*() call should be removed if it is redundant. + If you set a break point on the printf you'll see the offending wDraw*() call in the traceback + This is not fatal but could result in garbage being left on the screen if the command is cancelled. + */ cairo = gdk_cairo_create(bd->pixmap); } } width = width ? abs(width) : 1; - if ( color == wDrawColorWhite ) - width += 1; // Remove ghosts + if ( color == wDrawColorWhite ) { + width += 1; // Remove ghosts + } cairo_set_line_width(cairo, width); cairo_set_line_cap(cairo, CAIRO_LINE_CAP_BUTT); cairo_set_line_join(cairo, CAIRO_LINE_JOIN_MITER); - switch(lineType) - { - case wDrawLineSolid: - { - cairo_set_dash(cairo, 0, 0, 0); - break; - } - case wDrawLineDash: - { - double dashes[] = { 5, 3 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineDot: - { - double dashes[] = { 1, 2 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineDashDot: - { - double dashes[] = { 5, 2, 1, 2 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineDashDotDot: - { - double dashes[] = { 5, 2, 1, 2, 1, 2 }; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0); - break; - } - case wDrawLineCenter: - { - double dashes[] = { 8, 3, 5, 3}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0.0); - break; - } - case wDrawLinePhantom: - { - double dashes[] = { 8, 3, 5, 3, 5, 3}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cairo, dashes, len_dashes, 0.0); - break; - } + switch(lineType) { + case wDrawLineSolid: { + cairo_set_dash(cairo, 0, 0, 0); + break; + } + case wDrawLineDash: { + double dashes[] = { 5, 3 }; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0); + break; + } + case wDrawLineDot: { + double dashes[] = { 1, 2 }; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0); + break; + } + case wDrawLineDashDot: { + double dashes[] = { 5, 2, 1, 2 }; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0); + break; + } + case wDrawLineDashDotDot: { + double dashes[] = { 5, 2, 1, 2, 1, 2 }; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0); + break; + } + case wDrawLineCenter: { + double dashes[] = { 8, 3, 5, 3}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0.0); + break; + } + case wDrawLinePhantom: { + double dashes[] = { 8, 3, 5, 3, 5, 3}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cairo, dashes, len_dashes, 0.0); + break; + } } GdkColor * gcolor; @@ -315,49 +227,22 @@ static cairo_t* gtkDrawCreateCairoContext( bd->lastColor = color; - cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0); + cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, + gcolor->blue / 65535.0); return cairo; } -static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) { +static cairo_t* gtkDrawDestroyCairoContext(cairo_t *cairo) +{ cairo_destroy(cairo); return NULL; } -#ifdef CURSOR_SURFACE -cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, wWinPix_t height, wDrawColor color, wDrawOpts opts) { - cairo_t * cairo = NULL; - - if ((opts&wDrawOptCursor) || (opts&wDrawOptCursorRmv)) { - - if (surface!=NULL || surface->width != width || surface->height != height) { - if (surface->surface) cairo_surface_destroy(surface->surface); - surface->surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width,height ); - surface->width = width; - surface->height = height; - - } - - cairo = gtkDrawCreateCairoCursorContext(ct,surface->surface,0,wDrawLineSolid, color, opts); - cairo_save(cairo); - cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0); - cairo_paint(cairo); - cairo_restore(cairo); - surface->show = TRUE; - cairo_set_operator(cairo,CAIRO_OPERATOR_SOURCE); - - } - - return cairo; - -} -#endif - - void wDrawDelayUpdate( - wDraw_p bd, - wBool_t delay ) +void wDrawDelayUpdate( + wDraw_p bd, + wBool_t delay ) { GdkRectangle update_rect; @@ -372,17 +257,17 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, } - void wDrawLine( - wDraw_p bd, - wDrawPix_t x0, wDrawPix_t y0, - wDrawPix_t x1, wDrawPix_t y1, - wDrawWidth width, - wDrawLineType_e lineType, - wDrawColor color, - wDrawOpts opts ) +void wDrawLine( + wDraw_p bd, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t x1, wDrawPix_t y1, + wDrawWidth width, + wDrawLineType_e lineType, + wDrawColor color, + wDrawOpts opts ) { - GdkGC * gc; - GdkRectangle update_rect; +// GdkGC * gc; +// GdkRectangle update_rect; if ( bd == &psPrint_d ) { psPrintLine( x0, y0, x1, y1, width, lineType, color, opts ); @@ -393,13 +278,15 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, x1 = INMAPX(bd,x1); y1 = INMAPY(bd,y1); - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color, opts); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color, + opts); cairo_move_to(cairo, x0 + 0.5, y0 + 0.5); cairo_line_to(cairo, x1 + 0.5, y1 + 0.5); cairo_stroke(cairo); gtkDrawDestroyCairoContext(cairo); - if (bd->widget) - gtk_widget_queue_draw(GTK_WIDGET(bd->widget)); //,x0,y0+1,x1,y1+1); + if (bd->widget) { + gtk_widget_queue_draw(GTK_WIDGET(bd->widget)); //,x0,y0+1,x1,y1+1); + } } @@ -418,79 +305,86 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, */ - void wDrawArc( - wDraw_p bd, - wDrawPix_t x0, wDrawPix_t y0, - wDrawPix_t r, - wAngle_t angle0, - wAngle_t angle1, - int drawCenter, - wDrawWidth width, - wDrawLineType_e lineType, - wDrawColor color, - wDrawOpts opts ) +void wDrawArc( + wDraw_p bd, + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t r, + wAngle_t angle0, + wAngle_t angle1, + int drawCenter, + wDrawWidth width, + wDrawLineType_e lineType, + wDrawColor color, + wDrawOpts opts ) { int x, y, w, h; if ( bd == &psPrint_d ) { - psPrintArc( x0, y0, r, angle0, angle1, drawCenter, width, lineType, color, opts ); + psPrintArc( x0, y0, r, angle0, angle1, drawCenter, width, lineType, color, + opts ); return; } - if (r < 6.0/75.0) return; + if (r < 6.0/75.0) { return; } x = INMAPX(bd,x0-r); y = INMAPY(bd,y0+r); w = 2*r; h = 2*r; // now create the new arc - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color, opts); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, width, lineType, color, + opts); cairo_new_path(cairo); // its center point marker - if(drawCenter) - { + if(drawCenter) { // draw a small crosshair to mark the center of the curve - cairo_move_to(cairo, INMAPX(bd, x0 - (CENTERMARK_LENGTH / 2)), INMAPY(bd, y0 )); + cairo_move_to(cairo, INMAPX(bd, x0 - (CENTERMARK_LENGTH / 2)), INMAPY(bd, + y0 )); cairo_line_to(cairo, INMAPX(bd, x0 + (CENTERMARK_LENGTH / 2)), INMAPY(bd, y0 )); cairo_move_to(cairo, INMAPX(bd, x0), INMAPY(bd, y0 - (CENTERMARK_LENGTH / 2 ))); - cairo_line_to(cairo, INMAPX(bd, x0) , INMAPY(bd, y0 + (CENTERMARK_LENGTH / 2))); + cairo_line_to(cairo, INMAPX(bd, x0), INMAPY(bd, y0 + (CENTERMARK_LENGTH / 2))); cairo_new_sub_path( cairo ); } // draw the curve itself - cairo_arc_negative(cairo, INMAPX(bd, x0), INMAPY(bd, y0), r, (angle0 - 90 + angle1) * (M_PI / 180.0), (angle0 - 90) * (M_PI / 180.0)); + cairo_arc_negative(cairo, INMAPX(bd, x0), INMAPY(bd, y0), r, + (angle0 - 90 + angle1) * (M_PI / 180.0), (angle0 - 90) * (M_PI / 180.0)); cairo_stroke(cairo); gtkDrawDestroyCairoContext(cairo); - if (bd->widget && !bd->delayUpdate) - gtk_widget_queue_draw_area(bd->widget,x,y,w,h); + if (bd->widget && !bd->delayUpdate) { + gtk_widget_queue_draw_area(bd->widget,x,y,w,h); + } } - void wDrawPoint( - wDraw_p bd, - wDrawPix_t x0, wDrawPix_t y0, - wDrawColor color, - wDrawOpts opts ) +void wDrawPoint( + wDraw_p bd, + wDrawPix_t x0, wDrawPix_t y0, + wDrawColor color, + wDrawOpts opts ) { - GdkRectangle update_rect; +// GdkRectangle update_rect; if ( bd == &psPrint_d ) { /*psPrintArc( x0, y0, r, angle0, angle1, drawCenter, width, lineType, color, opts );*/ return; } - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, + opts); cairo_new_path(cairo); cairo_arc(cairo, INMAPX(bd, x0), INMAPY(bd, y0), 0.75, 0, 2 * M_PI); cairo_stroke(cairo); gtkDrawDestroyCairoContext(cairo); - if (bd->widget && !bd->delayUpdate) - gtk_widget_queue_draw_area(bd->widget,INMAPX(bd,x0-0.75),INMAPY(bd,y0+0.75),2,2); + if (bd->widget && !bd->delayUpdate) { + gtk_widget_queue_draw_area(bd->widget,INMAPX(bd,x0-0.75),INMAPY(bd,y0+0.75),2, + 2); + } } @@ -500,15 +394,15 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, * ******************************************************************************/ - void wDrawString( - wDraw_p bd, - wDrawPix_t x, wDrawPix_t y, - wAngle_t a, - const char * s, - wFont_p fp, - wFontSize_t fs, - wDrawColor color, - wDrawOpts opts ) +void wDrawString( + wDraw_p bd, + wDrawPix_t x, wDrawPix_t y, + wAngle_t a, + const char * s, + wFont_p fp, + wFontSize_t fs, + wDrawColor color, + wDrawOpts opts ) { PangoLayout *layout; GdkRectangle update_rect; @@ -528,19 +422,21 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, y = INMAPY(bd,y); /* draw text */ - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, + opts); cairo_save( cairo ); cairo_identity_matrix(cairo); layout = wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s, - &w, &h, - &ascent, &descent, &baseline); + &w, &h, + &ascent, &descent, &baseline); /* cairo does not support the old method of text removal by overwrite; * if color is White, then overwrite old text with a White rectangle */ GdkColor* const gcolor = wlibGetColor(color, TRUE); - cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0); + cairo_set_source_rgb(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, + gcolor->blue / 65535.0); cairo_translate( cairo, x, y ); cairo_rotate( cairo, angle ); @@ -554,7 +450,7 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, cairo_restore( cairo ); gtkDrawDestroyCairoContext(cairo); - if (bd->delayUpdate || bd->widget == NULL) return; + if (bd->delayUpdate || bd->widget == NULL) { return; } /* recalculate the area to be updated * for simplicity sake I added plain text height ascent and descent, @@ -565,20 +461,22 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, update_rect.width = (gint) (w * cos( angle ) + h * sin(angle))+2; update_rect.height = (gint) (h * sin( angle ) + w * cos(angle))+2; gtk_widget_draw(bd->widget, &update_rect); - if (bd->widget && !bd->delayUpdate) - gtk_widget_queue_draw_area(bd->widget, update_rect.x, update_rect.y, update_rect.width, update_rect.height); - + if (bd->widget && !bd->delayUpdate) { + gtk_widget_queue_draw_area(bd->widget, update_rect.x, update_rect.y, + update_rect.width, update_rect.height); + } + } - void wDrawGetTextSize( - wDrawPix_t *w, - wDrawPix_t *h, - wDrawPix_t *d, - wDrawPix_t *a, - wDraw_p bd, - const char * s, - wFont_p fp, - wFontSize_t fs ) +void wDrawGetTextSize( + wDrawPix_t *w, + wDrawPix_t *h, + wDrawPix_t *d, + wDrawPix_t *a, + wDraw_p bd, + const char * s, + wFont_p fp, + wFontSize_t fs ) { wDrawPix_t textWidth; wDrawPix_t textHeight; @@ -590,14 +488,15 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, *h = 0; /* draw text */ - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, wDrawColorBlack, bd->bTempMode?wDrawOptTemp:0 ); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, + wDrawColorBlack, bd->bTempMode?wDrawOptTemp:0 ); cairo_identity_matrix(cairo); wlibFontDestroyPangoLayout( - wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s, - &textWidth, &textHeight, - &ascent, &descent, &baseline) ); + wlibFontCreatePangoLayout(bd->widget, cairo, fp, fs, s, + &textWidth, &textHeight, + &ascent, &descent, &baseline) ); *w = textWidth; *h = textHeight; @@ -605,8 +504,9 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, //*d = textHeight-ascent; *d = descent; - if (debugWindow >= 3) + if (debugWindow >= 3) { fprintf(stderr, "text metrics: w=%0.1f, h=%0.1f, d=%0.1f\n", *w, *h, *d); + } gtkDrawDestroyCairoContext(cairo); } @@ -619,9 +519,9 @@ cairo_t* CreateCursorSurface(wControl_p ct, wSurface_p surface, wWinPix_t width, *******************************************************************************/ static void wlibDrawFilled( - cairo_t * cairo, - wDrawColor color, - wDrawOpts opt ) + cairo_t * cairo, + wDrawColor color, + wDrawOpts opt ) { if ( (opt & wDrawOptTransparent) != 0 ) { if ( (opt & wDrawOptTemp) == 0 ) { @@ -630,26 +530,28 @@ static void wlibDrawFilled( cairo_fill_preserve(cairo); } GdkColor * gcolor = wlibGetColor(color, TRUE); - cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0, 1.0); + cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, + gcolor->blue / 65535.0, 1.0); cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); cairo_stroke_preserve(cairo); cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); - cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, gcolor->blue / 65535.0, 0.3); + cairo_set_source_rgba(cairo, gcolor->red / 65535.0, gcolor->green / 65535.0, + gcolor->blue / 65535.0, 0.3); } cairo_fill(cairo); } - void wDrawFilledRectangle( - wDraw_p bd, - wDrawPix_t x, - wDrawPix_t y, - wDrawPix_t w, - wDrawPix_t h, - wDrawColor color, - wDrawOpts opt ) +void wDrawFilledRectangle( + wDraw_p bd, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h, + wDrawColor color, + wDrawOpts opt ) { - GdkRectangle update_rect; +// GdkRectangle update_rect; if ( bd == &psPrint_d ) { psPrintFillRectangle( x, y, w, h, color, opt ); @@ -659,7 +561,8 @@ static void wlibDrawFilled( x = INMAPX(bd,x); y = INMAPY(bd,y)-h; - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opt); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, + opt); cairo_move_to(cairo, x, y); cairo_rel_line_to(cairo, w, 0); @@ -669,22 +572,23 @@ static void wlibDrawFilled( wlibDrawFilled( cairo, color, opt ); gtkDrawDestroyCairoContext(cairo); - if (bd->widget && !bd->delayUpdate) + if (bd->widget && !bd->delayUpdate) { gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),x,y,w,h); + } } - void wDrawPolygon( - wDraw_p bd, - wDrawPix_t p[][2], - wPolyLine_e type[], - int cnt, - wDrawColor color, - wDrawWidth dw, - wDrawLineType_e lt, - wDrawOpts opt, - int fill, - int open ) +void wDrawPolygon( + wDraw_p bd, + wDrawPix_t p[][2], + wPolyLine_e type[], + int cnt, + wDrawColor color, + wDrawWidth dw, + wDrawLineType_e lt, + wDrawOpts opt, + int fill, + int open ) { static int maxCnt = 0; static GdkPoint *points; @@ -695,35 +599,37 @@ static void wlibDrawFilled( return; } - if (cnt > maxCnt) { - if (points == NULL) + if (cnt > maxCnt) { + if (points == NULL) { points = (GdkPoint*)malloc( cnt*sizeof *points ); - else + } else { points = (GdkPoint*)realloc( points, cnt*sizeof *points ); - if (points == NULL) + } + if (points == NULL) { abort(); + } maxCnt = cnt; } wDrawPix_t min_x,max_x,min_y,max_y; min_x = max_x = INMAPX(bd,p[0][0]); min_y = max_y = INMAPY(bd,p[0][1]); - for (i=0; i<cnt; i++) { - points[i].x = INMAPX(bd,p[i][0]); - if (points[i].x < min_x) min_x = points[i].x; - if (points[i].y < min_y) min_y = points[i].y; - if (points[i].x > max_x) max_x = points[i].x; - if (points[i].y > max_y) max_y = points[i].y; - points[i].y = INMAPY(bd,p[i][1]); + for (i=0; i<cnt; i++) { + points[i].x = INMAPX(bd,p[i][0]); + if (points[i].x < min_x) { min_x = points[i].x; } + if (points[i].y < min_y) { min_y = points[i].y; } + if (points[i].x > max_x) { max_x = points[i].x; } + if (points[i].y > max_y) { max_y = points[i].y; } + points[i].y = INMAPY(bd,p[i][1]); } - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, fill?0:dw, fill?wDrawLineSolid:lt, color, opt); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, fill?0:dw, + fill?wDrawLineSolid:lt, color, opt); - for(i = 0; i < cnt; ++i) - { + for(i = 0; i < cnt; ++i) { int j = i-1; int k = i+1; - if (j < 0) j = cnt-1; - if (k > cnt-1) k = 0; + if (j < 0) { j = cnt-1; } + if (k > cnt-1) { k = 0; } GdkPoint mid0, mid1, mid3, mid4; // save is static because of an apparent compiler bug on Linux // This happens with RelWithDebInfo target @@ -771,20 +677,24 @@ static void wlibDrawFilled( save = points[0]; } else { cairo_move_to(cairo, mid0.x, mid0.y); - if (type[i] == 1) - cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y, mid1.x, mid1.y); - else + if (type[i] == 1) { + cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y, + mid1.x, mid1.y); + } else { cairo_curve_to(cairo, mid3.x, mid3.y, mid4.x, mid4.y, mid1.x, mid1.y); + } save = mid0; } } else if (!type || type[i] == wPolyLineStraight || (open && (i==cnt-1))) { cairo_line_to(cairo, points[i].x, points[i].y); } else { cairo_line_to(cairo, mid0.x, mid0.y); - if (type[i] == wPolyLineSmooth) - cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y, mid1.x, mid1.y); - else + if (type[i] == wPolyLineSmooth) { + cairo_curve_to(cairo, points[i].x, points[i].y, points[i].x, points[i].y, + mid1.x, mid1.y); + } else { cairo_curve_to(cairo, mid3.x, mid3.y, mid4.x, mid4.y, mid1.x, mid1.y); + } } if ((i==cnt-1) && !open) { cairo_line_to(cairo, save.x, save.y); @@ -796,18 +706,20 @@ static void wlibDrawFilled( cairo_stroke(cairo); } gtkDrawDestroyCairoContext(cairo); - if (bd->widget && !bd->delayUpdate) - gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),min_x,min_y,max_x-min_y,max_y-min_y); + if (bd->widget && !bd->delayUpdate) { + gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),min_x,min_y,max_x-min_y, + max_y-min_y); + } } - void wDrawFilledCircle( - wDraw_p bd, - wDrawPix_t x0, - wDrawPix_t y0, - wDrawPix_t r, - wDrawColor color, - wDrawOpts opt ) +void wDrawFilledCircle( + wDraw_p bd, + wDrawPix_t x0, + wDrawPix_t y0, + wDrawPix_t r, + wDrawColor color, + wDrawOpts opt ) { int x, y, w, h; @@ -821,22 +733,26 @@ static void wlibDrawFilled( w = 2*r; h = 2*r; - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opt); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, + opt); cairo_arc(cairo, INMAPX(bd, x0), INMAPY(bd, y0), r, 0, 2 * M_PI); wlibDrawFilled( cairo, color, opt ); gtkDrawDestroyCairoContext(cairo); - if (bd->widget) - gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),x,y,w,h); + if (bd->widget && !bd->delayUpdate) { + gtk_widget_queue_draw_area(GTK_WIDGET(bd->widget),x,y,w,h); + } } - void wDrawClearTemp(wDraw_p bd) { +void wDrawClearTemp(wDraw_p bd) +{ //Wipe out temp space with 0 alpha (transparent) static long cDCT = 0; - if ( iDrawLog ) + if ( iDrawLog ) { printf( "wDrawClearTemp %ld\n", cDCT++ ); + } cairo_t* cairo = cairo_create(bd->temp_surface); cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0); @@ -848,29 +764,32 @@ static void wlibDrawFilled( cairo_fill(cairo); cairo_destroy(cairo); - if (bd->widget && !bd->delayUpdate) + if (bd->widget && !bd->delayUpdate) { gtk_widget_queue_draw(bd->widget); - } + } +} - void wDrawClear( - wDraw_p bd ) +void wDrawClear( + wDraw_p bd ) { - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, wDrawColorWhite, 0); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, + wDrawColorWhite, 0); cairo_move_to(cairo, 0, 0); cairo_rel_line_to(cairo, bd->w, 0); cairo_rel_line_to(cairo, 0, bd->h); cairo_rel_line_to(cairo, -bd->w, 0); cairo_fill(cairo); - if (bd->widget) + if (bd->widget) { gtk_widget_queue_draw(bd->widget); + } gtkDrawDestroyCairoContext(cairo); wDrawClearTemp(bd); } - void * wDrawGetContext( - wDraw_p bd ) +void * wDrawGetContext( + wDraw_p bd ) { return bd->context; } @@ -882,13 +801,13 @@ static void wlibDrawFilled( *******************************************************************************/ - wDrawBitMap_p wDrawBitMapCreate( - wDraw_p bd, - int w, - int h, - int x, - int y, - const unsigned char * fbits ) +wDrawBitMap_p wDrawBitMapCreate( + wDraw_p bd, + int w, + int h, + int x, + int y, + const unsigned char * fbits ) { wDrawBitMap_p bm; @@ -903,23 +822,21 @@ static void wlibDrawFilled( } - void wDrawBitMap( - wDraw_p bd, - wDrawBitMap_p bm, - wDrawPix_t x, wDrawPix_t y, - wDrawColor color, - wDrawOpts opts ) +void wDrawBitMap( + wDraw_p bd, + wDrawBitMap_p bm, + wDrawPix_t x, wDrawPix_t y, + wDrawColor color, + wDrawOpts opts ) { int i, j, wb; wDrawPix_t xx, yy; - wControl_p b; - wWin_p win; - GdkDrawable * gdk_drawable, * cairo_surface; GtkWidget * widget = bd->widget; - + static long cDBM = 0; - if ( iDrawLog ) + if ( iDrawLog ) { printf( "wDrawBitMap %ld\n", cDBM++ ); + } x = INMAPX( bd, x-bm->x ); y = INMAPY( bd, y-bm->y )-bm->h; @@ -927,32 +844,6 @@ static void wlibDrawFilled( cairo_t* cairo; -#ifdef CURSOR_SURFACE - if (opts&wDrawOptCursorRmv) color = wDrawColorWhite; //Wipeout existing cursor draw (simplistic first) - - - if ((opts&wDrawOptCursor) || (opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) { - - cairo = CreateCursorSurface((wControl_p)bd,&bd->cursor_surface, bd->w, bd->h, color, opts); - - if ((opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) { - bd->cursor_surface.show = FALSE; - } else bd->cursor_surface.show = TRUE; - - widget = bd->widget; - - - } else { - cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts); - widget = bd->widget; - } - - GtkWidget * new_widget = widget; - GdkGC * gc = NULL; - GdkWindow * gdk_window = NULL; - - win = bd->parent; -#endif cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, color, opts); @@ -961,55 +852,15 @@ static void wlibDrawFilled( if ( bm->bits[ j*wb+(i>>3) ] & (1<<(i&07)) ) { xx = x+i; yy = y+j; -#ifdef CURSOR_SURFACE - if ( 0 <= xx && xx < bd->w && - 0 <= yy && yy < bd->h ) { - b = (wControl_p)bd; - } else if ( (opts&wDrawOptNoClip) != 0 ) { - xx += bd->realX; - yy += bd->realY; - b = wlibGetControlFromPos( bd->parent, xx, yy ); - if ( b) { - xx -= b->realX; - yy -= b->realY; - new_widget = b->widget; - } else { - new_widget = bd->parent->widget; - } - } else { - continue; - } - - if (new_widget != widget) { - if (cairo) - cairo_destroy(cairo); - cairo = NULL; - if (widget && (widget != bd->parent->widget)) - gtk_widget_queue_draw(GTK_WIDGET(widget)); - if ( (opts&wDrawOptCursor) || (opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) { - if (!b) b = (wControl_p)(bd->parent->widget); - cairo = CreateCursorSurface(b,&b->cursor_surface, b->w, b->h, color, opts); - widget = b->widget; - gc = NULL; - if ((opts&wDrawOptCursorRmv) || (opts&wDrawOptCursorQuit)) - b->cursor_surface.show = FALSE; - else - b->cursor_surface.show = TRUE; - } else { - continue; - } - widget = new_widget; - } - if ((opts&wDrawOptCursorQuit) || (opts&wDrawOptCursorQuit) ) continue; -#endif cairo_rectangle(cairo, xx, yy, 1, 1); cairo_fill(cairo); } cairo_destroy(cairo); - if (widget && !bd->delayUpdate) + if (widget && !bd->delayUpdate) { gtk_widget_queue_draw_area(GTK_WIDGET(widget), x, y, bm->w, bm->h); + } } @@ -1022,8 +873,8 @@ static void wlibDrawFilled( - void wDrawSaveImage( - wDraw_p bd ) +void wDrawSaveImage( + wDraw_p bd ) { cairo_t * cr; if ( bd->pixmapBackup ) { @@ -1033,7 +884,7 @@ static void wlibDrawFilled( cr = gdk_cairo_create(bd->pixmapBackup); gdk_cairo_set_source_pixmap(cr, bd->pixmap, 0, 0); - cairo_paint(cr); + cairo_paint(cr); cairo_destroy(cr); cr = NULL; @@ -1041,8 +892,8 @@ static void wlibDrawFilled( } - void wDrawRestoreImage( - wDraw_p bd ) +void wDrawRestoreImage( + wDraw_p bd ) { GdkRectangle update_rect; if ( bd->pixmapBackup ) { @@ -1055,7 +906,7 @@ static void wlibDrawFilled( cr = NULL; - if ( bd->delayUpdate || bd->widget == NULL ) return; + if ( bd->delayUpdate || bd->widget == NULL ) { return; } update_rect.x = 0; update_rect.y = 0; update_rect.width = bd->w; @@ -1065,10 +916,10 @@ static void wlibDrawFilled( } - void wDrawSetSize( - wDraw_p bd, - wWinPix_t w, - wWinPix_t h , void * redraw) +void wDrawSetSize( + wDraw_p bd, + wWinPix_t w, + wWinPix_t h, void * redraw) { wBool_t repaint; if (bd == NULL) { @@ -1077,37 +928,47 @@ static void wlibDrawFilled( } /* Negative values crashes the program */ - if (w < 0 || h < 0) - return; + if ( w <= 0 || h <= 0 ) { + fprintf( stderr, "wDrawSetSize bad size %ldx%ld\n", w, h ); + if ( w <= 0 ) { + w = 100; + } + if ( h <= 0 ) { + h = 100; + } + } repaint = (w != bd->w || h != bd->h); bd->w = w; bd->h = h; gtk_widget_set_size_request( bd->widget, w, h ); - if (repaint) - { - if (bd->pixmap) + if (repaint) { + if (bd->pixmap) { gdk_pixmap_unref( bd->pixmap ); + } bd->pixmap = gdk_pixmap_new( bd->widget->window, w, h, -1 ); - if (bd->temp_surface) + if (bd->temp_surface) { cairo_surface_destroy( bd->temp_surface); + } bd->temp_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, w,h ); wDrawClear( bd ); - if (!redraw) + if (!redraw) { bd->redraw( bd, bd->context, w, h ); + } } /*wRedraw( bd )*/; } - void wDrawGetSize( - wDraw_p bd, - wWinPix_t *w, - wWinPix_t *h ) +void wDrawGetSize( + wDraw_p bd, + wWinPix_t *w, + wWinPix_t *h ) { - if (bd->widget) + if (bd->widget) { wlibControlGetSize( (wControl_p)bd ); + } *w = bd->w-2; *h = bd->h-2; } @@ -1119,32 +980,33 @@ static void wlibDrawFilled( * \return the resolution in dpi */ - double wDrawGetDPI( - wDraw_p d ) +double wDrawGetDPI( + wDraw_p d ) { //if (d == &psPrint_d) - //return 1440.0; + //return 1440.0; //else - return d->dpi; + return d->dpi; } - double wDrawGetMaxRadius( - wDraw_p d ) +double wDrawGetMaxRadius( + wDraw_p d ) { - if (d == &psPrint_d) + if (d == &psPrint_d) { return 10e9; - else + } else { return 32767.0; + } } - void wDrawClip( - wDraw_p d, - wDrawPix_t x, - wDrawPix_t y, - wDrawPix_t w, - wDrawPix_t h ) +void wDrawClip( + wDraw_p d, + wDrawPix_t x, + wDrawPix_t y, + wDrawPix_t w, + wDrawPix_t h ) { GdkRectangle rect; rect.width = (wWinPix_t)w; @@ -1157,38 +1019,29 @@ static void wlibDrawFilled( static gint draw_expose_event( - GtkWidget *widget, - GdkEventExpose *event, - wDraw_p bd) + GtkWidget *widget, + GdkEventExpose *event, + wDraw_p bd) { static long cDEE = 0; if ( iDrawLog ) printf( "draw_expose_event %ld %dx%d+%dx%d %ldx%ld+%ldx%ld\n", cDEE++, - event->area.x, event->area.y, event->area.width, event->area.height, - 0L, bd->w, 0L, bd->h ); + event->area.x, event->area.y, event->area.width, event->area.height, + 0L, bd->w, 0L, bd->h ); cairo_t* cairo = gdk_cairo_create (widget->window); gdk_cairo_set_source_pixmap(cairo,bd->pixmap,0,0); cairo_rectangle(cairo,event->area.x, event->area.y, - event->area.width, event->area.height); + event->area.width, event->area.height); cairo_set_operator(cairo,CAIRO_OPERATOR_SOURCE); cairo_fill(cairo); cairo_set_source_surface(cairo,bd->temp_surface,0,0); cairo_rectangle(cairo,event->area.x, event->area.y, - event->area.width, event->area.height); + event->area.width, event->area.height); cairo_set_operator(cairo,CAIRO_OPERATOR_OVER); cairo_fill(cairo); -#ifdef CURSOR_SURFACE - if (bd->cursor_surface.surface && bd->cursor_surface.show) { - cairo_set_source_surface(cairo,bd->cursor_surface.surface,0,0); - cairo_set_operator(cairo,CAIRO_OPERATOR_OVER); - cairo_rectangle(cairo,event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_fill(cairo); - } -#endif cairo_destroy(cairo); return TRUE; @@ -1196,14 +1049,14 @@ static gint draw_expose_event( static gint draw_configure_event( - GtkWidget *widget, - GdkEventConfigure *event, - wDraw_p bd) + GtkWidget *widget, + GdkEventConfigure *event, + wDraw_p bd) { return TRUE; } -static const char * actionNames[] = { "None", "Move", "LDown", "LDrag", "LUp", "RDown", "RDrag", "RUp", "Text", "ExtKey", "WUp", "WDown", "DblL", "ModK", "ScrU", "ScrD", "ScrL", "ScrR" }; +static const char * actionNames[] = { "None", "Move", "LDown", "LDrag", "LUp", "RDown", "RDrag", "RUp", "Text", "ExtKey", "WUp", "WDown", "DblL", "ModK", "ScrU", "ScrD", "ScrL", "ScrR", "MDown", "MDrag", "MUp" }; /** * Handler for scroll events, ie mouse wheel activity @@ -1212,30 +1065,35 @@ static const char * actionNames[] = { "None", "Move", "LDown", "LDrag", "LUp", " static int scrollTimer; static int timer_busy_count; static wAction_t lastAction; +static int timer_interval = 500; // Start at 0.5 secs -static int ScrollTimerPop(wDraw_p bd) { +static int ScrollTimerPop(wDraw_p bd) +{ - if (timer_busy_count>1) { - timer_busy_count = 0; - scrollTimer = 0; - } else { - timer_busy_count++; - return TRUE; - } - if (drawVerbose >= 2) - printf( "%s-Pop\n", actionNames[lastAction] ); - bd->action( bd, bd->context, lastAction, (wDrawPix_t)0, (wDrawPix_t)0 ); + if (timer_busy_count>4) + timer_interval = 250; //If lots of events 0.25 secs next time + if (timer_busy_count<1) + timer_interval = 500; //If few events 0.5 secs next time - return FALSE; + + if (drawVerbose >= 2) { + printf( "%s-Pop\n", actionNames[lastAction] ); + } + scrollTimer = 0; + timer_busy_count = 0; + // Don't do the action as may no longer be scrolling + // bd->action( bd, bd->context, lastAction, (wDrawPix_t)0, (wDrawPix_t)0 ); + + return FALSE; //Stops timer re-popping } static gint draw_scroll_event( - GtkWidget *widget, - GdkEventScroll *event, - wDraw_p bd) + GtkWidget *widget, + GdkEventScroll *event, + wDraw_p bd) { - wAction_t action; + wAction_t action = 0; static int oldEventX = 0; static int oldEventY = 0; static int newEventX = 0; @@ -1249,44 +1107,34 @@ static gint draw_scroll_event( oldEventY = OUTMAPX(bd, event->y_root); switch( event->direction ) { - case GDK_SCROLL_UP: - if (event->state & GDK_CONTROL_MASK) - action = wActionScrollRight; - else - action = wActionScrollUp; - break; - case GDK_SCROLL_DOWN: - if (event->state & GDK_CONTROL_MASK) - action = wActionScrollLeft; - else - action = wActionScrollDown; - break; - case GDK_SCROLL_LEFT: - action = wActionScrollLeft; - break; - case GDK_SCROLL_RIGHT: + case GDK_SCROLL_UP: + if (event->state & GDK_CONTROL_MASK) { action = wActionScrollRight; - break; - default: - return TRUE; - break; + } else { + action = wActionScrollUp; + } + break; + case GDK_SCROLL_DOWN: + if (event->state & GDK_CONTROL_MASK) { + action = wActionScrollLeft; + } else { + action = wActionScrollDown; + } + break; + case GDK_SCROLL_LEFT: + action = wActionScrollLeft; + break; + case GDK_SCROLL_RIGHT: + action = wActionScrollRight; + break; + default: + return TRUE; + break; } if (drawVerbose >= 2) printf( "%sNew[%dx%d]Delta[%dx%d]\n", actionNames[action], - newEventX, newEventY, oldEventX, oldEventY ); - - - - if (scrollTimer) { // Already have a timer - lastAction = action; - return TRUE; - } else { - lastAction = action; - timer_busy_count = 0; - scrollTimer = g_timeout_add(25,(GSourceFunc)ScrollTimerPop,bd); // 25ms delay - return TRUE; - } + newEventX, newEventY, oldEventX, oldEventY ); } else { @@ -1307,12 +1155,27 @@ static gint draw_scroll_event( default: break; } + } + if (event->time < GDK_CURRENT_TIME) return TRUE; //Ignore past events + + if (scrollTimer) { // Already have a timer + timer_busy_count++; + lastAction = action; + return TRUE; + } else { + lastAction = action; + timer_busy_count = 0; + scrollTimer = g_timeout_add(timer_interval,(GSourceFunc)ScrollTimerPop,bd); // 250ms delay + } + if (action != 0) { - if (drawVerbose >= 2) + if (drawVerbose >= 2) { printf( "%s[%ldx%ld]\n", actionNames[action], bd->lastX, bd->lastY ); - bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY); + } + bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, + (wDrawPix_t)bd->lastY); } return TRUE; @@ -1321,8 +1184,8 @@ static gint draw_scroll_event( static gint draw_leave_event( - GtkWidget *widget, - GdkEvent * event ) + GtkWidget *widget, + GdkEvent * event ) { wlibHelpHideBalloon(); return TRUE; @@ -1336,24 +1199,27 @@ static gint draw_leave_event( static gint draw_button_event( - GtkWidget *widget, - GdkEventButton *event, - wDraw_p bd ) + GtkWidget *widget, + GdkEventButton *event, + wDraw_p bd ) { wAction_t action = 0; - if (bd->action == NULL) + if (bd->action == NULL) { return TRUE; + } bd->lastX = OUTMAPX(bd, event->x); bd->lastY = OUTMAPY(bd, event->y); switch ( event->button ) { case 1: /* left mouse button */ - case 2: /* middle mouse button */ action = event->type==GDK_BUTTON_PRESS?wActionLDown:wActionLUp; - if (event->type==GDK_2BUTTON_PRESS) action = wActionLDownDouble; + if (event->type==GDK_2BUTTON_PRESS) { action = wActionLDownDouble; } + break; + case 2: /* middle mouse button */ + action = event->type==GDK_BUTTON_PRESS?wActionMDown:wActionMUp; /*bd->action( bd, bd->context, event->type==GDK_BUTTON_PRESS?wActionLDown:wActionLUp, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY );*/ break; case 3: /* right mouse button */ @@ -1362,27 +1228,31 @@ static gint draw_button_event( break; } if (action != 0) { - if (drawVerbose >= 2) + if (drawVerbose >= 2) { printf( "%s[%ldx%ld]\n", actionNames[action], bd->lastX, bd->lastY ); - bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); + } + bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, + (wDrawPix_t)bd->lastY ); } - if (!(bd->option & BD_NOFOCUS)) + if (!(bd->option & BD_NOFOCUS)) { gtk_widget_grab_focus( bd->widget ); + } return TRUE; } static gint draw_motion_event( - GtkWidget *widget, - GdkEventMotion *event, - wDraw_p bd ) + GtkWidget *widget, + GdkEventMotion *event, + wDraw_p bd ) { int x, y; GdkModifierType state; wAction_t action; - if (bd->action == NULL) + if (bd->action == NULL) { return TRUE; + } if (event->is_hint) { gdk_window_get_pointer (event->window, &x, &y, &state); @@ -1395,56 +1265,62 @@ static gint draw_motion_event( if (state & GDK_BUTTON1_MASK) { action = wActionLDrag; } else if (state & GDK_BUTTON2_MASK) { - action = wActionLDrag; + action = wActionMDrag; } else if (state & GDK_BUTTON3_MASK) { - action = wActionRDrag; + action = wActionRDrag; } else { action = wActionMove; } bd->lastX = OUTMAPX(bd, x); bd->lastY = OUTMAPY(bd, y); - if (drawVerbose >= 2) - printf( "%lx: %s[%ldx%ld] %s\n", (long)bd, actionNames[action], bd->lastX, bd->lastY, event->is_hint?"<Hint>":"<>" ); - bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); - if (!(bd->option & BD_NOFOCUS)) + if (drawVerbose >= 2) { + printf( "%lx: %s[%ldx%ld] %s\n", (long)bd, actionNames[action], bd->lastX, + bd->lastY, event->is_hint?"<Hint>":"<>" ); + } + bd->action( bd, bd->context, action, (wDrawPix_t)bd->lastX, + (wDrawPix_t)bd->lastY ); + if (!(bd->option & BD_NOFOCUS)) { gtk_widget_grab_focus( bd->widget ); + } return TRUE; } static gint draw_char_release_event( - GtkWidget * widget, - GdkEventKey *event, - wDraw_p bd ) + GtkWidget * widget, + GdkEventKey *event, + wDraw_p bd ) { - GdkModifierType modifiers; - guint key = event->keyval; - wModKey_e modKey = wModKey_None; - switch (key) { - case GDK_KEY_Alt_L: modKey = wModKey_Alt; break; - case GDK_KEY_Alt_R: modKey = wModKey_Alt; break; - case GDK_KEY_Shift_L: modKey = wModKey_Shift; break; - case GDK_KEY_Shift_R: modKey = wModKey_Shift; break; - case GDK_KEY_Control_L: modKey = wModKey_Ctrl; break; - case GDK_KEY_Control_R: modKey = wModKey_Ctrl; break; - default: ; - } +// GdkModifierType modifiers; + guint key = event->keyval; + wModKey_e modKey = wModKey_None; + switch (key) { + case GDK_KEY_Alt_L: modKey = wModKey_Alt; break; + case GDK_KEY_Alt_R: modKey = wModKey_Alt; break; + case GDK_KEY_Shift_L: modKey = wModKey_Shift; break; + case GDK_KEY_Shift_R: modKey = wModKey_Shift; break; + case GDK_KEY_Control_L: modKey = wModKey_Ctrl; break; + case GDK_KEY_Control_R: modKey = wModKey_Ctrl; break; + default: ; + } - if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) { - bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); - if (!(bd->option & BD_NOFOCUS)) - gtk_widget_grab_focus( bd->widget ); - return TRUE; - } else { - return FALSE; + if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) { + bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), + (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); + if (!(bd->option & BD_NOFOCUS)) { + gtk_widget_grab_focus( bd->widget ); } + return TRUE; + } else { return FALSE; + } + return FALSE; } static gint draw_char_event( - GtkWidget * widget, - GdkEventKey *event, - wDraw_p bd ) + GtkWidget * widget, + GdkEventKey *event, + wDraw_p bd ) { GdkModifierType modifiers; guint key = event->keyval; @@ -1453,9 +1329,12 @@ static gint draw_char_event( switch (key) { case GDK_KEY_Escape: key = 0x1B; break; case GDK_KEY_Return: + case GDK_KP_Enter: modifiers = gtk_accelerator_get_default_mod_mask(); - if (((event->state & modifiers)==GDK_CONTROL_MASK) || ((event->state & modifiers)==GDK_MOD1_MASK)) - extKey = wAccelKey_LineFeed; //If Return plus Control or Alt send in LineFeed + if (((event->state & modifiers)==GDK_CONTROL_MASK) + || ((event->state & modifiers)==GDK_MOD1_MASK)) { + extKey = wAccelKey_LineFeed; //If Return plus Control or Alt send in LineFeed + } key = 0x0D; break; case GDK_KEY_Linefeed: key = 0x0A; break; @@ -1489,31 +1368,40 @@ static gint draw_char_event( case GDK_KEY_Shift_R: modKey = wModKey_Shift; break; case GDK_KEY_Control_L: modKey = wModKey_Ctrl; break; case GDK_KEY_Control_R: modKey = wModKey_Ctrl; break; - default: ; + default: ; } if (extKey != wAccelKey_None) { if ( wlibFindAccelKey( event ) == NULL ) { - bd->action( bd, bd->context, wActionExtKey + ((int)extKey<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); + bd->action( bd, bd->context, wActionExtKey + ((int)extKey<<8), + (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); + } + if (!(bd->option & BD_NOFOCUS)) { + gtk_widget_grab_focus( bd->widget ); } - if (!(bd->option & BD_NOFOCUS)) - gtk_widget_grab_focus( bd->widget ); return TRUE; } else if ((key >=wAccelKey_Up) && (key<=wAccelKey_Left) && bd->action) { - bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); - if (!(bd->option & BD_NOFOCUS)) + bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX, + (wDrawPix_t)bd->lastY ); + if (!(bd->option & BD_NOFOCUS)) { gtk_widget_grab_focus( bd->widget ); + } return TRUE; - } else if (key <= 0xFF && (event->state&(GDK_CONTROL_MASK|GDK_MOD1_MASK)) == 0 && bd->action) { - bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); - if (!(bd->option & BD_NOFOCUS)) - gtk_widget_grab_focus( bd->widget ); + } else if (key <= 0xFF && (event->state&(GDK_CONTROL_MASK|GDK_MOD1_MASK)) == 0 + && bd->action) { + bd->action( bd, bd->context, wActionText+(key<<8), (wDrawPix_t)bd->lastX, + (wDrawPix_t)bd->lastY ); + if (!(bd->option & BD_NOFOCUS)) { + gtk_widget_grab_focus( bd->widget ); + } return TRUE; } else if (modKey!= wModKey_None && (bd->option & BD_MODKEYS)) { - bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); - if (!(bd->option & BD_NOFOCUS)) - gtk_widget_grab_focus( bd->widget ); - return TRUE; + bd->action(bd, bd->context, wActionModKey+((int)modKey<<8), + (wDrawPix_t)bd->lastX, (wDrawPix_t)bd->lastY ); + if (!(bd->option & BD_NOFOCUS)) { + gtk_widget_grab_focus( bd->widget ); + } + return TRUE; } else { return FALSE; } @@ -1532,17 +1420,17 @@ int XW = 0; int XH = 0; int xw, xh, cw, ch; - wDraw_p wDrawCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - long option, - wWinPix_t width, - wWinPix_t height, - void * context, - wDrawRedrawCallBack_p redraw, - wDrawActionCallBack_p action ) +wDraw_p wDrawCreate( + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + long option, + wWinPix_t width, + wWinPix_t height, + void * context, + wDrawRedrawCallBack_p redraw, + wDrawActionCallBack_p action ) { wDraw_p bd; @@ -1558,41 +1446,50 @@ int xw, xh, cw, ch; gtk_drawing_area_size( GTK_DRAWING_AREA(bd->widget), width, height ); gtk_widget_set_size_request( GTK_WIDGET(bd->widget), width, height ); gtk_signal_connect (GTK_OBJECT (bd->widget), "expose_event", - (GtkSignalFunc) draw_expose_event, bd); + (GtkSignalFunc) draw_expose_event, bd); gtk_signal_connect (GTK_OBJECT(bd->widget),"configure_event", - (GtkSignalFunc) draw_configure_event, bd); + (GtkSignalFunc) draw_configure_event, bd); gtk_signal_connect (GTK_OBJECT (bd->widget), "motion_notify_event", - (GtkSignalFunc) draw_motion_event, bd); + (GtkSignalFunc) draw_motion_event, bd); gtk_signal_connect (GTK_OBJECT (bd->widget), "button_press_event", - (GtkSignalFunc) draw_button_event, bd); + (GtkSignalFunc) draw_button_event, bd); gtk_signal_connect (GTK_OBJECT (bd->widget), "button_release_event", - (GtkSignalFunc) draw_button_event, bd); + (GtkSignalFunc) draw_button_event, bd); gtk_signal_connect (GTK_OBJECT (bd->widget), "scroll_event", - (GtkSignalFunc) draw_scroll_event, bd); + (GtkSignalFunc) draw_scroll_event, bd); gtk_signal_connect_after (GTK_OBJECT (bd->widget), "key_press_event", - (GtkSignalFunc) draw_char_event, bd); + (GtkSignalFunc) draw_char_event, bd); gtk_signal_connect_after (GTK_OBJECT (bd->widget), "key_release_event", - (GtkSignalFunc) draw_char_release_event, bd); + (GtkSignalFunc) draw_char_release_event, bd); gtk_signal_connect (GTK_OBJECT (bd->widget), "leave_notify_event", - (GtkSignalFunc) draw_leave_event, bd); + (GtkSignalFunc) draw_leave_event, bd); gtk_widget_set_can_focus(bd->widget,!(option & BD_NOFOCUS)); //if (!(option & BD_NOFOCUS)) // GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bd->widget), GTK_CAN_FOCUS); gtk_widget_set_events (bd->widget, GDK_EXPOSURE_MASK - | GDK_LEAVE_NOTIFY_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_SCROLL_MASK - | GDK_POINTER_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_KEY_PRESS_MASK - | GDK_KEY_RELEASE_MASK ); + | GDK_LEAVE_NOTIFY_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_SCROLL_MASK + | GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK + | GDK_KEY_PRESS_MASK + | GDK_KEY_RELEASE_MASK ); bd->lastColor = -1; double dpi; wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); + if ( width <= 0 || height <= 0 ) { + fprintf( stderr, "wDrawCreate bad size %ldx%ld\n", width, height ); + if ( width <= 0 ) { + width = 100; + } + if ( height <= 0 ) { + height = 100; + } + } bd->dpi = dpi; bd->maxW = bd->w = width; bd->maxH = bd->h = height; @@ -1601,19 +1498,21 @@ int xw, xh, cw, ch; wlibControlGetSize( (wControl_p)bd ); gtk_widget_realize( bd->widget ); bd->pixmap = gdk_pixmap_new( bd->widget->window, width, height, -1 ); - bd->temp_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width,height ); + bd->temp_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, + height ); wDrawClear(bd); bd->gc = gdk_gc_new( parent->gtkwin->window ); gdk_gc_copy( bd->gc, parent->gtkwin->style->base_gc[GTK_STATE_NORMAL] ); -{ - GdkCursor * cursor; - cursor = gdk_cursor_new ( GDK_TCROSS ); - gdk_window_set_cursor ( bd->widget->window, cursor); - gdk_cursor_destroy (cursor); -} + { + GdkCursor * cursor; + cursor = gdk_cursor_new ( GDK_TCROSS ); + gdk_window_set_cursor ( bd->widget->window, cursor); + gdk_cursor_destroy (cursor); + } #ifdef LATER - if (labelStr) + if (labelStr) { bd->labelW = gtkAddLabel( (wControl_p)bd, labelStr ); + } #endif gtk_widget_show( bd->widget ); wlibAddButton( (wControl_p)bd ); @@ -1638,7 +1537,7 @@ wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int arg ) double dpi; - wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); + wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0); bd->dpi = dpi; bd->maxW = bd->w = w; @@ -1674,7 +1573,8 @@ wBool_t wBitMapDelete( wDraw_p d ) * Background * ******************************************************************************/ -int wDrawSetBackground( wDraw_p bd, char * path, char ** error) { +int wDrawSetBackground( wDraw_p bd, char * path, char ** error) +{ GError *err = NULL; @@ -1698,36 +1598,39 @@ int wDrawSetBackground( wDraw_p bd, char * path, char ** error) { /** * Use a loaded background in another context. - * + * * \param from context with background - * \param to context to get a reference to the existing background + * \param to context to get a reference to the existing background */ void wDrawCloneBackground(wDraw_p from, wDraw_p to) { - if (from->background) { - to->background = from->background; - } else { - to->background = NULL; - } + if (from->background) { + to->background = from->background; + } else { + to->background = NULL; + } } /** -* Draw background to screen. The background will be sized and rotated before being shown. The bitmap -* is scaled so that the width is equal to size. The height is changed proportionally. +* Draw background to screen. The background will be sized and rotated before being shown. The bitmap +* is scaled so that the width is equal to size. The height is changed proportionally. * * \param bd drawing context * \param pos_x, pos_y bitmap position * \param size desired width after scaling -* \param angle +* \param angle * \param screen visibility of bitmap in percent */ -void wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, wWinPix_t size, wAngle_t angle, int screen) { +void wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, + wWinPix_t size, wAngle_t angle, int screen) +{ if (bd->background) { - cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, wDrawColorWhite, bd->bTempMode?wDrawOptTemp:0 ); + cairo_t* cairo = gtkDrawCreateCairoContext(bd, NULL, 0, wDrawLineSolid, + wDrawColorWhite, bd->bTempMode?wDrawOptTemp:0 ); cairo_save(cairo); int pixels_width = gdk_pixbuf_get_width(bd->background); int pixels_height = gdk_pixbuf_get_height(bd->background); @@ -1744,19 +1647,24 @@ void wDrawShowBackground( wDraw_p bd, wWinPix_t pos_x, wWinPix_t pos_y, wWinPix_ } cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); double rad = M_PI*(angle/180); - posy = (double)bd->h-((pixels_height*fabs(cos(rad))+pixels_width*fabs(sin(rad)))*scale)-posy; + posy = (double)bd->h-((pixels_height*fabs(cos(rad))+pixels_width*fabs(sin( + rad)))*scale)-posy; //width = (double)(pixels_width*scale); //height = (double)(pixels_height*scale); cairo_translate(cairo,posx,posy); cairo_scale(cairo, scale, scale); - cairo_translate(cairo, fabs(pixels_width/2.0*cos(rad))+fabs(pixels_height/2.0*sin(rad)), - fabs(pixels_width/2.0*sin(rad))+fabs(pixels_height/2.0*cos(rad))); + cairo_translate(cairo, fabs(pixels_width/2.0*cos(rad))+fabs( + pixels_height/2.0*sin(rad)), + fabs(pixels_width/2.0*sin(rad))+fabs(pixels_height/2.0*cos(rad))); cairo_rotate(cairo, M_PI*(angle/180.0)); // We need to clip around the image, or cairo will paint garbage data - cairo_rectangle(cairo, -pixels_width/2.0, -pixels_height/2.0, pixels_width, pixels_height); + cairo_rectangle(cairo, -pixels_width/2.0, -pixels_height/2.0, pixels_width, + pixels_height); cairo_clip(cairo); - gdk_cairo_set_source_pixbuf(cairo, bd->background, -pixels_width/2.0, -pixels_height/2.0); - cairo_pattern_t *mask = cairo_pattern_create_rgba (1.0,1.0,1.0,(100.0-screen)/100.0); + gdk_cairo_set_source_pixbuf(cairo, bd->background, -pixels_width/2.0, + -pixels_height/2.0); + cairo_pattern_t *mask = cairo_pattern_create_rgba (1.0,1.0,1.0, + (100.0-screen)/100.0); cairo_mask(cairo,mask); cairo_pattern_destroy(mask); cairo_restore(cairo); diff --git a/app/wlib/gtklib/gtkint.h b/app/wlib/gtklib/gtkint.h index 6d8a641..e3757a4 100644 --- a/app/wlib/gtklib/gtkint.h +++ b/app/wlib/gtklib/gtkint.h @@ -1,4 +1,4 @@ -/** \file gtkint.h +/** \file gtkint.h * Internal definitions for the gtk-library */ @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GTKINT_H @@ -42,24 +42,16 @@ extern wWin_p gtkMainW; -#ifdef CURSOR_SURFACE -typedef struct { - cairo_surface_t* surface; - wWinPix_t width; - wWinPix_t height; - wBool_t show; -} wCursorSurface_t, * wSurface_p; -#endif - typedef enum { - W_MAIN, W_POPUP, - B_BUTTON, B_CANCEL, B_POPUP, B_TEXT, B_INTEGER, B_FLOAT, - B_LIST, B_DROPLIST, B_COMBOLIST, - B_RADIO, B_TOGGLE, - B_DRAW, B_MENU, B_MULTITEXT, B_MESSAGE, B_LINES, - B_MENUITEM, B_BOX, - B_BITMAP, B_STATUS } wType_e; + W_MAIN, W_POPUP, + B_BUTTON, B_CANCEL, B_POPUP, B_TEXT, B_INTEGER, B_FLOAT, + B_LIST, B_DROPLIST, B_COMBOLIST, + B_RADIO, B_TOGGLE, + B_DRAW, B_MENU, B_MULTITEXT, B_MESSAGE, B_LINES, + B_MENUITEM, B_BOX, + B_BITMAP, B_STATUS +} wType_e; typedef void (*repaintProcCallback_p)( wControl_p ); typedef void (*doneProcCallback_p)( wControl_p b ); @@ -71,7 +63,6 @@ typedef void (*setTriggerCallback_p)( wControl_p b ); wWin_p parent; \ wWinPix_t origX, origY; \ wWinPix_t realX, realY; \ - wWinPix_t default_size_x, default_size_y; \ wWinPix_t labelW; \ wWinPix_t w, h; \ int maximize_initially; \ @@ -81,74 +72,73 @@ typedef void (*setTriggerCallback_p)( wControl_p b ); GtkWidget * widget; \ GtkWidget * label; \ doneProcCallback_p doneProc; \ - /* CURSOR_SURFACE wCursorSurface_t cursor_surface;*/ \ wBool_t outline; \ void * data; struct wWin_t { - WOBJ_COMMON - GtkWidget *gtkwin; /**< GTK window */ - wWinPix_t lastX, lastY; - wControl_p first, last; - wWinCallBack_p winProc; /**< window procedure */ - wBool_t shown; /**< visibility state */ - const char * nameStr; /**< window name (not title) */ - GtkWidget * menubar; /**< menubar handle (if exists) */ - int menu_height; - GdkGC * gc; /**< graphics context */ - int gc_linewidth; /**< ??? */ - wBool_t busy; - int resizeTimer; /** resizing **/ - int resizeW,resizeH; - int timer_idle_count; - int timer_busy_count; - int modalLevel; - }; + WOBJ_COMMON + GtkWidget *gtkwin; /**< GTK window */ + wWinPix_t lastX, lastY; + wControl_p first, last; + wWinCallBack_p winProc; /**< window procedure */ + wBool_t shown; /**< visibility state */ + const char * nameStr; /**< window name (not title) */ + GtkWidget * menubar; /**< menubar handle (if exists) */ + int menu_height; + GdkGC * gc; /**< graphics context */ + int gc_linewidth; /**< ??? */ + wBool_t busy; + int resizeTimer; /** resizing **/ + int resizeW,resizeH; + int timer_idle_count; + int timer_busy_count; + int modalLevel; +}; struct wControl_t { - WOBJ_COMMON - }; - + WOBJ_COMMON +}; + typedef struct wListItem_t * wListItem_p; struct wList_t { - WOBJ_COMMON + WOBJ_COMMON // GtkWidget *list; - int count; - int number; - int colCnt; - wWinPix_t *colWidths; - wBool_t *colRightJust; - GtkListStore *listStore; - GtkWidget *treeView; - int last; - wWinPix_t listX; - long * valueP; - wListCallBack_p action; - int recursion; - int editted; - int editable; - }; + int count; + int number; + int colCnt; + wWinPix_t *colWidths; + wBool_t *colRightJust; + GtkListStore *listStore; + GtkWidget *treeView; + int last; + wWinPix_t listX; + long * valueP; + wListCallBack_p action; + int recursion; + int editted; + int editable; +}; struct wListItem_t { - wBool_t active; - void * itemData; - char * label; - GtkLabel * labelG; - wBool_t selected; - wList_p listP; - }; + wBool_t active; + void * itemData; + char * label; + GtkLabel * labelG; + wBool_t selected; + wList_p listP; +}; #define gtkIcon_bitmap (1) #define gtkIcon_pixmap (2) struct wIcon_t { - int gtkIconType; - wWinPix_t w; - wWinPix_t h; - wDrawColor color; - const void * bits; - }; + int gtkIconType; + wWinPix_t w; + wWinPix_t h; + wDrawColor color; + const void * bits; +}; extern char wConfigName[]; extern wDrawColor wDrawColorWhite; @@ -157,39 +147,42 @@ extern wDrawColor wDrawColorBlack; /* boxes.c */ -void wlibDrawBox(wWin_p win, wBoxType_e style, wWinPix_t x, wWinPix_t y, wWinPix_t w, wWinPix_t h); +void wlibDrawBox(wWin_p win, wBoxType_e style, wWinPix_t x, wWinPix_t y, + wWinPix_t w, wWinPix_t h); /* button.c */ -void wlibSetLabel(GtkWidget *widget, long option, const char *labelStr, GtkLabel **labelG, GtkWidget **imageG); +void wlibSetLabel(GtkWidget *widget, long option, const char *labelStr, + GtkLabel **labelG, GtkWidget **imageG); void wlibButtonDoAction(wButton_p bb); struct wButton_t { - WOBJ_COMMON - GtkLabel * labelG; - GtkWidget * imageG; - wButtonCallBack_p action; - int busy; - int recursion; - long timer_id; - int timer_count; - int timer_state; + WOBJ_COMMON + GtkLabel * labelG; + GtkWidget * imageG; + wButtonCallBack_p action; + int busy; + int recursion; + long timer_id; + int timer_count; + int timer_state; }; /* color.c */ typedef struct { - unsigned char red; - unsigned char green; - unsigned char blue; - GdkColor normalColor; - GdkColor invertColor; - long rgb; - int colorChar; + unsigned char red; + unsigned char green; + unsigned char blue; + GdkColor normalColor; + GdkColor invertColor; + long rgb; + int colorChar; } colorMap_t; GdkColor *wlibGetColor(wDrawColor color, wBool_t normal); /* control.c */ -wBool_t wControlExpose (GtkWidget * widget, GdkEventExpose * event, wControl_p b); +wBool_t wControlExpose (GtkWidget * widget, GdkEventExpose * event, + wControl_p b); /* droplist.c */ enum columns { @@ -204,13 +197,19 @@ void wDropListClear(wList_p b); void *wDropListGetItemContext(wList_p b, wIndex_t inx); void wDropListAddValue(wList_p b, char *text, wListItem_p data); void wDropListSetIndex(wList_p b, int val); -wBool_t wDropListSetValues(wList_p b, wIndex_t row, const char *labelStr, wIcon_p bm, void *itemData); -wList_p wDropListCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, const char *helpStr, const char *labelStr, long option, long number, wWinPix_t width, long *valueP, wListCallBack_p action, void *data); +wBool_t wDropListSetValues(wList_p b, wIndex_t row, const char *labelStr, + wIcon_p bm, void *itemData); +wList_p wDropListCreate(wWin_p parent, wWinPix_t x, wWinPix_t y, + const char *helpStr, const char *labelStr, long option, long number, + wWinPix_t width, long *valueP, wListCallBack_p action, void *data); /* filesel.c */ /* font.c */ -PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void *cairo, wFont_p fp, wFontSize_t fs, const char *s, wDrawPix_t *width_p, wDrawPix_t *height_p, wDrawPix_t *ascent_p, wDrawPix_t *descent_p, wDrawPix_t *baseline_p); +PangoLayout *wlibFontCreatePangoLayout(GtkWidget *widget, void *cairo, + wFont_p fp, wFontSize_t fs, const char *s, wDrawPix_t *width_p, + wDrawPix_t *height_p, wDrawPix_t *ascent_p, wDrawPix_t *descent_p, + wDrawPix_t *baseline_p); void wlibFontDestroyPangoLayout(PangoLayout *layout); const char *wlibFontTranslate(wFont_p fp); @@ -220,16 +219,20 @@ const char *wlibFontTranslate(wFont_p fp); void wlibLineShow(wLine_p bl, wBool_t visible); /* list.c */ -int CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data); +int CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, + gpointer data); /* liststore.c */ wListItem_p wlibListItemGet(GtkListStore *ls, wIndex_t inx, GList **childR); void *wlibListStoreGetContext(GtkListStore *ls, int inx); void wlibListStoreClear(GtkListStore *listStore); GtkListStore *wlibNewListStore(int colCnt); -void wlibListStoreSetPixbuf(GtkListStore *ls, GtkTreeIter *iter, GdkPixbuf *pixbuf); -int wlibListStoreAddData(GtkListStore *ls, GdkPixbuf *pixbuf, int cols, wListItem_p id); -int wlibListStoreUpdateValues(GtkListStore *ls, int row, int cols, char *labels, wIcon_p bm); +void wlibListStoreSetPixbuf(GtkListStore *ls, GtkTreeIter *iter, + GdkPixbuf *pixbuf); +int wlibListStoreAddData(GtkListStore *ls, GdkPixbuf *pixbuf, int cols, + wListItem_p id); +int wlibListStoreUpdateValues(GtkListStore *ls, int row, int cols, char *labels, + wIcon_p bm); /* main.c */ char *wlibGetAppName(void); @@ -239,16 +242,17 @@ int getMlistOrigin(wMenuList_p ml, GList **pChildren); /* misc.c */ typedef struct accelData_t { - wAccelKey_e key; - int modifier; - wAccelKeyCallBack_p action; - void * data; + wAccelKey_e key; + int modifier; + wAccelKeyCallBack_p action; + void * data; } accelData_t; GdkPixbuf* wlibPixbufFromXBM(wIcon_p ip); int wlibAddLabel(wControl_p b, const char *labelStr); -void *wlibAlloc(wWin_p parent, wType_e type, wWinPix_t origX, wWinPix_t origY, const char *labelStr, int size, void *data); +void *wlibAlloc(wWin_p parent, wType_e type, wWinPix_t origX, wWinPix_t origY, + const char *labelStr, int size, void *data); void wlibComputePos(wControl_p b); void wlibControlGetSize(wControl_p b); void wlibAddButton(wControl_p b); @@ -267,46 +271,53 @@ GdkPixbuf *wlibMakePixbuf(wIcon_p ip); /* print.c */ struct wDraw_t { - WOBJ_COMMON - void * context; - wDrawActionCallBack_p action; - wDrawRedrawCallBack_p redraw; - - GdkPixmap * pixmap; - GdkPixmap * pixmapBackup; - cairo_surface_t * temp_surface; - - double dpi; - - GdkGC * gc; - wDrawWidth lineWidth; - wDrawOpts opts; - wWinPix_t maxW; - wWinPix_t maxH; - unsigned long lastColor; - wBool_t lastColorInverted; - const char * helpStr; - - wWinPix_t lastX; - wWinPix_t lastY; - - wBool_t delayUpdate; - cairo_t *printContext; - cairo_surface_t *curPrintSurface; - GdkPixbuf * background; - - wBool_t bTempMode; - }; + WOBJ_COMMON + void * context; + wDrawActionCallBack_p action; + wDrawRedrawCallBack_p redraw; + + GdkPixmap * pixmap; + GdkPixmap * pixmapBackup; + cairo_surface_t * temp_surface; + + double dpi; + + GdkGC * gc; + wDrawWidth lineWidth; + wDrawOpts opts; + wWinPix_t maxW; + wWinPix_t maxH; + unsigned long lastColor; + wBool_t lastColorInverted; + const char * helpStr; + + wWinPix_t lastX; + wWinPix_t lastY; + + wBool_t delayUpdate; + cairo_t *printContext; + cairo_surface_t *curPrintSurface; + GdkPixbuf * background; + + wBool_t bTempMode; +}; void WlibApplySettings(GtkPrintOperation *op); void WlibSaveSettings(GtkPrintOperation *op); -void psPrintLine(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, wDrawPix_t y1, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts); -void psPrintArc(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, double angle0, double angle1, wBool_t drawCenter, wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts); -void psPrintFillRectangle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, wDrawPix_t y1, wDrawColor color, wDrawOpts opts); -void psPrintFillPolygon(wDrawPix_t p[][2], wPolyLine_e type[], int cnt, wDrawColor color, wDrawOpts opts, int fill, int open); -void psPrintFillCircle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, wDrawColor color, wDrawOpts opts); -void psPrintString(wDrawPix_t x, wDrawPix_t y, double a, char *s, wFont_p fp, double fs, wDrawColor color, wDrawOpts opts); -static void WlibGetPaperSize(void); +void psPrintLine(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, wDrawPix_t y1, + wDrawWidth width, wDrawLineType_e lineType, wDrawColor color, wDrawOpts opts); +void psPrintArc(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, double angle0, + double angle1, wBool_t drawCenter, wDrawWidth width, wDrawLineType_e lineType, + wDrawColor color, wDrawOpts opts); +void psPrintFillRectangle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t x1, + wDrawPix_t y1, wDrawColor color, wDrawOpts opts); +void psPrintFillPolygon(wDrawPix_t p[][2], wPolyLine_e type[], int cnt, + wDrawColor color, wDrawOpts opts, int fill, int open); +void psPrintFillCircle(wDrawPix_t x0, wDrawPix_t y0, wDrawPix_t r, + wDrawColor color, wDrawOpts opts); +void psPrintString(wDrawPix_t x, wDrawPix_t y, double a, char *s, wFont_p fp, + double fs, wDrawColor color, wDrawOpts opts); +//static void WlibGetPaperSize(void); /* single.c */ void wlibStringUpdate(); @@ -325,12 +336,15 @@ void wlibHelpHideBalloon(); /* treeview.c */ void wlibTreeViewSetSelected(wList_p b, int index); -GtkWidget *wlibNewTreeView(GtkListStore *ls, int showTitles, int multiSelection); +GtkWidget *wlibNewTreeView(GtkListStore *ls, int showTitles, + int multiSelection); int wlibTreeViewAddColumns(GtkWidget *tv, int count); int wlibAddColumnTitles(GtkWidget *tv, const char **titles); -int wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf, wListItem_p userData); +int wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf, + wListItem_p userData); void wlibTreeViewAddRow(wList_p b, char *label, wIcon_p bm, wListItem_p id_p); -gboolean changeSelection(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data); +gboolean changeSelection(GtkTreeSelection *selection, GtkTreeModel *model, + GtkTreePath *path, gboolean path_currently_selected, gpointer data); int wTreeViewGetCount(wList_p b); void wTreeViewClear(wList_p b); @@ -338,7 +352,8 @@ void *wTreeViewGetItemContext(wList_p b, int row); /* window.c */ void wlibDoModal(wWin_p win0, wBool_t modal); -wBool_t catch_shift_ctrl_alt_keys(GtkWidget *widget, GdkEventKey *event, void *data); +wBool_t catch_shift_ctrl_alt_keys(GtkWidget *widget, GdkEventKey *event, + void *data); /* wpref.c */ diff --git a/app/wlib/gtklib/help.c b/app/wlib/gtklib/help.c index 45d1813..f062b83 100644 --- a/app/wlib/gtklib/help.c +++ b/app/wlib/gtklib/help.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define GTK_DISABLE_SINGLE_INCLUDES @@ -46,29 +46,31 @@ extern const char * GetCurCommandName(); static void DoHelpMenu(void *data) { - int func = (intptr_t)data; + int func = (intptr_t)data; - const char * topic; + const char * topic; - switch (func) { - case 1: - wHelp("contents"); - break; + switch (func) { + case 1: + wHelp("contents"); + break; - case 3: - topic = GetCurCommandName(); - if (topic && topic[0]) - wHelp(topic); - break; + case 3: + topic = GetCurCommandName(); + if (topic && topic[0]) { + wHelp(topic); + } + break; - default: - break; - } + default: + break; + } - return; + return; } -void wDoAccelHelp(wAccelKey_e key, void * context) { +void wDoAccelHelp(wAccelKey_e key, void * context) +{ DoHelpMenu(context); } @@ -81,6 +83,6 @@ void wDoAccelHelp(wAccelKey_e key, void * context) { void wMenuAddHelp(wMenu_p m) { - wMenuPushCreate(m, NULL, _("&Contents"), 0, DoHelpMenu, (void*)1); - wMenuPushCreate(m, NULL, _("Co&mmand Context help"), 0, DoHelpMenu, (void*)3); + wMenuPushCreate(m, NULL, _("&Contents"), 0, DoHelpMenu, (void*)1); + wMenuPushCreate(m, NULL, _("Co&mmand Context help"), 0, DoHelpMenu, (void*)3); } diff --git a/app/wlib/gtklib/ixhelp.c b/app/wlib/gtklib/ixhelp.c index 5079f61..80b579c 100644 --- a/app/wlib/gtklib/ixhelp.c +++ b/app/wlib/gtklib/ixhelp.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -77,34 +77,34 @@ static GtkWidget *contents_view; /** handle for the help contents pane */ static GtkWidget* lookup_widget(GtkWidget *widget, const gchar *widget_name) { - GtkWidget *parent, *found_widget; + GtkWidget *parent, *found_widget; - for (;;) { - if (GTK_IS_MENU(widget)) { - parent = gtk_menu_get_attach_widget(GTK_MENU(widget)); - } else { - parent = widget->parent; - } + for (;;) { + if (GTK_IS_MENU(widget)) { + parent = gtk_menu_get_attach_widget(GTK_MENU(widget)); + } else { + parent = widget->parent; + } - if (!parent) { - parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey"); - } + if (!parent) { + parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey"); + } - if (parent == NULL) { - break; - } + if (parent == NULL) { + break; + } - widget = parent; - } + widget = parent; + } - found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), - widget_name); + found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), + widget_name); - if (!found_widget) { - g_warning("Widget not found: %s", widget_name); - } + if (!found_widget) { + g_warning("Widget not found: %s", widget_name); + } - return found_widget; + return found_widget; } @@ -124,21 +124,21 @@ lookup_widget(GtkWidget *widget, const gchar *widget_name) GtkWidget * CreateHPaned(GtkBox *container, char *property) { - GtkWidget *hpaned; - long posSlider; + GtkWidget *hpaned; + long posSlider; - /* the horizontal slider */ - hpaned = gtk_hpaned_new(); - gtk_container_set_border_width(GTK_CONTAINER(hpaned), 6); + /* the horizontal slider */ + hpaned = gtk_hpaned_new(); + gtk_container_set_border_width(GTK_CONTAINER(hpaned), 6); - wPrefGetInteger(HTMLHELPSECTION, SLIDERPREFNAME, &posSlider, SLIDERPOSDEFAULT); - gtk_paned_set_position(GTK_PANED(hpaned), (int)posSlider); + wPrefGetInteger(HTMLHELPSECTION, SLIDERPREFNAME, &posSlider, SLIDERPOSDEFAULT); + gtk_paned_set_position(GTK_PANED(hpaned), (int)posSlider); - /* pack the horizontal slider into the main window */ - gtk_box_pack_start(container, hpaned, TRUE, TRUE, 0); - gtk_widget_show(hpaned); + /* pack the horizontal slider into the main window */ + gtk_box_pack_start(container, hpaned, TRUE, TRUE, 0); + gtk_widget_show(hpaned); - return (hpaned); + return (hpaned); } /** @@ -155,69 +155,69 @@ CreateHPaned(GtkBox *container, char *property) static gboolean DestroyHelpWindow(GtkWidget *win, GdkEvent *event, void *ptr) { - int i; - GtkWidget *widget; - char tmp[ 20 ]; + int i; + GtkWidget *widget; + char tmp[ 20 ]; - gint x, y; + gint x, y; - /* get the slider position and save it */ - widget = lookup_widget(win, PANED); - i = gtk_paned_get_position(GTK_PANED(widget)); - wPrefSetInteger(HTMLHELPSECTION, SLIDERPREFNAME, i); + /* get the slider position and save it */ + widget = lookup_widget(win, PANED); + i = gtk_paned_get_position(GTK_PANED(widget)); + wPrefSetInteger(HTMLHELPSECTION, SLIDERPREFNAME, i); - /* get the window position */ - gtk_window_get_position((GtkWindow *)win, &x, &y); - sprintf(tmp, "%d %d", x, y); - wPrefSetString(HTMLHELPSECTION, WINDOWPOSPREFNAME, tmp); + /* get the window position */ + gtk_window_get_position((GtkWindow *)win, &x, &y); + sprintf(tmp, "%d %d", x, y); + wPrefSetString(HTMLHELPSECTION, WINDOWPOSPREFNAME, tmp); - /* get the window size */ - gtk_window_get_size((GtkWindow *)win , &x, &y); - sprintf(tmp, "%d %d", x, y); - wPrefSetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME, tmp); + /* get the window size */ + gtk_window_get_size((GtkWindow *)win, &x, &y); + sprintf(tmp, "%d %d", x, y); + wPrefSetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME, tmp); - gtk_widget_hide(win); - return TRUE; + gtk_widget_hide(win); + return TRUE; } void back_button_clicked(GtkWidget *widget, gpointer data) { - webkit_web_view_go_back(WEBKIT_WEB_VIEW(data)); + webkit_web_view_go_back(WEBKIT_WEB_VIEW(data)); } void forward_button_clicked(GtkWidget *widget, gpointer data) { - webkit_web_view_go_forward(WEBKIT_WEB_VIEW(data)); + webkit_web_view_go_forward(WEBKIT_WEB_VIEW(data)); } void home_button_clicked(GtkWidget *widget, gpointer data) { - load_into_view("index.html", MAIN_VIEW); + load_into_view("index.html", MAIN_VIEW); } /* Toggles the contents pane */ void contents_button_clicked(GtkWidget *widget, gpointer data) { - if (gtk_paned_get_position(GTK_PANED(data)) < 50) { - gtk_paned_set_position(GTK_PANED(data), 370); - } else { - gtk_paned_set_position(GTK_PANED(data), 0); - } + if (gtk_paned_get_position(GTK_PANED(data)) < 50) { + gtk_paned_set_position(GTK_PANED(data), 370); + } else { + gtk_paned_set_position(GTK_PANED(data), 0); + } } gboolean contents_click_handler( - WebKitWebView *web_view, - WebKitWebFrame *frame, - WebKitNetworkRequest *request, - WebKitWebNavigationAction *navigation_action, - WebKitWebPolicyDecision *policy_decision, - gpointer data) + WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, + gpointer data) { - webkit_web_view_load_uri(WEBKIT_WEB_VIEW(data), - webkit_network_request_get_uri(request)); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(data), + webkit_network_request_get_uri(request)); - return TRUE; + return TRUE; } /** @@ -225,45 +225,45 @@ gboolean contents_click_handler( */ void initialize_buttons(GtkWidget *main_vbox, GtkWidget *content_hpane) { - GtkWidget *buttons_hbuttonbox; - GtkWidget *back_button; - GtkWidget *forward_button; - GtkWidget *home_button; - GtkWidget *contents_button; - - // define and attach signals to buttons - back_button = gtk_button_new_with_label(_("Back")); - g_signal_connect(back_button, "clicked", G_CALLBACK(back_button_clicked), - G_OBJECT(main_view)); - - forward_button = gtk_button_new_with_label(_("Forward")); - g_signal_connect(forward_button, "clicked", G_CALLBACK(forward_button_clicked), - G_OBJECT(main_view)); - - home_button = gtk_button_new_with_label(_("Home")); - g_signal_connect(home_button, "clicked", G_CALLBACK(home_button_clicked), - G_OBJECT(main_view)); - - contents_button = gtk_button_new_with_label(_("Contents")); - g_signal_connect(contents_button, "clicked", - G_CALLBACK(contents_button_clicked), G_OBJECT(content_hpane)); - - // button layout - buttons_hbuttonbox = gtk_hbutton_box_new(); - gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), back_button); - gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), forward_button); - gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), home_button); - gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), contents_button); - gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbuttonbox, FALSE, TRUE, 0); - gtk_box_set_spacing(GTK_BOX(buttons_hbuttonbox), 6); - gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons_hbuttonbox), - GTK_BUTTONBOX_START); - - /* Store pointers to all widgets, for use by lookup_widget(). */ - GLADE_HOOKUP_OBJECT(main_view, back_button, BACKBUTTON); - GLADE_HOOKUP_OBJECT(main_view, forward_button, FORWARDBUTTON); - GLADE_HOOKUP_OBJECT(main_view, home_button, HOMEBUTTON); - GLADE_HOOKUP_OBJECT(main_view, contents_button, CONTENTBUTTON); + GtkWidget *buttons_hbuttonbox; + GtkWidget *back_button; + GtkWidget *forward_button; + GtkWidget *home_button; + GtkWidget *contents_button; + + // define and attach signals to buttons + back_button = gtk_button_new_with_label(_("Back")); + g_signal_connect(back_button, "clicked", G_CALLBACK(back_button_clicked), + G_OBJECT(main_view)); + + forward_button = gtk_button_new_with_label(_("Forward")); + g_signal_connect(forward_button, "clicked", G_CALLBACK(forward_button_clicked), + G_OBJECT(main_view)); + + home_button = gtk_button_new_with_label(_("Home")); + g_signal_connect(home_button, "clicked", G_CALLBACK(home_button_clicked), + G_OBJECT(main_view)); + + contents_button = gtk_button_new_with_label(_("Contents")); + g_signal_connect(contents_button, "clicked", + G_CALLBACK(contents_button_clicked), G_OBJECT(content_hpane)); + + // button layout + buttons_hbuttonbox = gtk_hbutton_box_new(); + gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), back_button); + gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), forward_button); + gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), home_button); + gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), contents_button); + gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbuttonbox, FALSE, TRUE, 0); + gtk_box_set_spacing(GTK_BOX(buttons_hbuttonbox), 6); + gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons_hbuttonbox), + GTK_BUTTONBOX_START); + + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT(main_view, back_button, BACKBUTTON); + GLADE_HOOKUP_OBJECT(main_view, forward_button, FORWARDBUTTON); + GLADE_HOOKUP_OBJECT(main_view, home_button, HOMEBUTTON); + GLADE_HOOKUP_OBJECT(main_view, contents_button, CONTENTBUTTON); } /** @@ -275,123 +275,123 @@ void initialize_buttons(GtkWidget *main_vbox, GtkWidget *content_hpane) GtkWidget* CreateHelpWindow(void) { - GtkWidget *main_vbox; - GtkWidget *main_view_scroller; - GtkWidget *contents_view_scroller; - GtkWidget *content_hpane; + GtkWidget *main_vbox; + GtkWidget *main_view_scroller; + GtkWidget *contents_view_scroller; + GtkWidget *content_hpane; - int width; - int height; - int x, y; - int w = 0, h = 0; - const char *pref; + int width; + int height; + int x, y; + int w = 0, h = 0; + const char *pref; - wHelpWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); + wHelpWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - width = gdk_screen_get_width(gtk_window_get_screen((GtkWindow *)wHelpWindow)); - height = gdk_screen_get_height(gtk_window_get_screen((GtkWindow *)wHelpWindow)); + width = gdk_screen_get_width(gtk_window_get_screen((GtkWindow *)wHelpWindow)); + height = gdk_screen_get_height(gtk_window_get_screen((GtkWindow *)wHelpWindow)); - pref = wPrefGetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME); + pref = wPrefGetString(HTMLHELPSECTION, WINDOWSIZEPREFNAME); - if (pref) { - sscanf(pref, "%d %d", &w, &h); + if (pref) { + sscanf(pref, "%d %d", &w, &h); - if (w > width) { - w = width; - } + if (w > width) { + w = width; + } - if (h > height) { - h = height; - } - } else { - w = (width * 2)/ 5; - h = height - 100; - } + if (h > height) { + h = height; + } + } else { + w = (width * 2)/ 5; + h = height - 100; + } - pref = wPrefGetString(HTMLHELPSECTION, WINDOWPOSPREFNAME); + pref = wPrefGetString(HTMLHELPSECTION, WINDOWPOSPREFNAME); - if (pref) { - sscanf(pref, "%d %d", &x, &y); + if (pref) { + sscanf(pref, "%d %d", &x, &y); - if (y > height - h) { - y = height - h; - } + if (y > height - h) { + y = height - h; + } - if (x > width - w) { - x = width - w; - } - } else { - x = (width * 3) / 5 - 10; - y = 70; - } + if (x > width - w) { + x = width - w; + } + } else { + x = (width * 3) / 5 - 10; + y = 70; + } - gtk_window_resize((GtkWindow *)wHelpWindow, w, h); - gtk_window_move((GtkWindow *)wHelpWindow, x, y); + gtk_window_resize((GtkWindow *)wHelpWindow, w, h); + gtk_window_move((GtkWindow *)wHelpWindow, x, y); - gtk_window_set_title(GTK_WINDOW(wHelpWindow), "XTrkCad Help"); + gtk_window_set_title(GTK_WINDOW(wHelpWindow), "XTrkCad Help"); - g_signal_connect(G_OBJECT(wHelpWindow), "delete-event", - G_CALLBACK(DestroyHelpWindow), NULL); + g_signal_connect(G_OBJECT(wHelpWindow), "delete-event", + G_CALLBACK(DestroyHelpWindow), NULL); - main_view_scroller = gtk_scrolled_window_new(NULL, NULL); - contents_view_scroller = gtk_scrolled_window_new(NULL, NULL); - main_view = webkit_web_view_new(); - contents_view = webkit_web_view_new(); - // must be done here as it gets locked down later - load_into_view("contents.html", CONTENTS_VIEW); - gtk_widget_set_size_request(GTK_WIDGET(wHelpWindow), x, y); + main_view_scroller = gtk_scrolled_window_new(NULL, NULL); + contents_view_scroller = gtk_scrolled_window_new(NULL, NULL); + main_view = webkit_web_view_new(); + contents_view = webkit_web_view_new(); + // must be done here as it gets locked down later + load_into_view("contents.html", CONTENTS_VIEW); + gtk_widget_set_size_request(GTK_WIDGET(wHelpWindow), x, y); - main_vbox = gtk_vbox_new(FALSE, 5); - gtk_container_add(GTK_CONTAINER(wHelpWindow), main_vbox); + main_vbox = gtk_vbox_new(FALSE, 5); + gtk_container_add(GTK_CONTAINER(wHelpWindow), main_vbox); - gtk_container_add(GTK_CONTAINER(main_view_scroller), main_view); + gtk_container_add(GTK_CONTAINER(main_view_scroller), main_view); - gtk_container_add(GTK_CONTAINER(contents_view_scroller), contents_view); + gtk_container_add(GTK_CONTAINER(contents_view_scroller), contents_view); - content_hpane = gtk_hpaned_new(); - initialize_buttons(main_vbox, content_hpane); - gtk_container_add(GTK_CONTAINER(content_hpane), contents_view_scroller); - gtk_container_add(GTK_CONTAINER(content_hpane), main_view_scroller); - gtk_box_pack_start(GTK_BOX(main_vbox), content_hpane, TRUE, TRUE, 0); + content_hpane = gtk_hpaned_new(); + initialize_buttons(main_vbox, content_hpane); + gtk_container_add(GTK_CONTAINER(content_hpane), contents_view_scroller); + gtk_container_add(GTK_CONTAINER(content_hpane), main_view_scroller); + gtk_box_pack_start(GTK_BOX(main_vbox), content_hpane, TRUE, TRUE, 0); - gtk_paned_set_position(GTK_PANED(content_hpane), 370); + gtk_paned_set_position(GTK_PANED(content_hpane), 370); - g_signal_connect(contents_view, "navigation-policy-decision-requested", - G_CALLBACK(contents_click_handler), G_OBJECT(main_view)); + g_signal_connect(contents_view, "navigation-policy-decision-requested", + G_CALLBACK(contents_click_handler), G_OBJECT(main_view)); - /* Store pointers to all widgets, for use by lookup_widget(). */ - GLADE_HOOKUP_OBJECT_NO_REF(wHelpWindow, wHelpWindow, "wHelpWindow"); - GLADE_HOOKUP_OBJECT(wHelpWindow, content_hpane, PANED); - GLADE_HOOKUP_OBJECT(wHelpWindow, contents_view, TOCVIEW); - GLADE_HOOKUP_OBJECT(wHelpWindow, main_view, CONTENTSVIEW); + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT_NO_REF(wHelpWindow, wHelpWindow, "wHelpWindow"); + GLADE_HOOKUP_OBJECT(wHelpWindow, content_hpane, PANED); + GLADE_HOOKUP_OBJECT(wHelpWindow, contents_view, TOCVIEW); + GLADE_HOOKUP_OBJECT(wHelpWindow, main_view, CONTENTSVIEW); - return wHelpWindow; + return wHelpWindow; } void load_into_view(char *file, int requested_view) { - GtkWidget *view; + GtkWidget *view; - switch (requested_view) { - case MAIN_VIEW: - view = main_view; - break; + switch (requested_view) { + case MAIN_VIEW: + view = main_view; + break; - case CONTENTS_VIEW: - view = contents_view; - break; + case CONTENTS_VIEW: + view = contents_view; + break; - default: - printf("*** error, could not find view"); - break; - } + default: + printf("*** error, could not find view"); + break; + } - char fileToLoad[250] = "file://"; - strcat(fileToLoad,directory); - strcat(fileToLoad,file); + char fileToLoad[250] = "file://"; + strcat(fileToLoad,directory); + strcat(fileToLoad,file); - //debug printf("*** loading %s into pane %d.\n", fileToLoad, requested_view); - webkit_web_view_load_uri(WEBKIT_WEB_VIEW(view), fileToLoad); + //debug printf("*** loading %s into pane %d.\n", fileToLoad, requested_view); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(view), fileToLoad); } /** @@ -402,36 +402,36 @@ void load_into_view(char *file, int requested_view) void wHelp(const char * topic) { - char *htmlFile; + char *htmlFile; - //Take off any topic characters after a '-' + //Take off any topic characters after a '-' - if (!topic || !topic[0]) return; + if (!topic || !topic[0]) { return; } - if (!CheckHelpTopicExists(topic)) return; + if (!CheckHelpTopicExists(topic)) { return; } - if (!wHelpWindow) { - directory = malloc(BUFSIZ); - assert(directory != NULL); + if (!wHelpWindow) { + directory = malloc(BUFSIZ); + assert(directory != NULL); - sprintf(directory, "%s/html/", wGetAppLibDir()); + sprintf(directory, "%s/html/", wGetAppLibDir()); - wHelpWindow = CreateHelpWindow(); - /* load the default content */ - load_into_view("index.html", MAIN_VIEW); - } + wHelpWindow = CreateHelpWindow(); + /* load the default content */ + load_into_view("index.html", MAIN_VIEW); + } - /* need space for the 'html' extension plus dot plus \0 */ - htmlFile = malloc(strlen(topic) + 6); + /* need space for the 'html' extension plus dot plus \0 */ + htmlFile = malloc(strlen(topic) + 6); - assert(htmlFile != NULL); + assert(htmlFile != NULL); - sprintf(htmlFile, "%s.html", topic); + sprintf(htmlFile, "%s.html", topic); - load_into_view(htmlFile, MAIN_VIEW); - gtk_widget_show_all(wHelpWindow); - gtk_window_present(GTK_WINDOW(wHelpWindow)); + load_into_view(htmlFile, MAIN_VIEW); + gtk_widget_show_all(wHelpWindow); + gtk_window_present(GTK_WINDOW(wHelpWindow)); - free(htmlFile); + free(htmlFile); } diff --git a/app/wlib/gtklib/lines.c b/app/wlib/gtklib/lines.c index bd787a6..6ce7ac1 100644 --- a/app/wlib/gtklib/lines.c +++ b/app/wlib/gtklib/lines.c @@ -44,10 +44,10 @@ */ struct wLine_t { - WOBJ_COMMON - wBool_t visible; - int count; - wLines_t * lines; + WOBJ_COMMON + wBool_t visible; + int count; + wLines_t * lines; }; /** @@ -59,30 +59,30 @@ struct wLine_t { static void linesRepaint(wControl_p b) { - wLine_p bl = (wLine_p)(b); - int i; - wWin_p win = (wWin_p)(bl->parent); - GdkDrawable * window; - cairo_t *cr; - - if (!bl->visible) { - return; - } - - window = gtk_widget_get_window(win->widget); - cr = gdk_cairo_create(window); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); - cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); - - for (i=0; i<bl->count; i++) { - cairo_set_line_width(cr, bl->lines[i].width); - cairo_move_to(cr, bl->lines[i].x0, bl->lines[i].y0); - cairo_line_to(cr, bl->lines[i].x1, bl->lines[i].y1); - cairo_stroke(cr); - } - - cairo_destroy(cr); + wLine_p bl = (wLine_p)(b); + int i; + wWin_p win = (wWin_p)(bl->parent); + GdkDrawable * window; + cairo_t *cr; + + if (!bl->visible) { + return; + } + + window = gtk_widget_get_window(win->widget); + cr = gdk_cairo_create(window); + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); + + for (i=0; i<bl->count; i++) { + cairo_set_line_width(cr, bl->lines[i].width); + cairo_move_to(cr, bl->lines[i].x0, bl->lines[i].y0); + cairo_line_to(cr, bl->lines[i].x1, bl->lines[i].y1); + cairo_stroke(cr); + } + + cairo_destroy(cr); } /** @@ -94,10 +94,10 @@ static void linesRepaint(wControl_p b) */ void wlibLineShow( - wLine_p bl, - wBool_t visible) + wLine_p bl, + wBool_t visible) { - bl->visible = visible; + bl->visible = visible; } /** @@ -111,40 +111,40 @@ void wlibLineShow( */ wLine_p wLineCreate( - wWin_p parent, - const char * labelStr, - int count, - wLines_t * lines) + wWin_p parent, + const char * labelStr, + int count, + wLines_t * lines) { - wLine_p linesWindow; - int i; - linesWindow = (wLine_p)wlibAlloc(parent, B_LINES, 0, 0, labelStr, - sizeof *linesWindow, NULL); - linesWindow->visible = TRUE; - linesWindow->count = count; - linesWindow->lines = lines; - linesWindow->w = linesWindow->h = 0; - - for (i=0; i<count; i++) { - if (lines[i].x0 > linesWindow->w) { - linesWindow->w = lines[i].x0; - } - - if (lines[i].y0 > linesWindow->h) { - linesWindow->h = lines[i].y0; - } - - if (lines[i].x1 > linesWindow->w) { - linesWindow->w = lines[i].x1; - } - - if (lines[i].y1 > linesWindow->h) { - linesWindow->h = lines[i].y1; - } - } - - linesWindow->repaintProc = linesRepaint; - wlibAddButton((wControl_p)linesWindow); - linesWindow->widget = NULL; - return linesWindow; + wLine_p linesWindow; + int i; + linesWindow = (wLine_p)wlibAlloc(parent, B_LINES, 0, 0, labelStr, + sizeof *linesWindow, NULL); + linesWindow->visible = TRUE; + linesWindow->count = count; + linesWindow->lines = lines; + linesWindow->w = linesWindow->h = 0; + + for (i=0; i<count; i++) { + if (lines[i].x0 > linesWindow->w) { + linesWindow->w = lines[i].x0; + } + + if (lines[i].y0 > linesWindow->h) { + linesWindow->h = lines[i].y0; + } + + if (lines[i].x1 > linesWindow->w) { + linesWindow->w = lines[i].x1; + } + + if (lines[i].y1 > linesWindow->h) { + linesWindow->h = lines[i].y1; + } + } + + linesWindow->repaintProc = linesRepaint; + wlibAddButton((wControl_p)linesWindow); + linesWindow->widget = NULL; + return linesWindow; } diff --git a/app/wlib/gtklib/list.c b/app/wlib/gtklib/list.c index 2080b9f..92977dc 100644 --- a/app/wlib/gtklib/list.c +++ b/app/wlib/gtklib/list.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -37,9 +37,9 @@ #include "i18n.h" struct listSearch { - const char *search; - char *result; - int row; + const char *search; + char *result; + int row; }; @@ -59,21 +59,21 @@ struct listSearch { */ void wListClear( - wList_p b) + wList_p b) { - assert(b!= NULL); + assert(b!= NULL); - b->recursion++; + b->recursion++; - if (b->type == B_DROPLIST) { - wDropListClear(b); - } else { - wTreeViewClear(b); - } + if (b->type == B_DROPLIST) { + wDropListClear(b); + } else { + wTreeViewClear(b); + } - b->recursion--; - b->last = -1; - b->count = 0; + b->recursion--; + b->last = -1; + b->count = 0; } /** @@ -84,23 +84,23 @@ void wListClear( */ void wListSetIndex( - wList_p b, - int element) + wList_p b, + int element) { - if (b->widget == 0) { - abort(); - } + if (b->widget == 0) { + abort(); + } - b->recursion++; + b->recursion++; - if (b->type == B_DROPLIST) { - wDropListSetIndex(b, element); - } else { - wlibTreeViewSetSelected(b, element); - } + if (b->type == B_DROPLIST) { + wDropListSetIndex(b, element); + } else { + wlibTreeViewSetSelected(b, element); + } - b->last = element; - b->recursion--; + b->last = element; + b->recursion--; } /** @@ -121,23 +121,23 @@ int CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { - wListItem_p id_p; - struct listSearch *search = (struct listSearch *)data; - - gtk_tree_model_get(model, - iter, - LISTCOL_DATA, - &id_p, - -1); - - if (id_p && id_p->label && !strcmp(id_p->label, search->search)) { - search->result = (char *)id_p->label; - return TRUE; - } else { - search->result = NULL; - search->row++; - return FALSE; - } + wListItem_p id_p; + struct listSearch *search = (struct listSearch *)data; + + gtk_tree_model_get(model, + iter, + LISTCOL_DATA, + &id_p, + -1); + + if (id_p && id_p->label && !strcmp(id_p->label, search->search)) { + search->result = (char *)id_p->label; + return TRUE; + } else { + search->result = NULL; + search->row++; + return FALSE; + } } /** @@ -149,25 +149,25 @@ CompareListData(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, */ wIndex_t wListFindValue( - wList_p b, - const char * val) + wList_p b, + const char * val) { - struct listSearch thisSearch; + struct listSearch thisSearch; - assert(b!=NULL); - assert(b->listStore!=NULL); + assert(b!=NULL); + assert(b->listStore!=NULL); - thisSearch.search = val; - thisSearch.row = 0; + thisSearch.search = val; + thisSearch.row = 0; - gtk_tree_model_foreach(GTK_TREE_MODEL(b->listStore), CompareListData, - (void *)&thisSearch); + gtk_tree_model_foreach(GTK_TREE_MODEL(b->listStore), CompareListData, + (void *)&thisSearch); - if (!thisSearch.result) { - return -1; - } else { - return thisSearch.row; - } + if (!thisSearch.result) { + return -1; + } else { + return thisSearch.row; + } } /** @@ -178,13 +178,13 @@ wIndex_t wListFindValue( */ wIndex_t wListGetCount( - wList_p b) + wList_p b) { - if (b->type == B_DROPLIST) { - return wDropListGetCount(b); - } else { - return wTreeViewGetCount(b); - } + if (b->type == B_DROPLIST) { + return wDropListGetCount(b); + } else { + return wTreeViewGetCount(b); + } } /** @@ -196,18 +196,18 @@ wIndex_t wListGetCount( */ void * wListGetItemContext( - wList_p b, - wIndex_t inx) + wList_p b, + wIndex_t inx) { - if (inx < 0) { - return NULL; - } - - if (b->type == B_DROPLIST) { - return wDropListGetItemContext(b, inx); - } else { - return wTreeViewGetItemContext(b, inx); - } + if (inx < 0) { + return NULL; + } + + if (b->type == B_DROPLIST) { + return wDropListGetItemContext(b, inx); + } else { + return wTreeViewGetItemContext(b, inx); + } } /** @@ -221,57 +221,57 @@ void * wListGetItemContext( */ wIndex_t wListGetValues( - wList_p bl, - char * labelStr, - int labelSize, - void * * listDataRet, - void * * itemDataRet) + wList_p bl, + char * labelStr, + int labelSize, + void * * listDataRet, + void * * itemDataRet) { - wListItem_p id_p; - wIndex_t inx = bl->last; - const char * entry_value = ""; - void * item_data = NULL; - - assert(bl != NULL); - assert(bl->listStore != NULL); - - if (bl->type == B_DROPLIST && bl->editted) { - entry_value = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN( - bl->widget)))); - item_data = NULL; - inx = bl->last = -1; - } else { - //Make sure in range - if (bl->last > bl->count-1) bl->last = bl->count-1; - inx = bl->last; - - - if (inx >= 0) { - id_p = wlibListStoreGetContext(bl->listStore, inx); - - if (id_p==NULL) { - fprintf(stderr, "wListGetValues - id_p == NULL\n"); - bl->last = -1; - } else { - entry_value = id_p->label; - item_data = id_p->itemData; - } - } - } - - if (labelStr) { - strncpy(labelStr, entry_value, labelSize); - } - - if (listDataRet) { - *listDataRet = bl->data; - } - - if (itemDataRet) { - *itemDataRet = item_data; - } - - return bl->last; + wListItem_p id_p; + wIndex_t inx = bl->last; + const char * entry_value = ""; + void * item_data = NULL; + + assert(bl != NULL); + assert(bl->listStore != NULL); + + if (bl->type == B_DROPLIST && bl->editted) { + entry_value = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN( + bl->widget)))); + item_data = NULL; + inx = bl->last = -1; + } else { + //Make sure in range + if (bl->last > bl->count-1) { bl->last = bl->count-1; } + inx = bl->last; + + + if (inx >= 0) { + id_p = wlibListStoreGetContext(bl->listStore, inx); + + if (id_p==NULL) { + fprintf(stderr, "wListGetValues - id_p == NULL\n"); + bl->last = -1; + } else { + entry_value = id_p->label; + item_data = id_p->itemData; + } + } + } + + if (labelStr) { + strncpy(labelStr, entry_value, labelSize); + } + + if (listDataRet) { + *listDataRet = bl->data; + } + + if (itemDataRet) { + *itemDataRet = item_data; + } + + return bl->last; } /** @@ -282,22 +282,22 @@ wIndex_t wListGetValues( */ wBool_t wListGetItemSelected( - wList_p b, - wIndex_t inx) + wList_p b, + wIndex_t inx) { - wListItem_p id_p; + wListItem_p id_p; - if (inx < 0) { - return FALSE; - } + if (inx < 0) { + return FALSE; + } - id_p = wlibListStoreGetContext(b->listStore, inx); + id_p = wlibListStoreGetContext(b->listStore, inx); - if (id_p) { - return id_p->selected; - } else { - return FALSE; - } + if (id_p) { + return id_p->selected; + } else { + return FALSE; + } } /** @@ -308,16 +308,16 @@ wBool_t wListGetItemSelected( */ wIndex_t wListGetSelectedCount( - wList_p b) + wList_p b) { - wIndex_t selcnt, inx; + wIndex_t selcnt, inx; - for (selcnt=inx=0; inx<b->count; inx++) - if (wListGetItemSelected(b, inx)) { - selcnt++; - } + for (selcnt=inx=0; inx<b->count; inx++) + if (wListGetItemSelected(b, inx)) { + selcnt++; + } - return selcnt; + return selcnt; } /** @@ -329,26 +329,26 @@ wIndex_t wListGetSelectedCount( void wListSelectAll(wList_p bl) { - wIndex_t inx; - GtkTreeSelection *selection; + wIndex_t inx; + GtkTreeSelection *selection; - assert(bl != NULL); - // mark all items selected - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView)); - gtk_tree_selection_select_all(selection); + assert(bl != NULL); + // mark all items selected + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView)); + gtk_tree_selection_select_all(selection); - // and synchronize the internal data structures - wListGetCount(bl); + // and synchronize the internal data structures + wListGetCount(bl); - for (inx=0; inx<bl->count; inx++) { - wListItem_p ldp; + for (inx=0; inx<bl->count; inx++) { + wListItem_p ldp; - ldp = wlibListStoreGetContext(bl->listStore, inx); + ldp = wlibListStoreGetContext(bl->listStore, inx); - if (ldp) { - ldp->selected = TRUE; - } - } + if (ldp) { + ldp->selected = TRUE; + } + } } /** @@ -363,25 +363,25 @@ void wListSelectAll(wList_p bl) */ wBool_t wListSetValues( - wList_p b, - wIndex_t row, - const char * labelStr, - wIcon_p bm, - void *itemData) + wList_p b, + wIndex_t row, + const char * labelStr, + wIcon_p bm, + void *itemData) { - assert(b->listStore != NULL); + assert(b->listStore != NULL); - b->recursion++; + b->recursion++; - if (b->type == B_DROPLIST) { - wDropListSetValues(b, row, labelStr, bm, itemData); - } else { - wlibListStoreUpdateValues(b->listStore, row, b->colCnt, (char *)labelStr, bm); - } + if (b->type == B_DROPLIST) { + wDropListSetValues(b, row, labelStr, bm, itemData); + } else { + wlibListStoreUpdateValues(b->listStore, row, b->colCnt, (char *)labelStr, bm); + } - b->recursion--; - return TRUE; + b->recursion--; + return TRUE; } /** @@ -391,34 +391,34 @@ wBool_t wListSetValues( */ void wListDelete( - wList_p b, - wIndex_t inx) + wList_p b, + wIndex_t inx) { - GtkTreeIter iter; + GtkTreeIter iter; - assert(b->listStore != 0); - assert(b->type != B_DROPLIST); - b->recursion++; + assert(b->listStore != 0); + assert(b->type != B_DROPLIST); + b->recursion++; - if (b->type == B_DROPLIST) { - wNotice("Deleting from dropboxes is not implemented!", "Continue", NULL); - } else { - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), - &iter, - NULL, - inx); - gtk_list_store_remove(b->listStore, &iter); + if (b->type == B_DROPLIST) { + wNotice("Deleting from dropboxes is not implemented!", "Continue", NULL); + } else { + gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), + &iter, + NULL, + inx); + gtk_list_store_remove(b->listStore, &iter); - b->count--; - } + b->count--; + } - if (b->last == inx-1) b->last = -1; - else if (b->last >= inx) b->last = -1; + if (b->last == inx-1) { b->last = -1; } + else if (b->last >= inx) { b->last = -1; } - b->recursion--; - return; + b->recursion--; + return; } /** @@ -431,29 +431,29 @@ void wListDelete( */ int wListGetColumnWidths( - wList_p bl, - int colCnt, - wWinPix_t * colWidths) + wList_p bl, + int colCnt, + wWinPix_t * colWidths) { - int inx; + int inx; - if (bl->type != B_LIST) { - return 0; - } + if (bl->type != B_LIST) { + return 0; + } - if (bl->colWidths == NULL) { - return 0; - } + if (bl->colWidths == NULL) { + return 0; + } - for (inx=0; inx<colCnt; inx++) { - if (inx < bl->colCnt) { - colWidths[inx] = bl->colWidths[inx]; - } else { - colWidths[inx] = 0; - } - } + for (inx=0; inx<colCnt; inx++) { + if (inx < bl->colCnt) { + colWidths[inx] = bl->colWidths[inx]; + } else { + colWidths[inx] = 0; + } + } - return bl->colCnt; + return bl->colCnt; } /** @@ -467,45 +467,45 @@ int wListGetColumnWidths( */ wIndex_t wListAddValue( - wList_p b, - const char * labelStr, - wIcon_p bm, - void * itemData) + wList_p b, + const char * labelStr, + wIcon_p bm, + void * itemData) { - wListItem_p id_p; + wListItem_p id_p; - assert(b != NULL); + assert(b != NULL); - b->recursion++; + b->recursion++; - id_p = (wListItem_p)g_malloc(sizeof *id_p); - memset(id_p, 0, sizeof *id_p); - id_p->itemData = itemData; - id_p->active = TRUE; + id_p = (wListItem_p)g_malloc(sizeof *id_p); + memset(id_p, 0, sizeof *id_p); + id_p->itemData = itemData; + id_p->active = TRUE; - if (labelStr == NULL) { - labelStr = ""; - } + if (labelStr == NULL) { + labelStr = ""; + } - id_p->label = strdup(labelStr); - id_p->listP = b; + id_p->label = strdup(labelStr); + id_p->listP = b; - if (b->type == B_DROPLIST) { - wDropListAddValue(b, (char *)labelStr, id_p); - } else { - wlibTreeViewAddRow(b, (char *)labelStr, bm, id_p); - } + if (b->type == B_DROPLIST) { + wDropListAddValue(b, (char *)labelStr, id_p); + } else { + wlibTreeViewAddRow(b, (char *)labelStr, bm, id_p); + } - //free(id_p->label); + //free(id_p->label); - b->count++; - b->recursion--; + b->count++; + b->recursion--; - if (b->count == 1) { - b->last = 0; - } + if (b->count == 1) { + b->last = 0; + } - return b->count-1; + return b->count-1; } @@ -519,14 +519,14 @@ wIndex_t wListAddValue( void wListSetSize(wList_p bl, wWinPix_t w, wWinPix_t h) { - if (bl->type == B_DROPLIST) { - gtk_widget_set_size_request(bl->widget, w, -1); - } else { - gtk_widget_set_size_request(bl->widget, w, h); - } - - bl->w = w; - bl->h = h; + if (bl->type == B_DROPLIST) { + gtk_widget_set_size_request(bl->widget, w, -1); + } else { + gtk_widget_set_size_request(bl->widget, w, h); + } + + bl->w = w; + bl->h = h; } /** @@ -540,20 +540,20 @@ void wListSetSize(wList_p bl, wWinPix_t w, wWinPix_t h) */ wList_p wComboListCreate( - wWin_p parent, /* Parent window */ - wWinPix_t x, /* X-position */ - wWinPix_t y, /* Y-position */ - const char * helpStr, /* Help string */ - const char * labelStr, /* Label */ - long option, /* Options */ - long number, /* Number of displayed list entries */ - wWinPix_t width, /* Width */ - long *valueP, /* Selected index */ - wListCallBack_p action, /* Callback */ - void *data) /* Context */ + wWin_p parent, /* Parent window */ + wWinPix_t x, /* X-position */ + wWinPix_t y, /* Y-position */ + const char * helpStr, /* Help string */ + const char * labelStr, /* Label */ + long option, /* Options */ + long number, /* Number of displayed list entries */ + wWinPix_t width, /* Width */ + long *valueP, /* Selected index */ + wListCallBack_p action, /* Callback */ + void *data) /* Context */ { - wNotice("ComboLists are not implemented!", "Abort", NULL); - abort(); + wNotice("ComboLists are not implemented!", "Abort", NULL); + abort(); } diff --git a/app/wlib/gtklib/liststore.c b/app/wlib/gtklib/liststore.c index 088bf33..b1b0f8a 100644 --- a/app/wlib/gtklib/liststore.c +++ b/app/wlib/gtklib/liststore.c @@ -47,25 +47,25 @@ */ wListItem_p wlibListItemGet( - GtkListStore *ls, - wIndex_t inx, - GList ** childR) + GtkListStore *ls, + wIndex_t inx, + GList ** childR) { - wListItem_p id_p; + wListItem_p id_p; - assert(ls != NULL); + assert(ls != NULL); - if (childR) { - *childR = NULL; - } + if (childR) { + *childR = NULL; + } - if (inx < 0) { - return NULL; - } + if (inx < 0) { + return NULL; + } - id_p = wlibListStoreGetContext(ls, inx); + id_p = wlibListStoreGetContext(ls, inx); - return id_p; + return id_p; } /** @@ -79,33 +79,33 @@ wListItem_p wlibListItemGet( void * wlibListStoreGetContext(GtkListStore *ls, int inx) { - GtkTreeIter iter; - gchar *string = NULL; - gboolean result; - gint childs; - - childs = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(ls), - NULL); - - if (inx < childs) { - result = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls), - &iter, - NULL, - inx); - - if (result) { - gtk_tree_model_get(GTK_TREE_MODEL(ls), - &iter, - LISTCOL_DATA, - &string, - -1); - } else { - printf("Invalid index %d for list!\n", inx); - - } - } - - return (string); + GtkTreeIter iter; + gchar *string = NULL; + gboolean result; + gint childs; + + childs = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(ls), + NULL); + + if (inx < childs) { + result = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls), + &iter, + NULL, + inx); + + if (result) { + gtk_tree_model_get(GTK_TREE_MODEL(ls), + &iter, + LISTCOL_DATA, + &string, + -1); + } else { + printf("Invalid index %d for list!\n", inx); + + } + } + + return (string); } @@ -119,21 +119,22 @@ wlibListStoreGetContext(GtkListStore *ls, int inx) void wlibListStoreClear(GtkListStore *listStore) { - wListItem_p id_p; - int i = 0; + wListItem_p id_p; + int i = 0; - assert(listStore != NULL); + assert(listStore != NULL); - id_p = wlibListStoreGetContext(listStore, i++); + id_p = wlibListStoreGetContext(listStore, i++); - while (id_p) { - if (id_p->label) - g_free(id_p->label); - g_free(id_p); - id_p = wlibListStoreGetContext(listStore, i++); - } + while (id_p) { + if (id_p->label) { + g_free(id_p->label); + } + g_free(id_p); + id_p = wlibListStoreGetContext(listStore, i++); + } - gtk_list_store_clear(listStore); + gtk_list_store_clear(listStore); } /** @@ -148,23 +149,23 @@ wlibListStoreClear(GtkListStore *listStore) GtkListStore * wlibNewListStore(int colCnt) { - GtkListStore *ls; - GType *colTypes; - int i; + GtkListStore *ls; + GType *colTypes; + int i; - /* create the list store, using strings for all columns */ - colTypes = g_malloc(sizeof(GType) * (colCnt + LISTCOL_TEXT)); - colTypes[ LISTCOL_BITMAP ] = GDK_TYPE_PIXBUF; - colTypes[ LISTCOL_DATA ] = G_TYPE_POINTER; + /* create the list store, using strings for all columns */ + colTypes = g_malloc(sizeof(GType) * (colCnt + LISTCOL_TEXT)); + colTypes[ LISTCOL_BITMAP ] = GDK_TYPE_PIXBUF; + colTypes[ LISTCOL_DATA ] = G_TYPE_POINTER; - for (i = 0; i < colCnt; i++) { - colTypes[ LISTCOL_TEXT + i ] = G_TYPE_STRING; - } + for (i = 0; i < colCnt; i++) { + colTypes[ LISTCOL_TEXT + i ] = G_TYPE_STRING; + } - ls = gtk_list_store_newv(colCnt + LISTCOL_TEXT, colTypes); - g_free(colTypes); + ls = gtk_list_store_newv(colCnt + LISTCOL_TEXT, colTypes); + g_free(colTypes); - return (ls); + return (ls); } /** @@ -179,26 +180,26 @@ wlibNewListStore(int colCnt) static int wlibListStoreUpdateIter(GtkListStore *ls, GtkTreeIter *iter, char *labels) { - char *convertedLabels; - char *text; - char *start; - int current = 0; - - convertedLabels = strdup(wlibConvertInput(labels)); - start = convertedLabels; - - while ((text = strchr(start, '\t')) != NULL) { - *text = '\0'; - gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1); - start = text + 1; - current++; - } - - /* add the last piece of the string */ - gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1); - - free(convertedLabels); - return (current+1); + char *convertedLabels; + char *text; + char *start; + int current = 0; + + convertedLabels = strdup(wlibConvertInput(labels)); + start = convertedLabels; + + while ((text = strchr(start, '\t')) != NULL) { + *text = '\0'; + gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1); + start = text + 1; + current++; + } + + /* add the last piece of the string */ + gtk_list_store_set(ls, iter, LISTCOL_TEXT + current, start, -1); + + free(convertedLabels); + return (current+1); } /** @@ -213,9 +214,9 @@ wlibListStoreUpdateIter(GtkListStore *ls, GtkTreeIter *iter, char *labels) void wlibListStoreSetPixbuf(GtkListStore *ls, GtkTreeIter *iter, GdkPixbuf *pixbuf) { - gtk_list_store_set(ls, iter, LISTCOL_BITMAP, pixbuf, -1); - g_object_ref_sink(pixbuf); - g_object_unref(pixbuf); + gtk_list_store_set(ls, iter, LISTCOL_BITMAP, pixbuf, -1); + g_object_ref_sink(pixbuf); + g_object_unref(pixbuf); } /** * Add a row to the list store @@ -230,19 +231,19 @@ int wlibListStoreAddData(GtkListStore *ls, GdkPixbuf *pixbuf, int cols, wListItem_p id) { - GtkTreeIter iter; - int count; + GtkTreeIter iter; + int count; - gtk_list_store_append(ls, &iter); - gtk_list_store_set(ls, &iter, LISTCOL_DATA, id, -1); + gtk_list_store_append(ls, &iter); + gtk_list_store_set(ls, &iter, LISTCOL_DATA, id, -1); - if (pixbuf) { - wlibListStoreSetPixbuf(ls, &iter, pixbuf); - } + if (pixbuf) { + wlibListStoreSetPixbuf(ls, &iter, pixbuf); + } - count = wlibListStoreUpdateIter(ls, &iter, (char *)id->label); + count = wlibListStoreUpdateIter(ls, &iter, (char *)id->label); - return (count); + return (count); } /** @@ -261,23 +262,23 @@ int wlibListStoreUpdateValues(GtkListStore *ls, int row, int cols, char *labels, wIcon_p bm) { - GtkTreeIter iter; - int count; + GtkTreeIter iter; + int count; - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls), - &iter, - NULL, - row); + gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ls), + &iter, + NULL, + row); - count = wlibListStoreUpdateIter(ls, &iter, labels); + count = wlibListStoreUpdateIter(ls, &iter, labels); - if (bm) { - GdkPixbuf *pixbuf; + if (bm) { + GdkPixbuf *pixbuf; - pixbuf = wlibMakePixbuf(bm); - wlibListStoreSetPixbuf(ls, &iter, pixbuf); - } + pixbuf = wlibMakePixbuf(bm); + wlibListStoreSetPixbuf(ls, &iter, pixbuf); + } - return (count); + return (count); } diff --git a/app/wlib/gtklib/main.c b/app/wlib/gtklib/main.c index 470f17b..7022a0a 100644 --- a/app/wlib/gtklib/main.c +++ b/app/wlib/gtklib/main.c @@ -18,7 +18,7 @@ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -46,10 +46,10 @@ char *wExecutableName; * Initialize the application name for later use
*
* \param _appName IN Name of application
- * \return
+ * \return
*/
-
-void
+
+void
wInitAppName(char *_appName)
{
appName = g_strdup( _appName );
@@ -59,7 +59,7 @@ char * wlibGetAppName()
{
return( appName );
-}
+}
/*
*******************************************************************************
@@ -76,17 +76,19 @@ int main( int argc, char *argv[] ) wWin_p win;
const char *ld;
- if ( getenv( "GTKLIB_NOLOCALE" ) == 0 )
+ if ( getenv( "GTKLIB_NOLOCALE" ) == 0 ) {
setlocale( LC_ALL, "en_US" );
+ }
gtk_init( &argc, &argv );
- if ((win=wMain( argc, argv )) == NULL)
+ if ((win=wMain( argc, argv )) == NULL) {
exit(1);
- wExecutableName = argv[ 0 ];
+ }
+ wExecutableName = argv[ 0 ];
ld = wGetAppLibDir();
-
+
#ifdef WINDOWS
-
+
#else
// set up help search path on unix boxes
if (ld != NULL) {
@@ -94,14 +96,16 @@ int main( int argc, char *argv[] ) const char *hp;
sprintf( buff, "HELPPATH=/usr/lib/help:%s:", ld );
- if ( (hp = getenv("HELPPATH")) != NULL )
+ if ( (hp = getenv("HELPPATH")) != NULL ) {
strcat( buff, hp );
+ }
putenv( buff );
}
#endif
-
- if (!win->shown)
+
+ if (!win->shown) {
wWinShow( win, TRUE );
+ }
gtk_main();
exit(0);
diff --git a/app/wlib/gtklib/menu.c b/app/wlib/gtklib/menu.c index 754f88f..8646f15 100644 --- a/app/wlib/gtklib/menu.c +++ b/app/wlib/gtklib/menu.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -50,28 +50,29 @@ typedef enum { M_MENU, M_SEPARATOR, M_PUSH, M_LIST, M_LISTITEM, M_TOGGLE, M_RADIO } mtype_e; typedef enum { MM_BUTT, MM_MENU, MM_BAR, MM_POPUP } mmtype_e; -typedef struct{ mtype_e mtype; /**< menu entry type */ - GtkWidget *menu_item; - wMenu_p parentMenu; - int recursion; /**< recursion counter */ - } MOBJ_COMMON; /**< menu item specific data */ - - +typedef struct { + mtype_e mtype; /**< menu entry type */ + GtkWidget *menu_item; + wMenu_p parentMenu; + int recursion; /**< recursion counter */ +} MOBJ_COMMON; /**< menu item specific data */ + + struct wMenuItem_t { WOBJ_COMMON MOBJ_COMMON m; - }; +}; typedef struct wMenuItem_t * wMenuItem_p; -// a few macros to make access to members easier -//#define PTR2M( ptr ) ((ptr)->m) -#define MMENUITEM( ptr ) (((ptr)->m).menu_item) +// a few macros to make access to members easier +//#define PTR2M( ptr ) ((ptr)->m) +#define MMENUITEM( ptr ) (((ptr)->m).menu_item) #define MPARENT( ptr ) (((ptr)->m).parentMenu) #define MITEMTYPE( ptr ) (((ptr)->m).mtype) -#define MRECURSION( ptr ) (((ptr)->m).recursion) - - +#define MRECURSION( ptr ) (((ptr)->m).recursion) + + struct wMenu_t { WOBJ_COMMON MOBJ_COMMON m; @@ -83,21 +84,21 @@ struct wMenu_t { void * traceData; GtkLabel * labelG; GtkWidget * imageG; - }; +}; struct wMenuPush_t { WOBJ_COMMON MOBJ_COMMON m; wMenuCallBack_p action; wBool_t enabled; - }; +}; struct wMenuRadio_t { WOBJ_COMMON MOBJ_COMMON m; wMenuCallBack_p action; wBool_t enabled; - }; +}; struct wMenuList_t { WOBJ_COMMON @@ -105,44 +106,45 @@ struct wMenuList_t { int max; int count; wMenuListCallBack_p action; - }; +}; struct wMenuListItem_t { WOBJ_COMMON MOBJ_COMMON m; wMenuList_p mlist; - }; +}; typedef struct wMenuListItem_t * wMenuListItem_p; - + struct wMenuToggle_t { WOBJ_COMMON MOBJ_COMMON m; wMenuCallBack_p action; wBool_t enabled; wBool_t set; - }; +}; /*-----------------------------------------------------------------*/ - + /** * Handle activate event for menu items. * * \param widget IN widget that emitted the signal * \param value IN application data - * \return + * \return */ - + static void pushMenuItem( - GtkWidget * widget, - gpointer value ) + GtkWidget * widget, + gpointer value ) { wMenuItem_p m = (wMenuItem_p)value; wMenuToggle_p mt; - if (MRECURSION( m )) + if (MRECURSION( m )) { return; + } switch MITEMTYPE( m ) { case M_PUSH: @@ -155,9 +157,10 @@ static void pushMenuItem( break; case M_RADIO: /* NOTE: action is only called when radio button is activated, not when deactivated */ - if( gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget ) == TRUE ) + if( gtk_check_menu_item_get_active((GtkCheckMenuItem *)widget ) == TRUE ) { ((wMenuRadio_p)m)->action( ((wMenuRadio_p)m)->data ); - break; + } + break; case M_MENU: return; default: @@ -167,57 +170,63 @@ static void pushMenuItem( if( MPARENT(m)->traceFunc ) { MPARENT(m)->traceFunc( MPARENT( m ), m->labelStr, MPARENT(m)->traceData ); } -} +} /** * Create a new menu element, add to the parent menu and to help * * \param m IN parent menu * \param mtype IN type of new entry - * \param helpStr IN help topic + * \param helpStr IN help topic * \param labelStr IN display label * \param size IN size of additional data? * \return the newly created menu element */ static wMenuItem_p createMenuItem( - wMenu_p m, - mtype_e mtype, - const char * helpStr, - const char * labelStr, - int size ) + wMenu_p m, + mtype_e mtype, + const char * helpStr, + const char * labelStr, + int size ) { wMenuItem_p mi; mi = (wMenuItem_p)wlibAlloc( NULL, B_MENUITEM, 0, 0, labelStr, size, NULL ); MITEMTYPE( mi )= mtype; - + switch ( mtype ) { case M_LIST: - MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput(mi->labelStr)); // NULL; //PTR2M(m).menu_item + MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput( + mi->labelStr)); // NULL; //PTR2M(m).menu_item break; case M_SEPARATOR: MMENUITEM( mi ) = gtk_separator_menu_item_new(); break; case M_TOGGLE: - MMENUITEM( mi ) = gtk_check_menu_item_new_with_mnemonic(wlibConvertInput(mi->labelStr)); + MMENUITEM( mi ) = gtk_check_menu_item_new_with_mnemonic(wlibConvertInput( + mi->labelStr)); break; case M_RADIO: - MMENUITEM( mi ) = gtk_radio_menu_item_new_with_mnemonic(m->radioGroup, wlibConvertInput(mi->labelStr)); - m->radioGroup = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (MMENUITEM( mi ))); - break; + MMENUITEM( mi ) = gtk_radio_menu_item_new_with_mnemonic(m->radioGroup, + wlibConvertInput(mi->labelStr)); + m->radioGroup = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (MMENUITEM( + mi ))); + break; default: - MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput(mi->labelStr)); + MMENUITEM( mi ) = gtk_menu_item_new_with_mnemonic(wlibConvertInput( + mi->labelStr)); break; } if (MMENUITEM( mi )) { - if (m) + if (m) { gtk_menu_shell_append( (GtkMenuShell *)(m->menu), MMENUITEM( mi ) ); + } g_signal_connect( GTK_OBJECT(MMENUITEM( mi )), "activate", - G_CALLBACK(pushMenuItem), mi ); - gtk_widget_show(MMENUITEM( mi )); + G_CALLBACK(pushMenuItem), mi ); + gtk_widget_show(MMENUITEM( mi )); } - + // this is a link list of all menu items belonging to a specific menu // is used in automatic processing (macro)?? if (m) { @@ -229,8 +238,8 @@ static wMenuItem_p createMenuItem( m->last = mi; } mi->next = NULL; - - + + if (helpStr != NULL) { wlibAddHelpString( MMENUITEM( mi ), helpStr ); } @@ -240,13 +249,14 @@ static wMenuItem_p createMenuItem( /** * Add a accelerator key to a widget - * + * * @param w IN unused(?) * @param menu IN unused(?) * @param menu_item IN owning widget * @param acclKey IN the accelerator key */ -static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int acclKey ) +static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, + int acclKey ) { int mask; static GtkAccelGroup * accel_alpha_group = NULL; @@ -267,10 +277,10 @@ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int a gtk_window_add_accel_group(GTK_WINDOW(gtkMainW->gtkwin), accel_nonalpha_group ); gtk_accelerator_set_default_mod_mask( oldmods ); } - + mask = 0; if (acclKey) { - + if (acclKey&WALT) { mask |= GDK_MOD1_MASK; } @@ -305,38 +315,38 @@ static void setAcclKey( wWin_p w, GtkWidget * menu, GtkWidget * menu_item, int a mask |= GDK_CONTROL_MASK; } gtk_widget_add_accelerator( menu_item, "activate", - (isalpha(acclKey&0xFF)?accel_alpha_group:accel_nonalpha_group), - toupper(acclKey&0xFF), mask, GTK_ACCEL_VISIBLE|GTK_ACCEL_LOCKED ); + (isalpha(acclKey&0xFF)?accel_alpha_group:accel_nonalpha_group), + toupper(acclKey&0xFF), mask, GTK_ACCEL_VISIBLE|GTK_ACCEL_LOCKED ); } } /*-----------------------------------------------------------------*/ /** - * Create a radio button as a menu entry + * Create a radio button as a menu entry * * \param m IN menu to be extended * \param helpStr IN reference into help * \param labelStr IN text for entry * \param acclKey IN accelerator key to add - * \param action IN callback function + * \param action IN callback function * \param data IN application data * \param helpStr IN * \return menu entry */ wMenuRadio_p wMenuRadioCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wMenuCallBack_p action, - void *data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wMenuCallBack_p action, + void *data ) { wMenuRadio_p mi; mi = (wMenuRadio_p)createMenuItem( m, M_RADIO, helpStr, labelStr, sizeof *mi ); //~ if (m->mmtype == MM_POPUP && !testMenuPopup) - //~ return mi; + //~ return mi; setAcclKey( m->parent, m->menu, MMENUITEM( mi ), acclKey ); mi->action = action; mi->data = data; @@ -351,37 +361,38 @@ wMenuRadio_p wMenuRadioCreate( * \return */ -void wMenuRadioSetActive( - wMenuRadio_p mi ) +void wMenuRadioSetActive( + wMenuRadio_p mi ) { - gtk_check_menu_item_set_active( (GtkCheckMenuItem *)MMENUITEM(mi), TRUE ); -} + gtk_check_menu_item_set_active( (GtkCheckMenuItem *)MMENUITEM(mi), TRUE ); +} /*-----------------------------------------------------------------*/ /** - * Create a menu entry + * Create a menu entry * * \param m IN menu to be extended * \param helpStr IN reference into help * \param labelStr IN text for entry * \param acclKey IN acceleratoor key to add - * \param action IN callback function + * \param action IN callback function * \param data IN application data * \return menu entry */ wMenuPush_p wMenuPushCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wMenuCallBack_p action, - void *data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wMenuCallBack_p action, + void *data ) { wMenuPush_p mi; - mi = (wMenuPush_p)createMenuItem( m, M_PUSH, helpStr, labelStr, sizeof( struct wMenuPush_t )); + mi = (wMenuPush_p)createMenuItem( m, M_PUSH, helpStr, labelStr, + sizeof( struct wMenuPush_t )); setAcclKey( m->parent, m->menu, MMENUITEM( mi ), acclKey ); @@ -395,13 +406,13 @@ wMenuPush_p wMenuPushCreate( * Enable menu entry * * \param mi IN menu entry - * \param enable IN new state + * \param enable IN new state * \return */ void wMenuPushEnable( - wMenuPush_p mi, - wBool_t enable ) + wMenuPush_p mi, + wBool_t enable ) { mi->enabled = enable; gtk_widget_set_sensitive( GTK_WIDGET(MMENUITEM( mi )), enable ); @@ -419,12 +430,13 @@ void wMenuPushEnable( */ wMenu_p wMenuMenuCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr ) + wMenu_p m, + const char * helpStr, + const char * labelStr ) { wMenu_p mi; - mi = (wMenu_p)createMenuItem( m, M_MENU, helpStr, labelStr, sizeof( struct wMenu_t )); + mi = (wMenu_p)createMenuItem( m, M_MENU, helpStr, labelStr, + sizeof( struct wMenu_t )); mi->mmtype = MM_MENU; mi->menu = gtk_menu_new(); @@ -442,7 +454,7 @@ wMenu_p wMenuMenuCreate( */ void wMenuSeparatorCreate( - wMenu_p m ) + wMenu_p m ) { createMenuItem( m, M_SEPARATOR, NULL, "", sizeof( struct wMenuItem_t )); } @@ -464,46 +476,48 @@ int getMlistOrigin( wMenuList_p ml, GList **pChildren ) int count = 0; int found = -1; GtkWidget *mitem = MMENUITEM( ml ); - + *pChildren = gtk_container_get_children( GTK_CONTAINER( MPARENT( ml )->menu )); - if( !*pChildren ) + if( !*pChildren ) { return( -1 ); - + } + while( (mi = g_list_nth_data( *pChildren, count ))) { if( mi == mitem ) { found = TRUE; break; - } - else { + } else { count++; - } + } } - - if( found ) + + if( found ) { return( count ); - else + } else { return( -1 ); + } } /** - * Signal handler for clicking onto a menu list item. + * Signal handler for clicking onto a menu list item. * Parameters are the GtkWidget as expected and the pointer to the MenuListItem * * \param widget IN the GtkWidget - * \param value IN the menu list item + * \param value IN the menu list item * \return */ static void pushMenuList( - GtkWidget * widget, - gpointer value ) + GtkWidget * widget, + gpointer value ) { // pointer to the list item wMenuListItem_p ml = (wMenuListItem_p)value; - if (MRECURSION( ml )) + if (MRECURSION( ml )) { return; - + } + if (ml->mlist->count <= 0) { // this should never happen fprintf( stderr, "pushMenuItem: empty list\n" ); @@ -514,31 +528,32 @@ static void pushMenuList( const char * itemLabel; itemLabel = gtk_menu_item_get_label( GTK_MENU_ITEM( widget )); - - ml->mlist->action( 0, itemLabel, ml->data ); + + ml->mlist->action( 0, itemLabel, ml->data ); return; } fprintf( stderr, "pushMenuItem: item (%lx) not found\n", (long)widget ); } /** - * Create a list menu entry + * Create a list menu entry * * \param m IN menu to be extended * \param helpStr IN reference into help * \param max IN maximum number of elements - * \param action IN callback function + * \param action IN callback function * \return menu entry */ wMenuList_p wMenuListCreate( - wMenu_p m, - const char * helpStr, - int max, - wMenuListCallBack_p action ) + wMenu_p m, + const char * helpStr, + int max, + wMenuListCallBack_p action ) { wMenuList_p mi; - mi = (wMenuList_p)createMenuItem( m, M_LIST, NULL, _("<Empty List>"), sizeof( struct wMenuList_t )); + mi = (wMenuList_p)createMenuItem( m, M_LIST, NULL, _("<Empty List>"), + sizeof( struct wMenuList_t )); gtk_widget_set_sensitive( GTK_WIDGET(MMENUITEM( mi )), FALSE ); mi->next = NULL; mi->count = 0; @@ -551,90 +566,96 @@ wMenuList_p wMenuListCreate( /** * Add a new item to a list of menu entries - * The placeholder for the list is looked up. Then the new item is added immediately + * The placeholder for the list is looked up. Then the new item is added immediately * behind it. In case the maximum number of items is reached the last item is removed. * * \param ml IN handle for the menu list - the placeholder item * \param index IN position of new menu item - * \param labelStr IN the menu label for the new item + * \param labelStr IN the menu label for the new item * \param data IN application data for the new item - * \return + * \return */ void wMenuListAdd( - wMenuList_p ml, - int index, - const char * labelStr, - const void * data ) + wMenuList_p ml, + int index, + const char * labelStr, + const void * data ) { int i = 0; GList * children; i = getMlistOrigin( ml, &children ); - + if( i > -1 ) { wMenuListItem_p mi; // we're adding an item, so hide the default placeholder gtk_widget_hide( MMENUITEM( ml )); - + // delete an earlier entry with the same label - wMenuListDelete( ml, labelStr ); + wMenuListDelete( ml, labelStr ); // a new item ml->count ++; - + // is there a maximum number of items set and reached with the new item? if(( ml->max != -1 ) && ( ml->count > ml-> max )) { wMenuListItem_p mold; GtkWidget * item; - + // get the last item in the list item = g_list_nth_data( children, i + ml->max ); // get the pointer to the data structure mold = g_object_get_data( G_OBJECT( item ), WLISTITEM ); // kill the menu entry gtk_widget_destroy( item ); - // free the data + // free the data free( (void *)mold->labelStr ); free( (void *)mold ); ml->count--; - } - + } + // create the new menu item and initialize the data fields - mi = (wMenuListItem_p)wlibAlloc( NULL, B_MENUITEM, 0, 0, labelStr, sizeof( struct wMenuListItem_t ), NULL ); + mi = (wMenuListItem_p)wlibAlloc( NULL, B_MENUITEM, 0, 0, labelStr, + sizeof( struct wMenuListItem_t ), NULL ); MITEMTYPE( mi ) = M_LISTITEM; MMENUITEM( mi ) = gtk_menu_item_new_with_label(wlibConvertInput(mi->labelStr)); mi->data = (void *)data; mi->mlist = ml; g_object_set_data( G_OBJECT(MMENUITEM( mi )), WLISTITEM, mi ); - + // add the item to the menu - if ( index < 0 ) + if ( index < 0 ) { index = 0; - if ( index >= ml->count ) + } + if ( index >= ml->count ) { index = ml->count - 1; - gtk_menu_shell_insert((GtkMenuShell *)(MPARENT( ml )->menu), MMENUITEM( mi ), i + index + 1 ); - g_signal_connect( GTK_OBJECT(MMENUITEM( mi )), "activate", G_CALLBACK(pushMenuList), mi ); - + } + gtk_menu_shell_insert((GtkMenuShell *)(MPARENT( ml )->menu), MMENUITEM( mi ), + i + index + 1 ); + g_signal_connect( GTK_OBJECT(MMENUITEM( mi )), "activate", + G_CALLBACK(pushMenuList), mi ); + gtk_widget_show(MMENUITEM( mi )); } - - if( children ) + + if( children ) { g_list_free( children ); + } } /** * Remove the menu entry identified by a given label. * * \param ml IN menu list - * \param labelStr IN label string of item + * \param labelStr IN label string of item */ void wMenuListDelete( - wMenuList_p ml, - const char * labelStr ) + wMenuList_p ml, + const char * labelStr ) { int i; int found = FALSE; @@ -642,30 +663,31 @@ void wMenuListDelete( // find the placeholder for the list in the menu i = getMlistOrigin( ml, &children ); - + if( i > -1 ) { int origin; - GtkWidget * item; + GtkWidget * item; char * labelStrConverted; - + // starting from the placeholder, find the menu item with the correct text found = FALSE; labelStrConverted = wlibConvertInput( labelStr ); origin = i; - + // get menu item // get label of item // compare items // if identical, leave loop while( i <= origin + ml->count && !found ) { const char * itemLabel; - + item = g_list_nth_data( children, i ); itemLabel = gtk_menu_item_get_label( GTK_MENU_ITEM( item )); - if( !g_utf8_collate (itemLabel, labelStrConverted )) + if( !g_utf8_collate (itemLabel, labelStrConverted )) { found = TRUE; - else + } else { i++; + } } if( found ) { wMenuListItem_p mold; @@ -673,45 +695,47 @@ void wMenuListDelete( mold = g_object_get_data( G_OBJECT( item ), WLISTITEM ); // kill the menu entry gtk_widget_destroy( item ); - // free the data + // free the data free( (void *)mold->labelStr ); free( (void *)mold ); - ml->count--; + ml->count--; } - } - - if( children ) + } + + if( children ) { g_list_free( children ); + } } /** * Get the label and the application data of a specific menu list item * - * \param ml IN menu list + * \param ml IN menu list * \param index IN item within list * \param data OUT application data * \return item label */ -const char * +const char * wMenuListGet( wMenuList_p ml, int index, void ** data ) { int i; GList * children; const char * itemLabel = NULL; - + // check whether index is in range, if not return immediately if ( index >= ml->count || ml->count <= 0 ) { - if (data) + if (data) { *data = NULL; + } return NULL; } - + // find the placeholder for the list in the menu i = getMlistOrigin( ml, &children ); - + if( i > -1 ) { GtkWidget * item; wMenuListItem_p mold; @@ -721,10 +745,11 @@ wMenuListGet( wMenuList_p ml, int index, void ** data ) mold = g_object_get_data( G_OBJECT( GTK_MENU_ITEM( item ) ), WLISTITEM ); *data = mold->data; } - - if( children ) + + if( children ) { g_list_free( children ); - + } + return itemLabel; } @@ -735,16 +760,17 @@ wMenuListGet( wMenuList_p ml, int index, void ** data ) */ void wMenuListClear( - wMenuList_p ml ) + wMenuList_p ml ) { int origin; GList * children; - if (ml->count == 0) + if (ml->count == 0) { return; + } origin = getMlistOrigin( ml, &children ); - + if( origin > -1 ) { int i; @@ -752,23 +778,24 @@ void wMenuListClear( while( i < origin + ml->count ) { wMenuListItem_p mold; GtkWidget * item; - + item = g_list_nth_data( children, i + 1 ); mold = g_object_get_data( G_OBJECT( item ), WLISTITEM ); // kill the menu entry gtk_widget_destroy( item ); - // free the data + // free the data free( (void *)mold->labelStr ); free( (void *)mold ); i++; - } - } + } + } ml->count = 0; gtk_widget_show( MMENUITEM( ml )); - - if( children ) + + if( children ) { g_list_free( children ); + } } /*-----------------------------------------------------------------*/ /** @@ -779,30 +806,31 @@ void wMenuListClear( * \param labelStr IN text for entry * \param acclKey IN acceleratoor key to add * \param set IN initial state - * \param action IN callback function + * \param action IN callback function * \param data IN application data * \return menu entry */ wMenuToggle_p wMenuToggleCreate( - wMenu_p m, - const char * helpStr, - const char * labelStr, - long acclKey, - wBool_t set, - wMenuCallBack_p action, - void * data ) + wMenu_p m, + const char * helpStr, + const char * labelStr, + long acclKey, + wBool_t set, + wMenuCallBack_p action, + void * data ) { wMenuToggle_p mt; - mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, sizeof( struct wMenuToggle_t )); + mt = (wMenuToggle_p)createMenuItem( m, M_TOGGLE, helpStr, labelStr, + sizeof( struct wMenuToggle_t )); setAcclKey( m->parent, m->menu, MMENUITEM( mt ), acclKey ); mt->action = action; mt->data = data; mt->enabled = TRUE; MPARENT( mt ) = m; wMenuToggleSet( mt, set ); - + return mt; } @@ -814,7 +842,7 @@ wMenuToggle_p wMenuToggleCreate( */ wBool_t wMenuToggleGet( - wMenuToggle_p mt ) + wMenuToggle_p mt ) { return mt->set; } @@ -828,11 +856,11 @@ wBool_t wMenuToggleGet( */ wBool_t wMenuToggleSet( - wMenuToggle_p mt, - wBool_t set ) + wMenuToggle_p mt, + wBool_t set ) { wBool_t rc; - if (mt==NULL) return 0; + if (mt==NULL) { return 0; } MRECURSION( mt )++; gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(MMENUITEM( mt )), set ); MRECURSION( mt )--; @@ -845,13 +873,13 @@ wBool_t wMenuToggleSet( * Enable menu entry containing a check box * * \param mi IN menu entry - * \param enable IN new state + * \param enable IN new state * \return */ void wMenuToggleEnable( - wMenuToggle_p mt, - wBool_t enable ) + wMenuToggle_p mt, + wBool_t enable ) { mt->enabled = enable; } @@ -860,29 +888,30 @@ void wMenuToggleEnable( /*-----------------------------------------------------------------*/ /** - * Set the text for a menu + * Set the text for a menu * * \param m IN menu entry * \param labelStr IN new text * \return */ -void wMenuSetLabel( wMenu_p m, const char * labelStr) { +void wMenuSetLabel( wMenu_p m, const char * labelStr) +{ wlibSetLabel( m->widget, m->option, labelStr, &m->labelG, &m->imageG ); } /** - * Signal handler for menu items. Parameters are the GtkWidget as + * Signal handler for menu items. Parameters are the GtkWidget as * expected and the pointer to the MenuListItem * * \param widget IN the GtkWidget - * \param value IN the menu list item + * \param value IN the menu list item * \return */ static gint pushMenu( - GtkWidget * widget, - wMenu_p m ) + GtkWidget * widget, + wMenu_p m ) { gtk_menu_popup( GTK_MENU(m->menu), NULL, NULL, NULL, NULL, 0, 0 ); /* Tell calling code that we have handled this event; the buck @@ -903,12 +932,12 @@ static gint pushMenu( */ wMenu_p wMenuCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option ) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option ) { wMenu_p m; m = wlibAlloc( parent, B_MENU, x, y, labelStr, sizeof( struct wMenu_t ), NULL ); @@ -920,12 +949,12 @@ wMenu_p wMenuCreate( m->widget = gtk_button_new(); g_signal_connect (GTK_OBJECT(m->widget), "clicked", - G_CALLBACK(pushMenu), m ); + G_CALLBACK(pushMenu), m ); m->menu = gtk_menu_new(); wMenuSetLabel( m, labelStr ); - + gtk_fixed_put( GTK_FIXED(parent->widget), m->widget, m->realX, m->realY ); wlibControlGetSize( (wControl_p)m ); if ( m->w < 80 && (m->option&BO_ICON)==0) { @@ -939,27 +968,27 @@ wMenu_p wMenuCreate( } /** - * Add a drop-down menu to the menu bar. + * Add a drop-down menu to the menu bar. * - * \param w IN main window handle + * \param w IN main window handle * \param helpStr IN unused (should be help topic ) - * \param labelStr IN label for the drop-down menu + * \param labelStr IN label for the drop-down menu * \return pointer to the created drop-down menu */ wMenu_p wMenuBarAdd( - wWin_p w, - const char * helpStr, - const char * labelStr ) + wWin_p w, + const char * helpStr, + const char * labelStr ) { wMenu_p m; GtkWidget * menuItem; - + m = wlibAlloc( w, B_MENU, 0, 0, labelStr, sizeof( struct wMenu_t ), NULL ); m->mmtype = MM_BAR; m->realX = 0; m->realY = 0; - + menuItem = gtk_menu_item_new_with_mnemonic( wlibConvertInput(m->labelStr) ); m->menu = gtk_menu_new(); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), m->menu ); @@ -968,10 +997,10 @@ wMenu_p wMenuBarAdd( m->w = 0; m->h = 0; - + /* TODO: why is help not supported here? */ /*gtkAddHelpString( m->panel_item, helpStr );*/ - + return m; } @@ -982,13 +1011,13 @@ wMenu_p wMenuBarAdd( * Create a popup menu (context menu) * * \param w IN parent window - * \param labelStr IN label + * \param labelStr IN label * \return the created menu */ wMenu_p wMenuPopupCreate( - wWin_p w, - const char * labelStr ) + wWin_p w, + const char * labelStr ) { wMenu_p b; b = wlibAlloc( w, B_MENU, 0, 0, labelStr, sizeof *b, NULL ); @@ -999,10 +1028,11 @@ wMenu_p wMenuPopupCreate( b->w = 0; b->h = 0; g_signal_connect( GTK_OBJECT (b->menu), "key_press_event", - G_CALLBACK(catch_shift_ctrl_alt_keys), b); + G_CALLBACK(catch_shift_ctrl_alt_keys), b); g_signal_connect( GTK_OBJECT (b->menu), "key_release_event", - G_CALLBACK (catch_shift_ctrl_alt_keys), b); - gtk_widget_set_events ( GTK_WIDGET(b->menu), GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK ); + G_CALLBACK (catch_shift_ctrl_alt_keys), b); + gtk_widget_set_events ( GTK_WIDGET(b->menu), + GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK ); return b; } @@ -1023,30 +1053,30 @@ void wMenuPopupShow( wMenu_p mp ) /** * ?? Seems to be related to macro / automatic playback functionality * - * \param m IN - * \param func IN - * \param data IN + * \param m IN + * \param func IN + * \param data IN */ void wMenuSetTraceCallBack( - wMenu_p m, - wMenuTraceCallBack_p func, - void * data ) + wMenu_p m, + wMenuTraceCallBack_p func, + void * data ) { m->traceFunc = func; m->traceData = data; } /** - * ??? same as above - * \param m IN - * \param label IN + * ??? same as above + * \param m IN + * \param label IN * \return describe the return value */ wBool_t wMenuAction( - wMenu_p m, - const char * label ) + wMenu_p m, + const char * label ) { wMenuItem_p mi; wMenuToggle_p mt; @@ -1056,10 +1086,11 @@ wBool_t wMenuAction( case M_SEPARATOR: break; case M_PUSH: - if ( ((wMenuPush_p)mi)->enabled == FALSE ) + if ( ((wMenuPush_p)mi)->enabled == FALSE ) { wBeep(); - else + } else { ((wMenuPush_p)mi)->action( ((wMenuPush_p)mi)->data ); + } break; case M_TOGGLE: mt = (wMenuToggle_p)mi; @@ -1076,7 +1107,7 @@ wBool_t wMenuAction( break; default: /*fprintf(stderr, "Oops: wMenuAction\n");*/ - break; + break; } return TRUE; } diff --git a/app/wlib/gtklib/message.c b/app/wlib/gtklib/message.c index 4ecfe6f..6a63434 100644 --- a/app/wlib/gtklib/message.c +++ b/app/wlib/gtklib/message.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -42,10 +42,10 @@ */ struct wMessage_t { - WOBJ_COMMON - GtkWidget * labelWidget; - const char * message; - wWinPix_t labelWidth; + WOBJ_COMMON + GtkWidget * labelWidget; + const char * message; + wWinPix_t labelWidth; }; /** @@ -57,14 +57,14 @@ struct wMessage_t { */ void wMessageSetValue( - wMessage_p b, - const char * arg) + wMessage_p b, + const char * arg) { - if (b->widget == 0) { - abort(); - } + if (b->widget == 0) { + abort(); + } - gtk_label_set_text(GTK_LABEL(b->labelWidget), wlibConvertInput(arg)); + gtk_label_set_text(GTK_LABEL(b->labelWidget), wlibConvertInput(arg)); } /** @@ -76,11 +76,11 @@ void wMessageSetValue( */ void wMessageSetWidth( - wMessage_p b, - wWinPix_t width) + wMessage_p b, + wWinPix_t width) { - b->labelWidth = width; - gtk_widget_set_size_request(b->widget, width, -1); + b->labelWidth = width; + gtk_widget_set_size_request(b->widget, width, -1); } /** @@ -91,47 +91,47 @@ void wMessageSetWidth( */ wWinPix_t wMessageGetHeight( - long flags) + long flags) { - GtkWidget * temp; + GtkWidget * temp; - if (!(flags&COMBOBOX)) { + if (!(flags&COMBOBOX)) { temp = gtk_label_new("Test"); //To get size of text itself - } else { - temp = gtk_combo_box_text_new(); //to get max size of an object in infoBar - } - - if (wMessageSetFont(flags)) { - GtkStyle *style; - PangoFontDescription *fontDesc; - int fontSize; - /* get the current font descriptor */ - style = gtk_widget_get_style(temp); - fontDesc = style->font_desc; - /* get the current font size */ - fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); - - /* calculate the new font size */ - if (flags & BM_LARGE) { - pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); - } else { - pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); - } - - /* set the new font size */ - gtk_widget_modify_font(temp, fontDesc); - } - - if (flags&1L) { - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(temp),"Test"); - } - - GtkRequisition temp_requisition; - gtk_widget_size_request(temp,&temp_requisition); - g_object_ref_sink(temp); - gtk_widget_destroy(temp); - g_object_unref(temp); - return temp_requisition.height; + } else { + temp = gtk_combo_box_text_new(); //to get max size of an object in infoBar + } + + if (wMessageSetFont(flags)) { + GtkStyle *style; + PangoFontDescription *fontDesc; + int fontSize; + /* get the current font descriptor */ + style = gtk_widget_get_style(temp); + fontDesc = style->font_desc; + /* get the current font size */ + fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); + + /* calculate the new font size */ + if (flags & BM_LARGE) { + pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); + } else { + pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); + } + + /* set the new font size */ + gtk_widget_modify_font(temp, fontDesc); + } + + if (flags&1L) { + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(temp),"Test"); + } + + GtkRequisition temp_requisition; + gtk_widget_size_request(temp,&temp_requisition); + g_object_ref_sink(temp); + gtk_widget_destroy(temp); + g_object_unref(temp); + return temp_requisition.height; } /** @@ -148,61 +148,61 @@ wWinPix_t wMessageGetHeight( */ wMessage_p wMessageCreateEx( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * labelStr, - wWinPix_t width, - const char *message, - long flags) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * labelStr, + wWinPix_t width, + const char *message, + long flags) { - wMessage_p b; - GtkRequisition requisition; - GtkStyle *style; - PangoFontDescription *fontDesc; - int fontSize; - b = (wMessage_p)wlibAlloc(parent, B_MESSAGE, x, y, NULL, sizeof *b, NULL); - wlibComputePos((wControl_p)b); - b->message = message; - b->labelWidth = width; - b->labelWidget = gtk_label_new(message?wlibConvertInput(message):""); - - /* do we need to set a special font? */ - if (wMessageSetFont(flags)) { - /* get the current font descriptor */ - style = gtk_widget_get_style(GTK_WIDGET(b->labelWidget)); - fontDesc = style->font_desc; - /* get the current font size */ - fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); - - /* calculate the new font size */ - if (flags & BM_LARGE) { - pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); - } else { - pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); - } - - /* set the new font size */ - gtk_widget_modify_font((GtkWidget *)b->labelWidget, fontDesc); - } - - b->widget = gtk_fixed_new(); - gtk_widget_size_request(GTK_WIDGET(b->labelWidget), &requisition); - gtk_container_add(GTK_CONTAINER(b->widget), b->labelWidget); - gtk_widget_set_size_request(b->widget, width?width:requisition.width, - requisition.height); - wlibControlGetSize((wControl_p)b); - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - gtk_widget_show(b->widget); - gtk_widget_show(b->labelWidget); - wlibAddButton((wControl_p)b); - - /* Reset font size to normal */ - if (wMessageSetFont(flags)) { - pango_font_description_set_size(fontDesc, fontSize * PANGO_SCALE); - } - - return b; + wMessage_p b; + GtkRequisition requisition; + GtkStyle *style; + PangoFontDescription *fontDesc; + int fontSize; + b = (wMessage_p)wlibAlloc(parent, B_MESSAGE, x, y, NULL, sizeof *b, NULL); + wlibComputePos((wControl_p)b); + b->message = message; + b->labelWidth = width; + b->labelWidget = gtk_label_new(message?wlibConvertInput(message):""); + + /* do we need to set a special font? */ + if (wMessageSetFont(flags)) { + /* get the current font descriptor */ + style = gtk_widget_get_style(GTK_WIDGET(b->labelWidget)); + fontDesc = style->font_desc; + /* get the current font size */ + fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); + + /* calculate the new font size */ + if (flags & BM_LARGE) { + pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); + } else { + pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); + } + + /* set the new font size */ + gtk_widget_modify_font((GtkWidget *)b->labelWidget, fontDesc); + } + + b->widget = gtk_fixed_new(); + gtk_widget_size_request(GTK_WIDGET(b->labelWidget), &requisition); + gtk_container_add(GTK_CONTAINER(b->widget), b->labelWidget); + gtk_widget_set_size_request(b->widget, width?width:requisition.width, + requisition.height); + wlibControlGetSize((wControl_p)b); + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + gtk_widget_show(b->widget); + gtk_widget_show(b->labelWidget); + wlibAddButton((wControl_p)b); + + /* Reset font size to normal */ + if (wMessageSetFont(flags)) { + pango_font_description_set_size(fontDesc, fontSize * PANGO_SCALE); + } + + return b; } /** @@ -215,10 +215,10 @@ wMessage_p wMessageCreateEx( wWinPix_t wMessageGetWidth(const char *testString) { - GtkWidget *entry; - GtkRequisition requisition; +// GtkWidget *entry; +// GtkRequisition requisition; - return( wLabelWidth(testString)); + return( wLabelWidth(testString)); // entry = gtk_entry_new(); // g_object_ref_sink(entry); // diff --git a/app/wlib/gtklib/notice.c b/app/wlib/gtklib/notice.c index 0134b4f..5ab352b 100644 --- a/app/wlib/gtklib/notice.c +++ b/app/wlib/gtklib/notice.c @@ -41,9 +41,9 @@ static char * wlibChgMnemonic(char *label); typedef struct { - GtkWidget * win; - GtkWidget * label; - GtkWidget * butt[3]; + GtkWidget * win; + GtkWidget * label; + GtkWidget * butt[3]; } notice_win; static notice_win noticeW; static long noticeValue; @@ -55,17 +55,17 @@ static long noticeValue; */ static void doNotice( - GtkWidget * widget, - long value) + GtkWidget * widget, + long value) { - if (value != 2) { - // event not from from closing the window but from a button press - // Close the Notice dialog - gtk_widget_destroy(noticeW.win); - // Remember the button - noticeValue = value; - } - wlibDoModal(NULL, FALSE); + if (value != 2) { + // event not from from closing the window but from a button press + // Close the Notice dialog + gtk_widget_destroy(noticeW.win); + // Remember the button + noticeValue = value; + } + wlibDoModal(NULL, FALSE); } /** @@ -84,48 +84,48 @@ int wNoticeEx(int type, const char * no) { - int res; - unsigned flag; - char *headline; - GtkWidget *dialog; - GtkWindow *parent = NULL; + int res; + unsigned flag = GTK_MESSAGE_ERROR; + char *headline = _("Error"); + GtkWidget *dialog; + GtkWindow *parent = NULL; - switch (type) { - case NT_INFORMATION: - flag = GTK_MESSAGE_INFO; - headline = _("Information"); - break; + switch (type) { + case NT_INFORMATION: + flag = GTK_MESSAGE_INFO; + headline = _("Information"); + break; - case NT_WARNING: - flag = GTK_MESSAGE_WARNING; - headline = _("Warning"); - break; + case NT_WARNING: + flag = GTK_MESSAGE_WARNING; + headline = _("Warning"); + break; - case NT_ERROR: - flag = GTK_MESSAGE_ERROR; - headline = _("Error"); - break; - } + case NT_ERROR: + flag = GTK_MESSAGE_ERROR; + headline = _("Error"); + break; + } - if (gtkMainW) { - parent = GTK_WINDOW(gtkMainW->gtkwin); - } + if (gtkMainW) { + parent = GTK_WINDOW(gtkMainW->gtkwin); + } - wDestroySplash(); + wDestroySplash(); - dialog = gtk_message_dialog_new(parent, - GTK_DIALOG_DESTROY_WITH_PARENT, - flag, - ((no==NULL)?GTK_BUTTONS_OK:GTK_BUTTONS_YES_NO), - "%s", msg); - gtk_window_set_title(GTK_WINDOW(dialog), headline); + dialog = gtk_message_dialog_new(parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + flag, + ((no==NULL)?GTK_BUTTONS_OK:GTK_BUTTONS_YES_NO), + "%s", msg); + gtk_window_set_title(GTK_WINDOW(dialog), headline); - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); - res = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + res = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); - return res == GTK_RESPONSE_OK || res == GTK_RESPONSE_YES; + return res == GTK_RESPONSE_OK || res == GTK_RESPONSE_YES; } @@ -141,11 +141,11 @@ int wNoticeEx(int type, */ int wNotice( - const char * msg, /* Message */ - const char * yes, /* First button label */ - const char * no) /* Second label (or 'NULL') */ + const char * msg, /* Message */ + const char * yes, /* First button label */ + const char * no) /* Second label (or 'NULL') */ { - return wNotice3(msg, yes, no, NULL); + return wNotice3(msg, yes, no, NULL); } /** \brief Popup a notice box with three buttons. @@ -167,121 +167,121 @@ int wNotice( */ int wNotice3( - const char * msg, /* Message */ - const char * affirmative, /* First button label */ - const char * cancel, /* Second label (or 'NULL') */ - const char * alternate) + const char * msg, /* Message */ + const char * affirmative, /* First button label */ + const char * cancel, /* Second label (or 'NULL') */ + const char * alternate) { - notice_win *nw; - GtkWidget * vbox; - GtkWidget * hbox; - GtkWidget * hbox1; - GtkWidget * image; - nw = ¬iceW; - - char *aff = NULL; - char *can = NULL; - char *alt = NULL; - - wDestroySplash(); - - nw->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_window_set_position(GTK_WINDOW(nw->win), GTK_WIN_POS_CENTER); - gtk_container_set_border_width(GTK_CONTAINER(nw->win), 0); - gtk_window_set_resizable(GTK_WINDOW(nw->win), FALSE); - gtk_window_set_modal(GTK_WINDOW(nw->win), TRUE); - gtk_window_set_type_hint(GTK_WINDOW(nw->win), GDK_WINDOW_TYPE_HINT_DIALOG); - - vbox = gtk_vbox_new(FALSE, 12); - gtk_widget_show(vbox); - gtk_container_add(GTK_CONTAINER(nw->win), vbox); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); - - hbox = gtk_hbox_new(FALSE, 12); - gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show(hbox); - - image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING, - GTK_ICON_SIZE_DIALOG); - gtk_widget_show(image); - gtk_box_pack_start(GTK_BOX(hbox), image, TRUE, TRUE, 0); - gtk_misc_set_alignment(GTK_MISC(image), 0, 0); - - /* create the text label, allow GTK to wrap and allow for markup (for future enhancements) */ - nw->label = gtk_label_new(msg); - gtk_widget_show(nw->label); - gtk_box_pack_end(GTK_BOX(hbox), nw->label, TRUE, TRUE, 0); - gtk_label_set_use_markup(GTK_LABEL(nw->label), FALSE); - gtk_label_set_line_wrap(GTK_LABEL(nw->label), TRUE); - gtk_misc_set_alignment(GTK_MISC(nw->label), 0, 0); - - /* this hbox will include the button bar */ - hbox1 = gtk_hbox_new(TRUE, 0); - gtk_widget_show(hbox1); - gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, TRUE, 0); - - /* add the respective buttons */ - aff = wlibChgMnemonic((char *) affirmative); - nw->butt[ 0 ] = gtk_button_new_with_mnemonic(aff); - gtk_widget_show(nw->butt[ 0 ]); - gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 0 ], TRUE, TRUE, 0); - gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 0 ]), 3); - g_signal_connect(GTK_OBJECT(nw->butt[0]), "clicked", G_CALLBACK(doNotice), - (void*)1); - gtk_widget_set_can_default(nw->butt[ 0 ], TRUE); - - if (cancel) { - can = wlibChgMnemonic((char *) cancel); - nw->butt[ 1 ] = gtk_button_new_with_mnemonic(can); - gtk_widget_show(nw->butt[ 1 ]); - gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 1 ], TRUE, TRUE, 0); - gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 1 ]), 3); - g_signal_connect(GTK_OBJECT(nw->butt[1]), "clicked", G_CALLBACK(doNotice), - (void*)0); - gtk_widget_set_can_default(nw->butt[ 1 ], TRUE); - - if (alternate) { - alt = wlibChgMnemonic((char *) alternate); - nw->butt[ 2 ] = gtk_button_new_with_mnemonic(alt); - gtk_widget_show(nw->butt[ 2 ]); - gtk_box_pack_start(GTK_BOX(hbox1), nw->butt[ 2 ], TRUE, TRUE, 0); - gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 2 ]), 3); - g_signal_connect(GTK_OBJECT(nw->butt[2]), "clicked", G_CALLBACK(doNotice), - (void*)-1); - gtk_widget_set_can_default(nw->butt[ 2 ], TRUE); - } - } - - g_signal_connect(GTK_WINDOW(nw->win), - "destroy", G_CALLBACK(doNotice), (void*)2); - - gtk_widget_grab_default(nw->butt[ 0 ]); - gtk_widget_grab_focus(nw->butt[ 0 ]); - - gtk_widget_show(nw->win); - - if (gtkMainW) { - gtk_window_set_transient_for(GTK_WINDOW(nw->win), GTK_WINDOW(gtkMainW->gtkwin)); - /* gdk_window_set_group( nw->win->window, gtkMainW->gtkwin->window ); */ - } - - noticeValue = 0; // Default: Cancel - wlibDoModal(NULL, TRUE); - - if (aff) { - free(aff); - } - - if (can) { - free(can); - } - - if (alt) { - free(alt); - } - - return noticeValue; + notice_win *nw; + GtkWidget * vbox; + GtkWidget * hbox; + GtkWidget * hbox1; + GtkWidget * image; + nw = ¬iceW; + + char *aff = NULL; + char *can = NULL; + char *alt = NULL; + + wDestroySplash(); + + nw->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_window_set_position(GTK_WINDOW(nw->win), GTK_WIN_POS_CENTER); + gtk_container_set_border_width(GTK_CONTAINER(nw->win), 0); + gtk_window_set_resizable(GTK_WINDOW(nw->win), FALSE); + gtk_window_set_modal(GTK_WINDOW(nw->win), TRUE); + gtk_window_set_type_hint(GTK_WINDOW(nw->win), GDK_WINDOW_TYPE_HINT_DIALOG); + + vbox = gtk_vbox_new(FALSE, 12); + gtk_widget_show(vbox); + gtk_container_add(GTK_CONTAINER(nw->win), vbox); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); + + hbox = gtk_hbox_new(FALSE, 12); + gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show(hbox); + + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING, + GTK_ICON_SIZE_DIALOG); + gtk_widget_show(image); + gtk_box_pack_start(GTK_BOX(hbox), image, TRUE, TRUE, 0); + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + + /* create the text label, allow GTK to wrap and allow for markup (for future enhancements) */ + nw->label = gtk_label_new(msg); + gtk_widget_show(nw->label); + gtk_box_pack_end(GTK_BOX(hbox), nw->label, TRUE, TRUE, 0); + gtk_label_set_use_markup(GTK_LABEL(nw->label), FALSE); + gtk_label_set_line_wrap(GTK_LABEL(nw->label), TRUE); + gtk_misc_set_alignment(GTK_MISC(nw->label), 0, 0); + + /* this hbox will include the button bar */ + hbox1 = gtk_hbox_new(TRUE, 0); + gtk_widget_show(hbox1); + gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, TRUE, 0); + + /* add the respective buttons */ + aff = wlibChgMnemonic((char *) affirmative); + nw->butt[ 0 ] = gtk_button_new_with_mnemonic(aff); + gtk_widget_show(nw->butt[ 0 ]); + gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 0 ], TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 0 ]), 3); + g_signal_connect(GTK_OBJECT(nw->butt[0]), "clicked", G_CALLBACK(doNotice), + (void*)1); + gtk_widget_set_can_default(nw->butt[ 0 ], TRUE); + + if (cancel) { + can = wlibChgMnemonic((char *) cancel); + nw->butt[ 1 ] = gtk_button_new_with_mnemonic(can); + gtk_widget_show(nw->butt[ 1 ]); + gtk_box_pack_end(GTK_BOX(hbox1), nw->butt[ 1 ], TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 1 ]), 3); + g_signal_connect(GTK_OBJECT(nw->butt[1]), "clicked", G_CALLBACK(doNotice), + (void*)0); + gtk_widget_set_can_default(nw->butt[ 1 ], TRUE); + + if (alternate) { + alt = wlibChgMnemonic((char *) alternate); + nw->butt[ 2 ] = gtk_button_new_with_mnemonic(alt); + gtk_widget_show(nw->butt[ 2 ]); + gtk_box_pack_start(GTK_BOX(hbox1), nw->butt[ 2 ], TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(nw->butt[ 2 ]), 3); + g_signal_connect(GTK_OBJECT(nw->butt[2]), "clicked", G_CALLBACK(doNotice), + (void*)-1); + gtk_widget_set_can_default(nw->butt[ 2 ], TRUE); + } + } + + g_signal_connect(GTK_WINDOW(nw->win), + "destroy", G_CALLBACK(doNotice), (void*)2); + + gtk_widget_grab_default(nw->butt[ 0 ]); + gtk_widget_grab_focus(nw->butt[ 0 ]); + + gtk_widget_show(nw->win); + + if (gtkMainW) { + gtk_window_set_transient_for(GTK_WINDOW(nw->win), GTK_WINDOW(gtkMainW->gtkwin)); + /* gdk_window_set_group( nw->win->window, gtkMainW->gtkwin->window ); */ + } + + noticeValue = 0; // Default: Cancel + wlibDoModal(NULL, TRUE); + + if (aff) { + free(aff); + } + + if (can) { + free(can); + } + + if (alt) { + free(alt); + } + + return noticeValue; } /* \brief Convert label string from Windows mnemonic to GTK @@ -295,18 +295,18 @@ int wNotice3( static char * wlibChgMnemonic(char *label) { - char *ptr; - char *cp; + char *ptr; + char *cp; - cp = strdup(label); + cp = strdup(label); - ptr = strchr(cp, '&'); + ptr = strchr(cp, '&'); - if (ptr) { - *ptr = '_'; - } + if (ptr) { + *ptr = '_'; + } - return (cp); + return (cp); } diff --git a/app/wlib/gtklib/opendocument.c b/app/wlib/gtklib/opendocument.c index c03f9cb..5c057ec 100644 --- a/app/wlib/gtklib/opendocument.c +++ b/app/wlib/gtklib/opendocument.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -55,24 +55,24 @@ static char * ExtendPath(void) { - char *path = strdup(getenv("PATH")); - DynString newPath; - DynStringMalloc(&newPath, 16); + char *path = strdup(getenv("PATH")); + DynString newPath; + DynStringMalloc(&newPath, 16); - // append XTrackCAD's directory to the path as a fallback - DynStringCatCStrs(&newPath, - path, - ":", - wGetAppLibDir(), - NULL); + // append XTrackCAD's directory to the path as a fallback + DynStringCatCStrs(&newPath, + path, + ":", + wGetAppLibDir(), + NULL); - setenv("PATH", - DynStringToCStr(&newPath), - TRUE); + setenv("PATH", + DynStringToCStr(&newPath), + TRUE); - DynStringFree(&newPath); + DynStringFree(&newPath); - return (path); + return (path); } /** @@ -85,33 +85,33 @@ ExtendPath(void) unsigned wOpenFileExternal(char * filename) { - int rc; - DynString commandLine; - char *currentPath; - - assert(filename != NULL); - assert(strlen(filename)); - - currentPath = ExtendPath(); - - DynStringMalloc(&commandLine, 16); - DynStringCatCStrs(&commandLine, - DEFAULTOPENCOMMAND, - " \"", - filename, - "\"", - NULL); - - // the command should be found via the PATH - rc = system(DynStringToCStr(&commandLine)); - - // restore the PATH - setenv("PATH", - currentPath, - TRUE); - - free(currentPath); - DynStringFree(&commandLine); - - return(rc==0); + int rc; + DynString commandLine; + char *currentPath; + + assert(filename != NULL); + assert(strlen(filename)); + + currentPath = ExtendPath(); + + DynStringMalloc(&commandLine, 16); + DynStringCatCStrs(&commandLine, + DEFAULTOPENCOMMAND, + " \"", + filename, + "\"", + NULL); + + // the command should be found via the PATH + rc = system(DynStringToCStr(&commandLine)); + + // restore the PATH + setenv("PATH", + currentPath, + TRUE); + + free(currentPath); + DynStringFree(&commandLine); + + return(rc==0); } diff --git a/app/wlib/gtklib/osxhelp.c b/app/wlib/gtklib/osxhelp.c index 2fed375..b508961 100644 --- a/app/wlib/gtklib/osxhelp.c +++ b/app/wlib/gtklib/osxhelp.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -51,15 +51,15 @@ extern wBool_t CheckHelpTopicExists(const char *); static char *ChildProgramFile(char *parentProgram) { - char *startOfFilename; - char *childProgram; + char *startOfFilename; + char *childProgram; - childProgram = malloc(strlen(parentProgram)+ sizeof(HELPERPROGRAM) + 1); - strcpy(childProgram, parentProgram); - startOfFilename = strrchr(childProgram, '/'); - strcpy(startOfFilename + 1, HELPERPROGRAM); + childProgram = malloc(strlen(parentProgram)+ sizeof(HELPERPROGRAM) + 1); + strcpy(childProgram, parentProgram); + startOfFilename = strrchr(childProgram, '/'); + strcpy(startOfFilename + 1, HELPERPROGRAM); - return (childProgram); + return (childProgram); } @@ -71,92 +71,93 @@ char *ChildProgramFile(char *parentProgram) void wHelp(const char * topic) { - pid_t newPid; - int status; - const char html[] = ".html"; - static char *directory; /**< base directory for HTML files */ - char * htmlFile; - - struct { - int length; - char *page; - } buffer; - - if (!CheckHelpTopicExists(topic)) return; - - // check whether child already exists - if (pidOfChild != 0) { - if (waitpid(pidOfChild, &status, WNOHANG) < 0) { - // child exited -> clean up - close(handleOfPipe); - unlink(HELPCOMMANDPIPE); - handleOfPipe = 0; - pidOfChild = 0; // child exited - } - } - - // (re)start child - if (pidOfChild == 0) { - unlink(HELPCOMMANDPIPE); - int rc = mkfifo(HELPCOMMANDPIPE, 0666); - newPid = fork(); /* New process starts here */ - - if (newPid > 0) { - pidOfChild = newPid; - } else if (newPid == 0) { + pid_t newPid; + int status; + const char html[] = ".html"; + static char *directory; /**< base directory for HTML files */ + char * htmlFile; + + struct { + int length; + char *page; + } buffer; + + if (!CheckHelpTopicExists(topic)) { return; } + + // check whether child already exists + if (pidOfChild != 0) { + if (waitpid(pidOfChild, &status, WNOHANG) < 0) { + // child exited -> clean up + close(handleOfPipe); + unlink(HELPCOMMANDPIPE); + handleOfPipe = 0; + pidOfChild = 0; // child exited + } + } + + // (re)start child + if (pidOfChild == 0) { + unlink(HELPCOMMANDPIPE); + int rc = mkfifo(HELPCOMMANDPIPE, 0666); + newPid = fork(); /* New process starts here */ + + if (newPid > 0) { + pidOfChild = newPid; + } else if (newPid == 0) { char *child = ChildProgramFile(wExecutableName); - - if (execlp(child, child, NULL) < 0) { /* never normally returns */ - exit(8); - } - - free(child); - } else { /* -1 signifies fork failure */ - pidOfChild = 0; - return; - } - } - - buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1); - - if (!buffer.page) { - return; - } - - strcpy(buffer.page, topic); - strcat(buffer.page, html); - buffer.length = strlen(buffer.page); - - if (buffer.length>255) { - printf("Help Topic too long %s", buffer.page); - return; - } - - if (!handleOfPipe) { + + if (execlp(child, child, NULL) < 0) { /* never normally returns */ + exit(8); + } + + free(child); + } else { /* -1 signifies fork failure */ + pidOfChild = 0; + return; + } + } + + buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1); + + if (!buffer.page) { + return; + } + + strcpy(buffer.page, topic); + strcat(buffer.page, html); + buffer.length = strlen(buffer.page); + + if (buffer.length>255) { + printf("Help Topic too long %s", buffer.page); + return; + } + + if (!handleOfPipe) { handleOfPipe = open(HELPCOMMANDPIPE, O_WRONLY); if (handleOfPipe < 0) { - if (pidOfChild) - kill(pidOfChild, SIGKILL); /* tidy up on next call */ + if (pidOfChild) { + kill(pidOfChild, SIGKILL); /* tidy up on next call */ + } handleOfPipe = 0; return; } } - int written = 0; - int towrite = sizeof(int); + int written = 0; + int towrite = sizeof(int); - while (written < towrite){ - written += write(handleOfPipe, &buffer.length, sizeof(int)); - } - written =0; - towrite = strlen(buffer.page); - while (written < towrite){ - written += write(handleOfPipe, buffer.page+written, towrite-written); - } + while (written < towrite) { + written += write(handleOfPipe, &buffer.length, sizeof(int)); + } + written =0; + towrite = strlen(buffer.page); + while (written < towrite) { + written += write(handleOfPipe, buffer.page+written, towrite-written); + } - fsync(handleOfPipe); + fsync(handleOfPipe); - free(buffer.page); + free(buffer.page); } diff --git a/app/wlib/gtklib/pixbuf.c b/app/wlib/gtklib/pixbuf.c index a76e7f1..0d6e8b7 100644 --- a/app/wlib/gtklib/pixbuf.c +++ b/app/wlib/gtklib/pixbuf.c @@ -45,55 +45,55 @@ */ GdkPixbuf* wlibMakePixbuf( - wIcon_p ip) + wIcon_p ip) { - GdkPixbuf * pixbuf; - char line0[40]; - char line2[40]; - - assert(ip != NULL); - - if (ip->gtkIconType == gtkIcon_pixmap) { - pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)ip->bits); - } else { - const char * bits; - long rgb; - int row,col,wb; - char ** pixmapData; - - wb = (ip->w+7)/8; - pixmapData = (char**)g_malloc((3+ip->h) * sizeof *pixmapData); - pixmapData[0] = line0; - rgb = wDrawGetRGB(ip->color); - sprintf(line0, " %ld %ld 2 1", ip->w, ip->h); - sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb>>16)&0xFF, (rgb>>8)&0xFF, - rgb&0xFF); - pixmapData[1] = ". c None s None"; - pixmapData[2] = line2; - bits = ip->bits; - - for (row = 0; row<ip->h; row++) { - pixmapData[row+3] = (char*)g_malloc((ip->w+1) * sizeof **pixmapData); - - for (col = 0; col<ip->w; col++) { - if (bits[ row*wb+(col>>3) ] & (1<<(col&07))) { - pixmapData[row+3][col] = '#'; - } else { - pixmapData[row+3][col] = '.'; - } - } - - pixmapData[row+3][ip->w] = 0; - } - - pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData); - - for (row = 0; row<ip->h; row++) { - g_free(pixmapData[row+3]); - } - } - - return pixbuf; + GdkPixbuf * pixbuf; + char line0[40]; + char line2[40]; + + assert(ip != NULL); + + if (ip->gtkIconType == gtkIcon_pixmap) { + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)ip->bits); + } else { + const char * bits; + long rgb; + int row,col,wb; + char ** pixmapData; + + wb = (ip->w+7)/8; + pixmapData = (char**)g_malloc((3+ip->h) * sizeof *pixmapData); + pixmapData[0] = line0; + rgb = wDrawGetRGB(ip->color); + sprintf(line0, " %ld %ld 2 1", ip->w, ip->h); + sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb>>16)&0xFF, (rgb>>8)&0xFF, + rgb&0xFF); + pixmapData[1] = ". c None s None"; + pixmapData[2] = line2; + bits = ip->bits; + + for (row = 0; row<ip->h; row++) { + pixmapData[row+3] = (char*)g_malloc((ip->w+1) * sizeof **pixmapData); + + for (col = 0; col<ip->w; col++) { + if (bits[ row*wb+(col>>3) ] & (1<<(col&07))) { + pixmapData[row+3][col] = '#'; + } else { + pixmapData[row+3][col] = '.'; + } + } + + pixmapData[row+3][ip->w] = 0; + } + + pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData); + + for (row = 0; row<ip->h; row++) { + g_free(pixmapData[row+3]); + } + } + + return pixbuf; } diff --git a/app/wlib/gtklib/print.c b/app/wlib/gtklib/print.c index 7f8f49e..609efa9 100644 --- a/app/wlib/gtklib/print.c +++ b/app/wlib/gtklib/print.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdlib.h> @@ -79,8 +79,7 @@ extern struct wDraw_t psPrint_d; static wBool_t printContinue; /**< control print job, FALSE for cancelling */ static wIndex_t pageCount; /**< unused, could be used for progress indicator */ -static wIndex_t -totalPageCount; /**< unused, could be used for progress indicator */ +//static wIndex_t totalPageCount; /**< unused, could be used for progress indicator */ static double paperWidth; /**< physical paper width */ static double paperHeight; /**< physical paper height */ @@ -92,7 +91,7 @@ static double bBorder; /**< bottom margin */ static double scale_adjust = 1.0; static double scale_text = 1.0; -static long printFormat = PRINT_LANDSCAPE; +//static long printFormat = PRINT_LANDSCAPE; /***************************************************************************** * @@ -112,61 +111,61 @@ static void WlibGetPaperSize(void); void WlibApplySettings(GtkPrintOperation *op) { - gchar *filename; - GError *err = NULL; - GtkWidget *dialog; - - filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL); - - if (!(settings = gtk_print_settings_new_from_file(filename, &err))) { - if (err->code != G_FILE_ERROR_NOENT) { - // ignore file not found error as defaults will be used - dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s",err->message); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - } else { - // create default print settings - settings = gtk_print_settings_new(); - } - g_error_free(err); - } - - g_free(filename); - - if (settings && op) { - gtk_print_operation_set_print_settings(op, settings); - } - - err = NULL; - filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL); - - if (!(page_setup = gtk_page_setup_new_from_file(filename, &err))) { - // ignore file not found error as defaults will be used - if (err->code != G_FILE_ERROR_NOENT) { - dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s",err->message); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - } else { - page_setup = gtk_page_setup_new(); - } - - g_error_free(err); - } else { - // on success get the paper dimensions - WlibGetPaperSize(); - } - - g_free(filename); - - if (page_setup && op) { - gtk_print_operation_set_default_page_setup(op, page_setup); - } + gchar *filename; + GError *err = NULL; + GtkWidget *dialog; + + filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL); + + if (!(settings = gtk_print_settings_new_from_file(filename, &err))) { + if (err->code != G_FILE_ERROR_NOENT) { + // ignore file not found error as defaults will be used + dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s",err->message); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + } else { + // create default print settings + settings = gtk_print_settings_new(); + } + g_error_free(err); + } + + g_free(filename); + + if (settings && op) { + gtk_print_operation_set_print_settings(op, settings); + } + + err = NULL; + filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL); + + if (!(page_setup = gtk_page_setup_new_from_file(filename, &err))) { + // ignore file not found error as defaults will be used + if (err->code != G_FILE_ERROR_NOENT) { + dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s",err->message); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + } else { + page_setup = gtk_page_setup_new(); + } + + g_error_free(err); + } else { + // on success get the paper dimensions + WlibGetPaperSize(); + } + + g_free(filename); + + if (page_setup && op) { + gtk_print_operation_set_default_page_setup(op, page_setup); + } } @@ -180,55 +179,55 @@ WlibApplySettings(GtkPrintOperation *op) void WlibSaveSettings(GtkPrintOperation *op) { - GError *err = NULL; - gchar *filename; - GtkWidget *dialog; + GError *err = NULL; + gchar *filename; + GtkWidget *dialog; - if (op) { - if (settings != NULL) { - g_object_unref(settings); - } + if (op) { + if (settings != NULL) { + g_object_unref(settings); + } - settings = g_object_ref(gtk_print_operation_get_print_settings(op)); - } + settings = g_object_ref(gtk_print_operation_get_print_settings(op)); + } - filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL); + filename = g_build_filename(wGetAppWorkDir(), PRINTSETTINGS, NULL); - if (!gtk_print_settings_to_file(settings, filename, &err)) { - dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s",err->message); + if (!gtk_print_settings_to_file(settings, filename, &err)) { + dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s",err->message); - g_error_free(err); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - } + g_error_free(err); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + } - g_free(filename); + g_free(filename); - if (op) { - if (page_setup != NULL) { - g_object_unref(page_setup); - } + if (op) { + if (page_setup != NULL) { + g_object_unref(page_setup); + } - page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(op)); - } + page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(op)); + } - filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL); + filename = g_build_filename(wGetAppWorkDir(), PAGESETTINGS, NULL); - if (!gtk_page_setup_to_file(page_setup, filename, &err)) { - dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s",err->message); + if (!gtk_page_setup_to_file(page_setup, filename, &err)) { + dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s",err->message); - g_error_free(err); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - } + g_error_free(err); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + } - g_free(filename); + g_free(filename); } @@ -241,30 +240,32 @@ WlibSaveSettings(GtkPrintOperation *op) void wPrintSetup(wPrintSetupCallBack_p callback) { - GtkPageSetup *new_page_setup; - gchar *filename; - GError *err; - GtkWidget *dialog; + GtkPageSetup *new_page_setup; +// gchar *filename; +// GError *err; +// GtkWidget *dialog; - if ( !settings ) - WlibApplySettings(NULL); + if ( !settings ) { + WlibApplySettings(NULL); + } - new_page_setup = gtk_print_run_page_setup_dialog(GTK_WINDOW(gtkMainW->gtkwin), - page_setup, settings); + new_page_setup = gtk_print_run_page_setup_dialog(GTK_WINDOW(gtkMainW->gtkwin), + page_setup, settings); - if (page_setup && (page_setup != new_page_setup)) { //Can be the same if no mods... - g_object_unref(page_setup); - } + if (page_setup + && (page_setup != new_page_setup)) { //Can be the same if no mods... + g_object_unref(page_setup); + } - page_setup = new_page_setup; + page_setup = new_page_setup; - WlibGetPaperSize(); - WlibSaveSettings(NULL); + WlibGetPaperSize(); + WlibSaveSettings(NULL); } /***************************************************************************** * - * + * * */ @@ -272,7 +273,7 @@ void wPrintSetup(wPrintSetupCallBack_p callback) static GtkPrinter * pDefaultPrinter = NULL; gboolean isDefaultPrinter( GtkPrinter * printer, gpointer data ) { -const char * pPrinterName = gtk_printer_get_name( printer ); +//const char * pPrinterName = gtk_printer_get_name( printer ); if ( gtk_printer_is_default( printer ) ) { pDefaultPrinter = printer; return TRUE; @@ -284,18 +285,19 @@ static void getDefaultPrinter() { pDefaultPrinter = NULL; gtk_enumerate_printers( isDefaultPrinter, NULL, NULL, TRUE ); -} +} const char * wPrintGetName() { static char sPrinterName[100]; WlibApplySettings( NULL ); - const char * pPrinterName = - gtk_print_settings_get( settings, "format-for-printer" ); + const char * pPrinterName = + gtk_print_settings_get( settings, "format-for-printer" ); if ( pPrinterName == NULL ) { getDefaultPrinter(); - if ( pDefaultPrinter ) + if ( pDefaultPrinter ) { pPrinterName = gtk_printer_get_name( pDefaultPrinter ); + } } if ( pPrinterName == NULL ) { pPrinterName = ""; @@ -303,8 +305,9 @@ const char * wPrintGetName() strncpy (sPrinterName, pPrinterName, sizeof sPrinterName - 1 ); sPrinterName[ sizeof sPrinterName - 1 ] = '\0'; for ( char * cp = sPrinterName; *cp; cp++ ) - if ( *cp == ':' ) + if ( *cp == ':' ) { *cp = '-'; + } return sPrinterName; } /***************************************************************************** @@ -325,71 +328,65 @@ const char * wPrintGetName() static void setLineType( - double lineWidth, - wDrawLineType_e lineType, - wDrawOpts opts) + double lineWidth, + wDrawLineType_e lineType, + wDrawOpts opts) { - cairo_t *cr = psPrint_d.printContext; - - double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - - if (lineWidth < 0.0) { - lineWidth = P2I(-lineWidth)*2.0/scale_adjust; - } - - // make sure that there is a minimum line width used - if (lineWidth <= 0.09) { - lineWidth = 0.1/scale_adjust; - } - - cairo_set_line_width(cr, lineWidth); - switch(lineType) { - case wDrawLineDot: - { - double dashes[] = { 1, 2 , 1, 2}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cr, dashes, len_dashes, 0.0); - break; - } - case wDrawLineDash: - { - double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cr, dashes, len_dashes, 0.0); - break; - } - case wDrawLineDashDot: - { - double dashes[] = { 3, 2, 1, 2}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cr, dashes, len_dashes, 0.0); - break; - } - case wDrawLineDashDotDot: - { - double dashes[] = { 3, 2, 1, 2, 1, 2}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cr, dashes, len_dashes, 0.0); - break; - } - case wDrawLineCenter: - { - double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cr, dashes, len_dashes, 0.0); - break; - } - case wDrawLinePhantom: - { - double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3, DASH_LENGTH, 3}; - static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); - cairo_set_dash(cr, dashes, len_dashes, 0.0); - break; - } - default: - cairo_set_dash(cr, NULL, 0, 0.0); - } + cairo_t *cr = psPrint_d.printContext; + +// double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes +// static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + + if (lineWidth < 0.0) { + lineWidth = P2I(-lineWidth)*2.0/scale_adjust; + } + + // make sure that there is a minimum line width used + if (lineWidth <= 0.09) { + lineWidth = 0.1/scale_adjust; + } + + cairo_set_line_width(cr, lineWidth); + switch(lineType) { + case wDrawLineDot: { + double dashes[] = { 1, 2, 1, 2}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cr, dashes, len_dashes, 0.0); + break; + } + case wDrawLineDash: { + double dashes[] = { DASH_LENGTH, 3 }; //Reduce gap in between dashes + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cr, dashes, len_dashes, 0.0); + break; + } + case wDrawLineDashDot: { + double dashes[] = { 3, 2, 1, 2}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cr, dashes, len_dashes, 0.0); + break; + } + case wDrawLineDashDotDot: { + double dashes[] = { 3, 2, 1, 2, 1, 2}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cr, dashes, len_dashes, 0.0); + break; + } + case wDrawLineCenter: { + double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cr, dashes, len_dashes, 0.0); + break; + } + case wDrawLinePhantom: { + double dashes[] = { 1.5*DASH_LENGTH, 3, DASH_LENGTH, 3, DASH_LENGTH, 3}; + static int len_dashes = sizeof(dashes) / sizeof(dashes[0]); + cairo_set_dash(cr, dashes, len_dashes, 0.0); + break; + } + default: + cairo_set_dash(cr, NULL, 0, 0.0); + } } @@ -401,14 +398,14 @@ static void setLineType( */ static void psSetColor( - wDrawColor color) + wDrawColor color) { - cairo_t *cr = psPrint_d.printContext; - GdkColor* const gcolor = wlibGetColor(color, TRUE); + cairo_t *cr = psPrint_d.printContext; + GdkColor* const gcolor = wlibGetColor(color, TRUE); - cairo_set_source_rgb(cr, gcolor->red / 65535.0, - gcolor->green / 65535.0, - gcolor->blue / 65535.0); + cairo_set_source_rgb(cr, gcolor->red / 65535.0, + gcolor->green / 65535.0, + gcolor->blue / 65535.0); } /** @@ -423,29 +420,29 @@ static void psSetColor( */ void psPrintLine( - wDrawPix_t x0, wDrawPix_t y0, - wDrawPix_t x1, wDrawPix_t y1, - wDrawWidth width, - wDrawLineType_e lineType, - wDrawColor color, - wDrawOpts opts) + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t x1, wDrawPix_t y1, + wDrawWidth width, + wDrawLineType_e lineType, + wDrawColor color, + wDrawOpts opts) { - if (color == wDrawColorWhite) { - return; - } - - if (opts&wDrawOptTemp) { - return; - } - - psSetColor(color); - setLineType(width, lineType, opts); - - cairo_move_to(psPrint_d.printContext, - x0, y0); - cairo_line_to(psPrint_d.printContext, - x1, y1); - cairo_stroke(psPrint_d.printContext); + if (color == wDrawColorWhite) { + return; + } + + if (opts&wDrawOptTemp) { + return; + } + + psSetColor(color); + setLineType(width, lineType, opts); + + cairo_move_to(psPrint_d.printContext, + x0, y0); + cairo_line_to(psPrint_d.printContext, + x1, y1); + cairo_stroke(psPrint_d.printContext); } /** @@ -462,65 +459,65 @@ void psPrintLine( */ void psPrintArc( - wDrawPix_t x0, wDrawPix_t y0, - wDrawPix_t r, - double angle0, - double angle1, - wBool_t drawCenter, - wDrawWidth width, - wDrawLineType_e lineType, - wDrawColor color, - wDrawOpts opts) + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t r, + double angle0, + double angle1, + wBool_t drawCenter, + wDrawWidth width, + wDrawLineType_e lineType, + wDrawColor color, + wDrawOpts opts) { - cairo_t *cr = psPrint_d.printContext; + cairo_t *cr = psPrint_d.printContext; - if (color == wDrawColorWhite) { - return; - } + if (color == wDrawColorWhite) { + return; + } - if (opts&wDrawOptTemp) { - return; - } + if (opts&wDrawOptTemp) { + return; + } - psSetColor(color); - setLineType(width, lineType, opts); + psSetColor(color); + setLineType(width, lineType, opts); - if (angle1 >= 360.0) { - angle1 = 359.999; - } + if (angle1 >= 360.0) { + angle1 = 359.999; + } - angle1 = 90.0-(angle0+angle1); + angle1 = 90.0-(angle0+angle1); - while (angle1 < 0.0) { - angle1 += 360.0; - } + while (angle1 < 0.0) { + angle1 += 360.0; + } - while (angle1 >= 360.0) { - angle1 -= 360.0; - } + while (angle1 >= 360.0) { + angle1 -= 360.0; + } - angle0 = 90.0-angle0; + angle0 = 90.0-angle0; - while (angle0 < 0.0) { - angle0 += 360.0; - } + while (angle0 < 0.0) { + angle0 += 360.0; + } - while (angle0 >= 360.0) { - angle0 -= 360.0; - } + while (angle0 >= 360.0) { + angle0 -= 360.0; + } - // draw the curve - cairo_arc(cr, x0, y0, r, angle1 * M_PI / 180.0, angle0 * M_PI / 180.0); + // draw the curve + cairo_arc(cr, x0, y0, r, angle1 * M_PI / 180.0, angle0 * M_PI / 180.0); - if (drawCenter) { - // draw crosshair for center of curve - cairo_move_to(cr, x0 - CENTERMARK_LENGTH / 2, y0); - cairo_line_to(cr, x0 + CENTERMARK_LENGTH / 2, y0); - cairo_move_to(cr, x0, y0 - CENTERMARK_LENGTH / 2); - cairo_line_to(cr, x0, y0 + CENTERMARK_LENGTH / 2); - } + if (drawCenter) { + // draw crosshair for center of curve + cairo_move_to(cr, x0 - CENTERMARK_LENGTH / 2, y0); + cairo_line_to(cr, x0 + CENTERMARK_LENGTH / 2, y0); + cairo_move_to(cr, x0, y0 - CENTERMARK_LENGTH / 2); + cairo_line_to(cr, x0, y0 + CENTERMARK_LENGTH / 2); + } - cairo_stroke(psPrint_d.printContext); + cairo_stroke(psPrint_d.printContext); } /** @@ -534,28 +531,28 @@ void psPrintArc( */ void psPrintFillRectangle( - wDrawPix_t x0, wDrawPix_t y0, - wDrawPix_t x1, wDrawPix_t y1, - wDrawColor color, - wDrawOpts opts) + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t x1, wDrawPix_t y1, + wDrawColor color, + wDrawOpts opts) { - cairo_t *cr = psPrint_d.printContext; - double width = x0 - x1; - double height = y0 - y1; + cairo_t *cr = psPrint_d.printContext; + double width = x0 - x1; + double height = y0 - y1; - if (color == wDrawColorWhite) { - return; - } + if (color == wDrawColorWhite) { + return; + } - if (opts&wDrawOptTemp) { - return; - } + if (opts&wDrawOptTemp) { + return; + } - psSetColor(color); + psSetColor(color); - cairo_rectangle(cr, x0, y0, width, height); + cairo_rectangle(cr, x0, y0, width, height); - cairo_fill(cr); + cairo_fill(cr); } /** @@ -570,34 +567,34 @@ void psPrintFillRectangle( */ void psPrintFillPolygon( - wDrawPix_t p[][2], - wPolyLine_e type[], - int cnt, - wDrawColor color, - wDrawOpts opts, - int fill, - int open ) + wDrawPix_t p[][2], + wPolyLine_e type[], + int cnt, + wDrawColor color, + wDrawOpts opts, + int fill, + int open ) { - int inx; - cairo_t *cr = psPrint_d.printContext; + int inx; + cairo_t *cr = psPrint_d.printContext; - if (color == wDrawColorWhite) { - return; - } + if (color == wDrawColorWhite) { + return; + } - if (opts&wDrawOptTemp) { - return; - } + if (opts&wDrawOptTemp) { + return; + } - psSetColor(color); + psSetColor(color); - wDrawPix_t mid0[2], mid1[2], mid2[2], mid3[2], mid4[2]; + wDrawPix_t mid0[2], mid1[2], /*mid2[2],*/ mid3[2], mid4[2]; - for (inx=0; inx<cnt; inx++) { - int j = inx-1; - int k = inx+1; - if (j < 0) j = cnt-1; - if (k > cnt-1) k = 0; + for (inx=0; inx<cnt; inx++) { + int j = inx-1; + int k = inx+1; + if (j < 0) { j = cnt-1; } + if (k > cnt-1) { k = 0; } double len0, len1; double d0x = (p[inx][0]-p[j][0]); double d0y = (p[inx][1]-p[j][1]); @@ -625,33 +622,37 @@ void psPrintFillPolygon( mid4[1] = (mid1[1]-p[inx][1])/2+p[inx][1]; wDrawPix_t save[2]; if (inx==0) { - if (!type || (type && type[0] == wPolyLineStraight) || open) { - cairo_move_to(cr, p[ 0 ][ 0 ], p[ 0 ][ 1 ]); - save[0] = p[0][0]; save[1] = p[0][1]; - } else { - cairo_move_to(cr, mid0[0], mid0[1]); - if (type[inx] == wPolyLineSmooth) - cairo_curve_to(cr, p[inx][0], p[inx][1], p[inx][0], p[inx][1], mid1[0], mid1[1]); - else - cairo_curve_to(cr, mid3[0], mid3[1], mid4[0], mid4[1], mid1[0], mid1[1]); - save[0] = mid0[0]; save[1] = mid0[1]; - } - } else if (!type || (type && type[inx] == wPolyLineStraight) || (open && (inx==cnt-1)) ) { + if (!type || (type && type[0] == wPolyLineStraight) || open) { + cairo_move_to(cr, p[ 0 ][ 0 ], p[ 0 ][ 1 ]); + save[0] = p[0][0]; save[1] = p[0][1]; + } else { + cairo_move_to(cr, mid0[0], mid0[1]); + if (type[inx] == wPolyLineSmooth) { + cairo_curve_to(cr, p[inx][0], p[inx][1], p[inx][0], p[inx][1], mid1[0], + mid1[1]); + } else { + cairo_curve_to(cr, mid3[0], mid3[1], mid4[0], mid4[1], mid1[0], mid1[1]); + } + save[0] = mid0[0]; save[1] = mid0[1]; + } + } else if (!type || (type && type[inx] == wPolyLineStraight) || (open + && (inx==cnt-1)) ) { cairo_line_to(cr, p[ inx ][ 0 ], p[ inx ][ 1 ]); } else { cairo_line_to(cr, mid0[ 0 ], mid0[ 1 ]); - if (type && type[inx] == wPolyLineSmooth) + if (type && type[inx] == wPolyLineSmooth) { cairo_curve_to(cr, p[inx][0],p[inx][1],p[inx][0],p[inx][1],mid1[0],mid1[1]); - else + } else { cairo_curve_to(cr, mid3[0],mid3[1],mid4[0],mid4[1],mid1[0],mid1[1]); + } } if ((inx==cnt-1) && !open) { cairo_line_to(cr, save[0], save[1]); } - } + } - if (fill && !open) cairo_fill(cr); - else cairo_stroke(cr); + if (fill && !open) { cairo_fill(cr); } + else { cairo_stroke(cr); } } /** @@ -665,25 +666,25 @@ void psPrintFillPolygon( */ void psPrintFillCircle( - wDrawPix_t x0, wDrawPix_t y0, - wDrawPix_t r, - wDrawColor color, - wDrawOpts opts) + wDrawPix_t x0, wDrawPix_t y0, + wDrawPix_t r, + wDrawColor color, + wDrawOpts opts) { - if (color == wDrawColorWhite) { - return; - } + if (color == wDrawColorWhite) { + return; + } - if (opts&wDrawOptTemp) { - return; - } + if (opts&wDrawOptTemp) { + return; + } - psSetColor(color); + psSetColor(color); - cairo_arc(psPrint_d.printContext, - x0, y0, r, 0.0, 2 * M_PI); + cairo_arc(psPrint_d.printContext, + x0, y0, r, 0.0, 2 * M_PI); - cairo_fill(psPrint_d.printContext); + cairo_fill(psPrint_d.printContext); } @@ -710,102 +711,102 @@ void psPrintFillCircle( */ void psPrintString( - wDrawPix_t x, wDrawPix_t y, - double a, - char * s, - wFont_p fp, - double fs, - wDrawColor color, - wDrawOpts opts) + wDrawPix_t x, wDrawPix_t y, + double a, + char * s, + wFont_p fp, + double fs, + wDrawColor color, + wDrawOpts opts) { - char * cp; - double x0 = (double)x, y0 = (double)y; - int text_height, text_width; - double ascent; +// char * cp; + double x0 = (double)x, y0 = (double)y; + int text_height, text_width; +// double ascent; - cairo_t *cr; - cairo_matrix_t matrix; + cairo_t *cr; + cairo_matrix_t matrix; - PangoLayout *layout; - PangoFontDescription *desc; - PangoFontMetrics *metrics; - PangoContext *pcontext; + PangoLayout *layout; + PangoFontDescription *desc; +// PangoFontMetrics *metrics; + PangoContext *pcontext; - if (color == wDrawColorWhite) { - return; - } + if (color == wDrawColorWhite) { + return; + } - cr = psPrint_d.printContext; + cr = psPrint_d.printContext; - // get the current transformation matrix and transform the starting - // point of the string + // get the current transformation matrix and transform the starting + // point of the string - cairo_save(cr); + cairo_save(cr); - cairo_get_matrix(cr, &matrix); + cairo_get_matrix(cr, &matrix); - cairo_matrix_transform_point(&matrix, &x0, &y0); + cairo_matrix_transform_point(&matrix, &x0, &y0); - cairo_identity_matrix(cr); + cairo_identity_matrix(cr); - layout = pango_cairo_create_layout(cr); + layout = pango_cairo_create_layout(cr); - // set the correct font and size - /** \todo use a getter function instead of double conversion */ - desc = pango_font_description_from_string(wlibFontTranslate(fp)); + // set the correct font and size + /** \todo use a getter function instead of double conversion */ + desc = pango_font_description_from_string(wlibFontTranslate(fp)); - pango_font_description_set_size(desc, fs * PANGO_SCALE * scale_text); + pango_font_description_set_size(desc, fs * PANGO_SCALE * scale_text); - // render the string to a Pango layout - pango_layout_set_font_description(layout, desc); + // render the string to a Pango layout + pango_layout_set_font_description(layout, desc); - gchar *utf8 = wlibConvertInput(s); + gchar *utf8 = wlibConvertInput(s); - pango_layout_set_text(layout, utf8, -1); - pango_layout_set_width(layout, -1); - pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); - pango_layout_get_size(layout, &text_width, &text_height); + pango_layout_set_text(layout, utf8, -1); + pango_layout_set_width(layout, -1); + pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); + pango_layout_get_size(layout, &text_width, &text_height); - text_width = text_width / PANGO_SCALE; - text_height = text_height / PANGO_SCALE; + text_width = text_width / PANGO_SCALE; + text_height = text_height / PANGO_SCALE; - // get the height of the string - pcontext = pango_cairo_create_context(cr); - metrics = pango_context_get_metrics(pcontext, desc, - pango_context_get_language(pcontext)); + // get the height of the string + pcontext = pango_cairo_create_context(cr); +// metrics = pango_context_get_metrics(pcontext, desc, +// pango_context_get_language(pcontext)); - ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; +// ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; - int baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; + int baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; - cairo_translate(cr, x0, y0 ); - cairo_rotate(cr, -a * M_PI / 180.0); - cairo_translate( cr, 0, -baseline ); + cairo_translate(cr, x0, y0 ); + cairo_rotate(cr, -a * M_PI / 180.0); + cairo_translate( cr, 0, -baseline ); - cairo_move_to(cr,0,0); + cairo_move_to(cr,0,0); - pango_cairo_update_layout(cr, layout); + pango_cairo_update_layout(cr, layout); - // set the color - psSetColor(color); + // set the color + psSetColor(color); - // and show the string - if(!(opts & wDrawOutlineFont)) { + // and show the string + if(!(opts & wDrawOutlineFont)) { pango_cairo_show_layout(cr, layout); cairo_stroke( cr ); } else { PangoLayoutLine *line; line = pango_layout_get_line_readonly (layout, 0); - setLineType( wDrawLineSolid, 0, 0 ); + setLineType( wDrawLineSolid, 0, 0 ); pango_cairo_layout_line_path (cr, line); - cairo_stroke( cr ); + cairo_stroke( cr ); } - // free unused objects - g_object_unref(layout); - g_object_unref(pcontext); + // free unused objects + g_object_unref(layout); + g_object_unref(pcontext); - cairo_restore(cr); + cairo_restore(cr); } /** @@ -818,12 +819,12 @@ void psPrintString( void wPrintClip(wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h) { - cairo_move_to(psPrint_d.printContext, x, y); - cairo_rel_line_to(psPrint_d.printContext, w, 0); - cairo_rel_line_to(psPrint_d.printContext, 0, h); - cairo_rel_line_to(psPrint_d.printContext, -w, 0); - cairo_close_path(psPrint_d.printContext); - cairo_clip(psPrint_d.printContext); + cairo_move_to(psPrint_d.printContext, x, y); + cairo_rel_line_to(psPrint_d.printContext, w, 0); + cairo_rel_line_to(psPrint_d.printContext, 0, h); + cairo_rel_line_to(psPrint_d.printContext, -w, 0); + cairo_close_path(psPrint_d.printContext); + cairo_clip(psPrint_d.printContext); } /***************************************************************************** @@ -840,22 +841,22 @@ void wPrintClip(wDrawPix_t x, wDrawPix_t y, wDrawPix_t w, wDrawPix_t h) static void WlibGetPaperSize(void) { - double temp; - - bBorder = gtk_page_setup_get_bottom_margin(page_setup, GTK_UNIT_INCH); - tBorder = gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH); - lBorder = gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH); - rBorder = gtk_page_setup_get_right_margin(page_setup, GTK_UNIT_INCH); - paperHeight = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH); - paperWidth = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH); - - // XTrackCAD does page orientation itself. Basic assumption is that the - // paper is always oriented in portrait mode. Ignore settings by user - if (paperHeight < paperWidth) { - temp = paperHeight; - paperHeight = paperWidth; - paperWidth = temp; - } + double temp; + + bBorder = gtk_page_setup_get_bottom_margin(page_setup, GTK_UNIT_INCH); + tBorder = gtk_page_setup_get_top_margin(page_setup, GTK_UNIT_INCH); + lBorder = gtk_page_setup_get_left_margin(page_setup, GTK_UNIT_INCH); + rBorder = gtk_page_setup_get_right_margin(page_setup, GTK_UNIT_INCH); + paperHeight = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH); + paperWidth = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH); + + // XTrackCAD does page orientation itself. Basic assumption is that the + // paper is always oriented in portrait mode. Ignore settings by user + if (paperHeight < paperWidth) { + temp = paperHeight; + paperHeight = paperWidth; + paperWidth = temp; + } } /** @@ -868,15 +869,15 @@ WlibGetPaperSize(void) void wPrintGetMargins( - double * tMargin, - double * rMargin, - double * bMargin, - double * lMargin ) + double * tMargin, + double * rMargin, + double * bMargin, + double * lMargin ) { - if ( tMargin ) *tMargin = tBorder; - if ( rMargin ) *rMargin = rBorder; - if ( bMargin ) *bMargin = bBorder; - if ( lMargin ) *lMargin = lBorder; + if ( tMargin ) { *tMargin = tBorder; } + if ( rMargin ) { *rMargin = rBorder; } + if ( bMargin ) { *bMargin = bBorder; } + if ( lMargin ) { *lMargin = lBorder; } } @@ -889,18 +890,18 @@ void wPrintGetMargins( */ void wPrintGetPageSize( - double * w, - double * h) + double * w, + double * h) { - // if necessary load the settings - if (!settings) { - WlibApplySettings(NULL); - } + // if necessary load the settings + if (!settings) { + WlibApplySettings(NULL); + } - WlibGetPaperSize(); + WlibGetPaperSize(); - *w = paperWidth; - *h = paperHeight; + *w = paperWidth; + *h = paperHeight; } /** @@ -909,11 +910,11 @@ void wPrintGetPageSize( * \param context IN unused * \return */ -static void printAbort(void * context) -{ - printContinue = FALSE; +//static void printAbort(void * context) +//{ +// printContinue = FALSE; // wWinShow( printAbortW, FALSE ); -} +//} /** * Initialize new page. @@ -925,11 +926,11 @@ static void printAbort(void * context) */ wDraw_p wPrintPageStart(void) { - pageCount++; + pageCount++; - cairo_save(psPrint_d.printContext); + cairo_save(psPrint_d.printContext); - return &psPrint_d; + return &psPrint_d; } /** @@ -945,11 +946,11 @@ wDraw_p wPrintPageStart(void) wBool_t wPrintPageEnd(wDraw_p p) { - cairo_show_page(psPrint_d.printContext); + cairo_show_page(psPrint_d.printContext); - cairo_restore(psPrint_d.printContext); + cairo_restore(psPrint_d.printContext); - return printContinue; + return printContinue; } /***************************************************************************** @@ -970,93 +971,93 @@ wBool_t wPrintPageEnd(wDraw_p p) wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) { - GtkWidget *printDialog; - gint res; - cairo_surface_type_t surface_type; - cairo_matrix_t matrix; + GtkWidget *printDialog; + gint res; +// cairo_surface_type_t surface_type; +// cairo_matrix_t matrix; - printDialog = gtk_print_unix_dialog_new(title, GTK_WINDOW(gtkMainW->gtkwin)); + printDialog = gtk_print_unix_dialog_new(title, GTK_WINDOW(gtkMainW->gtkwin)); - // load the settings - WlibApplySettings(NULL); + // load the settings + WlibApplySettings(NULL); - // and apply them to the printer dialog - gtk_print_unix_dialog_set_settings((GtkPrintUnixDialog *)printDialog, settings); - gtk_print_unix_dialog_set_page_setup((GtkPrintUnixDialog *)printDialog, - page_setup); + // and apply them to the printer dialog + gtk_print_unix_dialog_set_settings((GtkPrintUnixDialog *)printDialog, settings); + gtk_print_unix_dialog_set_page_setup((GtkPrintUnixDialog *)printDialog, + page_setup); - res = gtk_dialog_run((GtkDialog *)printDialog); + res = gtk_dialog_run((GtkDialog *)printDialog); - if (res == GTK_RESPONSE_OK) { - selPrinter = gtk_print_unix_dialog_get_selected_printer(( - GtkPrintUnixDialog *)printDialog); + if (res == GTK_RESPONSE_OK) { + selPrinter = gtk_print_unix_dialog_get_selected_printer(( + GtkPrintUnixDialog *)printDialog); - if (settings) { - g_object_unref(settings); - } + if (settings) { + g_object_unref(settings); + } - settings = gtk_print_unix_dialog_get_settings((GtkPrintUnixDialog *) - printDialog); + settings = gtk_print_unix_dialog_get_settings((GtkPrintUnixDialog *) + printDialog); - if (page_setup) { - g_object_unref(page_setup); - } + if (page_setup) { + g_object_unref(page_setup); + } - page_setup = gtk_print_unix_dialog_get_page_setup((GtkPrintUnixDialog *) - printDialog); + page_setup = gtk_print_unix_dialog_get_page_setup((GtkPrintUnixDialog *) + printDialog); - curPrintJob = gtk_print_job_new(title, - selPrinter, - settings, - page_setup); + curPrintJob = gtk_print_job_new(title, + selPrinter, + settings, + page_setup); - psPrint_d.curPrintSurface = gtk_print_job_get_surface(curPrintJob, - NULL); - psPrint_d.printContext = cairo_create(psPrint_d.curPrintSurface); + psPrint_d.curPrintSurface = gtk_print_job_get_surface(curPrintJob, + NULL); + psPrint_d.printContext = cairo_create(psPrint_d.curPrintSurface); - WlibApplySettings( NULL ); - //update the paper dimensions - WlibGetPaperSize(); + WlibApplySettings( NULL ); + //update the paper dimensions + WlibGetPaperSize(); - /* for all surfaces including files the resolution is always 72 ppi (as all GTK uses PDF) */ - surface_type = cairo_surface_get_type(psPrint_d.curPrintSurface); + /* for all surfaces including files the resolution is always 72 ppi (as all GTK uses PDF) */ + /*surface_type = */cairo_surface_get_type(psPrint_d.curPrintSurface); - /* - * Override up-scaling for some printer drivers/Linux systems that don't support the latest CUPS - * - the user either sets preferences or the environment variable XTRKCADPRINTSCALE to a value - * and we just let the dpi default to 72ppi and set scaling to that value. - * And for PangoText we allow an override via preferences or variable XTRKCADPRINTTEXTSCALE - * Note - doing this will introduce differing artifacts. - * - */ - char * sEnvScale = PRODUCT "PRINTSCALE"; - char * sEnvTextScale = PRODUCT "PRINTTEXTSCALE"; + /* + * Override up-scaling for some printer drivers/Linux systems that don't support the latest CUPS + * - the user either sets preferences or the environment variable XTRKCADPRINTSCALE to a value + * and we just let the dpi default to 72ppi and set scaling to that value. + * And for PangoText we allow an override via preferences or variable XTRKCADPRINTTEXTSCALE + * Note - doing this will introduce differing artifacts. + * + */ + char * sEnvScale = PRODUCT "PRINTSCALE"; + char * sEnvTextScale = PRODUCT "PRINTTEXTSCALE"; - scale_text = 1.0; - scale_adjust = 1.0; + scale_text = 1.0; + scale_adjust = 1.0; - double printScale,printTextScale; + double printScale,printTextScale; - wPrefGetFloat(PREFSECTION, PRINTSCALE, &printScale, -1.0); - wPrefGetFloat(PREFSECTION, PRINTTEXTSCALE, &printTextScale, -1.0); + wPrefGetFloat(PREFSECTION, PRINTSCALE, &printScale, -1.0); + wPrefGetFloat(PREFSECTION, PRINTTEXTSCALE, &printTextScale, -1.0); - //If the preferences are not set, look at environmental variables + //If the preferences are not set, look at environmental variables - if (printScale < 0.0 ) { - if (getenv(sEnvScale) && (atof(getenv(sEnvScale)) > 0.0)) { - printScale = atof(getenv(sEnvScale)); - } - } - if (printTextScale < 0.0 ) { - if (getenv(sEnvTextScale) && (atof(getenv(sEnvTextScale)) > 0.0)) { - printTextScale = atof(getenv(sEnvTextScale)); - } - } + if (printScale < 0.0 ) { + if (getenv(sEnvScale) && (atof(getenv(sEnvScale)) > 0.0)) { + printScale = atof(getenv(sEnvScale)); + } + } + if (printTextScale < 0.0 ) { + if (getenv(sEnvTextScale) && (atof(getenv(sEnvTextScale)) > 0.0)) { + printTextScale = atof(getenv(sEnvTextScale)); + } + } - const char * sPrinterName = gtk_printer_get_name( selPrinter ); - if ((strcmp(sPrinterName,"Print to File") == 0) || printScale < 0.0) { + const char * sPrinterName = gtk_printer_get_name( selPrinter ); + if ((strcmp(sPrinterName,"Print to File") == 0) || printScale < 0.0) { double p_def = 600; cairo_surface_set_fallback_resolution(psPrint_d.curPrintSurface, p_def, p_def); psPrint_d.dpi = p_def; @@ -1071,33 +1072,33 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) psPrint_d.dpi = 72; } - // in XTrackCAD 0,0 is top left, in cairo bottom left. This is - // corrected via the following transformations. - // also the translate makes sure that the drawing is rendered - // within the paper margin + // in XTrackCAD 0,0 is top left, in cairo bottom left. This is + // corrected via the following transformations. + // also the translate makes sure that the drawing is rendered + // within the paper margin - cairo_translate(psPrint_d.printContext, lBorder*72, (paperHeight-bBorder)*72 ); + cairo_translate(psPrint_d.printContext, lBorder*72, (paperHeight-bBorder)*72 ); - cairo_scale(psPrint_d.printContext, 1.0 * scale_adjust, -1.0 * scale_adjust); + cairo_scale(psPrint_d.printContext, 1.0 * scale_adjust, -1.0 * scale_adjust); - //cairo_translate(psPrint_d.printContext, 0, -paperHeight* psPrint_d.dpi); + //cairo_translate(psPrint_d.printContext, 0, -paperHeight* psPrint_d.dpi); - WlibSaveSettings(NULL); - } + WlibSaveSettings(NULL); + } - gtk_widget_destroy(printDialog); + gtk_widget_destroy(printDialog); - if (copiesP) { - *copiesP = 1; - } + if (copiesP) { + *copiesP = 1; + } - printContinue = TRUE; + printContinue = TRUE; - if (res != GTK_RESPONSE_OK) { - return FALSE; - } else { - return TRUE; - } + if (res != GTK_RESPONSE_OK) { + return FALSE; + } else { + return TRUE; + } } /** @@ -1112,16 +1113,16 @@ wBool_t wPrintDocStart(const char * title, int fTotalPageCount, int * copiesP) void doPrintJobFinished(GtkPrintJob *job, void *data, GError *err) { - GtkWidget *dialog; +// GtkWidget *dialog; - cairo_destroy(psPrint_d.printContext); + cairo_destroy(psPrint_d.printContext); - if (err) { - dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s",err->message); - } + if (err) { + /*dialog = */gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s",err->message); + } } /** @@ -1131,12 +1132,12 @@ doPrintJobFinished(GtkPrintJob *job, void *data, GError *err) void wPrintDocEnd(void) { - cairo_surface_finish(psPrint_d.curPrintSurface); + cairo_surface_finish(psPrint_d.curPrintSurface); - gtk_print_job_send(curPrintJob, - doPrintJobFinished, - NULL, - NULL); + gtk_print_job_send(curPrintJob, + doPrintJobFinished, + NULL, + NULL); // wWinShow( printAbortW, FALSE ); } @@ -1144,11 +1145,11 @@ void wPrintDocEnd(void) wBool_t wPrintQuit(void) { - return FALSE; + return FALSE; } wBool_t wPrintInit(void) { - return TRUE; + return TRUE; } diff --git a/app/wlib/gtklib/single.c b/app/wlib/gtklib/single.c index 3856a64..6204ed5 100644 --- a/app/wlib/gtklib/single.c +++ b/app/wlib/gtklib/single.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define GTK_DISABLE_SINGLE_INCLUDES @@ -60,24 +60,27 @@ struct wString_t { * * \param b IN widget to be updated * \param arg IN new string value - * \return + * \return */ void wStringSetValue( - wString_p b, - const char *arg) + wString_p b, + const char *arg) { - if (b->widget == NULL) + if (b->widget == NULL) { abort(); - + } + // the contents should not be changed programatically while // the user is editing it - if( !(gtk_widget_has_focus(b->widget))) { - if (b->hasSignal) - gtk_signal_handler_block_by_data(GTK_OBJECT(b->widget), b); + if( (b->option&BO_IGNFOCUS) || !(gtk_widget_has_focus(b->widget))) { + if (b->hasSignal) { + gtk_signal_handler_block_by_data(GTK_OBJECT(b->widget), b); + } gtk_entry_set_text(GTK_ENTRY(b->widget), arg); - if (b->hasSignal) + if (b->hasSignal) { gtk_signal_handler_unblock_by_data(GTK_OBJECT(b->widget), b); + } } } @@ -86,12 +89,12 @@ void wStringSetValue( * * \param b IN widget to be updated * \param w IN new width - * \return + * \return */ void wStringSetWidth( - wString_p b, - wWinPix_t w) + wString_p b, + wWinPix_t w) { gtk_widget_set_size_request(b->widget, w, -1); b->w = w; @@ -105,11 +108,12 @@ void wStringSetWidth( */ const char *wStringGetValue( - wString_p b) + wString_p b) { - if ( !b->widget ) + if ( !b->widget ) { abort(); - + } + return gtk_entry_get_text(GTK_ENTRY(b->widget)); } @@ -134,37 +138,41 @@ void wlibStringUpdate() * * \param widget IN the edit field * \param b IN the widget data structure - * \return + * \return */ static gboolean stringActivated( - GtkEntry *widget, - wString_p b) + GtkEntry *widget, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringActivated: %s\n", b->labelStr ); + } const char *s; const char * output = "\n"; - if ( !b ) + if ( !b ) { return( FALSE ); - + } + s = wStringGetValue(b); - if (b->valueP) + if (b->valueP) { strcpy(b->valueP, s); + } if (b->action) { b->enter_pressed = TRUE; b->action( output, b->data); } - + // select the complete default value to make editing it easier gtk_editable_select_region( GTK_EDITABLE( widget ), 0, -1 ); return( TRUE ); } -static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event, gpointer g ) +static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event, + gpointer g ) { wControl_p b = (wControl_p)g; return wControlExpose(widget,event,b); @@ -176,34 +184,37 @@ static gboolean stringExposed(GtkWidget* widget, GdkEventExpose * event, gpointe * * \param widget IN * \param entry field IN - * \return + * \return */ static int stringChanged( - GtkEntry *widget, - wString_p b) + GtkEntry *widget, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringChanged: %s\n", b->labelStr); + } stringControl = b; return FALSE; } static int stringPreeditChanged( - GtkEntry *widget, - wString_p b) + GtkEntry *widget, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringPreeditChanged: %s\n", b->labelStr ); + } return FALSE; } static int stringFocusOutEvent( - GtkEntry *widget, - GdkEvent * event, - wString_p b) + GtkEntry *widget, + GdkEvent * event, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringFocusOut: %s\n", b->labelStr ); + } if (b->action) { const char *s; s = gtk_entry_get_text(GTK_ENTRY(b->widget)); @@ -213,64 +224,71 @@ static int stringFocusOutEvent( return FALSE; } static int stringFocusInEvent( - GtkEntry *widget, - GdkEvent * event, - wString_p b) + GtkEntry *widget, + GdkEvent * event, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringFocusIn: %s\n", b->labelStr ); + } stringControl = b; return FALSE; } static int stringLeaveNotifyEvent( - GtkEntry *widget, - GdkEvent * event, - wString_p b) + GtkEntry *widget, + GdkEvent * event, + wString_p b) { - if ( debugWindow >= 3 ) + if ( debugWindow >= 3 ) { printf( "stringLeaveNotfyEvent: %s\n", b->labelStr ); + } return FALSE; } static int stringEventAfter( - GtkEntry *widget, - wString_p b) + GtkEntry *widget, + wString_p b) { - if ( debugWindow >= 3 ) + if ( debugWindow >= 3 ) { printf( "stringEventAfter: %s\n", b->labelStr ); + } return FALSE; } static int stringEvent( - GtkEntry *widget, - wString_p b) + GtkEntry *widget, + wString_p b) { - if ( debugWindow >= 3 ) + if ( debugWindow >= 3 ) { printf( "stringEvent: %s\n", b->labelStr ); + } return FALSE; } static int stringKeyPressEvent( - GtkEntry *widget, - GdkEvent * event, - wString_p b) + GtkEntry *widget, + GdkEvent * event, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringKeyPressEvent: %s\n", b->labelStr ); + } return FALSE; } static int stringStateChanged( - GtkEntry *widget, - int state, - wString_p b) + GtkEntry *widget, + int state, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringStateChanged: %s\n", b->labelStr ); + } return FALSE; } static int stringActivate( - GtkEntry *widget, - wString_p b) + GtkEntry *widget, + wString_p b) { - if ( debugWindow >= 1 ) + if ( debugWindow >= 1 ) { printf( "stringActivate: %s\n", b->labelStr ); + } return stringChanged( widget, b ); } /** @@ -282,30 +300,30 @@ static int stringActivate( * \param helpStr IN help anchor * \param labelStr IN label * \param option IN option (supported BO_READONLY ) - * \param width IN width of entry field + * \param width IN width of entry field * \param valueP IN default value - * \param valueL IN maximum length of entry + * \param valueL IN maximum length of entry * \param action IN application callback function * \param data IN application data * \return the created widget */ wString_p wStringCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char *helpStr, - const char *labelStr, - long option, - wWinPix_t width, - char *valueP, - wIndex_t valueL, - wStringCallBack_p action, - void *data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char *helpStr, + const char *labelStr, + long option, + wWinPix_t width, + char *valueP, + wIndex_t valueL, + wStringCallBack_p action, + void *data) { wString_p b; - // create and initialize the widget + // create and initialize the widget b = (wString_p)wlibAlloc(parent, B_TEXT, x, y, labelStr, sizeof *b, data); b->valueP = valueP; b->action = action; @@ -314,63 +332,77 @@ wString_p wStringCreate( b->hasSignal = 0; wlibComputePos((wControl_p)b); - // create the gtk entry field and set maximum length if desired + // create the gtk entry field and set maximum length if desired b->widget = (GtkWidget *)gtk_entry_new(); - if (b->widget == NULL) abort(); + if (b->widget == NULL) { abort(); } - if( valueL ) + if( valueL ) { gtk_entry_set_max_length( GTK_ENTRY( b->widget ), valueL ); - + } + // it is assumed that the parent is a fixed layout widget and the entry can // be placed at a specific position gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - - // set minimum size for widget - if (width) + + // set minimum size for widget + if (width) { gtk_widget_set_size_request(b->widget, width, -1); - + } + // get the resulting size wlibControlGetSize((wControl_p)b); // if desired, place a label in front of the created widget - if (labelStr) + if (labelStr) { b->labelW = wlibAddLabel((wControl_p)b, labelStr); - - if (option & BO_READONLY) + } + + if (option & BO_READONLY) { gtk_editable_set_editable(GTK_EDITABLE(b->widget), FALSE); - + } + // set the default text and select it to make replacing it easier if (b->valueP) { wStringSetValue(b, b->valueP); // select the text only if text is editable } - + // show gtk_widget_show(b->widget); - + // add the new widget to the list of created widgets wlibAddButton((wControl_p)b); - - // link into help + + // link into help wlibAddHelpString(b->widget, helpStr); - - g_signal_connect(GTK_OBJECT(b->widget), "changed", G_CALLBACK(stringChanged), b); - g_signal_connect(GTK_OBJECT(b->widget), "preedit-changed", G_CALLBACK(stringPreeditChanged), b); - g_signal_connect(GTK_OBJECT(b->widget), "focus-out-event", G_CALLBACK(stringFocusOutEvent), b); - g_signal_connect(GTK_OBJECT(b->widget), "focus-in-event", G_CALLBACK(stringFocusInEvent), b); - g_signal_connect(GTK_OBJECT(b->widget), "leave-notify-event", G_CALLBACK(stringLeaveNotifyEvent), b); + + g_signal_connect(GTK_OBJECT(b->widget), "changed", G_CALLBACK(stringChanged), + b); + g_signal_connect(GTK_OBJECT(b->widget), "preedit-changed", + G_CALLBACK(stringPreeditChanged), b); + g_signal_connect(GTK_OBJECT(b->widget), "focus-out-event", + G_CALLBACK(stringFocusOutEvent), b); + g_signal_connect(GTK_OBJECT(b->widget), "focus-in-event", + G_CALLBACK(stringFocusInEvent), b); + g_signal_connect(GTK_OBJECT(b->widget), "leave-notify-event", + G_CALLBACK(stringLeaveNotifyEvent), b); g_signal_connect(GTK_OBJECT(b->widget), "event", G_CALLBACK(stringEvent), b); - g_signal_connect(GTK_OBJECT(b->widget), "event-after", G_CALLBACK(stringEventAfter), b); - g_signal_connect(GTK_OBJECT(b->widget), "key-press-event", G_CALLBACK(stringKeyPressEvent), b); - g_signal_connect(GTK_OBJECT(b->widget), "state-changed", G_CALLBACK(stringStateChanged), b); - g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivate), b); + g_signal_connect(GTK_OBJECT(b->widget), "event-after", + G_CALLBACK(stringEventAfter), b); + g_signal_connect(GTK_OBJECT(b->widget), "key-press-event", + G_CALLBACK(stringKeyPressEvent), b); + g_signal_connect(GTK_OBJECT(b->widget), "state-changed", + G_CALLBACK(stringStateChanged), b); + g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivate), + b); //if (option&BO_ENTER) - g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivated), b); + g_signal_connect(GTK_OBJECT(b->widget), "activate", G_CALLBACK(stringActivated), + b); b->hasSignal = 1; - g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", - G_CALLBACK(stringExposed), b); - + g_signal_connect_after(GTK_OBJECT(b->widget), "expose-event", + G_CALLBACK(stringExposed), b); + // set the default text and select it to make replacing it easier if (b->valueP) { wStringSetValue(b, b->valueP); @@ -378,6 +410,6 @@ wString_p wStringCreate( } gtk_widget_add_events( b->widget, GDK_FOCUS_CHANGE_MASK ); - + return b; } diff --git a/app/wlib/gtklib/splash.c b/app/wlib/gtklib/splash.c index 7b7613c..d42b7c0 100644 --- a/app/wlib/gtklib/splash.c +++ b/app/wlib/gtklib/splash.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <string.h> @@ -50,65 +50,65 @@ static GtkWidget *message; /**< window handle for progress message */ int wCreateSplash(char *appName, char *appVer) { - GtkWidget *vbox; - GtkWidget *image; - GtkWidget *label; - char *temp; - char logoPath[BUFSIZ]; - - /* create the basic window */ - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_decorated(GTK_WINDOW(window), FALSE); - gtk_window_set_title(GTK_WINDOW(window), appName); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN); + GtkWidget *vbox; + GtkWidget *image; + GtkWidget *label; + char *temp; + char logoPath[BUFSIZ]; + + /* create the basic window */ + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_decorated(GTK_WINDOW(window), FALSE); + gtk_window_set_title(GTK_WINDOW(window), appName); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN); #if GTK_MAJOR_VERSION > 1 || GTK_MINOR_VERSION > 5 - gtk_window_set_focus_on_map(GTK_WINDOW(window), FALSE); + gtk_window_set_focus_on_map(GTK_WINDOW(window), FALSE); #endif - vbox = gtk_vbox_new(FALSE, 0); - gtk_widget_show(vbox); - gtk_container_add(GTK_CONTAINER(window), vbox); + vbox = gtk_vbox_new(FALSE, 0); + gtk_widget_show(vbox); + gtk_container_add(GTK_CONTAINER(window), vbox); - /* add the logo image to the top of the splash window */ - sprintf(logoPath, "%s/" LOGOFILENAME, wGetAppLibDir()); - image = gtk_image_new_from_file(logoPath); - gtk_widget_show(image); - gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE, 0); - gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + /* add the logo image to the top of the splash window */ + sprintf(logoPath, "%s/" LOGOFILENAME, wGetAppLibDir()); + image = gtk_image_new_from_file(logoPath); + gtk_widget_show(image); + gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE, 0); + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); - /* put the product name into the window */ + /* put the product name into the window */ - temp = malloc(strlen(appName) + strlen(appVer) + 2); + temp = malloc(strlen(appName) + strlen(appVer) + 2); - if (!temp) { - return (FALSE); - } + if (!temp) { + return (FALSE); + } - sprintf(temp, "%s %s", appName, appVer); + sprintf(temp, "%s %s", appName, appVer); - label = gtk_label_new(temp); - gtk_widget_show(label); - gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); - gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL); - gtk_label_set_selectable(GTK_LABEL(label), FALSE); - gtk_misc_set_padding(GTK_MISC(label), 6, 2); + label = gtk_label_new(temp); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); + gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL); + gtk_label_set_selectable(GTK_LABEL(label), FALSE); + gtk_misc_set_padding(GTK_MISC(label), 6, 2); - free(temp); + free(temp); - label = gtk_label_new("Application is starting..."); - gtk_widget_show(label); - gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); - gtk_label_set_line_wrap(GTK_LABEL(label), FALSE); - gtk_misc_set_padding(GTK_MISC(label), 6, 2); + label = gtk_label_new("Application is starting..."); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); + gtk_label_set_line_wrap(GTK_LABEL(label), FALSE); + gtk_misc_set_padding(GTK_MISC(label), 6, 2); #if GTK_MINOR_VERSION > 5 - gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_START); + gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_START); #endif - message = label; + message = label; - gtk_widget_show(window); - return (TRUE); + gtk_widget_show(window); + return (TRUE); } /** @@ -120,13 +120,13 @@ wCreateSplash(char *appName, char *appVer) int wSetSplashInfo(char *msg) { - if (!window) return FALSE; - if (msg && message) { - gtk_label_set_text(GTK_LABEL(message), msg); - return TRUE; - } + if (!window) { return FALSE; } + if (msg && message) { + gtk_label_set_text(GTK_LABEL(message), msg); + return TRUE; + } - return FALSE; + return FALSE; } /** @@ -137,9 +137,9 @@ wSetSplashInfo(char *msg) void wDestroySplash(void) { - /* kill window */ - if (window) gtk_widget_destroy(window); - window = NULL; + /* kill window */ + if (window) { gtk_widget_destroy(window); } + window = NULL; - return; + return; } diff --git a/app/wlib/gtklib/statusbar.c b/app/wlib/gtklib/statusbar.c index a71d021..78d54ac 100644 --- a/app/wlib/gtklib/statusbar.c +++ b/app/wlib/gtklib/statusbar.c @@ -39,10 +39,10 @@ #include "gtkint.h" struct wStatus_t { - WOBJ_COMMON - GtkWidget * labelWidget; - const char * message; - wWinPix_t labelWidth; + WOBJ_COMMON + GtkWidget * labelWidget; + const char * message; + wWinPix_t labelWidth; }; /** @@ -54,20 +54,20 @@ struct wStatus_t { */ void wStatusSetValue( - wStatus_p b, - const char * arg) + wStatus_p b, + const char * arg) { - if (b->widget == 0) { - abort(); - } + if (b->widget == 0) { + abort(); + } - if (gtk_entry_get_max_length(GTK_ENTRY(b->labelWidget))<strlen(arg)) { - gtk_entry_set_max_length(GTK_ENTRY(b->labelWidget), strlen(arg)); - gtk_entry_set_width_chars(GTK_ENTRY(b->labelWidget), strlen(arg)); - } + if (gtk_entry_get_max_length(GTK_ENTRY(b->labelWidget))<strlen(arg)) { + gtk_entry_set_max_length(GTK_ENTRY(b->labelWidget), strlen(arg)); + gtk_entry_set_width_chars(GTK_ENTRY(b->labelWidget), strlen(arg)); + } - gtk_entry_set_text(GTK_ENTRY(b->labelWidget), wlibConvertInput(arg)); - gtk_widget_queue_draw (GTK_WIDGET(b->labelWidget)); + gtk_entry_set_text(GTK_ENTRY(b->labelWidget), wlibConvertInput(arg)); + gtk_widget_queue_draw (GTK_WIDGET(b->labelWidget)); } /** * Create a window for a simple text. @@ -83,38 +83,37 @@ void wStatusSetValue( */ wStatus_p wStatusCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * labelStr, - wWinPix_t width, - const char *message) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * labelStr, + wWinPix_t width, + const char *message) { - wStatus_p b; - GtkRequisition requisition; - b = (wStatus_p)wlibAlloc(parent, B_STATUS, x, y, NULL, sizeof *b, NULL); - wlibComputePos((wControl_p)b); - b->message = message; - b->labelWidth = width; - b->labelWidget = gtk_entry_new(); - gtk_editable_set_editable(GTK_EDITABLE(b->labelWidget), FALSE); - gtk_entry_set_has_frame(GTK_ENTRY(b->labelWidget), FALSE); - gtk_widget_set_can_focus(b->labelWidget, FALSE); - gtk_widget_set_sensitive(b->labelWidget, FALSE); - GdkColor black = {0, 0x0000, 0x0000, 0x0000}; - gtk_widget_modify_text(b->labelWidget,GTK_STATE_INSENSITIVE,&black); - gtk_entry_set_text(GTK_ENTRY(b->labelWidget), - message?wlibConvertInput(message):""); - - b->widget = gtk_fixed_new(); - gtk_container_add(GTK_CONTAINER(b->widget), b->labelWidget); - wlibControlGetSize((wControl_p)b); - gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); - gtk_widget_show(b->widget); - gtk_widget_show(b->labelWidget); - wlibAddButton((wControl_p)b); - - return b; + wStatus_p b; + b = (wStatus_p)wlibAlloc(parent, B_STATUS, x, y, NULL, sizeof *b, NULL); + wlibComputePos((wControl_p)b); + b->message = message; + b->labelWidth = width; + b->labelWidget = gtk_entry_new(); + gtk_editable_set_editable(GTK_EDITABLE(b->labelWidget), FALSE); + gtk_entry_set_has_frame(GTK_ENTRY(b->labelWidget), FALSE); + gtk_widget_set_can_focus(b->labelWidget, FALSE); + gtk_widget_set_sensitive(b->labelWidget, FALSE); + GdkColor black = {0, 0x0000, 0x0000, 0x0000}; + gtk_widget_modify_text(b->labelWidget,GTK_STATE_INSENSITIVE,&black); + gtk_entry_set_text(GTK_ENTRY(b->labelWidget), + message?wlibConvertInput(message):""); + + b->widget = gtk_fixed_new(); + gtk_container_add(GTK_CONTAINER(b->widget), b->labelWidget); + wlibControlGetSize((wControl_p)b); + gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY); + gtk_widget_show(b->widget); + gtk_widget_show(b->labelWidget); + wlibAddButton((wControl_p)b); + + return b; } /** @@ -127,22 +126,22 @@ wStatus_p wStatusCreate( wWinPix_t wStatusGetWidth(const char *testString) { - GtkWidget *entry; - GtkRequisition requisition; + GtkWidget *entry; + GtkRequisition requisition; - entry = gtk_entry_new(); - g_object_ref_sink(entry); + entry = gtk_entry_new(); + g_object_ref_sink(entry); - gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE); - gtk_entry_set_width_chars(GTK_ENTRY(entry), strlen(testString)); - gtk_entry_set_max_length(GTK_ENTRY(entry), strlen(testString)); + gtk_entry_set_has_frame(GTK_ENTRY(entry), FALSE); + gtk_entry_set_width_chars(GTK_ENTRY(entry), strlen(testString)); + gtk_entry_set_max_length(GTK_ENTRY(entry), strlen(testString)); - gtk_widget_size_request(entry, &requisition); + gtk_widget_size_request(entry, &requisition); - gtk_widget_destroy(entry); - g_object_unref(entry); + gtk_widget_destroy(entry); + g_object_unref(entry); - return (requisition.width); + return (requisition.width); } /** @@ -153,49 +152,49 @@ wStatusGetWidth(const char *testString) */ wWinPix_t wStatusGetHeight( - long flags) + long flags) { - GtkWidget * temp; + GtkWidget * temp; - if (!(flags&COMBOBOX)) { + if (!(flags&COMBOBOX)) { temp = gtk_entry_new(); //To get size of text itself - gtk_entry_set_has_frame(GTK_ENTRY(temp), FALSE); - } else { - temp = gtk_combo_box_text_new(); //to get max size of an object in infoBar - } - g_object_ref_sink(temp); - - if (wMessageSetFont(flags)) { - GtkStyle *style; - PangoFontDescription *fontDesc; - int fontSize; - /* get the current font descriptor */ - style = gtk_widget_get_style(temp); - fontDesc = style->font_desc; - /* get the current font size */ - fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); - - /* calculate the new font size */ - if (flags & BM_LARGE) { - pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); - } else { - pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); - } - - /* set the new font size */ - gtk_widget_modify_font(temp, fontDesc); - } - - if (flags&1L) { - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(temp),"Test"); - } - - GtkRequisition temp_requisition; - gtk_widget_size_request(temp,&temp_requisition); - //g_object_ref_sink(temp); - //g_object_unref(temp); - gtk_widget_destroy(temp); - return temp_requisition.height; + gtk_entry_set_has_frame(GTK_ENTRY(temp), FALSE); + } else { + temp = gtk_combo_box_text_new(); //to get max size of an object in infoBar + } + g_object_ref_sink(temp); + + if (wMessageSetFont(flags)) { + GtkStyle *style; + PangoFontDescription *fontDesc; + int fontSize; + /* get the current font descriptor */ + style = gtk_widget_get_style(temp); + fontDesc = style->font_desc; + /* get the current font size */ + fontSize = PANGO_PIXELS(pango_font_description_get_size(fontDesc)); + + /* calculate the new font size */ + if (flags & BM_LARGE) { + pango_font_description_set_size(fontDesc, fontSize * 1.4 * PANGO_SCALE); + } else { + pango_font_description_set_size(fontDesc, fontSize * 0.7 * PANGO_SCALE); + } + + /* set the new font size */ + gtk_widget_modify_font(temp, fontDesc); + } + + if (flags&1L) { + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(temp),"Test"); + } + + GtkRequisition temp_requisition; + gtk_widget_size_request(temp,&temp_requisition); + //g_object_ref_sink(temp); + //g_object_unref(temp); + gtk_widget_destroy(temp); + return temp_requisition.height; } /** @@ -207,9 +206,9 @@ wWinPix_t wStatusGetHeight( */ void wStatusSetWidth( - wStatus_p b, - wWinPix_t width) + wStatus_p b, + wWinPix_t width) { - b->labelWidth = width; - gtk_widget_set_size_request(b->widget, width, -1); + b->labelWidth = width; + gtk_widget_set_size_request(b->widget, width, -1); } diff --git a/app/wlib/gtklib/sysinfo.c b/app/wlib/gtklib/sysinfo.c new file mode 100644 index 0000000..eccd67f --- /dev/null +++ b/app/wlib/gtklib/sysinfo.c @@ -0,0 +1,137 @@ +/** \file sysinfo.c + * Collect info about runtime environment +*/ + +/* XTrkCad - Model Railroad CAD + * Copyright (C) 2024 Martin Fischer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <stdlib.h> + +#include <wlib.h> +#include "gtkint.h" + + +static char *buffer; + +/** + * Return the path to a temporary directory. The directory is not created. + * The result is put into a buffer and is only valid immediately after the call. + * + * \return pointer to fully qualified directory path + */ + +char * +wGetTempPath() +{ + gchar const *tempDir = g_get_tmp_dir(); + gchar *path; + gchar pidString[20]; + + g_snprintf(pidString, 20, "xtc%d", getpid()); + path = g_build_path("/", tempDir, pidString, (char *)0); + + if(buffer) { + g_free(buffer); + } + + buffer = g_strdup(path); + g_free(path); + + return(buffer); +} + +/** + * Get the Windows version. This function uses the Windows ver command to + * retrieve the OS version. The result is put into a buffer and is only + * valid immediately after the call. + * + * \return buffer containing the zero terminated string + * + */ + +char * +wGetOSVersion() +{ + FILE* pPipe; + size_t bufferSize = 80; + + if(buffer) { + free(buffer); + buffer = NULL; + } + + buffer = malloc(bufferSize); +// pPipe = _popen("cat /etc/*-release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g'", "r"); + pPipe = popen("uname -sr", "r"); + + while (fgets(buffer, bufferSize, pPipe)) + ; + + if (buffer[strlen(buffer) -1] == '\n') + buffer[strlen(buffer) -1 ] = '\0'; + pclose(pPipe); + + return(buffer); +} + + + +/** + * Get the name of the current user. The result is put into a buffer and is only + * valid immediately after the call. + * + * \return buffer containing the zero terminated string + * + */ + +char * +wGetUserID() +{ + const gchar *name; + + name = g_get_user_name(); + + if(buffer) { + g_free(buffer); + } + buffer = g_strdup( name ); + return(buffer); +} + +/** Get the user's profile directory. Other than on UNIX Windows differentiates + * between the home directory and and the profile directory. + * + * \return pointer to the user's profile directory + */ + +const char* wGetUserHomeRootDir(void) +{ + return(wGetUserHomeDir()); +} + +const char* wGetPlatformVersion() +{ + if(buffer) { + g_free(buffer); + } + + buffer = g_strdup_printf("%d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version ); + return(buffer); +} + diff --git a/app/wlib/gtklib/text.c b/app/wlib/gtklib/text.c index cb811b6..69a7ecc 100644 --- a/app/wlib/gtklib/text.c +++ b/app/wlib/gtklib/text.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -37,12 +37,12 @@ #include "gtkint.h" struct PrintData { - wText_p tb; - gint lines_per_page; - gdouble font_size; - gchar **lines; - gint total_lines; - gint total_pages; + wText_p tb; + gint lines_per_page; + gdouble font_size; + gchar **lines; + gint total_lines; + gint total_pages; }; #define HEADER_HEIGHT 20.0 @@ -58,10 +58,10 @@ struct PrintData { */ struct wText_t { - WOBJ_COMMON - wWinPix_t width, height; - int changed; - GtkWidget *text; + WOBJ_COMMON + wWinPix_t width, height; + int changed; + GtkWidget *text; }; /** @@ -74,15 +74,15 @@ struct wText_t { void wTextClear(wText_p bt) { - GtkTextBuffer *tb; - tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); - gtk_text_buffer_set_text(tb, "", -1); + GtkTextBuffer *tb; + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); + gtk_text_buffer_set_text(tb, "", -1); - if (bt->option & BO_READONLY) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE); - } + if (bt->option & BO_READONLY) { + gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE); + } - bt->changed = FALSE; + bt->changed = FALSE; } /** @@ -96,34 +96,34 @@ void wTextClear(wText_p bt) void wTextAppend(wText_p bt, const char *text) { - GtkTextBuffer *tb; - GtkTextIter ti1; - GtkTextMark *tm; - - - if (bt->text == 0) { - abort(); - } - - tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); - // convert to utf-8 - text = wlibConvertInput(text); - // append to end of buffer - gtk_text_buffer_get_end_iter(tb, &ti1); - gtk_text_buffer_insert(tb, &ti1, text, -1); - - if ( bt->option & BT_TOP ) { - // and scroll to start of text - gtk_text_buffer_get_start_iter(tb, &ti1); - } else { - // and scroll to end of text - gtk_text_buffer_get_end_iter(tb, &ti1); - } - tm = gtk_text_buffer_create_mark(tb, NULL, &ti1, TRUE ); - gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW(bt->text), tm ); - gtk_text_buffer_delete_mark( tb, tm ); - - bt->changed = FALSE; + GtkTextBuffer *tb; + GtkTextIter ti1; + GtkTextMark *tm; + + + if (bt->text == 0) { + abort(); + } + + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); + // convert to utf-8 + text = wlibConvertInput(text); + // append to end of buffer + gtk_text_buffer_get_end_iter(tb, &ti1); + gtk_text_buffer_insert(tb, &ti1, text, -1); + + if ( bt->option & BT_TOP ) { + // and scroll to start of text + gtk_text_buffer_get_start_iter(tb, &ti1); + } else { + // and scroll to end of text + gtk_text_buffer_get_end_iter(tb, &ti1); + } + tm = gtk_text_buffer_create_mark(tb, NULL, &ti1, TRUE ); + gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW(bt->text), tm ); + gtk_text_buffer_delete_mark( tb, tm ); + + bt->changed = FALSE; } /** @@ -138,21 +138,22 @@ void wTextAppend(wText_p bt, static char *wlibGetText(wText_p bt) { - GtkTextBuffer *tb; - GtkTextIter ti1, ti2; - char *cp, *cp1, *res; - - if (bt->text == 0) { - abort(); - } - - tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); - gtk_text_buffer_get_bounds(tb, &ti1, &ti2); - cp = gtk_text_buffer_get_text(tb, &ti1, &ti2, FALSE); - //cp1 = wlibConvertOutput(cp); - res = strdup(cp); - g_free(cp); - return res; + GtkTextBuffer *tb; + GtkTextIter ti1, ti2; + char *cp, *res; + //char *cp1; + + if (bt->text == 0) { + abort(); + } + + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); + gtk_text_buffer_get_bounds(tb, &ti1, &ti2); + cp = gtk_text_buffer_get_text(tb, &ti1, &ti2, FALSE); + //cp1 = wlibConvertOutput(cp); + res = strdup(cp); + g_free(cp); + return res; } /** @@ -165,20 +166,20 @@ static char *wlibGetText(wText_p bt) wBool_t wTextSave(wText_p bt, const char *fileName) { - FILE *f; - char *cp; - f = fopen(fileName, "w"); - - if (f==NULL) { - wNoticeEx(NT_ERROR, fileName, "Ok", NULL); - return FALSE; - } - - cp = wlibGetText(bt); - fwrite(cp, 1, strlen(cp), f); - free(cp); - fclose(f); - return TRUE; + FILE *f; + char *cp; + f = fopen(fileName, "w"); + + if (f==NULL) { + wNoticeEx(NT_ERROR, fileName, "Ok", NULL); + return FALSE; + } + + cp = wlibGetText(bt); + fwrite(cp, 1, strlen(cp), f); + free(cp); + fclose(f); + return TRUE; } /** @@ -196,28 +197,28 @@ begin_print(GtkPrintOperation *operation, GtkPrintContext *context, struct PrintData *pd) { - gchar *contents; - gdouble height; - contents = wlibGetText(pd->tb); - pd->lines = g_strsplit(contents, "\n", 0); - /* Count the total number of lines in the file. */ - /* ignore the header lines */ - pd->total_lines = 6; - - while (pd->lines[pd->total_lines] != NULL) { - pd->total_lines++; - } - - /* Based on the height of the page and font size, calculate how many lines can be - * rendered on a single page. A padding of 3 is placed between lines as well. - * Space for page header, table header and footer lines is subtracted from the total size - */ - height = gtk_print_context_get_height(context) - (pd->font_size + 3) - 2 * - (HEADER_HEIGHT + HEADER_GAP); - pd->lines_per_page = floor(height / (pd->font_size + 3)); - pd->total_pages = (pd->total_lines - 1) / pd->lines_per_page + 1; - gtk_print_operation_set_n_pages(operation, pd->total_pages); - free(contents); + gchar *contents; + gdouble height; + contents = wlibGetText(pd->tb); + pd->lines = g_strsplit(contents, "\n", 0); + /* Count the total number of lines in the file. */ + /* ignore the header lines */ + pd->total_lines = 6; + + while (pd->lines[pd->total_lines] != NULL) { + pd->total_lines++; + } + + /* Based on the height of the page and font size, calculate how many lines can be + * rendered on a single page. A padding of 3 is placed between lines as well. + * Space for page header, table header and footer lines is subtracted from the total size + */ + height = gtk_print_context_get_height(context) - (pd->font_size + 3) - 2 * + (HEADER_HEIGHT + HEADER_GAP); + pd->lines_per_page = floor(height / (pd->font_size + 3)); + pd->total_pages = (pd->total_lines - 1) / pd->lines_per_page + 1; + gtk_print_operation_set_n_pages(operation, pd->total_pages); + free(contents); } /** @@ -238,76 +239,76 @@ draw_page(GtkPrintOperation *operation, gint page_nr, struct PrintData *pd) { - cairo_t *cr; - PangoLayout *layout; - gdouble width, text_height, height; - gint line, i, text_width, layout_height; - PangoFontDescription *desc; - gchar *page_str; - cr = gtk_print_context_get_cairo_context(context); - width = gtk_print_context_get_width(context); - layout = gtk_print_context_create_pango_layout(context); - desc = pango_font_description_from_string("Monospace"); - pango_font_description_set_size(desc, pd->font_size * PANGO_SCALE); - /* - * render the header line with document type parts list on left and - * first line of layout title on right - */ - pango_layout_set_font_description(layout, desc); - pango_layout_set_text(layout, pd->lines[ 0 ], -1); // document type - pango_layout_set_width(layout, -1); - pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); - pango_layout_get_size(layout, NULL, &layout_height); - text_height = (gdouble) layout_height / PANGO_SCALE; - cairo_move_to(cr, 0, (HEADER_HEIGHT - text_height) / 2); - pango_cairo_show_layout(cr, layout); - pango_layout_set_text(layout, pd->lines[ 2 ], -1); // layout title - pango_layout_get_size(layout, &text_width, NULL); - pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); - cairo_move_to(cr, width - (text_width / PANGO_SCALE), - (HEADER_HEIGHT - text_height) / 2); - pango_cairo_show_layout(cr, layout); - /* Render the column header */ - cairo_move_to(cr, 0, HEADER_HEIGHT + HEADER_GAP + pd->font_size + 3); - pango_layout_set_text(layout, pd->lines[ 6 ], -1); - pango_cairo_show_layout(cr, layout); - cairo_rel_move_to(cr, 0, pd->font_size + 3); - pango_layout_set_text(layout, pd->lines[ 7 ], -1); - pango_cairo_show_layout(cr, layout); - /* Render the page text with the specified font and size. */ - cairo_rel_move_to(cr, 0, pd->font_size + 3); - line = page_nr * pd->lines_per_page + 8; - - for (i = 0; i < pd->lines_per_page && line < pd->total_lines; i++) { - pango_layout_set_text(layout, pd->lines[line], -1); - pango_cairo_show_layout(cr, layout); - cairo_rel_move_to(cr, 0, pd->font_size + 3); - line++; - } - - /* - * Render the footer line with date on the left and page number - * on the right - */ - pango_layout_set_text(layout, pd->lines[ 5 ], -1); // date - pango_layout_set_width(layout, -1); - pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); - pango_layout_get_size(layout, NULL, &layout_height); - text_height = (gdouble) layout_height / PANGO_SCALE; - height = gtk_print_context_get_height(context); - cairo_move_to(cr, 0, height - ((HEADER_HEIGHT - text_height) / 2)); - pango_cairo_show_layout(cr, layout); - page_str = g_strdup_printf(_("%d of %d"), page_nr + 1, - pd->total_pages); // page number - pango_layout_set_text(layout, page_str, -1); - pango_layout_get_size(layout, &text_width, NULL); - pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); - cairo_move_to(cr, width - (text_width / PANGO_SCALE), - height - ((HEADER_HEIGHT - text_height) / 2)); - pango_cairo_show_layout(cr, layout); - g_free(page_str); - g_object_unref(layout); - pango_font_description_free(desc); + cairo_t *cr; + PangoLayout *layout; + gdouble width, text_height, height; + gint line, i, text_width, layout_height; + PangoFontDescription *desc; + gchar *page_str; + cr = gtk_print_context_get_cairo_context(context); + width = gtk_print_context_get_width(context); + layout = gtk_print_context_create_pango_layout(context); + desc = pango_font_description_from_string("Monospace"); + pango_font_description_set_size(desc, pd->font_size * PANGO_SCALE); + /* + * render the header line with document type parts list on left and + * first line of layout title on right + */ + pango_layout_set_font_description(layout, desc); + pango_layout_set_text(layout, pd->lines[ 0 ], -1); // document type + pango_layout_set_width(layout, -1); + pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); + pango_layout_get_size(layout, NULL, &layout_height); + text_height = (gdouble) layout_height / PANGO_SCALE; + cairo_move_to(cr, 0, (HEADER_HEIGHT - text_height) / 2); + pango_cairo_show_layout(cr, layout); + pango_layout_set_text(layout, pd->lines[ 2 ], -1); // layout title + pango_layout_get_size(layout, &text_width, NULL); + pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); + cairo_move_to(cr, width - (text_width / PANGO_SCALE), + (HEADER_HEIGHT - text_height) / 2); + pango_cairo_show_layout(cr, layout); + /* Render the column header */ + cairo_move_to(cr, 0, HEADER_HEIGHT + HEADER_GAP + pd->font_size + 3); + pango_layout_set_text(layout, pd->lines[ 6 ], -1); + pango_cairo_show_layout(cr, layout); + cairo_rel_move_to(cr, 0, pd->font_size + 3); + pango_layout_set_text(layout, pd->lines[ 7 ], -1); + pango_cairo_show_layout(cr, layout); + /* Render the page text with the specified font and size. */ + cairo_rel_move_to(cr, 0, pd->font_size + 3); + line = page_nr * pd->lines_per_page + 8; + + for (i = 0; i < pd->lines_per_page && line < pd->total_lines; i++) { + pango_layout_set_text(layout, pd->lines[line], -1); + pango_cairo_show_layout(cr, layout); + cairo_rel_move_to(cr, 0, pd->font_size + 3); + line++; + } + + /* + * Render the footer line with date on the left and page number + * on the right + */ + pango_layout_set_text(layout, pd->lines[ 5 ], -1); // date + pango_layout_set_width(layout, -1); + pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); + pango_layout_get_size(layout, NULL, &layout_height); + text_height = (gdouble) layout_height / PANGO_SCALE; + height = gtk_print_context_get_height(context); + cairo_move_to(cr, 0, height - ((HEADER_HEIGHT - text_height) / 2)); + pango_cairo_show_layout(cr, layout); + page_str = g_strdup_printf(_("%d of %d"), page_nr + 1, + pd->total_pages); // page number + pango_layout_set_text(layout, page_str, -1); + pango_layout_get_size(layout, &text_width, NULL); + pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); + cairo_move_to(cr, width - (text_width / PANGO_SCALE), + height - ((HEADER_HEIGHT - text_height) / 2)); + pango_cairo_show_layout(cr, layout); + g_free(page_str); + g_object_unref(layout); + pango_font_description_free(desc); } /** @@ -324,8 +325,8 @@ end_print(GtkPrintOperation *operation, GtkPrintContext *context, struct PrintData *pd) { - g_strfreev(pd->lines); - free(pd); + g_strfreev(pd->lines); + free(pd); } /** @@ -341,47 +342,47 @@ end_print(GtkPrintOperation *operation, */ wBool_t wTextPrint( - wText_p bt) + wText_p bt) { - GtkPrintOperation *operation; - GtkWidget *dialog; - GError *error = NULL; - gint res; - struct PrintData *data; - /* Create a new print operation, applying saved print settings if they exist. */ - operation = gtk_print_operation_new(); - WlibApplySettings(operation); - data = malloc(sizeof(struct PrintData)); - data->font_size = 10.0; - data->tb = bt; - g_signal_connect(G_OBJECT(operation), "begin_print", - G_CALLBACK(begin_print), (gpointer) data); - g_signal_connect(G_OBJECT(operation), "draw_page", - G_CALLBACK(draw_page), (gpointer) data); - g_signal_connect(G_OBJECT(operation), "end_print", - G_CALLBACK(end_print), (gpointer) data); - /* Run the default print operation that will print the selected file. */ - res = gtk_print_operation_run(operation, - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, - GTK_WINDOW(gtkMainW->gtkwin), &error); - - /* If the print operation was accepted, save the new print settings. */ - if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { - WlibSaveSettings(operation); - } - /* Otherwise, report that the print operation has failed. */ - else if (error) { - dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s",error->message); - g_error_free(error); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - } - g_object_ref_sink(operation); - g_object_unref(operation); - return TRUE; + GtkPrintOperation *operation; + GtkWidget *dialog; + GError *error = NULL; + gint res; + struct PrintData *data; + /* Create a new print operation, applying saved print settings if they exist. */ + operation = gtk_print_operation_new(); + WlibApplySettings(operation); + data = malloc(sizeof(struct PrintData)); + data->font_size = 10.0; + data->tb = bt; + g_signal_connect(G_OBJECT(operation), "begin_print", + G_CALLBACK(begin_print), (gpointer) data); + g_signal_connect(G_OBJECT(operation), "draw_page", + G_CALLBACK(draw_page), (gpointer) data); + g_signal_connect(G_OBJECT(operation), "end_print", + G_CALLBACK(end_print), (gpointer) data); + /* Run the default print operation that will print the selected file. */ + res = gtk_print_operation_run(operation, + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, + GTK_WINDOW(gtkMainW->gtkwin), &error); + + /* If the print operation was accepted, save the new print settings. */ + if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { + WlibSaveSettings(operation); + } + /* Otherwise, report that the print operation has failed. */ + else if (error) { + dialog = gtk_message_dialog_new(GTK_WINDOW(gtkMainW->gtkwin), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s",error->message); + g_error_free(error); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + } + g_object_ref_sink(operation); + g_object_unref(operation); + return TRUE; } @@ -394,10 +395,10 @@ wBool_t wTextPrint( int wTextGetSize(wText_p bt) { - char *cp = wlibGetText(bt); - int len = strlen(cp); - free(cp); - return len + 1; + char *cp = wlibGetText(bt); + int len = strlen(cp); + free(cp); + return len + 1; } /** @@ -411,15 +412,15 @@ int wTextGetSize(wText_p bt) void wTextGetText(wText_p bt, char *text, int len) { - char *cp; - cp = wlibGetText(bt); - strncpy(text, cp, len); + char *cp; + cp = wlibGetText(bt); + strncpy(text, cp, len); - if (len > 0) { - text[len - 1] = '\0'; - } + if (len > 0) { + text[len - 1] = '\0'; + } - free(cp); + free(cp); } /** @@ -432,13 +433,13 @@ void wTextGetText(wText_p bt, char *text, int len) void wTextSetReadonly(wText_p bt, wBool_t ro) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), !ro); + gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), !ro); - if (ro) { - bt->option |= BO_READONLY; - } else { - bt->option &= ~BO_READONLY; - } + if (ro) { + bt->option |= BO_READONLY; + } else { + bt->option &= ~BO_READONLY; + } } /** @@ -450,7 +451,7 @@ void wTextSetReadonly(wText_p bt, wBool_t ro) wBool_t wTextGetModified(wText_p bt) { - return bt->changed; + return bt->changed; } /** @@ -464,9 +465,9 @@ wBool_t wTextGetModified(wText_p bt) void wTextSetSize(wText_p bt, wWinPix_t w, wWinPix_t h) { - gtk_widget_set_size_request(bt->widget, w, h); - bt->w = w; - bt->h = h; + gtk_widget_set_size_request(bt->widget, w, h); + bt->w = w; + bt->h = h; } /** @@ -481,11 +482,12 @@ void wTextSetSize(wText_p bt, wWinPix_t w, wWinPix_t h) * \return */ -void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols, wWinPix_t *width, +void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols, + wWinPix_t *width, wWinPix_t *height) { - *width = rows * 7; - *height = cols * 14; + *width = rows * 7; + *height = cols * 14; } /** @@ -498,7 +500,7 @@ void wTextComputeSize(wText_p bt, wWinPix_t rows, wWinPix_t cols, wWinPix_t *wid void wTextSetPosition(wText_p bt, int pos) { - /* TODO TextSetPosition */ + /* TODO TextSetPosition */ } /** @@ -511,11 +513,11 @@ void wTextSetPosition(wText_p bt, int pos) static void textChanged(GtkWidget *widget, wText_p bt) { - if (bt == 0) { - return; - } + if (bt == 0) { + return; + } - bt->changed = TRUE; + bt->changed = TRUE; } /** @@ -544,61 +546,61 @@ wTextCreate(wWin_p parent, wWinPix_t width, wWinPix_t height) { - wText_p bt; - GtkTextBuffer *tb; - // create the widget - bt = wlibAlloc(parent, B_MULTITEXT, x, y, labelStr, sizeof *bt, NULL); - bt->width = width; - bt->height = height; - bt->option = option; - wlibComputePos((wControl_p)bt); - // create a scroll window with scroll bars that are automatically created - bt->widget = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bt->widget), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - // create a text view and place it inside the scroll widget - bt->text = gtk_text_view_new(); - - if (bt->text == 0) { - abort(); - } - - gtk_container_add(GTK_CONTAINER(bt->widget), bt->text); - // get the text buffer and add a bold tag to it - tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); - gtk_text_buffer_create_tag(tb, "bold", "weight", PANGO_WEIGHT_BOLD, NULL); - - // this seems to assume some fixed size fonts, not really helpful - if (option&BT_CHARUNITS) { - width *= 7; - height *= 14; - } - - // show the widgets - gtk_widget_show(bt->text); - gtk_widget_show(bt->widget); - // set the size??? - gtk_widget_set_size_request(GTK_WIDGET(bt->widget), - width+15/*requisition.width*/, height); - - // configure read-only mode - if (bt->option&BO_READONLY) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(bt->text), FALSE); - } - - if (labelStr) { - bt->labelW = wlibAddLabel((wControl_p)bt, labelStr); - } - - wlibAddHelpString(bt->widget, helpStr); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(bt->text), GTK_WRAP_WORD); - g_signal_connect(G_OBJECT(tb), "changed", G_CALLBACK(textChanged), bt); - // place the widget in a fixed position of the parent - gtk_fixed_put(GTK_FIXED(parent->widget), bt->widget, bt->realX, bt->realY); - wlibControlGetSize((wControl_p)bt); - wlibAddButton((wControl_p)bt); - // done, return the finished widget - return bt; + wText_p bt; + GtkTextBuffer *tb; + // create the widget + bt = wlibAlloc(parent, B_MULTITEXT, x, y, labelStr, sizeof *bt, NULL); + bt->width = width; + bt->height = height; + bt->option = option; + wlibComputePos((wControl_p)bt); + // create a scroll window with scroll bars that are automatically created + bt->widget = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bt->widget), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + // create a text view and place it inside the scroll widget + bt->text = gtk_text_view_new(); + + if (bt->text == 0) { + abort(); + } + + gtk_container_add(GTK_CONTAINER(bt->widget), bt->text); + // get the text buffer and add a bold tag to it + tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bt->text)); + gtk_text_buffer_create_tag(tb, "bold", "weight", PANGO_WEIGHT_BOLD, NULL); + + // this seems to assume some fixed size fonts, not really helpful + if (option&BT_CHARUNITS) { + width *= 7; + height *= 14; + } + + // show the widgets + gtk_widget_show(bt->text); + gtk_widget_show(bt->widget); + // set the size??? + gtk_widget_set_size_request(GTK_WIDGET(bt->widget), + width+15/*requisition.width*/, height); + + // configure read-only mode + if (bt->option&BO_READONLY) { + gtk_text_view_set_editable(GTK_TEXT_VIEW(bt->text), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(bt->text), FALSE); + } + + if (labelStr) { + bt->labelW = wlibAddLabel((wControl_p)bt, labelStr); + } + + wlibAddHelpString(bt->widget, helpStr); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(bt->text), GTK_WRAP_WORD); + g_signal_connect(G_OBJECT(tb), "changed", G_CALLBACK(textChanged), bt); + // place the widget in a fixed position of the parent + gtk_fixed_put(GTK_FIXED(parent->widget), bt->widget, bt->realX, bt->realY); + wlibControlGetSize((wControl_p)bt); + wlibAddButton((wControl_p)bt); + // done, return the finished widget + return bt; } diff --git a/app/wlib/gtklib/timer.c b/app/wlib/gtklib/timer.c index 80c71fb..9e70458 100644 --- a/app/wlib/gtklib/timer.c +++ b/app/wlib/gtklib/timer.c @@ -52,14 +52,14 @@ static setTriggerCallback_p triggerFunc = NULL; */ static gint doAlarm( - gpointer data) + gpointer data) { - wAlarmCallBack_p func = (wAlarmCallBack_p)data; + wAlarmCallBack_p func = (wAlarmCallBack_p)data; - func(); + func(); - alarmTimer = 0; - return FALSE; + alarmTimer = 0; + return FALSE; } /** @@ -70,34 +70,34 @@ static gint doAlarm( */ void wAlarm( - long count, - wAlarmCallBack_p func) /* milliseconds */ + long count, + wAlarmCallBack_p func) /* milliseconds */ { - gtkPaused = TRUE; + gtkPaused = TRUE; - if (alarmTimer) { - g_source_remove(alarmTimer); - } + if (alarmTimer) { + g_source_remove(alarmTimer); + } - alarmTimer = g_timeout_add(count, doAlarm, (void *)(GSourceFunc)func); + alarmTimer = g_timeout_add(count, doAlarm, (void *)(GSourceFunc)func); } static void doTrigger(void) { - if (triggerControl && triggerFunc) { - triggerFunc(triggerControl); - triggerFunc = NULL; - triggerControl = NULL; - } + if (triggerControl && triggerFunc) { + triggerFunc(triggerControl); + triggerFunc = NULL; + triggerControl = NULL; + } } void wlibSetTrigger( - wControl_p b, - setTriggerCallback_p trigger) + wControl_p b, + setTriggerCallback_p trigger) { - triggerControl = b; - triggerFunc = trigger; - wAlarm(500, doTrigger); + triggerControl = b; + triggerFunc = trigger; + wAlarm(500, doTrigger); } /** @@ -107,27 +107,28 @@ void wlibSetTrigger( */ void wPause( - long count) /* milliseconds */ + long count) /* milliseconds */ { - while (gtk_events_pending()) - gtk_main_iteration(); //Allow GTK to finish before pausing - - struct timeval timeout; - sigset_t signal_mask; - sigset_t oldsignal_mask; - gdk_display_sync(gdk_display_get_default()); - timeout.tv_sec = count/1000; - timeout.tv_usec = (count%1000)*1000; - sigemptyset(&signal_mask); - sigaddset(&signal_mask, SIGIO); - sigaddset(&signal_mask, SIGALRM); - sigprocmask(SIG_BLOCK, &signal_mask, &oldsignal_mask); - - if (select(0, NULL, NULL, NULL, &timeout) == -1) { - perror("wPause:select"); - } - - sigprocmask(SIG_BLOCK, &oldsignal_mask, NULL); + while (gtk_events_pending()) { + gtk_main_iteration(); //Allow GTK to finish before pausing + } + + struct timeval timeout; + sigset_t signal_mask; + sigset_t oldsignal_mask; + gdk_display_sync(gdk_display_get_default()); + timeout.tv_sec = count/1000; + timeout.tv_usec = (count%1000)*1000; + sigemptyset(&signal_mask); + sigaddset(&signal_mask, SIGIO); + sigaddset(&signal_mask, SIGALRM); + sigprocmask(SIG_BLOCK, &signal_mask, &oldsignal_mask); + + if (select(0, NULL, NULL, NULL, &timeout) == -1) { + perror("wPause:select"); + } + + sigprocmask(SIG_BLOCK, &oldsignal_mask, NULL); } /** @@ -139,9 +140,9 @@ void wPause( unsigned long wGetTimer(void) { - struct timeval tv; - struct timezone tz; - - gettimeofday(&tv, &tz); - return (tv.tv_sec-startTime.tv_sec+1) * 1000 + tv.tv_usec /1000; + struct timeval tv; + struct timezone tz; + + gettimeofday(&tv, &tz); + return (tv.tv_sec-startTime.tv_sec+1) * 1000 + tv.tv_usec /1000; } diff --git a/app/wlib/gtklib/tooltip.c b/app/wlib/gtklib/tooltip.c index cd12d0a..75c8870 100644 --- a/app/wlib/gtklib/tooltip.c +++ b/app/wlib/gtklib/tooltip.c @@ -17,7 +17,7 @@ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -54,11 +54,11 @@ static wBool_t balloonVisible = FALSE; /**
* Hide the currently displayed Balloon Help.
*/
-
+
void
wlibHelpHideBalloon()
{
- wControlSetBalloon( balloonB, 0, 0, NULL );
+ wControlSetBalloon( balloonB, 0, 0, NULL );
}
/**
@@ -70,7 +70,7 @@ wlibHelpHideBalloon() void wSetBalloonHelp( wBalloonHelp_t * bh )
{
- balloonHelpStrings = bh;
+ balloonHelpStrings = bh;
}
/**
@@ -82,7 +82,7 @@ void wSetBalloonHelp( wBalloonHelp_t * bh ) void wEnableBalloonHelp( int enable )
{
- enableBalloonHelp = enable;
+ enableBalloonHelp = enable;
}
/**
@@ -93,10 +93,10 @@ void wEnableBalloonHelp( int enable ) */
void wControlSetHelp(
- wControl_p b,
- const char * help )
+ wControl_p b,
+ const char * help )
{
- wControlSetBalloonText( b, help );
+ wControlSetBalloonText( b, help );
}
/**
@@ -107,13 +107,13 @@ void wControlSetHelp( */
void wControlSetBalloonText(
- wControl_p b,
- const char * label )
+ wControl_p b,
+ const char * label )
{
- assert(b->widget != NULL);
+ assert(b->widget != NULL);
- gtk_widget_set_tooltip_text( b->widget, label );
+ gtk_widget_set_tooltip_text( b->widget, label );
}
/**
@@ -128,93 +128,93 @@ void wControlSetBalloonText( * \return
*/
-void wControlSetBalloon( wControl_p b, wWinPix_t dx, wWinPix_t dy, const char * msg )
+void wControlSetBalloon( wControl_p b, wWinPix_t dx, wWinPix_t dy,
+ const char * msg )
{
- PangoLayout * layout;
-
- gint x, y;
- gint w, h;
- wWinPix_t xx, yy;
- const char * msgConverted;
- GtkRequisition size;
-
- /* return if there is nothing to do */
- if (balloonVisible && balloonB == b &&
- balloonDx == dx && balloonDy == dy && msg != NULL && !balloonMsg[0])
- if (strcmp(msg,balloonMsg)==0)
- return;
-
- /* hide the tooltip */
- if ( msg == NULL ) {
- if ( balloonF != NULL && balloonVisible) {
- gtk_widget_hide( balloonF );
- balloonVisible = FALSE;
- }
- balloonMsg[0] = '\0';
- return;
- }
- msgConverted = wlibConvertInput(msg);
-
- if ( balloonF == NULL ) {
+ gint x, y;
+ gint w, h;
+ wWinPix_t xx, yy;
+ const char * msgConverted;
+ GtkRequisition size;
+
+ /* return if there is nothing to do */
+ if (balloonVisible && balloonB == b &&
+ balloonDx == dx && balloonDy == dy && msg != NULL && !balloonMsg[0])
+ if (strcmp(msg,balloonMsg)==0) {
+ return;
+ }
+
+ /* hide the tooltip */
+ if ( msg == NULL ) {
+ if ( balloonF != NULL && balloonVisible) {
+ gtk_widget_hide( balloonF );
+ balloonVisible = FALSE;
+ }
+ balloonMsg[0] = '\0';
+ return;
+ }
+ msgConverted = wlibConvertInput(msg);
+
+ if ( balloonF == NULL ) {
//GtkWidget *alignment;
- GdkColor color;
- color.red = 0x00C5 * 65536/255;
- color.green = 0x006F * 65536/255;
- color.blue = 0x0078 * 65536/255;
-
- balloonF = gtk_window_new( GTK_WINDOW_POPUP );
- gtk_window_set_type_hint( GTK_WINDOW( balloonF), GDK_WINDOW_TYPE_HINT_TOOLTIP );
- gtk_window_set_decorated (GTK_WINDOW (balloonF), FALSE );
- gtk_window_set_resizable( GTK_WINDOW (balloonF), FALSE );
- gtk_window_set_accept_focus(GTK_WINDOW( balloonF), FALSE);
- gtk_widget_modify_bg(GTK_WIDGET(balloonF), GTK_STATE_NORMAL, &color);
-
+ GdkColor color;
+ color.red = 0x00C5 * 65536/255;
+ color.green = 0x006F * 65536/255;
+ color.blue = 0x0078 * 65536/255;
+
+ balloonF = gtk_window_new( GTK_WINDOW_POPUP );
+ gtk_window_set_type_hint( GTK_WINDOW( balloonF), GDK_WINDOW_TYPE_HINT_TOOLTIP );
+ gtk_window_set_decorated (GTK_WINDOW (balloonF), FALSE );
+ gtk_window_set_resizable( GTK_WINDOW (balloonF), FALSE );
+ gtk_window_set_accept_focus(GTK_WINDOW( balloonF), FALSE);
+ gtk_widget_modify_bg(GTK_WIDGET(balloonF), GTK_STATE_NORMAL, &color);
+
GtkWidget * alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
gtk_alignment_set_padding( GTK_ALIGNMENT(alignment), 6, 6, 6, 6 );
gtk_container_add (GTK_CONTAINER (balloonF), alignment);
-
+
gtk_widget_show (alignment);
-
- balloonPI = gtk_label_new(msgConverted);
- gtk_container_add( GTK_CONTAINER(alignment), balloonPI );
- gtk_widget_show_all( balloonPI );
- }
- gtk_label_set_text( GTK_LABEL(balloonPI), msgConverted );
-
- balloonDx = dx;
- balloonDy = dy;
- balloonB = b;
- snprintf(balloonMsg, sizeof(balloonMsg), "%s", msg);
- gtk_widget_get_requisition(balloonPI, &size );
- w = size.width;
- h = size.height;
-
- gtk_window_get_position( GTK_WINDOW(b->parent->gtkwin), &x, &y);
-
- x += b->realX + dx;
- y += b->realY + b->h - dy;
+
+ balloonPI = gtk_label_new(msgConverted);
+ gtk_container_add( GTK_CONTAINER(alignment), balloonPI );
+ gtk_widget_show_all( balloonPI );
+ }
+ gtk_label_set_text( GTK_LABEL(balloonPI), msgConverted );
+
+ balloonDx = dx;
+ balloonDy = dy;
+ balloonB = b;
+ snprintf(balloonMsg, sizeof(balloonMsg), "%s", msg);
+ gtk_widget_get_requisition(balloonPI, &size );
+ w = size.width;
+ h = size.height;
+
+ gtk_window_get_position( GTK_WINDOW(b->parent->gtkwin), &x, &y);
+
+ x += b->realX + dx;
+ y += b->realY + b->h - dy;
#ifdef __linux__
- y += 7; // balloon popup overlaps the control
+ y += 7; // balloon popup overlaps the control
#endif
- xx = gdk_screen_width();
- yy = gdk_screen_height();
- if ( x < 0 ) {
- x = 0;
- } else if ( x+w > xx ) {
- x = xx - w;
- }
- if ( y < 0 ) {
- y = 0;
- } else if ( y+h > yy ) {
- y = yy - h ;
- }
- gtk_window_move( GTK_WINDOW( balloonF ), x, y );
- gtk_widget_show_all( balloonF );
- gtk_widget_show( balloonPI );
-
- balloonVisible = TRUE;
+ xx = gdk_screen_width();
+ yy = gdk_screen_height();
+ if ( x < 0 ) {
+ x = 0;
+ } else if ( x+w > xx ) {
+ x = xx - w;
+ }
+ if ( y < 0 ) {
+ y = 0;
+ } else if ( y+h > yy ) {
+ y = yy - h ;
+ }
+ gtk_window_move( GTK_WINDOW( balloonF ), x, y );
+ gtk_widget_show_all( balloonF );
+ gtk_widget_show( balloonPI );
+
+ balloonVisible = TRUE;
}
/**
@@ -232,36 +232,41 @@ void wBalloonHelpUpdate( void ) */
void wlibAddHelpString(
- GtkWidget * widget,
- const char * helpStr )
+ GtkWidget * widget,
+ const char * helpStr )
{
- char *string;
- char *wAppName = wlibGetAppName();
- wBalloonHelp_t * bhp;
-
- if (helpStr==NULL || *helpStr==0)
- return;
- if ( balloonHelpStrings == NULL )
- return;
-
- // search for the helpStr, bhp points to the entry when found
- for ( bhp = balloonHelpStrings; bhp->name && strcmp(bhp->name,helpStr) != 0; bhp++ )
- ;
-
- if (listMissingHelpStrings && !bhp->name) {
- printf( "Missing Help String: %s\n", helpStr );
- return;
- }
-
- string = malloc( strlen(wAppName) + 5 + strlen(helpStr) + 1 );
- sprintf( string, "%sHelp/%s", wAppName, helpStr );
-
- if(bhp->value)
+ char *string;
+ char *wAppName = wlibGetAppName();
+ wBalloonHelp_t * bhp;
+
+ if (helpStr==NULL || *helpStr==0) {
+ return;
+ }
+ if ( balloonHelpStrings == NULL ) {
+ return;
+ }
+
+ // search for the helpStr, bhp points to the entry when found
+ for ( bhp = balloonHelpStrings; bhp->name
+ && strcmp(bhp->name,helpStr) != 0; bhp++ )
+ ;
+
+ if (listMissingHelpStrings && !bhp->name) {
+ printf( "Missing Help String: %s\n", helpStr );
+ return;
+ }
+
+ string = malloc( strlen(wAppName) + 5 + strlen(helpStr) + 1 );
+ sprintf( string, "%sHelp/%s", wAppName, helpStr );
+
+ if(bhp->value) {
gtk_widget_set_tooltip_text( widget, wlibConvertInput(_(bhp->value)) );
+ }
- g_object_set_data( G_OBJECT( widget ), HELPDATAKEY, string );
+ g_object_set_data( G_OBJECT( widget ), HELPDATAKEY, string );
- if (listHelpStrings)
- printf( "HELPSTR - %s\n", string );
+ if (listHelpStrings) {
+ printf( "HELPSTR - %s\n", string );
+ }
}
diff --git a/app/wlib/gtklib/treeview.c b/app/wlib/gtklib/treeview.c index e8e0625..b3f2d77 100644 --- a/app/wlib/gtklib/treeview.c +++ b/app/wlib/gtklib/treeview.c @@ -53,7 +53,7 @@ int wTreeViewGetCount(wList_p b) { - return b->count; + return b->count; } /** @@ -65,9 +65,9 @@ wTreeViewGetCount(wList_p b) void wTreeViewClear(wList_p b) { - assert(b != NULL); + assert(b != NULL); - wlibListStoreClear(b->listStore); + wlibListStoreClear(b->listStore); } /** @@ -81,15 +81,15 @@ wTreeViewClear(wList_p b) void * wTreeViewGetItemContext(wList_p b, int row) { - wListItem_p id_p; + wListItem_p id_p; - id_p = wlibListItemGet(b->listStore, row, NULL); + id_p = wlibListItemGet(b->listStore, row, NULL); - if (id_p) { - return id_p->itemData; - } else { - return NULL; - } + if (id_p) { + return id_p->itemData; + } else { + return NULL; + } } /** @@ -101,11 +101,11 @@ wTreeViewGetItemContext(wList_p b, int row) */ wIndex_t wListGetIndex( - wList_p b) + wList_p b) { - assert(b!=NULL); + assert(b!=NULL); - return b->last; + return b->last; } /** @@ -119,48 +119,48 @@ wIndex_t wListGetIndex( void wlibTreeViewSetSelected(wList_p b, int index) { - GtkTreeSelection *sel; - GtkTreeIter iter; + GtkTreeSelection *sel; + GtkTreeIter iter; - wListItem_p id_p; + wListItem_p id_p; - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->treeView)); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->treeView)); - if (gtk_tree_selection_count_selected_rows(sel)) { + if (gtk_tree_selection_count_selected_rows(sel)) { int inx; - - gtk_tree_selection_unselect_all(sel); - // and synchronize the internal data structures - wTreeViewGetCount(b); + gtk_tree_selection_unselect_all(sel); - for (inx=0; inx<b->count; inx++) { - id_p = wlibListItemGet(b->listStore, inx, NULL); - id_p->selected = FALSE; - } - } + // and synchronize the internal data structures + wTreeViewGetCount(b); - if (index != -1) { + for (inx=0; inx<b->count; inx++) { + id_p = wlibListItemGet(b->listStore, inx, NULL); + id_p->selected = FALSE; + } + } + + if (index != -1) { gint childs; - + childs = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(b->listStore), - NULL ); + NULL ); if(index < childs) { gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), - &iter, - NULL, - index); + &iter, + NULL, + index); gtk_tree_selection_select_iter(sel, - &iter); + &iter); id_p = wlibListItemGet(b->listStore, index, NULL); - + if (id_p) { id_p->selected = TRUE; } - } - } + } + } } /** @@ -175,35 +175,37 @@ wlibTreeViewSetSelected(wList_p b, int index) GtkWidget * wlibNewTreeView(GtkListStore *ls, int showTitles, int multiSelection) { - GtkWidget *treeView; - GtkTreeSelection *sel; - assert(ls != NULL); + GtkWidget *treeView; + GtkTreeSelection *sel; + assert(ls != NULL); - /* create and configure the tree view */ - treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), showTitles); + /* create and configure the tree view */ + treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), showTitles); - /* set up selection handling */ - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView)); - gtk_tree_selection_set_mode(sel, - (multiSelection)?GTK_SELECTION_MULTIPLE:GTK_SELECTION_BROWSE); + /* set up selection handling */ + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView)); + gtk_tree_selection_set_mode(sel, + (multiSelection)?GTK_SELECTION_MULTIPLE:GTK_SELECTION_BROWSE); - return (treeView); + return (treeView); } +#if 0 static int changeListColumnWidth( - GtkTreeViewColumn * column, - void * width) + GtkTreeViewColumn * column, + void * width) { - //wList_p bl = (wList_p)data; + //wList_p bl = (wList_p)data; - //if (bl->recursion) - //return 0; - //if ( col >= 0 && col < bl->colCnt ) - //bl->colWidths[col] = width; - return 0; + //if (bl->recursion) + //return 0; + //if ( col >= 0 && col < bl->colCnt ) + //bl->colWidths[col] = width; + return 0; } +#endif /** * Create and initialize a column in treeview. Initially all columns are @@ -220,17 +222,17 @@ static void wlibAddColumn(GtkWidget *tv, int visibility, GtkCellRenderer *renderer, char *attribute, int value) { - GtkTreeViewColumn *column; + GtkTreeViewColumn *column; - column = gtk_tree_view_column_new(); - gtk_tree_view_column_pack_start(column, - renderer, - TRUE); - gtk_tree_view_column_add_attribute(column, renderer, attribute, value); - gtk_tree_view_column_set_visible(column, visibility); - gtk_tree_view_column_set_resizable(column, TRUE); + column = gtk_tree_view_column_new(); + gtk_tree_view_column_pack_start(column, + renderer, + TRUE); + gtk_tree_view_column_add_attribute(column, renderer, attribute, value); + gtk_tree_view_column_set_visible(column, visibility); + gtk_tree_view_column_set_resizable(column, TRUE); - gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column); + gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column); // g_signal_connect( column, "notify::width", G_CALLBACK(changeListColumnWidth), tv ); } @@ -247,22 +249,22 @@ wlibAddColumn(GtkWidget *tv, int visibility, GtkCellRenderer *renderer, int wlibTreeViewAddColumns(GtkWidget *tv, int count) { - GtkCellRenderer *renderer; - int i; + GtkCellRenderer *renderer; + int i; - assert(tv != NULL); - renderer = gtk_cell_renderer_pixbuf_new(); - /* first visible column is used for bitmaps */ - wlibAddColumn(tv, FALSE, renderer, "pixbuf", LISTCOL_BITMAP); + assert(tv != NULL); + renderer = gtk_cell_renderer_pixbuf_new(); + /* first visible column is used for bitmaps */ + wlibAddColumn(tv, FALSE, renderer, "pixbuf", LISTCOL_BITMAP); - renderer = gtk_cell_renderer_text_new(); + renderer = gtk_cell_renderer_text_new(); - /* add renderers to all columns */ - for (i = 0; i < count; i++) { - wlibAddColumn(tv, TRUE, renderer, "text", i + LISTCOL_TEXT); - } + /* add renderers to all columns */ + for (i = 0; i < count; i++) { + wlibAddColumn(tv, TRUE, renderer, "text", i + LISTCOL_TEXT); + } - return i; + return i; } /** @@ -276,26 +278,26 @@ wlibTreeViewAddColumns(GtkWidget *tv, int count) int wlibAddColumnTitles(GtkWidget *tv, const char **titles) { - int i = 0; - - assert(tv != NULL); - - if (titles) { - while (*titles) { - GtkTreeViewColumn *column; - - column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), i + 1); - - if (column) { - gtk_tree_view_column_set_title(column, titles[ i ]); - i++; - } else { - break; - } - } - } - - return i; + int i = 0; + + assert(tv != NULL); + + if (titles) { + while (*titles) { + GtkTreeViewColumn *column; + + column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), i + 1); + + if (column) { + gtk_tree_view_column_set_title(column, titles[ i ]); + i++; + } else { + break; + } + } + } + + return i; } /** @@ -313,20 +315,20 @@ int wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf, wListItem_p userData) { - GtkListStore *listStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW( - tv))); + GtkListStore *listStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW( + tv))); + + wlibListStoreAddData(listStore, pixbuf, cols, userData); - wlibListStoreAddData(listStore, pixbuf, cols, userData); + if (pixbuf) { + GtkTreeViewColumn *column; - if (pixbuf) { - GtkTreeViewColumn *column; - - // first column in list store has pixbuf - column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), 0); - gtk_tree_view_column_set_visible(column, - TRUE); - } - return 0; + // first column in list store has pixbuf + column = gtk_tree_view_get_column(GTK_TREE_VIEW(tv), 0); + gtk_tree_view_column_set_visible(column, + TRUE); + } + return 0; } @@ -344,28 +346,28 @@ wlibTreeViewAddData(GtkWidget *tv, int cols, char *label, GdkPixbuf *pixbuf, void wlibTreeViewAddRow(wList_p b, char *label, wIcon_p bm, wListItem_p id_p) { - GtkAdjustment *adj; - GdkPixbuf *pixbuf = NULL; + GtkAdjustment *adj; + GdkPixbuf *pixbuf = NULL; - if (bm) { - pixbuf = wlibMakePixbuf(bm); - } + if (bm) { + pixbuf = wlibMakePixbuf(bm); + } - wlibTreeViewAddData(b->treeView, b->colCnt, (char *)label, pixbuf, id_p); + wlibTreeViewAddData(b->treeView, b->colCnt, (char *)label, pixbuf, id_p); - adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(b->widget)); + adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(b->widget)); - if (gtk_adjustment_get_upper(adj) < gtk_adjustment_get_step_increment(adj) * - (b->count+1)) { - gtk_adjustment_set_upper(adj, - gtk_adjustment_get_upper(adj) + - gtk_adjustment_get_step_increment(adj)); - gtk_adjustment_changed(adj); - } + if (gtk_adjustment_get_upper(adj) < gtk_adjustment_get_step_increment(adj) * + (b->count+1)) { + gtk_adjustment_set_upper(adj, + gtk_adjustment_get_upper(adj) + + gtk_adjustment_get_step_increment(adj)); + gtk_adjustment_changed(adj); + } - b->last = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW( - b->treeView)), - NULL); + b->last = gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW( + b->treeView)), + NULL); } @@ -390,36 +392,34 @@ changeSelection(GtkTreeSelection *selection, gboolean path_currently_selected, gpointer data) { - GtkTreeIter iter; - GValue value = { 0 }; - wListItem_p id_p = NULL; - wList_p bl = (wList_p)data; - int row; - char *text; + GtkTreeIter iter; + GValue value = { 0 }; + wListItem_p id_p = NULL; + wList_p bl = (wList_p)data; + int row; + char *text; - text = gtk_tree_path_to_string(path); - row = atoi(text); - g_free(text); + text = gtk_tree_path_to_string(path); + row = atoi(text); + g_free(text); - gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get_value(model, &iter, LISTCOL_DATA, &value); + gtk_tree_model_get_iter(model, &iter, path); + gtk_tree_model_get_value(model, &iter, LISTCOL_DATA, &value); - id_p = g_value_get_pointer(&value); - id_p->selected = !path_currently_selected; + id_p = g_value_get_pointer(&value); + id_p->selected = !path_currently_selected; - if (id_p->selected) { - bl->last = row; + bl->last = row; - if (bl->valueP) { - *bl->valueP = row; - } + if (bl->valueP) { + *bl->valueP = row; + } - if (bl->action) { - bl->action(row, id_p->label, 1, bl->data, id_p->itemData); - } - } + if (bl->action) { + bl->action(row, id_p->label, id_p->selected, bl->data, id_p->itemData); + } - return TRUE; + return TRUE; } /** @@ -444,88 +444,88 @@ changeSelection(GtkTreeSelection *selection, */ wList_p wListCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - long option, - long number, - wWinPix_t width, - int colCnt, - wWinPix_t * colWidths, - wBool_t * colRightJust, - const char ** colTitles, - long *valueP, - wListCallBack_p action, - void *data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + long option, + long number, + wWinPix_t width, + int colCnt, + wWinPix_t * colWidths, + wBool_t * colRightJust, + const char ** colTitles, + long *valueP, + wListCallBack_p action, + void *data) { - GtkTreeSelection *sel; - wList_p bl; - static wWinPix_t zeroPos = 0; + GtkTreeSelection *sel; + wList_p bl; + static wWinPix_t zeroPos = 0; - assert(width != 0); + assert(width != 0); - bl = (wList_p)wlibAlloc(parent, B_LIST, x, y, labelStr, sizeof *bl, data); - bl->option = option; - bl->number = number; - bl->count = 0; - bl->last = -1; - bl->valueP = valueP; - bl->action = action; - bl->listX = bl->realX; + bl = (wList_p)wlibAlloc(parent, B_LIST, x, y, labelStr, sizeof *bl, data); + bl->option = option; + bl->number = number; + bl->count = 0; + bl->last = -1; + bl->valueP = valueP; + bl->action = action; + bl->listX = bl->realX; - if (colCnt <= 0) { - colCnt = 1; - colWidths = &zeroPos; - } + if (colCnt <= 0) { + colCnt = 1; + colWidths = &zeroPos; + } - bl->colCnt = colCnt; - bl->colWidths = (wWinPix_t*)malloc(colCnt * sizeof *(wWinPix_t*)0); - memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wWinPix_t*)0); + bl->colCnt = colCnt; + bl->colWidths = (wWinPix_t*)malloc(colCnt * sizeof *(wWinPix_t*)0); + memcpy(bl->colWidths, colWidths, colCnt * sizeof *(wWinPix_t*)0); - /* create the data structure for data */ - bl->listStore = wlibNewListStore(colCnt); - /* create the widget for the list store */ - bl->treeView = wlibNewTreeView(bl->listStore, - colTitles != NULL, - option & BL_MANY); + /* create the data structure for data */ + bl->listStore = wlibNewListStore(colCnt); + /* create the widget for the list store */ + bl->treeView = wlibNewTreeView(bl->listStore, + colTitles != NULL, + option & BL_MANY); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView)); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(bl->treeView)); - gtk_tree_selection_set_select_function(sel, - changeSelection, - bl, - NULL); + gtk_tree_selection_set_select_function(sel, + changeSelection, + bl, + NULL); - wlibTreeViewAddColumns(bl->treeView, colCnt); + wlibTreeViewAddColumns(bl->treeView, colCnt); - wlibAddColumnTitles(bl->treeView, colTitles); + wlibAddColumnTitles(bl->treeView, colTitles); - wlibComputePos((wControl_p)bl); + wlibComputePos((wControl_p)bl); - bl->widget = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bl->widget), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(bl->widget), - bl->treeView); + bl->widget = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bl->widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(bl->widget), + bl->treeView); - gtk_widget_set_size_request(bl->widget, width, (number+1)*ROW_HEIGHT); + gtk_widget_set_size_request(bl->widget, width, (number+1)*ROW_HEIGHT); /// g_signal_connect( GTK_OBJECT(bl->list), "resize_column", G_CALLBACK(changeListColumnWidth), bl ); - gtk_widget_show_all(bl->widget); + gtk_widget_show_all(bl->widget); - gtk_fixed_put(GTK_FIXED(parent->widget), bl->widget, bl->realX, bl->realY); - wlibControlGetSize((wControl_p)bl); + gtk_fixed_put(GTK_FIXED(parent->widget), bl->widget, bl->realX, bl->realY); + wlibControlGetSize((wControl_p)bl); - if (labelStr) { - bl->labelW = wlibAddLabel((wControl_p)bl, labelStr); - } + if (labelStr) { + bl->labelW = wlibAddLabel((wControl_p)bl, labelStr); + } - wlibAddButton((wControl_p)bl); - wlibAddHelpString(bl->widget, helpStr); + wlibAddButton((wControl_p)bl); + wlibAddHelpString(bl->widget, helpStr); - return bl; + return bl; } diff --git a/app/wlib/gtklib/uthash.h b/app/wlib/gtklib/uthash.h index 39fd891..bf74f7b 100644 --- a/app/wlib/gtklib/uthash.h +++ b/app/wlib/gtklib/uthash.h @@ -890,22 +890,22 @@ for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); #define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0) typedef struct UT_hash_bucket { - struct UT_hash_handle *hh_head; - unsigned count; - - /* expand_mult is normally set to 0. In this situation, the max chain length - * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If - * the bucket's chain exceeds this length, bucket expansion is triggered). - * However, setting expand_mult to a non-zero value delays bucket expansion - * (that would be triggered by additions to this particular bucket) - * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. - * (The multiplier is simply expand_mult+1). The whole idea of this - * multiplier is to reduce bucket expansions, since they are expensive, in - * situations where we know that a particular bucket tends to be overused. - * It is better to let its chain length grow to a longer yet-still-bounded - * value, than to do an O(n) bucket expansion too often. - */ - unsigned expand_mult; + struct UT_hash_handle *hh_head; + unsigned count; + + /* expand_mult is normally set to 0. In this situation, the max chain length + * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If + * the bucket's chain exceeds this length, bucket expansion is triggered). + * However, setting expand_mult to a non-zero value delays bucket expansion + * (that would be triggered by additions to this particular bucket) + * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. + * (The multiplier is simply expand_mult+1). The whole idea of this + * multiplier is to reduce bucket expansions, since they are expensive, in + * situations where we know that a particular bucket tends to be overused. + * It is better to let its chain length grow to a longer yet-still-bounded + * value, than to do an O(n) bucket expansion too often. + */ + unsigned expand_mult; } UT_hash_bucket; @@ -914,47 +914,47 @@ typedef struct UT_hash_bucket { #define HASH_BLOOM_SIGNATURE 0xb12220f2 typedef struct UT_hash_table { - UT_hash_bucket *buckets; - unsigned num_buckets, log2_num_buckets; - unsigned num_items; - struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ - ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ - - /* in an ideal situation (all buckets used equally), no bucket would have - * more than ceil(#items/#buckets) items. that's the ideal chain length. */ - unsigned ideal_chain_maxlen; - - /* nonideal_items is the number of items in the hash whose chain position - * exceeds the ideal chain maxlen. these items pay the penalty for an uneven - * hash distribution; reaching them in a chain traversal takes >ideal steps */ - unsigned nonideal_items; - - /* ineffective expands occur when a bucket doubling was performed, but - * afterward, more than half the items in the hash had nonideal chain - * positions. If this happens on two consecutive expansions we inhibit any - * further expansion, as it's not helping; this happens when the hash - * function isn't a good fit for the key domain. When expansion is inhibited - * the hash will still work, albeit no longer in constant time. */ - unsigned ineff_expands, noexpand; - - uint32_t signature; /* used only to find hash tables in external analysis */ + UT_hash_bucket *buckets; + unsigned num_buckets, log2_num_buckets; + unsigned num_items; + struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ + ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ + + /* in an ideal situation (all buckets used equally), no bucket would have + * more than ceil(#items/#buckets) items. that's the ideal chain length. */ + unsigned ideal_chain_maxlen; + + /* nonideal_items is the number of items in the hash whose chain position + * exceeds the ideal chain maxlen. these items pay the penalty for an uneven + * hash distribution; reaching them in a chain traversal takes >ideal steps */ + unsigned nonideal_items; + + /* ineffective expands occur when a bucket doubling was performed, but + * afterward, more than half the items in the hash had nonideal chain + * positions. If this happens on two consecutive expansions we inhibit any + * further expansion, as it's not helping; this happens when the hash + * function isn't a good fit for the key domain. When expansion is inhibited + * the hash will still work, albeit no longer in constant time. */ + unsigned ineff_expands, noexpand; + + uint32_t signature; /* used only to find hash tables in external analysis */ #ifdef HASH_BLOOM - uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ - uint8_t *bloom_bv; - char bloom_nbits; + uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ + uint8_t *bloom_bv; + char bloom_nbits; #endif } UT_hash_table; typedef struct UT_hash_handle { - struct UT_hash_table *tbl; - void *prev; /* prev element in app order */ - void *next; /* next element in app order */ - struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ - struct UT_hash_handle *hh_next; /* next hh in bucket order */ - void *key; /* ptr to enclosing struct's key */ - unsigned keylen; /* enclosing struct's key len */ - unsigned hashv; /* result of hash-fcn(key) */ + struct UT_hash_table *tbl; + void *prev; /* prev element in app order */ + void *next; /* next element in app order */ + struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ + struct UT_hash_handle *hh_next; /* next hh in bucket order */ + void *key; /* ptr to enclosing struct's key */ + unsigned keylen; /* enclosing struct's key len */ + unsigned hashv; /* result of hash-fcn(key) */ } UT_hash_handle; #endif /* UTHASH_H */ diff --git a/app/wlib/gtklib/util.c b/app/wlib/gtklib/util.c index 14ca689..3f746e6 100644 --- a/app/wlib/gtklib/util.c +++ b/app/wlib/gtklib/util.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -44,34 +44,36 @@ long debugWindow = 0; char wConfigName[ 256 ]; const char * wNames[] = { - "MAIN", - "POPUP", - "BUTT", - "CANCEL", - "POPUP", - "TEXT", - "INTEGER", - "FLOAT", - "LIST", - "DROPLIST", - "COMBOLIST", - "RADIO", - "TOGGLE", - "DRAW", - "MENU" - "MULTITEXT", - "MESSAGE", - "LINES", - "MENUITEM", - "BOX" + "MAIN", + "POPUP", + "BUTT", + "CANCEL", + "POPUP", + "TEXT", + "INTEGER", + "FLOAT", + "LIST", + "DROPLIST", + "COMBOLIST", + "RADIO", + "TOGGLE", + "DRAW", + "MENU" + "MULTITEXT", + "MESSAGE", + "LINES", + "MENUITEM", + "BOX" }; +#if 0 static wBool_t reverseIcon = #if defined(linux) - FALSE; + FALSE; #else - TRUE; + TRUE; +#endif #endif @@ -92,50 +94,49 @@ static wBool_t reverseIcon = */ GdkPixbuf* wlibPixbufFromXBM( - wIcon_p ip) + wIcon_p ip) { - GdkPixbuf * pixbuf; - - char line0[40]; - char line2[40]; - - char ** pixmapData; - int row, col, wb; - long rgb; - const char * bits; - - wb = (ip->w + 7) / 8; - pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData); - pixmapData[0] = line0; - rgb = wDrawGetRGB(ip->color); - sprintf(line0, " %ld %ld 2 1", ip->w, ip->h); - sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb >> 16)&0xFF, (rgb >> 8)&0xFF, - rgb & 0xFF); - pixmapData[1] = ". c None s None"; - pixmapData[2] = line2; - bits = ip->bits; - - for (row = 0; row < ip->h; row++) { - pixmapData[row + 3] = (char*) malloc((ip->w + 1) * sizeof **pixmapData); - - for (col = 0; col < ip->w; col++) { - if (bits[ row * wb + (col >> 3) ] & (1 << (col & 07))) { - pixmapData[row + 3][col] = '#'; - } - else { - pixmapData[row + 3][col] = '.'; - } - } - pixmapData[row + 3][ip->w] = 0; - } - - pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) pixmapData); - - for (row = 0; row < ip->h; row++) { - free(pixmapData[row + 3]); - } - free(pixmapData); - return pixbuf; + GdkPixbuf * pixbuf; + + char line0[40]; + char line2[40]; + + char ** pixmapData; + int row, col, wb; + long rgb; + const char * bits; + + wb = (ip->w + 7) / 8; + pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData); + pixmapData[0] = line0; + rgb = wDrawGetRGB(ip->color); + sprintf(line0, " %ld %ld 2 1", ip->w, ip->h); + sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb >> 16)&0xFF, (rgb >> 8)&0xFF, + rgb & 0xFF); + pixmapData[1] = ". c None s None"; + pixmapData[2] = line2; + bits = ip->bits; + + for (row = 0; row < ip->h; row++) { + pixmapData[row + 3] = (char*) malloc((ip->w + 1) * sizeof **pixmapData); + + for (col = 0; col < ip->w; col++) { + if (bits[ row * wb + (col >> 3) ] & (1 << (col & 07))) { + pixmapData[row + 3][col] = '#'; + } else { + pixmapData[row + 3][col] = '.'; + } + } + pixmapData[row + 3][ip->w] = 0; + } + + pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) pixmapData); + + for (row = 0; row < ip->h; row++) { + free(pixmapData[row + 3]); + } + free(pixmapData); + return pixbuf; } /** @@ -148,23 +149,25 @@ GdkPixbuf* wlibPixbufFromXBM( int wlibAddLabel(wControl_p b, const char * labelStr) { - GtkRequisition requisition, reqwidget; - - if (labelStr == NULL) { - return 0; - } - - b->label = gtk_label_new(wlibConvertInput(labelStr)); - gtk_widget_size_request(b->label, &requisition); - if (b->widget) - gtk_widget_size_request(b->widget, &reqwidget); - else - reqwidget.height = requisition.height; - gtk_container_add(GTK_CONTAINER(b->parent->widget), b->label); - gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, - b->realX - requisition.width - 8, b->realY + (reqwidget.height/2 - requisition.height/2)); - gtk_widget_show(b->label); - return requisition.width + 8; + GtkRequisition requisition, reqwidget; + + if (labelStr == NULL) { + return 0; + } + + b->label = gtk_label_new(wlibConvertInput(labelStr)); + gtk_widget_size_request(b->label, &requisition); + if (b->widget) { + gtk_widget_size_request(b->widget, &reqwidget); + } else { + reqwidget.height = requisition.height; + } + gtk_container_add(GTK_CONTAINER(b->parent->widget), b->label); + gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label, + b->realX - requisition.width - 8, + b->realY + (reqwidget.height/2 - requisition.height/2)); + gtk_widget_show(b->label); + return requisition.width + 8; } /** @@ -181,44 +184,44 @@ int wlibAddLabel(wControl_p b, const char * labelStr) */ void * wlibAlloc( - wWin_p parent, - wType_e type, - wWinPix_t origX, - wWinPix_t origY, - const char * labelStr, - int size, - void * data) + wWin_p parent, + wType_e type, + wWinPix_t origX, + wWinPix_t origY, + const char * labelStr, + int size, + void * data) { - wControl_p w = (wControl_p) malloc(size); - char * cp; - memset(w, 0, size); + wControl_p w = (wControl_p) malloc(size); + char * cp; + memset(w, 0, size); - if (w == NULL) { - abort(); - } + if (w == NULL) { + abort(); + } - w->outline = FALSE; + w->outline = FALSE; - w->type = type; - w->parent = parent; - w->origX = origX; - w->origY = origY; + w->type = type; + w->parent = parent; + w->origX = origX; + w->origY = origY; - if (labelStr) { - cp = (char*) malloc(strlen(labelStr) + 1); - w->labelStr = cp; + if (labelStr) { + cp = (char*) malloc(strlen(labelStr) + 1); + w->labelStr = cp; - for (; *labelStr; labelStr++) - if (*labelStr != '&') { - *cp++ = *labelStr; - } + for (; *labelStr; labelStr++) + if (*labelStr != '&') { + *cp++ = *labelStr; + } - *cp = 0; - } + *cp = 0; + } - w->doneProc = NULL; - w->data = data; - return w; + w->doneProc = NULL; + w->data = data; + return w; } /** @@ -228,23 +231,22 @@ void * wlibAlloc( */ void wlibComputePos( - wControl_p b) + wControl_p b) { - wWin_p w = b->parent; - - if (b->origX >= 0) { - b->realX = b->origX; - } - else { - b->realX = w->lastX + (-b->origX) - 1; - } - - if (b->origY >= 0) { - b->realY = b->origY + BORDERSIZE + ((w->option & F_MENUBAR) ? w->menu_height : 0); - } - else { - b->realY = w->lastY + (-b->origY) - 1; - } + wWin_p w = b->parent; + + if (b->origX >= 0) { + b->realX = b->origX; + } else { + b->realX = w->lastX + (-b->origX) - 1; + } + + if (b->origY >= 0) { + b->realY = b->origY + BORDERSIZE + ((w->option & F_MENUBAR) ? w->menu_height : + 0); + } else { + b->realY = w->lastY + (-b->origY) - 1; + } } /** @@ -254,12 +256,12 @@ void wlibComputePos( */ void wlibControlGetSize( - wControl_p b) + wControl_p b) { - GtkRequisition requisition; - gtk_widget_size_request(b->widget, &requisition); - b->w = requisition.width; - b->h = requisition.height; + GtkRequisition requisition; + gtk_widget_size_request(b->widget, &requisition); + b->w = requisition.width; + b->h = requisition.height; } /** @@ -268,50 +270,49 @@ void wlibControlGetSize( */ void wlibAddButton( - wControl_p b) + wControl_p b) { - wWin_p win = b->parent; - wBool_t resize = FALSE; - - if (win->first == NULL) { - win->first = b; - } - else { - win->last->next = b; - } - - win->last = b; - b->next = NULL; - b->parent = win; - win->lastX = b->realX + b->w; - win->lastY = b->realY + b->h; - - if (win->option & F_AUTOSIZE) { - if (win->lastX > win->realX) { - win->realX = win->lastX; - - if (win->w != (win->realX + win->origX)) { - resize = TRUE; - win->w = (win->realX + win->origX); - } - } - - if (win->lastY > win->realY) { - win->realY = win->lastY; - - if (win->h != (win->realY + win->origY)) { - resize = TRUE; - win->h = (win->realY + win->origY); - } - } - - if (win->shown) { - if (resize) { - gtk_widget_set_size_request(win->gtkwin, win->w, win->h); - gtk_widget_set_size_request(win->widget, win->w, win->h); - } - } - } + wWin_p win = b->parent; + wBool_t resize = FALSE; + + if (win->first == NULL) { + win->first = b; + } else { + win->last->next = b; + } + + win->last = b; + b->next = NULL; + b->parent = win; + win->lastX = b->realX + b->w; + win->lastY = b->realY + b->h; + + if (win->option & F_AUTOSIZE) { + if (win->lastX > win->realX) { + win->realX = win->lastX; + + if (win->w != (win->realX + win->origX)) { + resize = TRUE; + win->w = (win->realX + win->origX); + } + } + + if (win->lastY > win->realY) { + win->realY = win->lastY; + + if (win->h != (win->realY + win->origY)) { + resize = TRUE; + win->h = (win->realY + win->origY); + } + } + + if (win->shown) { + if (resize) { + gtk_widget_set_size_request(win->gtkwin, win->w, win->h); + gtk_widget_set_size_request(win->widget, win->w, win->h); + } + } + } } /** @@ -323,26 +324,26 @@ void wlibAddButton( */ wControl_p wlibGetControlFromPos( - wWin_p win, - wWinPix_t x, - wWinPix_t y) + wWin_p win, + wWinPix_t x, + wWinPix_t y) { - wControl_p b; - wWinPix_t xx, yy; - - for (b = win->first; b != NULL; b = b->next) { - if (b->widget && gtk_widget_get_visible(b->widget)) { - xx = b->realX; - yy = b->realY; - - if (xx <= x && x < xx + b->w && - yy <= y && y < yy + b->h) { - return b; - } - } - } - - return NULL; + wControl_p b; + wWinPix_t xx, yy; + + for (b = win->first; b != NULL; b = b->next) { + if (b->widget && gtk_widget_get_visible(b->widget)) { + xx = b->realX; + yy = b->realY; + + if (xx <= x && x < xx + b->w && + yy <= y && y < yy + b->h) { + return b; + } + } + } + + return NULL; } @@ -360,7 +361,7 @@ wControl_p wlibGetControlFromPos( */ void wBeep(void) { - gdk_display_beep(gdk_display_get_default()); + gdk_display_beep(gdk_display_get_default()); } /** @@ -368,13 +369,13 @@ void wBeep(void) */ void wFlush( - void) + void) { - while (gtk_events_pending()) { - gtk_main_iteration_do(FALSE); - } + while (gtk_events_pending()) { + gtk_main_iteration_do(FALSE); + } - gdk_display_sync(gdk_display_get_default()); + gdk_display_sync(gdk_display_get_default()); } /** @@ -399,71 +400,71 @@ void wSetCursor(wDraw_p bd, wCursor_t cursor) static GdkCursor * gdkcursors[wCursorQuestion+1]; GdkCursor * gdkcursor; //GdkWindow * gdkwindow = gtk_widget_get_window(GTK_WIDGET(win->gtkwin));; - GdkWindow * gdkwindow = gdk_get_default_root_window(); - GdkDisplay * display = gdk_window_get_display(gdkwindow); - if ((cursor == wCursorNone) && dontHideCursor) return; //Ignore if we dont want to suppress +// GdkWindow * gdkwindow = gdk_get_default_root_window(); +// GdkDisplay * display = gdk_window_get_display(gdkwindow); + if ((cursor == wCursorNone) && dontHideCursor) { return; } //Ignore if we dont want to suppress if (!gdkcursors[cursor]) { switch(cursor) { - case wCursorAppStart: - //gdkcursor = gdk_cursor_new_from_name (display,"progress"); - gdkcursor = gdk_cursor_new(GDK_WATCH); - break; - case wCursorHand: - //gdkcursor = gdk_cursor_new_from_name (display,"pointer"); - gdkcursor = gdk_cursor_new(GDK_HAND2); - break; - case wCursorNo: - //gdkcursor = gdk_cursor_new_from_name (display,"not-allowed"); - gdkcursor = gdk_cursor_new(GDK_X_CURSOR); - break; - case wCursorSizeAll: - //gdkcursor = gdk_cursor_new_from_name (display,"move"); - gdkcursor = gdk_cursor_new(GDK_FLEUR); - break; - case wCursorSizeNESW: - //gdkcursor = gdk_cursor_new_from_name (display,"nesw-resize"); - gdkcursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER); - break; - case wCursorSizeNS: - //gdkcursor = gdk_cursor_new_from_name (display,"ns-resize"); - gdkcursor = gdk_cursor_new(GDK_DOUBLE_ARROW); - break; - case wCursorSizeNWSE: - //gdkcursor = gdk_cursor_new_from_name (display,"nwse-resize"); - gdkcursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER); - break; - case wCursorSizeWE: - //gdkcursor = gdk_cursor_new_from_name (display,"ew-resize"); - gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); - break; - case wCursorWait: - //gdkcursor = gdk_cursor_new_from_name (display,"wait"); - gdkcursor = gdk_cursor_new(GDK_WATCH); - break; - case wCursorIBeam: - //gdkcursor = gdk_cursor_new_from_name (display,"text"); - gdkcursor = gdk_cursor_new(GDK_XTERM); - break; - case wCursorCross: - //gdkcursor = gdk_cursor_new_from_name (display,"crosshair"); - gdkcursor = gdk_cursor_new(GDK_TCROSS); - break; - case wCursorQuestion: - //gdkcursor = gdk_cursor_new_from_name (display,"help"); - gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW); - break; - case wCursorNone: - gdkcursor = gdk_cursor_new(GDK_BLANK_CURSOR); - break; - case wCursorNormal: - default: - //gdkcursor = gdk_cursor_new_from_name (display,"default"); - gdkcursor = gdk_cursor_new(GDK_LEFT_PTR); - break; + case wCursorAppStart: + //gdkcursor = gdk_cursor_new_from_name (display,"progress"); + gdkcursor = gdk_cursor_new(GDK_WATCH); + break; + case wCursorHand: + //gdkcursor = gdk_cursor_new_from_name (display,"pointer"); + gdkcursor = gdk_cursor_new(GDK_HAND2); + break; + case wCursorNo: + //gdkcursor = gdk_cursor_new_from_name (display,"not-allowed"); + gdkcursor = gdk_cursor_new(GDK_X_CURSOR); + break; + case wCursorSizeAll: + //gdkcursor = gdk_cursor_new_from_name (display,"move"); + gdkcursor = gdk_cursor_new(GDK_FLEUR); + break; + case wCursorSizeNESW: + //gdkcursor = gdk_cursor_new_from_name (display,"nesw-resize"); + gdkcursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER); + break; + case wCursorSizeNS: + //gdkcursor = gdk_cursor_new_from_name (display,"ns-resize"); + gdkcursor = gdk_cursor_new(GDK_DOUBLE_ARROW); + break; + case wCursorSizeNWSE: + //gdkcursor = gdk_cursor_new_from_name (display,"nwse-resize"); + gdkcursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER); + break; + case wCursorSizeWE: + //gdkcursor = gdk_cursor_new_from_name (display,"ew-resize"); + gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); + break; + case wCursorWait: + //gdkcursor = gdk_cursor_new_from_name (display,"wait"); + gdkcursor = gdk_cursor_new(GDK_WATCH); + break; + case wCursorIBeam: + //gdkcursor = gdk_cursor_new_from_name (display,"text"); + gdkcursor = gdk_cursor_new(GDK_XTERM); + break; + case wCursorCross: + //gdkcursor = gdk_cursor_new_from_name (display,"crosshair"); + gdkcursor = gdk_cursor_new(GDK_TCROSS); + break; + case wCursorQuestion: + //gdkcursor = gdk_cursor_new_from_name (display,"help"); + gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW); + break; + case wCursorNone: + gdkcursor = gdk_cursor_new(GDK_BLANK_CURSOR); + break; + case wCursorNormal: + default: + //gdkcursor = gdk_cursor_new_from_name (display,"default"); + gdkcursor = gdk_cursor_new(GDK_LEFT_PTR); + break; } gdkcursors[cursor] = gdkcursor; - } else gdkcursor = gdkcursors[cursor]; + } else { gdkcursor = gdkcursors[cursor]; } gdk_window_set_cursor ( gtk_widget_get_window(bd->widget), gdkcursor); } @@ -475,7 +476,7 @@ void wSetCursor(wDraw_p bd, wCursor_t cursor) const char * wMemStats(void) { - return "No stats available"; + return "No stats available"; } /** @@ -490,9 +491,9 @@ void wGetDisplaySize(wWinPix_t * w, wWinPix_t * h) GdkScreen *screen = gdk_screen_get_default(); guint monitor = gdk_screen_get_primary_monitor(screen); GdkRectangle screen_geometry = { 0, 0, 0, 0 }; - + gdk_screen_get_monitor_geometry( screen, monitor, &screen_geometry ); - + *w = screen_geometry.width; *h = screen_geometry.height; } @@ -509,42 +510,41 @@ static dynArr_t conversionBuffer_da; char * wlibConvertInput(const char * inString) { - const char * cp; - char * cq; - int extCharCnt, inCharCnt; - - /* Already UTF-8 encoded? */ - if (g_utf8_validate(inString, -1, NULL)) - /* Yes, do not double-convert */ { - return (char*) inString; - } - - for (cp = inString, extCharCnt = 0; *cp; cp++) { - if (((*cp)&0x80) != '\0') { - extCharCnt++; - } - } - - inCharCnt = cp - inString; - - if (extCharCnt == '\0') { - return (char*) inString; - } - - DYNARR_SET(char, conversionBuffer_da, inCharCnt + extCharCnt + 1); - - for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) { - if (((*cp)&0x80) != 0) { - *cq++ = 0xC0 + (((*cp)&0xC0) >> 6); - *cq++ = 0x80 + ((*cp)&0x3F); - } - else { - *cq++ = *cp; - } - } - - *cq = 0; - return (char*) conversionBuffer_da.ptr; + const char * cp; + char * cq; + int extCharCnt, inCharCnt; + + /* Already UTF-8 encoded? */ + if (g_utf8_validate(inString, -1, NULL)) + /* Yes, do not double-convert */ { + return (char*) inString; + } + + for (cp = inString, extCharCnt = 0; *cp; cp++) { + if (((*cp)&0x80) != '\0') { + extCharCnt++; + } + } + + inCharCnt = cp - inString; + + if (extCharCnt == '\0') { + return (char*) inString; + } + + DYNARR_SET(char, conversionBuffer_da, inCharCnt + extCharCnt + 1); + + for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) { + if (((*cp)&0x80) != 0) { + *cq++ = 0xC0 + (((*cp)&0xC0) >> 6); + *cq++ = 0x80 + ((*cp)&0x3F); + } else { + *cq++ = *cp; + } + } + + *cq = 0; + return (char*) conversionBuffer_da.ptr; } /** @@ -556,36 +556,35 @@ char * wlibConvertInput(const char * inString) char * wlibConvertOutput(const char * inString) { - const char * cp; - char * cq; - int extCharCnt, inCharCnt; - - for (cp = inString, extCharCnt = 0; *cp; cp++) { - if (((*cp)&0xC0) == 0x80) { - extCharCnt++; - } - } - - inCharCnt = cp - inString; - - if (extCharCnt == '\0') { - return (char*) inString; - } - - DYNARR_SET(char, conversionBuffer_da, inCharCnt + 1); - - for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) { - if (((*cp)&0x80) != 0) { - *cq++ = 0xC0 + (((*cp)&0xC0) >> 6); - *cq++ = 0x80 + ((*cp)&0x3F); - } - else { - *cq++ = *cp; - } - } - - *cq = '\0'; - return (char*) conversionBuffer_da.ptr; + const char * cp; + char * cq; + int extCharCnt, inCharCnt; + + for (cp = inString, extCharCnt = 0; *cp; cp++) { + if (((*cp)&0xC0) == 0x80) { + extCharCnt++; + } + } + + inCharCnt = cp - inString; + + if (extCharCnt == '\0') { + return (char*) inString; + } + + DYNARR_SET(char, conversionBuffer_da, inCharCnt + 1); + + for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) { + if (((*cp)&0x80) != 0) { + *cq++ = 0xC0 + (((*cp)&0xC0) >> 6); + *cq++ = 0x80 + ((*cp)&0x3F); + } else { + *cq++ = *cp; + } + } + + *cq = '\0'; + return (char*) conversionBuffer_da.ptr; } /*-----------------------------------------------------------------*/ @@ -595,32 +594,32 @@ static dynArr_t accelData_da; #define accelData(N) DYNARR_N( accelData_t, accelData_da, N ) static guint accelKeyMap[] = { - 0, /* wAccelKey_None, */ - GDK_KEY_Delete, /* wAccelKey_Del, */ - GDK_KEY_Insert, /* wAccelKey_Ins, */ - GDK_KEY_Home, /* wAccelKey_Home, */ - GDK_KEY_End, /* wAccelKey_End, */ - GDK_KEY_Page_Up, /* wAccelKey_Pgup, */ - GDK_KEY_Page_Down, /* wAccelKey_Pgdn, */ - GDK_KEY_Up, /* wAccelKey_Up, */ - GDK_KEY_Down, /* wAccelKey_Down, */ - GDK_KEY_Right, /* wAccelKey_Right, */ - GDK_KEY_Left, /* wAccelKey_Left, */ - GDK_KEY_BackSpace, /* wAccelKey_Back, */ - GDK_KEY_F1, /* wAccelKey_F1, */ - GDK_KEY_F2, /* wAccelKey_F2, */ - GDK_KEY_F3, /* wAccelKey_F3, */ - GDK_KEY_F4, /* wAccelKey_F4, */ - GDK_KEY_F5, /* wAccelKey_F5, */ - GDK_KEY_F6, /* wAccelKey_F6, */ - GDK_KEY_F7, /* wAccelKey_F7, */ - GDK_KEY_F8, /* wAccelKey_F8, */ - GDK_KEY_F9, /* wAccelKey_F9, */ - GDK_KEY_F10, /* wAccelKey_F10, */ - GDK_KEY_F11, /* wAccelKey_F11, */ - GDK_KEY_F12, /* wAccelKey_F12, */ - GDK_KEY_KP_Add, /* wAccelKey_Numpad_Add */ - GDK_KEY_KP_Subtract /* wAccelKey_Numpad_Subtract */ + 0, /* wAccelKey_None, */ + GDK_KEY_Delete, /* wAccelKey_Del, */ + GDK_KEY_Insert, /* wAccelKey_Ins, */ + GDK_KEY_Home, /* wAccelKey_Home, */ + GDK_KEY_End, /* wAccelKey_End, */ + GDK_KEY_Page_Up, /* wAccelKey_Pgup, */ + GDK_KEY_Page_Down, /* wAccelKey_Pgdn, */ + GDK_KEY_Up, /* wAccelKey_Up, */ + GDK_KEY_Down, /* wAccelKey_Down, */ + GDK_KEY_Right, /* wAccelKey_Right, */ + GDK_KEY_Left, /* wAccelKey_Left, */ + GDK_KEY_BackSpace, /* wAccelKey_Back, */ + GDK_KEY_F1, /* wAccelKey_F1, */ + GDK_KEY_F2, /* wAccelKey_F2, */ + GDK_KEY_F3, /* wAccelKey_F3, */ + GDK_KEY_F4, /* wAccelKey_F4, */ + GDK_KEY_F5, /* wAccelKey_F5, */ + GDK_KEY_F6, /* wAccelKey_F6, */ + GDK_KEY_F7, /* wAccelKey_F7, */ + GDK_KEY_F8, /* wAccelKey_F8, */ + GDK_KEY_F9, /* wAccelKey_F9, */ + GDK_KEY_F10, /* wAccelKey_F10, */ + GDK_KEY_F11, /* wAccelKey_F11, */ + GDK_KEY_F12, /* wAccelKey_F12, */ + GDK_KEY_KP_Add, /* wAccelKey_Numpad_Add */ + GDK_KEY_KP_Subtract /* wAccelKey_Numpad_Subtract */ }; /** @@ -633,24 +632,24 @@ static guint accelKeyMap[] = { */ void wAttachAccelKey( - wAccelKey_e key, - int modifier, - wAccelKeyCallBack_p action, - void * data) + wAccelKey_e key, + int modifier, + wAccelKeyCallBack_p action, + void * data) { - accelData_t * ad; + accelData_t * ad; // if (key < 1 || key > wAccelKey_F12) { // fprintf(stderr, "wAttachAccelKey(%d) out of range\n", (int) key); // return; // } - DYNARR_APPEND(accelData_t, accelData_da, 10); - ad = &accelData(accelData_da.cnt - 1); - ad->key = key; - ad->modifier = modifier; - ad->action = action; - ad->data = data; + DYNARR_APPEND(accelData_t, accelData_da, 10); + ad = &accelData(accelData_da.cnt - 1); + ad->key = key; + ad->modifier = modifier; + ad->action = action; + ad->data = data; } /** @@ -661,30 +660,30 @@ void wAttachAccelKey( */ struct accelData_t * wlibFindAccelKey( - GdkEventKey * event) + GdkEventKey * event) { - accelData_t * ad; - int modifier = 0; + accelData_t * ad; + int modifier = 0; - if ((event->state & GDK_SHIFT_MASK)) { - modifier |= WKEY_SHIFT; - } + if ((event->state & GDK_SHIFT_MASK)) { + modifier |= WKEY_SHIFT; + } - if ((event->state & GDK_CONTROL_MASK)) { - modifier |= WKEY_CTRL; - } + if ((event->state & GDK_CONTROL_MASK)) { + modifier |= WKEY_CTRL; + } - if ((event->state & GDK_MOD1_MASK)) { - modifier |= WKEY_ALT; - } + if ((event->state & GDK_MOD1_MASK)) { + modifier |= WKEY_ALT; + } - for (ad = &accelData(0); ad<&accelData(accelData_da.cnt); ad++) - if (event->keyval == accelKeyMap[ad->key] && - modifier == ad->modifier) { - return ad; - } + for (ad = &accelData(0); ad<&accelData(accelData_da.cnt); ad++) + if (event->keyval == accelKeyMap[ad->key] && + modifier == ad->modifier) { + return ad; + } - return NULL; + return NULL; } /** @@ -695,16 +694,16 @@ struct accelData_t * wlibFindAccelKey( */ wBool_t wlibHandleAccelKey( - GdkEventKey *event) + GdkEventKey *event) { - accelData_t * ad = wlibFindAccelKey(event); + accelData_t * ad = wlibFindAccelKey(event); - if (ad) { - ad->action(ad->key, ad->data); - return TRUE; - } + if (ad) { + ad->action(ad->key, ad->data); + return TRUE; + } - return FALSE; + return FALSE; } /** @@ -721,13 +720,13 @@ wBool_t wlibHandleAccelKey( void wControlLinkedSet(wControl_p b1, wControl_p b2) { - b2->synonym = b1->synonym; + b2->synonym = b1->synonym; - if (b2->synonym == NULL) { - b2->synonym = b1; - } + if (b2->synonym == NULL) { + b2->synonym = b1; + } - b1->synonym = b2; + b1->synonym = b2; } /** @@ -740,26 +739,24 @@ void wControlLinkedSet(wControl_p b1, wControl_p b2) void wControlLinkedActive(wControl_p b, int active) { - wControl_p savePtr = b; + wControl_p savePtr = b; - if (savePtr->type == B_MENUITEM) { - wMenuPushEnable((wMenuPush_p) savePtr, active); - } - else { - wControlActive(savePtr, active); - } + if (savePtr->type == B_MENUITEM) { + wMenuPushEnable((wMenuPush_p) savePtr, active); + } else { + wControlActive(savePtr, active); + } - savePtr = savePtr->synonym; + savePtr = savePtr->synonym; - while (savePtr && savePtr != b) { + while (savePtr && savePtr != b) { - if (savePtr->type == B_MENUITEM) { - wMenuPushEnable((wMenuPush_p) savePtr, active); - } - else { - wControlActive(savePtr, active); - } + if (savePtr->type == B_MENUITEM) { + wMenuPushEnable((wMenuPush_p) savePtr, active); + } else { + wControlActive(savePtr, active); + } - savePtr = savePtr->synonym; - } + savePtr = savePtr->synonym; + } } diff --git a/app/wlib/gtklib/window.c b/app/wlib/gtklib/window.c index 16a21a5..b8a3cdf 100644 --- a/app/wlib/gtklib/window.c +++ b/app/wlib/gtklib/window.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -40,11 +40,8 @@ wWin_p gtkMainW; -#define MIN_WIN_WIDTH 150 -#define MIN_WIN_HEIGHT 150 - -#define MIN_WIN_WIDTH_MAIN 400 -#define MIN_WIN_HEIGHT_MAIN 400 +#define MIN_WIN_WIDTH 50 +#define MIN_WIN_HEIGHT 50 #define SECTIONWINDOWSIZE "gtklib window size" #define SECTIONWINDOWPOS "gtklib window pos" @@ -55,6 +52,9 @@ static wControl_p firstWin = NULL, lastWin; static int keyState; static wBool_t gtkBlockEnabled = TRUE; static wBool_t maximize_at_next_show = FALSE; + +#include "../../bin/bitmaps/xtc.xpm" +static GdkPixbuf *windowIconPixbuf = NULL; /* ***************************************************************************** @@ -70,7 +70,8 @@ static wBool_t maximize_at_next_show = FALSE; * */ -static GdkRectangle getMonitorDimensions(GtkWidget * widget) { +static GdkRectangle getMonitorDimensions(GtkWidget * widget) +{ GdkRectangle monitor_dimensions; @@ -81,9 +82,10 @@ static GdkRectangle getMonitorDimensions(GtkWidget * widget) { GtkWidget * toplevel = gtk_widget_get_toplevel(widget); if (gtk_widget_is_toplevel(GTK_WIDGET(toplevel)) && - gtk_widget_get_parent_window(GTK_WIDGET(toplevel))) { + gtk_widget_get_parent_window(GTK_WIDGET(toplevel))) { - GdkWindow * window = GDK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(toplevel))); + GdkWindow * window = GDK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET( + toplevel))); screen = gdk_window_get_screen(GDK_WINDOW(window)); @@ -113,46 +115,39 @@ static GdkRectangle getMonitorDimensions(GtkWidget * widget) { static void getWinSize(wWin_p win, const char * nameStr) { - int w=50, h=50; - const char *cp; - char *cp1, *cp2; - - - /* - * Clamp window to be no bigger than one monitor size (to start - the user can always maximize) - */ - - GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); - - wWinPix_t maxDisplayWidth = monitor_dimensions.width-10; - wWinPix_t maxDisplayHeight = monitor_dimensions.height-50; - - - - if ((win->option&F_RECALLSIZE) && - (win->option&F_RECALLPOS) && - (cp = wPrefGetString(SECTIONWINDOWSIZE, nameStr)) && - (w = strtod(cp, &cp1), cp != cp1) && - (h = strtod(cp1, &cp2), cp1 != cp2)) { - win->option &= ~F_AUTOSIZE; - - if (w < 50) { - w = 50; - } - - if (h < 50) { - h = 50; - } - } - - if (w > maxDisplayWidth) w = maxDisplayWidth; - if (h > maxDisplayHeight) h = maxDisplayHeight; - - if (w<MIN_WIDTH) w = MIN_WIDTH; - if (h<MIN_HEIGHT) h = MIN_HEIGHT; - - win->w = win->origX = w; - win->h = win->origY = h; + /* + * original w/h values in .origX/Y + */ + int w = win->w = win->origX; + int h = win->h = win->origY; + + /* + * Take values from Prefs if possible + */ + const char *cp; + char *cp1, *cp2; + if ((win->option&F_RESIZE) && + (win->option&F_RECALLSIZE) && + (cp = wPrefGetString(SECTIONWINDOWSIZE, nameStr)) && + (w = strtod(cp, &cp1), cp != cp1) && + (h = strtod(cp1, &cp2), cp1 != cp2)) { + win->option &= ~F_AUTOSIZE; + + /* + * Clamp window to be no bigger than one monitor size (to start - the user can always maximize) + */ + GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); + wWinPix_t maxDisplayWidth = monitor_dimensions.width-10; + wWinPix_t maxDisplayHeight = monitor_dimensions.height-50; + if (w > maxDisplayWidth) { w = maxDisplayWidth; } + if (h > maxDisplayHeight) { h = maxDisplayHeight; } + + if (w<MIN_WIDTH) { w = MIN_WIDTH; } + if (h<MIN_HEIGHT) { h = MIN_HEIGHT; } + + win->w = win->origX = w; + win->h = win->origY = h; + } } @@ -166,14 +161,14 @@ static void getWinSize(wWin_p win, const char * nameStr) static void saveSize(wWin_p win) { - if ((win->option&F_RECALLSIZE) && - gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) { - char pos_s[20]; + if ((win->option&F_RECALLSIZE) && + gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) { + char pos_s[32]; - sprintf(pos_s, "%ld %ld", win->w, - (win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0)))); - wPrefSetString(SECTIONWINDOWSIZE, win->nameStr, pos_s); - } + sprintf(pos_s, "%ld %ld", win->w, + (win->h-(BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0)))); + wPrefSetString(SECTIONWINDOWSIZE, win->nameStr, pos_s); + } } /** @@ -185,47 +180,46 @@ static void saveSize(wWin_p win) static void getPos(wWin_p win) { - char *cp1, *cp2; - GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); + char *cp1, *cp2; + GdkRectangle monitor_dimensions = getMonitorDimensions(GTK_WIDGET(win->gtkwin)); - if ((win->option&F_RECALLPOS) && (!win->shown)) { - const char *cp; + if ((win->option&F_RECALLPOS) && (!win->shown)) { + const char *cp; - if ((cp = wPrefGetString(SECTIONWINDOWPOS, win->nameStr))) { - int x, y; + if ((cp = wPrefGetString(SECTIONWINDOWPOS, win->nameStr))) { + int x, y; - x = strtod(cp, &cp1); + x = strtod(cp, &cp1); - if (cp == cp1) { - return; - } + if (cp == cp1) { + return; + } - y = strtod(cp1, &cp2); + y = strtod(cp1, &cp2); - if (cp2 == cp1) { - return; - } + if (cp2 == cp1) { + return; + } - if (y > monitor_dimensions.height+monitor_dimensions.y-win->h) { - y = monitor_dimensions.height+monitor_dimensions.y-win->h; - } + if (y > monitor_dimensions.height+monitor_dimensions.y-win->h) { + y = monitor_dimensions.height+monitor_dimensions.y-win->h; + } - if (x > monitor_dimensions.width+monitor_dimensions.x-win->w) { - x = monitor_dimensions.width+monitor_dimensions.x-win->w; - } + if (x > monitor_dimensions.width+monitor_dimensions.x-win->w) { + x = monitor_dimensions.width+monitor_dimensions.x-win->w; + } - if (x <= 0) { - x = 1; - } + if (x <= 0) { + x = 1; + } - if (y <= 0) { - y = 1; - } + if (y <= 0) { + y = 1; + } - gtk_window_move(GTK_WINDOW(win->gtkwin), x, y); - //gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h); - } - } + gtk_window_move(GTK_WINDOW(win->gtkwin), x, y); + } + } } /** @@ -237,17 +231,17 @@ static void getPos(wWin_p win) static void savePos(wWin_p win) { - int x, y; + int x, y; - if ((win->option&F_RECALLPOS)) { - char pos_s[20]; + if ((win->option&F_RECALLPOS)) { + char pos_s[32]; - gdk_window_get_position(gtk_widget_get_window(GTK_WIDGET(win->gtkwin)), &x, &y); - x -= 5; - y -= 25; - sprintf(pos_s, "%d %d", x, y); - wPrefSetString(SECTIONWINDOWPOS, win->nameStr, pos_s); - } + gdk_window_get_position(gtk_widget_get_window(GTK_WIDGET(win->gtkwin)), &x, &y); + x -= 5; + y -= 25; + sprintf(pos_s, "%d %d", x, y); + wPrefSetString(SECTIONWINDOWPOS, win->nameStr, pos_s); + } } /** @@ -259,28 +253,17 @@ static void savePos(wWin_p win) */ void wWinGetSize( - wWin_p win, /* Window */ - wWinPix_t * width, /* Returned window width */ - wWinPix_t * height) /* Returned window height */ + wWin_p win, /* Window */ + wWinPix_t * width, /* Returned window width */ + wWinPix_t * height) /* Returned window height */ { - GtkRequisition requisition; - wWinPix_t w, h; - gtk_widget_size_request(win->gtkwin, &requisition); - w = win->w; - h = win->h; - - if (win->option&F_AUTOSIZE) { - if (win->realX > w) { - w = win->realX; - } - - if (win->realY > h) { - h = win->realY; - } - } - - *width = w; - *height = h - BORDERSIZE - ((win->option&F_MENUBAR)?win->menu_height:0); + GtkRequisition requisition; + wWinPix_t w, h; + gtk_widget_size_request(win->gtkwin, &requisition); + w = win->w; + h = win->h; + *width = w; + *height = h - BORDERSIZE - ((win->option&F_MENUBAR)?win->menu_height:0); } /** @@ -292,24 +275,23 @@ void wWinGetSize( */ void wWinSetSize( - wWin_p win, /* Window */ - wWinPix_t width, /* Window width */ - wWinPix_t height) /* Window height */ + wWin_p win, /* Window */ + wWinPix_t width, /* Window width */ + wWinPix_t height) /* Window height */ { - win->busy = TRUE; - win->w = width; - win->h = height + BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0); - if (win->option&F_RESIZE) { - gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h); - gtk_widget_set_size_request(win->widget, win->w-10, win->h-10); - } - else { - gtk_widget_set_size_request(win->gtkwin, win->w, win->h); - gtk_widget_set_size_request(win->widget, win->w, win->h); - } - - - win->busy = FALSE; + win->busy = TRUE; + win->w = width; + win->h = height + BORDERSIZE + ((win->option&F_MENUBAR)?MENUH:0); + if (win->option&F_RESIZE) { + gtk_window_resize(GTK_WINDOW(win->gtkwin), win->w, win->h); + gtk_widget_set_size_request(win->widget, win->w-10, win->h-10); + } else { + gtk_widget_set_size_request(win->gtkwin, win->w, win->h); + gtk_widget_set_size_request(win->widget, win->w, win->h); + } + + + win->busy = FALSE; } /** @@ -322,93 +304,93 @@ void wWinSetSize( */ void wWinShow( - wWin_p win, /* Window */ - wBool_t show) /* Command */ + wWin_p win, /* Window */ + wBool_t show) /* Command */ { - //GtkRequisition min_req, pref_req; + //GtkRequisition min_req, pref_req; - if (debugWindow >= 2) { - printf("Set Show %s\n", win->labelStr?win->labelStr:"No label"); - } + if (debugWindow >= 2) { + printf("Set Show %s\n", win->labelStr?win->labelStr:"No label"); + } - if (win->widget == 0) { - abort(); - } + if (win->widget == 0) { + abort(); + } - int width, height; + int width, height; - if (show) { - keyState = 0; - getPos(win); + if (show) { + keyState = 0; + getPos(win); - if (!win->shown) { + if (!win->shown) { gtk_widget_show(win->gtkwin); gtk_widget_show(win->widget); } - if (win->option & F_AUTOSIZE) { - GtkAllocation allocation; - GtkRequisition requistion; - gtk_widget_size_request(win->widget,&requistion); + if (win->option & F_AUTOSIZE) { + GtkAllocation allocation; + GtkRequisition requistion; + gtk_widget_size_request(win->widget,&requistion); - width = win->w; - height = win->h; + width = win->w; + height = win->h; - if (requistion.width != width || requistion.height != height ) { + if (requistion.width != width || requistion.height != height ) { width = requistion.width; height = requistion.height; - win->w = width; - win->h = height; + win->w = width; + win->h = height; - gtk_window_set_resizable(GTK_WINDOW(win->gtkwin),TRUE); + gtk_window_set_resizable(GTK_WINDOW(win->gtkwin),TRUE); - if (win->option&F_MENUBAR) { - gtk_widget_set_size_request(win->menubar, win->w-20, MENUH); + if (win->option&F_MENUBAR) { + gtk_widget_set_size_request(win->menubar, win->w-20, MENUH); - gtk_widget_get_allocation(win->menubar, &allocation); - win->menu_height = allocation.height; - } - } - gtk_window_resize(GTK_WINDOW(win->gtkwin), width+10, height+10); - } + gtk_widget_get_allocation(win->menubar, &allocation); + win->menu_height = allocation.height; + } + } + gtk_window_resize(GTK_WINDOW(win->gtkwin), width+10, height+10); + } - gtk_window_present(GTK_WINDOW(win->gtkwin)); + gtk_window_present(GTK_WINDOW(win->gtkwin)); - gdk_window_raise(gtk_widget_get_window(win->gtkwin)); + gdk_window_raise(gtk_widget_get_window(win->gtkwin)); - if (win->shown && win->modalLevel > 0) { - gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE); - } + if (win->shown && win->modalLevel > 0) { + gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE); + } - win->shown = show; - win->modalLevel = 0; + win->shown = show; + win->modalLevel = 0; - if ((!gtkBlockEnabled) || (win->option & F_BLOCK) == 0) { - wFlush(); - } else { - wlibDoModal(win, TRUE); - } - if (maximize_at_next_show) { - gtk_window_maximize(GTK_WINDOW(win->gtkwin)); - maximize_at_next_show = FALSE; - } - } else { - wFlush(); - saveSize(win); - savePos(win); - win->shown = show; + if ((!gtkBlockEnabled) || (win->option & F_BLOCK) == 0) { + wFlush(); + } else { + wlibDoModal(win, TRUE); + } + if (maximize_at_next_show) { + gtk_window_maximize(GTK_WINDOW(win->gtkwin)); + maximize_at_next_show = FALSE; + } + } else { + wFlush(); + saveSize(win); + savePos(win); + win->shown = show; - if (gtkBlockEnabled && (win->option & F_BLOCK) != 0) { - wlibDoModal(win, FALSE); - } + if (gtkBlockEnabled && (win->option & F_BLOCK) != 0) { + wlibDoModal(win, FALSE); + } - gtk_widget_hide(win->gtkwin); - gtk_widget_hide(win->widget); - } + gtk_widget_hide(win->gtkwin); + gtk_widget_hide(win->widget); + } } /** @@ -418,9 +400,9 @@ void wWinShow( */ void wWinBlockEnable( - wBool_t enabled) + wBool_t enabled) { - gtkBlockEnabled = enabled; + gtkBlockEnabled = enabled; } /** @@ -431,9 +413,9 @@ void wWinBlockEnable( */ wBool_t wWinIsVisible( - wWin_p win) + wWin_p win) { - return win->shown; + return win->shown; } /** @@ -445,7 +427,7 @@ wBool_t wWinIsVisible( wBool_t wWinIsMaximized(wWin_p win) { - return win->maximize_initially; + return win->maximize_initially; } /** @@ -456,10 +438,10 @@ wBool_t wWinIsMaximized(wWin_p win) */ void wWinSetTitle( - wWin_p win, /* Window */ - const char * title) /* New title */ + wWin_p win, /* Window */ + const char * title) /* New title */ { - gtk_window_set_title(GTK_WINDOW(win->gtkwin), title); + gtk_window_set_title(GTK_WINDOW(win->gtkwin), title); } /** @@ -470,28 +452,28 @@ void wWinSetTitle( */ void wWinSetBusy( - wWin_p win, /* Window */ - wBool_t busy) /* Command */ + wWin_p win, /* Window */ + wBool_t busy) /* Command */ { - GdkCursor * cursor; + GdkCursor * cursor; - if (win->gtkwin == 0) { - abort(); - } + if (win->gtkwin == 0) { + abort(); + } - if (busy) { - cursor = gdk_cursor_new(GDK_WATCH); - } else { - cursor = NULL; - } + if (busy) { + cursor = gdk_cursor_new(GDK_WATCH); + } else { + cursor = NULL; + } - gdk_window_set_cursor(gtk_widget_get_window(win->gtkwin), cursor); + gdk_window_set_cursor(gtk_widget_get_window(win->gtkwin), cursor); - if (cursor) { - gdk_cursor_unref(cursor); - } + if (cursor) { + gdk_cursor_unref(cursor); + } - gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), busy==0); + gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), busy==0); } /** @@ -507,42 +489,42 @@ void wWinSetBusy( */ void wlibDoModal( - wWin_p win0, - wBool_t modal) + wWin_p win0, + wBool_t modal) { - wWin_p win; - - for (win=(wWin_p)firstWin; win; win=(wWin_p)win->next) { - if (win->shown && win != win0) { - if (modal) { - if (win->modalLevel == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), FALSE); - } - - win->modalLevel++; - } else { - if (win->modalLevel > 0) { - win->modalLevel--; - - if (win->modalLevel == 0) { - gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE); - } - } - } - - if (win->modalLevel < 0) { - fprintf(stderr, "DoModal: %s modalLevel < 0", - win->nameStr?win->nameStr:"<NULL>"); - abort(); - } - } - } - - if (modal) { - gtk_main(); - } else { - gtk_main_quit(); - } + wWin_p win; + + for (win=(wWin_p)firstWin; win; win=(wWin_p)win->next) { + if (win->shown && win != win0) { + if (modal) { + if (win->modalLevel == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), FALSE); + } + + win->modalLevel++; + } else { + if (win->modalLevel > 0) { + win->modalLevel--; + + if (win->modalLevel == 0) { + gtk_widget_set_sensitive(GTK_WIDGET(win->gtkwin), TRUE); + } + } + } + + if (win->modalLevel < 0) { + fprintf(stderr, "DoModal: %s modalLevel < 0", + win->nameStr?win->nameStr:"<NULL>"); + abort(); + } + } + } + + if (modal) { + gtk_main(); + } else { + gtk_main_quit(); + } } /** @@ -553,32 +535,32 @@ void wlibDoModal( */ const char * wWinGetTitle( - wWin_p win) /* Window */ + wWin_p win) /* Window */ { - return win->labelStr; + return win->labelStr; } void wWinClear( - wWin_p win, - wWinPix_t x, - wWinPix_t y, - wWinPix_t width, - wWinPix_t height) + wWin_p win, + wWinPix_t x, + wWinPix_t y, + wWinPix_t width, + wWinPix_t height) { } void wWinDoCancel( - wWin_p win) + wWin_p win) { - wControl_p b; + wControl_p b; - for (b=win->first; b; b=b->next) { - if ((b->type == B_BUTTON) && (b->option & BB_CANCEL)) { - wlibButtonDoAction((wButton_p)b); - } - } + for (b=win->first; b; b=b->next) { + if ((b->type == B_BUTTON) && (b->option & BB_CANCEL)) { + wlibButtonDoAction((wButton_p)b); + } + } } /* @@ -590,155 +572,161 @@ void wWinDoCancel( */ static int window_redraw( - wWin_p win, - wBool_t doWinProc) + wWin_p win, + wBool_t doWinProc) { - wControl_p b; + wControl_p b; - if (win==NULL) { - return FALSE; - } + if (win==NULL) { + return FALSE; + } - for (b=win->first; b != NULL; b = b->next) { - if (b->repaintProc) { - b->repaintProc(b); - } - } + for (b=win->first; b != NULL; b = b->next) { + if (b->repaintProc) { + b->repaintProc(b); + } + } - return FALSE; + return FALSE; } static gint window_delete_event( - GtkWidget *widget, - GdkEvent *event, - wWin_p win) + GtkWidget *widget, + GdkEvent *event, + wWin_p win) { - wControl_p b; - /* if you return FALSE in the "delete_event" signal handler, - * GTK will emit the "destroy" signal. Returning TRUE means - * you don't want the window to be destroyed. - * This is useful for popping up 'are you sure you want to quit ?' - * type dialogs. */ - - /* Change TRUE to FALSE and the main window will be destroyed with - * a "delete_event". */ - - for (b = win->first; b; b=b->next) - if (b->doneProc) { - b->doneProc(b); - } - - if (win->winProc) { - win->winProc(win, wClose_e, NULL, win->data); - - if (win != gtkMainW) { - wWinShow(win, FALSE); - } - } - - return (TRUE); + wControl_p b; + /* if you return FALSE in the "delete_event" signal handler, + * GTK will emit the "destroy" signal. Returning TRUE means + * you don't want the window to be destroyed. + * This is useful for popping up 'are you sure you want to quit ?' + * type dialogs. */ + + /* Change TRUE to FALSE and the main window will be destroyed with + * a "delete_event". */ + + for (b = win->first; b; b=b->next) + if (b->doneProc) { + b->doneProc(b); + } + + if (win->winProc) { + win->winProc(win, wClose_e, NULL, win->data); + + if (win != gtkMainW) { + wWinShow(win, FALSE); + } + } + + return (TRUE); } static int fixed_expose_event( - GtkWidget * widget, - GdkEventExpose * event, - wWin_p win) + GtkWidget * widget, + GdkEventExpose * event, + wWin_p win) { int rc; - if (event->count==0) { - rc = window_redraw(win, TRUE); - } else { - rc = FALSE; - } - cairo_t* cr = gdk_cairo_create (gtk_widget_get_window(widget)); -#ifdef CURSOR_SURFACE - if (win && win->cursor_surface.surface && win->cursor_surface.show) { - cairo_set_source_surface(cr,win->cursor_surface.surface,event->area.x, event->area.y); - cairo_set_operator(cr,CAIRO_OPERATOR_OVER); - cairo_rectangle(cr,event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_fill(cr); + if (event->count==0) { + rc = window_redraw(win, TRUE); + } else { + rc = FALSE; } -#endif - return rc; + return rc; } -static int resizeTime(wWin_p win) { +static int resizeTime(wWin_p win) +{ - if (win->resizeW == win->w && win->resizeH == win->h) { // If hasn't changed since last + if (debugWindow >= 2) { + printf( "resizeTime idleCnt %d, busyCnt %d [%d %d] [%ld %ld]\n", + win->timer_idle_count, win->timer_busy_count, + win->resizeW, win->resizeH, win->w, win->h ); + } + if (win->resizeW == win->w + && win->resizeH == win->h) { // If hasn't changed since last if (win->timer_idle_count>3) { - win->winProc(win, wResize_e, NULL, win->data); //Trigger Redraw on last occasion if one-third of a second has elapsed + win->winProc(win, wResize_e, NULL, + win->data); //Trigger Redraw on last occasion if one-third of a second has elapsed win->timer_idle_count = 0; win->resizeTimer = 0; win->timer_busy_count = 0; return FALSE; //Stop Timer and don't resize - } else win->timer_idle_count++; + } else { win->timer_idle_count++; } } if (win->busy==FALSE && win->winProc) { //Always drive once if (win->timer_busy_count>10) { - win->winProc(win, wResize_e, NULL, win->data); //Redraw if ten times we saw a change (1 sec) - win->timer_busy_count = 0; + win->winProc(win, wResize_e, NULL, + win->data); //Redraw if ten times we saw a change (1 sec) + win->timer_busy_count = 0; } else { win->winProc(win, wResize_e, (void*) 1, win->data); //No Redraw win->timer_busy_count++; } - win->resizeW = win->w; //Remember this one - win->resizeH = win->h; + win->resizeW = win->w; //Remember this one + win->resizeH = win->h; } return TRUE; //Will redrive after another timer interval } static int window_configure_event( - GtkWidget * widget, - GdkEventConfigure * event, - wWin_p win) + GtkWidget * widget, + GdkEventConfigure * event, + wWin_p win) { - if (win==NULL) { - return FALSE; - } - - if (win->option&F_RESIZE) { - if (event->width < 10 || event->height < 10) { - return TRUE; - } - int w = win->w; - int h = win->h; - - - if (win->w != event->width || win->h != event->height) { - win->w = event->width; - win->h = event->height; - - if (win->w < MIN_WIN_WIDTH) { - win->w = MIN_WIN_WIDTH; - } - - if (win->h < MIN_WIN_HEIGHT) { - win->h = MIN_WIN_HEIGHT; - } - - if (win->option&F_MENUBAR) { - GtkAllocation allocation; - gtk_widget_get_allocation(win->menubar, &allocation); - win->menu_height= allocation.height; - gtk_widget_set_size_request(win->menubar, win->w-20, win->menu_height); - } - if (win->resizeTimer) { // Already have a timer - return FALSE; - } else { - win->resizeW = w; //Remember where this started - win->resizeH = h; - win->timer_idle_count = 0; //Start background timer on redraw - win->timer_busy_count = 0; - win->resizeTimer = g_timeout_add(100,(GSourceFunc)resizeTime,win); // 100ms delay - return FALSE; - } - } - } - - return FALSE; + if (win==NULL) { + return FALSE; + } + + if (debugWindow >= 2) { + printf( "config/resize: [%d %d]\n", event->width, event->height ); + } + if (win->option&F_RESIZE) { + if (event->width < 10 || event->height < 10) { + return TRUE; + } + int w = win->w; + int h = win->h; + + + if (win->w != event->width || win->h != event->height) { + if (debugWindow >= 2) { + printf( " Update [%ld %ld]\n", event->width-win->w, event->height-win->h ); + } + win->w = event->width; + win->h = event->height; + + if (win->w < MIN_WIN_WIDTH) { + win->w = MIN_WIN_WIDTH; + } + + if (win->h < MIN_WIN_HEIGHT) { + win->h = MIN_WIN_HEIGHT; + } + + if (win->option&F_MENUBAR) { + GtkAllocation allocation; + gtk_widget_get_allocation(win->menubar, &allocation); + win->menu_height= allocation.height; + gtk_widget_set_size_request(win->menubar, win->w-20, win->menu_height); + } + if (win->resizeTimer) { // Already have a timer + return FALSE; + } else { + win->resizeW = w; //Remember where this started + win->resizeH = h; + win->timer_idle_count = 0; //Start background timer on redraw + win->timer_busy_count = 0; + win->resizeTimer = g_timeout_add(100,(GSourceFunc)resizeTime, + win); // 100ms delay + return FALSE; + } + } + } + + return FALSE; } /** @@ -753,25 +741,25 @@ static int window_configure_event( */ gboolean window_state_event( - GtkWidget *widget, - GdkEventWindowState *event, - wWin_p win) + GtkWidget *widget, + GdkEventWindowState *event, + wWin_p win) { - if (!win) { - return (FALSE); - } + if (!win) { + return (FALSE); + } - win->maximize_initially = FALSE; + win->maximize_initially = FALSE; - if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) { - win->maximize_initially = TRUE; - } + if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) { + win->maximize_initially = TRUE; + } - if (win->busy==FALSE && win->winProc) { - win->winProc(win, wState_e, NULL, win->data); - } + if (win->busy==FALSE && win->winProc) { + win->winProc(win, wState_e, NULL, win->data); + } - return TRUE; + return TRUE; } /** * Get current state of shift, ctrl or alt keys. @@ -781,87 +769,90 @@ gboolean window_state_event( int wGetKeyState(void) { - return keyState; + return keyState; } wBool_t catch_shift_ctrl_alt_keys( - GtkWidget * widget, - GdkEventKey *event, - void * data) + GtkWidget * widget, + GdkEventKey *event, + void * data) { - int state = 0; - switch (event->keyval ) { - case GDK_KEY_Shift_L: - case GDK_KEY_Shift_R: - state |= WKEY_SHIFT; - break; - - case GDK_KEY_Control_L: - case GDK_KEY_Control_R: - state |= WKEY_CTRL; - break; - - case GDK_KEY_Alt_L: - case GDK_KEY_Alt_R: - state |= WKEY_ALT; - break; - - case GDK_KEY_Meta_L: - case GDK_KEY_Meta_R: - // Pressing SHIFT and then ALT generates a Meta key - //printf( "Meta\n" ); - state |= WKEY_ALT; - break; - } - - if (state != 0) { - if (event->type == GDK_KEY_PRESS) { - keyState |= state; - } else { - keyState &= ~state; - } - return TRUE; - } - return FALSE; + int state = 0; + switch (event->keyval ) { + case GDK_KEY_Shift_L: + case GDK_KEY_Shift_R: + state |= WKEY_SHIFT; + break; + + case GDK_KEY_Control_L: + case GDK_KEY_Control_R: + state |= WKEY_CTRL; + break; + + case GDK_KEY_Alt_L: + case GDK_KEY_Alt_R: + state |= WKEY_ALT; + break; + + case GDK_KEY_Meta_L: + case GDK_KEY_Meta_R: + // Pressing SHIFT and then ALT generates a Meta key + //printf( "Meta\n" ); + state |= WKEY_ALT; + break; + } + + if (state != 0) { + if (event->type == GDK_KEY_PRESS) { + keyState |= state; + } else { + keyState &= ~state; + } + return TRUE; + } + return FALSE; } static gint window_char_event( - GtkWidget * widget, - GdkEventKey *event, - wWin_p win) + GtkWidget * widget, + GdkEventKey *event, + wWin_p win) { - wControl_p bb; - - if (catch_shift_ctrl_alt_keys(widget, event, win)) { - return FALSE; - } - - if (event->type == GDK_KEY_RELEASE) { - return FALSE; - } - - if ( ( event->state & GDK_MODIFIER_MASK ) == 0 ) { - if (event->keyval == GDK_KEY_Escape) { - for (bb=win->first; bb; bb=bb->next) { - if (bb->type == B_BUTTON && (bb->option&BB_CANCEL)) { - wlibButtonDoAction((wButton_p)bb); - return TRUE; - } - } - } - } - - if (wlibHandleAccelKey(event)) { - return TRUE; - } else { - return FALSE; - } + wControl_p bb; + + if (catch_shift_ctrl_alt_keys(widget, event, win)) { + return FALSE; + } + + if (event->type == GDK_KEY_RELEASE) { + return FALSE; + } + + if ( ( event->state & GDK_MODIFIER_MASK ) == 0 ) { + if (event->keyval == GDK_KEY_Escape) { + for (bb=win->first; bb; bb=bb->next) { + if (bb->type == B_BUTTON && (bb->option&BB_CANCEL)) { + wlibButtonDoAction((wButton_p)bb); + return TRUE; + } + } + } + } + + if (wlibHandleAccelKey(event)) { + return TRUE; + } else { + return FALSE; + } } -void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, wWinPix_t min_height, wWinPix_t max_height, wWinPix_t base_width, wWinPix_t base_height, double aspect_ratio ) { +void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, + wWinPix_t min_height, wWinPix_t max_height, wWinPix_t base_width, + wWinPix_t base_height, double aspect_ratio ) +{ GdkGeometry hints; GdkWindowHints hintMask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE; - hints.min_width = min_width; + hints.min_width = min_width; hints.max_width = max_width; hints.min_height = min_height; hints.max_height = max_height; @@ -871,16 +862,16 @@ void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, wWinPix_ if( base_width != -1 && base_height != -1 ) { hintMask |= GDK_HINT_BASE_SIZE; } - + if(aspect_ratio > -1.0 ) { hintMask |= GDK_HINT_ASPECT; - } + } gtk_window_set_geometry_hints( - GTK_WINDOW(win->gtkwin), - win->gtkwin, - &hints, - hintMask); + GTK_WINDOW(win->gtkwin), + win->gtkwin, + &hints, + hintMask); } @@ -911,166 +902,158 @@ void wSetGeometry(wWin_p win, wWinPix_t min_width, wWinPix_t max_width, wWinPix_ */ static wWin_p wWinCommonCreate( - wWin_p parent, - int winType, - wWinPix_t x, - wWinPix_t y, - const char * labelStr, - const char * nameStr, - long option, - wWinCallBack_p winProc, - void * data) + wWin_p parent, + int winType, + wWinPix_t x, + wWinPix_t y, + const char * labelStr, + const char * nameStr, + long option, + wWinCallBack_p winProc, + void * data) { - wWin_p w; - int h; - w = wlibAlloc(NULL, winType, x, y, labelStr, sizeof *w, data); - w->busy = TRUE; - w->option = option; + wWin_p w; + int h; + w = wlibAlloc(NULL, winType, x, y, labelStr, sizeof *w, data); + w->busy = TRUE; + w->option = option; w->resizeTimer = 0; - h = BORDERSIZE; - - if (w->option&F_MENUBAR) { - h += MENUH; - } - - if (winType == W_MAIN) { - w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); - } else { - w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - if (gtkMainW) { - if (!(w->option&F_NOTTRANSIENT)) - gtk_window_set_transient_for(GTK_WINDOW(w->gtkwin), - GTK_WINDOW(gtkMainW->gtkwin)); - } - } - getWinSize(w, nameStr); - if (winType != W_MAIN) { - gtk_widget_set_app_paintable (w->gtkwin,TRUE); - } - - if (option & F_HIDE) { - gtk_widget_hide(w->gtkwin); - } - - /* center window on top of parent window */ - if (option & F_CENTER) { - gtk_window_set_position(GTK_WINDOW(w->gtkwin), GTK_WIN_POS_CENTER_ON_PARENT); - } - - - w->widget = gtk_fixed_new(); - - if (w->widget == 0) { - abort(); - } - - if (w->option&F_MENUBAR) { - w->menubar = gtk_menu_bar_new(); - gtk_container_add(GTK_CONTAINER(w->widget), w->menubar); - gtk_widget_show(w->menubar); - GtkAllocation allocation; - gtk_widget_get_allocation(w->menubar, &allocation); - w->menu_height = allocation.height; - gtk_widget_set_size_request(w->menubar, -1, w->menu_height); - } - - gtk_container_add(GTK_CONTAINER(w->gtkwin), w->widget); - - - - - if (w->option&F_AUTOSIZE) { - w->realX = 0; - w->w = MIN_WIN_WIDTH+20; - w->realY = h; - w->h = MIN_WIN_HEIGHT; - } else if (w->origX != 0){ - w->realX = w->origX; - w->realY = w->origY+h; - - w->default_size_x = w->w; - w->default_size_y = w->h; - //gtk_widget_set_size_request(w->widget, w->w-20, w->h); - - if (w->option&F_MENUBAR) { - gtk_widget_set_size_request(w->menubar, w->w-20, MENUH); - } - } - wWinPix_t scr_w, scr_h; - wGetDisplaySize(&scr_w, &scr_h); - if (scr_w < MIN_WIN_WIDTH) scr_w = MIN_WIN_WIDTH+10; - if (scr_h < MIN_WIN_HEIGHT) scr_h = MIN_WIN_HEIGHT; + h = BORDERSIZE; + + if (w->option&F_MENUBAR) { + h += MENUH; + } + + if (winType == W_MAIN) { + w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + } else { + w->gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + if (gtkMainW) { + if (!(w->option&F_NOTTRANSIENT)) + gtk_window_set_transient_for(GTK_WINDOW(w->gtkwin), + GTK_WINDOW(gtkMainW->gtkwin)); + } + } + getWinSize(w, nameStr); if (winType != W_MAIN) { - wSetGeometry(w, MIN_WIN_WIDTH, scr_w-10, MIN_WIN_HEIGHT, scr_h, -1, -1, -1); + gtk_widget_set_app_paintable (w->gtkwin,TRUE); + } + + if (option & F_HIDE) { + gtk_widget_hide(w->gtkwin); + } + + /* center window on top of parent window */ + if (option & F_CENTER) { + gtk_window_set_position(GTK_WINDOW(w->gtkwin), GTK_WIN_POS_CENTER_ON_PARENT); + } + + + w->widget = gtk_fixed_new(); + + if (w->widget == 0) { + abort(); + } + + if (w->option&F_MENUBAR) { + w->menubar = gtk_menu_bar_new(); + gtk_container_add(GTK_CONTAINER(w->widget), w->menubar); + gtk_widget_show(w->menubar); + GtkAllocation allocation; + gtk_widget_get_allocation(w->menubar, &allocation); + w->menu_height = allocation.height; + gtk_widget_set_size_request(w->menubar, -1, w->menu_height); + } + + gtk_container_add(GTK_CONTAINER(w->gtkwin), w->widget); + + + + + if (w->option&F_AUTOSIZE) { + w->realX = 0; + w->w = 0; + w->realY = h; + w->h = 0; + } else if (w->origX != 0) { + w->realX = w->origX; + w->realY = w->origY+h; + + //gtk_widget_set_size_request(w->widget, w->w-20, w->h); + + if (w->option&F_MENUBAR) { + gtk_widget_set_size_request(w->menubar, w->w-20, MENUH); + } + } + + w->first = w->last = NULL; + w->winProc = winProc; + g_signal_connect(GTK_OBJECT(w->gtkwin), "delete_event", + G_CALLBACK(window_delete_event), w); + g_signal_connect(GTK_OBJECT(w->widget), "expose_event", + G_CALLBACK(fixed_expose_event), w); + g_signal_connect(GTK_OBJECT(w->gtkwin), "configure_event", + G_CALLBACK(window_configure_event), w); + g_signal_connect(GTK_OBJECT(w->gtkwin), "window-state-event", + G_CALLBACK(window_state_event), w); + g_signal_connect(GTK_OBJECT(w->gtkwin), "key_press_event", + G_CALLBACK(window_char_event), w); + g_signal_connect(GTK_OBJECT(w->gtkwin), "key_release_event", + G_CALLBACK(window_char_event), w); + gtk_widget_set_events(w->widget, GDK_EXPOSURE_MASK); + gtk_widget_set_events(GTK_WIDGET(w->gtkwin), + GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK); + + if (w->option & F_RESIZE) { + gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), TRUE); + if ( ( w->option & F_AUTOSIZE ) == 0 ) { + gtk_window_resize(GTK_WINDOW(w->gtkwin), w->w, w->h); + } } else { - if (scr_w < MIN_WIN_WIDTH_MAIN+10) scr_w = MIN_WIN_WIDTH_MAIN+200; - if (scr_h < MIN_WIN_HEIGHT_MAIN+10) scr_h = MIN_WIN_HEIGHT_MAIN+200; - wSetGeometry(w, MIN_WIN_WIDTH_MAIN, scr_w-10, MIN_WIN_HEIGHT_MAIN, scr_h-10, -1, -1, -1); - } - - - - w->first = w->last = NULL; - w->winProc = winProc; - g_signal_connect(GTK_OBJECT(w->gtkwin), "delete_event", - G_CALLBACK(window_delete_event), w); - g_signal_connect(GTK_OBJECT(w->widget), "expose_event", - G_CALLBACK(fixed_expose_event), w); - g_signal_connect(GTK_OBJECT(w->gtkwin), "configure_event", - G_CALLBACK(window_configure_event), w); - g_signal_connect(GTK_OBJECT(w->gtkwin), "window-state-event", - G_CALLBACK(window_state_event), w); - g_signal_connect(GTK_OBJECT(w->gtkwin), "key_press_event", - G_CALLBACK(window_char_event), w); - g_signal_connect(GTK_OBJECT(w->gtkwin), "key_release_event", - G_CALLBACK(window_char_event), w); - gtk_widget_set_events(w->widget, GDK_EXPOSURE_MASK); - gtk_widget_set_events(GTK_WIDGET(w->gtkwin), - GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK); - - if (w->option & F_RESIZE) { - gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), TRUE); - gtk_window_resize(GTK_WINDOW(w->gtkwin), w->w, w->h); - } else { - gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), FALSE); - } - - w->lastX = 0; - w->lastY = h; - w->shown = FALSE; - w->nameStr = nameStr?strdup(nameStr):NULL; - - if (labelStr) { - gtk_window_set_title(GTK_WINDOW(w->gtkwin), labelStr); - } - - if (listHelpStrings) { - printf("WINDOW - %s\n", nameStr?nameStr:"<NULL>"); - } - - if (firstWin) { - lastWin->next = (wControl_p)w; - } else { - firstWin = (wControl_p)w; - } - - lastWin = (wControl_p)w; - gtk_widget_show(w->widget); - gtk_widget_realize(w->gtkwin); - GtkAllocation allocation; - gtk_widget_get_allocation(w->gtkwin, &allocation); - w->menu_height = allocation.height; - - w->busy = FALSE; - - if (option&F_MAXIMIZE) { - maximize_at_next_show = TRUE; - } - - return w; + gtk_window_set_resizable(GTK_WINDOW(w->gtkwin), FALSE); + } + + w->lastX = 0; + w->lastY = h; + w->shown = FALSE; + w->nameStr = nameStr?strdup(nameStr):NULL; + + if (labelStr) { + gtk_window_set_title(GTK_WINDOW(w->gtkwin), labelStr); + } + + if (listHelpStrings) { + printf("WINDOW - %s\n", nameStr?nameStr:"<NULL>"); + } + + if (firstWin) { + lastWin->next = (wControl_p)w; + } else { + firstWin = (wControl_p)w; + } + + lastWin = (wControl_p)w; + gtk_widget_show(w->widget); + gtk_widget_realize(w->gtkwin); + GtkAllocation allocation; + gtk_widget_get_allocation(w->gtkwin, &allocation); + w->menu_height = allocation.height; + + w->busy = FALSE; + + if (option&F_MAXIMIZE) { + maximize_at_next_show = TRUE; + } + + if ( windowIconPixbuf == NULL ) { + windowIconPixbuf = gdk_pixbuf_new_from_xpm_data((const char**)&xtc_xpm); + } + gtk_window_set_icon( GTK_WINDOW(w->gtkwin), windowIconPixbuf ); + + return w; } @@ -1091,38 +1074,38 @@ static wWin_p wWinCommonCreate( */ wWin_p wWinMainCreate( - const char * name, /* Application name */ - wWinPix_t x, /* Initial window width */ - wWinPix_t y, /* Initial window height */ - const char * helpStr, /* Help topic string */ - const char * labelStr, /* Window title */ - const char * nameStr, /* Window name */ - long option, /* Options */ - wWinCallBack_p winProc, /* Call back function */ - void * data) /* User context */ + const char * name, /* Application name */ + wWinPix_t x, /* Initial window width */ + wWinPix_t y, /* Initial window height */ + const char * helpStr, /* Help topic string */ + const char * labelStr, /* Window title */ + const char * nameStr, /* Window name */ + long option, /* Options */ + wWinCallBack_p winProc, /* Call back function */ + void * data) /* User context */ { - char *pos; - long isMaximized; + char *pos; + long isMaximized; - pos = strchr(name, ';'); + pos = strchr(name, ';'); - if (pos) { - /* if found, split application name and configuration name */ - strcpy(wConfigName, pos + 1); - } else { - /* if not found, application name and configuration name are same */ - strcpy(wConfigName, name); - } + if (pos) { + /* if found, split application name and configuration name */ + strcpy(wConfigName, pos + 1); + } else { + /* if not found, application name and configuration name are same */ + strcpy(wConfigName, name); + } - wPrefGetInteger("draw", "maximized", &isMaximized, 0); - option = option | (isMaximized?F_MAXIMIZE:0); + wPrefGetInteger("draw", "maximized", &isMaximized, 0); + option = option | (isMaximized?F_MAXIMIZE:0); - gtkMainW = wWinCommonCreate(NULL, W_MAIN, x, y, labelStr, nameStr, option, - winProc, data); + gtkMainW = wWinCommonCreate(NULL, W_MAIN, x, y, labelStr, nameStr, option, + winProc, data); - wDrawColorWhite = wDrawFindColor(0xFFFFFF); - wDrawColorBlack = wDrawFindColor(0x000000); - return gtkMainW; + wDrawColorWhite = wDrawFindColor(0xFFFFFF); + wDrawColorBlack = wDrawFindColor(0x000000); + return gtkMainW; } /** @@ -1141,29 +1124,29 @@ wWin_p wWinMainCreate( */ wWin_p wWinPopupCreate( - wWin_p parent, - wWinPix_t x, - wWinPix_t y, - const char * helpStr, - const char * labelStr, - const char * nameStr, - long option, - wWinCallBack_p winProc, - void * data) + wWin_p parent, + wWinPix_t x, + wWinPix_t y, + const char * helpStr, + const char * labelStr, + const char * nameStr, + long option, + wWinCallBack_p winProc, + void * data) { - wWin_p win; + wWin_p win; - if (parent == NULL) { - if (gtkMainW == NULL) { - abort(); - } + if (parent == NULL) { + if (gtkMainW == NULL) { + abort(); + } - parent = gtkMainW; - } + parent = gtkMainW; + } - win = wWinCommonCreate(parent, W_POPUP, x, y, labelStr, nameStr, option, - winProc, data); - return win; + win = wWinCommonCreate(parent, W_POPUP, x, y, labelStr, nameStr, option, + winProc, data); + return win; } @@ -1178,22 +1161,22 @@ wWin_p wWinPopupCreate( void wExit( - int rc) /* Application return code */ + int rc) /* Application return code */ { - wWin_p win; + wWin_p win; - for (win = (wWin_p)firstWin; win; win = (wWin_p)win->next) { - if (gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) { - saveSize(win); - savePos(win); - } - } + for (win = (wWin_p)firstWin; win; win = (wWin_p)win->next) { + if (gtk_widget_get_visible(GTK_WIDGET(win->gtkwin))) { + saveSize(win); + savePos(win); + } + } - wPrefFlush(""); + wPrefFlush(""); - if (gtkMainW && gtkMainW->winProc != NULL) { - gtkMainW->winProc(gtkMainW, wQuit_e, NULL, gtkMainW->data); - } + if (gtkMainW && gtkMainW->winProc != NULL) { + gtkMainW->winProc(gtkMainW, wQuit_e, NULL, gtkMainW->data); + } - exit(rc); + exit(rc); } diff --git a/app/wlib/gtklib/wpref.c b/app/wlib/gtklib/wpref.c index 3494ba2..356dd95 100644 --- a/app/wlib/gtklib/wpref.c +++ b/app/wlib/gtklib/wpref.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -26,6 +26,7 @@ #include <ctype.h> #include <dirent.h> #include <sys/stat.h> +#include <errno.h> #define GTK_DISABLE_SINGLE_INCLUDES #define GDK_DISABLE_DEPRECATED @@ -47,6 +48,8 @@ extern char wConfigName[]; static char appLibDir[BUFSIZ]; static char appWorkDir[BUFSIZ]; static char userHomeDir[BUFSIZ]; + +static char *profileFile; /* @@ -58,13 +61,13 @@ static char userHomeDir[BUFSIZ]; */ -/** Find the directory where configuration files, help, demos etc are installed. +/** Find the directory where configuration files, help, demos etc are installed. * The search order is: * 1. Directory specified by the XTRKCADLIB environment variable * 2. Directory specified by XTRKCAD_INSTALL_PREFIX/share/xtrkcad * 3. /usr/share/xtrkcad * 4. /usr/local/share/xtrkcad - * + * * \return pointer to directory name */ @@ -79,13 +82,19 @@ const char * wGetAppLibDir( void ) return appLibDir; } - for (cp=wlibGetAppName(),ep=envvar; *cp; cp++,ep++) + for (cp=wlibGetAppName(),ep=envvar; *cp; cp++,ep++) { *ep = toupper(*cp); - strcpy( ep, "LIB" ); + } +#ifndef __APPLE__ + if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) { + strcat( ep, "BETA" ); + } +#endif + strcat( ep, "LIB" ); ep = getenv( envvar ); if (ep != NULL) { if ((stat( ep, &buf) == 0 ) && S_ISDIR( buf.st_mode)) { - strncpy( appLibDir, ep, sizeof appLibDir ); + strncpy( appLibDir, ep, sizeof(appLibDir) -1 ); //printf( "wAppLbDir=%s\n", appLibDir ); return appLibDir; } @@ -100,13 +109,18 @@ const char * wGetAppLibDir( void ) char * dir1 = "/usr/share/"; char * dir2 = "/usr/local/share/"; + char * beta = ""; if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) { dir1 = "/usr/local/share/"; dir2 = "/usr/share/"; +#ifndef __APPLE__ + beta = "-beta"; +#endif } strcpy( appLibDir, dir1 ); strcat( appLibDir, wlibGetAppName() ); + strcat( appLibDir, beta ); if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) { //printf( "wAppLbDir=%s\n", appLibDir ); return appLibDir; @@ -120,14 +134,14 @@ const char * wGetAppLibDir( void ) } sprintf( msg, - _("The required configuration files could not be located in the expected location.\n\n" - "Usually this is an installation problem. Make sure that these files are installed in either \n" - " ../share/xtrkcad or\n" - " /usr/share/%s or\n" - " /usr/local/share/%s\n" - "If this is not possible, the environment variable %s must contain " - "the name of the correct directory."), - wlibGetAppName(), wlibGetAppName(), envvar ); + _("The required configuration files could not be located in the expected location.\n\n" + "Usually this is an installation problem. Make sure that these files are installed in either \n" + " ../share/xtrkcad or\n" + " /usr/share/%s or\n" + " /usr/local/share/%s\n" + "If this is not possible, the environment variable %s must contain " + "the name of the correct directory."), + wlibGetAppName(), wlibGetAppName(), envvar ); wNoticeEx( NT_ERROR, msg, _("Ok"), NULL ); appLibDir[0] = '\0'; wExit(0); @@ -144,20 +158,26 @@ const char * wGetAppLibDir( void ) const char * wGetAppWorkDir( - void ) + void ) { char tmp[BUFSIZ+20]; char * homeDir; DIR *dirp; - - if (appWorkDir[0] != '\0') + + if (appWorkDir[0] != '\0') { return appWorkDir; + } if ((homeDir = getenv( "HOME" )) == NULL) { wNoticeEx( NT_ERROR, _("HOME is not set"), _("Exit"), NULL); wExit(0); } sprintf( appWorkDir, "%s/.%s", homeDir, wlibGetAppName() ); +#ifndef __APPLE__ + if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) { + strcat( appWorkDir, "-beta" ); + } +#endif if ( (dirp = opendir(appWorkDir)) != NULL ) { closedir(dirp); } else { @@ -166,18 +186,18 @@ const char * wGetAppWorkDir( wNoticeEx( NT_ERROR, tmp, _("Exit"), NULL ); wExit(0); } else { - /* - * check for default configuration file and copy to + /* + * check for default configuration file and copy to * the workdir if it exists */ struct stat stFileInfo; char appEtcConfig[BUFSIZ]; sprintf( appEtcConfig, "/etc/%s.rc", wlibGetAppName()); - + if ( stat( appEtcConfig, &stFileInfo ) == 0 ) { char copyConfigCmd[(BUFSIZ * 2) + 3]; sprintf( copyConfigCmd, "cp %s %s", appEtcConfig, appWorkDir ); - int rc = system( copyConfigCmd ); + system( copyConfigCmd ); } } } @@ -194,16 +214,17 @@ const char * wGetAppWorkDir( const char *wGetUserHomeDir( void ) { char *homeDir; - - if( userHomeDir[ 0 ] != '\0' ) + + if( userHomeDir[ 0 ] != '\0' ) { return userHomeDir; - + } + if ((homeDir = getenv( "HOME" )) == NULL) { wNoticeEx( NT_ERROR, _("HOME is not set"), _("Exit"), NULL); wExit(0); } else { strcpy( userHomeDir, homeDir ); - } + } return userHomeDir; } @@ -218,62 +239,101 @@ const char *wGetUserHomeDir( void ) */ typedef struct { - char * section; - char * name; - wBool_t present; - wBool_t dirty; - char * val; - } prefs_t; + char * section; + char * name; + wBool_t present; + wBool_t dirty; + char * val; +} prefs_t; dynArr_t prefs_da; #define prefs(N) DYNARR_N(prefs_t,prefs_da,N) wBool_t prefInitted = FALSE; /** + * Define the name of the configuration file. Needed size is calculated, allocated and + * initialized with the filename + * + * \param name overwrite default configuration + */ + +void static +wlibSetProfileFilename(char *name) +{ + const char *workDir; + + workDir = wGetAppWorkDir(); + if (name && name[0]) { + size_t length; + length = snprintf(profileFile, 0, "%s", name); + profileFile = malloc(length + sizeof(NULL)); + snprintf( profileFile, length, "%s", name ); + } else { + size_t length; + length = snprintf(profileFile, 0, "%s/%s.rc", workDir, wConfigName ); + profileFile = malloc(length + sizeof(NULL)); + length = snprintf(profileFile, length+sizeof(NULL), "%s/%s.rc", workDir, wConfigName ); + } +} + + +/** + * Get the name of the configuration file. + * + * \return pointer to the filename. + * + */ + +char * +wGetProfileFilename() +{ + return(profileFile); +} + +/** * Read the configuration file into memory */ static void readPrefs( char * name, wBool_t update ) { - char tmp[BUFSIZ], *np, *vp, *cp; - const char * workDir; + char tmp[BUFSIZ+32], *np, *vp, *cp; FILE * prefFile; prefs_t * p; prefInitted = TRUE; - workDir = wGetAppWorkDir(); - if (name && name[0]) - sprintf( tmp, "%s", name ); - else - sprintf( tmp, "%s/%s.rc", workDir, wConfigName ); - prefFile = fopen( tmp, "r" ); - if (prefFile == NULL) + wlibSetProfileFilename(name); + + prefFile = fopen( profileFile, "r" ); + if (prefFile == NULL) { + // First run, no .rc file yet return; + } while ( ( fgets(tmp, sizeof tmp, prefFile) ) != NULL ) { char *sp; - + sp = tmp; - while ( *sp==' ' || *sp=='\t' ) sp++; - if ( *sp == '\n' || *sp == '#' ) + while ( *sp==' ' || *sp=='\t' ) { sp++; } + if ( *sp == '\n' || *sp == '#' ) { continue; + } np = strchr( sp, '.' ); if (np == NULL) { wNoticeEx( NT_INFORMATION, tmp, _("Continue"), NULL ); continue; } *np++ = '\0'; - while ( *np==' ' || *np=='\t' ) np++; + while ( *np==' ' || *np=='\t' ) { np++; } vp = strchr( np, ':' ); if (vp == NULL) { wNoticeEx( NT_INFORMATION, tmp, _("Continue"), NULL ); continue; } *vp++ = '\0'; - while ( *vp==' ' || *vp=='\t' ) vp++; + while ( *vp==' ' || *vp=='\t' ) { vp++; } cp = vp + strlen(vp) -1; - while ( cp >= vp && (*cp=='\n' || *cp==' ' || *cp=='\t') ) cp--; + while ( cp >= vp && (*cp=='\n' || *cp==' ' || *cp=='\t') ) { cp--; } cp[1] = '\0'; if (update) { - for (int i=0;i<prefs_da.cnt;i++) { + for (int i=0; i<prefs_da.cnt; i++) { p = &DYNARR_N(prefs_t,prefs_da,i); if (strcmp(p->name,np)==0 && strcmp(p->section,sp)==0) { p->val = strdup(vp); @@ -302,19 +362,21 @@ static void readPrefs( char * name, wBool_t update ) */ void wPrefSetString( - const char * section, /* Section */ - const char * name, /* Name */ - const char * sval ) /* Value */ + const char * section, /* Section */ + const char * name, /* Name */ + const char * sval ) /* Value */ { prefs_t * p; - if (!prefInitted) + if (!prefInitted) { readPrefs("", FALSE); - + } + for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { - if (p->val) + if (p->val) { free(p->val); + } p->dirty = TRUE; p->val = (sval?strdup( sval ):NULL); return; @@ -336,14 +398,15 @@ void wPrefSetString( */ char * wPrefGetStringBasic( - const char * section, /* Section */ - const char * name ) /* Name */ + const char * section, /* Section */ + const char * name ) /* Name */ { prefs_t * p; - if (!prefInitted) + if (!prefInitted) { readPrefs("", FALSE); - + } + for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) { return p->val; @@ -360,10 +423,10 @@ char * wPrefGetStringBasic( * \param lval IN value to save */ - void wPrefSetInteger( - const char * section, /* Section */ - const char * name, /* Name */ - long lval ) /* Value */ +void wPrefSetInteger( + const char * section, /* Section */ + const char * name, /* Name */ + long lval ) /* Value */ { char tmp[20]; @@ -382,13 +445,13 @@ char * wPrefGetStringBasic( */ wBool_t wPrefGetIntegerBasic( - const char * section, /* Section */ - const char * name, /* Name */ - long * res, /* Address of result */ - long def ) /* Default value */ + const char * section, /* Section */ + const char * name, /* Name */ + long * res, /* Address of result */ + long def ) /* Default value */ { const char * cp; - char *cp1; + char *cp1; cp = wPrefGetStringBasic( section, name ); if (cp == NULL) { @@ -404,17 +467,17 @@ wBool_t wPrefGetIntegerBasic( } /** - * Save a float value in the preferences file. + * Save a float value in the preferences file. * * \param section IN the file section into which the value should be saved * \param name IN the name of the preference * \param lval IN the value */ - void wPrefSetFloat( - const char * section, /* Section */ - const char * name, /* Name */ - double lval ) /* Value */ +void wPrefSetFloat( + const char * section, /* Section */ + const char * name, /* Name */ + double lval ) /* Value */ { char tmp[20]; @@ -434,13 +497,13 @@ wBool_t wPrefGetIntegerBasic( wBool_t wPrefGetFloatBasic( - const char * section, /* Section */ - const char * name, /* Name */ - double * res, /* Address of result */ - double def ) /* Default value */ + const char * section, /* Section */ + const char * name, /* Name */ + double * res, /* Address of result */ + double def ) /* Default value */ { const char * cp; - char *cp1; + char *cp1; cp = wPrefGetStringBasic( section, name ); if (cp == NULL) { @@ -455,62 +518,117 @@ wBool_t wPrefGetFloatBasic( return TRUE; } -void wPrefsLoad(char * name) { +void wPrefsLoad(char * name) +{ readPrefs(name,TRUE); } /** * Save the configuration to a file. The config parameters are held and updated in an array. - * To make the settings persistant, this function has to be called. + * To make the settings persistant, this function has to be called. * */ void wPrefFlush( - char * name ) + char * name ) { prefs_t * p; - char tmp[BUFSIZ]; - const char *workDir; + char tmp[BUFSIZ+32]; FILE * prefFile; - if (!prefInitted) + if (!prefInitted) { return; - - workDir = wGetAppWorkDir(); - if (name && name[0]) - snprintf( tmp, sizeof(tmp), "%s", name ); - else - snprintf( tmp, sizeof(tmp), "%s/%s.rc", workDir, wConfigName ); - prefFile = fopen( tmp, "w" ); - if (prefFile == NULL) + } + + wlibSetProfileFilename(name); + + prefFile = fopen( profileFile, "w" ); + if (prefFile == NULL) { + // Can not write pref file + size_t n = BUFSIZ+32-1-strlen(tmp); + strncat( tmp, ": ", n ); + strncat( tmp, strerror(errno), n-2 ); + wNoticeEx( NT_ERROR, tmp, "Ok", NULL ); return; + } for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { if(p->val) { fprintf( prefFile, "%s.%s: %s\n", p->section, p->name, p->val ); - } + } } fclose( prefFile ); } /** * Clear the preferences from memory - * \return + * \return */ void wPrefReset( - void ) + void ) { prefs_t * p; prefInitted = FALSE; for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) { - if (p->section) + if (p->section) { free( p->section ); - if (p->name) + } + if (p->name) { free( p->name ); - if (p->val) + } + if (p->val) { free( p->val ); + } } prefs_da.cnt = 0; } + +/** + * Split a line from the config file ie. rc ini-file into separate tokens. The + * line is split into sections, name of value and value following. Pointers + * to the respective token are returned. These are zero-terminated. + * If a token is not present, NULL is returned instead. + * The input line is modified. + * + * \param line input line, modified during excution of function + * \param section section if present + * \param name name of config value if present + * \param value name of value if present + */ +void +wPrefTokenize(char* line, char** section, char** name, char** value) +{ + *section = NULL; + *name = NULL; + *value = NULL; + + *section = strtok(line, "."); + *name = strtok(NULL, ":"); + *value = strtok(NULL, "\n"); + if(*value) + g_strstrip(*value); + +} + +/** + * A valid line for a config file is created from the individual elements. + * Values not need for specific statement are ignored. Eg. when section is + * present, name and value are not used. + * The caller has to make sure, that the return buffer is large enough. + * + * \param section section, first token, dellimited with '.' + * \param name name, left side of ':' + * \param value value, right side of ':' + * \param result pointer to buffer for formated line. + */ + +void +wPrefFormatLine(const char* section, const char* name, const char* value, char* result) +{ + if (!value || *value == '\0') { + value = ""; + } + sprintf(result, "%s.%s: %s", section, name, value); +}
\ No newline at end of file diff --git a/app/wlib/gtklib/writebitmap.c b/app/wlib/gtklib/writebitmap.c index be9aa62..0f5041a 100644 --- a/app/wlib/gtklib/writebitmap.c +++ b/app/wlib/gtklib/writebitmap.c @@ -1,5 +1,5 @@ /** \file writebitmap.c - * Bitmap file creation + * Bitmap file creation */ /* XTrackCad - Model Railroad CAD @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define GTK_DISABLE_SINGLE_INCLUDES @@ -34,21 +34,21 @@ /** * Get the Extension part of a filename - * + * * /param fname the filename - * + * * /return char* point to the extension */ static const char * GetExtension(const char *fname) { - const char *end = fname + strlen(fname); + const char *end = fname + strlen(fname); - while (end > fname && *end != '.') { - --end; - } - return( end + 1 ); + while (end > fname && *end != '.') { + --end; + } + return( end + 1 ); } /** @@ -61,42 +61,42 @@ GetExtension(const char *fname) wBool_t wBitMapWriteFile(wDraw_p d, const char * fileName) { - GdkPixbuf *pixbuf; - GError *error; - gboolean res; - const char *fileFormat = GetExtension(fileName); - char *writeFormat = NULL; - - if(!strcasecmp(fileFormat, PNGFORMAT )){ - writeFormat = PNGFORMAT; - } - if( !strcasecmp(fileFormat, "jpg") || - !strcasecmp(fileFormat, "jpeg")){ - writeFormat = JPEGFORMAT; - } - - if(!writeFormat) { - wNoticeEx(NT_ERROR, "WriteBitMap: invalid file format!", "Ok", NULL); - return FALSE; - } - - pixbuf = gdk_pixbuf_get_from_drawable(NULL, (GdkWindow*)d->pixmap, NULL, 0, 0, - 0, 0, d->w, d->h); - - if (!pixbuf) { - wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_get failed", "Ok", NULL); - return FALSE; - } - - error = NULL; - res = gdk_pixbuf_save(pixbuf, fileName, writeFormat, &error, NULL); - - if (res == FALSE) { - wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_save failed", "Ok", NULL); - return FALSE; - } - - g_object_ref_sink(pixbuf); - g_object_unref(pixbuf); - return TRUE; + GdkPixbuf *pixbuf; + GError *error; + gboolean res; + const char *fileFormat = GetExtension(fileName); + char *writeFormat = NULL; + + if(!strcasecmp(fileFormat, PNGFORMAT )) { + writeFormat = PNGFORMAT; + } + if( !strcasecmp(fileFormat, "jpg") || + !strcasecmp(fileFormat, "jpeg")) { + writeFormat = JPEGFORMAT; + } + + if(!writeFormat) { + wNoticeEx(NT_ERROR, "WriteBitMap: invalid file format!", "Ok", NULL); + return FALSE; + } + + pixbuf = gdk_pixbuf_get_from_drawable(NULL, (GdkWindow*)d->pixmap, NULL, 0, 0, + 0, 0, d->w, d->h); + + if (!pixbuf) { + wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_get failed", "Ok", NULL); + return FALSE; + } + + error = NULL; + res = gdk_pixbuf_save(pixbuf, fileName, writeFormat, &error, NULL); + + if (res == FALSE) { + wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_save failed", "Ok", NULL); + return FALSE; + } + + g_object_ref_sink(pixbuf); + g_object_unref(pixbuf); + return TRUE; } |