1 | /* |
---|
2 | * pibwdgquartz.cpp |
---|
3 | * PI |
---|
4 | * |
---|
5 | * Created by Bruno MANSOUX on 19/09/08. |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "pibwdgquartz.h" |
---|
10 | #include "PIContainerQuartz.h" |
---|
11 | |
---|
12 | OSStatus BaseWdgQuartzEventHandler (EventHandlerCallRef myHandler,EventRef event, void *userData); |
---|
13 | |
---|
14 | PIBaseWdgQuartz::PIBaseWdgQuartz(PIContainerGen *par, const char *nom, int sx, int sy, int px, int py) |
---|
15 | : PIBaseWdgGen(par,nom,sx,sy,px,py) |
---|
16 | { |
---|
17 | |
---|
18 | HIRect localHIRect; |
---|
19 | HIViewRef rootView; |
---|
20 | HIViewRef contentView; |
---|
21 | OSStatus err = 0; |
---|
22 | fName = nom; |
---|
23 | |
---|
24 | rootView = ((PIWdg*)par)->GetHIViewRef(); |
---|
25 | err = HIViewGetBounds (rootView, &localHIRect); |
---|
26 | |
---|
27 | err += HIScrollViewCreate(kHIScrollViewOptionsVertScroll | kHIScrollViewOptionsHorizScroll, &wdgHIView); |
---|
28 | err += HIViewSetVisible (wdgHIView, true); |
---|
29 | |
---|
30 | err += HIViewFindByID(rootView, kHIViewWindowContentID, &contentView); |
---|
31 | err += HIViewAddSubview (contentView, wdgHIView); |
---|
32 | |
---|
33 | err += HIViewGetBounds (wdgHIView, &localHIRect); |
---|
34 | |
---|
35 | localHIRect.origin.x = (float)px; |
---|
36 | localHIRect.origin.y = (float)py; |
---|
37 | localHIRect.size.width = (float)sx; |
---|
38 | localHIRect.size.height = (float)sy; |
---|
39 | |
---|
40 | err += HIViewSetFrame (wdgHIView, &localHIRect); |
---|
41 | |
---|
42 | err += HIViewGetFrame (wdgHIView, &localHIRect); |
---|
43 | |
---|
44 | printf("PIBaseWdgQuartz::PIBaseWdgQuartz Set Frame (%g %g) [%g %g] err : %d nom:%s\n", |
---|
45 | localHIRect.origin.x, localHIRect.origin.y, |
---|
46 | localHIRect.size.width, localHIRect.size.height, |
---|
47 | err,nom); |
---|
48 | |
---|
49 | /* |
---|
50 | err = InstallEventHandler (GetControlEventTarget (wdgHIView), |
---|
51 | NewEventHandlerUPP (BaseWdgQuartzEventHandler), |
---|
52 | GetEventTypeCount (basewdgSpec), |
---|
53 | (const EventTypeSpec*)&basewdgSpec, |
---|
54 | (void *) this, |
---|
55 | NULL); |
---|
56 | */ |
---|
57 | printf("PIBaseWdgQuartz::PIBaseWdgQuartz HIView %d \n",contentView); |
---|
58 | err += HIViewInstallEventHandler (contentView, |
---|
59 | NewEventHandlerUPP (BaseWdgQuartzEventHandler), |
---|
60 | GetEventTypeCount (basewdgSpec), |
---|
61 | (const EventTypeSpec*)&basewdgSpec, |
---|
62 | (void *) contentView, |
---|
63 | NULL); |
---|
64 | |
---|
65 | HIViewRender(contentView); |
---|
66 | mWGrC = new PIGraphicWin(this); |
---|
67 | } |
---|
68 | |
---|
69 | /* --Methode-- */ |
---|
70 | PIBaseWdgQuartz::~PIBaseWdgQuartz() |
---|
71 | { |
---|
72 | } |
---|
73 | |
---|
74 | /* --Methode-- */ |
---|
75 | void PIBaseWdgQuartz::FinishCreate() |
---|
76 | { |
---|
77 | } |
---|
78 | |
---|
79 | /* --Methode-- */ |
---|
80 | void PIBaseWdgQuartz::ActivatePtrCross() |
---|
81 | { |
---|
82 | } |
---|
83 | |
---|
84 | /* --Methode-- */ |
---|
85 | void PIBaseWdgQuartz::ActivateButton(int bid) |
---|
86 | { |
---|
87 | } |
---|
88 | |
---|
89 | /* --Methode-- */ |
---|
90 | void PIBaseWdgQuartz::ActivateMove(int bid) |
---|
91 | { |
---|
92 | } |
---|
93 | |
---|
94 | /* --Methode-- */ |
---|
95 | void PIBaseWdgQuartz::ActivateKeyboard() |
---|
96 | { |
---|
97 | } |
---|
98 | |
---|
99 | /* --Methode-- */ |
---|
100 | void PIBaseWdgQuartz::SelPointerShape(PIPointer ptr) |
---|
101 | { |
---|
102 | } |
---|
103 | |
---|
104 | /* --Methode-- */ |
---|
105 | PIPointer PIBaseWdgQuartz::GetPointerShape() |
---|
106 | { |
---|
107 | return PI_ArrowPointer; |
---|
108 | } |
---|
109 | |
---|
110 | /* --Methode-- */ |
---|
111 | void PIBaseWdgQuartz::AssignKeyboard() |
---|
112 | { |
---|
113 | } |
---|
114 | |
---|
115 | /* --Methode-- */ |
---|
116 | void PIBaseWdgQuartz::GetLastEventInfo(PIKeyModifier& kmod, unsigned long& tm) |
---|
117 | { |
---|
118 | } |
---|
119 | |
---|
120 | /* --Methode-- */ |
---|
121 | bool PIBaseWdgQuartz::IsVisible() |
---|
122 | { |
---|
123 | return true; |
---|
124 | } |
---|
125 | |
---|
126 | /* --Methode-- */ |
---|
127 | void PIBaseWdgQuartz::Refresh() |
---|
128 | { |
---|
129 | // return; |
---|
130 | |
---|
131 | printf("---->> PIBaseWdgQuartz::Refresh -%s- context:%lx\n",fName,mWGrC->GetCGContext()); |
---|
132 | EventRef rEvent; |
---|
133 | OSStatus err; |
---|
134 | |
---|
135 | err = CreateEvent( NULL, kEventClassControl, kEventControlDraw, |
---|
136 | GetCurrentEventTime(), kEventAttributeNone, &rEvent ); |
---|
137 | SetEventParameter( rEvent, kEventParamCGContextRef, typeCGContextRef, sizeof (CGContextRef), mWGrC->GetCGContext()); |
---|
138 | |
---|
139 | SendEventToEventTarget(rEvent, GetControlEventTarget (wdgHIView)); |
---|
140 | |
---|
141 | HIRect hiRect; |
---|
142 | HIViewGetFrame(wdgHIView, &hiRect); |
---|
143 | |
---|
144 | printf(" cg : %lx ox : %g oy : %g width : %g height : %g \n", |
---|
145 | |
---|
146 | mWGrC->GetCGContext(), hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height); |
---|
147 | // mWGrC->SetGCRect(hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height); |
---|
148 | // Draw(mWGrC, 0, 0, XSize(), YSize()); |
---|
149 | |
---|
150 | |
---|
151 | if(wdgHIView){ |
---|
152 | HIViewSetNeedsDisplay(wdgHIView, true); |
---|
153 | printf("---->> PIBaseWdgQuartz::Refresh -%s- \n",fName); |
---|
154 | } |
---|
155 | |
---|
156 | return; |
---|
157 | } |
---|
158 | |
---|
159 | /* --Methode-- */ |
---|
160 | void PIBaseWdgQuartz::eXposeProcess(CGContextRef cg, int x0, int y0, int dx, int dy) |
---|
161 | { |
---|
162 | printf("PIBaseWdgQuartz::ExposeProcess -%s- to x:%d y:%d dx:%d dy:%d\n",fName,x0,y0,dx,dy); |
---|
163 | if (1 == 1) { |
---|
164 | |
---|
165 | if (mWGrC->GetCGContext() == NULL) { |
---|
166 | mWGrC->SetCGContext(cg); |
---|
167 | printf("PIBaseWdgQuartz::ExposeProcess CHANGE context to %lx\n",cg); |
---|
168 | mWGrC->SetCTM(CGContextGetCTM(cg)); |
---|
169 | } else { |
---|
170 | |
---|
171 | // Flip the coordinates by translating and scaling. This produces a |
---|
172 | // coordinate system that matches the Quartz default coordinate system |
---|
173 | // with the origin in the lower-left corner with the y axis pointing up. |
---|
174 | HIRect bounds; |
---|
175 | HIViewGetBounds ((HIViewRef) wdgHIView, &bounds); |
---|
176 | |
---|
177 | // CGContextTranslateCTM(cg, 0, bounds.size.height); |
---|
178 | // CGContextScaleCTM(cg, 1.0, -1.0) |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | printf("PIBaseWdgQuartz::ExposeProcess set CTM to %lx\n",cg); |
---|
183 | CGContextSaveGState(cg); |
---|
184 | Draw(mWGrC, x0, y0, dx, dy); |
---|
185 | // CGContextRestoreGState (cg); |
---|
186 | CGContextRestoreGState (cg); |
---|
187 | |
---|
188 | return; |
---|
189 | } |
---|
190 | |
---|
191 | /* ============================================================================================================ */ |
---|
192 | /* ============================================================================================================ */ |
---|
193 | static int counterDraw = 0; |
---|
194 | // Handler |
---|
195 | OSStatus BaseWdgQuartzEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData) |
---|
196 | { |
---|
197 | OSStatus status = noErr; |
---|
198 | |
---|
199 | counterDraw++; |
---|
200 | PIGetEventName(event); |
---|
201 | |
---|
202 | // PIBaseWdgQuartz* wdg = (PIBaseWdgQuartz*) userData; |
---|
203 | printf("\n BaseWdgQuartzEventHandler (%d) : ",counterDraw); |
---|
204 | printf("\n"); |
---|
205 | |
---|
206 | CGContextRef cg; |
---|
207 | WindowRef window; |
---|
208 | Rect bounds; |
---|
209 | if (!userData) |
---|
210 | return status; |
---|
211 | |
---|
212 | status = GetEventParameter (event, kEventParamCGContextRef, |
---|
213 | typeCGContextRef, NULL, |
---|
214 | sizeof (CGContextRef), |
---|
215 | NULL, |
---|
216 | &cg); |
---|
217 | |
---|
218 | printf("BaseWdgQuartzEventHandler GET EVENT CLASS:%lx KIND %d status:%d\n",(long)GetEventClass(event),(int)GetEventKind(event), status); |
---|
219 | |
---|
220 | /* copy form .h file |
---|
221 | |
---|
222 | static const EventTypeSpec basewdgSpec[] = { |
---|
223 | { kEventClassWindow, kEventWindowResizeCompleted}, |
---|
224 | { kEventClassWindow, kEventWindowDrawContent}, |
---|
225 | { kEventClassHIObject, kEventHIObjectConstruct }, |
---|
226 | { kEventClassHIObject, kEventHIObjectInitialize }, |
---|
227 | { kEventClassHIObject, kEventHIObjectDestruct }, |
---|
228 | { kEventClassControl, kEventControlClick}, |
---|
229 | { kEventClassControl, kEventControlBoundsChanged}, |
---|
230 | { kEventClassControl, kEventControlOwningWindowChanged }, |
---|
231 | { kEventClassControl, kEventControlInitialize }, |
---|
232 | { kEventClassControl, kEventControlGetPartRegion }, |
---|
233 | { kEventClassControl, kEventControlHitTest } |
---|
234 | }; |
---|
235 | */ |
---|
236 | switch(GetEventClass(event)) |
---|
237 | { |
---|
238 | /* case kEventClassTablet: |
---|
239 | case kEventClassMouse: |
---|
240 | if (w->handleMouseEvent(event)) |
---|
241 | result = noErr; |
---|
242 | break; |
---|
243 | case kEventClassKeyboard: |
---|
244 | if (w->handleKeyboardEvent(event)) |
---|
245 | result = noErr; |
---|
246 | break; |
---|
247 | |
---|
248 | */ |
---|
249 | case kEventClassWindow: { |
---|
250 | |
---|
251 | switch (GetEventKind(event)) |
---|
252 | { |
---|
253 | case kEventWindowBoundsChanging: |
---|
254 | // left the code for live-resizing, but it is not used, because of window-refreshing issues... |
---|
255 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &bounds ); |
---|
256 | |
---|
257 | // wdg->adaptResize(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top); |
---|
258 | // wdg->requestRedraw(); |
---|
259 | status = noErr; |
---|
260 | break; |
---|
261 | |
---|
262 | case kEventWindowBoundsChanged: |
---|
263 | InvalWindowRect(window, GetWindowPortBounds(window, &bounds)); |
---|
264 | GetWindowBounds(window, kWindowContentRgn, &bounds); |
---|
265 | // wdg->adaptResize(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top); |
---|
266 | status = noErr; |
---|
267 | break; |
---|
268 | |
---|
269 | case kEventWindowClose: |
---|
270 | // wdg->requestClose(); |
---|
271 | status = noErr; |
---|
272 | break; |
---|
273 | |
---|
274 | default: |
---|
275 | HIViewRef view = (HIViewRef) userData; |
---|
276 | HIRect hiRect; |
---|
277 | HIViewGetFrame(view, &hiRect); |
---|
278 | // Pour le moment on rafraichit toute la vue |
---|
279 | int ox = (int)(hiRect.origin.x); |
---|
280 | int oy = (int)(hiRect.origin.x); |
---|
281 | int dx = (int)(hiRect.size.width); |
---|
282 | int dy = (int)(hiRect.size.height); |
---|
283 | /// wdg->eXposeProcess(cg, 0 , 0, dx, dy); |
---|
284 | break; |
---|
285 | } |
---|
286 | break; |
---|
287 | } |
---|
288 | case kEventClassControl : { |
---|
289 | switch (GetEventKind(event)) |
---|
290 | { |
---|
291 | case kEventControlDraw: { |
---|
292 | // wdg->SetQuartzCGContext(cg); |
---|
293 | HIViewRef view = (HIViewRef) userData; |
---|
294 | HIRect hiRect; |
---|
295 | HIViewGetFrame(view, &hiRect); |
---|
296 | // Pour le moment on rafraichit toute la vue |
---|
297 | int ox = (int)(hiRect.origin.x); |
---|
298 | int oy = (int)(hiRect.origin.x); |
---|
299 | int dx = (int)(hiRect.size.width); |
---|
300 | int dy = (int)(hiRect.size.height); |
---|
301 | printf("-->> PIbWdgquartz::BaseWdgQuartzEventHandler cg : %lx [%d %d] Frame [%d, %d] \n", (unsigned long)cg, ox, oy, dx, dy); |
---|
302 | |
---|
303 | HIRect bounds; |
---|
304 | HIViewGetBounds ((HIViewRef) userData, &bounds); |
---|
305 | printf("-->> PIbWdgquartz::BaseWdgQuartzEventHandler BOUNDS [%f %f] SIZE [%f, %f] \n",hiRect.origin.x,hiRect.origin.y,hiRect.size.width,hiRect.size.height); |
---|
306 | // err = HIViewSetFrame (wdgHIView, &localHIRect); |
---|
307 | |
---|
308 | /// wdg->eXposeProcess(cg, 0 , 0, dx, dy); |
---|
309 | } |
---|
310 | default: { |
---|
311 | printf("unknown: %g\n",GetEventClass(event)); |
---|
312 | break; |
---|
313 | } |
---|
314 | break; |
---|
315 | } |
---|
316 | break; |
---|
317 | } |
---|
318 | default: |
---|
319 | printf("unknown: %g\n",GetEventClass(event)); |
---|
320 | break; |
---|
321 | } |
---|
322 | |
---|
323 | ///// |
---|
324 | |
---|
325 | |
---|
326 | |
---|
327 | if (status != noErr) |
---|
328 | { |
---|
329 | printf(" err = %d \n",status); |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | /* |
---|
334 | // wdg->SetQuartzCGContext(cg); |
---|
335 | HIViewRef view = wdg->GetHIViewRef(); |
---|
336 | HIRect hiRect; |
---|
337 | HIViewGetFrame(view, &hiRect); |
---|
338 | // Pour le moment on rafraichit toute la vue |
---|
339 | int ox = (int)(hiRect.origin.x); |
---|
340 | int oy = (int)(hiRect.origin.x); |
---|
341 | int dx = (int)(hiRect.size.width); |
---|
342 | int dy = (int)(hiRect.size.height); |
---|
343 | printf(" BaseWdgQuartzEventHandler cg : %lx [%d %d] Frame [%d, %d] \n", (unsigned long)cg, ox, oy, dx, dy); |
---|
344 | |
---|
345 | HIRect bounds; |
---|
346 | HIViewGetBounds ((HIViewRef) userData, &bounds); |
---|
347 | printf(" BaseWdgQuartzEventHandler BOUNDS [%f %f] SIZE [%f, %f] \n",hiRect.origin.x,hiRect.origin.y,hiRect.size.width,hiRect.size.height); |
---|
348 | // err = HIViewSetFrame (wdgHIView, &localHIRect); |
---|
349 | |
---|
350 | wdg->eXposeProcess(cg, 0 , 0, dx, dy); |
---|
351 | */ |
---|
352 | } |
---|
353 | |
---|
354 | return status; |
---|
355 | } |
---|