[haiku-commits] r36931 - haiku/branches/features/stack-and-tile/src/servers/app

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 25 May 2010 08:22:39 +0200 (CEST)

Author: czeidler
Date: 2010-05-25 08:22:39 +0200 (Tue, 25 May 2010)
New Revision: 36931
Changeset: http://dev.haiku-os.org/changeset/36931/haiku

Added:
   haiku/branches/features/stack-and-tile/src/servers/app/Stacking.cpp
Modified:
   haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp
   haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.h
Log:
Work in progress: move stacking part into a seperate class.



Modified: 
haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp
===================================================================
--- haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp     
2010-05-24 22:27:55 UTC (rev 36930)
+++ haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp     
2010-05-25 06:22:39 UTC (rev 36931)
@@ -74,7 +74,7 @@
                        SATWindow* satWindow = 
GetSATWindow(fDesktop->FocusWindow());
                        if (!satWindow)
                                return;
-                       BList* stackedWindows = satWindow->StackedWindows();
+                       BList* stackedWindows = 
satWindow->GetStacking()->StackedWindows();
                        if (key == 0x61 && stackedWindows) {
                                int32 oldIndex =
                                        
stackedWindows->IndexOf(fDesktop->FocusWindow());
@@ -245,15 +245,8 @@
        fBottom2BottomSnappingWindowIds(NULL),
        fBottom2TopSnappingWindowIds(NULL),
 
-       fWindowUnder(NULL),
-       fStackedWindows(NULL),
-       fPrevStackedWindows(NULL),
-       fLeftStackingConstraint(NULL),
-       fTopStackingConstraint(NULL),
-       fRightStackingConstraint(NULL),
-       fBottomStackingConstraint(NULL),
        fId(0),
-       fStackedWindowIds(NULL)
+       fStacking(sat, this)
 {
 
 }
@@ -261,19 +254,6 @@
 
 SATWindow::~SATWindow()
 {
-       // if the window still has stackedWindowIds but is not stacked anymore,
-       // clean up the stackedWindowIds (they are not used by other windows
-       // anymore)
-       if (fStackedWindowIds
-               && (!fStackedWindows  || fStackedWindows->CountItems()==1)) {
-               for (int i = 0; i < fStackedWindowIds->CountItems(); i++) {
-                       int32* id = 
static_cast<int32*>(fStackedWindowIds->ItemAt(i));
-                       free(id);
-               }
-               delete fStackedWindowIds;
-               fStackedWindowIds = NULL;
-       }
-
        // clean up the entries in the snapping lists for each combo of
        // snapping orientations
        _FreeUpSnappingList(SNAP_LEFT, SNAP_LEFT, false);
@@ -286,7 +266,9 @@
        _FreeUpSnappingList(SNAP_BOTTOM, SNAP_BOTTOM, false);
 
        // clean up all other stacking and snapping
-       _RemoveStackingAndSnapping();
+       _RemoveSAT();
+       _RemoveSnapping();
+
        FinishStackingAndSnapping();
 
 }
@@ -297,11 +279,13 @@
 {
        // Re-stack and re-snap the window if in stacking & snapping mode
        if (fStackAndTile->IsStackingAndSnapping()) {
-               _RemoveStackingAndSnapping();
-               _RemoveStackingPersistently();
+               _RemoveSAT();
+
+               _RemoveSnapping();
                _RemoveSnappingPersistently();
-               _CheckIfReadyToStack();
                _CheckIfReadyToSnap();
+               
+               fStacking.MouseDown();
        }
 }
 
@@ -311,14 +295,15 @@
 {
        // Snap or stack the window if in stack & tiling mode
        if (fStackAndTile->IsStackingAndSnapping()) {
-               _RemoveStackingAndSnapping();
-               _RemoveStackingPersistently();
+               _RemoveSAT();
+               _RemoveSnapping();
                _RemoveSnappingPersistently();
-               _CheckIfReadyToStack();
                _CheckIfReadyToSnap();
-               _StackWindow();
                _SnapWindow();
-               _StackAndTile();
+               
+               fStacking.MouseUp();
+
+               StackAndTile();
                FinishStackingAndSnapping();
 
                //Activate this window so that others stacked/tiled along with 
it
@@ -336,13 +321,14 @@
        // Otherwise, dragging means the stack & tile constraints are
        // solved and windows adjusted accordingly.
        if (fStackAndTile->IsStackingAndSnapping()) {
-               _RemoveStackingAndSnapping();
-               _RemoveStackingPersistently();
+               _RemoveSAT();
+               _RemoveSnapping();
                _RemoveSnappingPersistently();
-               _CheckIfReadyToStack();
                _CheckIfReadyToSnap();
+               
+               fStacking.MoveWindow();
        } else
-               _StackAndTile();
+               StackAndTile();
 }
 
 
@@ -354,12 +340,15 @@
        // Otherwise, resizing means the stack & tile constraints are
        // solved and windows adjusted accordingly.
        if (fStackAndTile->IsStackingAndSnapping()) {
-               _RemoveStackingAndSnapping();
-               _RemoveStackingPersistently();
+               _RemoveSAT();
+
+               _RemoveSnapping();
                _RemoveSnappingPersistently();
                _CheckIfReadyToSnap();
+               
+               fStacking.ResizeWindow();
        } else
-               _StackAndTile();
+               StackAndTile();
 }
 
 
@@ -386,23 +375,14 @@
        _AddWindowsByIdsToList(Bottom2BottomSnappingWindowIds(),
                stackedAndTiledWindows);
 
-       // And then prepare to move stacked windows to the front
-       BList* stackedWindows = StackedWindows();
-       if (stackedWindows) {
-               for (int i = 0; i < stackedWindows->CountItems(); i++) {
-                       Window* stackedWindow = 
static_cast<Window*>(stackedWindows->ItemAt(i));
-                       if (stackedWindow != window
-                               && 
!stackedAndTiledWindows.HasItem(stackedWindow))
-                               stackedAndTiledWindows.AddItem(stackedWindow);
-               }
-       }
-
        // Do the actual moving here
        for (int i = 0; i < stackedAndTiledWindows.CountItems(); i ++) {
                Window* win = stackedAndTiledWindows.ItemAt(i);
                fWindow->Desktop()->CurrentWindows().RemoveWindow(win);
                bringToTopList.AddWindow(win);
        }
+       
+       fStacking.ActivateWindow(window, bringToTopList);
 }
 
 
