home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 8.8 KB | 311 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ToolFrm.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef TOOLFRM_H
- #include "ToolFrm.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) & !defined(__TOOLUTILS__)
- #include <ToolUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) & !defined(__LOWMEM__)
- #include <LowMem.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawframes
- #endif
-
- //========================================================================================
- // CLASS CToolFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::CToolFrame
- //----------------------------------------------------------------------------------------
-
- CToolFrame::CToolFrame(Environment *ev, ODFrame* odFrame, FW_CPresentation* presentation, CDrawPart *drawPart) :
- CFloatingWindowFrame(ev, odFrame, presentation, drawPart),
- fToolGrid(3, 2, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)), FW_CPoint(FW_IntToFixed(kToolCellSize), FW_IntToFixed(kToolCellSize)), FW_IntToFixed(1)),
- fFillFrameGrid(1, 3, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(kFillFrameSelectorPos)), FW_CPoint(FW_IntToFixed(15), FW_IntToFixed(12)), FW_IntToFixed(0))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::~CToolFrame
- //----------------------------------------------------------------------------------------
-
- CToolFrame::~CToolFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CFacetContext fc(ev, odFacet, invalidShape);
- fc.SetMapping(fMapping);
-
- EraseBackground(ev, fc);
-
- DrawTools(fc);
- DrawColors(fc);
-
- FW_CRect rect(
- FW_IntToFixed(2),
- FW_IntToFixed(2 + kToolHeight + 3),
- FW_IntToFixed(kToolWidth + 2),
- FW_IntToFixed(2 + kToolHeight + 3 + kSelectorHeight));
-
- CWidget widget(131);
- widget.Render(fc, rect);
-
- DrawRenderVerb(fc, fDrawPart->GetRenderVerb(), FW_kRGBBlack);
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::DrawTools
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::DrawTools(FW_CFacetContext& fc)
- {
- FW_CRect toolRect;
- fToolGrid.GetExteriorGridRect(toolRect);
-
- CWidget widget(128 + fDrawPart->GetRenderVerb() - 1);
- widget.Render(fc, toolRect);
-
- InvertTool(fc, fDrawPart->GetTool(), TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::DrawColors
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::DrawColors(FW_CFacetContext& fc)
- {
- FW_CFixed left = FW_IntToFixed(4);
- FW_CFixed top = FW_IntToFixed(kToolsWindowHeight - kColorSelectorHeight - 4);
- FW_CRect colorRect(left, top, left + FW_IntToFixed(kColorSelectorWidth), top + FW_IntToFixed(kColorSelectorHeight));
-
- FW_CColor color;
-
- FW_CRectShape rectShape(colorRect, FW_kFill);
-
- fDrawPart->GetFillColor(color);
- rectShape.GetInk()->SetForeColor(color);
- rectShape.GetStyle()->SetPattern(fDrawPart->GetFillPattern());
- rectShape.Render(fc); // fill
-
- fDrawPart->GetFrameColor(color);
- rectShape.GetInk()->SetForeColor(color);
- rectShape.GetStyle()->SetPenSize(FW_IntToFixed(5));
- rectShape.GetStyle()->SetPattern(fDrawPart->GetFramePattern());
- rectShape.SetRenderVerb(FW_kFrame);
- rectShape.Render(fc); // frame
- }
-
- //------------------------------------------------------------------------------
- // CToolFrame::DoMouseDown
- //------------------------------------------------------------------------------
-
- FW_Boolean CToolFrame::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
-
- unsigned long tool;
- if (fToolGrid.FindCell(where, tool))
- {
- fDrawPart->SetTool(ev, kSelectTool + tool);
- return TRUE;
- }
-
- unsigned long renderVerb;
- if (fFillFrameGrid.FindCell(where, renderVerb))
- {
- fDrawPart->SetRenderVerb(ev, kFrameOnly + renderVerb);
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::CheckTool
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::CheckTool(Environment *ev, unsigned short oldTool, unsigned short newTool)
- {
- // ----- If we never have been shown fFacet == NULL
- if (fFacet != NULL)
- {
- FW_CFacetContext fc(ev, fFacet);
- fc.SetMapping(fMapping);
- InvertTool(fc, oldTool, FALSE);
- InvertTool(fc, newTool, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::InvertTool
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::InvertTool(FW_CFacetContext& fc, unsigned short theTool, FW_Boolean state)
- {
- if (theTool>0)
- {
- FW_CRect rect;
- fToolGrid.GetCellInterior(theTool - kSelectTool, rect);
-
- #ifdef FW_BUILD_MAC
- if (state)
- {
- FW_PInk ink(FW_kRGBDarkGray, FW_kRGBWhite, FW_kHilite);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
- ink->SetForeColor(FW_kRGBWhite);
- ink->SetBackColor(FW_kRGBGray);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
- ink->SetForeColor(FW_kRGBGray);
- ink->SetBackColor(FW_kRGBLightGray);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
- }
- else
- {
- FW_PInk ink(FW_kRGBLightGray, FW_kRGBGray, FW_kHilite);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
- ink->SetForeColor(FW_kRGBGray);
- ink->SetBackColor(FW_kRGBWhite);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
- ink->SetForeColor(FW_kRGBWhite);
- ink->SetBackColor(FW_kRGBDarkGray);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, ink);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(state);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, FW_kInvertInk);
- #endif
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::CheckRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::CheckRenderVerb(Environment *ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
- {
- // If we never have been shown fFacet == NULL
- if (fFacet != NULL)
- {
- FW_CFacetContext fc(ev, fFacet);
- fc.SetMapping(fMapping);
- DrawRenderVerb(fc, oldRenderVerb, FW_kRGBLightGray);
- DrawRenderVerb(fc, newRenderVerb, FW_kRGBBlack);
- DrawTools(fc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::DrawRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::DrawRenderVerb(FW_CFacetContext& fc, unsigned short renderVerb, const FW_CColor& color)
- {
- if (renderVerb>0)
- {
- FW_CRect rect;
- fFillFrameGrid.GetCellInterior(renderVerb - kFrameOnly, rect);
- rect.Offset(FW_IntToFixed(0), FW_IntToFixed(4));
- rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
-
- FW_PStyle style(FW_IntToFixed(2));
- FW_PInk ink(color);
- FW_CLineShape::RenderLine(fc,
- FW_CPoint(rect.left + FW_IntToFixed(1), rect.bottom),
- FW_CPoint(rect.right, rect.bottom),
- ink,
- style);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::UpdateColors
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::UpdateColors(Environment *ev)
- {
- // If we never have been shown fFacet == NULL
- if (fFacet != NULL)
- {
- FW_CFacetContext fc(ev, fFacet);
- fc.SetMapping(fMapping);
- DrawColors(fc);
- }
- }
-