16
16
import org .eclipse .swt .graphics .Rectangle ;
17
17
import org .eclipse .swt .internal .browser .OS ;
18
18
import org .eclipse .swt .internal .xhtml .Element ;
19
- import org .eclipse .swt .internal .xhtml .document ;
20
19
import org .eclipse .swt .widgets .Decorations ;
21
20
import org .eclipse .swt .widgets .Monitor ;
21
+ import org .eclipse .swt .widgets .QuickLaunch ;
22
+ import org .eclipse .swt .widgets .TaskBar ;
22
23
23
24
/**
24
25
* @author zhou renjian
@@ -39,29 +40,51 @@ public ResizeHandler(Decorations shell, int status) {
39
40
this .status = status ;
40
41
}
41
42
43
+ private Rectangle getClientArea () {
44
+ int orientation = SWT .LEFT ;
45
+ int clientWidth = 0 ;
46
+ int clientHeight = 0 ;
47
+ int offsetX = 0 ;
48
+ int offsetY = 0 ;
49
+ /**
50
+ * @j2sNative
51
+ * clientWidth = document.body.parentNode.clientWidth;
52
+ * clientHeight = O$.getFixedBodyClientHeight(); //document.body.clientHeight;
53
+ * var display = null;
54
+ * if (this.shell != null) {
55
+ * display = this.shell.display;
56
+ * }
57
+ * if (display == null) {
58
+ * display = $wt.widgets.Display.Default;
59
+ * }
60
+ * if (display != null && display.taskBar != null) {
61
+ * orientation = display.taskBar.orientation;
62
+ * }
63
+ */ {}
64
+ if (orientation == SWT .BOTTOM ) {
65
+ offsetY = QuickLaunch .BAR_HEIGHT ;
66
+ clientHeight = clientHeight - QuickLaunch .BAR_HEIGHT - TaskBar .BAR_HEIGHT ;
67
+ } else if (orientation == SWT .TOP ) {
68
+ offsetY = TaskBar .BAR_HEIGHT ;
69
+ clientHeight = clientHeight - TaskBar .BAR_HEIGHT ;
70
+ }
71
+ return new Rectangle (offsetX , offsetY , clientWidth , clientHeight );
72
+ }
73
+
42
74
public void updateMinimized () {
75
+ Rectangle clientArea = getClientArea ();
43
76
Element tb = null ;
44
77
/**
45
78
* @j2sNative
46
79
* tb = this.shell.titleBar;
47
80
*/ {}
48
81
int h = ((shell .getStyle () & SWT .TITLE ) != 0 ) ? OS .getContainerHeight (tb ) : 0 ;
49
- shell .setLocation (- 1 , shell . getMonitor (). getClientArea () .height - h - 6 );
82
+ shell .setLocation (clientArea . x - 1 , clientArea . y + clientArea .height - h - 6 );
50
83
}
84
+
51
85
public void updateMaximized () {
52
- Monitor monitor = shell .getMonitor ();
53
- Rectangle area = monitor .getClientArea ();
54
- int height = area .height ;
55
- int width = area .width ;
56
- boolean isBodyMonitor = false ;
57
- /**
58
- * @j2sNative
59
- * isBodyMonitor = monitor.handle == document.body;
60
- */ {}
61
- if (isBodyMonitor ) { // update with current body client area
62
- width = document .body .parentNode .clientWidth ;
63
- height = OS .getFixedBodyClientHeight ();
64
- }
86
+ Rectangle clientArea = getClientArea ();
87
+
65
88
//int titleHeight = ((shell.getStyle() & SWT.TITLE) != 0) ? 20 : 0;
66
89
Element tb = null ;
67
90
/**
@@ -71,41 +94,122 @@ public void updateMaximized() {
71
94
int titleHeight = ((shell .getStyle () & SWT .TITLE ) != 0 ) ? OS .getContainerHeight (tb ) : 0 ;
72
95
// FIXME: maximized size is not accurate
73
96
//shell.setBounds(shell.computeTrim(0, 0, width + 4, height - titleHeight + 6));
74
- // boolean isOptMaximized = false;
75
- // /**
76
- // * @j2sNative
77
- // * isOptMaximized = window["ShellManager"] != null;
78
- // */ {}
79
- // if (!isOptMaximized) {
80
- // shell.setBounds(shell.computeTrim(0, 0, width, height - titleHeight));
81
- // } else {
82
- shell .setBounds (shell .computeTrim (0 , -titleHeight , width , height ));
83
- // }
97
+ boolean disablingMaxBar = false ;
98
+ /**
99
+ * @j2sNative
100
+ * disablingMaxBar = window["swt.maximized.bar"] == false;
101
+ */ {}
102
+ if (disablingMaxBar ) {
103
+ if (status == SWT .MAX ) {
104
+ shell .setBounds (shell .computeTrim (clientArea .x , clientArea .y , clientArea .width , clientArea .height - titleHeight ));
105
+ } else if ((status & SWT .TOP ) != 0 && (status & SWT .BOTTOM ) != 0 ) {
106
+ Rectangle bounds = shell .getBounds ();
107
+ int shellWidth = shell .getSize ().x ;
108
+ if ((status & SWT .LEFT ) != 0 ) {
109
+ shell .setBounds (clientArea .x , clientArea .y , shellWidth , clientArea .height + 2 );
110
+ } else if ((status & SWT .RIGHT ) != 0 ) {
111
+ shell .setBounds (clientArea .x + clientArea .width - shellWidth , clientArea .y , shellWidth , clientArea .height + 2 );
112
+ } else {
113
+ shell .setBounds (bounds .x , clientArea .y , shellWidth , clientArea .height + 2 );
114
+ }
115
+ } else if ((status & SWT .LEFT ) != 0 && (status & SWT .RIGHT ) != 0 ) {
116
+ Rectangle bounds = shell .getBounds ();
117
+ int shellHeight = shell .getSize ().y ;
118
+ if ((status & SWT .TOP ) != 0 ) {
119
+ shell .setBounds (clientArea .x , clientArea .y , clientArea .width + 2 , shellHeight );
120
+ } else if ((status & SWT .BOTTOM ) != 0 ) {
121
+ shell .setBounds (clientArea .x , clientArea .y + clientArea .height - 2 - shellHeight , clientArea .width + 2 , shellHeight );
122
+ } else {
123
+ shell .setBounds (clientArea .x , bounds .y , clientArea .width + 2 , shellHeight );
124
+ }
125
+ }
126
+ } else {
127
+ if (status == SWT .MAX ) {
128
+ shell .setBounds (shell .computeTrim (clientArea .x , clientArea .y - titleHeight , clientArea .width , clientArea .height ));
129
+ } else if ((status & SWT .TOP ) != 0 && (status & SWT .BOTTOM ) != 0 ) {
130
+ Rectangle bounds = shell .getBounds ();
131
+ int shellWidth = shell .getSize ().x ;
132
+ if ((status & SWT .LEFT ) != 0 ) {
133
+ shell .setBounds (clientArea .x , clientArea .y , shellWidth , clientArea .height + 2 );
134
+ } else if ((status & SWT .RIGHT ) != 0 ) {
135
+ shell .setBounds (clientArea .x + clientArea .width - shellWidth + 2 , clientArea .y , shellWidth , clientArea .height + 2 );
136
+ } else {
137
+ shell .setBounds (bounds .x , clientArea .y , shellWidth , clientArea .height + 2 );
138
+ }
139
+ } else if ((status & SWT .LEFT ) != 0 && (status & SWT .RIGHT ) != 0 ) {
140
+ Rectangle bounds = shell .getBounds ();
141
+ int shellHeight = shell .getSize ().y ;
142
+ if ((status & SWT .TOP ) != 0 ) {
143
+ shell .setBounds (clientArea .x , clientArea .y , clientArea .width + 2 , shellHeight );
144
+ } else if ((status & SWT .BOTTOM ) != 0 ) {
145
+ shell .setBounds (clientArea .x , clientArea .y + clientArea .height - 2 - shellHeight , clientArea .width + 2 , shellHeight );
146
+ } else {
147
+ shell .setBounds (clientArea .x , bounds .y , clientArea .width + 2 , shellHeight );
148
+ }
149
+ }
150
+ }
84
151
// shell.setBounds(0 - 4, 0 - 4, width - 2, height + 4);
85
152
//shell.setBounds(shell.computeTrim(0, 0, width + 2, height - 18));
86
153
}
154
+
87
155
public void updateCentered () {
88
- Element tb = null ;
89
- /**
90
- * @j2sNative
91
- * tb = this.shell.titleBar;
92
- */ {}
93
- int h = ((shell .getStyle () & SWT .TITLE ) != 0 ) ? OS .getContainerHeight (tb ) : 20 ;
94
- // Not used now
95
- Monitor monitor = shell .getMonitor ();
156
+ Rectangle clientArea = getClientArea ();
157
+
96
158
Point size = shell .getSize ();
97
- int y = (monitor . getClientArea (). height - size .y ) / 2 - h ;
159
+ int y = (clientArea . height - size .y ) / 2 ;
98
160
if (y < 0 ) {
99
161
y = 0 ;
100
162
}
101
- shell .setLocation ((monitor .getClientArea ().width - size .x ) / 2 , y );
163
+ if (status == SWT .CENTER ) {
164
+ if (y > 0 ) {
165
+ y = (int ) Math .round ((clientArea .height - size .y ) * 0.618 / 1.618 );
166
+ }
167
+ shell .setLocation ((clientArea .width - size .x ) / 2 + clientArea .x , y + clientArea .y );
168
+ } else if ((status & SWT .TOP ) != 0 ){
169
+ shell .setLocation ((clientArea .width - size .x ) / 2 + clientArea .x , clientArea .y );
170
+ } else if ((status & SWT .BOTTOM ) != 0 ){
171
+ int trimWidth = (shell .getStyle () & SWT .NO_TRIM ) != 0 ? 0 : 4 ; // 4: shadow
172
+ shell .setLocation ((clientArea .width - size .x ) / 2 + clientArea .x , clientArea .height - 2 - size .y + clientArea .y + trimWidth );
173
+ } else if ((status & SWT .LEFT ) != 0 ){
174
+ shell .setLocation (clientArea .x , y + clientArea .y );
175
+ } else if ((status & SWT .RIGHT ) != 0 ){
176
+ int trimWidth = (shell .getStyle () & SWT .NO_TRIM ) != 0 ? 0 : 4 ; // 4: shadow
177
+ shell .setLocation (clientArea .width - size .x + clientArea .x + trimWidth , y + clientArea .y );
178
+ }
102
179
}
103
- /**
104
- * @j2sNative
105
- * this.monitor.clientWidth = document.body.parentNode.clientWidth;
106
- * this.monitor.clientHeight = O$.getFixedBodyClientHeight(); //document.body.clientHeight;
107
- */
180
+
181
+ public void updateCornered () {
182
+ Rectangle clientArea = getClientArea ();
183
+ Point size = shell .getSize ();
184
+ int trimWidth = (shell .getStyle () & SWT .NO_TRIM ) != 0 ? 0 : 4 ; // 4: shadow
185
+ if ((status & SWT .TOP ) != 0 ){
186
+ if ((status & SWT .LEFT ) != 0 ) {
187
+ shell .setLocation (clientArea .x , clientArea .y );
188
+ } else if ((status & SWT .RIGHT ) != 0 ) {
189
+ shell .setLocation (clientArea .width - size .x + trimWidth , clientArea .y );
190
+ }
191
+ } else if ((status & SWT .BOTTOM ) != 0 ){
192
+ if ((status & SWT .LEFT ) != 0 ) {
193
+ shell .setLocation (clientArea .x , clientArea .height - 2 - size .y + clientArea .y + trimWidth );
194
+ } else if ((status & SWT .RIGHT ) != 0 ) {
195
+ shell .setLocation (clientArea .width - size .x + trimWidth , clientArea .height - 2 - size .y + clientArea .y + trimWidth );
196
+ }
197
+ }
198
+ }
199
+
108
200
public void updateMonitor () {
201
+ if (monitor == null ) {
202
+ return ;
203
+ }
204
+
205
+ Rectangle clientArea = getClientArea ();
206
+ /**
207
+ * @j2sNative
208
+ * this.monitor.clientX = clientArea.x;
209
+ * this.monitor.clientY = clientArea.y;
210
+ * this.monitor.clientWidth = clientArea.width;
211
+ * this.monitor.clientHeight = clientArea.height;
212
+ */ { clientArea .toString (); }
109
213
}
110
214
111
215
public int getStatus () {
0 commit comments