Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
6.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: PanelWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of PanelWnd.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "chicago.h"
  16. #include "PanelWnd.h"
  17. #include "..\..\LgLib\LgAux.h"
  18. #include "..\..\LgLib\Version.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. CPanelWnd::CPanelWnd()
  25. {
  26. m_pChildWnd = NULL;
  27. m_dAspect = 1.0;
  28. m_nMode = PN_NONE;
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPanelWnd::CPanelWnd") );
  30. }
  31. CPanelWnd::~CPanelWnd()
  32. {
  33. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPanelWnd::~CPanelWnd") );
  34. }
  35. BEGIN_MESSAGE_MAP(CPanelWnd, CWnd)
  36. //{{AFX_MSG_MAP(CPanelWnd)
  37. ON_WM_SIZE()
  38. ON_WM_SIZING()
  39. ON_WM_TIMER()
  40. ON_WM_MOUSEMOVE()
  41. ON_WM_LBUTTONDOWN()
  42. ON_WM_GETMINMAXINFO()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. BOOL CPanelWnd::Create(CWnd *pParentWnd, int x, int y, int nWidth, int nHeight)
  46. {
  47. return Create( pParentWnd, &CRect( x, y, x + nWidth, y + nHeight ) );
  48. }
  49. BOOL CPanelWnd::Create( CWnd *pParentWnd, CRect *pRect )
  50. {
  51. DestroyWindow();
  52. CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_ARROW ), GetSysColorBrush( COLOR_BTNFACE ), NULL );
  53. if( !CWnd::Create( strClassName, "", WS_CHILD | WS_DLGFRAME | WS_CLIPSIBLINGS, *pRect, pParentWnd, 0 ) )
  54. return FALSE;
  55. /*
  56. if( !CWnd::CreateEx( 0, strClassName, NULL, WS_POPUP | WS_DLGFRAME | WS_CLIPSIBLINGS, *pRect, pParentWnd, 0 ) )
  57. return FALSE;
  58. // Set WS_EX_LAYERED on this window
  59. BOOL bSet = SetWindowLong( GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong( GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_LAYERED );
  60. DWORD dwError = GetLastError();
  61. // Make this window 70% alpha
  62. bSet = SetLayeredWindowAttributes(GetSafeHwnd(), 0, (255 * 50) / 100, LWA_ALPHA);
  63. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CPanelWnd::CPanelWnd"), _T("Succeeded") );
  64. SetTimer( 1, 500, NULL );
  65. */
  66. return TRUE;
  67. }
  68. BOOL CPanelWnd::DestroyWindow()
  69. {
  70. m_pChildWnd = NULL;
  71. m_dAspect = 1.0;
  72. m_nMode = PN_NONE;
  73. return CWnd::DestroyWindow();
  74. }
  75. BOOL CPanelWnd::PlaceChild( CWnd *pChildWnd )
  76. {
  77. if( !pChildWnd )
  78. return FALSE;
  79. m_nMode = PM_SCALE;
  80. m_pChildWnd = pChildWnd;
  81. m_pChildWnd->SetParent( this );
  82. ScaleChildWindow();
  83. m_pChildWnd->ShowWindow( SW_SHOW );
  84. return TRUE;
  85. }
  86. BOOL CPanelWnd::PlaceChildCenter( CWnd *pChildWnd )
  87. {
  88. if( !pChildWnd )
  89. return FALSE;
  90. m_nMode = PM_CENTER;
  91. m_pChildWnd = pChildWnd;
  92. m_pChildWnd->SetParent( this );
  93. CenterChildWindow();
  94. m_pChildWnd->ShowWindow( SW_SHOW );
  95. return TRUE;
  96. }
  97. BOOL CPanelWnd::PlaceChildFit( CWnd *pChildWnd, double dAspect )
  98. {
  99. if( !pChildWnd )
  100. return FALSE;
  101. if( dAspect <= 0.0 )
  102. return FALSE;
  103. m_nMode = PM_FIT;
  104. m_pChildWnd = pChildWnd;
  105. m_dAspect = dAspect;
  106. m_pChildWnd->SetParent( this );
  107. FitChildWindow();
  108. m_pChildWnd->ShowWindow( SW_SHOW );
  109. return TRUE;
  110. }
  111. /*
  112. DWORD m_dwTime = GetTickCount();
  113. BOOL m_bWindowCompact = FALSE;
  114. CRect m_FullRect;
  115. */
  116. void CPanelWnd::OnSize(UINT nType, int cx, int cy)
  117. {
  118. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CPanelWnd::OnSize"), _T("Started...") );
  119. CWnd::OnSize(nType, cx, cy);
  120. switch( m_nMode )
  121. {
  122. case PM_FIT:
  123. FitChildWindow();
  124. break;
  125. case PM_SCALE:
  126. ScaleChildWindow();
  127. break;
  128. case PM_CENTER:
  129. CenterChildWindow();
  130. break;
  131. }
  132. /*
  133. if( m_bWindowCompact )
  134. {
  135. m_bWindowCompact = FALSE;
  136. GetWindowRect( &m_FullRect );
  137. if( m_pChildWnd )
  138. m_pChildWnd->ShowWindow( SW_SHOW );
  139. }
  140. */
  141. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CPanelWnd::OnSize"), _T("Done") );
  142. }
  143. void CPanelWnd::OnSizing(UINT fwSide, LPRECT pRect)
  144. {
  145. CWnd::OnSizing(fwSide, pRect);
  146. if( m_nMode != PM_CENTER )
  147. return;
  148. CRect ChildRect;
  149. m_pChildWnd->GetWindowRect( &ChildRect );
  150. ChildRect -= ChildRect.TopLeft();
  151. CRect SizeRect( pRect );
  152. SizeRect -= SizeRect.TopLeft();
  153. CSize Diff( SizeRect.Width() - ChildRect.Width(),
  154. SizeRect.Height() - ChildRect.Height() );
  155. switch( fwSide )
  156. {
  157. case WMSZ_TOPLEFT:
  158. if( Diff.cy < 0 )
  159. pRect->top = pRect->bottom - ChildRect.Height();
  160. case WMSZ_LEFT:
  161. if( Diff.cx < 0 )
  162. pRect->left = pRect->right - ChildRect.Width();
  163. break;
  164. case WMSZ_BOTTOMRIGHT:
  165. if( Diff.cy < 0 )
  166. pRect->bottom = pRect->top + ChildRect.Height();
  167. case WMSZ_RIGHT:
  168. if( Diff.cx < 0 )
  169. pRect->right = pRect->left + ChildRect.Width();
  170. break;
  171. case WMSZ_TOPRIGHT:
  172. if( Diff.cx < 0 )
  173. pRect->right = pRect->left + ChildRect.Width();
  174. case WMSZ_TOP:
  175. if( Diff.cy < 0 )
  176. pRect->top = pRect->bottom - ChildRect.Height();
  177. break;
  178. case WMSZ_BOTTOMLEFT:
  179. if( Diff.cx < 0 )
  180. pRect->left = pRect->right - ChildRect.Width();
  181. case WMSZ_BOTTOM:
  182. if( Diff.cy < 0 )
  183. pRect->bottom = pRect->top + ChildRect.Height();
  184. break;
  185. }
  186. }
  187. void CPanelWnd::FitChildWindow()
  188. {
  189. if( !m_pChildWnd )
  190. return;
  191. CRect WholeRect;
  192. GetClientRect( &WholeRect );
  193. CRect FitRect;
  194. ::FitRectWithAspect( &WholeRect, &FitRect, m_dAspect );
  195. m_pChildWnd->MoveWindow( &FitRect );
  196. }
  197. void CPanelWnd::CenterChildWindow()
  198. {
  199. if( !m_pChildWnd )
  200. return;
  201. CRect ChildRect;
  202. m_pChildWnd->GetWindowRect( &ChildRect );
  203. ChildRect -= ChildRect.TopLeft();
  204. CRect WholeRect;
  205. GetClientRect( &WholeRect );
  206. int xShift = ( WholeRect.Width() - ChildRect.Width() ) >> 1;
  207. int yShift = ( WholeRect.Height() - ChildRect.Height() ) >> 1;
  208. ChildRect += CPoint( xShift, yShift );
  209. m_pChildWnd->MoveWindow( &ChildRect );
  210. }
  211. void CPanelWnd::ScaleChildWindow()
  212. {
  213. if( !m_pChildWnd )
  214. return;
  215. CRect WholeRect;
  216. GetClientRect( &WholeRect );
  217. m_pChildWnd->MoveWindow( &WholeRect );
  218. }
  219. void CPanelWnd::OnTimer(UINT nIDEvent)
  220. {
  221. /*
  222. CPoint point;
  223. GetCursorPos( &point );
  224. CRect rect;
  225. GetWindowRect( &rect );
  226. if( rect.PtInRect( point ) )
  227. {
  228. m_dwTime = GetTickCount();
  229. if( m_bWindowCompact )
  230. {
  231. m_bWindowCompact = FALSE;
  232. if( m_pChildWnd )
  233. m_pChildWnd->ShowWindow( SW_SHOW );
  234. MoveWindow( &m_FullRect );
  235. }
  236. }
  237. if( m_bWindowCompact )
  238. {
  239. }
  240. else
  241. {
  242. if( (GetTickCount() - m_dwTime) > 1000 )
  243. {
  244. m_FullRect = rect;
  245. rect.left = rect.right - 10;
  246. MoveWindow( &rect );
  247. if( m_pChildWnd )
  248. m_pChildWnd->ShowWindow( SW_HIDE );
  249. m_bWindowCompact = TRUE;
  250. }
  251. }
  252. */
  253. CWnd::OnTimer(nIDEvent);
  254. }
  255. void CPanelWnd::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  256. {
  257. // lpMMI->ptMinTrackSize.x = 1;
  258. // lpMMI->ptMinTrackSize.y = 1;
  259. CWnd::OnGetMinMaxInfo(lpMMI);
  260. }