home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / miscprog / actormdi / mdiclien.cls < prev    next >
Encoding:
Text File  |  1990-12-06  |  4.4 KB  |  135 lines

  1. /* MDICLIEN.CLS - This class handles the creation and
  2.   maintenance of an MDI Client window.  An MDI Client
  3.   must be created with an MDIFrame as it's parent and
  4.   should be automatically destroyed by the MDIFrame's
  5.   default window procedure. */!!
  6.  
  7. inherit(Control, #MDIClient, #(childList activeChild windowMenu), 2, nil)!!
  8.  
  9. now(class(MDIClient))!!
  10.  
  11. Def newMDIClient(self, par, firstID)
  12. { ^init(createMDICLient(new(self:Behavior), par, style(self), firstID));
  13. }!!
  14.  
  15. /* Return the default window style. */
  16. Def style(self)
  17. { ^WS_CHILD bitOr WS_CLIPCHILDREN bitOr WS_VSCROLL bitOr WS_HSCROLL;
  18. }!!
  19.  
  20. now(MDIClient)!!
  21.  
  22. Def deactivateMDIChild(self, theChild)
  23. { if activeChild == theChild
  24.   then activeChild := nil;
  25.   endif;
  26. }!!
  27.  
  28. Def activateMDIChild(self, theChild)
  29. { activeChild := theChild;
  30. }!!
  31.  
  32. /* Return a pointer to the child window specified by theHWnd */
  33. Def activeChild(self)
  34. { ^activeChild;
  35. }!!
  36.  
  37. /* Step through all of the applications child windows and make sure that
  38.   they are ready to be closed, before closing the MDI Frame Window. */
  39. Def closeAllMDIChildren(self | allClosed)
  40. { allClosed := true;
  41.   do(copy(childList),
  42.   {using(aChild)
  43.      if shouldClose(aChild)
  44.      then destroy(aChild);
  45.      else allClosed := nil;
  46.      endif;
  47.   });
  48.   ^allClosed;
  49. }!!
  50.  
  51. /* Close the MDI child window associated with the window handle
  52.   that is passed to this routine. */
  53. Def closeMDIChild(self, theHWnd)
  54. { close(childList[theHWnd]);
  55. }!!
  56.  
  57. /* Destroy the MDI Child window that is associated with the
  58.   window handle that is passed in */
  59. Def destroyMDIChild(self, theHWnd)
  60. { destroy(childList[theHWnd]);
  61. }!!
  62.  
  63. /* Calling this method with a class name, caption text, and a rectangle
  64.   in which to display the window will create a new MDI child.  It will
  65.   then add that child windows pointer to the childList dictionary, keying
  66.   it on the hWnd of that child. */
  67. Def createMDIChild(self, childClass, wName, rect | theChild)
  68. { if theChild := new(childClass, self, nil, wName, rect)
  69.   then
  70.     if size(childList) == 0
  71.     then enableMenus(parent);
  72.       activeChild := theChild;
  73.     endif;
  74.     add(childList, getHWnd(theChild), theChild);
  75.   endif;
  76.   ^theChild;
  77. }!!
  78.  
  79. Def init(self)
  80. { childList := new(Dictionary, 2);
  81. }!!
  82.  
  83. /* Default for dialogs is to do nothing. Return 0
  84.   to let Windows do normal processing.
  85.   WARNING: Do not remove this method! May be redefined
  86.   in descendants if they register a private window
  87.   class with Windows for their dialogs. */
  88. Def defWndProc(self, msgNum, wP, lP)
  89. { ^0;
  90. }!!
  91.  
  92. /* This message is called every time an MDI Child makes a request to be
  93.   destroyed.  The default procedure for the MDI Client will handle the
  94.   destruction of the child window.  That childs pointer will then be
  95.   removed from the child window dictionary of the frame window. */
  96. Def WM_MDIDESTROY(self, wP, lP)
  97. { execWindowProc(self, #WM_MDIDESTROY, wP, lP);
  98.   remove(childList, wP);
  99.   if size(childList) == 0
  100.   then activeChild := nil;
  101.   endif;
  102.   disableMenus(parent);
  103. }!!
  104.  
  105. /* Make sure to remove the property created for the Client Window when
  106.   it has been destroyed. */
  107. Def WM_NCDESTROY(self, wP, lP)
  108. { Call RemoveProp(hWnd, asciiz("ActorOOP"));
  109. }!!
  110.  
  111. /* Create a new MDI client window.  Certain parameters should be the same
  112.   no matter the client window that is being created, thus these values
  113.   have been hardcoded.  For example, MDIClient should not have a menu,
  114.   will always be registered with the "mdiclient" class, and has it's
  115.   position and size determined by the MDIFrame window. */
  116. Def createMDICLient(self, par, style, firstChildID | clientStruct)
  117. { parent := par;
  118.   windowMenu := Call CreatePopupMenu();
  119.   Call AppendMenu(windowMenu, MF_STRING, 9997, asciiz("&Cascade"));
  120.   Call AppendMenu(windowMenu, MF_STRING, 9998, asciiz("&Tile"));
  121.   Call AppendMenu(windowMenu, MF_STRING, 9999, asciiz("&Arrange Icons"));
  122.   Call InsertMenu(menuHandle(parent), -1, MF_POPUP, windowMenu, asciiz("&Windows"));
  123.   clientStruct := new(Struct, 4);
  124.   putWord(clientStruct, windowMenu, 0);
  125.   putWord(clientStruct, firstChildID, 2);
  126.   hWnd := Call CreateWindow(asciiz("mdiclient"), 0, style,
  127.     0, 0, 0, 0, getHWnd(par), 0xCAC, HInstance, clientStruct);
  128.   if hWnd = 0
  129.   then alert(System, self, #windCreateError);
  130.   endif;
  131.   setActorProp(self);
  132.   defProc := Call GetWindowLong(hWnd, -4);
  133.   Call SetWindowLong(hWnd, -4, LpWFunc);
  134. }!!
  135.