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

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

Last version of PI comming from Reza

File size: 4.7 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 HIRect localHIRect;
18 HIViewRef rootView;
19 HIViewRef contentView;
20 OSStatus err;
21
22 rootView = ((PIWdg*)par)->GetHIViewRef();
23 err = HIViewGetBounds (rootView, &localHIRect);
24
25 err = HIScrollViewCreate(kHIScrollViewOptionsVertScroll | kHIScrollViewOptionsHorizScroll, &wdgHIView);
26 err += HIViewSetVisible (wdgHIView, true);
27
28 err += HIViewFindByID(rootView, kHIViewWindowContentID, &contentView);
29 err += HIViewAddSubview (contentView, wdgHIView);
30
31 err += HIViewGetBounds (wdgHIView, &localHIRect);
32
33 localHIRect.origin.x = (float)px;
34 localHIRect.origin.y = (float)py;
35 localHIRect.size.width = (float)sx;
36 localHIRect.size.height = (float)sy;
37
38 err = HIViewSetFrame (wdgHIView, &localHIRect);
39
40 err += HIViewGetFrame (wdgHIView, &localHIRect);
41
42 printf("PIBaseWdgQuartz::PIBaseWdgQuartz Set Frame (%g %g) [%g %g] err : %d \n",
43 localHIRect.origin.x, localHIRect.origin.y,
44 localHIRect.size.width, localHIRect.size.height,
45 err);
46
47 err = InstallEventHandler (GetControlEventTarget (wdgHIView),
48 NewEventHandlerUPP (BaseWdgQuartzEventHandler),
49 GetEventTypeCount (basewdgSpec),
50 (const EventTypeSpec*)&basewdgSpec,
51 (void *) this,
52 NULL);
53
54 HIViewRender(wdgHIView);
55
56 mWGrC = new PIGraphicWin(this);
57}
58
59/* --Methode-- */
60PIBaseWdgQuartz::~PIBaseWdgQuartz()
61{
62}
63
64/* --Methode-- */
65void PIBaseWdgQuartz::FinishCreate()
66{
67}
68
69/* --Methode-- */
70void PIBaseWdgQuartz::ActivatePtrCross()
71{
72}
73
74/* --Methode-- */
75void PIBaseWdgQuartz::ActivateButton(int bid)
76{
77}
78
79/* --Methode-- */
80void PIBaseWdgQuartz::ActivateMove(int bid)
81{
82}
83
84/* --Methode-- */
85void PIBaseWdgQuartz::ActivateKeyboard()
86{
87}
88
89/* --Methode-- */
90void PIBaseWdgQuartz::SelPointerShape(PIPointer ptr)
91{
92}
93
94/* --Methode-- */
95PIPointer PIBaseWdgQuartz::GetPointerShape()
96{
97 return PI_ArrowPointer;
98}
99
100/* --Methode-- */
101void PIBaseWdgQuartz::AssignKeyboard()
102{
103}
104
105/* --Methode-- */
106void PIBaseWdgQuartz::GetLastEventInfo(PIKeyModifier& kmod, unsigned long& tm)
107{
108}
109
110/* --Methode-- */
111bool PIBaseWdgQuartz::IsVisible()
112{
113 return true;
114}
115
116/* --Methode-- */
117void PIBaseWdgQuartz::Refresh()
118{
119 printf("PIBaseWdgQuartz::Refresh ");
120 EventRef rEvent;
121 OSStatus err;
122
123 err = CreateEvent( NULL, kEventClassControl, kEventControlDraw,
124 GetCurrentEventTime(), kEventAttributeNone, &rEvent );
125 SetEventParameter( rEvent, kEventParamCGContextRef, typeCGContextRef, sizeof (CGContextRef), mWGrC->GetCGContext());
126
127 SendEventToEventTarget(rEvent, GetControlEventTarget (wdgHIView));
128
129 HIRect hiRect;
130 HIViewGetFrame(wdgHIView, &hiRect);
131
132 CGContextRestoreGState (mWGrC->GetCGContext());
133 printf(" cg : %lx ox : %g oy : %g width : %g height : %g \n",
134 mWGrC->GetCGContext(), hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height);
135 // mWGrC->SetGCRect(hiRect.origin.x, hiRect.origin.y, hiRect.size.width, hiRect.size.height);
136 // Draw(mWGrC, 0, 0, XSize(), YSize());
137
138 return;
139}
140
141/* --Methode-- */
142void PIBaseWdgQuartz::eXposeProcess(CGContextRef cg, int x0, int y0, int dx, int dy)
143{
144 printf("PIBaseWdgQuartz::ExposeProcess \n");
145 CGContextSaveGState(cg);
146 mWGrC->SetCGContext(cg);
147 mWGrC->SetCTM(CGContextGetCTM(cg));
148 Draw(mWGrC, x0, y0, dx, dy);
149
150 return;
151}
152
153/* ============================================================================================================ */
154/* ============================================================================================================ */
155static int counterDraw = 0;
156// Handler
157OSStatus BaseWdgQuartzEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData)
158{
159 OSStatus status = noErr;
160
161 counterDraw++;
162 printf(" BaseWdgQuartzEventHandler (%d) : ", counterDraw);
163 PIGetEventName(event);
164
165 PIBaseWdgQuartz* wdg = (PIBaseWdgQuartz*) userData;
166
167 CGContextRef cg;
168
169 status = GetEventParameter (event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (CGContextRef), NULL, &cg);
170
171 if (status != noErr)
172 {
173 printf(" err = %d \n",status);
174 }
175 else
176 {
177 // wdg->SetQuartzCGContext(cg);
178 HIViewRef view = wdg->GetHIViewRef();
179 HIRect hiRect;
180 HIViewGetFrame(view, &hiRect);
181 // Pour le moment on rafraichit toute la vue
182 int ox = (int)(hiRect.origin.x);
183 int oy = (int)(hiRect.origin.x);
184 int dx = (int)(hiRect.size.width);
185 int dy = (int)(hiRect.size.height);
186 printf(" BaseWdgQuartzEventHandler cg : %lx [%d %d] Frame [%d, %d] \n", (unsigned long)cg, ox, oy, dx, dy);
187 wdg->eXposeProcess(cg, 0 , 0, dx, dy);
188 }
189
190 return status;
191}
Note: See TracBrowser for help on using the repository browser.