summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2018-12-05 16:38:50 +0100
committerAlexander Neumann <alexander.neumann@picos-software.com>2018-12-05 16:38:50 +0100
commite7059012c1907a9c9aca0116b4300d27bcb4f962 (patch)
treeb0901a44be11f5f11d4ff2809a8d4d240f9ce264
parentWindowBase: Add ForEachDescendant (diff)
downloadwireguard-windows-e7059012c1907a9c9aca0116b4300d27bcb4f962.tar.xz
wireguard-windows-e7059012c1907a9c9aca0116b4300d27bcb4f962.zip
WindowBase: Add persistence implementations that recursively call descendant's
-rw-r--r--window.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/window.go b/window.go
index f11972ff..0fe0e58b 100644
--- a/window.go
+++ b/window.go
@@ -915,6 +915,42 @@ func setWindowText(hwnd win.HWND, text string) error {
return nil
}
+func (wb *WindowBase) RestoreState() (err error) {
+ wb.ForEachDescendant(func(widget Widget) bool {
+ if persistable, ok := widget.(Persistable); ok && persistable.Persistent() {
+ if err = persistable.RestoreState(); err != nil {
+ return false
+ }
+ }
+
+ if _, ok := widget.(Container); ok {
+ return false
+ }
+
+ return true
+ })
+
+ return
+}
+
+func (wb *WindowBase) SaveState() (err error) {
+ wb.ForEachDescendant(func(widget Widget) bool {
+ if persistable, ok := widget.(Persistable); ok && persistable.Persistent() {
+ if err = persistable.SaveState(); err != nil {
+ return false
+ }
+ }
+
+ if _, ok := widget.(Container); ok {
+ return false
+ }
+
+ return true
+ })
+
+ return
+}
+
func forEachDescendant(hwnd win.HWND, lParam uintptr) uintptr {
if window := windowFromHandle(hwnd); window != nil && forEachDescendantCallback(window.(Widget)) {
return 1