// ----------------------------------------------------------------------------- // StartTracking // ----------------------------------------------------------------------------- //! Called before tracking. The new control value is calculated so that the //! slider thumb ends up centered on the mouse. This takes into account all //! of the inset and size values, and also considers the background image //! and thumb orientation compared to the slider orientation. // OSStatus TMeterControl::StartTracking(TCarbonEvent& inEvent, HIPoint& from) { float pos; SInt32 mini, maxi; TRect bounds = Bounds(); TRect thumbBounds = ScaledThumbBounds(); SliderOrientation boundsOrientation = OrientationForRect(bounds); mini = GetMinimum(); maxi = GetMaximum(); mTotalDetentMoved = 0; // compute a thumb bounds oriented the same as the slider TRect orientedThumbBounds = thumbBounds; if (boundsOrientation != mImageOrientation) { float temp = orientedThumbBounds.Width(); orientedThumbBounds.SetWidth(orientedThumbBounds.Height()); orientedThumbBounds.SetHeight(temp); } float distance; if (boundsOrientation == TSliderControl::kHorizontalOrientation) { distance = orientedThumbBounds.Width(); pos = (from.x - bounds.Width()/2.0 - mTopInset + orientedThumbBounds.Width()/2.0) / distance; } else { distance = orientedThumbBounds.Height(); pos = 1.f - (from.y - bounds.Height()/2.0 - mTopInset + orientedThumbBounds.Height()/2.0) / distance; } SInt32 curVal = GetValue(); SInt32 val = SInt32(rint(mini+pos*(maxi-mini+1))); if ( val > maxi) val = maxi; if ( val < mini) val = mini; if (val != curVal) { SetValue ( val ); } return noErr; }
void BrowserExtensionSymbian::createNewWindow(const ResourceRequest& request, const WindowArgs& winArgs, Frame** partResult) { ASSERT(!winArgs.dialog || request.frameName.isEmpty()); if (partResult) *partResult = NULL; const KURL& url = request.url(); const String* frameName = request.frameName.isEmpty() ? NULL : &(request.frameName); if (frameName) { // FIXME: Can't we just use m_frame->findFrame? if (CWebCoreFrameBridge* frameBridge = m_frame->bridge()->FindFrameNamed(frameName->des()) ) { if (!url.isEmpty()) { String argsReferrer = request.referrer(); String referrer; if (!argsReferrer.isEmpty()) referrer = argsReferrer; else referrer = frameBridge->Referrer(); frameBridge->Callback().LoadURL( url.des(), referrer.des(), request.reload, ETrue, request.frameName, EEventNull ); } frameBridge->Callback().ActivateWindow(); if (partResult) *partResult = frameBridge->impl(); return; } } CWebCorePageBridge *pageBridge; if (winArgs.dialog) pageBridge = m_frame->bridge()->Callback().createModalDialogWithURL( url.des() ); else pageBridge = m_frame->bridge()->Callback().createWindowWithURL( url.des(), request.frameName, ETrue ); if (!pageBridge) return; CWebCoreFrameBridge *frameBridge = pageBridge->mainFrame(); if ( frameBridge->impl() ) frameBridge->impl()->tree()->setName(AtomicString(request.frameName)); if (partResult) *partResult = frameBridge->impl(); frameBridge->Callback().setToolbarsVisible( winArgs.toolBarVisible || winArgs.locationBarVisible ); frameBridge->Callback().setStatusbarVisible( winArgs.statusBarVisible ); frameBridge->Callback().setScrollbarsVisible( winArgs.scrollbarsVisible ); frameBridge->Callback().setWindowIsResizable( winArgs.resizable ); TRect windowRect = pageBridge->impl()->windowRect().rect(); if (winArgs.xSet) windowRect.iTl.iX = winArgs.x; if (winArgs.ySet) windowRect.iTl.iY = winArgs.y; // 'width' and 'height' specify the dimensions of the WebView, but we can only resize the window, // so we compute a WebView delta and apply it to the window. TRect webViewRect = pageBridge->callback().outerView()->rect(); if (winArgs.widthSet) windowRect.SetWidth( windowRect.Width() + winArgs.width - webViewRect.Width() ); if (winArgs.heightSet) windowRect.SetHeight( windowRect.Height() + winArgs.height - webViewRect.Height() ); pageBridge->impl()->setWindowRect(windowRect); frameBridge->Callback().showWindow(); }
EXPORT_C TBool CEikScrollBarFrame::TileL(TEikScrollBarModel* aHModel, TEikScrollBarModel* aVModel, TRect& aClientRect, TRect& aInclusiveRect, const TEikScrollBarFrameLayout& aLayout) { TRect tempRect(aClientRect); if(aClientRect.Height() < 0 ) { aClientRect.iTl.iY = aClientRect.iBr.iY; aClientRect.iBr.iY = tempRect.iTl.iY; } if(aClientRect.Width() < 0 ) { aClientRect.iTl.iX = aClientRect.iBr.iX; aClientRect.iBr.iX = tempRect.iTl.iX; } tempRect = aInclusiveRect; if(aInclusiveRect.Height() < 0 ) { aInclusiveRect.iTl.iY = aInclusiveRect.iBr.iY; aInclusiveRect.iBr.iY = tempRect.iTl.iY; } if(aInclusiveRect.Width() < 0 ) { aInclusiveRect.iTl.iX = aInclusiveRect.iBr.iX; aInclusiveRect.iBr.iX = tempRect.iTl.iX; } if (iExtension && iExtension->iH.iVisibility!=EOff) { if(aClientRect.Height() < ScrollBarBreadth( CEikScrollBar::EHorizontal) ) { aClientRect.SetHeight( ScrollBarBreadth(CEikScrollBar::EHorizontal) ); } if(aInclusiveRect.Height() < ScrollBarBreadth( CEikScrollBar::EHorizontal) ) { aInclusiveRect.SetHeight( ScrollBarBreadth(CEikScrollBar::EHorizontal) ); } } TBool sizeChanged = EFalse; GetScrollBars(EFalse); CalcTheoreticalScrollBarVisibility(aVModel,aHModel); if (iV.iVisibility!=EOff) iV.iModel = *aVModel; MakeSBarVisible(iV, iScrollBarFrameFlags&EDisplayVScrollBar); if (iExtension && iExtension->iH.iBar) { if (iExtension->iH.iVisibility!=EOff) iExtension->iH.iModel = *aHModel; MakeSBarVisible(iExtension->iH, iScrollBarFrameFlags&EDisplayHScrollBar); } // Vertical Double span scollbar if (iV.iBar && TypeOfVScrollBar() == EDoubleSpan && iV.iExternalScrollBarAttached==EFalse ) { TInt scrollBarWidth = ScrollBarBreadth(CEikScrollBar::EVertical); // is 0 if SB not visible ! TInt horizontalScrollBarWidth = 0; if (iExtension && iExtension->iH.iVisibility!=EOff) { horizontalScrollBarWidth = ScrollBarBreadth(CEikScrollBar::EHorizontal); } CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iV.iBar); if (scrollbar->FixedLayoutRect().Size() == TSize(0,0)) { TMargins checkedClientMargin(aLayout.iClientMargin); TMargins checkedInclusiveMargin(aLayout.iInclusiveMargin); checkedClientMargin.iTop = Max(0,checkedClientMargin.iTop); checkedClientMargin.iBottom = Max(0,checkedClientMargin.iBottom); checkedClientMargin.iRight = Max(0,checkedClientMargin.iRight); checkedClientMargin.iLeft = Max(0,checkedClientMargin.iLeft); checkedInclusiveMargin.iTop = Max(0,checkedInclusiveMargin.iTop); checkedInclusiveMargin.iBottom = Max(0,checkedInclusiveMargin.iBottom); checkedInclusiveMargin.iRight = Max(0,checkedInclusiveMargin.iRight); checkedInclusiveMargin.iLeft = Max(0,checkedInclusiveMargin.iLeft); TInt width = 0; TInt xPos = 0; TInt yPos = 0; TInt height = 0; if (!AknLayoutUtils::LayoutMirrored()) { if (aLayout.iTilingMode == TEikScrollBarFrameLayout::EInclusiveRectConstant) { width = scrollBarWidth + checkedInclusiveMargin.iRight; xPos = aInclusiveRect.iBr.iX - width; yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop; height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth; if ((aClientRect.iBr.iX + width > aInclusiveRect.iBr.iX) || (aInclusiveRect.iBr.iX - width > aClientRect.iBr.iX)) { aClientRect.iBr.iX = aInclusiveRect.iBr.iX - width; sizeChanged = ETrue; } } else { width = scrollBarWidth + checkedClientMargin.iRight; xPos = aClientRect.iBr.iX + checkedClientMargin.iRight; yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop; height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth; if ((aClientRect.iBr.iX + width + checkedInclusiveMargin.iRight > aInclusiveRect.iBr.iX) || (aInclusiveRect.iBr.iX - (width + checkedInclusiveMargin.iRight) > aClientRect.iBr.iX)) { aInclusiveRect.iBr.iX = aClientRect.iBr.iX + width + checkedInclusiveMargin.iRight; sizeChanged = ETrue; } } } else { // Mirrored Left & Right if (aLayout.iTilingMode == TEikScrollBarFrameLayout::EInclusiveRectConstant) { width = scrollBarWidth + checkedInclusiveMargin.iRight; xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iRight; yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop; height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth; if ((aClientRect.iTl.iX - width < aInclusiveRect.iTl.iX) || (aInclusiveRect.iTl.iX + width > aClientRect.iTl.iX)) { aClientRect.iTl.iX = aInclusiveRect.iTl.iX + width; xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iRight; sizeChanged = ETrue; } } else { width = scrollBarWidth + checkedClientMargin.iRight; xPos = aClientRect.iTl.iX - checkedClientMargin.iRight; yPos = aInclusiveRect.iTl.iY + checkedInclusiveMargin.iTop; height = aInclusiveRect.Size().iHeight - (checkedInclusiveMargin.iTop + checkedInclusiveMargin.iBottom) - horizontalScrollBarWidth; if ((aClientRect.iTl.iX - width - checkedInclusiveMargin.iRight > aInclusiveRect.iTl.iX) || (aInclusiveRect.iTl.iX - (width + checkedInclusiveMargin.iRight) < aClientRect.iTl.iX)) { aInclusiveRect.iTl.iX = aClientRect.iTl.iX - width - checkedInclusiveMargin.iRight; xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iRight; sizeChanged = ETrue; } } } TRect newRect = TRect(TPoint(xPos, yPos), TSize(width, height )); if (iV.iBar->IsVisible() && (newRect != TRect(iV.iBar->Position(), iV.iBar->Size()))) { iV.iBar->SetRect(newRect); } } } // Horizontal Double span scollbar if (iExtension && iExtension->iH.iBar && TypeOfHScrollBar() == EDoubleSpan && iExtension->iH.iExternalScrollBarAttached==EFalse ) { TInt scrollBarWidth = ScrollBarBreadth(CEikScrollBar::EHorizontal); // is 0 if SB not visible ! TInt verticalScrollBarWidth = 0; if (iV.iVisibility!=EOff) { verticalScrollBarWidth = ScrollBarBreadth(CEikScrollBar::EVertical); } CAknDoubleSpanScrollBar* scrollbar = static_cast <CAknDoubleSpanScrollBar*> (iExtension->iH.iBar); if (scrollbar->FixedLayoutRect().Size() == TSize(0,0)) { TMargins checkedClientMargin(aLayout.iClientMargin); TMargins checkedInclusiveMargin(aLayout.iInclusiveMargin); checkedClientMargin.iTop = Max(0,checkedClientMargin.iTop); checkedClientMargin.iBottom = Max(0,checkedClientMargin.iBottom); checkedClientMargin.iRight = Max(0,checkedClientMargin.iRight); checkedClientMargin.iLeft = Max(0,checkedClientMargin.iLeft); checkedInclusiveMargin.iTop = Max(0,checkedInclusiveMargin.iTop); checkedInclusiveMargin.iBottom = Max(0,checkedInclusiveMargin.iBottom); checkedInclusiveMargin.iRight = Max(0,checkedInclusiveMargin.iRight); checkedInclusiveMargin.iLeft = Max(0,checkedInclusiveMargin.iLeft); TInt width = 0; TInt xPos = 0; TInt yPos = 0; TInt height = 0; if (aLayout.iTilingMode == TEikScrollBarFrameLayout::EInclusiveRectConstant) { width = scrollBarWidth + checkedInclusiveMargin.iBottom; // width as vertical direction (height). xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iLeft; if (AknLayoutUtils::LayoutMirrored()) { xPos += verticalScrollBarWidth; } yPos = aInclusiveRect.iBr.iY - checkedInclusiveMargin.iBottom - width; height = aInclusiveRect.Size().iWidth - (checkedInclusiveMargin.iLeft + checkedInclusiveMargin.iRight) - verticalScrollBarWidth; // height as horizontal (width). if ((aClientRect.iBr.iY + width > aInclusiveRect.iBr.iY) || (aInclusiveRect.iBr.iY - width > aClientRect.iBr.iY)) { aClientRect.iBr.iY = aInclusiveRect.iBr.iY - width; sizeChanged = ETrue; } } else { width = scrollBarWidth + checkedClientMargin.iBottom; // width as vertical direction (height). xPos = aInclusiveRect.iTl.iX + checkedInclusiveMargin.iLeft; if (AknLayoutUtils::LayoutMirrored()) { xPos += verticalScrollBarWidth; } yPos = aClientRect.iBr.iY + checkedClientMargin.iBottom; height = aInclusiveRect.Size().iWidth - (checkedInclusiveMargin.iLeft + checkedInclusiveMargin.iRight) - verticalScrollBarWidth; // height as horizontal (width). if ((aClientRect.iBr.iY + width + checkedClientMargin.iBottom > aInclusiveRect.iBr.iY) || (aInclusiveRect.iBr.iY - (width + checkedInclusiveMargin.iBottom) > aClientRect.iBr.iY)) { aInclusiveRect.iBr.iY = aClientRect.iBr.iY + width + checkedInclusiveMargin.iBottom; sizeChanged = ETrue; } } TRect newRect = TRect(TPoint(xPos, yPos), TSize(height, width )); // height & width swapped if (iExtension->iH.iBar->IsVisible() && (newRect != TRect(iV.iBar->Position(), iV.iBar->Size()))) { iExtension->iH.iBar->SetRect(newRect); } } } return sizeChanged; }
// ----------------------------------------------------------------------------- // StillTracking // ----------------------------------------------------------------------------- //! Called during mouse tracking. Works basically the same as the \c //! StartTracking() member function, except that thus function also //! calculates the amount of control value change based on how much the //! mouse position has changed since the last call to \c StillTracking(). //! This delta value is used for the control and option key modifiers, //! for higher precision slider control. //! OSStatus TMeterControl::StillTracking(TCarbonEvent&inEvent, HIPoint& from) { HIPoint mouse,delta; float d, pos; SInt32 mini, maxi; UInt32 modifiers; TRect bounds = Bounds(); TRect thumbBounds = ScaledThumbBounds(); SliderOrientation boundsOrientation = OrientationForRect(bounds); mini = GetMinimum(); maxi = GetMaximum(); inEvent.GetParameter<HIPoint>( kEventParamWindowMouseLocation, typeHIPoint, &mouse ); ConvertToLocal(mouse); delta.x = mouse.x - from.x; delta.y = mouse.y - from.y; inEvent.GetParameter( kEventParamKeyModifiers, &modifiers ); // compute a thumb bounds oriented the same as the slider TRect orientedThumbBounds = thumbBounds; if (boundsOrientation != mImageOrientation) { float temp = orientedThumbBounds.Width(); orientedThumbBounds.SetWidth(orientedThumbBounds.Height()); orientedThumbBounds.SetHeight(temp); } float distance; if (boundsOrientation == TSliderControl::kHorizontalOrientation) { distance = orientedThumbBounds.Width(); pos = (mouse.x - bounds.Width()/2.0 - mTopInset + orientedThumbBounds.Width()/2.0) / distance; d = delta.x / distance; } else { distance = orientedThumbBounds.Height(); pos = 1.f - (mouse.y - bounds.Height()/2.0 - mTopInset + orientedThumbBounds.Height()/2.0) / distance; d = -delta.y / distance; } SInt32 curVal = GetValue(); if (mUseDetent && (curVal == mDetentValue || abs(curVal - mDetentValue) <= mDetentRange)) { if (boundsOrientation == TSliderControl::kHorizontalOrientation) mTotalDetentMoved += delta.x; else mTotalDetentMoved += delta.y; if (fabsf(mTotalDetentMoved) < 15.0) { if (curVal != mDetentValue) SetValue(mDetentValue); from = mouse; return noErr; } } mTotalDetentMoved = 0; SInt32 val; if ((modifiers == controlKey || modifiers == optionKey)) { // value depends on how much the mouse moved SInt32 ratio = 1; if (modifiers & controlKey) ratio = 50; else if (modifiers & optionKey) ratio = 10; val = SInt32(rint(curVal + d * (1 + maxi - mini) / ratio)); } else { // value is directly proportional to position val = SInt32(rint(mini + pos * (1 + maxi - mini))); } if ( val > maxi) val = maxi; if ( val < mini) val = mini; if (val != curVal) { SetValue ( val ); from = mouse; } return noErr; }
//! The fun part of the control //! //! XXX need to test with vertically oriented images void TMeterControl::CompatibleDraw(RgnHandle inLimitRgn, CGContextRef inContext, bool inCompositing) { #pragma unused(inLimitRgn) TRect bounds = Bounds(); CGContextRef context = inContext; SliderOrientation boundsOrientation = OrientationForRect(bounds); TRect backBounds = RectForCGImage(mBackImage); float scaleY = ScaleY(); // draw slider thumb if (mThumbImage) { TRect thumbBounds = ScaledThumbBounds(); // compute a thumb bounds oriented the same as the slider TRect orientedThumbBounds = thumbBounds; if (boundsOrientation != mImageOrientation) { float temp = orientedThumbBounds.Width(); orientedThumbBounds.SetWidth(orientedThumbBounds.Height()); orientedThumbBounds.SetHeight(temp); } // the thumb image is assumed to be of the same orientation as the // background image float slideDistance; if (boundsOrientation == TSliderControl::kVerticalOrientation) slideDistance = orientedThumbBounds.Height(); else slideDistance = orientedThumbBounds.Width(); slideDistance -= (mTopInset + mBottomInset) * scaleY; float position = (float(GetValue() - GetMinimum()) / float(GetMaximum() - GetMinimum())) * slideDistance; orientedThumbBounds.SetAroundCenter(bounds.CenterX(), bounds.CenterY(), orientedThumbBounds.Width(), orientedThumbBounds.Height()); #if 0 float xOffset, yOffset; if (boundsOrientation == TSliderControl::kVerticalOrientation) { xOffset = bounds.CenterX() + mXInset - orientedThumbBounds.Width()/2.0; yOffset = bounds.MinY() + mTopInset + (bounds.Height() + slideDistance) / 2.0; } else { xOffset = bounds.MinX() + mTopInset + (bounds.Width() + slideDistance) / 2.0; yOffset = bounds.CenterY() + mXInset - - orientedThumbBounds.Height()/2.0;; } #else float xOffset, yOffset; if (boundsOrientation == TSliderControl::kVerticalOrientation) { xOffset = bounds.CenterX() + mXInset - orientedThumbBounds.Width()/2.0; yOffset = bounds.CenterY() + mTopInset - slideDistance / 2.0; } else { yOffset = bounds.CenterY() + mXInset - orientedThumbBounds.Height()/2.0;; xOffset = bounds.CenterX() + mTopInset - slideDistance / 2.0; } #endif CGContextTranslateCTM(context, xOffset, yOffset); orientedThumbBounds.SetOrigin(thumbBounds.Origin()); if (boundsOrientation == TSliderControl::kHorizontalOrientation) { orientedThumbBounds.SetWidth(position); } else { orientedThumbBounds.MoveBy(0, orientedThumbBounds.Height()-position); orientedThumbBounds.SetHeight(position); } CGContextClipToRect(context, orientedThumbBounds); if (mImageOrientation != boundsOrientation) { CGContextRotateCTM(context, DegreesToRadians(90.0)); } HIViewDrawCGImage(context, &thumbBounds, mThumbImage); } }