Beispiel #1
0
    void Label::CalculateDrawStringParams(std::wstring* paint_text,
        gfx::Rect* text_bounds,
        int* flags) const
    {
        DCHECK(paint_text && text_bounds && flags);

        if(elide_in_middle_)
        {
            *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(), true);
        }
        else
        {
            *paint_text = text_;
        }

        *text_bounds = GetTextBounds();
        *flags = ComputeMultiLineFlags();

        // If rtl_alignment_mode_ is AUTO_DETECT_ALIGNMENT (such as for text from
        // webpage, not from chrome's UI), its directionality is forced to be RTL if
        // it is right aligned. Otherwise, its directionality is forced to be LTR.
        if(rtl_alignment_mode_ == AUTO_DETECT_ALIGNMENT)
        {
            if(horiz_alignment_ == ALIGN_RIGHT)
            {
                *flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
            }
            else
            {
                *flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
            }
        }
    }
Beispiel #2
0
    gfx::Rect Label::GetTextBounds() const
    {
        gfx::Rect available_rect(GetAvailableRect());
        gfx::Size text_size(GetTextSize());
        text_size.set_width(std::min(available_rect.width(), text_size.width()));

        gfx::Insets insets = GetInsets();
        gfx::Point text_origin(insets.left(), insets.top());
        switch(horiz_alignment_)
        {
        case ALIGN_LEFT:
            break;
        case ALIGN_CENTER:
            // We put any extra margin pixel on the left rather than the right.  We
            // used to do this because measurement on Windows used
            // GetTextExtentPoint32(), which could report a value one too large on the
            // right; we now use DrawText(), and who knows if it can also do this.
            text_origin.Offset((available_rect.width()+1-text_size.width())/2, 0);
            break;
        case ALIGN_RIGHT:
            text_origin.set_x(available_rect.right()-text_size.width());
            break;
        default:
            NOTREACHED();
            break;
        }
        text_origin.Offset(0,
            std::max(0, (available_rect.height()-text_size.height()))/2);
        return gfx::Rect(text_origin, text_size);
    }
Beispiel #3
0
    gfx::Size Label::GetTextSize() const
    {
        if(!text_size_valid_)
        {
            // For single-line strings, we supply the largest possible width, because
            // while adding NO_ELLIPSIS to the flags works on Windows for forcing
            // SizeStringInt() to calculate the desired width, it doesn't seem to work
            // on Linux.
            int w = is_multi_line_ ? GetAvailableRect().width() :
                std::numeric_limits<int>::max();
            int h = font_.GetHeight();
            // For single-line strings, ignore the available width and calculate how
            // wide the text wants to be.
            int flags = ComputeMultiLineFlags();
            if(!is_multi_line_)
            {
                flags |= gfx::Canvas::NO_ELLIPSIS;
            }
            gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
            text_size_.SetSize(w, h);
            text_size_valid_ = true;
        }

        return text_size_;
    }
Beispiel #4
0
void CCJSizeDockBar::OnMouseMove(UINT nFlags, CPoint point) 
{
	if( m_bDragging )
	{
		CRect rectWin;
		GetWindowRect(&rectWin);
		CRect rectAvail;
		GetAvailableRect(rectAvail);
		CFrameWnd *pFrame=GetDockingFrame();
		ClientToScreen(&point);
		pFrame->ScreenToClient(&point);
		UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
		
		if (nID == AFX_IDW_SIZEBAR_LEFT) {
			point.x = point.x>rectAvail.right ? rectAvail.right:point.x;
			point.x = point.x<m_iTrackBorderSize ? m_iTrackBorderSize:point.x;
		}
		
		else if (nID == AFX_IDW_SIZEBAR_TOP) {
			point.y = point.y>rectAvail.bottom ? rectAvail.bottom:point.y;
			point.y = point.y<m_iTrackBorderSize ? m_iTrackBorderSize:point.y;
		}
		
		else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
			point.x = point.x<rectAvail.left ? rectAvail.left:point.x;
			point.x = point.x>rectAvail.right+m_iActualSize-m_iTrackBorderSize ? rectAvail.right-m_iTrackBorderSize+m_iActualSize:point.x;
		}
		
		else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
			point.y = point.y<rectAvail.top ? rectAvail.top:point.y;
			point.y = point.y>rectAvail.bottom+m_iActualSize-m_iTrackBorderSize ? rectAvail.bottom-m_iTrackBorderSize+m_iActualSize:point.y;		
		}
		
		int deltaX = point.x-m_ptCurDrag.x;
		int deltaY = point.y-m_ptCurDrag.y;
		
		m_ptCurDrag = point;
		
		if (nID == AFX_IDW_SIZEBAR_LEFT || nID == AFX_IDW_SIZEBAR_RIGHT && deltaX)
		{	
			OnInvertTracker(m_rcTrack);
			m_rcTrack.left+=deltaX;
			m_rcTrack.right+=deltaX;
			OnInvertTracker(m_rcTrack);
		}
		
		else if( nID == AFX_IDW_SIZEBAR_TOP || nID == AFX_IDW_SIZEBAR_BOTTOM && deltaY)
		{
			OnInvertTracker(m_rcTrack);
			m_rcTrack.top+=deltaY;
			m_rcTrack.bottom+=deltaY;
			OnInvertTracker(m_rcTrack);
		}
	}
	
	CDockBar::OnMouseMove(nFlags, point);
}
BOOL ElementExpanderImpl::AnyElementsVisible() const
{
	OpRect visible_rect;

	GetAvailableRect(visible_rect);

	for (ElementOfInterest* eoi = First(); eoi; eoi = eoi->Suc())
		if (visible_rect.Intersecting(eoi->GetDestination()))
			return TRUE;

	return FALSE;
}
Beispiel #6
0
void CCJSizeDockBar::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if( m_bDragging )
	{
		CRect rectWin;
		CRect rectAvail;
		GetWindowRect(&rectWin);
		ReleaseCapture();
		m_bDragging = FALSE;
		OnInvertTracker(m_rcTrack);
		GetAvailableRect(rectAvail);
		UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
		
		if (nID == AFX_IDW_SIZEBAR_LEFT ) {
			int maxWidth = rectAvail.Width()-m_iSafeSpace;
			int newWidth = m_rcTrack.left-m_ptStartDrag.x;
			m_iActualSize = newWidth>maxWidth ? maxWidth: newWidth;
			m_iActualSize += rectWin.Width();
		}
		
		else if (nID == AFX_IDW_SIZEBAR_TOP) {
			int maxHeight = rectAvail.Height()-m_iSafeSpace;
			int newHeight = m_rcTrack.top-m_ptStartDrag.y;
			m_iActualSize = newHeight>maxHeight ? maxHeight : newHeight;
			m_iActualSize += rectWin.Height();
		}
		
		else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
			int maxWidth = rectAvail.Width()-m_iSafeSpace;
			int newWidth = m_ptStartDrag.x-m_rcTrack.left;
			m_iActualSize = newWidth>maxWidth ? maxWidth: newWidth;
			m_iActualSize += rectWin.Width();
		}
		
		else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
			int maxHeight = rectAvail.Height()-m_iSafeSpace;
			int newHeight = m_ptStartDrag.y-m_rcTrack.top;
			m_iActualSize = newHeight>maxHeight ? maxHeight : newHeight;
			m_iActualSize += rectWin.Height();
		}
		
		if(m_iActualSize<m_iTrackBorderSize )
			m_iActualSize = m_iTrackBorderSize;
		
		GetDockingFrame()->RecalcLayout();
		RecalcAllExcept(NULL);
	}
	
	CDockBar::OnLButtonUp(nFlags, point);
}
BOOL CXTPDockingPaneSplitterWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
	if (m_pContainer == 0)
		return CWnd::OnSetCursor(pWnd, nHitTest, message);

	if (GetDockingPaneManager()->IsSplittersLocked())
		return CWnd::OnSetCursor(pWnd, nHitTest, message);

	CRect rcAvail, rcUnion;
	if (!GetAvailableRect(rcAvail, rcUnion))
		return CWnd::OnSetCursor(pWnd, nHitTest, message);

	::SetCursor(m_hCursor);
	return TRUE;
}
Beispiel #8
0
    bool Label::GetTooltipText(const gfx::Point& p, string16* tooltip)
    {
        DCHECK(tooltip);

        // If a tooltip has been explicitly set, use it.
        if(!tooltip_text_.empty())
        {
            tooltip->assign(tooltip_text_);
            return true;
        }

        // Show the full text if the text does not fit.
        if(!is_multi_line_ &&
            (font_.GetStringWidth(text_)>GetAvailableRect().width()))
        {
            *tooltip = text_;
            return true;
        }
        return false;
    }
