[3747] | 1 | /*
|
---|
| 2 | * pibwdgquartz.cpp
|
---|
| 3 | * PI
|
---|
| 4 | *
|
---|
| 5 | * Created by Bruno MANSOUX on 19/09/08.
|
---|
| 6 | *
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #include "pibwdgquartz.h"
|
---|
[4077] | 10 | #include "PIContainerQuartz.h"
|
---|
[3747] | 11 |
|
---|
[4077] | 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)
|
---|
[3747] | 15 | : PIBaseWdgGen(par,nom,sx,sy,px,py)
|
---|
| 16 | {
|
---|
[4081] | 17 |
|
---|
| 18 | HIRect localHIRect;
|
---|
[4077] | 19 | HIViewRef rootView;
|
---|
| 20 | HIViewRef contentView;
|
---|
[4086] | 21 | OSStatus err = 0;
|
---|
[4081] | 22 | fName = nom;
|
---|
[4077] | 23 |
|
---|
| 24 | rootView = ((PIWdg*)par)->GetHIViewRef();
|
---|
| 25 | err = HIViewGetBounds (rootView, &localHIRect);
|
---|
[4081] | 26 |
|
---|
[4086] | 27 | err += HIScrollViewCreate(kHIScrollViewOptionsVertScroll | kHIScrollViewOptionsHorizScroll, &wdgHIView);
|
---|
[4077] | 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 |
|
---|
[4086] | 40 | err += HIViewSetFrame (wdgHIView, &localHIRect);
|
---|
[4077] | 41 |
|
---|
| 42 | err += HIViewGetFrame (wdgHIView, &localHIRect);
|
---|
| 43 |
|
---|
[4081] | 44 | printf("PIBaseWdgQuartz::PIBaseWdgQuartz Set Frame (%g %g) [%g %g] err : %d nom:%s\n",
|
---|
[4077] | 45 | localHIRect.origin.x, localHIRect.origin.y,
|
---|
| 46 | localHIRect.size.width, localHIRect.size.height,
|
---|
[4081] | 47 | err,nom);
|
---|
[4077] | 48 |
|
---|
[4086] | 49 | /*
|
---|
| 50 | err = InstallEventHandler (GetControlEventTarget (wdgHIView),
|
---|
[4077] | 51 | NewEventHandlerUPP (BaseWdgQuartzEventHandler),
|
---|
| 52 | GetEventTypeCount (basewdgSpec),
|
---|
| 53 | (const EventTypeSpec*)&basewdgSpec,
|
---|
| 54 | (void *) this,
|
---|
| 55 | NULL);
|
---|
[4086] | 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);
|
---|
[4077] | 64 |
|
---|
[4086] | 65 | HIViewRender(contentView);
|
---|
[4077] | 66 | mWGrC = new PIGraphicWin(this);
|
---|
[3747] | 67 | }
|
---|
| 68 |
|
---|
[4077] | 69 | /* --Methode-- */
|
---|
[3747] | 70 | PIBaseWdgQuartz::~PIBaseWdgQuartz()
|
---|
| 71 | {
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[4077] | 74 | /* --Methode-- */
|
---|
[3747] | 75 | void PIBaseWdgQuartz::FinishCreate()
|
---|
| 76 | {
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[4077] | 79 | /* --Methode-- */
|
---|
[3747] | 80 | void PIBaseWdgQuartz::ActivatePtrCross()
|
---|
| 81 | {
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[4077] | 84 | /* --Methode-- */
|
---|
[3747] | 85 | void PIBaseWdgQuartz::ActivateButton(int bid)
|
---|
| 86 | {
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[4077] | 89 | /* --Methode-- */
|
---|
[3747] | 90 | void PIBaseWdgQuartz::ActivateMove(int bid)
|
---|
| 91 | {
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[4077] | 94 | /* --Methode-- */
|
---|
[3747] | 95 | void PIBaseWdgQuartz::ActivateKeyboard()
|
---|
| 96 | {
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[4077] | 99 | /* --Methode-- */
|
---|
[3747] | 100 | void PIBaseWdgQuartz::SelPointerShape(PIPointer ptr)
|
---|
| 101 | {
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[4077] | 104 | /* --Methode-- */
|
---|
[3747] | 105 | PIPointer PIBaseWdgQuartz::GetPointerShape()
|
---|
| 106 | {
|
---|
[4077] | 107 | return PI_ArrowPointer;
|
---|
[3747] | 108 | }
|
---|
| 109 |
|
---|
[4077] | 110 | /* --Methode-- */
|
---|
[3747] | 111 | void PIBaseWdgQuartz::AssignKeyboard()
|
---|
| 112 | {
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[4077] | 115 | /* --Methode-- */
|
---|
[3747] | 116 | void PIBaseWdgQuartz::GetLastEventInfo(PIKeyModifier& kmod, unsigned long& tm)
|
---|
| 117 | {
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[4077] | 120 | /* --Methode-- */
|
---|
[3747] | 121 | bool PIBaseWdgQuartz::IsVisible()
|
---|
| 122 | {
|
---|
| 123 | return true;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[4077] | 126 | /* --Methode-- */
|
---|
[3747] | 127 | void PIBaseWdgQuartz::Refresh()
|
---|
| 128 | {
|
---|
[4081] | 129 | // return;
|
---|
[4086] | 130 |
|
---|
| 131 | printf("---->> PIBaseWdgQuartz::Refresh -%s- context:%lx\n",fName,mWGrC->GetCGContext());
|
---|
[4077] | 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",
|
---|
[4086] | 145 |
|
---|
| 146 | mWGrC->GetCGContext(), hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height);
|
---|
[4077] | 147 | // mWGrC->SetGCRect(hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height);
|
---|
| 148 | // Draw(mWGrC, 0, 0, XSize(), YSize());
|
---|
| 149 |
|
---|
[4086] | 150 |
|
---|
| 151 | if(wdgHIView){
|
---|
| 152 | HIViewSetNeedsDisplay(wdgHIView, true);
|
---|
| 153 | printf("---->> PIBaseWdgQuartz::Refresh -%s- \n",fName);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[3747] | 156 | return;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[4077] | 159 | /* --Methode-- */
|
---|
| 160 | void PIBaseWdgQuartz::eXposeProcess(CGContextRef cg, int x0, int y0, int dx, int dy)
|
---|
[3747] | 161 | {
|
---|
[4081] | 162 | printf("PIBaseWdgQuartz::ExposeProcess -%s- to x:%d y:%d dx:%d dy:%d\n",fName,x0,y0,dx,dy);
|
---|
[4086] | 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);
|
---|
[4077] | 184 | Draw(mWGrC, x0, y0, dx, dy);
|
---|
[4081] | 185 | // CGContextRestoreGState (cg);
|
---|
[4086] | 186 | CGContextRestoreGState (cg);
|
---|
[4077] | 187 |
|
---|
[3747] | 188 | return;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[4077] | 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 |
|
---|
[4086] | 202 | // PIBaseWdgQuartz* wdg = (PIBaseWdgQuartz*) userData;
|
---|
| 203 | printf("\n BaseWdgQuartzEventHandler (%d) : ",counterDraw);
|
---|
[4081] | 204 | printf("\n");
|
---|
[4077] | 205 |
|
---|
| 206 | CGContextRef cg;
|
---|
[4081] | 207 | WindowRef window;
|
---|
| 208 | Rect bounds;
|
---|
[4086] | 209 | if (!userData)
|
---|
[4081] | 210 | return status;
|
---|
| 211 |
|
---|
[4086] | 212 | status = GetEventParameter (event, kEventParamCGContextRef,
|
---|
| 213 | typeCGContextRef, NULL,
|
---|
| 214 | sizeof (CGContextRef),
|
---|
| 215 | NULL,
|
---|
| 216 | &cg);
|
---|
[4077] | 217 |
|
---|
[4086] | 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 | */
|
---|
[4081] | 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 |
|
---|
[4086] | 248 | */
|
---|
| 249 | case kEventClassWindow: {
|
---|
[4081] | 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 |
|
---|
[4086] | 257 | // wdg->adaptResize(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
|
---|
| 258 | // wdg->requestRedraw();
|
---|
[4081] | 259 | status = noErr;
|
---|
| 260 | break;
|
---|
| 261 |
|
---|
| 262 | case kEventWindowBoundsChanged:
|
---|
| 263 | InvalWindowRect(window, GetWindowPortBounds(window, &bounds));
|
---|
| 264 | GetWindowBounds(window, kWindowContentRgn, &bounds);
|
---|
[4086] | 265 | // wdg->adaptResize(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
|
---|
[4081] | 266 | status = noErr;
|
---|
| 267 | break;
|
---|
| 268 |
|
---|
| 269 | case kEventWindowClose:
|
---|
| 270 | // wdg->requestClose();
|
---|
| 271 | status = noErr;
|
---|
| 272 | break;
|
---|
| 273 |
|
---|
[4086] | 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);
|
---|
[4081] | 284 | break;
|
---|
| 285 | }
|
---|
| 286 | break;
|
---|
| 287 | }
|
---|
| 288 | case kEventClassControl : {
|
---|
[4086] | 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 | }
|
---|
[4081] | 316 | break;
|
---|
[4086] | 317 | }
|
---|
[4081] | 318 | default:
|
---|
| 319 | printf("unknown: %g\n",GetEventClass(event));
|
---|
| 320 | break;
|
---|
[4086] | 321 | }
|
---|
[4081] | 322 |
|
---|
| 323 | /////
|
---|
| 324 |
|
---|
| 325 |
|
---|
| 326 |
|
---|
[4077] | 327 | if (status != noErr)
|
---|
| 328 | {
|
---|
| 329 | printf(" err = %d \n",status);
|
---|
| 330 | }
|
---|
| 331 | else
|
---|
| 332 | {
|
---|
[4081] | 333 | /*
|
---|
| 334 | // wdg->SetQuartzCGContext(cg);
|
---|
[4077] | 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);
|
---|
[4081] | 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 |
|
---|
[4077] | 350 | wdg->eXposeProcess(cg, 0 , 0, dx, dy);
|
---|
[4081] | 351 | */
|
---|
[4077] | 352 | }
|
---|
| 353 |
|
---|
| 354 | return status;
|
---|
| 355 | }
|
---|