📄 ew_object.cpp
字号:
/*--------------------------------------------------------------------------
EW_Object.cpp - 窗口元素类的实现文件
本程序是FishGUI软件的一部分
版权所有 (C) 2003,2004 王咏武
http://www.contextfree.net/wangyw/
----------------------------------------------------------------------------
作者对 FishGUI 软件及其所有源代码授权如下:
允许任何个人、组织、机构、企业无偿获得、修改、使用、重新发布 FishGUI 软
件及其源代码,或按照有偿或者无偿的方式发行基于 FishGUI 源代码的全部或部
分内容开发的软件产品,——但行使以上权利时,须遵守以下约定:
1、重新发布 FishGUI 软件及其源代码时,不得隐去软件及其源代码中原有的版
权信息和开发者标识。
2、发行基于 FishGUI 源代码的全部或部分内容开发的软件产品时,必须在产品
的显著位置标明以下字样:
【本产品的一部分功能是基于王咏武在 FishGUI 软件中的工作完成的】
3、在正式出版物中引用 FishGUI 的文档、源代码或注释内容的,应注明软件的
原作者为王咏武。
--------------------------------------------------------------------------*/
/*! \addtogroup Framework
* @{
*/
/*! \file
* \brief 窗口元素类的实现文件
*
*/
/*! @} */
#include "../OSAdaptor/EW_OSAdaptor.h"
#include "EW_Container.h"
// message map of base object
//##ModelId=3F5C4D4103CC
const EW_MSGMAP EW_Object::m_MsgMap = { NULL, & EW_Object::m_MsgEntries[0] };
//##ModelId=3F5C4D41037C
const EW_MSGMAP_ENTRY EW_Object::m_MsgEntries[] =
{
ON_DRAW (EW_Object::OnDraw)
ON_FOCUS (EW_Object::OnFocus)
{ false, 0, 0, (EW_PMSG_vv)NULL }
};
EW_Object::~EW_Object()
{
EW_GetTimerManager()->KillObjectTimer(this);
}
//##ModelId=3F5C4D42001F
const EW_MSGMAP * EW_Object::GetMessageMap() const
{
return & EW_Object::m_MsgMap;
}
void EW_Object::DrawBorder(EW_OSAdaptor * pAdaptor)
{
EW_Rect Rect;
if (m_wStyle & GS_TRANSPARENT)
return;
pAdaptor->BeginDraw(m_Rect);
EW_Point p[3];
switch(m_wStyle & FS_MASK)
{
case FS_RAISED:
Rect = m_Rect;
Rect -= 2;
pAdaptor->FillRect(Rect, m_Background, m_Background);
p[0].x = p[1].x = m_Rect.wLeft;
p[0].y = m_Rect.wBottom - 1;
p[1].y = p[2].y = m_Rect.wTop;
p[2].x = m_Rect.wRight - 1;
pAdaptor->DrawPolyLine(3, p, COLOR_GRAY);
p[0].x = p[1].x = m_Rect.wLeft + 1;
p[0].y = m_Rect.wBottom - 2;
p[1].y = p[2].y = m_Rect.wTop + 1;
p[2].x = m_Rect.wRight - 2;
pAdaptor->DrawPolyLine(3, p, COLOR_WHITE);
p[0].x = p[1].x = m_Rect.wRight - 1;
p[0].y = m_Rect.wTop + 1;
p[1].y = p[2].y = m_Rect.wBottom - 1;
p[2].x = m_Rect.wLeft + 1;
pAdaptor->DrawPolyLine(3, p, COLOR_DARKGRAY);
p[0].x = p[1].x = m_Rect.wRight;
p[0].y = m_Rect.wTop;
p[1].y = p[2].y = m_Rect.wBottom;
p[2].x = m_Rect.wLeft;
pAdaptor->DrawPolyLine(3, p, COLOR_BLACK);
break;
case FS_RECESSED:
Rect = m_Rect;
Rect -= 2;
pAdaptor->FillRect(Rect, m_Background, m_Background);
p[0].x = p[1].x = m_Rect.wRight - 1;
p[0].y = m_Rect.wTop + 1;
p[1].y = p[2].y = m_Rect.wBottom - 1;
p[2].x = m_Rect.wLeft + 1;
pAdaptor->DrawPolyLine(3, p, COLOR_GRAY);
p[0].x = p[1].x = m_Rect.wRight;
p[0].y = m_Rect.wTop;
p[1].y = p[2].y = m_Rect.wBottom;
p[2].x = m_Rect.wLeft;
pAdaptor->DrawPolyLine(3, p, COLOR_WHITE);
p[0].x = p[1].x = m_Rect.wLeft;
p[0].y = m_Rect.wBottom - 1;
p[1].y = p[2].y = m_Rect.wTop;
p[2].x = m_Rect.wRight - 1;
pAdaptor->DrawPolyLine(3, p, COLOR_DARKGRAY);
p[0].x = p[1].x = m_Rect.wLeft + 1;
p[0].y = m_Rect.wBottom - 2;
p[1].y = p[2].y = m_Rect.wTop + 1;
p[2].x = m_Rect.wRight - 2;
pAdaptor->DrawPolyLine(3, p, COLOR_BLACK);
break;
case FS_THIN:
pAdaptor->FillRect(m_Rect, COLOR_BLACK, m_Background);
break;
case FS_NONE:
pAdaptor->FillRect(m_Rect, m_Background, m_Background);
break;
default:
break;
}
pAdaptor->EndDraw();
}
void EW_Object::GetClientRect(EW_Rect & rect) const
{
// 根据边框风格除去不同的边框大小
switch (m_wStyle & FS_MASK)
{
case FS_RAISED:
case FS_RECESSED:
rect = m_Rect;
rect -= 2;
break;
case FS_THIN:
rect = m_Rect;
rect -= 1;
break;
case FS_NONE:
rect = m_Rect;
break;
default:
rect.Set(0, 0, 0, 0);
break;
}
}
bool EW_Object::Message(EW_Message * pMsg)
{
// 通过虚函数得到该类的消息映射表指针
const EW_MSGMAP * pMsgMap = GetMessageMap();
// 从本类向基类循环查找消息映射表,直到找到该消息,或到达最后的基类
for ( ; pMsgMap; pMsgMap = pMsgMap->m_pBaseMsgMap)
{
// 在一个消息映射表中查找该消息
const EW_MSGMAP_ENTRY * lpEntry = pMsgMap->FindMsgCallback(pMsg->wType, pMsg->wData, pMsg->wID);
if (lpEntry->m_Callback)
{
// 根据消息类型分发消息
switch (pMsg->wType)
{
case EW_MSG_DRAW:
{
EW_OSAdaptor * pAdaptor = EW_GetAdaptor();
if (! pAdaptor)
return false;
// 把消息处理函数的指针强制转换成正确的类型
EW_PMSG_vd pfn = (EW_PMSG_vd)lpEntry->m_Callback;
// 调用消息处理函数
(this->*pfn)(pAdaptor);
}
return true;
case EW_MSG_KEY:
case EW_MSG_MOUSE:
{
EW_PMSG_bm pfn = (EW_PMSG_bm)lpEntry->m_Callback;
return (this->*pfn)(pMsg);
}
case EW_MSG_FOCUS:
case EW_MSG_DRAW_REQUEST:
{
EW_PMSG_vm pfn = (EW_PMSG_vm)lpEntry->m_Callback;
(this->*pfn)(pMsg);
}
return true;
case EW_MSG_TIMER:
case EW_MSG_UPDATE_VIEW:
(this->*(lpEntry->m_Callback))();
return true;
case EW_MSG_NOTIFY:
if (lpEntry->m_wID)
(this->*(lpEntry->m_Callback))();
else
{
EW_PMSG_vm pfn = (EW_PMSG_vm)lpEntry->m_Callback;
(this->*pfn)(pMsg);
}
return true;
default:
return false;;
}
}
}
return false;
}
bool EW_Object::StartTimer(const BYTE timerID, const WORD dwInterval)
{
return EW_GetTimerManager()->StartTimer(this, timerID, dwInterval);
}
//##ModelId=3F5DAA140320
/*! \brief 删除当前窗口元素的定时器
*
* \param timerID 定时器的唯一标识(对于当前窗口元素唯一)
* \return 定时器是否成功删除
* true 成功
* false 失败
*/
bool EW_Object::KillTimer(const BYTE timerID)
{
return EW_GetTimerManager()->KillTimer(this, timerID);
}
void EW_Object::NotifyParent(WORD wNotification)
{
if (m_pParent)
{
EW_Message Msg(EW_MSG_NOTIFY, wNotification, ID());
m_pParent->Message(& Msg);
}
}
void EW_Object::RequestDraw()
{
if (m_pParent)
{
EW_Message Msg(EW_MSG_DRAW_REQUEST);
Msg.lData = (DWORD)this;
m_pParent->Message(& Msg);
}
}
//##ModelId=3F6EAC8F0128
void EW_Object::OnFocus(EW_Message * pMsg)
{
if (pMsg->wData == FFS_LOSE)
ResetFocus();
else
SetFocus();
RequestDraw();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -