home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.1 KB | 321 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWButton.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- // ----- Framewrk Includes -----
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWRRECT_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__CONTROLS__)
- #include <Controls.h>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //========================================================================================
- // CLASS FW_CButton
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CButton, FW_CNativeControl)
- FW_DEFINE_AUTO(FW_CButton)
-
- // 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_CButton::FW_CButton
- //----------------------------------------------------------------------------------------
-
- FW_CButton::FW_CButton(Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- FW_ButtonKind kind,
- const FW_CString& label,
- const FW_CFont& font,
- FW_Message msg,
- FW_ControlValue value) :
- FW_CNativeControl(ev, container, bounds, viewID, msg, value),
- fKind(0)
- {
- Initialize(ev, kind, label, font);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::FW_CButton
- //----------------------------------------------------------------------------------------
-
- FW_CButton::FW_CButton(Environment* ev) :
- FW_CNativeControl(ev),
- fKind(0)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::~FW_CButton
- //----------------------------------------------------------------------------------------
-
- FW_CButton::~FW_CButton()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::MacGetProcID
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_MAC
-
- short FW_CButton::MacGetProcID()
- {
- short procID = pushButProc; // use this as default
-
- if (fKind == FW_kRadioButton) procID = radioButProc;
- else if (fKind == FW_kCheckButton) procID = checkBoxProc;
-
- return procID;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::SetButtonKind
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::SetButtonKind(Environment* ev, FW_ButtonKind kind)
- {
- FW_UNUSED(ev);
- // For now this method can only be used to change a push button to a default button
- FW_ASSERT(fKind == FW_kDefaultPushButton || kind == FW_kDefaultPushButton);
-
- // Use a margin to add/remove a default button's outline
- fControlHelper->SetControlMargin(kind == FW_kDefaultPushButton ? 4 : 0);
-
- fKind = kind;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- #ifdef FW_BUILD_MAC
- FW_CNativeControl::Draw(ev, facet, invalidShape);
-
- if (fKind == FW_kDefaultPushButton)
- {
- FW_CViewContext gc(ev, this, facet, invalidShape);
- // Draw the standard default button border
-
- FW_Fixed buttonOval = FW_IntToFixed(2) + FW_Half(GetSize(ev).y);
- FW_CRoundRectShape::RenderRoundRect(
- gc,
- FW_CRect(FW_kZeroPoint, GetSize(ev)),
- FW_CPoint(buttonOval, buttonOval),
- FW_kFrame,
- FW_kNormalInk,
- FW_CStyle(FW_IntToFixed(3)));
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows handles updating controls automatically
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::SimulateButtonPressed
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::SimulateButtonPressed(Environment* ev)
- {
- if (fKind == FW_kPushButton || fKind == FW_kDefaultPushButton) {
- #ifdef FW_BUILD_MAC
- FW_CViewContext gc(ev, this, GetFrame(ev)->GetActiveFacet(ev), NULL);
-
- FW_CPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
- fControlHelper->SimulateButtonPressed(qdPoint, qdSize);
- #endif
- }
-
- // Send notification
- Notify(ev, FW_CControlNotification(this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::PrivSetValue
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CButton::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))
- {
- // If it's a radio button being turned on we must notify its radio-cluster receiver
- // This should be done before any custom message the radio button might be sending
- // to other receivers
- if (fKind == FW_kRadioButton && value != 0)
- Notify(ev, FW_CControlNotification(this, FW_kRadioClusterMsg));
-
- // Send a control message to its receivers
- if (GetMessage(ev) != FW_kNullMsg && GetMessage(ev) != FW_kRadioClusterMsg)
- Notify(ev, FW_CControlNotification(this));
-
- return true;
- }
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::ControlClicked
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::ControlClicked(Environment *ev, FW_ControlValue oldValue, ODFacet* facet)
- {
- // Change radio and checkbox value (this will send a notification too)
- // Send the notification directly for push buttons
-
- if (GetButtonKind(ev) == FW_kRadioButton)
- PrivSetValue(ev, 1, facet);
- else if (GetButtonKind(ev) == FW_kCheckButton)
- PrivSetValue(ev, 1 - oldValue, facet);
- else
- Notify(ev, FW_CControlNotification(this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::Initialize(Environment* ev,
- FW_ButtonKind kind,
- const FW_CString& label,
- const FW_CFont& font)
- {
- short max = 1;
- fKind = kind;
-
- if (fKind == FW_kPushButton || fKind == FW_kDefaultPushButton)
- {
- fValue = 0; // Push Button's value cannot change
- max = 0;
- }
- else
- {
- if (fValue != 0) fValue = 1; // Radio and Check buttons have 2 values
- }
-
- #ifdef FW_BUILD_MAC
- Str255 pascalText;
- label.ExportPascal(pascalText);
- fControlHelper = new FW_CPrivMacControlHelper
- (ev, this, fValue, 0, max, MacGetProcID(), pascalText, font);
- #endif
-
- #ifdef FW_BUILD_WIN
- // TO UPDATE
- fControlHelper = new FW_CPrivWinControlHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinControlHelper), this);
- fControlHelper->SetText(label);
- #endif
-
- // Control message define Default/Cancel buttons inside a FW_CDialogFrame
- FW_CFrame* frame = GetFrame(ev);
- frame->PrivButtonAttached(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CNativeControl::InitializeFromStream(ev, stream);
-
- FW_ButtonKind kind;
- FW_CString label;
- FW_CFont font;
-
- stream >> kind;
- stream >> font;
- stream >> label;
-
- FW_ASSERT(kind >= 0 && kind <= FW_kMaxButtonKind);
-
- Initialize(ev, kind, label, font);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CButton::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CButton::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CNativeControl::Flatten(ev, stream);
-
- FW_CString title;
- fControlHelper->GetText(title);
-
- stream << fKind;
- stream << title;
- stream << fControlHelper->GetFont(ev);
- }
-
-