From 84645fa4423afc580b873cc852f7cfd4b98c74d1 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 23 Nov 2009 10:28:48 +0000 Subject: [PATCH] Cosmetics git-svn-id: svn://ultimatepp.org/upp/trunk@1718 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/DropTree.cpp | 432 ++++++++++++++++++------------------ 1 file changed, 216 insertions(+), 216 deletions(-) diff --git a/uppsrc/CtrlLib/DropTree.cpp b/uppsrc/CtrlLib/DropTree.cpp index 9b3f437ba..e58c85e37 100644 --- a/uppsrc/CtrlLib/DropTree.cpp +++ b/uppsrc/CtrlLib/DropTree.cpp @@ -1,216 +1,216 @@ -#include "CtrlLib.h" - -namespace Upp { - -CH_VALUE(TreeDropEdge, ChBorder(BlackBorder())); - -CtrlFrame& TreeDropFrame() -{ - static LookFrame m(TreeDropEdge); - return m; -} - -PopUpTree::PopUpTree() { - SetFrame(TreeDropFrame()); - Accel(); - MouseMoveCursor(); - NoPopUpEx(); - SetDropLines(16); - open = autosize = false; - showpos = Null; - WhenOpen = WhenClose = THISBACK(OpenClose); -} - -PopUpTree::~PopUpTree() {} - -void PopUpTree::CancelMode() { - if(open) { - DoClose(); - WhenCancel(); - } - TreeCtrl::CancelMode(); -} - -void PopUpTree::DoClose() { - open = false; - Ctrl::Close(); -} - -void PopUpTree::Deactivate() { - if(open) { - DoClose(); - IgnoreMouseClick(); - WhenCancel(); - } -} - -void PopUpTree::Select() { - if(IsCursor() && !GetData().IsVoid()) { - DoClose(); - WhenSelect(); - } -} - -bool PopUpTree::Key(dword key, int n) { - switch(key) { - case K_ENTER: - case K_ALT_DOWN: - DoClose(); - WhenSelect(); - return true; - case K_ESCAPE: - DoClose(); - WhenCancel(); - return true; - } - return TreeCtrl::Key(key, n); -} - -void PopUpTree::PopUp(Ctrl *owner, int x, int top, int bottom, int width) { - DoClose(); - Rect area = Ctrl::GetWorkArea(); - int mh = min(maxheight, area.bottom - bottom); - int h = AddFrameSize(width, maxheight).cy; - showpos.x = x; - showpos.y = bottom; - showwidth = width; - up = false; - if(showpos.y + h > area.bottom) { - up = true; - showpos.y = top; - } - open = false; - Ctrl popup; - int ht = AddFrameSize(width, min(mh, autosize ? GetTreeSize().cy : INT_MAX)).cy; - Rect rt = RectC(showpos.x, showpos.y - (up ? ht : 0), showwidth, ht); - if(GUI_PopUpEffect()) { - if(up) { - popup.SetRect(Rect(rt.left, rt.bottom - 1, rt.right, rt.bottom)); - popup.Add(TopPos(0, rt.Height()).LeftPos(0, rt.Width())); - } - else { - popup.SetRect(Rect(rt.left, rt.top, rt.right, rt.top + 1)); - popup.Add(BottomPos(0, rt.Height()).LeftPos(0, rt.Width())); - } - CenterCursor(); - popup.PopUp(owner, true, true, GUI_DropShadows()); - SetFocus(); - Ctrl::ProcessEvents(); - Animate(popup, rt, GUIEFFECT_SLIDE); - Ctrl::Remove(); - } - CenterCursor(); - SetRect(rt); - Ctrl::PopUp(owner, true, true, GUI_DropShadows()); - SetFocus(); - open = true; -} - -void PopUpTree::OpenClose(int) -{ - if(autosize) { - SyncTree(); - Rect area = Ctrl::GetWorkArea(); - int mh = min(maxheight, area.bottom - showpos.y); - int ht = AddFrameSize(showwidth, min(mh, GetTreeSize().cy)).cy; - SetRect(RectC(showpos.x, showpos.y - (up ? ht : 0), showwidth, ht)); - } -} - -void PopUpTree::PopUp(Ctrl *owner, int width) -{ - Rect r = owner->GetScreenRect(); - r.right = r.left + width; - PopUp(owner, r.left, r.top, r.bottom, width); - if(IsNull(showpos)) - showpos = r.TopLeft(); - OpenClose(0); -} - -void PopUpTree::PopUp(Ctrl *owner) -{ - Rect r = owner->GetScreenRect(); - PopUp(owner, r.left, r.top, r.bottom, r.Width()); -} - -void DropTree::Sync() { - Image icon; - if(tree.IsCursor()) - icon = tree.GetNode(tree.GetCursor()).image; - icond.Set(valuedisplay ? *valuedisplay : tree.GetDisplay(tree.GetCursor()), icon); - MultiButton::SetDisplay(icond); - Set(tree.GetValue()); -} - -bool DropTree::Key(dword k, int) { - if(IsReadOnly()) return false; - if(k == K_ALT_DOWN) { - Drop(); - return true; - } - return false; -} - -void DropTree::Drop() { - if(IsReadOnly()) return; - if(dropfocus) - SetFocus(); - WhenDrop(); - tree.PopUp(this, GetRect().GetWidth()); -} - -void DropTree::Select() { - if(dropfocus) - SetFocus(); - Sync(); - UpdateAction(); -} - -void DropTree::Cancel() { - if(dropfocus) - SetFocus(); - Sync(); -} - -void DropTree::Clear() { - tree.Clear(); - tree <<= Null; - Sync(); - Update(); -} - -void DropTree::SetData(const Value& data) -{ - if(tree.Get() != data) { - tree <<= data; - Update(); - Sync(); - } -} - -Value DropTree::GetData() const -{ - return notnull && IsNull(tree.Get()) ? NotNullError() : tree.Get(); -} - -DropTree& DropTree::ValueDisplay(const Display& d) -{ - valuedisplay = &d; - Sync(); - return *this; -} - -DropTree::DropTree() -{ - displayall = false; - valuedisplay = NULL; - dropfocus = false; - notnull = false; - AddButton().Main().WhenPush = THISBACK(Drop); - NoInitFocus(); - tree.WhenSelect = THISBACK(Select); - tree.WhenCancel = THISBACK(Cancel); - dropwidth = 0; -} - -}; \ No newline at end of file +#include "CtrlLib.h" + +namespace Upp { + +CH_VALUE(TreeDropEdge, ChBorder(BlackBorder())); + +CtrlFrame& TreeDropFrame() +{ + static LookFrame m(TreeDropEdge); + return m; +} + +PopUpTree::PopUpTree() { + SetFrame(TreeDropFrame()); + Accel(); + MouseMoveCursor(); + NoPopUpEx(); + SetDropLines(16); + open = autosize = false; + showpos = Null; + WhenOpen = WhenClose = THISBACK(OpenClose); +} + +PopUpTree::~PopUpTree() {} + +void PopUpTree::CancelMode() { + if(open) { + DoClose(); + WhenCancel(); + } + TreeCtrl::CancelMode(); +} + +void PopUpTree::DoClose() { + open = false; + Ctrl::Close(); +} + +void PopUpTree::Deactivate() { + if(open) { + DoClose(); + IgnoreMouseClick(); + WhenCancel(); + } +} + +void PopUpTree::Select() { + if(IsCursor() && !GetData().IsVoid()) { + DoClose(); + WhenSelect(); + } +} + +bool PopUpTree::Key(dword key, int n) { + switch(key) { + case K_ENTER: + case K_ALT_DOWN: + DoClose(); + WhenSelect(); + return true; + case K_ESCAPE: + DoClose(); + WhenCancel(); + return true; + } + return TreeCtrl::Key(key, n); +} + +void PopUpTree::PopUp(Ctrl *owner, int x, int top, int bottom, int width) { + DoClose(); + Rect area = Ctrl::GetWorkArea(); + int mh = min(maxheight, area.bottom - bottom); + int h = AddFrameSize(width, maxheight).cy; + showpos.x = x; + showpos.y = bottom; + showwidth = width; + up = false; + if(showpos.y + h > area.bottom) { + up = true; + showpos.y = top; + } + open = false; + Ctrl popup; + int ht = AddFrameSize(width, min(mh, autosize ? GetTreeSize().cy : INT_MAX)).cy; + Rect rt = RectC(showpos.x, showpos.y - (up ? ht : 0), showwidth, ht); + if(GUI_PopUpEffect()) { + if(up) { + popup.SetRect(Rect(rt.left, rt.bottom - 1, rt.right, rt.bottom)); + popup.Add(TopPos(0, rt.Height()).LeftPos(0, rt.Width())); + } + else { + popup.SetRect(Rect(rt.left, rt.top, rt.right, rt.top + 1)); + popup.Add(BottomPos(0, rt.Height()).LeftPos(0, rt.Width())); + } + CenterCursor(); + popup.PopUp(owner, true, true, GUI_DropShadows()); + SetFocus(); + Ctrl::ProcessEvents(); + Animate(popup, rt, GUIEFFECT_SLIDE); + Ctrl::Remove(); + } + CenterCursor(); + SetRect(rt); + Ctrl::PopUp(owner, true, true, GUI_DropShadows()); + SetFocus(); + open = true; +} + +void PopUpTree::OpenClose(int) +{ + if(autosize) { + SyncTree(); + Rect area = Ctrl::GetWorkArea(); + int mh = min(maxheight, area.bottom - showpos.y); + int ht = AddFrameSize(showwidth, min(mh, GetTreeSize().cy)).cy; + SetRect(RectC(showpos.x, showpos.y - (up ? ht : 0), showwidth, ht)); + } +} + +void PopUpTree::PopUp(Ctrl *owner, int width) +{ + Rect r = owner->GetScreenRect(); + r.right = r.left + width; + PopUp(owner, r.left, r.top, r.bottom, width); + if(IsNull(showpos)) + showpos = r.TopLeft(); + OpenClose(0); +} + +void PopUpTree::PopUp(Ctrl *owner) +{ + Rect r = owner->GetScreenRect(); + PopUp(owner, r.left, r.top, r.bottom, r.Width()); +} + +void DropTree::Sync() { + Image icon; + if(tree.IsCursor()) + icon = tree.GetNode(tree.GetCursor()).image; + icond.Set(valuedisplay ? *valuedisplay : tree.GetDisplay(tree.GetCursor()), icon); + MultiButton::SetDisplay(icond); + Set(tree.GetValue()); +} + +bool DropTree::Key(dword k, int) { + if(IsReadOnly()) return false; + if(k == K_ALT_DOWN) { + Drop(); + return true; + } + return false; +} + +void DropTree::Drop() { + if(IsReadOnly()) return; + if(dropfocus) + SetFocus(); + WhenDrop(); + tree.PopUp(this, GetRect().GetWidth()); +} + +void DropTree::Select() { + if(dropfocus) + SetFocus(); + Sync(); + UpdateAction(); +} + +void DropTree::Cancel() { + if(dropfocus) + SetFocus(); + Sync(); +} + +void DropTree::Clear() { + tree.Clear(); + tree <<= Null; + Sync(); + Update(); +} + +void DropTree::SetData(const Value& data) +{ + if(tree.Get() != data) { + tree <<= data; + Update(); + Sync(); + } +} + +Value DropTree::GetData() const +{ + return notnull && IsNull(tree.Get()) ? NotNullError() : tree.Get(); +} + +DropTree& DropTree::ValueDisplay(const Display& d) +{ + valuedisplay = &d; + Sync(); + return *this; +} + +DropTree::DropTree() +{ + displayall = false; + valuedisplay = NULL; + dropfocus = false; + notnull = false; + AddButton().Main().WhenPush = THISBACK(Drop); + NoInitFocus(); + tree.WhenSelect = THISBACK(Select); + tree.WhenCancel = THISBACK(Cancel); + dropwidth = 0; +} + +};