Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Docking Pane
  New Posts New Posts RSS Feed - Insuring one pane remains in pane container.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Insuring one pane remains in pane container.

 Post Reply Post Reply
Author
Message
mitcheljh View Drop Down
Groupie
Groupie


Joined: 20 July 2008
Location: United States
Status: Offline
Points: 35
Post Options Post Options   Thanks (0) Thanks(0)   Quote mitcheljh Quote  Post ReplyReply Direct Link To This Post Topic: Insuring one pane remains in pane container.
    Posted: 30 August 2008 at 8:35am

Hi,

I'm using a pane manager in my main childview, to house 2 main panes What I'd like to do now, is to insure one of the two main panes is always present in the main pane container, but it could be either one I'm guessing there's at least one way to do this in the XTP_DOCKINGPANE_ACTION event.

I may need to perform a few restrictions to achieve this goal...

1) Preventing floating of the pane container.

2) only allowing detaching of the panes.

3) not allowing detaching of a pane if the other pane is already floated.

I think I have a handle on #3 above, but am having problems with 1 and 2.

Thanks!

After a bit more work I was able to find a solution to my desired behavior.  I thought I'd share my solution in case others needed the same kind of behavior.  The solution includes creating a boolean class member to flag when one of the panes is just starting to be dragged.  I'm guessing there's other solutions to achieving this behavior, so this is just one that works for me.

LRESULT CChildView::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
{
  if (wParam == XTP_DPN_SHOWWINDOW) {
    CXTPDockingPane* pPane = (CXTPDockingPane*)(lParam);
    return onDockingPaneShowWindow(pPane);
  } else if (wParam == XTP_DPN_ACTION) {
    XTP_DOCKINGPANE_ACTION* pAction = (XTP_DOCKINGPANE_ACTION*)lParam;
    return onDockingPaneAction(pAction);
  }

  return 0;
}


bool CChildView::onDockingPaneAction(XTP_DOCKINGPANE_ACTION* pAction)
{
  if (pAction->action == xtpPaneActionDocking)
  {
    // limit docking to left and right
    if ((pAction->dockDirection != xtpPaneDockLeft && pAction->dockDirection != xtpPaneDockRight)
        || (pAction->pDockContainer->GetType() == xtpPaneTypeTabbedContainer)) {
      pAction->bCancel = true;
      return true;
    }
    paneFloatingStarted = false;
  } else if (pAction->action == xtpPaneActionDragging) {
    // check if other pane is already floated
    CXTPDockingPaneInfoList& list = paneManager.GetPaneList();
    POSITION pos = list.GetHeadPosition();
    for (int i = 0; i < list.GetCount(); ++i) {
      CXTPDockingPane* pPane = list.GetNext(pos);
      if (pPane->IsFloating()) {
        pAction->bCancel = true;  // other pane already floated.  Don't allow this one to float
      }
    }
  } else if (pAction->action == xtpPaneActionFloating) {
    if (paneFloatingStarted) {
      pAction->bCancel = true; // more than one pane trying to float.  Don't allow
    } else {
      paneFloatingStarted = true;   // flag this pane as currently being f
    }
    return true;
  } else if (pAction->action == xtpPaneActionFloated) {
   paneFloatingStarted = false;
   return true;
  } else if (pAction->action == xtpPaneActionDetaching) {
    paneFloatingStarted = false;
    return true;
  } else if (pAction->action == xtpPaneActionDocked) {
    paneFloatingStarted = false;
    return true;
  }

  return false;
}

Back to Top
kent_t View Drop Down
Groupie
Groupie


Joined: 15 July 2008
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote kent_t Quote  Post ReplyReply Direct Link To This Post Posted: 26 September 2008 at 1:47pm
I for one, would like to Thank You very much.

That code just saved me several hours of painful trial and error code searching and testing.

I made the decision to buy CodeJock without realizing there is not any meaningful documentation, (that I can find at least). So now I have to live with it. I feel like I'm using open source software that is supported by the community instead of a company.

Thanks again, I really appreciate it.

Back to Top
mitcheljh View Drop Down
Groupie
Groupie


Joined: 20 July 2008
Location: United States
Status: Offline
Points: 35
Post Options Post Options   Thanks (0) Thanks(0)   Quote mitcheljh Quote  Post ReplyReply Direct Link To This Post Posted: 26 September 2008 at 8:07pm
No problem Kent. Glad to hear someone besides myself needs the same kind of behavior. I've actually updated the code above to account for a couple of other things that should be considered, and to also remove the 'pin' when only one pane remains. (Last remaining pane shouldn't be able to be unpinned or closed).   The code is below. In the code, you'll notice I use two different panes, a tree pane and a calendar pane. Slight modifications will be needed for more than 2 panes.



enum { id_tree_pane, id_calendar_pane, id_both_panes };

LRESULT CChildView::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
{
if (wParam == XTP_DPN_SHOWWINDOW) {
    CXTPDockingPane* pPane = (CXTPDockingPane*)(lParam);
    return onDockingPaneShowWindow(pPane);
} else if (wParam == XTP_DPN_ACTION) {
    XTP_DOCKINGPANE_ACTION* pAction = (XTP_DOCKINGPANE_ACTION*)lParam;
    return onDockingPaneAction(pAction);
}

return 0;
}


bool CChildView::onDockingPaneAction(XTP_DOCKINGPANE_ACTION* pAction)
{
if (pAction->action == xtpPaneActionDocking)
{
    // limit docking to left and right
    if ((pAction->dockDirection != xtpPaneDockLeft && pAction->dockDirection != xtpPaneDockRight)
        || (pAction->pDockContainer->GetType() == xtpPaneTypeTabbedContainer)) {
      pAction->bCancel = true;
      return true;
    }
    paneFloatingStarted = false;
} else if (pAction->action == xtpPaneActionDragging) {
    // check if other pane is already floated
    CXTPDockingPaneInfoList& list = paneManager.GetPaneList();
    POSITION pos = list.GetHeadPosition();
    for (int i = 0; i < list.GetCount(); ++i) {
      CXTPDockingPane* pPane = list.GetNext(pos);
      if (pPane->IsFloating()) {
        pAction->bCancel = true; // other pane already floated. Don't allow this one to float
        return true;
      }
    }
} else if (pAction->action == xtpPaneActionFloating) {
    if (paneFloatingStarted) {
      pAction->bCancel = true; // more than one pane trying to float. Don't allow
      return true;
    } else if (!pAction->pPane->IsFloating()) {
      paneFloatingStarted = true;   // flag this pane as currently being floated
    }
} else if (pAction->action == xtpPaneActionFloated) {
    paneFloatingStarted = false;
} else if (pAction->action == xtpPaneActionDetaching) {
    paneFloatingStarted = false;
} else if (pAction->action == xtpPaneActionDocked) {
    // add pin
    makeHideable(id_both_panes, true);
    paneFloatingStarted = false;
    return XTP_ACTION_NOCLOSE;
} else if (pAction->action == xtpPaneActionAttaching) {
    // remove pin
    makeHideable(id_both_panes, false);
    paneFloatingStarted = false;
    return XTP_ACTION_NOCLOSE;
} else if (pAction->action == xtpPaneActionUnpinned) {
    makeHideable(pAction->pPane->GetID() == id_tree_pane ? id_calendar_pane : id_tree_pane, false);
} else if (pAction->action == xtpPaneActionPinned) {
    makeHideable(pAction->pPane->GetID() == id_tree_pane ? id_calendar_pane : id_tree_pane, true);
}

return false;
}

void CChildView::makeHideable(UINT id, bool hideable)
{
CXTPDockingPaneInfoList& list = paneManager.GetPaneList();
POSITION pos = list.GetHeadPosition();
for (int i = 0; i < list.GetCount(); ++i) {
    CXTPDockingPane* pPane = list.GetNext(pos);
    if (id == id_both_panes || pPane->GetID() == id) {
      pPane->SetOptions(hideable ? xtpPaneNoCloseable : xtpPaneNoCloseable|xtpPaneNoHideable);
    }
}
paneManager.RedrawPanes();
}
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.