home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.6 KB | 227 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Dialog.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Mary Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef DIALOG_H
- #include "Dialog.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- ODF Includes -----
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- #ifndef FWKEYF_H
- #include "FWKeyF.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef SLMIXOS_H
- #include "SLMixOS.h" // for FW_Beep
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfclock
- #endif
-
- //========================================================================================
- // CClockSettingsDialogFrame class
- //========================================================================================
-
- FW_DEFINE_AUTO(CClockSettingsDialogFrame)
-
- //----------------------------------------------------------------------------------------
- // CClockSettingsDialogFrame constructor
- //----------------------------------------------------------------------------------------
-
- CClockSettingsDialogFrame::CClockSettingsDialogFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- CClockPart* part)
- : FW_CDialogFrame(ev, odFrame, presentation, part),
- fClockPart(part),
- fNumberView(NULL),
- fStringView(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CClockSettingsDialogFrame destructor
- //----------------------------------------------------------------------------------------
-
- CClockSettingsDialogFrame::~CClockSettingsDialogFrame()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CClockSettingsDialogFrame::PostCreateViewFromStream
- //----------------------------------------------------------------------------------------
-
- void CClockSettingsDialogFrame::PostCreateViewFromStream(Environment* ev)
- {
- // ----- Call inherited to propagate to all subviews if necessary
- FW_CSuperView::PostCreateViewFromStream(ev);
-
- // ----- Find the time offset edit view
- FW_CView* view = FindViewByID(ev, kTimeOffsetViewID);
- fNumberView = FW_DYNAMIC_CAST(FW_CEditView, view);
- FW_ASSERT(fNumberView);
-
- FW_CString initialString;
- CClockContent* clockContent = (CClockContent*) fClockPart->GetContent(ev);
-
- // ----- Initialize the time offset edit view
- FW_CTimeSpan offset = clockContent->GetTimeOffset();
- short hours = offset.GetHours();
- initialString.ReplaceAllAsSignedDecimalInteger(hours);
- fNumberView->SetText(ev, initialString);
- CNumberFilter* filter = FW_NEW( CNumberFilter, (ev, (FW_MEventHandler*)fNumberView));
-
- // ----- Find the face string edit view
- view = FindViewByID(ev, kFaceStringViewID);
- fStringView = FW_DYNAMIC_CAST(FW_CEditView, view);
- FW_ASSERT(fStringView);
-
- // ----- Initialize the face string edit view
- initialString = clockContent->GetFaceString();
- fStringView->SetText(ev, initialString);
-
- // WARNING: Make sure that classes created from resources won't be dead-stripped
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- FW_DO_NOT_DEAD_STRIP(FW_CEditView);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CClockSettingsDialogFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CClockSettingsDialogFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- FW_Message msg = notification.GetMessage();
-
- // ---- Get new settings from edit fields when clicking on Set button ----
- if (msg == FW_kDefaultButtonMsg)
- {
- // Get new face string from EditView
- FW_CString faceString = fStringView->GetText(ev);
-
- // Get offset string from EditView
- FW_CString offsetString = fNumberView->GetText(ev);
- long offset = offsetString.ParseAsSignedInteger(); // in hours
- if (offset < -23 || offset > 23) // Sanity check
- {
- // Open Alert and return to avoid closing the dialog
- FW_CString partName;
- FW_CString errorMessage;
- FW_PSharedLibraryResourceFile resFile(ev);
- ::FW_LoadStringByID(ev, resFile, kClockStrings, FW_kMultiStringRes, kOffsetErrorString, errorMessage);
- fClockPart->GetPartName(ev, partName);
- FW_ErrorAlert(partName, errorMessage);
- return;
- }
-
- // Pass new settings to part before closing dialog
- fClockPart->SetClock(ev, offset, faceString);
- }
-
- // Must call inherited to close the dialog on OK & Cancel
- // WARNING: do not do anything else after this call... the dialog is gone!
- FW_CDialogFrame::HandleNotification(ev, notification);
- }
-
- //========================================================================================
- // CNumberFilter class
- //========================================================================================
-
- FW_DEFINE_AUTO(CNumberFilter)
- FW_DEFINE_CLASS_M1(CNumberFilter, FW_MEventHandler)
-
- //----------------------------------------------------------------------------------------
- // CNumberFilter constructor
- //----------------------------------------------------------------------------------------
- CNumberFilter::CNumberFilter(Environment* ev, FW_MEventHandler* parent)
- : FW_MEventHandler()
- {
- parent->AdoptEventHandler(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CNumberFilter destructor
- //----------------------------------------------------------------------------------------
- CNumberFilter::~CNumberFilter()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CNumberFilter::DoCharKey
- //----------------------------------------------------------------------------------------
- FW_Handled CNumberFilter::DoCharKey(Environment* ev, const FW_CCharKeyEvent& keyEvent)
- {
- char c = keyEvent.GetChar(ev);
-
- // Allow backspace and arrow keys, characters 0-9 and minus sign
- switch (c)
- {
- case 0x08:
- case 0x1C:
- case 0x1D:
- case 0x1E:
- case 0x1F:
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- return FW_kNotHandled;
- }
-
- // not a valid character
- FW_Beep();
- return FW_kHandled;
- }
-