[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;
|
---|
| 21 | OSStatus err;
|
---|
[4081] | 22 | fName = nom;
|
---|
[4077] | 23 |
|
---|
| 24 | rootView = ((PIWdg*)par)->GetHIViewRef();
|
---|
| 25 | err = HIViewGetBounds (rootView, &localHIRect);
|
---|
[4081] | 26 |
|
---|
[4077] | 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 |
|
---|
[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 |
|
---|
| 49 | err = InstallEventHandler (GetControlEventTarget (wdgHIView),
|
---|
| 50 | NewEventHandlerUPP (BaseWdgQuartzEventHandler),
|
---|
| 51 | GetEventTypeCount (basewdgSpec),
|
---|
| 52 | (const EventTypeSpec*)&basewdgSpec,
|
---|
| 53 | (void *) this,
|
---|
| 54 | NULL);
|
---|
| 55 |
|
---|
| 56 | HIViewRender(wdgHIView);
|
---|
[4081] | 57 | FinishCreate();
|
---|
[4077] | 58 | mWGrC = new PIGraphicWin(this);
|
---|
[3747] | 59 | }
|
---|
| 60 |
|
---|
[4077] | 61 | /* --Methode-- */
|
---|
[3747] | 62 | PIBaseWdgQuartz::~PIBaseWdgQuartz()
|
---|
| 63 | {
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[4077] | 66 | /* --Methode-- */
|
---|
[3747] | 67 | void PIBaseWdgQuartz::FinishCreate()
|
---|
| 68 | {
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[4077] | 71 | /* --Methode-- */
|
---|
[3747] | 72 | void PIBaseWdgQuartz::ActivatePtrCross()
|
---|
| 73 | {
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[4077] | 76 | /* --Methode-- */
|
---|
[3747] | 77 | void PIBaseWdgQuartz::ActivateButton(int bid)
|
---|
| 78 | {
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[4077] | 81 | /* --Methode-- */
|
---|
[3747] | 82 | void PIBaseWdgQuartz::ActivateMove(int bid)
|
---|
| 83 | {
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[4077] | 86 | /* --Methode-- */
|
---|
[3747] | 87 | void PIBaseWdgQuartz::ActivateKeyboard()
|
---|
| 88 | {
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[4077] | 91 | /* --Methode-- */
|
---|
[3747] | 92 | void PIBaseWdgQuartz::SelPointerShape(PIPointer ptr)
|
---|
| 93 | {
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[4077] | 96 | /* --Methode-- */
|
---|
[3747] | 97 | PIPointer PIBaseWdgQuartz::GetPointerShape()
|
---|
| 98 | {
|
---|
[4077] | 99 | return PI_ArrowPointer;
|
---|
[3747] | 100 | }
|
---|
| 101 |
|
---|
[4077] | 102 | /* --Methode-- */
|
---|
[3747] | 103 | void PIBaseWdgQuartz::AssignKeyboard()
|
---|
| 104 | {
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[4077] | 107 | /* --Methode-- */
|
---|
[3747] | 108 | void PIBaseWdgQuartz::GetLastEventInfo(PIKeyModifier& kmod, unsigned long& tm)
|
---|
| 109 | {
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[4077] | 112 | /* --Methode-- */
|
---|
[3747] | 113 | bool PIBaseWdgQuartz::IsVisible()
|
---|
| 114 | {
|
---|
| 115 | return true;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[4077] | 118 | /* --Methode-- */
|
---|
[3747] | 119 | void PIBaseWdgQuartz::Refresh()
|
---|
| 120 | {
|
---|
[4081] | 121 | // return;
|
---|
| 122 | printf("---->> PIBaseWdgQuartz::Refresh -%s- context:%lx\n",fName,mWGrC->GetCGContext());
|
---|
[4077] | 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 |
|
---|
[3747] | 140 | return;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[4077] | 143 | /* --Methode-- */
|
---|
| 144 | void PIBaseWdgQuartz::eXposeProcess(CGContextRef cg, int x0, int y0, int dx, int dy)
|
---|
[3747] | 145 | {
|
---|
[4081] | 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());
|
---|
[4077] | 154 | Draw(mWGrC, x0, y0, dx, dy);
|
---|
[4081] | 155 | // CGContextRestoreGState (cg);
|
---|
| 156 | CGContextRestoreGState (mWGrC->GetCGContext());
|
---|
[4077] | 157 |
|
---|
[3747] | 158 | return;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[4077] | 161 | /* ============================================================================================================ */
|
---|
| 162 | /* ============================================================================================================ */
|
---|
| 163 | static int counterDraw = 0;
|
---|
| 164 | // Handler
|
---|
| 165 | OSStatus BaseWdgQuartzEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData)
|
---|
| 166 | {
|
---|
| 167 | OSStatus status = noErr;
|
---|
| 168 |
|
---|
| 169 | counterDraw++;
|
---|
| 170 | PIGetEventName(event);
|
---|
| 171 |
|
---|
| 172 | PIBaseWdgQuartz* wdg = (PIBaseWdgQuartz*) userData;
|
---|
[4081] | 173 | printf("\n BaseWdgQuartzEventHandler -%s- (%d) : ", wdg->fName,counterDraw);
|
---|
| 174 | printf("\n");
|
---|
[4077] | 175 |
|
---|
| 176 | CGContextRef cg;
|
---|
[4081] | 177 | WindowRef window;
|
---|
| 178 | Rect bounds;
|
---|
| 179 | if (!wdg)
|
---|
| 180 | return status;
|
---|
| 181 |
|
---|
[4077] | 182 | status = GetEventParameter (event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (CGContextRef), NULL, &cg);
|
---|
| 183 |
|
---|
[4081] | 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 |
|
---|
[4077] | 258 | if (status != noErr)
|
---|
| 259 | {
|
---|
| 260 | printf(" err = %d \n",status);
|
---|
| 261 | }
|
---|
| 262 | else
|
---|
| 263 | {
|
---|
[4081] | 264 | /*
|
---|
| 265 | // wdg->SetQuartzCGContext(cg);
|
---|
[4077] | 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);
|
---|
[4081] | 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 |
|
---|
[4077] | 281 | wdg->eXposeProcess(cg, 0 , 0, dx, dy);
|
---|
[4081] | 282 | */
|
---|
[4077] | 283 | }
|
---|
| 284 |
|
---|
| 285 | return status;
|
---|
| 286 | }
|
---|