home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 8.9 KB | 317 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ToolFrm.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 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
-
- #ifndef FWCONTXT_H
- #include "FWContxt.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
-
- FW_DEFINE_AUTO(CToolFrame)
-
- //========================================================================================
- // 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_kFixedPos1),
- fFillFrameGrid(1, 3, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(kFillFrameSelectorPos)), FW_CPoint(FW_IntToFixed(15), FW_IntToFixed(12)), FW_kFixed0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::~CToolFrame
- //----------------------------------------------------------------------------------------
-
- CToolFrame::~CToolFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
- vc.SetMapping(fMapping);
-
- EraseBackground(ev, vc);
-
- DrawTools(vc);
- DrawColors(vc);
-
- 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(vc, rect);
-
- DrawRenderVerb(vc, fDrawPart->GetRenderVerb(), FW_kRGBBlack);
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::DrawTools
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::DrawTools(FW_CGraphicContext& gc)
- {
- FW_CRect toolRect;
- fToolGrid.GetExteriorGridRect(toolRect);
-
- CWidget widget(128 + fDrawPart->GetRenderVerb() - 1);
- widget.Render(gc, toolRect);
-
- InvertTool(gc, fDrawPart->GetTool(), TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::DrawColors
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::DrawColors(FW_CGraphicContext& gc)
- {
- FW_Fixed left = FW_IntToFixed(4);
- FW_Fixed 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(gc); // 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(gc); // 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_CViewContext vc(ev, this, fFacet);
- vc.SetMapping(fMapping);
- InvertTool(vc, oldTool, FALSE);
- InvertTool(vc, newTool, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::InvertTool
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::InvertTool(FW_CGraphicContext& gc, unsigned short theTool, FW_Boolean state)
- {
- if (theTool>0)
- {
- FW_CRect rect;
- fToolGrid.GetCellInterior(theTool - kSelectTool, rect);
-
- #ifdef FW_BUILD_MAC
- if (state)
- {
- FW_CInk ink(FW_kRGBDarkGray, FW_kRGBWhite, FW_kHilite);
- FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
- ink.SetForeColor(FW_kRGBWhite);
- ink.SetBackColor(FW_kRGBGray);
- FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
- ink.SetForeColor(FW_kRGBGray);
- ink.SetBackColor(FW_kRGBLightGray);
- FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
- }
- else
- {
- FW_CInk ink(FW_kRGBLightGray, FW_kRGBGray, FW_kHilite);
- FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
- ink.SetForeColor(FW_kRGBGray);
- ink.SetBackColor(FW_kRGBWhite);
- FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
- ink.SetForeColor(FW_kRGBWhite);
- ink.SetBackColor(FW_kRGBDarkGray);
- FW_CRectShape::RenderRect(gc, rect, FW_kFill, ink);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(state);
- FW_CRectShape::RenderRect(gc, 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_CViewContext vc(ev, this, fFacet);
- vc.SetMapping(fMapping);
- DrawRenderVerb(vc, oldRenderVerb, FW_kRGBLightGray);
- DrawRenderVerb(vc, newRenderVerb, FW_kRGBBlack);
- DrawTools(vc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CToolFrame::DrawRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CToolFrame::DrawRenderVerb(FW_CGraphicContext& gc, unsigned short renderVerb, const FW_CColor& color)
- {
- if (renderVerb>0)
- {
- FW_CRect rect;
- fFillFrameGrid.GetCellInterior(renderVerb - kFrameOnly, rect);
- rect.Offset(FW_kFixed0, FW_IntToFixed(4));
- rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
-
- FW_CStyle style(FW_IntToFixed(2));
- FW_CInk ink(color);
- FW_CLineShape::RenderLine(gc,
- FW_CPoint(rect.left + FW_kFixedPos1, 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_CViewContext vc(ev, this, fFacet);
- vc.SetMapping(fMapping);
- DrawColors(vc);
- }
- }
-