summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/area_windows.c18
-rw-r--r--redo/area_windows.go76
-rw-r--r--redo/winapi_windows.h2
3 files changed, 82 insertions, 14 deletions
diff --git a/redo/area_windows.c b/redo/area_windows.c
index 4ee2335..b4d3d23 100644
--- a/redo/area_windows.c
+++ b/redo/area_windows.c
@@ -5,7 +5,7 @@
#include "winapi_windows.h"
#include "_cgo_epxort.h"
-LPWSTR areaWindowClass = L"gouiarea";
+#define areaWindowClass L"gouiarea"
static void getScrollPos(HWND hwnd, int *xpos, int *ypos)
{
@@ -441,3 +441,19 @@ DWORD makeAreaWindowClass(char **errmsg)
}
return 0;
}
+
+HWND newArea(void *data)
+{
+ HWND hwnd;
+
+ hwnd = CreateWindowExW(
+ 0,
+ areaWindowClass, L"",
+ WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ 100, 100,
+ msgwin, NULL, hInstance, data);
+ if (hwnd == NULL)
+ xpanic("container creation failed", GetLastError());
+ return hwnd;
+}
diff --git a/redo/area_windows.go b/redo/area_windows.go
index 4c45629..06f4eed 100644
--- a/redo/area_windows.go
+++ b/redo/area_windows.go
@@ -12,10 +12,43 @@ import (
// #include "winapi_windows.h"
import "C"
-const (
- areastyle = _WS_HSCROLL | _WS_VSCROLL | controlstyle
- areaxstyle = 0 | controlxstyle
-)
+type area struct {
+ *areabase
+
+ _hwnd C.HWND
+
+ clickCounter *clickCounter
+}
+
+func registerAreaWndClass() (err error) {
+ var errmsg *C.char
+
+ err := C.makeWindowWindowClass(&errmsg)
+ if err != 0 || errmsg != nil {
+ return fmt.Errorf("%s: %v", C.GoString(errmsg), syscall.Errno(err))
+ }
+ return nil
+}
+
+func newArea(ab *areabase) Area {
+ a := &area{
+ areabase: ab,
+ clickCounter: new(clickCounter),
+ }
+ a._hwnd = C.newArea(unsafe.Pointer(a))
+ a.SetSize(width, height)
+ return a
+}
+
+func (a *area) SetSize(width, height int) {
+ a.width = width
+ a.height = height
+ C.SendMessageW(a._hwnd, C.msgAreaSizeChanged, 0, 0)
+}
+
+func (a *area) RepaintAll() {
+ C.SendMessageW(a._hwnd, C.msgAreaRepaintAll, 0, 0)
+}
//export doPaint
func doPaint(xrect *C.RECT, hscroll C.int, vscroll C.int, data unsafe.Pointer, dx *C.intptr_t, dy *C.intptr_t) unsafe.Pointer {
@@ -241,7 +274,11 @@ var modonlykeys = map[C.WPARAM]Modifiers{
C.VK_RWIN: Super,
}
-// TODO storeAreaHWND
+//export storeAreaHWND
+func storeAreaHWND(data unsafe.Pointer, hwnd C.HWND) {
+ a := (*area)(data)
+ a._hwnd = hwnd
+}
//export areaResetClickCounter
func areaResetClickCounter(data unsafe.Pointer) {
@@ -249,12 +286,27 @@ func areaResetClickCounter(data unsafe.Pointer) {
a.clickCounter.reset()
}
-func registerAreaWndClass() (err error) {
- var errmsg *C.char
+func (a *area) hwnd() C.HWND {
+ return a._hwnd
+}
- err := C.makeWindowWindowClass(&errmsg)
- if err != 0 || errmsg != nil {
- return fmt.Errorf("%s: %v", C.GoString(errmsg), syscall.Errno(err))
- }
- return nil
+func (a *area) setParent(p *controlParent) {
+ basesetParent(a, p)
+}
+
+func (a *area) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
+ return baseallocate(a, x, y, width, height, d)
+}
+
+func (a *area) preferredSize(d *sizing) (width, height int) {
+ // the preferred size of an Area is its size
+ return a.width, a.height
+}
+
+func (a *area) commitResize(a *allocation, d *sizing) {
+ basecommitResize(a, a, d)
+}
+
+func (a *area) getAuxResizeInfo(d *sizing) {
+ basegetAuxResizeInfo(a, d)
}
diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h
index 4b88db2..0cc8cb1 100644
--- a/redo/winapi_windows.h
+++ b/redo/winapi_windows.h
@@ -102,8 +102,8 @@ extern DWORD makeContainerWindowClass(char **);
extern HWND newContainer(void *);
/* area_window.c */
-extern LPWSTR areaWindowClass;
extern void repaintArea(HWND);
extern DWORD makeAreaWindowClass(char **);
+extern HWND newArea(void *);
#endif