LPSTR create_gensetup (HWND hwnd, LPCSTR dsn, LPCSTR attrs, BOOL add, BOOL *verify_conn) { EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit }; RgnHandle cursorRgn = NULL; TGENSETUP gensetup_t; ControlID controlID; WindowRef wgensetup; ControlRef control; EventRecord event; IBNibRef nibRef; OSStatus err; char msg[1024]; gensetup_t.verify_conn = true; /* Search the bundle for a .nib file named 'odbcadmin'. */ /* Search the bundle for a .nib file named 'odbcadmin'. */ err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier ( CFSTR ("org.iodbc.adm")), CFSTR ("gensetup"), &nibRef); if (err == noErr) { /* Nib found ... so create the window */ CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wgensetup); DisposeNibReference (nibRef); /* Set the title with the DSN */ if (dsn) { msg[0] = STRLEN ("Setup of ") + STRLEN(dsn); sprintf (msg+1, "Setup of %s", (char*)dsn); SetWTitle (wgensetup, msg); } /* Install handlers for the finish button, the cancel */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSDSN_CNTL, wgensetup, gensetup_t.dsn_entry); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVERIFYCONN_CNTL, wgensetup, gensetup_t.verify_conn_cb); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSLIST_CNTL, wgensetup, gensetup_t.key_list); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSKEYWORD_CNTL, wgensetup, gensetup_t.key_entry); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVALUE_CNTL, wgensetup, gensetup_t.value_entry); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSUPDATE_CNTL, wgensetup, gensetup_t.bupdate); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSADD_CNTL, wgensetup, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (gensetup_add_clicked), 1, &controlSpec, &gensetup_t, NULL); InstallEventHandler (GetControlEventTarget (gensetup_t.bupdate), NewEventHandlerUPP (gensetup_update_clicked), 1, &controlSpec, &gensetup_t, NULL); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSOK_CNTL, wgensetup, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (gensetup_ok_clicked), 1, &controlSpec, &gensetup_t, NULL); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSCANCEL_CNTL, wgensetup, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (gensetup_cancel_clicked), 1, &controlSpec, &gensetup_t, NULL); /* Parse the attributes line */ gensetup_t.mainwnd = wgensetup; parse_attribute_line (&gensetup_t, dsn, attrs, add); AdvanceKeyboardFocus (wgensetup); /* Show the window and run the loop */ DeactivateControl (gensetup_t.bupdate); DSNSETUP = &gensetup_t; ShowWindow (wgensetup); /* The main loop */ while (gensetup_t.mainwnd) { switch (WaitNextEvent (everyEvent, &event, 60L, cursorRgn)) { }; } *verify_conn = gensetup_t.verify_conn; } else goto error; return gensetup_t.connstr; error: fprintf (stderr, "Can't load Window. Err: %d\n", (int) err); return gensetup_t.connstr; }
LPSTR create_keyval (HWND hwnd, LPCSTR attrs, BOOL *verify_conn) { GtkWidget *gensetup, *dialog_vbox1, *fixed1; GtkWidget *l_comment, *scrolledwindow1, *clist1; GtkWidget *l_key, *l_value, *t_keyword, *t_value, *l_copyright; GtkWidget *vbuttonbox1, *b_add, *b_update, *l_keyword, *l_valeur; GtkWidget *dialog_action_area1, *hbuttonbox1, *b_ok, *b_cancel; GtkWidget *cb_verify; guint button_key; GtkAccelGroup *accel_group; TGENSETUP gensetup_t; char buff[1024]; if (hwnd == NULL || !GTK_IS_WIDGET (hwnd)) return (LPSTR) attrs; accel_group = gtk_accel_group_new (); gensetup = gtk_dialog_new (); gtk_object_set_data (GTK_OBJECT (gensetup), "gensetup", gensetup); gtk_window_set_title (GTK_WINDOW (gensetup), "Advanced File DSN Creation Settings"); gtk_window_set_position (GTK_WINDOW (gensetup), GTK_WIN_POS_CENTER); gtk_window_set_modal (GTK_WINDOW (gensetup), TRUE); gtk_window_set_policy (GTK_WINDOW (gensetup), FALSE, FALSE, FALSE); #if GTK_CHECK_VERSION(2,0,0) gtk_widget_show (gensetup); #endif dialog_vbox1 = GTK_DIALOG (gensetup)->vbox; gtk_object_set_data (GTK_OBJECT (gensetup), "dialog_vbox1", dialog_vbox1); gtk_widget_show (dialog_vbox1); fixed1 = gtk_fixed_new (); gtk_widget_ref (fixed1); gtk_object_set_data_full (GTK_OBJECT (gensetup), "fixed1", fixed1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (fixed1); gtk_box_pack_start (GTK_BOX (dialog_vbox1), fixed1, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (fixed1), 6); l_comment = gtk_label_new ("If you know the driver-specific keywords for this data source, you can type them and their values here. For more information on driver-specific keywords, please consult your ODBC driver documentation."); gtk_widget_ref (l_comment); gtk_object_set_data_full (GTK_OBJECT (gensetup), "l_comment", l_comment, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (l_comment); gtk_fixed_put (GTK_FIXED (fixed1), l_comment, 8, 7); gtk_widget_set_uposition (l_comment, 8, 7); gtk_widget_set_usize (l_comment, 330, 70); gtk_label_set_justify (GTK_LABEL (l_comment), GTK_JUSTIFY_LEFT); gtk_label_set_line_wrap (GTK_LABEL (l_comment), TRUE); scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_ref (scrolledwindow1); gtk_object_set_data_full (GTK_OBJECT (gensetup), "scrolledwindow1", scrolledwindow1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (scrolledwindow1); gtk_fixed_put (GTK_FIXED (fixed1), scrolledwindow1, 8, 88); gtk_widget_set_uposition (scrolledwindow1, 8, 88); gtk_widget_set_usize (scrolledwindow1, 320, 184); clist1 = gtk_clist_new (2); gtk_widget_ref (clist1); gtk_object_set_data_full (GTK_OBJECT (gensetup), "clist1", clist1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (clist1); gtk_container_add (GTK_CONTAINER (scrolledwindow1), clist1); gtk_clist_set_column_width (GTK_CLIST (clist1), 0, 137); gtk_clist_set_column_width (GTK_CLIST (clist1), 1, 80); gtk_clist_column_titles_show (GTK_CLIST (clist1)); l_key = gtk_label_new (szKeysColumnNames[0]); gtk_widget_ref (l_key); gtk_object_set_data_full (GTK_OBJECT (gensetup), "l_key", l_key, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (l_key); gtk_clist_set_column_widget (GTK_CLIST (clist1), 0, l_key); l_value = gtk_label_new (szKeysColumnNames[1]); gtk_widget_ref (l_value); gtk_object_set_data_full (GTK_OBJECT (gensetup), "l_value", l_value, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (l_value); gtk_clist_set_column_widget (GTK_CLIST (clist1), 1, l_value); t_keyword = gtk_entry_new (); gtk_widget_ref (t_keyword); gtk_object_set_data_full (GTK_OBJECT (gensetup), "t_keyword", t_keyword, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (t_keyword); gtk_fixed_put (GTK_FIXED (fixed1), t_keyword, 80, 288); gtk_widget_set_uposition (t_keyword, 80, 288); gtk_widget_set_usize (t_keyword, 158, 22); t_value = gtk_entry_new (); gtk_widget_ref (t_value); gtk_object_set_data_full (GTK_OBJECT (gensetup), "t_value", t_value, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (t_value); gtk_fixed_put (GTK_FIXED (fixed1), t_value, 80, 320); gtk_widget_set_uposition (t_value, 80, 320); gtk_widget_set_usize (t_value, 158, 22); vbuttonbox1 = gtk_vbutton_box_new (); gtk_widget_ref (vbuttonbox1); gtk_object_set_data_full (GTK_OBJECT (gensetup), "vbuttonbox1", vbuttonbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (vbuttonbox1); gtk_fixed_put (GTK_FIXED (fixed1), vbuttonbox1, 248, 280); gtk_widget_set_uposition (vbuttonbox1, 248, 280); gtk_widget_set_usize (vbuttonbox1, 85, 69); b_add = gtk_button_new_with_label (""); button_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_add)->child), szKeysButtons[0]); gtk_widget_add_accelerator (b_add, "clicked", accel_group, button_key, GDK_MOD1_MASK, 0); gtk_widget_ref (b_add); gtk_object_set_data_full (GTK_OBJECT (gensetup), "b_add", b_add, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (b_add); gtk_container_add (GTK_CONTAINER (vbuttonbox1), b_add); GTK_WIDGET_SET_FLAGS (b_add, GTK_CAN_DEFAULT); gtk_widget_add_accelerator (b_add, "clicked", accel_group, 'A', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); b_update = gtk_button_new_with_label (""); button_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_update)->child), szKeysButtons[1]); gtk_widget_add_accelerator (b_update, "clicked", accel_group, button_key, GDK_MOD1_MASK, 0); gtk_widget_ref (b_update); gtk_object_set_data_full (GTK_OBJECT (gensetup), "b_update", b_update, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (b_update); gtk_container_add (GTK_CONTAINER (vbuttonbox1), b_update); GTK_WIDGET_SET_FLAGS (b_update, GTK_CAN_DEFAULT); gtk_widget_add_accelerator (b_update, "clicked", accel_group, 'U', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); gtk_widget_set_sensitive (b_update, FALSE); l_keyword = gtk_label_new ("Keyword : "); gtk_widget_ref (l_keyword); gtk_object_set_data_full (GTK_OBJECT (gensetup), "l_keyword", l_keyword, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (l_keyword); gtk_fixed_put (GTK_FIXED (fixed1), l_keyword, 8, 290); gtk_widget_set_uposition (l_keyword, 8, 290); gtk_widget_set_usize (l_keyword, 69, 16); gtk_label_set_justify (GTK_LABEL (l_keyword), GTK_JUSTIFY_LEFT); l_valeur = gtk_label_new ("Value : "); gtk_widget_ref (l_valeur); gtk_object_set_data_full (GTK_OBJECT (gensetup), "l_valeur", l_valeur, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (l_valeur); gtk_fixed_put (GTK_FIXED (fixed1), l_valeur, 8, 323); gtk_widget_set_uposition (l_valeur, 8, 323); gtk_widget_set_usize (l_valeur, 51, 16); gtk_label_set_justify (GTK_LABEL (l_valeur), GTK_JUSTIFY_LEFT); cb_verify = gtk_check_button_new_with_label ("Verify this connection(recommended)"); gtk_widget_ref (cb_verify); gtk_object_set_data_full (GTK_OBJECT (gensetup), "cb_verify", cb_verify, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (cb_verify); gtk_fixed_put (GTK_FIXED (fixed1), cb_verify, 8, 350); gtk_widget_set_uposition (cb_verify, 8, 350); gtk_widget_set_usize (cb_verify, 230, 24); dialog_action_area1 = GTK_DIALOG (gensetup)->action_area; gtk_object_set_data (GTK_OBJECT (gensetup), "dialog_action_area1", dialog_action_area1); gtk_widget_show (dialog_action_area1); gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5); hbuttonbox1 = gtk_hbutton_box_new (); gtk_widget_ref (hbuttonbox1); gtk_object_set_data_full (GTK_OBJECT (gensetup), "hbuttonbox1", hbuttonbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (hbuttonbox1); gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE, 0); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END); gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10); b_ok = gtk_button_new_with_label (""); button_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_ok)->child), "_Ok"); gtk_widget_add_accelerator (b_ok, "clicked", accel_group, button_key, GDK_MOD1_MASK, 0); gtk_widget_ref (b_ok); gtk_object_set_data_full (GTK_OBJECT (gensetup), "b_ok", b_ok, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (b_ok); gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_ok); GTK_WIDGET_SET_FLAGS (b_ok, GTK_CAN_DEFAULT); gtk_widget_add_accelerator (b_ok, "clicked", accel_group, 'O', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); b_cancel = gtk_button_new_with_label (""); button_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_cancel)->child), "_Cancel"); gtk_widget_add_accelerator (b_cancel, "clicked", accel_group, button_key, GDK_MOD1_MASK, 0); gtk_widget_ref (b_cancel); gtk_object_set_data_full (GTK_OBJECT (gensetup), "b_cancel", b_cancel, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (b_cancel); gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_cancel); GTK_WIDGET_SET_FLAGS (b_cancel, GTK_CAN_DEFAULT); gtk_widget_add_accelerator (b_cancel, "clicked", accel_group, 'C', GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); /* Ok button events */ gtk_signal_connect (GTK_OBJECT (b_ok), "clicked", GTK_SIGNAL_FUNC (gensetup_ok_clicked), &gensetup_t); /* Cancel button events */ gtk_signal_connect (GTK_OBJECT (b_cancel), "clicked", GTK_SIGNAL_FUNC (gensetup_cancel_clicked), &gensetup_t); /* Add button events */ gtk_signal_connect (GTK_OBJECT (b_add), "clicked", GTK_SIGNAL_FUNC (gensetup_add_clicked), &gensetup_t); /* Update button events */ gtk_signal_connect (GTK_OBJECT (b_update), "clicked", GTK_SIGNAL_FUNC (gensetup_update_clicked), &gensetup_t); /* Close window button events */ gtk_signal_connect (GTK_OBJECT (gensetup), "delete_event", GTK_SIGNAL_FUNC (delete_event), &gensetup_t); gtk_signal_connect (GTK_OBJECT (gensetup), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); /* List events */ gtk_signal_connect (GTK_OBJECT (clist1), "select_row", GTK_SIGNAL_FUNC (gensetup_list_select), &gensetup_t); gtk_signal_connect (GTK_OBJECT (clist1), "unselect_row", GTK_SIGNAL_FUNC (gensetup_list_unselect), &gensetup_t); gtk_window_add_accel_group (GTK_WINDOW (gensetup), accel_group); gensetup_t.dsn_entry = NULL; gensetup_t.key_list = clist1; gensetup_t.bupdate = b_update; gensetup_t.key_entry = t_keyword; gensetup_t.value_entry = t_value; gensetup_t.mainwnd = gensetup; gensetup_t.verify_conn_cb = cb_verify; gensetup_t.verify_conn = *verify_conn; gtk_toggle_button_set_active(cb_verify, *verify_conn); /* Parse the attributes line */ parse_attribute_line (&gensetup_t, NULL, attrs, TRUE); gtk_widget_show_all (gensetup); gtk_main (); *verify_conn = gensetup_t.verify_conn; return gensetup_t.connstr; }