⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.cpp

📁 这是一个mp3的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________

   FreeAmp - The Free MP3 Player

   Copyright (C) 1999 EMusic

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

   $Id: Window.cpp,v 1.23 2000/01/19 22:20:30 ijr Exp $
____________________________________________________________________________*/ 

// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disabled.
#ifdef WIN32
#pragma warning(disable:4786) 
#endif

#include <stdio.h>
#include <algorithm>
#include "Window.h"
#include "Theme.h"
#include "debug.h"

#define DB Debug_v("%s:%d\n", __FILE__, __LINE__);

const int iDesktopSnapAmount = 10;

Window::Window(Theme *pTheme, string &oName)
{
    m_oName = oName;
    m_bExit = false;
    m_pTheme = pTheme;
    m_bWindowMove = false;
    m_bLButtonDown = false;
    m_bStayOnTop = false;
    m_bLiveInToolbar = false;

    m_pCanvas = NULL;
    m_pMouseInControl = NULL;
    m_pCaptureControl = NULL;
    m_pMouseDownControl = NULL;
    m_bIsVulcanMindMeldHost = false;
    m_bMindMeldInProgress = false;
}

Window::~Window(void)
{
    if (!m_bIsVulcanMindMeldHost)
    {
       delete m_pCanvas;
       ClearControls();
    }   
}

void Window::VulcanMindMeldHost(bool bHost)
{
    m_bIsVulcanMindMeldHost = bHost;
    
    if (bHost)
    {
       delete m_pCanvas;
       m_pCanvas = NULL;
    }
}

Error Window::VulcanMindMeld(Window *pOther)
{
    vector<Control *>::iterator i;
    ControlMapIterator          j;
    string                      oName;
    
    m_oName = pOther->m_oName;
    m_pTheme = pOther->m_pTheme;

    m_bWindowMove = pOther->m_bWindowMove;
    m_bStayOnTop = pOther->m_bLiveInToolbar;

    m_pMouseInControl = NULL;
    m_pCaptureControl = NULL;
    m_pMouseDownControl = NULL;

    m_oControls.clear();
    for(i = pOther->m_oControls.begin(); i != pOther->m_oControls.end(); i++)
        m_oControls.push_back(*i);

    m_oControlMap.clear();
    for(j = pOther->m_oControlMap.begin(); j != pOther->m_oControlMap.end(); j++)
        m_oControlMap.insert(pair<string, Control *>((*j).first, (*j).second));
        
    m_pCanvas = pOther->m_pCanvas;
    Init();   
   
    return kError_NoErr;
}

void Window::Init(void)
{
    vector<Control *>::iterator i;

    m_pCanvas->Init();

    for(i = m_oControls.begin(); i != m_oControls.end(); i++)
    {
        (*i)->SetParent(this);
        (*i)->Init();
    }    
        
    m_pTheme->InitControls();    
}

void Window::AddControl(Control *pControl)
{
    string oName;

    if (m_bMindMeldInProgress)
       return;

    pControl->GetName(oName);
    m_oControlMap.insert(pair<string, Control *>(oName, pControl));
    m_oControls.push_back(pControl);
}

void Window::ClearControls(void)
{
    if (m_bMindMeldInProgress)
       return;
       
    while(m_oControls.size() > 0)
    {
        delete m_oControls[0];
        m_oControls.erase(m_oControls.begin());
    }
    m_oControlMap.clear();
}

Canvas *Window::GetCanvas(void)
{
    return m_pCanvas;
}

void Window::GetName(string &oName)
{
    oName = m_oName;
}

Error Window::ControlEnable(const string &oTarget, bool bSet, bool &bEnable)
{
    ControlMapIterator i;
    int                j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
         (*i).second->Enable(bSet, bEnable);
    }        

    return (j == 0) ? kError_InvalidParam : kError_NoErr;
}

Error Window::ControlShow(const string &oTarget, bool bSet, bool &bShow)
{
    Pos                 oPos;
    Rect                oRect;
    Error               eRet;
    Control            *pControl;
    ControlMapIterator  i;
    int                 j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
        pControl = (*i).second;
        
        eRet = pControl->Show(bSet, bShow);

        GetMousePos(oPos);
        GetWindowPosition(oRect);
        oPos.x -= oRect.x1;
        oPos.y -= oRect.y1;
        if (bSet && bShow && pControl->PosInControl(oPos))
    	    pControl->AcceptTransition(CT_MouseEnter);
    }        

    return (j == 0) ? kError_InvalidParam : kError_NoErr;
}

Error Window::ControlIntValue(const string &oTarget, bool bSet, int &iValue)
{
    ControlMapIterator  i;
    int                 j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
         (*i).second->IntValue(bSet, iValue);
    }        

    return (j == 0) ? kError_InvalidParam : kError_NoErr;
}

Error Window::ControlStringValue(const string &oTarget, bool bSet, string &oValue)
{
    ControlMapIterator  i;
    int                 j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
         (*i).second->StringValue(bSet, oValue);
    }        

    return (j == 0) ? kError_InvalidParam : kError_NoErr;
}

Error Window::ControlGetDesc(const string &oTarget, string &oDesc)
{
    ControlMapIterator  i;
    int                 j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
         (*i).second->GetDesc(oDesc);
         return kError_NoErr;
    }        

    return kError_InvalidParam;
}

Error Window::ControlGetTip(const string &oTarget, string &oTip)
{
    ControlMapIterator  i;
    int                 j;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    for(i = m_oControlMap.find(oTarget), j = 0; 
        j != (int)m_oControlMap.count(oTarget); j++, i++) 
    {
         (*i).second->GetTip(oTip);
         return kError_NoErr;
    }        

    return kError_InvalidParam;
}

Error Window::SendControlMessage(Control *pControl, 
                                 ControlMessageEnum eMesg)
{
    string oControlName;

    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
   
    pControl->GetName(oControlName);

    return m_pTheme->HandleControlMessage(oControlName, eMesg);
}

bool Window::DoesControlExist(const string &oName)
{
    if (m_bMindMeldInProgress)
       return false;
       
    return m_oControlMap.find(oName) != m_oControlMap.end();
}

Control *Window::ControlFromPos(Pos &oPos)
{
    vector<Control *>::iterator i;
    bool                        bShown;

    if (m_bMindMeldInProgress)
       return NULL;

    for(i = m_oControls.begin(); i != m_oControls.end(); i++)
    {
        (*i)->Show(false, bShown);
        if ((*i)->PosInControl(oPos) && bShown) 
            return (*i);
    }        

    return NULL;
}

Error Window::StartMouseCapture(Control *pControl)
{
    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    m_pCaptureControl = pControl;
    return CaptureMouse(true);
}

Error Window::EndMouseCapture(void)
{
    if (m_bMindMeldInProgress)
       return kError_InvalidParam;
       
    m_pCaptureControl = NULL;
    return CaptureMouse(false);
}

void Window::HandleMouseMove(Pos &oScreenPos)
{
    Control *pControl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -