source: Sophya/trunk/SophyaPI/PI/Quartz/pistdwdgquartz.cpp@ 4081

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

Conception dun projet XCode pour X et qq methodes vide. Rien de neuf

  • Property svn:executable set to *
File size: 9.7 KB
RevLine 
[3747]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
12vector<PIWdg*> vpiwdg;
13
14static void CommonControlActionCallback (ControlRef theControl, ControlPartCode partCode);
15
16static 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-- */
35PILabelQuartz::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);
[4077]46 err = CreateStaticTextControl (wParent, &wdgRect, cfsrLabel, NULL, &wdgHIView);
[3747]47}
48
49/* --Methode-- */
50PILabelQuartz::~PILabelQuartz()
51{
52}
53
54/* --Methode-- */
55void PILabelQuartz::SetLabel(string const& sLabel)
56{
57 OSStatus err;
58
59 cfsrLabel = CFStringCreateWithCString(kCFAllocatorDefault,sLabel.c_str(),kCFStringEncodingMacRoman);
60 // SetPortWindowPort(wParent);
61
[4077]62 err = SetControlData (wdgHIView,0,kControlEditTextCFStringTag,sizeof(cfsrLabel),(Ptr)&cfsrLabel);
[3747]63
64 return;
65}
66
67
68/* ========== PITextQuartz ========== */
69
70/* --Methode-- */
71PITextQuartz::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-- */
78PITextQuartz::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-- */
85PITextQuartz::~PITextQuartz()
86{
87}
88
89/* --Methode-- */
90void 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);
[4077]96 err = CreateEditUnicodeTextControl (wParent,&wdgRect,unicodeText,false,NULL,&wdgHIView);
[3747]97
98 return;
99}
100
101/* --Methode-- */
102string PITextQuartz::GetText() const
103{
104 CFStringRef str;
105 char* cText;
106
[4077]107 GetControlData(wdgHIView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str),&str,NULL);
[3747]108
109 cText = (char *)CFStringGetCStringPtr(str,kCFStringEncodingMacRoman);
110 string sText(cText);
111 return (sText);
112}
113
114/* --Methode-- */
115void PITextQuartz::SetMutiLineMode(bool mlm)
116{
117 return;
118}
119
120
121/* --Methode-- */
122void PITextQuartz::SetTextEditable(bool te)
123{
124 if (te == false)
[4077]125 DeactivateControl (wdgHIView);
[3747]126
127 return;
128}
129
130/* --Methode-- */
131void PITextQuartz::SetMsg(PIMessage msg)
132{
133}
134
135
136/* ========== PIHITextViewQuartz ========== */
137
138/* --Methode-- */
139PIHITextViewQuartz::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-- */
166PIHITextViewQuartz::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-- */
173PIHITextViewQuartz::~PIHITextViewQuartz()
174{
175}
176
177
178/* --Methode-- */
179void 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-- */
200string 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-- */
219void PIHITextViewQuartz::SetMutiLineMode(bool mlm)
220{
221 return;
222}
223
224
225/* --Methode-- */
226void PIHITextViewQuartz::SetTextEditable(bool te)
227{
228 return;
229}
230
231
232/* --Methode-- */
233void PIHITextViewQuartz::SetMsg(PIMessage msg)
234{
235
236}
237
238/* ========== PIButtonQuartz ========== */
239
240EventTypeSpec controlEvents[] = {{kEventClassControl, kEventControlHit}};
241
242PIButtonQuartz::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
[4077]249 CreatePushButtonControl (par->GetWindowRef(),&wdgRect,title,&wdgHIView);
250 SetControlTitleWithCFString (wdgHIView, title);
[3747]251 _actionProc = NewControlActionUPP (CommonControlActionCallback);
[4077]252 SetControlAction (wdgHIView, _actionProc);
[3747]253 vpiwdg.push_back(this);
254}
255
256
257PIButtonQuartz::~PIButtonQuartz()
258{
259}
260
261void PIButtonQuartz::ActivatePress(bool acp)
262{
263 return;
264}
265
266void PIButtonQuartz::SetLabel(string const& sText)
267{
268 title = CFStringCreateWithCString (NULL, sText.c_str(), kCFStringEncodingMacRoman);
[4077]269 SetControlTitleWithCFString(wdgHIView,title);
[3747]270 return;
271}
272
273
274
275/* ========== PICheckBoxQuartz ========== */
276
277PICheckBoxQuartz::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);
[4077]283 CreateCheckBoxControl (par->GetWindowRef(),&wdgRect,title,0,TRUE,&wdgHIView);
284 SetControlTitleWithCFString (wdgHIView, title);
[3747]285 _actionProc = NewControlActionUPP (CommonControlActionCallback);
[4077]286 SetControlAction (wdgHIView, _actionProc);
287 _state = GetControl32BitValue (wdgHIView);
[3747]288
289 vpiwdg.push_back(this);
290}
291
292
293PICheckBoxQuartz::~PICheckBoxQuartz()
294{
295}
296
297void PICheckBoxQuartz::SetState(bool acp)
298{
299 _state = acp;
300 return;
301}
302
303bool PICheckBoxQuartz::GetState()
304{
[4077]305 _state = GetControl32BitValue (wdgHIView);
[3747]306 printf("GetState : %d ",_state);
307 return _state;
308}
309
310/* ========== PIRadioQuartz ========== */
311
312PIRadioQuartz::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);
[4077]320 CreateRadioButtonControl (par->GetWindowRef(),&wdgRect,title,initialValue,FALSE,&wdgHIView);
321 SetControlTitleWithCFString (wdgHIView, title);
[3747]322 _actionProc = NewControlActionUPP (CommonControlActionCallback);
[4077]323 SetControlAction (wdgHIView, _actionProc);
[3747]324 vpiwdg.push_back(this);
325}
326
327PIRadioQuartz::~PIRadioQuartz()
328{
329}
330
331/* ========== PIRadioGroupQuartz ========== */
332
333PIRadioGroupQuartz::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;
[4077]341 error = CreateRadioGroupControl (par->GetWindowRef(),&wdgRect,&wdgHIView);
[3747]342 _state = 0;
343}
344
345void PIRadioGroupQuartz::AddRadioButton(PIRadio* piRadio)
346{
347 OSErr error;
[4077]348 error = EmbedControl(piRadio->GetHIViewRef(),wdgHIView);
[3747]349
350 return;
351}
352
353PIRadioGroupQuartz::~PIRadioGroupQuartz()
354{
355}
356
[4081]357
358PIScrollBarQuartz::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
364void PIScrollBarQuartz::GetMinMax(int& min, int& max){
365 printf("PIScrollBarQuartz::GetMinMax NOT IMPLEMENTED\n");
366}
367
368
369int PIScrollBarQuartz::GetValue(){
370 printf("PIScrollBarQuartz::GetValue NOT IMPLEMENTED\n");
371 return 0;
372}
373
374
375int PIScrollBarQuartz::GetSlSize(){
376 printf("PIScrollBarQuartz::GetSlSize NOT IMPLEMENTED\n");
377 return 0;
378}
379
380
381void PIScrollBarQuartz::SetMinMax(int, int){
382 printf("PIScrollBarQuartz::SetMinMax NOT IMPLEMENTED\n");
383}
384
385
386void PIScrollBarQuartz::SetSlSize(int){
387 printf("PIScrollBarQuartz::SetSlSize NOT IMPLEMENTED\n");
388}
389
390
391void PIScrollBarQuartz::ActivateDrag(bool){
392 printf("PIScrollBarQuartz::ActivateDrag NOT IMPLEMENTED\n");
393}
394
395
396void PIScrollBarQuartz::SetValue(int){
397 printf("PIScrollBarQuartz::SetValue NOT IMPLEMENTED\n");
398}
399
Note: See TracBrowser for help on using the repository browser.