void
GetServiceTypeToLookup(CFMutableStringRef * serviceString, UInt16 * serviceMenuItem)
{
    ControlID 		controlID = { kNSLSample, kServicesTypePopup };
    ControlRef		control;
    CFStringRef		outString;
    MenuRef		menu;
    SInt16		value;
    OSStatus		err;
    
    err = GetControlByID(gMainWindow, &controlID, &control);
    if (err == noErr)
    {
        value = GetControlValue(control);
        if (serviceString)
        {
            menu = GetControlPopupMenuHandle(control);
            if (menu)
            {
                CopyMenuItemTextAsCFString(menu, value, &outString);
                if (serviceString)
                {
                    *serviceString = CFStringCreateMutableCopy(NULL, CFStringGetLength(outString), outString);
                    CFStringLowercase(*serviceString, NULL);
                }
                if (outString) CFRelease(outString);
            }
        }
        
        if (serviceMenuItem) *serviceMenuItem = value;
    }
}
void
AddServiceToPopupMenu(char * serviceType, UInt16 serviceLen, UInt16 * serviceMenuItem)
{
    ControlID 		controlID = { kNSLSample, kServicesTypePopup };
    ControlRef		control;
    CFStringRef		tempService = NULL;
    CFStringRef    	menuText = NULL;
    char		tempServiceString[kMaxTypeNameLength];
    CFComparisonResult	result = -1;
    MenuRef		menu;
    OSStatus		err = noErr;
    short		itemCount, i;
    
    if (serviceType)
    {
        err = GetControlByID(gMainWindow, &controlID, &control);
        if (err == noErr)
        {
            strncpy(tempServiceString, serviceType, serviceLen);
            tempServiceString[serviceLen] = '\0';
            
            for (i = 0; i < serviceLen; i++) tempServiceString[i] = toupper(tempServiceString[i]);
            
            tempService = CFStringCreateWithCString(NULL, tempServiceString, CFStringGetSystemEncoding());
            if (tempService)
            {
                menu = GetControlPopupMenuHandle(control);
                itemCount = CountMenuItems(menu);
                
                for (i = 1; i <= itemCount; i ++)
                {
                    CopyMenuItemTextAsCFString(menu, i , &menuText);
                    if (menuText)
                    {                        
                        result = CFStringCompare(menuText, tempService, kCFCompareCaseInsensitive);
                        if (result == kCFCompareEqualTo)
                        {
                            if (serviceMenuItem) *serviceMenuItem = i;
                            break;
                        }
                    }
                }
                
                if (result != kCFCompareEqualTo)
                {
                    err = AppendMenuItemTextWithCFString(menu, tempService, 0, 0, serviceMenuItem);
                    if (err == noErr)
                    {
                        SetControlMaximum(control, itemCount + 1);
                        if (serviceMenuItem) *serviceMenuItem = itemCount + 1;
                    }
                    CFRelease(tempService);
                }
            }
        }
    }
}
Exemple #3
0
/*	GetDialogPopupMenuMenuHandle(theDialog, popupItemNumber, mhP)

	Thread Safety: GetDialogPopupMenuMenuHandle is not thread-safe.
*/
static int
GetDialogPopupMenuMenuHandle(DialogPtr theDialog, int popupItemNumber, MenuHandle* mhP)
{
	ControlRef controlH;
	int err;

	*mhP = NULL;
	
	if (err = XOPGetDialogItemAsControl(theDialog, popupItemNumber, &controlH))
		return err;
		
	*mhP = GetControlPopupMenuHandle(controlH);
	if (*mhP == 0)
		return -1;

	return 0;
}
Exemple #4
0
OSStatus
OPL_LoginDialog::handleCommandEvent(UInt32 commandID)
{
    UInt32 idx;
    CFStringRef str;
    char *dsn;
    char tmp_path[1024];

    switch (commandID) {
    case 'SDIR':
        ControlRef f_select;
        CFStringRef menuText;
        MenuRef menu;

        getControl(kLoginDIR, &f_select);
        menu = GetControlPopupMenuHandle(f_select);
        idx = GetControlValue (f_select);
        CopyMenuItemTextAsCFString(menu, idx, &menuText);
        CFStringGetCString(menuText, tmp_path, sizeof(tmp_path), kCFStringEncodingUTF8);
        CFRelease(menuText);

        loadFDSNList(tmp_path);
        return noErr;

    case 'SFDS':
        idx = fdsnlist->getSelectedItem();
        if (idx && !fdsnlist->getItemType(idx))
        {   // set DSN
            dsn = OPL_CFString_to_char(fdsnlist->getItem(idx));
            str = OPL_CFString_asprintf("%s/%s", cur_dir, dsn);
            setEditText(kLoginDSN, str);
            free(dsn);
        }
        return noErr;

    case 'SDS ':
        idx = dsnlist->getSelectedItem();
        if (idx)
            setEditText(kLoginDSN, CFStringCreateCopy(NULL, dsnlist->getItem(idx)));
        return noErr;

    default:
        return OPL_Dialog::handleCommandEvent(commandID);
    }
}
Exemple #5
0
void
OPL_LoginDialog::fill_dir_menu(char *path)
{
    char *tmp_dir, *prov, *dir;
    MenuRef items_m;
    int i = -1;
    ControlRef f_select;

    getControl(kLoginDIR, &f_select);

    if (!path || !(prov = strdup (path)))
        return;

    if (prov[strlen(prov) - 1] == '/' && strlen(prov) > 1)
        prov[strlen(prov) - 1] = 0;

    items_m = GetControlPopupMenuHandle (f_select);
    DeleteMenuItems (items_m, 1, CountMenuItems (items_m));

    /* Add the root directory */
    AppendMenuItemTextWithCFString(items_m, CFSTR("/"), 0, 0, NULL);

    for (tmp_dir = prov, dir = NULL; tmp_dir;
            tmp_dir = strchr (tmp_dir + 1, '/'))
    {
        if (strchr (tmp_dir + 1, '/'))
        {
            dir = strchr (tmp_dir + 1, '/');
            *dir = 0;
        }

        AppendMenuItemTextWithCFString(items_m, OPL_char_to_CFString(prov), 0, 0, NULL);

        if (dir)
            *dir = '/';
    }
    i = CountMenuItems (items_m);
    SetControlMaximum (f_select, i);
    SetControlValue (f_select, i);
    if (cur_dir)
        free(cur_dir);
    cur_dir = prov;
}
Exemple #6
0
static void fill_dir_menu(TDSNCHOOSER *dsnchoose_t, char *path)
{
  char *curr_dir, *prov, *dir;
  MenuRef items_m;
  int i = -1;
  CFStringRef str;
  ControlRef f_select = dsnchoose_t->fdir;

  if (!path || !(prov = strdup (path)))
    return;

  if (prov[strlen(prov) - 1] == '/' && strlen(prov) > 1)
    prov[strlen(prov) - 1] = 0;

  items_m = GetControlPopupMenuHandle (f_select);
  DeleteMenuItems (items_m, 1, CountMenuItems (items_m));

  /* Add the root directory */
  AppendMenuItemTextWithCFString(items_m, CFSTR("/"), 0, 0, NULL);

  if (strlen(prov) > 1)
    for (curr_dir = prov, dir = NULL; curr_dir;
          curr_dir = strchr (curr_dir + 1, '/'))
      {
        if (strchr (curr_dir + 1, '/'))
	  {
	    dir = strchr (curr_dir + 1, '/');
	    *dir = 0;
	  }

        str = CFStringCreateWithCString(NULL, prov, kCFStringEncodingUTF8);
        AppendMenuItemTextWithCFString(items_m, str, 0, 0, NULL);

        if (dir)
	  *dir = '/';
      }

  i = CountMenuItems (items_m);
  SetControlMaximum (f_select, i);
  SetControlValue (f_select, i);
  strncpy(dsnchoose_t->curr_dir, prov, sizeof(dsnchoose_t->curr_dir));
}
Exemple #7
0
/*	CreatePopMenu(theDialog, popupItemNumber, titleItemNumber, itemList, initialItem)

	Creates a popup menu in the specified dialog.
	
	popupItemNumber is the dialog item number for the popup menu.
	On Macintosh, this must be a CNTL item representing a popup button control.
	See notes above under "About Carbon Popup Menus".
	
	titleItemNumber is the dialog item number for the static text title for the popup menu.
	Prior to XOP Toolkit 5, on Macintosh, this item was highlighted when the user
	clicked on the popup menu. As of XOP Toolkit 5, it is no longer used by must be
	present for backward compatibility.
	
	itemList is a semicolon-separated list of items to insert into the menu.
	For example, "Red;Green;Blue".
	
	initialItem is the 1-based number of the item in the popup menu that should
	be initially selected.
	
	The menu handle allocated here will be disposed when you call KillPopMenus
	at the end of the dialog.
	
	In contrast to Macintosh menu manager routines, this routine does not
	treat any characters as meta-characters.

	Thread Safety: CreatePopMenu is not thread-safe.
*/
int
CreatePopMenu(DialogPtr theDialog, int popupItemNumber, int titleItemNumber, const char* itemList, int initialItem)
{
	MenuHandle mH;
	ControlHandle controlH;
	int menuID;
	int i;
	int err;

	if (gPopMenuInfoP == NULL) {
		// gPopMenuInfoP is used by KillPopMenusAfterDialogIsKilled to keep track of which menu IDs are free for use with popup menus.
		gPopMenuInfoP = (XOPPopMenuInfo*)NewPtrClear(MAX_POPUP_MENUS*(sizeof(XOPPopMenuInfo)));	// Assume never more than MAX_POPUP_MENUS popups.
		if (gPopMenuInfoP == NULL)
			return NOMEM;
	}
	
	if (err = XOPGetDialogItemAsControl(theDialog, popupItemNumber, &controlH))
		return err;

	/*	Find a free menu ID. Menus IDs from 1100-1199 are reserved for XOPs.
		This routine uses the range 1150 to 1199 for dialog popup menus.
	*/
	mH = NULL;
	menuID = FIRST_POPUP_MENU_ID;
	for(i=0; i<MAX_POPUP_MENUS; i++) {
		if (gPopMenuInfoP[i].menuID == 0) {
			char menuName[64];
			sprintf(menuName, "Menu %d", menuID);
			{
				unsigned char temp[256];
				CopyCStringToPascal(menuName, temp);
				mH = NewMenu(menuID, temp);
			}
			if (mH == NULL)
				return NOMEM;
			break;
		}
		menuID += 1;
	}
	if (mH == NULL)					// Ran out of menu IDs.
		return -1;					// Very unlikely.
	
	XOPFillMenuNoMeta(mH, 0, itemList);
	
	/*	Tell the control what menu handle it should use. According to Eric Schlegel from Apple,
		the menu does not need to be in the menu list. If this succeeds, the control now owns
		the menu handle and will dispose it.
	*/
	err = SetControlData(controlH, kControlMenuPart, kControlPopupButtonOwnedMenuRefTag, sizeof(mH), &mH);
	if (err!=0 || mH!=GetControlPopupMenuHandle(controlH)) {
		/*	If here, you are probably need to double-check your popupItemNumber
			or your CNTL resource or your DITL resource.
		*/
		DisposeMenu(mH);
		return err ? err:-1;		// Should never happen.
	}

	SetPopMenuMax(theDialog, popupItemNumber);
	
	// Store the menu ID so we can tell what menu ID is free the next time we create a popup menu.
	gPopMenuInfoP[menuID-FIRST_POPUP_MENU_ID].theDialog = theDialog;
	gPopMenuInfoP[menuID-FIRST_POPUP_MENU_ID].menuID = menuID;
	
	// Set the initially-selected item.
	SetPopItem(theDialog, popupItemNumber, initialItem);
	
	return 0;
}