Counter Strike : Global Offensive Source Code
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.

96 lines
1.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "mxBitmapButton.h"
  8. #include "hlfaceposer.h"
  9. mxBitmapButton::mxBitmapButton( mxWindow *parent, int x, int y, int w, int h, int id /*= 0*/, const char *bitmap /* = 0 */ )
  10. : mxWindow( parent, x, y, w, h, "" )
  11. {
  12. setId( id );
  13. m_bmImage.valid = false;
  14. SetImage( bitmap );
  15. HWND wnd = (HWND)getHandle();
  16. DWORD style = GetWindowLong( wnd, GWL_STYLE );
  17. style |= WS_CLIPSIBLINGS;
  18. SetWindowLong( wnd, GWL_STYLE, style );
  19. }
  20. mxBitmapButton::~mxBitmapButton( void )
  21. {
  22. DeleteImage();
  23. }
  24. void mxBitmapButton::redraw()
  25. {
  26. HWND wnd = (HWND)getHandle();
  27. if ( !wnd )
  28. return;
  29. if ( !m_bmImage.valid )
  30. return;
  31. RECT rc;
  32. GetClientRect( wnd, &rc );
  33. HDC dc = GetDC( wnd );
  34. DrawBitmapToDC( dc, 0, 0, w(), h(), m_bmImage );
  35. ReleaseDC( wnd, dc );
  36. ValidateRect( wnd, &rc );
  37. }
  38. int mxBitmapButton::handleEvent( mxEvent * event )
  39. {
  40. int iret = 0;
  41. switch (event->event)
  42. {
  43. case mxEvent::MouseUp:
  44. // Send message to parent
  45. HWND parent = (HWND)( getParent() ? getParent()->getHandle() : NULL );
  46. if ( parent )
  47. {
  48. LPARAM lp;
  49. WPARAM wp;
  50. wp = MAKEWPARAM( getId(), BN_CLICKED );
  51. lp = (long)getHandle();
  52. SendMessage( parent, WM_COMMAND, wp, lp );
  53. iret = 1;
  54. }
  55. break;
  56. }
  57. return iret;
  58. }
  59. void mxBitmapButton::SetImage( const char *bitmapname )
  60. {
  61. if ( m_bmImage.valid )
  62. {
  63. DeleteImage();
  64. }
  65. LoadBitmapFromFile( bitmapname, m_bmImage );
  66. }
  67. void mxBitmapButton::DeleteImage( void )
  68. {
  69. if ( m_bmImage.valid )
  70. {
  71. DeleteObject( m_bmImage.image );
  72. m_bmImage.valid = false;
  73. }
  74. }