// $Revision: 1.5 $ // Copyright (C) 1995 Taligent, Inc. All rights reserved. #ifndef Taligent_SCROLLINGVIEW #include #endif #ifndef TaligentSamples_WEBVIEW #include "WebView.h" #endif #ifndef TaligentSamples_WEBMODEL #include "WebModel.h" #endif MCollectibleDefinitionsMacro(TWebView, kOriginalVersion); TWebView::TWebView() : TDocumentComponentView(), fScrollingViewAlias(NIL), fTextViewAlias(NIL), fTitleViewAlias(NIL) { } TWebView::TWebView(TGUIBundle* bundleToAlias) : TDocumentComponentView(bundleToAlias), fScrollingViewAlias(NIL), fTextViewAlias(NIL), fTitleViewAlias(NIL) { } TWebView::TWebView(const TWebView& source) : TDocumentComponentView(source), fScrollingViewAlias(NIL), fTextViewAlias(NIL), fTitleViewAlias(NIL) { } TWebView::~TWebView() { } TStream& TWebView::operator>>=(TStream& toStream) const { ::WriteVersion(toStream); TDocumentComponentView::operator>>=(toStream); return toStream; } TStream& TWebView::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TDocumentComponentView::operator<<=(fromStream); return fromStream; } void TWebView::AdoptHypertextView(TView* adoptScrollingView, TView* textViewAlias) { if (fScrollingViewAlias != 0) { delete OrphanChild(*fScrollingViewAlias); } fTextViewAlias = textViewAlias; fScrollingViewAlias = adoptScrollingView; AdoptChild(fScrollingViewAlias); HandleAllocatedAreaChanged(GetAllocatedArea()); } void TWebView::HandleAllocatedAreaChanged(const TGArea& newArea) { // calculate the total view dimensions TGRect webViewArea = newArea.GetBounds(); GCoordinate rightSide = webViewArea.GetBottomRight().fX; PlaceLabelView(newArea); if (fTitleViewAlias != NIL) { GCoordinate titleHeight = fTitleViewAlias->GetAllocatedAreaInParent().GetBottomRight().fY; if (fScrollingViewAlias != NIL) { TGRect textViewArea(TGPoint(0,titleHeight), webViewArea.GetBottomRight()); fScrollingViewAlias->SetAllocatedAreaInParent(textViewArea); if (fTextViewAlias != NIL) { TScrollingView* scrollingView = 0; DynamicCastTo(scrollingView, fScrollingViewAlias); if (scrollingView != 0) { TGPoint clipSize = scrollingView->GetClipRectSize(); TGArea textViewArea; fTextViewAlias->GetAllocatedArea(textViewArea); TGPoint textSize = textViewArea.GetBounds().GetSize(); textSize.fX = clipSize.fX; fTextViewAlias->SetAllocatedArea(TGRect(TGPoint(0,0), textSize)); } } } } } void TWebView::HandleAfterConnectionToViewRoot() { // This call to the parent's HandleAfterConnectionToViewRoot() must // be present whenever you override this member function. TDocumentComponentView::HandleAfterConnectionToViewRoot(); if (fTitleViewAlias == NIL) { CreateTitleView(); } } void TWebView::CreateTitleView() { if (fTitleViewAlias != NIL) { delete OrphanChild(*fTitleViewAlias); fTitleViewAlias = NIL; } const TModelPointerTo model(GetModelReference()); TStandardText labelText = model->GetPageTitle(); fTitleViewAlias = new TLabelView(new TTextLabel(labelText)); AdoptChild(fTitleViewAlias); PlaceLabelView(GetAllocatedArea()); } void TWebView::PlaceLabelView(const TGArea& mainViewArea) { if (fTitleViewAlias != NIL) { TGRect titleRect = fTitleViewAlias->GetLooseFitBounds(); GCoordinate titleHeight = titleRect.GetBottomRight().fY; GCoordinate rightSide = mainViewArea.GetBounds().GetBottomRight().fX; TGRect titleViewArea(TGPoint(0,0), TGPoint(rightSide, titleHeight)); fTitleViewAlias->SetAllocatedAreaInParent(titleViewArea); } } void TWebView::HandleModelChanged(const TNotification& change) { CreateTitleView(); Invalidate(); } bool TWebView::DistributePositionalEvent(TEvent& event, const TGPoint& local) { // This code masks a small problem that causes the selection feedback to // disappear. bool result = TDocumentComponentView::DistributePositionalEvent(event, local); TMouseDownEvent* eventPointer = 0; ::DynamicCastTo(eventPointer, &event); if (eventPointer != 0) { Invalidate(); } return result; }