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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   source\owl\mdichild.cpp
  4. //   Defines class TMDIChild. This defines the basic behavior of all MDI
  5. //   child windows
  6. //----------------------------------------------------------------------------
  7. #pragma hdrignore SECTION
  8. #include <owl\owlpch.h>
  9. #include <owl\mdichild.h>
  10. #include <owl\mdi.h>
  11.  
  12.  
  13. #if !defined(SECTION) || SECTION == 1
  14.  
  15. DEFINE_RESPONSE_TABLE1(TMDIChild, TFrameWindow)
  16.   EV_WM_MDIACTIVATE,
  17.   EV_WM_NCACTIVATE,
  18. END_RESPONSE_TABLE;
  19.  
  20. //
  21. // constructor for a TMDIChild
  22. //
  23. TMDIChild::TMDIChild(TMDIClient&     parent,
  24.                      const char far* title,
  25.                      TWindow*        clientWnd,
  26.                      BOOL            shrinkToClient,
  27.                      TModule*        module)
  28. {
  29.   //
  30.   // Initialize virtual bases, in case the derived-most used default ctor
  31.   //
  32.   TWindow::Init(&parent, title, module);
  33.   TFrameWindow::Init(clientWnd, shrinkToClient);
  34.  
  35.   Attr.Style = WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
  36.                WS_SYSMENU | WS_CAPTION | WS_THICKFRAME |
  37.                WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
  38.   Attr.Y = Attr.H = CW_USEDEFAULT;
  39. }
  40.  
  41. //
  42. // constructor for a TMDIChild which is being used in a DLL as an alias
  43. // for a non-OWL window
  44. //
  45. TMDIChild::TMDIChild(HWND hWnd, TModule*   module)
  46.   : TFrameWindow(hWnd, module),
  47.     TWindow(hWnd, module)
  48. {
  49.   Attr.Style = WS_CLIPSIBLINGS;
  50. }
  51.  
  52. BOOL
  53. TMDIChild::EvNCActivate(BOOL active)
  54. {
  55.   return IsFlagSet(wfUnHidden) ? FALSE : TFrameWindow::EvNCActivate(active);
  56. }
  57.  
  58. BOOL
  59. TMDIChild::ShowWindow(int cmdShow)
  60. {
  61.   int  retVal = TFrameWindow::ShowWindow(cmdShow);     // 0 if had been hidden
  62.   if ((retVal != 0) != (cmdShow != SW_HIDE)) { // if visible state has changed
  63.     if ((HWND)Parent->HandleMessage(WM_MDIGETACTIVE) == *this) {
  64.       if (cmdShow == SW_HIDE)
  65.         Parent->HandleMessage(WM_MDINEXT, (UINT)(HWND)*this);
  66.       else
  67.         HandleMessage(WM_NCACTIVATE, TRUE); // resend suppressed message
  68.     }
  69. #if defined(__WIN32__)
  70.     Parent->HandleMessage(WM_MDIREFRESHMENU);
  71. #else
  72.     Parent->HandleMessage(WM_MDISETMENU, TRUE);
  73. #endif
  74.   }
  75.   return retVal;
  76. }
  77.  
  78. BOOL
  79. TMDIChild::EnableWindow(BOOL enable)
  80. {
  81.   int retVal = TFrameWindow::EnableWindow(enable);  // 0 if previously enabled
  82.   if ((retVal!=0) != (enable==0)) {  // if disabled state has actually changed
  83.     if (!enable && (HWND)Parent->HandleMessage(WM_MDIGETACTIVE) == *this)
  84.       Parent->HandleMessage(WM_MDINEXT, (UINT)(HWND)*this);
  85. #if defined(__WIN32__)
  86.     Parent->HandleMessage(WM_MDIREFRESHMENU);
  87. #else
  88.     Parent->HandleMessage(WM_MDISETMENU, TRUE);
  89. #endif
  90.   }
  91.   return retVal;
  92. }
  93.  
  94. BOOL
  95. TMDIChild::PreProcessMsg(MSG& msg)
  96. {
  97.   //
  98.   // if the MDI child has requested keyboard navigation then TFrameWindow's
  99.   // PreProcessMsg() member function will call ::IsDialogMessage() which will
  100.   // eat the event and the MDI client window won't get a chance to do MDI
  101.   // accelerator processing
  102.   //
  103.   // so, we will do it here to make sure it gets done
  104.   //
  105.   if (KeyboardHandling && Parent->PreProcessMsg(msg))
  106.     return TRUE;
  107.  
  108.   if (hAccel && ::TranslateAccelerator(Parent->Parent->HWindow, hAccel, &msg))
  109.     return TRUE;
  110.  
  111.   return TFrameWindow::PreProcessMsg(msg);
  112. }
  113.  
  114. //
  115. // destroys the MS-Windows element associated with the TMDIChild
  116. //
  117. void
  118. TMDIChild::Destroy(int)
  119. {
  120.   if (HWindow) {
  121.     ForEach(DoEnableAutoCreate);
  122.  
  123.     if (Parent) // send destroy message to MDI client window
  124.       Parent->HandleMessage(WM_MDIDESTROY, (WPARAM) HWindow);
  125.  
  126.     else
  127.       ::DestroyWindow(HWindow);
  128.   }
  129. }
  130.  
  131. void
  132. TMDIChild::PerformCreate(int)
  133. {
  134.   PRECONDITION(Parent);
  135.  
  136.   MDICREATESTRUCT  createStruct;
  137.  
  138.   createStruct.szClass = GetClassName();
  139.   createStruct.szTitle = Title;
  140.   createStruct.hOwner = *GetModule();
  141.   createStruct.x = Attr.X;
  142.   createStruct.y = Attr.Y;
  143.   createStruct.cx = Attr.W;
  144.   createStruct.cy = Attr.H;
  145.  
  146.   DWORD style = Attr.Style;
  147.   if (style & WS_MAXIMIZE) {  // Work around a Windows MDI bug
  148.     Attr.Style &= ~(WS_MAXIMIZE | WS_VISIBLE);
  149.     Attr.Style |= WS_DISABLED;
  150.   }
  151.   createStruct.style = Attr.Style;
  152.   createStruct.lParam = (LPARAM)Attr.Param;
  153.  
  154.   HWindow = (HWND)Parent->HandleMessage(WM_MDICREATE, 0, (LPARAM)&createStruct);
  155.  
  156.   if (style & WS_MAXIMIZE) {  // finish up maximized mdi workaround
  157.     EnableWindow(TRUE);
  158.                 Attr.Style = style;
  159.     Parent->HandleMessage(WM_MDIMAXIMIZE, WPARAM(HWindow));
  160.   }
  161. }
  162.  
  163. void
  164. TMDIChild::EvMDIActivate(HWND hWndActivated,
  165.                          HWND /*hWndDeactivated*/)
  166. {
  167.   if (HWindow == hWndActivated) {
  168.     //
  169.     // A bug in Windows MDI causes the first MDI child to not get a
  170.     // WM_SETFOCUS. Simulate it now
  171.     //
  172.     if (!GetWindow(GW_HWNDNEXT) && GetFocus() != HWindow)
  173.       HandleMessage(WM_SETFOCUS, WPARAM(HWindow));
  174.  
  175.     //
  176.     // Merge this windows menubar with the MDI frame's if there is a
  177.     // MenuDescr assigned
  178.     //
  179.     if (GetMenuDescr()) {
  180.       TFrameWindow* frame = TYPESAFE_DOWNCAST(Parent->Parent,TFrameWindow);
  181.       if (frame)
  182.         frame->MergeMenu(*GetMenuDescr());
  183.     }
  184.  
  185.   } else {
  186.     //
  187.     // Restore the MDI frame's menubar if there is no other MDI child being
  188.     // activated
  189.     //
  190.     if (GetMenuDescr() && !hWndActivated) {
  191.       TFrameWindow* frame = TYPESAFE_DOWNCAST(Parent->Parent,TFrameWindow);
  192.       if (frame)
  193.         frame->RestoreMenu();
  194.     }
  195.   }
  196. }
  197.  
  198. //
  199. // override DefWindowProc to use DefMDIChildProc
  200. //
  201. LRESULT
  202. TMDIChild::DefWindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
  203. {
  204.   return ::DefMDIChildProc(HWindow, msg, wParam, lParam);
  205. }
  206.  
  207. #endif
  208. #if !defined(SECTION) || SECTION == 2
  209.  
  210.  
  211. IMPLEMENT_STREAMABLE2(TMDIChild, TFrameWindow, TWindow);
  212.  
  213. void*
  214. TMDIChild::Streamer::Read(ipstream& is, uint32 /*version*/) const
  215. {
  216.   ReadVirtualBase((TFrameWindow*)GetObject(), is);
  217.   return GetObject();
  218. }
  219.  
  220. //
  221. // writes data of the TMDIChild to the passed opstream
  222. //
  223. void
  224. TMDIChild::Streamer::Write(opstream& os) const
  225. {
  226.   WriteVirtualBase((TFrameWindow*)GetObject(), os);
  227. }
  228.  
  229.  
  230. #endif
  231.