From 2ebd16b1a1439fa36fa93ff45a038ed587af2562 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Mon, 18 Apr 2022 15:03:38 +0200 Subject: [PATCH] optimizing Ctrl::Top, LabelBase --- uppsrc/Core/Core.upp | 2 +- uppsrc/Core/Ptr.cpp | 21 ------------- uppsrc/Core/Ptr.h | 1 - uppsrc/CtrlCore/CtrlChild.cpp | 5 ++- uppsrc/CtrlCore/CtrlCore.h | 4 +-- uppsrc/CtrlCore/Win32Wnd.cpp | 3 +- uppsrc/CtrlLib/LabelBase.cpp | 30 +++++++++--------- uppsrc/CtrlLib/LabelBase.h | 59 ++++++++++++++++++++++------------- 8 files changed, 60 insertions(+), 65 deletions(-) diff --git a/uppsrc/Core/Core.upp b/uppsrc/Core/Core.upp index e02155dbc..b73ebc784 100644 --- a/uppsrc/Core/Core.upp +++ b/uppsrc/Core/Core.upp @@ -95,9 +95,9 @@ file Algo.h, CoAlgo.h, Sorted.h, - Sort.h, CoSort.h, Obsolete.h, + Sort.h, Vcont.h, BiCont.h, Other.h, diff --git a/uppsrc/Core/Ptr.cpp b/uppsrc/Core/Ptr.cpp index 2d6900d43..b812bec4c 100644 --- a/uppsrc/Core/Ptr.cpp +++ b/uppsrc/Core/Ptr.cpp @@ -2,27 +2,6 @@ namespace Upp { -/* Faster, but consuming more memory.... -PteBase::Prec *PteBase::PtrAdd() -{ - AtomicInc(prec->n); - return prec; -} - -void PteBase::PtrRelease(Prec *prec) -{ - if(prec && AtomicDec(prec->n) == 0) - delete prec; -} - -PteBase::PteBase() -{ - prec = new Prec; - prec->n = 1; - prec->ptr = this; -} -*/ - static StaticMutex sPteLock; PteBase::Prec *PteBase::PtrAdd() diff --git a/uppsrc/Core/Ptr.h b/uppsrc/Core/Ptr.h index 34ce16578..1c348e01e 100644 --- a/uppsrc/Core/Ptr.h +++ b/uppsrc/Core/Ptr.h @@ -11,7 +11,6 @@ protected: Prec *PtrAdd(); static void PtrRelease(Prec *prec); - static Prec *PtrAdd(const Uuid& uuid); PteBase(); ~PteBase(); diff --git a/uppsrc/CtrlCore/CtrlChild.cpp b/uppsrc/CtrlCore/CtrlChild.cpp index 2133d6bd7..a86af14ab 100644 --- a/uppsrc/CtrlCore/CtrlChild.cpp +++ b/uppsrc/CtrlCore/CtrlChild.cpp @@ -6,8 +6,11 @@ namespace Upp { void Ctrl::DeleteTop() { - if(top && utop) + if(top && utop) { delete utop; + utop = nullptr; + top = false; + } } void Ctrl::SetParent(Ctrl *parent) diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index 9ee1b864b..206f0217a 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -505,6 +505,8 @@ private: Frame frame; + LogPos pos;//8 + Rect16 rect; //8 union { Ctrl *uparent; @@ -514,8 +516,6 @@ private: Ctrl *prev_sibling = nullptr; Ctrl *next_sibling = nullptr; Ctrl *children = nullptr; - LogPos pos;//8 - Rect16 rect; //8 const char *info_ptr = nullptr; int16 caretx, carety, caretcx, caretcy;//8 diff --git a/uppsrc/CtrlCore/Win32Wnd.cpp b/uppsrc/CtrlCore/Win32Wnd.cpp index da1fb6bce..2c65b3d15 100644 --- a/uppsrc/CtrlCore/Win32Wnd.cpp +++ b/uppsrc/CtrlCore/Win32Wnd.cpp @@ -503,11 +503,10 @@ void Ctrl::WndFree() { GuiLock __; Top *top = GetTop(); - if(!top) return; RevokeDragDrop(GetHWND()); + if(!top) return; ReleaseUDropTarget(top->dndtgt); isopen = false; - if(!top) return; HWND owner = GetWindow(top->hwnd, GW_OWNER);// CXL 31.10.2003 z DoRemove bool focus = ::GetFocus() == top->hwnd; LLOG("Ctrl::WndDestroy owner " << (void *)owner diff --git a/uppsrc/CtrlLib/LabelBase.cpp b/uppsrc/CtrlLib/LabelBase.cpp index cceae5cdb..80c8f839a 100644 --- a/uppsrc/CtrlLib/LabelBase.cpp +++ b/uppsrc/CtrlLib/LabelBase.cpp @@ -115,19 +115,6 @@ int ChooseAccessKey(const char *text, dword used) return 0; } -DrawLabel::DrawLabel() -{ - push = focus = disabled = false; - lspc = rspc = 0; - limg_never_hide = false; - rimg_never_hide = false; - ink = disabledink = Null; - align = valign = ALIGN_CENTER; - accesskey = 0; - font = StdFont(); - nowrap = false; -} - Size DrawLabel::GetSize(int txtcx) const { return GetSize(txtcx, limg.GetSize(), lspc, rimg.GetSize(), rspc); @@ -288,7 +275,17 @@ Size DrawLabel::Paint(Draw& w, int x, int y, int cx, int cy, bool vak) const void LabelBase::LabelUpdate() {} +DrawLabel LabelBase::Make() const +{ + DrawLabel lx; + (DrawLabelBasic&)lx = lbl; + if(ext) + (DrawLabelExt&)lx = *ext; + return lx; +} + LabelBase& LabelBase::SetLeftImage(const Image& img, int spc, bool never_hide) { + DrawLabelExt& lbl = Ext(); lbl.limg = img; lbl.lspc = spc; lbl.limg_never_hide = never_hide; @@ -297,6 +294,7 @@ LabelBase& LabelBase::SetLeftImage(const Image& img, int spc, bool never_hide) { } LabelBase& LabelBase::SetRightImage(const Image& img, int spc, bool never_hide) { + DrawLabelExt& lbl = Ext(); lbl.rimg = img; lbl.rspc = spc; lbl.rimg_never_hide = never_hide; @@ -305,7 +303,7 @@ LabelBase& LabelBase::SetRightImage(const Image& img, int spc, bool never_hide) } LabelBase& LabelBase::SetPaintRect(const PaintRect& paintrect) { - lbl.paintrect = paintrect; + Ext().paintrect = paintrect; LabelUpdate(); return *this; } @@ -361,7 +359,7 @@ LabelBase& LabelBase::SetVAlign(int valign) { Size LabelBase::PaintLabel(Ctrl *ctrl, Draw& w, const Rect& r, bool disabled, bool push, bool focus, bool vak) { - DrawLabel lbl1 = lbl; + DrawLabel lbl1 = Make(); lbl1.disabled = disabled; lbl1.push = push; lbl1.focus = focus; @@ -386,7 +384,7 @@ Size LabelBase::PaintLabel(Draw& w, int x, int y, int cx, int cy, bool disabled, Size LabelBase::GetLabelSize() const { - return lbl.GetSize(); + return Make().GetSize(); } void LinkToolTipIn__(); diff --git a/uppsrc/CtrlLib/LabelBase.h b/uppsrc/CtrlLib/LabelBase.h index 2c14d1cdd..bb14a7481 100644 --- a/uppsrc/CtrlLib/LabelBase.h +++ b/uppsrc/CtrlLib/LabelBase.h @@ -28,29 +28,41 @@ void DrawVertDrop(Draw& w, int x, int y, int cy); Point GetDragScroll(Ctrl *ctrl, Point p, Size max); Point GetDragScroll(Ctrl *ctrl, Point p, int max = 16); -struct DrawLabel { - PaintRect paintrect; +struct DrawLabelBasic { String text; - Image limg; - Image rimg; Font font; - Color lcolor; - Color ink, disabledink; - Color rcolor; - - int rspc; - int lspc; + Color ink; + Color disabledink; int accesskey; - int align:4, valign:4; - + int align:4; + int valign:4; + bool nowrap:1; - bool push:1; - bool focus:1; - bool disabled:1; - bool limg_never_hide:1; - bool rimg_never_hide:1; + + DrawLabelBasic() { align = valign = ALIGN_CENTER; nowrap = false; accesskey = 0; font = StdFont(); } +}; + +struct DrawLabelExt { + PaintRect paintrect; + + Image limg; + Image rimg; + + Color lcolor; + int lspc = 0; + Color rcolor; + int rspc = 0; + + bool limg_never_hide = false; + bool rimg_never_hide = false; +}; + +struct DrawLabel : DrawLabelBasic, DrawLabelExt { + bool push = false; + bool focus = false; + bool disabled = false; Size GetSize(int txtcx, Size sz1, int lspc, Size sz2, int rspc) const; Size GetSize(int txtcx = INT_MAX) const; @@ -58,8 +70,6 @@ struct DrawLabel { Size Paint(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey = true) const; Size Paint(Draw& w, const Rect& r, bool visibleaccesskey = true) const; Size Paint(Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey = true) const; - - DrawLabel(); }; Image DisabledImage(const Image& img, bool disabled = true); @@ -69,7 +79,11 @@ class LabelBase { protected: virtual void LabelUpdate(); - DrawLabel lbl; + DrawLabelBasic lbl; + One ext; + + DrawLabelExt& Ext() { if(!ext) ext.Create() ; return *ext; } + DrawLabel Make() const; public: LabelBase& SetLeftImage(const Image& bmp1, int spc = 0, bool never_hide = false); @@ -93,7 +107,7 @@ public: int GetAlign() const { return lbl.align; } int GetVAlign() const { return lbl.valign; } - PaintRect GetPaintRect() const { return lbl.paintrect; } + PaintRect GetPaintRect() const { return ext ? ext->paintrect : PaintRect(); } String GetText() const { return lbl.text; } Font GetFont() const { return lbl.font; } Color GetInk() const { return lbl.ink; } @@ -107,6 +121,9 @@ public: Size PaintLabel(Draw& w, int x, int y, int cx, int cy, bool disabled = false, bool push = false, bool focus = false, bool vak = true); Size GetLabelSize() const; + + LabelBase(const LabelBase& src) { lbl = src.lbl; if(src.ext) ext = clone(src.ext); } + LabelBase() {} virtual ~LabelBase(); };