home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.4 KB | 222 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWClustr.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWAROPER_H
- #include "FWArOper.h"
- #endif
-
- #ifndef FWCLUSTR_H
- #include "FWClustr.h"
- #endif
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //========================================================================================
- // CLASS FW_CRadioCluster
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CRadioCluster)
- FW_DEFINE_CLASS_M0(FW_CRadioCluster)
-
- // 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_CRadioCluster::FW_CRadioCluster
- //----------------------------------------------------------------------------------------
-
- FW_CRadioCluster::FW_CRadioCluster(Environment* ev) :
- FW_MReceiver(),
- fButtonList(),
- fButtonOn(0)
- {
- FW_UNUSED(ev);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::~FW_CRadioCluster
- //----------------------------------------------------------------------------------------
-
- FW_CRadioCluster::~FW_CRadioCluster()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::AddRadio
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::AddRadio(Environment* ev, FW_CButton* radio)
- {
- FW_ASSERT(radio != NULL && radio->GetButtonKind(ev) == FW_kRadioButton);
-
- // This works only if the radio button uses the default button message
- // Otherwise the RadioCluster will not catch the notification
- AddInterest(FW_CInterest(radio, FW_kRadioClusterMsg));
- fButtonList.AddLast(radio);
-
- // Use the first button added to the cluster as the default one
- if (!fButtonOn)
- {
- fButtonOn = radio;
- radio->SetValue(ev, 1);
- }
- else if (radio->GetValue(ev) != 0)
- {
- fButtonOn->SetValue(ev, 0);
- fButtonOn = radio;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::RemoveRadio
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::RemoveRadio(Environment* ev, FW_CButton* radio)
- {
- FW_UNUSED(ev);
- // It is dangerous to delete the selected radio button
- FW_ASSERT(fButtonOn != radio);
-
- RemoveInterest(FW_CInterest(radio, FW_kRadioClusterMsg));
- fButtonList.Remove(radio);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- switch (notification.GetMessage())
- {
- case FW_kRadioClusterMsg:
- {
- const FW_CControlNotification& controlNotification =
- (FW_CControlNotification&) notification;
- FW_CButton* radioClicked = FW_DYNAMIC_CAST(FW_CButton, controlNotification.GetControl(ev));
- FW_ASSERT(radioClicked);
- FW_TOrderedCollectionIterator<FW_CButton> iter(&fButtonList);
- for (FW_CButton* button = iter.First(); iter.IsNotComplete(); button = iter.Next())
- {
- if (button != radioClicked && button->GetValue(ev) == 1)
- button->SetValue(ev, 0);
- }
-
- fButtonOn = radioClicked;
- }
- break;
-
- case FW_kNotifierDeletedMsg:
- FW_CButton* button = FW_DYNAMIC_CAST(FW_CButton, notification.GetNotifier());
- if (button && fButtonList.Contains(button))
- {
- fButtonList.Remove(button);
- if (fButtonList.Count() == 0)
- delete this;
- }
- break;
-
- default:
- FW_DEBUG_MESSAGE("FW_CRadioCluster can't handle this message");
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- // If all radio buttons have been removed at runtime the radio-cluster was deleted too
-
- FW_CSuperView* superView = fButtonOn->GetSuperView(ev);
- FW_WRITE_DYNAMIC_OBJECT(stream, superView, FW_CSuperView);
-
- // [LSD] todo: add code to retrieve the list of radio buttons connected
- short numRadioButtons = 0;
- long dummy = 0;
-
- stream << dummy, numRadioButtons;
- /*
- FW_TOrderedCollectionIterator<FW_CInterest> ite(&fInterestList);
- short numRadioButtons = ite.Count();
- long dummy = 0;
-
- stream << dummy, numRadioButtons;
-
- FW_CNotifier* nofifier;
- FW_CButton* button;
- for (anInterest = ite.First(); ite.IsNotComplete(); anInterest = ite.Next())
- {
- notifier = anInterest->GetNotifier();
- button = FW_DYNAMIC_CAST(FW_CButton, notifier);
- FW_ASSERT(button != 0);
-
- stream << button->GetViewID(ev);
- */
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- // Read the parent view of the radio buttons
- FW_CSuperView* parentView;
- FW_READ_DYNAMIC_OBJECT(stream, &parentView, FW_CSuperView);
-
- short numRadioButtons;
- stream >> numRadioButtons;
-
- FW_ASSERT(numRadioButtons > 0);
-
- for (short i = 1; i <= numRadioButtons; i++)
- {
- ODID radioID;
- stream >> radioID;
-
- FW_CView* view = parentView->FindViewByID(ev, radioID);
- FW_CButton* button = FW_DYNAMIC_CAST(FW_CButton, view);
- FW_ASSERT(button != NULL);
-
- AddRadio(ev, button);
- }
- }
-
-
-