1 /* Copyright Krzysztof Kowalczyk 2006-2007
8 #define WIN_CLASS_NAME "PDFTEST_PDF_WIN"
9 #define COL_WINDOW_BG RGB(0xff, 0xff, 0xff)
11 static HWND gHwndSplash
;
12 static HWND gHwndFitz
;
13 static HBRUSH gBrushBg
;
15 static RenderedBitmap
*gBmpSplash
, *gBmpFitz
;
17 /* Set the client area size of the window 'hwnd' to 'dx'/'dy'. */
18 static void resizeClientArea(HWND hwnd
, int x
, int dx
, int dy
, int *dx_out
)
21 GetClientRect(hwnd
, &rc
);
22 if ((rect_dx(&rc
) == dx
) && (rect_dy(&rc
) == dy
))
26 GetWindowRect(hwnd
, &rw
);
27 int win_dx
= rect_dx(&rw
) + (dx
- rect_dx(&rc
));
28 int win_dy
= rect_dy(&rw
) + (dy
- rect_dy(&rc
));
29 SetWindowPos(hwnd
, NULL
, x
, 0, win_dx
, win_dy
, SWP_NOACTIVATE
| SWP_NOREPOSITION
| SWP_NOZORDER
);
34 static void resizeClientAreaToRenderedBitmap(HWND hwnd
, RenderedBitmap
*bmp
, int x
, int *dxOut
)
38 resizeClientArea(hwnd
, x
, dx
, dy
, dxOut
);
41 static void drawBitmap(HWND hwnd
, RenderedBitmap
*bmp
)
45 HDC hdc
= BeginPaint(hwnd
, &ps
);
46 SetBkMode(hdc
, TRANSPARENT
);
47 FillRect(hdc
, &ps
.rcPaint
, gBrushBg
);
49 HBITMAP hbmp
= bmp
->createDIBitmap(hdc
);
51 HDC bmpDC
= CreateCompatibleDC(hdc
);
53 SelectObject(bmpDC
, hbmp
);
54 int xSrc
= 0, ySrc
= 0;
55 int xDest
= 0, yDest
= 0;
56 int bmpDx
= bmp
->dx();
57 int bmpDy
= bmp
->dy();
58 BitBlt(hdc
, xDest
, yDest
, bmpDx
, bmpDy
, bmpDC
, xSrc
, ySrc
, SRCCOPY
);
68 static void onPaint(HWND hwnd
)
70 if (hwnd
== gHwndSplash
)
72 drawBitmap(hwnd
, gBmpSplash
);
73 if (hwnd
== gHwndFitz
)
75 drawBitmap(hwnd
, gBmpFitz
);
78 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
90 /* it might happen that we get WM_PAINT after destroying a window */
95 /* WM_DESTROY might be sent as a result of File\Close, in which case CloseWindow() has already been called */
99 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
104 static BOOL
registerWinClass(void)
109 wcex
.cbSize
= sizeof(WNDCLASSEX
);
111 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
112 wcex
.lpfnWndProc
= WndProc
;
115 wcex
.hInstance
= NULL
;
117 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
118 wcex
.hbrBackground
= NULL
;
119 wcex
.lpszMenuName
= NULL
;
120 wcex
.lpszClassName
= WIN_CLASS_NAME
;
123 atom
= RegisterClassEx(&wcex
);
129 static bool initWinIfNecessary(void)
134 if (!registerWinClass())
137 gBrushBg
= CreateSolidBrush(COL_WINDOW_BG
);
139 gHwndSplash
= CreateWindow(
140 WIN_CLASS_NAME
, "Splash",
150 gHwndFitz
= CreateWindow(
151 WIN_CLASS_NAME
, "Fitz",
161 ShowWindow(gHwndSplash
, SW_HIDE
);
162 ShowWindow(gHwndFitz
, SW_HIDE
);
166 static void pumpMessages(void)
172 isMessage
= PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
);
175 TranslateMessage(&msg
);
176 DispatchMessage(&msg
);
180 void PreviewBitmapInit(void)
182 /* no need to do anything */
185 static void deleteRenderedBitmaps()
191 void PreviewBitmapDestroy(void)
195 deleteRenderedBitmaps();
196 DeleteObject(gBrushBg
);
199 static void UpdateWindows(void)
204 resizeClientAreaToRenderedBitmap(gHwndFitz
, gBmpFitz
, 0, &fitzDx
);
205 ShowWindow(gHwndFitz
, SW_SHOW
);
206 InvalidateRect(gHwndFitz
, NULL
, FALSE
);
207 UpdateWindow(gHwndFitz
);
209 ShowWindow(gHwndFitz
, SW_HIDE
);
213 resizeClientAreaToRenderedBitmap(gHwndSplash
, gBmpSplash
, fitzDx
, NULL
);
214 ShowWindow(gHwndSplash
, SW_SHOW
);
215 InvalidateRect(gHwndSplash
, NULL
, FALSE
);
216 UpdateWindow(gHwndSplash
);
218 ShowWindow(gHwndSplash
, SW_HIDE
);
224 void PreviewBitmapSplashFitz(RenderedBitmap
*bmpSplash
, RenderedBitmap
*bmpFitz
)
226 if (!initWinIfNecessary())
229 deleteRenderedBitmaps();
230 gBmpSplash
= bmpSplash
;