home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / MRCE / SOURCE.ZIP / MDIFLOAT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-11  |  5.9 KB  |  183 lines

  1. // MRCEXT: Micro Focus Extension DLL for MFC 2.1+
  2. // Copyright (C)1994-5    Micro Focus Inc, 2465 East Bayshore Rd, Palo Alto, CA 94303.
  3. // 
  4. //  This program is free software; you can redistribute it and/or modify
  5. //  it under the terms of the GNU General Public License as published by
  6. //  the Free Software Foundation. In addition, you may also charge for any
  7. //  application    using MRCEXT, and are under no obligation to supply source
  8. //  code. You must accredit Micro Focus Inc in the "About Box", or banner
  9. //  of your application. 
  10. //
  11. //  This program is distributed in the hope that it will be useful,
  12. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. //  GNU General Public License for more details.
  15. //
  16. //  You should also have received a copy of the GNU General Public License with this
  17. //  software, also indicating additional rights you have when using MRCEXT.  
  18. //
  19. //
  20. // mdifloat.cpp : implementation file
  21. // $Revision:   1.2  $
  22. // $Date:   11 Sep 1995 09:48:52  $
  23. // $Author:   MRC  $
  24.  
  25. // This is the window used when floating a control bar in an MDI client (so it appears at
  26. // the same level as other documents in an application). Some work is still need to handle
  27. // saving state properly.
  28.  
  29.  
  30. #include "mrcstafx.h"
  31. #include "mrcpriv.h"
  32.  
  33. #ifdef _DEBUG
  34. #undef THIS_FILE
  35. static char BASED_CODE THIS_FILE[] = __FILE__;
  36. #endif
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMRCMDIFloatWnd
  40.  
  41. IMPLEMENT_DYNCREATE(CMRCMDIFloatWnd, CMDIFloat_Parent)
  42.  
  43. CMRCMDIFloatWnd::CMRCMDIFloatWnd() : m_wndMDIDockBar(TRUE)
  44. {
  45.     m_wndMDIDockBar.m_bAutoDelete = FALSE;
  46. }
  47.  
  48. CMRCMDIFloatWnd::~CMRCMDIFloatWnd()
  49. {
  50. }
  51.  
  52.  
  53. BEGIN_MESSAGE_MAP(CMRCMDIFloatWnd, CMDIFloat_Parent)
  54.     //{{AFX_MSG_MAP(CMRCMDIFloatWnd)
  55.     ON_WM_SIZE()
  56.     ON_WM_CLOSE()
  57.     ON_WM_WINDOWPOSCHANGED()
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CMRCMDIFloatWnd message handlers
  64.  
  65. BOOL CMRCMDIFloatWnd::Create(CWnd* pParent, DWORD dwBarStyle)
  66. {
  67.     // set m_bInRecalcLayout to avoid flashing during creation
  68.     // RecalcLayout will be called once something is docked
  69.     m_bInRecalcLayout = TRUE;
  70.  
  71.     DWORD dwStyle = WS_CHILD | WS_OVERLAPPEDWINDOW | FWS_SNAPTOBARS;
  72.     if (!CMDIFloat_Parent::Create(NULL, NULL, dwStyle, rectDefault, NULL  /*(CMDIFrameWnd *)pParent)*/))
  73.     {
  74.         m_bInRecalcLayout = FALSE;
  75.         return FALSE;
  76.     }
  77.  
  78.     // Create a single dockbar for this frame with ID=AFX_IDW_DOCKBAR_FLOAT (picked up later)
  79.     dwStyle = dwBarStyle & (CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT) ?
  80.         CBRS_ALIGN_LEFT : CBRS_ALIGN_TOP;
  81.     dwStyle |= dwBarStyle & CBRS_FLOAT_MULTI;
  82.  
  83.     if (!m_wndMDIDockBar.Create(pParent, WS_CHILD | WS_VISIBLE | dwStyle, AFX_IDW_DOCKBAR_FLOAT))
  84.     {
  85.         m_bInRecalcLayout = FALSE;
  86.         return FALSE;
  87.     }
  88.     m_wndMDIDockBar.SetParent(this);
  89.  
  90.     m_bInRecalcLayout = FALSE;
  91.     return TRUE;             
  92. }
  93.  
  94.  
  95. //--------------------------------------------------------------------------
  96. void CMRCMDIFloatWnd::OnSize(UINT nType, int cx, int cy) 
  97. // respond to the miniframe resizing. If we've got a sizeable control
  98. // bar in the window, then we set it's size. Need to adjust for the
  99. // window borders. The window will then get repositioned by a ReCalcLayout()
  100. //--------------------------------------------------------------------------
  101. {
  102.     if (cx == 0 && cy == 0)
  103.         return;
  104.  
  105.     CDockBar* pDock = &m_wndMDIDockBar;
  106.  
  107.     // We don't support CBRS_FLOAT_MULTI
  108.     if ((pDock->m_dwStyle & CBRS_FLOAT_MULTI) == 0)
  109.     {
  110.         // CMiniDockFrameWnd class assumes if there is only 1 bar, then it's at position 1
  111.         // in the array
  112.         CMRCSizeControlBar* pBar = ((CSizeDockBar *)pDock)->GetFirstControlBar();
  113.         // ignore size request if not visible....
  114.         if (pBar != NULL && IsSizeable(pBar) && pBar->IsVisible())
  115.         {
  116.             CRect rect(0, 0, cx, cy);
  117.             AdjustForBorders(rect, pBar->m_dwStyle);
  118.  
  119.             pBar->m_FloatSize.cx = rect.Width();
  120.             pBar->m_FloatSize.cy = rect.Height();
  121.         }
  122.     }
  123.     CMDIFloat_Parent::OnSize(nType, cx, cy);    // call parent to update menu's etc.
  124. }
  125.  
  126.  
  127. void CMRCMDIFloatWnd::OnClose() 
  128. {
  129.     CDockBar* pDock = &m_wndMDIDockBar;
  130.  
  131.     if ((pDock->m_dwStyle & CBRS_FLOAT_MULTI) == 0)
  132.     {
  133.      // CMiniDockFrameWnd class assumes if there is only 1 bar, then it's at position 1
  134.      // in the array
  135.         CControlBar* pBar = ((CSizeDockBar *) pDock)->GetFirstControlBar();
  136.          if (pBar != NULL && pBar->IsKindOf(RUNTIME_CLASS(CMRCSizeControlBar)) )
  137.              if (((CMRCSizeControlBar *)pBar)->m_Style & SZBARF_DESTROY_ON_CLOSE)
  138.             {
  139.                   // close the Frame Window
  140.                   CFrameWnd::OnClose();       // close the window
  141.                   delete pBar;            // now explicitly delete the control bar
  142.                   return;
  143.             }
  144.     } 
  145.  
  146.     // otherwise just close it. .. really just want to hide it...
  147.     CMDIFloat_Parent::OnClose();
  148. }
  149.  
  150.  
  151. void CMRCMDIFloatWnd::RecalcLayout(BOOL bNotify)
  152. {
  153.     if (!m_bInRecalcLayout)
  154.     {
  155.         CMDIFloat_Parent::RecalcLayout(bNotify);
  156.  
  157.         // syncronize window text of frame window with dockbar itself
  158.         CString strTitle;
  159.         m_wndMDIDockBar.GetWindowText(strTitle);
  160.         AfxSetWindowText(m_hWnd, strTitle);
  161.     }
  162. }
  163.  
  164.  
  165. //------------------------------------------------------------------
  166. void CMRCMDIFloatWnd::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) 
  167. // Updates the floating position for a bar. 
  168. //------------------------------------------------------------------
  169. {
  170.     CMDIFloat_Parent::OnWindowPosChanged(lpwndpos);
  171.  
  172.     if ((m_wndMDIDockBar.m_dwStyle & CBRS_FLOAT_MULTI) == 0)
  173.     {
  174.         CMRCSizeControlBar* pBar = ((CSizeDockBar *) &m_wndMDIDockBar)->GetFirstControlBar();
  175.          if (pBar != NULL && pBar->IsKindOf(RUNTIME_CLASS(CMRCSizeControlBar)) )
  176.          {
  177.              CRect rect;
  178.             GetWindowRect(&rect);
  179.              pBar->m_FloatingPosition = rect.TopLeft();
  180.          }    
  181.     }
  182. }
  183.