1c2c66affSColin Finck /*
2c2c66affSColin Finck * COPYRIGHT: See COPYING in the top level directory
3c2c66affSColin Finck * PROJECT: ReactOS Console Server DLL
4c2c66affSColin Finck * FILE: win32ss/user/winsrv/consrv/frontends/gui/graphics.c
5c2c66affSColin Finck * PURPOSE: GUI Terminal Front-End - Support for graphics-mode screen-buffers
6c2c66affSColin Finck * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7c2c66affSColin Finck */
8c2c66affSColin Finck
9c2c66affSColin Finck /* INCLUDES *******************************************************************/
10c2c66affSColin Finck
11c2c66affSColin Finck #include <consrv.h>
12c2c66affSColin Finck
13c2c66affSColin Finck #define NDEBUG
14c2c66affSColin Finck #include <debug.h>
15c2c66affSColin Finck
16c2c66affSColin Finck #include "guiterm.h"
17c2c66affSColin Finck
18c2c66affSColin Finck /* FUNCTIONS ******************************************************************/
19c2c66affSColin Finck
20c2c66affSColin Finck VOID
GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,PGUI_CONSOLE_DATA GuiData)21c2c66affSColin Finck GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
22c2c66affSColin Finck PGUI_CONSOLE_DATA GuiData)
23c2c66affSColin Finck {
24c2c66affSColin Finck /*
25c2c66affSColin Finck * This function supposes that the system clipboard was opened.
26c2c66affSColin Finck */
27c2c66affSColin Finck
28c2c66affSColin Finck HDC hMemDC;
29c2c66affSColin Finck HBITMAP hBitmapTarget, hBitmapOld;
30c2c66affSColin Finck HPALETTE hPalette, hPaletteOld;
31c2c66affSColin Finck ULONG selWidth, selHeight;
32c2c66affSColin Finck
33c2c66affSColin Finck if (Buffer->BitMap == NULL) return;
34c2c66affSColin Finck
35570eba2aSHermès Bélusca-Maïto selWidth = ConioRectWidth(&GuiData->Selection.srSelection);
36570eba2aSHermès Bélusca-Maïto selHeight = ConioRectHeight(&GuiData->Selection.srSelection);
37c2c66affSColin Finck DPRINT("Selection is (%d|%d) to (%d|%d)\n",
38c2c66affSColin Finck GuiData->Selection.srSelection.Left,
39c2c66affSColin Finck GuiData->Selection.srSelection.Top,
40c2c66affSColin Finck GuiData->Selection.srSelection.Right,
41c2c66affSColin Finck GuiData->Selection.srSelection.Bottom);
42c2c66affSColin Finck
43c2c66affSColin Finck hMemDC = CreateCompatibleDC(GuiData->hMemDC);
44c2c66affSColin Finck if (hMemDC == NULL) return;
45c2c66affSColin Finck
46c2c66affSColin Finck /* Allocate a bitmap to be given to the clipboard, so it will not be freed here */
47c2c66affSColin Finck hBitmapTarget = CreateCompatibleBitmap(GuiData->hMemDC, selWidth, selHeight);
48c2c66affSColin Finck if (hBitmapTarget == NULL)
49c2c66affSColin Finck {
50c2c66affSColin Finck DeleteDC(hMemDC);
51c2c66affSColin Finck return;
52c2c66affSColin Finck }
53c2c66affSColin Finck
54c2c66affSColin Finck /* Select the new bitmap */
55c2c66affSColin Finck hBitmapOld = SelectObject(hMemDC, hBitmapTarget);
56c2c66affSColin Finck
57c2c66affSColin Finck /* Change the palette in hMemDC if the current palette does exist */
58c2c66affSColin Finck if (Buffer->PaletteHandle == NULL)
59c2c66affSColin Finck hPalette = GuiData->hSysPalette;
60c2c66affSColin Finck else
61c2c66affSColin Finck hPalette = Buffer->PaletteHandle;
62c2c66affSColin Finck
63c2c66affSColin Finck if (hPalette) hPaletteOld = SelectPalette(hMemDC, hPalette, FALSE);
64c2c66affSColin Finck
65c2c66affSColin Finck /* Grab the mutex */
66c2c66affSColin Finck NtWaitForSingleObject(Buffer->Mutex, FALSE, NULL);
67c2c66affSColin Finck
68c2c66affSColin Finck // The equivalent of a SetDIBitsToDevice call...
69c2c66affSColin Finck // It seems to be broken: it does not copy the tail of the bitmap.
70c2c66affSColin Finck // http://wiki.allegro.cc/index.php?title=StretchDIBits
71c2c66affSColin Finck #if 0
72c2c66affSColin Finck StretchDIBits(hMemDC,
73c2c66affSColin Finck 0, 0,
74c2c66affSColin Finck selWidth, selHeight,
75c2c66affSColin Finck GuiData->Selection.srSelection.Left,
76c2c66affSColin Finck GuiData->Selection.srSelection.Top,
77c2c66affSColin Finck selWidth, selHeight,
78c2c66affSColin Finck Buffer->BitMap,
79c2c66affSColin Finck Buffer->BitMapInfo,
80c2c66affSColin Finck Buffer->BitMapUsage,
81c2c66affSColin Finck SRCCOPY);
82c2c66affSColin Finck #else
83c2c66affSColin Finck SetDIBitsToDevice(hMemDC,
84c2c66affSColin Finck /* Coordinates / size of the repainted rectangle, in the framebuffer's frame */
85c2c66affSColin Finck 0, 0,
86c2c66affSColin Finck selWidth, selHeight,
87c2c66affSColin Finck /* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
88c2c66affSColin Finck GuiData->Selection.srSelection.Left,
89c2c66affSColin Finck GuiData->Selection.srSelection.Top,
90c2c66affSColin Finck 0,
91c2c66affSColin Finck Buffer->ScreenBufferSize.Y, // == Buffer->BitMapInfo->bmiHeader.biHeight
92c2c66affSColin Finck Buffer->BitMap,
93c2c66affSColin Finck Buffer->BitMapInfo,
94c2c66affSColin Finck Buffer->BitMapUsage);
95c2c66affSColin Finck #endif
96c2c66affSColin Finck
97c2c66affSColin Finck /* Release the mutex */
98c2c66affSColin Finck NtReleaseMutant(Buffer->Mutex, NULL);
99c2c66affSColin Finck
100c2c66affSColin Finck /* Restore the palette and the old bitmap */
101c2c66affSColin Finck if (hPalette) SelectPalette(hMemDC, hPaletteOld, FALSE);
102c2c66affSColin Finck SelectObject(hMemDC, hBitmapOld);
103c2c66affSColin Finck
104c2c66affSColin Finck EmptyClipboard();
105c2c66affSColin Finck SetClipboardData(CF_BITMAP, hBitmapTarget);
106c2c66affSColin Finck
107c2c66affSColin Finck DeleteDC(hMemDC);
108c2c66affSColin Finck }
109c2c66affSColin Finck
110c2c66affSColin Finck VOID
GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,PGUI_CONSOLE_DATA GuiData)111c2c66affSColin Finck GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
112c2c66affSColin Finck PGUI_CONSOLE_DATA GuiData)
113c2c66affSColin Finck {
114c2c66affSColin Finck /*
115c2c66affSColin Finck * This function supposes that the system clipboard was opened.
116c2c66affSColin Finck */
117c2c66affSColin Finck
118c2c66affSColin Finck // PCONSRV_CONSOLE Console = Buffer->Header.Console;
119c2c66affSColin Finck
120c2c66affSColin Finck UNIMPLEMENTED;
121c2c66affSColin Finck }
122c2c66affSColin Finck
123c2c66affSColin Finck VOID
GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,PGUI_CONSOLE_DATA GuiData,PRECT rcView,PRECT rcFramebuffer)124c2c66affSColin Finck GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
125c2c66affSColin Finck PGUI_CONSOLE_DATA GuiData,
126c2c66affSColin Finck PRECT rcView,
127c2c66affSColin Finck PRECT rcFramebuffer)
128c2c66affSColin Finck {
129*75d0346cSHermès Bélusca-Maïto PCONSRV_CONSOLE Console = (PCONSRV_CONSOLE)Buffer->Header.Console;
130c2c66affSColin Finck // ASSERT(Console == GuiData->Console);
131c2c66affSColin Finck
1325ca9c9c1SHermès Bélusca-Maïto ConioInitLongRect(rcFramebuffer, 0, 0, 0, 0);
133602db402SMichael Fritscher
1345ca9c9c1SHermès Bélusca-Maïto if (Buffer->BitMap == NULL)
1355ca9c9c1SHermès Bélusca-Maïto return;
136c2c66affSColin Finck
1375ca9c9c1SHermès Bélusca-Maïto if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE))
1385ca9c9c1SHermès Bélusca-Maïto return;
139c2c66affSColin Finck
1405ca9c9c1SHermès Bélusca-Maïto ConioInitLongRect(rcFramebuffer,
1415ca9c9c1SHermès Bélusca-Maïto Buffer->ViewOrigin.Y * 1 + rcView->top,
1425ca9c9c1SHermès Bélusca-Maïto Buffer->ViewOrigin.X * 1 + rcView->left,
1435ca9c9c1SHermès Bélusca-Maïto Buffer->ViewOrigin.Y * 1 + rcView->bottom,
1445ca9c9c1SHermès Bélusca-Maïto Buffer->ViewOrigin.X * 1 + rcView->right);
145c2c66affSColin Finck
146c2c66affSColin Finck /* Grab the mutex */
147c2c66affSColin Finck NtWaitForSingleObject(Buffer->Mutex, FALSE, NULL);
148c2c66affSColin Finck
149c2c66affSColin Finck /*
150c2c66affSColin Finck * The seventh parameter (YSrc) of SetDIBitsToDevice always designates
151c2c66affSColin Finck * the Y-coordinate of the "lower-left corner" of the image, be the DIB
152c2c66affSColin Finck * in bottom-up or top-down mode.
153c2c66affSColin Finck */
154c2c66affSColin Finck SetDIBitsToDevice(GuiData->hMemDC,
155c2c66affSColin Finck /* Coordinates / size of the repainted rectangle, in the framebuffer's frame */
156c2c66affSColin Finck rcFramebuffer->left,
157c2c66affSColin Finck rcFramebuffer->top,
158c2c66affSColin Finck rcFramebuffer->right - rcFramebuffer->left,
159c2c66affSColin Finck rcFramebuffer->bottom - rcFramebuffer->top,
160c2c66affSColin Finck /* Coordinates / size of the corresponding image portion, in the graphics screen-buffer's frame */
161c2c66affSColin Finck rcFramebuffer->left,
162c2c66affSColin Finck rcFramebuffer->top,
163c2c66affSColin Finck 0,
164c2c66affSColin Finck Buffer->ScreenBufferSize.Y, // == Buffer->BitMapInfo->bmiHeader.biHeight
165c2c66affSColin Finck Buffer->BitMap,
166c2c66affSColin Finck Buffer->BitMapInfo,
167c2c66affSColin Finck Buffer->BitMapUsage);
168c2c66affSColin Finck
169c2c66affSColin Finck /* Release the mutex */
170c2c66affSColin Finck NtReleaseMutant(Buffer->Mutex, NULL);
171c2c66affSColin Finck
172c2c66affSColin Finck LeaveCriticalSection(&Console->Lock);
173c2c66affSColin Finck }
174c2c66affSColin Finck
175c2c66affSColin Finck /* EOF */
176