home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / ProcessMap / $Sources / CPProcessMap.Event.cpp < prev    next >
Encoding:
Text File  |  1995-04-28  |  9.1 KB  |  339 lines  |  [TEXT/MPCC]

  1. //----------------------------------------------------------------------------------------
  2. // UI Events protocol
  3. //----------------------------------------------------------------------------------------
  4.  
  5. #ifndef _PROCESSMAP_
  6. #include "CPProcessMap.h"
  7. #endif
  8.  
  9. //----------------------------------------------------------------------------------------
  10.  
  11. ODBoolean CPProcessMap::HandleEvent(Environment* ev, ODEventData* event,
  12.                                    ODFrame* frame, ODFacet* facet,
  13.                                    ODEventInfo* eventInfo)
  14. {
  15.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_HandleEvent
  16.     EnteringMethod("\pCPProcessMap::HandleEvent");
  17.     ODUnused(eventInfo);
  18.  
  19.     ODBoolean    tWasHandled = kODFalse;
  20.  
  21.     switch ( event->what )
  22.     {
  23.     case nullEvent:
  24.         if (::IsDialogEvent((EventRecord *)event))
  25.         {
  26.             short itemHit;
  27.             DialogPtr dialog;
  28.             tWasHandled = ::DialogSelect((EventRecord *)event, &dialog, &itemHit);
  29.             return tWasHandled;
  30.         }
  31.         tWasHandled = kODTrue;
  32.         if ( RefreshProcessMap() )
  33.             PrivInvalAllDisplayFrames(ev);
  34.         break;
  35.  
  36.     case mouseDown:
  37.         tWasHandled = this->PrivHandleMouseDown(ev, event, frame, facet);
  38.         break;
  39.  
  40.     case kODEvtMouseDownEmbedded:
  41.     case mouseUp:
  42.     case keyDown:
  43.     case autoKey:
  44.     case activateEvt:
  45.         tWasHandled = kODTrue;
  46.         break;
  47.         
  48.     case kODEvtMenu:
  49.         tWasHandled = this->PrivHandleMenuEvent(ev, frame, event );
  50.         break;
  51.         
  52.     default:
  53.         break;
  54.     }
  55.  
  56.     return tWasHandled;
  57. }
  58.  
  59. //----------------------------------------------------------------------------------------
  60.  
  61. void CPProcessMap::AdjustMenus(Environment* ev, ODFrame* frame)
  62. {
  63.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_AdjustMenus
  64.     EnteringMethod("\pCPProcessMap::AdjustMenus");
  65.     ODUnused(frame);
  66.  
  67.     Str63        aboutText;
  68.     ODIText*    odiText;
  69.  
  70.     fMenuBar->EnableCommand(ev, kODCommandViewAsWin, !frame->IsRoot(ev) );
  71.     fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, kODTrue);
  72.  
  73.     {
  74.         CUsingLibraryResources fil;
  75.         ::GetIndString(aboutText, kContentStringResID, kAboutTextID);
  76.     }
  77.  
  78.     ODScriptCode script = ::GetScriptManagerVariable(smSysScript);
  79.     ODLangCode lang = ::GetScriptVariable(script, smScriptLang);
  80.     odiText = CreateIText(script, lang, aboutText);
  81.     fMenuBar->SetItemString(ev, kODCommandAbout, odiText);
  82.     DisposeIText(odiText);
  83.  
  84. short sNum;
  85.     sNum = ::CountMItems(fMenu);
  86.     for(int i=0;i<sNum;i++)
  87.     {
  88.         ::DeleteMenuItem(fMenu, sNum-i);
  89.     }
  90.     for(i=0;i<sNumOfProcess;i++)
  91.         ::InsertMenuItem(fMenu, (StringPtr)aProcesses[i].pName, i);
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // CPProcessMap::PrivHandleMenuEvent
  96. //----------------------------------------------------------------------------------------
  97.  
  98. ODSession* gSession;
  99.  
  100. ODBoolean CPProcessMap::PrivHandleMenuEvent(Environment* ev, ODFrame* frame, ODEventData* event)
  101. {
  102.     EnteringMethod("\pCPProcessMap::PrivHandleMenuEvent");
  103.     ODUnused(frame);
  104.  
  105.     long    menuResult = event->message;
  106.     short    menu = HiWord(menuResult);
  107.     short    item = LoWord(menuResult);
  108.     short sCommand;
  109.  
  110.     if (menu) {
  111.  
  112.         switch( (sCommand=fMenuBar->GetCommand(ev, menu, item)) ) 
  113.         {
  114.         case kODCommandAbout:
  115.         {
  116.             CUsingLibraryResources fil;
  117.  
  118.             if (fSession->GetArbitrator(ev)->RequestFocus(ev, fModalFocus, frame))
  119.             {
  120.                 ::SetCursor(&ODQDGlobals.arrow);
  121.                 gSession = fSession;                // DialogFilter uses this!
  122.                 ModalFilterUPP modalFilter = NewModalFilterProc(MyDialogFilter);
  123.                 ::Alert(kProcessMapAboutBoxID, modalFilter);
  124.                 DisposeRoutineDescriptor(modalFilter);
  125.                 fSession->GetArbitrator(ev)->RelinquishFocus(ev, fModalFocus,frame);
  126.             }
  127.             else
  128.                 ::SysBeep(1);
  129.         }
  130.         break;
  131.  
  132.         case kODCommandClear:
  133.             break;
  134.  
  135.         case kODCommandViewAsWin:
  136.             this->Open(ev, frame);
  137.             break;
  138.  
  139.         case kODCommandGetPartInfo:
  140.             ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
  141.             fSession->GetInfo(ev)->ShowPartFrameInfo(ev, facets->First(ev), kODFalse);
  142.             break;
  143.  
  144.         default:
  145.             if ( kMenuID+1 <= sCommand && sCommand <= kMenuID+1+MAX_PROCESS )
  146.             {
  147.                 ::SetFrontProcess(&aProcesses[sCommand - kMenuID - 1].thePSN);
  148.                 break;
  149.             }
  150.             return kODFalse;
  151.         }
  152.     }
  153.  
  154.     return kODTrue;
  155. }
  156.  
  157. //------------------------------------------------------------------------------
  158. // CPProcessMap::PrivHandleMouseDown
  159. //------------------------------------------------------------------------------
  160.  
  161. ODBoolean CPProcessMap::PrivHandleMouseDown(Environment* ev, ODEventData* event,
  162.                                          ODFrame* frame, ODFacet* facet)
  163. {
  164.     EnteringMethod("\pCPProcessMap::PrivHandleMouseDown");
  165.  
  166.     ODBoolean handled = kODFalse;
  167.  
  168.     if (facet == kODNULL)        // Did we get a click outside a modal dialog? …
  169.     {
  170.         ::SysBeep(1);
  171.         return kODTrue;            // Return that click was handled.
  172.     }
  173.  
  174.     // Activate the window if it is not active…
  175.     if (! facet->GetWindow(ev)->IsActive(ev))
  176.     {
  177.         // select the window
  178.         facet->GetWindow(ev)->Select(ev);
  179.  
  180.         // typically you continue handling the event, if not, just return kODTrue
  181.         handled = kODTrue;
  182.         
  183.         // return kODTrue; // user needs to click twice to get something done
  184.     }
  185.  
  186.     // dialog events first
  187.     if (::IsDialogEvent((EventRecord *)event))
  188.     {
  189.         short        itemHit;
  190.         DialogPtr    dialog;
  191.  
  192.         handled = ::DialogSelect((EventRecord *)event, &dialog, &itemHit);
  193.         ODWindow* window = fSession->GetWindowState(ev)->GetODWindow(ev, dialog);
  194.         return handled;        // In preparation for more "if" cases to be added below.
  195.     }
  196.  
  197.     // get the mouse in local coordinates
  198.     ODWindow* odwnd = frame->GetWindow(ev);
  199.     ODPoint odPoint;
  200.     GetWindowPoint(odwnd, ev, event->where, &odPoint);
  201.  
  202.     // test for click in grow box, if appropriate
  203.     if (frame->IsRoot(ev))
  204.     {
  205.         WindowPtr wnd   = (WindowPtr)odwnd->GetPlatformWindow(ev);
  206.  
  207.         Rect r = wnd->portRect;
  208.         r.left = r.right  - 15;
  209.         r.top  = r.bottom - 15;
  210.         if (::PtInRect(odPoint.AsQDPoint(), &r)) {
  211.             ::SetRect(&r, 200, 200, 20000, 20000);
  212.             long newWindowSize = ::GrowWindow(wnd, event->where, &r);
  213.             ::SizeWindow(wnd, LoWord(newWindowSize), HiWord(newWindowSize), true);
  214.             odwnd->AdjustWindowShape(ev);
  215.             return kODTrue;
  216.         }
  217.     }
  218.  
  219.     if ( fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame) )
  220.     {
  221.         // Try to grab all of our foci…
  222.         this->FocusAcquired(ev, fSelectionFocus, frame);
  223.         this->FocusAcquired(ev, fMenuFocus, frame);
  224.         this->FocusAcquired(ev, fKeyFocus, frame);
  225.  
  226.     } else {
  227.         // We couldn't get focus we requested, so bail.
  228.         // Alternatively, parts of functionality can be disabled.
  229.         return kODFalse;
  230.     }
  231.  
  232.     // Handle clicks in used shape…
  233.     odPoint = facet->GetWindowContentTransform(ev, kODNULL)->InvertPoint(ev, &odPoint);
  234.  
  235.     ODShape*  usedShape = this->PrivGetUsedShape(ev, frame);
  236.     ODBoolean hit       = usedShape->ContainsPoint(ev, &odPoint);
  237.     usedShape->Release(ev);
  238.  
  239.     //if (hit)
  240.         handled = this->PrivUsedShapeHandleMouseDown(ev, event, frame, facet);
  241.  
  242.     return handled;
  243. }
  244.  
  245. //------------------------------------------------------------------------------
  246. // CPProcessMap::PrivUsedShapeHandleMouseDown
  247. //------------------------------------------------------------------------------
  248.  
  249. ODBoolean CPProcessMap::PrivUsedShapeHandleMouseDown(Environment* ev, ODEventData* event,
  250.                                          ODFrame* frame, ODFacet* facet)
  251. {
  252.     EnteringMethod("\pCPProcessMap::PrivUsedShapeHandleMouseDown");
  253.  
  254.     // Get the window and platform window (i.e. WindowPtr)…
  255.     ODWindow* odwnd = frame->GetWindow(ev);
  256.     ODPlatformWindow facetPort = odwnd->GetPlatformWindow(ev);
  257.  
  258.     // Get the mouse in window-local and facet-local coordinates…
  259.     ODPoint windowPoint;
  260.     GetWindowPoint(odwnd, ev, event->where, &windowPoint);
  261.     ODPoint facetPoint = 
  262.         facet->GetWindowContentTransform(ev, kODNULL)->InvertPoint(ev, &windowPoint);
  263.  
  264.     // Handle the click in whatever way is appropriate…
  265.     {
  266.         CFocus foc(ev, facet);
  267.  
  268.         Point        macPoint = facetPoint.AsQDPoint();
  269.         short    sBase, sCeil, sPos;
  270.         short   bias;
  271.         short width;
  272.  
  273.         if ( fHorizontal )
  274.         {
  275.             sBase = rctBar.left;
  276.             sCeil = rctBar.right;
  277.             sPos  = macPoint.h;
  278.             bias  = 1;
  279.             width = sCeil - sBase;
  280.         }
  281.         else
  282.         {
  283.             sBase = rctBar.bottom;
  284.             sCeil = rctBar.top;
  285.             sPos  = macPoint.v;
  286.             bias  = -1;
  287.             width = sBase - sCeil;
  288.         }
  289.  
  290.         if ( PtInRect(macPoint, &rctBar ) )
  291.         {
  292.         float f;
  293.  
  294.             f = width;
  295.             f*= lSystemHeap;
  296.             f/= lLogicalSize;
  297.             f*= bias;
  298.             if (    ( fHorizontal && sBase <= sPos && sPos <  sBase+f )
  299.                 ||    (!fHorizontal && sBase >  sPos && sPos >= sBase+f )
  300.             )
  301.             {
  302.                 DrawProcessName("\pSystem Heap", 0, lSystemHeap);
  303.                 return kODTrue;        // We handled the click.
  304.             }
  305.             for(int i=0;i<sNumOfProcess;i++)
  306.             {
  307.                 f = width;
  308.                 f*= aProcesses[i].lStartAddress;
  309.                 f/= lLogicalSize;
  310.                 f*= bias;
  311.                 if (  fHorizontal && sPos <= sBase+f ) continue;
  312.                 if ( !fHorizontal && sPos >  sBase+f ) continue;
  313.                 f = width;
  314.                 f*= aProcesses[i].lEndAddress;
  315.                 f/= lLogicalSize;
  316.                 f*= bias;
  317.                 if (  fHorizontal && sPos >= sBase+f ) continue;
  318.                 if ( !fHorizontal && sPos <  sBase+f ) continue;
  319.                 DrawProcessName((StringPtr)aProcesses[i].pName, aProcesses[i].lStartAddress,aProcesses[i].lEndAddress);
  320.                 return kODTrue;
  321.             }
  322.             f = width;
  323.             f*= lAboveBufPtr;
  324.             f/= lLogicalSize;
  325.             f*= bias;
  326.             if (    ( fHorizontal && sBase+f <= sPos && sPos <  sCeil)
  327.                 ||    (!fHorizontal && sBase+f >  sPos && sPos >= sCeil)
  328.             )
  329.             {
  330.                 DrawProcessName("\pAbove BufPtr",lAboveBufPtr, lLogicalSize);
  331.                 return kODTrue;        // We handled the click.
  332.             }
  333.             DrawProcessName("\pFREE BLOCK",0,0);
  334.         }
  335.     }
  336.  
  337.     return kODTrue;        // We handled the click.
  338. }
  339.