Migrated sizing_windows.go to C.
This commit is contained in:
parent
2c025a97ef
commit
29b80f7542
|
@ -0,0 +1,37 @@
|
|||
/* 17 july 2014 */
|
||||
|
||||
#include "winapi_windows.h"
|
||||
|
||||
HDC getDC(HWND hwnd)
|
||||
{
|
||||
HDC dc;
|
||||
|
||||
dc = GetDC(hwnd);
|
||||
if (dc == NULL)
|
||||
xpanic("error getting DC for preferred size calculations", GetLastError());
|
||||
/* TODO */
|
||||
/* TODO save for restoring later */
|
||||
/*
|
||||
if (SelectObject(dc, controlFont) == NULL)
|
||||
xpanic("error loading control font into device context for preferred size calculation", GetLastError());
|
||||
*/
|
||||
return dc;
|
||||
}
|
||||
|
||||
void releaseDC(HWND hwnd, HDC dc)
|
||||
{
|
||||
if (ReleaseDC(hwnd, dc) == 0)
|
||||
xpanic("error releasing DC for preferred size calculations", GetLastError());
|
||||
}
|
||||
|
||||
void getTextMetricsW(HDC dc, TEXTMETRICW *tm)
|
||||
{
|
||||
if (GetTextMetricsW(dc, tm) == 0)
|
||||
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
||||
}
|
||||
|
||||
void moveWindow(HWND hwnd, int x, int y, int width, int height)
|
||||
{
|
||||
if (MoveWindow(hwnd, x, y, width, height, TRUE) == 0)
|
||||
xpanic("error setting window/control rect", GetLastError());
|
||||
}
|
|
@ -6,6 +6,9 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// #include "winapi_windows.h"
|
||||
import "C"
|
||||
|
||||
type sizing struct {
|
||||
sizingbase
|
||||
|
||||
|
@ -25,23 +28,20 @@ const (
|
|||
func (w *window) beginResize() (d *sizing) {
|
||||
d = new(sizing)
|
||||
|
||||
dc := getTextDC(w.hwnd)
|
||||
defer releaseTextDC(w.hwnd, dc)
|
||||
dc := C.getDC(w.hwnd)
|
||||
defer C.releaseDC(w.hwnd, dc)
|
||||
|
||||
var tm s_TEXTMETRICW
|
||||
var tm C.TEXTMETRICW
|
||||
|
||||
res, err := f_GetTextMetricsW(dc, &tm)
|
||||
if res == 0 {
|
||||
panic(fmt.Errorf("error getting text metrics for preferred size calculations: %v", err))
|
||||
}
|
||||
C.getTextMetricsW(dc, &tm)
|
||||
d.baseX = int(tm.tmAveCharWidth) // TODO not optimal; third reference below has better way
|
||||
d.baseY = int(tm.tmHeight)
|
||||
|
||||
if w.spaced {
|
||||
d.xmargin = f_MulDiv(marginDialogUnits, d.baseX, 4)
|
||||
d.ymargin = f_MulDiv(marginDialogUnits, d.baseY, 8)
|
||||
d.xpadding = f_MulDiv(paddingDialogUnits, d.baseX, 4)
|
||||
d.ypadding = f_MulDiv(paddingDialogUnits, d.baseY, 8)
|
||||
d.xmargin = int(C.MulDiv(marginDialogUnits, d.baseX, 4))
|
||||
d.ymargin = int(C.MulDiv(marginDialogUnits, d.baseY, 8))
|
||||
d.xpadding = int(C.MulDiv(paddingDialogUnits, d.baseX, 4))
|
||||
d.ypadding = int(C.MulDiv(paddingDialogUnits, d.baseY, 8))
|
||||
}
|
||||
|
||||
return d
|
||||
|
@ -75,14 +75,11 @@ func (w *widgetbase) commitResize(c *allocation, d *sizing) {
|
|||
yoff = stdDlgSizes[s.ctype].yoffalt
|
||||
}
|
||||
if yoff != 0 {
|
||||
yoff = f_MulDiv(yoff, d.baseY, 8)
|
||||
yoff = int(C.MulDiv(yoff, d.baseY, 8))
|
||||
}
|
||||
c.y += yoff
|
||||
*/
|
||||
res, err := f_MoveWindow(w.hwnd, c.x, c.y, c.width, c.height, c_TRUE)
|
||||
if res == 0 {
|
||||
panic(fmt.Errorf("error setting window/control rect: %v", err))
|
||||
}
|
||||
C.moveWindow(w.hwnd, int(c.x), int(c.y), int(c.width), int(c.height))
|
||||
}
|
||||
|
||||
func (w *widgetbase) getAuxResizeInfo(d *sizing) {
|
||||
|
@ -160,29 +157,6 @@ var stdDlgSizes = [nctypes]dlgunits{
|
|||
}
|
||||
*/
|
||||
|
||||
func getTextDC(hwnd uintptr) (dc uintptr) {
|
||||
dc, err := f_GetDC(hwnd)
|
||||
if dc == hNULL {
|
||||
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
|
||||
}
|
||||
// TODO
|
||||
/*
|
||||
// TODO save so it can be restored later
|
||||
res, err = f_SelectObject(dc, controlFont)
|
||||
if res == hNULL {
|
||||
panic(fmt.Errorf("error loading control font into device context for preferred size calculation: %v", err))
|
||||
}
|
||||
*/
|
||||
return dc
|
||||
}
|
||||
|
||||
func releaseTextDC(hwnd uintptr, dc uintptr) {
|
||||
res, err := f_ReleaseDC(hwnd, dc)
|
||||
if res == 0 {
|
||||
panic(fmt.Errorf("error releasing DC for preferred size calculations: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *widgetbase) preferredSize(d *sizing) (width int, height int) {
|
||||
// TODO
|
||||
/*
|
||||
|
|
|
@ -45,3 +45,9 @@ extern int nCmdShow;
|
|||
extern HICON hDefaultIcon;
|
||||
extern HCURSOR hArrowCursor;
|
||||
extern DWORD initWindows(char **);
|
||||
|
||||
/* sizing_windows.c */
|
||||
extern HDC getDC(HWND);
|
||||
extern void releaseDC(HWND, HDC);
|
||||
extern void getTextMetricsW(HDC, TEXTMETRICW *);
|
||||
extern void moveWindow(HWND, int, int, int, int);
|
||||
|
|
Loading…
Reference in New Issue