home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 95.5 KB | 3,705 lines | [TEXT/MPS ] |
- // UDDialog.cp
- // Copyright © 1988-1991 Apple Computer Inc. All rights reserved.
-
-
- #ifndef __UDIALOG__
- #include <UDialog.h>
- #endif
-
- #ifndef __STDIO__
- #include <Stdio.h>
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __SANE__
- #include <Sane.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __UASSOCIATION__
- #include <UAssociation.h>
- #endif
-
- #ifndef __UAPPLICATION__
- #include <UApplication.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __USCROLLER__
- #include <UScroller.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UERRORMGR__
- #include <UErrorMgr.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- #ifndef __UPOPUP__
- #include <UPopUp.h>
- #endif
-
- #ifndef __UADORNERS__
- #include <UAdorners.h>
- #endif
-
- #ifndef __UITERATOR__
- #include <UIterator.h>
- #endif
-
- #ifndef __UVIEWSERVER__
- #include <UViewServer.h>
- #endif
-
- TAssociation* gParamTxt; // Used for text substitution
- TFloatingTEManager* gFloatingTEManager; // The floating TEView used with edit text fields.
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- pascal void InitUDialog(void)
- {
- if (qTemplateViews)
- {
- // So the linker doesn't dead strip these
- DontDeadStrip(TDialogView);
- DontDeadStrip(TControl);
- DontDeadStrip(TButton);
- DontDeadStrip(TCheckBox);
- DontDeadStrip(TRadio);
- DontDeadStrip(TCluster);
- DontDeadStrip(TIcon);
- DontDeadStrip(TPicture);
- DontDeadStrip(TPopup);
- DontDeadStrip(TStaticText);
- DontDeadStrip(TEditText);
- DontDeadStrip(TNumberText);
- DontDeadStrip(TPattern);
-
- RegisterStdType("TDialogView", kStdDialogView);
- RegisterStdType("TControl", kStdControl);
- RegisterStdType("TButton", kStdButton);
- RegisterStdType("TCheckBox", kStdCheckBox);
- RegisterStdType("TRadio", kStdRadio);
- RegisterStdType("TCluster", kStdCluster);
- RegisterStdType("TIcon", kStdIcon);
- RegisterStdType("TPicture", kStdPicture);
- RegisterStdType("TPopup", kStdPopup);
- RegisterStdType("TStaticText", kStdStaticText);
- RegisterStdType("TEditText", kStdEditText);
- RegisterStdType("TNumberText", kStdNumberText);
- RegisterStdType("TPattern", kStdPattern);
- }
-
- gFloatingTEManager = new TFloatingTEManager;
- gFloatingTEManager->IObject();
-
- /*!!! Create the dictionary for the global text substitution mechanism.
- This should move out of UDialog soon */
-
- gParamTxt = new TAssociation;
- gParamTxt->IAssociation();
-
- gUDialogInitialized = TRUE;
- }
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal TDialogTEView* AquireFloatingTEView()
- {
- if (gFloatingTEManager)
- return (gFloatingTEManager->AquireFloatingTE());
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void ReleaseFloatingTEView(TDialogTEView* aDialogTEView)
- {
- if (gFloatingTEManager)
- gFloatingTEManager->ReleaseFloatingTE(aDialogTEView);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void MAParamText(const Str255& keyStr,
- const Str255& valueStr)
-
- {
- gParamTxt->InsertEntry(keyStr, valueStr);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void MAReplaceText(Str255& theText)
- {
- CArrayIterator iter(gParamTxt->fEntries);
-
- for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
- {
- TEntry* anEntry = (TEntry*)gParamTxt->fEntries->At(i);
- short index;
-
- while (index = theText.Pos(**(anEntry->fKey)))
- {
- theText.Delete(index, (**(anEntry->fKey)).Length());
- if (theText.Length() + (**(anEntry->fValue)).Length() < sizeof(Str255))
- theText.Insert(**(anEntry->fValue), index);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TDialogView::Initialize(void) // override
- {
- inherited::Initialize();
-
- #if qDebug
- if (!gUDialogInitialized)
- {
- ProgramBreak("InitUDialog must be called before creating a Dialog View.");
- Failure(noErr, 0);
- }
- #endif
-
- fDefaultItem = kNoIdentifier;
- fCancelItem = kNoIdentifier;
- fDismisser = kNoIdentifier;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TDialogView::IDialogView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- IDType itsDefItemID,
- IDType itsCancelItemID)
-
- {
- #if qDebug
- if (!gUDialogInitialized)
- {
- ProgramBreak("InitUDialog must be called before creating a Dialog View.");
- Failure(noErr, 0);
- }
- #endif
-
- this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- fDefaultItem = itsDefItemID;
- fCancelItem = itsCancelItemID;
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TDialogView::IRes(TDocument* itsDocument,
- TView* itsSuperView,
- Ptr& itsParams) // override
-
- {
- #if qDebug
- if (!gUDialogInitialized)
- {
- ProgramBreak("InitUDialog must be called before creating a Dialog View.");
- Failure(noErr, 0);
- }
- #endif
-
- inherited::IRes(itsDocument, itsSuperView, itsParams);
-
- DialogViewTemplate& templateData = *((DialogViewTemplate *) itsParams);
- fDefaultItem = templateData.defaultItem;
- fCancelItem = templateData.cancelItem;
-
- OffsetPtr(itsParams, sizeof(DialogViewTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TDialogView::Clone(void) // override
-
- {
- TDialogView * aClonedDialogView;
-
-
- aClonedDialogView = (TDialogView *)(inherited::Clone());
-
-
- return aClonedDialogView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TDialogView::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- inherited::WRes(theResource, itsParams);
-
- DialogViewTemplate& templateData = *((DialogViewTemplate *) (ExpandPtr((Handle)theResource, itsParams, sizeof(DialogViewTemplate))));
-
- templateData.defaultItem = fDefaultItem;
- templateData.cancelItem = fCancelItem;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TDialogView::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams)// override
-
- {
- gWResSignature = 'dlog';
- gWResType = "TDialogView";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TDialogView::Free(void) // override
-
- {
-
- inherited::Free();
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal Boolean TDialogView::CanDismiss(IDType dismissing)
- {
- TView * dismissingView;
- Boolean successful;
-
- // First, make sure the view initiating the the dismissal, if any, is enabled.
-
- if (((long)dismissing) != ((long)kNoIdentifier))
- dismissingView = this->FindSubView(dismissing);
- else
- dismissingView = NULL; // no dismissing view
-
- // Thanks Tommi GESSL
- successful = (dismissingView == NULL) || (dismissingView->IsEnabled());
-
- if (successful) /* test only we haven´t failed */
- {
- /* Now, if we're not cancelling, make sure the current edit text is valid and
- return false if it isn't.*/
-
- if (((long)fCancelItem == (long)kNoIdentifier) || (dismissing != fCancelItem))
- {
- this->DoSelectEditText(NULL, False);// Attempt to deselect current edit text
- return (this->GetCurrentEditText() == NULL);// Successful only if it was deselected
- }
- else
- return (successful);
- }
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TDialogView::Close(void) // override
-
- {
- if (((long)fDismisser) == ((long)kNoIdentifier))
- this->DismissDialog(kNoIdentifier);
-
- inherited::Close();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal Boolean TDialogView::DeselectCurrentEditText(void)
- {
- TEditText * currentEditText;
- Boolean result = TRUE;
-
- currentEditText = this->GetCurrentEditText();
- if ((currentEditText) && (currentEditText->fTEView))
- {
- result = (currentEditText->fTEView->WillingToResignTarget() == kValidValue);
- this->BeTarget();
- }
- return result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TDialogView::DismissDialog(IDType dismisser)
-
- {
- TWindow * itsWindow;
-
-
- itsWindow = this->GetWindow();
- if (!itsWindow->IsDismissed())
- if (this->CanDismiss(dismisser))
- {
- itsWindow->Dismiss();
- fDismisser = dismisser;
- }
- else
- Failure(noErr, 0); // Silent failure
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogView::DoEvent(EvtNumber eventNumber,
- TEvtHandler* source,
- TEvent* event)// override
-
- {
- switch (eventNumber)
- {
- case mEditTextHit:
- #if qDebug
- if (source && !source->IsMemberClass(GetClassIDFromName("TEditText")))
- ProgramBreak("Got mEditTextHit on non-TEditText view.");
- #endif
-
- //!!!RCR
- #if FALSE
- else
- this->DoSelectEditText((TEditText *)source, False);
- #endif
-
- break;
- default:
- if (source && source->IsMemberClass(GetClassIDFromName("TControl")) && ((TControl *)source)->fDismissesDialog)
- this->DismissDialog(((TView *)source)->fIdentifier);
- else
- inherited::DoEvent(eventNumber, source, event);
- break;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogView::DoCommandKey(TToolboxEvent* event)// override
-
- {
- TView * cancelView;
-
-
- //!!! this needs internationalization
- if (this->IsEnabled() && event->fCharacter == '.' && ((long)fCancelItem != (long)kNoIdentifier))
- {
- cancelView = this->FindSubView(fCancelItem);
- if (cancelView)
- {
- if (cancelView->IsMemberClass(GetClassIDFromName("TControl")))
- cancelView->HandleEvent(((TControl *)cancelView)->fDefChoice, this, NULL);
- else
- cancelView->HandleEvent(mCancelKey, this, NULL);
- }
- else
- this->HandleEvent(mCancelKey, this, NULL);
- }
- else
- inherited::DoCommandKey(event);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogView::DoKeyCommand(TToolboxEvent* event)// override
- {
- TView * defaultView;
- TView * cancelView;
-
-
- // If we get this far, nobody's handled the Tab, Enter, or Return keys, so we will
- if (this->IsEnabled())
- {
- switch (event->fCharacter)
- {
- case chEscape:
- if (event->fKeyCode == kClearVirtualCode)// esc double for two different keys!
- inherited::DoKeyCommand(event);
- else if (((long)fCancelItem) != ((long)kNoIdentifier))
- {
- cancelView = this->FindSubView(fCancelItem);
- if (cancelView)
- {
- if (cancelView->IsMemberClass(GetClassIDFromName("TControl")))
- cancelView->HandleEvent(((TControl *)cancelView)->fDefChoice, this, NULL);
- else
- cancelView->HandleEvent(mCancelKey, this, NULL);
- }
- else
- this->HandleEvent(mCancelKey, this, NULL);
- }
- else
- inherited::DoKeyCommand(event);
- break;
- case chEnter:
- case chReturn:
- if ((long)fDefaultItem != (long)kNoIdentifier)
- {
- defaultView = this->FindSubView(fDefaultItem);
- if (defaultView)
- {
- if (defaultView->IsMemberClass(GetClassIDFromName("TControl")))
- defaultView->HandleEvent(((TControl *)defaultView)->fDefChoice, this, NULL);
- else
- defaultView->HandleEvent(mDefaultKey, this, NULL);
- }
- else
- this->HandleEvent(mDefaultKey, this, NULL);
- }
- else
- inherited::DoKeyCommand(event);
- break;
- default:
- inherited::DoKeyCommand(event);
- break;
- }
- }
- else
- inherited::DoKeyCommand(event);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogView::DoSelectEditText(TEditText* theEditText,
- Boolean selectChars)
- {
-
- if (theEditText != this->GetCurrentEditText())// If we're not editing this view…
- {
- if (theEditText == NULL)
- this->BeTarget(); // Set the window's target to self
- else
- {
- if (theEditText->IsEnabled())
- theEditText->StartEdit(selectChars);
- #if qDebug
- else
- ProgramBreak("Attempt to select a disabled edit text view");
- #endif
- }
- }
- else if (selectChars && (theEditText))// Make sure all the chars are selected.
- theEditText->SetSelection(0, MAXINT, kRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- class CCheckSubView
- {
- const void*& fStaticLink;
- const DoToEditTextType& fDoToEditText;
- public:
- // Constructor
- CCheckSubView(const DoToEditTextType DoToEditText,
- void* staticLink) :
- fDoToEditText(DoToEditText),
- fStaticLink(staticLink)
- {}
-
- pascal void CheckSubView(TView* theSubView);
- };
-
- #pragma segment DlgRes
-
- pascal void CCheckSubView::CheckSubView(TView* theSubView)
- {
- if (theSubView && theSubView->IsMemberClass(GetClassIDFromName("TEditText")))
- fDoToEditText((TEditText *)theSubView, fStaticLink);
- else
- {
- CCheckSubView aCCheckSubView(fDoToEditText, fStaticLink);
-
- theSubView->EachSubView((DoToViewType) & CCheckSubView::CheckSubView, &aCCheckSubView);
- }
- }
-
- #pragma segment DlgRes
-
- pascal void TDialogView::EachEditText(DoToEditTextType DoToEditText,
- void* staticLink)
- {
- CCheckSubView aCCheckSubView(DoToEditText, staticLink);
-
- this->EachSubView((DoToViewType) & CCheckSubView::CheckSubView, &aCCheckSubView);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal TEditText* TDialogView::GetCurrentEditText(void)
- {
- TEvtHandler * currentTarget;
- TWindow * myWindow;
- TEditText * result;
-
- //!!!RCR Needs work
- result = NULL;
- myWindow = this->GetWindow();
- if (myWindow)
- currentTarget = myWindow->GetTarget();
- else
- currentTarget = NULL;
- if ((currentTarget) && currentTarget->IsMemberClass(GetClassIDFromName("TDialogTEView")))
- result = ((TDialogTEView *)currentTarget)->fEditText;
- return result;
- }
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TView* TDialogView::GetDialogView(void) // override
- {
- return this;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TDialogView::DoOpen(void)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TDialogView::Open(void) // override
-
- {
- fDismisser = kNoIdentifier;
- this->DoOpen();
- inherited::Open();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal IDType TDialogView::PoseModally(void)
- {
- TWindow * itsWindow;
-
- itsWindow = this->GetWindow();
- if (itsWindow)
- {
- itsWindow->PoseModally();
- return fDismisser;
- }
- else
- return kNoIdentifier;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogView::SelectEditText(IDType itsIdentifier,
- Boolean selectChars)
- {
- TView * aSubView;
-
- aSubView = this->FindSubView(itsIdentifier);
- if ((aSubView) && aSubView->IsMemberClass(GetClassIDFromName("TEditText")))
- this->DoSelectEditText((TEditText *)aSubView, selectChars);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TDialogView::Fields(TObject* obj) // override
- {
- obj->DoToField("TDialogView", NULL, bClass);
- obj->DoToField("fDefaultItem", &fDefaultItem, bIDType);
- obj->DoToField("fCancelItem", &fCancelItem, bIDType);
- obj->DoToField("fDismisser", &fDismisser, bIDType);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TButton::Initialize(void) // override
- {
-
- inherited::Initialize();
-
- fDefChoice = mButtonHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TButton::IButton(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const Str255& itsLabel)
- {
- this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 0, ((pushButProc) | useWFont));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TButton::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
-
- {
- VRect itsArea;
-
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- this->ControlArea(itsArea);
- this->CreateCMgrControl(itsArea, ((ButtonTemplatePtr)itsParams)->itsLabel, 0, 0, 0, ((pushButProc) | useWFont));
-
- OffsetPtrWStr(itsParams, sizeof(ButtonTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TButton::Clone(void) // override
- {
- TButton * aClonedButton;
-
-
- aClonedButton = (TButton *)(inherited::Clone());
-
- return aClonedButton;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TButton::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- Str255 theLabel;
-
- inherited::WRes(theResource, itsParams);
-
- this->GetText(theLabel);
-
- ButtonTemplate& templateData = *((ButtonTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(ButtonTemplate), theLabel.Length()));
-
- // templateData.itsLabel = theLabel;
- CopyStr255(theLabel, PRStr(templateData.itsLabel));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TButton::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
-
- {
- gWResSignature = 'butn';
- gWResType = "TButton";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TButton::DoEvent(EvtNumber eventNumber,
- TEvtHandler* source,
- TEvent* event) // override
-
- {
- if ((eventNumber == mButtonHit) && (source != this) && this->IsEnabled())
- this->Flash();
- inherited::DoEvent(eventNumber, this, event); // note source change
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TButton::Fields(TObject* obj) // override
- {
- obj->DoToField("TButton", NULL, bClass);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TCheckBox::Initialize(void) // override
- {
- inherited::Initialize();
-
- fDefChoice = mCheckBoxHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TCheckBox::ICheckBox(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const Str255& itsLabel,
- Boolean isTurnedOn)
-
- {
- this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1, ((checkBoxProc) | useWFont));
- this->SetState(isTurnedOn, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TCheckBox::IRes(TDocument* /* itsDocument */,
- TView* itsSuperView,
- Ptr& itsParams) // override
-
- {
- VRect itsArea;
-
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- this->ControlArea(itsArea);
- this->CreateCMgrControl(itsArea, ((CheckBoxTemplatePtr)itsParams)->itsLabel, ((CheckBoxTemplatePtr)itsParams)->isOn, 0, 1, ((checkBoxProc) | useWFont));
-
- OffsetPtrWStr(itsParams, sizeof(CheckBoxTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TCheckBox::Clone(void) // override
- {
- TCheckBox * aClonedCheckBox;
-
- aClonedCheckBox = (TCheckBox *)(inherited::Clone());
-
- return aClonedCheckBox;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TCheckBox::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- Str255 theLabel;
-
- inherited::WRes(theResource, itsParams);
-
- this->GetText(theLabel);
-
- CheckBoxTemplate& templateData = *((CheckBoxTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(CheckBoxTemplate), theLabel.Length()));
-
- templateData.isOn = this->IsOn();
- // templateData.itsLabel = theLabel;
- CopyStr255(theLabel, PRStr(templateData.itsLabel));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TCheckBox::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- gWResSignature = 'chkb';
- gWResType = "TCheckBox";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCheckBox::DoEvent(EvtNumber eventNumber,
- TEvtHandler*, // source
- TEvent* event)// override
-
- {
- if (eventNumber == mCheckBoxHit)
- this->Toggle(kRedraw);
- inherited::DoEvent(eventNumber, this, event);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal Boolean TCheckBox::IsOn(void)
- {
- return (this->GetLongVal() != 0);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCheckBox::SetState(Boolean state,
- Boolean redraw)
- {
- this->SetLongVal((long)state, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCheckBox::Toggle(Boolean redraw)
-
- {
- this->SetLongVal((long)(!this->IsOn()), redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCheckBox::ToggleIf(Boolean matchState,
- Boolean redraw)
- {
- if (this->IsOn() == matchState)
- this->SetLongVal((long)(!this->IsOn()), redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TCheckBox::Fields(TObject* obj) // override
- {
- obj->DoToField("TCheckBox", NULL, bClass);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TRadio::Initialize(void) // override
- {
- inherited::Initialize();
-
- fDefChoice = mRadioHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TRadio::IRadio(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const Str255& itsLabel,
- Boolean isTurnedOn)
-
- {
- this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1, ((radioButProc) | useWFont));
- this->SetState(isTurnedOn, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TRadio::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
-
- {
- VRect itsArea;
-
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- this->ControlArea(itsArea);
- this->CreateCMgrControl(itsArea, ((RadioTemplatePtr)itsParams)->itsLabel, ((RadioTemplatePtr)itsParams)->isOn, 0, 1, (radioButProc | useWFont));
- OffsetPtrWStr(itsParams, sizeof(RadioTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TRadio::Clone(void) // override
- {
- TRadio * aClonedRadio;
-
- aClonedRadio = (TRadio *)(inherited::Clone());
-
- return aClonedRadio;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TRadio::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
-
- {
- Str255 theLabel;
-
- inherited::WRes(theResource, itsParams);
-
- this->GetText(theLabel);
-
- RadioTemplate& templateData = *((RadioTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(RadioTemplate), theLabel.Length()));
-
- templateData.isOn = this->IsOn();
- // templateData.itsLabel = theLabel;
- CopyStr255(theLabel, PRStr(templateData.itsLabel));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TRadio::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- gWResSignature = 'radb';
- gWResType = "TRadio";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TRadio::DoEvent(EvtNumber eventNumber,
- TEvtHandler*, // source
- TEvent* event) // override
-
- {
- if ((eventNumber == mRadioHit) &&!this->IsOn())
- this->Toggle(kRedraw);
- inherited::DoEvent(eventNumber, this, event);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal Boolean TRadio::IsOn(void)
- {
- return (this->GetLongVal() != 0);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TRadio::SetState(Boolean state,
- Boolean redraw)
- {
- this->SetLongVal((long)(state), redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TRadio::Toggle(Boolean redraw)
- {
- this->SetLongVal((long)(!this->IsOn()), redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TRadio::ToggleIf(Boolean matchState,
- Boolean redraw)
- {
- if (this->IsOn() == matchState)
- this->SetLongVal((long)(!this->IsOn()), redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TRadio::Fields(TObject* obj) // override
- {
- obj->DoToField("TRadio", NULL, bClass);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TCluster::Initialize(void) // override
-
- {
- inherited::Initialize();
-
- fDataHandle = NULL;
- fRsrcID = kNoResource;
- fIndex = 0; // ??? Is there a constant for this
-
- fDefChoice = mClusterHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TCluster::ICluster(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsRsrcID,
- short itsIndex)
-
-
- {
- Str255 aString;
- FailInfo fi;
-
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fRsrcID = itsRsrcID;
- fIndex = itsIndex;
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- GetIndString(aString, fRsrcID, fIndex);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
-
- this->SetLabel(aString, kDontRedraw);
- }
- this->SetEnable(False); // Default is not to enable hit testing
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TCluster::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
-
- {
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- this->SetLabel(((ClusterTemplatePtr)itsParams)->itsLabel, kDontRedraw);
-
- OffsetPtrWStr(itsParams, sizeof(ClusterTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TCluster::Clone(void) // override
- {
- TCluster * aClonedCluster;
- Str255 theLabel;
-
-
- aClonedCluster = (TCluster *)(inherited::Clone());
-
- aClonedCluster->fDataHandle = NULL;
- this->GetLabel(theLabel);
- aClonedCluster->SetLabel(theLabel, kDontRedraw);
-
- return aClonedCluster;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TCluster::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
-
- {
- Str255 theLabel;
-
- inherited::WRes(theResource, itsParams);
-
- this->GetLabel(theLabel);
-
- ClusterTemplate& templateData = *((ClusterTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(ClusterTemplate), theLabel.Length()));
-
- // templateData.itsLabel = theLabel;
- CopyStr255(theLabel, PRStr(templateData.itsLabel));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TCluster::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
-
- {
- gWResSignature = 'clus';
- gWResType = "TCluster";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TCluster::Free(void) // override
- {
- this->ReleaseLabel();
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCluster::DoEvent(EvtNumber eventNumber,
- TEvtHandler* source,
- TEvent* event)// override
- {
- // If we got this far, a radio's changed state. Only worry about it if it's our subview!
- if ((eventNumber == mRadioHit) && (((TView *)source)->fSuperView == this))
- {
- CSubViewIterator iter(this);
-
- for (TView* theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- // If the subview is a TRadio, and it's not the calling radio…
- if (theSubView->IsMemberClass(GetClassIDFromName("TRadio")) && (theSubView != source))
- ((TRadio *)theSubView)->SetState(False, kRedraw); // …set it off and redraw it
- }
-
- inherited::DoEvent(eventNumber, source, event);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCluster::Draw(const VRect& area) // override
- {
- short theFontHeight;
- VCoordinate theFrameTop;
- VRect theFrame;
- Rect theQDFrame;
- RGBColor oldColor;
- TextStyle aTextStyle;
- FontInfo theFontInfo;
-
- if (fDataHandle)
- {
- PenNormal(); // Normalcy in most things
-
- PenSize(fPenSize.h, fPenSize.v); // PenSize(2, 2);
-
- GetIfColor(oldColor); // Save the original pen color
- aTextStyle = fTextStyle;
- GetTextStyleFontInfo(aTextStyle, theFontInfo, theFontHeight);
- this->ControlArea(theFrame); // Get the control's extent
- theFrameTop = theFrame.top + ((theFontHeight) >> 1);
-
- theFrame.Inset(VPoint(fPenSize.v + 1, fPenSize.h + 1)); // Inset the frame a little.
-
- theFrame.top = theFrameTop; // Bump top so it cuts label in half
-
- this->ViewToQDRect(theFrame, theQDFrame);
- FrameRect(theQDFrame); // Draw the frame
- this->DrawLabel(area); // Draw the label
-
- SetIfColor(oldColor);
- }
- inherited::Draw(area); // Let parents have a chance to draw too
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TCluster::DrawLabel(const VRect& /* area */)
- {
- TextStyle aTextStyle;
- Str255 theText;
- Rect labelQDRect;
- VRect dstRect;
- FontInfo theFontInfo;
-
-
- aTextStyle = fTextStyle;
- SetPortTextStyle(aTextStyle); // Install the object's TextStyle
-
- this->GetLabel(theText); // retrieve the label
-
- MAReplaceText(theText);
-
- VRect labelRect(0, 16, MAGetFontInfo(theFontInfo), StringWidth(theText) + 8 + 16);
- if ((labelRect & dstRect).Valid())
- {
- this->ViewToQDRect(labelRect, labelQDRect);
- MATextBox((Ptr)(((long) & theText) + 1), theText.Length(), labelQDRect, teCenter, kNoAutoWrap, NULL, kEraseFirst, kNoSpaceForCaret);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TCluster::GetLabel(Str255& theLabel)
- {
- if (fDataHandle)
- CopyStr255((**((String255Handle)fDataHandle)), (Ptr) & theLabel);
- else
- theLabel = "";
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TCluster::ReleaseLabel(void)
- {
- fDataHandle = (StringHandle)DisposeIfHandle((Handle)fDataHandle);
-
- fRsrcID = kNoResource;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal Boolean FindRadio(TView* aView,
- void* /* staticLink */)
- {
- return (aView && aView->IsMemberClass(GetClassIDFromName("TRadio")) && ((TRadio *)aView)->IsOn());
- }
-
-
- pascal IDType TCluster::ReportCurrent(void)
- {
- TView * rView;
-
- rView = this->FirstSubViewThat(FindRadio, this);
- if (rView)
- return (rView->fIdentifier);
- else
- return kNoIdentifier;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TCluster::SetLabel(const Str255& theLabel,
- Boolean redraw)
-
- {
- this->ReleaseLabel();
- if (!theLabel.IsEmpty())
- {
- fDataHandle = NewString(theLabel);
- if (MemError() != noErr)
- fDataHandle = NULL;
- }
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TCluster::Fields(TObject* obj) // override
- {
- Str255 aString;
-
- obj->DoToField("TCluster", NULL, bClass);
- obj->DoToField("fRsrcID", &fRsrcID, bInteger);
- obj->DoToField("fIndex", &fIndex, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
- if (fDataHandle)
- {
- aString = (**((String255Handle)fDataHandle));
- obj->DoToField("**fDataHandle", &aString, bString);
- }
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TIcon::Initialize(void) // override
-
- {
- inherited::Initialize();
-
- fDataHandle = NULL;
- fIsColor = kPreferColor;
- fPreferColor = kPreferColor;
- fRsrcID = kNoResource;
-
- fDefChoice = mIconHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TIcon::IIcon(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsRsrcID,
- Boolean preferColor)
-
- {
- FailInfo fi;
- Handle itsRsrcHandle;
- SignedByte savedState;
-
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fPreferColor = preferColor;
- fIsColor = preferColor;
- fRsrcID = itsRsrcID;
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
- {
- // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
- itsRsrcHandle = GetResource('cicn', fRsrcID);
- if (itsRsrcHandle)
- {
- savedState = HGetState(itsRsrcHandle);
- HNoPurge(itsRsrcHandle);
- }
-
- fDataHandle = (Handle)GetCIcon(fRsrcID);
-
- // restore the state of the 'cicn' resource
- if (itsRsrcHandle)
- HSetState(itsRsrcHandle, savedState);
- }
- if (fDataHandle == NULL)
- {
- fDataHandle = GetIcon(fRsrcID);
- if (fDataHandle)
- fIsColor =!kPreferColor; // Either can't or won't
- }
- FailNILResource(fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
- this->SetEnable(False); // Default is to not enable hit testing }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TIcon::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- FailInfo fi;
- Handle itsRsrcHandle;
- SignedByte savedState;
-
- fDataHandle = NULL;
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- IconTemplate& templateData = *((IconTemplate *) itsParams);
-
- fPreferColor = templateData.preferColor;
- fIsColor = templateData.preferColor;
- fRsrcID = templateData.rsrcID;
-
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
- {
- // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
- itsRsrcHandle = GetResource('cicn', fRsrcID);
- if (itsRsrcHandle)
- {
- savedState = HGetState(itsRsrcHandle);
- HNoPurge(itsRsrcHandle);
- }
-
- fDataHandle = (Handle)GetCIcon(fRsrcID);
-
- // restore the state of the 'cicn' resource
- if (itsRsrcHandle)
- HSetState(itsRsrcHandle, savedState);
- }
- if (fDataHandle == NULL)
- {
- fDataHandle = GetIcon(fRsrcID);
- if (fDataHandle)
- fIsColor =!kPreferColor; // Either can't or won't
- }
- // Don't die because resource not found - just return NULL handle
- FailNILResource(fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
-
- OffsetPtr(itsParams, sizeof(IconTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TIcon::Clone(void) // override
- {
- TIcon * aClonedIcon;
- Handle aHandle;
- OSErr err;
- Handle itsRsrcHandle;
- SignedByte savedState;
-
-
- aClonedIcon = (TIcon *)(inherited::Clone());
- aClonedIcon->fDataHandle = NULL;
-
- if (fDataHandle)
- {
- if (fIsColor)
- {
- // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
- itsRsrcHandle = GetResource('cicn', fRsrcID);
- if (itsRsrcHandle)
- {
- savedState = HGetState(itsRsrcHandle);
- HNoPurge(itsRsrcHandle);
- }
-
- aClonedIcon->fDataHandle = (Handle)GetCIcon(fRsrcID);
-
- // restore the state of the 'cicn' resource
- if (itsRsrcHandle)
- HSetState(itsRsrcHandle, savedState);
- }
- else
- {
- aHandle = fDataHandle;
- err = HandToHand(aHandle);
- if (err != noErr)
- FailNIL(aHandle);
- aClonedIcon->fDataHandle = aHandle;
- }
- }
- return aClonedIcon;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TIcon::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- inherited::WRes(theResource, itsParams);
-
- IconTemplate& templateData = *((IconTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(IconTemplate)));
-
- templateData.preferColor = fPreferColor;
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Tried to write TIcon with no resource ID.\n");
- #endif
-
- templateData.rsrcID = fRsrcID;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TIcon::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- gWResSignature = 'icon';
- gWResType = "TIcon";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TIcon::Free(void) // override
- {
- this->ReleaseIcon();
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TIcon::Draw(const VRect& area) // override
- {
- SignedByte oldState;
- VRect theRect;
- Rect theQDRect;
- PixMap aPixMap;
- BitMapPtr aBitMapPtr;
- Rect srcRect;
-
-
- if (fDataHandle)
- {
- if (IsAResource(fDataHandle))
- LoadResource(fDataHandle);
- if (*fDataHandle) // If there's room for the icon…
- {
- PenNormal(); // NECESSARY?
- this->ControlArea(theRect);
- this->ViewToQDRect(theRect, theQDRect);
- oldState = HGetState(fDataHandle);
- HNoPurge(fDataHandle);
- HLock(fDataHandle);
-
- if (fIsColor)
- {
-
- // We can't use PlotCIcon here because it can't be written to a picture
- // and when WriteToDeskScrap is called, the icon is plotted on the
- // desktop rather than in the picture. So instead, pick apart the color
- // icon handle and use copybits, ignoring the mask.
-
- aPixMap = (**((CIconHandle)fDataHandle)).iconPMap;
- HLock((**((CIconHandle)fDataHandle)).iconData);
- aPixMap.baseAddr = *((**((CIconHandle)fDataHandle)).iconData);
- srcRect = aPixMap.bounds;
- aBitMapPtr = (BitMapPtr) & aPixMap;
- CopyBits((*aBitMapPtr), qd.thePort->portBits, srcRect, theQDRect, srcCopy, NULL);
- HUnlock((**((CIconHandle)fDataHandle)).iconData);
- }
- else
- PlotIcon(theQDRect, fDataHandle);
-
- HSetState(fDataHandle, oldState);
- }
- }
-
- inherited::Draw(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TIcon::ReleaseIcon(void)
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- {
- if (fIsColor)
- DisposCIcon((CIconHandle)fDataHandle);
- else
- HPurge(fDataHandle);
- fDataHandle = NULL;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TIcon::SetIcon(Handle theIcon,
- Boolean redraw)
- {
- short theID;
- ResType theType;
- Str255 name;
-
-
- this->ReleaseIcon();
- if (GetHandleSize(theIcon) != 128)
- fPreferColor = TRUE;
- else
- fPreferColor = FALSE;
- fDataHandle = theIcon;
-
- // get the rsrc id
- GetResInfo(theIcon, theID, theType, name);
- if (ResError() == noErr)
- fRsrcID = theID;
-
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TIcon::Fields(TObject* obj) // override
- {
- obj->DoToField("TIcon", NULL, bClass);
- obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
- obj->DoToField("fIsColor", &fIsColor, bBoolean);
- obj->DoToField("fRsrcID", &fRsrcID, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TSmallIcon::Initialize(void) // override
- {
- inherited::Initialize();
- fDataHandle = NULL;
- fRsrcID = kNoResource;
- fDefChoice = mSmallIconHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TSmallIcon::ISmallIcon(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsRsrcID)
- {
- FailInfo fi;
-
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fRsrcID = itsRsrcID;
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- fDataHandle = GetResource('SICN', fRsrcID);
- FailNILResource(fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
- this->SetEnable(False); // Default is to not enable hit testing
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TSmallIcon::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- const short kReadOnlySICN = 256; // resource ID of small slashed pencil icon
- FailInfo fi;
-
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- // fRsrcID = ((SmallIconTemplatePtr) itsParams)->rsrcID;
- fRsrcID = kReadOnlySICN; // !!! change when templates are updated
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- fDataHandle = GetResource('SICN', fRsrcID);
- FailNILResource(fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
-
- // OffsetPtr(itsParams, sizeof(SmallIconTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TSmallIcon::Clone(void) // override
- {
- TSmallIcon * aClonedSmallIcon;
- Handle aHandle;
- OSErr err;
-
-
- aClonedSmallIcon = (TSmallIcon *)(inherited::Clone());
-
- aHandle = aClonedSmallIcon->fDataHandle;
- if (aHandle)
- {
- err = HandToHand(aHandle);
- if (err != noErr)
- FailNIL(aHandle);
- aClonedSmallIcon->fDataHandle = aHandle;
- }
-
- return aClonedSmallIcon;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TSmallIcon::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- inherited::WRes(theResource, itsParams);
-
- SmallIconTemplate& templateData = *((SmallIconTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(SmallIconTemplate)));
-
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Tried to write TSmallIcon with no resource ID.\n");
- #endif
-
- templateData.rsrcID = fRsrcID;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TSmallIcon::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams)// override
- {
- gWResSignature = 'SICN';
- gWResType = "TSmallIcon";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TSmallIcon::Draw(const VRect& area) // override
- {
- SignedByte oldState;
- VRect theRect;
- Rect theQDRect;
- BitMap srcBits;
- GrafPtr port;
-
-
- #if qDebug
- this->AssumeFocused();
- #endif
-
- if (fDataHandle)
- {
- if (IsAResource(fDataHandle))
- LoadResource(fDataHandle);
- if (*fDataHandle) // If there's room for the small icon…
- {
- this->ControlArea(theRect);
- this->ViewToQDRect(theRect, theQDRect);
- oldState = HGetState(fDataHandle);
- HNoPurge(fDataHandle);
- // construct a source BitMap
- srcBits.baseAddr = (*fDataHandle);
- srcBits.rowBytes = 2;
- SetRect(srcBits.bounds, 0, 0, 16, 16);
-
- GetPort(port);
- CopyBits(srcBits, port->portBits, srcBits.bounds, theQDRect, srcCopy, NULL);
- HSetState(fDataHandle, oldState);
- }
- }
-
- inherited::Draw(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TSmallIcon::ReleaseSmallIcon(void)
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- HPurge(fDataHandle);
- fDataHandle = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TSmallIcon::SetSmallIcon(short theSmallIcon,
- Boolean redraw)
- {
- FailInfo fi;
-
- this->ReleaseSmallIcon();
- if (fi.Try())
- {
- fDataHandle = GetResource('SICN', theSmallIcon);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- fRsrcID = theSmallIcon;
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TSmallIcon::Fields(TObject* obj) // override
- {
- obj->DoToField("TSmallIcon", NULL, bClass);
- obj->DoToField("fRsrcID", &fRsrcID, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TPattern::Initialize(void) // override
- {
- inherited::Initialize();
-
- fDataHandle = NULL;
- fPreferColor = kPreferColor;
- fIsColor = kPreferColor;
- fRsrcID = kNoResource;
-
- fDefChoice = mPatternHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TPattern::IPattern(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsRsrcID,
- Boolean preferColor)
- {
- FailInfo fi;
-
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fPreferColor = preferColor;
- fIsColor = preferColor;
- fRsrcID = itsRsrcID;
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
- fDataHandle = (Handle)GetPixPat(fRsrcID);
- if (fDataHandle == NULL)
- {
- fDataHandle = (Handle)GetPattern(fRsrcID);
- if (fDataHandle)
- fIsColor =!kPreferColor; // Either can't or won't
- }
- FailNILResource(fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
- this->SetEnable(False); // Default is to not enable hit testing
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TPattern::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- FailInfo fi;
-
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- PatternTemplate& templateData = *((PatternTemplate *) itsParams);
- fPreferColor = templateData.preferColor;
- fIsColor = templateData.preferColor;
- fRsrcID = templateData.rsrcID;
-
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
- fDataHandle = (Handle)GetPixPat(fRsrcID);
- if (fDataHandle == NULL)
- {
- fDataHandle = (Handle)GetPattern(fRsrcID);
- if (fDataHandle)
- fIsColor =!kPreferColor; // Either can't or won't
- }
- FailNILResource(fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
-
- OffsetPtr(itsParams, sizeof(PatternTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TPattern::Clone(void) // override
- {
- TPattern * aClonedPattern;
- FailInfo fi;
- Handle aHandle;
- OSErr err;
-
- VOLATILE(aClonedPattern);
-
- aClonedPattern = (TPattern *)(inherited::Clone());
-
- if (fDataHandle)
- {
- if (fi.Try())
- {
- if (fIsColor)
- aClonedPattern->fDataHandle = (Handle)GetPixPat(fRsrcID);
- else
- {
- aHandle = fDataHandle;
- err = HandToHand(aHandle);
- aClonedPattern->fDataHandle = aHandle;
- }
- FailNIL(aClonedPattern->fDataHandle);
- fi.Success();
- }
- else // Recover
- {
- aClonedPattern->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedPattern;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TPattern::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- inherited::WRes(theResource, itsParams);
-
- PatternTemplate& templateData = *((PatternTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(PatternTemplate)));
-
- templateData.preferColor = fPreferColor;
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Tried to write TPattern with no resource ID.\n");
- #endif
-
- templateData.rsrcID = fRsrcID;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TPattern::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- gWResSignature = 'patn';
- gWResType = "TPattern";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TPattern::Free(void) // override
- {
- this->ReleasePattern();
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TPattern::Draw(const VRect& area) // override
- {
- Boolean wasLocked;
- VRect theRect;
- Rect theQDRect;
-
- if (fDataHandle)
- {
- if (IsAResource(fDataHandle) &&!fIsColor)// Pixpat handles != resource handles
- LoadResource(fDataHandle);
- if (*fDataHandle) // If there's room for the pattern…
- {
- PenNormal(); // NECESSARY?
- this->ControlArea(theRect);
- this->ViewToQDRect(theRect, theQDRect);
- wasLocked = IsHandleLocked(fDataHandle);// Remember current lock state
- if (!wasLocked)
- HLock(fDataHandle); // Because FillRect may move memory
- if (fIsColor)
- FillCRect(theQDRect, (PixPatHandle)fDataHandle);
- else
- FillRect(theQDRect, *((PatHandle)fDataHandle));
- if (!wasLocked)
- HUnlock(fDataHandle); // restore handle's unlocked state
- }
- }
-
- inherited::Draw(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TPattern::ReleasePattern(void)
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- {
- if (fIsColor)
- DisposPixPat((PixPatHandle)fDataHandle);
- else
- HPurge(fDataHandle);
- fDataHandle = NULL;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TPattern::SetPattern(Handle thePattern,
- Boolean redraw)
- {
- short theID;
- ResType theType;
- Str255 name;
-
- this->ReleasePattern();
- fDataHandle = thePattern;
-
- // get the rsrc id for non-color patterns (color pattern handles aren't resource handles)
- if (!fIsColor)
- {
- GetResInfo(thePattern, theID, theType, name);
- if (ResError() == noErr)
- fRsrcID = theID;
- }
-
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TPattern::Fields(TObject* obj) // override
- {
- obj->DoToField("TPattern", NULL, bClass);
- obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
- obj->DoToField("fIsColor", &fIsColor, bBoolean);
- obj->DoToField("fRsrcID", &fRsrcID, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TPicture::Initialize(void) // override
- {
- inherited::Initialize();
-
- fDataHandle = NULL;
- fRsrcID = kNoResource;
-
- fDefChoice = mPictureHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TPicture::IPicture(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsRsrcID)
- {
- FailInfo fi;
-
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fRsrcID = itsRsrcID;
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- fDataHandle = GetPicture(fRsrcID);
- FailNILResource((Handle)fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
- this->SetEnable(False); // Default is to not enable hit testing
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TPicture::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- FailInfo fi;
-
- fDataHandle = NULL;
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- fRsrcID = ((PictureTemplatePtr)itsParams)->rsrcID;
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- fDataHandle = GetPicture(fRsrcID);
- FailNILResource((Handle)fDataHandle); // was FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
-
- OffsetPtr(itsParams, sizeof(PictureTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TPicture::Clone(void) // override
- {
- TPicture * aClonedPicture;
- FailInfo fi;
-
- VOLATILE(aClonedPicture);
-
- aClonedPicture = (TPicture *)(inherited::Clone());
-
- if (fDataHandle)
- {
- aClonedPicture->fDataHandle = NULL;
- if (fi.Try())
- {
- aClonedPicture->fDataHandle = GetPicture(fRsrcID);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- aClonedPicture->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedPicture;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TPicture::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- inherited::WRes(theResource, itsParams);
-
- PictureTemplate& templateData = *((PictureTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(PictureTemplate)));
-
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Tried to write TPicture with no resource ID.\n");
- #endif
-
- templateData.rsrcID = fRsrcID;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TPicture::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- gWResSignature = 'pict';
- gWResType = "TPicture";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TPicture::Free(void) // override
- {
- this->ReleasePicture();
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TPicture::Draw(const VRect& area) // override
- {
- SignedByte oldState;
- VRect theRect;
- Rect theQDRect;
-
-
- if (fDataHandle)
- {
- if (IsAResource((Handle)fDataHandle))
- LoadResource((Handle)fDataHandle);
- if (*fDataHandle) // If there's room for the picture…
- {
- this->ControlArea(theRect);
- this->ViewToQDRect(theRect, theQDRect);
- oldState = HGetState((Handle)fDataHandle);
- HNoPurge((Handle)fDataHandle);
- PenNormal(); // ??? NECESSARY ???
- DrawPicture(fDataHandle, theQDRect);
- HSetState((Handle)fDataHandle, oldState);
- }
- }
- inherited::Draw(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TPicture::ReleasePicture(void)
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- {
- HPurge((Handle)fDataHandle);
- fDataHandle = NULL;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TPicture::SetPicture(PicHandle thePicture,
- Boolean redraw)
- {
- short theID;
- ResType theType;
- Str255 name;
-
- this->ReleasePicture();
- fDataHandle = thePicture;
-
- // get the rsrc id
- GetResInfo((Handle)thePicture, theID, theType, name);
- if (ResError() == noErr)
- fRsrcID = theID;
-
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TPicture::Fields(TObject* obj) // override
- {
- obj->DoToField("TPicture", NULL, bClass);
- obj->DoToField("fRsrcID", &fRsrcID, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TEOpen
-
- pascal void TDialogTEView::Initialize(void) // override
- {
- inherited::Initialize();
-
- fEditText = NULL; /* We don't own this reference but we don't
- want an invalid one either */
- fScroller = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TEOpen
-
- pascal void TDialogTEView::IDialogTEView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHDeterminer,
- SizeDeterminer itsVDeterminer,
- const VRect& itsInset,
- const TextStyle& itsTextStyle,
- short itsJustification,
- Boolean itsStyleType,
- Boolean itsAutoWrap)
-
- {
- FailInfo fi;
- TScroller * aScroller;
- VOLATILE(aScroller);
-
- this->ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer, itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
-
- if (fi.Try())
- {
- aScroller = new TScroller;
- aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
- aScroller->AddSubView(this);
- }
- else // Recover
- {
- aScroller = (TScroller *)FreeIfObject(aScroller);
- this->Free();
- fi.ReSignal();
- }
- fScroller = aScroller;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TEOpen
-
- pascal void TDialogTEView::IRes(TDocument* itsDocument,
- TView* itsSuperView,
- Ptr& itsParams) // override
-
- {
- FailInfo fi;
- TScroller * aScroller;
- VOLATILE(aScroller);
-
- inherited::IRes(itsDocument, itsSuperView, itsParams);
-
- if (fi.Try())
- {
- aScroller = new TScroller;
- aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
- aScroller->AddSubView(this);
- }
- else // Recover
- {
- aScroller = (TScroller *)FreeIfObject(aScroller);
- this->Free();
- fi.ReSignal();
- }
- fScroller = aScroller;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TDialogTEView::Clone(void) // override
- {
- TDialogTEView * aClonedDialogTEView;
-
- aClonedDialogTEView = (TDialogTEView *)(inherited::Clone());
-
- aClonedDialogTEView->fEditText = NULL; // no current edittext
-
- if (aClonedDialogTEView->fScroller)
- aClonedDialogTEView->fScroller = (TScroller *)(aClonedDialogTEView->fScroller->Clone());
-
- return aClonedDialogTEView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TEClose
-
- pascal void TDialogTEView::Free(void) // override
- {
- if (fScroller)
- {
- fScroller->RemoveSubView(this);
- fScroller = (TScroller *)FreeIfObject(fScroller);
- }
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TDialogTEView::Fields(TObject* obj) // override
- {
- obj->DoToField("TDialogTEView", NULL, bClass);
- obj->DoToField("fEditText", &fEditText, bObject);
- obj->DoToField("fScroller", &fScroller, bObject);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogTEView::BecameWindowTarget(void) // override
- {
- inherited::BecameWindowTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogTEView::BecameApplicationTarget(void) // override
- {
- inherited::BecameApplicationTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TDialogTEView::InstallEditText(TEditText* theEditText,
- Boolean selectChars)
-
- {
- Str255 theText;
- TextStyle aTextStyle;
- VRect theControlArea;
- VRect validExtent;
- Boolean hadPendingUpdate;
-
- if (fEditText)
- {
- fEditText->RemoveSubView(fScroller);
- fEditText = NULL;
- }
-
- if (theEditText)
- {
- fControlChars = theEditText->fControlChars;
- fMaxChars = theEditText->fMaxChars;
- fInset = gZeroVRect;
- hadPendingUpdate = theEditText->HasPendingUpdate();
-
- this->SetJustification(theEditText->fJust, kDontRedraw);
- this->ChangeWrap(theEditText->fAutoWrap, kDontRedraw);
-
- aTextStyle = theEditText->fTextStyle;
- this->SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
-
- theEditText->ControlArea(theControlArea);
-
- theEditText->AddSubView(fScroller); // my scroller
-
- if (fAutoWrap)
- fSizeDeterminer[hSel] = sizeSuperView;
- else
- fSizeDeterminer[hSel] = sizeVariable;/* Let the width vary with the number of
- characters */
-
- fSuperView->Resize(VPoint(theControlArea.Length(vSel),theControlArea.Length(hSel)), kDontInvalidate);
- fSuperView->Locate(theControlArea[topLeft], kDontInvalidate);
-
- theEditText->GetText(theText);
- this->SetText(theText);
- this->RecalcText();
- this->SynchView(kDontRedraw);
- this->AdjustSize();
-
- // Make the scroller's thinking match the display that the user already sees
- fScroller->fTranslation.h = 0;
- switch (GetActualJustification(fJustification))
- {
- case teFlushDefault:
- case teFlushLeft:
- fScroller->fTranslation.v = 0;
- break;
- case teFlushRight: /* Right brain thinkers… left brain thinkers?? */
- ((TScroller *)fSuperView)->fTranslation.h = fScroller->fMaxTranslation.h;
- break;
- case teCenter:
- fScroller->fTranslation.h = fScroller->fMaxTranslation.h / 2;
- break;
- }
- theEditText->InvalidateFocus();
- theEditText->UpdateCoordinates();
-
- if (selectChars)
- SetSelect(0, MAXINT, fHTE);
- else
- SetSelect(0, 0, fHTE); // Caller will set the selection.
-
- this->BeInScroller(fScroller);
-
- // Make my enable and my scroller's enable match my new superview
- this->SetEnable(theEditText->IsEnabled());
- fScroller->SetEnable(theEditText->IsEnabled());
-
- // Revalidate my extent to eliminate the flicker created by resizing the scrollers
- //!!! RCR && SRF Revisit this
- #if FALSE
- if (!hadPendingUpdate)
- {
- this->GetExtent(validExtent);
- this->ValidateVRect(validExtent);
- }
- #endif
-
- }
-
- fEditText = theEditText;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogTEView::ResignedWindowTarget(void) // override
- {
- inherited::ResignedWindowTarget();
-
- /* If we're deselecting a field and it's been scrolled, invalidate it
- so that it is redrawn correctly.*/
- if (fScroller->fTranslation.v != 0)
- this->ForceRedraw();
- else
- {
- switch (GetActualJustification(fJustification))
- {
- case teFlushDefault:
- case teFlushLeft:
- if (fScroller->fTranslation.h != 0)
- this->ForceRedraw();
- break;
- case teFlushRight:
- if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
- this->ForceRedraw();
- break;
- case teCenter:
- if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
- this->ForceRedraw();
- break;
- }
- }
-
- if (fEditText)
- fEditText->StopEdit();
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogTEView::ResignedApplicationTarget(void) // override
- {
- inherited::ResignedApplicationTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TDialogTEView::TargetValidationFailed(long reason)// override
- {
- if (fEditText)
- fEditText->TargetValidationFailed(reason);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal long TDialogTEView::WillingToResignTarget(void)// override
- {
- TCommand * lastCommand;
- long result;
-
- result = 0;
-
- if (fEditText)
- {
- lastCommand = this->GetLastCommand();
- if ((lastCommand) && (lastCommand->fView == this))
- this->CommitLastCommand();
-
- result = fEditText->Validate();
- }
- return result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TDialogTEView::ComputeSize(VPoint& newSize)// override
- {
- inherited::ComputeSize(newSize);
-
- if (!fAutoWrap)
- switch (fSizeDeterminer[hSel])
- {
- case sizeVariable:
- /* TTEView already computed the variable size, bump it up to at leat the scroller's
- size so that the cursor is claimed for the EditText and the user can click anywhere. */
- if (!fStyleType)
- newSize.h = Max(fScroller->fSize.h, newSize.h);
- break;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TStaticText::Initialize(void) // override
- {
- inherited::Initialize();
-
- fDataHandle = NULL;
- fRsrcID = kNoResource;
- fIndex = 0;
- fJust = teFlushDefault; // Default to system justification
- fAutoWrap = TRUE; // Default to compatibility with 2.0
-
- fDefChoice = mStaticTextHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TStaticText::IStaticText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short itsRsrcID,
- short itsIndex)
- {
- Str255 aString;
- FailInfo fi;
-
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fRsrcID = itsRsrcID;
- fIndex = itsIndex;
-
- //fJust = teFlushDefault;
- //fAutoWrap = TRUE;
-
- if (fRsrcID != kNoResource)
- {
- if (fi.Try())
- {
- GetIndString(aString, fRsrcID, fIndex);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- this->SetText(aString, kDontRedraw);
- }
- this->SetEnable(False); // Default is to not enable hit testing
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TStaticText::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- //fAutoWrap = TRUE;
- //fDefChoice = mStaticTextHit;
-
- StaticTextTemplate& templateData = *((StaticTextTemplate *) itsParams);
-
- fJust = templateData.just;
- this->SetText(templateData.data, kDontRedraw);
-
- OffsetPtrWStr(itsParams, sizeof(StaticTextTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TStaticText::Clone(void) // override
- {
- TStaticText * aClonedStaticText;
- StringHandle newString;
-
- aClonedStaticText = (TStaticText *)(inherited::Clone());
-
- newString = aClonedStaticText->fDataHandle;
- if (newString)
- FailOSErr(HandToHand((Handle&)newString));
- aClonedStaticText->fDataHandle = newString;
-
- return aClonedStaticText;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TStaticText::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- Str255 theText;
-
- inherited::WRes(theResource, itsParams);
-
- this->GetText(theText);
-
- StaticTextTemplate& templateData = *((StaticTextTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(StaticTextTemplate), theText.Length()));
-
- templateData.just = fJust;
- // templateData.data = theText;
- CopyStr255(theText, PRStr(templateData.data));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TStaticText::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams)// override
- {
- gWResSignature = 'stat';
- gWResType = "TStaticText";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TStaticText::Free(void) // override
- {
- this->ReleaseText();
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TStaticText::ChangeWrap(Boolean newAutoWrap,
- Boolean redraw)
- {
- fAutoWrap = newAutoWrap;
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TStaticText::DoSubstitution(Str255& theText)
-
- {
- MAReplaceText(theText);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TStaticText::Draw(const VRect& area)// override
- {
- VRect theRect;
- RGBColor oldColor;
- Str255 theText;
- TextStyle aTextStyle;
-
- if (fDataHandle)
- {
- this->GetText(theText);
- this->DoSubstitution(theText); // Make the substitution if desired
- this->ControlArea(theRect);
- PenNormal(); // ??? NECESSARY ???
- GetIfColor(oldColor);
- aTextStyle = fTextStyle;
- SetPortTextStyle(aTextStyle);
- this->ImageText((Ptr)(((long) & theText) + 1), theText.Length(), theRect, fJust);
- SetIfColor(oldColor);
- }
- inherited::Draw(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TStaticText::GetText(Str255& theText)
- {
- if (fDataHandle)
- CopyStr255((**((String255Handle)fDataHandle)), (Ptr)&theText);
- else
- theText = "";
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TStaticText::ImageText(Ptr text,
- long Length,
- const VRect& box,
- short just)
- {
- Rect qdBox;
-
- this->ViewToQDRect(box, qdBox);
- MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TStaticText::ReleaseText(void)
- {
- fDataHandle = (StringHandle)DisposeIfHandle((Handle)fDataHandle);
-
- fRsrcID = kNoResource;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TStaticText::SetJustification(short theJust,
- Boolean redraw)
- {
- fJust = theJust;
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TStaticText::SetText(const Str255& theText,
- Boolean redraw)
- {
- VRect area;
- Rect qdArea;
-
-
- if ((fDataHandle == NULL) || (theText != (**((String255Handle)fDataHandle))))
- {
- this->ReleaseText();
- fDataHandle = NewString(theText);
- if (MemError() != noErr)
- fDataHandle = NULL;
- if (redraw && this->IsDrawable())
- {
- this->ControlArea(area);
- this->ViewToQDRect(area, qdArea);
- EraseRect(qdArea);
- this->Draw(area);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TStaticText::Fields(TObject* obj) // override
- {
- Str255 aString;
-
- obj->DoToField("TStaticText", NULL, bClass);
- obj->DoToField("fRsrcID", &fRsrcID, bInteger);
- obj->DoToField("fIndex", &fIndex, bInteger);
- obj->DoToField("fDataHandle", &fDataHandle, bHandle);
- if (fDataHandle)
- {
- aString = (**((String255Handle)fDataHandle));
- obj->DoToField("(**fDataHandle)", &aString, bString);
- }
- obj->DoToField("fJust", &fJust, bInteger);
- obj->DoToField("fAutoWrap", &fAutoWrap, bBoolean);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TEditText::Initialize(void) // override
- {
- inherited::Initialize();
-
- fTEView = NULL;
- fMaxChars = 255; // Is there a constant?
-
- fControlChars = ASSETELEM(chLeft) | ASSETELEM(chRight) | ASSETELEM(chUp) | ASSETELEM(chDown) | ASSETELEM(chBackspace);
- fTextStyle = gSystemStyle;
- fPenSize = Point(1,1); // …and a thin frame
- this->SetAdornment(kFrame, kDontRedraw);
- fAutoWrap = False; /* Default to compatibility with 2.0 Never
- the twain shall meet.*/
- fDefChoice = mEditTextHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TEditText::IEditText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- short itsMaxChars)
- {
- this->IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
-
- fAutoWrap = False; /* Default to compatibility with 2.0 Never
- the twain shall meet.*/
- fMaxChars = itsMaxChars;
- fTextStyle = gSystemStyle;
- this->Inset(3, 3, kDontRedraw); // Default is a little, teeny inset…
- fPenSize = Point(1,1); // …and a thin frame
- this->SetAdornment(kFrame, kDontRedraw);
- this->SetEnable(TRUE);
- fDefChoice = mEditTextHit;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TEditText::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- fAutoWrap = False; /* Default to compatibility with 2.0 Never
- the twain shall meet.*/
- EditTextTemplate& templateData = *((EditTextTemplate *) itsParams);
-
- fMaxChars = templateData.maxChars;
- fControlChars = templateData.controlChars;
-
- fDefChoice = mEditTextHit;
-
- OffsetPtr(itsParams, sizeof(EditTextTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TObject* TEditText::Clone(void) // override
- {
- TEditText * aClonedEditText;
-
- aClonedEditText = (TEditText *)(inherited::Clone());
-
- aClonedEditText->fTEView = NULL;
-
- return aClonedEditText;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- pascal void TEditText::Free(void) // override
-
- {
- this->RemoveFloatingTEView();
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TEditText::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- inherited::WRes(theResource, itsParams);
-
- EditTextTemplate& templateData = *((EditTextTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(EditTextTemplate)));
-
- templateData.maxChars = fMaxChars;
- templateData.controlChars = fControlChars;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TEditText::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
- {
- gWResSignature = 'edit';
- gWResType = "TEditText";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::BecameWindowTarget(void) // override
- {
- this->StartEdit(TRUE);
-
- inherited::BecameWindowTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::BecameApplicationTarget(void) // override
- {
- /*
- if (fTEView)
- fTEView->BecomeApplicationTarget();
- else
- this->StartEdit(TRUE);
- */
- inherited::BecameApplicationTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TEditText::TargetValidationFailed(long reason)
- {
- Str255 aString;
-
- if (reason != kValidValue)
- {
- if (reason != kErrorHandled) // go ahead and post an alert
- {
- if ((reason < 1) || (reason > kNoOfDefaultReasons))
- reason = kInvalidValue;
-
- GetIndString(aString, (short)kInvalidValueReasons, (short)reason);//!!! Note casting
- ParamText(aString, "", "", "");
- StdAlert(phInvalidValue);
- }
- aString = (**((String255Handle)fDataHandle));// Restart with previous value
- this->RestartEdit(aString);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::ChangeWrap(Boolean newAutoWrap,
- Boolean redraw)// override
- {
- inherited::ChangeWrap(newAutoWrap, redraw);
- if (fTEView)
- fTEView->ChangeWrap(newAutoWrap, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal Boolean TEditText::Deselect(void)
- {
- long validateResult;
- TCommand * lastCommand;
- Boolean result;
-
-
- result = TRUE;
-
- /* Commit the last command to prevent undo from applying to the wrong edit text,
- and to ensure that all changes are made before validating. */
- if (fTEView)
- {
- lastCommand = fTEView->GetLastCommand();
- if ((lastCommand) && (lastCommand->fView == fTEView))
- fTEView->CommitLastCommand();
- }
-
- validateResult = this->Validate();
- if (validateResult == kValidValue)
- this->StopEdit();
- else
- {
- this->TargetValidationFailed(validateResult);
- result = FALSE;
- }
- return result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::DoSubstitution(Str255& theText)// override
- {
- // Default action is for editable text items is not to do any substitions
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TEditText::Fields(TObject* obj) // override
- {
- obj->DoToField("TEditText", NULL, bClass);
- obj->DoToField("fMaxChars", &fMaxChars, bInteger);
- obj->DoToField("fTEView", &fTEView, bObject);
- obj->DoToField("fControlChars", &fControlChars, bHexLongInt);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::GetText(Str255& theText) // override
- {
- Handle theChars;
- short numberOfChars;
-
-
- if (fTEView == NULL)
- inherited::GetText(theText);
- else
- {
- theChars = fTEView->ExtractText();
- numberOfChars = (short)Min(255, GetHandleSize(theChars));//!!! Note cast
- theText[0] = ((char)(numberOfChars));
- BlockMove((Ptr)(*theChars), (Ptr)(((long) & theText) + 1), numberOfChars);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::ImageText(Ptr text,
- long Length,
- const VRect& box,
- short just) // override
- {
- Rect qdBox;
-
- if (Length >= 0)
- {
- this->ViewToQDRect(box, qdBox);
- MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::InstallFloatingTEView(Boolean selectChars)
- {
- TDialogTEView * aFloatingTEView;
-
- if (fTEView == NULL)
- {
- aFloatingTEView = AquireFloatingTEView();
- if (aFloatingTEView == NULL)
- {
- #if qDebug
- ProgramBreak("###the aquired TEView is nil.");
- #endif
-
- //!!! exit(InstallFloatingTEView);
- }
- aFloatingTEView->InstallEditText(this, selectChars);
- fTEView = aFloatingTEView;
- }
-
- // since the floating TE view handles dim/hilite drawing - these adorners are removed
- if (fDimmed)
- this->DeleteAdorner(gDimAdorner, kDontRedraw);
- if (fHilite)
- this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TEditText::MakeVisible(void)
- {
- VRect myExtent;
- VPoint minToSee;
-
- this->GetExtent(myExtent);
- myExtent.Inset(VPoint(-10, -10));
- minToSee.h = Min(fSize.h + 10, kMaxCoord);
- minToSee.v = Min(fSize.v + 10, kMaxCoord);
-
- this->RevealRect(myExtent, minToSee, kVisible);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::RemoveFloatingTEView(void)
- {
- if (fTEView)
- {
- fTEView->InstallEditText(NULL, False);
- /*!!!*/
- ReleaseFloatingTEView(fTEView);
- fTEView = NULL;
- }
-
- // since the floating TE view handles dim/hilite drawing - these adorners were removed
- if (fDimmed)
- this->AddAdorner(gDimAdorner, kLowestAdornPriority - 10, kDontRedraw);
- if (fHilite)
- this->AddAdorner(gHiliteAdorner, kLowestAdornPriority - 5, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TEditText::RestartEdit(const Str255& restartText)
- {
- Rect area;
-
- if (fTEView->Focus()) // First, attempt to focus the TEView
- {
- ClipRect(gZeroRect); /* Prevent TE from mucking up the hilite with
- a stinking insertion point */
-
- //!!!RCR this->InstallSelection(TRUE, False);
- fTEView->SetActive(FALSE); // Deactivate the selection
- this->SetText(restartText, kDontRedraw);// Set the text to previous value
- this->SetSelection(0, MAXINT, kDontRedraw);// Select all characters
-
- //!!!RCR this->InstallSelection(False, TRUE); */ /* Activate the selection
- fTEView->SetActive(TRUE);
-
- this->InvalidateFocus(); // Make sure we re-focus
- fTEView->ForceRedraw();
- }
- else
- this->SetText(restartText, kDontRedraw);// Just set the text if we can't focus
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TEditText::SetJustification(short theJust,
- Boolean redraw)
- {
- if (fTEView)
- fTEView->SetJustification(theJust, redraw);
- inherited::SetJustification(theJust, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::SetSelection(short selStart,
- short selEnd,
- Boolean redraw)
- {
- if (fTEView)
- {
- if (redraw && fTEView->IsDrawable())
- TESetSelect(selStart, selEnd, fTEView->fHTE);
- else
- SetSelect(selStart, selEnd, fTEView->fHTE);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TEditText::SetText(const Str255& theText,
- Boolean redraw) // override
- {
- Str255 currentText;
- VRect area;
- Rect qdArea;
-
- if (fTEView)
- {
- this->GetText(currentText);
- if (currentText != theText)
- {
- fTEView->SetText(theText);
- fTEView->RecalcText();
- fTEView->SynchView(kDontRedraw);
- if (redraw && this->IsDrawable())
- {
- this->ControlArea(area);
- this->ViewToQDRect(area, qdArea);
- EraseRect(qdArea);
- this->DrawContents();
- }
- }
- }
- else
- inherited::SetText(theText, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::ResignedWindowTarget(void) // override
- {
- inherited::ResignedWindowTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal void TEditText::ResignedApplicationTarget(void) // override
- {
- /*
- if (fTEView)
- fTEView->ResignedApplicationTarget();
- */
- inherited::ResignedApplicationTarget();
- }
-
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TEditText::StartEdit(Boolean selectChars)
- {
- this->InstallFloatingTEView(selectChars);
- this->SetTarget(fTEView);
-
- this->MakeVisible();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TEditText::StopEdit(void)
- {
- Str255 aString;
-
- if (fTEView)
- {
- this->GetText(aString); /* Must get the text before removing
- the floating TEView */
- // fTEView->InstallSelection(TRUE, FALSE);
- this->RemoveFloatingTEView();
- this->SetText(aString, kDontRedraw);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal long TEditText::Validate(void)
- {
- long validateResult;
-
- validateResult = inherited::Validate();
- if ((validateResult == kValidValue) && (fTEView) && (GetHandleSize(fTEView->fText) > fMaxChars))
- validateResult = kTooManyCharacters;
- return validateResult;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal Boolean TEditText::WantToBecomeTarget(void)// override
- {
- return ((fTEView == NULL) && this->IsEnabled())/* && this.IsActive*/;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal long TEditText::WillingToResignTarget(void)// override
- {
- return inherited::WillingToResignTarget();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TNumberText::Initialize(void) // override
- {
- inherited::Initialize();
-
- fMaximum = MAXLONGINT;
- fMinimum = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TNumberText::INumberText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- long itsValue,
- long itsMinimum,
- long itsMaximum)
- {
- this->IEditText(itsSuperView, itsLocation, itsSize, 255);
- #if qDebugMsg
- if (itsMinimum > itsMaximum)
- fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
- #endif
-
- fMinimum = itsMinimum;
- fMaximum = itsMaximum;
-
- this->SetValue(itsValue, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- pascal void TNumberText::IRes(TDocument* ,
- TView* itsSuperView,
- Ptr& itsParams) // override
- {
- inherited::IRes(NULL, itsSuperView, itsParams);
-
- NumberTextTemplate& templateData = *((NumberTextTemplate *) itsParams);
-
- #if qDebugMsg
- if (templateData.minimum > templateData.maximum)
- fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
- #endif
-
- fMinimum = templateData.minimum;
- fMaximum = templateData.maximum;
-
- this->SetValue(templateData.value, kDontRedraw);
-
- OffsetPtr(itsParams, sizeof(NumberTextTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TNumberText::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams) // override
-
- {
- inherited::WRes(theResource, itsParams);
-
- NumberTextTemplate& templateData = *((NumberTextTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(NumberTextTemplate)));
-
- templateData.value = this->GetValue();
- templateData.minimum = fMinimum;
- templateData.maximum = fMaximum;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TNumberText::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams)// override
- {
- gWResSignature = 'nmbr';
- gWResType = "TNumberText";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal long TNumberText::GetValue(void)
- {
- Str255 aString;
- long theValue;
-
- this->GetText(aString);
- StringToNum(aString, theValue);
- return theValue;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal void TNumberText::SetValue(long newValue,
- Boolean redraw)
- {
- Str255 aString;
-
- newValue = Max(fMinimum, Min(fMaximum, newValue));
- NumToString(newValue, aString);
- this->SetText(aString, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- pascal long TNumberText::Validate(void) // override
- {
- Str255 theString;
- decimal decRec;
- extended extValue;
- short validPrefix = 0;
- long result;
-
-
- result = kValidValue;
-
- //!!! This really begs for a fRequired field to test when the string is left empty
- // Then we would inform the user that an empty string is not a valid option.
- // Also a fDefault field is necessary. GetValue would return fDefault rather
- // than 0 when the string is empty. For now (2.0) we will not validate an empty
- // string and assume that if the user wants a value they will override.
-
- this->GetText(theString);
- if (!theString.IsEmpty())
- {
- short index = 0;
- short itsLength = theString.Length();
- p2cstr(&theString); // Note: p2cstr!
- str2dec((const char *) &theString, index, decRec, validPrefix);
- if (validPrefix && (++index > itsLength) && (decRec.exp >= 0))
- {
- extValue = dec2num(decRec);
- if (extValue < fMinimum)
- result = kValueTooSmall;
- else if (extValue > fMaximum)
- result = kValueTooLarge;
- }
- else
- result = kNonNumericCharacters;
- }
- return result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
-
- pascal void TNumberText::Fields(TObject* obj) // override
- {
- obj->DoToField("TNumberText", NULL, bClass);
- obj->DoToField("fMinimum", &fMinimum, bLongInt);
- obj->DoToField("fMaximum", &fMaximum, bLongInt);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- pascal void TFloatingTEManager::Initialize(void)// override
- {
- inherited::Initialize();
- fCache = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgClose
- pascal void TFloatingTEManager::Free(void) // override
- {
- if (fCache)
- fCache = (TDialogTEView *)(FreeIfObject(fCache));
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgFields
- pascal void TFloatingTEManager::Fields(TObject* obj)// override
- {
- obj->DoToField("TFloatingTEManager", NULL, bClass);
- obj->DoToField("fCache", &fCache, bObject);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal TDialogTEView* TFloatingTEManager::AquireFloatingTE(void)
- {
- TDialogTEView * result;
-
- if (fCache) // Got one in the cache!
- {
- result = fCache;
- fCache = NULL; // Cache is now empty
- }
- else
- result = this->MakeDialogTEView();
- return result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- pascal TDialogTEView* TFloatingTEManager::MakeDialogTEView(void)
- {
- TDialogTEView * aDialogTEView = NULL;
-
- if (qTemplateViews && (gApplication))
- aDialogTEView = (TDialogTEView *)(gViewServer->DoCreateViews(NULL, NULL, kDialogTEViewID, gZeroVPt));
- else
- {
- aDialogTEView = new TDialogTEView;
- aDialogTEView->IDialogTEView(NULL, NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable, gZeroVRect, gSystemStyle, teFlushDefault, kWithoutStyle, False);
-
- }
- aDialogTEView->fMinAhead = 1; /* Don't _jump_ the view ahead when
- autoscrolling for scrollselectionintoview
- */
- return aDialogTEView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TFloatingTEManager::ReleaseFloatingTE(TDialogTEView* aDialogTEView)
- {
- if (fCache == NULL)
- fCache = aDialogTEView;
- else
- aDialogTEView->Free();
- }
-
-
-