static DialogRef DrawDialogTheSystem6or7Way(void) { DialogItemType itemType; Handle itemHandle; Rect itemBox; DialogRef theDialog = GetNewDialog(256, NULL, (WindowRef)-1L); if (theDialog == NULL) return(NULL); // Move it! MoveWindow(GetDialogWindow(theDialog), 10, 271, false); // Setting the check box GetDialogItem(theDialog, 2, &itemType, &itemHandle, &itemBox); SetControlValue((ControlHandle)itemHandle, 1); // Setting a radio button GetDialogItem(theDialog, 3, &itemType, &itemHandle, &itemBox); SetControlValue((ControlHandle)itemHandle, 1); // Setting the draw proc for the user item GetDialogItem(theDialog, 13, &itemType, &itemHandle, &itemBox); gUserH = (itemBox.left + itemBox.right) / 2; gUserV = (itemBox.top + itemBox.bottom) / 2; SetDialogItem(theDialog, 13, itemType, (Handle)&MyDrawUserItem, &itemBox); // Setting the action proc for the scroll bar so that the PageUp/PageDown/Up/Down buttons work GetDialogItem(theDialog, 14, &itemType, &itemHandle, &itemBox); SetControlAction((ControlHandle)itemHandle, ScrollBarActionProc); ShowWindow(GetDialogWindow(theDialog)); return(theDialog); }
// -------------------------------------------------------------------------------------- void OpenPrefsDialog(void) { DialogRef dialog; WindowRef dialogWindow; ControlRef control; ListHandle iconList; Cell theCell; dialog = GetNewDialog(rPrefsDialogPlatinum, NULL, kFirstWindowOfClass); if (dialog == NULL) ExitToShell(); SetPortDialogPort(dialog); dialogWindow = GetDialogWindow(dialog); SetDialogDefaultItem(dialog, kStdOkItemIndex); SetDialogCancelItem(dialog, kStdCancelItemIndex); GetDialogItemAsControl(dialog, iIconList, &control); GetControlData(control, kControlEntireControl, kControlListBoxListHandleTag, sizeof(ListHandle), &iconList, NULL); AddRowsAndDataToIconList(iconList, rIconListIconBaseID); (*iconList)->selFlags = lOnlyOne; SetPt(&theCell, 0, 0); LSetSelect(true, theCell, iconList); SetKeyboardFocus(dialogWindow, control, kControlFocusNextPart); gPanelNumber = 0; DisableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog); ShowWindow(dialogWindow); } // OpenPrefsDialog
static PASCAL_RTN Boolean QTCmpr_FilterProc (DialogPtr theDialog, EventRecord *theEvent, short *theItemHit, long theRefCon) { #pragma unused(theItemHit, theRefCon) Boolean myEventHandled = false; WindowRef myEventWindow = NULL; WindowRef myDialogWindow = NULL; #if TARGET_API_MAC_CARBON myDialogWindow = GetDialogWindow(theDialog); #else myDialogWindow = theDialog; #endif switch (theEvent->what) { case updateEvt: // update the specified window, if it's behind the modal dialog box myEventWindow = (WindowRef)theEvent->message; if ((myEventWindow != NULL) && (myEventWindow != myDialogWindow)) { #if TARGET_OS_MAC QTFrame_HandleEvent(theEvent); #endif myEventHandled = false; // so sayeth IM } break; } return(myEventHandled); }
void mac_openabout(void) { DialogItemType itemtype; Handle item; VersRecHndl vers; Rect box; StringPtr longvers; WinInfo *wi; if (windows.about) SelectWindow(windows.about); else { windows.about = GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); wi = snew(WinInfo); memset(wi, 0, sizeof(*wi)); wi->wtype = wAbout; wi->update = &mac_updateabout; wi->click = &mac_clickabout; wi->activate = &mac_activateabout; wi->close = &mac_closeabout; SetWRefCon(windows.about, (long)wi); vers = (VersRecHndl)Get1Resource('vers', 1); if (vers != NULL && *vers != NULL) { longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, &itemtype, &item, &box); assert(itemtype & kStaticTextDialogItem); SetDialogItemText(item, longvers); } ShowWindow(windows.about); } }
void ConfigDialog::Refresh() { HWND hWnd = GetDialogWindow(); if(hWnd != NULL) { SendMessage(hWnd, WM_APP_REFRESH, 0, 0); } }
/* ShowDialogWindow(theDialog) Makes the dialog visible. Thread Safety: ShowDialogWindow is not thread-safe. */ void ShowDialogWindow(DialogPtr theDialog) { WindowRef theWindow; theWindow = GetDialogWindow(theDialog); if (theWindow != NULL) ShowWindow(theWindow); }
/* InvalDBox(theDialog, itemNumber) Thread Safety: InvalDBox is not thread-safe. */ static void InvalDBox(DialogPtr theDialog, int itemNumber) { WindowRef theWindow; Rect box; theWindow = GetDialogWindow(theDialog); GetDBox(theDialog, itemNumber, &box); InvalWindowRect(theWindow, &box); }
static void RunDialogTheSystem6or7Way(DialogRef theDialog) { SInt16 itemHit; DialogItemType itemType; Handle itemHandle; Rect itemBox; BringToFront(GetDialogWindow(theDialog)); do { ModalDialog(MySystem6or7DialogFilter, &itemHit); switch (itemHit) { case 2: { // we enable or disable the user item depending on whether the box is checked or not GetDialogItem(theDialog, itemHit, &itemType, &itemHandle, &itemBox); SInt16 enable = GetControlValue((ControlHandle)itemHandle); SetControlValue((ControlHandle)itemHandle, 1 - enable); GetDialogItem(theDialog, 13, &itemType, &itemHandle, &itemBox); SetDialogItem(theDialog, 13, enable?userItem+itemDisable:userItem, itemHandle, &itemBox); HideDialogItem(theDialog, 13); ShowDialogItem(theDialog, 13); } break; case 3: case 4: case 5: case 6: case 7: { // one radio button was chosen, let's adjust them all (we could also remember the last one...) int i; for (i = 3; i <= 7; i++) { GetDialogItem(theDialog, i, &itemType, &itemHandle, &itemBox); SetControlValue((ControlHandle)itemHandle, (i == itemHit)?1:0); } } break; case 14: { // the indicator of the scroll bar was moved so let's display the value in the first edit box // this is System 6 or 7 style so the controls can only handle 16 bits value (hence a max of 32767) GetDialogItem(theDialog, itemHit, &itemType, &itemHandle, &itemBox); SInt16 newValue = GetControlValue((ControlHandle)itemHandle); Str255 theStr; NumToString(newValue, theStr); GetDialogItem(theDialog, 9, &itemType, &itemHandle, &itemBox); SetDialogItemText(itemHandle, theStr); SelectDialogItemText(theDialog, 9, 0, 32767); } break; } } while (!(itemHit == ok)); DisposeDialog(theDialog); }
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); }
void mac_newkey(void) { KeyState *ks; WinInfo *wi; Handle h; short type; Rect rect; ks = snew(KeyState); ks->box = GetNewDialog(wKey, NULL, (WindowPtr)-1); GetDialogItem(ks->box, wiKeyProgress, &type, &h, &rect); ks->progress = (ControlHandle)h; wi = snew(WinInfo); memset(wi, 0, sizeof(*wi)); wi->ks = ks; wi->wtype = wKey; wi->update = &mac_updatekey; wi->click = &mac_clickkey; wi->activate = &mac_activatekey; SetWRefCon(GetDialogWindow(ks->box), (long)wi); ShowWindow(GetDialogWindow(ks->box)); }
// -------------------------------------------------------------------------------------- void ClosePrefsDialog(DialogRef prefsDialog) { ControlRef listBoxControl; ListHandle iconList; HideWindow(GetDialogWindow(prefsDialog)); GetDialogItemAsControl(prefsDialog, iIconList, &listBoxControl); GetControlData(listBoxControl, kControlEntireControl, kControlListBoxListHandleTag, sizeof(ListHandle), &iconList, NULL); ReleaseIconListIcons(iconList); DisposeDialog(prefsDialog); EnableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog); }
void QTApp_AdjustMenus (WindowReference theWindow, MenuReference theMenu) { #if TARGET_OS_MAC #pragma unused(theMenu) #endif WindowObject myWindowObject = NULL; MovieController myMC = NULL; MenuReference myMenu; #if TARGET_OS_WIN32 myMenu = theMenu; #endif #if TARGET_OS_MAC myMenu = GetMenuHandle(kFileMenuResID); #endif if (theWindow != NULL) myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow); if (myWindowObject != NULL) myMC = (**myWindowObject).fController; // don't let us close the monitor window if (QTFrame_GetFrontAppWindow() == QTFrame_GetWindowReferenceFromWindow(GetDialogWindow(gMonitor))) QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kDisableMenuItem); #if TARGET_OS_MAC myMenu = GetMenuHandle(kTestMenuResID); #endif QTFrame_SetMenuItemState(myMenu, IDM_SHOW_VIDEO_SETTINGS, gVideoChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemState(myMenu, IDM_SHOW_SOUND_SETTINGS, gSoundChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemState(myMenu, IDM_RECORD_VIDEO, gVideoChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemCheck(myMenu, IDM_RECORD_VIDEO, (gVideoChannel && gRecordVideo) ? true : false); QTFrame_SetMenuItemState(myMenu, IDM_RECORD_SOUND, gSoundChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemCheck(myMenu, IDM_RECORD_SOUND, (gSoundChannel && gRecordSound) ? true : false); QTFrame_SetMenuItemState(myMenu, IDM_RECORD_SPLIT, (gSoundChannel && gRecordSound && gVideoChannel && gRecordVideo) ? kEnableMenuItem : kDisableMenuItem); QTFrame_SetMenuItemCheck(myMenu, IDM_RECORD_SPLIT, gSplitTracks ? true : false); QTFrame_SetMenuItemState(myMenu, IDM_QUARTER_SIZE, gVideoChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemCheck(myMenu, IDM_QUARTER_SIZE, gQuarterSize); QTFrame_SetMenuItemState(myMenu, IDM_HALF_SIZE, gVideoChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemCheck(myMenu, IDM_HALF_SIZE, gHalfSize); QTFrame_SetMenuItemState(myMenu, IDM_FULL_SIZE, gVideoChannel == NULL ? kDisableMenuItem : kEnableMenuItem); QTFrame_SetMenuItemCheck(myMenu, IDM_FULL_SIZE, gFullSize); QTFrame_SetMenuItemState(myMenu, IDM_RECORD, (gSoundChannel && gRecordSound) || (gVideoChannel && gRecordVideo) ? kEnableMenuItem : kDisableMenuItem); }
// -------------------------------------------------------------------------------------- static pascal OSStatus listBoxControlEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *prefsDialog) { OSStatus result = eventNotHandledErr; UInt32 eventClass, eventKind; DialogRef dialog; WindowRef dialogWindow; eventClass = GetEventClass(event); eventKind = GetEventKind(event); switch (eventClass) { case kEventClassTextInput: switch (eventKind) { case kEventTextInputUnicodeForKeyEvent: /* The strategy here is to first let the default handler handle the event (i.e. change the selected cell in the category list box control), then react to that change by showing the correct category panel. However the key pressed could potentially cause the default or cancel button to get hit. In this case, our window handler will be called which will dispose of the dialog. If this is the case, we need to not postprocess the event. We will test for this by getting the dialog's window, retaining it, calling the default handler, then getting the window's retain count. If the retain count is back to 1, then we know the dialog is already disposed. */ dialog = (DialogRef)prefsDialog; dialogWindow = GetDialogWindow(dialog); RetainWindow(dialogWindow); // hold onto the dialog's window result = CallNextEventHandler(nextHandler, event); if (result == noErr) // we don't need to postprocess if nothing happened { ItemCount retainCount; retainCount = GetWindowRetainCount(dialogWindow); if (retainCount > 1) // if we're the last one holding the window handleDialogItemHit(dialog, iIconList); // then there's no } // need to postprocess anything because it's about to go away ReleaseWindow(dialogWindow); break; } break; } return result; }
void ConfigDialog::ShowDialog() { HWND hWnd = GetDialogWindow(); if(hWnd != NULL) { SetFocus(hWnd); return; } else { mConfigInfo = *ConfigManager::Get()->GetConfig(); ghInstance = PluginManager::Get()->GetPluginInterface()->hDllInstance; DialogBox(ghInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, ConfigProc); } }
// -------------------------------------------------------------------------------------- void ClosePrefsDialog(DialogRef prefsDialog) { ControlRef listBoxControl; ListHandle iconList; HideWindow(GetDialogWindow(prefsDialog)); GetDialogItemAsControl(prefsDialog, iIconList, &listBoxControl); GetControlData(listBoxControl, kControlEntireControl, kControlListBoxListHandleTag, sizeof(ListHandle), &iconList, NULL); ReleaseIconListIcons(iconList); DisposeEventHandlerUPP(gDialogEventHandler); DisposeEventHandlerUPP(gListBoxControlEventHandler); RegisterListDefinition(kIconListLDEF, NULL); // unregister the list definition DisposeDialog(prefsDialog); EnableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog); }
static Boolean MyMacOS8or9DialogFilter(DialogRef theDialog, EventRecord *inEvent, DialogItemIndex *itemHit) { // this ModalFilterProc is much simpler than its System 6 or 7 ancestor // the controls used instead of the dialog items are a bit smarter and more self-standing if ((inEvent->what == keyDown) || (inEvent->what == autoKey)) { char c = (inEvent->message & charCodeMask); // return or enter key? if ((c == kReturnCharCode) || (c == kEnterCharCode)) { *itemHit = 1; return true; } // tab key? if (c == kTabCharCode) { AdvanceKeyboardFocus(GetDialogWindow(theDialog)); return true; } } return false; }
/* void showSplashScreen (); */ NS_IMETHODIMP nsNativeAppSupportMac::ShowSplashScreen() { mDialog = ::GetNewDialog(rSplashDialog, nil, (WindowPtr)-1L); if (!mDialog) return NS_ERROR_FAILURE; #if TARGET_CARBON ::ShowWindow(GetDialogWindow(mDialog)); ::SetPortDialogPort(mDialog); #else ::ShowWindow(mDialog); ::SetPort(mDialog); #endif ::DrawDialog(mDialog); // we don't handle events for this dialog, so we // need to draw explicitly. Yuck. return NS_OK; }
OSStatus DisplayAlert(CFStringRef error, CFStringRef explanation, OSStatus status) { DialogRef dialog; if (status == 0) CreateStandardAlert(kAlertStopAlert, error, explanation, NULL, &dialog); else { CFStringRef exp; if (status > 0) { char s[8]; CFStringRef stat = UTCreateStringForOSType(status); CFStringGetCString(stat, s, sizeof(s), kCFStringEncodingMacRoman); CFRelease(stat); exp = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s: '%s' (0x%x)"), CFStringGetCStringPtr(explanation, kCFStringEncodingMacRoman), s, status); } else { exp = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s: %d (0x%x)"), CFStringGetCStringPtr(explanation, kCFStringEncodingMacRoman), status, status); } CreateStandardAlert(kAlertStopAlert, error, exp, NULL, &dialog); } SetWindowTitleWithCFString(GetDialogWindow(dialog), CFSTR("Accordion")); RunStandardAlert(dialog, NULL, NULL); return noErr; }
static int DoXOPAlert(short dlogID, const char* title, const char* message) { DialogPtr theDialog; WindowRef theWindow; short hit; unsigned char temp[256]; int result = 0; ArrowCursor(); paramtext(message, "", "", ""); theDialog = GetNewDialog(dlogID, NULL, (WindowPtr)-1L); // This must access Igor's data fork which contains the DLOG resources for these dialogs. if (theDialog == NULL) return -1; theWindow = GetDialogWindow(theDialog); if (theWindow == NULL) return -1; CopyCStringToPascal(title, temp); SetWTitle(theWindow, temp); ShowDialogWindow(theDialog); do { ModalDialog(NULL, &hit); switch(hit) { case 1: // OK or Yes. result = 1; break; case 2: // No or Cancel. if (dlogID == IGOR_OK_CANCEL_DLOG) result = -1; // Cancel result is -1. else result = 2; break; case 3: // Cancel. result = -1; break; } } while(result == 0); DisposeDialog(theDialog); return result; }
void MySelectDialogItemText(DialogRef theDialog, short editTextitemNum, short strtSel, short endSel) { #if TARGET_API_MAC_CARBON // with the new MAC code, the edit text item with the focus was not showing the text // it acted like the text was invisible... like it had drawn it and didn't care to redraw it. // I don't know what is up with that, but Hiding and Showing the item seems to do the trick // even though InvalDialogItemRect didn't help if(!IsWindowVisible(GetDialogWindow(theDialog))) { // then this is being called when the window is being set up // and so we need to use our trick HideDialogItem(theDialog,editTextitemNum); ShowDialogItem(theDialog,editTextitemNum); } #endif SelectDialogItemText(theDialog,editTextitemNum,strtSel,endSel); }
/* DisplayDialogCmd(theDialog, dlogItemNo, cmd) Displays the command in an IGOR-style dialog. See GBLoadWaveDialog.c for an example. dlogItemNo is the item number of the dialog item in which the command is to be displayed. On the Macintosh, this must be a user item. On Windows, it must be an EDITTEXT item. Thread Safety: DisplayDialogCmd is not thread-safe. */ void DisplayDialogCmd(DialogPtr theDialog, int dlogItemNo, const char* cmd) { WindowRef theWindow; CGrafPtr thePort; Rect box; int font, size; int lineHeight; FontInfo info; RgnHandle saveClipRgnH; theWindow = GetDialogWindow(theDialog); thePort = GetWindowPort(theWindow); font = GetPortTextFont(thePort); // Save text characteristics. size = GetPortTextSize(thePort); TextFont(kFontIDMonaco); TextSize(9); GetFontInfo(&info); lineHeight = info.ascent + info.descent + info.leading; GetDBox(theDialog, dlogItemNo, &box); saveClipRgnH = NewRgn(); if (saveClipRgnH != NULL) { GetClip(saveClipRgnH); ClipRect(&box); InsetRect(&box, 2, 2); EraseRect(&box); if (*cmd != 0) { MoveTo(box.left+2, box.top + info.ascent + 2); DrawDialogCmd(cmd, lineHeight); } SetClip(saveClipRgnH); DisposeRgn(saveClipRgnH); } TextFont(font); // Restore font, size, style. TextSize(size); }
static PyObject * MacOS_splash(PyObject *self, PyObject *args) { int resid = -1; static DialogPtr curdialog = NULL; DialogPtr olddialog; WindowRef theWindow; CGrafPtr thePort; #if 0 short xpos, ypos, width, height, swidth, sheight; #endif if (!PyArg_ParseTuple(args, "|i", &resid)) return NULL; olddialog = curdialog; curdialog = NULL; if ( resid != -1 ) { curdialog = GetNewDialog(resid, NULL, (WindowPtr)-1); if ( curdialog ) { theWindow = GetDialogWindow(curdialog); thePort = GetWindowPort(theWindow); #if 0 width = thePort->portRect.right - thePort->portRect.left; height = thePort->portRect.bottom - thePort->portRect.top; swidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left; sheight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - LMGetMBarHeight(); xpos = (swidth-width)/2; ypos = (sheight-height)/5 + LMGetMBarHeight(); MoveWindow(theWindow, xpos, ypos, 0); ShowWindow(theWindow); #endif DrawDialog(curdialog); } } if (olddialog) DisposeDialog(olddialog); Py_INCREF(Py_None); return Py_None; }
/* XOPDialogFilter(dialog, eventPtr, itemHitPtr) Handles the mapping of the enter key to the default button, the mapping of the escape key to the cancel button, and setting the cursor depending on the control under it. This requires that you previously called SetDialogDefaultItem, SetDialogCancelItem and SetDialogTracksCursor as shown in the sample XOPs. Also handles updating Igor windows if the dialog is moved. However, it does not update XOP windows. Thread Safety: XOPDialogFilter is not thread-safe. */ static pascal Boolean XOPDialogFilter(DialogPtr theDialog, EventRecord *eventPtr, short *itemHitPtr) { int callStdFilter; int result; result = 0; // Means ModalDialog should handle the event. callStdFilter = 1; switch (eventPtr->what) { case updateEvt: if ((WindowPtr)eventPtr->message != GetDialogWindow(theDialog)) { // Mac OS X does the updating automatically, apparently using offscreen bitmaps. } break; case keyDown: { int keyCode = eventPtr->message & charCodeMask; // Low order byte is character code. switch(keyCode) { case kHelpCharCode: if (eventPtr->modifiers & optionKey) { // option-help shows or hides Igor's contextual help window. ShowHideContextualHelp(-1); result = -1; // We handled the event. *itemHitPtr = 0; // This is not a hit in any item. callStdFilter = 0; } break; } } break; } if (callStdFilter) result = StdFilterProc(theDialog, eventPtr, itemHitPtr); return result; }
void do_about_box( void) { GrafPtr oldPort; DialogPtr dptr; short item, itemType; Handle itemHdl; Rect itemRect; dptr = GetNewDialog( rAboutBox, nil, (WindowPtr)-1L); if( dptr == (DialogPtr)0){ Handle items = NewHandle( sizeof(missing_DITL)); static Rect bounds = {40, 20, 150, 340}; if( ! items) return; BlockMove( missing_DITL, *items, sizeof(missing_DITL)); dptr = NewColorDialog( nil, &bounds, (unsigned char*)"\005About", false, dBoxProc, (WindowPtr)-1L, false, 0, items); } if( dptr == (DialogPtr)0) return; GetPort (&oldPort); SetPort (GetDialogPort(dptr)); GetDialogItem( dptr, ok, &itemType, &itemHdl, &itemRect); InsetRect( &itemRect, -4, -4); SetDialogItem( dptr, 6, userItem + itemDisable, (Handle)outline_hook_upp, &itemRect); FlushEvents( everyEvent, 0); ShowWindow( GetDialogWindow(dptr)); do { ModalDialog( about_filter_upp, &item); } while( item != ok); DisposeDialog( dptr); SetPort( oldPort); }
short EditProfilesClick(DialogPtr dialog, short itemNum, long lParam, VOIDPTR data) { Point pos,mp,clippedPos; Rect r; double speed, direction; long curSelection; long dir,i,n; unsigned long incr; char s[30]; OSErr err=0,settingsErr = 0; CProfilesList *tlist; DepthValuesSet dvals; //if (AddRecordRowIsSelected2()) if (VLAddRecordRowIsSelected(&sgObjects)) { //Last row is selected //Disable delete button MyEnableControl(dialog,EPDELETEROWS_BTN,FALSE); // And change title in replace dialog to "Add new record" MySetControlTitle(dialog, EPREPLACE, "Add New Record"); } else { MySetControlTitle(dialog, EPREPLACE, "Replace Selected"); MyEnableControl(dialog,EPDELETEROWS_BTN,TRUE); } switch(itemNum) { case EPOK: { // don't retrieve increment here // Just use the value from the last time they incremented. // Why bother them if we are not going to use the value. //if(ShowAutoIncrement2()) err = RetrieveIncrementDepth(dialog); //if(err) break; //sgSpeedUnits = GetPopSelection(dialog, EPSPEEDPOPUP); if(sgDepthVals) { DepthValuesSetH dvalsh = sgDepthValuesH; n = sgDepthVals->GetItemCount(); if(n == 0) { // no items are entered, tell the user char msg[512],buttonName[64]; GetWizButtonTitle_Cancel(buttonName); sprintf(msg,"You have not entered any data values. Either enter data values and use the 'Add New Record' button, or use the '%s' button to exit the dialog.",buttonName); printError(msg); break; } // check that all the values are in range - if there is some range // or may allow the user to change units for(i=0; i<n; i++) { char errStr[256] = ""; err=sgDepthVals->GetListItem((Ptr)&dvals,i); if(err) { SysBeep(5); // this shouldn't ever happen break; } /*UV2RTheta(dvals.value.u,dvals.value.v,&r,&theta); err = CheckWindSpeedLimit(r,sgSpeedUnits,errStr); if(err) { strcat(errStr," Check your units and each of the records you entered."); printError(errStr); return 0; // stay in the dialog }*/ } //sCellLength = EditText2Float(dialog,EPDXDY); // use map size instead and calculate km from that //sNumCells = EditText2Float(dialog,EPNUMCELLS); // will want to check that spill is inside of the grid, and grid is not super small ///////////// // point of no return ////////////// if(dvalsh == 0) { dvalsh = (DepthValuesSetH)_NewHandle(n*sizeof(DepthValuesSet)); if(!dvalsh) { TechError("EditProfilesClick:OKAY", "_NewHandle()", 0); //return EPCANCEL; break; // make them cancel so that code gets executed } sgDepthValuesH = dvalsh; } else { _SetHandleSize((Handle)dvalsh,n*sizeof(DepthValuesSet)); if(_MemError()) { TechError("EditProfilesClick:OKAY", "_NewHandle()", 0); //return EPCANCEL; break; // make them cancel, so that code gets executed } } for(i=0; i<n; i++) { if(err=sgDepthVals->GetListItem((Ptr)&dvals,i))return EPOK; (*dvalsh)[i]=dvals; } } ///////////////////////////// DisposeEPStuff(); return EPOK; } case EPCANCEL: //SetEPDialogNonPtrFields(sgWindMover,&sharedEPDialogNonPtrFields); DisposeEPStuff(); return EPCANCEL; break; case EPINCREMENT: case EPDEPTH: case EPTEMP: case EPSAL: //case EPDXDY: CheckNumberTextItem(dialog, itemNum, TRUE); // allow decimals break; case EPU: case EPV: //case EPDXDY: CheckNumberTextItemAllowingNegative(dialog, itemNum, TRUE); // allow decimals break; //case EPNUMCELLS: //CheckNumberTextItem(dialog, itemNum, FALSE); // don't allow decimals //break; case EPDELETEALL: sgDepthVals->ClearList(); VLReset(&sgObjects,1); UpdateDisplayWithCurSelection(dialog); break; case EPDELETEROWS_BTN: if (VLGetSelect(&curSelection, &sgObjects)) { sgDepthVals->DeleteItem(curSelection); VLDeleteItem(curSelection,&sgObjects); if(sgObjects.numItems == 0) { VLAddItem(1,&sgObjects); VLSetSelect(0,&sgObjects); } --curSelection; if(curSelection >-1) { VLSetSelect(curSelection,&sgObjects); } VLUpdate(&sgObjects); } UpdateDisplayWithCurSelection(dialog); break; //case EPSPEEDPOPUP: //{ //PopClick(dialog, itemNum, &sgSpeedUnits); //} //break; case EPREPLACE: err = RetrieveIncrementDepth(dialog); if(err) break; if (VLGetSelect(&curSelection, &sgObjects)) { err=GetDepthVals(dialog,&dvals); if(err) break; if(curSelection==sgDepthVals->GetItemCount()) { // replacing blank record err = AddReplaceRecord(dialog,INCREMENT_DEPTH,!REPLACE,dvals); SelectNthRow(dialog, curSelection+1 ); } else // replacing existing record { VLGetSelect(&curSelection,&sgObjects); sgDepthVals->DeleteItem(curSelection); VLDeleteItem(curSelection,&sgObjects); err = AddReplaceRecord(dialog,!INCREMENT_DEPTH,REPLACE,dvals); } } break; case EPLIST: // retrieve every time they click on the list // because clicking can cause the increment to be hidden // and we need to verify it before it gets hidden err = RetrieveIncrementDepth(dialog); if(err) break; /////////// pos=GetMouseLocal(GetDialogWindow(dialog)); VLClick(pos, &sgObjects); VLUpdate(&sgObjects); VLGetSelect(&curSelection,&sgObjects); if(curSelection == -1 ) { curSelection = sgObjects.numItems-1; VLSetSelect(curSelection,&sgObjects); VLUpdate(&sgObjects); } //ShowHideAutoIncrement(dialog,curSelection); // moved into UpdateDisplayWithCurSelection() //if (AddRecordRowIsSelected2()) if (VLAddRecordRowIsSelected(&sgObjects)) { DepthValuesSet dvals; sgDepthVals->GetListItem((Ptr)&dvals,sgDepthVals->GetItemCount()-1); err = RetrieveIncrementDepth(dialog); if(err) break; IncrementDepth(dialog,dvals.depth); } UpdateDisplayWithCurSelection(dialog); break; } return 0; }
void _debug( code_part part, const char *function, const char *str, ... ) { va_list ap; static char outputBuffer[MAX_LEN_LOG_LINE]; static unsigned int repeated = 0; /* times current message repeated */ static unsigned int next = 2; /* next total to print update */ static unsigned int prev = 0; /* total on last update */ va_start(ap, str); vssprintf(outputBuffer, str, ap); va_end(ap); ssprintf(inputBuffer[useInputBuffer1 ? 1 : 0], "[%s] %s", function, outputBuffer); if (sstrcmp(inputBuffer[0], inputBuffer[1]) == 0) { // Received again the same line repeated++; if (repeated == next) { if (repeated > 2) { ssprintf(outputBuffer, "last message repeated %u times (total %u repeats)", repeated - prev, repeated); } else { ssprintf(outputBuffer, "last message repeated %u times", repeated - prev); } printToDebugCallbacks(outputBuffer); prev = repeated; next *= 2; } } else { // Received another line, cleanup the old if (repeated > 0 && repeated != prev && repeated != 1) { /* just repeat the previous message when only one repeat occurred */ if (repeated > 2) { ssprintf(outputBuffer, "last message repeated %u times (total %u repeats)", repeated - prev, repeated); } else { ssprintf(outputBuffer, "last message repeated %u times", repeated - prev); } printToDebugCallbacks(outputBuffer); } repeated = 0; next = 2; prev = 0; } if (!repeated) { time_t rawtime; struct tm * timeinfo; char ourtime[15]; //HH:MM:SS time ( &rawtime ); timeinfo = localtime ( &rawtime ); strftime (ourtime,15,"%I:%M:%S",timeinfo); // Assemble the outputBuffer: ssprintf(outputBuffer, "%-8s|%s: %s", code_part_names[part], ourtime, useInputBuffer1 ? inputBuffer[1] : inputBuffer[0]); printToDebugCallbacks(outputBuffer); // Throw up a dialog box for windows users since most don't have a clue to check the stderr.txt file for information // Use for (duh) Fatal errors, that force us to terminate the game. if (part == LOG_FATAL) { #if defined(WZ_OS_WIN) char wbuf[512]; ssprintf(wbuf, "%s\n\nPlease check your stderr.txt file in the same directory as the program file for more details. \ \nDo not forget to upload both the stderr.txt file and the warzone2100.rpt file in your bug reports!", useInputBuffer1 ? inputBuffer[1] : inputBuffer[0]); MessageBoxA( NULL, wbuf, "Warzone has terminated unexpectedly", MB_OK|MB_ICONERROR); #elif defined(WZ_OS_MAC32) // FIXME: Needs to be made compatible with 64bit AlertStdCFStringAlertParamRec param; DialogRef dialog; OSStatus err; DialogItemIndex itemHit; char aBuffer[512]; GetStandardAlertDefaultParams( ¶m, kStdCFStringAlertVersionOne ); param.movable = true; ssprintf(aBuffer, "%s\n\nPlease check your logs for more details.\n", useInputBuffer1 ? inputBuffer[1] : inputBuffer[0] ); err = CreateStandardAlert( kAlertStopAlert, CFStringCreateWithCString( nil, aBuffer, kCFStringEncodingMacRoman), CFSTR( "Run Console.app and search for wz2100 and copy that to a file.\ \n\nFor the Crash report on 10.4/10.5 check\ \n~/Library/Logs/CrashReporter,\ \non 10.6 check ~/Library/Logs/DiagnosticReports\ \nDo not forget to upload and attach those to a bug report at http://developer.wz2100.net/newticket\ \nThanks!" ), ¶m, &dialog ); SetWindowTitleWithCFString( GetDialogWindow( dialog ), CFSTR( "Warzone has terminated unexpectedly" ) ); RunStandardAlert( dialog, NULL, &itemHit ); #endif }
// -------------------------------------------------------------------------------------- void OpenPrefsDialog(void) { ListDefSpec listSpec; DialogRef dialog; WindowRef dialogWindow; EventTypeSpec dialogEvents[] = { {kEventClassControl, kEventControlHit} }; ControlID controlID = {kAppSignature, 0}; ControlRef control; EventTypeSpec listBoxControlEvents[] = { {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent} }; ListHandle iconList; Cell theCell; listSpec.defType = kListDefUserProcType; listSpec.u.userProc = NewListDefUPP(IconListDef); // this is automatically disposed // when the program exits RegisterListDefinition(kIconListLDEF, &listSpec); dialog = GetNewDialog(rPrefsDialog, NULL, kFirstWindowOfClass); if (dialog == NULL) ExitToShell(); SetPortDialogPort(dialog); dialogWindow = GetDialogWindow(dialog); // install window handlers ChangeWindowAttributes(dialogWindow, kWindowStandardHandlerAttribute, kWindowNoAttributes); gDialogEventHandler = NewEventHandlerUPP(dialogEventHandler); InstallWindowEventHandler(dialogWindow, gDialogEventHandler, GetEventTypeCount(dialogEvents), dialogEvents, (void *)dialog, NULL); GetDialogItemAsControl(dialog, kStdOkItemIndex, &control); // set control IDs to controlID.id = kStdOkItemIndex; // match dialog item SetControlID(control, &controlID); // indices which are SetWindowDefaultButton(dialogWindow, control); // not tracked by any // standard handlers GetDialogItemAsControl(dialog, kStdCancelItemIndex, &control); // also set the default controlID.id = kStdCancelItemIndex; // and cancel buttons (because Mac OS 8/9 SetControlID(control, &controlID); // under CarbonLib doesn't respect the SetWindowCancelButton(dialogWindow, control); // dialog's default and cancel buttons) GetDialogItemAsControl(dialog, iIconList, &control); controlID.id = iIconList; SetControlID(control, &controlID); /* We need to postprocess keyboard events on the icon list so that we can change panels after the user changes the selected cell by using the keyboard. */ gListBoxControlEventHandler = NewEventHandlerUPP(listBoxControlEventHandler); InstallControlEventHandler(control, gListBoxControlEventHandler, GetEventTypeCount(listBoxControlEvents), listBoxControlEvents, (void *)dialog, NULL); GetControlData(control, kControlEntireControl, kControlListBoxListHandleTag, sizeof(ListHandle), &iconList, NULL); AddRowsAndDataToIconList(iconList, rIconListIconBaseID); SetListSelectionFlags(iconList, lOnlyOne); SetPt(&theCell, 0, 0); LSetSelect(true, theCell, iconList); SetKeyboardFocus(dialogWindow, control, kControlFocusNextPart); gPanelNumber = 0; SetPrefsDialogHelpTags(dialog); DisableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog); ShowWindow(dialogWindow); } // OpenPrefsDialog
char *QTTarg_GetStringFromUser (short thePromptStringIndex) { short myItem; short mySavedResFile; GrafPtr mySavedPort; DialogPtr myDialog = NULL; short myItemKind; Handle myItemHandle; Rect myItemRect; Str255 myString; char *myCString = NULL; OSErr myErr = noErr; ////////// // // save the current resource file and graphics port // ////////// mySavedResFile = CurResFile(); GetPort(&mySavedPort); // set the application's resource file UseResFile(gAppResFile); ////////// // // create the dialog box in which the user will enter a URL // ////////// myDialog = GetNewDialog(kGetStr_DLOGID, NULL, (WindowPtr)-1L); if (myDialog == NULL) goto bail; QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false); MacSetPort(GetDialogPort(myDialog)); SetDialogDefaultItem(myDialog, kGetStr_OKButton); SetDialogCancelItem(myDialog, kGetStr_CancelButton); // set the prompt string GetIndString(myString, kTextKindsResourceID, thePromptStringIndex); GetDialogItem(myDialog, kGetStr_StrLabelItem, &myItemKind, &myItemHandle, &myItemRect); SetDialogItemText(myItemHandle, myString); MacShowWindow(GetDialogWindow(myDialog)); ////////// // // display and handle events in the dialog box until the user clicks OK or Cancel // ////////// do { ModalDialog(gModalFilterUPP, &myItem); } while ((myItem != kGetStr_OKButton) && (myItem != kGetStr_CancelButton)); ////////// // // handle the selected button // ////////// if (myItem != kGetStr_OKButton) { myErr = userCanceledErr; goto bail; } // retrieve the edited text GetDialogItem(myDialog, kGetStr_StrTextItem, &myItemKind, &myItemHandle, &myItemRect); GetDialogItemText(myItemHandle, myString); myCString = QTUtils_ConvertPascalToCString(myString); bail: // restore the previous resource file and graphics port MacSetPort(mySavedPort); UseResFile(mySavedResFile); if (myDialog != NULL) DisposeDialog(myDialog); return(myCString); }
static DialogRef DrawDialogTheMacOS8or9Way(void) { short i; ControlRef theControl; DialogRef theDialog = GetNewDialog(257, NULL, (WindowRef)-1L); if (theDialog == NULL) return(NULL); // Let's get a pulsing blue default button! GetDialogItemAsControl(theDialog, 1, &theControl); SetWindowDefaultButton(GetDialogWindow(theDialog), theControl); // Setting the check box GetDialogItemAsControl(theDialog, 2, &theControl); SetControl32BitValue(theControl, 1); // We need to autoembed our radio buttons in the radio group // so that they work automatically for (i = 4; i <= 8; i++) { GetDialogItemAsControl(theDialog, i, &theControl); AutoEmbedControl(theControl, GetDialogWindow(theDialog)); } // we assign a key filter on our edit text box so that only digits can be entered ControlRef theTextControl; ControlKeyFilterUPP keyFilter = MyEditKeyFilter; GetDialogItemAsControl(theDialog, 9, &theTextControl); SetKeyboardFocus(GetDialogWindow(theDialog), theTextControl, kControlFocusNextPart); SetControlData(theTextControl, kControlEntireControl, kControlEditTextKeyFilterTag, sizeof(keyFilter), &keyFilter); // Setting the action proc for the scroll bar so that the PageUp/PageDown/Up/Down buttons work // We also associate the previous edit text box with the scroll bar so it gets updated GetDialogItemAsControl(theDialog, 14, &theControl); SetControlAction(theControl, ScrollBar32BitActionProc); SetControl32BitMaximum(theControl, 0x7fffffff); SetControlReference(theControl, (SInt32)theTextControl); // The static text control is created as a resource but we could only set its title and // not its content. We set the content now! GetDialogItemAsControl(theDialog, 15, &theControl); Str255 theTitle; GetControlTitle(theControl, theTitle); SetControlData(theControl, kControlEntireControl, kControlStaticTextTextTag, theTitle[0], &theTitle[1]); // We set up our User Pane Control with the draw, hit test, and track (actually action) procs GetDialogItemAsControl(theDialog, 13, &theControl); Rect bounds; GetControlBounds(theControl, &bounds); gUserH = (bounds.left + bounds.right) / 2; gUserV = (bounds.top + bounds.bottom) / 2; ControlUserPaneDrawUPP userPaneDraw = MyUserPaneDrawProc; SetControlData(theControl, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(userPaneDraw), &userPaneDraw); ControlUserPaneHitTestUPP userPaneHitTest = MyUserPaneHitTestProc; SetControlData(theControl, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(userPaneHitTest), &userPaneHitTest); SetControlAction(theControl, MoveSpotActionProc); ShowWindow(GetDialogWindow(theDialog)); return(theDialog); }
static Boolean MySystem6or7DialogFilter(DialogRef theDialog, EventRecord *inEvent, DialogItemIndex *itemHit) { if ((inEvent->what == keyDown) || (inEvent->what == autoKey)) { char c = (inEvent->message & charCodeMask); // return or enter key? if ((c == kReturnCharCode) || (c == kEnterCharCode)) { *itemHit = 1; return true; } // tab key or arrow keys? if (c == kTabCharCode) return false; if (c == kLeftArrowCharCode) return false; if (c == kRightArrowCharCode) return false; if (c == kUpArrowCharCode) return false; if (c == kDownArrowCharCode) return false; // digits only for edittext box item #9 ? // pre-Carbon, this would have been: ((DialogPeek)theDialog)->editField+1 == 9 if (GetDialogKeyboardFocusItem(theDialog) == 9) { if ((c < '0') || (c > '9')) { SysBeep(1); return true; } } } // we got a click! if (inEvent->what == mouseDown) { DialogItemType itemType; Handle itemHandle; Rect itemBox; GetDialogItem(theDialog, 13, &itemType, &itemHandle, &itemBox); // is the user item enabled? if (!(itemType & itemDisable)) { CGrafPtr savePort; GetPort(&savePort); SetPortDialogPort(theDialog); Point thePoint = inEvent->where; GlobalToLocal(&thePoint); Boolean inside = PtInRect(thePoint, &itemBox); // is the click inside the user item? if (inside) { // let's constrain and move the spot! // it's possible to track the spot here but it's complex // so we just move on the click and don't track. // that's typical of dialog's user items of that era. Rect userRect1 = {gUserV-4, gUserH-4, gUserV+4, gUserH+4}; EraseRect(&userRect1); InvalWindowRect(GetDialogWindow(theDialog), &userRect1); gUserH = thePoint.h; gUserV = thePoint.v; if (gUserH < itemBox.left+4) gUserH = itemBox.left+4; if (gUserH > itemBox.right-4) gUserH = itemBox.right-4; if (gUserV < itemBox.top+4) gUserV = itemBox.top+4; if (gUserV > itemBox.bottom-4) gUserV = itemBox.bottom-4; Rect userRect2 = {gUserV-4, gUserH-4, gUserV+4, gUserH+4}; InvalWindowRect(GetDialogWindow(theDialog), &userRect2); } SetPort(savePort); } } return false; }