/* FileApp.cls
   This class contains all necessary methods to initialize an
   MDI File Window application.  It can be used to seal off the
   MDIFileWindow classes and create a stand alone application.
      PAD
*/!!

inherit(Application, #FileApp, nil, 2, nil)!!

now(class(FileApp))!!

/* Remove unwanted Globals and Classes that are
  part of the Actor development environment. */
Def removeExtra(self)
{ do(#(SortedCollection WinEllipse WinPolygon StopWatch
       ListBox ScrollBar SnapDialog),
  {using(g) removeGlobal(self, g);
  });
}!!

/* Remove unwanted Globals and Classes that are
  part of the Actor development environment. */
Def removeActor(self)
{ do(#(ClassList MethodList VarList ClVarDialog
    ClassDialog DebugDialog DirtyCLD SealDialog
    AboutWindow WorkWindow
    ToolWindow Browser MethodBrowser DebugWindow
    Inspector BrowEdit DBBrowEdit DebugEdit WorkSpace),
  {using(g) removeGlobal(self, g);
  });
}!!

now(FileApp)!!

/* Duplicates the Actor low-level message loop with the exception
   that it handles modeless dialogs.  It still has the problem
   with child windows without menus since it dispatchs messages
   to the hWnd passed in the message struct. It therefore does
   need the translateMsg method to handle those cases. */
Def messageLoop(self | hMsg, lpMsg, hProp, lpProp hAccel, tmp, hWnd, hMD, wind)
{ if TheApp == self
  then hMsg := asGlobalHandle("123456789012345678", GMEM_FIXED);
    lpMsg := globalLock(hMsg);
    hProp := asGlobalHandle(asciiz("ActorOOP"), GMEM_FIXED);
    lpProp := globalLock(hProp);
    hAccel := Call LoadAccelerators(HInstance, asciiz(loadString(IDSNAME)));
    /* works only if OC returned from modelessHandles is the same for
       the "life" of the message loop, since the loop depends on hMD
       to reference to same OC as $HModelessDialog class var. */
    hMD := modelessHandles(Dialog);

    loop  /* start message loop */
    while Call GetMessage(lpMsg, 0, 0, 0) <> 0
    begin         /* Modeless dialog processing */
      tmp := size(hMD:OrderedCollection);
      loop
      while tmp > 0
      begin tmp := tmp - 1;
        (Call IsDialogMessage(hMD:Object[tmp], lpMsg) <> 0) cand (tmp := -1);
      endLoop;
                  /* Not a message for a modeless dialog */
      if tmp = 0
      then        /* Find the ultimate ancestor of the window */
        hWnd := wordAt(lpMsg);
        loop
        while not(
          (wind := (asLong(Call GetProp(hWnd, lpProp))*4L):Object[0]):Object)
            cand ((tmp := Call GetParent(hWnd)) <> 0)
        begin hWnd := tmp;
        endLoop;
        wind cand (hWnd := translateMsg(wind, lpMsg) cor hWnd);
        if (hWnd <> 0)
           cand (Call TranslateMDISysAccel(getHWnd(getClient(mainWindow)),lpMsg) = 0)
           cand (Call TranslateAccelerator(hWnd, hAccel, lpMsg) = 0)
        then Call TranslateMessage(lpMsg);
          Call DispatchMessage(lpMsg);
        else (wordAt(lpMsg) = 0) cand message(self, lpMsg);
        endif;
      endif;
    endLoop;
    globalUnlock(hMsg);
    globalUnlock(hProp);
    ^nil; /* Return nil to skip the low-level message loop */
  endif;
}!!

/* Create and show the application mainWindow
   Load a data file, if necessary. */ 
Def init(self, cmdLine | dlg fName)
{ init(self:ancestor, cmdLine);
  mainWindow := newMain(MDIFileWindow, "FileEditMenu", "MultiEdit", nil);
  setClassType(mainWindow,#FileChildMDI);
  show(mainWindow, CmdShow); 
  ^messageLoop(self);
}!!

/* Class Initialization */
