📄 window.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Copyright (C) 1999-2000 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.52 2000/11/08 16:27:02 robert 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_bIsDockWindow = false;
m_pCanvas = NULL;
m_pMouseInControl = NULL;
m_pCaptureControl = NULL;
m_pMouseDownControl = NULL;
m_bIsVulcanMindMeldHost = false;
m_bMindMeldInProgress = false;
m_bNoOutsideMessages = false;
m_pUsageMutex = new Mutex();
m_pUsageSem = new Semaphore();
m_iUsageCount = 0;
}
Window::~Window(void)
{
vector<Panel *>::iterator i;
if (!m_bIsVulcanMindMeldHost)
{
delete m_pCanvas;
ClearControls();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
delete (Panel *)*i;
}
delete m_pUsageMutex;
delete m_pUsageSem;
}
void Window::IncUsageRef(void)
{
for(;;)
{
m_pUsageMutex->Acquire();
if (m_iUsageCount < 0)
{
m_pUsageMutex->Release();
m_pUsageSem->Wait();
}
else
break;
}
m_iUsageCount++;
m_pUsageMutex->Release();
}
void Window::DecUsageRef(void)
{
m_pUsageMutex->Acquire();
m_iUsageCount--;
m_pUsageSem->Signal();
m_pUsageMutex->Release();
}
void Window::LockUsageRef(void)
{
for(;;)
{
m_pUsageMutex->Acquire();
if (m_iUsageCount > 0)
{
m_pUsageMutex->Release();
ProcessWaitingMessages();
m_pUsageSem->Wait();
}
else
break;
}
m_iUsageCount = -1;
m_pUsageMutex->Release();
}
void Window::UnlockUsageRef(void)
{
m_pUsageMutex->Acquire();
m_iUsageCount = 0;
m_pUsageSem->Signal();
m_pUsageMutex->Release();
}
void Window::VulcanMindMeldHost(bool bHost)
{
m_bIsVulcanMindMeldHost = bHost;
if (bHost)
{
delete m_pCanvas;
m_pCanvas = NULL;
}
}
Error Window::VulcanMindMeld(Window *pOther)
{
vector<Panel *>::iterator k;
string oName;
LockUsageRef();
m_bNoOutsideMessages = true;
m_oName = pOther->m_oName;
m_pTheme = pOther->m_pTheme;
m_bWindowMove = pOther->m_bWindowMove;
m_bStayOnTop = pOther->m_bLiveInToolbar;
m_bIsDockWindow = pOther->m_bIsDockWindow;
m_oDockPos = pOther->m_oDockPos;
m_pMouseInControl = NULL;
m_pCaptureControl = NULL;
m_pMouseDownControl = NULL;
m_oPanels.clear();
for(k = pOther->m_oPanels.begin(); k != pOther->m_oPanels.end(); k++)
{
(*k)->SetParentWindow(this);
m_oPanels.push_back(*k);
}
m_pCanvas = pOther->m_pCanvas;
UnlockUsageRef();
Init();
m_bNoOutsideMessages = false;
return kError_NoErr;
}
void Window::Init(void)
{
vector<Panel *>::iterator i;
IncUsageRef();
m_pCanvas->InitBackgrounds(&m_oPanels);
m_pCanvas->Init();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->Init();
m_pTheme->InitControls();
DecUsageRef();
}
void Window::AddPanel(Panel *pPanel)
{
string oName;
IncUsageRef();
m_oPanels.push_back(pPanel);
DecUsageRef();
}
void Window::PanelStateChanged(void)
{
vector<Panel *>::iterator i;
Rect oRect, oWindowRect;
IncUsageRef();
m_pCanvas->InitBackgrounds(&m_oPanels);
m_pCanvas->Init();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ShowAllControls();
GetWindowPosition(oWindowRect);
m_pCanvas->GetBackgroundRect(oRect);
oWindowRect.x2 = oWindowRect.x1 + oRect.Width();
oWindowRect.y2 = oWindowRect.y1 + oRect.Height();
SetWindowPosition(oWindowRect);
m_pCanvas->Invalidate(oRect);
DecUsageRef();
}
void Window::ClearControls(void)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ClearControls();
DecUsageRef();
}
Canvas *Window::GetCanvas(void)
{
return m_pCanvas;
}
void Window::GetName(string &oName)
{
oName = m_oName;
}
void Window::SetDockPosition(Pos &oPos)
{
m_oDockPos = oPos;
m_bIsDockWindow = true;
}
Error Window::ControlEnable(const string &oTarget, bool bSet, bool &bEnable)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ControlEnable(oTarget, bSet, bEnable);
DecUsageRef();
return kError_NoErr;
}
Error Window::ControlShow(const string &oTarget, bool bSet, bool &bShow)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ControlShow(oTarget, bSet, bShow);
DecUsageRef();
return kError_NoErr;
}
Error Window::ControlIntValue(const string &oTarget, bool bSet, int &iValue)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ControlIntValue(oTarget, bSet, iValue);
DecUsageRef();
return kError_NoErr;
}
Error Window::ControlStringValue(const string &oTarget, bool bSet, string &oValue)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ControlStringValue(oTarget, bSet, oValue);
DecUsageRef();
return kError_NoErr;
}
Error Window::ControlGetDesc(const string &oTarget, string &oDesc)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ControlGetDesc(oTarget, oDesc);
DecUsageRef();
return kError_InvalidParam;
}
Error Window::ControlGetTip(const string &oTarget, string &oTip)
{
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
(*i)->ControlGetTip(oTarget, oTip);
DecUsageRef();
return kError_InvalidParam;
}
Error Window::SendControlMessage(Control *pControl,
ControlMessageEnum eMesg)
{
string oControlName;
Error eRet;
IncUsageRef();
pControl->GetName(oControlName);
eRet = m_pTheme->HandleControlMessage(oControlName, eMesg);
DecUsageRef();
return eRet;
}
bool Window::DoesControlExist(const string &oName)
{
bool bRet = false;
vector<Panel *>::iterator i;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end() && !bRet; i++)
{
bRet = (*i)->DoesControlExist(oName);
}
DecUsageRef();
return bRet;
}
Control *Window::ControlFromPos(Pos &oPos)
{
vector<Panel *>::iterator i;
Control *pControl = NULL;
IncUsageRef();
for(i = m_oPanels.begin(); i != m_oPanels.end() && !pControl; i++)
{
pControl = (*i)->ControlFromPos(oPos);
}
DecUsageRef();
return pControl;
}
void Window::GetControlToolTips(vector<pair<Rect, string> > &oList)
{
vector<Panel *>::iterator i;
IncUsageRef();
oList.clear();
for(i = m_oPanels.begin(); i != m_oPanels.end(); i++)
{
(*i)->GetControlToolTips(oList);
}
DecUsageRef();
}
Error Window::StartMouseCapture(Control *pControl)
{
IncUsageRef();
m_pCaptureControl = pControl;
DecUsageRef();
return CaptureMouse(true);
}
Error Window::EndMouseCapture(void)
{
IncUsageRef();
m_pCaptureControl = NULL;
DecUsageRef();
return CaptureMouse(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -