foobar2000 SDK  2015-08-03
Data Structures | Public Types | Public Member Functions | Data Fields | Private Member Functions | Static Private Member Functions | Private Attributes
cfgDialogPositionData

#include <WindowPositionUtils.h>

+ Inheritance diagram for cfgDialogPositionData:

Data Structures

struct  DeOverlapState
 

Public Types

enum  { posInvalid = 0x80000000, sizeInvalid = 0xFFFFFFFF, dpiInvalid = 0 }
 

Public Member Functions

 cfgDialogPositionData ()
 
void AddWindow (CWindow wnd)
 
void FetchConfig ()
 
void OverrideDefaultSize (t_uint32 width, t_uint32 height)
 
void RemoveWindow (CWindow wnd)
 

Data Fields

t_uint32 m_dpiX
 
t_uint32 m_dpiY
 
t_uint32 m_height
 
t_int32 m_posX
 
t_int32 m_posY
 
t_uint32 m_width
 

Private Member Functions

BOOL ApplyConfig (CWindow wnd)
 
void ApplyDPI ()
 
CSize GrabDPI () const
 
BOOL StoreConfig (CWindow wnd)
 
void TryFetchConfig ()
 

Static Private Member Functions

static void DeOverlap (CWindow wnd, CRect &rc)
 
static int DeOverlapDelta ()
 
static bool DeOverlapTest (CWindow wnd, CPoint topLeft)
 
static BOOL GetParentWndRect (CWindow wndParent, CRect &rc)
 
static BOOL CALLBACK MyEnumChildProc (HWND wnd, LPARAM param)
 

Private Attributes

pfc::avltree_t< CWindow > m_windows
 

Detailed Description

Definition at line 107 of file WindowPositionUtils.h.


Data Structure Documentation

struct cfgDialogPositionData::DeOverlapState

Definition at line 170 of file WindowPositionUtils.h.

Data Fields
bool m_match
CWindow m_thisWnd
CPoint m_topLeft

Member Enumeration Documentation

anonymous enum
Enumerator
posInvalid 
sizeInvalid 
dpiInvalid 

Definition at line 265 of file WindowPositionUtils.h.

Constructor & Destructor Documentation

cfgDialogPositionData::cfgDialogPositionData ( )
inline

Member Function Documentation

void cfgDialogPositionData::AddWindow ( CWindow  wnd)
inline

Definition at line 118 of file WindowPositionUtils.h.

118  {
119  TryFetchConfig();
120  m_windows += wnd;
121  ApplyConfig(wnd);
122  }
pfc::avltree_t< CWindow > m_windows
BOOL ApplyConfig(CWindow wnd)
BOOL cfgDialogPositionData::ApplyConfig ( CWindow  wnd)
inlineprivate

Definition at line 131 of file WindowPositionUtils.h.

131  {
132  ApplyDPI();
133  CWindow wndParent = wnd.GetParent();
134  UINT flags = SWP_NOACTIVATE | SWP_NOZORDER;
135  CRect rc;
136  if (!GetClientRectAsSC(wnd,rc)) return FALSE;
137  if (m_width != sizeInvalid && m_height != sizeInvalid && (wnd.GetWindowLong(GWL_STYLE) & WS_SIZEBOX) != 0) {
138  rc.right = rc.left + m_width;
139  rc.bottom = rc.top + m_height;
140  } else {
141  flags |= SWP_NOSIZE;
142  }
143  if (wndParent != NULL) {
144  CRect rcParent;
145  if (GetParentWndRect(wndParent, rcParent)) {
146  if (m_posX != posInvalid && m_posY != posInvalid) {
147  rc.MoveToXY( rcParent.TopLeft() + CPoint(m_posX, m_posY) );
148  } else {
149  CPoint center = rcParent.CenterPoint();
150  rc.MoveToXY( center.x - rc.Width() / 2, center.y - rc.Height() / 2);
151  }
152  }
153  }
154  if (!AdjustWindowRectHelper(wnd, rc)) return FALSE;
155 
156  DeOverlap(wnd, rc);
157 
158  {
159  CRect rcAdjust(0,0,1,1);
160  if (wndParent != NULL) {
161  CRect temp;
162  if (wndParent.GetWindowRect(temp)) rcAdjust = temp;
163  }
164  AdjustRectToScreenArea(rc, rcAdjust);
165  }
166 
167 
168  return wnd.SetWindowPos(NULL, rc, flags);
169  }
static void AdjustRectToScreenArea(CRect &rc, CRect rcParent)
static BOOL GetParentWndRect(CWindow wndParent, CRect &rc)
static BOOL GetClientRectAsSC(CWindow wnd, CRect &rc)
static BOOL AdjustWindowRectHelper(CWindow wnd, CRect &rc)
static void DeOverlap(CWindow wnd, CRect &rc)
void cfgDialogPositionData::ApplyDPI ( )
inlineprivate

