Leaked source code of windows server 2003
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.

1382 lines
36 KiB

  1. //
  2. // cuiwnd.cpp
  3. //
  4. #include "private.h"
  5. #include "cuiwnd.h"
  6. #include "cuiobj.h"
  7. #include "cuitip.h"
  8. #include "cuishadw.h"
  9. #include "cuischem.h"
  10. #include "cuisys.h"
  11. #include "cuiutil.h"
  12. #define UIWINDOW_CLASSNAME "CiceroUIWndFrame"
  13. #define UIWINDOW_TITLE "CiceroUIWndFrame"
  14. // TIMER IDs
  15. #define idTimer_UIObject 0x5461
  16. #define idTimer_MonitorMouse 0x7982
  17. // if this is too small like 100ms, tooltip does not work correctly.
  18. #define iElapse_MonitorMouse 1000
  19. /*=============================================================================*/
  20. /* */
  21. /* C U I F W I N D O W */
  22. /* */
  23. /*=============================================================================*/
  24. /* C U I F W I N D O W */
  25. /*------------------------------------------------------------------------------
  26. Constructor of CUIFWindow
  27. ------------------------------------------------------------------------------*/
  28. CUIFWindow::CUIFWindow( HINSTANCE hInst, DWORD dwStyle ) : CUIFObject( NULL /* no parent */, 0 /* no ID */, NULL /* no rectangle */, dwStyle )
  29. {
  30. m_hInstance = hInst;
  31. _xWnd = WND_DEF_X;
  32. _yWnd = WND_DEF_Y;
  33. _nWidth = WND_WIDTH;
  34. _nHeight = WND_HEIGHT;
  35. m_hWnd = NULL;
  36. m_pUIWnd = this;
  37. m_pUIObjCapture = NULL;
  38. m_pTimerUIObj = NULL;
  39. m_pUIObjPointed = NULL;
  40. m_fCheckingMouse = FALSE;
  41. m_pWndToolTip = NULL;
  42. m_pWndShadow = NULL;
  43. m_fShadowEnabled = TRUE;
  44. m_pBehindModalUIWnd = NULL;
  45. CreateScheme();
  46. }
  47. void CUIFWindow::CreateScheme()
  48. {
  49. if (m_pUIFScheme)
  50. delete m_pUIFScheme;
  51. // create scheme
  52. UIFSCHEME scheme;
  53. scheme = UIFSCHEME_DEFAULT;
  54. if (FHasStyle( UIWINDOW_OFC10MENU )) {
  55. scheme = UIFSCHEME_OFC10MENU;
  56. }
  57. else if (FHasStyle( UIWINDOW_OFC10TOOLBAR )) {
  58. scheme = UIFSCHEME_OFC10TOOLBAR;
  59. }
  60. else if (FHasStyle( UIWINDOW_OFC10WORKPANE )) {
  61. scheme = UIFSCHEME_OFC10WORKPANE;
  62. }
  63. m_pUIFScheme = CreateUIFScheme( scheme );
  64. Assert( m_pUIFScheme != NULL );
  65. SetScheme(m_pUIFScheme);
  66. }
  67. /* ~ C U I F W I N D O W */
  68. /*------------------------------------------------------------------------------
  69. Destructor of CUIFWindow
  70. ------------------------------------------------------------------------------*/
  71. CUIFWindow::~CUIFWindow( void )
  72. {
  73. CUIFObject *pUIObj;
  74. Assert( !m_hWnd || !GetThis(m_hWnd) );
  75. // delete tooltip/shadow
  76. if (m_pWndToolTip != NULL) {
  77. delete m_pWndToolTip;
  78. }
  79. if (m_pWndShadow != NULL) {
  80. delete m_pWndShadow;
  81. }
  82. // delete all childlen
  83. while (pUIObj = m_ChildList.GetLast()) {
  84. m_ChildList.Remove( pUIObj );
  85. delete pUIObj;
  86. }
  87. // dispose scheme
  88. if (m_pUIFScheme)
  89. delete m_pUIFScheme;
  90. }
  91. /* I N I T I A L I Z E */
  92. /*------------------------------------------------------------------------------
  93. Initialize UI window object
  94. (UIFObject method)
  95. ------------------------------------------------------------------------------*/
  96. CUIFObject *CUIFWindow::Initialize( void )
  97. {
  98. LPCTSTR pszClassName = GetClassName();
  99. WNDCLASSEX WndClass;
  100. // register window class
  101. MemSet( &WndClass, 0, sizeof(WndClass));
  102. WndClass.cbSize = sizeof( WndClass );
  103. if (!GetClassInfoEx( m_hInstance, pszClassName, &WndClass )) {
  104. MemSet( &WndClass, 0, sizeof(WndClass));
  105. WndClass.cbSize = sizeof( WndClass );
  106. WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  107. WndClass.lpfnWndProc = WindowProcedure;
  108. WndClass.cbClsExtra = 0;
  109. WndClass.cbWndExtra = 8;
  110. WndClass.hInstance = m_hInstance;
  111. WndClass.hIcon = NULL;
  112. WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
  113. WndClass.hbrBackground = NULL;
  114. WndClass.lpszMenuName = NULL;
  115. WndClass.lpszClassName = pszClassName;
  116. WndClass.hIconSm = NULL;
  117. RegisterClassEx( &WndClass );
  118. }
  119. // update scheme
  120. UpdateUIFSys();
  121. UpdateUIFScheme();
  122. // create tooltip
  123. if (FHasStyle( UIWINDOW_HASTOOLTIP )) {
  124. m_pWndToolTip = new CUIFToolTip( m_hInstance, UIWINDOW_TOPMOST | UIWINDOW_WSBORDER | (FHasStyle( UIWINDOW_LAYOUTRTL ) ? UIWINDOW_LAYOUTRTL : 0), this);
  125. if (m_pWndToolTip)
  126. m_pWndToolTip->Initialize();
  127. }
  128. // create shadow
  129. if (FHasStyle( UIWINDOW_HASSHADOW )) {
  130. m_pWndShadow = new CUIFShadow( m_hInstance, UIWINDOW_TOPMOST, this );
  131. if (m_pWndShadow)
  132. m_pWndShadow->Initialize();
  133. }
  134. return CUIFObject::Initialize();
  135. }
  136. /* P A I N T O B J E C T */
  137. /*------------------------------------------------------------------------------
  138. Paint window object
  139. (UIFObject method)
  140. ------------------------------------------------------------------------------*/
  141. void CUIFWindow::PaintObject( HDC hDC, const RECT *prcUpdate )
  142. {
  143. BOOL fReleaseDC = FALSE;
  144. HDC hDCMem;
  145. HBITMAP hBmpMem;
  146. HBITMAP hBmpOld;
  147. if (hDC == NULL) {
  148. hDC = GetDC( m_hWnd );
  149. fReleaseDC = TRUE;
  150. }
  151. if (prcUpdate == NULL) {
  152. prcUpdate = &GetRectRef();
  153. }
  154. // prepare memory dc
  155. hDCMem = CreateCompatibleDC( hDC );
  156. if (!hDCMem) {
  157. return;
  158. }
  159. hBmpMem = CreateCompatibleBitmap( hDC,
  160. prcUpdate->right - prcUpdate->left,
  161. prcUpdate->bottom - prcUpdate->top );
  162. if (hBmpMem) {
  163. hBmpOld = (HBITMAP)SelectObject( hDCMem, hBmpMem );
  164. // paint to memory dc
  165. BOOL fRetVal = SetViewportOrgEx( hDCMem, -prcUpdate->left, -prcUpdate->top, NULL );
  166. Assert( fRetVal );
  167. //
  168. // theme support
  169. //
  170. BOOL fDefault = TRUE;
  171. if (SUCCEEDED(EnsureThemeData(GetWnd())))
  172. {
  173. if (FHasStyle( UIWINDOW_CHILDWND ) &&
  174. SUCCEEDED(DrawThemeParentBackground(GetWnd(),
  175. hDCMem,
  176. &GetRectRef())))
  177. {
  178. fDefault = FALSE;
  179. }
  180. else if (SUCCEEDED(DrawThemeBackground(hDCMem,
  181. GetDefThemeStateID(),
  182. &GetRectRef(),
  183. 0 )))
  184. fDefault = FALSE;
  185. }
  186. if (fDefault)
  187. {
  188. if (m_pUIFScheme)
  189. m_pUIFScheme->FillRect( hDCMem, prcUpdate, UIFCOLOR_WINDOW );
  190. }
  191. //
  192. CUIFObject::PaintObject( hDCMem, prcUpdate );
  193. // transfer image to screen
  194. BitBlt( hDC,
  195. prcUpdate->left,
  196. prcUpdate->top,
  197. prcUpdate->right - prcUpdate->left,
  198. prcUpdate->bottom - prcUpdate->top,
  199. hDCMem,
  200. prcUpdate->left,
  201. prcUpdate->top,
  202. SRCCOPY );
  203. SelectObject( hDCMem, hBmpOld );
  204. DeleteObject( hBmpMem );
  205. }
  206. DeleteDC( hDCMem );
  207. if (fReleaseDC) {
  208. ReleaseDC( m_hWnd, hDC );
  209. }
  210. }
  211. /* G E T C L A S S N A M E */
  212. /*------------------------------------------------------------------------------
  213. Get class name
  214. ------------------------------------------------------------------------------*/
  215. LPCTSTR CUIFWindow::GetClassName( void )
  216. {
  217. return TEXT( UIWINDOW_CLASSNAME );
  218. }
  219. /* G E T W I N D O W T I T L E */
  220. /*------------------------------------------------------------------------------
  221. Get window title
  222. ------------------------------------------------------------------------------*/
  223. LPCTSTR CUIFWindow::GetWndTitle( void )
  224. {
  225. return TEXT( UIWINDOW_TITLE );
  226. }
  227. /* G E T W N D S T Y L E */
  228. /*------------------------------------------------------------------------------
  229. ------------------------------------------------------------------------------*/
  230. DWORD CUIFWindow::GetWndStyle( void )
  231. {
  232. DWORD dwWndStyle = 0;
  233. // determine style
  234. if (FHasStyle( UIWINDOW_CHILDWND )) {
  235. dwWndStyle |= WS_CHILD | WS_CLIPSIBLINGS;
  236. }
  237. else {
  238. dwWndStyle |= WS_POPUP | WS_DISABLED;
  239. }
  240. if (FHasStyle( UIWINDOW_OFC10MENU )) {
  241. dwWndStyle |= WS_BORDER;
  242. }
  243. else if (FHasStyle( UIWINDOW_WSDLGFRAME )) {
  244. dwWndStyle |= WS_DLGFRAME;
  245. }
  246. else if (FHasStyle( UIWINDOW_OFC10TOOLBAR )) {
  247. dwWndStyle |= WS_BORDER;
  248. }
  249. else if (FHasStyle( UIWINDOW_WSBORDER )) {
  250. dwWndStyle |= WS_BORDER;
  251. }
  252. return dwWndStyle;
  253. }
  254. /* G E T W N D S T Y L E E X */
  255. /*------------------------------------------------------------------------------
  256. ------------------------------------------------------------------------------*/
  257. DWORD CUIFWindow::GetWndStyleEx( void )
  258. {
  259. DWORD dwWndStyleEx = 0;
  260. // determine ex style
  261. if (FHasStyle( UIWINDOW_TOPMOST )) {
  262. dwWndStyleEx |= WS_EX_TOPMOST;
  263. }
  264. if (FHasStyle( UIWINDOW_TOOLWINDOW )) {
  265. dwWndStyleEx |= WS_EX_TOOLWINDOW;
  266. }
  267. if (FHasStyle( UIWINDOW_LAYOUTRTL )) {
  268. dwWndStyleEx |= WS_EX_LAYOUTRTL;
  269. }
  270. return dwWndStyleEx;
  271. }
  272. /* C R E A T E W N D */
  273. /*------------------------------------------------------------------------------
  274. Create window
  275. ------------------------------------------------------------------------------*/
  276. HWND CUIFWindow::CreateWnd( HWND hWndParent )
  277. {
  278. HWND hWnd;
  279. // create window
  280. hWnd = CreateWindowEx( GetWndStyleEx(), /* ex style */
  281. GetClassName(), /* class name */
  282. GetWndTitle(), /* window title */
  283. GetWndStyle(), /* window style */
  284. _xWnd, /* initial position (x) */
  285. _yWnd, /* initial position (y) */
  286. _nWidth, /* initial width */
  287. _nHeight, /* initial height */
  288. hWndParent, /* parent winodw */
  289. NULL, /* menu handle */
  290. m_hInstance, /* instance */
  291. this ); /* lpParam */
  292. // create tooltip window
  293. if (m_pWndToolTip != NULL) {
  294. m_pWndToolTip->CreateWnd( hWnd );
  295. }
  296. // create shadow window
  297. if (m_pWndShadow != NULL) {
  298. m_pWndShadow->CreateWnd( hWnd );
  299. }
  300. return hWnd;
  301. }
  302. /* S H O W */
  303. /*------------------------------------------------------------------------------
  304. ------------------------------------------------------------------------------*/
  305. void CUIFWindow::Show( BOOL fShow )
  306. {
  307. if (IsWindow( m_hWnd )) {
  308. if (fShow && FHasStyle( UIWINDOW_TOPMOST ))
  309. SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
  310. m_fVisible = fShow;
  311. ShowWindow( m_hWnd, fShow ? SW_SHOWNOACTIVATE : SW_HIDE );
  312. }
  313. }
  314. /* M O V E */
  315. /*------------------------------------------------------------------------------
  316. ------------------------------------------------------------------------------*/
  317. void CUIFWindow::Move(int x, int y, int nWidth, int nHeight)
  318. {
  319. _xWnd = x;
  320. _yWnd = y;
  321. if (nWidth >= 0)
  322. _nWidth = nWidth;
  323. if (nHeight >= 0)
  324. _nHeight = nHeight;
  325. if (IsWindow(m_hWnd)) {
  326. AdjustWindowPosition();
  327. MoveWindow(m_hWnd, _xWnd, _yWnd, _nWidth, _nHeight, TRUE);
  328. }
  329. }
  330. /* A N I M A T E W N D */
  331. /*------------------------------------------------------------------------------
  332. ------------------------------------------------------------------------------*/
  333. BOOL CUIFWindow::AnimateWnd( DWORD dwTime, DWORD dwFlags )
  334. {
  335. BOOL fRet = FALSE;
  336. if (!IsWindow( GetWnd() )) {
  337. return FALSE;
  338. }
  339. if (CUIIsAnimateWindowAvail()) {
  340. BOOL fVisibleOrg = m_fVisible;
  341. // HACK!
  342. // AnimateWindow never send WM_SHOWWINDOW message.
  343. // Need to set visible state before call AnimateWindow because
  344. // it need to be turned on in OnPaint() to handle WM_PRINTCLIENT
  345. // message. If animate window failed, restore it to original state.
  346. if ((dwFlags & AW_HIDE) == 0) {
  347. m_fVisible = TRUE;
  348. }
  349. else {
  350. m_fVisible = FALSE;
  351. }
  352. OnAnimationStart();
  353. // get system settings about animation
  354. fRet = CUIAnimateWindow( GetWnd(), dwTime, dwFlags );
  355. if (!fRet) {
  356. m_fVisible = fVisibleOrg;
  357. }
  358. OnAnimationEnd();
  359. }
  360. return fRet;
  361. }
  362. /* R E M O V E U I O B J */
  363. /*------------------------------------------------------------------------------
  364. Remove child UI object
  365. ------------------------------------------------------------------------------*/
  366. void CUIFWindow::RemoveUIObj( CUIFObject *pUIObj )
  367. {
  368. if (pUIObj == m_pUIObjCapture) {
  369. // release capture before remove
  370. SetCaptureObject( NULL );
  371. }
  372. if (pUIObj == m_pTimerUIObj) {
  373. // kill timer before remove
  374. SetTimerObject( NULL );
  375. }
  376. if (pUIObj == m_pUIObjPointed) {
  377. // no object pointed...
  378. m_pUIObjPointed = NULL;
  379. }
  380. CUIFObject::RemoveUIObj( pUIObj );
  381. }
  382. /* S E T C A P T U R E O B J E C T */
  383. /*------------------------------------------------------------------------------
  384. Set capture object
  385. Start/end capturing mouse
  386. ------------------------------------------------------------------------------*/
  387. void CUIFWindow::SetCaptureObject( CUIFObject *pUIObj )
  388. {
  389. if (pUIObj != NULL) {
  390. // start capture
  391. m_pUIObjCapture = pUIObj;
  392. SetCapture( TRUE );
  393. } else {
  394. // end capture
  395. m_pUIObjCapture = NULL;
  396. SetCapture( FALSE );
  397. }
  398. }
  399. /* S E T C A P T U R E O B J E C T */
  400. /*------------------------------------------------------------------------------
  401. Set capture
  402. Start/end capturing mouse
  403. ------------------------------------------------------------------------------*/
  404. void CUIFWindow::SetCapture(BOOL fSet)
  405. {
  406. if (fSet) {
  407. ::SetCapture( m_hWnd );
  408. } else {
  409. ::ReleaseCapture();
  410. }
  411. }
  412. /* S E T C A P T U R E O B J E C T */
  413. /*------------------------------------------------------------------------------
  414. Set capture object
  415. Start/end capturing mouse
  416. ------------------------------------------------------------------------------*/
  417. void CUIFWindow::SetBehindModal(CUIFWindow *pModalUIWnd)
  418. {
  419. m_pBehindModalUIWnd = pModalUIWnd;
  420. }
  421. /* S E T T I M E R O B J E C T */
  422. /*------------------------------------------------------------------------------
  423. Set timer object
  424. Make/kill timer
  425. ------------------------------------------------------------------------------*/
  426. void CUIFWindow::SetTimerObject( CUIFObject *pUIObj, UINT uElapse )
  427. {
  428. if (pUIObj != NULL) {
  429. // make timer
  430. Assert( uElapse != 0 );
  431. m_pTimerUIObj = pUIObj;
  432. SetTimer( m_hWnd, idTimer_UIObject, uElapse, NULL );
  433. } else {
  434. // kill timer
  435. Assert( uElapse == 0 );
  436. m_pTimerUIObj = NULL;
  437. KillTimer( m_hWnd, idTimer_UIObject );
  438. }
  439. }
  440. /* H A N D L E M O U S E M S G */
  441. /*------------------------------------------------------------------------------
  442. Mouse message handler
  443. Pass mouse message to appropriate UI object (capturing/monitoring/under
  444. the cursor)
  445. ------------------------------------------------------------------------------*/
  446. void CUIFWindow::HandleMouseMsg( UINT uMsg, POINT pt )
  447. {
  448. CUIFObject *pUIObj = ObjectFromPoint( pt );
  449. // check mouse in/out
  450. SetObjectPointed( pUIObj, pt );
  451. // find UI object to handle mouse message
  452. if (m_pUIObjCapture != NULL) {
  453. pUIObj = m_pUIObjCapture;
  454. }
  455. // set cursor
  456. if (pUIObj == NULL || !pUIObj->OnSetCursor( uMsg, pt )) {
  457. SetCursor( LoadCursor( NULL, IDC_ARROW ) );
  458. }
  459. // handle mouse message
  460. if (pUIObj != NULL && pUIObj->IsEnabled()) {
  461. switch (uMsg) {
  462. case WM_MOUSEMOVE: {
  463. pUIObj->OnMouseMove( pt );
  464. break;
  465. }
  466. case WM_LBUTTONDOWN: {
  467. pUIObj->OnLButtonDown( pt );
  468. break;
  469. }
  470. case WM_MBUTTONDOWN: {
  471. pUIObj->OnMButtonDown( pt );
  472. break;
  473. }
  474. case WM_RBUTTONDOWN: {
  475. pUIObj->OnRButtonDown( pt );
  476. break;
  477. }
  478. case WM_LBUTTONUP: {
  479. pUIObj->OnLButtonUp( pt );
  480. break;
  481. }
  482. case WM_MBUTTONUP: {
  483. pUIObj->OnMButtonUp( pt );
  484. break;
  485. }
  486. case WM_RBUTTONUP: {
  487. pUIObj->OnRButtonUp( pt );
  488. break;
  489. }
  490. } /* of switch */
  491. }
  492. }
  493. /* S E T O B J E C T P O I N T E D */
  494. /*------------------------------------------------------------------------------
  495. Set UI object pointed (the UI object under cursor)
  496. Notify MouseIn/Out to the object when changed
  497. ------------------------------------------------------------------------------*/
  498. void CUIFWindow::SetObjectPointed( CUIFObject *pUIObj, POINT pt )
  499. {
  500. if (pUIObj != m_pUIObjPointed) {
  501. // notify mouse out
  502. if (m_pUIObjCapture != NULL) {
  503. // notify only to capturing object
  504. if (m_pUIObjCapture == m_pUIObjPointed && m_pUIObjPointed->IsEnabled()) {
  505. m_pUIObjPointed->OnMouseOut( pt );
  506. }
  507. } else {
  508. if (m_pUIObjPointed != NULL && m_pUIObjPointed->IsEnabled()) {
  509. m_pUIObjPointed->OnMouseOut( pt );
  510. }
  511. }
  512. // set object pointed (object under the cursor)
  513. m_pUIObjPointed = pUIObj;
  514. // notify mouse in
  515. if (m_pUIObjCapture != NULL) {
  516. // notify only to capturing object
  517. if (m_pUIObjCapture == m_pUIObjPointed && m_pUIObjPointed->IsEnabled()) {
  518. m_pUIObjPointed->OnMouseIn( pt );
  519. }
  520. } else {
  521. if (m_pUIObjPointed != NULL && m_pUIObjPointed->IsEnabled()) {
  522. m_pUIObjPointed->OnMouseIn( pt );
  523. }
  524. }
  525. }
  526. }
  527. /* O N O B J E C T M O V E D */
  528. /*------------------------------------------------------------------------------
  529. Called when the UI object has been moved
  530. Check mouse in/out for the object
  531. ------------------------------------------------------------------------------*/
  532. void CUIFWindow::OnObjectMoved( CUIFObject *pUIObj )
  533. {
  534. POINT pt;
  535. if (IsWindow( m_hWnd )) {
  536. // set object pointed to check mouse in/out
  537. GetCursorPos( &pt );
  538. ScreenToClient( m_hWnd, &pt );
  539. SetObjectPointed( ObjectFromPoint( pt ), pt );
  540. }
  541. }
  542. /* S E T R E C T */
  543. /*------------------------------------------------------------------------------
  544. Set rect of object
  545. (CUIFObject method)
  546. ------------------------------------------------------------------------------*/
  547. void CUIFWindow::SetRect( const RECT * /*prc*/ )
  548. {
  549. RECT rc = { 0, 0, 0, 0 };
  550. if (IsWindow( GetWnd() )) {
  551. GetClientRect( GetWnd(), &rc );
  552. }
  553. CUIFObject::SetRect( &rc );
  554. }
  555. /* C L I E N T R E C T T O W I N D O W R E C T */
  556. /*------------------------------------------------------------------------------
  557. Get window rect from client rect
  558. ------------------------------------------------------------------------------*/
  559. void CUIFWindow::ClientRectToWindowRect( RECT *prc )
  560. {
  561. DWORD dwWndStyle;
  562. DWORD dwWndStyleEx;
  563. if (IsWindow( m_hWnd )) {
  564. dwWndStyle = GetWindowLong( m_hWnd, GWL_STYLE );
  565. dwWndStyleEx = GetWindowLong( m_hWnd, GWL_EXSTYLE );
  566. }
  567. else {
  568. dwWndStyle = GetWndStyle();
  569. dwWndStyleEx = GetWndStyleEx();
  570. }
  571. Assert( prc != NULL );
  572. AdjustWindowRectEx( prc, dwWndStyle, FALSE, dwWndStyleEx );
  573. }
  574. /* G E T W I N D O W F R A M E S I Z E */
  575. /*------------------------------------------------------------------------------
  576. Get window frame size
  577. ------------------------------------------------------------------------------*/
  578. void CUIFWindow::GetWindowFrameSize( SIZE *psize )
  579. {
  580. RECT rc = { 0, 0, 0, 0 };
  581. Assert( psize != NULL );
  582. ClientRectToWindowRect( &rc );
  583. psize->cx = (rc.right - rc.left) / 2;
  584. psize->cy = (rc.bottom - rc.top) / 2;
  585. }
  586. /* O N A N I M A T I O N S T A R T */
  587. /*------------------------------------------------------------------------------
  588. ------------------------------------------------------------------------------*/
  589. void CUIFWindow::OnAnimationStart( void )
  590. {
  591. }
  592. /* O N A N I M A T I O N E N D */
  593. /*------------------------------------------------------------------------------
  594. ------------------------------------------------------------------------------*/
  595. void CUIFWindow::OnAnimationEnd( void )
  596. {
  597. // show/hide shadow
  598. if (m_pWndShadow && m_fShadowEnabled) {
  599. m_pWndShadow->Show( m_fVisible );
  600. }
  601. }
  602. /* O N T H E M E C H A N G E D
  603. /*------------------------------------------------------------------------------
  604. ------------------------------------------------------------------------------*/
  605. void CUIFWindow::OnThemeChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
  606. {
  607. ClearTheme();
  608. }
  609. /* W I N D O W P R O C */
  610. /*------------------------------------------------------------------------------
  611. Window procedure of the object
  612. This function is called from WindowProcedure which is actual callback
  613. function to handle message.
  614. ------------------------------------------------------------------------------*/
  615. LRESULT CUIFWindow::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  616. {
  617. switch( uMsg ) {
  618. case WM_CREATE: {
  619. // store rects
  620. SetRect( NULL );
  621. OnCreate(hWnd);
  622. break;
  623. }
  624. case WM_SETFOCUS: {
  625. OnSetFocus(hWnd);
  626. break;
  627. }
  628. case WM_KILLFOCUS: {
  629. OnKillFocus(hWnd);
  630. break;
  631. }
  632. case WM_SIZE: {
  633. // store rects
  634. SetRect( NULL );
  635. break;
  636. }
  637. case WM_SETCURSOR: {
  638. POINT pt;
  639. // get current cursor pos
  640. GetCursorPos( &pt );
  641. ScreenToClient( m_hWnd, &pt );
  642. if (m_pBehindModalUIWnd)
  643. {
  644. m_pBehindModalUIWnd->ModalMouseNotify( HIWORD(lParam), pt );
  645. return TRUE;
  646. }
  647. // start checking mouse in/out
  648. if (!m_fCheckingMouse) {
  649. SetTimer( m_hWnd, idTimer_MonitorMouse, iElapse_MonitorMouse, NULL );
  650. m_fCheckingMouse = TRUE;
  651. }
  652. // tooltip
  653. if (m_pWndToolTip != NULL) {
  654. MSG msg;
  655. msg.hwnd = GetWnd();
  656. msg.message = HIWORD(lParam);
  657. msg.wParam = 0;
  658. msg.lParam = MAKELPARAM( pt.x, pt.y );
  659. m_pWndToolTip->RelayEvent( &msg );
  660. }
  661. // handle mouse message
  662. if (!FHasStyle( UIWINDOW_NOMOUSEMSGFROMSETCURSOR ))
  663. HandleMouseMsg( HIWORD(lParam), pt );
  664. return TRUE;
  665. }
  666. case WM_MOUSEACTIVATE: {
  667. return MA_NOACTIVATE;
  668. }
  669. case WM_MOUSEMOVE:
  670. case WM_LBUTTONDOWN:
  671. case WM_MBUTTONDOWN:
  672. case WM_RBUTTONDOWN:
  673. case WM_LBUTTONUP:
  674. case WM_MBUTTONUP:
  675. case WM_RBUTTONUP: {
  676. POINT pt;
  677. POINTSTOPOINT( pt, MAKEPOINTS( lParam ) );
  678. if (m_pBehindModalUIWnd) {
  679. m_pBehindModalUIWnd->ModalMouseNotify( uMsg, pt );
  680. break;
  681. }
  682. // handle mouse message
  683. HandleMouseMsg( uMsg, pt );
  684. break;
  685. }
  686. case WM_NOTIFY: {
  687. OnNotify(hWnd, (int)wParam, (NMHDR *)lParam);
  688. break;
  689. }
  690. case WM_NOTIFYFORMAT: {
  691. return OnNotifyFormat(hWnd, (HWND)wParam, lParam);
  692. break;
  693. }
  694. case WM_KEYDOWN: {
  695. OnKeyDown(hWnd, wParam, lParam);
  696. return 0;
  697. }
  698. case WM_KEYUP: {
  699. OnKeyUp(hWnd, wParam, lParam);
  700. return 0;
  701. }
  702. case WM_PAINT: {
  703. HDC hDC;
  704. PAINTSTRUCT ps;
  705. hDC = BeginPaint( hWnd, &ps );
  706. PaintObject( hDC, &ps.rcPaint );
  707. EndPaint( hWnd, &ps );
  708. break;
  709. }
  710. case WM_PRINTCLIENT: {
  711. HDC hDC = (HDC)wParam;
  712. PaintObject( hDC, NULL );
  713. break;
  714. }
  715. case WM_DESTROY: {
  716. if (m_pWndToolTip) {
  717. if (IsWindow( m_pWndToolTip->GetWnd() )) {
  718. DestroyWindow( m_pWndToolTip->GetWnd() );
  719. }
  720. }
  721. if (m_pWndShadow) {
  722. if (IsWindow( m_pWndShadow->GetWnd() )) {
  723. DestroyWindow( m_pWndShadow->GetWnd() );
  724. }
  725. }
  726. OnDestroy(hWnd);
  727. break;
  728. }
  729. case WM_NCDESTROY: {
  730. OnNCDestroy(hWnd);
  731. break;
  732. }
  733. case WM_COMMAND: {
  734. break;
  735. }
  736. case WM_TIMER: {
  737. switch (wParam) {
  738. case idTimer_MonitorMouse: {
  739. POINT pt;
  740. POINT ptClient;
  741. RECT rc;
  742. BOOL fMouseOut;
  743. // get current cursor pos
  744. GetCursorPos( &pt );
  745. ptClient = pt;
  746. ScreenToClient( m_hWnd, &ptClient );
  747. // check if mouse is outside of the window
  748. GetWindowRect( m_hWnd, &rc );
  749. fMouseOut = (!PtInRect( &rc, pt ) || WindowFromPoint( pt ) != m_hWnd);
  750. // stop monitoring mouse when mouseout
  751. if (fMouseOut) {
  752. ::KillTimer( m_hWnd, idTimer_MonitorMouse );
  753. m_fCheckingMouse = FALSE;
  754. SetObjectPointed( NULL, ptClient );
  755. OnMouseOutFromWindow( ptClient );
  756. }
  757. // notify mouse movement
  758. if (!fMouseOut && m_pBehindModalUIWnd)
  759. {
  760. m_pBehindModalUIWnd->ModalMouseNotify( WM_MOUSEMOVE, ptClient );
  761. }
  762. // tooltip
  763. if (m_pWndToolTip != NULL) {
  764. MSG msg;
  765. msg.hwnd = GetWnd();
  766. msg.message = WM_MOUSEMOVE;
  767. msg.wParam = 0;
  768. msg.lParam = MAKELPARAM( ptClient.x, ptClient.y );
  769. m_pWndToolTip->RelayEvent( &msg );
  770. }
  771. // handle mouse movement
  772. if (!fMouseOut) {
  773. HandleMouseMsg( WM_MOUSEMOVE, ptClient );
  774. }
  775. break;
  776. }
  777. case idTimer_UIObject: {
  778. if (m_pTimerUIObj != NULL)
  779. m_pTimerUIObj->OnTimer();
  780. break;
  781. }
  782. default: {
  783. OnTimer((UINT)wParam );
  784. break;
  785. }
  786. }
  787. break;
  788. }
  789. case WM_ACTIVATE: {
  790. return OnActivate(hWnd, uMsg, wParam, lParam);
  791. break;
  792. }
  793. case WM_WINDOWPOSCHANGED: {
  794. // move shadow
  795. if (m_pWndShadow) {
  796. WINDOWPOS *pWndPos = (WINDOWPOS*)lParam;
  797. m_pWndShadow->OnOwnerWndMoved( (pWndPos->flags & SWP_NOSIZE) == 0 );
  798. }
  799. return OnWindowPosChanged(hWnd, uMsg, wParam, lParam);
  800. break;
  801. }
  802. case WM_WINDOWPOSCHANGING: {
  803. // show/hide shadow
  804. if (m_pWndShadow) {
  805. WINDOWPOS *pWndPos = (WINDOWPOS*)lParam;
  806. if ((pWndPos->flags & SWP_HIDEWINDOW) != 0) {
  807. m_pWndShadow->Show( FALSE );
  808. }
  809. // don't go behaind of shadow
  810. if (((pWndPos->flags & SWP_NOZORDER) == 0) && (pWndPos->hwndInsertAfter == m_pWndShadow->GetWnd())) {
  811. pWndPos->flags |= SWP_NOZORDER;
  812. }
  813. m_pWndShadow->OnOwnerWndMoved( (pWndPos->flags & SWP_NOSIZE) == 0 );
  814. }
  815. return OnWindowPosChanging(hWnd, uMsg, wParam, lParam);
  816. break;
  817. }
  818. case WM_SYSCOLORCHANGE: {
  819. UpdateUIFScheme();
  820. OnSysColorChange();
  821. break;
  822. }
  823. case WM_SHOWWINDOW: {
  824. // show/hide shadow
  825. if (m_pWndShadow && m_fShadowEnabled) {
  826. m_pWndShadow->Show( (BOOL)wParam );
  827. }
  828. return OnShowWindow( hWnd, uMsg, wParam, lParam );
  829. break;
  830. }
  831. case WM_SETTINGCHANGE: {
  832. UpdateUIFSys();
  833. UpdateUIFScheme();
  834. return OnSettingChange( hWnd, uMsg, wParam, lParam );
  835. break;
  836. }
  837. case WM_DISPLAYCHANGE: {
  838. UpdateUIFSys();
  839. UpdateUIFScheme();
  840. return OnDisplayChange( hWnd, uMsg, wParam, lParam );
  841. break;
  842. }
  843. case WM_ERASEBKGND: {
  844. return OnEraseBkGnd(hWnd, uMsg, wParam, lParam);
  845. }
  846. case WM_ENDSESSION: {
  847. OnEndSession(hWnd, wParam, lParam);
  848. return 0;
  849. }
  850. case WM_THEMECHANGED: {
  851. OnThemeChanged(hWnd, wParam, lParam);
  852. return 0;
  853. }
  854. case WM_GETOBJECT: {
  855. return OnGetObject( hWnd, uMsg, wParam, lParam );
  856. break;
  857. }
  858. default: {
  859. if (uMsg >= WM_USER) {
  860. Assert( GetThis(hWnd) != NULL );
  861. GetThis(hWnd)->OnUser(hWnd, uMsg, wParam, lParam);
  862. break;
  863. }
  864. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  865. }
  866. } /* of switch */
  867. return 0;
  868. }
  869. /* W I N D O W P R O C E D U R E */
  870. /*------------------------------------------------------------------------------
  871. Window procedure of the class
  872. ------------------------------------------------------------------------------*/
  873. LRESULT CALLBACK CUIFWindow::WindowProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  874. {
  875. LRESULT lResult = 0;
  876. CUIFWindow *pUIWindow = NULL;
  877. // preprcess
  878. switch (uMsg) {
  879. #ifdef UNDER_CE
  880. case WM_CREATE: {
  881. CREATESTRUCT *pCreateStruct = (CREATESTRUCT *)lParam;
  882. pUIWindow = (CUIFWindow *)pCreateStruct->lpCreateParams;
  883. SetThis( hWnd, pUIWindow );
  884. pUIWindow->m_hWnd = hWnd;
  885. break;
  886. }
  887. #else /* !UNDER_CE */
  888. case WM_NCCREATE: {
  889. CREATESTRUCT *pCreateStruct = (CREATESTRUCT *)lParam;
  890. pUIWindow = (CUIFWindow *)pCreateStruct->lpCreateParams;
  891. SetThis( hWnd, pUIWindow );
  892. pUIWindow->m_hWnd = hWnd;
  893. break;
  894. }
  895. case WM_GETMINMAXINFO: {
  896. pUIWindow = GetThis( hWnd );
  897. if (pUIWindow == NULL) {
  898. // we may be able to ignore this message since the default position
  899. // has been set in initializing WWindow object.
  900. return DefWindowProc( hWnd, uMsg, wParam, lParam );
  901. }
  902. break;
  903. }
  904. #endif /* !UNDER_CE */
  905. default: {
  906. pUIWindow = GetThis( hWnd );
  907. break;
  908. }
  909. }
  910. // call window procedure
  911. Assert( pUIWindow != NULL );
  912. if (pUIWindow != NULL) {
  913. Assert(pUIWindow->FInitialized());
  914. switch (uMsg) {
  915. #ifdef UNDER_CE
  916. case WM_DESTROY: {
  917. #else /* !UNDER_CE */
  918. case WM_NCDESTROY: {
  919. #endif /* !UNDER_CE */
  920. pUIWindow->m_hWnd = NULL;
  921. SetThis( hWnd, NULL );
  922. break;
  923. }
  924. }
  925. lResult = pUIWindow->WindowProc( hWnd, uMsg, wParam, lParam );
  926. }
  927. return lResult;
  928. }
  929. /* Adjust Window Pos
  930. /*------------------------------------------------------------------------------
  931. ------------------------------------------------------------------------------*/
  932. typedef HMONITOR (*MONITORFROMRECT)(LPRECT prc, DWORD dwFlags);
  933. typedef BOOL (*GETMONITORINFO)(HMONITOR hMonitor, LPMONITORINFO lpmi);
  934. static MONITORFROMRECT g_pfnMonitorFromRect = NULL;
  935. static GETMONITORINFO g_pfnGetMonitorInfo = NULL;
  936. /* InitMoniterFunc
  937. /*------------------------------------------------------------------------------
  938. ------------------------------------------------------------------------------*/
  939. BOOL CUIFWindow::InitMonitorFunc()
  940. {
  941. HMODULE hModUser32;
  942. if (g_pfnMonitorFromRect && g_pfnGetMonitorInfo)
  943. return TRUE;
  944. hModUser32 = CUIGetSystemModuleHandle(TEXT("user32.dll"));
  945. if (hModUser32)
  946. {
  947. g_pfnMonitorFromRect = (MONITORFROMRECT)GetProcAddress(hModUser32, "MonitorFromRect");
  948. g_pfnGetMonitorInfo = (GETMONITORINFO)GetProcAddress(hModUser32, "GetMonitorInfoA");
  949. }
  950. if (g_pfnMonitorFromRect && g_pfnGetMonitorInfo)
  951. return TRUE;
  952. return FALSE;
  953. }
  954. /* GetWorkArea
  955. /*------------------------------------------------------------------------------
  956. ------------------------------------------------------------------------------*/
  957. BOOL CUIFWindow::GetWorkArea(RECT *prcIn, RECT *prcOut)
  958. {
  959. BOOL bRet = FALSE;
  960. HMONITOR hMon;
  961. MONITORINFO mi;
  962. if (!FHasStyle( UIWINDOW_HABITATINWORKAREA | UIWINDOW_HABITATINSCREEN ))
  963. return FALSE;
  964. if (!InitMonitorFunc())
  965. goto TrySPI;
  966. hMon = g_pfnMonitorFromRect(prcIn, MONITOR_DEFAULTTONEAREST);
  967. if (!hMon)
  968. goto TrySPI;
  969. mi.cbSize = sizeof(mi);
  970. if (g_pfnGetMonitorInfo(hMon, &mi))
  971. {
  972. if (FHasStyle( UIWINDOW_HABITATINWORKAREA )) {
  973. *prcOut = mi.rcWork;
  974. return TRUE;
  975. }
  976. else if (FHasStyle( UIWINDOW_HABITATINSCREEN )) {
  977. *prcOut = mi.rcMonitor;
  978. return TRUE;
  979. }
  980. return FALSE;
  981. }
  982. TrySPI:
  983. if (FHasStyle( UIWINDOW_HABITATINWORKAREA )) {
  984. return SystemParametersInfo(SPI_GETWORKAREA, 0, prcOut, FALSE);
  985. }
  986. else if (FHasStyle( UIWINDOW_HABITATINSCREEN )) {
  987. prcOut->top = 0;
  988. prcOut->left = 0;
  989. prcOut->right = GetSystemMetrics(SM_CXSCREEN);
  990. prcOut->bottom = GetSystemMetrics(SM_CYSCREEN);
  991. return TRUE;
  992. }
  993. return FALSE;
  994. }
  995. /* Adjust Window Position
  996. /*------------------------------------------------------------------------------
  997. ------------------------------------------------------------------------------*/
  998. void CUIFWindow::AdjustWindowPosition()
  999. {
  1000. RECT rc;
  1001. RECT rcWnd;
  1002. rcWnd.left = _xWnd;
  1003. rcWnd.top = _yWnd;
  1004. rcWnd.right = _xWnd + _nWidth;
  1005. rcWnd.bottom = _yWnd + _nHeight;
  1006. if (!GetWorkArea(&rcWnd, &rc))
  1007. return;
  1008. if (_xWnd < rc.left)
  1009. _xWnd = rc.left;
  1010. if (_yWnd < rc.top)
  1011. _yWnd = rc.top;
  1012. if (_xWnd + _nWidth >= rc.right)
  1013. _xWnd = rc.right - _nWidth;
  1014. if (_yWnd + _nHeight >= rc.bottom)
  1015. _yWnd = rc.bottom - _nHeight;
  1016. }