home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 25.5 KB | 878 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWContrH.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
-
- #include "FWFrameW.hpp"
-
- #ifndef FWCONTRH_H
- #include "FWContrH.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWPOPUP_H
- #include "FWPopup.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- #ifndef FWINTERE_H
- #include "FWIntere.h"
- #endif
-
- #ifndef FWBNDSTR_H
- #include "FWBndStr.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- #ifndef SLREGION_H
- #include "SLRegion.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //FW_DEFINE_CLASS_M0(FW_CPrivMacControlHelper)
-
- #define IS_POPUP_PROCID(id) (id >= popupMenuProc && id <= popupMenuProc + 15)
-
- QDTextUPP FW_CPrivMacGrayishTextProc::fgOldTextProcUPP;
-
- //========================================================================================
- // CLASS FW_CPrivMacGrayishTextProc
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPrivMacGrayishTextProc)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacGrayishTextProc::FW_CPrivMacGrayishTextProc
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacGrayishTextProc::FW_CPrivMacGrayishTextProc(GrafPtr thePort) :
- fPort(thePort),
- fIsColorPort(((CGrafPtr)(thePort))->portVersion & (0xC000) == 0xC000),
- fQDProcsCreated(false),
- fNewTextProcUPP(NewQDTextProc(TextProcCallback))
- {
- if (fPort->grafProcs)
- {
- fgOldTextProcUPP = fPort->grafProcs->textProc;
- }
- else
- {
- fgOldTextProcUPP = NULL;
- fQDProcsCreated = true;
- if (fIsColorPort)
- {
- ::SetStdCProcs(&fCQDProcs);
- fPort->grafProcs = (QDProcs*)&fCQDProcs;
- }
- else
- {
- ::SetStdProcs(&fQDProcs);
- fPort->grafProcs = &fQDProcs;
- }
- }
-
- fPort->grafProcs->textProc = fNewTextProcUPP;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacGrayishTextProc::~FW_CPrivMacGrayishTextProc
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacGrayishTextProc::~FW_CPrivMacGrayishTextProc()
- {
- FW_START_DESTRUCTOR
-
- if (fQDProcsCreated)
- fPort->grafProcs = NULL;
- else if (fgOldTextProcUPP != NULL)
- {
- fPort->grafProcs->textProc = fgOldTextProcUPP;
- fgOldTextProcUPP = NULL;
- }
-
- if (fNewTextProcUPP)
- DisposeRoutineDescriptor(fNewTextProcUPP);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacGrayishTextProc::TextProcCallback
- //----------------------------------------------------------------------------------------
-
- pascal void FW_CPrivMacGrayishTextProc::TextProcCallback(short byteCount,
- Ptr textBuf,
- Point numer,
- Point denom)
- {
- GrafPtr curPort;
- ::GetPort(&curPort);
- ::RGBColor oldForeColor;
- FW_Boolean modeChanged = false;
-
- if (curPort->txMode == grayishTextOr)
- {
- RGBColor grayColor = FW_CColor(FW_kRGBGray);
-
- ::GetForeColor(&oldForeColor);
- ::RGBForeColor(&grayColor);
-
- ::TextMode(srcOr);
-
- modeChanged = true;
- }
-
- if (FW_CPrivMacGrayishTextProc::fgOldTextProcUPP != NULL)
- CallQDTextProc(FW_CPrivMacGrayishTextProc::fgOldTextProcUPP, byteCount, textBuf, numer, denom);
- else
- StdText(byteCount, textBuf, numer, denom);
-
-
- if (modeChanged)
- {
- ::TextMode(grayishTextOr);
- ::RGBForeColor(&oldForeColor);
- }
- }
-
- //========================================================================================
- // CLASS FW_CPrivMacControlHelper
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::FW_CPrivMacControlHelper
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacControlHelper::FW_CPrivMacControlHelper(Environment* ev,
- FW_CNativeControl* control,
- short value,
- short min,
- short max,
- short procID,
- const Str255 label,
- const FW_CFont& font,
- long refCon) :
- fControl(control),
- fControlHandle(NULL),
- fControlMargin(0),
- fMacProcID(procID),
- fMacFontID(systemFont),
- fMacFontStyle(normal),
- fMacFontSize(12)
- {
- Initialize(ev, value, min, max, label, font, refCon);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper()
- {
- if (fControlHandle)
- ::DisposeControl(fControlHandle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Initialize(Environment* ev,
- short value,
- short min, // = menu ID for popups
- short max, // = titleWidth for popups
- const Str255 label,
- const FW_CFont& font,
- long refCon)
- {
- // Controls are created in the platform window
- FW_CAcquiredODWindow aqODWindow = fControl->GetFrame(ev)->GetWindow(ev)->AcquireODWindow(ev);
- GrafPtr curWin = aqODWindow->GetPlatformWindow(ev);
-
- FW_CPlatformPoint qdLocation = fControl->GetLocation(ev).AsPlatformPoint();
- FW_CPlatformPoint qdSize = fControl->GetSize(ev).AsPlatformPoint();
-
- FW_CPlatformRect rect(qdLocation.h, qdLocation.v,
- qdLocation.h + qdSize.h, qdLocation.v + qdSize.v);
-
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort(curWin);
-
- RgnHandle clipRgn = ::FW_NewRegion();
- if (clipRgn)
- {
- ::GetClip(clipRgn);
- Rect emptyRect;
- ::SetRect(&emptyRect, 0, 0, 0, 0);
- ::ClipRect(&emptyRect);
- }
-
- fMacFontID = font.MacGetFontID();
- fMacFontStyle = font.MacGetFontStyle();
- fMacFontSize = FW_FixedToInt(font.GetFontSize());
- ::TextFont(fMacFontID);
- ::TextFace(fMacFontStyle);
- ::TextSize(fMacFontSize);
- ::TextMode(srcOr);
-
- if (!font.IsEqual(FW_CFont(FW_kSystemFont)))
- {
- // Control uses its own font instead of the System Font
- fMacProcID += kControlUsesOwningWindowsFontVariant;
- }
-
- if (IS_POPUP_PROCID(fMacProcID) && max == 0 && label[0] > 0)
- {
- // Compute default title width
- max = ::StringWidth(label) + 5;
- }
-
- FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev);
-
- fControlHandle = ::NewControl(curWin, &rect, label, false, value, min, max,
- fMacProcID, refCon);
- (**fControlHandle).contrlVis = 255;
- ::SetControlReference(fControlHandle, (long)this);
-
- if (clipRgn)
- {
- ::SetClip(clipRgn);
- ::FW_DisposeRegion(clipRgn);
- }
-
- if (oldPort != curWin)
- SetPort(oldPort);
-
- if (resAccess)
- delete resAccess;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::OpenResFileForPopup
- //----------------------------------------------------------------------------------------
- // OpenDoc bug or feature? we must open the part's resource file before any call to
- // the control manager because the MENU resource of a popup won't be re-loaded correctly...
-
- FW_CAcquireCFMResourceAccess* FW_CPrivMacControlHelper::OpenResFileForPopup(Environment* ev)
- {
- FW_CAcquireCFMResourceAccess* resAccess = NULL;
-
- if (IS_POPUP_PROCID(fMacProcID))
- {
- resAccess = FW_NEW(FW_CAcquireCFMResourceAccess, (ev));
- FW_ASSERT(resAccess);
- }
- return resAccess;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetBounds(const FW_CPlatformRect& controlBounds)
- {
- (*fControlHandle)->contrlRect = controlBounds;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetValue
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetValue(short value, const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- // If the value is the same as the current one it may be because we are updating
- // the control in multiple facets (from FW_CNativeControl::PrivSetValue), so we need
- // to force the redraw by changing the old value first
-
- if ((*fControlHandle)->contrlValue == value)
- (*fControlHandle)->contrlValue = (value == 0) ? 1 : 0;
-
- SetupControl(location, size);
- ::SetControlValue(fControlHandle, value);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetValue
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetValue(short value, FW_Boolean drawNow)
- {
- if (drawNow)
- ::SetControlValue(fControlHandle, value);
- else
- (*fControlHandle)->contrlValue = value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetMin
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetMin(short min)
- {
- // Turn off visibility to avoid unwanted drawing
- short vis = (**fControlHandle).contrlVis;
- (**fControlHandle).contrlVis = 0;
-
- ::SetControlMinimum(fControlHandle, min);
-
- (**fControlHandle).contrlVis = vis;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetMax
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetMax(short max)
- {
- // Turn off visibility to avoid unwanted drawing
- short vis = (**fControlHandle).contrlVis;
- (**fControlHandle).contrlVis = 0;
-
- ::SetControlMaximum(fControlHandle, max);
-
- (**fControlHandle).contrlVis = vis;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetText
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetText(const FW_CString& text)
- {
- Str255 pascalText;
- text.ExportPascal(pascalText);
-
- // Turn off visibility to avoid unwanted drawing
- short vis = (**fControlHandle).contrlVis;
- (**fControlHandle).contrlVis = 0;
-
- ::SetControlTitle(fControlHandle, pascalText);
-
- (**fControlHandle).contrlVis = vis;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::GetText
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::GetText(FW_CString& text) const
- {
- Str255 pascalText;
- ::GetControlTitle(fControlHandle, pascalText);
- text.ReplaceAll(pascalText);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::GetFont
- //----------------------------------------------------------------------------------------
-
- FW_CFont FW_CPrivMacControlHelper::GetFont(Environment* ev) const
- {
- FW_UNUSED(ev);
- FW_CFont font;
-
- font.MacSetFontID(fMacFontID);
-
- // if the font is the system font, set the size to 12 and
- // ignore the style and size data members
- if (fMacFontID == systemFont)
- font.SetFontSize(FW_IntToFixed(12));
- else
- {
- font.SetFontStyle(FW_CFont::PlatformToODFFontStyle(fMacFontStyle));
- font.SetFontSize(FW_IntToFixed(fMacFontSize));
- }
-
- return font;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::DrawControl
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::DrawControl(Environment* ev, ODFacet* facet)
- {
- FW_CAcquiredODWindow aqODWindow = facet->GetFrame(ev)->AcquireWindow(ev);
-
- // All native Mac controls are drawn with Draw1Control except for
- // inactive scroll-bars which are simply empty rectangles
- if (fMacProcID != scrollBarProc || aqODWindow->IsActive(ev))
- {
- ::Draw1Control(fControlHandle);
- }
- else
- {
- // Use direct QD calls instead of ODF graphics because the control cannot
- // scale anyway.
- Rect sbRect = (*fControlHandle)->contrlRect;
- ::FrameRect(&sbRect);
- ::InsetRect(&sbRect, 1, 1);
- ::EraseRect(&sbRect);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Draw(Environment* ev,
- ODFacet* facet,
- const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev);
-
- if (facet->GetCanvas(ev)->IsDynamic(ev))
- {
- SetupControl(location, size);
- DrawControl(ev, facet);
- }
- else
- {
- Print(ev, facet, location, size);
- }
-
- if (resAccess)
- delete resAccess;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Print
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Print(Environment* ev, ODFacet* facet,
- const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- GrafPtr savedPort;
- GrafPtr usePort = (**fControlHandle).contrlOwner;
-
- ::GetPort(&savedPort);
- ::SetPort(usePort);
-
- SetupControl(FW_CPlatformPoint(0, 0), size);
-
- Rect srcRect;
- srcRect.top = 0;
- srcRect.left = 0;
- srcRect.bottom = size.v;
- srcRect.right = size.h;
-
-
- OpenCPicParams picParams;
- picParams.srcRect = srcRect;
- picParams.hRes = 0x00480000;
- picParams.vRes = 0x00480000;
- picParams.version = -2;
- PicHandle picHandle = ::OpenCPicture(&picParams);
-
- {
- FW_CPrivMacGrayishTextProc grayishTextProc(usePort);
- DrawControl(ev, facet);
- }
-
- ::ClosePicture();
-
- // ----- Set back the port and draw the picture -----
- ::SetPort(savedPort);
-
- ::OffsetRect(&srcRect, location.h, location.v);
- ::DrawPicture(picHandle, &srcRect);
- ::KillPicture(picHandle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Enable
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Enable(FW_Boolean enabled, const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- // Since we may be dealing with multiple facets we need to changing the old hilite
- // value first to force a correct redraw in each facet.
-
- short hilite = enabled ? 0 : 255;
-
- if (hilite == (*fControlHandle)->contrlHilite)
- (*fControlHandle)->contrlHilite = 255 - hilite;
-
- SetupControl(location, size);
- ::HiliteControl(fControlHandle, hilite);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Enable
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Enable(FW_Boolean enabled)
- {
- // Turn off visibility to avoid unwanted drawing
- short vis = (**fControlHandle).contrlVis;
- (**fControlHandle).contrlVis = 0;
-
- ::HiliteControl(fControlHandle, enabled ? 0 : 255);
-
- (**fControlHandle).contrlVis = vis;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Show
- //----------------------------------------------------------------------------------------
- // This version of Show can be used for immediate drawing (like scrollbar activation)
-
- void FW_CPrivMacControlHelper::Show(const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- // We need to reset the visibility to 0 before calling ::ShowControl to force the
- // control manager to show it again. For instance a scrollbar activation may
- // occur across multiple facets and this method will be called for each facet!
- (**fControlHandle).contrlVis = 0;
-
- SetupControl(location, size);
- ::ShowControl(fControlHandle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Show
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Show()
- {
- // Only change visibility flag. View should be invalidated
- (**fControlHandle).contrlVis = 255;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Hide
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::Hide()
- {
- // Only change visibility flag. View should be invalidated
- (**fControlHandle).contrlVis = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::Hide
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SimulateButtonPressed(const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- SetupControl(location, size);
- long ticks;
- ::HiliteControl(fControlHandle, kControlButtonPart);
- ::Delay(10, &ticks);
- ::HiliteControl(fControlHandle, 0);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::MouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivMacControlHelper::MouseDown(Environment* ev, const FW_CViewContext& vc,
- const FW_CPlatformPoint& whereMouse)
- {
- FW_CPlatformPoint controlLocation = vc.LogicalToDevice(FW_kZeroPoint);
- FW_CPlatformPoint controlSize = GetControl()->GetSize(ev).AsPlatformPoint();
-
- SetupControl(controlLocation, controlSize);
-
- FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev);
-
- // [LSD] hack for popups who don't seem to respond to TestControl normally...
- short partCode = ::TestControl(fControlHandle, whereMouse);
- if (IS_POPUP_PROCID(fMacProcID))
- {
- partCode = kControlMenuPart;
- ::PenSize(0, 0);
- ::Draw1Control(fControlHandle);
- ::PenNormal();
- }
-
- FW_Boolean mouseHandled = PartCodeSwitch(ev, vc, whereMouse, partCode);
-
- if (resAccess)
- delete resAccess;
-
- return mouseHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::PartCodeSwitch
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivMacControlHelper::PartCodeSwitch(Environment* ev, const FW_CViewContext& vc, const FW_CPlatformPoint& whereMouse, short partCode)
- {
- FW_Boolean mouseHandled = TRUE;
- ODFacet* facet = vc.GetFacet();
-
- switch (partCode)
- {
- case kControlButtonPart:
- case kControlCheckBoxPart: // = kControlRadioButtonPart:
- {
- if (::TrackControl(fControlHandle, whereMouse, NULL))
- {
- GetControl()->ControlClicked(ev, GetValue(), facet);
- }
- }
- break;
-
- case kControlIndicatorPart:
- case kControlMenuPart:
- {
- short before = GetValue();
- ::TrackControl(fControlHandle, whereMouse, (ControlActionUPP) (-1));
- short after = GetValue();
-
- if (after != before)
- {
- if (partCode == kControlIndicatorPart)
- after = after - before; // use a delta for scroll bars
-
- GetControl()->ControlClicked(ev, after, facet);
- }
-
- }
- break;
-
- default:
- mouseHandled = FALSE;
- }
-
- return mouseHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacControlHelper::SetupControl
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacControlHelper::SetupControl(const FW_CPlatformPoint& location,
- const FW_CPlatformPoint& size)
- {
- // Set control coordinates
- (*fControlHandle)->contrlRect.top = location.v + fControlMargin;
- (*fControlHandle)->contrlRect.left = location.h + fControlMargin;
- (*fControlHandle)->contrlRect.bottom = location.v + size.v - fControlMargin;
- (*fControlHandle)->contrlRect.right = location.h + size.h - fControlMargin;
-
- ::PenNormal();
-
- // Set port's font if control doesn't use the default system font
- if (fMacFontID != systemFont)
- {
- ::TextFont(fMacFontID);
- ::TextFace(fMacFontStyle);
- ::TextSize(fMacFontSize);
- ::TextMode(srcOr);
- }
- }
-
- //========================================================================================
- // CLASS FW_CPrivMacScrollBarControlHelper
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacScrollBarControlHelper::FW_CPrivMacScrollBarControlHelper
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacScrollBarControlHelper::FW_CPrivMacScrollBarControlHelper(Environment* ev,
- FW_CNativeControl* control,
- short value,
- short min,
- short max,
- long refCon) :
- FW_CPrivMacControlHelper(ev, control, value, min, max, scrollBarProc, "\p", FW_kSystemFont, refCon),
- fFacet(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacScrollBarControlHelper::~FW_CPrivMacScrollBarControlHelper
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacScrollBarControlHelper::~FW_CPrivMacScrollBarControlHelper()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacScrollBarControlHelper::PartCodeSwitch
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivMacScrollBarControlHelper::PartCodeSwitch(Environment* ev,
- const FW_CViewContext& vc,
- const FW_CPlatformPoint& whereMouse,
- short partCode)
- {
- FW_Boolean mouseHandled = FW_CPrivMacControlHelper::PartCodeSwitch(ev, vc, whereMouse, partCode);
-
- if (!mouseHandled)
- {
- mouseHandled = TRUE;
- fFacet = vc.GetFacet();
-
- switch (partCode)
- {
- case kControlDownButtonPart:
- case kControlUpButtonPart:
- case kControlPageDownPart:
- case kControlPageUpPart:
- {
- ControlActionUPP actionProc = NewControlActionProc(&CallActionProc);
-
- GrafPtr macPort;
- ::GetPort(&macPort);
-
- ::TrackControl(fControlHandle, whereMouse, actionProc);
- DisposeRoutineDescriptor((UniversalProcPtr) actionProc);
- }
- break;
-
- default:
- mouseHandled = FALSE;
- }
- }
-
-
- return mouseHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacScrollBarControlHelper::CallActionProc
- //----------------------------------------------------------------------------------------
-
- pascal void FW_CPrivMacScrollBarControlHelper::CallActionProc(ControlHandle controlHandle,
- short partCode)
- {
- FW_CPrivMacScrollBarControlHelper *controlHelper = (FW_CPrivMacScrollBarControlHelper*)::GetControlReference(controlHandle);
-
- controlHelper->ActionProc(partCode);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacScrollBarControlHelper::ActionProc
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacScrollBarControlHelper::ActionProc(short partCode)
- {
- FW_SOMEnvironment ev;
-
- FW_CScrollBar* scrollBar = FW_DYNAMIC_CAST(FW_CScrollBar, GetControl());
- FW_ASSERT(scrollBar);
- FW_ASSERT(fFacet);
-
- FW_Fixed changeBy = FW_kFixed0;
-
- switch (partCode)
- {
- case kControlDownButtonPart:
- changeBy = scrollBar->GetMinorScrollUnits(ev);
- break;
-
- case kControlUpButtonPart:
- changeBy = -scrollBar->GetMinorScrollUnits(ev);
- break;
-
- case kControlPageDownPart:
- changeBy = scrollBar->GetMajorScrollUnits(ev);
- break;
-
- case kControlPageUpPart:
- changeBy = -scrollBar->GetMajorScrollUnits(ev);
- break;
- };
-
- short before = GetValue();
- short after = before + FW_FixedToInt(changeBy);
-
- short min = GetMin();
- short max = GetMax();
- if (after < min)
- after = min;
- else if (after > max)
- after = max;
-
- if (after != before)
- {
- // [LSD] we need to save & restore the contrlRect of the original facet because
- // multiple facets will change it and TrackControl returns with wrong udpate.
- Rect savedRect = (*fControlHandle)->contrlRect;
-
- GetControl()->ControlClicked(ev, after - before, fFacet);
-
- (*fControlHandle)->contrlRect = savedRect;
- }
- }
-
-
- #endif
-