00001 #include "CopperWindow.h"
00002 #include "MercuryTheme.h"
00003
00004 std::map< MString, NewCopperFunction > *ToMakeWindows;
00005
00006 CopperWindow::~CopperWindow()
00007 {
00008 for ( unsigned i = 0; i < m_vWindows.size(); i++ )
00009 SAFE_DELETE( m_vWindows[i] );
00010 }
00011
00012 void CopperWindow::Init( CopperWindow * pParent, const MString & sName )
00013 {
00014 MercuryObject::Init();
00015
00016 m_pParent = pParent;
00017 SetName( sName );
00018 m_iCurrentFocus = 0;
00019 m_iLastMouseWindow = -1;
00020
00021 m_pBrdOverOn.Message = THEME.GetMetricS( sName, "MouseOverOnMessage" );
00022 m_pBrdOverOn.Data = THEME.GetMetricS( sName, "MouseOverOnData" );
00023
00024 m_pBrdOverOff.Message = THEME.GetMetricS( sName, "MouseOverOffMessage" );
00025 m_pBrdOverOff.Data = THEME.GetMetricS( sName, "MouseOverOffData" );
00026
00027 m_pBrdUpInTarget.Message = THEME.GetMetricS( sName, "MouseUpInTargetMessage" );
00028 m_pBrdUpInTarget.Data = THEME.GetMetricS( sName, "MouseUpInTargetData" );
00029
00030 m_pBrdUpOutTarget.Message = THEME.GetMetricS( sName, "MouseUpOutTargetMessage" );
00031 m_pBrdUpOutTarget.Data = THEME.GetMetricS( sName, "MouseUpOutTargetData" );
00032
00033 m_pBrdDown.Message = THEME.GetMetricS( sName, "MouseDownMessage" );
00034 m_pBrdDown.Data = THEME.GetMetricS( sName, "MouseDownData" );
00035
00036 Tweening.AddCommand( THEME.GetMetricS( sName, "OnCommand" ) );
00037 }
00038
00039 void CopperWindow::KeyPress( const CopperKeypress & pKeypress )
00040 {
00041 if ( m_vWindows.size() > 0 )
00042 m_vWindows[m_iCurrentFocus]->KeyPress( pKeypress );
00043 }
00044
00045 bool CopperWindow::MouseEvent( const CopperMouseEvent & pMouseEvent )
00046 {
00047 if ( pMouseEvent.pType == CopperMouseEvent::MOUSE_IN )
00048 m_pBrdOverOn.Broadcast();
00049
00050 if ( pMouseEvent.pType == CopperMouseEvent::MOUSE_OUT )
00051 m_pBrdOverOff.Broadcast();
00052
00053 if ( pMouseEvent.pType == CopperMouseEvent::MOUSE_DOWN )
00054 m_pBrdDown.Broadcast();
00055
00056 if ( pMouseEvent.pType == CopperMouseEvent::MOUSE_UP )
00057 {
00058 if ( IsMouseEventOnTarget( pMouseEvent ) )
00059 m_pBrdUpInTarget.Broadcast();
00060 else
00061 m_pBrdUpOutTarget.Broadcast();
00062
00063 for ( unsigned i = 0; i < m_vWindows.size(); i++ )
00064 {
00065 CopperMouseEvent pNewMouse = pMouseEvent;
00066 pNewMouse.x -= (int)m_vWindows[i]->GetX();
00067 pNewMouse.y -= (int)m_vWindows[i]->GetY();
00068 m_vWindows[i]->MouseEvent( pNewMouse );
00069 }
00070 return true;
00071 }
00072
00073 for ( unsigned i = 0; i < m_vWindows.size(); i++ )
00074 {
00075 CopperMouseEvent pNewMouse = pMouseEvent;
00076 pNewMouse.x -= (int)m_vWindows[i]->GetX();
00077 pNewMouse.y -= (int)m_vWindows[i]->GetY();
00078 if ( m_vWindows[i]->IsMouseEventOnTarget( pNewMouse ) )
00079 {
00080 m_vWindows[i]->MouseEvent( pNewMouse );
00081
00082 if ( (unsigned)m_iLastMouseWindow != i )
00083 {
00084 pNewMouse.pType = CopperMouseEvent::MOUSE_OUT;
00085 if ( m_iLastMouseWindow >=0 && (unsigned)m_iLastMouseWindow < m_vWindows.size() )
00086 m_vWindows[m_iLastMouseWindow]->MouseEvent( pNewMouse );
00087 pNewMouse.pType = CopperMouseEvent::MOUSE_IN;
00088 m_vWindows[i]->MouseEvent( pNewMouse );
00089 m_iLastMouseWindow = i;
00090 }
00091 return true;
00092 }
00093 }
00094
00095 if ( m_iLastMouseWindow >= 0 && (unsigned)m_iLastMouseWindow<m_vWindows.size() )
00096 {
00097 CopperMouseEvent pNewMouse = pMouseEvent;
00098 pNewMouse.x -= (int)m_vWindows[m_iLastMouseWindow]->GetX();
00099 pNewMouse.y -= (int)m_vWindows[m_iLastMouseWindow]->GetY();
00100 pNewMouse.pType = CopperMouseEvent::MOUSE_OUT;
00101 m_vWindows[m_iLastMouseWindow]->MouseEvent( pNewMouse );
00102 m_iLastMouseWindow = -1;
00103 }
00104
00105 return false;
00106 }
00107
00108 bool CopperWindow::IsMouseEventOnTarget( const CopperMouseEvent & pMouseEvent )
00109 {
00110 return ( pMouseEvent.x >= 0 && pMouseEvent.y >= 0 && pMouseEvent.x < m_fWidth && pMouseEvent.y < m_fHeight );
00111 }
00112
00113 MString CopperWindow::GetFocus()
00114 {
00115 return m_vWindows[m_iCurrentFocus]->GetName();
00116 }
00117
00118 void CopperWindow::SetFocus( const MString & sFocus )
00119 {
00120 for ( unsigned i = 0; i < m_vWindows.size(); i++ )
00121 if ( m_vWindows[i]->GetName() == sFocus )
00122 {
00123 m_iCurrentFocus = i;
00124 return;
00125 }
00126 }
00127
00128 CopperWindow * GetCopperByClass( const MString & sClassName, const MString & sWindowName ) {
00129 if ( ToMakeWindows->find( sClassName ) == ToMakeWindows->end() )
00130 return NULL;
00131 return (*ToMakeWindows)[sClassName](sWindowName);
00132 }
00133
00134 void RegisterCopperWindow( const MString& sClassName, NewCopperFunction pfn )
00135 {
00136 if ( ToMakeWindows == NULL )
00137 ToMakeWindows = new std::map< MString, NewCopperFunction >;
00138 (*ToMakeWindows)[sClassName] = pfn;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165