home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 11.8 KB | 384 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWStatic.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWSTATIC_H
- #include "FWStatic.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPOLYSH_H
- #include "FWPolySh.h"
- #endif
-
- #ifndef FWPOLY_H
- #include "FWPoly.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWTXTSHP_H
- #include "FWTxtShp.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- #define LabelMargin FW_IntToFixed(4)
-
- //========================================================================================
- // CLASS FW_CStaticText
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CStaticText)
- FW_DEFINE_CLASS_M1(FW_CStaticText, FW_CView)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::FW_CStaticText
- //----------------------------------------------------------------------------------------
-
- FW_CStaticText::FW_CStaticText (Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- const FW_CString& text,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& ink) :
- FW_CView(ev, container, bounds, viewID),
- fTextBoxShape(0),
- fEraseColor(FW_kRGBWhite),
- fEraseOnDraw(false)
- {
- Initialize(ev, bounds, text, font, options, ink);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::FW_CStaticText
- //----------------------------------------------------------------------------------------
-
- FW_CStaticText::FW_CStaticText (Environment* ev,
- FW_CSuperView* container,
- ODID viewID,
- const FW_CTextBoxShape& textboxshape) :
- FW_CView(ev, container, FW_kZeroRect, viewID),
- fTextBoxShape(0),
- fEraseColor(FW_kRGBWhite),
- fEraseOnDraw(false)
- {
- fTextBoxShape = FW_NEW(FW_CTextBoxShape, (textboxshape));
-
- Disable(ev); // disable event handler
-
- // set the view bounds with the textbox
- FW_CRect bounds;
- fTextBoxShape->GetTextBox(bounds);
- PrivSetBounds(ev, bounds);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::FW_CStaticText
- //----------------------------------------------------------------------------------------
-
- FW_CStaticText::FW_CStaticText (Environment* ev) :
- FW_CView(ev),
- fTextBoxShape(0),
- fEraseColor(FW_kRGBWhite),
- fEraseOnDraw(false)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::~FW_CStaticText
- //----------------------------------------------------------------------------------------
-
- FW_CStaticText::~FW_CStaticText()
- {
- FW_START_DESTRUCTOR
- delete fTextBoxShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CStaticText::Draw (Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- FW_UNUSED(invalidShape);
- FW_CViewContext vc(ev, this, facet);
-
- if (fEraseOnDraw)
- {
- fEraseOnDraw = false;
- FW_CInk eraseInk(fEraseColor);
-
- FW_CRect invalidRect;
- vc.GetClipRect(invalidRect);
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, eraseInk);
- }
-
- fTextBoxShape->Render(vc);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::SetText
- //----------------------------------------------------------------------------------------
-
- void FW_CStaticText::SetText(Environment* ev, const FW_CString& text, FW_ERedrawVerb redraw)
- {
- fTextBoxShape->SetString(text);
-
- if (redraw == FW_kInvalidate)
- {
- Invalidate(ev);
- fEraseOnDraw = true;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CStaticText::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CView::Flatten(ev, stream);
-
- FW_CString text;
- fTextBoxShape->GetString(text);
-
- stream << FW_CFont(FW_kNormalFont); // [LSD] use default font for now
- stream << text;
- // stream << ink;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CStaticText::Initialize(Environment* ev,
- const FW_CRect& bounds,
- const FW_CString& text,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& ink)
- {
- // Must reset bounds to (0,0) origin because View drawing is done in view coordinates
- FW_CRect box(FW_kZeroPoint, bounds.Size());
- fTextBoxShape = FW_NEW(FW_CTextBoxShape, (text, box, font, options, ink));
-
- Disable(ev); // disable event handler
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStaticText::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CStaticText::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CView::InitializeFromStream(ev, stream);
-
- FW_CFont font;
- FW_CString text;
-
- stream >> font;
- stream >> fEraseColor;
- stream >> text;
-
- // FW_CInk ink; [LSD] todo
- // stream >> ink;
- FW_CInk ink(FW_kNormalTextInk);
-
- Initialize(ev, GetBounds(ev), text, font, FW_kTextBoxClipToBox, ink);
- }
-
- //========================================================================================
- // CLASS FW_CGroupBox
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CGroupBox)
- FW_DEFINE_CLASS_M1(FW_CGroupBox, FW_CStaticText)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::FW_CGroupBox
- //----------------------------------------------------------------------------------------
-
- FW_CGroupBox::FW_CGroupBox (Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- const FW_CString& string,
- const FW_CFont& font,
- FW_TextBoxOptions options,
- const FW_CInk& textInk,
- const FW_CInk& frameInk) :
- FW_CStaticText(ev, container, bounds, viewID, string, font, options, textInk),
- fFrameInk(frameInk)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::FW_CGroupBox
- //----------------------------------------------------------------------------------------
-
- FW_CGroupBox::FW_CGroupBox (Environment* ev,
- FW_CSuperView* container,
- ODID viewID,
- const FW_CTextBoxShape& textbox,
- const FW_CInk& frameInk) :
- FW_CStaticText(ev, container, viewID, textbox),
- fFrameInk(frameInk)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::FW_CGroupBox
- //----------------------------------------------------------------------------------------
-
- FW_CGroupBox::FW_CGroupBox (Environment* ev) :
- FW_CStaticText(ev)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::~FW_CGroupBox
- //----------------------------------------------------------------------------------------
-
- FW_CGroupBox::~FW_CGroupBox()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CGroupBox::SetLabelRect(Environment* ev, FW_CGraphicContext& gc, FW_CRect& labelRect)
- {
- FW_CTextBoxShape* textShape = GetTextBoxShape(ev);
-
- FW_CString255 label;
- textShape->GetString(label);
-
- FW_CPoint textExtent = FW_CTextShape::CalcTextExtent(gc, label, textShape->GetFont());
-
- labelRect.top = FW_kFixed0;
- labelRect.bottom = textExtent.y;
-
- FW_Fixed textsize = textExtent.x + LabelMargin;
- FW_Fixed width = GetSize(ev).x;
- if ((textsize + FW_IntToFixed(2) * LabelMargin) > width )
- textsize = width - FW_IntToFixed(2) * LabelMargin; // label is longer than box
-
- switch(textShape->GetOptions() & FW_kPrivTextBoxHorzJusificationMask)
- {
- case FW_kTextBoxJustifyHCenter:
- labelRect.left = (width - textsize) / FW_IntToFixed(2);
- labelRect.right = labelRect.left + textsize;
- break;
- case FW_kTextBoxJustifyRight:
- labelRect.right = width - LabelMargin;
- labelRect.left = labelRect.right - textsize;
- break;
- case FW_kTextBoxJustifyLeft:
- default:
- labelRect.left = LabelMargin;
- labelRect.right = labelRect.left + textsize;
- break;
- }
-
- // update the label's textbox
- textShape->SetTextBox(labelRect);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CGroupBox::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- FW_UNUSED(invalidShape);
- FW_CViewContext gc (ev, this, facet);
-
- // Must compute the position of the label first
- FW_CRect labelRect;
- SetLabelRect(ev, gc, labelRect);
-
- // Draw box with top side centered on text
- FW_CRect groupRect(FW_kZeroPoint, GetSize(ev));
- groupRect.top += (labelRect.bottom - labelRect.top) / FW_IntToFixed(2);
-
- // draw bottom and right edge inside the view
- groupRect.bottom -= FW_kFixedPos1;
- groupRect.right -= FW_kFixedPos1;
-
- // Use a polygone instead of drawing the frame to avoid crossing the label
- // (would it work better to clip out the textbox region?)
- // FW_CRectShape groupShape(groupRect, FW_kFrame, fFrameInk);
- // groupShape.Render(gc);
- FW_CPoint points[6] = { FW_CPoint(labelRect.left, groupRect.top),
- FW_CPoint(groupRect.left, groupRect.top),
- FW_CPoint(groupRect.left, groupRect.bottom),
- FW_CPoint(groupRect.right, groupRect.bottom),
- FW_CPoint(groupRect.right, groupRect.top),
- FW_CPoint(labelRect.right, groupRect.top) };
- FW_CPolygonShape poly(FW_CPolygon(6, points), FW_kFrame, FALSE, fFrameInk);
- poly.Render(gc);
-
- // Draw label
- GetTextBoxShape(ev)->Render(gc);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CGroupBox::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CStaticText::Flatten(ev, stream);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGroupBox::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CGroupBox::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CStaticText::InitializeFromStream(ev, stream);
- }
-
-