From 16507e4f829223da3d7a8037155257842fbd113e Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Wed, 26 Mar 2014 01:35:07 -0300 Subject: fix crash when spelling error is in hidden part of a text on path (bzr r13212) --- src/ui/dialog/spellcheck.cpp | 88 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp index 00bd445bf..8a4ddc57e 100644 --- a/src/ui/dialog/spellcheck.cpp +++ b/src/ui/dialog/spellcheck.cpp @@ -590,52 +590,54 @@ SpellCheck::nextWord() // draw rect std::vector points = _layout->createSelectionShape(_begin_w, _end_w, _text->i2dt_affine()); - Geom::Point tl, br; - tl = br = points.front(); - for (unsigned i = 0 ; i < points.size() ; i ++) { - if (points[i][Geom::X] < tl[Geom::X]) - tl[Geom::X] = points[i][Geom::X]; - if (points[i][Geom::Y] < tl[Geom::Y]) - tl[Geom::Y] = points[i][Geom::Y]; - if (points[i][Geom::X] > br[Geom::X]) - br[Geom::X] = points[i][Geom::X]; - if (points[i][Geom::Y] > br[Geom::Y]) - br[Geom::Y] = points[i][Geom::Y]; - } + if (points.size() >= 4) { // we may not have a single quad if this is a clipped part of text on path; in that case skip drawing the rect + Geom::Point tl, br; + tl = br = points.front(); + for (unsigned i = 0 ; i < points.size() ; i ++) { + if (points[i][Geom::X] < tl[Geom::X]) + tl[Geom::X] = points[i][Geom::X]; + if (points[i][Geom::Y] < tl[Geom::Y]) + tl[Geom::Y] = points[i][Geom::Y]; + if (points[i][Geom::X] > br[Geom::X]) + br[Geom::X] = points[i][Geom::X]; + if (points[i][Geom::Y] > br[Geom::Y]) + br[Geom::Y] = points[i][Geom::Y]; + } - // expand slightly - Geom::Rect area = Geom::Rect(tl, br); - double mindim = fabs(tl[Geom::Y] - br[Geom::Y]); - if (fabs(tl[Geom::X] - br[Geom::X]) < mindim) - mindim = fabs(tl[Geom::X] - br[Geom::X]); - area.expandBy(MAX(0.05 * mindim, 1)); - - // create canvas path rectangle, red stroke - SPCanvasItem *rect = sp_canvas_bpath_new(sp_desktop_sketch(desktop), NULL); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(rect), 0xff0000ff, 3.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(rect), 0, SP_WIND_RULE_NONZERO); - SPCurve *curve = new SPCurve(); - curve->moveto(area.corner(0)); - curve->lineto(area.corner(1)); - curve->lineto(area.corner(2)); - curve->lineto(area.corner(3)); - curve->lineto(area.corner(0)); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(rect), curve); - sp_canvas_item_show(rect); - _rects = g_slist_prepend(_rects, rect); - - // scroll to make it all visible - Geom::Point const center = desktop->get_display_area().midpoint(); - area.expandBy(0.5 * mindim); - Geom::Point scrollto; - double dist = 0; - for (unsigned corner = 0; corner < 4; corner ++) { - if (Geom::L2(area.corner(corner) - center) > dist) { - dist = Geom::L2(area.corner(corner) - center); - scrollto = area.corner(corner); + // expand slightly + Geom::Rect area = Geom::Rect(tl, br); + double mindim = fabs(tl[Geom::Y] - br[Geom::Y]); + if (fabs(tl[Geom::X] - br[Geom::X]) < mindim) + mindim = fabs(tl[Geom::X] - br[Geom::X]); + area.expandBy(MAX(0.05 * mindim, 1)); + + // create canvas path rectangle, red stroke + SPCanvasItem *rect = sp_canvas_bpath_new(sp_desktop_sketch(desktop), NULL); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(rect), 0xff0000ff, 3.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(rect), 0, SP_WIND_RULE_NONZERO); + SPCurve *curve = new SPCurve(); + curve->moveto(area.corner(0)); + curve->lineto(area.corner(1)); + curve->lineto(area.corner(2)); + curve->lineto(area.corner(3)); + curve->lineto(area.corner(0)); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(rect), curve); + sp_canvas_item_show(rect); + _rects = g_slist_prepend(_rects, rect); + + // scroll to make it all visible + Geom::Point const center = desktop->get_display_area().midpoint(); + area.expandBy(0.5 * mindim); + Geom::Point scrollto; + double dist = 0; + for (unsigned corner = 0; corner < 4; corner ++) { + if (Geom::L2(area.corner(corner) - center) > dist) { + dist = Geom::L2(area.corner(corner) - center); + scrollto = area.corner(corner); + } } + desktop->scroll_to_point (scrollto, 1.0); } - desktop->scroll_to_point (scrollto, 1.0); // select text; if in Text tool, position cursor to the beginning of word // unless it is already in the word -- cgit v1.2.3 From bad6e2e0dd2b5cea8a3f8a56f68d301ded69e768 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 26 Mar 2014 13:30:14 -0400 Subject: Remove Snap menu item and improve grid menu item text (bzr r13213) --- src/desktop-events.cpp | 1 + src/interface.cpp | 3 --- src/menus-skeleton.h | 1 - src/verbs.cpp | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 244d5c8ab..0129a382d 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -230,6 +230,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge // Ruler click (without drag) toggle the guide visibility on and off Inkscape::XML::Node *repr = desktop->namedview->getRepr(); sp_namedview_toggle_guides(sp_desktop_document(desktop), repr); + } clicked = false; diff --git a/src/interface.cpp b/src/interface.cpp index bdbedd311..6eb1b6a5a 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -580,9 +580,6 @@ static gboolean checkitem_update(GtkWidget *widget, GdkEventExpose * /*event*/, else if (!strcmp(action->id, "ToggleGuides")) { ison = dt->namedview->getGuides(); } - else if (!strcmp(action->id, "ToggleSnapGlobal")) { - ison = dt->namedview->getSnapGlobal(); - } else if (!strcmp(action->id, "ViewCmsToggle")) { ison = dt->colorProfAdjustEnabled(); } diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index 3fcb77207..de48ea2be 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -131,7 +131,6 @@ static char const menus_skeleton[] = " \n" " \n" " \n" -" \n" " \n" " \n" " \n" diff --git a/src/verbs.cpp b/src/verbs.cpp index 8b72dd5ab..5914c058a 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2743,7 +2743,7 @@ Verb *Verb::_base_verbs[] = { new ZoomVerb(SP_VERB_ZOOM_OUT, "ZoomOut", N_("Zoom Out"), N_("Zoom out"), INKSCAPE_ICON("zoom-out")), new ZoomVerb(SP_VERB_TOGGLE_RULERS, "ToggleRulers", N_("_Rulers"), N_("Show or hide the canvas rulers"), NULL), new ZoomVerb(SP_VERB_TOGGLE_SCROLLBARS, "ToggleScrollbars", N_("Scroll_bars"), N_("Show or hide the canvas scrollbars"), NULL), - new ZoomVerb(SP_VERB_TOGGLE_GRID, "ToggleGrid", N_("_Grid"), N_("Show or hide the grid"), INKSCAPE_ICON("show-grid")), + new ZoomVerb(SP_VERB_TOGGLE_GRID, "ToggleGrid", N_("Page _Grid"), N_("Show or hide the page grid"), INKSCAPE_ICON("show-grid")), new ZoomVerb(SP_VERB_TOGGLE_GUIDES, "ToggleGuides", N_("G_uides"), N_("Show or hide guides (drag from a ruler to create a guide)"), INKSCAPE_ICON("show-guides")), new ZoomVerb(SP_VERB_TOGGLE_SNAPPING, "ToggleSnapGlobal", N_("Snap"), N_("Enable snapping"), INKSCAPE_ICON("snap")), new ZoomVerb(SP_VERB_TOGGLE_COMMANDS_TOOLBAR, "ToggleCommandsToolbar", N_("_Commands Bar"), N_("Show or hide the Commands bar (under the menu)"), NULL), -- cgit v1.2.3 From 9e0bf17c455a81983aeedb26203cfb80442bc630 Mon Sep 17 00:00:00 2001 From: David Mathog Date: Wed, 26 Mar 2014 21:36:31 +0100 Subject: Second patch for analyzer warnings in libuemf. (bzr r13214) --- src/extension/internal/text_reassemble.c | 39 ++++- src/libuemf/uemf_utf.c | 292 ++++++++++++++++++++----------- src/libuemf/upmf.c | 213 ++++++++++++++-------- src/libuemf/upmf.h | 2 +- src/libuemf/uwmf.c | 2 +- 5 files changed, 355 insertions(+), 193 deletions(-) (limited to 'src') diff --git a/src/extension/internal/text_reassemble.c b/src/extension/internal/text_reassemble.c index c62c83120..810e3f8cc 100644 --- a/src/extension/internal/text_reassemble.c +++ b/src/extension/internal/text_reassemble.c @@ -67,8 +67,8 @@ Optional compiler switches for development: File: text_reassemble.c -Version: 0.0.13 -Date: 24-MAR-2014 +Version: 0.0.14 +Date: 25-MAR-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) @@ -601,10 +601,13 @@ FT_INFO *ftinfo_init(void){ */ int ftinfo_make_insertable(FT_INFO *fti){ int status=0; + FNT_SPECS *tmp; if(!fti)return(2); if(fti->used >= fti->space){ fti->space += ALLOCINFO_CHUNK; - if((fti->fonts = (FNT_SPECS *) realloc(fti->fonts, fti->space * sizeof(FNT_SPECS) ))){ + tmp = (FNT_SPECS *) realloc(fti->fonts, fti->space * sizeof(FNT_SPECS) ); + if(tmp){ + fti->fonts = tmp; memset(&fti->fonts[fti->used],0,(fti->space - fti->used)*sizeof(FNT_SPECS)); } else { @@ -844,10 +847,13 @@ void ftinfo_dump(const FT_INFO *fti){ */ int fsp_alts_make_insertable(FNT_SPECS *fsp){ int status=0; + ALT_SPECS *tmp; if(!fsp)return(2); if(fsp->used >= fsp->space){ fsp->space += ALLOCINFO_CHUNK; - if((fsp->alts = (ALT_SPECS *) realloc(fsp->alts, fsp->space * sizeof(ALT_SPECS) ))){ + tmp = (ALT_SPECS *) realloc(fsp->alts, fsp->space * sizeof(ALT_SPECS) ); + if(tmp){ + fsp->alts = tmp; memset(&fsp->alts[fsp->used],0,(fsp->space - fsp->used)*sizeof(ALT_SPECS)); } else { @@ -912,10 +918,13 @@ int fsp_alts_weight(FNT_SPECS *fsp, uint32_t a_idx){ */ int csp_make_insertable(CHILD_SPECS *csp){ int status=0; + int *tmp; if(!csp)return(2); if(csp->used >= csp->space){ csp->space += ALLOCINFO_CHUNK; - if((csp->members = (int *) realloc(csp->members, csp->space * sizeof(int) ))){ + tmp = (int *) realloc(csp->members, csp->space * sizeof(int) ); + if(tmp){ + csp->members = tmp; memset(&csp->members[csp->used],0,(csp->space - csp->used)*sizeof(int)); } else { @@ -1007,9 +1016,12 @@ CX_INFO *cxinfo_init(void){ */ int cxinfo_make_insertable(CX_INFO *cxi){ int status=0; + CX_SPECS *tmp; if(cxi->used >= cxi->space){ cxi->space += ALLOCINFO_CHUNK; - if((cxi->cx = (CX_SPECS *) realloc(cxi->cx, cxi->space * sizeof(CX_SPECS) ))){ + tmp = (CX_SPECS *) realloc(cxi->cx, cxi->space * sizeof(CX_SPECS) ); + if(tmp){ + cxi->cx = tmp; memset(&cxi->cx[cxi->used],0,(cxi->space - cxi->used)*sizeof(CX_SPECS)); } else { @@ -1178,9 +1190,12 @@ TP_INFO *tpinfo_init(void){ */ int tpinfo_make_insertable(TP_INFO *tpi){ int status=0; + TCHUNK_SPECS *tmp; if(tpi->used >= tpi->space){ tpi->space += ALLOCINFO_CHUNK; - if((tpi->chunks = (TCHUNK_SPECS *) realloc(tpi->chunks, tpi->space * sizeof(TCHUNK_SPECS) ))){ + tmp = (TCHUNK_SPECS *) realloc(tpi->chunks, tpi->space * sizeof(TCHUNK_SPECS) ); + if(tmp){ + tpi->chunks = tmp; memset(&tpi->chunks[tpi->used],0,(tpi->space - tpi->used)*sizeof(TCHUNK_SPECS)); } else { @@ -1251,10 +1266,13 @@ BR_INFO *brinfo_init(void){ */ int brinfo_make_insertable(BR_INFO *bri){ int status=0; + BRECT_SPECS *tmp; if(!bri)return(2); if(bri->used >= bri->space){ bri->space += ALLOCINFO_CHUNK; - if(!(bri->rects = (BRECT_SPECS *) realloc(bri->rects, bri->space * sizeof(BRECT_SPECS) ))){ status = 1; } + tmp = (BRECT_SPECS *) realloc(bri->rects, bri->space * sizeof(BRECT_SPECS) ); + if(tmp){ bri->rects = tmp; } + else { status = 1;} } return(status); } @@ -1680,11 +1698,14 @@ int trinfo_load_ft_opts(TR_INFO *tri, int use_kern, int load_flags, int kern_mod */ int trinfo_append_out(TR_INFO *tri, const char *src){ size_t slen; + uint8_t *tmp; if(!src)return(-1); slen = strlen(src); if(tri->outused + (int) slen + 1 >= tri->outspace){ tri->outspace += TEREMAX(ALLOCOUT_CHUNK,slen+1); - if(!(tri->out = realloc(tri->out, tri->outspace )))return(-1); + tmp = realloc(tri->out, tri->outspace * sizeof(uint8_t) ); + if(tmp){ tri->out = tmp; } + else { return(-1); } } memcpy(tri->out + tri->outused, src, slen+1); /* copy the terminator */ tri->outused += slen; /* do not count the terminator in the length */ diff --git a/src/libuemf/uemf_utf.c b/src/libuemf/uemf_utf.c index 0159d51cd..5c6507818 100644 --- a/src/libuemf/uemf_utf.c +++ b/src/libuemf/uemf_utf.c @@ -227,6 +227,7 @@ uint16_t *U_Utf32leToUtf16le( size_t *len ){ char *dst,*dst2; + char *src2 = (char *) src; size_t srclen,dstlen,status; if(!src)return(NULL); @@ -235,16 +236,23 @@ uint16_t *U_Utf32leToUtf16le( dstlen = 2 + srclen; // this will always work, but may waste space dst2 = dst = calloc(dstlen,1); // so there will be at least one terminator - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-16LE", "UTF-32LE"); - status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=wchar16len((uint16_t *)dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-16LE", "UTF-32LE"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=wchar16len((uint16_t *)dst2); + } + } } return((uint16_t *)dst2); } @@ -270,17 +278,23 @@ uint32_t *U_Utf16leToUtf32le( else { srclen = 2*wchar16len(src)+2; } // include terminator, length in BYTES dstlen = 2*(2 + srclen); // This should always work dst2 = dst = calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-32LE", "UTF-16LE"); - if ( conv == (iconv_t)-1)return(NULL); - status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=wchar32len((uint32_t *)dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-32LE", "UTF-16LE"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=wchar32len((uint32_t *)dst2); + } + } } return((uint32_t *) dst2); } @@ -312,17 +326,23 @@ uint32_t *U_Latin1ToUtf32le( else { srclen = strlen(src)+1; } // include terminator, length in BYTES dstlen = sizeof(uint32_t)*(1 + srclen); // This should always work but might waste some space dst2 = dst = calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-32LE", "LATIN1"); - if ( conv == (iconv_t) -1)return(NULL); - status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=wchar32len((uint32_t *)dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-32LE", "LATIN1"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=wchar32len((uint32_t *)dst2); + } + } } return((uint32_t *) dst2); } @@ -348,17 +368,23 @@ uint32_t *U_Utf8ToUtf32le( else { srclen = strlen(src)+1; } // include terminator, length in BYTES dstlen = sizeof(uint32_t)*(1 + srclen); // This should always work but might waste some space dst2 = dst = calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-32LE", "UTF-8"); - if ( conv == (iconv_t) -1)return(NULL); - status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=wchar32len((uint32_t *)dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-32LE", "UTF-8"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=wchar32len((uint32_t *)dst2); + } + } } return((uint32_t *) dst2); } @@ -384,17 +410,23 @@ char *U_Utf32leToUtf8( else { srclen = 4*(1 + wchar32len(src)); } //include terminator, length in BYTES dstlen = 1 + srclen; // This should always work but might waste some space dst2 = dst = calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-8", "UTF-32LE"); - if ( conv == (iconv_t)-1)return(NULL); - status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=strlen(dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-8", "UTF-32LE"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=strlen(dst2); + } + } } return(dst2); } @@ -412,25 +444,31 @@ uint16_t *U_Utf8ToUtf16le( size_t *len ){ char *dst,*dst2; + char *src2 = (char *) src; size_t srclen,dstlen,status; - iconv_t conv; if(!src)return(NULL); if(max){ srclen = max; } else { srclen = strlen(src)+1; } // include terminator, length in BYTES dstlen = 2 * (1 + srclen); // this will always work, but may waste space dst2 = dst =calloc(dstlen,1); // so there will always be a terminator - if(!dst)return(NULL); - conv = iconv_open("UTF-16LE", "UTF-8"); - if (conv == (iconv_t) -1)return(NULL); - status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=wchar16len((uint16_t *)dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-16LE", "UTF-8"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=wchar16len((uint16_t *)dst2); + } + } } return((uint16_t *)dst2); } @@ -448,7 +486,7 @@ char *U_Utf16leToUtf8( size_t *len ){ char *dst, *dst2; - char *ret=NULL; + char *src2 = (char *) src; size_t srclen,dstlen,status; if(!src)return(NULL); @@ -457,16 +495,28 @@ char *U_Utf16leToUtf8( dstlen = 1 + 2*srclen; // this will always work, but may waste space // worst case is all glyphs (==max) need 4 UTF-8 encoded bytes + terminator. dst2 = dst = (char *) calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-8", "UTF-16LE"); - status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status != (size_t) -1){ - if(len)*len=strlen(dst2); - ret=U_strdup(dst2); // make a string of exactly the right size + if(dst){ + iconv_t conv = iconv_open("UTF-8", "UTF-16LE"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=strlen(dst2); + dst = dst2; + dst2 = U_strdup(dst); // make a string of exactly the right size + free(dst); // free the one which was probably too big + } + } } - free(dst2); // free the one which was probably too big - return(ret); + return(dst2); } /** @@ -482,22 +532,36 @@ char *U_Utf16leToLatin1( size_t *len ){ char *dst, *dst2; - char *ret=NULL; + char *src2 = (char *) src; size_t srclen,dstlen,status; if(!src)return(NULL); if(max){ srclen = 2*max; } else { srclen = 2*(1 +wchar16len(src)); } //include terminator, length in BYTES dstlen = 1 + srclen; // this will always work as latin1 is always 1 byte/character - ret = dst2 = dst = (char *) calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("LATIN1//TRANSLIT", "UTF-16LE"); // translate what can be, fill in with something close for the rest - status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status != (size_t) -1){ - if(len)*len=strlen(dst2); + dst2 = dst = (char *) calloc(dstlen,1); + if(dst){ + iconv_t conv = iconv_open("LATIN1//TRANSLIT", "UTF-16LE"); + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=strlen(dst2); + dst = dst2; + dst2 = U_strdup(dst); // make a string of exactly the right size + free(dst); // free the one which was probably too big + } + } } - return(ret); + return(dst2); } /** \brief Put a single 16 bit character into UTF-16LE form. @@ -534,22 +598,29 @@ char *U_Utf8ToLatin1( size_t *len ){ char *dst,*dst2; + char *src2 = (char *) src; size_t srclen,dstlen,status; if(max){ srclen = max; } else { srclen = strlen(src)+1; } // include terminator, length in BYTES dstlen = (1 + srclen); // This should always work but might waste some space dst2 = dst = calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("LATIN1//TRANSLIT", "UTF-8"); // translate what can be, fill in with something close for the rest - if ( conv == (iconv_t) -1)return(NULL); - status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=strlen(dst2); + if(dst){ + iconv_t conv = iconv_open("LATIN1//TRANSLIT", "UTF-8"); // translate what can be, fill in with something close for the rest + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=strlen(dst2); + } + } } return((char *) dst2); } @@ -571,22 +642,29 @@ char *U_Latin1ToUtf8( size_t *len ){ char *dst,*dst2; + char *src2 = (char *) src; size_t srclen,dstlen,status; if(max){ srclen = max; } else { srclen = strlen(src)+1; } // include terminator, will waste some space dstlen = (1 + 2*srclen); // This should always work because all latin1 convert to 1 or 2 byte UTF8, it might waste some space dst2 = dst = calloc(dstlen,1); - if(!dst)return(NULL); - iconv_t conv = iconv_open("UTF-8", "LATIN1"); // everything should translate - if ( conv == (iconv_t) -1)return(NULL); - status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); - iconv_close(conv); - if(status == (size_t) -1){ - free(dst2); - dst2 = NULL; - } - else if(len){ - *len=strlen(dst2); + if(dst){ + iconv_t conv = iconv_open("UTF-8", "LATIN1"); // everything should translate + if ( conv == (iconv_t) -1){ + free(dst2); + dst2=NULL; + } + else { + status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen); + iconv_close(conv); + if(status == (size_t) -1){ + free(dst2); + dst2 = NULL; + } + else if(len){ + *len=strlen(dst2); + } + } } return((char *) dst2); } diff --git a/src/libuemf/upmf.c b/src/libuemf/upmf.c index a7a5e42b5..0b7204635 100644 --- a/src/libuemf/upmf.c +++ b/src/libuemf/upmf.c @@ -70,18 +70,25 @@ void U_swap4(void *ul, unsigned int count); /** \brief Utility function for writing one or more EMF+ records in a PseudoObject to the EMF output file - \param po U_PSEUDO_OBJ to write + \return 1 on success, 0 on error. + \param po U_PSEUDO_OBJ to write, it is deleted after it is written \param sum U_PSEUDO_OBJ to use for scratch space \param et EMFTRACK used to write records to EMF file */ -void U_PMR_write(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *sum, EMFTRACK *et){ +int U_PMR_write(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *sum, EMFTRACK *et){ char *rec; + int status = 0; sum->Used = 0; /* clean it out, retaining allocated memory */ sum = U_PO_append(sum, "EMF+", 4); /* indicates that this comment holds an EMF+ record */ + if(!sum)goto end; sum = U_PO_append(sum, po->Data, po->Used); /* the EMF+ record itself */ + if(!sum)goto end; + U_PO_free(&po); /* delete the PseudoObject */ rec = U_EMRCOMMENT_set(sum->Used, sum->Data); /* stuff it into the EMF comment */ - (void) emf_append((PU_ENHMETARECORD)rec, et, 1); /* write it to the EMF file */ - U_PO_free(&po); /* delete the PseudoObjects */ + if(!emf_append((PU_ENHMETARECORD)rec, et, 1))goto end; /* write it to the EMF file, delete the record, check status */ + status = 1; +end: + return(status); } /** @@ -442,8 +449,12 @@ int U_OA_append(U_OBJ_ACCUM *oa, const char *data, int size, int Type, int Id){ tail = oa->used; if(oa->used + size >= oa->space){ oa->space += size; - oa->accum = (char *) realloc(oa->accum, oa->space); - if(!oa->accum)return(1); + char *newaccum = (char *) realloc(oa->accum, oa->space); + if(!newaccum){ + oa->space -= size; /* put it back the way it was */ + return(1); + } + oa->accum = newaccum; } memcpy(oa->accum + tail,data,size); oa->used += size; @@ -525,19 +536,22 @@ U_PSEUDO_OBJ *U_PO_create(char *Data, size_t Size, size_t Use, uint32_t Type){ U_PSEUDO_OBJ *U_PO_append(U_PSEUDO_OBJ *po, const char *Data, size_t Size){ /* po cannot be NULL,as in U_PO_po_append(), because there would be no way to determine the TYPE of the resulting PO */ if(po){ - if(po->Used + Size > po->Size){ + if(!po->Data || po->Used + Size > po->Size){ po->Size = po->Used + Size; - po->Data = realloc(po->Data, po->Size); + char *newData = realloc(po->Data, po->Size); + if(!newData){ + po->Size -= Size; /* put it back the way it was*/ + po=NULL; /* skip the rest of the actions, does not affect po in caller */ + } + else { + po->Data = newData; + } } - if(po->Data){ + if(po){ /* po->Data ready to append new data */ if(Data){ memcpy(po->Data + po->Used, Data, Size); } else { memset(po->Data + po->Used, 0, Size); } po->Used += Size; } - if(!po->Data){ - free(po); - po=NULL; - } } return(po); } @@ -551,33 +565,35 @@ U_PSEUDO_OBJ *U_PO_append(U_PSEUDO_OBJ *po, const char *Data, size_t Size){ */ U_PSEUDO_OBJ *U_PO_po_append(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *Src, int StripE){ if(!Src){ return(NULL); } + if((StripE && (Src->Used == 4)) || !Src->Used){ return(po); } /* appending nothing is not an error */ char *Data = Src->Data; - size_t Size = Src->Size; + size_t Size = Src->Used; /* append only what is used */ + U_PSEUDO_OBJ *ipo = po; if(StripE){ Size -= 4; } - if(!po){ - po = U_PO_create(NULL, 0, 0, Src->Type); /* create an empty pseudoobject */ + if(!ipo){ + ipo = U_PO_create(NULL, 0, 0, Src->Type); /* create an empty pseudoobject */ } - if(po){ - if(po->Data){ - if(po->Used + Size > po->Size){ - po->Size = po->Used + Size; - po->Data = realloc(po->Data, po->Size); + if(ipo){ + if(!ipo->Data || ipo->Used + Size > ipo->Size){ + ipo->Size = ipo->Used + Size; + char *newData = realloc(ipo->Data, ipo->Size); + if(!newData){ + if(ipo != po)U_PO_free(&ipo); } - if(po->Data){ - if(Data){ - if(StripE){ memcpy(po->Data + po->Used, Data + 4, Size); } /* Size is already 4 less, skip the leading Elements value */ - else { memcpy(po->Data + po->Used, Data, Size); } /* copy everything */ - } - else { memset(po->Data + po->Used, 0, Size); } /* set everything */ - po->Used += Size; + else { + ipo->Data = newData; } } - if(!po->Data){ - free(po); - po=NULL; + if(ipo){ + if(Data){ + if(StripE){ memcpy(ipo->Data + ipo->Used, Data + 4, Size); } /* Size is already 4 less, skip the leading Elements value */ + else { memcpy(ipo->Data + ipo->Used, Data, Size); } /* copy everything */ + } + else { memset(ipo->Data + ipo->Used, 0, Size); } /* set everything */ + ipo->Used += Size; } } - return(po); + return(ipo); } /** @@ -672,7 +688,7 @@ U_DPSEUDO_OBJ *U_PATH_create(int Elements, const U_PMF_POINTF *Points, uint8_t F if(!(Others & U_PPT_Bezier)){ return(NULL); } /* will pass if either line or bezier is set */ } - U_DPSEUDO_OBJ *Path = (U_DPSEUDO_OBJ *)malloc(sizeof(U_DPSEUDO_OBJ)); + U_DPSEUDO_OBJ *Path = (U_DPSEUDO_OBJ *)calloc(sizeof(U_DPSEUDO_OBJ),1); /* make poTypes and poPoints NULL */ const U_SERIAL_DESC List[] = { {NULL,0,0,U_XX} }; if(Path){ Path->Elements = Elements; @@ -733,17 +749,23 @@ int U_DPO_clear(U_DPSEUDO_OBJ *dpo){ int U_PATH_moveto(U_DPSEUDO_OBJ *Path, U_PMF_POINTF Point, uint8_t Flags){ if(!Path){ return(0); } U_PSEUDO_OBJ *tpo; + U_PSEUDO_OBJ *tpo2; uint8_t Type = (Flags & U_PTP_NotClose) | U_PPT_Start; tpo = U_PMF_POINTF_set(1, &Point); if(!tpo){ return(0); } - Path->poPoints = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poPoints = tpo2; + tpo = U_PMF_PATHPOINTTYPE_set(1, &Type); if(!tpo){ return(0); } - Path->poTypes = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); + tpo2= U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poTypes = tpo2; Path->Elements++; return(1); @@ -760,16 +782,22 @@ int U_PATH_lineto(U_DPSEUDO_OBJ *Path, U_PMF_POINTF Point, uint8_t Flags){ if(!Path || !Path->Elements){ return(0); } /* must be at least one point to extend from */ if(Path->poTypes->Data[Path->Elements - 1] & U_PTP_CloseSubpath){ return(0); } /* cannot extend a closed subpath */ U_PSEUDO_OBJ *tpo; + U_PSEUDO_OBJ *tpo2; uint8_t Type = (Flags & U_PTP_NotClose) | U_PPT_Line; tpo = U_PMF_POINTF_set(1, &Point); if(!tpo){ return(0); } - Path->poPoints = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poPoints = tpo2; + tpo = U_PMF_PATHPOINTTYPE_set(1, &Type); if(!tpo){ return(0); } - Path->poTypes = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poTypes = tpo2; Path->Elements++; return(1); @@ -802,18 +830,24 @@ int U_PATH_polylineto(U_DPSEUDO_OBJ *Path, uint32_t Elements, const U_PMF_POINTF if(!Path || !Points){ return(0); } if(!Elements){ return(1); } /* harmless - do nothing */ U_PSEUDO_OBJ *tpo; + U_PSEUDO_OBJ *tpo2; uint8_t First, Others; tpo = U_PMF_POINTF_set(Elements, Points); - Path->poPoints = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poPoints = tpo2; + if(StartSeg){ First = (Flags & U_PTP_NotClose) | U_PPT_Start; } else { First = (Flags & U_PTP_NotClose) | U_PPT_Line; } Others = (Flags & U_PTP_NotClose) | U_PPT_Line; tpo = U_PMF_PATHPOINTTYPE_set2(Elements, First, Others); if(!tpo){ return(0); } - Path->poTypes = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poTypes = tpo2; Path->Elements += Elements; return(1); @@ -842,19 +876,24 @@ int U_PATH_polybezierto(U_DPSEUDO_OBJ *Path, uint32_t Elements, const U_PMF_POIN if(StartSeg && ((Elements - 1) % 3)){ return(0); } /* new segment must be 1 + N*3 points */ if(!StartSeg && (Elements % 3)){ return(0); } /* extend segment must be N*3 points */ U_PSEUDO_OBJ *tpo; + U_PSEUDO_OBJ *tpo2; uint8_t First, Others; tpo = U_PMF_POINTF_set(Elements, Points); - Path->poPoints = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poPoints = tpo2; if(StartSeg){ First = (Flags & U_PTP_NotClose) | U_PPT_Start; } else { First = (Flags & U_PTP_NotClose) | U_PPT_Bezier; } Others = (Flags & U_PTP_NotClose) | U_PPT_Bezier; tpo = U_PMF_PATHPOINTTYPE_set2(Elements, First, Others); if(!tpo){ return(0); } - Path->poTypes = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); + tpo2 = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS); U_PO_free(&tpo); + if(!tpo2)return(0); + Path->poTypes = tpo2; Path->Elements += Elements; return(1); @@ -2856,23 +2895,28 @@ U_PSEUDO_OBJ *U_PMF_PATHPOINTTYPERLE_set(uint32_t Elements, const uint8_t *Bz, c if(!Bz || !RL || !Ppte)return(NULL); /* allocate space in the structure but put no data in */ U_PSEUDO_OBJ *po = U_PO_create(NULL, 4 + 2*Elements, 0, U_PMF_PATHPOINTTYPERLE_OID | U_PMF_ARRAY_OID); - - U_PSEUDO_OBJ *poi = U_PMF_4NUM_set(Elements); - po = U_PO_append(po, poi->Data, poi->Used); - U_PO_free(&poi); - + U_PSEUDO_OBJ *holdpo = po; if(po){ + U_PSEUDO_OBJ *poi = U_PMF_4NUM_set(Elements); + if(!poi)goto end; + po = U_PO_append(po, poi->Data, poi->Used); + U_PO_free(&poi); + if(!po)goto end; + for( ;Elements; Elements--, Bz++, RL++, Ppte++){ po = U_PO_append(po, (char *)Ppte, 1); - if(*RL > 0x3F){ /* run length too big for field */ - U_PO_free(&po); - return(NULL); - } + if(!po)goto end; + + if(*RL > 0x3F) goto end; /* run length too big for field */ + utmp = (*Bz ? 1 : 0) | ((*RL & 0x3F)<<2); /* bit 1 is not used and is set to 0 */ po = U_PO_append(po, (char *)&utmp, 1); + if(!po)goto end; } } - return(po); +end: + if(!po)U_PO_free(&holdpo); + return(holdpo); } /** @@ -3007,10 +3051,13 @@ U_PSEUDO_OBJ *U_PMF_POINTR_set(uint32_t Elements, const U_PMF_POINTF *Coords){ U_PSEUDO_OBJ *poi; /* Worst case scenario it is 4 bytes per coord, plus the count */ U_PSEUDO_OBJ *po = U_PO_create(NULL, 4 + 4*Elements, 0, U_PMF_POINTR_OID); /* not exactly an array, so no U_PMF_ARRAY_OID */ + U_PSEUDO_OBJ *holdpo = po; + if(!po)goto end; poi = U_PMF_4NUM_set(Elements); po = U_PO_append(po, poi->Data, poi->Used); U_PO_free(&poi); + if(po)goto end; for(Xf = Yf = 0.0 ;Elements; Elements--, Coords++){ Xf = U_ROUND(Coords->X) - Xf; @@ -3026,27 +3073,27 @@ U_PSEUDO_OBJ *U_PMF_POINTR_set(uint32_t Elements, const U_PMF_POINTF *Coords){ if(!poi)poi = U_PMF_INTEGER15_set(X); /* This one must work because of the range checking, above */ po = U_PO_append(po, poi->Data, poi->Used); U_PO_free(&poi); + if(!po)goto end; poi = U_PMF_INTEGER7_set(Y); if(!poi)poi = U_PMF_INTEGER15_set(Y); /* This one must work because of the range checking, above */ po = U_PO_append(po, poi->Data, poi->Used); U_PO_free(&poi); + if(!po)goto end; } /* Because the values stored were some unpredictable combination of 1 and 2 bytes, the last byte may not end on a 4 byte boundary. Make it do so by padding with up to 3 zero bytes. */ -#if 1 + int residual; - unsigned long int us, uu; - us = po->Size; /* printing size_t portably is a pain, this avoids the issue */ - uu = po->Used; residual = 3 & po->Used; -printf("DEBUG Used:%lu residual:%d\n",uu, residual);fflush(stdout); if(residual){ - po = U_PO_append(po, NULL, (4 - residual)); + po = U_PO_append(po, NULL, (4 - residual)); + if(!po)goto end; } -printf("DEBUG Size:%lu Used:%lu \n",us,uu);fflush(stdout); -#endif - return(po); + +end: + if(!po)U_PO_free(&holdpo); + return(holdpo); } /** @@ -4714,22 +4761,29 @@ U_PSEUDO_OBJ *U_PMR_OBJECT_set(uint32_t ObjID, int otype, int ntype, uint32_t TS int Pad = UP4(TSize) - TSize; if((otype < U_OT_Brush) || (otype > U_OT_CustomLineCap)){ return(NULL); } if(ntype && (cbData > U_OBJRECLIM)){ return(NULL); } - if(!Data){ return(NULL); } + if(!Data || !cbData){ return(NULL); } U_PSEUDO_OBJ *po; if(!ntype && !TSize && (cbData > U_OBJRECLIM)){ ntype = 1; TSize = cbData; po = U_PO_create(NULL, TSize + 16 * (1 + (TSize/cbData)), 0, U_PMR_OBJECT_OID); - if(!po)return(po); - while(cbData){ - CSize = (cbData > U_OBJRECLIM ? U_OBJRECLIM : cbData); - U_PSEUDO_OBJ *pot = U_PMR_OBJECT_set(ObjID, otype, ntype, TSize, CSize, Data); - po = U_PO_po_append(po, pot, U_PMF_KEEP_ELEMENTS); - U_PO_free(&pot); - Data += U_OBJRECLIM; - cbData -= CSize; - } + if(po){ + while(cbData){ + CSize = (cbData > U_OBJRECLIM ? U_OBJRECLIM : cbData); + U_PSEUDO_OBJ *pot = U_PMR_OBJECT_set(ObjID, otype, ntype, TSize, CSize, Data); + if(!pot)break; + U_PSEUDO_OBJ *newpo = U_PO_po_append(po, pot, U_PMF_KEEP_ELEMENTS); + U_PO_free(&pot); + if(!newpo)break; + po = newpo; + Data += U_OBJRECLIM; + cbData -= CSize; + } + if(cbData){ /* some error */ + U_PO_free(&po); + } + } } else { /* Send in DataSize, U_PMR_CMN_HDR_set will adjust Header Size with 1-3 pad bytes if needed */ @@ -6280,22 +6334,24 @@ int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ \param Points Caller must free. Array of U_PMF_POINTF coordinates. */ int U_PMF_VARPOINTS_get(const char **contents, uint16_t Flags, int Elements, U_PMF_POINTF **Points){ - if(!contents || !*contents || !Points || !Elements){ return(0); } + int status = 0; + if(!contents || !*contents || !Points || !Elements){ return(status); } U_PMF_POINTF *pts = (U_PMF_POINTF *)malloc(Elements * sizeof(U_PMF_POINTF)); + if(!pts){ return(status); } + *Points = pts; U_FLOAT XF, YF; U_FLOAT XFS, YFS; - *Points = pts; for(XFS = YFS = 0.0; Elements; Elements--, pts++){ if(Flags & U_PPF_P){ - U_PMF_POINTR_get(contents, &XF, &YF); + if(!U_PMF_POINTR_get(contents, &XF, &YF))break; /* this should never happen */ XFS += XF; /* position relative to previous point, first point is always 0,0 */ YFS += YF; pts->X = XFS; pts->Y = YFS; } else if(Flags & U_PPF_C){ - (void) U_PMF_POINT_get(contents, &XF, &XF); + if(!U_PMF_POINT_get(contents, &XF, &XF))break; /* this should never happen */ pts->X = XF; pts->Y = YF; } @@ -6303,7 +6359,14 @@ int U_PMF_VARPOINTS_get(const char **contents, uint16_t Flags, int Elements, U_P (void) U_PMF_POINTF_get(contents, &(pts->X), &(pts->Y)); } } - return(1); + if(Elements){ /* some error in the preceding */ + free(pts); + *Points = NULL; + } + else { + status = 1; + } + return(status); } /** diff --git a/src/libuemf/upmf.h b/src/libuemf/upmf.h index 48fc9bf53..27ac94a89 100644 --- a/src/libuemf/upmf.h +++ b/src/libuemf/upmf.h @@ -2820,7 +2820,7 @@ typedef struct { //! \cond /* EMF+ prototypes (helper functions) */ -void U_PMR_write(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *sum, EMFTRACK *et); +int U_PMR_write(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *sum, EMFTRACK *et); int U_PMR_drawline(uint32_t PenID, uint32_t PathID, U_PMF_POINTF Start, U_PMF_POINTF End, int Dashed, U_PSEUDO_OBJ *sum, EMFTRACK *et); int U_PMR_drawstring( const char *string, int Vpos, uint32_t FontID, const U_PSEUDO_OBJ *BrushID, uint32_t FormatID, U_PMF_STRINGFORMAT Sfs, const char *FontName, U_FLOAT Height, U_FontInfoParams *fip, uint32_t FontFlags, diff --git a/src/libuemf/uwmf.c b/src/libuemf/uwmf.c index 82be9f324..b4a1dfc52 100644 --- a/src/libuemf/uwmf.c +++ b/src/libuemf/uwmf.c @@ -599,7 +599,7 @@ const char *U_wmr_names(int idx){ */ const char *U_wmr_escnames(int idx){ const char *name; - if(idx>=0 && idx <= 0x0023){ + if(idx>=1 && idx <= 0x0023){ switch(idx){ case 0x0001: name = "NEWFRAME"; break; case 0x0002: name = "ABORTDOC"; break; -- cgit v1.2.3 From 31c8b511d6306bd4e922388ef483d1c232ed52d6 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 21:46:17 +0100 Subject: Two more changes in libuemf to silence analyzer. (bzr r13215) --- src/libuemf/symbol_convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libuemf/symbol_convert.c b/src/libuemf/symbol_convert.c index 650f4332d..6a919fc2f 100644 --- a/src/libuemf/symbol_convert.c +++ b/src/libuemf/symbol_convert.c @@ -988,8 +988,8 @@ int i; if(hold_symb != new_symb || hold_wing != new_wing || hold_zdng != new_zdng || hold_pua != new_pua ){ // must (re)generate tables if(!from_unicode){ // create arrays - from_unicode = (unsigned char *) calloc(0x10000,sizeof(char)); - to_font = (unsigned char *) calloc(0x10000,sizeof(char)); + from_unicode = (unsigned char *) calloc(0x10000,sizeof(unsigned char)); + to_font = (unsigned char *) calloc(0x10000,sizeof(unsigned char)); // should check here for malloc error } hold_symb = new_symb; -- cgit v1.2.3 From 2af3266fc2db760a1c8771e5945a0c94587d18e8 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 22:14:16 +0100 Subject: Cleaned up includes of tools / revert experimental casting macro replacements from r13061 (bzr r13216) --- src/ui/tools/arc-tool.h | 10 ++++- src/ui/tools/box3d-tool.h | 19 ++++++-- src/ui/tools/calligraphic-tool.h | 10 ++++- src/ui/tools/connector-tool.h | 33 +++++++++----- src/ui/tools/dropper-tool.h | 4 ++ src/ui/tools/dynamic-base.cpp | 1 + src/ui/tools/dynamic-base.h | 11 ++++- src/ui/tools/eraser-tool.cpp | 1 + src/ui/tools/eraser-tool.h | 2 + src/ui/tools/freehand-base.h | 25 +++++++---- src/ui/tools/measure-tool.cpp | 1 + src/ui/tools/pencil-tool.h | 4 ++ src/ui/tools/tool-base.cpp | 1 + src/ui/tools/tool-base.h | 92 +++++++++++++++++++++------------------ src/widgets/connector-toolbar.cpp | 3 ++ src/widgets/pencil-toolbar.cpp | 12 +---- 16 files changed, 147 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/ui/tools/arc-tool.h b/src/ui/tools/arc-tool.h index eaa50f2b9..c4c67660d 100644 --- a/src/ui/tools/arc-tool.h +++ b/src/ui/tools/arc-tool.h @@ -16,12 +16,18 @@ */ #include -#include #include <2geom/point.h> +#include + #include "ui/tools/tool-base.h" -#include "sp-ellipse.h" +class SPItem; +class SPGenericEllipse; + +namespace Inkscape { + class Selection; +} #define SP_ARC_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_ARC_CONTEXT(obj) (dynamic_cast(const Inkscape::UI::Tools::ToolBase*(obj)) != NULL) diff --git a/src/ui/tools/box3d-tool.h b/src/ui/tools/box3d-tool.h index 99bf99a7a..1dd6bb5f8 100644 --- a/src/ui/tools/box3d-tool.h +++ b/src/ui/tools/box3d-tool.h @@ -16,12 +16,25 @@ */ #include -#include -#include "ui/tools/tool-base.h" + +#include <2geom/point.h> +#include + #include "proj_pt.h" #include "vanishing-point.h" -#include "box3d.h" +#include "ui/tools/tool-base.h" + +class SPItem; +class SPBox3D; + +namespace Box3D { + struct VPDrag; +} + +namespace Inkscape { + class Selection; +} #define SP_BOX3D_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_BOX3D_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) diff --git a/src/ui/tools/calligraphic-tool.h b/src/ui/tools/calligraphic-tool.h index 926e9d126..83b4d73ff 100644 --- a/src/ui/tools/calligraphic-tool.h +++ b/src/ui/tools/calligraphic-tool.h @@ -18,8 +18,16 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include +#include + +#include <2geom/point.h> + #include "ui/tools/dynamic-base.h" -#include "splivarot.h" + +class SPItem; +class Path; +struct SPCanvasItem; #define DDC_MIN_PRESSURE 0.0 #define DDC_MAX_PRESSURE 1.0 diff --git a/src/ui/tools/connector-tool.h b/src/ui/tools/connector-tool.h index 59534a173..b85412a53 100644 --- a/src/ui/tools/connector-tool.h +++ b/src/ui/tools/connector-tool.h @@ -12,25 +12,34 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include -#include -#include -#include "ui/tools/tool-base.h" +#include +#include + #include <2geom/point.h> -#include "libavoid/connector.h" -#include +#include -#define SP_CONNECTOR_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) -//#define SP_IS_CONNECTOR_CONTEXT(obj) (dynamic_cast((const ToolBase*)obj) != NULL) +#include "ui/tools/tool-base.h" -struct SPKnot; +class SPItem; class SPCurve; +struct SPKnot; +struct SPCanvasItem; + +namespace Avoid { + class ConnRef; +} + +namespace Inkscape { + class Selection; -namespace Inkscape -{ - class Selection; + namespace XML { + class Node; + } } +#define SP_CONNECTOR_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) +//#define SP_IS_CONNECTOR_CONTEXT(obj) (dynamic_cast((const ToolBase*)obj) != NULL) + enum { SP_CONNECTOR_CONTEXT_IDLE, SP_CONNECTOR_CONTEXT_DRAGGING, diff --git a/src/ui/tools/dropper-tool.h b/src/ui/tools/dropper-tool.h index dd6f25bb6..cfeb91dab 100644 --- a/src/ui/tools/dropper-tool.h +++ b/src/ui/tools/dropper-tool.h @@ -12,8 +12,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <2geom/point.h> + #include "ui/tools/tool-base.h" +struct SPCanvasItem; + #define SP_DROPPER_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_DROPPER_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) diff --git a/src/ui/tools/dynamic-base.cpp b/src/ui/tools/dynamic-base.cpp index 21b4b0532..eb789d850 100644 --- a/src/ui/tools/dynamic-base.cpp +++ b/src/ui/tools/dynamic-base.cpp @@ -10,6 +10,7 @@ #include "preferences.h" #include "display/sp-canvas-item.h" #include "desktop.h" +#include "display/curve.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 diff --git a/src/ui/tools/dynamic-base.h b/src/ui/tools/dynamic-base.h index 76fcd0f02..c948fa286 100644 --- a/src/ui/tools/dynamic-base.h +++ b/src/ui/tools/dynamic-base.h @@ -20,8 +20,15 @@ */ #include "ui/tools/tool-base.h" -#include "display/curve.h" -#include <2geom/point.h> + +struct SPCanvasItem; +class SPCurve; + +namespace Inkscape { + namespace XML { + class Node; + } +} #define SAMPLING_SIZE 8 /* fixme: ?? */ diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 011d28663..4106785e7 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -66,6 +66,7 @@ #include "verbs.h" #include <2geom/math-utils.h> #include <2geom/pathvector.h> +#include "display/curve.h" #include "ui/tools/eraser-tool.h" diff --git a/src/ui/tools/eraser-tool.h b/src/ui/tools/eraser-tool.h index eb7eb16e8..110f57ba3 100644 --- a/src/ui/tools/eraser-tool.h +++ b/src/ui/tools/eraser-tool.h @@ -19,6 +19,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <2geom/point.h> + #include "ui/tools/dynamic-base.h" #define ERC_MIN_PRESSURE 0.0 diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h index c8da9faed..5a4b91800 100644 --- a/src/ui/tools/freehand-base.h +++ b/src/ui/tools/freehand-base.h @@ -14,22 +14,29 @@ * Released under GNU GPL */ -#include -#include -#include <2geom/point.h> +#include + #include "ui/tools/tool-base.h" -#include "live_effects/effect.h" +#include "live_effects/effect-enum.h" + +struct SPCanvasItem; +class SPCurve; +struct SPDrawAnchor; + +namespace Inkscape { + class Selection; +} + +namespace boost { + template + class optional; +} /* Freehand context */ #define SP_DRAW_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_DRAW_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) -struct SPDrawAnchor; -namespace Inkscape -{ - class Selection; -} namespace Inkscape { namespace UI { diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 380aa79e3..2c85874bc 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -43,6 +43,7 @@ #include "sp-namedview.h" #include "enums.h" #include "ui/control-manager.h" +#include "knot-enums.h" using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index efc1f60e0..2ad05606d 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -7,6 +7,10 @@ #include "ui/tools/freehand-base.h" +#include <2geom/piecewise.h> +#include <2geom/d2.h> +#include <2geom/sbasis.h> + #define SP_PENCIL_CONTEXT(obj) (dynamic_cast((ToolBase*)obj)) #define SP_IS_PENCIL_CONTEXT(obj) (dynamic_cast((const ToolBase*)obj) != NULL) diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 752053be1..96ac95926 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -57,6 +57,7 @@ #include "shape-editor.h" #include "sp-guide.h" #include "color.h" +#include "knot.h" // globals for temporary switching to selector by space static bool selector_toggled = FALSE; diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index def6e3d91..e11a22296 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -12,25 +12,29 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include +#include +#include + +#include <2geom/point.h> #include +#include #include #include "knot.h" -#include "2geom/forward.h" #include "preferences.h" -class GrDrag; -class SPDesktop; -class SPItem; -class ShapeEditor; +namespace Glib { + class ustring; +} + +class GrDrag; +class SPDesktop; +class SPItem; +class ShapeEditor; namespace Inkscape { class MessageContext; class SelCue; - namespace XML { - class Node; - } } #define SP_EVENT_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) @@ -45,8 +49,7 @@ class ToolBase; gboolean sp_event_context_snap_watchdog_callback(gpointer data); void sp_event_context_discard_delayed_snap_event(ToolBase *ec); -class DelayedSnapEvent -{ +class DelayedSnapEvent { public: enum DelayedSnapEventOrigin { UNDEFINED_HANDLER = 0, @@ -60,12 +63,19 @@ public: }; DelayedSnapEvent(ToolBase *event_context, gpointer const dse_item, gpointer dse_item2, GdkEventMotion const *event, DelayedSnapEvent::DelayedSnapEventOrigin const origin) - : _timer_id(0), _event(NULL), _item(dse_item), _item2(dse_item2), _origin(origin), _event_context(event_context) + : _timer_id(0) + , _event(NULL) + , _item(dse_item) + , _item2(dse_item2) + , _origin(origin) + , _event_context(event_context) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double value = prefs->getDoubleLimited("/options/snapdelay/value", 0, 0, 1000); + _timer_id = g_timeout_add(value, &sp_event_context_snap_watchdog_callback, this); _event = gdk_event_copy((GdkEvent*) event); + ((GdkEventMotion *)_event)->time = GDK_CURRENT_TIME; } @@ -74,11 +84,25 @@ public: if (_event != NULL) gdk_event_free(_event); // Remove the copy of the original event } - ToolBase* getEventContext() {return _event_context;} - DelayedSnapEventOrigin getOrigin() {return _origin;} - GdkEvent* getEvent() {return _event;} - gpointer getItem() {return _item;} - gpointer getItem2() {return _item2;} + ToolBase* getEventContext() { + return _event_context; + } + + DelayedSnapEventOrigin getOrigin() { + return _origin; + } + + GdkEvent* getEvent() { + return _event; + } + + gpointer getItem() { + return _item; + } + + gpointer getItem2() { + return _item2; + } private: guint _timer_id; @@ -137,7 +161,10 @@ public: Inkscape::SelCue *_selcue; GrDrag *_grdrag; - GrDrag *get_drag () {return _grdrag;} + + GrDrag *get_drag () { + return _grdrag; + } ShapeEditor* shape_editor; @@ -162,8 +189,10 @@ public: */ class ToolPrefObserver: public Inkscape::Preferences::Observer { public: - ToolPrefObserver(Glib::ustring const &path, ToolBase *ec) : - Inkscape::Preferences::Observer(path), ec(ec) { + ToolPrefObserver(Glib::ustring const &path, ToolBase *ec) + : Inkscape::Preferences::Observer(path) + , ec(ec) + { } virtual void notify(Inkscape::Preferences::Entry const &val) { @@ -189,7 +218,6 @@ protected: /// The cursor's hot spot gint hot_x, hot_y; - /// Whether the tool should receive delayed snap events bool sp_event_context_knot_mouseover() const; @@ -226,28 +254,6 @@ void sp_toggle_dropper(SPDesktop *dt); bool sp_event_context_knot_mouseover(ToolBase *ec); } // namespace Tools - -//#include - -namespace Tool { - -template -bool is_a(const T* t) { - //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); - //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); - - return dynamic_cast(static_cast(t)) != NULL; -} - -template -Derived* to(T* t) { - //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); - //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); - - return dynamic_cast(static_cast(t)); -} - -} // namespace Tool } // namespace UI } // namespace Inkscape diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index a0965721f..9bbc1bbb4 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -28,12 +28,15 @@ # include "config.h" #endif +#include + #include "connector-toolbar.h" #include "conn-avoid-ref.h" #include "desktop-handles.h" #include "desktop.h" #include "document-undo.h" #include "ege-adjustment-action.h" +#include "enums.h" #include "graphlayout.h" #include "ink-action.h" #include "inkscape.h" diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index 6598e995a..682de8594 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -73,16 +73,8 @@ static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl) // in pen tool we have more options than in pencil tool; if one of them was chosen, we do any // preparatory work here - //if (SP_IS_PEN_CONTEXT(desktop->event_context)) { - // Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context); - // sp_pen_context_set_polyline_mode(pc); - //} - - using namespace Inkscape::UI; - using Inkscape::UI::Tools::PenTool; - - if (Tool::is_a(desktop->event_context)) { - PenTool* pc = Tool::to(desktop->event_context); + if (SP_IS_PEN_CONTEXT(desktop->event_context)) { + Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context); pc->setPolylineMode(); } } -- cgit v1.2.3 From 490cccade871fc530f7927f9eb8e7425e0e928db Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 22:24:57 +0100 Subject: Cleaned up connector-tool, pen-tool, and pencil-tool. (bzr r13217) --- src/ui/tools/connector-tool.cpp | 96 ++++++++---------- src/ui/tools/pen-tool.cpp | 212 ++++++++++++++++++++++------------------ src/ui/tools/pencil-tool.cpp | 93 ++++++++---------- 3 files changed, 199 insertions(+), 202 deletions(-) (limited to 'src') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index d2e23837c..b72ce5346 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -379,7 +379,7 @@ cc_deselect_handle(SPKnot* knot) } bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; + bool ret = false; Geom::Point p(event->button.x, event->button.y); @@ -412,7 +412,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { } } - ret = TRUE; + ret = true; } break; @@ -422,7 +422,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { this->_setActiveShape(item); } - ret = TRUE; + ret = true; } break; @@ -434,7 +434,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { } bool ConnectorTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -469,20 +469,15 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { Geom::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ Geom::Point p = this->desktop->w2d(event_w); - ToolBase *event_context = SP_EVENT_CONTEXT(this); - gint ret = FALSE; - - if ( bevent.button == 1 && !event_context->space_panning ) { - - SPDesktop *desktop = this->desktop; + bool ret = false; + if ( bevent.button == 1 && !this->space_panning ) { if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { - return TRUE; + return true; } - Geom::Point const event_w(bevent.x, - bevent.y); + Geom::Point const event_w(bevent.x, bevent.y); this->xp = bevent.x; this->yp = bevent.y; @@ -520,7 +515,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { } this->state = SP_CONNECTOR_CONTEXT_DRAGGING; - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_DRAGGING: @@ -539,7 +534,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { } this->cc_set_active_conn(this->newconn); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_CLOSE: @@ -564,20 +559,19 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { else if (this->npoints != 0) { this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; } } return ret; } gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); + bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow middle-button scrolling - return FALSE; + return false; } Geom::Point const event_w(mevent.x, mevent.y); @@ -586,7 +580,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( ( abs( (gint) mevent.x - this->xp ) < this->tolerance ) && ( abs( (gint) mevent.y - this->yp ) < this->tolerance ) ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -594,12 +588,10 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { // the motion notify coordinates as given (no snapping back to origin) this->within_tolerance = false; - SPDesktop *const dt = this->desktop; - /* Find desktop coordinates */ - Geom::Point p = dt->w2d(event_w); + Geom::Point p = desktop->w2d(event_w); - SnapManager &m = dt->namedview->snap_manager; + SnapManager &m = desktop->namedview->snap_manager; switch (this->state) { case SP_CONNECTOR_CONTEXT_DRAGGING: @@ -607,12 +599,12 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gobble_motion_events(mevent.state); // This is movement during a connector creation. if ( this->npoints > 0 ) { - m.setup(dt); + m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); this->selection->clear(); this->_setSubsequentPoint(p); - ret = TRUE; + ret = true; } break; } @@ -621,7 +613,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gobble_motion_events(GDK_BUTTON1_MASK); g_assert( SP_IS_PATH(this->clickeditem)); - m.setup(dt); + m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); @@ -645,7 +637,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->red_curve->transform(i2d); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_STOP: @@ -653,7 +645,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { break; default: if (!this->sp_event_context_knot_mouseover()) { - m.setup(dt); + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); m.unSetup(); } @@ -663,13 +655,10 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { } gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && !event_context->space_panning ) { + bool ret = false; - SPDesktop *desktop = this->desktop; + if ( revent.button == 1 && !this->space_panning ) { SPDocument *doc = sp_desktop_document(desktop); - SnapManager &m = desktop->namedview->snap_manager; Geom::Point const event_w(revent.x, revent.y); @@ -688,7 +677,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->within_tolerance) { this->_finishSegment(p); - return TRUE; + return true; } // Connector has been created via a drag, end it now. this->_setSubsequentPoint(p); @@ -711,7 +700,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { doc->ensureUpToDate(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - return TRUE; + return true; break; } case SP_CONNECTOR_CONTEXT_STOP: @@ -720,13 +709,13 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { default: break; } - ret = TRUE; + ret = true; } return ret; } gint ConnectorTool::_handleKeyPress(guint const keyval) { - gint ret = FALSE; + bool ret = false; switch (keyval) { case GDK_KEY_Return: @@ -734,13 +723,11 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { if (this->npoints != 0) { this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; } break; case GDK_KEY_Escape: if (this->state == SP_CONNECTOR_CONTEXT_REROUTING) { - - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); this->_reroutingFinish(NULL); @@ -750,13 +737,13 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { this->state = SP_CONNECTOR_CONTEXT_IDLE; desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, _("Connector endpoint drag cancelled.")); - ret = TRUE; + ret = true; } else if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting this->state = SP_CONNECTOR_CONTEXT_STOP; this->_resetColors(); - ret = TRUE; + ret = true; } break; default: @@ -766,7 +753,6 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { } void ConnectorTool::_reroutingFinish(Geom::Point *const p) { - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); // Clear the temporary path: @@ -819,14 +805,13 @@ void ConnectorTool::_setInitialPoint(Geom::Point const p) { void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { g_assert( this->npoints != 0 ); - SPDesktop *dt = this->desktop; - Geom::Point o = dt->dt2doc(this->p[0]); - Geom::Point d = dt->dt2doc(p); + Geom::Point o = desktop->dt2doc(this->p[0]); + Geom::Point d = desktop->dt2doc(p); Avoid::Point src(o[Geom::X], o[Geom::Y]); Avoid::Point dst(d[Geom::X], d[Geom::Y]); if (!this->newConnRef) { - Avoid::Router *router = sp_desktop_document(dt)->router; + Avoid::Router *router = sp_desktop_document(desktop)->router; this->newConnRef = new Avoid::ConnRef(router); this->newConnRef->setEndpoint(Avoid::VertID::src, src); if (this->isOrthogonal) @@ -841,7 +826,7 @@ void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { this->newConnRef->router()->processTransaction(); // Recreate curve from libavoid route. recreateCurve( this->red_curve, this->newConnRef, this->curvature ); - this->red_curve->transform(dt->doc2dt()); + this->red_curve->transform(desktop->doc2dt()); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); } @@ -890,7 +875,6 @@ void ConnectorTool::_flushWhite(SPCurve *gc) { /* Now we have to go back to item coordinates at last */ c->transform(this->desktop->dt2doc()); - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -965,7 +949,6 @@ void ConnectorTool::_finishSegment(Geom::Point const /*p*/) { } void ConnectorTool::_finish() { - SPDesktop *const desktop = this->desktop; desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector")); this->red_curve->reset(); @@ -1083,7 +1066,6 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc) } void ConnectorTool::_activeShapeAddKnot(SPItem* item) { - SPDesktop *desktop = this->desktop; SPKnot *knot = sp_knot_new(desktop, 0); knot->owner = item; @@ -1096,10 +1078,12 @@ void ConnectorTool::_activeShapeAddKnot(SPItem* item) { // We don't want to use the standard knot handler. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; g_signal_connect(G_OBJECT(knot->item), "event", G_CALLBACK(cc_generic_knot_handler), knot); + sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); sp_knot_show(knot); this->knots[knot] = 1; @@ -1198,7 +1182,6 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { } for (int i = 0; i < 2; ++i) { - // Create the handle if it doesn't exist if ( this->endpt_handle[i] == NULL ) { SPKnot *knot = sp_knot_new(this->desktop, @@ -1215,6 +1198,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { // since we don't want this knot to be draggable. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; g_signal_connect(G_OBJECT(knot->item), "event", @@ -1228,6 +1212,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { g_signal_handlers_disconnect_by_func( G_OBJECT(this->endpt_handle[i]->item), (void*)G_CALLBACK(endpt_handler), (gpointer) this ); + this->endpt_handler_id[i] = 0; } @@ -1264,10 +1249,13 @@ void cc_create_connection_point(ConnectorTool* cc) { cc_deselect_handle( cc->selected_handle ); } + SPKnot *knot = sp_knot_new(cc->desktop, 0); + // We do not process events on this knot. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; cc_select_handle( knot ); diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 7228690b1..ea66360d0 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -263,7 +263,7 @@ void PenTool::_endpointSnapHandle(Geom::Point &p, guint const state) const { } bool PenTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -287,7 +287,7 @@ bool PenTool::item_handler(SPItem* item, GdkEvent* event) { * Callback to handle all pen events. */ bool PenTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -327,22 +327,20 @@ bool PenTool::root_handler(GdkEvent* event) { gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->events_disabled) { // skip event processing if events are disabled - return FALSE; + return false; } - FreehandBase * const dc = SP_DRAW_CONTEXT(this); - SPDesktop * const desktop = dc->desktop; Geom::Point const event_w(bevent.x, bevent.y); Geom::Point event_dt(desktop->w2d(event_w)); - ToolBase *event_context = SP_EVENT_CONTEXT(this); - gint ret = FALSE; - if (bevent.button == 1 && !event_context->space_panning + bool ret = false; + + if (bevent.button == 1 && !this->space_panning // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path) && this->expecting_clicks_for_LPE != 1) { - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { + return true; } if (!this->grab ) { @@ -392,8 +390,8 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); } - spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state); - ret = TRUE; + spdc_create_single_dot(this, p, "/tools/freehand/pen", bevent.state); + ret = true; break; } @@ -441,9 +439,9 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->green_anchor && this->green_anchor->active) { // we clicked on the current curve start, so close it even if // we drag a handle away from it - dc->green_closed = TRUE; + this->green_closed = TRUE; } - ret = TRUE; + ret = true; break; } else { @@ -454,7 +452,7 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { } this->state = this->polylines_only ? PenTool::POINT : PenTool::CONTROL; - ret = TRUE; + ret = true; break; case PenTool::CONTROL: g_warning("Button down in CONTROL state"); @@ -474,17 +472,17 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { this->_finishSegment(event_dt, bevent.state); if (this->green_closed) { // finishing at the start anchor, close curve - this->_finish(TRUE); + this->_finish(true); } else { // finishing at some other anchor, finish curve but not close - this->_finish(FALSE); + this->_finish(false); } - ret = TRUE; + ret = true; } else if (bevent.button == 3 && this->npoints != 0) { // right click - finish path - this->_finish(FALSE); - ret = TRUE; + this->_finish(false); + ret = true; } if (this->expecting_clicks_for_LPE > 0) { @@ -498,28 +496,25 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { * Handle motion_notify event. */ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(this); - SPDesktop * const dt = event_context->desktop; + bool ret = false; - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling - return FALSE; + return false; } if (this->events_disabled) { // skip motion events if pen events are disabled - return FALSE; + return false; } - Geom::Point const event_w(mevent.x, - mevent.y); + Geom::Point const event_w(mevent.x, mevent.y); + if (pen_within_tolerance) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( Geom::LInfty( event_w - pen_drag_origin_w ) < tolerance ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -528,7 +523,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { pen_within_tolerance = false; // Find desktop coordinates - Geom::Point p = dt->w2d(event_w); + Geom::Point p = desktop->w2d(event_w); // Test, whether we hit any anchor SPDrawAnchor *anchor = spdc_test_inside(this, event_w); @@ -543,8 +538,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->_setSubsequentPoint(p, true); ret = TRUE; } else if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -554,7 +549,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { // Placing controls is last operation in CLOSE state this->_endpointSnap(p, mevent.state); this->_setCtrl(p, mevent.state); - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is perfectly valid @@ -584,7 +579,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } - ret = TRUE; + ret = true; } else { if (anchor && !this->anchor_statusbar) { this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to continue the path from this point.")); @@ -594,8 +589,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -614,15 +609,15 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->_setCtrl(this->p[1], mevent.state); } gobble_motion_events(GDK_BUTTON1_MASK); - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is perfectly valid break; default: if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -641,17 +636,14 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->events_disabled) { // skip event processing if events are disabled - return FALSE; + return false; } - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && !event_context->space_panning) { + bool ret = false; - FreehandBase *dc = SP_DRAW_CONTEXT (this); + if (revent.button == 1 && !this->space_panning) { + Geom::Point const event_w(revent.x, revent.y); - Geom::Point const event_w(revent.x, - revent.y); // Find desktop coordinates Geom::Point p = this->desktop->w2d(event_w); @@ -677,14 +669,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } } this->state = PenTool::CONTROL; - ret = TRUE; + ret = true; break; case PenTool::CONTROL: // End current segment this->_endpointSnap(p, revent.state); this->_finishSegment(p, revent.state); this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; case PenTool::CLOSE: // End current segment @@ -692,14 +684,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->_endpointSnap(p, revent.state); } this->_finishSegment(p, revent.state); - this->_finish(TRUE); + this->_finish(true); this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is allowed, if we just canceled curve this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -717,10 +709,10 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->_finishSegment(p, revent.state); if (this->green_closed) { // finishing at the start anchor, close curve - this->_finish(TRUE); + this->_finish(true); } else { // finishing at some other anchor, finish curve but not close - this->_finish(FALSE); + this->_finish(false); } break; case PenTool::STOP: @@ -730,7 +722,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { break; } this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -742,9 +734,9 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->grab = NULL; } - ret = TRUE; + ret = true; - dc->green_closed = FALSE; + this->green_closed = FALSE; } // TODO: can we be sure that the path was created correctly? @@ -752,13 +744,12 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) { this->setPolylineMode(); - ToolBase *ec = SP_EVENT_CONTEXT(this); - Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); + Inkscape::Selection *selection = sp_desktop_selection(this->desktop); if (this->waiting_LPE) { // we have an already created LPE waiting for a path this->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); - selection->add(SP_OBJECT(this->waiting_item)); + selection->add(this->waiting_item); this->waiting_LPE = NULL; } else { // the case that we need to create a new LPE and apply it to the just-drawn path is @@ -770,11 +761,11 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; + bool ret = false; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path if (this->npoints != 0 && bevent.button == 1) { this->_finish(FALSE); - ret = TRUE; + ret = true; } return ret; } @@ -881,67 +872,97 @@ void PenTool::_lastpointToLine() { gint PenTool::_handleKeyPress(GdkEvent *event) { - - gint ret = FALSE; + bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px switch (get_group0_keyval (&event->key)) { - case GDK_KEY_Left: // move last point left case GDK_KEY_KP_Left: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(-10, 0); // shift - else this->_lastpointMoveScreen(-1, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(-10, 0); // shift + } + else { + this->_lastpointMoveScreen(-1, 0); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(-10*nudge, 0); // shift - else this->_lastpointMove(-nudge, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(-10*nudge, 0); // shift + } + else { + this->_lastpointMove(-nudge, 0); // no shift + } } - ret = TRUE; + ret = true; } break; case GDK_KEY_Up: // move last point up case GDK_KEY_KP_Up: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, 10); // shift - else this->_lastpointMoveScreen(0, 1); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(0, 10); // shift + } + else { + this->_lastpointMoveScreen(0, 1); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(0, 10*nudge); // shift - else this->_lastpointMove(0, nudge); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(0, 10*nudge); // shift + } + else { + this->_lastpointMove(0, nudge); // no shift + } } - ret = TRUE; + ret = true; } break; case GDK_KEY_Right: // move last point right case GDK_KEY_KP_Right: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(10, 0); // shift - else this->_lastpointMoveScreen(1, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(10, 0); // shift + } + else { + this->_lastpointMoveScreen(1, 0); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(10*nudge, 0); // shift - else this->_lastpointMove(nudge, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(10*nudge, 0); // shift + } + else { + this->_lastpointMove(nudge, 0); // no shift + } } - ret = TRUE; + ret = true; } break; case GDK_KEY_Down: // move last point down case GDK_KEY_KP_Down: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, -10); // shift - else this->_lastpointMoveScreen(0, -1); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(0, -10); // shift + } + else { + this->_lastpointMoveScreen(0, -1); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(0, -10*nudge); // shift - else this->_lastpointMove(0, -nudge); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(0, -10*nudge); // shift + } + else { + this->_lastpointMove(0, -nudge); // no shift + } } - ret = TRUE; + ret = true; } break; @@ -983,29 +1004,29 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { case GDK_KEY_u: if (MOD__SHIFT_ONLY(event)) { this->_lastpointToCurve(); - ret = TRUE; + ret = true; } break; case GDK_KEY_L: case GDK_KEY_l: if (MOD__SHIFT_ONLY(event)) { this->_lastpointToLine(); - ret = TRUE; + ret = true; } break; case GDK_KEY_Return: case GDK_KEY_KP_Enter: if (this->npoints != 0) { - this->_finish(FALSE); - ret = TRUE; + this->_finish(false); + ret = true; } break; case GDK_KEY_Escape: if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting this->_cancel (); - ret = TRUE; + ret = true; } break; case GDK_KEY_z: @@ -1013,13 +1034,13 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { if (MOD__CTRL_ONLY(event) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo this->_cancel (); - ret = TRUE; + ret = true; } break; case GDK_KEY_g: case GDK_KEY_G: if (MOD__SHIFT_ONLY(event)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); + sp_selection_to_guides(this->desktop); ret = true; } break; @@ -1029,7 +1050,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) { if (!this->red_curve->is_empty()) { this->_cancel (); - ret = TRUE; + ret = true; } else { // do nothing; this event should be handled upstream } @@ -1067,7 +1088,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { this->state = PenTool::POINT; this->_setSubsequentPoint(pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; - ret = TRUE; + ret = true; } break; default: @@ -1120,7 +1141,6 @@ void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_t g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles g_assert(message != NULL); - SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; Geom::Point rel = p - this->p[pc_point_to_compare]; Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str()); @@ -1257,7 +1277,6 @@ void PenTool::_finish(gboolean const closed) { this->_disableEvents(); - SPDesktop *const desktop = this->desktop; this->message_context->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); @@ -1278,7 +1297,6 @@ void PenTool::_finish(gboolean const closed) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - this->desktop->canvas->endForcedFullRedraws(); this->_enableEvents(); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 230ec62af..88bba34cf 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -115,7 +115,7 @@ void PencilTool::_endpointSnap(Geom::Point &p, guint const state) { * Callback for handling all pencil context events. */ bool PencilTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -150,16 +150,13 @@ bool PencilTool::root_handler(GdkEvent* event) { } gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( bevent.button == 1 && !event_context->space_panning) { + bool ret = false; - FreehandBase *dc = SP_DRAW_CONTEXT (this); - SPDesktop *desktop = dc->desktop; + if ( bevent.button == 1 && !this->space_panning) { Inkscape::Selection *selection = sp_desktop_selection(desktop); - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { + return true; } if (!this->grab) { @@ -185,7 +182,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { switch (this->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Current segment will be finished with release */ - ret = TRUE; + ret = true; break; default: /* Set first point of sequence */ @@ -196,7 +193,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { if (!(bevent.state & GDK_SHIFT_MASK)) { m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); } - spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state); + spdc_create_single_dot(this, p, "/tools/freehand/pencil", bevent.state); m.unSetup(); ret = true; break; @@ -221,7 +218,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { } this->sa = anchor; this->_setStartpoint(p); - ret = TRUE; + ret = true; break; } @@ -231,25 +228,23 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { } gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { - SPDesktop *const dt = this->desktop; - if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point this->is_drawing = false; - return TRUE; + return true; } - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + bool ret = false; + + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling - return FALSE; + return false; } if ( ( mevent.state & GDK_BUTTON1_MASK ) && !this->grab && this->is_drawing) { /* Grab mouse, so release will not pass unnoticed */ - this->grab = SP_CANVAS_ITEM(dt->acetate); + this->grab = SP_CANVAS_ITEM(desktop->acetate); sp_canvas_item_grab(this->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), @@ -257,7 +252,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { } /* Find desktop coordinates */ - Geom::Point p = dt->w2d(Geom::Point(mevent.x, mevent.y)); + Geom::Point p = desktop->w2d(Geom::Point(mevent.x, mevent.y)); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(mevent.x, mevent.y)); @@ -266,7 +261,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( Geom::LInfty( Geom::Point(mevent.x,mevent.y) - pencil_drag_origin_w ) < tolerance ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } @@ -286,13 +281,13 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { p = ptnr; } this->_setEndpoint(p); - ret = TRUE; + ret = true; break; default: /* We may be idle or already freehand */ if ( mevent.state & GDK_BUTTON1_MASK && this->is_drawing ) { if (this->state == SP_PENCIL_CONTEXT_IDLE) { - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); } this->state = SP_PENCIL_CONTEXT_FREEHAND; @@ -313,7 +308,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->ps.push_back(this->p[0]); } this->_addFreehandPoint(p, mevent.state); - ret = TRUE; + ret = true; } if (anchor && !this->anchor_statusbar) { @@ -340,8 +335,8 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { // a) press the mousebutton to start a freehand drawing, or // b) release the mousebutton to finish a freehand drawing if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -351,20 +346,16 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { } gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && this->is_drawing && !event_context->space_panning) { - SPDesktop *const dt = this->desktop; + bool ret = false; + if ( revent.button == 1 && this->is_drawing && !this->space_panning) { this->is_drawing = false; /* Find desktop coordinates */ - Geom::Point p = dt->w2d(Geom::Point(revent.x, revent.y)); + Geom::Point p = desktop->w2d(Geom::Point(revent.x, revent.y)); /* Test whether we hit any anchor. */ - SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, - revent.y)); + SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, revent.y)); switch (this->state) { case SP_PENCIL_CONTEXT_IDLE: @@ -374,7 +365,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed this->state = SP_PENCIL_CONTEXT_ADDLINE; } - ret = TRUE; + ret = true; break; case SP_PENCIL_CONTEXT_ADDLINE: /* Finish segment now */ @@ -387,13 +378,12 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->_setEndpoint(p); this->_finishEndpoint(); this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(event_context); - ret = TRUE; + sp_event_context_discard_delayed_snap_event(this); + ret = true; break; case SP_PENCIL_CONTEXT_FREEHAND: if (revent.state & GDK_MOD1_MASK) { /* sketch mode: interpolate the sketched path and improve the current output path with the new interpolation. don't finish sketch */ - this->_sketchInterpolate(); if (this->green_anchor) { @@ -418,7 +408,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->ea = anchor; /* Write curves to object */ - dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); + desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); this->_interpolate(); spdc_concat_colors_and_flush(this, FALSE); @@ -431,7 +421,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // reset sketch mode too this->sketch_n = 0; } - ret = TRUE; + ret = true; break; case SP_PENCIL_CONTEXT_SKETCH: default: @@ -444,7 +434,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->grab = NULL; } - ret = TRUE; + ret = true; } return ret; } @@ -458,7 +448,7 @@ void PencilTool::_cancel() { this->is_drawing = false; this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + sp_event_context_discard_delayed_snap_event(this); this->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); @@ -478,7 +468,8 @@ void PencilTool::_cancel() { } gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { - gint ret = FALSE; + bool ret = false; + switch (keyval) { case GDK_KEY_Up: case GDK_KEY_Down: @@ -486,7 +477,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { case GDK_KEY_KP_Down: // Prevent the zoom field from activation. if (!mod_ctrl_only(state)) { - ret = TRUE; + ret = true; } break; case GDK_KEY_Escape: @@ -494,7 +485,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { // if drawing, cancel, otherwise pass it up for deselecting if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); - ret = TRUE; + ret = true; } } break; @@ -504,14 +495,14 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { // if drawing, cancel, otherwise pass it up for undo if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); - ret = TRUE; + ret = true; } } break; case GDK_KEY_g: case GDK_KEY_G: if (mod_shift_only(state)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); + sp_selection_to_guides(this->desktop); ret = true; } break; @@ -530,14 +521,14 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { } gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { - gint ret = FALSE; + bool ret = false; switch (keyval) { case GDK_KEY_Alt_L: case GDK_KEY_Alt_R: case GDK_KEY_Meta_L: case GDK_KEY_Meta_R: if (this->state == SP_PENCIL_CONTEXT_SKETCH) { - spdc_concat_colors_and_flush(this, FALSE); + spdc_concat_colors_and_flush(this, false); this->sketch_n = 0; this->sa = NULL; this->ea = NULL; @@ -545,9 +536,9 @@ gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + sp_event_context_discard_delayed_snap_event(this); this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand sketch")); - ret = TRUE; + ret = true; } break; default: -- cgit v1.2.3 From 93d7b99fddde41fa76427a916da80e6d5c27c932 Mon Sep 17 00:00:00 2001 From: David Mathog Date: Wed, 26 Mar 2014 22:41:33 +0100 Subject: Fixed typo. (bzr r13218) --- src/libuemf/upmf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/libuemf/upmf.c b/src/libuemf/upmf.c index 0b7204635..3c652c9b8 100644 --- a/src/libuemf/upmf.c +++ b/src/libuemf/upmf.c @@ -6360,7 +6360,7 @@ int U_PMF_VARPOINTS_get(const char **contents, uint16_t Flags, int Elements, U_P } } if(Elements){ /* some error in the preceding */ - free(pts); + free(*Points); *Points = NULL; } else { -- cgit v1.2.3 From f8c86a279932d95dc938cab0343fb22383e9fa86 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 23:06:03 +0100 Subject: Cleaned up pencil-tool. (bzr r13219) --- src/ui/tools/pencil-tool.cpp | 84 +++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 88bba34cf..86274928b 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -237,7 +237,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool ret = false; - if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || (mevent.state & GDK_BUTTON2_MASK) || (mevent.state & GDK_BUTTON3_MASK)) { // allow scrolling return false; } @@ -285,7 +285,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { break; default: /* We may be idle or already freehand */ - if ( mevent.state & GDK_BUTTON1_MASK && this->is_drawing ) { + if ( (mevent.state & GDK_BUTTON1_MASK) && this->is_drawing ) { if (this->state == SP_PENCIL_CONTEXT_IDLE) { sp_event_context_discard_delayed_snap_event(this); } @@ -641,37 +641,31 @@ void PencilTool::_interpolate() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square( this->desktop->w2d().descrim() * - tol) * exp(0.2*tol - 2); + double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); - g_assert(is_zero(this->req_tangent) - || is_unit_vector(this->req_tangent)); - Geom::Point const tHatEnd(0, 0); + g_assert(is_zero(this->req_tangent) || is_unit_vector(this->req_tangent)); - guint n_points = this->ps.size(); this->green_curve->reset(); this->red_curve->reset(); this->red_curve_is_valid = false; - Geom::Point * b = g_new(Geom::Point, 4*n_points); - Geom::Point * points = g_new(Geom::Point, 4*n_points); - for (unsigned int i = 0; i < this->ps.size(); i++) { - points[i] = this->ps[i]; - } + int n_points = this->ps.size(); // worst case gives us a segment per point - int max_segs = 4*n_points; + int max_segs = 4 * n_points; - int const n_segs = Geom::bezier_fit_cubic_r(b, points, n_points, - tolerance_sq, max_segs); + std::vector b(max_segs); - if ( n_segs > 0) - { + int const n_segs = Geom::bezier_fit_cubic_r(b.data(), this->ps.data(), n_points, tolerance_sq, max_segs); + + if (n_segs > 0) { /* Fit and draw and reset state */ this->green_curve->moveto(b[0]); + for (int c = 0; c < n_segs; c++) { - this->green_curve->curveto(b[4*c+1], b[4*c+2], b[4*c+3]); + this->green_curve->curveto(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]); } + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->green_curve); /* Fit and draw and copy last point */ @@ -691,8 +685,7 @@ void PencilTool::_interpolate() { : Geom::unit_vector(req_vec) ); } } - g_free(b); - g_free(points); + this->ps.clear(); } @@ -705,41 +698,36 @@ void PencilTool::_sketchInterpolate() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square( this->desktop->w2d().descrim() * - tol) * exp(0.2*tol - 2); + double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); bool average_all_sketches = prefs->getBool("/tools/freehand/pencil/average_all_sketches", true); - g_assert(is_zero(this->req_tangent) - || is_unit_vector(this->req_tangent)); - Geom::Point const tHatEnd(0, 0); + g_assert(is_zero(this->req_tangent) || is_unit_vector(this->req_tangent)); - guint n_points = this->ps.size(); this->red_curve->reset(); this->red_curve_is_valid = false; - Geom::Point * b = g_new(Geom::Point, 4*n_points); - Geom::Point * points = g_new(Geom::Point, 4*n_points); - for (unsigned i = 0; i < this->ps.size(); i++) { - points[i] = this->ps[i]; - } + int n_points = this->ps.size(); // worst case gives us a segment per point - int max_segs = 4*n_points; + int max_segs = 4 * n_points; - int const n_segs = Geom::bezier_fit_cubic_r(b, points, n_points, - tolerance_sq, max_segs); + std::vector b(max_segs); - if ( n_segs > 0) - { + int const n_segs = Geom::bezier_fit_cubic_r(b.data(), this->ps.data(), n_points, tolerance_sq, max_segs); + + if (n_segs > 0) { Geom::Path fit(b[0]); + for (int c = 0; c < n_segs; c++) { - fit.appendNew(b[4*c+1], b[4*c+2], b[4*c+3]); + fit.appendNew(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]); } + Geom::Piecewise > fit_pwd2 = fit.toPwSb(); - if ( this->sketch_n > 0 ) { - double t =0.; + if (this->sketch_n > 0) { + double t; + if (average_all_sketches) { // Average = (sum of all) / n // = (sum of all + new one) / n+1 @@ -748,18 +736,21 @@ void PencilTool::_sketchInterpolate() { } else { t = 0.5; } + this->sketch_interpolation = Geom::lerp(t, fit_pwd2, this->sketch_interpolation); + // simplify path, to eliminate small segments - Path *path = new Path; - path->LoadPathVector(Geom::path_from_piecewise(this->sketch_interpolation, 0.01)); - path->Simplify(0.5); - Geom::PathVector *pathv = path->MakePathVector(); + Path path; + path.LoadPathVector(Geom::path_from_piecewise(this->sketch_interpolation, 0.01)); + path.Simplify(0.5); + + Geom::PathVector *pathv = path.MakePathVector(); this->sketch_interpolation = (*pathv)[0].toPwSb(); - delete path; delete pathv; } else { this->sketch_interpolation = fit_pwd2; } + this->sketch_n++; this->green_curve->reset(); @@ -783,8 +774,7 @@ void PencilTool::_sketchInterpolate() { : Geom::unit_vector(req_vec) ); } } - g_free(b); - g_free(points); + this->ps.clear(); } -- cgit v1.2.3 From 60e6c1d025ba5923e15a49763378732eaabe4f5a Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 27 Mar 2014 01:11:46 +0100 Subject: Changed some return types from gint to bool. (bzr r13220) --- src/ui/tools/connector-tool.cpp | 8 ++++---- src/ui/tools/connector-tool.h | 8 ++++---- src/ui/tools/pen-tool.cpp | 10 +++++----- src/ui/tools/pen-tool.h | 10 +++++----- src/ui/tools/pencil-tool.cpp | 10 +++++----- src/ui/tools/pencil-tool.h | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index b72ce5346..e19f35832 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -465,7 +465,7 @@ bool ConnectorTool::root_handler(GdkEvent* event) { } -gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { +bool ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { Geom::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ Geom::Point p = this->desktop->w2d(event_w); @@ -565,7 +565,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { return ret; } -gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { +bool ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -654,7 +654,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { return ret; } -gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { +bool ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { bool ret = false; if ( revent.button == 1 && !this->space_panning ) { @@ -714,7 +714,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { return ret; } -gint ConnectorTool::_handleKeyPress(guint const keyval) { +bool ConnectorTool::_handleKeyPress(guint const keyval) { bool ret = false; switch (keyval) { diff --git a/src/ui/tools/connector-tool.h b/src/ui/tools/connector-tool.h index b85412a53..9a9ae64cf 100644 --- a/src/ui/tools/connector-tool.h +++ b/src/ui/tools/connector-tool.h @@ -124,10 +124,10 @@ public: private: void _selectionChanged(Inkscape::Selection *selection); - gint _handleButtonPress(GdkEventButton const &bevent); - gint _handleMotionNotify(GdkEventMotion const &mevent); - gint _handleButtonRelease(GdkEventButton const &revent); - gint _handleKeyPress(guint const keyval); + bool _handleButtonPress(GdkEventButton const &bevent); + bool _handleMotionNotify(GdkEventMotion const &mevent); + bool _handleButtonRelease(GdkEventButton const &revent); + bool _handleKeyPress(guint const keyval); void _setInitialPoint(Geom::Point const p); void _setSubsequentPoint(Geom::Point const p); diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index ea66360d0..09c0a2a4f 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -324,7 +324,7 @@ bool PenTool::root_handler(GdkEvent* event) { /** * Handle mouse button press event. */ -gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { +bool PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->events_disabled) { // skip event processing if events are disabled return false; @@ -495,7 +495,7 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { /** * Handle motion_notify event. */ -gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { +bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool ret = false; if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { @@ -633,7 +633,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { /** * Handle mouse button release event. */ -gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { +bool PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->events_disabled) { // skip event processing if events are disabled return false; @@ -760,7 +760,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { return ret; } -gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { +bool PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { bool ret = false; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path if (this->npoints != 0 && bevent.button == 1) { @@ -871,7 +871,7 @@ void PenTool::_lastpointToLine() { } -gint PenTool::_handleKeyPress(GdkEvent *event) { +bool PenTool::_handleKeyPress(GdkEvent *event) { bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px diff --git a/src/ui/tools/pen-tool.h b/src/ui/tools/pen-tool.h index 182d270ee..4dec7b4fe 100644 --- a/src/ui/tools/pen-tool.h +++ b/src/ui/tools/pen-tool.h @@ -80,11 +80,11 @@ protected: virtual bool item_handler(SPItem* item, GdkEvent* event); private: - gint _handleButtonPress(GdkEventButton const &bevent); - gint _handleMotionNotify(GdkEventMotion const &mevent); - gint _handleButtonRelease(GdkEventButton const &revent); - gint _handle2ButtonPress(GdkEventButton const &bevent); - gint _handleKeyPress(GdkEvent *event); + bool _handleButtonPress(GdkEventButton const &bevent); + bool _handleMotionNotify(GdkEventMotion const &mevent); + bool _handleButtonRelease(GdkEventButton const &revent); + bool _handle2ButtonPress(GdkEventButton const &bevent); + bool _handleKeyPress(GdkEvent *event); void _setInitialPoint(Geom::Point const p); void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status = 0); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 86274928b..374846539 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -149,7 +149,7 @@ bool PencilTool::root_handler(GdkEvent* event) { return ret; } -gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { +bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) { bool ret = false; if ( bevent.button == 1 && !this->space_panning) { @@ -227,7 +227,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { return ret; } -gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { +bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point @@ -345,7 +345,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { return ret; } -gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { +bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) { bool ret = false; if ( revent.button == 1 && this->is_drawing && !this->space_panning) { @@ -467,7 +467,7 @@ void PencilTool::_cancel() { this->desktop->canvas->endForcedFullRedraws(); } -gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { +bool PencilTool::_handleKeyPress(guint const keyval, guint const state) { bool ret = false; switch (keyval) { @@ -520,7 +520,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { return ret; } -gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { +bool PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { bool ret = false; switch (keyval) { case GDK_KEY_Alt_L: diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index 2ad05606d..e01b0afb5 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -54,11 +54,11 @@ protected: virtual bool root_handler(GdkEvent* event); private: - gint _handleButtonPress(GdkEventButton const &bevent); - gint _handleMotionNotify(GdkEventMotion const &mevent); - gint _handleButtonRelease(GdkEventButton const &revent); - gint _handleKeyPress(guint const keyval, guint const state); - gint _handleKeyRelease(guint const keyval, guint const state); + bool _handleButtonPress(GdkEventButton const &bevent); + bool _handleMotionNotify(GdkEventMotion const &mevent); + bool _handleButtonRelease(GdkEventButton const &revent); + bool _handleKeyPress(guint const keyval, guint const state); + bool _handleKeyRelease(guint const keyval, guint const state); void _setStartpoint(Geom::Point const &p); void _setEndpoint(Geom::Point const &p); -- cgit v1.2.3