source: Sophya/trunk/SophyaPI/PI/Quartz/pibwdgquartz.cpp@ 4085

Last change on this file since 4085 was 4085, checked in by garnier, 13 years ago

avancements sur PI

File size: 7.8 KB
Line 
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
12OSStatus BaseWdgQuartzEventHandler (EventHandlerCallRef myHandler,EventRef event, void *userData);
13
14PIBaseWdgQuartz::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;
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 err = InstallEventHandler (GetControlEventTarget (wdgHIView),
50 NewEventHandlerUPP (BaseWdgQuartzEventHandler),
51 GetEventTypeCount (basewdgSpec),
52 (const EventTypeSpec*)&basewdgSpec,
53 (void *) this,
54 NULL);
55
56 HIViewRender(wdgHIView);
57 mWGrC = new PIGraphicWin(this);
58}
59
60/* --Methode-- */
61PIBaseWdgQuartz::~PIBaseWdgQuartz()
62{
63}
64
65/* --Methode-- */
66void PIBaseWdgQuartz::FinishCreate()
67{
68}
69
70/* --Methode-- */
71void PIBaseWdgQuartz::ActivatePtrCross()
72{
73}
74
75/* --Methode-- */
76void PIBaseWdgQuartz::ActivateButton(int bid)
77{
78}
79
80/* --Methode-- */
81void PIBaseWdgQuartz::ActivateMove(int bid)
82{
83}
84
85/* --Methode-- */
86void PIBaseWdgQuartz::ActivateKeyboard()
87{
88}
89
90/* --Methode-- */
91void PIBaseWdgQuartz::SelPointerShape(PIPointer ptr)
92{
93}
94
95/* --Methode-- */
96PIPointer PIBaseWdgQuartz::GetPointerShape()
97{
98 return PI_ArrowPointer;
99}
100
101/* --Methode-- */
102void PIBaseWdgQuartz::AssignKeyboard()
103{
104}
105
106/* --Methode-- */
107void PIBaseWdgQuartz::GetLastEventInfo(PIKeyModifier& kmod, unsigned long& tm)
108{
109}
110
111/* --Methode-- */
112bool PIBaseWdgQuartz::IsVisible()
113{
114 return true;
115}
116
117/* --Methode-- */
118void PIBaseWdgQuartz::Refresh()
119{
120// return;
121 printf("---->> PIBaseWdgQuartz::Refresh -%s- context:%lx\n",fName,mWGrC->GetCGContext());
122 EventRef rEvent;
123 OSStatus err;
124
125 err = CreateEvent( NULL, kEventClassControl, kEventControlDraw,
126 GetCurrentEventTime(), kEventAttributeNone, &rEvent );
127 SetEventParameter( rEvent, kEventParamCGContextRef, typeCGContextRef, sizeof (CGContextRef), mWGrC->GetCGContext());
128
129 SendEventToEventTarget(rEvent, GetControlEventTarget (wdgHIView));
130
131 HIRect hiRect;
132 HIViewGetFrame(wdgHIView, &hiRect);
133
134 printf(" cg : %lx ox : %g oy : %g width : %g height : %g \n",
135 mWGrC->GetCGContext(), hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height);
136 // mWGrC->SetGCRect(hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height);
137 // Draw(mWGrC, 0, 0, XSize(), YSize());
138
139 return;
140}
141
142/* --Methode-- */
143void PIBaseWdgQuartz::eXposeProcess(CGContextRef cg, int x0, int y0, int dx, int dy)
144{
145 printf("PIBaseWdgQuartz::ExposeProcess -%s- to x:%d y:%d dx:%d dy:%d\n",fName,x0,y0,dx,dy);
146 if (mWGrC->GetCGContext() == NULL) {
147 mWGrC->SetCGContext(cg);
148 printf("PIBaseWdgQuartz::ExposeProcess CHANGE context to %lx\n",cg);
149 mWGrC->SetCTM(CGContextGetCTM(cg));
150 }
151 printf("PIBaseWdgQuartz::ExposeProcess set CTM to %lx\n",cg);
152 CGContextSaveGState(mWGrC->GetCGContext());
153 Draw(mWGrC, x0, y0, dx, dy);
154// CGContextRestoreGState (cg);
155 CGContextRestoreGState (mWGrC->GetCGContext());
156
157 return;
158}
159
160/* ============================================================================================================ */
161/* ============================================================================================================ */
162static int counterDraw = 0;
163// Handler
164OSStatus BaseWdgQuartzEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData)
165{
166 OSStatus status = noErr;
167
168 counterDraw++;
169 PIGetEventName(event);
170
171 PIBaseWdgQuartz* wdg = (PIBaseWdgQuartz*) userData;
172 printf("\n BaseWdgQuartzEventHandler -%s- (%d) : ", wdg->fName,counterDraw);
173 printf("\n");
174
175 CGContextRef cg;
176 WindowRef window;
177 Rect bounds;
178 if (!wdg)
179 return status;
180
181 status = GetEventParameter (event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (CGContextRef), NULL, &cg);
182
183 switch(GetEventClass(event))
184 {
185/* case kEventClassTablet:
186 case kEventClassMouse:
187 if (w->handleMouseEvent(event))
188 result = noErr;
189 break;
190 case kEventClassKeyboard:
191 if (w->handleKeyboardEvent(event))
192 result = noErr;
193 break;
194
195*/ case kEventClassWindow: {
196
197 switch (GetEventKind(event))
198 {
199 case kEventWindowBoundsChanging:
200 // left the code for live-resizing, but it is not used, because of window-refreshing issues...
201 GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &bounds );
202
203// wdg->adaptResize(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
204// wdg->requestRedraw();
205 status = noErr;
206 break;
207
208 case kEventWindowBoundsChanged:
209 InvalWindowRect(window, GetWindowPortBounds(window, &bounds));
210 GetWindowBounds(window, kWindowContentRgn, &bounds);
211// wdg->adaptResize(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
212 status = noErr;
213 break;
214
215 case kEventWindowClose:
216// wdg->requestClose();
217 status = noErr;
218 break;
219
220 default:
221 break;
222 }
223 break;
224 }
225 case kEventClassControl : {
226 case kEventControlDraw: {
227 // wdg->SetQuartzCGContext(cg);
228 HIViewRef view = wdg->GetHIViewRef();
229 HIRect hiRect;
230 HIViewGetFrame(view, &hiRect);
231 // Pour le moment on rafraichit toute la vue
232 int ox = (int)(hiRect.origin.x);
233 int oy = (int)(hiRect.origin.x);
234 int dx = (int)(hiRect.size.width);
235 int dy = (int)(hiRect.size.height);
236 printf("-->> PIbWdgquartz::BaseWdgQuartzEventHandler -%s- cg : %lx [%d %d] Frame [%d, %d] \n", wdg->fName,(unsigned long)cg, ox, oy, dx, dy);
237
238 HIRect bounds;
239 HIViewGetBounds ((HIViewRef) userData, &bounds);
240 printf("-->> PIbWdgquartz::BaseWdgQuartzEventHandler BOUNDS [%f %f] SIZE [%f, %f] \n",hiRect.origin.x,hiRect.origin.y,hiRect.size.width,hiRect.size.height);
241 // err = HIViewSetFrame (wdgHIView, &localHIRect);
242
243 wdg->eXposeProcess(cg, 0 , 0, dx, dy);
244 }
245 break;
246 }
247 break;
248 default:
249 printf("unknown: %g\n",GetEventClass(event));
250 break;
251 }
252
253 /////
254
255
256
257 if (status != noErr)
258 {
259 printf(" err = %d \n",status);
260 }
261 else
262 {
263/*
264 // wdg->SetQuartzCGContext(cg);
265 HIViewRef view = wdg->GetHIViewRef();
266 HIRect hiRect;
267 HIViewGetFrame(view, &hiRect);
268 // Pour le moment on rafraichit toute la vue
269 int ox = (int)(hiRect.origin.x);
270 int oy = (int)(hiRect.origin.x);
271 int dx = (int)(hiRect.size.width);
272 int dy = (int)(hiRect.size.height);
273 printf(" BaseWdgQuartzEventHandler cg : %lx [%d %d] Frame [%d, %d] \n", (unsigned long)cg, ox, oy, dx, dy);
274
275 HIRect bounds;
276 HIViewGetBounds ((HIViewRef) userData, &bounds);
277 printf(" BaseWdgQuartzEventHandler BOUNDS [%f %f] SIZE [%f, %f] \n",hiRect.origin.x,hiRect.origin.y,hiRect.size.width,hiRect.size.height);
278// err = HIViewSetFrame (wdgHIView, &localHIRect);
279
280 wdg->eXposeProcess(cg, 0 , 0, dx, dy);
281*/
282 }
283
284 return status;
285}
Note: See TracBrowser for help on using the repository browser.