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.
28 PCONSOLE Console
= Buffer
->Header
.Console
;
31 HBITMAP hBitmapTarget
, hBitmapOld
;
32 HPALETTE hPalette
, hPaletteOld
;
33 ULONG selWidth
, selHeight
;
35 if (Buffer
->BitMap
== NULL
) return;
37 selWidth
= Console
->Selection
.srSelection
.Right
- Console
->Selection
.srSelection
.Left
+ 1;
38 selHeight
= Console
->Selection
.srSelection
.Bottom
- Console
->Selection
.srSelection
.Top
+ 1;
39 DPRINT1("Selection is (%d|%d) to (%d|%d)\n",
40 Console
->Selection
.srSelection
.Left
,
41 Console
->Selection
.srSelection
.Top
,
42 Console
->Selection
.srSelection
.Right
,
43 Console
->Selection
.srSelection
.Bottom
);
45 hMemDC
= CreateCompatibleDC(GuiData
->hMemDC
);
46 if (hMemDC
== NULL
) return;
48 /* Allocate a bitmap to be given to the clipboard, so it will not be freed here */
49 hBitmapTarget
= CreateCompatibleBitmap(GuiData
->hMemDC
, selWidth
, selHeight
);
50 if (hBitmapTarget
== NULL
)
56 /* Select the new bitmap */
57 hBitmapOld
= SelectObject(hMemDC
, hBitmapTarget
);
59 /* Change the palette in hMemDC if the current palette does exist */
60 if (Buffer
->PaletteHandle
== NULL
)
61 hPalette
= GuiData
->hSysPalette
;
63 hPalette
= Buffer
->PaletteHandle
;
65 if (hPalette
) hPaletteOld
= SelectPalette(hMemDC
, hPalette
, FALSE
);
68 NtWaitForSingleObject(Buffer
->Mutex
, FALSE
, NULL
);
70 // The equivalent of a SetDIBitsToDevice call...
71 // It seems to be broken: it does not copy the tail of the bitmap.
72 // http://wiki.allegro.cc/index.php?title=StretchDIBits
77 Console
->Selection
.srSelection
.Left
,
78 Console
->Selection
.srSelection
.Top
,
85 SetDIBitsToDevice(hMemDC
,
86 /* Coordinates / size of the repainted rectangle, in the framebuffer's frame */
89 /* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
90 Console
->Selection
.srSelection
.Left
,
91 Console
->Selection
.srSelection
.Top
,
93 Buffer
->ScreenBufferSize
.Y
, // == Buffer->BitMapInfo->bmiHeader.biHeight
99 /* Release the mutex */
100 NtReleaseMutant(Buffer
->Mutex
, NULL
);
102 /* Restore the palette and the old bitmap */
103 if (hPalette
) SelectPalette(hMemDC
, hPaletteOld
, FALSE
);
104 SelectObject(hMemDC
, hBitmapOld
);
107 SetClipboardData(CF_BITMAP
, hBitmapTarget
);
113 GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
114 PGUI_CONSOLE_DATA GuiData
)
117 * This function supposes that the system clipboard was opened.
120 // PCONSOLE Console = Buffer->Header.Console;
126 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
127 PGUI_CONSOLE_DATA GuiData
,
131 if (Buffer
->BitMap
== NULL
) return;
133 rcFramebuffer
->left
= Buffer
->ViewOrigin
.X
* 1 + rcView
->left
;
134 rcFramebuffer
->top
= Buffer
->ViewOrigin
.Y
* 1 + rcView
->top
;
135 rcFramebuffer
->right
= Buffer
->ViewOrigin
.X
* 1 + rcView
->right
;
136 rcFramebuffer
->bottom
= Buffer
->ViewOrigin
.Y
* 1 + rcView
->bottom
;
139 NtWaitForSingleObject(Buffer
->Mutex
, FALSE
, NULL
);
142 * The seventh parameter (YSrc) of SetDIBitsToDevice always designates
143 * the Y-coordinate of the "lower-left corner" of the image, be the DIB
144 * in bottom-up or top-down mode.
146 SetDIBitsToDevice(GuiData
->hMemDC
,
147 /* Coordinates / size of the repainted rectangle, in the framebuffer's frame */
150 rcFramebuffer
->right
- rcFramebuffer
->left
,
151 rcFramebuffer
->bottom
- rcFramebuffer
->top
,
152 /* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
156 Buffer
->ScreenBufferSize
.Y
, // == Buffer->BitMapInfo->bmiHeader.biHeight
159 Buffer
->BitMapUsage
);
161 /* Release the mutex */
162 NtReleaseMutant(Buffer
->Mutex
, NULL
);