예제 #1
0
func (doc *Document) withSurface(f func(surface *drawing.Surface) os.Error) os.Error {
	hdc := doc.nextPageInfo.createDC()
	defer DeleteDC(hdc)

	surface, err := drawing.NewSurfaceFromHDC(hdc)
	if err != nil {
		return err
	}
	defer surface.Dispose()

	return f(surface)
}
예제 #2
0
func (doc *Document) Print() (err os.Error) {
	defer func() {
		if x := recover(); x != nil {
			err = toError(x)
		}
	}()

	hdc := doc.pages[0].info.createDC()
	defer DeleteDC(hdc)

	var di DOCINFO
	di.CbSize = unsafe.Sizeof(di)
	di.LpszDocName = syscall.StringToUTF16Ptr(doc.name)

	if StartDoc(hdc, &di) <= 0 {
		return newError("StartDoc failed")
	}
	defer func() {
		if EndDoc(hdc) <= 0 {
			err = newError("EndDoc failed")
		}
	}()

	surface, err := drawing.NewSurfaceFromHDC(hdc)
	if err != nil {
		return err
	}
	defer surface.Dispose()

	for i, page := range doc.pages {
		if i > 0 {
			// TODO: Only reset dc if required.
			page.info.resetDC(hdc)
		}

		if StartPage(hdc) <= 0 {
			return newError("StartPage failed")
		}

		err = page.Draw(surface)
		if err != nil {
			return err
		}

		if EndPage(hdc) <= 0 {
			return newError("EndPage failed")
		}
	}

	return nil
}
예제 #3
0
func (cw *CustomWidget) wndProc(msg *MSG, origWndProcPtr uintptr) uintptr {
	switch msg.Message {
	case WM_PAINT:
		if cw.paint == nil {
			// TODO: log?
			break
		}

		var ps PAINTSTRUCT

		hdc := BeginPaint(cw.hWnd, &ps)
		if hdc == 0 {
			// TODO: log?
			break
		}
		defer EndPaint(cw.hWnd, &ps)

		surface, err := drawing.NewSurfaceFromHDC(hdc)
		if err != nil {
			// TODO: log?
			break
		}
		defer surface.Dispose()

		r := &ps.RcPaint
		err = cw.paint(surface, drawing.Rectangle{r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top})
		if err != nil {
			// TODO: log?
			break
		}

		return 0

	case WM_ERASEBKGND:
		if !cw.ClearsBackground() {
			return 1
		}

	case WM_SIZE, WM_SIZING:
		if cw.InvalidatesOnResize() {
			cw.Invalidate()
		}
	}

	return cw.Widget.wndProc(msg, origWndProcPtr)
}