From d38d643a74d836f523c8ba402fd6c48aeea4fa97 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 6 Sep 2011 06:29:05 +0000 Subject: [PATCH] bazaar: obsoleted DockCtrl moved to archive git-svn-id: svn://ultimatepp.org/upp/trunk@3826 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- archive/DockCtrl/AutoHideBar.cpp | 226 +++ archive/DockCtrl/ChangeLog.txt | 115 ++ archive/DockCtrl/DockCtrl.cpp | 1419 +++++++++++++++++++ archive/DockCtrl/DockCtrl.h | 1135 +++++++++++++++ archive/DockCtrl/DockCtrl.lay | 31 + archive/DockCtrl/DockCtrl.t | 999 +++++++++++++ archive/DockCtrl/DockCtrl.upp | 30 + archive/DockCtrl/DockTabs.cpp | 890 ++++++++++++ archive/DockCtrl/DockWindow.cpp | 979 +++++++++++++ archive/DockCtrl/DockableCtrl.cpp | 246 ++++ archive/DockCtrl/DockableCtrl.iml | 114 ++ archive/DockCtrl/PaneFrame.cpp | 666 +++++++++ archive/DockCtrl/PaneSplitter.cpp | 161 +++ archive/DockCtrl/READMEFIRST.txt | 5 + archive/DockCtrl/TODO.txt | 15 + archive/DockCtrl/icon.ico | Bin 0 -> 6 bytes archive/DockCtrl/init | 6 + archive/DockCtrlExample/DockCtrlExample.h | 48 + archive/DockCtrlExample/DockCtrlExample.lay | 12 + archive/DockCtrlExample/DockCtrlExample.upp | 16 + archive/DockCtrlExample/init | 7 + archive/DockCtrlExample/main.cpp | 211 +++ 22 files changed, 7331 insertions(+) create mode 100644 archive/DockCtrl/AutoHideBar.cpp create mode 100644 archive/DockCtrl/ChangeLog.txt create mode 100644 archive/DockCtrl/DockCtrl.cpp create mode 100644 archive/DockCtrl/DockCtrl.h create mode 100644 archive/DockCtrl/DockCtrl.lay create mode 100644 archive/DockCtrl/DockCtrl.t create mode 100644 archive/DockCtrl/DockCtrl.upp create mode 100644 archive/DockCtrl/DockTabs.cpp create mode 100644 archive/DockCtrl/DockWindow.cpp create mode 100644 archive/DockCtrl/DockableCtrl.cpp create mode 100644 archive/DockCtrl/DockableCtrl.iml create mode 100644 archive/DockCtrl/PaneFrame.cpp create mode 100644 archive/DockCtrl/PaneSplitter.cpp create mode 100644 archive/DockCtrl/READMEFIRST.txt create mode 100644 archive/DockCtrl/TODO.txt create mode 100644 archive/DockCtrl/icon.ico create mode 100644 archive/DockCtrl/init create mode 100644 archive/DockCtrlExample/DockCtrlExample.h create mode 100644 archive/DockCtrlExample/DockCtrlExample.lay create mode 100644 archive/DockCtrlExample/DockCtrlExample.upp create mode 100644 archive/DockCtrlExample/init create mode 100644 archive/DockCtrlExample/main.cpp diff --git a/archive/DockCtrl/AutoHideBar.cpp b/archive/DockCtrl/AutoHideBar.cpp new file mode 100644 index 000000000..aa8116ab6 --- /dev/null +++ b/archive/DockCtrl/AutoHideBar.cpp @@ -0,0 +1,226 @@ +#include "DockCtrl.h" + +AutoHideBar& AutoHideBar::Attach(DockableCtrl& ctrl) +{ + DockWindow& c = reinterpret_cast(ctrl); + TabInterface::Add(c.SetOwnerBar(this)); + childcount++; + ShowBar(); + active = -1; + return *this; +} + +void AutoHideBar::Detach(DockableCtrl& ctrl) +{ + DockWindow& c = reinterpret_cast(ctrl); + active = TabInterface::Find(ctrl); + if(tabs.GetCount() == 1) + { + CloseAll(); + HideBar(); + } + else Close(active); + childcount--; + c.SetOwnerBar(NULL); + HideWindow(); +} + +DockableCtrl* AutoHideBar::GetChild(int position) +{ + int i = Find(position); + if(i >= 0 && i < this->GetTabs().GetCount()) + return GetTabs().At(i).dock; + return NULL; +} + +int AutoHideBar::GetCount() +{ + return childcount; +} + +void AutoHideBar::ShowWindow() +{ + DockWindow* hiddenwindow = reinterpret_cast(tabs[active].dock); + if(!hiddenwindow->IsOpen()) + { + Size s = hiddenwindow->GetSizeHint(); + Rect r = GetScreenRect(); + Rect rr = r; + switch(layout) + { + case LAYOUT_LEFT: + rr.left = r.right; + s.cy = r.GetHeight(); +#if defined(PLATFORM_X11) + rr.right += 1; +#endif + break; + case LAYOUT_TOP: + rr.top = r.bottom; + s.cx = r.GetWidth(); +#if defined(PLATFORM_X11) + rr.bottom += 1; +#endif + break; + case LAYOUT_RIGHT: + rr.right = r.left; + s.cy = r.GetHeight(); +#if defined(PLATFORM_X11) + rr.left -= 1; +#endif + break; + case LAYOUT_BOTTOM: + rr.bottom = r.top; + s.cx = r.GetWidth(); +#if defined(PLATFORM_X11) + rr.top -= 1; +#endif + break; + + } + popup.SetRect(rr); + popup.Add(hiddenwindow->SizePos()); + hiddenwindow->Ctrl::Show(); + popup.PopUp(GetOwner(), false, true, false, false); + ctrl = hiddenwindow; + Ctrl::ProcessEvents(); + AdjustSize(rr, s); + Animate(popup, rr, GUIEFFECT_SLIDE); + } +} + +void AutoHideBar::HideWindow() +{ + if(popup.IsOpen()) + popup.Close(); + if(ctrl) + { + if(ctrl->IsChild()) + ctrl->Remove(); + ctrl = NULL; + } + active = -1; + highlight = -1; + Refresh(); +} + +void AutoHideBar::AdjustSize(Rect &r, const Size &sz) +{ + switch (layout) + { + case LAYOUT_LEFT: + r.right += sz.cx; + break; + case LAYOUT_TOP: + r.bottom += sz.cy; + break; + case LAYOUT_RIGHT: + r.left -= sz.cx; + break; + case LAYOUT_BOTTOM: + r.top -= sz.cy; + break; + }; +} + +void AutoHideBar::OnHighlight() +{ + DockableCtrl* hiddenwindow = NULL; + + if(highlight >= 0) + hiddenwindow = tabs[highlight].dock; + if(!hiddenwindow || hiddenwindow == ctrl) + return; + else if(ctrl) + { + if(hiddenwindow) + { + if(popup.IsOpen()) + popup.Close(); + ctrl->Remove(); + ctrl = NULL; + } + else HideWindow(); + } + if(hiddenwindow) + { + TabInterface::SetActiveTab(highlight); + ShowWindow(); + } +} + +void AutoHideBar::OnClose(int id, DockableCtrl& ctrl) +{ + ctrl.Shut(); +} + +void AutoHideBar::MouseMove(Point p, dword keysflags) +{ + TabInterface::MouseMove(p, keysflags); +} + +void AutoHideBar::MouseEnter(Point p, dword keyflags) +{ + if (ctrl && ctrl->IsOpen()) KillTimeCallback(2); + TabInterface::MouseEnter(p, keyflags); +} + +void AutoHideBar::MouseLeave() +{ + if (ctrl && ctrl->IsOpen()) + KillSetTimeCallback(1000, THISBACK(HideWindow), 2); + TabInterface::MouseLeave(); +} + +void AutoHideBar::FrameAdd(Ctrl& parent) +{ + parent.Add(*this); +} + +void AutoHideBar::FrameRemove() +{ + this->Ctrl::Remove(); +} + +void AutoHideBar::ShowBar() +{ + if(!size) SetSize(GetHeight() + 2); +} + +void AutoHideBar::HideBar() +{ + if(size) SetSize(0); +} + +AutoHideBar::AutoHideBar() +{ + internalname = "autohidebar"; + ctrl = NULL; + SetStyle(DockCtrlChStyle::StyleDefault()); + HasScrollBar(false); + HasButtons(false); + HasIcons(true); + Draggable(false); + SetSize(0); + childcount = 0; + + TabInterface::WhenHighlight = THISBACK(OnHighlight); + TabInterface::WhenClose = THISBACK(OnClose); + + popup.WhenEnter = THISBACK2(MouseEnter, Point(0, 0), 0); + popup.WhenLeave = THISBACK(MouseLeave); +} + +AutoHideBar::~AutoHideBar() +{ + ctrl = NULL; +} + +void AutoHideBar::PopupWindow::ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags) +{ + if(event == MOUSELEAVE) + WhenLeave(); + else if(event == MOUSEENTER) + WhenEnter(); + Ctrl::ChildMouseEvent(child, event, p, zdelta, keyflags); +} diff --git a/archive/DockCtrl/ChangeLog.txt b/archive/DockCtrl/ChangeLog.txt new file mode 100644 index 000000000..fcfdd30f1 --- /dev/null +++ b/archive/DockCtrl/ChangeLog.txt @@ -0,0 +1,115 @@ +//============================================================================================== +// DockCtrl: A dockable widget framework for U++ +// Author: Ismail YILMAZ +//============================================================================================== + + +[+] - new feature +[-] - bugfix +[*] - change + +Recent revisions are added to the current versions logs under date/time info. + +0.50 + > First Public Beta - public release name DockCtrl DEV802b.1 + > Package versioning is synchronised with the main Ultimate++ releases. + -------------------------------------------------------------------------------------------- + + full featured tabbed dock windows implemented. + optional "Nested tabbing" (a complex, yet very easy to use tabbing mode) introduced. + automatic tab alignment of tabbed windows is made optional. + + autohide feature is implemented. + "tabbed autohiding" introduced. + animated window (Thanks to Mrjtuk). + + introducing "Complex Dockable Framework" concept. namely, numereous and seperate + DockCtrl can be nested in any standard U++ Ctrl derived class. + + unified (mostly...) Chameleon structure "DockCtrlChStyle" added for easy customization. + + internationalization support added. currentyl only Turkish and English languages are supported. + + added settings menu + + added SetLayout() method for easy instatiation of DockCtrl class. + + self-explanatory example code is added to the package. + * DockPane helper class renamed to PaneFrame; + * removed Splitter ctrl code from DockPane and made into a seperate custom class PaneSplitter. + * control panel is heavily improved. + from now on, control panel has full access and control over the docked windows. + - Fixed most of the sizing issues by adding size hint methods (see DockableCtrl.cpp). + - Many internal bugfix and cleanup. + +0.51 + > public release name DockCtrl DEV802b.2 + -------------------------------------------------------------------------------------------- +2/19/2008 + - fixed a nasty bug in TabWindow Detach() method which led to stack overflow error. + (However, this feature is still in it'a alpha stage. So, it is experimental. There may very well + be bugs... USE IT AT YOUR RISK!) + - fixed tab dragging bug which cause to trigger the StartWindowDrag() in tab frame's empty area. + - ResetLayout() method fixed and renamed to ResetWidgetLayout(). + - the tabs and tabbed window title showed incorrect info(title, icon) in "nested tabbing" mode + and in "tabbed autohide" mede. this bug is fixed for both mode by adding + RefreshTabWindowLabel() method to TabWindow class. + - other internal and minor bugfixes. + * removed irrelevant packages from the assembly :) (remnants of my early experiments...) + * DockCtrlExample is added to the package. now the main package is named DockCtrl Dev802b.2 + * default and enhanced background skins are polished. now they have more native look. + +2/20/2008 + + german translation added (Thanks to Masu). + - fixed "call by reference errors" under MingW 3.4.2 (Thanks to Masu) + - Tab text alignment, close button detection bugs and scrollbar separator line painting are fixed (Thank to Unodgs). + - fixed autohide bug which caused the framework fall into an infinite loop when trying to hide a 2+ level nested tabs. + +2/21/2008 + * from now on, default U++ chameleon skins are used for painting the dragbar background (in default and enhanced style) + namely, from now on system colors applies to the Dockctrl dragbar. used skin samples are as following: + default skin = drawed using default TabCtrl style. + enhanced skin = drawed using default ToolBar style. + classic skin = no special draw action (uses current system background). + + tab repositioning for TabWindow and Autohide (using Ctrl + Left drag or with solely Middle Drag) added; + +2/23/2008 + + added partial X11 support (only drag-n-drop at the moment) - thanks to Mrjtuk. + * from now on, tab drag-n-drop animation has transparency effect. + - fixed a bug in tab animation which causes to set the active tab to the last tab in the list. now the tabs + correctly set the cursour to the previously active tab if the dnd is cancelled. + - fixed a bug in tab animation transparency effect which causes pane's with more than 2 childs to draw the animation + incorrectly. + - Fixed a nasty bug in AlphaHighlight() function to crash the application when compiled under MingW (5.1.3) (Thanks to Masu) + +2/26/2008 + + X11 related dnd issues fixed. DockCtrl now has full X11 docking support (Tested On KUBUNTU). + + Russian translation and more accurate layout file for control panel added to the source (Thanks to Anton). + +0.52 + > public release name DockCtrl DEV803b.1 + -------------------------------------------------------------------------------------------- +3/21/2008 + + added full serialization support. + + added default/custom layout support. + * DockableCtrl class reworked (now it is more abstract); + * TabWindow class reworked (no longer uses PaneSplitter() class to control child widgets). + * DockCtrl class renamed to DockBase class and added a more generic DockCtrl class. + * DockBase class derives from TopWindow. + + added InitDockCtrl() method for widget initialization. + + added InitCustomLayouts() method for planned "predefined" layout support. + + added Tabify() method (with 1 overload) to simplify widget tabbing. + + added DockFloat() method to DockableCtrl class. + + added ShowDragBarButtons() method to DockWindow class. + + added ForbidDragAndDrop()/PermitDragAndDrop() methods to DockableCtrl base widget class. + dnd behaviour of each DockableCtrl derived widget can be controlled using this method pair. + + added layout group to the settings window. + + added HotKey support for Settings window (default is CTRL + HOME). + + added methods to control forbid/permit on window sides. + - numerous bugfixes, and improvements. + +3/22/2008 + + double clicking on a dragbar of a authidden dockwindow will cause it go into docked state. + + added "stdsize" variable to the PaneFrame class. + + added ShowXXXXPane() (X:left/top/right/bottom) public methods to the Dockbase class. + +3/27/2008 + + added widget grouping (both predefined/default and user) support. + + added WidgetGroup() method and defined "%" operator for widget grouping. + + added group manager to the settings window. + * tab window creation/managment mechanism changed. + + + \ No newline at end of file diff --git a/archive/DockCtrl/DockCtrl.cpp b/archive/DockCtrl/DockCtrl.cpp new file mode 100644 index 000000000..fc968ed61 --- /dev/null +++ b/archive/DockCtrl/DockCtrl.cpp @@ -0,0 +1,1419 @@ +#include "DockCtrl/DockCtrl.h" + +#define IMAGEFILE +#define IMAGECLASS DockCtrlImages +#include + +//=============================================== +// DockCtrl class: +// Actual Framework. +//=============================================== + +DockCtrl::DockCtrl() : DockBase() +{ + ctrlinit = false; + AllowAll(); +} + +DockCtrl::~DockCtrl() +{ + ctrlinit = false; +} + +void DockCtrl::State(int reason) +{ + if(reason == Ctrl::OPEN) + { + if(!ctrlinit) + { + InitFrameWork(); + InitDockCtrl (); + InitDefaultLayout(); + InitCustomLayouts(); + InitFrameWorkSettings(); + ctrlinit = true; + } + } +} + +//=============================================== +// DockBase class: +// A dockable widget framework base ctrl. +//=============================================== + +Ctrl& DockBase::Dock(DockableCtrl& ctrl) +{ + int alignment = ctrl.Alignment(); + // Register ctrl. + ctrl.SetBase(this); + AddCtrlRecord(ctrl); + // Dock... + switch(alignment) + { + case DockableCtrl::DOCK_LEFT: + GetPaneFrame(alignment).Attach(ctrl).Vert(); + break; + case DockableCtrl::DOCK_TOP: + GetPaneFrame(alignment).Attach(ctrl).Horz(); + break; + case DockableCtrl::DOCK_RIGHT: + GetPaneFrame(alignment).Attach(ctrl).Vert(); + break; + case DockableCtrl::DOCK_BOTTOM: + GetPaneFrame(alignment).Attach(ctrl).Horz(); + break; + default: + if(ctrl.IsFloating()) + { + ctrl.CenterOwner(); + ctrl.SetSize(panesize); + ctrl.FloatEx(Rect(0, 0, panesize.cx / 4, panesize.cy / 3)); + ctrl.NoCenter(); + } + break; + } + RefreshPanel(); + return *this; +} + +DockableCtrl& DockBase::Tabify(DockableCtrl& ctrl1, DockableCtrl& ctrl2) +{ + // Register Ctrls. + AddCtrlRecord(ctrl1); + AddCtrlRecord(ctrl2); + // By default (if not stated otherwise) create tabwindows from Left PaneFrame. + TabWindow* tabwindow = GetPaneFrame(0).AddTabWindow(); + ASSERT(tabwindow); + tabwindow->Attach(ctrl1); + tabwindow->Attach(ctrl2); + return (DockableCtrl&) *tabwindow; +} + +DockableCtrl& DockBase::Tabify(String groupname, DockableCtrl& ctrl1, DockableCtrl& ctrl2) +{ + return (DockableCtrl&) dynamic_cast(Tabify(ctrl1, ctrl2)).SetGroup(groupname); +} + +DockableCtrl& DockBase::Tabify(DockableCtrl& ctrl1, DockableCtrl& ctrl2, DockableCtrl& ctrl3, DockableCtrl& ctrl4) +{ + return Tabify(Tabify(ctrl1, ctrl2), Tabify(ctrl3, ctrl4)); +} + +DockableCtrl& DockBase::Tabify(String groupname, DockableCtrl& ctrl1, DockableCtrl& ctrl2, DockableCtrl& ctrl3, DockableCtrl& ctrl4) +{ + return (DockableCtrl&) dynamic_cast(Tabify(ctrl1, ctrl2, ctrl3, ctrl4)).SetGroup(groupname); +} + +void DockBase::TabifyGroupAndDock(String groupname, int alignment) +{ + Dock(TabifyGroup(groupname).DockingStyle(alignment, DockableCtrl::STATE_SHOW)); +} + +void DockBase::TabifyGroupAndAutoHide(String groupname, int alignment) +{ + Dock(TabifyGroup(groupname).DockingStyle(alignment, DockableCtrl::STATE_AUTO)); +} + +void DockBase::TabifyGroupAndFloat(String groupname) +{ + Dock(TabifyGroup(groupname).DockFloat()); +} + +DockableCtrl& DockBase::TabifyGroup(String name) +{ + DockableCtrl* ctrl = NULL; + Vector& ids = groups.Get(name); + int ncount = ids.GetCount(); + ASSERT(ncount); + TabWindow* tabwindow = GetPaneFrame(0).AddTabWindow(); + ASSERT(tabwindow); + for(int i = 0; i < ncount; i++) tabwindow->Attach(*GetCtrlRecordFromId(ids[i])->ctrl); + tabwindow->SetGroup(name); + return (DockableCtrl&) *tabwindow; +} + +DockBase& DockBase::WidgetGroup(String name) +{ + NewWidgetGroup(predefinedgroup = name); + return *this; +} + +DockBase& DockBase::operator%(DockableCtrl& ctrl) +{ + int id = GetCtrlRecord(ctrl)->id; + if(!FindWidgetinGroup(predefinedgroup, id)) + AddWidgettoGroup(predefinedgroup, id); + return *this; +} + +DockBase& DockBase::WidgetLayout(String name) +{ + NewWidgetLayout(predefinedgroup = name); + return *this; +} + +DockBase& DockBase::operator/(DockableCtrl& ctrl) +{ + return *this; +} + +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 DockBase::Attach(DockableCtrl& ctrl) +{ + GetPaneFrame(ctrl.Alignment()).Attach(ctrl); +} + +void DockBase::Attach(DockableCtrl* ctrl) +{ + Attach(*ctrl); +} + +void DockBase::Detach(DockableCtrl& ctrl) +{ + GetPaneFrame(ctrl.Alignment()).Detach(ctrl); +} + +void DockBase::Detach(DockableCtrl* ctrl) +{ + Detach(*ctrl); +} + +void DockBase::ShowLeftPane(bool b) +{ + if(b) GetPaneFrame(PaneFrame::LEFT).ShowFrame(); + else GetPaneFrame(PaneFrame::LEFT).HideFrame(); +} + +void DockBase::ShowTopPane(bool b) +{ + if(b) GetPaneFrame(PaneFrame::TOP).ShowFrame(); + else GetPaneFrame(PaneFrame::TOP).HideFrame(); +} + +void DockBase::ShowRightPane(bool b) +{ + if(b) GetPaneFrame(PaneFrame::RIGHT).ShowFrame(); + else GetPaneFrame(PaneFrame::RIGHT).HideFrame(); +} + +void DockBase::ShowBottomPane(bool b) +{ + if(b) GetPaneFrame(PaneFrame::BOTTOM).ShowFrame(); + else GetPaneFrame(PaneFrame::BOTTOM).HideFrame(); +} + +void DockBase::AllowAll() +{ + AllowedSides[0] = true; + AllowedSides[1] = true; + AllowedSides[2] = true; + AllowedSides[3] = true; +} + +void DockBase::AllowLeft() +{ + AllowedSides[0] = true; + AllowedSides[1] = false; + AllowedSides[2] = false; + AllowedSides[3] = false; +} + +void DockBase::AllowTop() +{ + AllowedSides[1] = true; + AllowedSides[0] = false; + AllowedSides[2] = false; + AllowedSides[3] = false; +} + +void DockBase::AllowRight() +{ + AllowedSides[2] = true; + AllowedSides[0] = false; + AllowedSides[1] = false; + AllowedSides[3] = false; +} + +void DockBase::AllowBottom() +{ + AllowedSides[3] = true; + AllowedSides[0] = false; + AllowedSides[1] = false; + AllowedSides[2] = false; +} + +void DockBase::AllowLeftRight() +{ + AllowedSides[0] = true; + AllowedSides[2] = true; + AllowedSides[1] = false; + AllowedSides[3] = false; +} + +void DockBase::AllowTopBottom() +{ + AllowedSides[1] = true; + AllowedSides[3] = true; + AllowedSides[0] = false; + AllowedSides[2] = false; +} + +void DockBase::AllowLeftTop() +{ + AllowedSides[0] = true; + AllowedSides[1] = true; + AllowedSides[2] = false; + AllowedSides[3] = false; +} + +void DockBase::AllowRightBottom() +{ + AllowedSides[2] = true; + AllowedSides[3] = true; + AllowedSides[0] = false; + AllowedSides[1] = false; +} + +void DockBase::AllowLeftBottom() +{ + AllowedSides[0] = true; + AllowedSides[3] = true; + AllowedSides[1] = false; + AllowedSides[2] = false; +} + +void DockBase::AllowTopRight() +{ + AllowedSides[1] = true; + AllowedSides[2] = true; + AllowedSides[0] = false; + AllowedSides[3] = false; +} + +void DockBase::AllowNestedTabbing(bool b) +{ + tabsnested = b; + controlpanel.TabOptionNest <<= tabsnested; +} + +void DockBase::ControlPanel() +{ + if(controlpanel.IsOpen()) return; + controlpanel.Open(GetTopWindow()); + RefreshGroups(); + RefreshPanel(); +} + +void DockBase::OnPanelAction() +{ + CtrlRecord* ctrlrecord = GetCtrlRecordFromIndex(listtab.list.GetClickRow()); + if(ctrlrecord) + ctrlrecord->ctrl->Menu(); +} + +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(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(); +} + +void DockBase::Serialize(Stream& s) +{ + String layout = "CTRLSLAYOUTS"; + String group = "CTRLGROUPS"; + String settings = "DOCKCTRLSETTINGS"; + int version = 1; + int n = 0; + + s.Magic(1234765); + + if(s.IsStoring()) + { + s / version; + SerializePlacement(s); + s / settings; + s % tabsicons; + s % tabsclose; + s % tabsautoalign; + s % tabsnested; + s % autohideicons; + s % autohideclose; + s / layoutindex; + s / skinindex; + s / hotkey; + + s / layout; + // Write Layouts. + n = layouts.GetCount(); + s / n; + for(int i = 0; i < n; i++) + { + String key = layouts.GetKey(i); + String lay = layouts.Get(key); + s / key; + s / lay; + } + // Write Layout List. + n = controlpanel.layoutlist.GetCount(); + s / n; + for(int i = 0; i < n; i++) + { + String lname = controlpanel.layoutlist.GetKey(i); + s / lname; + } + + s / group; + // Write Groups. + //int j = predefinedgroups + 1; + n = groups.GetCount(); + s / n; + for(int i = 0; i < n; i++) + { + String key = groups.GetKey(i); + Vector& ids = groups.Get(key); + s / key; + ids.Serialize(s); + } + } + else + { + n = 0; + s / version; + SerializePlacement(s); + s / settings; + s % tabsicons; + s % tabsclose; + s % tabsautoalign; + s % tabsnested; + s % autohideicons; + s % autohideclose; + s / layoutindex; + s / skinindex; + s / hotkey; + + s / layout; + // Read Layouts. + s / n; + for(int i = 0; i < n; i++) + { + String key, lay; + s / key; + s / lay; + layouts.FindAdd(key, lay); + } + // Read Layout List. + s / n; + for(int i = 0; i < n; i++) + { + String lname; + s / lname; + controlpanel.layoutlist.Add(lname); + } + s / group; + // Read Groups. + s / n; + for(int i = 0; i < n; i++) + { + String key; + Vector ids; + ids.Clear(); + s / key; + ids.Serialize(s); + groups.FindAdd(key, ids); + } + // Write Ctrl values. + controlpanel.TabOptionIcon <<= tabsicons; + controlpanel.TabOptionClose <<= tabsclose; + controlpanel.TabOptionNest <<= tabsnested; + controlpanel.TabOptionAlignment <<= tabsautoalign; + controlpanel.AutoOptionIcon <<= autohideicons; + controlpanel.AutoOptionClose <<= autohideclose; + + controlpanel.layoutlist.SetIndex(layoutindex); + controlpanel.skinlist.SetIndex(skinindex); + } + s.Magic(); +} + +void DockBase::InitFrameWorkSettings() +{ + RefreshWidgetLayout(); + SetSkin(skinindex); + SetWidgetLayout(layoutindex); +} + +void DockBase::InitDefaultLayout() +{ + String name = t_("Default"); + if(layouts.Find(name) < 0) NewWidgetLayout(name); + NewWidgetGroup(name); +} + +void DockBase::SetSkin(int index) +{ + switch(index) + { + case 0: style = &(DockCtrlChStyle::StyleDefault()); break; + case 1: style = &(DockCtrlChStyle::StyleClassic()); break; + case 2: style = &(DockCtrlChStyle::StyleEnhanced()); break; + default: break; + } + + for(int i = 0; i < GetCtrlRecords().GetCount(); i++) + dynamic_cast(GetCtrlRecordFromIndex(i)->ctrl)->SetStyle(*style); + for(int i = 0; i < GetTabWindowCount(); i++) + GetTabWindowFromIndex(i)->SetStyle(*style); +} + +DockBase& DockBase::SetStyle(const DockCtrlChStyle::Style& s) +{ + style = &s; + Refresh(); + return *this; +} + + +void DockBase::OnSelectSkin() +{ + int newindex = controlpanel.skinlist.GetIndex(); + if(skinindex == newindex) return; + SetSkin(skinindex = newindex); +} + +void DockBase::OnSelectLayout() +{ + int newindex = controlpanel.layoutlist.GetIndex(); + if(layoutindex == newindex) return; + SetWidgetLayout(layoutindex = newindex); +} + +void DockBase::InitFrameWork() +{ + panesize = GetSize(); + int cx = panesize.cx / 4; + int cy = panesize.cy / 3; + + AddFrame(hide[0]); + AddFrame(hide[1]); + AddFrame(hide[2]); + AddFrame(hide[3]); + + hide[0].SetLayout(DockCtrlCustomFrame::LAYOUT_LEFT); + hide[2].SetLayout(DockCtrlCustomFrame::LAYOUT_RIGHT); + hide[1].SetLayout(DockCtrlCustomFrame::LAYOUT_TOP); + hide[3].SetLayout(DockCtrlCustomFrame::LAYOUT_BOTTOM); + + AddFrame(pane[0]); + AddFrame(pane[2]); + AddFrame(pane[1]); + AddFrame(pane[3]); + + pane[0].SetLayout(this, PaneFrame::LEFT, cx); + pane[2].SetLayout(this, PaneFrame::RIGHT, cx); + pane[1].SetLayout(this, PaneFrame::TOP, cy); + pane[3].SetLayout(this, PaneFrame::BOTTOM, cy); +} + +DockBase::DockBase() +{ + skinindex = layoutindex = 0; + tabsicons = tabsclose = tabsautoalign = true; + tabsnested = false; + autohideicons = autohideclose = true; + isready = false; + panesize.Clear(); + LeftPos(0, 0).TopPos(0,0); + CtrlLayout(listtab); + CtrlLayout(grouptab); + CtrlLayout(controlpanel); + controlpanel.CenterScreen().Sizeable().Zoomable().Title(t_("Settings")); + listtab.list.AddColumn(); + listtab.list.AddColumn(t_("Window Title")); + listtab.list.AddColumn(t_("Alignment")); + listtab.list.AddColumn(t_("State")); + listtab.list.AddColumn(t_("Position")); + listtab.list.EvenRowColor(); + listtab.list.SetLineCy(16); + + grouptab.grouptree.MultiSelect(); + controlpanel.panel.Add(listtab.SizePos(), t_("Status")); + controlpanel.panel.Add(grouptab.SizePos(), t_("Group Manager")); + + controlpanel.skinlist.Add(0, String(t_("Default"))).Add(1, String(t_("Classic"))).Add(2, String(t_("Enhanced"))).SetIndex(skinindex); + controlpanel.skinlist.WhenAction = THISBACK(OnSelectSkin); + controlpanel.layoutlist.WhenAction = THISBACK(OnSelectLayout); + listtab.list.WhenLeftClick = THISBACK(OnPanelAction); + grouptab.grouptree.WhenDropInsert = THISBACK(GroupDrop); + grouptab.grouptree.WhenDrag = THISBACK(GroupDrag); + grouptab.grouptree.WhenBar = THISBACK(GroupMenu); + grouptab.grouptree.WhenCursor = THISBACK(GroupSelect); + + grouptab.groupadd <<= THISBACK(OnAddNewGroup); + grouptab.groupdelete <<= THISBACK(OnDeleteGroup); + controlpanel.layoutbutton <<= THISBACK(ResetWidgetLayout); + controlpanel.layoutadd <<= THISBACK(OnAddNewLayout); + controlpanel.layoutdelete <<= THISBACK(OnDeleteLayout); + controlpanel.TabOptionAlignment <<= THISBACK(RefreshWidgetLayout); + controlpanel.TabOptionIcon <<= THISBACK(RefreshWidgetLayout); + controlpanel.TabOptionClose <<= THISBACK(RefreshWidgetLayout); + controlpanel.AutoOptionClose <<= THISBACK(RefreshWidgetLayout); + controlpanel.AutoOptionIcon <<= THISBACK(RefreshWidgetLayout); + + controlpanel.TabOptionIcon <<= tabsicons; + controlpanel.TabOptionClose <<= tabsclose; + controlpanel.TabOptionNest <<= tabsnested; + controlpanel.TabOptionAlignment <<= tabsautoalign; + + controlpanel.AutoOptionIcon <<= autohideicons; + controlpanel.AutoOptionClose <<= autohideclose; + + grouptab.groupdelete.Disable(); + SetKey(K_CTRL_HOME); +} + +DockBase::~DockBase() +{ + CleanUp(); + panesize.Clear(); +} + +void DockBase::CleanUp() +{ + for(int i = 0; i < panelicons.GetCount(); i++) + delete panelicons.At(i); + for(int i = 0; i < layouts.GetCount(); i++) + layouts.Remove(i); + for(int i = 0; i < groups.GetCount(); i++) + groups.Remove(i); + RemoveTabWindows(); + DeleteCtrlRecords(); +} + +void DockBase::RefreshWidgetLayout() +{ + TabWindow* tabwindow = NULL; + + tabsicons = (bool) controlpanel.TabOptionIcon.Get(); + tabsclose = (bool) controlpanel.TabOptionClose.Get(); + tabsnested = (bool) controlpanel.TabOptionNest.Get(); + tabsautoalign = (bool) controlpanel.TabOptionAlignment.Get(); + autohideicons = (bool) controlpanel.AutoOptionIcon.Get(); + autohideclose = (bool) controlpanel.AutoOptionClose.Get(); + + int n = GetTabWindowCount(); + for(int i = 0; i < n; i++) + { + tabwindow = GetTabWindowFromIndex(i); + if(tabsautoalign) + { + switch(tabwindow->GetBaseTab()->Alignment()) + { + case DockableCtrl::DOCK_LEFT: + tabwindow->SetLayout(DockCtrlCustomFrame::LAYOUT_RIGHT); + break; + case DockableCtrl::DOCK_TOP: + tabwindow->SetLayout(DockCtrlCustomFrame::LAYOUT_BOTTOM); + break; + case DockableCtrl::DOCK_RIGHT: + tabwindow->SetLayout(DockCtrlCustomFrame::LAYOUT_LEFT); + break; + case DockableCtrl::DOCK_BOTTOM: + tabwindow->SetLayout(DockCtrlCustomFrame::LAYOUT_TOP); + break; + } + } + else tabwindow->SetLayout(DockCtrlCustomFrame::LAYOUT_BOTTOM); + tabwindow->GetTabs().HasIcons(tabsicons); + tabwindow->GetTabs().HasButtons(tabsclose); + } + for(int i = 0; i < 4; i++) GetHideBar(i).HasButtons(autohideclose).HasIcons(autohideicons); +} + +void DockBase::OnAddNewLayout() +{ + String name; + if(EditText(name, t_("Add new layout"), t_("Layout name:"), 32)) + { + if(IsNull(name)) + { + Exclamation(t_("You must enter a name for the new layout")); + return; + } + else if(layouts.Find(name) >= 0) + { + if(!PromptOKCancel(Format(t_("Layout '%s' adready exists. Do you want to overwrite it?"), name))) + return; + } + NewWidgetLayout(name); + RefreshPanel(); + } +} + + +void DockBase::OnDeleteLayout() +{ + DelWidgetLayout(layouts.GetKey(layoutindex)); +} + +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::RemoveCtrlRecord(DockableCtrl& ctrl) +{ + CtrlRecord* record = GetCtrlRecord(ctrl); + if(record) delete record; +} + +void DockBase::DeleteCtrlRecords() +{ + for(int i = 0; i < ctrls.GetCount(); i++) + delete ctrls.At(i); +} + +DockBase::CtrlRecord* DockBase::GetCtrlRecord(DockableCtrl& ctrl) +{ + for(int i = 0; i < ctrls.GetCount(); i++) + { + CtrlRecord* record = ctrls.At(i); + if(record->ctrl == &ctrl) return record; + } + return NULL; +} + +DockBase::CtrlRecord* DockBase::GetCtrlRecordFromIndex(int index) +{ + if(index >= 0 && index < ctrls.GetCount()) + return ctrls.At(index); + return NULL; +} + +DockBase::CtrlRecord* DockBase::GetCtrlRecordFromId(int id) +{ + for(int i = 0; i < ctrls.GetCount(); i++) + { + CtrlRecord* record = ctrls.At(i); + if(record->id == id) return record; + } + return NULL; +} + +DockBase::CtrlRecord* DockBase::GetCtrlRecordFromGroup(String group) +{ + return NULL; +} + +DockableCtrl* DockBase::GetDockedWindowFromIndex(int index) +{ + Vector docks; + docks.Clear(); + for(int i = 0; i < 8; i++) + { + if(i < 4) + { + int n = GetPaneFrame(i).GetCount(); + if(n) for(int j = 0; j < n; j++) docks.Add(GetPaneFrame(i).GetChild(j + 1)); + } + else + { + int n = GetHideBar(i - 4).GetCount(); + if(n) for(int j = 0; j < n; j++) docks.Add(GetHideBar(i - 4).GetChild(j)); + } + } + return docks.GetCount() ? docks.At(index) : NULL; +} + +TabWindow* DockBase::GetTabWindowFromIndex(int index) +{ + TabWindow* tabwindow = tabwindows.At(index); + ASSERT(tabwindow); + return tabwindow; +} + +int DockBase::GetTabWindowCount() +{ + return tabwindows.GetCount(); +} + +int DockBase::GetDockedWindowCount() +{ + int dockcount = 0; + for(int i = 0; i < 8; i++) + if(i < 4) dockcount += GetPaneFrame(i).GetCount(); + else dockcount += GetHideBar(i - 4).GetCount(); + return dockcount; +} + +void DockBase::RemoveTabWindows() +{ + for(int i = 0 ; i < tabwindows.GetCount(); i++) + if(tabwindows.At(i)) delete tabwindows.At(i); +} + +void DockBase::RefreshTabWindowList() +{ + for(int i = 0; i < tabwindows.GetCount(); i++) + if(tabwindows.At(i)->IsDestroyed()) + { + TabWindow *t = tabwindows.At(i); + tabwindows.Remove(i); + delete t; + } +} + +Vector& DockBase::GetTabWindows() +{ + return tabwindows; +} + +void DockBase::NewWidgetLayout(String name) +{ + StringStream s; + SerializeLayout(s); + int id = AddWidgetLayout(name); + layouts[id] = (String) s; +} + +int DockBase::AddWidgetLayout(String name) +{ + int id = layouts.Find(name); + if(id < 0) + { + id = layouts.FindAdd(name, String()); + controlpanel.layoutlist.Add(name); + int index = controlpanel.layoutlist.GetCount() - 1; + controlpanel.layoutlist.SetIndex(layoutindex = index); + } + return id; +} + +void DockBase::AddWidgetLayout(String name, DockableCtrl& ctrl, int alignment, int state, int position) +{ + +} + +void DockBase::DelWidgetLayout(String name) +{ + int id = layouts.Find(name); + if(id < 0) return; + if(PromptOKCancel(Format(t_("Do you really want to delete layout '%s'"), name))) + { + layouts.RemoveKey(name); + controlpanel.layoutlist.Remove(id); + id--; + controlpanel.layoutlist.SetIndex(layoutindex = id); + } +} + +void DockBase::SetWidgetLayout(String name) +{ + int id = layouts.Find(name); + if(id < 0) return; + SetWidgetLayout(id); +} + +void DockBase::SetWidgetLayout(int index) +{ + if(layoutindex != index) controlpanel.layoutlist.SetIndex(layoutindex = index); + if(index == 0) controlpanel.layoutdelete.Disable(); + else controlpanel.layoutdelete.Enable(); + + String key = layouts.GetKey(index); + String& layout = layouts.Get(key); + StringStream s(layout); + s.SetLoading(); + SerializeLayout(s); +} + +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::ResetWidgetLayout() +{ + controlpanel.layoutlist.SetIndex(layoutindex = 0); + SetWidgetLayout(layoutindex); + RefreshPanel(); +} + +void DockBase::NewWidgetGroup(String name, bool predefined) +{ + predefined = true; + TreeCtrl& tree = grouptab.grouptree; + Vector 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; +} + +bool DockBase::AddWidgettoGroup(String name, DockableCtrl& ctrl) +{ + CtrlRecord* record = GetCtrlRecord(ctrl); + if(!record || name == t_("Default")) return false; + NewWidgetGroup(name); + Vector& 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; +} + +bool DockBase::AddWidgettoGroup(String name, int id) +{ + CtrlRecord* record = GetCtrlRecordFromId(id); + if(!record) return false; + return AddWidgettoGroup(name, *record->ctrl); +} + +bool DockBase::DeleteWidgetfromGroup(String name, DockableCtrl& ctrl) +{ + CtrlRecord* record = GetCtrlRecord(ctrl); + if(groups.Find(name) < 0 || name == t_("Default") || !record) return false; + Vector& ids = groups.Get(name); + for(int i = 0; i < ids.GetCount(); i++) if(record->id == ids[i]) ids.Remove(i); + return true; +} + +bool DockBase::DeleteWidgetfromGroup(String name, int id) +{ + CtrlRecord* record = GetCtrlRecordFromId(id); + if(!record) return false; + return DeleteWidgetfromGroup(name, *record->ctrl); +} + +int DockBase::AddWidgetGroup(String name) +{ + return 1; +} + +void DockBase::DeleteWidgetGroup(String name) +{ + TreeCtrl& tree = grouptab.grouptree; + if(name == t_("Default")) return; + if(PromptOKCancel(Format(t_("Do you really want to delete group '%s'"), name))) + { + groups.RemoveKey(name); + int id = tree.Find(name); + if(id >= 0) + { + tree.RemoveChildren(id); + tree.Remove(id); + } + tree.Refresh(); + } + +} + +Vector& DockBase::FindWidgetGroup(String name) +{ + return groups.Get(name); +} + +bool DockBase::FindWidgetinGroup(String name, int id) +{ + Vector& ids = FindWidgetGroup(name); + for(int i = 0; i < ids.GetCount(); i++) + if(ids[i] == id) return true; + return false; +} + +void DockBase::OnAddNewGroup() +{ + String name; + if(EditText(name, t_("Add new group"), t_("Group name:"), 32)) + { + if(IsNull(name)) + { + Exclamation(t_("You must enter a name for the new group")); + return; + } + else if(groups.Find(name) >= 0) + { + if(!PromptOKCancel(Format(t_("Group '%s' adready exists. Do you want to overwrite it?"), name))) + return; + } + NewWidgetGroup(name); + RefreshPanel(); + } +} + +void DockBase::OnDeleteGroup() +{ + TreeCtrl& tree = grouptab.grouptree; + int id = tree.GetCursor(); + if(id == 0) return; + DeleteWidgetGroup(tree.GetValue(tree.GetCursor())); +} + +void DockBase::GroupDrop(int parent, int ii, PasteClip& d) +{ + if (parent == 0) return d.Reject(); + + TreeCtrl& tree = grouptab.grouptree; + int p = tree.GetParent(parent); + if (p != 0) parent = p; + + if(AcceptInternal(d, "DockCtrlGroupTreeDrag")) + { + Vector sel = tree.GetSel(); + for (int i = 0; i < sel.GetCount(); i++) + { + + int id = tree.Get(sel[i]); + String group = (String) tree.GetValue(parent); + if(group == t_("Default") || FindWidgetinGroup(group, id)) + return d.Reject(); + AddWidgettoGroup(group, id); + tree.Open(parent); + } + return; + } + tree.SetFocus(); +} + +void DockBase::GroupDrag() +{ + TreeCtrl& tree = grouptab.grouptree; + int idc = -1; + if (tree.GetCursor() >= 0 && tree.GetParent(tree.GetCursor()) <= 0) + return; + if(tree.DoDragAndDrop(InternalClip(tree, "DockCtrlGroupTreeDrag"), tree.GetDragSample()) == DND_MOVE) + { + int parent = tree.GetParent(tree.GetCursor()); + idc = tree.GetCursor(); + String name = tree.GetValue(idc); + String group = (String) tree.GetValue(parent); + int id = tree.Get(idc); + if(DeleteWidgetfromGroup(group, id)) tree.Remove(idc); + } + tree.Refresh(); +} + +void DockBase::GroupSelect() +{ + TreeCtrl& tree = grouptab.grouptree; + int root = tree.GetCursor(); + if(root < 0) return; + int id = tree.GetParent(root); + String group = (String) tree.GetValue(root); + grouptab.groupdelete.Enable(id == 0 && group != t_("Default")); +} + +void DockBase::RefreshGroups() +{ + TreeCtrl& tree = grouptab.grouptree; + tree.Clear(); + tree.SetRoot(DockCtrlImages::DefaultImage(), t_("Available Widget Groups")); + tree.Open(0); + for(int i = 0; i < groups.GetCount(); i++) + { + String group = groups.GetKey(i); + Vector& ids = groups.Get(group); + tree.Add(0, DockCtrlImages::DefaultImage(), group); + for(int j = 0; j < ids.GetCount(); j++) + { + CtrlRecord* record = GetCtrlRecordFromId(ids[j]); + ASSERT(record); + tree.Add(tree.Find(group), record->ctrl->GetIcon(), Value(record->id), Value(record->ctrl->GetLabel())); + } + } +} + +void DockBase::GroupMenu(Bar& bar) +{ + TreeCtrl& tree = grouptab.grouptree; + int id = tree.GetCursor(); + if(id < 0) return; + id = tree.GetParent(id); + activegroup = (String) tree.GetValue(tree.GetCursor()); + if(id >= 0) + { + if(id == 0 && tree.GetChildCount(id)) + { + bar.Add(Format(t_("Dock Group '%s'"), activegroup), THISBACK1(GroupDockMenu, 0)); + bar.Add(Format(t_("AutoHide Group '%s'"), activegroup), THISBACK1(GroupDockMenu, 1)); + bar.Add(Format(t_("Float Group '%s'"), activegroup), THISBACK3(GroupMenuAction, activegroup, 2, -1)); + bar.Separator(); + bar.Add(tree.GetChildCount(tree.GetCursor()) > 1, Format(t_("Tabify Group '%s' and..."), activegroup), THISBACK1(GroupTabifyMenu, 3)); + bar.Separator(); + bar.Add(activegroup != t_("Default"), Format(t_("Delete Group '%s'"), activegroup), THISBACK1(DeleteWidgetGroup, activegroup)); + bar.Separator(); + bar.Add(Format(t_("Close Group '%s'"), activegroup), DockCtrlImages::CClose(), THISBACK3(GroupMenuAction, activegroup, -1, -1)); + + } + if(id > 0) + { + Vector sel = tree.GetSel(); + for(int i = 0; i < sel.GetCount(); i++) id = tree.Get(sel[i]); + CtrlRecord* record = GetCtrlRecordFromId(id); + ASSERT(record); + record->ctrl->Menu(); + } + } + else bar.Add(t_("Add New Group..."), THISBACK(OnAddNewGroup)); +} + +void DockBase::GroupDockMenu(Bar& bar, int command) +{ + if(IsSideAllowed(DockableCtrl::DOCK_TOP)) bar.Add(t_("Top"), THISBACK3(GroupMenuAction, activegroup, (int) command, (int)DockableCtrl::DOCK_TOP)); + if(IsSideAllowed(DockableCtrl::DOCK_LEFT)) bar.Add(t_("Left"), THISBACK3(GroupMenuAction, activegroup, (int) command, (int)DockableCtrl::DOCK_LEFT)); + if(IsSideAllowed(DockableCtrl::DOCK_RIGHT)) bar.Add(t_("Right"), THISBACK3(GroupMenuAction, activegroup, (int) command, (int)DockableCtrl::DOCK_RIGHT)); + if(IsSideAllowed(DockableCtrl::DOCK_BOTTOM)) bar.Add(t_("Bottom"), THISBACK3(GroupMenuAction, activegroup, (int) command, (int)DockableCtrl::DOCK_BOTTOM)); +} + +void DockBase::GroupTabifyMenu(Bar& bar, int command) +{ + bar.Add(t_("Dock"), THISBACK1(GroupDockMenu, 3)); + bar.Add(t_("Auto Hide"), THISBACK1(GroupDockMenu, 4)); + bar.Add(t_("Float"), THISBACK3(GroupMenuAction, activegroup, 5, -1)); +} + +void DockBase::GroupMenuAction(String name, int command, int alignment) +{ + DockableCtrl* ctrl = NULL; + Vector& 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; + } + } + } +} + +bool DockBase::Key(dword key, int count) +{ + if(key == hotkey) + ControlPanel(); + return TopWindow::Key(key, count); +} + +CH_STYLE(DockCtrlChStyle, Style, StyleClassic) +{ + font = StdFont(); + barmargins = Rect(2,2,2,2); + barheight = font.Info().GetHeight() + 8; + tabheight = font.Info().GetHeight() + 8; + tabmargin = 2; + tabsel = Rect(2, 2, 2, 2); + tabedge = Rect(6, 6, 6, 6); + tabextendleft = 0; + + DockCtrlImgsLook(barbackground, DockCtrlImages::I_CBarBackground, 1); + DockCtrlImgsLook(barshut, DockCtrlImages::I_CClose, 3); + DockCtrlImgsLook(barhide, DockCtrlImages::I_CHide, 3); + DockCtrlImgsLook(barmenu, DockCtrlImages::I_CMenu, 3); + + + CtrlsImageLook(tabnormal, ClassicCtrlsImg::I_TAB, 4); + CtrlsImageLook(tabfirst, ClassicCtrlsImg::I_FTAB, 4); + CtrlsImageLook(tablast, ClassicCtrlsImg::I_LTAB, 4); + CtrlsImageLook(tabboth, ClassicCtrlsImg::I_BTAB, 4); +} + +CH_STYLE(DockCtrlChStyle, Style, StyleEnhanced) +{ + font = StdFont(); + barmargins = Rect(2,2,2,2); + barheight = font.Info().GetHeight() + 8; + tabheight = font.Info().GetHeight() + 8; + tabmargin = 2; + tabsel = Rect(2, 2, 2, 2); + tabedge = Rect(6, 6, 6, 6); + tabextendleft = 0; + + const ToolBar::Style* defguistyle = &ToolBar::StyleDefault(); + barbackground[0] = defguistyle->arealook; + + DockCtrlImgsLook(barshut, DockCtrlImages::I_CClose, 3); + DockCtrlImgsLook(barhide, DockCtrlImages::I_CHide, 3); + DockCtrlImgsLook(barmenu, DockCtrlImages::I_CMenu, 3); + + CtrlsImageLook(tabnormal, CtrlsImg::I_TAB, 4); + CtrlsImageLook(tabfirst, CtrlsImg::I_FTAB, 4); + CtrlsImageLook(tablast, CtrlsImg::I_LTAB, 4); + CtrlsImageLook(tabboth, CtrlsImg::I_BTAB, 4); + + stdhighlight = StandardHighlight(Blend(SColorHighlight, SColorPaper, 90), SColorHighlight); + tabhighlight = AlphaHighlight(stdhighlight, 80); + +} + +CH_STYLE(DockCtrlChStyle, Style, StyleDefault) +{ + font = StdFont(); + barmargins = Rect(2,2,2,2); + barheight = font.Info().GetHeight() + 8; + tabheight = font.Info().GetHeight() + 8; + tabmargin = 2; + tabsel = Rect(2, 2, 2, 2); + tabedge = Rect(6, 6, 6, 6); + tabextendleft = 0; + + const TabCtrl::Style* defguistyle = &TabCtrl::StyleDefault(); + barbackground[0] = defguistyle->normal[0]; + + DockCtrlImgsLook(barshut, DockCtrlImages::I_DClose, 3); + DockCtrlImgsLook(barhide, DockCtrlImages::I_DHide, 3); + DockCtrlImgsLook(barmenu, DockCtrlImages::I_DMenu, 3); + + CtrlsImageLook(tabnormal, CtrlsImg::I_TAB, 4); + CtrlsImageLook(tabfirst, CtrlsImg::I_FTAB, 4); + CtrlsImageLook(tablast, CtrlsImg::I_LTAB, 4); + CtrlsImageLook(tabboth, CtrlsImg::I_BTAB, 4); + + + stdhighlight = StandardHighlight(Blend(SColorHighlight, SColorPaper, 90), SColorHighlight); + tabhighlight = AlphaHighlight(stdhighlight, 80); + +} diff --git a/archive/DockCtrl/DockCtrl.h b/archive/DockCtrl/DockCtrl.h new file mode 100644 index 000000000..054a691d1 --- /dev/null +++ b/archive/DockCtrl/DockCtrl.h @@ -0,0 +1,1135 @@ +//============================================================================================== +// DockCtrl: A dockable widget framework for U++ +// Author: Ismail YILMAZ +// Version: 0.52 (DEV-0803b.2) +//============================================================================================== + +#ifndef DOCKCTRL_H +#define DOCKCTRL_H + +#include +#include + +using namespace UPP; + +#define LAYOUTFILE +#include + +#define IMAGECLASS DockCtrlImgs +#define IMAGEFILE +#include + +#define TFILE +#include + +#include + +class PaneSplitter; +class TabInterface; +class AutoHideBar; +class PaneFrame; +class DockBase; +class DockCtrl; +class DockWindow; +class TabWindow; +class DockableCtrl; + +//---------------------------------------------------------------------------------------------- +// DockCtrl: Chameleon Support. +// +struct DockCtrlChStyle : Moveable +{ + struct Style : ChStyle