home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / MDIFRAME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  4.1 KB  |  156 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   source\owl\mdiframe.cpp
  4. //   Implementation of class TMDIFrame.  This defines the basic behavior of
  5. //   all MDI frame windows.
  6. //----------------------------------------------------------------------------
  7. #pragma hdrignore SECTION
  8. #include <owl\owlpch.h>
  9. #include <owl\mdi.h>
  10.  
  11. #if !defined(SECTION) || SECTION == 1
  12.  
  13. DEFINE_RESPONSE_TABLE1(TMDIFrame, TFrameWindow)
  14. END_RESPONSE_TABLE;
  15.  
  16. //
  17. // constructor for a TMDIFrame
  18. //
  19. TMDIFrame::TMDIFrame(const char far* title,
  20.                      TResId          menuResId,
  21.                      TMDIClient&     clientWnd,
  22.                      TModule*        module)
  23. {
  24.   //
  25.   // Initialize virtual bases, in case the derived-most used default ctor
  26.   //
  27.   TWindow::Init(0, title, module);
  28.   TFrameWindow::Init(&clientWnd, FALSE);
  29.  
  30.   if (menuResId)
  31.     AssignMenu(menuResId);
  32. }
  33.  
  34. //
  35. // constructor for a TMDIFrame which is being used as an alias for a
  36. // non-OWL window
  37. //
  38. TMDIFrame::TMDIFrame(HWND       hWnd,
  39.                      HWND       clientHWnd,
  40.                      TModule*   module)
  41.   : TFrameWindow(hWnd, module),
  42.     TWindow(hWnd, module)
  43. {
  44.   CHECK(::GetParent(clientHWnd) == hWnd);
  45.  
  46.   //
  47.   // NOTE: Attr.Menu set in TWindow's constructor
  48.   //
  49.   ClientWnd = new TMDIClient(clientHWnd);
  50.   ClientWnd->Parent = this;
  51. }
  52.  
  53. //
  54. //    an MDI frame must have a menu.  Give it an empty one if none supplied.
  55. //
  56. void
  57. TMDIFrame::PerformCreate(int menuOrId)
  58. {
  59.   TFrameWindow::PerformCreate(menuOrId ? menuOrId : (int)::CreateMenu());
  60. }
  61.  
  62. //
  63. // look for the MDI submenu in a menubar by looking for the normal
  64. // MDI commands, and return pos if found. Scan from right to
  65. // left since the Window menu is usually near the right.
  66. //
  67. HMENU
  68. TMDIFrame::FindChildMenu(HMENU menu)
  69. {
  70.   if (menu) {
  71.     int   numItems = ::GetMenuItemCount(menu);
  72.     for (int i = numItems-1; i >= 0; i--) {
  73.       HMENU childMenu = ::GetSubMenu(menu, i);
  74.       if (childMenu &&
  75.           ::GetMenuState(childMenu, CM_CASCADECHILDREN, MF_BYCOMMAND) != (UINT)-1 ||
  76.           ::GetMenuState(childMenu, CM_TILECHILDREN, MF_BYCOMMAND) != (UINT)-1 ||
  77.           ::GetMenuState(childMenu, CM_ARRANGEICONS, MF_BYCOMMAND) != (UINT)-1) {
  78.         return childMenu;
  79.       }
  80.     }
  81.   }
  82.   return 0;
  83. }
  84.  
  85. //
  86. // MDI specific version of SetMenu uses WM_MDISETMENU to set a new
  87. // menu bar and childMenu within it.
  88. //
  89. BOOL
  90. TMDIFrame::SetMenu(HMENU newMenu)
  91. {
  92.   PRECONDITION(newMenu);
  93.  
  94.   HMENU childMenu = FindChildMenu(newMenu);
  95.  
  96.   if (HWindow) {
  97.     #if defined(__WIN32__)
  98.       HMENU oldMenu = (HMENU)ClientWnd->HandleMessage(WM_MDISETMENU,
  99.                                                       (WPARAM)newMenu,
  100.                                                       (LPARAM)childMenu);
  101.     #else
  102.       HMENU oldMenu = (HMENU)ClientWnd->HandleMessage(WM_MDISETMENU,
  103.                                                       FALSE,
  104.                                                       MAKELPARAM(newMenu, childMenu));
  105.     #endif
  106.     DrawMenuBar();
  107.     if (!oldMenu)
  108.       return FALSE;
  109.   }
  110.   return TRUE;
  111. }
  112.  
  113. TMDIClient*
  114. TMDIFrame::GetClientWindow()
  115. {
  116.   return TYPESAFE_DOWNCAST(ClientWnd,TMDIClient);
  117. }
  118.  
  119. //
  120. // override TWindow method and call ::DefFrameProc() instead of
  121. // ::DefWindowProc()
  122. //
  123. LRESULT
  124. TMDIFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  125. {
  126.   return ::DefFrameProc(HWindow, ClientWnd ? ClientWnd->HWindow : 0,
  127.                         message, wParam, lParam);
  128. }
  129.  
  130. #endif
  131. #if !defined(SECTION) || SECTION == 2
  132.  
  133. IMPLEMENT_STREAMABLE2(TMDIFrame, TFrameWindow, TWindow);
  134.  
  135. //
  136. // reads an instance of TMDIFrame from the passed ipstream
  137. //
  138. void*
  139. TMDIFrame::Streamer::Read(ipstream& is, uint32 /*version*/) const
  140. {
  141.   ReadVirtualBase((TFrameWindow*)GetObject(), is);
  142.   GetObject()->AssignMenu(GetObject()->Attr.Menu);
  143.   return GetObject();
  144. }
  145.  
  146. //
  147. // writes the TMDIFrame to the passed opstream
  148. //
  149. void
  150. TMDIFrame::Streamer::Write(opstream& os) const
  151. {
  152.   WriteVirtualBase((TFrameWindow*)GetObject(), os);
  153. }
  154.  
  155. #endif
  156.