2015-05-14 08:43:25 -05:00
// 14 may 2015
2016-04-22 18:51:33 -05:00
# include "uipriv_windows.hpp"
2015-05-14 09:08:49 -05:00
2016-04-22 18:51:33 -05:00
static std : : map < uiWindowsControl * , bool > resizes ;
2015-05-14 09:08:49 -05:00
2016-04-24 17:23:00 -05:00
// TODO clicking buttons doesn't get rid of anything?
2015-09-01 06:33:13 -05:00
void uiWindowsControlQueueRelayout ( uiWindowsControl * c )
2015-05-18 11:04:52 -05:00
{
2016-04-24 17:23:00 -05:00
HWND hwnd ;
HWND parent ;
2015-05-18 11:04:52 -05:00
uintmax_t i ;
// resizing a control requires us to reocmpute the sizes of everything in the top-level window
2016-04-24 17:23:00 -05:00
hwnd = ( HWND ) uiControlHandle ( uiControl ( c ) ) ;
// TODO what if this is toplevel
parent = parentToplevel ( hwnd ) ;
if ( parent = = utilWindow ) // not in a parent
2015-05-18 11:04:52 -05:00
return ;
2016-04-24 17:23:00 -05:00
c = uiWindowsControl ( SendMessageW ( parent , msgGetuiWindow , 0 , 0 ) ) ;
2016-04-22 18:51:33 -05:00
resizes [ c ] = true ;
2015-05-14 09:08:49 -05:00
}
void doResizes ( void )
{
2015-08-31 14:14:02 -05:00
uiWindowsControl * w ;
2015-05-16 00:55:34 -05:00
HWND hwnd ;
2015-08-31 14:14:02 -05:00
RECT r ;
2015-05-14 09:08:49 -05:00
2016-04-22 18:51:33 -05:00
for ( const auto & iter : resizes ) {
w = iter . first ;
2015-09-02 15:26:54 -05:00
// don't clip content if content dynamically changed (tab page changed, etc.)
2015-12-04 18:34:51 -06:00
// do this BEFORE removing w from the queue list to avoid double queueing
2015-09-02 15:26:54 -05:00
ensureMinimumWindowSize ( uiWindow ( w ) ) ;
2015-05-17 20:15:39 -05:00
hwnd = ( HWND ) uiControlHandle ( uiControl ( w ) ) ;
2016-04-22 18:51:33 -05:00
if ( GetClientRect ( hwnd , & r ) = = 0 ) {
logLastError ( L " error getting uiWindow client rect " ) ;
// give up on this one; move on to the next one
continue ;
}
2015-08-31 14:14:02 -05:00
( * ( w - > Relayout ) ) ( w , r . left , r . top , r . right - r . left , r . bottom - r . top ) ;
2015-05-14 09:08:49 -05:00
// we used SWP_NOREDRAW; we need to queue a redraw ourselves
2015-06-04 15:36:28 -05:00
// force all controls to be redrawn; this fixes things like the date-time picker's up-down not showing up until hovered over (and bypasses complications caused by WS_CLIPCHILDREN and WS_CLIPSIBLINGS, which we don't use but other controls might)
if ( RedrawWindow ( hwnd , NULL , NULL , RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN ) = = 0 )
2016-04-22 18:51:33 -05:00
logLastError ( L " error redrawing controls after a resize " ) ; // and keep going anyway
2015-05-14 09:08:49 -05:00
}
2016-04-22 18:51:33 -05:00
// and wipe the list
resizes . clear ( ) ;
2015-05-14 09:08:49 -05:00
}
2016-04-22 18:51:33 -05:00
///////////////////////
// TODO REEVALUATE EVERYTHING BEYOND THIS POINT
// if we do have to keep, verify the error handling
///////////////////////
2015-05-15 15:04:10 -05:00
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing and https://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
// this X value is really only for buttons but I don't see a better one :/
# define winXPadding 4
# define winYPadding 4
2015-08-31 14:14:02 -05:00
uiWindowsSizing * uiWindowsNewSizing ( HWND hwnd )
2015-05-15 15:04:10 -05:00
{
2015-08-31 16:50:23 -05:00
uiWindowsSizing * d ;
2015-05-15 15:04:10 -05:00
HDC dc ;
HFONT prevfont ;
TEXTMETRICW tm ;
SIZE size ;
2015-08-31 14:14:02 -05:00
d = uiNew ( uiWindowsSizing ) ;
2015-05-15 15:04:10 -05:00
2015-05-16 00:55:34 -05:00
dc = GetDC ( hwnd ) ;
2015-05-15 15:04:10 -05:00
if ( dc = = NULL )
2016-04-22 18:51:33 -05:00
logLastError ( L " error getting DC " ) ;
2015-05-15 15:04:10 -05:00
prevfont = ( HFONT ) SelectObject ( dc , hMessageFont ) ;
if ( prevfont = = NULL )
2016-04-22 18:51:33 -05:00
logLastError ( L " error loading control font into device context " ) ;
2015-05-15 15:04:10 -05:00
ZeroMemory ( & tm , sizeof ( TEXTMETRICW ) ) ;
if ( GetTextMetricsW ( dc , & tm ) = = 0 )
2016-04-22 18:51:33 -05:00
logLastError ( L " error getting text metrics " ) ;
2015-05-15 15:04:10 -05:00
if ( GetTextExtentPoint32W ( dc , L " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " , 52 , & size ) = = 0 )
2016-04-22 18:51:33 -05:00
logLastError ( L " error getting text extent point " ) ;
2015-05-15 15:04:10 -05:00
2015-08-31 14:14:02 -05:00
d - > BaseX = ( int ) ( ( size . cx / 26 + 1 ) / 2 ) ;
d - > BaseY = ( int ) tm . tmHeight ;
d - > InternalLeading = tm . tmInternalLeading ;
2015-05-15 15:04:10 -05:00
if ( SelectObject ( dc , prevfont ) ! = hMessageFont )
2016-04-22 18:51:33 -05:00
logLastError ( L " error restoring previous font into device context " ) ;
2015-05-16 00:55:34 -05:00
if ( ReleaseDC ( hwnd , dc ) = = 0 )
2016-04-22 18:51:33 -05:00
logLastError ( L " error releasing DC " ) ;
2015-05-15 15:04:10 -05:00
2015-08-31 14:14:02 -05:00
d - > XPadding = uiWindowsDlgUnitsToX ( winXPadding , d - > BaseX ) ;
d - > YPadding = uiWindowsDlgUnitsToY ( winYPadding , d - > BaseY ) ;
2015-05-18 11:04:52 -05:00
return d ;
2015-05-15 15:04:10 -05:00
}
2015-05-18 10:46:50 -05:00
2015-08-31 14:14:02 -05:00
void uiWindowsFreeSizing ( uiWindowsSizing * d )
2015-05-18 10:46:50 -05:00
{
uiFree ( d ) ;
}