home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 10.5 KB | 358 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Utils.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- //========================================================================================
- // class CGrid
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CGrid::CGrid
- //----------------------------------------------------------------------------------------
-
- CGrid::CGrid(unsigned short rows, unsigned short columns,
- const FW_CPoint& position,
- const FW_CPoint& cellInterior,
- FW_Fixed penSize) :
- fRows(rows),
- fColumns(columns),
- fCellSize(cellInterior.x + penSize, cellInterior.y + penSize),
- fHalfPenSize(FW_Half(penSize)),
- fPosition(position.x + FW_Half(penSize), position.y + FW_Half(penSize))
- {
-
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::FindCell
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CGrid::FindCell(const FW_CPoint& where, unsigned long& index) const
- {
- FW_CRect rect;
- unsigned long lastIndex = fRows * fColumns;
- for (unsigned long x = 0; x < lastIndex; x++)
- {
- GetCellInterior(x, rect);
- if (rect.Contains(where))
- {
- index = x;
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::FindCell
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CGrid::FindCell(const FW_CPoint& where, unsigned short& row, unsigned short& column) const
- {
- FW_CRect rect;
- for (unsigned short x = 0; x < fColumns; x++)
- for (unsigned short y = 0; y < fRows; y++)
- {
- GetCellInterior(y, x, rect);
- if (rect.Contains(where))
- {
- column = x;
- row = y;
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellInterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellInterior(unsigned short row, unsigned short column, FW_CRect& rect) const
- {
- FW_ASSERT(row <= fRows && column <= fColumns);
- rect.Set(FW_kFixed0, FW_kFixed0, fCellSize.x, fCellSize.y);
- rect.Place(FW_MultipliedByInt(fCellSize.x, column), FW_MultipliedByInt(fCellSize.y, row));
- rect.Inset(fHalfPenSize, fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellInterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellInterior(unsigned long index, FW_CRect& rect) const
- {
- unsigned short row, column;
- GetRowColumn(index, row, column);
- GetCellInterior(row, column, rect);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellExterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellExterior(unsigned short row, unsigned short column, FW_CRect& rect) const
- {
- FW_ASSERT(row <= fRows && column <= fColumns);
- rect.Set(FW_kFixed0, FW_kFixed0, fCellSize.x, fCellSize.y);
- rect.Place(FW_MultipliedByInt(fCellSize.x, column), FW_MultipliedByInt(fCellSize.y, row));
- rect.Inset(-fHalfPenSize, -fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellExterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellExterior(unsigned long index, FW_CRect& rect) const
- {
- unsigned short row, column;
- GetRowColumn(index, row, column);
- GetCellExterior(row, column, rect);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetRowColumn
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetRowColumn(unsigned long index, unsigned short& row, unsigned short& column) const
- {
- row = index / fColumns;
- column = index - (row * fColumns);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetExteriorGridRect
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetExteriorGridRect(FW_CRect& rect) const
- {
- rect.Set(FW_kFixed0, FW_kFixed0, FW_MultipliedByInt(fCellSize.x, fColumns), FW_MultipliedByInt(fCellSize.y, fRows));
- rect.Inset(-fHalfPenSize, -fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetInteriorGridRect
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetInteriorGridRect(FW_CRect& rect) const
- {
- rect.Set(FW_kFixed0, FW_kFixed0, FW_MultipliedByInt(fCellSize.x, fColumns), FW_MultipliedByInt(fCellSize.y, fRows));
- rect.Inset(fHalfPenSize, fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::DrawGridBorders
- //----------------------------------------------------------------------------------------
-
- void CGrid::DrawGridBorders(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style)
- {
- FW_CPoint position(fPosition.x - fHalfPenSize, fPosition.y - fHalfPenSize);
- FW_CLineShape line(position.x, position.y, position.x + FW_MultipliedByInt(fCellSize.x, fColumns), position.y);
- line.SetInk(ink);
- line.SetStyle(style);
- unsigned short i;
- for (i = 0; i <= fRows; i++)
- {
- line.Render(gc);
- line.MoveShape(FW_kFixed0, fCellSize.y);
- }
-
- line.SetLineStart(position.x, position.y);
- line.SetLineEnd(position.x, position.y + FW_MultipliedByInt(fCellSize.y, fRows));
- for (i = 0; i <= fColumns; i++)
- {
- line.Render(gc);
- line.MoveShape(fCellSize.x, FW_kFixed0);
- }
- }
-
- //========================================================================================
- // class CWidget
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CWidget::CWidget
- //----------------------------------------------------------------------------------------
-
- CWidget::CWidget(FW_ResourceId resId) :
- fResId(resId)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CWidget::~CWidget
- //----------------------------------------------------------------------------------------
-
- CWidget::~CWidget()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CWidget::Render
- //----------------------------------------------------------------------------------------
-
- void CWidget::Render(FW_CGraphicContext& gc, const FW_CRect& rect)
- {
- FW_SOMEnvironment ev;
- FW_CSharedLibraryResourceFile partResFile(ev);
-
- #ifdef FW_BUILD_MAC
- FW_CPicture picture(partResFile, fResId);
- FW_CPictureShape::RenderPicture(gc, picture, rect);
- #endif
- #ifdef FW_BUILD_WIN
- FW_CBitmap bitmap(partResFile, fResId);
- FW_CBitmapShape::RenderBitmap(gc, bitmap, rect);
- #endif
- }
-
- //========================================================================================
- // class CDrawReadableStream
- //========================================================================================
-
- FW_DEFINE_AUTO(CDrawReadableStream)
-
- //----------------------------------------------------------------------------------------
- // CDrawReadableStream::CDrawReadableStream
- //----------------------------------------------------------------------------------------
-
- CDrawReadableStream::CDrawReadableStream(Environment* ev,
- CDrawPart* drawPart,
- FW_ORandomAccessSink* sink,
- FW_OStorageUnitSink* suSink,
- FW_CCloneInfo* cloneInfo):
- FW_CReadableStream(sink),
- fEnvironment(ev),
- fDrawPart(drawPart),
- fSUSink(suSink),
- fCloneInfo(cloneInfo)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawReadableStream::CDrawReadableStream
- //----------------------------------------------------------------------------------------
-
- CDrawReadableStream::~CDrawReadableStream()
- {
- FW_START_DESTRUCTOR
- }
-
- //========================================================================================
- // class CDrawWritableStream
- //========================================================================================
-
- FW_DEFINE_AUTO(CDrawWritableStream)
-
- //----------------------------------------------------------------------------------------
- // CDrawWritableStream::CDrawWritableStream
- //----------------------------------------------------------------------------------------
-
- CDrawWritableStream::CDrawWritableStream(Environment* ev,
- FW_ORandomAccessSink* sink,
- FW_OStorageUnitSink* suSink,
- FW_CCloneInfo* cloneInfo):
- FW_CWritableStream(sink),
- fEnvironment(ev),
- fSUSink(suSink),
- fCloneInfo(cloneInfo)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawWritableStream::CDrawWritableStream
- //----------------------------------------------------------------------------------------
-
- CDrawWritableStream::~CDrawWritableStream()
- {
- FW_START_DESTRUCTOR
- }
-
-
-
-