home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-21 | 4.7 KB | 201 lines | [TEXT/CWIE] |
- #include "ocheaders.h"
- #include "BDDISPIDs.h"
- #include "CPopupMenuControl.h"
- #include "CMenuControl.h"
- #include "CPopupMenuTracker.h"
- #include "BDUtils.h"
- #include "Colors.h"
- #include "FnAssert.h"
- #include "dispatch.h"
- #include <LArray.h>
- #include <LArrayIterator.h>
- #include "CConnectionPoint.h"
- #include "CCPContainer.h"
- #include <iterator.h>
- #include <ctype.h>
- #include <math.h>
- #include <stdio.h>
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Constants
- //
-
- const Int32 DefaultIdleTicks = 60;
- const Uint32 DefaultIdleRefCon = 0;
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // class statics
- //
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::CMenuControl
- //
-
- CMenuControl::CMenuControl(void)
- {
- mCaption = NULL;
-
- SetOriginatorName("Menu");
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::~CMenuControl
- //
-
- CMenuControl::~CMenuControl(void)
- {
- if ( mCaption )
- {
- delete [] mCaption;
- mCaption = NULL;
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::IInProcObject::Draw
- //
-
- STDMETHODIMP
- CMenuControl::Draw(DrawContext * context)
- {
- ASSERT((context != NULL), "NULL draw context!");
-
- if (context->DrawAspect != DVASPECT_CONTENT)
- return ResultFromScode(DV_E_DVASPECT);
-
- SetText(context, mCaption, kDontRedraw);
- Draw3D(context);
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::IInProcObject::DoEvent
- //
-
- STDMETHODIMP
- CMenuControl::DoMouse(MouseEventType inMouseET, PlatformEvent* inEvent)
- {
- DrawContext context = {(PortType) 0};
- mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &context);
-
- switch (inMouseET)
- {
- case MouseDown:
- {
- SetTextColor(&context, RGB_RED, kDontRedraw);
- SetState(&context, rstDepressed, kRedraw);
-
- Point menuLocation;
- GetMenuLocation(context, &menuLocation);
- CPopupMenuTracker thePopup(this, mMenuHandle, 0);
- thePopup.TrackMouse(menuLocation);
- thePopup.GetCurrentItem(&mItemSelected);
- SetTextColor(&context, RGB_BLACK, kDontRedraw);
- SetState(&context, rstNominal, kRedraw);
-
- mContainerSiteP->ReleaseContext(&context);
-
- if ( mItemSelected.itemNumber != 0 )
- FireEvent(IID_IDidMenuEvents, DISPID_CLICK, inEvent);
-
- break;
- }
-
- case MouseEnter:
- {
- SetTextColor(&context, RGB_RED, kDontRedraw);
- SetState(&context, rstGreen, kRedraw);
- mContainerSiteP->ReleaseContext(&context);
-
- break;
- }
-
- case MouseLeave:
- {
- SetTextColor(&context, RGB_BLACK, kDontRedraw);
- SetState(&context, rstNominal, kRedraw);
- mContainerSiteP->ReleaseContext(&context);
-
- break;
- }
-
- default:
- mContainerSiteP->ReleaseContext(&context);
- break;
-
- }
-
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::IPersistPropertyBag::Load
- //
-
- STDMETHODIMP
- CMenuControl::Load(IPropertyBag* propertyBag, IErrorLog* errorLog)
- {
- CPopupMenuControl::Load(propertyBag, errorLog);
-
- char propertyString[Str255BufferLength];
-
- if ( ::LoadPropertyString(propertyBag, "caption", propertyString, Str255StringLength, errorLog) )
- {
- if ( mCaption )
- {
- delete [] mCaption;
- mCaption = NULL;
- }
-
- mCaption = (char *) new char[Str255BufferLength];
- strcpy(mCaption, propertyString);
-
- SetOriginatorName(mCaption);
- }
-
- // If we successfully loaded a mCaption, then set the source name to the
- // same thing. The source name is used to handle the case where we want to pass
- // the source of a Popup event through to another event client. If the
- // CPopupMenuControl generates events itself (as when it's subclassed by
- // CMenuControl), then the source is this object itself.
- if ( mCaption )
- SetSourceName(mCaption);
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::IDoMenuEvents::Popup
- //
-
- STDMETHODIMP
- CMenuControl::Popup(IUnknown* /*Source*/, PlatformEvent* /*Event*/)
- {
- // We're not expecting anyone to be sending us Popup messages.
-
- return ResultFromScode(E_FAIL);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CMenuControl::GetMenuLocation
- //
- void CMenuControl::GetMenuLocation(const DrawContext & context, Point * menuLocation)
- {
- ASSERT(menuLocation != NULL, "NULL parameter!");
-
- menuLocation->v = context.Location.bottom + 1;
- menuLocation->h = context.Location.left;
- ::LocalToGlobal(menuLocation);
- }
-