home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 14.7 KB | 496 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Part.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- // Modified by: M.Boetcher to accept Dropped and Pasted sounds
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef ACTIONS_H
- #include "Actions.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWDRCMD_H
- #include "FWDrCmd.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWNOTIFN_H
- #include <FWNotifn.h>
- #endif
-
- #ifndef FWCLAINF_H
- #include <FWClaInf.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef FWODTYPS_H
- #include "FWODTyps.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- // ----- Macintosh Includes -----
- #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
- #include <Sound.h>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfbutton
- #endif
-
- //========================================================================================
- // Constant
- //========================================================================================
-
- // View ids
-
- const ODID kButtonId = 0;
-
- //========================================================================================
- // class CButtonPart
- //========================================================================================
-
- FW_DEFINE_AUTO(CButtonPart)
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::CButtonPart
- //----------------------------------------------------------------------------------------
-
- CButtonPart::CButtonPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::~CButtonPart
- //----------------------------------------------------------------------------------------
-
- CButtonPart::~CButtonPart()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CButtonPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register our Presentation
- CButtonSelection* selection =
- FW_NEW(CButtonSelection, (ev, fButtonContent));
- RegisterPresentation(ev, kODFButtonPresentation,
- TRUE, selection);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::NewPartContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CButtonPart::NewPartContent(Environment* ev)
- {
- fButtonContent = FW_NEW(CButtonContent, (ev, this));
- return fButtonContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CButtonPart::NewFrame(Environment* ev,
- ODFrame* frame,
- FW_CPresentation* presentation,
- FW_Boolean storage)
- {
- return FW_NEW(CButtonFrame, (ev, frame, presentation, this, kButtonView));
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::ClearPartStorage
- //----------------------------------------------------------------------------------------
-
- void CButtonPart::ClearPartStorage(Environment* ev, ODStorageUnit* storage)
- {
- FW_CPart::ClearPartStorage(ev, storage);
-
- // ----- Remove script value if any -----
- if (storage->Exists(ev, kODPropContents, kScriptScrapKind, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kScriptScrapKind, 0, kODPosUndefined);
- storage->Remove(ev);
- }
-
- // ----- Remove sound value if any -----
- if (storage->Exists(ev, kODPropContents, kSoundScrapKind, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kSoundScrapKind, 0, kODPosUndefined);
- storage->Remove(ev);
- }
- }
-
- //------------------------------------------------------------------------------
- // CButtonPart::IsValidContentValue
- //------------------------------------------------------------------------------
- // Because I support more than the standard PartKind I have to test for them
-
- FW_Boolean CButtonPart::IsValidContentValue(Environment* ev, ODType type)
- {
- if (FW_PrimitiveStringEqual(type, this->GetPartKind(ev)))
- return true;
- else if (FW_PrimitiveStringEqual(type, kScriptScrapKind))
- return true;
- else if (FW_PrimitiveStringEqual(type, kSoundScrapKind))
- return true;
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::DoAction
- //----------------------------------------------------------------------------------------
-
- void CButtonPart::DoAction()
- {
- CAction* action = fButtonContent->GetAction();
- if (action != NULL)
- action->DoIt();
- }
-
- //========================================================================================
- // class CButtonFrame
- //========================================================================================
-
- FW_DEFINE_AUTO(CButtonFrame)
- FW_DEFINE_CLASS_M2(CButtonFrame, FW_CFrame, FW_MReceiver)
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::CButtonFrame
- //----------------------------------------------------------------------------------------
-
- CButtonFrame::CButtonFrame(Environment* ev,
- ODFrame* frame,
- FW_CPresentation* presentation,
- CButtonPart* part,
- FW_ResourceId id) : // view resource id
- FW_CFrame(ev, frame, presentation, part, id),
- FW_MDroppableFrame(ev, this),
- fButtonPart(part)
- {
- // CButtonFrame maintains its own focus sets instead of using the presentation's default
- // in order to switch between 2 kind of focus in during mouse-down:
- // - fEmptyFocusSet will be used to handle simple clicks
- // - fFullFocusSet will be used to select the button as an embedded frame
- ODArbitrator* arbitrator = part->GetSession(ev)->GetArbitrator(ev);
- fEmptyFocusSet = arbitrator->CreateFocusSet(ev);
- fFullFocusSet = arbitrator->CreateFocusSet(ev);
- fFullFocusSet->Add(ev, FW_CPart::gKeyFocusToken);
- fFullFocusSet->Add(ev, FW_CPart::gMenuFocusToken);
- fFullFocusSet->Add(ev, FW_CPart::gSelectionFocusToken);
- fFullFocusSet->Add(ev, FW_CPart::gClipboardFocusToken);
-
- fFocusSet = fEmptyFocusSet;
-
- ChangeDroppableState(ev, FW_kFrameDroppable); // Only droppable in view as frame
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::~CButtonFrame
- //----------------------------------------------------------------------------------------
-
- CButtonFrame::~CButtonFrame()
- {
- FW_START_DESTRUCTOR
-
- delete fFullFocusSet;
- delete fEmptyFocusSet;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::PostCreateViewFromStream
- //----------------------------------------------------------------------------------------
- // PostCreateViewFromStream is called after subviews are created from resources.
- // Add code which cannot be handled by current resource types.
-
- void CButtonFrame::PostCreateViewFromStream(Environment* ev)
- {
- // ----- Add a behavior to our button
- FW_CView* view = FindViewById(ev, 1);
- FW_CButton* button = FW_DYNAMIC_CAST(FW_CButton, view);
- FW_ASSERT(button != NULL);
-
- // The role of the COptionBehavior is to detect Option-Click (In this case change the focus
- // set of the frame). Having a behavior allows us to not have to subclass FW_CButton.
- COptionBehavior* optionBehavior = FW_NEW(COptionBehavior, (ev, this));
- button->AdoptEventHandler(ev, optionBehavior);
-
- // WARNING: Make sure that classes created from resources won't be dead-stripped
- FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- // NOTE: This method is not used because the frame resource id was passed to the ctor
- // We left it to show how to create views by program instead of using resources.
- #if 0
- void CButtonFrame::CreateSubViews(Environment* ev)
- {
- // Create button control with this frame size
- FW_CRect frameRect = this->GetBounds(ev);
- FW_CButton* button = FW_NEW(FW_CButton, (ev, this, kButtonId, frameRect, FW_kPushButton,
- FW_CString("Button")));
-
- // Bind button to keep the same frame size
- button->SetBindings(ev, FW_kFitToEnclosure);
-
- // Connect the frame to this button
- button->LinkControlTo(ev, this);
-
- // The role of the COptionBehavior is to detect Option-Click (In this case change the focus
- // set of the frame). Having a behavior allows us to not have to subclass FW_CButton.
- COptionBehavior* optionBehavior = FW_NEW(COptionBehavior, (ev, this));
- button->AdoptEventHandler(ev, optionBehavior);
-
- // Create a GrowBox only in root frame
- if (this->IsRoot(ev))
- {
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
- frameRect.right -= sbSize.x;
- frameRect.bottom -= sbSize.y;
-
- FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
- }
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CButtonFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
-
- if (!acceptDrop)
- {
- for (ODStorageUnit *dragSU = dragInfo->First(ev);
- dragSU != NULL;
- dragSU = dragInfo->Next(ev))
- {
- if (CSoundAction::IsInStorage(ev, dragSU))
- return TRUE;
- if (CScriptAction::IsInStorage(ev, dragSU))
- return TRUE;
- }
- }
-
- return acceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- FW_CViewContext fc(ev, NULL, facet, invalidShape);
-
- // Just erase before the button draws itself
- FW_CRect invalidRect;
- fc.GetClipRect(invalidRect);
- FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- if (notification.GetMessage() == FW_kButtonPressedMsg)
- {
- // no need to check for the button Id, there is only 1 button in this frame
- fButtonPart->DoAction();
- return;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::GetFocusSet
- //----------------------------------------------------------------------------------------
-
- ODFocusSet* CButtonFrame::GetFocusSet(Environment* ev) const
- {
- return fFocusSet;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::SetFocusSet
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::SetFocusSet(Environment* ev, FW_Boolean optionPressed)
- {
- // Warning: Do not change fFocusSet while the frame is active otherwise the wrong focus
- // will be used at the next deactivation
-
- if (HasSelectionFocus(ev) == FALSE) {
- fFocusSet = optionPressed ? fFullFocusSet : fEmptyFocusSet;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CButtonFrame::NewDropCommand(Environment *ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* facet,
- const FW_CPoint& dropPoint)
- {
-
- return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, FW_kCantUndo));
- }
-
- //========================================================================================
- // class COptionBehavior
- //========================================================================================
-
- FW_DEFINE_AUTO(COptionBehavior)
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::COptionBehavior
- //----------------------------------------------------------------------------------------
-
- COptionBehavior::COptionBehavior(Environment* ev, CButtonFrame* frame) :
- FW_MEventHandler(ev, NULL, kNoPriority),
- fFrame(frame)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::~COptionBehavior
- //----------------------------------------------------------------------------------------
-
- COptionBehavior::~COptionBehavior()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean COptionBehavior::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean optionPressed = theMouseEvent.IsCopyModifier(ev);
-
- // Switches focus set on the fly to allow selection of the button when it's an
- // embedded frame.
- fFrame->SetFocusSet(ev, optionPressed);
-
- return optionPressed;
- }
-