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; }
static pascal OSStatus NPServerDialogEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { OSStatus err, result = eventNotHandledErr; WindowRef tWindowRef = (WindowRef) inUserData; switch (GetEventClass(inEvent)) { case kEventClassCommand: switch (GetEventKind(inEvent)) { HICommand tHICommand; case kEventCommandUpdateStatus: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr && tHICommand.commandID == 'clos') { UpdateMenuCommandStatus(false); result = noErr; } break; case kEventCommandProcess: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr) { switch (tHICommand.commandID) { case 'OKAY': HIViewRef ctl, root; HIViewID cid; root = HIViewGetRoot(tWindowRef); cid.id = 0; cid.signature = 'OKAY'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); cid.signature = 'CNSL'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); npserver.dialogprocess = kNPSDialogProcess; result = noErr; break; case 'CNSL': npserver.dialogprocess = kNPSDialogCancel; result = noErr; break; } } break; } break; } return (result); }
void drivers_notification_item (ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message) { static Boolean ignore_next = false, selected = false; switch (message) { case kDataBrowserItemSelected: if (DRIVERCHOOSER->b_configure) { ActivateControl (DRIVERCHOOSER->b_remove); DrawOneControl (DRIVERCHOOSER->b_remove); ActivateControl (DRIVERCHOOSER->b_configure); DrawOneControl (DRIVERCHOOSER->b_configure); } else { ActivateControl (DRIVERCHOOSER->b_add); DrawOneControl (DRIVERCHOOSER->b_add); } if (selected) ignore_next = true; else selected = true; break; case kDataBrowserItemDeselected: if (!ignore_next) { if (DRIVERCHOOSER->b_configure) { DeactivateControl (DRIVERCHOOSER->b_remove); DrawOneControl (DRIVERCHOOSER->b_remove); DeactivateControl (DRIVERCHOOSER->b_configure); DrawOneControl (DRIVERCHOOSER->b_configure); } else { DeactivateControl (DRIVERCHOOSER->b_add); DrawOneControl (DRIVERCHOOSER->b_add); } selected = false; } else { ignore_next = false; selected = true; } break; case kDataBrowserItemDoubleClicked: if (DRIVERCHOOSER->b_configure) driver_configure_clicked (NULL, NULL, DRIVERCHOOSER); break; }; }
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; }
static pascal OSStatus MacOSXDialogCommandProcess(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* inUserData) { HICommand aCommand; OSStatus status = eventNotHandledErr; GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand); switch (aCommand.commandID) { case kHICommandOK: // we got a valid click on the OK button so let's quit our local run loop QuitAppModalLoopForWindow((WindowRef) inUserData); break; case 'CBED': { // we still enable or disable the custom spot view depending on whether the box is checked or not HIViewRef checkBox = ((HICommandExtended *)&aCommand)->source.control; SInt32 enable = GetControl32BitValue(checkBox); HIViewID hidcsv = {0, 13}; HIViewRef customSpotView; HIViewFindByID(HIViewGetRoot(GetControlOwner(checkBox)), hidcsv, &customSpotView); if (enable) ActivateControl(customSpotView); else DeactivateControl(customSpotView); HIViewSetNeedsDisplay(customSpotView, true); } break; } return status; }
static void fdsn_notification_item (ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message) { static Boolean ignore_next = false, selected = false; switch (message) { case kDataBrowserItemSelected: ActivateControl (DSNCHOOSER->fremove); DrawOneControl (DSNCHOOSER->fremove); ActivateControl (DSNCHOOSER->ftest); DrawOneControl (DSNCHOOSER->ftest); ActivateControl (DSNCHOOSER->fconfigure); DrawOneControl (DSNCHOOSER->fconfigure); if (selected) ignore_next = true; else selected = true; break; case kDataBrowserItemDeselected: if (!ignore_next) { DeactivateControl (DSNCHOOSER->fremove); DrawOneControl (DSNCHOOSER->fremove); DeactivateControl (DSNCHOOSER->ftest); DrawOneControl (DSNCHOOSER->ftest); DeactivateControl (DSNCHOOSER->fconfigure); DrawOneControl (DSNCHOOSER->fconfigure); } else { ignore_next = false; selected = true; } break; case kDataBrowserItemDoubleClicked: filedsn_configure_clicked (NULL, NULL, DSNCHOOSER); break; }; }
/* HiliteDControl(theDialog, itemNumber, enable) Thread Safety: HiliteDControl is not thread-safe. */ void HiliteDControl(DialogPtr theDialog, int itemNumber, int enable) { ControlHandle controlH; if (XOPGetDialogItemAsControl(theDialog, itemNumber, &controlH) == 0) { if (enable) ActivateControl(controlH); else DeactivateControl(controlH); } }
static void DeleteCheatItem (void) { OSStatus err; HIViewRef ctl, root; HIViewID cid; Handle selectedItems; ItemCount selectionCount; selectedItems = NewHandle(0); if (!selectedItems) return; err = GetDataBrowserItems(dbRef, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, selectedItems); selectionCount = (GetHandleSize(selectedItems) / sizeof(DataBrowserItemID)); if (selectionCount == 0) { DisposeHandle(selectedItems); return; } err = RemoveDataBrowserItems(dbRef, kDataBrowserNoItem, selectionCount, (DataBrowserItemID *) *selectedItems, kDataBrowserItemNoProperty); for (unsigned int i = 0; i < selectionCount; i++) { citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].valid = false; citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].enabled = false; numofcheats--; } DisposeHandle(selectedItems); root = HIViewGetRoot(wRef); cid.id = 0; if (numofcheats < MAC_MAX_CHEATS) { cid.signature = kNewButton; HIViewFindByID(root, cid, &ctl); err = ActivateControl(ctl); } if (numofcheats == 0) { cid.signature = kAllButton; HIViewFindByID(root, cid, &ctl); err = DeactivateControl(ctl); } }
static void dsnsetup_notification_item (ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message) { static Boolean ignore_next = false, selected = false; switch (message) { case kDataBrowserItemSelected: if (DSNSETUP) { ActivateControl (DSNSETUP->bupdate); DrawOneControl (DSNSETUP->bupdate); SetControlData (DSNSETUP->key_entry, 0, kControlEditTextCFStringTag, sizeof(CFStringRef), &DSNSETUP_array[0][itemID - DBITEM_ID - 1]); DrawOneControl (DSNSETUP->key_entry); SetControlData (DSNSETUP->value_entry, 0, kControlEditTextCFStringTag, sizeof(CFStringRef), &DSNSETUP_array[1][itemID - DBITEM_ID - 1]); DrawOneControl (DSNSETUP->value_entry); } if (selected) ignore_next = true; else selected = true; break; case kDataBrowserItemDeselected: if (!ignore_next && DSNSETUP) { DeactivateControl (DSNSETUP->bupdate); DrawOneControl (DSNSETUP->bupdate); SetControlData (DSNSETUP->key_entry, 0, kControlEditTextTextTag, 0, ""); DrawOneControl (DSNSETUP->key_entry); SetControlData (DSNSETUP->value_entry, 0, kControlEditTextTextTag, 0, ""); DrawOneControl (DSNSETUP->value_entry); selected = false; } else { ignore_next = false; selected = true; } break; }; }
static void AddCheatItem (void) { OSStatus err; HIViewRef ctl, root; HIViewID cid; DataBrowserItemID id[1]; unsigned int i; if (numofcheats == MAC_MAX_CHEATS) return; for (i = 0; i < MAC_MAX_CHEATS; i++) if (citem[i].valid == false) break; if (i == MAC_MAX_CHEATS) return; numofcheats++; citem[i].valid = true; citem[i].enabled = false; citem[i].address = 0; citem[i].value = 0; sprintf(citem[i].description, "Cheat %03" PRIu32, citem[i].id); id[0] = citem[i].id; err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, 1, id, kDataBrowserItemNoProperty); err = RevealDataBrowserItem(dbRef, id[0], kCmAddress, true); root = HIViewGetRoot(wRef); cid.id = 0; if (numofcheats == MAC_MAX_CHEATS) { cid.signature = kNewButton; HIViewFindByID(root, cid, &ctl); err = DeactivateControl(ctl); } if (numofcheats) { cid.signature = kAllButton; HIViewFindByID(root, cid, &ctl); err = ActivateControl(ctl); } }
static pascal void DBItemNotificationCallBack (HIViewRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message) { OSStatus err; HIViewRef ctl; HIViewID cid = { kDelButton, 0 }; ItemCount selectionCount; switch (message) { case kDataBrowserSelectionSetChanged: HIViewFindByID(HIViewGetRoot(wRef), cid, &ctl); err = GetDataBrowserItemCount(browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &selectionCount); if (selectionCount == 0) err = DeactivateControl(ctl); else err = ActivateControl(ctl); } }
static void parse_attribute_line (TGENSETUP * gensetup_t, LPCSTR dsn, LPCSTR attrs, BOOL add) { if (dsn) { SetControlData (gensetup_t->dsn_entry, 0, kControlEditTextTextTag, STRLEN (dsn), (UInt8 *) dsn); if (add) ActivateControl (gensetup_t->dsn_entry); else DeactivateControl (gensetup_t->dsn_entry); DrawOneControl (gensetup_t->dsn_entry); } addkeywords_to_list (gensetup_t->key_list, attrs, gensetup_t); }
static void RunDialogTheMacOS8or9Way(DialogRef theDialog) { SInt16 itemHit; ControlRef theControl; ControlRef theTextControl; BringToFront(GetDialogWindow(theDialog)); do { ModalDialog(MyMacOS8or9DialogFilter, &itemHit); switch (itemHit) { case 2: { // we still enable or disable the user pane depending on whether the box is checked or not GetDialogItemAsControl(theDialog, itemHit, &theControl); SInt32 enable = GetControl32BitValue(theControl); SetControl32BitValue(theControl, 1 - enable); GetDialogItemAsControl(theDialog, 13, &theControl); if (!enable) ActivateControl(theControl); else DeactivateControl(theControl); } break; case 9: case 10: { // we got a click in an edit text control, if didn't have the focus, let's set it GetDialogItemAsControl(theDialog, itemHit, &theTextControl); ControlRef currentFocus; GetKeyboardFocus(GetDialogWindow(theDialog), ¤tFocus); if (currentFocus != theTextControl) SetKeyboardFocus(GetDialogWindow(theDialog), theTextControl, kControlFocusNextPart); } break; } } while (!(itemHit == ok)); DisposeDialog(theDialog); }
bool wxToolBarTool::DoEnable(bool enable) { if ( IsControl() ) { GetControl()->Enable( enable ) ; } else if ( IsButton() ) { #if TARGET_API_MAC_OSX if ( enable ) EnableControl( m_controlHandle ) ; else DisableControl( m_controlHandle ) ; #else if ( enable ) ActivateControl( m_controlHandle ) ; else DeactivateControl( m_controlHandle ) ; #endif } return true ; }
// -------------------------------------------------------------------------------------- void HandleActivate(WindowRef window, Boolean activate) { ControlRef rootControl; ListHandle iconList; SInt16 pixelDepth; Boolean isColorDevice; GetRootControl(window, &rootControl); GetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); SetPortWindowPort(window); GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice); if (activate) { SetThemeTextColor(kThemeTextColorModelessDialogActive, pixelDepth, isColorDevice); ActivateControl(rootControl); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LActivate(true, iconList); RedrawPrefsWindowList(window); // redraw the list with the active appearance drawFrameAndFocus(iconList, true, window); EnableMenuItem(GetMenuRef(mFile), iClose); } else // deactivate { SetThemeTextColor(kThemeTextColorModelessDialogInactive, pixelDepth, isColorDevice); DeactivateControl(rootControl); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LActivate(false, iconList); RedrawPrefsWindowList(window); // redraw the list with the inactive appearance drawFrameAndFocus(iconList, false, window); DisableMenuItem(GetMenuRef(mFile), iClose); } }
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; }
static pascal OSStatus PreferencesEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { OSStatus err, result = eventNotHandledErr; WindowRef tWindowRef = (WindowRef) inUserData; switch (GetEventClass(inEvent)) { case kEventClassWindow: { switch (GetEventKind(inEvent)) { case kEventWindowClose: { QuitAppModalLoopForWindow(tWindowRef); result = noErr; break; } } break; } case kEventClassCommand: { switch (GetEventKind(inEvent)) { HICommand tHICommand; case kEventCommandUpdateStatus: { err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr && tHICommand.commandID == 'clos') { UpdateMenuCommandStatus(true); result = noErr; } break; } case kEventCommandProcess: { HIViewRef ctl, root; HIViewID cid; SInt32 value; FSRef ref; bool8 r; root = HIViewGetRoot(tWindowRef); err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr) { switch (tHICommand.commandID) { case 'S_EF': { HideWindow(tWindowRef); ConfigureSoundEffects(); ShowWindow(tWindowRef); result = noErr; break; } case 'G_FL': { if (systemVersion >= 0x1040) { HideWindow(tWindowRef); ConfigureCoreImageFilter(); ShowWindow(tWindowRef); } result = noErr; break; } case 'G__7': { cid.signature = 'grap'; cid.id = iNibGGLStretch; HIViewFindByID(root, cid, &ctl); value = GetControl32BitValue(ctl); cid.id = iNibGAspectRatio; HIViewFindByID(root, cid, &ctl); if (value) ActivateControl(ctl); else DeactivateControl(ctl); result = noErr; break; } case 'G_13': { cid.signature = 'grap'; cid.id = iNibGScreenCurvature; HIViewFindByID(root, cid, &ctl); value = GetControl32BitValue(ctl); cid.id = iNibGCurvatureWarp; HIViewFindByID(root, cid, &ctl); if (value) ActivateControl(ctl); else DeactivateControl(ctl); result = noErr; break; } case 'S__3': { cid.signature = 'snd_'; cid.id = iNibSStereo; HIViewFindByID(root, cid, &ctl); value = GetControl32BitValue(ctl); cid.id = iNibSReverseStereo; HIViewFindByID(root, cid, &ctl); if (value) ActivateControl(ctl); else DeactivateControl(ctl); result = noErr; break; } case 'F_FL': { UInt32 modifierkey; err = GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifierkey); if (err == noErr) { if (modifierkey & optionKey) { CFStringRef str; MenuRef menu; str = CFCopyLocalizedString(CFSTR("NoneSelected"), "NoneSelected"); cid.signature = 'othe'; cid.id = iNibOSaveFolder; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, 3); err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL); err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, str); DisableMenuItem(menu, iNibSaveFolderNameMenuItem); HIViewSetNeedsDisplay(ctl, true); CFRelease(str); if (saveFolderPath) CFRelease(saveFolderPath); saveFolderPath = NULL; } else r = NavBeginChooseFolderSheet(tWindowRef); } result = noErr; break; } case 'NvDn': { r = NavEndChooseFolderSheet(&ref); if (r) { CFStringRef str; CFURLRef url; MenuRef menu; url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref); str = CFURLCopyLastPathComponent(url); cid.signature = 'othe'; cid.id = iNibOSaveFolder; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, iNibSaveFolderNameMenuItem); err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL); err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, str); EnableMenuItem(menu, iNibSaveFolderNameMenuItem); HIViewSetNeedsDisplay(ctl, true); CFRelease(str); str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); if (saveFolderPath) CFRelease(saveFolderPath); saveFolderPath = str; CFRelease(url); } result = noErr; break; } } } break; } } break; } } return (result); }
void ConfigurePreferences (void) { OSStatus err; IBNibRef nibRef; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { WindowRef tWindowRef; SInt32 oldVolume; uint32 oldPlaybackRate, oldInputRate, oldInterval, oldBufferSize; bool8 oldSynchronize, old16BitPlayback, oldStereo, oldReverseStereo, oldLagEnable; oldSynchronize = Settings.SoundSync; old16BitPlayback = Settings.SixteenBitSound; oldStereo = Settings.Stereo; oldReverseStereo = Settings.ReverseStereo; oldPlaybackRate = Settings.SoundPlaybackRate; oldInputRate = Settings.SoundInputRate; oldInterval = macSoundInterval_ms; oldBufferSize = macSoundBuffer_ms; oldLagEnable = macSoundLagEnable; oldVolume = macSoundVolume; if (cartOpen) DeinitGameWindow(); S9xGraphicsDeinit(); err = CreateWindowFromNib(nibRef, CFSTR("Preferences"), &tWindowRef); if (err == noErr) { EventHandlerUPP tUPP, iUPP, aUPP, pUPP; EventHandlerRef tRef, iRef, aRef, pRef; EventTypeSpec tEvents[] = { { kEventClassControl, kEventControlHit } }, iEvents[] = { { kEventClassControl, kEventControlClick } }, aEvents[] = { { kEventClassControl, kEventControlClick } }, pEvents[] = { { kEventClassWindow, kEventWindowClose }, { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; ControlActionUPP arrowsUPP, sliderUPP; HIViewRef ctl, root; HIViewID cid; MenuRef menu; char num[16]; root = HIViewGetRoot(tWindowRef); cid.signature = 'tabs'; cid.id = 128; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, lastTabIndex); SelectTabPane(ctl, lastTabIndex); tUPP = NewEventHandlerUPP(TabEventHandler); err = InstallControlEventHandler(ctl, tUPP, GetEventTypeCount(tEvents), tEvents, 0, &tRef); cid.signature = 'snd_'; cid.id = iNibSInputRateText; HIViewFindByID(root, cid, &ctl); iUPP = NewEventHandlerUPP(InputRateTextEventHandler); err = InstallControlEventHandler(ctl, iUPP, GetEventTypeCount(iEvents), iEvents, 0, &iRef); cid.signature = 'grap'; cid.id = iNibGAspectRatioText; HIViewFindByID(root, cid, &ctl); aUPP = NewEventHandlerUPP(AspectRatioTextEventHandler); err = InstallControlEventHandler(ctl, aUPP, GetEventTypeCount(aEvents), aEvents, 0, &aRef); pUPP = NewEventHandlerUPP(PreferencesEventHandler); err = InstallWindowEventHandler(tWindowRef, pUPP, GetEventTypeCount(pEvents), pEvents, (void *) tWindowRef, &pRef); sliderUPP = NewControlActionUPP(InputRateSliderActionProc); arrowsUPP = NewControlActionUPP(LittleArrowsActionProc); cid.signature = 'grap'; cid.id = iNibGFullScreen; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, fullscreen); cid.id = iNibGSwitchResolution; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, autoRes); cid.id = iNibGShowFrameRate; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.DisplayFrameRate); cid.id = iNibGTransparency; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.Transparency); cid.id = iNibGGL32bit; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, gl32bit); cid.id = iNibGGLStretch; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, glstretch); cid.id = iNibGVideoMode; HIViewFindByID(root, cid, &ctl); switch (videoMode) { case VIDEOMODE_BLOCKY: SetControl32BitValue(ctl, iOpenGLBlocky); break; case VIDEOMODE_TV: SetControl32BitValue(ctl, iOpenGLTVMode); break; case VIDEOMODE_SMOOTH: SetControl32BitValue(ctl, iOpenGLSmoothMode); break; case VIDEOMODE_BLEND: SetControl32BitValue(ctl, iOpenGLBlendMode); break; case VIDEOMODE_SUPEREAGLE: SetControl32BitValue(ctl, iOpenGLEagleMode); break; case VIDEOMODE_2XSAI: SetControl32BitValue(ctl, iOpenGL2xSAIMode); break; case VIDEOMODE_SUPER2XSAI: SetControl32BitValue(ctl, iOpenGLSuper2xSAIMode); break; case VIDEOMODE_EPX: SetControl32BitValue(ctl, iOpenGLEPXMode); break; case VIDEOMODE_HQ2X: SetControl32BitValue(ctl, iOpenGLHQ2xMode); break; case VIDEOMODE_HQ3X: SetControl32BitValue(ctl, iOpenGLHQ3xMode); break; case VIDEOMODE_HQ4X: SetControl32BitValue(ctl, iOpenGLHQ4xMode); break; case VIDEOMODE_NTSC_C: SetControl32BitValue(ctl, iOpenGLNTSC_CMode); break; case VIDEOMODE_NTSC_S: SetControl32BitValue(ctl, iOpenGLNTSC_SMode); break; case VIDEOMODE_NTSC_R: SetControl32BitValue(ctl, iOpenGLNTSC_RMode); break; case VIDEOMODE_NTSC_M: SetControl32BitValue(ctl, iOpenGLNTSC_MMode); break; case VIDEOMODE_NTSC_TV_C: SetControl32BitValue(ctl, iOpenGLNTSC_TV_CMode); break; case VIDEOMODE_NTSC_TV_S: SetControl32BitValue(ctl, iOpenGLNTSC_TV_SMode); break; case VIDEOMODE_NTSC_TV_R: SetControl32BitValue(ctl, iOpenGLNTSC_TV_RMode); break; case VIDEOMODE_NTSC_TV_M: SetControl32BitValue(ctl, iOpenGLNTSC_TV_MMode); break; } cid.id = iNibGDirectMP; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, multiprocessor); cid.id = iNibGGLVSync; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, vsync); cid.id = iNibGDrawOverscan; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, drawoverscan); cid.id = iNibGScreenCurvature; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, screencurvature); cid.id = iNibGCurvatureWarp; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macCurvatureWarp); if (!screencurvature) DeactivateControl(ctl); cid.id = iNibGAspectRatio; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macAspectRatio); if (!glstretch) DeactivateControl(ctl); cid.id = iNibGCIFilterEnable; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, ciFilterEnable); if (systemVersion < 0x1040) DisableControl(ctl); if (systemVersion < 0x1040) { cid.id = iNibGCoreImageFilter; HIViewFindByID(root, cid, &ctl); DisableControl(ctl); } cid.signature = 'snd_'; cid.id = iNibSSynchronize; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.SoundSync); cid.id = iNibS16BitPlayback; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.SixteenBitSound); DeactivateControl(ctl); cid.id = iNibSStereo; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.Stereo); DeactivateControl(ctl); cid.id = iNibSReverseStereo; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.ReverseStereo); DeactivateControl(ctl); cid.id = iNibSPlaybackRate; HIViewFindByID(root, cid, &ctl); switch (Settings.SoundPlaybackRate) { case 48000: SetControl32BitValue(ctl, 1); break; case 44100: SetControl32BitValue(ctl, 2); break; case 35000: SetControl32BitValue(ctl, 3); break; case 32000: SetControl32BitValue(ctl, 4); break; case 30000: SetControl32BitValue(ctl, 5); break; case 22050: SetControl32BitValue(ctl, 6); break; case 16000: SetControl32BitValue(ctl, 7); break; case 11025: SetControl32BitValue(ctl, 8); break; case 8000: SetControl32BitValue(ctl, 9); break; } cid.id = iNibSInputRate; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.SoundInputRate); SetControlAction(ctl, sliderUPP); cid.id = iNibSInputRateText; HIViewFindByID(root, cid, &ctl); sprintf(num, "%d", Settings.SoundInputRate); SetStaticTextCStr(ctl, num, false); cid.id = iNibSInterval; HIViewFindByID(root, cid, &ctl); switch (macSoundInterval_ms) { case 8: SetControl32BitValue(ctl, 1); break; case 16: SetControl32BitValue(ctl, 2); break; case 32: SetControl32BitValue(ctl, 3); break; case 64: SetControl32BitValue(ctl, 4); break; case 0: default: SetControl32BitValue(ctl, 6); break; } cid.id = iNibSBufferSize; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macSoundBuffer_ms / 20); cid.id = iNibSAllowLag; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macSoundLagEnable); DeactivateControl(ctl); cid.id = iNibSVolume; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macSoundVolume); cid.signature = 'othe'; cid.id = iNibOSaveFolder; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, saveInROMFolder + 1); err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL); if (saveFolderPath) { CFURLRef url; CFStringRef ref; url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, saveFolderPath, kCFURLPOSIXPathStyle, true); ref = CFURLCopyLastPathComponent(url); err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, ref); CFRelease(ref); CFRelease(url); EnableMenuItem(menu, iNibSaveFolderNameMenuItem); } else { CFStringRef ref; ref = CFCopyLocalizedString(CFSTR("NoneSelected"), "NoneSelected"); err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, ref); CFRelease(ref); DisableMenuItem(menu, iNibSaveFolderNameMenuItem); } cid.id = iNibOAutoSaveInterval; HIViewFindByID(root, cid, &ctl); sprintf(num, "%d", Settings.AutoSaveDelay); SetEditTextCStr(ctl, num, false); cid.signature = 'msc2'; cid.id = iNibMCPUCycles; HIViewFindByID(root, cid, &ctl); sprintf(num, "%" PRIi32, Settings.HDMATimingHack); SetEditTextCStr(ctl, num, false); cid.id = iNibMTurboSkipArrows; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macFastForwardRate); SetControlAction(ctl, arrowsUPP); cid.id = iNibMTurboSkipText; HIViewFindByID(root, cid, &ctl); sprintf(num, "%d", macFastForwardRate); SetStaticTextCStr(ctl, num, false); cid.id = iNibMFrameSkip; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macFrameSkip + 2); cid.id = iNibMAllowInvalidVRAMAccess; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, !Settings.BlockInvalidVRAMAccessMaster); cid.id = iNibMAllowSpecificGameHacks; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, !Settings.DisableGameSpecificHacks); cid.signature = 'osx_'; cid.id = iNibXStartOpenDialog; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, startopendlog); cid.id = iNibXShowTimeInFrz; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, showtimeinfrz); cid.id = iNibXMusicBoxMode; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, musicboxmode); cid.id = iNibXEnableToggle; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, enabletoggle); cid.id = iNibXSaveWindowPos; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, savewindowpos); cid.id = iNibXUseIPSPatch; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, !Settings.NoPatch); cid.id = iNibXOnScreenInfo; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, onscreeninfo); cid.id = iNibXInactiveMode; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, inactiveMode); cid.id = iNibXBSXBootup; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.BSXBootup); MoveWindowPosition(tWindowRef, kWindowPreferences, false); ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowPreferences); cid.signature = 'grap'; cid.id = iNibGFullScreen; HIViewFindByID(root, cid, &ctl); fullscreen = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGSwitchResolution; HIViewFindByID(root, cid, &ctl); autoRes = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGShowFrameRate; HIViewFindByID(root, cid, &ctl); Settings.DisplayFrameRate = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGTransparency; HIViewFindByID(root, cid, &ctl); Settings.Transparency = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGGL32bit; HIViewFindByID(root, cid, &ctl); gl32bit = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGGLStretch; HIViewFindByID(root, cid, &ctl); glstretch = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGVideoMode; HIViewFindByID(root, cid, &ctl); switch (GetControl32BitValue(ctl)) { case iOpenGLBlocky: drawingMethod = kDrawingOpenGL; videoMode = VIDEOMODE_BLOCKY; break; case iOpenGLTVMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_TV; break; case iOpenGLSmoothMode: drawingMethod = kDrawingOpenGL; videoMode = VIDEOMODE_SMOOTH; break; case iOpenGLBlendMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_BLEND; break; case iOpenGLEagleMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_SUPEREAGLE; break; case iOpenGL2xSAIMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_2XSAI; break; case iOpenGLSuper2xSAIMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_SUPER2XSAI; break; case iOpenGLEPXMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_EPX; break; case iOpenGLHQ2xMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_HQ2X; break; case iOpenGLHQ3xMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_HQ3X; break; case iOpenGLHQ4xMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_HQ4X; break; case iOpenGLNTSC_CMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_C; S9xBlitNTSCFilterSet(&snes_ntsc_composite); break; case iOpenGLNTSC_SMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_S; S9xBlitNTSCFilterSet(&snes_ntsc_svideo); break; case iOpenGLNTSC_RMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_R; S9xBlitNTSCFilterSet(&snes_ntsc_rgb); break; case iOpenGLNTSC_MMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_M; S9xBlitNTSCFilterSet(&snes_ntsc_monochrome); break; case iOpenGLNTSC_TV_CMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_C; S9xBlitNTSCFilterSet(&snes_ntsc_composite); break; case iOpenGLNTSC_TV_SMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_S; S9xBlitNTSCFilterSet(&snes_ntsc_svideo); break; case iOpenGLNTSC_TV_RMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_R; S9xBlitNTSCFilterSet(&snes_ntsc_rgb); break; case iOpenGLNTSC_TV_MMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_M; S9xBlitNTSCFilterSet(&snes_ntsc_monochrome); break; } cid.id = iNibGDirectMP; HIViewFindByID(root, cid, &ctl); multiprocessor = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGGLVSync; HIViewFindByID(root, cid, &ctl); vsync = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGDrawOverscan; HIViewFindByID(root, cid, &ctl); drawoverscan = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGScreenCurvature; HIViewFindByID(root, cid, &ctl); screencurvature = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGCurvatureWarp; HIViewFindByID(root, cid, &ctl); macCurvatureWarp = GetControl32BitValue(ctl); cid.id = iNibGAspectRatio; HIViewFindByID(root, cid, &ctl); macAspectRatio = GetControl32BitValue(ctl); cid.id = iNibGCIFilterEnable; HIViewFindByID(root, cid, &ctl); ciFilterEnable = GetControl32BitValue(ctl) ? true : false; cid.signature = 'snd_'; cid.id = iNibSSynchronize; HIViewFindByID(root, cid, &ctl); Settings.SoundSync = GetControl32BitValue(ctl) ? true : false; cid.id = iNibS16BitPlayback; HIViewFindByID(root, cid, &ctl); Settings.SixteenBitSound = GetControl32BitValue(ctl) ? true : false; cid.id = iNibSStereo; HIViewFindByID(root, cid, &ctl); Settings.Stereo = GetControl32BitValue(ctl) ? true : false; cid.id = iNibSReverseStereo; HIViewFindByID(root, cid, &ctl); Settings.ReverseStereo = GetControl32BitValue(ctl) ? true : false; cid.id = iNibSPlaybackRate; HIViewFindByID(root, cid, &ctl); switch (GetControl32BitValue(ctl)) { case 1: Settings.SoundPlaybackRate = 48000; break; case 2: Settings.SoundPlaybackRate = 44100; break; case 3: Settings.SoundPlaybackRate = 35000; break; case 4: Settings.SoundPlaybackRate = 32000; break; case 5: Settings.SoundPlaybackRate = 30000; break; case 6: Settings.SoundPlaybackRate = 22050; break; case 7: Settings.SoundPlaybackRate = 16000; break; case 8: Settings.SoundPlaybackRate = 11025; break; case 9: Settings.SoundPlaybackRate = 8000; break; } cid.id = iNibSInputRate; HIViewFindByID(root, cid, &ctl); Settings.SoundInputRate = GetControl32BitValue(ctl); cid.id = iNibSInterval; HIViewFindByID(root, cid, &ctl); switch (GetControl32BitValue(ctl)) { case 1: macSoundInterval_ms = 8; break; case 2: macSoundInterval_ms = 16; break; case 3: macSoundInterval_ms = 32; break; case 4: macSoundInterval_ms = 64; break; case 6: default: macSoundInterval_ms = 0; break; } cid.id = iNibSBufferSize; HIViewFindByID(root, cid, &ctl); macSoundBuffer_ms = GetControl32BitValue(ctl) * 20; cid.id = iNibSAllowLag; HIViewFindByID(root, cid, &ctl); macSoundLagEnable = GetControl32BitValue(ctl); cid.id = iNibSVolume; HIViewFindByID(root, cid, &ctl); macSoundVolume = GetControl32BitValue(ctl); cid.signature = 'othe'; cid.id = iNibOSaveFolder; HIViewFindByID(root, cid, &ctl); saveInROMFolder = GetControl32BitValue(ctl) - 1; cid.id = iNibOAutoSaveInterval; HIViewFindByID(root, cid, &ctl); GetEditTextCStr(ctl, num); Settings.AutoSaveDelay = atoi(num); cid.signature = 'msc2'; cid.id = iNibMCPUCycles; HIViewFindByID(root, cid, &ctl); GetEditTextCStr(ctl, num); Settings.HDMATimingHack = atoi(num); if ((Settings.HDMATimingHack <= 0) || (Settings.HDMATimingHack >= 200)) Settings.HDMATimingHack = 100; cid.id = iNibMTurboSkipArrows; HIViewFindByID(root, cid, &ctl); macFastForwardRate = GetControl32BitValue(ctl); cid.id = iNibMFrameSkip; HIViewFindByID(root, cid, &ctl); macFrameSkip = GetControl32BitValue(ctl) - 2; cid.id = iNibMAllowInvalidVRAMAccess; HIViewFindByID(root, cid, &ctl); Settings.BlockInvalidVRAMAccessMaster = GetControl32BitValue(ctl) ? false : true; cid.id = iNibMAllowSpecificGameHacks; HIViewFindByID(root, cid, &ctl); Settings.DisableGameSpecificHacks = GetControl32BitValue(ctl) ? false : true; cid.signature = 'osx_'; cid.id = iNibXStartOpenDialog; HIViewFindByID(root, cid, &ctl); startopendlog = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXShowTimeInFrz; HIViewFindByID(root, cid, &ctl); showtimeinfrz = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXMusicBoxMode; HIViewFindByID(root, cid, &ctl); musicboxmode = GetControl32BitValue(ctl); cid.id = iNibXEnableToggle; HIViewFindByID(root, cid, &ctl); enabletoggle = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXSaveWindowPos; HIViewFindByID(root, cid, &ctl); savewindowpos = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXUseIPSPatch; HIViewFindByID(root, cid, &ctl); Settings.NoPatch = GetControl32BitValue(ctl) ? false : true; cid.id = iNibXOnScreenInfo; HIViewFindByID(root, cid, &ctl); onscreeninfo = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXInactiveMode; HIViewFindByID(root, cid, &ctl); inactiveMode = GetControl32BitValue(ctl); cid.id = iNibXBSXBootup; HIViewFindByID(root, cid, &ctl); Settings.BSXBootup = GetControl32BitValue(ctl) ? true : false; DisposeControlActionUPP(arrowsUPP); DisposeControlActionUPP(sliderUPP); err = RemoveEventHandler(pRef); DisposeEventHandlerUPP(pUPP); err = RemoveEventHandler(aRef); DisposeEventHandlerUPP(aUPP); err = RemoveEventHandler(iRef); DisposeEventHandlerUPP(iUPP); err = RemoveEventHandler(tRef); DisposeEventHandlerUPP(tUPP); CFRelease(tWindowRef); } DisposeNibReference(nibRef); S9xGraphicsInit(); if (((oldSynchronize != Settings.SoundSync ) || (old16BitPlayback != Settings.SixteenBitSound ) || (oldStereo != Settings.Stereo ) || (oldReverseStereo != Settings.ReverseStereo ) || (oldPlaybackRate != Settings.SoundPlaybackRate) || (oldInputRate != Settings.SoundInputRate ) || (oldInterval != macSoundInterval_ms ) || (oldBufferSize != macSoundBuffer_ms ) || (oldLagEnable != macSoundLagEnable ) || (oldVolume != macSoundVolume )) && cartOpen) SNES9X_InitSound(); if (!fullscreen && cartOpen) { InitGameWindow(); ShowWindow(gWindow); } if (cartOpen) { FSRef ref; err = FSPathMakeRef((unsigned char *) Memory.ROMFilename, &ref, NULL); if (err == noErr) CheckSaveFolder(&ref); } } }
void create_driverchooser (HWND hwnd, TDRIVERCHOOSER * choose_t) { EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit }; RgnHandle cursorRgn = NULL; WindowRef wdrvchooser; ControlID controlID; EventRecord event; IBNibRef nibRef; OSStatus err; if (hwnd == NULL) return; /* Search the bundle for a .nib file named 'odbcadmin'. */ err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (CFSTR ("org.iodbc.adm")), CFSTR ("odbcdriver"), &nibRef); if (err == noErr) { /* Nib found ... so create the window */ CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wdrvchooser); DisposeNibReference (nibRef); /* Set the control into the structure */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, DCLIST_CNTL, wdrvchooser, choose_t->driverlist); GETCONTROLBYID (controlID, CNTL_SIGNATURE, DCFINISH_CNTL, wdrvchooser, choose_t->b_add); GETCONTROLBYID (controlID, CNTL_SIGNATURE, DCCANCEL_CNTL, wdrvchooser, choose_t->b_remove); choose_t->driver = NULL; choose_t->mainwnd = wdrvchooser; /* Install handlers for the finish button, the cancel */ InstallEventHandler (GetControlEventTarget (choose_t->b_add), NewEventHandlerUPP (driverchooser_ok_clicked), 1, &controlSpec, choose_t, NULL); InstallEventHandler (GetControlEventTarget (choose_t->b_remove), NewEventHandlerUPP (driverchooser_cancel_clicked), 1, &controlSpec, choose_t, NULL); Drivers_nrows = 0; adddrivers_to_list (choose_t->driverlist, choose_t->mainwnd, TRUE); /* Show the window and run the loop */ choose_t->b_configure = NULL; DRIVERCHOOSER = choose_t; DeactivateControl (DRIVERCHOOSER->b_add); ShowWindow (wdrvchooser); /* The main loop */ while (choose_t->mainwnd) WaitNextEvent (everyEvent, &event, 60L, cursorRgn); } else goto error; return; error: choose_t->driver = NULL; fprintf (stderr, "Can't load Window. Err: %d\n", (int) err); return; }
/***************************************************** * * Handle_WindowCommandProcess(inHandlerCallRef, inEvent, inUserData) * * Purpose: called to handle of the events generated by the various controls of the HICustomView_Tester window * * Inputs: inHandlerCallRef - reference to the current handler call chain * inEvent - the event * inUserData - app-specified data you passed in the call to InstallEventHandler * * Returns: OSStatus - noErr indicates the event was handled * eventNotHandledErr indicates the event was not handled and the Toolbox should take over */ static pascal OSStatus Handle_WindowCommandProcess(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData) { OSStatus status; HIViewRef customView = (HIViewRef)inUserData; // getting the command HICommandExtended aCommand; status = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(aCommand), NULL, &aCommand); require_noerr(status, ExitCommandProcess); status = eventNotHandledErr; // cheking that the command came from a control if ( ! (aCommand.attributes & kHICommandFromControl) ) goto ExitCommandProcess; switch (aCommand.commandID) { // // Asking for a refresh of the custom view // case 'SNDt': HIViewSetNeedsDisplay(customView, true); status = noErr; break; // // Setting the control value of the custom view // case 'SV00': SetControl32BitValue(customView, 0); status = noErr; break; case 'SV01': SetControl32BitValue(customView, 1); status = noErr; break; case 'SV17': SetControl32BitValue(customView, 17); status = noErr; break; case 'SVTH': SetControl32BitValue(customView, 1000); status = noErr; break; case 'SVet': { HIViewRef editText; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText); char buffer[11]; Size actualSize; GetControlData(editText, kControlEntireControl, kControlEditTextTextTag, 10, buffer, &actualSize); if (actualSize > 10) actualSize = 10; buffer[actualSize] = 0; SetControl32BitValue(customView, atoi(buffer)); } status = noErr; break; // // Setting the state of the custom view // case 'CHlt': // setting the hilite to non-0 also stomps the previous hilite state if any // and we don't want that in our testing if (GetControl32BitValue(aCommand.source.control) == 1) HiliteControl(customView, 1); else HiliteControl(customView, 0); status = noErr; break; case 'CEnb': { HIViewRef hiliteControl; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckHiliteID, &hiliteControl); if (GetControl32BitValue(aCommand.source.control) == 1) EnableControl(customView); else DisableControl(customView); UInt16 prevHilite = GetControlHilite(customView); if ((prevHilite == kControlInactivePart) || (prevHilite == kControlDisabledPart)) DisableControl(hiliteControl); else EnableControl(hiliteControl); HIViewSetNeedsDisplay(customView, true); } status = noErr; break; case 'CAct': { HIViewRef hiliteControl; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckHiliteID, &hiliteControl); if (GetControl32BitValue(aCommand.source.control) == 1) ActivateControl(customView); else DeactivateControl(customView); UInt16 prevHilite = GetControlHilite(customView); if ((prevHilite == kControlInactivePart) || (prevHilite == kControlDisabledPart)) DisableControl(hiliteControl); else EnableControl(hiliteControl); HIViewSetNeedsDisplay(customView, true); } status = noErr; break; // // Testing the custom view in or as a scroller in a HIScrollView // case 'CTiS': case 'CTaS': if (GetControl32BitValue(aCommand.source.control) == 1) { // create a HIScrollView and install it where and as the custom view was HIViewRef scrollView; status = HIScrollViewCreate(kHIScrollViewValidOptions, &scrollView); require_noerr(status, ExitCommandProcess); HIRect frame; status = HIViewGetFrame(customView, &frame); require_noerr(status, ExitCommandProcess); status = HIViewSetFrame(scrollView, &frame); require_noerr(status, ExitCommandProcess); HIViewSetLayoutInfo(scrollView, &kBindToParentLayout); HIViewSetLayoutInfo(customView, &kNoBindLayout); status = HIViewAddSubview(HIViewGetSuperview(customView), scrollView); require_noerr(status, ExitCommandProcess); if (aCommand.commandID == 'CTiS') { // if we are testing the custom view in a scroller, we embed it in a scrolling User Pane // that we embed in the HIScrollView Rect boundsRect = {0, 0, 1000, 1000}; HIViewRef userPane; status = CreateUserPaneControl(NULL, &boundsRect, kControlSupportsEmbedding, &userPane); require_noerr(status, ExitCommandProcess); EventTypeSpec userPaneEvents[] = { {kEventClassScrollable, kEventScrollableGetInfo}, {kEventClassScrollable, kEventScrollableScrollTo} }; InstallControlEventHandler(userPane, UserPaneHandler, 2, userPaneEvents, userPane, NULL); status = HIViewAddSubview(scrollView, userPane); require_noerr(status, ExitCommandProcess); status = HIViewAddSubview(userPane, customView); require_noerr(status, ExitCommandProcess); HIViewSetVisible(userPane, true); } else { // else we just embed the custom view directly in the HIScrollView status = HIViewAddSubview(scrollView, customView); require_noerr(status, ExitCommandProcess); } HIViewSetVisible(scrollView, true); // the 2 modes are not compatible so we disable the other check box HIViewRef otherCheckToDisable; if (aCommand.commandID == 'CTiS') HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestAsScrollID, &otherCheckToDisable); else HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestInScrollID, &otherCheckToDisable); require_noerr(status, ExitCommandProcess); DisableControl(otherCheckToDisable); // if we reach here, status is already set to noErr so we don't set it again } else { // we remove the HIScrollView and set the custom view back to where and as it was HIViewRef scrollView; if (aCommand.commandID == 'CTiS') scrollView = HIViewGetSuperview(HIViewGetSuperview(customView)); else scrollView = HIViewGetSuperview(customView); status = HIViewAddSubview(HIViewGetSuperview(scrollView), customView); require_noerr(status, ExitCommandProcess); HIRect frame; status = HIViewGetFrame(scrollView, &frame); require_noerr(status, ExitCommandProcess); status = HIViewSetFrame(customView, &frame); require_noerr(status, ExitCommandProcess); HIViewSetLayoutInfo(customView, &kBindToParentLayout); // by releasing the HIScrollView, we also release the scrolling User Pane if any // which was embedded inside CFRelease(scrollView); // we renable the other check box HIViewRef otherCheckToEnable; if (aCommand.commandID == 'CTiS') HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestAsScrollID, &otherCheckToEnable); else HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestInScrollID, &otherCheckToEnable); require_noerr(status, ExitCommandProcess); EnableControl(otherCheckToEnable); // if we reach here, status is already set to noErr so we don't set it again } break; } ExitCommandProcess: return status; } // Handle_WindowCommandProcess
static pascal OSStatus NPClientDialogEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { #pragma unused (inHandlerRef, inUserData) OSStatus err, result = eventNotHandledErr; switch (GetEventClass(inEvent)) { case kEventClassCommand: switch (GetEventKind(inEvent)) { case kEventCommandProcess: HICommand tHICommand; err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &tHICommand); if (err == noErr) { switch (tHICommand.commandID) { case 'OK__': CFStringRef ref; HIViewRef ctl, root; HIViewID cid; unsigned char pstr[256]; root = HIViewGetRoot(mRef); cid.id = 0; cid.signature = 'SVIP'; HIViewFindByID(root, cid, &ctl); GetEditTextText(ctl, pstr); DeactivateControl(ctl); ConvertPString(pstr, npclient.serverIP); if (strlen(npclient.serverIP) == 0) strcpy(npclient.serverIP, "127.0.0.1"); strcpy(npServerIP, npclient.serverIP); printf("%s\n", npServerIP); cid.signature = 'CLNM'; HIViewFindByID(root, cid, &ctl); CopyEditTextCFString(ctl, &ref); DeactivateControl(ctl); if (ref) { Boolean r; r = CFStringGetCString(ref, npclient.name, 256, MAC_PATH_ENCODING); if (!r) strcpy(npclient.name, "unknown"); else if (strlen(npclient.name) == 0) strcpy(npclient.name, "Guest"); CFRelease(ref); } else strcpy(npclient.name, "unknown"); strcpy(npName, npclient.name); printf("%s\n", npName); cid.signature = 'OK__'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); cid.signature = 'NOT_'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); npclient.dialogcancel = false; npclient.dialogprocess = kNPCDialogConnect; result = noErr; break; case 'NOT_': npclient.dialogcancel = true; npclient.dialogprocess = kNPCDialogCancel; result = noErr; break; case 'NvDn': npclient.dialogcancel = false; npclient.dialogprocess = kNPCDialogOpenEnd; result = noErr; } } } } return (result); }
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 (WindowRef wnd, LPCSTR attrs, BOOL *verify_conn) { EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit }; RgnHandle cursorRgn = NULL; TKEYVAL keyval_t; ControlID controlID; WindowRef wkeyval; ControlRef control; EventRecord event; IBNibRef nibRef; OSStatus err; /* Search the bundle for a .nib file named 'odbcadmin'. */ err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier ( CFSTR ("org.iodbc.adm")), CFSTR ("keyval"), &nibRef); if (err == noErr) { /* Nib found ... so create the window */ CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wkeyval); DisposeNibReference (nibRef); /* Install handlers for the finish button, the cancel */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVERIFYCONN_CNTL, wkeyval, keyval_t.verify_conn_cb); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSLIST_CNTL, wkeyval, keyval_t.key_list); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSKEYWORD_CNTL, wkeyval, keyval_t.key_entry); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSVALUE_CNTL, wkeyval, keyval_t.value_entry); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSUPDATE_CNTL, wkeyval, keyval_t.bupdate); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSADD_CNTL, wkeyval, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (keyval_add_clicked), 1, &controlSpec, &keyval_t, NULL); InstallEventHandler (GetControlEventTarget (keyval_t.bupdate), NewEventHandlerUPP (keyval_update_clicked), 1, &controlSpec, &keyval_t, NULL); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSOK_CNTL, wkeyval, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (keyval_ok_clicked), 1, &controlSpec, &keyval_t, NULL); GETCONTROLBYID (controlID, CNTL_SIGNATURE, GSCANCEL_CNTL, wkeyval, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (keyval_cancel_clicked), 1, &controlSpec, &keyval_t, NULL); /* Parse the attributes line */ keyval_t.mainwnd = wkeyval; addkeywords_to_list (keyval_t.key_list, attrs, &keyval_t); AdvanceKeyboardFocus (wkeyval); /* Show the window and run the loop */ DeactivateControl (keyval_t.bupdate); KEYVAL = &keyval_t; ShowSheetWindow(wkeyval, wnd); /* The main loop */ while (keyval_t.mainwnd) WaitNextEvent (everyEvent, &event, 60L, cursorRgn); if (keyval_t.connstr) *verify_conn = keyval_t.verify_conn; } else goto error; return keyval_t.connstr; error: fprintf (stderr, "Can't load Window. Err: %d\n", (int) err); return keyval_t.connstr; }
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; }
static pascal OSStatus NPClientDialogEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { OSStatus err, result = eventNotHandledErr; switch (GetEventClass(inEvent)) { case kEventClassCommand: switch (GetEventKind(inEvent)) { HICommand tHICommand; case kEventCommandUpdateStatus: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr && tHICommand.commandID == 'clos') { UpdateMenuCommandStatus(false); result = noErr; } break; case kEventCommandProcess: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand); if (err == noErr) { switch (tHICommand.commandID) { case 'OK__': CFStringRef ref; HIViewRef ctl, root; HIViewID cid; root = HIViewGetRoot(mRef); cid.id = 0; cid.signature = 'SVIP'; HIViewFindByID(root, cid, &ctl); GetEditTextCStr(ctl, npclient.serverIP); DeactivateControl(ctl); if (npclient.serverIP[0] == 0) strcpy(npclient.serverIP, "127.0.0.1"); strcpy(npServerIP, npclient.serverIP); printf("%s\n", npServerIP); cid.signature = 'CLNM'; HIViewFindByID(root, cid, &ctl); CopyEditTextCFString(ctl, &ref); DeactivateControl(ctl); if (ref) { Boolean r; r = CFStringGetCString(ref, npclient.name, 256, kCFStringEncodingUTF8); if (!r) strcpy(npclient.name, "unknown"); else if (npclient.name[0] == 0) strcpy(npclient.name, "Guest"); CFRelease(ref); } else strcpy(npclient.name, "unknown"); strcpy(npName, npclient.name); printf("%s\n", npName); cid.signature = 'OK__'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); cid.signature = 'NOT_'; HIViewFindByID(root, cid, &ctl); DeactivateControl(ctl); npclient.dialogcancel = false; npclient.dialogprocess = kNPCDialogConnect; result = noErr; break; case 'NOT_': npclient.dialogcancel = true; npclient.dialogprocess = kNPCDialogCancel; result = noErr; break; case 'NvDn': npclient.dialogcancel = false; npclient.dialogprocess = kNPCDialogOpenEnd; result = noErr; break; } } break; } break; } return (result); }
void ConfigureCheat (void) { if (!cartOpen) return; OSStatus err; IBNibRef nibRef; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { err = CreateWindowFromNib(nibRef, CFSTR("CheatEntry"), &wRef); if (err == noErr) { DataBrowserCallbacks callbacks; EventHandlerRef eref; EventHandlerUPP eUPP; EventTypeSpec events[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus }, { kEventClassWindow, kEventWindowClose } }; HIViewRef ctl, root; HIViewID cid; root = HIViewGetRoot(wRef); cid.id = 0; cid.signature = kDataBrowser; HIViewFindByID(root, cid, &dbRef); #ifdef MAC_PANTHER_SUPPORT if (systemVersion < 0x1040) { HISize minSize; Rect rct; GetWindowBounds(wRef, kWindowContentRgn, &rct); minSize.width = (float) (rct.right - rct.left); minSize.height = (float) (rct.bottom - rct.top ); err = SetWindowResizeLimits(wRef, &minSize, NULL); } #endif callbacks.version = kDataBrowserLatestCallbacks; err = InitDataBrowserCallbacks(&callbacks); callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(DBClientDataCallback); callbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP(DBCompareCallBack); callbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP(DBItemNotificationCallBack); err = SetDataBrowserCallbacks(dbRef, &callbacks); if (systemVersion >= 0x1040) err = DataBrowserChangeAttributes(dbRef, kDataBrowserAttributeListViewAlternatingRowColors, kDataBrowserAttributeNone); InitCheatItems(); ImportCheatItems(); DataBrowserItemID *id; id = new DataBrowserItemID[MAC_MAX_CHEATS]; if (!id) QuitWithFatalError(0, "cheat 01"); numofcheats = 0; for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++) { if (citem[i].valid) { id[numofcheats] = citem[i].id; numofcheats++; } } if (numofcheats) err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, numofcheats, id, kDataBrowserItemNoProperty); delete [] id; cid.signature = kNewButton; HIViewFindByID(root, cid, &ctl); if (numofcheats == MAC_MAX_CHEATS) err = DeactivateControl(ctl); else err = ActivateControl(ctl); cid.signature = kAllButton; HIViewFindByID(root, cid, &ctl); if (numofcheats == 0) err = DeactivateControl(ctl); else err = ActivateControl(ctl); cid.signature = kDelButton; HIViewFindByID(root, cid, &ctl); err = DeactivateControl(ctl); eUPP = NewEventHandlerUPP(CheatEventHandler); err = InstallWindowEventHandler(wRef, eUPP, GetEventTypeCount(events), events, (void *) wRef, &eref); err = SetKeyboardFocus(wRef, dbRef, kControlFocusNextPart); MoveWindowPosition(wRef, kWindowCheatEntry, true); ShowWindow(wRef); err = RunAppModalLoopForWindow(wRef); HideWindow(wRef); SaveWindowPosition(wRef, kWindowCheatEntry); err = RemoveEventHandler(eref); DisposeEventHandlerUPP(eUPP); DisposeDataBrowserItemNotificationUPP(callbacks.u.v1.itemNotificationCallback); DisposeDataBrowserItemCompareUPP(callbacks.u.v1.itemCompareCallback); DisposeDataBrowserItemDataUPP(callbacks.u.v1.itemDataCallback); CFRelease(wRef); DetachCheatItems(); } DisposeNibReference(nibRef); } }
pascal OSStatus keyval_add_clicked (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { TKEYVAL *keyval_t = (TKEYVAL *) inUserData; DataBrowserItemID item = DBITEM_ID + 1; DataBrowserCallbacks dbCallbacks; ThemeDrawingState outState = NULL; UInt16 colSize[2] = { 150, 250 }; SInt16 outBaseline; Point ioBound; CFStringRef data[2]; Size len; int i = 0, j; if (keyval_t) { GetThemeDrawingState (&outState); GetControlData (keyval_t->key_entry, 0, kControlEditTextCFStringTag, sizeof (CFStringRef), &data[0], &len); if (CFStringGetLength(data[0])) { GetControlData (keyval_t->value_entry, 0, kControlEditTextCFStringTag, sizeof (CFStringRef), &data[1], &len); /* Try to see if the keyword already exists */ for (i = 0; i < KEYVAL_nrows; i++, item++) if (CFStringCompare (data[0], KEYVAL_array[0][i], 0) == kCFCompareEqualTo) goto done; /* Install an event handler on the component databrowser */ dbCallbacks.version = kDataBrowserLatestCallbacks; InitDataBrowserCallbacks (&dbCallbacks); dbCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP (keyval_notification_item); /* On Mac OS X 10.0.x : this is clientDataCallback */ dbCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP (keyval_getset_item); SetDataBrowserCallbacks (keyval_t->key_list, &dbCallbacks); /* Begin the draw of the data browser */ SetDataBrowserTarget (keyval_t->key_list, DBITEM_ID); /* An update operation */ if(i<KEYVAL_nrows) { CFRelease (KEYVAL_array[1][i]); KEYVAL_array[1][i] = data[1]; UpdateDataBrowserItems (keyval_t->key_list, DBITEM_ID, 1, &item, GSKEYWORD_ID, kDataBrowserItemNoProperty); } else if(len) { KEYVAL_array[0][i] = data[0]; KEYVAL_array[1][i] = data[1]; AddDataBrowserItems (keyval_t->key_list, DBITEM_ID, 1, &item, GSKEYWORD_ID); KEYVAL_nrows++; } for(j = 0 ; j < KEYVAL_nrows ; j++) { for(i = 0 ; i < 2 ; i++) { GetThemeTextDimensions (KEYVAL_array[i][j], kThemeSystemFont, kThemeStateActive, false, &ioBound, &outBaseline); if(colSize[i] < ioBound.h) colSize[i] = ioBound.h; } } ActivateControl (keyval_t->key_list); /* Resize the columns to have a good look */ SetDataBrowserTableViewNamedColumnWidth (keyval_t->key_list, GSKEYWORD_ID, colSize[0] + 20); SetDataBrowserTableViewNamedColumnWidth (keyval_t->key_list, GSVALUE_ID, colSize[1] + 20); DrawOneControl (keyval_t->key_list); /* Remove the DataBrowser callback */ SetDataBrowserCallbacks (NULL, &dbCallbacks); } done: SetControlData (keyval_t->key_entry, 0, kControlEditTextTextTag, 0, ""); DrawOneControl (keyval_t->key_entry); SetControlData (keyval_t->value_entry, 0, kControlEditTextTextTag, 0, ""); DrawOneControl (keyval_t->value_entry); DeactivateControl (KEYVAL->bupdate); DrawOneControl (KEYVAL->bupdate); } return noErr; }
ALIST_API void ALActivate(Boolean isActive, ALHandle hAL) { short status; short hilite; ALPtr pAL; // Sanity check! if (hAL == nil || *hAL == nil) return; // Get current status of the active flag status = BTST((*hAL)->flags, alFActive) ? alBitSet : alBitClear; if ((isActive && status == alBitSet) || (!isActive && status == alBitClear)) return; // Do nothing, we're already the way the user wants us to be. else { // Hide the selection hiliting. _ALHiliteSelected(hAL); pAL = *hAL; if ( isActive ) { BSET(pAL->flags, alFComingActive); BSET(pAL->flags, alFActive); hilite = kControlNoPart; } else { BCLR(pAL->flags, alFActive); hilite = kControlInactivePart; // Dispose of the offscreen port if we're inactive. if (pAL->offscreenPort != nil) { DisposeGWorld(pAL->offscreenPort); (*hAL)->offscreenPort = nil; } } // Show the selection hiliting. _ALHiliteSelected(hAL); #if ALIST_USEAPPEARANCEMGR if (BTST((*hAL)->flags, alFHasAppearanceMgr) != 0) { if ((*hAL)->vScroll != nil) { if (hilite == kControlInactivePart) DeactivateControl((*hAL)->vScroll); else ActivateControl((*hAL)->vScroll); } if ((*hAL)->hScroll != nil) { if (hilite == kControlInactivePart) DeactivateControl((*hAL)->hScroll); else ActivateControl((*hAL)->hScroll); } } else #endif { if ((*hAL)->vScroll != nil) HiliteControl((*hAL)->vScroll, hilite); if ((*hAL)->hScroll != nil) HiliteControl((*hAL)->hScroll, hilite); } ALUpdate( nil, hAL ); } } // ALActivate