@@ -418,96 +398,8 @@
 
        STRACE_SAT(("\twindow id = %x\n", windowId));
 
-       // find id's of stacked windows and do the stacking
-       type_code typeFound;
-       int32 countFound;
-       settings.GetInfo("window id", &typeFound, &countFound);
-       settings.GetInfo("stacked windows", &typeFound, &countFound);
+       fStacking.SetSettings(settings);
 
-       // if stacked window ids are found, then use them to stack this window
-       if (typeFound == B_INT32_TYPE && countFound > 0) {
-               Window* windowToStackUnder = NULL;
-
-               // This list contains all window id's that are supposed to be
-               // stacked with current window but aren't open
-               BList* persistentIdsToAdd = new BList();
-
-               for (int i = 0; i < countFound; i++) {
-                       int32 id;
-                       settings.FindInt32("stacked windows", i, &id);
-
-                       bool persist = true;
-
-                       // find a window (W) from the stack with an id from the 
list.
-                       // if it is not this window itself, then stack it with 
this window
-                       // UNLESS the W's stacking list doesn't contain this 
window,
-                       // which implies W's been unstacked while this window 
was hidden
-                       SATWindow* window = _FindWindow(id);
-                       if (window && window != this && 
window->StackedWindowIds()) {
-                               bool idExists = false;
-                               for (int j = 0; !idExists && j < 
window->StackedWindowIds()
-                                                       ->CountItems(); j++) {
-                                       int32* stackedId =
-                                               
static_cast<int32*>(window->StackedWindowIds()
-                                                       ->ItemAt(j));
-                                       idExists = windowId == *stackedId;
-                               }
-                               if (idExists) {
-                                       if (!windowToStackUnder) {
-                                               //note this will execute only 
once during loop
-                                               windowToStackUnder = 
window->GetWindow();
-                                       }
-                               }
-                               else {
-                                       persist = false;
-                               }
-                       }
-
-                       if (persist) {
-                               int32* idRef = 
static_cast<int32*>(malloc(sizeof(int32)));
-                               *idRef = id;
-                               persistentIdsToAdd->AddItem(idRef);
-                       }
-               }
-
-               if (windowToStackUnder) {
-                       StackWindowBefore(windowToStackUnder);
-                       SATWindow* windowToStackUnderSAT
-                               = 
fStackAndTile->GetSATWindow(windowToStackUnder);
-                       if (windowToStackUnderSAT)
-                               windowToStackUnderSAT->_StackAndTile();
-               }
-               else
-                       InitStackedWindowIds();
-
-               #ifdef DEBUG_STACK_AND_TILE
-               for (int i = 0; i < StackedWindowIds()->CountItems(); i++) {
-                       int32* stackedId =
-                               
static_cast<int32*>(StackedWindowIds()->ItemAt(i));
-                       STRACE_SAT(("\tstackedWindowIds[%d]=%x\n", i, 
*stackedId));
-               }
-               #endif
-
-               // Add the remaining window id's to the persistent stacking list
-               // These are the ones that belong to currently unopened windows
-               for (int i = 0; i < persistentIdsToAdd->CountItems(); i++) {
-                       int32* idRef =
-                               
static_cast<int32*>(persistentIdsToAdd->ItemAt(i));
-                       bool idExists = false;
-                       for (int j = 0; !idExists &&
-                                       j < StackedWindowIds()->CountItems(); 
j++) {
-                               int32* stackedId =
-                                       
static_cast<int32*>(StackedWindowIds()->ItemAt(j));
-                               idExists = *idRef == *stackedId;
-                       }
-                       if (!idExists) {
-                               STRACE_SAT(("\t** window %x isn't open - but 
stacked\n",
-                                               *idRef));
-                               StackedWindowIds()->AddItem(idRef);
-                       }
-               }
-       }
-
        _SnapWindowFromSettings("snap left2left", SNAP_LEFT, SNAP_LEFT,
                &settings);
        _SnapWindowFromSettings("snap left2right", SNAP_LEFT, SNAP_RIGHT,
@@ -524,7 +416,7 @@
        _SnapWindowFromSettings("snap bottom2bottom", SNAP_BOTTOM, SNAP_BOTTOM,
                &settings);
 
-       _StackAndTile();
+       StackAndTile();
 
        STRACE_SAT(("Finished DefaultDecorator::SetSettings() on %s\n",
                fWindow->Title()));
@@ -546,7 +438,7 @@
                        int32 id;
                        settings->FindInt32(label, i, &id);
 
-                       SATWindow* window = _FindWindow(id);
+                       SATWindow* window = FindWindow(id);
                        if (window == this) {
                                continue;
                        }
@@ -597,34 +489,31 @@
        if (settings->AddInt32("window id", fId) != B_OK)
                return false;
 
-       // store id's of stacked windows
-       if (!_StoreIntsInSettings("stacked windows", StackedWindowIds(),
-                       settings))
-               return false;
+       fStacking.GetSettings(settings);
 
        // store id's of snapped windows
-       if (!_StoreIntsInSettings("snap left2left", 
Left2LeftSnappingWindowIds(),
+       if (!StoreIntsInSettings("snap left2left", Left2LeftSnappingWindowIds(),
                settings))
                return false;
-       if (!_StoreIntsInSettings("snap left2right", 
Left2RightSnappingWindowIds(),
+       if (!StoreIntsInSettings("snap left2right", 
Left2RightSnappingWindowIds(),
                settings))
                return false;
-       if (!_StoreIntsInSettings("snap right2right",
+       if (!StoreIntsInSettings("snap right2right",
                Right2RightSnappingWindowIds(), settings))
                return false;
-       if (!_StoreIntsInSettings("snap right2left", 
Right2LeftSnappingWindowIds(),
+       if (!StoreIntsInSettings("snap right2left", 
Right2LeftSnappingWindowIds(),
                settings))
                return false;
-       if (!_StoreIntsInSettings("snap top2top", Top2TopSnappingWindowIds(),
+       if (!StoreIntsInSettings("snap top2top", Top2TopSnappingWindowIds(),
                settings))
                return false;
-       if (!_StoreIntsInSettings("snap top2bottom", 
Top2BottomSnappingWindowIds(),
+       if (!StoreIntsInSettings("snap top2bottom", 
Top2BottomSnappingWindowIds(),
                settings))
                return false;
-       if (!_StoreIntsInSettings("snap bottom2top", 
Bottom2TopSnappingWindowIds(),
+       if (!StoreIntsInSettings("snap bottom2top", 
Bottom2TopSnappingWindowIds(),
                settings))
                return false;
-       if (!_StoreIntsInSettings("snap bottom2bottom",
+       if (!StoreIntsInSettings("snap bottom2bottom",
                Bottom2BottomSnappingWindowIds(), settings))
                return false;
 
@@ -635,8 +524,8 @@
 
 
 bool
-SATWindow::_StoreIntsInSettings(const char* label,
-       BList* ids, BMessage* settings) const
+SATWindow::StoreIntsInSettings(const char* label, BList* ids,
+       BMessage* settings)
 {
        if (ids) {
                for (int i = 0; i < ids->CountItems(); i++) {
@@ -702,23 +591,15 @@
 }
 
 
-void
-SATWindow::InitStackedWindowIds()
-{
-       if (!fStackedWindowIds)
-               fStackedWindowIds = new BList();
-}
-
-
 /*!    \brief Initializes all the Stack & Tile specific data for this window.
                Unless this initialization is done, the methods for stacking and
                snapping will not work. If the window is already initialized, 
the
                method returns immediately.
 */
 void
-SATWindow::_InitStackingAndSnapping()
+SATWindow::InitStackingAndSnapping()
 {
-       STRACE_SAT(("Window::_InitStackingAndSnapping() on %s, fLeftVar=%d\n",
+       STRACE_SAT(("Window::InitStackingAndSnapping() on %s, fLeftVar=%d\n",
                fWindow->Title(), fLeftVar));
 
        // if there are variables for the sides, then it is already initialized
@@ -787,9 +668,22 @@
        label << ".fHeightConstraint";
        fHeightConstraint->SetLabel(label.String());
 
+       _InitSnapping();
+
+       STRACE_SAT(("Finished Window::InitStackingAndSnapping() on %s\n",
+               fWindow->Title()));
+}
+
+
+void
+SATWindow::_InitSnapping()
+{
+       STRACE_SAT(("Window::_InitSnapping() on %s, fLeftVar=%d\n",
+               fWindow->Title(), fLeftVar));
+
        fSnappingConstraints = new BList();
 
-       STRACE_SAT(("Finished Window::_InitStackingAndSnapping() on %s\n",
+       STRACE_SAT(("Finished Window::_InitSnapping() on %s\n",
                fWindow->Title()));
 }
 
@@ -800,9 +694,9 @@
                snapping of a window can be set up from scratch.
 */
 void
-SATWindow::_RemoveStackingAndSnapping()
+SATWindow::_RemoveSAT()
 {
-       STRACE_SAT(("Window::_RemoveStackingAndSnapping() on %s, fLeftVar=%d\n",
+       STRACE_SAT(("Window::_RemoveSAT() on %s, fLeftVar=%d\n",
                fWindow->Title(), fLeftVar));
 
        // if there are no variables for the sides, then it is not active
@@ -822,72 +716,6 @@
        fWidthConstraint = NULL;
        fHeightConstraint = NULL;
 
-       // remove stacking specific data
-       fPrevStackedWindows = fStackedWindows;
-       if (fStackedWindows) {
-               // remove constraints
-               delete fLeftStackingConstraint;
-               delete fTopStackingConstraint;
-               delete fRightStackingConstraint;
-               delete fBottomStackingConstraint;
-               fLeftStackingConstraint = NULL;
-               fTopStackingConstraint  = NULL;
-               fRightStackingConstraint = NULL;
-               fBottomStackingConstraint = NULL;
-
-               // if this is the first window in the stack, then the stacking
-               // constraints have to be changed to refer to the new first 
window
-               if (fWindow == fStackedWindows->FirstItem()) {
-                       Window* newFirstWindow = static_cast<Window*>(
-                               fStackedWindows->ItemAt(1));
-                       SATWindow* newFirstWindowSAT = 
fStackAndTile->GetSATWindow(
-                               newFirstWindow);
-                       if (newFirstWindowSAT) {
-                               // the first window does not need stacking 
constraints
-                               delete 
newFirstWindowSAT->fLeftStackingConstraint;
-                               delete 
newFirstWindowSAT->fTopStackingConstraint;
-                               delete 
newFirstWindowSAT->fRightStackingConstraint;
-                               delete 
newFirstWindowSAT->fBottomStackingConstraint;
-                               newFirstWindowSAT->fLeftStackingConstraint = 
NULL;
-                               newFirstWindowSAT->fTopStackingConstraint = 
NULL;
-                               newFirstWindowSAT->fRightStackingConstraint = 
NULL;
-                               newFirstWindowSAT->fBottomStackingConstraint = 
NULL;
-
-                               // the following windows need stacking 
constraints referring to
-                               // the first window
-                               for (int i = 2; i < 
fStackedWindows->CountItems(); i++) {
-                                       Window* window = static_cast<Window*>(
-                                               fStackedWindows->ItemAt(i));
-                                       SATWindow* windowSAT = 
fStackAndTile->GetSATWindow(
-                                               window);
-                                       if (!windowSAT)
-                                               continue;
-                                       
-                                       
windowSAT->fLeftStackingConstraint->SetLeftSide(1,
-                                               windowSAT->fLeftVar, -1, 
newFirstWindowSAT->fLeftVar);
-                                       
windowSAT->fTopStackingConstraint->SetLeftSide(1,
-                                               windowSAT->fTopVar, -1, 
newFirstWindowSAT->fTopVar);
-                                       
windowSAT->fRightStackingConstraint->SetLeftSide(1,
-                                               windowSAT->fRightVar, -1, 
newFirstWindowSAT->fRightVar);
-                                       
windowSAT->fBottomStackingConstraint->SetLeftSide(1,
-                                               windowSAT->fBottomVar, -1,
-                                               newFirstWindowSAT->fBottomVar);
-                               }
-                       }
-               }
-
-               // remove this window from the stack
-               fStackedWindows->RemoveItem(fWindow);
-               fStackedWindows = NULL;
-       }
-
-       // remove snapping specific data
-       if (fSnappingConstraints) {
-               for (int i = 0; i < fSnappingConstraints->CountItems(); i++)
-                       delete 
static_cast<Constraint*>(fSnappingConstraints->ItemAt(i));
-               fSnappingConstraints = NULL;
-       }
-
        // deleting variables also invalidates their constraints
        // therefore we can delete them afterwards without harm
        delete fLeftVar;
@@ -899,6 +727,25 @@
        fRightVar = NULL;
        fBottomVar = NULL;
 
+       STRACE_SAT(("Finished Window::_RemoveSAT() on %s\n",
+               fWindow->Title()));
+}
+
+
+void
+SATWindow::_RemoveSnapping()
+{
+       STRACE_SAT(("Window::_RemoveSnapping() on %s, fLeftVar=%d\n",
+               fWindow->Title(), fLeftVar));
+
+       // if there are no variables for the sides, then it is not active
+       if (!fSnappingConstraints)
+               return;
+
+       for (int i = 0; i < fSnappingConstraints->CountItems(); i++)
+               delete 
static_cast<Constraint*>(fSnappingConstraints->ItemAt(i));
+       fSnappingConstraints = NULL;
+
        // For each previously snapped window, make sure that it is within
        // screen bounds, so as to prevent it from being lost off-screen
        _EnsureAndSAT(fLeft2LeftSnappingWindowIds);
@@ -923,230 +770,15 @@
 
        for (int i = 0; i < idList->CountItems(); i++) {
                int32* id = static_cast<int32*>(idList->ItemAt(i));
-               SATWindow* winSAT = _FindWindow(*id);
+               SATWindow* winSAT = FindWindow(*id);
                if (winSAT) {
                        _EnsureWindowWithinScreenBounds(winSAT, this);
-                       winSAT->_StackAndTile();
+                       winSAT->StackAndTile();
                }
        }
 }
 
 
-/*!    \brief Looks for a suitable stacking candidate by checking which window
-               tabs overlap with this window's tab, and gives visual feedback 
by
-               adjusting window tab highlights. This method is called during 
the
-               Stack & Tile configuration mode.
-*/
-void
-SATWindow::_CheckIfReadyToStack()
-{
-       // stacking only works if this window has a tab
-       if (!fWindow->Decorator())
-               return;
-
-       SATWindow* prevWindowUnder = fWindowUnder;
-       fWindowUnder = NULL;
-
-       // search for stacking candidate
-       BRect thisTabRect(fWindow->Decorator()->TabRect().left,
-               fWindow->Decorator()->TabRect().top,
-               fWindow->Decorator()->TabRect().right + 1,
-               fWindow->Decorator()->TabRect().bottom);
-       for (Window* window = fWindow->Desktop()->CurrentWindows().LastWindow();
-               window;
-               window = window->PreviousWindow(fWindow->CurrentWorkspace())) {
-               if (window != fWindow && !window->IsHidden() && 
window->Decorator()
-                       && 
thisTabRect.Intersects(window->Decorator()->TabRect())) {
-                       // remember window as the candidate for stacking
-                       fWindowUnder = fStackAndTile->GetSATWindow(window);
-                       break;
-               }
-       }
-
-       // if the stacking candidate has changed, change tab highlights
-       if(prevWindowUnder != fWindowUnder) {
-               if(!prevWindowUnder) { // candidate found for the first time
-                       fWindow->Desktop()->HighlightTab(fWindow, true);
-                       fWindow->Desktop()->HighlightTab(fWindowUnder->fWindow, 
true);
-               } else if(!fWindowUnder) { // no candidate after there was one
-                       fWindow->Desktop()->HighlightTab(fWindow, false);
-                       
fWindow->Desktop()->HighlightTab(prevWindowUnder->fWindow, false);
-               } else { // changing from one to another candidate
-                       
fWindow->Desktop()->HighlightTab(prevWindowUnder->fWindow, false);
-                       fWindow->Desktop()->HighlightTab(fWindowUnder->fWindow, 
true);
-               }
-       }
-}
-
-
-/*!    \brief Stacks this window to the current candidate window for stacking
-               and adjusts the window tabs of the stack. Afterwards the 
stacking
-               candidate is cleared.
-*/
-void
-SATWindow::_StackWindow()
-{
-       STRACE_SAT(("Window::_StackWindow() on %s, fWindowUnder=%x\n",
-               fWindow->Title(), fWindowUnder));
-
-       // stack only if there is a candidate window for stacking
-       if (fWindowUnder == NULL)
-               return;
-
-       // align this window with the stack
-       fWindow->Desktop()->MoveWindowBy(fWindow,
-               fWindowUnder->GetWindow()->Frame().left - fWindow->Frame().left,
-               fWindowUnder->GetWindow()->Frame().top - fWindow->Frame().top);
-       fWindow->Desktop()->ResizeWindowBy(fWindow,
-               fWindowUnder->GetWindow()->Frame().right - 
fWindow->Frame().right,
-               fWindowUnder->GetWindow()->Frame().bottom - 
fWindow->Frame().bottom);
-
-       // make sure there is a stacked window list
-       BList* stack = fWindowUnder->fStackedWindows;
-       if (!stack) {
-               stack = new BList();
-               stack->AddItem(fWindowUnder->GetWindow());
-               fWindowUnder->fStackedWindows = stack;
-       }
-
-       // make sure there is a stacked window id list
-       BList* stackIds = fWindowUnder->fStackedWindowIds;
-       if (!stackIds) {
-               stackIds = new BList();
-               int32* id = static_cast<int32*>(malloc(sizeof(int32)));
-               *id = fWindowUnder->WindowId();
-               stackIds->AddItem(id);
-               fWindowUnder->fStackedWindowIds = stackIds;
-       }
-
-       // add this window's id to the stacked window id list - ONLY
-       // if not already contained
-       bool idExists = false;
-       for (int i = 0; !idExists && i < stackIds->CountItems(); i++) {
-               int32* stackedId = static_cast<int32*>(stackIds->ItemAt(i));
-               idExists = *stackedId == WindowId();
-       }
-       if (!idExists) {
-               int32* id = static_cast<int32*>(malloc(sizeof(int32)));
-               *id = WindowId();
-               stackIds->AddItem(id);
-       }
-       fStackedWindowIds = stackIds;
-
-       // add this window to the stack before the windowUnder,
-       // rearrange the window tabs and initialize constraints
-       stack->AddItem(fWindow, stack->IndexOf(fWindowUnder->GetWindow()));
-       fStackedWindows = stack;
-       _ArrangeStackedWindowTabs();
-       _InitStackingAndSnapping();
-
-       // set up stacking constraints
-       Window* firstWindow = static_cast<Window*>(stack->FirstItem());
-       SATWindow* firstWindowSAT = NULL;
-       if (fWindow != firstWindow)
-               firstWindowSAT = fStackAndTile->GetSATWindow(firstWindow);
-       if (firstWindowSAT){
-               // if this is not the first window, then add stacking 
constraints
-               // referring to the first window in the stack
-               firstWindowSAT->_InitStackingAndSnapping();
-               fLeftStackingConstraint = 
fLeftVar->IsEqual(firstWindowSAT->fLeftVar);
-               fTopStackingConstraint = 
fTopVar->IsEqual(firstWindowSAT->fTopVar);
-               fRightStackingConstraint = fRightVar->IsEqual(
-                       firstWindowSAT->fRightVar);
-               fBottomStackingConstraint = fBottomVar->IsEqual(
-                       firstWindowSAT->fBottomVar);
-               BString label("stacking of ");
-               label << fWindow->Title();
-               fLeftStackingConstraint->SetLabel(label.String());
-               fTopStackingConstraint->SetLabel(label.String());
-               fRightStackingConstraint->SetLabel(label.String());
-               fBottomStackingConstraint->SetLabel(label.String());
-       } else {
-               // if this is the first window in the stack, then the stacking
-               // constraints of the following windows have to be changed to 
refer
-               // to this window
-               for (int i = 1; i < fStackedWindows->CountItems(); i++) {
-                       Window* window = static_cast<Window*>(
-                               fStackedWindows->ItemAt(i));
-                       SATWindow* satWindow = 
fStackAndTile->GetSATWindow(window);
-                       // is in stack list so we don't need to check if valid
-                       satWindow->_InitStackingAndSnapping();
-
-                       // either create new stacking constraints
-                       // or just change the existing ones
-                       if (!satWindow->fLeftStackingConstraint) {
-                               satWindow->fLeftStackingConstraint =
-                                       satWindow->fLeftVar->IsEqual(fLeftVar);
-                               satWindow->fTopStackingConstraint =
-                                       satWindow->fTopVar->IsEqual(fTopVar);
-                               satWindow->fRightStackingConstraint =
-                                       
satWindow->fRightVar->IsEqual(fRightVar);
-                               satWindow->fBottomStackingConstraint =
-                                       
satWindow->fBottomVar->IsEqual(fBottomVar);
-                               BString label("stacking of ");
-                               label << fWindow->Title();
-                               
satWindow->fLeftStackingConstraint->SetLabel(label.String());
-                               
satWindow->fTopStackingConstraint->SetLabel(label.String());
-                               
satWindow->fRightStackingConstraint->SetLabel(label.String());
-                               
satWindow->fBottomStackingConstraint->SetLabel(label.String());
-                       } else {
-                               satWindow->fLeftStackingConstraint->SetLeftSide(
-                                       1, satWindow->fLeftVar, -1, fLeftVar);
-                               satWindow->fTopStackingConstraint->SetLeftSide(
-                                       1, satWindow->fTopVar, -1, fTopVar);
-                               
satWindow->fRightStackingConstraint->SetLeftSide(
-                                       1, satWindow->fRightVar, -1, fRightVar);
-                               
satWindow->fBottomStackingConstraint->SetLeftSide(
-                                       1, satWindow->fBottomVar, -1, 
fBottomVar);
-                       }
-               }
-       }
-
-       // clear stacking candidate
-       fWindowUnder = NULL;
-
-       STRACE_SAT(("Finished Window::_StackWindow() on %s\n", 
fWindow->Title()));
-}
-
-
-/*!    \brief Stacks this window onto the stack of the given window so that the
-               tab of this window is before the tab of the given window.
-
-       \param window the window with the stack where this window will be added.
-*/
-void
-SATWindow::StackWindowBefore(Window* window)
-{
-       fWindowUnder = fStackAndTile->GetSATWindow(window);
-       _StackWindow();
-}
-
-
-/*!    \brief Arranges the tab locations of the windows that are in the stack 
of
-               this window.
-*/
-void
-SATWindow::_ArrangeStackedWindowTabs()
-{
-       STRACE_SAT(("Window::_ArrangeStackedWindowTabs() on %s, 
fStackedWindows=%x\n",
-               fWindow->Title(), fStackedWindows));
-       if (!fStackedWindows)
-               return;
-
-       // adjust tab locations of stacked windows
-       float location = 0;
-       for (int i = 0; i < fStackedWindows->CountItems(); i++) {
-               Window* window = 
static_cast<Window*>(fStackedWindows->ItemAt(i));
-               fWindow->Desktop()->SetWindowTabLocation(window, location);
-               STRACE_SAT(("\t%s.tabLocation = %f\n", window->Title(), 
location));
-               location = window->TabLocation()
-                       + window->Decorator()->TabRect().Width() + 1;
-       }
-       STRACE_SAT(("Finished Window::_ArrangeStackedWindowTabs() on %s\n",
-               fWindow->Title()));
-}
-
-
 /*!    \brief Compiles suitable snapping candidates by checking which windows
                are adjacent to this window, and gives visual feedback by 
adjusting
                window border highlights. This method is called during the 
Stack & Tile
@@ -1177,13 +809,14 @@
        // go through all windows and look for snapping candidates
        for (Window* window = fWindow->Desktop()->CurrentWindows().LastWindow();
                window; window = 
window->PreviousWindow(fWindow->CurrentWorkspace())) {
-               Window* windowUnder = fWindowUnder != NULL ? 
fWindowUnder->fWindow : NULL;
+               Window* windowUnder = fStacking.GetWindowUnder() != NULL
+                       ? fStacking.GetWindowUnder()->fWindow : NULL;
                if (!window->IsHidden()
                        && fWindow != window    // don't snap window to itself
                        && window != windowUnder
                                // don't snap with stacking candidate
-                       && !(strcmp(window->Title(), "Deskbar")==0)
-                       && !(strcmp(window->Title(), "Desktop")==0)) {
+                       && !(strcmp(window->Title(), "Deskbar") == 0)
+                       && !(strcmp(window->Title(), "Desktop") == 0)) {
 
                        // is window adjacent on the left of this window?
                        BRect thisLeft(fWindow->Frame().left - 12,
@@ -1299,9 +932,9 @@
                // adjust window position & initialize snapping
                fWindow->Desktop()->MoveWindowBy(fWindow,
                        bounds.right - fWindow->Frame().left + 11, 0);
-               _InitStackingAndSnapping();
-               topmostWindow->_InitStackingAndSnapping();
-               bottommostWindow->_InitStackingAndSnapping();
+               InitStackingAndSnapping();
+               topmostWindow->InitStackingAndSnapping();
+               bottommostWindow->InitStackingAndSnapping();
 
                // adjust top border
                if (fTopAdjacentWindows->IsEmpty()) {
@@ -1349,7 +982,7 @@
                for (int i = 0; i < fLeftAdjacentWindows->CountItems(); i++) {
                        SATWindow* window = fStackAndTile->GetSATWindow(
                                
static_cast<Window*>(fLeftAdjacentWindows->ItemAt(i)));
-                       window->_InitStackingAndSnapping();
+                       window->InitStackingAndSnapping();
                        Constraint* leftSnapping =
                                
fStackAndTile->GetLinearSpec()->AddConstraint(-1,
                                        window->fRightVar, 1, fLeftVar, 
OperatorType(EQ), 11);
@@ -1375,9 +1008,9 @@
                // adjust window position & initialize snapping
                fWindow->Desktop()->MoveWindowBy(fWindow, 0,
                        bounds.bottom - fWindow->Frame().top + 32);
-               _InitStackingAndSnapping();
-               leftmostWindow->_InitStackingAndSnapping();
-               rightmostWindow->_InitStackingAndSnapping();
+               InitStackingAndSnapping();
+               leftmostWindow->InitStackingAndSnapping();
+               rightmostWindow->InitStackingAndSnapping();
 
                // adjust left border
                if (fLeftAdjacentWindows->IsEmpty()) {
@@ -1425,7 +1058,7 @@
                for (int i = 0; i < fTopAdjacentWindows->CountItems(); i++) {
                        SATWindow* window = fStackAndTile->GetSATWindow(
                                
static_cast<Window*>(fTopAdjacentWindows->ItemAt(i)));
-                       window->_InitStackingAndSnapping();
+                       window->InitStackingAndSnapping();
                        Constraint* topSnapping =
                                
fStackAndTile->GetLinearSpec()->AddConstraint(-1,
                                        window->fBottomVar, 1, fTopVar, 
OperatorType(EQ), 32);
@@ -1452,9 +1085,9 @@
                // adjust window position & initialize snapping
                fWindow->Desktop()->MoveWindowBy(fWindow,
                        bounds.left - fWindow->Frame().right - 11, 0);
-               _InitStackingAndSnapping();
-               topmostWindow->_InitStackingAndSnapping();
-               bottommostWindow->_InitStackingAndSnapping();
+               InitStackingAndSnapping();
+               topmostWindow->InitStackingAndSnapping();
+               bottommostWindow->InitStackingAndSnapping();
 
                // adjust top border
                if (fTopAdjacentWindows->IsEmpty()) {
@@ -1501,7 +1134,7 @@
                for (int i = 0; i < fRightAdjacentWindows->CountItems(); i++) {
                        SATWindow* window = fStackAndTile->GetSATWindow(
                                
static_cast<Window*>(fRightAdjacentWindows->ItemAt(i)));
-                       window->_InitStackingAndSnapping();
+                       window->InitStackingAndSnapping();
                        Constraint* rightSnapping =
                                
fStackAndTile->GetLinearSpec()->AddConstraint(-1, fRightVar, 1,
                                        window->fLeftVar, OperatorType(EQ), 11);
@@ -1527,9 +1160,9 @@
                // adjust window position & initialize snapping
                fWindow->Desktop()->MoveWindowBy(fWindow, 0,
                        bounds.top - fWindow->Frame().bottom - 32);
-               _InitStackingAndSnapping();
-               leftmostWindow->_InitStackingAndSnapping();
-               rightmostWindow->_InitStackingAndSnapping();
+               InitStackingAndSnapping();
+               leftmostWindow->InitStackingAndSnapping();
+               rightmostWindow->InitStackingAndSnapping();
 
                // adjust left border
                if (fLeftAdjacentWindows->IsEmpty()) {
@@ -1577,7 +1210,7 @@
                for (int i = 0; i < fBottomAdjacentWindows->CountItems(); i++) {
                        SATWindow* window = fStackAndTile->GetSATWindow(
                                
static_cast<Window*>(fBottomAdjacentWindows->ItemAt(i)));
-                       window->_InitStackingAndSnapping();
+                       window->InitStackingAndSnapping();
                        Constraint* bottomSnapping =
                                
fStackAndTile->GetLinearSpec()->AddConstraint(-1, fBottomVar, 1,
                                        window->fTopVar, OperatorType(EQ), 32);
@@ -1786,8 +1419,8 @@
        BRect thisFrame = fWindow->Frame();
        BRect otherFrame = otherWindow->Frame();
 
-       _InitStackingAndSnapping();
-       otherWindow->_InitStackingAndSnapping();
+       InitStackingAndSnapping();
+       otherWindow->InitStackingAndSnapping();
 
        // For each possible pair of snapping orientations, work out the
        // necessary updates to make to the linear constraints
@@ -1946,9 +1579,6 @@
 void
 SATWindow::FinishStackingAndSnapping()
 {
-       // clear stacking candidate
-       fWindowUnder = NULL;
-
        // clear snapping candidates
        delete fLeftAdjacentWindows;
        delete fTopAdjacentWindows;
@@ -1958,28 +1588,8 @@
        fTopAdjacentWindows = NULL;
        fRightAdjacentWindows = NULL;
        fBottomAdjacentWindows = NULL;
-
-       // if the window was removed from a stack then rearrange tabs in the 
stack,
-       // remove the stack if it contains only one window
-       // and reset tab location of this window if it is not stacked again
-       if (fPrevStackedWindows) {
-               SATWindow* firstWindow = fStackAndTile->GetSATWindow(
-                       static_cast<Window*>(fPrevStackedWindows->FirstItem()));
-               firstWindow->_ArrangeStackedWindowTabs();
-
-               // remove stacks with only one window
-               if (fPrevStackedWindows->CountItems() == 1) {
-                       firstWindow->fStackedWindows = NULL;
-                       delete fPrevStackedWindows;
-               }
-
-               if (!fStackedWindows)
-                       fWindow->Desktop()->SetWindowTabLocation(fWindow, 0);
-               fPrevStackedWindows = NULL;
-       }
-
-       // if the window was added to a stack then rearrange tabs in that stack
-       _ArrangeStackedWindowTabs();
+       
+       fStacking.FinishStacking();
 }
 
 
@@ -1988,9 +1598,9 @@
                the windows that are stacked with this window.
 */
 void
-SATWindow::_StackAndTile()
+SATWindow::StackAndTile()
 {
-       STRACE_SAT(("Window::_StackAndTile() on %s, 
fWindow->Desktop()->fStackAndTileSpec=%x\n",
+       STRACE_SAT(("Window::StackAndTile() on %s, 
fWindow->Desktop()->fStackAndTileSpec=%x\n",
                fWindow->Title(), fStackAndTile->GetLinearSpec()));
 
        // works only if stack and tile is active for this window
@@ -2048,7 +1658,7 @@
        fTopConstraint->SetPenaltyNeg(1);
        fTopConstraint->SetPenaltyPos(1);
 
-       _ArrangeStackedWindowTabs();
+       fStacking.DoStacking();
 
        #if 0
        //#ifdef DEBUG_STACK_AND_TILE
@@ -2082,16 +1692,23 @@
        debug_printf("\n");
        delete specStr;
        #endif
-       STRACE_SAT(("Finished Window::_StackAndTile() on %s\n", 
fWindow->Title()));
+       STRACE_SAT(("Finished Window::StackAndTile() on %s\n", 
fWindow->Title()));
 }
 
 
+::Desktop*
+SATWindow::Desktop()
+{
+       return fWindow->Desktop();
+}
+
+
 void
 SATWindow::_BoundWindowByWorkspace()
 {
        BRect workspaceRect = 
fWindow->Desktop()->WorkspaceFrame(fWindow->Workspaces());
 
-       _InitStackingAndSnapping();
+       InitStackingAndSnapping();
        fLeftVar->SetRange(workspaceRect.left, workspaceRect.right);
        fTopVar->SetRange(workspaceRect.top, workspaceRect.bottom);
        fRightVar->SetRange(workspaceRect.left, workspaceRect.right);
@@ -2153,32 +1770,6 @@
 }
 
 
-/*!    \brief Removes the id of this window from the list of stacked window ids
-               if there is such a list for this window. The list is made 
persistent
-               through DefaultDecorator::GetSettings().
-*/
-void
-SATWindow::_RemoveStackingPersistently()
-{
-       STRACE_SAT(("Window::_RemoveStackingPersistently() on %s, 
fStackedWindowIds=%x\n",
-               fWindow->Title(), fStackedWindowIds));
-       if (!fStackedWindowIds)
-               return;
-
-       for (int i = 0; i < fStackedWindowIds->CountItems(); i++) {
-               int32* id = static_cast<int32*>(fStackedWindowIds->ItemAt(i));
-               if (*id == fId) {
-                       fStackedWindowIds->RemoveItem(i);
-                       free(id);
-               }
-       }
-
-       fStackedWindowIds = NULL;
-       STRACE_SAT(("Finished Window::_RemoveStackingPersistently() on %s\n",
-               fWindow->Title()));
-}
-
-
 /*!    \brief Removes information about snapped windows that would otherwise be
                made persistent through DefaultDecorator::GetSettings().
 */
@@ -2229,7 +1820,7 @@
        for (int i = 0; i < idList->CountItems(); i++) {
                int32* id = static_cast<int32*>(idList->ItemAt(i));
                if (deleteFromOtherWindowsList) {
-                       SATWindow* otherWindow = _FindWindow(*id);
+                       SATWindow* otherWindow = FindWindow(*id);
                        // Remove this window from the other window's snapping 
list.
                        // Note the order of orientation is reversed.
                        if (otherWindow)
@@ -2252,7 +1843,7 @@
        bool added = false;
        for (int i = 0; i < windowIdsToAdd->CountItems(); i++) {
                int32* id = static_cast<int32*>(windowIdsToAdd->ItemAt(i));
-               SATWindow* windowToAdd = _FindWindow(*id);
+               SATWindow* windowToAdd = FindWindow(*id);
                if (windowToAdd && !windows.HasItem(windowToAdd->GetWindow()))
                        windows.AddItem(windowToAdd->GetWindow());
        }
@@ -2261,7 +1852,7 @@
 
 
 SATWindow*
-SATWindow::_FindWindow(int32 windowId)
+SATWindow::FindWindow(int32 windowId)
 {
        for (Window* window = fWindow->Desktop()->CurrentWindows().LastWindow();
                window != NULL; window = window->PreviousWindow(

Modified: haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.h
===================================================================
--- haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.h       
2010-05-24 22:27:55 UTC (rev 36930)
+++ haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.h       
2010-05-25 06:22:39 UTC (rev 36931)
@@ -71,6 +71,57 @@
 };

[... truncated: 765 lines follow ...]

Other related posts:

  • » [haiku-commits] r36931 - haiku/branches/features/stack-and-tile/src/servers/app - clemens . zeidler