1# $Id$
2#
3
4namespace eval geometry {
5    custom::defvar MainWindowState {} \
6	[::msgcat::mc "Stored main window state (normal or zoomed)"] \
7	-type string -group Hidden
8
9    custom::defvar MainWindowStateUntabbed {} \
10	[::msgcat::mc "Stored main window state (normal or zoomed) in\
11		       non-tabbed mode"] \
12	-type string -group Hidden
13
14    custom::defvar MainWindowGeometry {} \
15	[::msgcat::mc "Stored main window geometry"] \
16	-type string -group Hidden
17
18    custom::defvar MainWindowGeometryUntabbed {} \
19	[::msgcat::mc "Stored main window geometry in non-tabbed mode"] \
20	-type string -group Hidden
21
22    hook::add finload_hook [namespace current]::setupBindings 101
23    hook::add finload_hook [namespace current]::restoreMainWindowState 99.9
24}
25
26proc geometry::setupBindings {} {
27    bind . <Map> [namespace current]::saveMainWindowState
28    bind . <Configure> [namespace current]::saveMainWindowGeometry
29}
30
31proc geometry::saveMainWindowState {} {
32    global usetabbar
33    variable MainWindowState
34    variable MainWindowStateUntabbed
35
36    set screen [winfo screen .]
37    if {$usetabbar} {
38	array set tmp $MainWindowState
39    } else {
40	array set tmp $MainWindowStateUntabbed
41    }
42
43    set state [wmstate .]
44    if {![info exists tmp($screen)] || ![string equal $state $tmp($screen)]} {
45	set tmp($screen) $state
46	if {$usetabbar} {
47	    set MainWindowState [array get tmp]
48	} else {
49	    set MainWindowStateUntabbed [array get tmp]
50	}
51    }
52}
53
54proc geometry::saveMainWindowGeometry {} {
55    after cancel [namespace current]::afterSaveMainWindowGeometry
56    after idle [namespace current]::afterSaveMainWindowGeometry
57}
58
59proc geometry::afterSaveMainWindowGeometry {} {
60    global usetabbar
61    variable MainWindowGeometry
62    variable MainWindowGeometryUntabbed
63
64    set state [wmstate .]
65    if {![string equal $state normal]} {
66	return
67    }
68
69    set screen [winfo screen .]
70    if {$usetabbar} {
71	array set tmp $MainWindowGeometry
72    } else {
73	array set tmp $MainWindowGeometryUntabbed
74    }
75
76    set geometry [wm geometry .]
77    if {![info exists tmp($screen)] || ![string equal $geometry $tmp($screen)]} {
78	set tmp($screen) $geometry
79	if {$usetabbar} {
80	    set MainWindowGeometry [array get tmp]
81	} else {
82	    set MainWindowGeometryUntabbed [array get tmp]
83	}
84    }
85}
86
87proc geometry::restoreMainWindowState {} {
88    global tcl_platform
89    global usetabbar
90    variable MainWindowState
91    variable MainWindowStateUntabbed
92    variable MainWindowGeometry
93    variable MainWindowGeometryUntabbed
94
95    set screen [winfo screen .]
96
97    if {$usetabbar} {
98	array set tmp1 $MainWindowGeometry
99    } else {
100	array set tmp1 $MainWindowGeometryUntabbed
101    }
102    if {[info exists tmp1($screen)]} {
103	wm geometry . $tmp1($screen)
104    }
105
106    if {$usetabbar} {
107	array set tmp2 $MainWindowState
108    } else {
109	array set tmp2 $MainWindowStateUntabbed
110    }
111    if {[info exists tmp2($screen)] && [string equal $tmp2($screen) zoomed]} {
112	wmstate . zoomed
113    }
114    update
115}
116
117