From 5ec0082e6a2d8e7ef9729f01597179647ea3d805 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 1 Aug 2014 21:41:45 -0400 Subject: [PATCH] Cleaned up sizing_windows.go now that the important things have been reimplemented. --- redo/sizing_windows.go | 109 +++++------------------------------------ 1 file changed, 11 insertions(+), 98 deletions(-) diff --git a/redo/sizing_windows.go b/redo/sizing_windows.go index 127bb85..08bb0ab 100644 --- a/redo/sizing_windows.go +++ b/redo/sizing_windows.go @@ -5,6 +5,14 @@ package ui // #include "winapi_windows.h" import "C" +// For Windows, Microsoft just hands you a list of preferred control sizes as part of the MSDN documentation and tells you to roll with it. +// These sizes are given in "dialog units", which are independent of the font in use. +// We need to convert these into standard pixels, which requires we get the device context of the OS window. +// References: +// - http://msdn.microsoft.com/en-us/library/ms645502%28VS.85%29.aspx - the calculation needed +// - http://support.microsoft.com/kb/125681 - to get the base X and Y +// (thanks to http://stackoverflow.com/questions/58620/default-button-size) + type sizing struct { sizingbase @@ -53,107 +61,12 @@ func (c *container) translateAllocationCoords(allocations []*allocation, winwidt // no translation needed on windows } -// For Windows, Microsoft just hands you a list of preferred control sizes as part of the MSDN documentation and tells you to roll with it. -// These sizes are given in "dialog units", which are independent of the font in use. -// We need to convert these into standard pixels, which requires we get the device context of the OS window. -// References: -// - http://msdn.microsoft.com/en-us/library/windows/desktop/aa511279.aspx#controlsizing for control sizes -// - http://msdn.microsoft.com/en-us/library/ms645502%28VS.85%29.aspx - the calculation needed -// - http://support.microsoft.com/kb/125681 - to get the base X and Y -// (thanks to http://stackoverflow.com/questions/58620/default-button-size) -// For push buttons, date/time pickers, links (which we don't use), toolbars, and rebars (another type of toolbar), Common Controls version 6 provides convenient methods to use instead, falling back to the old way if it fails. - -// As we are left with incomplete data, an arbitrary size will be chosen -const ( - defaultWidth = 100 // 2 * preferred width of buttons -) - -type dlgunits struct { - width int - height int - longest bool // TODO actually use this - getsize uintptr - area bool // use area sizes instead - yoff int - yoffalt int -} - -// TODO -/* -var stdDlgSizes = [nctypes]dlgunits{ - c_button: dlgunits{ - width: 50, - height: 14, - getsize: _BCM_GETIDEALSIZE, - }, - c_checkbox: dlgunits{ - // widtdh is not defined here so assume longest - longest: true, - height: 10, - }, - c_combobox: dlgunits{ - // technically the height of a combobox has to include the drop-down list (this is a historical accident: originally comboboxes weren't drop-down) - // but since we're forcing Common Controls version 6, we can take advantage of one of its mechanisms to automatically fix this mistake (bad practice but whatever) - // see also: http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx - // note that the Microsoft guidelines pages don't take the list size into account - longest: true, - height: 12, // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx; the page linked above says 14 - }, - c_lineedit: dlgunits{ - longest: true, - height: 14, - }, - c_label: dlgunits{ - longest: true, - height: 8, - yoff: 3, - yoffalt: 0, - }, - c_listbox: dlgunits{ - longest: true, - // height is not clearly defined here ("an integral number of items (3 items minimum)") so just use a three-line edit control - height: 14 + 10 + 10, - }, - c_progressbar: dlgunits{ - width: 237, // the first reference says 107 also works; TODO decide which to use - height: 8, - }, - c_area: dlgunits{ - area: true, - }, -} -*/ - -//func (w *widgetbase) preferredSize(d *sizing) (width int, height int) { -// TODO +//TODO /* +func (w *widgetbase) preferredSize(d *sizing) (width int, height int) { // the preferred size of an Area is its size if stdDlgSizes[s.ctype].area { return s.areawidth, s.areaheight } - - if msg := stdDlgSizes[s.ctype].getsize; msg != 0 { - var size _SIZE - - r1, _, _ := _sendMessage.Call( - uintptr(s.hwnd), - msg, - uintptr(0), - uintptr(unsafe.Pointer(&size))) - if r1 != uintptr(_FALSE) { // success - return int(size.cx), int(size.cy) - } - // otherwise the message approach failed, so fall back to the regular approach - println("message failed; falling back") - } - - width = stdDlgSizes[s.ctype].width - if width == 0 { - width = defaultWidth - } - height = stdDlgSizes[s.ctype].height - width = fromdlgunitsX(width, d) // equivalent to right of rect - height = fromdlguntisY(height, d) // equivalent to bottom of rect +} */ -// return width, height -//}