Commit 0cd3ee3d authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

wordpad: Remove sized print preview page buffer.

This extra buffer only saves the result of the StretchBlt operatation, which isn't worth doing since a BitBlt will still be needed from the buffer to the screen. This causes noticable delay on resizing since a new sized bitmap needs to be created, the old bitmap needs to be destroyed, and then both a StretchBlt and a Bitblt is needed to actually repaint the window.
parent 6c9edce1
...@@ -33,8 +33,6 @@ typedef struct _previewinfo ...@@ -33,8 +33,6 @@ typedef struct _previewinfo
int textlength; int textlength;
HDC hdc; HDC hdc;
HDC hdc2; HDC hdc2;
HDC hdcSized;
HDC hdcSized2;
RECT window; RECT window;
RECT rcPage; RECT rcPage;
SIZE bmSize; SIZE bmSize;
...@@ -705,43 +703,44 @@ static void update_preview_sizes(HWND hwndPreview, BOOL zoomLevelUpdated) ...@@ -705,43 +703,44 @@ static void update_preview_sizes(HWND hwndPreview, BOOL zoomLevelUpdated)
update_preview_scrollbars(hwndPreview, &window); update_preview_scrollbars(hwndPreview, &window);
} }
static void draw_preview_page(HDC hdc, HDC* hdcSized, FORMATRANGE* lpFr, float ratio, int bmNewWidth, int bmNewHeight, int bmWidth, int bmHeight, BOOL draw_margins) static void draw_margin_lines(HDC hdc, int x, int y, float ratio)
{ {
HBITMAP hBitmapScaled = CreateCompatibleBitmap(hdc, bmNewWidth, bmNewHeight);
HBITMAP oldbm;
HPEN hPen, oldPen; HPEN hPen, oldPen;
int TopMargin = (int)((float)twips_to_pixels(lpFr->rc.top, GetDeviceCaps(hdc, LOGPIXELSX)) * ratio); SIZE dpi;
int BottomMargin = (int)((float)twips_to_pixels(lpFr->rc.bottom, GetDeviceCaps(hdc, LOGPIXELSX)) * ratio); RECT page_margin = preview.rcPage;
int LeftMargin = (int)((float)twips_to_pixels(lpFr->rc.left, GetDeviceCaps(hdc, LOGPIXELSY)) * ratio);
int RightMargin = (int)((float)twips_to_pixels(lpFr->rc.right, GetDeviceCaps(hdc, LOGPIXELSY)) * ratio);
if(*hdcSized) { dpi.cx = GetDeviceCaps(hdc, LOGPIXELSX);
oldbm = SelectObject(*hdcSized, hBitmapScaled); dpi.cy = GetDeviceCaps(hdc, LOGPIXELSY);
DeleteObject(oldbm);
} else { page_margin.left = preview.rcPage.left + margins.left;
*hdcSized = CreateCompatibleDC(hdc); page_margin.top = preview.rcPage.top + margins.top;
SelectObject(*hdcSized, hBitmapScaled); page_margin.bottom = preview.rcPage.bottom - margins.bottom;
} page_margin.right = preview.rcPage.right - margins.right;
StretchBlt(*hdcSized, 0, 0, bmNewWidth, bmNewHeight, hdc, 0, 0, bmWidth, bmHeight, SRCCOPY); page_margin.left = (int)((float)twips_to_pixels(page_margin.left, dpi.cx) * ratio);
page_margin.top = (int)((float)twips_to_pixels(page_margin.top, dpi.cy) * ratio);
page_margin.bottom = (int)((float)twips_to_pixels(page_margin.bottom, dpi.cy) * ratio);
page_margin.right = (int)((float)twips_to_pixels(page_margin.right, dpi.cx) * ratio);
if (!draw_margins) return; page_margin.left += x;
page_margin.top += y;
page_margin.bottom += y;
page_margin.right += x;
/* Draw margin lines */
hPen = CreatePen(PS_DOT, 1, RGB(0,0,0)); hPen = CreatePen(PS_DOT, 1, RGB(0,0,0));
oldPen = SelectObject(*hdcSized, hPen); oldPen = SelectObject(hdc, hPen);
MoveToEx(*hdcSized, 0, TopMargin, NULL); MoveToEx(hdc, x, page_margin.top, NULL);
LineTo(*hdcSized, bmNewWidth, TopMargin); LineTo(hdc, x + preview.bmScaledSize.cx, page_margin.top);
MoveToEx(*hdcSized, 0, BottomMargin, NULL); MoveToEx(hdc, x, page_margin.bottom, NULL);
LineTo(*hdcSized, bmNewWidth, BottomMargin); LineTo(hdc, x + preview.bmScaledSize.cx, page_margin.bottom);
MoveToEx(*hdcSized, LeftMargin, 0, NULL); MoveToEx(hdc, page_margin.left, y, NULL);
LineTo(*hdcSized, LeftMargin, bmNewHeight); LineTo(hdc, page_margin.left, y + preview.bmScaledSize.cy);
MoveToEx(*hdcSized, RightMargin, 0, NULL); MoveToEx(hdc, page_margin.right, y, NULL);
LineTo(*hdcSized, RightMargin, bmNewHeight); LineTo(hdc, page_margin.right, y + preview.bmScaledSize.cy);
SelectObject(*hdcSized, oldPen); SelectObject(hdc, oldPen);
DeleteObject(hPen); DeleteObject(hPen);
} }
...@@ -750,41 +749,6 @@ static BOOL is_last_preview_page(int page) ...@@ -750,41 +749,6 @@ static BOOL is_last_preview_page(int page)
return preview.pageEnds[page - 1] >= preview.textlength; return preview.pageEnds[page - 1] >= preview.textlength;
} }
/* Update for zoom ratio changes with same page. */
static void update_scaled_preview(HWND hMainWnd)
{
FORMATRANGE fr;
HWND hwndPreview;
/* This may occur on WM_CREATE before update_preview is called
* because a WM_SIZE message is generated from updating the
* scrollbars. */
if (!preview.hdc) return;
hwndPreview = GetDlgItem(hMainWnd, IDC_PREVIEW);
fr.hdcTarget = make_dc();
fr.rc = fr.rcPage = preview.rcPage;
fr.rc.left += margins.left;
fr.rc.top += margins.top;
fr.rc.bottom -= margins.bottom;
fr.rc.right -= margins.right;
draw_preview_page(preview.hdc, &preview.hdcSized, &fr, preview.zoomratio,
preview.bmScaledSize.cx, preview.bmScaledSize.cy,
preview.bmSize.cx, preview.bmSize.cy, TRUE);
if(preview.pages_shown > 1)
{
draw_preview_page(preview.hdc2, &preview.hdcSized2, &fr, preview.zoomratio,
preview.bmScaledSize.cx, preview.bmScaledSize.cy,
preview.bmSize.cx, preview.bmSize.cy,
!is_last_preview_page(preview.page));
}
InvalidateRect(hwndPreview, NULL, FALSE);
DeleteDC(fr.hdcTarget);
}
void init_preview(HWND hMainWnd, LPWSTR wszFileName) void init_preview(HWND hMainWnd, LPWSTR wszFileName)
{ {
HINSTANCE hInstance = GetModuleHandleW(0); HINSTANCE hInstance = GetModuleHandleW(0);
...@@ -824,18 +788,6 @@ void close_preview(HWND hMainWnd) ...@@ -824,18 +788,6 @@ void close_preview(HWND hMainWnd)
DeleteObject(oldbm); DeleteObject(oldbm);
preview.hdc2 = NULL; preview.hdc2 = NULL;
} }
if(preview.hdcSized) {
HBITMAP oldbm = GetCurrentObject(preview.hdcSized, OBJ_BITMAP);
DeleteDC(preview.hdcSized);
DeleteObject(oldbm);
preview.hdcSized = NULL;
}
if(preview.hdcSized2) {
HBITMAP oldbm = GetCurrentObject(preview.hdcSized2, OBJ_BITMAP);
DeleteDC(preview.hdcSized2);
DeleteObject(oldbm);
preview.hdcSized2 = NULL;
}
preview_bar_show(hMainWnd, FALSE); preview_bar_show(hMainWnd, FALSE);
DestroyWindow(hwndPreview); DestroyWindow(hwndPreview);
...@@ -896,19 +848,19 @@ static LRESULT print_preview(HWND hwndPreview) ...@@ -896,19 +848,19 @@ static LRESULT print_preview(HWND hwndPreview)
HDC hdc; HDC hdc;
RECT window, background; RECT window, background;
PAINTSTRUCT ps; PAINTSTRUCT ps;
POINT scrollpos; int x, y;
hdc = BeginPaint(hwndPreview, &ps); hdc = BeginPaint(hwndPreview, &ps);
GetClientRect(hwndPreview, &window); GetClientRect(hwndPreview, &window);
FillRect(hdc, &window, GetStockObject(GRAY_BRUSH)); FillRect(hdc, &window, GetStockObject(GRAY_BRUSH));
scrollpos.x = GetScrollPos(hwndPreview, SB_HORZ); x = preview.spacing.cx - GetScrollPos(hwndPreview, SB_HORZ);
scrollpos.y = GetScrollPos(hwndPreview, SB_VERT); y = preview.spacing.cy - GetScrollPos(hwndPreview, SB_VERT);
background.left = preview.spacing.cx - 2 - scrollpos.x; background.left = x - 2;
background.right = background.left + preview.bmScaledSize.cx + 4; background.right = background.left + preview.bmScaledSize.cx + 4;
background.top = preview.spacing.cy - 2 - scrollpos.y; background.top = y - 2;
background.bottom = background.top + preview.bmScaledSize.cy + 4; background.bottom = background.top + preview.bmScaledSize.cy + 4;
FillRect(hdc, &background, GetStockObject(BLACK_BRUSH)); FillRect(hdc, &background, GetStockObject(BLACK_BRUSH));
...@@ -921,15 +873,19 @@ static LRESULT print_preview(HWND hwndPreview) ...@@ -921,15 +873,19 @@ static LRESULT print_preview(HWND hwndPreview)
FillRect(hdc, &background, GetStockObject(BLACK_BRUSH)); FillRect(hdc, &background, GetStockObject(BLACK_BRUSH));
} }
BitBlt(hdc, preview.spacing.cx - scrollpos.x, preview.spacing.cy - scrollpos.y, StretchBlt(hdc, x, y, preview.bmScaledSize.cx, preview.bmScaledSize.cy,
preview.bmScaledSize.cx, preview.bmScaledSize.cy, preview.hdc, 0, 0, preview.bmSize.cx, preview.bmSize.cy, SRCCOPY);
preview.hdcSized, 0, 0, SRCCOPY);
draw_margin_lines(hdc, x, y, preview.zoomratio);
if(preview.pages_shown > 1) if(preview.pages_shown > 1)
{ {
BitBlt(hdc, preview.spacing.cx * 2 + preview.bmScaledSize.cx - scrollpos.x, x += preview.spacing.cx + preview.bmScaledSize.cx;
preview.spacing.cy - scrollpos.y, preview.bmScaledSize.cx, StretchBlt(hdc, x, y, preview.bmScaledSize.cx, preview.bmScaledSize.cy,
preview.bmScaledSize.cy, preview.hdcSized2, 0, 0, SRCCOPY); preview.hdc2, 0, 0, preview.bmSize.cx, preview.bmSize.cy, SRCCOPY);
if (!is_last_preview_page(preview.page))
draw_margin_lines(hdc, x, y, preview.zoomratio);
} }
preview.window = window; preview.window = window;
...@@ -1011,7 +967,7 @@ static void update_preview(HWND hMainWnd) ...@@ -1011,7 +967,7 @@ static void update_preview(HWND hMainWnd)
DeleteDC(fr.hdcTarget); DeleteDC(fr.hdcTarget);
ReleaseDC(hwndPreview, hdc); ReleaseDC(hwndPreview, hdc);
update_scaled_preview(hMainWnd); InvalidateRect(hwndPreview, NULL, FALSE);
update_preview_buttons(hMainWnd); update_preview_buttons(hMainWnd);
update_preview_statusbar(hMainWnd); update_preview_statusbar(hMainWnd);
} }
...@@ -1103,7 +1059,7 @@ LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -1103,7 +1059,7 @@ LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SIZE: case WM_SIZE:
{ {
update_preview_sizes(hWnd, FALSE); update_preview_sizes(hWnd, FALSE);
update_scaled_preview(hWnd); InvalidateRect(hWnd, NULL, FALSE);
break; break;
} }
...@@ -1216,7 +1172,7 @@ LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -1216,7 +1172,7 @@ LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
toggle_num_pages(hMainWnd); toggle_num_pages(hMainWnd);
} else { } else {
update_preview_sizes(hWnd, TRUE); update_preview_sizes(hWnd, TRUE);
update_scaled_preview(hMainWnd); InvalidateRect(hWnd, NULL, FALSE);
update_preview_buttons(hMainWnd); update_preview_buttons(hMainWnd);
} }
...@@ -1285,7 +1241,7 @@ LRESULT preview_command(HWND hWnd, WPARAM wParam) ...@@ -1285,7 +1241,7 @@ LRESULT preview_command(HWND hWnd, WPARAM wParam)
} else { } else {
HWND hwndPreview = GetDlgItem(hWnd, IDC_PREVIEW); HWND hwndPreview = GetDlgItem(hWnd, IDC_PREVIEW);
update_preview_sizes(hwndPreview, TRUE); update_preview_sizes(hwndPreview, TRUE);
update_scaled_preview(hWnd); InvalidateRect(hwndPreview, NULL, FALSE);
update_preview_buttons(hWnd); update_preview_buttons(hWnd);
} }
} }
...@@ -1301,7 +1257,7 @@ LRESULT preview_command(HWND hWnd, WPARAM wParam) ...@@ -1301,7 +1257,7 @@ LRESULT preview_command(HWND hWnd, WPARAM wParam)
toggle_num_pages(hWnd); toggle_num_pages(hWnd);
} else { } else {
update_preview_sizes(hwndPreview, TRUE); update_preview_sizes(hwndPreview, TRUE);
update_scaled_preview(hWnd); InvalidateRect(hwndPreview, NULL, FALSE);
update_preview_buttons(hWnd); update_preview_buttons(hWnd);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment