home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 10.6 KB | 360 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPopup.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPOPUP_H
- #include "FWPopup.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //========================================================================================
- // CLASS FW_CPopupMenu
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPopupMenu)
- FW_DEFINE_CLASS_M1(FW_CPopupMenu, FW_CNativeControl)
-
- // 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_CPopupMenu::FW_CPopupMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenu::FW_CPopupMenu(Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- FW_ResourceID menuID,
- const FW_CString& title,
- short titleWidth,
- short initialMenuItem,
- FW_PopupMenuStyle popupVariation,
- const FW_CFont& font,
- long popupRefCon) :
- FW_CNativeControl(ev, container, bounds, viewID, FW_kPopupClickedMsg)
- {
- Initialize(ev, menuID, title, titleWidth, initialMenuItem, popupVariation, font, popupRefCon);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::FW_CPopupMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenu::FW_CPopupMenu(Environment* ev) :
- FW_CNativeControl(ev)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::~FW_CPopupMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenu::~FW_CPopupMenu()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPopupMenu::Initialize(Environment* ev,
- FW_ResourceID menuID,
- const FW_CString& title,
- short titleWidth,
- short initialMenuItem,
- FW_PopupMenuStyle popupVariation,
- const FW_CFont& font,
- long popupRefCon)
- {
- #ifdef FW_BUILD_MAC
- Str255 pascalText;
- title.ExportPascal(pascalText);
- fControlHelper = new FW_CPrivMacControlHelper (ev, this, 0, (short)menuID, titleWidth,
- popupMenuProc + popupVariation, pascalText, font, popupRefCon);
-
- if (GetPlatformMenuHandle() == 0)
- {
- // Menu wasn't loaded correctly
- FW_DEBUG_MESSAGE("Missing MENU resource or incorrect menuID");
- }
- fControlHelper->SetValue(initialMenuItem, FALSE);
- fValue = fControlHelper->GetValue();
- #endif
-
- #ifdef FW_BUILD_WIN
- // [TODO]
- fControlHelper = new FW_CPrivWinPopupMenuHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinPopupMenuHelper), this);
- fControlHelper->SetText(title);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::GetPlatformMenuHandle
- //----------------------------------------------------------------------------------------
-
- FW_PlatformHandle FW_CPopupMenu::GetPlatformMenuHandle() const
- {
- #ifdef FW_BUILD_MAC
- PopupPrivateDataHandle h =
- (PopupPrivateDataHandle) (**(fControlHelper->GetControlHandle())).contrlData;
- return (FW_PlatformHandle)(**h).mHandle;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::PrivSetValue
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPopupMenu::PrivSetValue(Environment *ev, FW_ControlValue value, ODFacet* facet)
- {
- // Update the native control. Return false if value was not changed
- if (FW_CNativeControl::PrivSetValue(ev, value, facet))
- {
- // Send a popup menu message to its receivers
- if (GetMessage(ev) != FW_kNullMsg)
- Notify(ev, FW_CPopupMenuNotification(this));
-
- return true;
- }
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::ControlClicked
- //----------------------------------------------------------------------------------------
-
- void FW_CPopupMenu::ControlClicked(Environment *ev, FW_ControlValue value, ODFacet* facet)
- {
- PrivSetValue(ev, value, facet);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::GetMenuString
- //----------------------------------------------------------------------------------------
-
- void FW_CPopupMenu::GetMenuString(Environment* ev, short index, FW_CString& str) const
- {
- // [LSD] todo: add checking for valid index
-
- #ifdef FW_BUILD_MAC
- FW_CAcquireCFMResourceAccess resAccess(ev); // open res file for MENU resource
-
- // force an udpate of the control handle to get the correct menu handle...
- Point zero = { 0, 0};
- ::TestControl(fControlHelper->GetControlHandle(), zero);
-
- MenuHandle macMenu = (MenuHandle)GetPlatformMenuHandle();
- Str255 pascalStr;
-
- ::GetMenuItemText(macMenu, index, pascalStr);
- str.ReplaceAll(pascalStr);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPopupMenu::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CNativeControl::Flatten(ev, stream);
-
- ControlHandle controlH = fControlHelper->GetControlHandle();
- FW_CString title;
- fControlHelper->GetText(title);
-
- // [LSD] we use default values for some fields for now.
- PopupPrivateDataHandle h =
- (PopupPrivateDataHandle) ((*controlH)->contrlData);
- FW_ASSERT(h);
- FW_ResourceID menuID = (**h).mID;
-
- stream << menuID;
- stream << (short)0; // 0 titleWidth. It will be calculated dynamically when the view is read in
- stream << GetValue(ev);
- stream << ::GetControlVariant(controlH);
- stream << (*controlH)->contrlRfCon;
- stream << fControlHelper->GetFont(ev);
- stream << title;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenu::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPopupMenu::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CNativeControl::InitializeFromStream(ev, stream);
-
- FW_ResourceID menuID;
- FW_CString title;
- short titleWidth;
- short initialMenuItem;
- FW_PopupMenuStyle popupVariation;
- FW_CFont font;
- long popupRefCon;
-
- stream >> menuID;
- stream >> titleWidth;
- stream >> initialMenuItem;
- stream >> popupVariation;
- stream >> popupRefCon;
- stream >> font;
- stream >> title;
-
- Initialize(ev, menuID, title, titleWidth, initialMenuItem, popupVariation, font, popupRefCon);
- }
-
- //========================================================================================
- // CLASS FW_CPopupMenuNotification
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CPopupMenuNotification, FW_CControlNotification)
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenuNotification::FW_CPopupMenuNotification
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenuNotification::FW_CPopupMenuNotification(FW_CPopupMenu* popup) :
- FW_CControlNotification(popup)
- {
- FW_SOMEnvironment ev;
- fMenuIndex = (short)popup->GetValue(ev);
- popup->GetMenuString(ev, fMenuIndex, fMenuString);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenuNotification::FW_CPopupMenuNotification
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenuNotification::FW_CPopupMenuNotification(const FW_CPopupMenuNotification& other) :
- FW_CControlNotification(other)
- {
- FW_SOMEnvironment ev;
- fMenuIndex = other.GetMenuIndex(ev);
- other.GetMenuString(ev, fMenuString);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenuNotification::~FW_CPopupMenuNotification
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenuNotification::~FW_CPopupMenuNotification()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenuNotification::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPopupMenuNotification& FW_CPopupMenuNotification::operator=(const FW_CPopupMenuNotification& other)
- {
- if (this != &other)
- {
- FW_CControlNotification::operator=(other);
- fMenuIndex = other.fMenuIndex;
- fMenuString = other.fMenuString;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPopupMenuNotification::operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPopupMenuNotification::operator==(const FW_CPopupMenuNotification& other) const
- {
- return FW_CControlNotification::operator==(other) &&
- fMenuIndex == other.fMenuIndex &&
- fMenuString == other.fMenuString;
- }
-
-