window.go 3.6 KB
Newer Older
1 2 3 4 5 6 7 8
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under GNU General Public License v3.0
//
//----------------------------------------

yanghye's avatar
yanghye 已提交
9 10
package cef

11 12 13 14
import (
	"github.com/energye/golcl/lcl"
	"github.com/energye/golcl/lcl/types"
)
yanghye's avatar
yanghye 已提交
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
//辅助工具
type auxTools struct {
	devToolsWindow   *LCLBrowserWindow //devTools
	devToolsX        int32             //上次改变的窗体位置,宽度
	devToolsY        int32             //
	devToolsWidth    int32             //
	devToolsHeight   int32             //
	viewSourceWindow *LCLBrowserWindow //viewSource
	viewSourceUrl    string            //
	viewSourceX      int32             //上次改变的窗体位置,宽度
	viewSourceY      int32             //
	viewSourceWidth  int32             //
	viewSourceHeight int32             //
}

//窗口属性
type WindowProperty struct {
	IsShowModel  bool               //是否以模态窗口显示
	WindowState  types.TWindowState //窗口 状态
	Title        string             //窗口 标题
	Url          string             //默认打开URL
	Icon         string             //窗口图标 加载本地图标
	IconFS       string             //窗口图标 加载emfs内置图标
	CanMinimize  bool               //窗口 是否启用最小化功能
	CanMaximize  bool               //窗口 是否启用最大化功能
	CanResize    bool               //窗口 是否允许调整窗口大小
	CanClose     bool               //窗口 关闭时是否关闭窗口
	CenterWindow bool               //窗口 是否居中显示
	AlwaysOnTop  bool               //窗口 置顶
	X            int32              //窗口 CenterWindow=false X坐标
	Y            int32              //窗口 CenterWindow=false Y坐标
	Width        int32              //窗口 宽
	Height       int32              //窗口 高
}

yanghye's avatar
yanghye 已提交
51
//创建一个新window窗口
52 53 54 55 56 57
func NewWindow(windowProperty *WindowProperty) *LCLBrowserWindow {
	if windowProperty == nil {
		windowProperty = NewWindowProperty()
	}
	var window = &LCLBrowserWindow{}
	window.windowProperty = windowProperty
yanghye's avatar
yanghye 已提交
58 59 60 61 62 63
	//window.TForm = lcl.NewForm(owner)
	lcl.Application.CreateForm(&window)
	window.ParentDoubleBuffered()
	window.FormCreate()
	window.SetNotInTaskBar()
	window.defaultWindowEvent()
64
	window.SetCaption(windowProperty.Title)
65 66 67
	if windowProperty.CenterWindow {
		window.SetWidth(windowProperty.Width)
		window.SetHeight(windowProperty.Height)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
		window.SetPosition(types.PoDesktopCenter)
	} else {
		window.SetPosition(types.PoDefault)
		window.SetBounds(windowProperty.X, windowProperty.Y, windowProperty.Width, windowProperty.Height)
	}
	if windowProperty.IconFS != "" {
		_ = window.Icon().LoadFromFSFile(windowProperty.IconFS)
	} else if windowProperty.Icon != "" {
		window.Icon().LoadFromFile(windowProperty.Icon)
	}
	if windowProperty.AlwaysOnTop {
		window.SetFormStyle(types.FsSystemStayOnTop)
	}
	window.EnabledMinimize(windowProperty.CanMinimize)
	window.EnabledMaximize(windowProperty.CanMaximize)
	if !windowProperty.CanResize {
		window.SetBorderStyle(types.BsSingle)
	}
yanghye's avatar
yanghye 已提交
86 87
	return window
}
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

type IBrowserWindow interface {
	Show()
	Hide()
	Close()
}

type ILCLBrowserWindow interface {
	IBrowserWindow
	Id() int32
}

type IViewsFrameworkBrowserWindow interface {
	IBrowserWindow
	CreateTopLevelWindow()
	CenterWindow(size *TCefSize)
}

//创建一个 窗口默认属性
func NewWindowProperty() *WindowProperty {
	return &WindowProperty{
		Title:        "Energy",
		Url:          "about:blank",
		CanMinimize:  true,
		CanMaximize:  true,
		CanResize:    true,
		CanClose:     true,
		CenterWindow: true,
		Width:        1024,
		Height:       768,
	}
}