home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.7 KB | 331 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ClockPar.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef CLOCKPAR_H
- #include "ClockPar.h"
- #endif
-
- #ifndef CLOCKDEF_H
- #include "ClockDef.h"
- #endif
-
- #ifndef CLOCKFRA_H
- #include "ClockFra.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWODUTIL_H
- #include "FWODUtil.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
- #include <Sound.h>
- #endif
-
- //========================================================================================
- // RunTime informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfclock
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- const short kClockIdleFreq = 15;
-
- const ODValueType CClockPart::kPartKind = kODFClockKind;
- const ODValueType CClockPart::kPartUserName = kODFClockEditorUserString;
-
- //========================================================================================
- // Class CClockPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CClockPart::CClockPart
- //----------------------------------------------------------------------------------------
- CClockPart::CClockPart(ODPart* odPart) :
- FW_CPart(odPart, CClockPart::kPartKind, CClockPart::kPartUserName, FW_gInstance, kPartIconID),
- fLastTime(),
- fClockType(kAnalogClock),
- fHasTickSound(FALSE),
- fHasChimeSound(TRUE),
- fLockIdle(FALSE)
- #ifdef FW_BUILD_MAC
- ,fChimeSound(NULL),
- fTickSound(NULL)
- #endif
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::~CClockPart
- //----------------------------------------------------------------------------------------
- CClockPart::~CClockPart()
- {
- #ifdef FW_BUILD_MAC
- if (fChimeSound)
- FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle)fChimeSound);
- fChimeSound = NULL;
-
- if (fTickSound)
- FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle)fTickSound);
- fTickSound = NULL;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::Initialize
- //----------------------------------------------------------------------------------------
- void CClockPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register Presentation -----
- fPresentation = RegisterPresentation(ev, "Apple:Presentation:ODFClock", TRUE);
-
- FW_CSharedLibraryResourceFile resFile;
-
- FW_CMenuBar *menuBar = this->GetMenuBar(ev);
-
- FW_CPullDownMenu* pullDownMenu = new FW_CPullDownMenu(ev, resFile, kClockMenuStrings, kClockMenuString);
- pullDownMenu->AppendToggleItem(ev, resFile, kClockMenuStrings, kClockAnalogMenuString, kClockDigitalMenuString, cClockType);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendTextItem(ev, resFile, kClockMenuStrings, kClockTickMenuString, cClockSoundsTick);
- pullDownMenu->AppendTextItem(ev, resFile, kClockMenuStrings, kClockChimeMenuString, cClockSoundsChime);
-
- menuBar->AdoptMenuLast(ev, pullDownMenu);
-
- #ifdef FW_BUILD_MAC
- // ----- We still have the resource file of this CFM lirary opened
- // ----- Get default clock sounds
- fChimeSound = ::GetResource(soundListRsrc, kClockChime);
- ::DetachResource(fChimeSound);
-
- fTickSound = ::GetResource(soundListRsrc, kClockTick);
- ::DetachResource(fTickSound);
- #endif
- this->SetLastTime(FW_CTime::GetCurrentTime());
-
- RegisterIdle(ev, kClockIdleFreq);
- }
-
- //------------------------------------------------------------------------------
- // CClockPart::InternalizeContent
- //------------------------------------------------------------------------------
- void CClockPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- FW_CStorageUnitSink sink(storageUnit, kODPropContents, this->GetPartKind(ev));
- FW_CReadableStream stream(&sink);
- stream >> fClockType;
- stream >> fHasTickSound;
- stream >> fHasChimeSound;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::ExternalizeContent
- //----------------------------------------------------------------------------------------
- void CClockPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
- FW_CStorageUnitSink sink(storageUnit, kODPropContents, this->GetPartKind(ev));
- FW_CWritableStream stream(&sink);
- stream << fClockType;
- stream << fHasTickSound;
- stream << fHasChimeSound;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::NewFrame
- //----------------------------------------------------------------------------------------
- FW_CFrame* CClockPart::NewFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, FW_Boolean fromStorage)
- {
- FW_UNUSED(fromStorage);
-
- return new CClockFrame(ev, odFrame, presentation, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::DoIdle
- //----------------------------------------------------------------------------------------
- FW_Boolean CClockPart::DoIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
- {
- FW_UNUSED(theNullEvent);
-
- if (fLockIdle)
- return TRUE;
-
- FW_CTime currentTime = FW_CTime::GetCurrentTime();
- if (this->GetLastTime() != currentTime)
- {
- short frameCount = 0;
-
- // Update all the display frames of the same type
- FW_CPartFrameIterator iter(this);
- for (CClockFrame *clockFrame = (CClockFrame*)iter.First(); iter.IsNotComplete(); clockFrame = (CClockFrame*)iter.Next())
- {
- if ((!clockFrame->IsInLimbo(ev)))
- {
- frameCount++;
- if (clockFrame->GetViewType(ev) == FW_CPart::gViewAsFrameToken)
- clockFrame->UpdateClock(ev, currentTime);
- }
- }
-
- if (frameCount > 0)
- {
- if (fHasTickSound)
- this->PlayTickSound();
- if (fHasChimeSound && (currentTime.GetMinute() == 0) && (currentTime.GetSecond() == 0))
- this->PlayChimeSound();
- }
-
- this->SetLastTime(currentTime);
- }
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // CClockPart::DoMenu
- //------------------------------------------------------------------------------
- FW_Boolean CClockPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean menuHandled = TRUE;
-
- switch (theMenuEvent.GetCommandID(ev))
- {
- #ifdef FW_BUILD_MAC
- case kODCommandAbout:
- ::FW_About(FW_gInstance);
- break;
- #endif
- case cClockType:
- {
- fLockIdle = TRUE;
- this->SetClockType(this->GetClockType() == kAnalogClock ? kDigitalClock : kAnalogClock);
-
- FW_CPresentationFrameIterator iter(fPresentation);
- for (CClockFrame* frame = (CClockFrame*)iter.First(); iter.IsNotComplete(); frame = (CClockFrame*)iter.Next())
- {
- frame->ChangeClockType(ev, this->GetClockType());
- this->ContentUpdated(ev, frame); // content in frame has changed (notify containers)
- }
- fLockIdle = FALSE;
- this->Changed(ev); // document has changed (enable Save menu item)
- }
- break;
-
- case cClockSoundsTick:
- fHasTickSound = !fHasTickSound;
- this->Changed(ev);
- break;
-
- case cClockSoundsChime:
- fHasChimeSound = !fHasChimeSound;
- this->Changed(ev);
- break;
-
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
- FW_Boolean CClockPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- menuBar->SetItemString(ev, kODCommandAbout, FW_CString32("About ODFClock..."));
-
- menuBar->EnableAndToggleCommand(ev, cClockType, TRUE, this->GetClockType() != kAnalogClock);
- menuBar->EnableAndCheckCommand(ev, cClockSoundsTick, TRUE, fHasTickSound);
- menuBar->EnableAndCheckCommand(ev, cClockSoundsChime, TRUE, fHasChimeSound);
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::PlayTickSound
- //----------------------------------------------------------------------------------------
- void CClockPart::PlayTickSound()
- {
- #ifdef FW_BUILD_MAC
- ::SndPlay(NULL, (SndListHandle)fTickSound, TRUE);
- #endif
- #ifdef FW_BUILD_WIN
- ::MessageBeep(-1);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CClockPart::PlayChimeSound
- //----------------------------------------------------------------------------------------
- void CClockPart::PlayChimeSound()
- {
- #ifdef FW_BUILD_MAC
- ::SndPlay(NULL, (SndListHandle)fChimeSound, TRUE);
- #endif
- #ifdef FW_BUILD_WIN
- ::MessageBeep(-1);
- #endif
- }
-
-