home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 12.1 KB | 405 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWAbout.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWPART_K
- #include "FWPart.k"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWICONSH_H
- #include "FWIconSh.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWRESACC_H
- #include "FWResAcc.h"
- #endif
-
- #ifndef FWRESSIN_H
- #include "FWResSin.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWTXTSHP_H
- #include "FWTxtShp.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwabout
- #endif
-
- FW_DEFINE_AUTO(FW_CAboutFrame)
-
- //========================================================================================
- // Constants for this module
- //========================================================================================
-
- const ODID kOKButtonID = 1;
-
- const FW_Fixed kDialogWidth = FW_IntToFixed(350);
- const FW_Fixed kDialogHeight = FW_IntToFixed(250);
- const FW_Fixed kLargeMargin = FW_IntToFixed(20);
- const FW_Fixed kSmallMargin = FW_IntToFixed(10);
- const FW_Fixed kIconSize = FW_IntToFixed(32);
-
- const FW_Fixed kButtonWidth = FW_IntToFixed(80);
- const FW_Fixed kButtonHeight = FW_IntToFixed(30);
-
- const FW_Fixed kCopyrightHeight = FW_IntToFixed(30);
- const FW_Fixed kDescriptionHeight = FW_IntToFixed(200);
-
- //========================================================================================
- // FW_About
- //========================================================================================
-
- void FW_About(Environment* ev, FW_CPart* part, FW_ResourceID id)
- {
- FW_CPresentation* aboutDialogPresentation = NULL;
- FW_VOLATILE(aboutDialogPresentation);
-
- short throwAt = 0;
- FW_VOLATILE(throwAt);
-
- FW_TRY
- {
- ODTypeToken token = FW_CSession::Tokenize(ev, "Apple:ODF:Presentation:About");
- aboutDialogPresentation = new FW_CPrivAboutPresentation(ev, part, token, id);
-
- throwAt = 1;
-
- part->PrivAddPresentation(aboutDialogPresentation);
-
- throwAt = 2;
-
- FW_CDialogFrame* aboutFrame =
- FW_CDialogFrame::NewModalDialog(ev,
- part, // Your part
- aboutDialogPresentation, // Presentation
- FW_CPoint(kDialogWidth, kDialogHeight), // Window size
- FW_kZeroPoint, // Window position
- FW_kStandardDialogPosition, // Already made modal by NewModalDialog
- FW_CString("")); // Title for moveable dialog
-
- if (aboutFrame != NULL)
- {
- aboutFrame->SetDefaultButton(ev, kOKButtonID);
- aboutFrame->GetWindow(ev)->Show(ev);
- }
- else
- {
- part->PrivRemovePresentation(aboutDialogPresentation);
- delete aboutDialogPresentation;
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (throwAt == 2)
- part->PrivRemovePresentation(aboutDialogPresentation);
-
- delete aboutDialogPresentation;
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //========================================================================================
- // class FW_CPrivAboutPresentation
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivAboutPresentation::FW_CPrivAboutPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPrivAboutPresentation::FW_CPrivAboutPresentation(Environment *ev,
- FW_CPart* thePart,
- ODTypeToken presentationType,
- FW_ResourceID resourceID) :
- FW_CPresentation(ev, thePart, NULL, presentationType, FW_kNoViewID, FW_kNoViewID),
- fAboutID(resourceID)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivAboutPresentation::~FW_CPrivAboutPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPrivAboutPresentation::~FW_CPrivAboutPresentation()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivAboutPresentation::PrivNewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* FW_CPrivAboutPresentation::PrivNewFrame(Environment *ev,
- ODFrame* odFrame,
- FW_Boolean fromStorage)
- {
- FW_UNUSED(fromStorage);
- return FW_NEW(FW_CAboutFrame, (ev, odFrame, this, GetPart(ev), fAboutID));
- }
-
- //========================================================================================
- // class FW_CAboutFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::FW_CAboutFrame
- //----------------------------------------------------------------------------------------
-
- FW_CAboutFrame::FW_CAboutFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_CPart* part,
- FW_ResourceID resourceID)
- : FW_CDialogFrame(ev, odFrame, presentation, part)
- {
- FW_ResourceID iconID;
-
- // ----- Load the about resource
- FW_PSharedLibraryResourceFile resFile(ev, part->GetPartInstance(ev));
-
- FW_PResource aboutResource(ev, resFile, resourceID, FW_kAboutResourceType);
- FW_PResourceSink sink(ev, aboutResource);
- FW_CReadableStream stream(sink);
- stream >> iconID;
-
- stream >> fPartNameFontSize;
- stream >> fPartNameFontStyle;
- stream >> fPartNameFontName;
- stream >> fPartName;
-
- stream >> fVersionFontSize;
- stream >> fVersionFontStyle;
- stream >> fVersionFontName;
- stream >> fVersion;
-
- stream >> fCreditsFontSize;
- stream >> fCreditsFontStyle;
- stream >> fCreditsFontName;
- stream >> fCredits;
-
- stream >> fOKString;
- stream >> fButtonSize;
-
- // ----- Load the icon and set up the icon shape
- FW_CRect bounds(kLargeMargin, kLargeMargin, kLargeMargin + FW_IntToFixed(32), kLargeMargin + FW_IntToFixed(32));
-
- FW_CIcon icon(resFile, iconID, 32);
- fIconShape = FW_NEW(FW_CIconShape ,(icon, bounds));
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::~FW_CAboutFrame
- //----------------------------------------------------------------------------------------
-
- FW_CAboutFrame::~FW_CAboutFrame()
- {
- FW_START_DESTRUCTOR
-
- delete fIconShape;
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::FacetAdded
- //----------------------------------------------------------------------------------------
-
- void FW_CAboutFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
- {
- FW_CDialogFrame::FacetAdded(ev, facet, facetCount);
-
- if (facetCount == 1)
- {
- ODPlatformWindow platformWindow = facet->GetWindow(ev)->GetPlatformWindow(ev);
-
- WCTabHandle newColorTable = (WCTabHandle)FW_CMemoryManager::AllocateSystemHandle
- (8+sizeof(ColorSpec));
- (*newColorTable)->ctSize = 0;
- (*newColorTable)->ctTable[0].value = wContentColor;
- (*newColorTable)->ctTable[0].rgb = FW_CColor(FW_kRGBLightGray);
- ::SetWinColor(platformWindow, newColorTable);
- }
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CAboutFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- // ----- Set drawing contect for the CFrame
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- // ----- Draw the Icon -----
- fIconShape->Render(vc);
-
- // ----- Draw the lines -----
- FW_CInk lineColor(FW_kRGBDarkGray);
- FW_Fixed pos = kLargeMargin+kIconSize+kSmallMargin;
- FW_CLineShape::RenderLine(vc,
- FW_CPoint(pos, kLargeMargin),
- FW_CPoint(pos, kDialogHeight - kLargeMargin),
- lineColor);
- FW_CLineShape::RenderLine(vc,
- FW_CPoint(kLargeMargin, pos),
- FW_CPoint(kDialogWidth - kLargeMargin, pos),
- lineColor);
-
- // ----- Draw the Part Name -----
- FW_CInk standardInk(FW_kNormalTextInk);
-
- FW_CFont partNameFont(FW_GetTimesFontName(), FW_kBold, FW_IntToFixed(24));
- FW_CTextShape::RenderText(vc,
- fPartName,
- FW_CPoint(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin, kLargeMargin+kIconSize),
- FW_CFont(fPartNameFontName, fPartNameFontStyle, fPartNameFontSize),
- FW_kTextAlignLeft+FW_kTextAlignBaseLine,
- standardInk);
-
- // ----- Draw the Version -----
- FW_CTextShape::RenderText(vc,
- fVersion,
- FW_CPoint(kDialogWidth-kLargeMargin, kLargeMargin+kIconSize),
- FW_CFont(fVersionFontName, fVersionFontStyle, fVersionFontSize),
- FW_kTextAlignRight+FW_kTextAlignBaseLine,
- standardInk);
-
- // ----- Draw the user Credits -----
- FW_CRect descriptionBox(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
- kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
- kDialogWidth - kLargeMargin,
- kDialogHeight - kLargeMargin - kButtonHeight - kSmallMargin);
- FW_CTextBoxShape::RenderTextBox(vc,
- fCredits,
- descriptionBox,
- FW_CFont(fCreditsFontName, fCreditsFontStyle, fCreditsFontSize),
- FW_kTextBoxJustifyLeft+FW_kTextBoxJustifyTop+FW_kTextBoxWordWrap,
- standardInk);
-
- // ----- Draw the ODF Copyright -----
- FW_CString odfCopyRight;
- ::FW_PrivLoadODFString(ev, FW_kODFCopyright, odfCopyRight);
- FW_CRect copyrightBox(kLargeMargin+kIconSize+kSmallMargin+kSmallMargin,
- kDialogHeight - kLargeMargin - kButtonHeight,
- kDialogWidth - kLargeMargin - kButtonWidth,
- kDialogHeight - kLargeMargin);
- FW_CTextBoxShape::RenderTextBox(vc,
- odfCopyRight,
- copyrightBox,
- FW_CFont("geneva", FW_kPlain, FW_IntToFixed(9)),
- FW_kTextBoxJustifyLeft+FW_kTextBoxJustifyTop+FW_kTextBoxWordWrap,
- standardInk);
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void FW_CAboutFrame::CreateSubViews(Environment* ev)
- {
- if (fButtonSize == FW_kZeroPoint)
- fButtonSize.Set(kButtonWidth, kButtonHeight); // use default size
-
- // ----- Create the OK button
- FW_CRect buttonRect(kDialogWidth - kLargeMargin - fButtonSize.x,
- kDialogHeight - kLargeMargin - fButtonSize.y,
- kDialogWidth - kLargeMargin,
- kDialogHeight - kLargeMargin);
- FW_CButton* okButton = FW_NEW(FW_CButton, (ev, this, buttonRect, kOKButtonID,
- FW_kPushButton, fOKString));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CAboutFrame::DoAdjustMenus(Environment *ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- FW_UNUSED(hasMenuFocus);
- if (isRoot)
- menuBar->EnableCommand(ev, kODCommandAbout, FALSE);
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAboutFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void FW_CAboutFrame::HandleNotification(Environment *ev, const FW_CNotification& notification)
- {
- FW_CPresentation* presentation = GetPresentation(ev);
- FW_CPart* part = GetPart(ev);
-
- // Close and delete the dialog on OK
- FW_CDialogFrame::HandleNotification(ev, notification);
-
- part->PrivRemovePresentation(presentation);
- delete presentation;
- }
-