Definition at line 226 of file WindowPositionUtils.h.

226  {
227  const CSize screenDPI = QueryScreenDPIEx();
228  if (screenDPI.cx == 0 || screenDPI.cy == 0) {
229  PFC_ASSERT(!"Should not get here - something seriously wrong with the OS");
230  return;
231  }
232  if (m_dpiX != dpiInvalid && m_dpiX != screenDPI.cx) {
233  if (m_width != sizeInvalid) m_width = MulDiv(m_width, screenDPI.cx, m_dpiX);
234  if (m_posX != posInvalid) m_posX = MulDiv(m_posX, screenDPI.cx, m_dpiX);
235  }
236  if (m_dpiY != dpiInvalid && m_dpiY != screenDPI.cy) {
237  if (m_height != sizeInvalid) m_height = MulDiv(m_height, screenDPI.cy, m_dpiY);
238  if (m_posY != posInvalid) m_posY = MulDiv(m_posY, screenDPI.cy, m_dpiY);
239  }
240  m_dpiX = screenDPI.cx;
241  m_dpiY = screenDPI.cy;
242  }
SIZE QueryScreenDPIEx()
Definition: win32_misc.cpp:35
static void cfgDialogPositionData::DeOverlap ( CWindow  wnd,
CRect &  rc 
)
inlinestaticprivate

Definition at line 196 of file WindowPositionUtils.h.

196  {
197  const int delta = DeOverlapDelta();
198  for(;;) {
199  if (!DeOverlapTest(wnd, rc.TopLeft())) break;
200  rc.OffsetRect(delta,delta);
201  }
202  }
static bool DeOverlapTest(CWindow wnd, CPoint topLeft)
static int cfgDialogPositionData::DeOverlapDelta ( )
inlinestaticprivate

Definition at line 193 of file WindowPositionUtils.h.

193  {
194  return pfc::max_t<int>(GetSystemMetrics(SM_CYCAPTION),1);
195  }
static bool cfgDialogPositionData::DeOverlapTest ( CWindow  wnd,
CPoint  topLeft 
)
inlinestaticprivate

Definition at line 187 of file WindowPositionUtils.h.

187  {
188  DeOverlapState state = {};
189  state.m_thisWnd = wnd; state.m_topLeft = topLeft; state.m_match = false;
190  EnumThreadWindows(GetCurrentThreadId(), MyEnumChildProc, reinterpret_cast<LPARAM>(&state));
191  return state.m_match;
192  }
static BOOL CALLBACK MyEnumChildProc(HWND wnd, LPARAM param)
void cfgDialogPositionData::FetchConfig ( )
inline

Definition at line 128 of file WindowPositionUtils.h.

static BOOL cfgDialogPositionData::GetParentWndRect ( CWindow  wndParent,
CRect &  rc 
)
inlinestaticprivate

Definition at line 250 of file WindowPositionUtils.h.

250  {
251  if (!wndParent.IsIconic()) {
252  return wndParent.GetWindowRect(rc);
253  }
254  WINDOWPLACEMENT pl = {sizeof(pl)};
255  if (!wndParent.GetWindowPlacement(&pl)) return FALSE;
256  rc = pl.rcNormalPosition;
257  return TRUE;
258  }
CSize cfgDialogPositionData::GrabDPI ( ) const
inlineprivate

