1 | /*
|
---|
2 | * pistdwdgmosx.cpp
|
---|
3 | * PI
|
---|
4 | *
|
---|
5 | * Created by Bruno MANSOUX on 24/08/07.
|
---|
6 | * Copyright 2007 __MyCompanyName__. All rights reserved.
|
---|
7 | *
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "pistdwdgquartz.h"
|
---|
11 |
|
---|
12 | vector<PIWdg*> vpiwdg;
|
---|
13 |
|
---|
14 | static void CommonControlActionCallback (ControlRef theControl, ControlPartCode partCode);
|
---|
15 |
|
---|
16 | static void CommonControlActionCallback (ControlRef theControl, ControlPartCode partCode)
|
---|
17 | {
|
---|
18 | vector<PIWdg*>::iterator it;
|
---|
19 | for(it = vpiwdg.begin(); it != vpiwdg.end(); it++)
|
---|
20 | {
|
---|
21 | printf ("click : %d \n",(int)(*it)->Msg());
|
---|
22 | if (((*it)->GetHIViewRef()) == theControl)
|
---|
23 | {
|
---|
24 | printf ("Valid : %d \n",(int)(*it)->Msg());
|
---|
25 | (*it)->Send((*it)->Msg(), PIMsg_Click, NULL);
|
---|
26 | break;
|
---|
27 | }
|
---|
28 | }
|
---|
29 | return;
|
---|
30 | }
|
---|
31 |
|
---|
32 | /* ========== PILabelQuartz ========== */
|
---|
33 |
|
---|
34 | /* --Methode-- */
|
---|
35 | PILabelQuartz::PILabelQuartz(PIContainerGen *par, const char *nom, int sx, int sy, int px, int py)
|
---|
36 | : PILabelGen(par, nom, sx, sy, px, py)
|
---|
37 | {
|
---|
38 | OSStatus err;
|
---|
39 | WindowRef wParent;
|
---|
40 |
|
---|
41 | string sNom(nom);
|
---|
42 | wParent = ((PIContainer *)par)->GetWindowRef();
|
---|
43 | SetPortWindowPort(wParent);
|
---|
44 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
45 | cfsrLabel = CFStringCreateWithCString(kCFAllocatorDefault,nom,kCFStringEncodingMacRoman);
|
---|
46 | err = CreateStaticTextControl (wParent, &wdgRect, cfsrLabel, NULL, &wdgHIView);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* --Methode-- */
|
---|
50 | PILabelQuartz::~PILabelQuartz()
|
---|
51 | {
|
---|
52 | }
|
---|
53 |
|
---|
54 | /* --Methode-- */
|
---|
55 | void PILabelQuartz::SetLabel(string const& sLabel)
|
---|
56 | {
|
---|
57 | OSStatus err;
|
---|
58 |
|
---|
59 | cfsrLabel = CFStringCreateWithCString(kCFAllocatorDefault,sLabel.c_str(),kCFStringEncodingMacRoman);
|
---|
60 | // SetPortWindowPort(wParent);
|
---|
61 |
|
---|
62 | err = SetControlData (wdgHIView,0,kControlEditTextCFStringTag,sizeof(cfsrLabel),(Ptr)&cfsrLabel);
|
---|
63 |
|
---|
64 | return;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | /* ========== PITextQuartz ========== */
|
---|
69 |
|
---|
70 | /* --Methode-- */
|
---|
71 | PITextQuartz::PITextQuartz(PIContainerGen *par, const char *nom, int sx, int sy, int px, int py)
|
---|
72 | : PITextGen(par, nom, sx, sy, px, py)
|
---|
73 | {
|
---|
74 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /* --Methode-- */
|
---|
78 | PITextQuartz::PITextQuartz(PIContainerGen* par, const char* nom, bool vsb, bool hsb,
|
---|
79 | int sx, int sy, int px, int py)
|
---|
80 | : PITextGen(par, nom, vsb, hsb, sx, sy, px, py)
|
---|
81 | {
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* --Methode-- */
|
---|
85 | PITextQuartz::~PITextQuartz()
|
---|
86 | {
|
---|
87 | }
|
---|
88 |
|
---|
89 | /* --Methode-- */
|
---|
90 | void PITextQuartz::SetText(string const& s)
|
---|
91 | {
|
---|
92 | OSStatus err;
|
---|
93 | WindowRef wParent = ((PIContainer *)Parent())->GetWindowRef();
|
---|
94 |
|
---|
95 | unicodeText = CFStringCreateWithCString (NULL,(char *)s.c_str(), kCFStringEncodingMacRoman);
|
---|
96 | err = CreateEditUnicodeTextControl (wParent,&wdgRect,unicodeText,false,NULL,&wdgHIView);
|
---|
97 |
|
---|
98 | return;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* --Methode-- */
|
---|
102 | string PITextQuartz::GetText() const
|
---|
103 | {
|
---|
104 | CFStringRef str;
|
---|
105 | char* cText;
|
---|
106 |
|
---|
107 | GetControlData(wdgHIView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str),&str,NULL);
|
---|
108 |
|
---|
109 | cText = (char *)CFStringGetCStringPtr(str,kCFStringEncodingMacRoman);
|
---|
110 | string sText(cText);
|
---|
111 | return (sText);
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* --Methode-- */
|
---|
115 | void PITextQuartz::SetMutiLineMode(bool mlm)
|
---|
116 | {
|
---|
117 | return;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | /* --Methode-- */
|
---|
122 | void PITextQuartz::SetTextEditable(bool te)
|
---|
123 | {
|
---|
124 | if (te == false)
|
---|
125 | DeactivateControl (wdgHIView);
|
---|
126 |
|
---|
127 | return;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /* --Methode-- */
|
---|
131 | void PITextQuartz::SetMsg(PIMessage msg)
|
---|
132 | {
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | /* ========== PIHITextViewQuartz ========== */
|
---|
137 |
|
---|
138 | /* --Methode-- */
|
---|
139 | PIHITextViewQuartz::PIHITextViewQuartz(PIContainerGen *par, const char *nom, int sx, int sy, int px, int py)
|
---|
140 | : PITextGen(par, nom, sx, sy, px, py)
|
---|
141 | {
|
---|
142 | OSStatus err;
|
---|
143 | HIRect hiRect; // = { { 0, 0 }, { 100, 100 } };
|
---|
144 | int ox,oy,fx,fy;
|
---|
145 | int mx,my;
|
---|
146 | WindowRef wParent = ((PIContainer *)par)->GetWindowRef();
|
---|
147 | mx = sx/50;
|
---|
148 | my = sy/50;
|
---|
149 | ox = px+mx;
|
---|
150 | oy = py+my;
|
---|
151 | fx = px+sx-mx;
|
---|
152 | fy = py+sy-my;
|
---|
153 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
154 |
|
---|
155 | SetRect(&userPaneRect,ox,oy,fx,fy);
|
---|
156 | hiRect.origin.x = ox;
|
---|
157 | hiRect.origin.y = oy;
|
---|
158 | hiRect.size.width = fx-ox;
|
---|
159 | hiRect.size.height = fy-oy;
|
---|
160 | err = HITextViewCreate (&hiRect,0,0,&outTextView);
|
---|
161 | err = CreateUserPaneControl (wParent, &userPaneRect,kControlSupportsEmbedding,&fUserPane);
|
---|
162 | err = SetControlVisibility(fUserPane, true, true );
|
---|
163 | }
|
---|
164 |
|
---|
165 | /* --Methode-- */
|
---|
166 | PIHITextViewQuartz::PIHITextViewQuartz(PIContainerGen* par, const char* nom, bool vsb, bool hsb,
|
---|
167 | int sx, int sy, int px, int py)
|
---|
168 | : PITextGen(par, nom, vsb, hsb, sx, sy, px, py)
|
---|
169 | {
|
---|
170 | }
|
---|
171 |
|
---|
172 | /* --Methode-- */
|
---|
173 | PIHITextViewQuartz::~PIHITextViewQuartz()
|
---|
174 | {
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 | /* --Methode-- */
|
---|
179 | void PIHITextViewQuartz::SetText(string const& s)
|
---|
180 | {
|
---|
181 | OSStatus err;
|
---|
182 | CFStringRef cfsrText;
|
---|
183 |
|
---|
184 | cfsrText = CFStringCreateWithCString (NULL,(char *)s.c_str(), kCFStringEncodingMacRoman);
|
---|
185 |
|
---|
186 | TXNObject txn = HITextViewGetTXNObject(outTextView);
|
---|
187 | textLength = CFStringGetLength(cfsrText);
|
---|
188 | uniChars = (UniChar*) malloc( sizeof( UniChar ) * textLength );
|
---|
189 | CFStringGetCharacters(cfsrText, CFRangeMake( 0, textLength ), uniChars );
|
---|
190 | err = TXNSetData(txn,kTXNUnicodeTextData, uniChars, textLength * sizeof( UniChar ), 0, 0 );
|
---|
191 | err = HIViewAddSubview (fUserPane, outTextView);
|
---|
192 | HIViewPlaceInSuperviewAt (outTextView,10,10);
|
---|
193 | ShowControl (fUserPane);
|
---|
194 | err = HIViewSetVisible (outTextView, true);
|
---|
195 |
|
---|
196 | return;
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* --Methode-- */
|
---|
200 | string PIHITextViewQuartz::GetText() const
|
---|
201 | {
|
---|
202 | CFStringRef str;
|
---|
203 | char* cText;
|
---|
204 |
|
---|
205 | GetControlData(outTextView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str),&str,NULL);
|
---|
206 | cText = (char *)CFStringGetCStringPtr(str,kCFStringEncodingMacRoman);
|
---|
207 | /*
|
---|
208 | textLength = CFStringGetLength(str);
|
---|
209 | uniChars = (UniChar*) realloc( sizeof( UniChar ) * textLength );
|
---|
210 | CFStringGetCharacters(str, CFRangeMake( 0, textLength ), uniChars );
|
---|
211 | */
|
---|
212 |
|
---|
213 | string sText(cText);
|
---|
214 | return (sText);
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | /* --Methode-- */
|
---|
219 | void PIHITextViewQuartz::SetMutiLineMode(bool mlm)
|
---|
220 | {
|
---|
221 | return;
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | /* --Methode-- */
|
---|
226 | void PIHITextViewQuartz::SetTextEditable(bool te)
|
---|
227 | {
|
---|
228 | return;
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | /* --Methode-- */
|
---|
233 | void PIHITextViewQuartz::SetMsg(PIMessage msg)
|
---|
234 | {
|
---|
235 |
|
---|
236 | }
|
---|
237 |
|
---|
238 | /* ========== PIButtonQuartz ========== */
|
---|
239 |
|
---|
240 | EventTypeSpec controlEvents[] = {{kEventClassControl, kEventControlHit}};
|
---|
241 |
|
---|
242 | PIButtonQuartz::PIButtonQuartz(PIContainerQuartz *par,const char *nom, PIMessage msg,int sx, int sy, int px, int py)
|
---|
243 | :PIButtonGen(par,nom,msg,sx,sy,px,py)
|
---|
244 | {
|
---|
245 | WindowRef wParent = ((PIContainer *)par)->GetWindowRef();
|
---|
246 | SetPortWindowPort(wParent);
|
---|
247 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
248 |
|
---|
249 | CreatePushButtonControl (par->GetWindowRef(),&wdgRect,title,&wdgHIView);
|
---|
250 | SetControlTitleWithCFString (wdgHIView, title);
|
---|
251 | _actionProc = NewControlActionUPP (CommonControlActionCallback);
|
---|
252 | SetControlAction (wdgHIView, _actionProc);
|
---|
253 | vpiwdg.push_back(this);
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | PIButtonQuartz::~PIButtonQuartz()
|
---|
258 | {
|
---|
259 | }
|
---|
260 |
|
---|
261 | void PIButtonQuartz::ActivatePress(bool acp)
|
---|
262 | {
|
---|
263 | return;
|
---|
264 | }
|
---|
265 |
|
---|
266 | void PIButtonQuartz::SetLabel(string const& sText)
|
---|
267 | {
|
---|
268 | title = CFStringCreateWithCString (NULL, sText.c_str(), kCFStringEncodingMacRoman);
|
---|
269 | SetControlTitleWithCFString(wdgHIView,title);
|
---|
270 | return;
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 |
|
---|
275 | /* ========== PICheckBoxQuartz ========== */
|
---|
276 |
|
---|
277 | PICheckBoxQuartz::PICheckBoxQuartz(PIContainerQuartz *par, const char *nom, PIMessage msg, int sx, int sy, int px, int py)
|
---|
278 | :PICheckBoxGen(par,nom,msg,sx,sy,px,py)
|
---|
279 | {
|
---|
280 | WindowRef wParent = ((PIContainer *)par)->GetWindowRef();
|
---|
281 | SetPortWindowPort(wParent);
|
---|
282 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
283 | CreateCheckBoxControl (par->GetWindowRef(),&wdgRect,title,0,TRUE,&wdgHIView);
|
---|
284 | SetControlTitleWithCFString (wdgHIView, title);
|
---|
285 | _actionProc = NewControlActionUPP (CommonControlActionCallback);
|
---|
286 | SetControlAction (wdgHIView, _actionProc);
|
---|
287 | _state = GetControl32BitValue (wdgHIView);
|
---|
288 |
|
---|
289 | vpiwdg.push_back(this);
|
---|
290 | }
|
---|
291 |
|
---|
292 |
|
---|
293 | PICheckBoxQuartz::~PICheckBoxQuartz()
|
---|
294 | {
|
---|
295 | }
|
---|
296 |
|
---|
297 | void PICheckBoxQuartz::SetState(bool acp)
|
---|
298 | {
|
---|
299 | _state = acp;
|
---|
300 | return;
|
---|
301 | }
|
---|
302 |
|
---|
303 | bool PICheckBoxQuartz::GetState()
|
---|
304 | {
|
---|
305 | _state = GetControl32BitValue (wdgHIView);
|
---|
306 | printf("GetState : %d ",_state);
|
---|
307 | return _state;
|
---|
308 | }
|
---|
309 |
|
---|
310 | /* ========== PIRadioQuartz ========== */
|
---|
311 |
|
---|
312 | PIRadioQuartz::PIRadioQuartz(PIContainerQuartz *par,const char *nom, PIMessage msg,int sx, int sy, int px, int py,
|
---|
313 | int initialValue)
|
---|
314 | :PIWdg(par,nom,sx,sy,px,py)
|
---|
315 | {
|
---|
316 | SetMsg(msg);
|
---|
317 | WindowRef wParent = ((PIContainer *)par)->GetWindowRef();
|
---|
318 | SetPortWindowPort(wParent);
|
---|
319 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
320 | CreateRadioButtonControl (par->GetWindowRef(),&wdgRect,title,initialValue,FALSE,&wdgHIView);
|
---|
321 | SetControlTitleWithCFString (wdgHIView, title);
|
---|
322 | _actionProc = NewControlActionUPP (CommonControlActionCallback);
|
---|
323 | SetControlAction (wdgHIView, _actionProc);
|
---|
324 | vpiwdg.push_back(this);
|
---|
325 | }
|
---|
326 |
|
---|
327 | PIRadioQuartz::~PIRadioQuartz()
|
---|
328 | {
|
---|
329 | }
|
---|
330 |
|
---|
331 | /* ========== PIRadioGroupQuartz ========== */
|
---|
332 |
|
---|
333 | PIRadioGroupQuartz::PIRadioGroupQuartz(PIContainerQuartz *par,const char *nom, PIMessage msg,int sx, int sy, int px, int py)
|
---|
334 | :PIWdg(par,nom,sx,sy,px,py)
|
---|
335 | {
|
---|
336 | SetMsg(msg);
|
---|
337 | WindowRef wParent = ((PIContainer *)par)->GetWindowRef();
|
---|
338 | SetPortWindowPort(wParent);
|
---|
339 | SetRect(&wdgRect,px,py,px+sx,py+sy);
|
---|
340 | OSErr error;
|
---|
341 | error = CreateRadioGroupControl (par->GetWindowRef(),&wdgRect,&wdgHIView);
|
---|
342 | _state = 0;
|
---|
343 | }
|
---|
344 |
|
---|
345 | void PIRadioGroupQuartz::AddRadioButton(PIRadio* piRadio)
|
---|
346 | {
|
---|
347 | OSErr error;
|
---|
348 | error = EmbedControl(piRadio->GetHIViewRef(),wdgHIView);
|
---|
349 |
|
---|
350 | return;
|
---|
351 | }
|
---|
352 |
|
---|
353 | PIRadioGroupQuartz::~PIRadioGroupQuartz()
|
---|
354 | {
|
---|
355 | }
|
---|
356 |
|
---|
357 |
|
---|
358 | PIScrollBarQuartz::PIScrollBarQuartz(PIContainerQuartz *par, const char *nom, PIMessage msg,
|
---|
359 | int dir, int sx, int sy, int px, int py)
|
---|
360 | : PIScrollBarGen(par, nom, msg, dir, sx, sy, px, py){
|
---|
361 | printf("PIScrollBarQuartz:PIScrollBarQuartz: NOT IMPLEMENTED\n");
|
---|
362 | }
|
---|
363 |
|
---|
364 | void PIScrollBarQuartz::GetMinMax(int& min, int& max){
|
---|
365 | printf("PIScrollBarQuartz::GetMinMax NOT IMPLEMENTED\n");
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | int PIScrollBarQuartz::GetValue(){
|
---|
370 | printf("PIScrollBarQuartz::GetValue NOT IMPLEMENTED\n");
|
---|
371 | return 0;
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | int PIScrollBarQuartz::GetSlSize(){
|
---|
376 | printf("PIScrollBarQuartz::GetSlSize NOT IMPLEMENTED\n");
|
---|
377 | return 0;
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | void PIScrollBarQuartz::SetMinMax(int, int){
|
---|
382 | printf("PIScrollBarQuartz::SetMinMax NOT IMPLEMENTED\n");
|
---|
383 | }
|
---|
384 |
|
---|
385 |
|
---|
386 | void PIScrollBarQuartz::SetSlSize(int){
|
---|
387 | printf("PIScrollBarQuartz::SetSlSize NOT IMPLEMENTED\n");
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|
391 | void PIScrollBarQuartz::ActivateDrag(bool){
|
---|
392 | printf("PIScrollBarQuartz::ActivateDrag NOT IMPLEMENTED\n");
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 | void PIScrollBarQuartz::SetValue(int){
|
---|
397 | printf("PIScrollBarQuartz::SetValue NOT IMPLEMENTED\n");
|
---|
398 | }
|
---|
399 |
|
---|
400 | // Global function SetRect
|
---|
401 | void SetRect(Rect* wdgRect,short px,short py,short sright,short sbottom){
|
---|
402 | wdgRect->left = px;
|
---|
403 | wdgRect->right= sright;
|
---|
404 | wdgRect->top = py;
|
---|
405 | wdgRect->bottom = sbottom;
|
---|
406 | }
|
---|
407 |
|
---|