OP_BOOLEAN ElementExpanderImpl::Show()
{
	if (Empty())
		return OpBoolean::IS_FALSE;

	OpWindow* parent_window = document->GetWindow()->GetWindowCommander()->GetOpWindow();
	UINT32 window_width, window_height;

	parent_window->GetInnerSize(&window_width, &window_height);

	overlay_rect.Empty();

	OP_ASSERT(!overlay_window);
	OP_ASSERT(!overlay_container);

	RETURN_IF_ERROR(OpWindow::Create(&overlay_window));
	RETURN_IF_ERROR(overlay_window->Init(OpWindow::STYLE_OVERLAY, OpTypedObject::WINDOW_TYPE_UNKNOWN, parent_window));

	overlay_container = OP_NEW(ElementExpanderContainer, (this));
	if (!overlay_container)
		return OpStatus::ERR_NO_MEMORY;

	RETURN_IF_ERROR(overlay_container->Init(OpRect(0, 0, 0, 0), overlay_window));

#ifdef WIDGETS_F_T_GREY_BACKGROUND
	overlay_container->SetEraseBg(TRUE);
	overlay_container->GetRoot()->SetBackgroundColor(OP_RGBA(0, 0, 0, 128));
#else
	overlay_container->GetRoot()->SetBackgroundColor(OP_RGBA(0, 0, 0, 0));
	overlay_container->SetEraseBg(FALSE);
#endif // WIDGETS_F_T_GREY_BACKGROUND

	overlay_container->GetRoot()->SetListener(this);
	RETURN_IF_ERROR(g_main_message_handler->SetCallBack(this, MSG_FINGERTOUCH_ANIMATE, (MH_PARAM_1)this));

	OpRect visible_rect;
	GetAvailableRect(visible_rect);
	RETURN_IF_ERROR(LayoutElements(visible_rect, LAYER_SPACING, LAYER_PADDING, scale_factor));

	// No elements found suitable for expansion after laying out.
	if (Empty())
		return OpBoolean::IS_FALSE;

	//when using viewport, let's create overlay window as big as the whole
	//page so user can scroll it
	if (document)
	{
		//visual device can be NULL only for top-level document manager,
		//so it should be safe to assume it's not NULL in this case
		VisualDevice* vd = document->GetVisualDevice();
		OpRect rect = vd->GetRenderingViewport();
		window_width = rect.width;
		window_height = rect.height;
	}

	overlay_rect.Set(0, 0, window_width, window_height);
	overlay_container->SetPos(AffinePos(overlay_rect.x, overlay_rect.y));
	// FIXME, invalidates the whole gogi buffer
	overlay_container->SetSize(overlay_rect.width, overlay_rect.height);
	overlay_window->SetInnerPos(overlay_rect.x, overlay_rect.y);
	// FIXME, invalidates the whole gogi buffer
	overlay_window->SetInnerSize(overlay_rect.width, overlay_rect.height);
	overlay_window->Show(TRUE);

	// Start the link expansion timer
	ExtendTimeOut();

	for (ElementOfInterest* eoi = First(); eoi; eoi = eoi->Suc())
	{
		if (eoi->GetHtmlElement())
			eoi->GetHtmlElement()->SetReferenced(TRUE);
		RETURN_IF_ERROR(eoi->PrepareForDisplay());
	}

	ExpandElements();

	return OpBoolean::IS_TRUE;
}
void CXTPDockingPaneSplitterWnd::OnLButtonDown(UINT /*nFlags*/, CPoint point)
{
	if (m_pContainer == 0)
		return;

	CXTPDockingPaneManager* pManager = GetDockingPaneManager();

	if (pManager->IsSplittersLocked())
		return;

	CXTPWindowRect rc(this);

	CRect rcAvail, rcUnion;
	if (!GetAvailableRect(rcAvail, rcUnion))
		return;

	if (m_pContainer->OnAction(xtpPaneActionSplitterResizing))
		return;

	m_pContainer->NormalizeDockingSize();

	BOOL bHoriz = m_pContainer->m_bHoriz;


	//point = rc.TopLeft();
	ClientToScreen(&point);

	if (pManager->IsSplitterTrackerUsed())
	{

		CXTPSplitterTracker tracker;
		BOOL bAccept = tracker.Track(this, rcAvail, rc, point, bHoriz);

		if (bAccept)
		{
			Reposition(rc, rcUnion);


			pManager->RecalcFrameLayout(m_pContainer, TRUE);
		}
	}
	else
	{
		CPoint ptOffset = bHoriz ? CPoint(rc.left - point.x, 0) :
			CPoint(0, rc.top - point.y);

		SetCapture();

		while (::GetCapture() == m_hWnd)
		{
			MSG msg;

			while (::PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE | PM_NOYIELD))
			{
				DispatchMessage(&msg);
			}

			if (!GetMessage(&msg, NULL, 0, 0))
				break;

			if (msg.message == WM_MOUSEMOVE)
			{

				point = CPoint(msg.lParam);
				ClientToScreen(&point);
				point += ptOffset;

				point.x = max(min(point.x, rcAvail.right), rcAvail.left);
				point.y = max(min(point.y, rcAvail.bottom), rcAvail.top);

				if (bHoriz)
				{
					if (rc.left == point.x)
						continue;
					rc.OffsetRect(point.x - rc.left, 0);
				}
				else
				{
					if (rc.top == point.y)
						continue;
					rc.OffsetRect(0, point.y - rc.top);
				}

				Reposition(rc, rcUnion);

				pManager->RecalcFrameLayout(m_pContainer);
			}
			else if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) break;
			else if (msg.message == WM_LBUTTONUP) break;
			else ::DispatchMessage(&msg);
		}

		if (CWnd::GetCapture() == this) ReleaseCapture();
	}

	m_pContainer->OnAction(xtpPaneActionSplitterResized);
}