summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-04 20:10:23 -0400
committerPietro Gagliardi <[email protected]>2014-08-04 20:10:23 -0400
commit91f1a34003d56a5778d1ae48f7d18c3f27eea1ed (patch)
treec49f88038ff3c42bc4c62216987b311355bb43f6
parentef513c433732f3a12f2d83417b9b1fb92d152930 (diff)
Re-added base units calculation to the resizing code now that container stores a HWND again.
-rw-r--r--redo/container_windows.go7
-rw-r--r--redo/sizing_windows.c16
-rw-r--r--redo/winapi_windows.h5
-rw-r--r--redo/window_windows.c1
4 files changed, 10 insertions, 19 deletions
diff --git a/redo/container_windows.go b/redo/container_windows.go
index 88abd3e..06fbb5b 100644
--- a/redo/container_windows.go
+++ b/redo/container_windows.go
@@ -91,10 +91,13 @@ const (
)
func (c *container) beginResize() (d *sizing) {
+ var baseX, baseY C.int
+
d = new(sizing)
- d.baseX = C.baseX
- d.baseY = C.baseY
+ C.calculateBaseUnits(c.hwnd, &baseX, &baseY)
+ d.baseX = baseX
+ d.baseY = baseY
if spaced {
d.xmargin = fromdlgunitsX(marginDialogUnits, d)
diff --git a/redo/sizing_windows.c b/redo/sizing_windows.c
index 60d57f3..a2cd2cf 100644
--- a/redo/sizing_windows.c
+++ b/redo/sizing_windows.c
@@ -3,21 +3,14 @@
#include "winapi_windows.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;
-int baseX;
-int baseY;
-
-/* called by newWindow() so we can calculate base units when we have a window */
-void calculateBaseUnits(HWND hwnd)
+void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY)
{
HDC dc;
HFONT prevFont;
TEXTMETRICW tm;
- if (baseUnitsCalculated)
- return;
dc = GetDC(hwnd);
if (dc == NULL)
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());
if (GetTextMetricsW(dc, &tm) == 0)
xpanic("error getting text metrics for preferred size calculations", GetLastError());
- baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
- baseY = (int) tm.tmHeight;
+ *baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
+ *baseY = (int) tm.tmHeight;
if (SelectObject(dc, prevFont) != controlFont)
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
if (ReleaseDC(hwnd, dc) == 0)
xpanic("error releasing DC for preferred size calculations", GetLastError());
- baseUnitsCalculated = TRUE;
}
void moveWindow(HWND hwnd, int x, int y, int width, int height)
diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h
index db90e97..27e92cc 100644
--- a/redo/winapi_windows.h
+++ b/redo/winapi_windows.h
@@ -65,10 +65,7 @@ extern HFONT statusbarFont;
extern DWORD initWindows(char **);
/* sizing_windows.c */
-extern BOOL baseUnitsCalculated;
-extern int baseX;
-extern int baseY;
-extern void calculateBaseUnits(HWND);
+extern void calculateBaseUnits(HWND, int *, int *);
extern void moveWindow(HWND, int, int, int, int);
extern LONG controlTextLength(HWND, LPWSTR);
diff --git a/redo/window_windows.c b/redo/window_windows.c
index 9cf0654..3cd43cd 100644
--- a/redo/window_windows.c
+++ b/redo/window_windows.c
@@ -73,7 +73,6 @@ HWND newWindow(LPWSTR title, int width, int height, void *data)
NULL, NULL, hInstance, data);
if (hwnd == NULL)
xpanic("Window creation failed", GetLastError());
- calculateBaseUnits(hwnd);
return hwnd;
}