Question

I want to be able to create a dialog box with 2 textfields in it. I can create a dialog with 1 textfield with code below,

const void* keys[] =
{
kCFUserNotificationAlertHeaderKey,
kCFUserNotificationAlertMessageKey,
kCFUserNotificationAlternateButtonTitleKey,
kCFUserNotificationTextFieldTitlesKey
};

const void* values[] =
{
titleStr,
messageStr,
CFSTR("Cancel"),
labelStr
};

 CFDictionaryRef elements = CFDictionaryCreate(0, keys, values, sizeof(keys)/sizeof(*keys), &kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
          CFShow(elements);

When I add one more key-value pair, e.g. kCFUserNotificationTextFieldTitlesKey with some CFSTR(""), I do not see anything getting updated in the dialog box.

So how can we have multiple textfield, e.g. Username/password, in CFDitionaryCreate().

I read in the documentation that we can have multiple titleKeys with an array, but i am not sure how to do that.

I was able to add one field in the dialog kCFUserNotificationProgressIndicatorValueKey but not able to add same key again.

I am relatively new to OSX and carbon API (which i am aware that is been deprecated) I'd appreciate if I am pointed to the right resource or example which can help me achieve this.

Also, using Cocoa is not an option here. I need to achieve this using carbon.

Was it helpful?

Solution

The value associated with the key kCFUserNotificationTextFieldTitlesKey or kCFUserNotificationTextFieldValuesKey would be an array of strings:

CFTypeRef values[2] = { CFSTR("one"), CFSTR("two") };
CFArrayRef valArray = CFArrayCreate( NULL, values, 2, &kCFTypeArrayCallBacks );

By the way, you're using Core Foundation, not Carbon. Not every C-based API is Carbon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top