void DockBase::GroupMenuAction(String name, int command, int alignment) { DockableCtrl* ctrl = NULL; Vector<int>& ids = groups.Get(name); int ncount = ids.GetCount(); bool aligned = (alignment >= DockableCtrl::DOCK_LEFT && alignment <= DockableCtrl::DOCK_BOTTOM); for(int i = 0; i < ncount * 2; i++) { if(i < ncount) { ctrl = GetCtrlRecordFromId(ids[i])->ctrl; ASSERT(ctrl); ctrl->Shut(); } else { if(i == ncount) RefreshTabWindowList(); ctrl = GetCtrlRecordFromId(ids[i - ncount])->ctrl; ASSERT(ctrl); switch(command) { case 0: Dock(ctrl->DockingStyle(alignment, DockableCtrl::STATE_SHOW)); break; case 1: Dock(ctrl->SetSizeHint(Size(0,0)).DockingStyle(alignment, DockableCtrl::STATE_AUTO)); break; case 2: Dock(ctrl->DockFloat()); break; case 3: if (i - ncount == 0) TabifyGroupAndDock(name, alignment); break; case 4: if (i - ncount == 0) TabifyGroupAndAutoHide(name, alignment); break; case 5: if (i - ncount == 0) TabifyGroupAndFloat(name); break; } } } }
void AutoHideBar::ComposeTab(Tab& tab, const Font &font, Color ink, int 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(); } if(icons) { tab.AddImage((style == CTRL_DISABLED) ? DisabledImage(d->GetIcon()) : d->GetIcon()); } if (showtext) { tab.AddText(txt, font, ink); } }
void DockCont::TabSelected() { int ix = tabbar.GetCursor(); if (ix >= 0) { DockableCtrl *dc = Get0(ix); if (!dc) return; Ctrl *ctrl = GetCtrl(ix); Ctrl *first = &handle; for (Ctrl *c = first->GetNext(); c; c = c->GetNext()) if (c != ctrl) c->Hide(); ctrl->Show(); Icon(dc->GetIcon()).Title(dc->GetTitle()); handle.dc = dc; SyncButtons(*dc); if (IsTabbed()) { DockCont *c = static_cast<DockCont *>(GetParent()); c->tabbar.SyncRepos(); c->TabSelected(); c->RefreshFrame(); } else RefreshLayout(); } }
void DockWindow::DockAsTab(DockCont &target, DockableCtrl &dc) { DockCont *c = GetContainer(dc); if (c) { if (c->GetCount() == 1) CloseContainer(*c); else { Ctrl *c = dc.GetParent(); dc.Remove(); c->Layout(); } } target.Add(dc); }
bool DockBase::AddWidgettoGroup(String name, DockableCtrl& ctrl) { CtrlRecord* record = GetCtrlRecord(ctrl); if(!record || name == t_("Default")) return false; NewWidgetGroup(name); Vector<int>& ids = groups.Get(name); for(int i = 0; i < ids.GetCount(); i++) if(ids[i] == record->id) { Exclamation(Format(t_("Error: Widget (%s) is already in the group '%s'"), ctrl.GetLabel(), name)); return false; } ids.Add(record->id); grouptab.grouptree.Add(grouptab.grouptree.Find(name), ctrl.GetIcon(), Value(record->id), Value(ctrl.GetLabel())); return true; }
void DockCont::SyncButtons(DockableCtrl &dc) { if (base) { Ctrl::LogPos lp; const DockableCtrl::Style &s = dc.GetStyle(); int btnsize = handle.GetHandleSize(s) - 3; Logc &inc = s.handle_vert ? lp.y : lp.x; lp.x = s.handle_vert ? Ctrl::Logc(ALIGN_LEFT, 1, btnsize) : Ctrl::Logc(ALIGN_RIGHT, 1, btnsize); lp.y = Ctrl::Logc(ALIGN_TOP, 1, btnsize); if (close.GetParent()) { close.SetLook(s.close).SetPos(lp).Show(); inc.SetA(inc.GetA() + btnsize + 1); } bool ah = base->IsAutoHide(); autohide.Show(ah); if (ah && autohide.GetParent()) { autohide.SetLook(s.autohide).SetPos(lp); inc.SetA(inc.GetA() + btnsize + 1); } if (windowpos.GetParent()) windowpos.SetLook(s.windowpos).SetPos(lp).Show(); } else { close.Hide(); autohide.Hide(); windowpos.Hide(); } }
void DockWindow::Float(DockableCtrl &dc, Point p) { if (dc.GetParent() && p.IsNullInstance()) p = GetScreenRect().TopLeft(); else Register(dc); FloatContainer(*GetReleasedContainer(dc), p); }
void DockWindow::AutoHide(int align, DockableCtrl &dc) { ALIGN_ASSERT(align); Register(dc); DockCont *c = GetReleasedContainer(dc); c->StateAutoHide(*this); hideframe[align].AddCtrl(*c, dc.GetGroup()); }
Size DockTabBar::GetStdSize(const Tab &t) { DockableCtrl *d; const Value &q = t.key; Value v; if (IsTypeRaw<DockCont *>(q)) { DockCont *c = ValueTo<DockCont *>(q); d = &c->GetCurrent(); v = c->GetTitle(); } else { ASSERT(IsTypeRaw<DockableCtrl *>(q)); d = ValueTo<DockableCtrl *>(q); v = d->GetTitle(); } int isz = (IsVert() ? d->GetIcon().GetHeight() : d->GetIcon().GetWidth()); return showtext ? (TabBar::GetStdSize(v) + Size(isz+2, 0)) : Size(isz, isz); }
void DockBase::NewWidgetGroup(String name, bool predefined) { predefined = true; TreeCtrl& tree = grouptab.grouptree; Vector<int> ids; ids.Clear(); int group = groups.FindAdd(name, ids); if(tree.Find(name) < 0) tree.Add(0, DockCtrlImages::DefaultImage(), Value(name)); if(name != t_("Default")) return; for(int i = 0; i < ctrls.GetCount(); i++) { DockableCtrl * ctrl = ctrls[i]->ctrl; int id = ctrls[i]->id; ids.Add(ctrls[i]->id); tree.Add(tree.Find(name), ctrl->GetIcon(), Value(id), Value(ctrl->GetLabel())); } groups[group] = ids; }
void DockCont::TabDragged(int ix) { if (ix >= 0) { // Special code needed Value v = tabbar.Get(ix); if (IsDockCont(v)) { DockCont *c = ContCast(v); c->Remove(); base->FloatFromTab(*this, *c); } else { DockableCtrl *c = DockCast(v); c->Remove(); base->FloatFromTab(*this, *c); } if (tabbar.IsAutoHide()) RefreshLayout(); } }
void DockWindow::Close(DockableCtrl &dc) { DockCont *c = GetContainer(dc); if (c && c->GetCount() > 1) { dc.Remove(); c->Layout(); c = NULL; } if (c) CloseContainer(*c); }
void DockBase::AddCtrlRecord(DockableCtrl& ctrl) { CtrlRecord* record = NULL; if(GetCtrlRecord(ctrl) || ctrl.IsTabWindow()) return; ctrls.Add((record = new CtrlRecord())); if(record) { record->ctrl = &ctrl; record->id = ctrls.GetCount(); ImageCtrl* imagectrl = new ImageCtrl(); panelicons.Add(imagectrl); } }
void DockBase::DoDragAndDrop(DockableCtrl& ctrl, Point p, Size sz) { for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { if(i != j) { if(!GetPaneFrame(j).HasCtrlInRange(ctrl, p)) { GetPaneFrame(j).DnDSourceoutofRange(); GetPaneFrame(j).DnDAnimate(); } } } if(GetPaneFrame(i).HasCtrlInRange(ctrl, p)) { ctrl.SetDropTarget(i, ctrl.GetDropState()); break; } } }
void DockCont::GetGroups(Vector<String> &groups) { for (int i = 0; i < tabbar.GetCount(); i++) { Value v = tabbar.Get(i); if (IsDockCont(v)) ContCast(v)->GetGroups(groups); else { DockableCtrl *dc = DockCast(v); String g = dc->GetGroup(); if (!g.IsEmpty()) { bool found = false; for (int j = 0; j < groups.GetCount(); j++) if (groups[j] == g) { found = true; break; } if (!found) groups.Add(g); } } } }
bool DockWindow::IsDockAllowed(int align, DockableCtrl &dc) { ALIGN_ASSERT(align); return dockable[align] && dc.IsDockAllowed(align); }
void DockWindow::Float(DockableCtrl &dc, const char *title, Point p) { dc.Title(title); Float(dc, p); }
void AutoHideBar::OnClose(int id, DockableCtrl& ctrl) { ctrl.Shut(); }
void DockBase::Detach(DockableCtrl& ctrl) { GetPaneFrame(ctrl.Alignment()).Detach(ctrl); }
void DockBase::SerializeLayout(Stream& s, bool deflay) { CtrlRecord* record = NULL; DockableCtrl* ctrl = NULL; TreeCtrl& tree = grouptab.grouptree; String name; int panesize = 0; int type = 0; int alignment = 0; int state = 0; int position = 0; int id = 0; int childcount = 0; Size childsize; if(s.IsStoring()) { // Remove unused TabWindows (BugFix). RefreshTabWindowList(); // Write Tabbing mode. s % tabsnested; // Write Widgets. // Write Docked (shown or hidden) and AutoHidden widgets. childcount = GetDockedWindowCount(); s / childcount; if(childcount) for(int i = 0; i < childcount; i++) { ctrl = GetDockedWindowFromIndex(i); ASSERT(ctrl); ctrl->Serialize(s); } // Write PaneFrame sizes. for(int i = 0; i < 4; i++) { panesize = GetPaneFrame(i).GetSize(); s / panesize; } childcount = 0; int ctrlscount = ctrls.GetCount(); // Write Floating Dockwindows. for(int i = 0; i < ctrlscount * 2; i++) { if(i < ctrlscount) childcount += GetCtrlRecordFromIndex(i)->ctrl->IsFloating() ? 1 : 0; if(i >= ctrlscount) { if(i == ctrlscount) s / childcount; ctrl = GetCtrlRecordFromIndex(i - ctrlscount)->ctrl; ASSERT(ctrl); if(ctrl->IsFloating()) ctrl->Serialize(s); } } childcount = 0; // Write Floating TabWindows. int tabwindowcount = GetTabWindowCount(); if(tabwindowcount) for(int i = 0; i < tabwindowcount * 2; i++) { if(i < tabwindowcount) childcount += GetTabWindowFromIndex(i)->IsFloating() ? 1 : 0; if(i >= tabwindowcount) { if(i == tabwindowcount) s / childcount; TabWindow* tabwindow = GetTabWindowFromIndex(i - tabwindowcount); ASSERT(tabwindow); if(tabwindow->IsFloating()) tabwindow->Serialize(s); } } } if(s.IsLoading()) { childcount = 0; // Close All widgets. for(int i = 0; i < GetTabWindowCount(); i++) GetTabWindowFromIndex(i)->DetachAll(); for(int i = 0; i < ctrls.GetCount(); i++) GetCtrlRecordFromIndex(i)->ctrl->Shut(); // Remove unused TabWindows (BugFix). RefreshTabWindowList(); // Read Tabbing Mode s % tabsnested; controlpanel.TabOptionNest <<= tabsnested; // Read Docked (shown or hidden) and AutoHidden widgets. s / childcount; if(childcount) for(int i = 0; i < childcount; i++) { s / type / id; if(type == DockableCtrl::TYPE_DOCKWINDOW) GetCtrlRecordFromId(id)->ctrl->Serialize(s); if(type == DockableCtrl::TYPE_TABWINDOW) GetPaneFrame(0).AddTabWindow()->Serialize(s); } // Read PaneFrame sizes. for(int i = 0; i < 4; i++) { s / panesize; GetPaneFrame(i).SetSize(panesize); } childcount = 0; s / childcount; if(childcount) for(int i = 0; i < childcount; i++) { s / type / id; GetCtrlRecordFromId(id)->ctrl->Serialize(s); } childcount = 0; s / childcount; if(childcount) for(int j = 0; j < childcount; j++) { s / type / id; TabWindow* tabwindow = GetPaneFrame(0).AddTabWindow(); tabwindow->Serialize(s); } } s.Close(); }
void DockBase::RefreshPanel() { if(!controlpanel.IsOpen() || !controlpanel.IsVisible()) return; listtab.list.Clear(); for(int i = 0; i < GetCtrlRecords().GetCount(); i++) { int alignment = 0; bool tabbed = false; bool floating = false; DockableCtrl* ctrl = GetCtrlRecordFromIndex(i)->ctrl; if(ctrl->IsTabbed()) { TabWindow* tabwindow = dynamic_cast<DockWindow*>(ctrl)->GetOwnerTab(); if(tabwindow) { alignment = tabwindow->GetBaseTab()->Alignment(); floating = tabwindow->GetBaseTab()->IsAutoHidden(); tabbed = true; } } else alignment = ctrl->Alignment(); String a, s; switch(alignment) { case DockableCtrl::DOCK_LEFT: a = t_("LEFT"); break; case DockableCtrl::DOCK_TOP: a = t_("TOP"); break; case DockableCtrl::DOCK_RIGHT: a = t_("RIGHT"); break; case DockableCtrl::DOCK_BOTTOM: a = t_("BOTTOM"); break; case DockableCtrl::DOCK_NONE: if(ctrl->IsFloating() || tabbed) a = t_("FLOATING"); else a = t_("NONE"); break; } switch(ctrl->State()) { case DockableCtrl::STATE_SHOW: s = t_("SHOWN"); break; case DockableCtrl::STATE_HIDE: s = t_("HIDDEN"); break; case DockableCtrl::STATE_AUTO: s = t_("AUTO HIDDEN"); break; case DockableCtrl::STATE_SHUT: s = t_("SHUT"); break; case DockableCtrl::STATE_TABBED: floating ? s = t_("AUTO HIDDEN") : s = t_("TABBED"); break; } listtab.list.Add(0, Format("%s",ctrl->GetLabel()), a, s, ctrl->Position()); listtab.list.SetCtrl(i, 0, (panelicons.At(i))->SetImage(ctrl->GetIcon().IsNullInstance() ? DockCtrlImages::DefaultImage : ctrl->GetIcon())); } controlpanel.Refresh(); }