2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include "../InternalHelpers.h"
\r
25 #include "../Resources.h"
\r
27 #include "RenderForm.h"
\r
29 using namespace System;
\r
30 using namespace System::Drawing;
\r
31 using namespace System::ComponentModel;
\r
32 using namespace System::Windows::Forms;
\r
38 RenderForm::RenderForm()
\r
40 Construct( "SlimDX" );
\r
43 RenderForm::RenderForm( System::String^ text )
\r
48 void RenderForm::Construct( System::String^ text )
\r
51 ClientSize = System::Drawing::Size( 800, 600 );
\r
52 MinimumSize = System::Drawing::Size( 200, 200 );
\r
54 ResizeRedraw = true;
\r
55 SetStyle( ControlStyles::AllPaintingInWmPaint | ControlStyles::UserPaint, true );
\r
57 Icon = SlimDX::Resources::BlackIcon;
\r
60 void RenderForm::OnResizeBegin( EventArgs^ e )
\r
62 Form::OnResizeBegin(e);
\r
66 OnPauseRendering(e);
\r
69 void RenderForm::OnResizeEnd( EventArgs^ e )
\r
71 Form::OnResizeEnd(e);
\r
77 OnResumeRendering(e);
\r
80 void RenderForm::OnLoad( EventArgs^ e )
\r
87 void RenderForm::OnPaintBackground( PaintEventArgs^ e )
\r
89 SLIMDX_UNREFERENCED_PARAMETER( e );
\r
92 void RenderForm::OnPauseRendering(EventArgs^ e)
\r
94 if (&RenderForm::PauseRendering != nullptr)
\r
95 PauseRendering(this, e);
\r
98 void RenderForm::OnResumeRendering(EventArgs^ e)
\r
100 if (&RenderForm::ResumeRendering != nullptr)
\r
101 ResumeRendering(this, e);
\r
104 void RenderForm::OnUserResized(EventArgs^ e)
\r
106 if (&RenderForm::UserResized != nullptr)
\r
107 UserResized(this, e);
\r
110 void RenderForm::OnMonitorChanged(EventArgs^ e)
\r
112 if (&RenderForm::MonitorChanged != nullptr)
\r
113 MonitorChanged(this, e);
\r
116 void RenderForm::OnAppActivated(EventArgs^ e)
\r
118 if (&RenderForm::AppActivated != nullptr)
\r
119 AppActivated(this, e);
\r
122 void RenderForm::OnAppDeactivated(EventArgs^ e)
\r
124 if (&RenderForm::AppDeactivated != nullptr)
\r
125 AppDeactivated(this, e);
\r
128 void RenderForm::OnSystemSuspend(EventArgs^ e)
\r
130 if (&RenderForm::SystemSuspend != nullptr)
\r
131 SystemSuspend(this, e);
\r
134 void RenderForm::OnSystemResume(EventArgs^ e)
\r
136 if (&RenderForm::SystemResume != nullptr)
\r
137 SystemResume(this, e);
\r
140 void RenderForm::OnScreensaver(CancelEventArgs^ e)
\r
142 if (&RenderForm::Screensaver != nullptr)
\r
143 Screensaver(this, e);
\r
146 void RenderForm::WndProc( Message% m )
\r
148 Int64 wparam = m.WParam.ToInt64();
\r
150 if (m.Msg == WM_SIZE)
\r
152 if (wparam == SIZE_MINIMIZED)
\r
156 OnPauseRendering(EventArgs::Empty);
\r
161 GetClientRect(reinterpret_cast<HWND>(m.HWnd.ToPointer()), &rect);
\r
162 if (rect.bottom - rect.top == 0)
\r
164 // Rapidly clicking the task bar to minimize and restore a window
\r
165 // can cause a WM_SIZE message with SIZE_RESTORED when
\r
166 // the window has actually become minimized due to rapid change
\r
167 // so just ignore this message
\r
169 else if (wparam == SIZE_MAXIMIZED)
\r
172 OnResumeRendering(EventArgs::Empty);
\r
177 OnUserResized(EventArgs::Empty);
\r
180 else if (wparam == SIZE_RESTORED)
\r
183 OnResumeRendering(EventArgs::Empty);
\r
188 if (!sizeMove && Size != cachedSize)
\r
190 OnUserResized(EventArgs::Empty);
\r
197 else if (m.Msg == WM_ACTIVATEAPP)
\r
200 OnAppActivated(EventArgs::Empty);
\r
202 OnAppDeactivated(EventArgs::Empty);
\r
204 else if (m.Msg == WM_POWERBROADCAST)
\r
206 if (wparam == PBT_APMQUERYSUSPEND)
\r
208 OnSystemSuspend(EventArgs::Empty);
\r
209 m.Result = IntPtr(1);
\r
212 else if (wparam == PBT_APMRESUMESUSPEND)
\r
214 OnSystemResume(EventArgs::Empty);
\r
215 m.Result = IntPtr(1);
\r
219 else if (m.Msg == WM_MENUCHAR)
\r
221 // A menu is active and the user presses a key that does not correspond to any mnemonic or accelerator key
\r
222 // So just ignore and don't beep
\r
223 m.Result = IntPtr(MAKELRESULT(0, MNC_CLOSE));
\r
226 else if (m.Msg == WM_SYSCOMMAND)
\r
229 if (wparam == SC_MONITORPOWER || wparam == SC_SCREENSAVE)
\r
231 CancelEventArgs^ e = gcnew CancelEventArgs();
\r
235 m.Result = IntPtr::Zero;
\r
244 void RenderForm::UpdateScreen()
\r
246 DisplayMonitor^ current = DisplayMonitor::FromWindow(Handle);
\r
247 if (monitor != nullptr && monitor->DeviceName != current->DeviceName)
\r
250 OnMonitorChanged(EventArgs::Empty);
\r