home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-21 | 6.5 KB | 269 lines | [TEXT/CWIE] |
- #include "ocheaders.h"
- #include "BDDISPIDs.h"
- #include "CButton2Control.h"
- #include "BDConsts.h"
- #include "BDUtils.h"
- #include "FnAssert.h"
- #include "dispatch.h"
- #include <LArray.h>
- #include "CConnectionPoint.h"
- #include "CCPContainer.h"
- //#include "CButtonError.h"
- #include <iterator.h>
- #include <ctype.h>
- #include <math.h>
- #include <stdio.h>
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::CButtonControl
- //
-
- CButtonControl::CButtonControl(void)
- {
- mButtonControl = NULL;
- mDoTracking = false;
-
- mCaption = NULL;
- mID[0] = 0;
-
- // CBaseEventServer setup
- AddOutGoingInterface(IID_IDoMenuEvents);
- SetUpConnectionPoints();
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::~CButtonControl
- //
-
- CButtonControl::~CButtonControl(void)
- {
- if ( mCaption )
- {
- delete [] mCaption;
- mCaption = NULL;
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::IUnknown::QueryInterface
- //
- // Returns a pointer to the specified interface on a component to which a
- // client currently holds an interface pointer.
- //
-
- STDMETHODIMP
- CButtonControl::QueryInterface(REFIID refID, void** obj)
- {
- HRESULT result = E_NOINTERFACE;
-
- result = CBaseEventServer::QueryInterface(refID, obj);
- if ( result == S_OK )
- goto labelExit;
-
- result = CBaseControl::QueryInterface(refID, obj);
- if ( result == S_OK )
- goto labelExit;
-
- labelExit:
- return result;
- /*
- OBSOLETE!
-
- if ( RefID == IID_IDoMenuEvents ) // an outgoing interface
- {
- *Obj = (void*) (IDoMenuEvents*) this;
- AddRef();
-
- return ResultFromScode(S_OK);
- }
- else
- return CBaseControl::QueryInterface(RefID, Obj);
- */
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::IInProcObject::Draw
- //
-
- STDMETHODIMP
- CButtonControl::Draw(THIS_ DrawContext* Context)
- {
- if (Context->DrawAspect != DVASPECT_CONTENT)
- return ResultFromScode(DV_E_DVASPECT);
-
- if ( mButtonControl )
- UpdateButtonControl();
- else
- CreateButtonControl(((WindowPtr)Context->Port), &(Context->Location));
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::IControl::DoMouse
- //
-
- STDMETHODIMP
- CButtonControl::DoMouse(THIS_ MouseEventType inMouseET, PlatformEvent* inEvent)
- {
- switch (inMouseET)
- {
- case MouseDown:
- {
- if ( mDoTracking )
- {
- // NOTE: any handlers won't actually get the mouse down event
- // until after we're done tracking, because it's asychronous.
- FireEvent(IID_IStandardEvents, DISPID_MOUSEDOWN, inEvent);
- if ( Track(inEvent) == inButton )
- FireEvent(IID_IStandardEvents, DISPID_MOUSEUP, inEvent);
- }
- else
- FireEvent(IID_IDoMenuEvents, DISPID_POPUP, inEvent);
-
- break;
- }
-
- case MouseUp:
- // in case we're supporting mouse tracking, don't do anything for
- // a mouse up event, since we handle it with the mouse down.
- if ( mDoTracking )
- break;
- else // of course, we don't do anything otherwise right now, either.
- break;
-
- }
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::IPersistPropertyBag::Load
- //
-
- STDMETHODIMP
- CButtonControl::Load(IPropertyBag* propertyBag, IErrorLog* errorLog)
- {
- char propertyString[Str255BufferLength];
-
- // try to load in each property. if we can't get it, then leave
- // things at the default.
-
- // The name of the button
- if ( ::LoadPropertyString(propertyBag, "caption", propertyString, Str255StringLength, errorLog) )
- {
- if ( mCaption )
- {
- delete [] mCaption;
- mCaption = NULL;
- }
-
- mCaption = (char *) new char[Str255BufferLength];
- strcpy(mCaption, propertyString);
- }
-
- // do we want to track the mouse in the standard Mac way?
- if ( ::LoadPropertyString(propertyBag, "tracking", propertyString, Str255BufferLength, errorLog) )
- {
- if ( !strcmp(propertyString, "1") )
- mDoTracking = true;
- }
-
- // Eventually we may be able to inherit this from CBaseControl, or
- // an as-yet undefined base class that simply loads the ID paramter.
- // When the framework supports GetID instead of GetName in IControl, then
- // mID may change to something else, as well.
- if ( ::LoadPropertyString(propertyBag, "sourceid", propertyString, Str255StringLength, errorLog) )
- {
- strcpy((char*)(&mID[1]), propertyString);
- mID[0] = strlen(propertyString);
- }
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CEventSender::FireOneEvent
- //
-
- STDMETHODIMP
- CButtonControl::FireOneEvent(REFIID RefID, long EventID, IUnknown* EventTarget, PlatformEvent* Event)
- {
- IDoMenuEvents* popTarget = (IDoMenuEvents*) EventTarget;
- IUnknown* unk;
-
- this->QueryInterface(IID_IUnknown, (void**) &unk);
-
- switch ( EventID )
- {
- case DISPID_POPUP:
- popTarget->Popup(unk, Event);
- break;
- }
-
- return ResultFromScode(S_OK);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::CreateButtonControl
- //
- void CButtonControl::CreateButtonControl(const WindowPtr window, const Rect * ctrlRect)
- {
- c2pstr(mCaption);
-
- mButtonControl = ::NewControl ( window, // the grafport
- ctrlRect, // where to draw it
- (StringPtr)mCaption, // button name/title
- true, // it's visible
- 0, // initial value - ignored
- 0, // min value - ignored
- 0, // max value - ignored
- pushButProc, // it's a button
- 0); // user-defined refcon -- not used
- ASSERT(mButtonControl != NULL, "NULL Control");
-
- p2cstr((StringPtr)mCaption);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::Track
- //
-
- short CButtonControl::Track(PlatformEvent* Event)
- {
- short releasePoint = 0;
-
- ASSERT(Event != NULL, "NULL event pointer!");
-
- // We need to Acquire here, so that TrackControl is focused
- DrawContext Context = {(PortType) 0};
- mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context);
-
- if ( mButtonControl )
- releasePoint = ::TrackControl(mButtonControl, Event->where, NULL);
-
- mContainerSiteP->ReleaseContext(&Context);
-
- return releasePoint;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CButtonControl::UpdateButtonControl
- //
-
- void CButtonControl::UpdateButtonControl(void)
- {
- if ( mButtonControl )
- ::Draw1Control(mButtonControl);
- }
-