Scid  4.6.5
windows.tcl
Go to the documentation of this file.
1 ###
2 ### windows.tcl: part of Scid.
3 ### Copyright (C) 1999-2003 Shane Hudson.
4 ###
5 
6 
7 namespace eval ::windows {
8 
9  # TODO
10 }
11 
12 ########################################################################
13 ### Optional windows: all off initially.
14 
15 set treeWin 0
16 set pgnWin 0
17 set filterGraph 0
18 
19 ################################################################################
20 # Creates a toplevel window depending of the docking option
21 ################################################################################
22 proc createToplevel { {w} {closeto ""} } {
23  set name [string range $w 1 end]
24  set f .fdock$name
25 
26  # Raise window if already exist
27  if { [winfo exists $w] } {
28  if {! $::docking::USE_DOCKING } {
29  tk::PlaceWindow $w
30  } else {
31  if { [::docking::isUndocked $w] } {
32  tk::PlaceWindow $f
33  } else {
34  [::docking::find_tbn $f] select $f
35  }
36  }
37  return "already_exists"
38  }
39 
40  if { $::docking::USE_DOCKING } {
41  set old_dest $::docking::layout_dest_notebook
42  if {$old_dest == "" && $closeto != ""} {
43  set tab [string range $closeto 1 end]
44  set ::docking::layout_dest_notebook [::docking::find_tbn .fdock$tab]
45  }
46  frame $f -container 1
47  toplevel .$name -use [ winfo id $f]
48  docking::add_tab "$f" "$f"
49  set ::docking::layout_dest_notebook $old_dest
50  } else {
51  toplevel $w
52  }
53 }
54 
55 
56 proc createWindow { {w} {default_w} {default_h} {title} } {
57  # Raise window if already exists
58  if { [winfo exists $w] } {
59  if {[winfo toplevel $w] == $w} {
60  wm deiconify $w
61  } else {
62  [::docking::find_tbn $w] select $w
63  }
64  return 0
65  }
66 
67  # Set default width and height values, if they do not exists
68  if {![info exists ::winWidth($w)]} {
69  set ::winWidth($w) $default_w
70  }
71  if {![info exists ::winHeight($w)]} {
72  set ::winHeight($w) $default_h
73  }
74 
75  # Create the window
76  frame $w
77  if { $::docking::USE_DOCKING } {
78  docking::add_tab $w "$title"
79  } else {
80  wm manage $w
81  wm title $w "Scid: $title"
83  setWinSize $w
84  }
85 
87  after idle "bind $w <Destroy> \"+cleanupWindow $w %W\""
88 
89  return 1
90 }
91 
92 proc cleanupWindow { {w} {w_destroy} } {
93  if {[string equal $w $w_destroy]} {
94  if {[winfo toplevel $w] == $w} {
95  scan [wm geometry $w] "%dx%d+%d+%d" l h x y
96  set ::winWidth($w) $l
97  set ::winHeight($w) $h
98  set ::winX($w) $x
99  set ::winY($w) $y
100  } else {
102  }
103  }
104 }
105 
106 
107 ################################################################################
108 # In the case of a window closed without the context menu in docked mode, arrange for the tabs to be cleaned up
109 # Alternative way : directly call ::docking::cleanup $w when closing window
110 ################################################################################
111 proc createToplevelFinalize {w} {
112  if { $::docking::USE_DOCKING } {
113  bind $w <Destroy> +[ namespace code "::docking::cleanup $w %W"]
114  }
115 }
116 
117 ################################################################################
118 # if undocked window : sets the title of the toplevel window
119 # if docked : sets the name of the tab
120 # w : name of the toplevel window
121 proc setTitle { w title } {
122  set f .fdock[ string range $w 1 end]
123  if { [catch {set nb [ ::docking::find_tbn $f]}]} {
124  set nb ""
125  }
126 
127  if { $nb == "" } {
128  wm title $w $title
129  } else {
130  # in docked mode trim down title to spare space
131  if { [ string range $title 0 5] == "Scid: " && [ string length $title] > 6 } {
132  set title [string range $title 6 end]
133  }
134  $nb tab $f -text $title
135  }
136 }
137 
138 ################################################################################
139 # Sets the menu for a new window : in docked mode the menu is displayed by clicking on the tab of the notebook
140 ################################################################################
141 proc setMenu { w m} {
142  if { ! $::docking::USE_DOCKING } {
143  $w configure -menu $m
144  }
145 }
146 
147 
148 # recordWinSize:
149 # Records window width and height, for saving in options file.
150 #
151 proc recordWinSize {win} {
152  global winWidth winHeight winX winY
153  if {![winfo exists $win]} { return}
154  if { $::docking::USE_DOCKING && ! [ ::docking::isUndocked $win]} { return}
155  set temp [wm geometry $win]
156 
157  set suffix ""
158  set n [scan $temp "%dx%d+%d+%d" width height x y]
159  if {$n == 4} {
160  set winWidth${suffix}($win) $width
161  set winHeight${suffix}($win) $height
162  set winX${suffix}($win) $x
163  set winY${suffix}($win) $y
164  }
165 }
166 
167 proc setWinLocation {win} {
168  global winX winY
169  set suffix ""
170  if {[info exists winX${suffix}($win)] && [info exists winY${suffix}($win)] && \
171  [set winX${suffix}($win)] >= 0 && [set winY${suffix}($win)] >= 0} {
172  catch [list wm geometry $win "+[set winX${suffix}($win)]+[set winY${suffix}($win)]"]
173  }
174 }
175 
176 proc setWinSize {win} {
177  global winWidth winHeight
178  set suffix ""
179  if {[info exists winWidth${suffix}($win)] && [info exists winHeight${suffix}($win)] && \
180  [set winWidth${suffix}($win)] > 0 && [set winHeight${suffix}($win)] > 0 } {
181  catch [list wm geometry $win "[set winWidth${suffix}($win)]x[set winHeight${suffix}($win)]"]
182  }
183 }
184 
185 ###
186 ### End of file: windows.tcl
187 ###