2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/frontends/gui/graphics.c
5 * PURPOSE: GUI Terminal Front-End - Support for graphics-mode screen-buffers
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 /* INCLUDES *******************************************************************/
18 /* FUNCTIONS ******************************************************************/
21 GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
22 PGUI_CONSOLE_DATA GuiData
)
25 * This function supposes that the system clipboard was opened.
29 HBITMAP hBitmapTarget
, hBitmapOld
;
30 HPALETTE hPalette
, hPaletteOld
;
31 ULONG selWidth
, selHeight
;
33 if (Buffer
->BitMap
== NULL
) return;
35 selWidth
= GuiData
->Selection
.srSelection
.Right
- GuiData
->Selection
.srSelection
.Left
+ 1;
36 selHeight
= GuiData
->Selection
.srSelection
.Bottom
- GuiData
->Selection
.srSelection
.Top
+ 1;
37 DPRINT("Selection is (%d|%d) to (%d|%d)\n",
38 GuiData
->Selection
.srSelection
.Left
,
39 GuiData
->Selection
.srSelection
.Top
,
40 GuiData
->Selection
.srSelection
.Right
,
41 GuiData
->Selection
.srSelection
.Bottom
);
43 hMemDC
= CreateCompatibleDC(GuiData
->hMemDC
);
44 if (hMemDC
== NULL
) return;
46 /* Allocate a bitmap to be given to the clipboard, so it will not be freed here */
47 hBitmapTarget
= CreateCompatibleBitmap(GuiData
->hMemDC
, selWidth
, selHeight
);
48 if (hBitmapTarget
== NULL
)
54 /* Select the new bitmap */
55 hBitmapOld
= SelectObject(hMemDC
, hBitmapTarget
);
57 /* Change the palette in hMemDC if the current palette does exist */
58 if (Buffer
->PaletteHandle
== NULL
)
59 hPalette
= GuiData
->hSysPalette
;
61 hPalette
= Buffer
->PaletteHandle
;
63 if (hPalette
) hPaletteOld
= SelectPalette(hMemDC
, hPalette
, FALSE
);
66 NtWaitForSingleObject(Buffer
->Mutex
, FALSE
, NULL
);
68 // The equivalent of a SetDIBitsToDevice call...
69 // It seems to be broken: it does not copy the tail of the bitmap.
70 // http://wiki.allegro.cc/index.php?title=StretchDIBits
75 GuiData
->Selection
.srSelection
.Left
,
76 GuiData
->Selection
.srSelection
.Top
,
83 SetDIBitsToDevice(hMemDC
,
84 /* Coordinates / size of the repainted rectangle, in the framebuffer's frame */
87 /* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
88 GuiData
->Selection
.srSelection
.Left
,
89 GuiData
->Selection
.srSelection
.Top
,
91 Buffer
->ScreenBufferSize
.Y
, // == Buffer->BitMapInfo->bmiHeader.biHeight
97 /* Release the mutex */
98 NtReleaseMutant(Buffer
->Mutex
, NULL
);
100 /* Restore the palette and the old bitmap */
101 if (hPalette
) SelectPalette(hMemDC
, hPaletteOld
, FALSE
);
102 SelectObject(hMemDC
, hBitmapOld
);
105 SetClipboardData(CF_BITMAP
, hBitmapTarget
);
111 GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
112 PGUI_CONSOLE_DATA GuiData
)
115 * This function supposes that the system clipboard was opened.
118 // PCONSRV_CONSOLE Console = Buffer->Header.Console;
124 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
125 PGUI_CONSOLE_DATA GuiData
,
129 PCONSRV_CONSOLE Console
= Buffer
->Header
.Console
;
130 // ASSERT(Console == GuiData->Console);
132 if (Buffer
->BitMap
== NULL
) return;
134 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
136 rcFramebuffer
->left
= Buffer
->ViewOrigin
.X
* 1 + rcView
->left
;
137 rcFramebuffer
->top
= Buffer
->ViewOrigin
.Y
* 1 + rcView
->top
;
138 rcFramebuffer
->right
= Buffer
->ViewOrigin
.X
* 1 + rcView
->right
;
139 rcFramebuffer
->bottom
= Buffer
->ViewOrigin
.Y
* 1 + rcView
->bottom
;
142 NtWaitForSingleObject(Buffer
->Mutex
, FALSE
, NULL
);
145 * The seventh parameter (YSrc) of SetDIBitsToDevice always designates
146 * the Y-coordinate of the "lower-left corner" of the image, be the DIB
147 * in bottom-up or top-down mode.
149 SetDIBitsToDevice(GuiData
->hMemDC
,
150 /* Coordinates / size of the repainted rectangle, in the framebuffer's frame */
153 rcFramebuffer
->right
- rcFramebuffer
->left
,
154 rcFramebuffer
->bottom
- rcFramebuffer
->top
,
155 /* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
159 Buffer
->ScreenBufferSize
.Y
, // == Buffer->BitMapInfo->bmiHeader.biHeight
162 Buffer
->BitMapUsage
);
164 /* Release the mutex */
165 NtReleaseMutant(Buffer
->Mutex
, NULL
);
167 LeaveCriticalSection(&Console
->Lock
);