home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-22 | 26.8 KB | 1,034 lines | [TEXT/CWIE] |
- // =================================================================================
- //
- // CButtonControl.cpp ©1996 Microsoft Corporation All rights reserved.
- //
- // =================================================================================
-
- #include "ocheaders.h"
- #include <math.h>
- #include <PlatformControlGuid.h>
- #include "CConnectionPoint.h"
- #include "CCPContainer.h"
- #include "CButtonControl.h"
-
- static pascal void ScrollBarActionProc(ControlRef theControl, ControlPartCode partCode);
-
- #pragma mark === CButtonControl::Constructors & Destructors ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::CButtonControl
- //=--------------------------------------------------------------------------=
-
- CButtonControl::CButtonControl(void) : CBaseControl()
- {
- // mBounds.top = mBounds.left = 0;
- // mBounds.bottom = mBounds.right = 25;
- *mID = 0;
- *mTitle = 0;
- mRefCon = (Int32) this;
- mCurrentValue = 0;
- mMinValue = 0;
- mMaxValue = 1;
- mControlType = PushButtonType;
- mPageDistance = 2;
- mActive = true;
- mVisible = true;
-
- // Create the new connection point container object
- CCPContainer* containerObj = new CCPContainer(1);
-
- // Snag the interface pointer
- if ( containerObj )
- containerObj->QueryInterface(IID_IConnectionPointContainer, &mCPContainerP);
-
- // if we have a container object, allocate the connection points
- if ( mCPContainerP )
- // We support 1 connection point
- containerObj->AddConnectionPoint(IID_IPlatformControlListener);
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::~CButtonControl
- //=--------------------------------------------------------------------------=
-
- CButtonControl::~CButtonControl()
- {
- }
-
-
- #pragma mark === CButtonControl::IUnknown methods ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IUnknown::QueryInterface::
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::QueryInterface(REFIID inRefID, void** outObj)
- {
- if ( inRefID == IID_IPlatformControl )
- {
- *outObj = (void*) (IPlatformControl*) this;
- AddRef();
-
- return S_OK;
- }
- else
- return CBaseControl::QueryInterface(inRefID, outObj);
- }
-
-
- #pragma mark === CButtonControl::IControl methods ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IControl::GetID
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetID(Int32 inBufferSize, Char8* outID)
- {
- if (*mID)
- {
- if (*mID < inBufferSize)
- inBufferSize = *mID;
- ::BlockMove(mID + 1, outID, inBufferSize);
- *(outID + inBufferSize) = 0;
- }
- else
- return CBaseControl::GetID(inBufferSize, outID);
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IControl::Draw
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::Draw( DrawContext* inContext)
- {
- if (inContext->DrawAspect != DVASPECT_CONTENT)
- return DV_E_DVASPECT;
-
- DrawMe((CButtonContextInfo*)GetContextInfoByID(inContext->ContextID), inContext);
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IControl::DoMouse
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::DoMouse(MouseEventType inMouseET, PlatformEvent* inEvent)
- {
- ErrorCode theResult = S_FALSE;
-
- switch (inMouseET)
- {
- case MouseUp:
- DrawAllContexts();
- theResult = S_OK;
- break;
-
- case MouseDown:
- theResult = DoMouseDown(inEvent);
- break;
- default:
- break;
- }
-
- return theResult;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IControl::DoActivate
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::DoActivate(ActivateEventType inActiveET, UInt32 inContextID, PlatformEvent* inEvent)
- {
- #pragma unused (inEvent)
- Boolean8 Redraw = false;
- CButtonContextInfo* ContextInfo = (CButtonContextInfo*)GetContextInfoByID(inContextID);
- ControlRef theControl = ContextInfo->GetControlRef();
-
- if (mActive && (inActiveET == WindowDeactivate || inActiveET == AppDeactivate))
- {
- ::HidePen();
- ::HiliteControl(theControl, kControlInactivePart);
- ::ShowPen();
- Redraw = true;
- }
- else if (mActive && inActiveET == WindowActivate)
- {
- ::HidePen();
- ::HiliteControl(theControl, kControlNoPart);
- ::ShowPen();
- Redraw = true;
- }
-
- if (Redraw)
- {
- DrawContext Context = { BeginPortType };
- if (mContainerSiteP->AcquireContext(inContextID, &Context) == S_OK)
- {
- DrawMe(ContextInfo, &Context);
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
- return S_OK;
- }
-
-
- #pragma mark === CButtonControl::IPersistPropertyBag methods ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPersistPropertyBag::Load
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::Load(IPropertyBag* PropertyBag, IErrorLog* ErrorLog)
- {
- ControlPropertyType SetProps = EmptyControlPropertyType;
- ErrorCode ECode = S_OK;
- Int32 i;
- PlatformPoint PrevSize = mSize;
- VARIANT v;
-
- v.vt = VT_BSTR;
- v.bstrVal = NULL;
-
- CBaseControl::Load(PropertyBag, ErrorLog);
-
- if (mSize.v != PrevSize.v || mSize.h != PrevSize.h)
- SetProps = ControlPropertyType(SetProps | SizeControlProperty);
-
- if (PropertyBag->Read("ctype", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- Char8 c = *(v.bstrVal + sizeof(Uint32));
-
- switch (c)
- {
- case 's':
- case 'S':
- mControlType = ScrollBarType;
- mMaxValue = 32767;
- break;
- case 'r':
- case 'R':
- mControlType = RadioButtonType;
- break;
- case 'c':
- case 'C':
- mControlType = CheckBoxType;
- break;
- case 'p':
- case 'P':
- default:
- // the control defaults to a push button
- mControlType = PushButtonType;
- break;
- }
- CoTaskMemFree(v.bstrVal);
- SetProps = ControlPropertyType(SetProps | TypeControlProperty);
- }
-
- if (PropertyBag->Read("max", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- ::StringToNum((Uchar8*)v.bstrVal + sizeof(Uint32) - 1, &i);
- mMaxValue = i;
- CoTaskMemFree(v.bstrVal);
- SetProps = ControlPropertyType(SetProps | MaxValueControlProperty);
- }
-
- if (PropertyBag->Read("min", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- ::StringToNum((Uchar8*)v.bstrVal + sizeof(Uint32) - 1, &i);
- mMinValue = i;
- CoTaskMemFree(v.bstrVal);
- SetProps = ControlPropertyType(SetProps | MinValueControlProperty);
- }
-
- if (PropertyBag->Read("start", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- ::StringToNum((Uchar8*)v.bstrVal + sizeof(Uint32) - 1, &i);
- mCurrentValue = i;
- CoTaskMemFree(v.bstrVal);
- SetProps = ControlPropertyType(SetProps | ValueControlProperty);
- }
-
- if (PropertyBag->Read("title", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- Int16 NameLen = *((Uint32*) v.bstrVal);
-
- if (NameLen > 255)
- NameLen = 255;
- ::BlockMove(v.bstrVal + sizeof(Uint32), mTitle + 1, NameLen);
- *mTitle = NameLen;
- CoTaskMemFree(v.bstrVal);
- SetProps = ControlPropertyType(SetProps | TitleControlProperty);
- }
-
- if (PropertyBag->Read("visible", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- Char8 c = *(v.bstrVal + sizeof(Uint32));
-
- if (c == 'F' || c == 'f')
- mVisible = false;
- else
- mVisible = true;
-
- SetProps = ControlPropertyType(SetProps | VisibleControlProperty);
- }
-
- TouchAllContexts(SetProps);
-
- return ECode;
- }
-
-
- #pragma mark === CButtonControl::CBaseControl methods ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::CBaseControl::NewContext
- //=--------------------------------------------------------------------------=
-
- CBaseContextInfo*
- CButtonControl::NewContext(Uint32 inContextID)
- {
- CButtonContextInfo* NewContextInfo = new CButtonContextInfo(this, inContextID);
-
- return NewContextInfo;
- }
-
-
- #pragma mark === CButtonControl methods ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::CBaseControl::NewContext
- //=--------------------------------------------------------------------------=
-
- void
- CButtonControl::TouchAllContexts(ControlPropertyType PropertyType)
- {
- CButtonContextInfo* ContextInfo;
- Int16 Index = 1;
-
- while ((ContextInfo = (CButtonContextInfo*)GetContextInfoByIndex(Index++)) != NULL)
- {
- ControlRef theControl = ContextInfo->GetControlRef();
- DrawContext Context = { BeginPortType };
-
- if (!theControl || PropertyType & TypeControlProperty)
- ContextInfo->MakePlatformControl();
- else if (mContainerSiteP->AcquireContext(ContextInfo->GetContextID(), &Context) == S_OK)
- {
- ::HidePen(); // keep the changes from drawing until we are done
-
- if (PropertyType & SizeControlProperty)
- ::SizeControl(theControl, mSize.h, mSize.v);
-
- if (PropertyType & VisibleControlProperty)
- {
- if (mVisible)
- ::ShowControl(theControl);
- else
- ::HideControl(theControl);
- }
-
- if (PropertyType & TitleControlProperty)
- ::SetControlTitle(theControl, mTitle);
-
- if (PropertyType & MinValueControlProperty)
- ::SetControlMinimum(theControl, mMinValue);
-
- if (PropertyType & MaxValueControlProperty)
- ::SetControlMaximum(theControl, mMaxValue);
-
- if (PropertyType & ValueControlProperty)
- ::SetControlValue(theControl, mCurrentValue);
-
- ::ShowPen(); // okay to draw now
-
- DrawMe(ContextInfo, &Context);
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::DoMouseDown
- //=--------------------------------------------------------------------------=
-
- ErrorCode
- CButtonControl::DoMouseDown(PlatformEvent* inEvent)
- {
- Boolean8 DoRelease = true;
- DrawContext Context = { BeginPortType };
- Point Origin, COrigin;
-
- if (mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context) == S_OK)
- {
- CButtonContextInfo* ContextInfo = (CButtonContextInfo*)mActiveContext;
- if (ContextInfo)
- {
- ControlRef WhichControl;
- ControlPartCode PartCode;
- Point COrigin = ContextInfo->GetOrigin();
- Point LocalPoint = inEvent->where;
-
- Origin = *(Point*)(&Context.Port->portRect);
- COrigin = ContextInfo->GetOrigin();
- ::SetOrigin(Origin.h - COrigin.h, Origin.v - COrigin.v);
- ::GlobalToLocal(&LocalPoint);
- ::OffsetRgn(Context.Port->clipRgn, -COrigin.h, -COrigin.v);
-
- if ((PartCode = ::FindControl(LocalPoint, Context.Port, &WhichControl)) != 0)
- {
- Boolean8 Redraw = false;
- Boolean8 NotifyListeners;
- ControlActionUPP ActionProc;
- Int16 OldValue = ::GetControlValue(ContextInfo->GetControlRef());
- Int16 NewValue;
-
- switch (mControlType)
- {
- case ScrollBarType:
- switch (PartCode)
- {
- case kControlPageUpPart:
- case kControlPageDownPart:
- // at this point it would be good to ask the target what its page size is
- // and put that into mJumpDistance
- // intentional fall through
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- ActionProc = NewControlActionProc(ScrollBarActionProc);
- break;
- case kControlIndicatorPart:
- default:
- ActionProc = NULL;
- break;
- }
- break;
- case PushButtonType:
- case CheckBoxType:
- case RadioButtonType:
- default:
- ActionProc = NULL;
- break;
- }
-
- NotifyListeners = ::TrackControl(ContextInfo->GetControlRef(), LocalPoint, ActionProc);
- if (ActionProc)
- ::DisposeRoutineDescriptor(ActionProc);
-
- switch (mControlType)
- {
- case CheckBoxType:
- case RadioButtonType:
- if (NotifyListeners)
- {
- NewValue = OldValue ? 0 : 1;
- Redraw = true;
- }
- break;
- case ScrollBarType:
- NewValue = ::GetControlValue(ContextInfo->GetControlRef());
- break;
- case PushButtonType:
- default:
- break;
- }
-
- // tell all sibling controls about the value change
- if (NewValue != OldValue)
- {
- DoRelease = false;
- mCurrentValue = NewValue;
- NotifyListeners = true;
- ::OffsetRgn(Context.Port->clipRgn, COrigin.h, COrigin.v);
- ::SetOrigin(Origin.h, Origin.v);
- mContainerSiteP->ReleaseContext(&Context);
- TouchAllContexts(ValueControlProperty);
- }
-
- // tell all the listeners that there was a click or value change
- if (NotifyListeners)
- TellListeners(NewValue);
- }
- }
- #if BE_STRICT
- else
- DebugStr("\pCButtonControl::DoMouse - Unrecognized context!");
- #endif // BE_STRICT
- if (DoRelease)
- {
- ::OffsetRgn(Context.Port->clipRgn, COrigin.h, COrigin.v);
- ::SetOrigin(Origin.h, Origin.v);
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
- #if BE_STRICT
- else
- DebugStr("\pCButtonControl::DoMouse - Couldn't acquire default context");
- #endif // BE_STRICT
- DrawAllContexts();
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::DrawAllContexts
- //=--------------------------------------------------------------------------=
-
- void
- CButtonControl::DrawAllContexts(void)
- {
- DrawContext Context = {BeginPortType};
- Int32 Index = 1;
- CButtonContextInfo* ContextInfo;
-
- while((ContextInfo = (CButtonContextInfo*)GetContextInfoByIndex(Index++)) != NULL)
- if (mContainerSiteP->AcquireContext(ContextInfo->GetContextID(), &Context) == S_OK)
- {
- DrawMe(ContextInfo, &Context);
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::DrawMe
- //=--------------------------------------------------------------------------=
-
- void
- CButtonControl::DrawMe(CButtonContextInfo* inContextInfoP, DrawContext* inContextP)
- {
- if (inContextInfoP->GetControlRef()) // if the context has a real control then just draw it
- {
- Point Origin = *(Point*)(&inContextP->Port->portRect);
- Point COrigin = inContextInfoP->GetOrigin();
-
- ::SetOrigin(Origin.h - COrigin.h, Origin.v - COrigin.v);
- ::OffsetRgn(inContextP->Port->clipRgn, -COrigin.h, -COrigin.v);
-
- ::DrawOneControl(inContextInfoP->GetControlRef());
- ::OffsetRgn(inContextP->Port->clipRgn, COrigin.h, COrigin.v);
- ::SetOrigin(Origin.h, Origin.v);
- }
- else if (mVisible) // otherwise, it must not be able to handle a control, build a temp one - this doesn't work yet
- {
- PicHandle TempPict = NULL;
- WindowPtr TempWin = ::NewCWindow(NULL, &inContextP->Location, "\p", false, documentProc, NULL, false, NULL);
-
- if (TempWin)
- {
- Rect Bounds = { 0 };
-
- Bounds.right = mSize.h;
- Bounds.bottom = mSize.v;
- ::HidePen();
- ControlRef TempControl = ::NewControl(TempWin, &Bounds, mTitle, true,
- mCurrentValue, mMinValue, mMaxValue, mControlType, mRefCon);
- if (TempControl)
- {
- PicHandle TempPict;
-
- if ((TempPict = ::OpenPicture(&Bounds)) != NULL)
- {
- ::DrawOneControl(TempControl);
- ::ClosePicture();
- }
- ::DisposeControl(TempControl);
- }
- ::ShowPen();
- ::DisposeWindow(TempWin);
- }
-
- if (TempPict)
- {
- ::SetPort(inContextP->Port);
- ::DrawPicture(TempPict, &inContextP->Location);
- ::DisposeHandle(Handle(TempPict));
- }
- }
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::TellListeners
- //=--------------------------------------------------------------------------=
-
- void
- CButtonControl::TellListeners(Int32 ControlValue)
- {
- IEnumConnectionPoints* enumCP;
-
- // Get an enumerator for the connection points
- if ( SUCCEEDED(mCPContainerP->EnumConnectionPoints(&enumCP)) )
- {
- IConnectionPoint* connectionPoint;
- IUnknown* Me;
-
- this->QueryInterface(IID_IUnknown, (void**) &Me);
-
- // Loop through all the connection points for this control
- while ( enumCP->Next(1, &connectionPoint, nil) == NOERROR )
- {
- IEnumConnections* enumC;
-
- // Get all the connections for this connection point
- if ( SUCCEEDED( connectionPoint->EnumConnections(&enumC) ))
- {
- CONNECTDATA connectData;
-
- // Loop through all the connections for this connection point
- while ( enumC->Next(1, &connectData, nil) == NOERROR )
- {
- IPlatformControlListener* Listener;
- // Get the interface implementation for this connection
- // if successful, fire the event
- if (connectData.pUnk->QueryInterface(IID_IPlatformControlListener, &Listener) == S_OK)
- {
- Listener->OnControlValueChange(Me, ControlValue);
- Listener->Release();
- }
- }
-
- // Release the enumerator
- enumC->Release();
- }
- }
-
- enumCP->Release();
- }
- }
-
-
- #pragma mark === CButtonControl::IPlatformControl ===
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetType
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetType(IUnknown* inSource, ControlType* outCntrlType)
- {
- #pragma unused (inSource)
-
- *outCntrlType = mControlType;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetType
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetType(IUnknown* inSource, ControlType inCntrlType)
- {
- #pragma unused (inSource)
-
- if (mControlType != inCntrlType)
- {
- mControlType = inCntrlType;
- TouchAllContexts(VisibleControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetSize
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetSize(IUnknown* inSource, Int32* outWidth, Int32* outHeight)
- {
- #pragma unused (inSource)
- *outWidth = mSize.h;
- *outHeight = mSize.v;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetSize
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetSize(IUnknown* inSource, Int32 inWidth, Int32 inHeight)
- {
- #pragma unused (inSource)
- if (inWidth != mSize.h || inHeight != mSize.v)
- {
- mSize.h = inWidth;
- mSize.v = inHeight;
-
- TouchAllContexts(SizeControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetVisible
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetVisible(IUnknown* inSource, Boolean8* outIsVisible)
- {
- #pragma unused (inSource)
-
- *outIsVisible = mVisible;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetVisible
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetVisible(IUnknown* inSource, Boolean8 inShowIt)
- {
- #pragma unused (inSource)
-
- if (mVisible != inShowIt)
- {
- mVisible = inShowIt;
- TouchAllContexts(VisibleControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetHilite
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetHilite(IUnknown* inSource, ControlHiliteType* outHiliteType)
- {
- #pragma unused (inSource)
-
- *outHiliteType = mHilite;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetHilite
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetHilite(IUnknown* inSource, ControlHiliteType inHiliteType)
- {
- #pragma unused (inSource)
-
- if (mHilite != inHiliteType)
- {
- mHilite = inHiliteType;
- TouchAllContexts(HiliteControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetTitle
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetTitle(IUnknown* inSource, Int32 inBufferSize, Char8* outControlTitle)
- {
- #pragma unused (inSource)
-
- Int16 NameLen = *mTitle;
- if (NameLen > inBufferSize)
- NameLen = inBufferSize;
-
- ::BlockMove(mTitle, outControlTitle, NameLen);
- *(outControlTitle + NameLen) = '\0';
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetTitle
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetTitle(IUnknown* inSource, Char8* inControlTitle)
- {
- #pragma unused (inSource)
-
- Char8* EndChar = inControlTitle;
- Int16 NameLen;
-
- while (*EndChar++)
- ;
-
- NameLen = EndChar - inControlTitle - 1;
- if (NameLen > 255)
- NameLen = 255;
- ::BlockMove(inControlTitle, mTitle + 1, NameLen);
- *mTitle = NameLen;
- TouchAllContexts(TitleControlProperty);
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetMinValue
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetMinValue(IUnknown* inSource, Int32* outMinValue)
- {
- #pragma unused (inSource)
-
- *outMinValue = mMinValue;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetMinValue
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetMinValue(IUnknown* inSource, Int32 inMinValue)
- {
- #pragma unused (inSource)
-
- if (inMinValue != mMinValue)
- {
- mMinValue = inMinValue;
- TouchAllContexts(MinValueControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetMaxValue
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetMaxValue(IUnknown* inSource, Int32* outMaxValue)
- {
- #pragma unused (inSource)
-
- *outMaxValue = mMaxValue;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetMaxValue
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetMaxValue(IUnknown* inSource, Int32 inMaxValue)
- {
- #pragma unused (inSource)
-
- if (inMaxValue != mMaxValue)
- {
- mMaxValue = inMaxValue;
- TouchAllContexts(MaxValueControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::GetValue
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::GetValue(IUnknown* inSource, Int32* outValue)
- {
- #pragma unused (inSource)
-
- *outValue = mCurrentValue;
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetValue
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetValue(IUnknown* inSource, Int32 inValue)
- {
- #pragma unused (inSource)
-
- if (inValue != mCurrentValue)
- {
- mCurrentValue = inValue;
- TouchAllContexts(ValueControlProperty);
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonControl::IPlatformControl::SetPageDistance
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CButtonControl::SetPageDistance(IUnknown* inSource, Int32 inPageDistance)
- {
- #pragma unused (inSource)
-
- mPageDistance = inPageDistance;
-
- return S_OK;
- }
-
-
- #pragma mark === CButtonContextInfo Constructor & Destructor ===
-
- //=--------------------------------------------------------------------------=
- // CButtonContextInfo::CButtonContextInfo
- //=--------------------------------------------------------------------------=
- CButtonContextInfo::CButtonContextInfo(CButtonControl* inControlP, Uint32 inContextID) :
- CBaseContextInfo (inControlP, inContextID)
- {
- DrawContext Context = { BeginPortType };
-
- mTBControlRef = NULL;
-
- MakePlatformControl();
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonContextInfo::MakePlatformControl
- //=--------------------------------------------------------------------------=
-
- void
- CButtonContextInfo::MakePlatformControl(void)
- {
- DrawContext Context = { BeginPortType };
- CButtonControl* ButtonControlP = (CButtonControl*)mControlP;
- Rect Bounds = { 0 };
-
- {
- Int32 Width, Height;
-
- ((CButtonControl*)mControlP)->GetSize(NULL, &Width, &Height);
- Bounds.right = Width;
- Bounds.bottom = Height;
- }
-
- if (mTBControlRef)
- {
- ::DisposeControl(mTBControlRef);
- mTBControlRef = NULL;
- }
-
- if (ButtonControlP->mContainerSiteP->AcquireContext(mContextID, &Context) == S_OK)
- {
- mOrigin = *(Point*)(&Context.Port->portRect);
- if (Context.PortType == QDWindowPortType)
- {
- StringPtr ControlTitle = ButtonControlP->mTitle;
- Str255 TempName;
-
- if (!*ControlTitle)
- {
- ControlTitle = TempName;
- ButtonControlP->GetID(254, (Char8*)(TempName+1));
- *TempName = strlen((Char8*)(TempName+1));
- }
-
- ::SetOrigin(0, 0);
- ::OffsetRect(&Bounds, -mOrigin.h, -mOrigin.v);
- ::ClipRect(&Bounds);
- mTBControlRef = ::NewControl(Context.Port, &Bounds, ControlTitle, ButtonControlP->mVisible,
- ButtonControlP->mCurrentValue, ButtonControlP->mMinValue, ButtonControlP->mMaxValue,
- ButtonControlP->mControlType, ButtonControlP->mRefCon);
- ::SetOrigin(mOrigin.h, mOrigin.v);
- }
- ButtonControlP->mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
-
- //=--------------------------------------------------------------------------=
- // CButtonContextInfo::~CButtonContextInfo
- //=--------------------------------------------------------------------------=
- CButtonContextInfo::~CButtonContextInfo(void)
- {
- ::DisposeControl(mTBControlRef);
- }
-
-
- #pragma mark === Control Action Procs ===
-
- //=--------------------------------------------------------------------------=
- // ScrollBarActionProc [static]
- //=--------------------------------------------------------------------------=
- static pascal void
- ScrollBarActionProc(ControlRef theControl, ControlPartCode partCode)
- {
- Int16 OldValue, NewValue, MinValue, MaxValue;
- Int16 ScrollDistance = 0;
-
- switch (partCode)
- {
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- ScrollDistance = 1;
- break;
- case kControlPageUpPart:
- case kControlPageDownPart:
- ScrollDistance = ((CButtonControl*)::GetControlReference(theControl))->GetPageDistance();
- break;
- }
-
- if (partCode == kControlUpButtonPart || partCode == kControlPageUpPart)
- ScrollDistance = -ScrollDistance;
-
- OldValue = ::GetControlValue(theControl);
- NewValue = OldValue + ScrollDistance;
- if (NewValue < (MinValue = ::GetControlMinimum(theControl)))
- NewValue = MinValue;
- else if (NewValue > (MaxValue = ::GetControlMaximum(theControl)))
- NewValue = MaxValue;
-
- if (OldValue != NewValue)
- {
- ::SetControlValue(theControl, NewValue); // this needs to be changed to move ALL sibling controls
- // here is where we'd like to send out messages to listeners
- }
- }
-