Rev 193 | Rev 268 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
2 | This file is part of a common library |
||
3 | Copyright (C) 1990-2006 Toby Thain, toby@telegraphics.com.au |
||
4 | |||
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 |
||
7 | the Free Software Foundation; either version 2 of the License, or |
||
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
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 |
||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | */ |
||
19 | |||
20 | #include <controldefinitions.h> |
||
21 | #include <stdio.h> |
||
22 | |||
23 | #include "carbonstuff.h" |
||
24 | |||
25 | #include "scroll.h" |
||
26 | #include "misc.h" // max |
||
27 | #include "calc_std_state.h" // natural_size |
||
28 | #include "qd.h" // WIDTHOF/HEIGHTOF |
||
29 | #include "dbg.h" |
||
30 | |||
31 | pascal void myaction(ControlHandle theControl,short partCode); |
||
32 | pascal void myactionind(void); |
||
33 | |||
34 | static ControlHandle hbar,vbar; |
||
35 | static int lasth,lastv; |
||
36 | static short scroll[4]; |
||
37 | |||
38 | void fix_scrollers(ControlHandle hb,ControlHandle vb,short oldh,short oldv){ |
||
39 | RgnHandle rgn,clip; |
||
40 | GrafPtr save; |
||
41 | WindowRef w; |
||
42 | short dh,dv; |
||
43 | Rect r; |
||
44 | |||
45 | dh = oldh - GetControlValue(hb); |
||
46 | dv = oldv - GetControlValue(vb); |
||
47 | if(dh||dv){ |
||
48 | GetPort(&save); |
||
49 | |||
50 | w = GetControlOwner(hb); |
||
51 | SetPortWindowPort(w); |
||
52 | GetWindowPortBounds(w,&r); |
||
53 | r.right -= SCROLL_BAR_WIDTH-1; |
||
54 | r.bottom -= SCROLL_BAR_WIDTH-1; |
||
55 | ScrollRect(&r,dh,dv,rgn = NewRgn()); |
||
56 | |||
57 | // since this window update is outside the normal BeginUpdate...EndUpdate process, |
||
58 | // the drawing environment will not be clipped to the "invalidated" region: |
||
59 | // we must do this ourselves (doing it here means the draw_window function |
||
60 | // does not need to -- this means it can behave the same whether called from here, |
||
61 | // or for an update event) |
||
62 | // it also means draw_window must respect any clip region already set |
||
63 | GetClip(clip = NewRgn()); |
||
64 | SetClip(rgn); |
||
65 | draw_window(w,rgn); |
||
66 | SetClip(clip); |
||
67 | |||
68 | DisposeRgn(rgn); |
||
69 | |||
70 | SetPort(save); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | void adjust_scrollers(WindowPtr w,short ch,short cv,ControlHandle hs,ControlHandle vs){ |
||
75 | Rect r; |
||
76 | short oh,ov,vh,vv; |
||
77 | |||
78 | GetWindowPortBounds(w,&r); |
||
79 | r.right -= SCROLL_BAR_WIDTH-1; |
||
80 | r.bottom -= SCROLL_BAR_WIDTH-1; |
||
81 | vh = WIDTHOF(r); |
||
82 | vv = HEIGHTOF(r); |
||
83 | |||
84 | // HideControl(hs); HideControl(vs); |
||
85 | |||
86 | SizeControl(hs,vh+2,SCROLL_BAR_WIDTH); |
||
87 | SizeControl(vs,SCROLL_BAR_WIDTH,vv+2); |
||
88 | MoveControl(hs,r.left-1,r.bottom); |
||
89 | MoveControl(vs,r.right,r.top-1); |
||
90 | oh = GetControlValue(hs); |
||
91 | ov = GetControlValue(vs); |
||
92 | SetControlMaximum(hs,max(ch - vh,0)); |
||
93 | SetControlMaximum(vs,max(cv - vv,0)); |
||
94 | fix_scrollers(hs,vs,oh,ov); |
||
95 | #if TARGET_CARBON |
||
96 | SetControlViewSize(hs,vh); |
||
97 | SetControlViewSize(vs,vv); |
||
98 | #endif |
||
99 | |||
100 | // ShowControl(hs); ShowControl(vs); |
||
101 | } |
||
102 | |||
103 | pascal void myaction(ControlHandle theControl,short partCode){ |
||
104 | if(partCode){ |
||
105 | if(partCode != kControlIndicatorPart){ |
||
106 | lasth = GetControlValue(hbar); |
||
107 | lastv = GetControlValue(vbar); |
||
108 | SetControlValue(theControl,GetControlValue(theControl) + scroll[partCode-kControlUpButtonPart]); |
||
109 | } |
||
110 | fix_scrollers(hbar,vbar,lasth,lastv); |
||
111 | lasth = GetControlValue(hbar); |
||
112 | lastv = GetControlValue(vbar); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | void scroll_home(ControlHandle hs,ControlHandle vs){ |
||
117 | short hv = GetControlValue(hs),vv = GetControlValue(vs); |
||
118 | SetControlValue(hs,GetControlMinimum(hs)); |
||
119 | SetControlValue(vs,GetControlMinimum(vs)); |
||
120 | fix_scrollers(hs,vs,hv,vv); |
||
121 | } |
||
122 | |||
123 | void scroll_homev(ControlHandle hs,ControlHandle vs){ |
||
124 | short hv = GetControlValue(hs),vv = GetControlValue(vs); |
||
125 | SetControlValue(vs,GetControlMinimum(vs)); |
||
126 | fix_scrollers(hs,vs,hv,vv); |
||
127 | } |
||
128 | |||
129 | void scroll_end(ControlHandle hs,ControlHandle vs){ |
||
130 | short hv = GetControlValue(hs),vv = GetControlValue(vs); |
||
131 | SetControlValue(hs,GetControlMaximum(hs)); |
||
132 | SetControlValue(vs,GetControlMaximum(vs)); |
||
133 | fix_scrollers(hs,vs,hv,vv); |
||
134 | } |
||
135 | |||
136 | void scroll_endv(ControlHandle hs,ControlHandle vs){ |
||
137 | short hv = GetControlValue(hs),vv = GetControlValue(vs); |
||
138 | SetControlValue(vs,GetControlMaximum(vs)); |
||
139 | fix_scrollers(hs,vs,hv,vv); |
||
140 | } |
||
141 | |||
142 | void calc_scroll_jumps(ControlHandle c,Boolean horiz){ |
||
143 | WindowRef w = GetControlOwner(c); |
||
144 | Rect r; |
||
145 | int i; |
||
146 | |||
147 | GetWindowPortBounds(w,&r); |
||
148 | i = (horiz ? WIDTHOF(r) : HEIGHTOF(r)) - (SCROLL_BAR_WIDTH-1); |
||
149 | scroll[0] = -(scroll[1] = i/10); |
||
150 | scroll[2] = -(scroll[3] = i - scroll[1]); |
||
151 | } |
||
152 | |||
153 | void scroll_pageh(ControlHandle hs,ControlHandle vs,short part){ |
||
154 | hbar = hs; |
||
155 | vbar = vs; |
||
156 | calc_scroll_jumps(hs,false); |
||
157 | myaction(vs,part); |
||
158 | } |
||
159 | |||
160 | void scroll_pagev(ControlHandle hs,ControlHandle vs,short part){ |
||
161 | hbar = hs; |
||
162 | vbar = vs; |
||
163 | calc_scroll_jumps(vs,false); |
||
164 | myaction(vs,part); |
||
165 | } |
||
166 | |||
167 | void do_scroll(EventRecord *e,short part,ControlHandle c,ControlHandle hs,ControlHandle vs){ |
||
168 | ControlActionUPP ca_upp = NewControlActionUPP(myaction); |
||
169 | |||
170 | hbar = hs; |
||
171 | vbar = vs; |
||
172 | |||
173 | lasth = GetControlValue(hs); |
||
174 | lastv = GetControlValue(vs); |
||
175 | |||
176 | calc_scroll_jumps(c,c==hs); |
||
177 | //TrackControl(c,e->where,action_UPP); |
||
178 | HandleControlClick(c,e->where,e->modifiers,ca_upp); |
||
179 | DisposeControlActionUPP(ca_upp); |
||
180 | } |