Rev 193 | Rev 268 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 259 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | This file is part of a common library |
2 | This file is part of a common library |
3 | Copyright (C) 1990-2006 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 1990-2006 Toby Thain, toby@telegraphics.com.au |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
18 | */ |
19 | 19 | ||
20 | #include "calc_std_state.h" |
20 | #include "calc_std_state.h" |
21 | #include "wind.h" |
21 | #include "wind.h" |
22 | 22 | ||
23 | void set_std_state(WindowPtr w,Rect *r){ |
23 | void set_std_state(WindowPtr w,Rect *r){ |
24 | if(ZOOMABLE(w)) |
24 | if(ZOOMABLE(w)) |
25 | (*(WStateDataHandle)((WindowPeek)w)->dataHandle)->stdState = *r; |
25 | (*(WStateDataHandle)((WindowPeek)w)->dataHandle)->stdState = *r; |
26 | } |
26 | } |
27 | void std_user_state(WindowPtr w){ |
27 | void std_user_state(WindowPtr w){ |
28 | WStateDataHandle h = (WStateDataHandle)((WindowPeek)w)->dataHandle; // ppcc wants cast |
28 | WStateDataHandle h = (WStateDataHandle)((WindowPeek)w)->dataHandle; // ppcc wants cast |
29 | if(ZOOMABLE(w)) |
29 | if(ZOOMABLE(w)) |
30 | (*h)->userState = (*h)->stdState; |
30 | (*h)->userState = (*h)->stdState; |
31 | } |
31 | } |
32 | 32 | ||
33 | void calc_std_state(WindowPtr w,Boolean force_default,Boolean stagger,Rect *s){ |
33 | void calc_std_state(WindowPtr w,Boolean force_default,Boolean stagger,Rect *s){ |
34 | short i,new_left,new_top,h_offset,v_offset; |
34 | short i,new_left,new_top,h_offset,v_offset; |
35 | Rect d,wr,sr,r; |
35 | Rect d,wr,sr,r; |
36 | Boolean spot_taken,too_wide,too_high; |
36 | Boolean spot_taken,too_wide,too_high; |
37 | WindowPeek peek; |
37 | WindowPeek peek; |
38 | Point size; |
38 | Point size; |
39 | 39 | ||
40 | /* As per Human Interface Note 7, |
40 | /* As per Human Interface Note 7, |
41 | * recalculate standard state starting from user state, |
41 | * recalculate standard state starting from user state, |
42 | * so that top-left corner of window only moves if necessary. |
42 | * so that top-left corner of window only moves if necessary. |
43 | */ |
43 | */ |
44 | 44 | ||
45 | /* "display each additional window on the screen that |
45 | /* "display each additional window on the screen that |
46 | * contains the largest portion of the frontmost window" */ |
46 | * contains the largest portion of the frontmost window" */ |
47 | 47 | ||
48 | size = natural_size(w); |
48 | size = natural_size(w); |
49 | d = FrontWindow() ? dominant_device_rect(FrontWindow()) : main_device_rect(); |
49 | d = FrontWindow() ? dominant_device_rect(FrontWindow()) : main_device_rect(); |
50 | global_wind_rect(w,&wr); |
50 | global_wind_rect(w,&wr); |
51 | get_struc_bbox(w,&sr); |
51 | get_struc_bbox(w,&sr); |
52 | InsetRect(&d,2,2); |
52 | InsetRect(&d,2,2); |
53 | d.left += wr.left - sr.left; |
53 | d.left += wr.left - sr.left; |
54 | d.top += wr.top - sr.top; |
54 | d.top += wr.top - sr.top; |
55 | d.right += wr.right - sr.right; |
55 | d.right += wr.right - sr.right; |
56 | d.bottom += wr.bottom - sr.bottom; |
56 | d.bottom += wr.bottom - sr.bottom; |
57 | 57 | ||
58 | h_offset = v_offset = 0; |
58 | h_offset = v_offset = 0; |
59 | do{ |
59 | do{ |
60 | *s = d; |
60 | *s = d; |
61 | new_left = (force_default || wr.left<s->left ? s->left : wr.left) + h_offset; |
61 | new_left = (force_default || wr.left<s->left ? s->left : wr.left) + h_offset; |
62 | new_top = (force_default || wr.top<s->top ? s->top : wr.top) + v_offset; |
62 | new_top = (force_default || wr.top<s->top ? s->top : wr.top) + v_offset; |
63 | if(too_wide = (i=new_left+size.h)>s->right) |
63 | if(too_wide = (i=new_left+size.h)>s->right) |
64 | if((i=s->right-size.h)>s->left) |
64 | if((i=s->right-size.h)>s->left) |
65 | s->left = i; // move window left to expose entire content |
65 | s->left = i; // move window left to expose entire content |
66 | else{ // natural size is wider than screen |
66 | else{ // natural size is wider than screen |
67 | short new_width = width_filter(w,i = s->right - s->left); |
67 | short new_width = width_filter(w,i = s->right - s->left); |
68 | new_width>i ? (s->right=s->left+new_width) : (s->left=s->right-new_width); |
68 | new_width>i ? (s->right=s->left+new_width) : (s->left=s->right-new_width); |
69 | } |
69 | } |
70 | else{ |
70 | else{ |
71 | s->left = new_left; |
71 | s->left = new_left; |
72 | s->right = i; |
72 | s->right = i; |
73 | } |
73 | } |
74 | if(too_high = (i=new_top+size.v)>s->bottom) |
74 | if(too_high = (i=new_top+size.v)>s->bottom) |
75 | if((i=s->bottom-size.v)>s->top) |
75 | if((i=s->bottom-size.v)>s->top) |
76 | s->top = i; // move window up to expose entire content |
76 | s->top = i; // move window up to expose entire content |
77 | else{ // natural size is higher than screen |
77 | else{ // natural size is higher than screen |
78 | short new_height = height_filter(w,i = s->bottom - s->top); |
78 | short new_height = height_filter(w,i = s->bottom - s->top); |
79 | new_height>i ? (s->bottom=s->top+new_height) : (s->top=s->bottom-new_height); |
79 | new_height>i ? (s->bottom=s->top+new_height) : (s->top=s->bottom-new_height); |
80 | } |
80 | } |
81 | else{ |
81 | else{ |
82 | s->top = new_top; |
82 | s->top = new_top; |
83 | s->bottom = i; |
83 | s->bottom = i; |
84 | } |
84 | } |
85 | 85 | ||
86 | spot_taken = false; |
86 | spot_taken = false; |
87 | if(stagger && !(too_wide||too_high)) |
87 | if(stagger && !(too_wide||too_high)) |
88 | for(peek = (WindowPeek)FrontWindow(); peek; peek = peek->nextWindow) |
88 | for(peek = (WindowPeek)FrontWindow(); peek; peek = peek->nextWindow) |
89 | if(peek->visible){ |
89 | if(peek->visible){ |
90 | global_wind_rect((WindowPtr)peek,&r); |
90 | global_wind_rect((WindowPtr)peek,&r); |
91 | if( abs(s->left-r.left) + abs(s->top-r.top) < STAGGER_SLOP ){ |
91 | if( abs(s->left-r.left) + abs(s->top-r.top) < STAGGER_SLOP ){ |
92 | spot_taken = true; |
92 | spot_taken = true; |
93 | h_offset += STAGGER_H; |
93 | h_offset += STAGGER_H; |
94 | v_offset += STAGGER_V; |
94 | v_offset += STAGGER_V; |
95 | break; |
95 | break; |
96 | } |
96 | } |
97 | } |
97 | } |
98 | }while(spot_taken); |
98 | }while(spot_taken); |
99 | } |
99 | } |
100 | 100 | ||
101 | void zoom_to_std_state(WindowPtr w,Boolean force_default,Boolean stagger){ Rect r; |
101 | void zoom_to_std_state(WindowPtr w,Boolean force_default,Boolean stagger){ Rect r; |
102 | calc_std_state(w,force_default,stagger,&r); |
102 | calc_std_state(w,force_default,stagger,&r); |
103 | if(ZOOMABLE(w)){ |
103 | if(ZOOMABLE(w)){ |
104 | set_std_state(w,&r); |
104 | set_std_state(w,&r); |
105 | SetPort(w); |
105 | SetPort(w); |
106 | ZoomWindow(w,inZoomOut,false); |
106 | ZoomWindow(w,inZoomOut,false); |
107 | }else{ |
107 | }else{ |
108 | MoveWindow(w,r.left,r.top,false); |
108 | MoveWindow(w,r.left,r.top,false); |
109 | SizeWindow(w,r.right-r.left,r.bottom-r.top,true/*???*/); |
109 | SizeWindow(w,r.right-r.left,r.bottom-r.top,true/*???*/); |
110 | } |
110 | } |
111 | } |
111 | } |