PDA

View Full Version : Problem with Carbon Input Fields




Soulstorm
Apr 9, 2006, 05:52 PM
Hello, I have the following problem. I have made this window:
http://forums.macrumors.com/attachment.php?attachmentid=44803&stc=1&d=1144623001
which is self-explanatory. All command event handlers are handled properly.

There is one problem though. Below is the code that handles the conversion to uppercase:
pascal void MyCommandHandler(WindowRef window){
cout << "handler\n";
ControlHandle stringInTextEdit;
ControlHandle stringOutTextEdit;

ControlID stringInControlID = {kControlSignature, kStringInControlID};
ControlID stringOutControlID = {kControlSignature, kStringOutControlID};

CFMutableStringRef theString;

GetControlByID(window, &stringInControlID, &stringInTextEdit);
GetControlByID(window, &stringOutControlID, &stringOutTextEdit);

GetControlData(stringInTextEdit,
kControlEntireControl,
kControlEditTextCFStringTag,
sizeof(CFStringRef),
&theString,
NULL);

CFStringUppercase(theString,NULL);

SetControlData(stringOutTextEdit,
kControlEntireControl,
kControlEditTextCFStringTag,
sizeof(CFStringRef),
&theString);
DrawOneControl(stringOutTextEdit);

cout << theString;
}the problem is that I don't see any letters drawn on the second text field! What is my fault?



Soulstorm
Apr 9, 2006, 05:59 PM
Problem Solved Moderators Please Remove This Thread

bousozoku
Apr 9, 2006, 06:18 PM
Problem Solved Moderators Please Remove This Thread

You sure that someone else new won't need the answer some day?

Soulstorm
Apr 10, 2006, 10:55 AM
yes, because it was my mistake. no strange programming workarounds here.

iSee
Apr 10, 2006, 01:48 PM
Hmmm, just 7 minutes between the OP and self-found fix.

Actually, having working with teams of programmers for a long time, it is interesting how often this happens: A fellow programmer stuck on something, sometimes for hours, comes to ask for help. Just by explaining the situation and posing the question they suddenly realize what the solution is. :) Sometimes they don't even get half way through the explanation before they say, "Oh wait! never mind, I've got it." and walk away.

Orgainizing your thoughts in order to explain something to someone else is an effective analytical approach.

kainjow
Apr 10, 2006, 01:51 PM
Soulstorm: I'm curious, why are you learning Carbon?

Soulstorm
Apr 10, 2006, 03:40 PM
Soulstorm: I'm curious, why are you learning Carbon?
I've been asking myself the same question over and over again.

The short answer is because I want to have some of my C++ programs use GUI. And I don't know Obj-C, so Carbon is one-way for me.

But so far, all I see is that carbon is really inexplicably difficult. Perhaps I should learn Obj-C and move to Cocoa? Note that I intend to keep my programs Mac-Oriented, so, portability is not my primary concern (if I move to Windows or Linux, I will learn another API, I am 20 years old and I have all my life ahead of me to do so...).

From your question it seems you would advise me against using carbon...

What is your opinion?

kainjow
Apr 10, 2006, 03:47 PM
If you're simply wanting to put a GUI to your C++ programs, and you don't care about Windows or Linux, then Cocoa is the way to go.

Since you're learning Carbon, you mine as well put your efforts into learning Cocoa.

Here's the Objective-C/Cocoa equivalent of what you're trying to do:

- (IBAction)convertToUppercase:(id)sender
{
[textBox2 setStringValue:[[textBox1 stringValue] lowercaseString]];
}
That's it. The main thing about Objective-C/Cocoa is learning Objective-C's syntax, but if you know C/C++, it'll take you about a days worth of learning. Then, it's just a matter of learning the APIs.

There's tons of info about Cocoa over at http://www.cocoadev.com also

Soulstorm
Apr 10, 2006, 05:47 PM
- (IBAction)convertToUppercase:(id)sender
{
[textBox2 setStringValue:[[textBox1 stringValue] lowercaseString]];
}
damn. I am really jealous now. I should learn Obj-C and then move to cocoa... I'm a bit afraid of learning a new language, but since I have a background in OOP with C++, it shouldn't be a problem...

I will go and buy a book tomorrow to learn Obj-C. Any good recommendations?

kainjow
Apr 10, 2006, 05:53 PM
These 2 books are probably the most popular:

Cocoa Programming for Mac OS X (http://www.amazon.com/gp/product/0201726831/ref=pd_sim_books/002-2814893-6864826?n=283155)
Cocoa Programming (http://www.amazon.com/gp/product/0672322307/002-2814893-6864826?n=283155)

Since you already know OOP, and I'm assuming memory management (?), then Objective-C will be a cinch.

caveman_uk
Apr 11, 2006, 03:09 AM
Actually the line should be

[textBox2 setStringValue:[[textBox1 stringValue] uppercaseString]];

if you want to convert to upper case.;)

Seriously objective-C is a pretty easy language. It's miles easier to learn than C++. The hard part is remembering the Cocoa API but then again you're spending a lot of time learning the carbon API so the work learning the Cocoa version should be comparable.

Can I also add Steve Kochan's book (http://www.amazon.com/gp/product/0672325861/qid=1144742662/sr=2-3/ref=pd_bbs_b_2_3/002-1320373-7871242?s=books&v=glance&n=283155) to the list. It's more an Objective-C book than a cocoa book but covers the language well. There's also this primer (http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/index.html?http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/chapter_1_section_1.html) on the Apple site although it's a bit dry...

Soulstorm
Apr 12, 2006, 04:17 AM
I ordered those books from amazon.com.
But when I try to speak to any reseller here in Greece, they don't even know what Obj-C is. They're like "Are you sure there is such a language?".

Is there Obj-C on the PC (I suppose there is)? Is it extensively used, or it is just the most widely used language on the Mac?

caveman_uk
Apr 12, 2006, 09:39 AM
I
Is there Obj-C on the PC (I suppose there is)? Is it extensively used, or it is just the most widely used language on the Mac?
It's not widely used on PC (if at all) and is most extensively used on the mac but it's not a 'closed' language as support for it is built into the GNU gcc compiler. You can compile objective-C code on any system that can use the gcc compiler. You can also use the GNUstep libraries which are an open source version of the NeXTStep libraries which ultimately became Cocoa (http://www.gnustep.org/). If you wanted you could use GNUStep and the gcc compiler to create cross platform code.