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