CopperWindow.cpp

Go to the documentation of this file.
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;    //Since it doesn't actually matter
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  * (c) 2006 Charles Lohr
00143  * All rights reserved.
00144  * 
00145  * Permission is hereby granted, free of charge, to any person obtaining a
00146  * copy of this software and associated documentation files (the
00147  * "Software"), to deal in the Software without restriction, including
00148  * without limitation the rights to use, copy, modify, merge, publish,
00149  * distribute, and/or sell copies of the Software, and to permit persons to
00150  * whom the Software is furnished to do so, provided that the above
00151  * copyright notice(s) and this permission notice appear in all copies of
00152  * the Software and that both the above copyright notice(s) and this
00153  * permission notice appear in supporting documentation.
00154  * 
00155  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00156  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00157  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
00158  * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
00159  * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
00160  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00161  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
00162  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00163  * PERFORMANCE OF THIS SOFTWARE.
00164  */
00165 

Hosted by SourceForge.net Logo