home *** CD-ROM | disk | FTP | other *** search
- // MRCEXT: Micro Focus Extension DLL for MFC 2.1+
- // Copyright (C)1994-5 Micro Focus Inc, 2465 East Bayshore Rd, Palo Alto, CA 94303.
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation. In addition, you may also charge for any
- // application using MRCEXT, and are under no obligation to supply source
- // code. You must accredit Micro Focus Inc in the "About Box", or banner
- // of your application.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should also have received a copy of the GNU General Public License with this
- // software, also indicating additional rights you have when using MRCEXT.
- //
- //
- // SIZEDLG.CPP
- // $Date: 04 Dec 1995 15:24:26 $
- // $Revision: 1.0 $
- // $Author: MRC $
- //
- // Most of this code has been borrowed wholesale from MFC's CDialogBar().
-
- #include "mrcstafx.h"
-
- typedef struct _Rect_And_Hwnd
- {
- CRect m_rect;
- HWND m_hWnd;
- } RECT_AND_HWND;
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define new DEBUG_NEW
-
- const TCHAR _afxWndControlBar[] = _T("AfxControlBar"); // class for control bars
-
-
- CMRCSizeDialogBar::CMRCSizeDialogBar(int nStyle) : CMRCSizeControlBar(nStyle)
- {
- m_GadgetResizeHandle = NULL;
- }
-
-
- CMRCSizeDialogBar::~CMRCSizeDialogBar()
- {
- DestroyGadgetResizeHandle(m_GadgetResizeHandle);
- /*
- for (int i = m_arrRect.GetUpperBound(); i >= 0; i--)
- delete ((RECT_AND_HWND *)m_arrRect[i]);
- m_arrRect.RemoveAll(); */
-
- DestroyWindow(); // avoid PostNcDestroy problems
- }
-
-
- BEGIN_MESSAGE_MAP(CMRCSizeDialogBar, CMRCSizeControlBar)
- //{{AFX_MSG_MAP(CMRCSizeDialogBar)
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
-
-
- BOOL CMRCSizeDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName,
- UINT nStyle, UINT nID)
- {
- ASSERT(pParentWnd != NULL);
- ASSERT(lpszTemplateName != NULL);
-
- // Alas, MFC doesn't export many of the debugging only functions, so we have to live without
- // this safety net.
- //#ifdef _DEBUG
- // dialog template must exist and be invisible with WS_CHILD set
- //if (!_AfxCheckDialogTemplate(lpszTemplateName, TRUE))
- //{
- // ASSERT(FALSE); // invalid dialog template name
- // PostNcDestroy(); // cleanup if Create fails too soon
- // return FALSE;
- //}
- //#endif //_DEBUG
-
- // allow chance to modify styles
- m_dwStyle = nStyle;
- CREATESTRUCT cs;
- memset(&cs, 0, sizeof(cs));
- cs.lpszClass = _afxWndControlBar;
- cs.style = (DWORD)nStyle | WS_CHILD;
- cs.hMenu = (HMENU)nID;
- cs.hInstance = AfxGetInstanceHandle();
- cs.hwndParent = pParentWnd->GetSafeHwnd();
- if (!PreCreateWindow(cs))
- return FALSE;
-
- // create a modeless dialog
- HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
- AfxHookWindowCreate(this);
- HWND hWnd = ::CreateDialog(hInst, lpszTemplateName,
- pParentWnd->GetSafeHwnd(), NULL);
- if (!AfxUnhookWindowCreate())
- PostNcDestroy(); // cleanup if Create fails too soon
-
- if (hWnd == NULL)
- return FALSE;
- ASSERT(hWnd == m_hWnd);
-
- // dialog template MUST specify that the dialog
- // is an invisible child window
- SetDlgCtrlID(nID);
- CRect rect;
-
-
- // force WS_CLIPSIBLINGS
- // I also remove the titlebar. This means the resource can include a caption, which
- // will be used when the frame is floating.
- ModifyStyle(WS_CAPTION, WS_CLIPSIBLINGS);
- if (!ExecuteDlgInit(lpszTemplateName))
- return FALSE;
-
- // m_sizeDefault isn't actually used by the CMRCSizeDialogBar, but since it's public, it
- // seemed sensible to keep it available. Otherwise it might be difficult to get hold
- // of the original size of the dialog (as specified in the resource file).
-
- //GetWindowRect(&rect);
- GetClientRect(&rect);
- m_sizeDefault = rect.Size(); // set fixed size
-
- // Move to position 0,0
- // NB: size not forced to zero, as this can affect resizing if bar is immediately docked
- SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_NOSIZE);
-
- // set all the sizes to be the default after the positioning done above
- m_VertDockSize = m_sizeDefault;
- m_HorzDockSize = m_sizeDefault;
- m_FloatSize = m_sizeDefault;
-
-
- // if auto-sizing, store the rectangles of all the child windows.
- if (m_Style & SZBARF_DLGAUTOSIZE)
- {
- m_GadgetResizeHandle = CreateGadgetResizeHandle(this);
- }
- return TRUE;
- }
-
-
- //--------------------------------------------------------------------------
- BOOL CMRCSizeDialogBar::OnEraseBkgnd(CDC* pDC)
- // need to paint the background...
- //--------------------------------------------------------------------------
- {
- return CControlBar::OnEraseBkgnd(pDC);
- }
-
-
- //--------------------------------------------------------------------------
- void CMRCSizeDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
- //--------------------------------------------------------------------------
- {
- UpdateDialogControls(pTarget, bDisableIfNoHndler);
- }
-
-
- //--------------------------------------------------------------------------
- void CMRCSizeDialogBar::OnSizedOrDocked(int cx, int cy, BOOL bFloating, int flags)
- //--------------------------------------------------------------------------
- {
- CMRCSizeControlBar::OnSizedOrDocked(cx, cy, bFloating, flags);
- if (cx == 0 || cy == 0)
- return;
-
- // if auto-sizing, go thru and reposition all the controls.
- if (m_Style & SZBARF_DLGAUTOSIZE)
- {
- ResizeGadgetsOnWindow(m_GadgetResizeHandle, cx, cy);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Gadget resizing functions - used to resize all the child windows of a dialog
- // bar above. Routines extracted as they may be more used in general
-
- //---------------------------------------------------------------------------
- GADGETRESIZEHANDLE CreateGadgetResizeHandle(CWnd *pWnd)
- // For a given window, creates an array of the child windows, that can be used
- // for resizing later on.
- //---------------------------------------------------------------------------
- {
- CPtrArray * pArray = new CPtrArray;
-
- // 1st element of the array stores the client rectangle of the given window
- RECT_AND_HWND * pRectWnd = new RECT_AND_HWND;
- pWnd->GetClientRect(&(pRectWnd->m_rect));
- pRectWnd->m_hWnd == NULL;
- pArray->Add(pRectWnd);
-
- for (HWND hWndChild = ::GetTopWindow(pWnd->m_hWnd); hWndChild != NULL;
- hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT))
- {
- RECT_AND_HWND * pRectWnd = new RECT_AND_HWND;
- pRectWnd->m_hWnd = hWndChild;
- ::GetWindowRect(hWndChild, &(pRectWnd->m_rect));
- pWnd->ScreenToClient(&(pRectWnd->m_rect));
- pArray->Add(pRectWnd);
- }
-
- return (GADGETRESIZEHANDLE) pArray;
- }
-
-
- //---------------------------------------------------------------------------
- void DestroyGadgetResizeHandle(GADGETRESIZEHANDLE Handle)
- // deletes the underlying array and it's elements
- //---------------------------------------------------------------------------
- {
- CPtrArray * pArray = (CPtrArray *)Handle;
- if (pArray != NULL)
- {
- for (int i = pArray->GetUpperBound(); i >= 0; i--)
- delete ((RECT_AND_HWND *)pArray->GetAt(i));
- delete pArray;
- }
- }
-
-
- //---------------------------------------------------------------------------
- void ResizeGadgetsOnWindow(GADGETRESIZEHANDLE Handle, int cx, int cy)
- // Resizes all the gadgets in an array to match the new size.
- // Generally called from an OnSize routine (or the like)
- //---------------------------------------------------------------------------
- {
- CPtrArray * pArray = (CPtrArray *)Handle;
-
- if (pArray == NULL || cx == 0 || cy == 0)
- return;
-
- ASSERT(pArray->GetSize() > 0); // must be at least one element in the array
-
- // if auto-sizing, go thru and reposition all the controls.
- CSize sizeOrig = ((RECT_AND_HWND *)pArray->GetAt(0))->m_rect.Size();
- for (int i = 1; i < pArray->GetSize(); i++)
- {
- RECT_AND_HWND * pRectWnd = (RECT_AND_HWND *)pArray->GetAt(i);
- CRect newRect = pRectWnd->m_rect;
- newRect.top = newRect.top * cy / sizeOrig.cy;
- newRect.bottom = newRect.bottom * cy / sizeOrig.cy;
- newRect.left = newRect.left * cx / sizeOrig.cx;
- newRect.right = newRect.right * cx / sizeOrig.cx;
- ::SetWindowPos(pRectWnd->m_hWnd, NULL,
- newRect.left, newRect.top, newRect.Width(), newRect.Height(),
- SWP_NOZORDER);
- }
- }
-
-
-
-
-
- #undef new
-
- IMPLEMENT_DYNAMIC(CMRCSizeDialogBar, CMRCSizeControlBar)
-
- ///////////////////////////////////////////////////////////////////////////
-