home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-28 | 9.1 KB | 339 lines | [TEXT/MPCC] |
- //----------------------------------------------------------------------------------------
- // UI Events protocol
- //----------------------------------------------------------------------------------------
-
- #ifndef _PROCESSMAP_
- #include "CPProcessMap.h"
- #endif
-
- //----------------------------------------------------------------------------------------
-
- ODBoolean CPProcessMap::HandleEvent(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet,
- ODEventInfo* eventInfo)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_HandleEvent
- EnteringMethod("\pCPProcessMap::HandleEvent");
- ODUnused(eventInfo);
-
- ODBoolean tWasHandled = kODFalse;
-
- switch ( event->what )
- {
- case nullEvent:
- if (::IsDialogEvent((EventRecord *)event))
- {
- short itemHit;
- DialogPtr dialog;
- tWasHandled = ::DialogSelect((EventRecord *)event, &dialog, &itemHit);
- return tWasHandled;
- }
- tWasHandled = kODTrue;
- if ( RefreshProcessMap() )
- PrivInvalAllDisplayFrames(ev);
- break;
-
- case mouseDown:
- tWasHandled = this->PrivHandleMouseDown(ev, event, frame, facet);
- break;
-
- case kODEvtMouseDownEmbedded:
- case mouseUp:
- case keyDown:
- case autoKey:
- case activateEvt:
- tWasHandled = kODTrue;
- break;
-
- case kODEvtMenu:
- tWasHandled = this->PrivHandleMenuEvent(ev, frame, event );
- break;
-
- default:
- break;
- }
-
- return tWasHandled;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPProcessMap::AdjustMenus(Environment* ev, ODFrame* frame)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_AdjustMenus
- EnteringMethod("\pCPProcessMap::AdjustMenus");
- ODUnused(frame);
-
- Str63 aboutText;
- ODIText* odiText;
-
- fMenuBar->EnableCommand(ev, kODCommandViewAsWin, !frame->IsRoot(ev) );
- fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, kODTrue);
-
- {
- CUsingLibraryResources fil;
- ::GetIndString(aboutText, kContentStringResID, kAboutTextID);
- }
-
- ODScriptCode script = ::GetScriptManagerVariable(smSysScript);
- ODLangCode lang = ::GetScriptVariable(script, smScriptLang);
- odiText = CreateIText(script, lang, aboutText);
- fMenuBar->SetItemString(ev, kODCommandAbout, odiText);
- DisposeIText(odiText);
-
- short sNum;
- sNum = ::CountMItems(fMenu);
- for(int i=0;i<sNum;i++)
- {
- ::DeleteMenuItem(fMenu, sNum-i);
- }
- for(i=0;i<sNumOfProcess;i++)
- ::InsertMenuItem(fMenu, (StringPtr)aProcesses[i].pName, i);
- }
-
- //----------------------------------------------------------------------------------------
- // CPProcessMap::PrivHandleMenuEvent
- //----------------------------------------------------------------------------------------
-
- ODSession* gSession;
-
- ODBoolean CPProcessMap::PrivHandleMenuEvent(Environment* ev, ODFrame* frame, ODEventData* event)
- {
- EnteringMethod("\pCPProcessMap::PrivHandleMenuEvent");
- ODUnused(frame);
-
- long menuResult = event->message;
- short menu = HiWord(menuResult);
- short item = LoWord(menuResult);
- short sCommand;
-
- if (menu) {
-
- switch( (sCommand=fMenuBar->GetCommand(ev, menu, item)) )
- {
- case kODCommandAbout:
- {
- CUsingLibraryResources fil;
-
- if (fSession->GetArbitrator(ev)->RequestFocus(ev, fModalFocus, frame))
- {
- ::SetCursor(&ODQDGlobals.arrow);
- gSession = fSession; // DialogFilter uses this!
- ModalFilterUPP modalFilter = NewModalFilterProc(MyDialogFilter);
- ::Alert(kProcessMapAboutBoxID, modalFilter);
- DisposeRoutineDescriptor(modalFilter);
- fSession->GetArbitrator(ev)->RelinquishFocus(ev, fModalFocus,frame);
- }
- else
- ::SysBeep(1);
- }
- break;
-
- case kODCommandClear:
- break;
-
- case kODCommandViewAsWin:
- this->Open(ev, frame);
- break;
-
- case kODCommandGetPartInfo:
- ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
- fSession->GetInfo(ev)->ShowPartFrameInfo(ev, facets->First(ev), kODFalse);
- break;
-
- default:
- if ( kMenuID+1 <= sCommand && sCommand <= kMenuID+1+MAX_PROCESS )
- {
- ::SetFrontProcess(&aProcesses[sCommand - kMenuID - 1].thePSN);
- break;
- }
- return kODFalse;
- }
- }
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // CPProcessMap::PrivHandleMouseDown
- //------------------------------------------------------------------------------
-
- ODBoolean CPProcessMap::PrivHandleMouseDown(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet)
- {
- EnteringMethod("\pCPProcessMap::PrivHandleMouseDown");
-
- ODBoolean handled = kODFalse;
-
- if (facet == kODNULL) // Did we get a click outside a modal dialog? …
- {
- ::SysBeep(1);
- return kODTrue; // Return that click was handled.
- }
-
- // Activate the window if it is not active…
- if (! facet->GetWindow(ev)->IsActive(ev))
- {
- // select the window
- facet->GetWindow(ev)->Select(ev);
-
- // typically you continue handling the event, if not, just return kODTrue
- handled = kODTrue;
-
- // return kODTrue; // user needs to click twice to get something done
- }
-
- // dialog events first
- if (::IsDialogEvent((EventRecord *)event))
- {
- short itemHit;
- DialogPtr dialog;
-
- handled = ::DialogSelect((EventRecord *)event, &dialog, &itemHit);
- ODWindow* window = fSession->GetWindowState(ev)->GetODWindow(ev, dialog);
- return handled; // In preparation for more "if" cases to be added below.
- }
-
- // get the mouse in local coordinates
- ODWindow* odwnd = frame->GetWindow(ev);
- ODPoint odPoint;
- GetWindowPoint(odwnd, ev, event->where, &odPoint);
-
- // test for click in grow box, if appropriate
- if (frame->IsRoot(ev))
- {
- WindowPtr wnd = (WindowPtr)odwnd->GetPlatformWindow(ev);
-
- Rect r = wnd->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- if (::PtInRect(odPoint.AsQDPoint(), &r)) {
- ::SetRect(&r, 200, 200, 20000, 20000);
- long newWindowSize = ::GrowWindow(wnd, event->where, &r);
- ::SizeWindow(wnd, LoWord(newWindowSize), HiWord(newWindowSize), true);
- odwnd->AdjustWindowShape(ev);
- return kODTrue;
- }
- }
-
- if ( fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame) )
- {
- // Try to grab all of our foci…
- this->FocusAcquired(ev, fSelectionFocus, frame);
- this->FocusAcquired(ev, fMenuFocus, frame);
- this->FocusAcquired(ev, fKeyFocus, frame);
-
- } else {
- // We couldn't get focus we requested, so bail.
- // Alternatively, parts of functionality can be disabled.
- return kODFalse;
- }
-
- // Handle clicks in used shape…
- odPoint = facet->GetWindowContentTransform(ev, kODNULL)->InvertPoint(ev, &odPoint);
-
- ODShape* usedShape = this->PrivGetUsedShape(ev, frame);
- ODBoolean hit = usedShape->ContainsPoint(ev, &odPoint);
- usedShape->Release(ev);
-
- //if (hit)
- handled = this->PrivUsedShapeHandleMouseDown(ev, event, frame, facet);
-
- return handled;
- }
-
- //------------------------------------------------------------------------------
- // CPProcessMap::PrivUsedShapeHandleMouseDown
- //------------------------------------------------------------------------------
-
- ODBoolean CPProcessMap::PrivUsedShapeHandleMouseDown(Environment* ev, ODEventData* event,
- ODFrame* frame, ODFacet* facet)
- {
- EnteringMethod("\pCPProcessMap::PrivUsedShapeHandleMouseDown");
-
- // Get the window and platform window (i.e. WindowPtr)…
- ODWindow* odwnd = frame->GetWindow(ev);
- ODPlatformWindow facetPort = odwnd->GetPlatformWindow(ev);
-
- // Get the mouse in window-local and facet-local coordinates…
- ODPoint windowPoint;
- GetWindowPoint(odwnd, ev, event->where, &windowPoint);
- ODPoint facetPoint =
- facet->GetWindowContentTransform(ev, kODNULL)->InvertPoint(ev, &windowPoint);
-
- // Handle the click in whatever way is appropriate…
- {
- CFocus foc(ev, facet);
-
- Point macPoint = facetPoint.AsQDPoint();
- short sBase, sCeil, sPos;
- short bias;
- short width;
-
- if ( fHorizontal )
- {
- sBase = rctBar.left;
- sCeil = rctBar.right;
- sPos = macPoint.h;
- bias = 1;
- width = sCeil - sBase;
- }
- else
- {
- sBase = rctBar.bottom;
- sCeil = rctBar.top;
- sPos = macPoint.v;
- bias = -1;
- width = sBase - sCeil;
- }
-
- if ( PtInRect(macPoint, &rctBar ) )
- {
- float f;
-
- f = width;
- f*= lSystemHeap;
- f/= lLogicalSize;
- f*= bias;
- if ( ( fHorizontal && sBase <= sPos && sPos < sBase+f )
- || (!fHorizontal && sBase > sPos && sPos >= sBase+f )
- )
- {
- DrawProcessName("\pSystem Heap", 0, lSystemHeap);
- return kODTrue; // We handled the click.
- }
- for(int i=0;i<sNumOfProcess;i++)
- {
- f = width;
- f*= aProcesses[i].lStartAddress;
- f/= lLogicalSize;
- f*= bias;
- if ( fHorizontal && sPos <= sBase+f ) continue;
- if ( !fHorizontal && sPos > sBase+f ) continue;
- f = width;
- f*= aProcesses[i].lEndAddress;
- f/= lLogicalSize;
- f*= bias;
- if ( fHorizontal && sPos >= sBase+f ) continue;
- if ( !fHorizontal && sPos < sBase+f ) continue;
- DrawProcessName((StringPtr)aProcesses[i].pName, aProcesses[i].lStartAddress,aProcesses[i].lEndAddress);
- return kODTrue;
- }
- f = width;
- f*= lAboveBufPtr;
- f/= lLogicalSize;
- f*= bias;
- if ( ( fHorizontal && sBase+f <= sPos && sPos < sCeil)
- || (!fHorizontal && sBase+f > sPos && sPos >= sCeil)
- )
- {
- DrawProcessName("\pAbove BufPtr",lAboveBufPtr, lLogicalSize);
- return kODTrue; // We handled the click.
- }
- DrawProcessName("\pFREE BLOCK",0,0);
- }
- }
-
- return kODTrue; // We handled the click.
- }
-