From 3d301cdaab4995dc013c4f8f82a38f1a28edc28d Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 9 Apr 2020 11:59:59 +0000 Subject: [PATCH] CtrlLib: Some Progress now work in non-main thread without restrictions git-svn-id: svn://ultimatepp.org/upp/trunk@14285 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/Progress.cpp | 23 +++++++++++++++++++++-- uppsrc/CtrlLib/Progress.h | 4 ++-- uppsrc/CtrlLib/src.tpp/Progress_en-us.tpp | 20 ++++++++++++++------ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/uppsrc/CtrlLib/Progress.cpp b/uppsrc/CtrlLib/Progress.cpp index f14953c1a..7cb9d463e 100644 --- a/uppsrc/CtrlLib/Progress.cpp +++ b/uppsrc/CtrlLib/Progress.cpp @@ -196,6 +196,8 @@ void Progress::Create() { void Progress::Process() { + if(!IsMainThread()) + return; if(!IsOpen()) { dword t = msecs(); if((int)(t - show_time) >= show_delay) { @@ -209,6 +211,13 @@ void Progress::Process() } } +void Progress::SetText(const String& s) +{ + GuiLock __; + text = s; + Setxt(); +} + void Progress::Setxt() { info = Format(text, pos); @@ -216,8 +225,11 @@ void Progress::Setxt() } void Progress::Set(int apos, int atotal) { + GuiLock __; pos = apos; total = atotal; + if(!IsMainThread()) + return; dword t = msecs(); if(abs((int)(t - set_time)) < granularity) return; @@ -229,6 +241,7 @@ void Progress::Set(int apos, int atotal) { pi.Set(apos, atotal); Setxt(); Sync(); + Process(); } @@ -242,6 +255,7 @@ void Progress::SetPos(int apos) { void Progress::Step(int n) { + GuiLock __; Set(pos + n, total); } @@ -258,13 +272,16 @@ void Progress::Cancel() { bool Progress::Canceled() { - stop.Show(); - Process(); + if(IsMainThread()) { + stop.Show(); + Process(); + } return cancel; } bool Progress::SetCanceled(int pos, int total) { + GuiLock __; stop.Show(); Set(pos, total); return cancel; @@ -272,6 +289,7 @@ bool Progress::SetCanceled(int pos, int total) bool Progress::SetPosCanceled(int pos) { + GuiLock __; stop.Show(); SetPos(pos); return cancel; @@ -279,6 +297,7 @@ bool Progress::SetPosCanceled(int pos) bool Progress::StepCanceled(int n) { + GuiLock __; stop.Show(); Step(n); return cancel; diff --git a/uppsrc/CtrlLib/Progress.h b/uppsrc/CtrlLib/Progress.h index b1191001c..b4abfe02d 100644 --- a/uppsrc/CtrlLib/Progress.h +++ b/uppsrc/CtrlLib/Progress.h @@ -75,8 +75,8 @@ public: void Set(int pos, int total); void SetPos(int pos); - void SetText(const char *s) { text = s; Setxt(); Sync(); } - void SetText(const String& s) { text = s; Setxt(); Sync(); } + void SetText(const char *s) { SetText((String)s); } + void SetText(const String& s); void SetTotal(int total); void Step(int steps = 1); int GetPos() const { return pos; } diff --git a/uppsrc/CtrlLib/src.tpp/Progress_en-us.tpp b/uppsrc/CtrlLib/src.tpp/Progress_en-us.tpp index c0c79f2d5..efab455a6 100644 --- a/uppsrc/CtrlLib/src.tpp/Progress_en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/Progress_en-us.tpp @@ -1,5 +1,4 @@ topic "Progress"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,0#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "Progress"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_}%EN-US [ {{10000@3 [s0; [*@(229)4 Progress]]}}&] [s3; &] @@ -58,18 +58,21 @@ active window is used as owner.&] [s4;%- &] [s5;:Progress`:`:Set`(int`,int`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 pos], [@(0.0.255) int]_[*@3 total])&] -[s2; Sets the current progress position and total.&] +[s2; Sets the current progress position and total. This method can +be called from non`-main thread without restriction.&] [s3; &] [s4;%- &] [s5;:Progress`:`:SetPos`(int`):%- [@(0.0.255) void]_[* SetPos]([@(0.0.255) int]_[*@3 pos])&] -[s2; Sets the current progress position.&] +[s2; Sets the current progress position. This method can be called +from non`-main thread without restriction.&] [s3; &] [s4;%- &] [s5;:Progress`:`:SetText`(const char`*`):%- [@(0.0.255) void]_[* SetText]([@(0.0.255) const ]_[@(0.0.255) char]_`*[*@3 s])&] [s5;:Progress`:`:SetText`(const String`&`):%- [@(0.0.255) void]_[* SetText]([@(0.0.255) con st]_[_^String^ String][@(0.0.255) `&]_[*@3 s])&] -[s2; Sets the text to be displayed in dialog.&] +[s2; Sets the text to be displayed in dialog. This method can be +called from non`-main thread without restriction.&] [s3; &] [s4;%- &] [s5;:Progress`:`:SetTotal`(int`):%- [@(0.0.255) void]_[* SetTotal]([@(0.0.255) int]_[*@3 tota @@ -80,7 +83,8 @@ l])&] [s5;:Progress`:`:Step`(int`):%- [@(0.0.255) void]_[* Step]([@(0.0.255) int]_[*@3 steps]_`=_[@3 1 ])&] [s2; Advances progress by [%-*@3 steps]. If total number of steps is -zero, `"running bar`" is displayed.&] +zero, `"running bar`" is displayed. This method can be called +from non`-main thread without restriction.&] [s3; &] [s4;%- &] [s5;:Progress`:`:GetPos`(`)const:%- [@(0.0.255) int]_[* GetPos]()_[@(0.0.255) const]&] @@ -97,7 +101,11 @@ zero, `"running bar`" is displayed.&] [s4;%- &] [s5;:Progress`:`:Canceled`(`):%- [@(0.0.255) bool]_[* Canceled]()&] [s2; Shows a Cancel button if not shown yet. If this button is pressed, -sets dialog to canceled mode. Returns true if dialog was canceled.&] +sets dialog to canceled mode. Returns true if dialog was canceled. +This method can be called from non`-main thread without restriction. +Calling this method from the main thread also invokes processing +GUI events, including paint event, so calling this as often as +once per 1ms is desirable.&] [s3; &] [s4;%- &] [s5;:Progress`:`:SetCanceled`(int`,int`):%- [@(0.0.255) bool]_[* SetCanceled]([@(0.0.255) i