Definition at line 243 of file WindowPositionUtils.h.

243  {
244  CSize DPI(96,96);
245  if (m_dpiX != dpiInvalid) DPI.cx = m_dpiX;
246  if (m_dpiY != dpiInvalid) DPI.cy = m_dpiY;
247  return DPI;
248  }
static BOOL CALLBACK cfgDialogPositionData::MyEnumChildProc ( HWND  wnd,
LPARAM  param 
)
inlinestaticprivate

Definition at line 175 of file WindowPositionUtils.h.

175  {
176  DeOverlapState * state = reinterpret_cast<DeOverlapState*>(param);
177  if (wnd != state->m_thisWnd && IsWindowVisible(wnd) ) {
178  CRect rc;
179  if (GetWindowRect(wnd, rc)) {
180  if (rc.TopLeft() == state->m_topLeft) {
181  state->m_match = true; return FALSE;
182  }
183  }
184  }
185  return TRUE;
186  }
void cfgDialogPositionData::OverrideDefaultSize ( t_uint32  width,
t_uint32  height 
)
inline
void cfgDialogPositionData::RemoveWindow ( CWindow  wnd)
inline

Definition at line 123 of file WindowPositionUtils.h.

123  {
124  if (m_windows.contains(wnd)) {
125  StoreConfig(wnd); m_windows -= wnd;
126  }
127  }
pfc::avltree_t< CWindow > m_windows
BOOL StoreConfig(CWindow wnd)
bool contains(const t_param &p_item) const
Definition: avltree.h:427
BOOL cfgDialogPositionData::StoreConfig ( CWindow  wnd)
inlineprivate

Definition at line 203 of file WindowPositionUtils.h.

203  {
204  CRect rc;
205  if (!GetClientRectAsSC(wnd, rc)) return FALSE;
206  const CSize DPI = QueryScreenDPIEx();
207  m_dpiX = DPI.cx; m_dpiY = DPI.cy;
208  m_width = rc.Width(); m_height = rc.Height();
210  CWindow parent = wnd.GetParent();
211  if (parent != NULL) {
212  CRect rcParent;
213  if (GetParentWndRect(parent, rcParent)) {
214  m_posX = rc.left - rcParent.left;
215  m_posY = rc.top - rcParent.top;
216  }
217  }
218  return TRUE;
219  }
static BOOL GetParentWndRect(CWindow wndParent, CRect &rc)
static BOOL GetClientRectAsSC(CWindow wnd, CRect &rc)
SIZE QueryScreenDPIEx()
Definition: win32_misc.cpp:35
void cfgDialogPositionData::TryFetchConfig ( )
inlineprivate

Definition at line 220 of file WindowPositionUtils.h.

220  {
221  for(pfc::const_iterator<CWindow> walk = m_windows.first(); walk.is_valid(); ++walk) {
222  if (StoreConfig(*walk)) break;
223  }
224  }
pfc::avltree_t< CWindow > m_windows
bool is_valid() const
Definition: iterators.h:24
BOOL StoreConfig(CWindow wnd)
const_iterator first() const
Definition: avltree.h:485

Field Documentation

t_uint32 cfgDialogPositionData::m_dpiX

Definition at line 264 of file WindowPositionUtils.h.

t_uint32 cfgDialogPositionData::m_dpiY

Definition at line 264 of file WindowPositionUtils.h.

t_uint32 cfgDialogPositionData::m_height

Definition at line 262 of file WindowPositionUtils.h.

t_int32 cfgDialogPositionData::m_posX

Definition at line 263 of file WindowPositionUtils.h.

t_int32 cfgDialogPositionData::m_posY

Definition at line 263 of file WindowPositionUtils.h.

t_uint32 cfgDialogPositionData::m_width

Definition at line 262 of file WindowPositionUtils.h.

pfc::avltree_t<CWindow> cfgDialogPositionData::m_windows
private

Definition at line 260 of file WindowPositionUtils.h.


The documentation for this class was generated from the following file: