9dbe27f767e2067a5fa6126ade418c15f5d7f919
[reactos.git] / reactos / win32ss / user / winsrv / consrv / frontends / gui / fullscreen.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/frontends/gui/fullscreen.c
5 * PURPOSE: GUI Terminal Full-screen Mode
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "consrv.h"
12 #include "include/conio.h"
13 #include "include/console.h"
14 #include "include/settings.h"
15 #include "guisettings.h"
16
17 #define NDEBUG
18 #include <debug.h>
19
20
21 /* FUNCTIONS ******************************************************************/
22
23 BOOL
24 EnterFullScreen(PGUI_CONSOLE_DATA GuiData)
25 {
26 DEVMODEW DevMode;
27
28 ZeroMemory(&DevMode, sizeof(DevMode));
29 DevMode.dmSize = sizeof(DevMode);
30
31 DevMode.dmDisplayFixedOutput = DMDFO_CENTER; // DMDFO_STRETCH // DMDFO_DEFAULT
32 // DevMode.dmDisplayFlags = DMDISPLAYFLAGS_TEXTMODE;
33 DevMode.dmPelsWidth = 640; // GuiData->ActiveBuffer->ViewSize.X * GuiData->CharWidth;
34 DevMode.dmPelsHeight = 480; // GuiData->ActiveBuffer->ViewSize.Y * GuiData->CharHeight;
35 // DevMode.dmBitsPerPel = 32;
36 DevMode.dmFields = DM_DISPLAYFIXEDOUTPUT | /* DM_DISPLAYFLAGS | DM_BITSPERPEL | */ DM_PELSWIDTH | DM_PELSHEIGHT;
37
38 return (ChangeDisplaySettingsW(&DevMode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
39 }
40
41 VOID
42 LeaveFullScreen(PGUI_CONSOLE_DATA GuiData)
43 {
44 ChangeDisplaySettingsW(NULL, CDS_RESET);
45 }
46
47
48 // static VOID
49 // GuiConsoleResize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam);
50
51 VOID
52 SwitchFullScreen(PGUI_CONSOLE_DATA GuiData, BOOL FullScreen)
53 {
54 PCONSOLE Console = GuiData->Console;
55
56 /*
57 * See:
58 * http://stackoverflow.com/questions/2382464/win32-full-screen-and-hiding-taskbar
59 * http://stackoverflow.com/questions/3549148/fullscreen-management-with-winapi
60 * http://blogs.msdn.com/b/oldnewthing/archive/2010/04/12/9994016.aspx
61 * http://blogs.msdn.com/b/oldnewthing/archive/2005/05/05/414910.aspx
62 * http://stackoverflow.com/questions/1400654/how-do-i-put-my-opengl-app-into-fullscreen-mode
63 * http://nehe.gamedev.net/tutorial/creating_an_opengl_window_win32/13001/
64 * http://www.reocities.com/pcgpe/dibs.html
65 */
66
67 /* If we are already in the given state, just bail out */
68 if (FullScreen == GuiData->GuiInfo.FullScreen) return;
69
70 /* Save the current window state if we are not already full-screen */
71 if (!GuiData->GuiInfo.FullScreen)
72 {
73 GuiData->IsWndMax = IsZoomed(GuiData->hWindow);
74 if (GuiData->IsWndMax)
75 SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
76
77 /* Save its old position and size and show state */
78 GuiData->WndPl.length = sizeof(WINDOWPLACEMENT);
79 GetWindowPlacement(GuiData->hWindow, &GuiData->WndPl);
80
81 /* Save the old window styles */
82 GuiData->WndStyle = GetWindowLongPtr(GuiData->hWindow, GWL_STYLE );
83 GuiData->WndStyleEx = GetWindowLongPtr(GuiData->hWindow, GWL_EXSTYLE);
84 }
85
86 if (FullScreen)
87 {
88 SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
89
90 /* Switch to full screen */
91 if (EnterFullScreen(GuiData))
92 {
93 /* Save the new state */
94 Console->FixedSize = TRUE;
95 GuiData->GuiInfo.FullScreen = TRUE;
96
97 GuiData->ActiveBuffer->OldViewSize = GuiData->ActiveBuffer->ViewSize;
98 // GuiData->ActiveBuffer->OldScreenBufferSize = GuiData->ActiveBuffer->ScreenBufferSize;
99
100 /* Change the window styles */
101 SetWindowLongPtr(GuiData->hWindow, GWL_STYLE,
102 WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
103 SetWindowLongPtr(GuiData->hWindow, GWL_EXSTYLE,
104 WS_EX_APPWINDOW);
105 // SetWindowPos(GuiData->hWindow, NULL, 0, 0, 0, 0,
106 // SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
107 // SWP_FRAMECHANGED | SWP_SHOWWINDOW);
108
109 /* Reposition the window to the upper-left corner */
110 SetWindowPos(GuiData->hWindow, HWND_TOPMOST, 0, 0, 0, 0,
111 SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW);
112
113 /* Make it the foreground window */
114 SetForegroundWindow(GuiData->hWindow);
115
116 /* Resize it */
117 // // GuiConsoleResizeWindow(GuiData);
118 // GuiConsoleResize(GuiData, SIZE_RESTORED, MAKELPARAM(640, 480));
119
120 PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
121 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
122 }
123
124 PostMessageW(GuiData->hWindow, WM_SYSCOMMAND,
125 GuiData->GuiInfo.FullScreen || GuiData->IsWndMax
126 ? SC_MAXIMIZE : SC_RESTORE,
127 0);
128 // ShowWindowAsync(GuiData->hWindow, SW_RESTORE);
129 }
130 else
131 {
132 SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
133
134 /* Restore windowing mode */
135 LeaveFullScreen(GuiData);
136
137 /* Save the new state */
138 GuiData->GuiInfo.FullScreen = FALSE;
139 Console->FixedSize = FALSE;
140
141 /*
142 * Restore possible saved dimensions
143 * of the active screen buffer view.
144 */
145 GuiData->ActiveBuffer->ViewSize = GuiData->ActiveBuffer->OldViewSize;
146 // GuiData->ActiveBuffer->ScreenBufferSize = GuiData->ActiveBuffer->OldScreenBufferSize;
147
148 /* Restore the window styles */
149 SetWindowLongPtr(GuiData->hWindow, GWL_STYLE,
150 GuiData->WndStyle);
151 SetWindowLongPtr(GuiData->hWindow, GWL_EXSTYLE,
152 GuiData->WndStyleEx);
153 SetWindowPos(GuiData->hWindow, NULL, 0, 0, 0, 0,
154 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
155 SWP_FRAMECHANGED /*| SWP_SHOWWINDOW*/);
156
157
158 /* Restore the window to its original position */
159 SetWindowPlacement(GuiData->hWindow, &GuiData->WndPl);
160
161 PostMessageW(GuiData->hWindow, WM_SYSCOMMAND,
162 GuiData->IsWndMax ? SC_MAXIMIZE : SC_RESTORE,
163 0);
164 // ShowWindowAsync(GuiData->hWindow, SW_RESTORE);
165
166 /* Make it the foreground window */
167 SetForegroundWindow(GuiData->hWindow);
168
169 /* Resize it */
170 // GuiConsoleResizeWindow(GuiData);
171
172 // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
173 // // ShowWindowAsync(GuiData->hWindow, SW_RESTORE);
174 }
175 }
176
177 VOID
178 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData)
179 {
180 PCONSOLE Console = GuiData->Console;
181 BOOL FullScreen;
182
183 if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
184
185 /* Switch to full-screen or to windowed mode */
186 FullScreen = !GuiData->GuiInfo.FullScreen;
187 DPRINT1("GuiConsoleSwitchFullScreen - Switch to %s ...\n",
188 (FullScreen ? "full-screen" : "windowed mode"));
189
190 SwitchFullScreen(GuiData, FullScreen);
191
192 LeaveCriticalSection(&Console->Lock);
193 }
194
195 /* EOF */