home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-26 | 8.1 KB | 294 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ODFxFrm.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFx.hpp"
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifdef FW_BUILD_MAC
- #include "ColorPicker.h"
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfx
- #endif
-
- FW_DEFINE_AUTO(CODFxFrame)
-
- //========================================================================================
- // CODFxFrame class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame constructor
- //----------------------------------------------------------------------------------------
- CODFxFrame::CODFxFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CODFxContent* content) :
- FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
- FW_MDraggableFrame(ev, this),
- FW_MDroppableFrame(ev, this),
- fContent(content)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame destructor
- //----------------------------------------------------------------------------------------
-
- CODFxFrame::~CODFxFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled CODFxFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Handled result = FW_kNotHandled;
-
- if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE) &&
- this->Drag(ev, theMouseEvent))
- result = FW_kHandled;
- else if(theMouseEvent.GetNumberOfClicks(ev) == 2)
- {
- const short numRegions = fContent->GetNumColors() == 4 ? 2 : 3;
-
- // which region of the frame was the mouse clicked?
- FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
-
- FW_CRect bounds = GetBounds(ev);
- FW_Fixed third = FW_DividedByInt(bounds.Width(), numRegions);
-
- short xZone = -1;
- for(short x = 1; x <= numRegions; x++)
- if(mouse.x < FW_MultipliedByInt(FW_DividedByInt(bounds.Width(), numRegions), x))
- {
- xZone = x - 1;
- break;
- }
-
- short yZone = -1;
- for(short y = 1; y <= numRegions; y++)
- if(mouse.y < FW_MultipliedByInt(FW_DividedByInt(bounds.Height(), numRegions), y))
- {
- yZone = y - 1;
- break;
- }
-
- if(xZone >= 0 && yZone >= 0)
- {
- short colorIndex = (yZone * 3) + xZone;
- RGBColor color = fContent->GetColorData(colorIndex);
- Point pt = {0,0};
- if(::GetColor(pt, "\p", &color, &color))
- {
- fContent->SetColorData(ev, colorIndex, FW_CColor(color));
- Invalidate(ev);
- }
- }
- result = FW_kHandled;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled CODFxFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- FW_UNUSED(isRoot);
- if (hasMenuFocus)
- menuBar->EnableCommand(ev, kODCommandCopy, true);
-
- return FW_kNotHandled;
- }
-
- void CODFxFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- FW_CRect bounds(GetBounds(ev));
-
- // render the picture to the screen
- FW_CPictureShape::RenderPicture(vc, fContent->GetPictureData(ev), bounds);
-
- if(fContent->GetShowGridLines() && odFacet->GetCanvas(ev)->IsDynamic(ev))
- {
- const short numRegions = fContent->GetNumColors() == 4 ? 2 : 3;
-
- FW_Fixed hLoc = bounds.left;
- FW_Fixed vLoc = bounds.top;
-
- for(short x = 0; x < numRegions; x++)
- {
- hLoc += FW_DividedByInt(bounds.Width(), numRegions);
- vLoc += FW_DividedByInt(bounds.Height(), numRegions);
- FW_CLineShape::RenderLine(vc, FW_CPoint(bounds.left, vLoc), FW_CPoint(bounds.right, vLoc), FW_kInvertInk);
- FW_CLineShape::RenderLine(vc, FW_CPoint(hLoc, bounds.top), FW_CPoint(hLoc, bounds.bottom), FW_kInvertInk);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- // By default a FW_CFrame view is not refreshed entirely when resized.
- // You must decide if your content's appearance depends on the frame's size.
- // If it doesn't you don't need to override FrameShapeChanged().
- // Here we must redraw the whole frame everytime because the text is centered.
-
- void CODFxFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- this->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::NewClipboardCommand
- //----------------------------------------------------------------------------------------
-
- FW_CClipboardCommand* CODFxFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
- {
- return FW_NEW(CODFxEditCommand, (ev, commandID, fContent, this));
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::NewDragCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDragCommand* CODFxFrame::NewDragCommand(Environment *ev,
- FW_CFrame* theFrame,
- const FW_CMouseEvent& theMouseEvent)
- {
- FW_UNUSED(theMouseEvent);
- return FW_NEW(CODFxDragCommand, (ev, fContent, theFrame));
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CODFxFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- FW_UNUSED(frame);
- return FW_NEW(CODFxDropCommand, (ev, fContent, this, dropInfo, odFacet, dropPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void CODFxFrame::CreateSubViews(Environment* ev)
- {
- // Create a GrowBox only in root frame
- // Note: you do not need CreateSubViews if the views are defined in resources.
- // See the Container or Form samples.
-
- if (this->IsRoot(ev))
- {
- FW_CRect frameRect = GetBounds(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());
- }
- }
-