ReactOS  0.4.13-dev-551-gf37fb1f
imgedwnd.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 static const TCHAR szImageEditWndClass[] = TEXT("ImageSoftEditWndClass");
4 
5 #define IMAGE_FRAME_SIZE 1
6 
7 static VOID
9 {
10  SCROLLINFO si;
11  RECT rcClient;
12 
13  GetClientRect(Info->hSelf,
14  &rcClient);
15 
16  si.cbSize = sizeof(si);
17  si.fMask = SIF_PAGE | SIF_RANGE;
18  si.nPage = rcClient.right - (2 * IMAGE_FRAME_SIZE);
19  si.nMin = 0;
20  si.nMax = Info->Width;
21 
22  SetScrollInfo(Info->hSelf,
23  SB_HORZ,
24  &si,
25  TRUE);
26 
27  si.nPage = rcClient.bottom - (2 * IMAGE_FRAME_SIZE);
28  si.nMax = Info->Height;
29  SetScrollInfo(Info->hSelf,
30  SB_VERT,
31  &si,
32  TRUE);
33 }
34 
35 
36 static BOOL
38 {
39  /* FIXME: convert this to a DIB Section */
40  /* set bitmap dimensions */
41  Info->Width = Info->OpenInfo->New.Width;
42  Info->Height = Info->OpenInfo->New.Height;
43 
44  return TRUE;
45 }
46 
47 static BOOL
49 {
50  BITMAPFILEHEADER bmfh;
51  HANDLE hFile;
52  BITMAP bitmap;
54  BOOL bSuccess, bRet = FALSE;
55 
56  hFile = CreateFile(Info->OpenInfo->Open.lpImagePath,
59  NULL,
62  NULL);
64  return bRet;
65 
67  &bmfh,
68  sizeof(BITMAPFILEHEADER),
69  &BytesRead,
70  NULL);
71 
72  if (bSuccess && (BytesRead == sizeof(BITMAPFILEHEADER))
73  && (bmfh.bfType == *(WORD *)"BM"))
74  {
75  DWORD InfoSize = bmfh.bfOffBits - sizeof(BITMAPFILEHEADER);
76 
77  Info->pbmi = HeapAlloc(ProcessHeap,
78  0,
79  InfoSize);
80  if (Info->pbmi)
81  {
83  Info->pbmi,
84  InfoSize,
85  &BytesRead,
86  NULL);
87 
88  if (bSuccess && (BytesRead == InfoSize))
89  {
90  Info->hBitmap = CreateDIBSection(NULL,
91  Info->pbmi,
93  (VOID *)&Info->pBits,
94  NULL,
95  0);
96  if (Info->hBitmap != NULL)
97  {
99  Info->pBits,
100  bmfh.bfSize - bmfh.bfOffBits,
101  &BytesRead,
102  NULL);
103 
104  GetObject(Info->hBitmap,
105  sizeof(BITMAP),
106  &bitmap);
107 
108  Info->Width = bitmap.bmWidth;
109  Info->Height = bitmap.bmHeight;
110 
111  bRet = TRUE;
112  }
113  }
114  }
115  }
116  else if (!bSuccess)
117  {
118  GetError(0);
119  }
120 
122 
123  return bRet;
124 }
125 
126 
127 static BOOL
129 {
130  //BOOL bRet = FALSE;
131 
132  Info->Zoom = 100;
133 
134  if (Info->OpenInfo != NULL)
135  {
136  HDC hDC;
137 
138  if (Info->hDCMem)
139  {
140  DeleteObject(Info->hDCMem);
141  Info->hDCMem = NULL;
142  }
143 
144  hDC = GetDC(Info->hSelf);
145  Info->hDCMem = CreateCompatibleDC(hDC);
146  ReleaseDC(Info->hSelf, hDC);
147 
148  if (Info->OpenInfo->CreateNew)
149  {
151  }
152  else
153  {
155  }
156 
157  Info->OpenInfo = NULL;
158  }
159 
161 
162  /* Add image editor to the list */
163  Info->Next = Info->MainWnd->ImageEditors;
164  Info->MainWnd->ImageEditors = Info;
165 
166  InvalidateRect(Info->hSelf,
167  NULL,
168  TRUE);
169 
170  /* FIXME - if returning FALSE, remove the image editor from the list! */
171  return TRUE;
172 }
173 
174 static VOID
176 {
177  PEDIT_WND_INFO *PrevEditor;
178  PEDIT_WND_INFO Editor;
179 
180  DeleteDC(Info->hDCMem);
181 
182  /* FIXME - free resources and run down editor */
184  0,
185  Info->pbmi);
187  0,
188  Info->pBits);
189 
190  /* Remove the image editor from the list */
191  PrevEditor = &Info->MainWnd->ImageEditors;
192  Editor = Info->MainWnd->ImageEditors;
193  do
194  {
195  if (Editor == Info)
196  {
197  *PrevEditor = Info->Next;
198  break;
199  }
200  PrevEditor = &Editor->Next;
201  Editor = Editor->Next;
202  } while (Editor != NULL);
203 }
204 
205 static VOID
207  HDC hDC,
208  LPPAINTSTRUCT lpps)
209 {
210  HBITMAP hOldBitmap;
211 
212  if (Info->hBitmap)
213  {
214  hOldBitmap = (HBITMAP) SelectObject(Info->hDCMem,
215  Info->hBitmap);
216 
217  BitBlt(hDC,
218  lpps->rcPaint.left,
219  lpps->rcPaint.top,
220  lpps->rcPaint.right - lpps->rcPaint.left,
221  lpps->rcPaint.bottom - lpps->rcPaint.top,
222  Info->hDCMem,
223  lpps->rcPaint.left,
224  lpps->rcPaint.top,
225  SRCCOPY);
226 
227  Info->hBitmap = SelectObject(Info->hDCMem, hOldBitmap);
228  }
229 }
230 
231 static LRESULT CALLBACK
233  UINT uMsg,
234  WPARAM wParam,
235  LPARAM lParam)
236 {
238  LRESULT Ret = 0;
239  HDC hDC;
240  static INT xMouse, yMouse;
241  static BOOL bLeftButtonDown, bRightButtonDown;
242 
243  /* Get the window context */
245  GWLP_USERDATA);
246  if (Info == NULL && uMsg != WM_CREATE)
247  {
248  goto HandleDefaultMessage;
249  }
250 
251  switch (uMsg)
252  {
253  case WM_CREATE:
254  {
255  Info = (PEDIT_WND_INFO)(((LPMDICREATESTRUCT)((LPCREATESTRUCT)lParam)->lpCreateParams)->lParam);
256  Info->hSelf = hwnd;
257 
260  (LONG_PTR)Info);
261 
262  if (!InitEditWnd(Info))
263  {
264  Ret = (LRESULT)-1;
265  break;
266  }
267  break;
268  }
269 /*
270  case WM_ERASEBKGND:
271  if (Info->Width != 0 && Info->Height != 0)
272  {
273  Ret = TRUE;
274  }
275  break;
276 */
277  case WM_LBUTTONDOWN:
278  if (! bRightButtonDown)
279  SetCapture(Info->hSelf);
280 
281  bLeftButtonDown = TRUE;
282  xMouse = LOWORD(lParam);
283  yMouse = HIWORD(lParam);
284 
287  break;
288 
289  case WM_LBUTTONUP:
290  if (bLeftButtonDown)
291  SetCapture(NULL);
292 
293  bLeftButtonDown = FALSE;
294 
295  break;
296 
297  case WM_RBUTTONDOWN:
298  if (! bLeftButtonDown)
299  SetCapture(Info->hSelf);
300 
301  bRightButtonDown = TRUE;
302  xMouse = LOWORD(lParam);
303  yMouse = HIWORD(lParam);
304 
307  break;
308 
309  case WM_RBUTTONUP:
310  if (bRightButtonDown)
311  SetCapture(NULL);
312 
313  bRightButtonDown = FALSE;
314 
315  break;
316 
317  case WM_MOUSEMOVE:
318  {
319  HPEN hPen, hPenOld;
320 
321  if (!bLeftButtonDown && !bRightButtonDown)
322  break;
323 
324  hDC = GetDC(Info->hSelf);
325 
326  SelectObject(Info->hDCMem,
327  Info->hBitmap);
328 
329  if (bLeftButtonDown)
330  hPen = CreatePen(PS_SOLID,
331  3,
332  RGB(0, 0, 0));
333  else
334  hPen = CreatePen(PS_SOLID,
335  3,
336  RGB(255, 255, 255));
337 
338  hPenOld = SelectObject(hDC,
339  hPen);
340  SelectObject(Info->hDCMem,
341  hPen);
342 
343  MoveToEx(hDC,
344  xMouse,
345  yMouse,
346  NULL);
347 
348  MoveToEx(Info->hDCMem,
349  xMouse,
350  yMouse,
351  NULL);
352 
353  xMouse = LOWORD(lParam);
354  yMouse = HIWORD(lParam);
355 
356  LineTo(hDC,
357  xMouse,
358  yMouse);
359 
360  LineTo(Info->hDCMem,
361  xMouse,
362  yMouse);
363 
365  hPenOld);
367  hPenOld));
368 
369  ReleaseDC(Info->hSelf,
370  hDC);
371  }
372  break;
373 
374  case WM_PAINT:
375  {
376  if (Info->Width != 0 && Info->Height != 0)
377  {
378  PAINTSTRUCT ps;
379  HDC hDC;
380 
381  hDC = BeginPaint(hwnd,
382  &ps);
383  if (hDC != NULL)
384  {
386  hDC,
387  &ps);
388 
389  EndPaint(hwnd,
390  &ps);
391  }
392  }
393  break;
394  }
395 
396  case WM_SIZE:
397  {
399  goto HandleDefaultMessage;
400  }
401 
402  case WM_MENUSELECT:
403  case WM_ENTERMENULOOP:
404  case WM_EXITMENULOOP:
405  /* forward these messages to the main window procedure */
406  Ret = SendMessage(Info->MainWnd->hSelf,
407  uMsg,
408  wParam,
409  lParam);
410  break;
411 
412  case WM_MDIACTIVATE:
413  /* Switch the main window context if neccessary */
415  (HWND)wParam,
416  (HWND)lParam);
417  break;
418 
419  case WM_DESTROY:
420  {
422 
424  0,
425  Info);
428  0);
429  break;
430  }
431 
432  default:
433 HandleDefaultMessage:
434  Ret = DefMDIChildProc(hwnd,
435  uMsg,
436  wParam,
437  lParam);
438  break;
439  }
440 
441  return Ret;
442 }
443 
444 VOID
446  BOOL Setup)
447 {
448  if (Setup)
449  {
450  /* FIXME - setup editor environment (e.g. show toolbars, enable menus etc) */
451  }
452  else
453  {
454  /* FIXME - cleanup editor environment (e.g. hide toolbars, disable menus etc) */
455  }
456 }
457 
458 BOOL
460  POPEN_IMAGE_EDIT_INFO OpenInfo)
461 {
463  HWND hWndEditor;
464  LONG Width, Height;
465 
467  0,
468  sizeof(EDIT_WND_INFO));
469  if (Info != NULL)
470  {
472  sizeof(EDIT_WND_INFO));
473  Info->MainWnd = MainWnd;
474  Info->MdiEditorType = metImageEditor;
475  Info->OpenInfo = OpenInfo;
476 
477  if (OpenInfo->CreateNew)
478  {
479  Width = OpenInfo->New.Width;
480  Height = OpenInfo->New.Height;
481  }
482  else
483  {
484  Width = CW_USEDEFAULT;
485  Height = CW_USEDEFAULT;
486  }
487 
489  OpenInfo->lpImageName,
491  200,
492  200,
493  Width,
494  Height,
495  MainWnd->hMdiClient,
496  hInstance,
497  (LPARAM)Info);
498 
499  if (hWndEditor != NULL)
500  {
501  return TRUE;
502  }
503 
505  0,
506  Info);
507  }
508 
509  return FALSE;
510 }
511 
512 BOOL
514 {
515  WNDCLASSEX wc = {0};
516 
517  wc.cbSize = sizeof(WNDCLASSEX);
518  wc.style = CS_HREDRAW | CS_VREDRAW;
520  wc.hInstance = hInstance;
521  wc.hIcon = LoadIcon(hInstance,
529  IMAGE_ICON,
530  16,
531  16,
532  LR_SHARED);
533 
534  return RegisterClassEx(&wc) != (ATOM)0;
535 }
536 
537 VOID
539 {
541  hInstance);
542 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define IDC_PAINTBRUSHCURSOR
Definition: resource.h:246
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
UINT style
Definition: winuser.h:3155
#define MAKEINTRESOURCE
Definition: winuser.h:591
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define CloseHandle
Definition: compat.h:398
#define LR_SHARED
Definition: winuser.h:1090
#define IMAGE_ICON
Definition: winuser.h:212
#define RegisterClassEx
Definition: winuser.h:5703
#define SIF_RANGE
Definition: winuser.h:1221
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
static const TCHAR szImageEditWndClass[]
Definition: imgedwnd.c:3
HCURSOR hCursor
Definition: winuser.h:3161
WNDPROC lpfnWndProc
Definition: winuser.h:3156
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE ACPI_HANDLE *OutHandle ACPI_HANDLE *OutHandle void *Context void *Context ACPI_EVENT_HANDLER Handler UINT32 UINT32 ACPI_GPE_HANDLER void *Context UINT32 ACPI_NOTIFY_HANDLER void *Context ACPI_ADR_SPACE_TYPE ACPI_ADR_SPACE_HANDLER ACPI_ADR_SPACE_SETUP Setup
Definition: acpixf.h:816
HDC WINAPI GetDC(_In_opt_ HWND)
LPCSTR lpszClassName
Definition: winuser.h:3164
WORD ATOM
Definition: dimm.idl:113
#define SB_VERT
Definition: winuser.h:553
#define SB_HORZ
Definition: winuser.h:552
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
struct _EDIT_WND_INFO * Next
Definition: imgedwnd.h:72
LONG top
Definition: windef.h:292
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define ZeroMemory
Definition: winbase.h:1635
#define CS_HREDRAW
Definition: winuser.h:648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
#define WHITE_BRUSH
Definition: wingdi.h:901
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
UINT_PTR WPARAM
Definition: windef.h:207
HICON hIconSm
Definition: winuser.h:3165
LONG left
Definition: windef.h:291
static VOID ImageEditWndRepaint(PEDIT_WND_INFO Info, HDC hDC, LPPAINTSTRUCT lpps)
Definition: imgedwnd.c:206
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
LONG right
Definition: windef.h:293
CREATESTRUCTA * LPCREATESTRUCT
Definition: winuser.h:5592
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:410
int32_t INT
Definition: typedefs.h:56
#define SIF_PAGE
Definition: winuser.h:1219
static BOOLEAN bSuccess
Definition: drive.cpp:417
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
struct TraceInfo Info
#define FILE_SHARE_READ
Definition: compat.h:125
#define IDC_PAINTBRUSHCURSORMOUSEDOWN
Definition: resource.h:247
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
VOID GetError(VOID)
Definition: misc.c:192
#define PS_SOLID
Definition: wingdi.h:585
HINSTANCE hInstance
Definition: charmap.c:20
HINSTANCE hInstance
Definition: winuser.h:3159
HWND hMdiClient
Definition: precomp.h:43
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define WM_ENTERMENULOOP
Definition: winuser.h:1780
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
static BOOL InitEditWnd(PEDIT_WND_INFO Info)
Definition: imgedwnd.c:128
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_MENUSELECT
Definition: winuser.h:1723
#define CW_USEDEFAULT
Definition: winuser.h:225
#define GWLP_USERDATA
Definition: treelist.c:63
#define IDI_IMAGESOFTICON
Definition: resource.h:13
#define WM_EXITMENULOOP
Definition: winuser.h:1781
smooth NULL
Definition: ftsmooth.c:416
VOID UninitImageEditWindowImpl(VOID)
Definition: imgedwnd.c:538
struct _OPEN_IMAGE_EDIT_INFO::@1503::@1505 New
LONG_PTR LPARAM
Definition: windef.h:208
UINT cbSize
Definition: winuser.h:3154
BOOL CreateImageEditWindow(PMAIN_WND_INFO MainWnd, POPEN_IMAGE_EDIT_INFO OpenInfo)
Definition: imgedwnd.c:459
#define OPEN_EXISTING
Definition: compat.h:426
HBRUSH hbrBackground
Definition: winuser.h:3162
#define DefMDIChildProc
Definition: ros2win.h:33
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_RBUTTONDOWN
Definition: winuser.h:1755
static BOOL LoadBlankCanvas(PEDIT_WND_INFO Info)
Definition: imgedwnd.c:37
Definition: uimain.c:88
#define CS_VREDRAW
Definition: winuser.h:653
char TCHAR
Definition: xmlstorage.h:189
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define WM_SIZE
Definition: winuser.h:1593
#define RGB(r, g, b)
Definition: wingdi.h:2918
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
#define WM_RBUTTONUP
Definition: winuser.h:1756
#define GetObject
Definition: wingdi.h:4446
BOOL InitImageEditWindowImpl(VOID)
Definition: imgedwnd.c:513
#define WS_HSCROLL
Definition: pedump.c:628
#define WM_PAINT
Definition: winuser.h:1602
HICON hIcon
Definition: winuser.h:3160
static BOOL LoadDIBImage(PEDIT_WND_INFO Info)
Definition: imgedwnd.c:48
#define LRESULT
Definition: ole.h:14
#define GENERIC_READ
Definition: compat.h:124
#define CreateMDIWindow
Definition: winuser.h:5619
#define WM_MDIACTIVATE
Definition: winuser.h:1790
_In_ HANDLE hFile
Definition: mswsock.h:90
#define LoadCursor
Definition: winuser.h:5678
HANDLE ProcessHeap
Definition: servman.c:15
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HWND WINAPI SetCapture(_In_ HWND hWnd)
#define TEXT(s)
Definition: k32.h:26
static VOID EditWndUpdateScrollInfo(PEDIT_WND_INFO Info)
Definition: imgedwnd.c:8
BOOL WINAPI DeleteDC(_In_ HDC)
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
struct _EDIT_WND_INFO * PEDIT_WND_INFO
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
#define WM_LBUTTONUP
Definition: winuser.h:1753
Definition: bl.h:1331
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define WM_MOUSEMOVE
Definition: winuser.h:1751
#define WS_VSCROLL
Definition: pedump.c:627
#define SendMessage
Definition: winuser.h:5709
#define WM_CREATE
Definition: winuser.h:1590
#define HIWORD(l)
Definition: typedefs.h:246
LONG bottom
Definition: windef.h:294
#define LoadImage
Definition: winuser.h:5681
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5585
#define LoadIcon
Definition: winuser.h:5679
#define GetWindowLongPtr
Definition: treelist.c:73
static LRESULT CALLBACK ImageEditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: imgedwnd.c:232
LONG_PTR LRESULT
Definition: windef.h:209
#define DIB_RGB_COLORS
Definition: wingdi.h:366
VOID SetImageEditorEnvironment(PEDIT_WND_INFO Info, BOOL Setup)
Definition: imgedwnd.c:445
#define UnregisterClass
Definition: winuser.h:5727
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
LPARAM lParam
Definition: combotst.c:139
#define IMAGE_FRAME_SIZE
Definition: imgedwnd.c:5
#define LOWORD(l)
Definition: pedump.c:82
int WINAPI SetScrollInfo(_In_ HWND, _In_ int, _In_ LPCSCROLLINFO, _In_ BOOL)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SRCCOPY
Definition: wingdi.h:332
VOID MainWndSwitchEditorContext(PMAIN_WND_INFO Info, HWND hDeactivate, HWND hActivate)
Definition: mainwnd.c:1313
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
static VOID DestroyEditWnd(PEDIT_WND_INFO Info)
Definition: imgedwnd.c:175
#define WS_MAXIMIZE
Definition: pedump.c:623