/* PAD - This class handles the creation and maintenance of an MDI Client window.  An MDI Client must be created with an MDIFrameWindow as it's parent and should be automatically destroyed by the MDIFrameWindow's default window procedure. */!!

inherit(Control, #MDIClient, nil, 2, nil)!!

now(class(MDIClient))!!

/* Create a new instance of the MDIClient class.  As arguments it
   accepts a pointer to the parent window (this should be an MDIFrame
   window) and client structure.  This client structure should be a 4
   byte struct containing a popup menu handle in the first word and an
   id for the first MDI child window in the second word.  Make sure the
   id for the MDI child is high enough so that it will not conflict with
   any numbers passed into the MDIFrame windows command method. */
Def new(self, par, clientStruct)
{ ^newStyle(self, par, nil, clientStruct)
}!!

/* This will take care of the actual creation of an MDIClient.  The
   parameters passed can bee seen in the "new" method, with the exception
   of style.  If no style is defined in the newStyle statement a style will
   be obtained from the "style" class method of MDIClient.  This style
   should be appropriate for most MDI applications. */
Def newStyle(self, par, style, clientStruct | theWnd)
{ theWnd := new(self:Behavior);
  create(theWnd, par, style cor style(self), clientStruct);
  ^init(theWnd);
}!!

/* Return the default window style. */
Def style(self)
{ ^WS_CHILD bitOr WS_CLIPCHILDREN bitOr WS_VSCROLL bitOr WS_HSCROLL;
}!!

now(MDIClient)!!

/* Default for dialogs is to do nothing. Return 0
 to let Windows do normal processing.
 WARNING: Do not remove this method! May be redefined
 in descendants if they register a private window
 class with Windows for their dialogs. */
Def defWndProc(self, msgNum, wP, lP)
{ ^0
}
!!

/* This message is called every time an MDI Child makes a request to be
   destroyed.  The default procedure for the MDI Client will handle the
   destruction of the child window.  That childs pointer will then be
   removed from the child window dictionary of the frame window. */
Def WM_MDIDESTROY(self wP lP)
{ execWindowProc(self,#WM_MDIDESTROY,wP,lP);
  remove(parent,wP);
}
!!

/* An MDI Client Window should be destroyed via it's Frame Window so
   this disables the normal destroy method. */
Def destroy(self)
{ }!!

/* An MDI Client window will be destroyed via it's Frame Windows
   default Frame procedure. */
Def WM_DESTROY(self, wp, lp)
{ }!!

/* Make sure to remove the property created for the Client Window when
   it has been destroyed. */
Def WM_NCDESTROY(self, wp, lp)
{ Call RemoveProp(hWnd, asciiz("ActorOOP"));
}!!

/* Create a new MDI client window.  Certain parameters should be the same
   no matter the client window that is being created, thus these values
   have been hardcoded.  For example, MDIClient should not have a menu,
   will always be registered with the "mdiclient" class, and has it's
   position and size determined by the MDIFrame window. */
Def create(self par style clientStruct)
{ parent := par;
  hWnd := Call CreateWindow(asciiz("mdiclient"),0, style,
    0,0,0,0,getHWnd(par),0xCAC,HInstance,lP(clientStruct));
  freeHandle(clientStruct);
  if hWnd = 0
  then alert(System, self, #windCreateError);
  endif;
  setActorProp(self);
  defProc := Call GetWindowLong(hWnd, -4);
  Call SetWindowLong(hWnd, -4, LpWFunc);
}!!

/* Class Initialization */