foobar2000 SDK  2015-01-14
CDialogResizeHelper.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 bool CDialogResizeHelper::EvalRect(UINT id, CRect & out) const {
4  for(t_size walk = 0; walk < m_table.get_size(); ++walk) {
5  if (m_table[walk].id == id) {
6  CRect client; WIN32_OP_D( m_thisWnd.GetClientRect(client) );
7  return _EvalRect(walk, client.Size(), out);
8  }
9  }
10  return false;
11 }
12 
13 bool CDialogResizeHelper::_EvalRect(t_size index, CSize wndSize, CRect & out) const {
14  CRect rc;
15  const Param & e = m_table[index];
16  if (m_origRects.query(e.id, rc)) {
17  int delta_x = wndSize.cx - m_rcOrigClient.right,
18  delta_y = wndSize.cy - m_rcOrigClient.bottom;
19 
20  rc.left += pfc::rint32( e.snapLeft * delta_x );
21  rc.right += pfc::rint32( e.snapRight * delta_x );
22  rc.top += pfc::rint32(e.snapTop * delta_y );
23  rc.bottom += pfc::rint32(e.snapBottom * delta_y );
24 
25  out = rc;
26  return true;
27  }
28  return false;
29 }
30 
31 void CDialogResizeHelper::OnSize(UINT, CSize newSize)
32 {
33  if (m_thisWnd != NULL) {
34  HDWP hWinPosInfo = BeginDeferWindowPos( m_table.get_size() + (m_sizeGrip != NULL ? 1 : 0) );
35  for(t_size n = 0; n < m_table.get_size(); ++n) {
36  CRect rc;
37  if (_EvalRect(n, newSize, rc)) {
38  hWinPosInfo = DeferWindowPos(hWinPosInfo, m_thisWnd.GetDlgItem(m_table[n].id), 0, rc.left,rc.top,rc.Width(),rc.Height(),SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS);
39  }
40  }
41  if (m_sizeGrip != NULL)
42  {
43  RECT rc, rc_grip;
44  if (m_thisWnd.GetClientRect(&rc) && m_sizeGrip.GetWindowRect(&rc_grip)) {
45  DWORD flags = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOCOPYBITS;
46  if (IsZoomed(m_thisWnd)) flags |= SWP_HIDEWINDOW;
47  else flags |= SWP_SHOWWINDOW;
48  hWinPosInfo = DeferWindowPos(hWinPosInfo, m_sizeGrip, NULL, rc.right - (rc_grip.right - rc_grip.left), rc.bottom - (rc_grip.bottom - rc_grip.top), 0, 0, flags );
49  }
50  }
51  EndDeferWindowPos(hWinPosInfo);
52  //RedrawWindow(m_thisWnd, NULL, NULL, RDW_UPDATENOW | RDW_ALLCHILDREN);
53  }
54  SetMsgHandled(FALSE);
55 }
56 
57 void CDialogResizeHelper::OnGetMinMaxInfo(LPMINMAXINFO info) const {
58  CRect r;
59  const DWORD dwStyle = m_thisWnd.GetWindowLong(GWL_STYLE);
60  const DWORD dwExStyle = m_thisWnd.GetWindowLong(GWL_EXSTYLE);
61  if (max_x && max_y)
62  {
63  r.left = 0; r.right = max_x;
64  r.top = 0; r.bottom = max_y;
65  MapDialogRect(m_thisWnd,&r);
66  AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle);
67  info->ptMaxTrackSize.x = r.right - r.left;
68  info->ptMaxTrackSize.y = r.bottom - r.top;
69  }
70  if (min_x && min_y)
71  {
72  r.left = 0; r.right = min_x;
73  r.top = 0; r.bottom = min_y;
74  MapDialogRect(m_thisWnd,&r);
75  AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle);
76  info->ptMinTrackSize.x = r.right - r.left;
77  info->ptMinTrackSize.y = r.bottom - r.top;
78  }
79 }
80 
81 void CDialogResizeHelper::OnInitDialog(CWindow thisWnd) {
83  m_thisWnd = thisWnd;
84  m_thisWnd.GetClientRect(&m_rcOrigClient);
85  for(t_size n = 0; n < m_table.get_size(); n++) {
86  CRect rc;
87  const UINT id = m_table[n].id;
88  if (GetChildWindowRect(m_thisWnd,id,&rc)) {
89  m_origRects.set(id, rc);
90  }
91  }
92  AddSizeGrip();
93  SetMsgHandled(FALSE);
94 }
96  m_sizeGrip = NULL; m_thisWnd = NULL;
97  SetMsgHandled(FALSE);
98 }
99 
101 {
102  if (m_thisWnd != NULL && m_sizeGrip == NULL)
103  {
104  if (m_thisWnd.GetWindowLong(GWL_STYLE) & WS_POPUP) {
105  m_sizeGrip = CreateWindowEx(0, WC_SCROLLBAR, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SBS_SIZEGRIP | SBS_SIZEBOXBOTTOMRIGHTALIGN,
106  0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
107  m_thisWnd, (HMENU)0, NULL, NULL);
108  if (m_sizeGrip != NULL)
109  {
110  RECT rc, rc_grip;
111  if (m_thisWnd.GetClientRect(&rc) && m_sizeGrip.GetWindowRect(&rc_grip)) {
112  m_sizeGrip.SetWindowPos(NULL, rc.right - (rc_grip.right - rc_grip.left), rc.bottom - (rc_grip.bottom - rc_grip.top), 0, 0, SWP_NOZORDER | SWP_NOSIZE);
113  }
114  }
115  }
116  }
117 }
118 
119 
120 void CDialogResizeHelper::InitTable(const Param* table, t_size tableSize) {
121  m_table.set_data_fromptr(table, tableSize);
122 }
123 void CDialogResizeHelper::InitTable(const ParamOld * table, t_size tableSize) {
124  m_table.set_size(tableSize);
125  for(t_size walk = 0; walk < tableSize; ++walk) {
126  const ParamOld in = table[walk];
127  Param entry = {};
128  entry.id = table[walk].id;
129  if (in.flags & dialog_resize_helper::X_MOVE) entry.snapLeft = entry.snapRight = 1;
130  else if (in.flags & dialog_resize_helper::X_SIZE) entry.snapRight = 1;
131  if (in.flags & dialog_resize_helper::Y_MOVE) entry.snapTop = entry.snapBottom = 1;
132  else if (in.flags & dialog_resize_helper::Y_SIZE) entry.snapBottom = 1;
133  m_table[walk] = entry;
134  }
135 }
136 void CDialogResizeHelper::InitMinMax(const CRect & range) {
137  min_x = range.left; min_y = range.top; max_x = range.right; max_y = range.bottom;
138 }
BOOL GetChildWindowRect(HWND wnd, UINT id, RECT *child)
void info(const char *p_message)
Definition: console.cpp:4
void remove_all()
Definition: map.h:139
pfc::map_t< UINT, CRect > m_origRects
bool EvalRect(UINT id, CRect &out) const
void InitMinMax(const CRect &range)
void OnGetMinMaxInfo(LPMINMAXINFO lpMMI) const
bool _EvalRect(t_size index, CSize wndSize, CRect &out) const
pfc::array_t< Param > m_table
size_t t_size
Definition: int_types.h:48
void InitTable(const Param *table, t_size tableSize)
t_int32 rint32(double p_val)
Definition: primitives.h:712
void set(const _t_key &p_key, const _t_value &p_value)
Definition: map.h:22
void OnSize(UINT nType, CSize size)
void OnInitDialog(CWindow thisWnd)
bool query(const _t_key &p_key, _t_value &p_value) const
Definition: map.h:44