home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.3 KB | 279 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Dialog.cpp
- // Release Version: $ ODF 2 $
- //
- // 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 FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWSTATIC_H
- #include "FWStatic.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWPOPUP_H
- #include "FWPopup.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWEXCDEF_H
- #include <FWExcDef.h>
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- // ----- PPob View Support -----
-
- #if FW_PPOB_VIEWS
- #include "FWPPobRd.h"
- #endif
-
- // ----- MacApp View Support -----
-
- #if FW_MACAPP_VIEWS
- #include "FWMARead.h"
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment viewtester
- #endif
-
- FW_DEFINE_AUTO(CDialogFrame)
-
- //========================================================================================
- // class CDialogFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDialogFrame::CDialogFrame
- //----------------------------------------------------------------------------------------
- CDialogFrame::CDialogFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation,
- CViewTesterPart* part)
- : FW_CDialogFrame(ev, odFrame, presentation, part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDialogFrame::~CDialogFrame
- //----------------------------------------------------------------------------------------
-
- CDialogFrame::~CDialogFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDialogFrame::Initialize
- //----------------------------------------------------------------------------------------
-
- void CDialogFrame::Initialize(Environment* ev)
- {
- FW_Boolean usingMacApp = ((CViewTesterPart*)GetPart(ev))->UsingMacApp();
-
- ODID editID = usingMacApp ? kMacAppEditID : kPPobEditID;
- ODID otherEditID = usingMacApp ? kPPobEditID : kMacAppEditID;
- ODID otherPopupID = usingMacApp ? kPPobPopupID : kMacAppPopupID;
-
- FW_CView* view = FindViewByID(ev, editID);
- view->BecomeTarget(ev, false);
- view = FindViewByID(ev, otherEditID);
- view->SetVisible(ev, false);
- view = FindViewByID(ev, otherPopupID);
- view->Disable(ev);
-
- // Make sure that classes created from ODFRC resources won't be dead-stripped
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- }
-
- //----------------------------------------------------------------------------------------
- // CDialogFrame::Draw
- //----------------------------------------------------------------------------------------
- /*
- void CDialogFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- // Dialog needs to erase its background in order to hide the edit views after
- // using Invalidate().
- FW_CRect rect;
- vc.GetClipRect(rect);
- FW_CRectShape::RenderRect(vc, rect, FW_kFill, FW_kWhiteEraseInk);
- }
- */
- //----------------------------------------------------------------------------------------
- // CDialogFrame::GetResourceID
- //----------------------------------------------------------------------------------------
-
- short CDialogFrame::GetResourceID(Environment* ev, const FW_CString& resName)
- {
- short id = 0;
- Str255 pName;
- resName.ExportPascal(pName);
-
- // Open the current resource file and find the id of the selected resource
- // (because ODF doesn't any API to open a resource by name...)
-
- FW_PResourceFile* resFile = 0;
- long resType;
-
- if (((CViewTesterPart*)GetPart(ev))->UsingMacApp())
- {
- resType = FW_kMAType;
- resFile = FW_CMacAppReader::GetResFile(ev, FW_CMacAppReader::kCurrentResFile);
- }
- else
- {
- resType = FW_kPPobType;
- resFile = FW_CPPobReader::GetResFile(ev, FW_CPPobReader::kCurrentResFile);
- }
-
- Handle resHdl = Get1NamedResource(resType, pName);
- if (resHdl)
- {
- ResType type;
- GetResInfo(resHdl, &id, &type, pName);
- }
- else
- FW_Beep(); // shouldn't happen
-
- delete resFile;
- return id;
- }
-
- //----------------------------------------------------------------------------------------
- // CDialogFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CDialogFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- long viewID = 0;
- CViewTesterPart* part = (CViewTesterPart*)GetPart(ev);
- ODID editID = part->UsingMacApp() ? kMacAppEditID : kPPobEditID;
- ODID popupID = part->UsingMacApp() ? kMacAppPopupID : kPPobPopupID;
- FW_CEditView* editView = FW_DYNAMIC_CAST(FW_CEditView, FindViewByID(ev, editID));
-
- FW_Message dialogMsg = notification.GetMessage();
-
- if (dialogMsg == FW_kDefaultButtonMsg)
- {
- viewID = editView->GetText(ev).ParseAsUnsignedInteger();
- }
- else if (dialogMsg == FW_kPopupClickedMsg)
- {
- const FW_CPopupMenuNotification& popupNotification =
- (FW_CPopupMenuNotification&) notification;
- // update the edit view
- if (popupNotification.GetMenuIndex(ev) == 1)
- {
- editView->SetText(ev, FW_CString());
- editView->Enable(ev);
- editView->BecomeTarget(ev, false);
- }
- else
- {
- FW_CString resStr;
- popupNotification.GetMenuString(ev, resStr);
- viewID = GetResourceID(ev, resStr);
- resStr.ReplaceAllAsUnsignedDecimalInteger(viewID);
-
- editView->ResignTarget(ev);
- editView->Disable(ev);
- editView->SetText(ev, resStr);
- }
- }
-
- if (dialogMsg == FW_kDefaultButtonMsg || dialogMsg == FW_kCancelButtonMsg)
- {
- // MEGA HACK to work around a Mac ToolBox problem: if we don't purge the menu
- // handle from its additional resource items everytime the dialog is closed,
- // then the menu duplicates them the next time the dialog is up!
- // (can someone explain me why?)
- FW_CPopupMenu* popup = (FW_CPopupMenu*)FindViewByID(ev, kMacAppPopupID);
- MenuHandle menuHdl = (MenuHandle)popup->GetPlatformMenuHandle();
- short numItems = CountMItems(menuHdl);
- int i;
- for (i = numItems; i > 2; i--)
- DeleteMenuItem(menuHdl, i);
-
- popup = (FW_CPopupMenu*)FindViewByID(ev, kPPobPopupID);
- menuHdl = (MenuHandle)popup->GetPlatformMenuHandle();
- numItems = CountMItems(menuHdl);
- for (i = numItems; i > 2; i--)
- DeleteMenuItem(menuHdl, i);
-
- // Call FW_CDialogFrame to close the dialog on OK & Cancel
- FW_CDialogFrame::HandleNotification(ev, notification);
-
- // Switch the frame's views
- if (viewID != 0)
- part->ChangeViews(ev, viewID);
- }
- }
-
-