Example #1
0
void CTableFormatControl::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	if (m_pTable != NULL)
	{
		CRect crInterior;
		GetClientRect(crInterior);
		Util::Draw3dBorder(
								 &dc,
								 crInterior,
								 GetSysColor(COLOR_BTNHILIGHT),
								 GetSysColor(COLOR_BTNSHADOW),
								 GetSysColor(COLOR_BTNFACE),
								 GetSysColor(COLOR_BTNTEXT),
								 RGB(255, 255, 255),
								 1,
								 TRUE,
								 TRUE,
								 FALSE);

		// Set the DC.
		m_rc.destination_hdc = dc.GetSafeHdc();
		m_rc.set_info(m_rc.destination_hdc);

		// Establish the palettes if necessary.
		HPALETTE hOurPal = (HPALETTE)pOurPal->GetSafeHandle();
		HPALETTE hOldPal = NULL;
		if (m_rc.info.type == RASTER_TYPE_PALETTE)
		{
			hOldPal = ::SelectPalette(m_rc.destination_hdc, hOurPal, FALSE);
			::RealizePalette(m_rc.destination_hdc);
		}

		REFRESH_EXTENT re;

		// Build the refresh extent.
		re.extent = m_rc.source_pbox;
		re.refresh_type = REFRESH_ALL;
		re.my_object = NULL;
		re.update_object = NULL;
		re.update_state = NULL;

		BOOL fDrawn = !m_pDoc->draw_objects(&re, &m_rc);
		ASSERT(fDrawn);

		if (hOldPal != NULL)
		{
			::SelectPalette(m_rc.destination_hdc, hOldPal, FALSE);
		}
	}
}
Example #2
0
void CDocumentPreview::DrawPreview(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// Find enclosing bounds for isolating objects
	PBOX Bounds;
	if (GetPreviewWnd() == NULL || !GetBounds(&Bounds))
	{
		// can not continue.
		return;
	}

	HDC hdc = lpDrawItemStruct->hDC;

	// If we are totally clipped, skip it.
	RECT r;
	if (GetClipBox(hdc, &r) == NULLREGION)
	{
		return;
	}

	// Draw a nice frame around our image
	if (!m_fEncloseObjects)
	{
		DrawFrame(hdc);
	}

	PPNT Dims;
	Dims.x = Bounds.x1 - Bounds.x0;
	Dims.y = Bounds.y1 - Bounds.y0;

	RedisplayContext rc;

	rc.destination_hdc = hdc;

	rc.hwnd = lpDrawItemStruct->hwndItem;
	rc.set_info(rc.destination_hdc);

	// Establish the palettes if necessary.
	HPALETTE hOurPal = (HPALETTE)pOurPal->GetSafeHandle();
	HPALETTE hOldPal = NULL;
	if (rc.info.type == RASTER_TYPE_PALETTE)
	{
		hOldPal = SelectPalette(rc.destination_hdc, hOurPal, FALSE);
		RealizePalette(rc.destination_hdc);
	}

	CRect crBounds = m_crPreview;
	CRgn region;
	region.CreateRectRgn(crBounds.left, crBounds.top, crBounds.right, crBounds.bottom);
	HRGN hrgn = region;
	::SelectClipRgn(hdc, hrgn);
	rc.clip_region = hrgn;

	rc.x_resolution = m_nXResolution;
	rc.y_resolution = m_nYResolution;

	rc.scaled_source_x0 =  Bounds.x0*rc.x_resolution;
	rc.scaled_source_y0 =  Bounds.y0*rc.y_resolution;

	rc.destination_x0 = crBounds.left;
	rc.destination_y0 = crBounds.top;

	rc.destination_rect = crBounds;

	rc.clip_rect = rc.destination_rect;

	rc.outline_gamma_curve =
		rc.bitmap_gamma_curve = screen_gamma_curve;

	rc.source_pbox = Bounds;

	PCOORD Scale;
	int n;
	if (Dims.x > Dims.y)
	{
		Scale = scale_pcoord(Dims.x, rc.x_resolution, PAGE_RESOLUTION);
		n = crBounds.Width();
	}
	else
	{
		Scale = scale_pcoord(Dims.y, rc.y_resolution, PAGE_RESOLUTION);
		n = crBounds.Height();
	}

	while (Scale > 32000)
	{
		n >>= 1;
		Scale >>= 1;
	}
	if (n == 0)
	{
		n++;
	}

	rc.SetScaling(n, (USHORT)Scale);

	// Install the abort interrupt check
	rc.set_check_interrupt(standard_check_interrupt, (VOIDPTR)&rc);

	REFRESH_EXTENT re;

	// Build the refresh extent.
	re.extent = rc.source_pbox;
	re.refresh_type = REFRESH_ALL;
	re.my_object = NULL;
	re.update_object = NULL;
	re.update_state = NULL;

	BOOL fDrawn = (m_fForceToFront) ? 
		!m_pDoc->DrawPreview(&re, &rc) : !m_pDoc->CPmwDoc::DrawPreview(&re, &rc);
	if (!fDrawn)
	{
		UpdateState* ustate = re.update_state;
		if (ustate != NULL)
		{
			switch (ustate->type)
			{
				case UPDATE_TYPE_Interrupted:
				{
					// This should not happen...
					delete ustate;
					// Fall through to...
				}
				case UPDATE_TYPE_Terminated:
				{
					// Try again later
					break;
				}
				default:
				{
					// Ignore other types (e.g. "error")
					fDrawn = TRUE;
					break;
				}
			}
		}
		if (!fDrawn)
		{
			::InvalidateRect(lpDrawItemStruct->hwndItem, &m_crPreview, FALSE);
		}
	}

	if (hOldPal != NULL)
	{
		SelectPalette(rc.destination_hdc, hOldPal, FALSE);
	}
}