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

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

Conception dun projet XCode pour X et qq methodes vide. Rien de neuf

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