Docking: Store titles directly

git-svn-id: svn://ultimatepp.org/upp/trunk@2556 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
mrjt 2010-07-21 16:43:23 +00:00
parent b67450e59a
commit b339efe5a3
8 changed files with 105 additions and 59 deletions

View file

@ -235,11 +235,11 @@ void DockCont::ChildAdded(Ctrl *child)
return;
else if (DockableCtrl *dc = dynamic_cast<DockableCtrl *>(child)) {
Value v = ValueCast(dc);
tabbar.Insert(0, v, Null, dc->GetGroup(), true);
tabbar.InsertKey(0, v, dc->GetTitle(), Null, dc->GetGroup(), true);
}
else if (DockCont *dc = dynamic_cast<DockCont *>(child)) {
Value v = ValueCast(dc);
tabbar.Insert(0, v, Null, Null, true);
tabbar.InsertKey(0, v, dc->GetTitle(), Null, Null, true);
}
else
return;
@ -332,9 +332,8 @@ void DockCont::TabSelected()
if (IsTabbed()) {
DockCont *c = static_cast<DockCont *>(GetParent());
c->tabbar.SyncRepos();
c->ChildTitleChanged(*this);
c->TabSelected();
c->RefreshFrame();
}
else
handle.Refresh();
@ -516,7 +515,8 @@ void DockCont::State(DockWindow& dock, DockCont::DockState state)
void DockCont::SignalStateChange()
{
SignalStateChange(GetCount()-1, 0);
if (GetCount())
SignalStateChange(GetCount()-1, 0);
}
void DockCont::SignalStateChange(int from, int to)
@ -743,11 +743,25 @@ WString DockCont::GetTitle(bool force_count) const
return GetCurrent().GetTitle();
}
void DockCont::ChildTitleChanged()
void DockCont::ChildTitleChanged(DockableCtrl &dc)
{
tabbar.SyncRepos();
ChildTitleChanged(&dc, dc.GetTitle(), dc.GetIcon());
}
void DockCont::ChildTitleChanged(DockCont &dc)
{
ChildTitleChanged(&dc, dc.GetTitle(), Null);
}
void DockCont::ChildTitleChanged(Ctrl *child, WString title, Image icon)
{
for (int i = 0; i < tabbar.GetCount(); i++)
if (CtrlCast(tabbar.GetKey(i)) == child) {
tabbar.Set(i, tabbar.GetKey(i), title, icon);
break;
}
if (!GetParent())
Title(GetTitle());
Title(GetTitle());
RefreshFrame();
}

View file

@ -39,7 +39,7 @@ public:
/* virtual void ChildGotFocus() { handle.RefreshFocus(true); TopWindow::ChildGotFocus(); }
virtual void ChildLostFocus() { handle.RefreshFocus(HasFocusDeep()); TopWindow::ChildLostFocus(); }
virtual void GotFocus() { handle.RefreshFocus(true); }
virtual void LostFocus() { handle.RefreshFocus(HasFocusDeep()); }*/
virtual void LostFocus() { handle.RefreshFocus(HasFocusDeep()); } */
public:
#if defined(PLATFORM_WIN32)
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -132,6 +132,7 @@ private:
bool IsDockAllowed0(int align, const Value& v) const;
void SyncButtons(DockableCtrl& dc);
Ctrl *FindFirstChild() const;
void ChildTitleChanged(Ctrl *child, WString title, Image icon);
void State(DockWindow& dock, DockCont::DockState state);
@ -209,7 +210,8 @@ public:
void SyncUserSize(bool h, bool v);
WString GetTitle(bool force_count = false) const;
void ChildTitleChanged();
void ChildTitleChanged(DockableCtrl &dc);
void ChildTitleChanged(DockCont &dc);
bool IsDockAllowed(int align, int dc_ix = -1) const;

View file

