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"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// #include "winapi_windows.h"
|
||||||
|
import "C"
|
||||||
|
|
||||||
type sizing struct {
|
type sizing struct {
|
||||||
sizingbase
|
sizingbase
|
||||||
|
|
||||||
|
@ -25,23 +28,20 @@ const (
|
||||||
func (w *window) beginResize() (d *sizing) {
|
func (w *window) beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
|
|
||||||
dc := getTextDC(w.hwnd)
|
dc := C.getDC(w.hwnd)
|
||||||
defer releaseTextDC(w.hwnd, dc)
|
defer C.releaseDC(w.hwnd, dc)
|
||||||
|
|
||||||
var tm s_TEXTMETRICW
|
var tm C.TEXTMETRICW
|
||||||
|
|
||||||
res, err := f_GetTextMetricsW(dc, &tm)
|
C.getTextMetricsW(dc, &tm)
|
||||||
if res == 0 {
|
|
||||||
panic(fmt.Errorf("error getting text metrics for preferred size calculations: %v", err))
|
|
||||||
}
|
|
||||||
d.baseX = int(tm.tmAveCharWidth) // TODO not optimal; third reference below has better way
|
d.baseX = int(tm.tmAveCharWidth) // TODO not optimal; third reference below has better way
|
||||||
d.baseY = int(tm.tmHeight)
|
d.baseY = int(tm.tmHeight)
|
||||||
|
|
||||||
if w.spaced {
|
if w.spaced {
|
||||||
d.xmargin = f_MulDiv(marginDialogUnits, d.baseX, 4)
|
d.xmargin = int(C.MulDiv(marginDialogUnits, d.baseX, 4))
|
||||||
d.ymargin = f_MulDiv(marginDialogUnits, d.baseY, 8)
|
d.ymargin = int(C.MulDiv(marginDialogUnits, d.baseY, 8))
|
||||||
d.xpadding = f_MulDiv(paddingDialogUnits, d.baseX, 4)
|
d.xpadding = int(C.MulDiv(paddingDialogUnits, d.baseX, 4))
|
||||||
d.ypadding = f_MulDiv(paddingDialogUnits, d.baseY, 8)
|
d.ypadding = int(C.MulDiv(paddingDialogUnits, d.baseY, 8))
|
||||||
}
|
}
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
@ -75,14 +75,11 @@ func (w *widgetbase) commitResize(c *allocation, d *sizing) {
|
||||||
yoff = stdDlgSizes[s.ctype].yoffalt
|
yoff = stdDlgSizes[s.ctype].yoffalt
|
||||||
}
|
}
|
||||||
if yoff != 0 {
|
if yoff != 0 {
|
||||||
yoff = f_MulDiv(yoff, d.baseY, 8)
|
yoff = int(C.MulDiv(yoff, d.baseY, 8))
|
||||||
}
|
}
|
||||||
c.y += yoff
|
c.y += yoff
|
||||||
*/
|
*/
|
||||||
res, err := f_MoveWindow(w.hwnd, c.x, c.y, c.width, c.height, c_TRUE)
|
C.moveWindow(w.hwnd, int(c.x), int(c.y), int(c.width), int(c.height))
|
||||||
if res == 0 {
|
|
||||||
panic(fmt.Errorf("error setting window/control rect: %v", err))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *widgetbase) getAuxResizeInfo(d *sizing) {
|
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) {
|
func (w *widgetbase) preferredSize(d *sizing) (width int, height int) {
|
||||||
// TODO
|
// TODO
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -45,3 +45,9 @@ extern int nCmdShow;
|
||||||
extern HICON hDefaultIcon;
|
extern HICON hDefaultIcon;
|
||||||
extern HCURSOR hArrowCursor;
|
extern HCURSOR hArrowCursor;
|
||||||
extern DWORD initWindows(char **);
|
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