📄 rolloutctrl.h
字号:
}
//Return true, if all controls was deleted
void RemoveAllRollouts()
{
m_RolloutCtrls.RemoveAll();
xMax = 0;
}
/*
//Return true if set
bool SetRolloutDefButton(HWND hRolloutCtrl,DWORD dwDefBtn)
{
// ATLASSERT(::IsWindow(hRolloutCtrl));
const int idx = FindByHandle(hRolloutCtrl);
if (idx == -1) return false;
//m_RolloutCtrls[idx]->dwDefButton = dwDefBtn;
return true;
}
//Return 0 if control not found
DWORD GetRolloutDefButton(HWND hRolloutCtrl) const
{
// ATLASSERT(::IsWindow(hRolloutCtrl));
const int idx = FindByHandle(hRolloutCtrl);
if (idx == -1) return 0;
return m_RolloutCtrls[idx]->dwDefButton;
}
*/
int GetRolloutCount() const
{
return m_RolloutCtrls.GetSize();
}
HWND GetRollout(int nIndex)
{
return m_RolloutCtrls[nIndex]->hWnd;
}
void ExpandRollout(HWND hWndRollout, bool fExpand = true, bool fUpdate = true)
{
// ATLASSERT(::IsWindow(hWndRollout));
const int idx = FindByHandle(hWndRollout);
if (idx != -1){
ExpandRollout(idx,fExpand,fUpdate);
}
}
void ExpandRollout(int nIndex, bool fExpand = true, bool fUpdate = true)
{
m_RolloutCtrls[nIndex]->rloButton.SetChecked(fExpand);
if (fUpdate)
m_RolloutCtrls[nIndex]->rloButton.Invalidate();
}
void ExpandAllRollouts(bool fExpand = true,bool fUpdate = true)
{
for(int i = 0; i < m_RolloutCtrls.GetSize(); i++)
ExpandRollout(i, fExpand, fUpdate);
}
bool IsRolloutCollapsed(HWND hWndRollout) const
{
bool res = false;
const int idx = FindByHandle(hWndRollout);
if (idx != -1){
res = IsRolloutCollapsed(idx);
}
return res;
}
bool IsRolloutCollapsed(int nIndex) const
{
return m_RolloutCtrls[nIndex]->rloButton.IsChecked();
}
void EnableRollout(HWND hWndRollout, bool fEnable)
{
ATLASSERT(::IsWindow(hWndRollout));
const int idx = FindByHandle(hWndRollout);
if (idx != -1){
EnableRollout(idx, fEnable);
}
}
void EnableRollout(int nIndex, bool fEnable)
{
::EnableWindow(m_RolloutCtrls[nIndex]->hWnd, fEnable);
}
bool IsRolloutEnabled(HWND hWndRollout) const
{
bool res = false;
ATLASSERT(::IsWindow(hWndRollout));
const int idx = FindByHandle(hWndRollout);
if (idx != -1){
res = IsRolloutEnabled(idx) == TRUE;
}
return res;
}
bool IsRolloutEnabled(int nIndex) const
{
return ::IsWindowEnabled(m_RolloutCtrls[nIndex]->hWnd) == TRUE;
}
int GetWidth() const
{
return xMax;
}
}; //end of CRolloutHolder
// Messages
#define RCM_BASE (WM_USER + 2)
// Request expand from parent
// WPARAM unused
// LPARAM unused
#define RCM_ISEXPANDED (RCM_BASE + 0)
class ATL_NO_VTABLE CRolloutContainerT: public CRolloutHolder
{
protected:
CSize outer_margins,inner_margins;
int ySpacing;
int yOffset;
bool fTrans;
//bool fResize;
public:
// Construction
CRolloutContainerT()
{
outer_margins.SetSize(4,4);
inner_margins.SetSize(10,10);
ySpacing = 6;
yOffset = 0;
fTrans = false;
//fResize = false;
}
BOOL SubclassWindow(HWND)
{
return FALSE;
}
bool AddDialog(HWND hWnd,PCTSTR pszTitle,bool fExpand = false)
{
CWindow wnd = hWnd;
_DASSERT(wnd.IsWindow()){
return false;
}
CRect rc;
wnd.GetClientRect(&rc);
if (GetWidth() < rc.Width())
RecalcWidth(rc.Width());
else{
rc.right = GetWidth();
wnd.SetWindowPos(NULL,0,0,rc.right,rc.bottom,
SWP_NOZORDER|SWP_NOMOVE);
}
rc.right += inner_margins.cx*2;
rc.bottom += inner_margins.cy*2;
rc.OffsetRect(outer_margins.cx,outer_margins.cy);
const int idx = AddRollout(_GetThisWindow(),hWnd,pszTitle,rc);
if (idx != -1){
if (fExpand)
return Expand(idx);
else
return Collapse(idx);
}
return false;
}
bool RemoveDialog(HWND hWnd)
{
bool b = RemoveRollout(hWnd);
if (b){
_Invalidate();
RecalcButtons();
}
return b;
}
//Implementation in rolloutctrl.cpp
bool Expand(int idx);
//Implementation in rolloutctrl.cpp
bool Collapse(int idx);
//Implementation in rolloutctrl.cpp
//called by CScrollWindowImpl
void _DoPaint(CDCHandle dc);
protected:
virtual void Init() = 0;
//Implementation in rolloutctrl.cpp
int GetTopForButton(int idx) const;
//Implementation in rolloutctrl.cpp
virtual int RecalcButtons() const;
virtual BOOL _Invalidate() = 0;
virtual HWND _GetThisWindow() = 0;
//Implementation in rolloutctrl.cpp
int RecalcWidth(int iWidth) const;
int GetHeight() const
{
const int idx = GetRolloutCount()-1;
int top = GetTopForButton(idx);
Rollout& ro = *m_RolloutCtrls[idx];
CRect r;
//ro.rloButton.GetClientRect(&r);
top += 9;//r.Height();
if (IsRolloutCollapsed(idx)){
::GetClientRect(ro.hWnd,&r);
}
else{
r.SetRect(0,0,0,0);
}
r.bottom += inner_margins.cy*2;
top += r.Height();
//border 4*1
top += 4;
top += ySpacing;
return top;
}
}; //end of CRolloutContainerT
class CRolloutContainer:
public CScrollWindowImpl<CRolloutContainer>,
public CRolloutContainerT
{
typedef CRolloutContainer _thisClass;
typedef CScrollWindowImpl<CRolloutContainer> _baseClass;
public:
DECLARE_WND_CLASS_EX(_T("AWTL_RolloutView"),0,COLOR_BTNFACE);
BOOL PreTranslateMessage(PMSG pMsg)
{
return ::IsDialogMessage(m_hWnd, pMsg);
}
void DoPaint(CDCHandle dc)
{
_DoPaint(dc);
}
protected:
void Init(){}
BOOL _Invalidate()
{
return Invalidate();
}
HWND _GetThisWindow()
{
return m_hWnd;
}
int RecalcButtons() const
{
int top = CRolloutContainerT::RecalcButtons();
SIZE sz = {
GetWidth() + outer_margins.cx*2+inner_margins.cx*2,
top
};
const_cast<_thisClass*>(this)->SetScrollSize(sz,TRUE);
return top;
}
private:
// Message map and handlers
BEGIN_MSG_MAP(_thisClass)
CHAIN_MSG_MAP(_baseClass)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
COMMAND_CODE_HANDLER(BN_CLICKED, OnRolloutCtrlClicked)
END_MSG_MAP()
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
Init();
return 1;
}
LRESULT OnRolloutCtrlClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& bHandled)
{
const int idx = FindByBtnHandle(hWndCtl);
if (idx != -1){
if (!::SendMessage(m_RolloutCtrls[idx]->hWnd, RCM_ISEXPANDED, 0, 0)){
if (IsRolloutCollapsed(idx))
Expand(idx);
else
Collapse(idx);
}
}
return 1;
}
}; //end of CRolloutContainer
class C3DStudioRolloutContainer:
public CWindowImpl<C3DStudioRolloutContainer>,
public CRolloutContainerT
{
private:
typedef C3DStudioRolloutContainer _thisClass;
typedef CWindowImpl<C3DStudioRolloutContainer> _baseClass;
mutable int _height;
int prev,cur;
CPoint _ptOffset;
CPoint _ptStartDrag;
HBRUSH clrActiveCaption;
HCURSOR _hCursorHand;
#if (WINVER < 0x0500) && ((_WIN32_WINNT < 0x0400) || !defined(_WIN32_WINNT))
UINT m_uMsgMouseWheel;
#endif
public:
DECLARE_WND_CLASS_EX(_T("AWTL_Rollout3DStudioView"),0,COLOR_BTNFACE);
C3DStudioRolloutContainer()
{
_height = 0;
_ptOffset.SetPoint(0,0);
prev = 0;
cur = 0;
fTrans = true;
}
BOOL PreTranslateMessage(PMSG pMsg)
{
return ::IsDialogMessage(m_hWnd, pMsg);
}
protected:
RECT GetSliderRect() const
{
const int right = GetWidth()+outer_margins.cx*2+
inner_margins.cx*2+4;
CRect r;
GetClientRect(&r);
return CRect(right,2,right+6,r.Height()-2);
}
void InvalidateSlider()
{
CRect rc(GetSliderRect());
CRect r;
GetClientRect(&r);
rc.top = 0;
rc.bottom = r.Height();
InvalidateRect(&rc);
}
//Implementation in rolloutctrl.cpp
void Scroll(int newY);
//Implementation in rolloutctrl.cpp
void DoPaint(CDCHandle dc);
void Init()
{
clrActiveCaption = ::GetSysColorBrush(COLOR_ACTIVECAPTION);
#if WINVER >= 0x0500
_hCursorHand = ::LoadCursor(NULL, IDC_HAND);
#else
_hCursorHand = ::LoadCursor(NULL, IDC_SIZENS);
#endif
#if (WINVER < 0x0500) && ((_WIN32_WINNT < 0x0400) || !defined(_WIN32_WINNT))
m_uMsgMouseWheel = ::RegisterWindowMessage(MSH_MOUSEWHEEL);
#endif
}
BOOL _Invalidate()
{
return Invalidate();
}
HWND _GetThisWindow()
{
return m_hWnd;
}
int RecalcButtons() const
{
int top = CRolloutContainerT::RecalcButtons();
_height = top-yOffset;
/* SIZE sz = {
GetWidth() + outer_margins.cx*2+inner_margins.cx*2,
top
};
const_cast<_thisClass*>(this)->SetScrollSize(sz,TRUE);
*/
return top;
}
private:
// Message map and handlers
BEGIN_MSG_MAP(_thisClass)
//CHAIN_MSG_MAP(_baseClass)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
#if (WINVER < 0x0500) && ((_WIN32_WINNT < 0x0400) || !defined(_WIN32_WINNT))
MESSAGE_HANDLER(m_uMsgMouseWheel, OnMouseWheel)
#endif
MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
COMMAND_CODE_HANDLER(BN_CLICKED, OnRolloutCtrlClicked)
END_MSG_MAP()
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
Init();
return 1;
}
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
CPaintDC dc(m_hWnd);
// dc.SetViewportOrg(-_ptOffset.x, -_ptOffset.y);
DoPaint((HDC)dc);
return 1;
}
//Implementation in rolloutctrl.cpp
LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled);
//Implementation in rolloutctrl.cpp
LRESULT OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled);
LRESULT OnLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
CPoint p(lParam);
CRect r(GetSliderRect());
r.InflateRect(4,0);
if (r.PtInRect(p)){
SetCursor(_hCursorHand);
CRect rc;
GetClientRect(&rc);
if (_height >= rc.Height()){
SetCapture();
_ptStartDrag = p;
}
}
SetFocus();
return 1;
}
LRESULT OnLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if (GetCapture() == m_hWnd){
prev = _ptOffset.y;
cur = 0;
ReleaseCapture();
}
return 0;
}
//GET_WHEEL_DELTA_WPARAM
LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
#if (WINVER < 0x0500) && ((_WIN32_WINNT < 0x0400) || !defined(_WIN32_WINNT))
const int iDelta = (uMsg == WM_MOUSEWHEEL)?(short)HIWORD(wParam):wParam;
#else
const int iDelta = GET_WHEEL_DELTA_WPARAM(wParam);
#endif
Scroll(-iDelta/5);
prev = _ptOffset.y;
cur = 0;
return 1;
}
LRESULT OnRolloutCtrlClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& bHandled)
{
const int idx = FindByBtnHandle(hWndCtl);
if (idx != -1){
if (!::SendMessage(m_RolloutCtrls[idx]->hWnd, RCM_ISEXPANDED, 0, 0)){
if (IsRolloutCollapsed(idx))
Expand(idx);
else
Collapse(idx);
}
}
return 1;
}
}; //end of C3DStudioRolloutContainer
}; //end of AWTL namespace
#endif // !defined(__ROLLOUTCTRL__H)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -