pascal OSStatus filedsn_remove_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData; DataBrowserItemID first, last; OSStatus err; if (!choose_t) return noErr; /* Retrieve the DSN name */ if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (first > DBITEM_ID && first <= DBITEM_ID + FDSN_nrows) { char str[1024]; char *path; if (FDSN_type[first - DBITEM_ID - 1] == 0) return noErr; /* Get the DSN */ CFStringGetCString(FDSN_array[first - DBITEM_ID - 1], str, sizeof(str), kCFStringEncodingUTF8); asprintf (&path, "%s/%s", choose_t->curr_dir, str); if (path) { if (create_confirm (choose_t->mainwnd, path, "Are you sure you want to remove this File DSN ?")) { /* Call the right function */ if (unlink(path) < 0) { create_error (choose_t->mainwnd, NULL, "Error removing file DSN:", strerror (errno)); } } free(path); addfdsns_to_list (choose_t, choose_t->curr_dir, true); } } } if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (!first && !last) { DeactivateControl (choose_t->fremove); DeactivateControl (choose_t->fconfigure); DeactivateControl (choose_t->ftest); } } return noErr; }
pascal OSStatus filedsn_test_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData; DataBrowserItemID first, last; OSStatus err; char connstr[4096] = { 0 }; if (!choose_t) return noErr; /* Retrieve the DSN name */ if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (first > DBITEM_ID && first <= DBITEM_ID + FDSN_nrows) { char str[1024]; char *path; if (FDSN_type[first - DBITEM_ID - 1] == 0) return noErr; /* Get the DSN */ CFStringGetCString(FDSN_array[first - DBITEM_ID - 1], str, sizeof(str), kCFStringEncodingUTF8); asprintf (&path, "%s/%s", choose_t->curr_dir, str); if (path) { /* Create connection string and connect to data source */ snprintf (connstr, sizeof (connstr), "FILEDSN=%s", path); if (test_driver_connect(choose_t, connstr)) { _iodbcdm_messagebox (choose_t->mainwnd, path, "The connection DSN was tested successfully, and can be used at this time."); } free(path); } } } if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (!first && !last) { DeactivateControl (choose_t->fremove); DeactivateControl (choose_t->fconfigure); DeactivateControl (choose_t->ftest); } } return noErr; }
pascal OSStatus driverchooser_ok_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TDRIVERCHOOSER *choose_t = (TDRIVERCHOOSER *) inUserData; DataBrowserItemID first, last; OSStatus err; if (choose_t) { /* Get the selection */ if ((err = GetDataBrowserSelectionAnchor (choose_t->driverlist, &first, &last)) == noErr) { if (first > DBITEM_ID && first <= DBITEM_ID + Drivers_nrows) { /* Get the driver name */ choose_t->driver = convert_CFString_to_wchar(Drivers_array[0][first - DBITEM_ID - 1]); } else choose_t->driver = NULL; } else choose_t->driver = NULL; DisposeWindow (choose_t->mainwnd); choose_t->mainwnd = NULL; choose_t->driverlist = NULL; Drivers_nrows = 0; } return noErr; }
pascal OSStatus filedsn_add_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData; DataBrowserItemID first, last; OSStatus err; SQLCHAR drv[1024] = { 0 }; LPSTR s, attrs; TFDRIVERCHOOSER drvchoose_t; if (!choose_t) return noErr; /* Try first to get the driver name */ SQLSetConfigMode (ODBC_USER_DSN); drvchoose_t.attrs = NULL; drvchoose_t.dsn = NULL; drvchoose_t.driver = NULL; drvchoose_t.curr_dir = choose_t->curr_dir; create_fdriverchooser (choose_t->mainwnd, &drvchoose_t); /* Check output parameters */ if (drvchoose_t.ok) { if (sizeof(drv) > WCSLEN(drvchoose_t.driver) + strlen("DRIVER=")) { s = strcpy(drv, "DRIVER="); s += strlen("DRIVER="); dm_strcpy_W2A(s, drvchoose_t.driver); attrs = drvchoose_t.attrs; filedsn_configure(choose_t, drv, drvchoose_t.dsn, attrs ? attrs :"\0\0", TRUE, drvchoose_t.verify_conn); addfdsns_to_list (choose_t, choose_t->curr_dir, true); } } if (drvchoose_t.driver) free (drvchoose_t.driver); if (drvchoose_t.attrs) free (drvchoose_t.attrs); if (drvchoose_t.dsn) free (drvchoose_t.dsn); if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (!first && !last) { DeactivateControl (choose_t->fremove); DeactivateControl (choose_t->fconfigure); DeactivateControl (choose_t->ftest); } } return noErr; }
pascal OSStatus gensetup_update_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TGENSETUP *gensetup_t = (TGENSETUP *) inUserData; DataBrowserItemID item = DBITEM_ID + 1, first, last; DataBrowserCallbacks dbCallbacks; ThemeDrawingState outState = NULL; UInt16 colSize[2] = { 150, 250 }; SInt16 outBaseline; Point ioBound; CFStringRef data[2]; Size len; int i = 0, j; if (gensetup_t) { GetThemeDrawingState (&outState); GetControlData (gensetup_t->key_entry, 0, kControlEditTextCFStringTag, sizeof (CFStringRef), &data[0], &len); if (CFStringGetLength(data[0])) { GetControlData (gensetup_t->value_entry, 0, kControlEditTextCFStringTag, sizeof (CFStringRef), &data[1], &len); if(GetDataBrowserSelectionAnchor (gensetup_t->key_list, &first, &last) == noErr) { i = first - DBITEM_ID - 1; item += i; } else i = 0; /* Install an event handler on the component databrowser */ dbCallbacks.version = kDataBrowserLatestCallbacks; InitDataBrowserCallbacks (&dbCallbacks); dbCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP (dsnsetup_notification_item); /* On Mac OS X 10.0.x : this is clientDataCallback */ dbCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP (dsnsetup_getset_item); SetDataBrowserCallbacks (gensetup_t->key_list, &dbCallbacks); /* Begin the draw of the data browser */ SetDataBrowserTarget (gensetup_t->key_list, DBITEM_ID); /* An update operation */ if(i<DSNSETUP_nrows) { CFRelease (DSNSETUP_array[0][i]); CFRelease (DSNSETUP_array[1][i]); DSNSETUP_array[0][i] = data[0]; DSNSETUP_array[1][i] = data[1]; UpdateDataBrowserItems (gensetup_t->key_list, DBITEM_ID, 1, &item, GSKEYWORD_ID, kDataBrowserItemNoProperty); } for(j = 0 ; j < DSNSETUP_nrows ; j++) { for(i = 0 ; i < 2 ; i++) { GetThemeTextDimensions (DSNSETUP_array[i][j], kThemeSystemFont, kThemeStateActive, false, &ioBound, &outBaseline); if(colSize[i] < ioBound.h) colSize[i] = ioBound.h; } } ActivateControl (gensetup_t->key_list); /* Resize the columns to have a good look */ SetDataBrowserTableViewNamedColumnWidth (gensetup_t->key_list, GSKEYWORD_ID, colSize[0] + 20); SetDataBrowserTableViewNamedColumnWidth (gensetup_t->key_list, GSVALUE_ID, colSize[1] + 20); DrawOneControl (gensetup_t->key_list); /* Remove the DataBrowser callback */ SetDataBrowserCallbacks (NULL, &dbCallbacks); } SetControlData (gensetup_t->key_entry, 0, kControlEditTextTextTag, 0, ""); DrawOneControl (gensetup_t->key_entry); SetControlData (gensetup_t->value_entry, 0, kControlEditTextTextTag, 0, ""); DrawOneControl (gensetup_t->value_entry); DeactivateControl (DSNSETUP->bupdate); DrawOneControl (DSNSETUP->bupdate); } return noErr; }
OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const { return GetDataBrowserSelectionAnchor( m_controlRef, first, last ); }
pascal OSStatus filedsn_configure_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData; DataBrowserItemID first, last; OSStatus err; char str[1024], path[1024]; int id; char *drv = NULL; char *attrs = NULL; char *_attrs = NULL; /* attr list */ size_t len = 0; /* current attr list length (w/o list-terminating NUL) */ char *p, *p_next; WORD read_len; char entries[4096]; char *curr_dir; if (!choose_t) return noErr; curr_dir = choose_t->curr_dir; /* Retrieve the DSN name */ if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist, &first, &last)) == noErr) { if (first > DBITEM_ID && first <= DBITEM_ID + FDSN_nrows) { id = first - DBITEM_ID - 1; CFStringGetCString(FDSN_array[id], str, sizeof(str), kCFStringEncodingUTF8); if (*curr_dir == '/' && strlen(curr_dir) == 1) snprintf(path, sizeof(path), "/%s", str); else snprintf(path, sizeof(path), "%s/%s", curr_dir, str); if (FDSN_type[id] == 0) /* Directory */ { addfdsns_to_list (choose_t, path, true); } else /* File DSN*/ { /* Get list of entries in .dsn file */ if (!SQLReadFileDSN (path, "ODBC", NULL, entries, sizeof (entries), &read_len)) { create_error (choose_t->mainwnd, NULL, "SQLReadFileDSN failed", NULL); goto done; } /* add params from the .dsn file */ for (p = entries; *p != '\0'; p = p_next) { char *tmp; size_t add_len; /* length of added attribute */ char value[1024]; /* get next entry */ p_next = strchr (p, ';'); if (p_next) *p_next++ = '\0'; if (!SQLReadFileDSN (path, "ODBC", p, value, sizeof(value), &read_len)) { create_error (choose_t->mainwnd, NULL, "SQLReadFileDSN failed", NULL); goto done; } if (!strcasecmp (p, "DRIVER")) { /* got driver keyword */ add_len = strlen ("DRIVER=") + strlen (value) + 1; drv = malloc (add_len); snprintf (drv, add_len, "DRIVER=%s", value); continue; } /* +1 for '=', +1 for NUL */ add_len = strlen (p) + 1 + strlen (value) + 1; /* +1 for list-terminating NUL */; tmp = realloc (attrs, len + add_len + 1); if (tmp == NULL) { create_error (choose_t->mainwnd, NULL, "Error adding file DSN:", strerror (errno)); goto done; } attrs = tmp; snprintf (attrs + len, add_len, "%s=%s", p, value); len += add_len; } if (drv == NULL) { /* no driver found, probably unshareable file data source */ create_error (choose_t->mainwnd, NULL, "Can't configure file DSN without DRIVER keyword (probably unshareable data source?)", NULL); goto done; } if (attrs == NULL) attrs = "\0\0"; else { /* NUL-terminate the list */ attrs[len] = '\0'; _attrs = attrs; } /* Configure file DSN */ filedsn_configure (choose_t, drv, path, attrs, FALSE, TRUE); addfdsns_to_list (choose_t, curr_dir, true); } } } done: if (drv != NULL) free (drv); if (_attrs != NULL) free (_attrs); if ((err = GetDataBrowserSelectionAnchor (choose_t->sdsnlist, &first, &last)) == noErr) { if (!first && !last) { DeactivateControl (choose_t->sremove); DeactivateControl (choose_t->sconfigure); DeactivateControl (choose_t->stest); } } return noErr; }