home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 20.6 KB | 681 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWControl.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWCONTRL_H
- #include "FWContrl.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWRECEVR_H
- #include "FWRecevr.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWFCTINF_H
- #include "FWFctInf.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.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
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //========================================================================================
- // Forward declarations
- //========================================================================================
-
-
- //========================================================================================
- // CLASS FW_CControl
- //========================================================================================
-
- FW_DEFINE_CLASS_M2(FW_CControl, FW_CView, FW_MNotifier)
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::FW_CControl
- //----------------------------------------------------------------------------------------
-
- FW_CControl::FW_CControl(Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- FW_Message msg,
- FW_ControlValue value) :
- FW_CView(ev, container, bounds, viewID),
- FW_MNotifier(),
- fMessage(msg),
- fValue(value)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::FW_CControl
- //----------------------------------------------------------------------------------------
-
- FW_CControl::FW_CControl(Environment* ev) :
- FW_CView(ev),
- FW_MNotifier(),
- fMessage(0),
- fValue(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::~FW_CControl
- //----------------------------------------------------------------------------------------
-
- FW_CControl::~FW_CControl()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::AdjustCursor
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CControl::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFacet);
- FW_UNUSED(theMousePoint);
- FW_UNUSED(eventInfo);
-
- FW_gArrowCursor.Select();
- return FW_kHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::LinkControlTo
- //----------------------------------------------------------------------------------------
-
- void FW_CControl::LinkControlTo(Environment *ev, FW_MReceiver* receiver)
- {
- receiver->AddInterest(FW_CInterest(this, GetMessage(ev)));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::SetValue
- //----------------------------------------------------------------------------------------
-
- void FW_CControl::SetValue(Environment* ev, FW_ControlValue value)
- {
- if (value != fValue)
- {
- fValue = value;
-
- // Notify the control's receivers that its value changed
-
- if (fMessage != FW_kNullMsg)
- Notify(ev, FW_CControlNotification(this));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::PrivSetValue
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CControl::PrivSetValue(Environment*, FW_ControlValue value, ODFacet*)
- {
- if (fValue == value)
- return false;
-
- fValue = value;
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::SetMessage
- //----------------------------------------------------------------------------------------
-
- void FW_CControl::SetMessage(Environment* ev, FW_Message msg)
- {
- FW_UNUSED(ev);
- fMessage = msg;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CControl::Flatten(Environment*ev, FW_CWritableStream& stream) const
- {
- FW_CView::Flatten(ev, stream);
-
- // Find out what receiverKind should be written out. Try the SuperView then the Frame
- short receiverKind = 0;
- FW_CView* view = GetSuperView(ev);
- FW_MReceiver* receiver = FW_DYNAMIC_CAST(FW_MReceiver, view);
- FW_MNotifier* notifier = (FW_MNotifier*)this;
- FW_CInterest interest(notifier, GetMessage(ev));
-
- if (receiver != NULL && notifier->IsConnectedTo(receiver, interest) )
- {
- receiverKind = FW_kViewReceiver;
- }
- else if (view->IsFrame(ev) == false)
- {
- view = GetFrame(ev);
- FW_MReceiver* receiver = FW_DYNAMIC_CAST(FW_MReceiver, view);
- if (receiver != NULL && notifier->IsConnectedTo(receiver,interest))
- {
- receiverKind = FW_kFrameReceiver;
- }
- }
-
- stream << fMessage << receiverKind << fValue;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControl::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CControl::InitializeFromStream(Environment*ev, FW_CReadableStream& stream)
- {
- FW_CView::InitializeFromStream(ev, stream);
-
- short receiverKind;
-
- stream >> fMessage >> receiverKind >> fValue;
-
- FW_ASSERT(receiverKind >= 0 && receiverKind <= FW_kFrameReceiver);
-
- // Connection to a receiver
- if (receiverKind == FW_kViewReceiver || receiverKind == FW_kFrameReceiver)
- {
- FW_CView* view = (receiverKind == FW_kViewReceiver) ? GetSuperView(ev) :
- GetFrame(ev);
-
- // We check that the view is a valid receiver before linking the control
- FW_MReceiver* receiver = FW_DYNAMIC_CAST(FW_MReceiver, view);
- if (receiver == NULL)
- {
- // If you get this error:
- // -1- Make sure that the view or frame class you want to link to this control
- // inherits from FW_MReceiver.
- // -2- Make sure that you use a RTTI macro FW_DEFINE_CLASS_Mx, like:
- // FW_DEFINE_CLASS_M2(MyFrame, FW_CFrame, FW_MReceiver)
- // (See also ODF samples)
- FW_DEBUG_MESSAGE("Your view or frame is not a FW_MReceiver, or you forgot RTTI macros");
- }
- else
- LinkControlTo(ev, receiver);
- }
- }
-
- //========================================================================================
- // CLASS FW_CNativeControl
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CNativeControl, FW_CControl)
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::FW_CNativeControl
- //----------------------------------------------------------------------------------------
-
- FW_CNativeControl::FW_CNativeControl(Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- FW_Message msg,
- FW_ControlValue value) :
- FW_CControl(ev, container, bounds, viewID, msg, value),
- fControlHelper(NULL)
- {
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::FW_CNativeControl
- //----------------------------------------------------------------------------------------
-
- FW_CNativeControl::FW_CNativeControl(Environment* ev) :
- FW_CControl(ev),
- fControlHelper(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::~FW_CNativeControl
- //----------------------------------------------------------------------------------------
-
- FW_CNativeControl::~FW_CNativeControl()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::GetLabel
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::GetLabel(Environment* ev, FW_CString& label)
- {
- FW_UNUSED(ev);
- #ifdef FW_BUILD_MAC
- fControlHelper->GetText(label);
- #else
- FW_UNUSED(label);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::SetLabel
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::SetLabel(Environment* ev, const FW_CString& label, FW_ERedrawVerb redraw)
- {
- #ifdef FW_BUILD_MAC
- fControlHelper->SetText(label); // change title without redraw
- #endif
-
- if (redraw == FW_kInvalidate)
- Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::GetPlatformControlHandle
- //----------------------------------------------------------------------------------------
-
- FW_PlatformHandle FW_CNativeControl::GetPlatformControlHandle(Environment* ev) const
- {
- FW_UNUSED(ev);
- #ifdef FW_BUILD_MAC
- return (FW_PlatformHandle)fControlHelper->GetControlHandle();
- #endif
- #ifdef FW_BUILD_WIN
- return fControlHelper->fHWnd;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::SetValue
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::SetValue(Environment *ev, FW_ControlValue value)
- {
- // This is not called in response of a mousedown event, the facet is NULL
- PrivSetValue(ev, value, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::PrivSetValue
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CNativeControl::PrivSetValue(Environment* ev, FW_ControlValue value,
- ODFacet* curFacet)
- {
- short min = fControlHelper->GetMin();
- short max = fControlHelper->GetMax();
-
- if (value < min)
- value = min;
- if (value > max)
- value = max;
-
- // Update base class value or return false if value is the same
- if (FW_CControl::PrivSetValue(ev, value, curFacet) == false)
- return false;
-
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
-
- // If subviews are already created SetValue will trigger some drawing
- if (GetFrame(ev)->PrivSubViewsCreated(ev))
- {
- // During a mousedown event the view context & control are already set up
- // so we can update the control more quickly in the current facet
- if (curFacet != NULL)
- fControlHelper->SetValue(value, true);
-
- // Update the controls in each remaining facet if any
- FW_CFrameFacetIterator ite(ev, GetFrame(ev));
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- if (facet == curFacet) continue;
-
- FW_CViewContext vc(ev, this, facet);
- FW_CPlatformPoint qdPoint = vc.LogicalToDevice(FW_kZeroPoint);
- fControlHelper->SetValue(value, qdPoint, qdSize);
- }
- }
- else
- {
- // If SetValue is called during the initial creation of subviews we want to
- // avoid any drawing before the whole facet is updated
- fControlHelper->SetValue(value, false);
- }
-
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- #ifdef FW_BUILD_MAC
- FW_CViewContext gc(ev, this, facet, invalidShape);
-
- FW_CPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
- fControlHelper->Draw(ev, facet, qdPoint, qdSize);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(facet);
- FW_UNUSED(invalidShape);
- // Windows handles updating controls automatically
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CNativeControl::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- #ifdef FW_BUILD_MAC
- ODFacet* odFacet = theMouseEvent.GetFacet(ev);
- FW_CViewContext vc(ev, this, odFacet);
-
- FW_CPoint canvasWhere = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kWindow);
-
- {
- // Take into account the origin offset for pattern alignment. [AMB]
- FW_CAcquiredODTransform aqTransform(odFacet->CreateTransform(ev));
-
- ODPlatformCanvas plfmCanvas = vc.GetPlatformCanvas();
- FW_CPoint offset(FW_IntToFixed(plfmCanvas->portRect.left),
- FW_IntToFixed(plfmCanvas->portRect.top));
-
- ODPoint odOffset = offset;
- aqTransform->MoveBy(ev, &odOffset);
-
- canvasWhere.Transform(ev, aqTransform);
- }
-
- fControlHelper->MouseDown(ev, vc, canvasWhere.AsPlatformPoint());
- return FW_kHandled;
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(theMouseEvent);
- // Windows handles mouse events automatically
- return FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::Disable
- //----------------------------------------------------------------------------------------
- void FW_CNativeControl::Disable(Environment* ev)
- {
- if (IsEnabled(ev))
- {
- // Call inherited
- FW_MEventHandler::Disable(ev);
-
- if (GetFrame(ev)->PrivSubViewsCreated(ev))
- {
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
-
- FW_CFrameFacetIterator ite(ev, GetFrame(ev));
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- FW_CViewContext vc(ev, this, facet);
- FW_CPlatformPoint qdPoint = vc.LogicalToDevice(FW_kZeroPoint);
-
- fControlHelper->Enable(false, qdPoint, qdSize);
- }
- }
- else
- fControlHelper->Enable(false); // avoid drawing
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::Enable
- //----------------------------------------------------------------------------------------
- void FW_CNativeControl::Enable(Environment* ev)
- {
- if (!IsEnabled(ev))
- {
- // Call inherited
- FW_MEventHandler::Enable(ev);
-
- if (GetFrame(ev)->PrivSubViewsCreated(ev))
- {
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
-
- FW_CFrameFacetIterator ite(ev, GetFrame(ev));
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- FW_CViewContext vc(ev, this, facet);
- FW_CPlatformPoint qdPoint = vc.LogicalToDevice(FW_kZeroPoint);
-
- fControlHelper->Enable(true, qdPoint, qdSize);
- }
- }
- else
- fControlHelper->Enable(true); // avoid drawing
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::SetVisible
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate)
- {
- FW_CView::SetVisible(ev, visible, propagate);
-
- if (visible)
- fControlHelper->Show();
- else
- fControlHelper->Hide();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::RedrawControl
- //----------------------------------------------------------------------------------------
- // Used to refresh a scrollbar for instance
-
- void FW_CNativeControl::RedrawControl(Environment* ev)
- {
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
-
- FW_CFrameFacetIterator ite(ev, GetFrame(ev));
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- FW_CViewContext vc(ev, this, facet);
- FW_CPlatformPoint qdPoint = vc.LogicalToDevice(FW_kZeroPoint);
-
- fControlHelper->Hide();
- fControlHelper->Show(qdPoint, qdSize);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::LocationChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::LocationChanged(Environment* ev, const FW_CPoint &oldLocation)
- {
- FW_CControl::LocationChanged(ev, oldLocation);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_CPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
- FW_CPlatformPoint wndSize = fc.ContentToCanvas(GetSize(ev).x, GetSize(ev).y);
- fControlHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::SizeChanged(Environment* ev, const FW_CPoint &oldSize)
- {
- FW_CControl::SizeChanged(ev, oldSize);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_CPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
- FW_CPlatformPoint wndSize = fc.ContentToCanvas(GetSize(ev).x, GetSize(ev).y);
- fControlHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::Flatten(Environment*ev, FW_CWritableStream& stream) const
- {
- FW_CControl::Flatten(ev, stream);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CNativeControl::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CNativeControl::InitializeFromStream(Environment*ev, FW_CReadableStream& stream)
- {
- FW_CControl::InitializeFromStream(ev, stream);
- }
-
- //========================================================================================
- // CLASS FW_CControlNotification
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CControlNotification, FW_CNotification)
-
- //----------------------------------------------------------------------------------------
- // FW_CControlNotification::FW_CControlNotification
- //----------------------------------------------------------------------------------------
-
- FW_CControlNotification::FW_CControlNotification(FW_CControl* control, FW_Message inMsg) :
- FW_CNotification(),
- fControl(control)
- {
- // Create an interest using the control message by default
- FW_SOMEnvironment ev;
- FW_Message msg = (inMsg != 0) ? inMsg : control->GetMessage(ev);
-
- SetInterest(FW_CInterest((FW_MNotifier*)control, msg));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControlNotification::FW_CControlNotification
- //----------------------------------------------------------------------------------------
-
- FW_CControlNotification::FW_CControlNotification(const FW_CControlNotification& other) :
- FW_CNotification(other),
- fControl(other.fControl)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControlNotification::~FW_CControlNotification
- //----------------------------------------------------------------------------------------
-
- FW_CControlNotification::~FW_CControlNotification()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControlNotification::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CControlNotification& FW_CControlNotification::operator=(const FW_CControlNotification& other)
- {
- if (this != &other)
- {
- FW_CNotification::operator=(other);
- fControl = other.fControl;
- }
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CControlNotification::operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CControlNotification::operator==(const FW_CControlNotification& other) const
- {
- return FW_CNotification::operator==(other) && fControl == other.fControl;
- }
-
-
-