@ -22,47 +22,10 @@ void DockTabBar::FrameAddSize(Size& sz)
TabBar::FrameAddSize(sz);
}
void DockTabBar::PaintTab(Draw& w, const Rect &r, const Tab& tab, const Font &font, Color ink, dword style)
{
DockableCtrl *d;
WString txt;
const Value &q = tab.value;
ink = (style == CTRL_DISABLED) ? SColorDisabled : ink;
if (IsTypeRaw<DockCont *>(q)) {
DockCont *c = ValueTo<DockCont *>(q);
d = &c->GetCurrent();
txt = c->GetTitle();
}
else {
ASSERT(IsTypeRaw<DockableCtrl *>(q));
d = ValueTo<DockableCtrl *>(q);
txt = d->GetTitle();
}
Size isz(0, 0);
if(icons)
{
const Image& icon = (style == CTRL_DISABLED) ? DisabledImage(d->GetIcon()) : d->GetIcon();
if (!icon.IsEmpty()) {
isz = icon.GetSize();
Point ip = GetImagePosition(r, isz.cx, isz.cy, TB_SPACEICON, LEFT);
w.DrawImage(ip.x, ip.y, icon);
}
}
if (showtext)
{
Point p = GetTextPosition(r, GetTextSize(txt, font).cy, isz.cx > 0 ? isz.cx + TB_SPACEICON + TB_MARGIN : TB_MARGIN);
w.DrawText(p.x, p.y, GetTextAngle(), txt, font, ink);
}
}
Size DockTabBar::GetStdSize(const Tab &t)
{
DockableCtrl *d;
const Value &q = t.value;
const Value &q = t.key;
Value v;
if (IsTypeRaw<DockCont *>(q)) {
DockCont *c = ValueTo<DockCont *>(q);
@ -290,6 +253,43 @@ void AutoHideBar::TabDrag(int ix)
GetCtrl(ix)->MoveBegin();
}
void AutoHideBar::PaintTab(Draw& w, const Rect &r, const Tab& tab, const Font &font, Color ink, dword style)
{
DockableCtrl *d;
WString txt;
const Value &q = tab.value;
ink = (style == CTRL_DISABLED) ? SColorDisabled : ink;
if (IsTypeRaw<DockCont *>(q)) {
DockCont *c = ValueTo<DockCont *>(q);
d = &c->GetCurrent();
txt = c->GetTitle();
}
else {
ASSERT(IsTypeRaw<DockableCtrl *>(q));
d = ValueTo<DockableCtrl *>(q);
txt = d->GetTitle();
}
Size isz(0, 0);
if(icons)
{
const Image& icon = (style == CTRL_DISABLED) ? DisabledImage(d->GetIcon()) : d->GetIcon();
if (!icon.IsEmpty()) {
isz = icon.GetSize();
Point ip = GetImagePosition(r, isz.cx, isz.cy, TB_SPACEICON, LEFT);
w.DrawImage(ip.x, ip.y, icon);
}
}
if (showtext)
{
Point p = GetTextPosition(r, GetTextSize(txt, font).cy, isz.cx > 0 ? isz.cx + TB_SPACEICON + TB_MARGIN : TB_MARGIN);
w.DrawText(p.x, p.y, GetTextAngle(), txt, font, ink);
}
}
AutoHideBar::AutoHideBar()
{
ctrl = NULL;

View file

@ -31,8 +31,6 @@ protected:
bool icons:1;
bool showtext:1;
virtual void PaintTab(Draw& w, const Rect &r, const Tab& tab,
const Font &font, Color ink, dword style);
virtual Size GetStdSize(const Tab &t);
virtual void RightDown(Point p, dword keyflags);
@ -63,6 +61,9 @@ public:
static void SetTimeout(int delay_ms) { ASSERT(delay_ms > 0); autohide_timeout = delay_ms; }
AutoHideBar();
virtual void PaintTab(Draw& w, const Rect &r, const Tab& tab,
const Font &font, Color ink, dword style);
private:
static int autohide_timeout;
@ -87,6 +88,11 @@ private:
void AdjustSize(Rect& r, const Size& sz);
};
struct DockTabable
{
virtual Value GetSortValue() = 0;
};
END_UPP_NAMESPACE
#endif

View file

@ -31,7 +31,18 @@ DockableCtrl& DockableCtrl::SizeHint(const Size& min, const Size& max, const Si
DockableCtrl& DockableCtrl::Title(const WString& _title)
{
title = _title; if (GetContainer()) GetContainer()->ChildTitleChanged(); return *this;
title = _title;
if (GetContainer())
GetContainer()->ChildTitleChanged(*this);
return *this;
}
DockableCtrl& DockableCtrl::Icon(const Image& m)
{
icon = m;
if (GetContainer())
GetContainer()->ChildTitleChanged(*this);
return *this;
}
bool DockableCtrl::IsFloating() const

View file

@ -53,7 +53,7 @@ public:
virtual void WindowMenu(Bar& bar) { WhenMenuBar(bar); }
const Image& GetIcon() { return icon; }
DockableCtrl& Icon(const Image& m) { icon = m; return *this; }
DockableCtrl& Icon(const Image& m);
DockableCtrl& Title(const char *_title) { return Title((WString)_title); }
DockableCtrl& Title(const WString& _title);
const WString& GetTitle() { return title; }
@ -102,6 +102,8 @@ public:
void Highlight();
void TimedHighlight(int ms);
virtual Value GetSortValue() { return GetTitle(); }
DockableCtrl();
};

View file

@ -1632,13 +1632,17 @@ void TabBar::SetData(const Value &key)
}
}
void TabBar::Set(int n, const Value &newkey, const Value &newvalue)
{
Set(n, newkey, newvalue, tabs[n].img);
}
void TabBar::Set(int n, const Value &newkey, const Value &newvalue, Image icon)
{
ASSERT(n >= 0 && n < tabs.GetCount());
tabs[n].key = newkey;
tabs[n].value = newvalue;
if (IsNull(icon))
tabs[n].img = icon;
tabs[n].img = icon;
if (stacking) {
String id = tabs[n].stackid;
tabs[n].stackid = GetStackId(tabs[n]);
@ -1651,16 +1655,21 @@ void TabBar::Set(int n, const Value &newkey, const Value &newvalue, Image icon)
Refresh();
}
void TabBar::Set(const Value &key, const Value &newvalue, Image icon)
void TabBar::SetValue(const Value &key, const Value &newvalue)
{
Set(FindKey(key), key, newvalue);
}
void TabBar::Set(int n, const Value &newvalue, Image icon)
void TabBar::SetValue(int n, const Value &newvalue)
{
Set(n, tabs[n].key, newvalue);
}
void TabBar::SetKey(int n, const Value &newkey)
{
Set(n, newkey, tabs[n].value);
}
void TabBar::SetIcon(int n, Image icon)
{
ASSERT(n >= 0 && n < tabs.GetCount());

View file

@ -403,9 +403,11 @@ public:
Value GetKey(int n) const { ASSERT(n >= 0 && n < tabs.GetCount()); return tabs[n].key;}
Value GetValue(int n) const { ASSERT(n >= 0 && n < tabs.GetCount()); return tabs[n].value;}
Value Get(const Value& key) const { return GetValue(FindKey(key)); }
void Set(int n, const Value& newkey, const Value& newvalue, Image icon = Null);
void Set(const Value &key, const Value& newvalue, Image icon = Null);
void Set(int n, const Value& newvalue, Image icon = Null);
void Set(int n, const Value& newkey, const Value& newvalue);
void Set(int n, const Value& newkey, const Value& newvalue, Image icon);
void SetValue(const Value &key, const Value &newvalue);
void SetValue(int n, const Value &newvalue);
void SetKey(int n, const Value &newkey);
void SetIcon(int n, Image icon);
void SetTabGroup(int n, const String& group);