From c844ab87cd86cc29669d3c737dd7d101651c2006 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 1 Dec 2014 15:28:45 +0000 Subject: [PATCH] CtrlLib: Optimized ToolBar refreshes git-svn-id: svn://ultimatepp.org/upp/trunk@7938 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/Bar.cpp | 7 +++++-- uppsrc/CtrlLib/Bar.h | 5 +++-- uppsrc/CtrlLib/CtrlLib.upp | 2 +- uppsrc/CtrlLib/Static.cpp | 9 +++++++++ uppsrc/CtrlLib/StaticCtrl.h | 2 +- uppsrc/CtrlLib/ToolBar.cpp | 2 +- uppsrc/CtrlLib/ToolButton.cpp | 35 ++++++++++++++++++++++++++++++----- uppsrc/ide/idewin.cpp | 2 +- 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/uppsrc/CtrlLib/Bar.cpp b/uppsrc/CtrlLib/Bar.cpp index 2c303a257..254c942a2 100644 --- a/uppsrc/CtrlLib/Bar.cpp +++ b/uppsrc/CtrlLib/Bar.cpp @@ -289,7 +289,7 @@ Bar::Item& Bar::Add(bool enable, KeyInfo& (*key)(), const UPP::Image& image, Ca Bar::Item& Bar::Add(const char *text, const UPP::Image& image, Callback callback) { - return Add(true, text, image, callback); + return AddItem(callback).Text(text).Image(image); } Bar::Item& Bar::Add(const String& text, const UPP::Image& image, Callback callback) @@ -299,7 +299,10 @@ Bar::Item& Bar::Add(const String& text, const UPP::Image& image, Callback callba Bar::Item& Bar::Add(KeyInfo& (*key)(), const UPP::Image& image, Callback callback) { - return Add(true, key, image, callback); + const char *text = (*key)().name; + if(*text == '\3') + text = t_GetLngString(text + 1); + return Add(text, image, callback).Key(key); } Bar::Item& Bar::Add(bool enable, const char *text, Callback callback) diff --git a/uppsrc/CtrlLib/Bar.h b/uppsrc/CtrlLib/Bar.h index 610fcdf1e..523d50ad5 100644 --- a/uppsrc/CtrlLib/Bar.h +++ b/uppsrc/CtrlLib/Bar.h @@ -426,6 +426,7 @@ private: public: enum Kind { NOLABEL, RIGHTLABEL, BOTTOMLABEL }; + void ResetKeepStyle(); void Reset(); static const Style& StyleDefault(); @@ -434,10 +435,10 @@ public: bool IsChecked() { return checked; } UPP::Image GetImage() const; - ToolButton& SetStyle(const Style& s) { style = &s; Refresh(); return *this; } + ToolButton& SetStyle(const Style& s); ToolButton& MinSize(Size sz) { minsize = sz; return *this; } ToolButton& MaxIconSize(Size sz) { maxiconsize = sz; return *this; } - ToolButton& Kind(int _kind) { kind = _kind; Refresh(); return *this; } + ToolButton& Kind(int _kind); ToolButton& Label(const char *text, int kind); ToolButton& Label(const char *text); ToolButton& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; } diff --git a/uppsrc/CtrlLib/CtrlLib.upp b/uppsrc/CtrlLib/CtrlLib.upp index 267ba5bd2..d17134919 100644 --- a/uppsrc/CtrlLib/CtrlLib.upp +++ b/uppsrc/CtrlLib/CtrlLib.upp @@ -35,8 +35,8 @@ file DropList.cpp, DropChoice.cpp, StaticCtrl.h, - Static.cpp, Splitter.h, + Static.cpp, Splitter.cpp, FrameSplitter.cpp, SliderCtrl.h, diff --git a/uppsrc/CtrlLib/Static.cpp b/uppsrc/CtrlLib/Static.cpp index c286e1aa6..818b19aba 100644 --- a/uppsrc/CtrlLib/Static.cpp +++ b/uppsrc/CtrlLib/Static.cpp @@ -331,6 +331,15 @@ SeparatorCtrl& SeparatorCtrl::SetSize(int w) return *this; } +SeparatorCtrl& SeparatorCtrl::SetStyle(const Style& s) +{ + if(&s != style) { + style = &s; + Refresh(); + } + return *this; +} + SeparatorCtrl::SeparatorCtrl() { NoWantFocus(); diff --git a/uppsrc/CtrlLib/StaticCtrl.h b/uppsrc/CtrlLib/StaticCtrl.h index 0f871183b..9a90fd43b 100644 --- a/uppsrc/CtrlLib/StaticCtrl.h +++ b/uppsrc/CtrlLib/StaticCtrl.h @@ -162,7 +162,7 @@ public: SeparatorCtrl& Margin(int l, int r); SeparatorCtrl& Margin(int w) { return Margin(w, w); } SeparatorCtrl& SetSize(int w); - SeparatorCtrl& SetStyle(const Style& s) { style = &s; Refresh(); return *this; } + SeparatorCtrl& SetStyle(const Style& s); SeparatorCtrl(); }; diff --git a/uppsrc/CtrlLib/ToolBar.cpp b/uppsrc/CtrlLib/ToolBar.cpp index 5a815f007..9f7537ca2 100644 --- a/uppsrc/CtrlLib/ToolBar.cpp +++ b/uppsrc/CtrlLib/ToolBar.cpp @@ -55,7 +55,7 @@ void ToolBar::Paint(Draw& w) Bar::Item& ToolBar::AddItem(Callback cb) { ToolButton& m = item.DoIndex(ii++); - m.Reset(); + m.ResetKeepStyle(); m.WhenAction = cb; m.MinSize(IsNull(buttonminsize) ? style->buttonminsize : buttonminsize); m.MaxIconSize(IsNull(maxiconsize) ? style->maxiconsize : maxiconsize); diff --git a/uppsrc/CtrlLib/ToolButton.cpp b/uppsrc/CtrlLib/ToolButton.cpp index a17fa5af0..55504490b 100644 --- a/uppsrc/CtrlLib/ToolButton.cpp +++ b/uppsrc/CtrlLib/ToolButton.cpp @@ -52,7 +52,7 @@ ToolButton::ToolButton() ToolButton::~ToolButton() {} -void ToolButton::Reset() +void ToolButton::ResetKeepStyle() { repeat = false; accel = 0; @@ -60,13 +60,18 @@ void ToolButton::Reset() NoWantFocus(); minsize = Size(0, 0); maxiconsize = Size(INT_MAX, INT_MAX); - style = &StyleDefault(); Tip(""); Help(""); Topic(""); Description(""); } +void ToolButton::Reset() +{ + ResetKeepStyle(); + style = &StyleDefault(); +} + void ToolButton::UpdateTip() { LTIMING("UpdateTip"); @@ -83,9 +88,22 @@ void ToolButton::UpdateTip() Bar::Item& ToolButton::Text(const char *txt) { - ExtractAccessKey(txt, text); - UpdateTip(); - Refresh(); + String newtext; + ExtractAccessKey(txt, newtext); + if(newtext != text) { + text = newtext; + UpdateTip(); + Refresh(); + } + return *this; +} + +ToolButton& ToolButton::SetStyle(const Style& s) +{ + if(style != &s) { + style = &s; + Refresh(); + } return *this; } @@ -134,6 +152,13 @@ ToolButton& ToolButton::Label(const char *text) return *this; } +ToolButton& ToolButton::Kind(int _kind) +{ + if(kind != _kind) + Refresh(); + return *this; +} + Image ToolButton::GetImage() const { UPP::Image m = img; diff --git a/uppsrc/ide/idewin.cpp b/uppsrc/ide/idewin.cpp index bc7ac80f1..a1c909f24 100644 --- a/uppsrc/ide/idewin.cpp +++ b/uppsrc/ide/idewin.cpp @@ -707,7 +707,7 @@ void AppMain___() #endif #ifdef _DEBUG -// Ctrl::ShowRepaint(50); + Ctrl::ShowRepaint(50); #endif #ifdef PLATFORM_WIN32