home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / MDIFRAME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.4 KB  |  205 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Implementation of class TMDIFrame.  This defines the basic behavior of
  8. // all MDI frame windows.
  9. //----------------------------------------------------------------------------
  10. #pragma hdrignore SECTION
  11. #include <owl/pch.h>
  12. #if !defined(OWL_MDI_H)
  13. # include <owl/mdi.h>
  14. #endif
  15. #if !defined(OWL_APPLICAT_H)
  16. # include <owl/applicat.h>
  17. #endif
  18.  
  19. OWL_DIAGINFO;
  20. DIAG_DECLARE_GROUP(OwlCmd);
  21.  
  22. #if !defined(SECTION) || SECTION == 1
  23.  
  24. DEFINE_RESPONSE_TABLE1(TMDIFrame, TFrameWindow)
  25. END_RESPONSE_TABLE;
  26.  
  27. //
  28. // Constructor for a TMDIFrame
  29. //
  30. TMDIFrame::TMDIFrame(const char far* title,
  31.                      TResId          menuResId,
  32.                      TMDIClient&     clientWnd,
  33.                      TModule*        module)
  34. {
  35.   // Initialize virtual bases, in case the derived-most used default ctor
  36.   //
  37.   TWindow::Init(0, title, module);
  38.   TFrameWindow::Init(&clientWnd, false);
  39.  
  40.   if (menuResId)
  41.     AssignMenu(menuResId);
  42. }
  43.  
  44. //
  45. // Constructor for a TMDIFrame which is being used as an alias for a
  46. // non-OWL window
  47. //
  48. TMDIFrame::TMDIFrame(THandle    handle,
  49.                      THandle    clientHandle,
  50.                      TModule*   module)
  51. :
  52.   TFrameWindow(handle, module),
  53.   TWindow(handle, module)
  54. {
  55.   CHECK(::GetParent(clientHandle) == handle);
  56.  
  57.   // NOTE: Attr.Menu set in TWindow's constructor
  58.   //
  59.   ClientWnd = new TMDIClient(clientHandle);
  60.   ClientWnd->Parent = this;
  61. }
  62.  
  63. //
  64. // An MDI frame must have a menu.  Give it an empty one if none supplied.
  65. //
  66. void
  67. TMDIFrame::PerformCreate(int menuOrId)
  68. {
  69.   TFrameWindow::PerformCreate(menuOrId ? menuOrId : (int)::CreateMenu());
  70. }
  71.  
  72. //
  73. // Look for the MDI submenu in a menubar by looking for the normal MDI
  74. // commands, and return pos if found. Scan from right to left since the Window
  75. // menu is usually near the right.
  76. //
  77. HMENU
  78. TMDIFrame::FindChildMenu(HMENU menu)
  79. {
  80.   if (menu) {
  81.     int   numItems = ::GetMenuItemCount(menu);
  82.     for (int i = numItems-1; i >= 0; i--) {
  83.       HMENU childMenu = ::GetSubMenu(menu, i);
  84.       if (childMenu &&
  85.           (TUser::GetMenuState(childMenu, CM_CASCADECHILDREN, MF_BYCOMMAND) != (uint)-1 ||
  86.            TUser::GetMenuState(childMenu, CM_TILECHILDREN, MF_BYCOMMAND) != (uint)-1 ||
  87.            TUser::GetMenuState(childMenu, CM_ARRANGEICONS, MF_BYCOMMAND) != (uint)-1)) {
  88.         return childMenu;
  89.       }
  90.     }
  91.   }
  92.   return 0;
  93. }
  94.  
  95. //
  96. // MDI specific version of SetMenu uses WM_MDISETMENU to set a new
  97. // menu bar and childMenu within it.
  98. //
  99. bool
  100. TMDIFrame::SetMenu(HMENU newMenu)
  101. {
  102.   PRECONDITION(newMenu);
  103.  
  104.   if (IsFlagSet(wfMainWindow))
  105.     GetApplication()->PreProcessMenu(newMenu);
  106.  
  107.   if (GetHandle()) {
  108.     HMENU childMenu = FindChildMenu(newMenu);
  109. #if defined(BI_PLAT_WIN32)
  110.     HMENU oldMenu = (HMENU)ClientWnd->HandleMessage(WM_MDISETMENU,
  111.                                                     TParam1(newMenu),
  112.                                                     TParam2(childMenu));
  113. #else
  114.     HMENU oldMenu = (HMENU)ClientWnd->HandleMessage(WM_MDISETMENU,
  115.                                                     false,
  116.                                                     MkParam2(newMenu, childMenu));
  117. #endif
  118.     DrawMenuBar();
  119.     if (!oldMenu)
  120.       return false;
  121.   }
  122.   return true;
  123. }
  124.  
  125. //
  126. // Return the client window of this MDI frame.
  127. //
  128. #if !defined(BI_NO_COVAR_RET)
  129. TMDIClient*
  130. TMDIFrame::GetClientWindow()
  131. {
  132.   return TYPESAFE_DOWNCAST(ClientWnd,TMDIClient);
  133. }
  134. #else
  135. TWindow*
  136. TMDIFrame::GetClientWindow()
  137. {
  138.   return ClientWnd;
  139. }
  140. #endif
  141.  
  142. //
  143. // Locate and return the child window that is the target of command and command
  144. // enable messages. Pass this to our active mdi child, if any, to let it
  145. // locate its active command target.
  146. //
  147. TWindow::THandle
  148. TMDIFrame::GetCommandTarget()
  149. {
  150. #if !defined(BI_NO_COVAR_RET)
  151.   TFrameWindow* mdiChild = GetClientWindow()->GetActiveMDIChild();
  152. #else
  153.   TFrameWindow* mdiChild = TYPESAFE_DOWNCAST(GetClientWindow(),TMDIClient)->
  154.                              GetActiveMDIChild();
  155. #endif
  156.  
  157.   TRACEX(OwlCmd, 1, "TMDIFrame::GetCommandTarget - returns " << \
  158.                     (mdiChild ? "ActiveMDIChild->GetCommandTarget()" \
  159.                               : "TFrameWindow::GetCommandTarget()"));
  160.  
  161.   return mdiChild ? mdiChild->GetCommandTarget() : TFrameWindow::GetCommandTarget();
  162. }
  163.  
  164. //
  165. // Override TWindow method and call ::DefFrameProc() instead of
  166. // ::DefWindowProc()
  167. //
  168. TResult
  169. TMDIFrame::DefWindowProc(uint message, TParam1 param1, TParam2 param2)
  170. {
  171.   return ::DefFrameProc(GetHandle(), ClientWnd ? ClientWnd->GetHandle() : 0,
  172.                         message, param1, param2);
  173. }
  174.  
  175. #endif
  176. #if !defined(SECTION) || SECTION == 2
  177.  
  178. IMPLEMENT_STREAMABLE2(TMDIFrame, TFrameWindow, TWindow);
  179.  
  180. #if !defined(BI_NO_OBJ_STREAMING)
  181.  
  182. //
  183. // Reads an instance of TMDIFrame from the passed ipstream
  184. //
  185. void*
  186. TMDIFrame::Streamer::Read(ipstream& is, uint32 /*version*/) const
  187. {
  188.   ReadVirtualBase((TFrameWindow*)GetObject(), is);
  189.   GetObject()->AssignMenu(GetObject()->Attr.Menu);
  190.   return GetObject();
  191. }
  192.  
  193. //
  194. // Writes the TMDIFrame to the passed opstream
  195. //
  196. void
  197. TMDIFrame::Streamer::Write(opstream& os) const
  198. {
  199.   WriteVirtualBase((TFrameWindow*)GetObject(), os);
  200. }
  201.  
  202. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  203.  
  204. #endif
  205.