From f067ce79b19e7f23940510dfa88fb5fc9febc41d Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 9 Sep 2010 22:30:21 +0200 Subject: Removing SetRedraw, and trying a bulk method instead. --- iup/src/gtk/iupgtk_common.c | 6 ------ iup/src/gtk/iupgtk_text.c | 15 ++++++++++++- iup/src/iup_drv.h | 4 ---- iup/src/iup_layout.c | 10 --------- iup/src/iup_text.c | 25 ++++++++++++++++++++-- iup/src/iup_text.h | 4 +++- iup/src/mot/iupmot_common.c | 6 ------ iup/src/mot/iupmot_text.c | 14 +++++++++++- iup/src/win/iupwin_common.c | 5 ----- iup/src/win/iupwin_text.c | 52 ++++++++++++++++++++++++++++++++++++--------- 10 files changed, 95 insertions(+), 46 deletions(-) (limited to 'iup/src') diff --git a/iup/src/gtk/iupgtk_common.c b/iup/src/gtk/iupgtk_common.c index a27087e..d84c1c8 100755 --- a/iup/src/gtk/iupgtk_common.c +++ b/iup/src/gtk/iupgtk_common.c @@ -107,12 +107,6 @@ void iupdrvRedrawNow(Ihandle *ih) gdk_window_process_updates(window, FALSE); } -void iupdrvSetRedraw(Ihandle *ih, int value) -{ - (void)ih; - (void)value; -} - void iupdrvScreenToClient(Ihandle* ih, int *x, int *y) { gint win_x = 0, win_y = 0; diff --git a/iup/src/gtk/iupgtk_text.c b/iup/src/gtk/iupgtk_text.c index 9499c20..c5961de 100755 --- a/iup/src/gtk/iupgtk_text.c +++ b/iup/src/gtk/iupgtk_text.c @@ -1144,8 +1144,21 @@ static char* gtkTextGetOverwriteAttrib(Ihandle* ih) return "NO"; } -void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag) +void* iupdrvTextAddFormatTagStartBulk(Ihandle* ih) { + (void)ih; +} + +void iupdrvTextAddFormatTagStopBulk(Ihandle* ih, void* state) +{ + (void)ih; + (void)state; +} + +void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag, int bulk) +{ + (void)bulk; + GtkTextBuffer *buffer; GtkTextIter start_iter, end_iter; GtkTextTag* tag; diff --git a/iup/src/iup_drv.h b/iup/src/iup_drv.h index ec8a253..1071347 100755 --- a/iup/src/iup_drv.h +++ b/iup/src/iup_drv.h @@ -66,10 +66,6 @@ void iupdrvPostRedraw(Ihandle *ih); * \ingroup drv */ void iupdrvRedrawNow(Ihandle *ih); -/** Sets if a control is drawable or not. - * \ingroup drv */ -void iupdrvSetRedraw(Ihandle *ih, int value); - /** Reparent the native control. * \ingroup drv */ void iupdrvReparent(Ihandle* ih); diff --git a/iup/src/iup_layout.c b/iup/src/iup_layout.c index fc9dcf6..9387135 100755 --- a/iup/src/iup_layout.c +++ b/iup/src/iup_layout.c @@ -91,16 +91,6 @@ void IupRedraw(Ihandle* ih, int children) iLayoutDisplayRedrawChildren(ih); } -void IupSetRedraw(Ihandle* ih, int value) -{ - iupASSERT(iupObjectCheck(ih)); - if (!iupObjectCheck(ih)) - return; - - if (ih->handle && ih->iclass->nativetype != IUP_TYPEVOID) - iupdrvSetRedraw(ih, value); -} - void iupLayoutUpdate(Ihandle* ih) { Ihandle* child; diff --git a/iup/src/iup_text.c b/iup/src/iup_text.c index d2e2e36..cd8f400 100755 --- a/iup/src/iup_text.c +++ b/iup/src/iup_text.c @@ -83,7 +83,17 @@ void iupTextUpdateFormatTags(Ihandle* ih) for (i = 0; i < count; i++) { - iupdrvTextAddFormatTag(ih, tag_array[i]); + char* bulk = iupAttribGet(tag_array[i], "BULK"); + if (format && iupStrBoolean(format)) + { + Ihandle* child = NULL; + void* state = iupdrvTextAddFormatTagStartBulk(ih); + for (child = IupGetNextChild(tag_array[i], NULL); child; child = IupGetNextChild(tag_array[i], child)) + iupdrvTextAddFormatTag(ih, child, 1); + iupdrvTextAddFormatTagStopBulk(ih, state); + } + else + iupdrvTextAddFormatTag(ih, tag_array[i], 0); IupDestroy(tag_array[i]); } iupArrayDestroy(ih->data->formattags); @@ -101,7 +111,18 @@ int iupTextSetAddFormatTagHandleAttrib(Ihandle* ih, const char* value) /* must update VALUE before updating the format */ iTextUpdateValueAttrib(ih); - iupdrvTextAddFormatTag(ih, formattag); + char* bulk = iupAttribGet(formattag, "BULK"); + if (format && iupStrBoolean(format)) + { + Ihandle* child = NULL; + void* state = iupdrvTextAddFormatTagStartBulk(ih); + for (child = IupGetNextChild(formattag, NULL); child; child = IupGetNextChild(formattag, child)) + iupdrvTextAddFormatTag(ih, child, 1); + iupdrvTextAddFormatTagStopBulk(ih, state); + } + else + iupdrvTextAddFormatTag(ih, formattag, 0); + IupDestroy(formattag); } else diff --git a/iup/src/iup_text.h b/iup/src/iup_text.h index e018961..56a8725 100755 --- a/iup/src/iup_text.h +++ b/iup/src/iup_text.h @@ -15,7 +15,9 @@ extern "C" { void iupdrvTextInitClass(Iclass* ic); void iupdrvTextAddBorders(int *w, int *h); void iupdrvTextAddSpin(int *w, int h); -void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag); +void* iupdrvTextAddFormatTagStartBulk(Ihandle* ih); +void iupdrvTextAddFormatTagStopBulk(Ihandle* ih, void* state); +void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag, int bulk); void iupdrvTextConvertLinColToPos(Ihandle* ih, int lin, int col, int *pos); void iupdrvTextConvertPosToLinCol(Ihandle* ih, int pos, int *lin, int *col); diff --git a/iup/src/mot/iupmot_common.c b/iup/src/mot/iupmot_common.c index 554504f..286e075 100755 --- a/iup/src/mot/iupmot_common.c +++ b/iup/src/mot/iupmot_common.c @@ -235,12 +235,6 @@ void iupdrvRedrawNow(Ihandle *ih) XmUpdateDisplay(ih->handle); } -void iupdrvSetRedraw(Ihandle *ih, int value) -{ - (void)ih; - (void)value; -} - void iupdrvScreenToClient(Ihandle* ih, int *x, int *y) { Window child; diff --git a/iup/src/mot/iupmot_text.c b/iup/src/mot/iupmot_text.c index d9d2c74..5af1328 100755 --- a/iup/src/mot/iupmot_text.c +++ b/iup/src/mot/iupmot_text.c @@ -43,10 +43,22 @@ #define XmNwrap "Nwrap" #endif -void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag) +void* iupdrvTextAddFormatTagStartBulk(Ihandle* ih) +{ + (void)ih; +} + +void iupdrvTextAddFormatTagStopBulk(Ihandle* ih, void* state) +{ + (void)ih; + (void)state; +} + +void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag, int bulk) { (void)ih; (void)formattag; + (void)bulk; } void iupdrvTextAddSpin(int *w, int h) diff --git a/iup/src/win/iupwin_common.c b/iup/src/win/iupwin_common.c index 7a20d8c..0f53e68 100755 --- a/iup/src/win/iupwin_common.c +++ b/iup/src/win/iupwin_common.c @@ -100,11 +100,6 @@ void iupdrvRedrawNow(Ihandle *ih) RedrawWindow(ih->handle,NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_INTERNALPAINT|RDW_UPDATENOW); } -void iupdrvSetRedraw(Ihandle *ih, int value) -{ - SendMessage(ih->handle, WM_SETREDRAW, value ? TRUE : FALSE, 0); -} - void iupdrvPostRedraw(Ihandle *ih) { /* Post a REDRAW */ diff --git a/iup/src/win/iupwin_text.c b/iup/src/win/iupwin_text.c index ee6fbb7..9059796 100755 --- a/iup/src/win/iupwin_text.c +++ b/iup/src/win/iupwin_text.c @@ -1171,7 +1171,35 @@ static int winTextSetStandardFontAttrib(Ihandle* ih, const char* value) return iupdrvSetStandardFontAttrib(ih, value); } -void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag) +typedef struct +{ + int eventMask; + DWORD line; + CHARRANGE oldRange; +} formatTagBulkState; + +void* iupdrvTextAddFormatTagStartBulk(Ihandle* ih) +{ + formatTagBulkState* state = (formatTagBulkState*) malloc(sizeof(formatTagBulkState)); + state->line = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0); + SendMessage(ih->handle, EM_EXGETSEL, 0, (LPARAM)&state->oldRange); + state->eventMask = SendMessage(ih->handle, EM_SETEVENTMASK, 0, 0); + SendMessage(ih->handle, WM_SETREDRAW, FALSE, 0); + return state; +} + +void iupdrvTextAddFormatTagStopBulk(Ihandle* ih, void* stateOpaque) +{ + formatTagBulkState* state = (formatTagBulkState*) stateOpaque; + SendMessage(ih->handle, EM_EXSETSEL, 0, (LPARAM)&state->oldRange); + DWORD line = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0); + SendMessage(ih->handle, EM_LINESCROLL, 0, state->line - line); + SendMessage(ih->handle, WM_SETREDRAW, TRUE, 0); + SendMessage(ih->handle, EM_SETEVENTMASK, 0, state->eventMask); + free(state); +} + +void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag, int bulk) { int convert2twips, pixel2twips; char *selection, *units; @@ -1197,9 +1225,6 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag) convert2twips = val; } - /* saves current selection / scroll position before doing anything */ - line0 = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0); - SendMessage(ih->handle, EM_EXGETSEL, 0, (LPARAM)&oldRange); selection = iupAttribGet(formattag, "SELECTION"); if (selection) { @@ -1216,7 +1241,12 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag) } } - oldEventMask = SendMessage(ih->handle, EM_SETEVENTMASK, 0, 0); + if (!bulk) { + line0 = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0); + SendMessage(ih->handle, EM_EXGETSEL, 0, (LPARAM)&oldRange); + oldEventMask = SendMessage(ih->handle, EM_SETEVENTMASK, 0, 0); + SendMessage(ih->handle, WM_SETREDRAW, FALSE, 0); + } if (iupAttribGet(formattag, "FONTSCALE") && !iupAttribGet(formattag, "FONTSIZE")) iupAttribSetStr(formattag, "FONTSIZE", iupGetFontSizeAttrib(ih)); @@ -1228,11 +1258,13 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag) if (charformat.dwMask != 0) SendMessage(ih->handle, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&charformat); - /* restores selection / scroll position */ - SendMessage(ih->handle, EM_EXSETSEL, 0, (LPARAM)&oldRange); - line1 = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0); - SendMessage(ih->handle, EM_LINESCROLL, 0, line0 - line1); - SendMessage(ih->handle, EM_SETEVENTMASK, 0, oldEventMask); + if (!bulk) { + SendMessage(ih->handle, EM_EXSETSEL, 0, (LPARAM)&oldRange); + line1 = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0); + SendMessage(ih->handle, EM_LINESCROLL, 0, line0 - line1); + SendMessage(ih->handle, WM_SETREDRAW, TRUE, 0); + SendMessage(ih->handle, EM_SETEVENTMASK, 0, oldEventMask); + } } static int winTextSetRemoveFormattingAttrib(Ihandle* ih, const char* value) -- cgit v1.2.3