home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWL1.PAK / MDIFRAME.CPP < prev    next >
Text File  |  1995-08-29  |  5KB  |  167 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* --------------------------------------------------------
  4.   MDIFRAME.CPP
  5.   Defines type TMDIFrame.  This defines the basic behavior
  6.   of all MDI frame windows.
  7.   -------------------------------------------------------- */
  8.  
  9. #include "mdi.h"
  10.  
  11. __link(RegMDIClient)
  12.  
  13. /* Constructor for a TMDIFrame.  Initializes its data fields using
  14.    passed parameters and default values. */
  15. TMDIFrame::TMDIFrame(LPSTR ATitle, LPSTR MenuName, PTModule AModule)
  16.           : TWindow(NULL, ATitle, AModule)
  17. {
  18.   AssignMenu(MenuName);
  19.   ClientWnd = NULL;
  20.   ChildMenuPos = 0;
  21.   ActiveChild = NULL;
  22.   SetFlags(WB_MDIFRAME, TRUE);
  23. }
  24.  
  25. /* Constructor for a TMDIFrame.  Initializes its data fields using
  26.    passed parameters and default values. */
  27. TMDIFrame::TMDIFrame(LPSTR ATitle, int MenuId, PTModule AModule)
  28.           : TWindow(NULL, ATitle, AModule)
  29. {
  30.   AssignMenu(MenuId);
  31.   ClientWnd = NULL;
  32.   ChildMenuPos = 0;
  33.   ActiveChild = NULL;
  34.   SetFlags(WB_MDIFRAME, TRUE);
  35. }
  36.  
  37. /* Constructor for a TMDIFrame which is being used in a DLL as an alias
  38.    for a non-OWL window */
  39. TMDIFrame::TMDIFrame(HWND AnHWindow, HWND ClientHWnd, PTModule AModule)
  40.           : TWindow(AnHWindow, AModule)
  41. {
  42. // Attr.Menu set in TWindow's constructor
  43.   ChildMenuPos = 0;
  44.   ActiveChild = NULL;
  45.   ClientWnd = new TMDIClient(this, ClientHWnd);
  46.   RemoveClient();   // remove ClientWnd from OWL child list
  47.   SetFlags(WB_MDIFRAME | WB_ALIAS, TRUE);
  48. }
  49.  
  50. /* Destructor for a TMDIFrame.  Disposes of the TMDIFrame's MDI client
  51.   window. */
  52. TMDIFrame::~TMDIFrame()
  53. {
  54.   if ( ClientWnd )
  55.   {
  56.     delete ClientWnd;
  57.     ClientWnd = NULL;
  58.   }
  59. }
  60.  
  61. /* Sets up the TMDIFrame by constructing and creating its TMDIClient. */
  62. void TMDIFrame::SetupWindow()
  63. {
  64.   HMENU FrameMenu;
  65.   RECT R;
  66.  
  67.   InitClientWindow();
  68.   RemoveClient();   // remove ClientWnd from OWL child list
  69.   FrameMenu = GetMenu(HWindow);
  70.   ClientWnd->ClientAttr->hWindowMenu = GetSubMenu(FrameMenu, ChildMenuPos);
  71.   GetClientRect(HWindow, &R);
  72.   if ( ClientWnd->Attr.X == CW_USEDEFAULT )
  73.   {
  74.     ClientWnd->Attr.X = R.left;
  75.     ClientWnd->Attr.Y = R.top;
  76.   }
  77.   if ( ClientWnd->Attr.W == CW_USEDEFAULT )
  78.   {
  79.     ClientWnd->Attr.W = R.right - R.left;
  80.     ClientWnd->Attr.H = R.bottom - R.top;
  81.   }
  82.  
  83.   // allow client area to grow scroll bars if necessary.
  84.   ClientWnd->Attr.Style |= WS_VSCROLL + WS_HSCROLL;
  85.  
  86.   if ( ClientWnd->Create() )
  87.     TWindow::SetupWindow();
  88.   else
  89.     Status = EM_INVALIDCLIENT;
  90. }
  91.  
  92. /* Specifies registration attributes for the MS-Windows window class
  93.    of the TMDIFrame.  Sets the fields of the passed WNDCLASS parameter
  94.    to the default attributes appropriate for a TMDIFrame. */
  95. void TMDIFrame::GetWindowClass(WNDCLASS& AWndClass)
  96. {
  97.   TWindow::GetWindowClass(AWndClass);
  98.   AWndClass.style = 0;
  99. }
  100.  
  101. /* Creates a valid new MDI child window after calling InitChild
  102.    to construct a new MDI child window object. */
  103. PTWindowsObject TMDIFrame::CreateChild()
  104. {
  105.   return GetModule()->MakeWindow(InitChild());
  106. }
  107.  
  108. static BOOL CannotClose(void *P, void *)
  109. {
  110.   if ( ((PTWindowsObject)P)->IsFlagSet(WB_MDICHILD) )
  111.     return !((PTWindowsObject)P)->CanClose();
  112.   else
  113.     return FALSE;
  114. }
  115.  
  116. static void CloseChild(void *AChild, void *)
  117. {
  118.   if ( ((PTWindowsObject)AChild)->IsFlagSet(WB_MDICHILD) )
  119.     ((PTWindowsObject)AChild)->ShutDownWindow();
  120. }
  121.  
  122. /* Closes each MDI child, after calling the child's CanClose method to
  123.   ensure that it is Ok to do so. Returns TRUE if all children are closed
  124.   (or there were no children), FALSE if any child can't be closed */
  125. BOOL TMDIFrame::CloseChildren()
  126. {
  127.   if ( !FirstThat(CannotClose, NULL) ) // All children can be closed
  128.   {
  129.     ForEach(CloseChild, NULL);
  130.     return TRUE;
  131.   }
  132.   return FALSE;
  133. }
  134.  
  135. /* Reads an instance of TMDIFrame from the passed ipstream. */
  136. void *TMDIFrame::read(ipstream& is)
  137. {
  138.   TWindow::read(is);
  139.  
  140.   GetChildPtr(is, (PTWindowsObject)ActiveChild);
  141.  
  142.   is >> ClientWnd;
  143.   if ( ClientWnd )
  144.     ClientWnd->Parent = this;
  145.   is >> ChildMenuPos;
  146.   return this;
  147. }
  148.  
  149. /* Writes the TMDIFrame to the passed opstream. */
  150. void TMDIFrame::write(opstream& os)
  151. {
  152.   TWindow::write(os);
  153.  
  154.   PutChildPtr(os, ActiveChild);
  155.  
  156.   os << ClientWnd;
  157.   os << ChildMenuPos;
  158. }
  159.  
  160. TStreamable *TMDIFrame::build()
  161. {
  162.   return new TMDIFrame(streamableInit);
  163. }
  164.  
  165. TStreamableClass RegMDIFrame("TMDIFrame", TMDIFrame::build,
  166.                       __DELTA(TMDIFrame));
  167.