Re-added base units calculation to the resizing code now that container stores a HWND again.
This commit is contained in:
parent
ef513c4337
commit
91f1a34003
|
@ -91,10 +91,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *container) beginResize() (d *sizing) {
|
func (c *container) beginResize() (d *sizing) {
|
||||||
|
var baseX, baseY C.int
|
||||||
|
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
|
|
||||||
d.baseX = C.baseX
|
C.calculateBaseUnits(c.hwnd, &baseX, &baseY)
|
||||||
d.baseY = C.baseY
|
d.baseX = baseX
|
||||||
|
d.baseY = baseY
|
||||||
|
|
||||||
if spaced {
|
if spaced {
|
||||||
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
|
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
|
||||||
|
|
|
@ -3,21 +3,14 @@
|
||||||
#include "winapi_windows.h"
|
#include "winapi_windows.h"
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
/* TODO rename to sizer_windows.c and move all but the first function to control_windows.c */
|
/* TODO figure out where these should go */
|
||||||
|
|
||||||
BOOL baseUnitsCalculated = FALSE;
|
void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY)
|
||||||
int baseX;
|
|
||||||
int baseY;
|
|
||||||
|
|
||||||
/* called by newWindow() so we can calculate base units when we have a window */
|
|
||||||
void calculateBaseUnits(HWND hwnd)
|
|
||||||
{
|
{
|
||||||
HDC dc;
|
HDC dc;
|
||||||
HFONT prevFont;
|
HFONT prevFont;
|
||||||
TEXTMETRICW tm;
|
TEXTMETRICW tm;
|
||||||
|
|
||||||
if (baseUnitsCalculated)
|
|
||||||
return;
|
|
||||||
dc = GetDC(hwnd);
|
dc = GetDC(hwnd);
|
||||||
if (dc == NULL)
|
if (dc == NULL)
|
||||||
xpanic("error getting DC for preferred size calculations", GetLastError());
|
xpanic("error getting DC for preferred size calculations", GetLastError());
|
||||||
|
@ -26,13 +19,12 @@ void calculateBaseUnits(HWND hwnd)
|
||||||
xpanic("error loading control font into device context for preferred size calculation", GetLastError());
|
xpanic("error loading control font into device context for preferred size calculation", GetLastError());
|
||||||
if (GetTextMetricsW(dc, &tm) == 0)
|
if (GetTextMetricsW(dc, &tm) == 0)
|
||||||
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
||||||
baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
|
*baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
|
||||||
baseY = (int) tm.tmHeight;
|
*baseY = (int) tm.tmHeight;
|
||||||
if (SelectObject(dc, prevFont) != controlFont)
|
if (SelectObject(dc, prevFont) != controlFont)
|
||||||
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
|
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
|
||||||
if (ReleaseDC(hwnd, dc) == 0)
|
if (ReleaseDC(hwnd, dc) == 0)
|
||||||
xpanic("error releasing DC for preferred size calculations", GetLastError());
|
xpanic("error releasing DC for preferred size calculations", GetLastError());
|
||||||
baseUnitsCalculated = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveWindow(HWND hwnd, int x, int y, int width, int height)
|
void moveWindow(HWND hwnd, int x, int y, int width, int height)
|
||||||
|
|
|
@ -65,10 +65,7 @@ extern HFONT statusbarFont;
|
||||||
extern DWORD initWindows(char **);
|
extern DWORD initWindows(char **);
|
||||||
|
|
||||||
/* sizing_windows.c */
|
/* sizing_windows.c */
|
||||||
extern BOOL baseUnitsCalculated;
|
extern void calculateBaseUnits(HWND, int *, int *);
|
||||||
extern int baseX;
|
|
||||||
extern int baseY;
|
|
||||||
extern void calculateBaseUnits(HWND);
|
|
||||||
extern void moveWindow(HWND, int, int, int, int);
|
extern void moveWindow(HWND, int, int, int, int);
|
||||||
extern LONG controlTextLength(HWND, LPWSTR);
|
extern LONG controlTextLength(HWND, LPWSTR);
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,6 @@ HWND newWindow(LPWSTR title, int width, int height, void *data)
|
||||||
NULL, NULL, hInstance, data);
|
NULL, NULL, hInstance, data);
|
||||||
if (hwnd == NULL)
|
if (hwnd == NULL)
|
||||||
xpanic("Window creation failed", GetLastError());
|
xpanic("Window creation failed", GetLastError());
|
||||||
calculateBaseUnits(hwnd);
|
|
||||||
return hwnd;
|
return hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue