short PGFAlert(char *inCStr, short allowCancel) { #ifdef PGP_MACINTOSH DialogPtr pfAlert; GrafPtr savePort; short result=0, i; Str255 s; GetPort(&savePort); strcpy((char *)s, inCStr); c2pstr((char *)s); if((pfAlert = GetNewDialog(130,nil,(WindowPtr)-1L)) != NULL) { SetPort(pfAlert); ParamText((uchar *)s,"\p","\p","\p"); if(!allowCancel) HideDialogItem(pfAlert,2); SetDialogCancelItem(pfAlert, 2); SetDialogDefaultItem(pfAlert, 1); ShowWindow(pfAlert); SysBeep(30); ModalDialog(nil, &i); DisposeDialog(pfAlert); result = (i==1); }
// -------------------------------------------------------------------------------------- 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
short ModalMacros(NewMacroInfo *macrost) { DialogPtr dtemp; short dItem; short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; SetUpMovableModalMenus(); dtemp=GetNewMyDialog( MacroDLOG + 2, NULL, kInFront, (void *)ThirdCenterDialog); SetDialogDefaultItem(dtemp, 1); SetDialogCancelItem(dtemp, 2); SetDialogTracksCursor(dtemp, 1); HideDialogItem(dtemp, 25); // no save default in session macros dialog dialogPane = 0; // start with Command-[0-9] // RAB BetterTelnet 2.0b5 - fix cancel button so it works again oldMacros = macrost->handle; HandToHand(&oldMacros); oldMacroIndexes = *macrost; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(macrost, i, (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); /* BYU LSC */ GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } TelInfo->macrosModeless = dtemp; dItem = 0; while ((dItem != 1) && (dItem != 2)) { movableModalDialog(0, &dItem); MacroDialog(macrost, dtemp, 0, dItem); } if (dItem == 2) CancelMacros(macrost, dtemp); else CloseMacros(macrost, dtemp); ResetMenus(); return dItem; }
void SetDefaultItemBehavior(DialogRef dialog) { #if TARGET_API_MAC_CARBON short cancelButtonItemNum; (void)SetDialogTracksCursor (dialog,true); SetDialogDefaultItem(dialog,1); cancelButtonItemNum = DetermineCancelButtonItemNumByLookingAtButtons(dialog); if(cancelButtonItemNum < 1) cancelButtonItemNum = 1; // make the default button respond to the "escape key" i.e. equivalent to the cancel button SetDialogCancelItem(dialog,cancelButtonItemNum); #else #pragma unused(dialog) // nothing to do, the modalfilter proc takes care of the behavior #endif }
void Macros( void) { DialogPtr dtemp; short dItem; short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; setLastCursor(theCursors[normcurs]); if (TelInfo->macrosModeless) { SelectWindow(TelInfo->macrosModeless); return; } dtemp=GetNewMyDialog( MacroDLOG, NULL, kInFront, (void *)ThirdCenterDialog); SetDialogDefaultItem(dtemp, 1); SetDialogCancelItem(dtemp, 2); SetDialogTracksCursor(dtemp, 1); dialogPane = 0; // start with Command-[0-9] // RAB BetterTelnet 2.0b5 - fix cancel button so it works again oldMacros = TelInfo->newMacros.handle; HandToHand(&oldMacros); oldMacroIndexes = TelInfo->newMacros; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(&TelInfo->newMacros, i, (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); /* BYU LSC */ GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } TelInfo->macrosModeless = dtemp; }
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); }
Boolean DoUI (GPtr globals) { short item; Str255 hS = ""; //histstatus int16 currentResources = 0; DialogPtr dp; DialogTHndl dt; gStuff->theRect.top = gStuff->theRect.left = gStuff->theRect.bottom = gStuff->theRect.right = 0; dt = (DialogTHndl) GetResource ('DLOG', uiID); HNoPurge ((Handle) dt); CenterDialog (dt); dp = GetNewDialog (uiID, nil, (WindowPtr) -1); (void) SetDialogDefaultItem (dp, ok); (void) SetDialogCancelItem (dp, cancel); PIGetString(kHistStatus, hS); // get status string do { currentResources = CountPIResources(histResource); if (gCurrentHistory < 1) gCurrentHistory = 1; if (gCurrentHistory > currentResources) gCurrentHistory = currentResources; if (currentResources <= kDHistTotal || gCurrentHistory+kDHistTotal > currentResources) PIDisableControl (dp, kDDownButton); // nothing extra to show else PIEnableControl (dp, kDDownButton); if (gCurrentHistory < 2) PIDisableControl (dp, kDUpButton); else PIEnableControl (dp, kDUpButton); if (currentResources >= gCurrentHistory && currentResources > 0) { PIEnableControl (dp, kDTrimFirst); PIEnableControl (dp, kDTrimLast); } else { PIDisableControl (dp, kDTrimFirst); PIDisableControl (dp, kDTrimLast); } UpdateHistories(globals, dp, currentResources, hS); MoveableModalDialog (dp, gStuff->processEvent, nil, &item); switch (item) { case cancel: gResult = userCanceledErr; // have to set this so we don't get recorded break; case kDTrimFirst: if (currentResources >= gCurrentHistory) { DeletePIResource (histResource, gCurrentHistory); gStuff->dirty = TRUE; } break; case kDTrimLast: if (currentResources >= gCurrentHistory + kDHistTotal-1) { DeletePIResource (histResource, gCurrentHistory+ kDHistTotal-1); gStuff->dirty = TRUE; } else if (currentResources > 0) { DeletePIResource (histResource, currentResources); gStuff->dirty = TRUE; } break; case kDUpButton: gCurrentHistory--; break; case kDDownButton: gCurrentHistory++; break; } // end switch (item) } while (item != ok && item != cancel); DisposeDialog (dp); HPurge ((Handle) dt); return (item == ok); }
void dialog_scropt(void) { DialogPtr hDlg; ControlHandle chipbtn[2]; ControlHandle grcgbtn[4]; ControlHandle lcdbtn[2]; ControlHandle skipbtn; ControlHandle c16btn; UINT chip; UINT grcg; UINT color16; UINT lcd; UINT skipline; UINT val; char work[32]; Str255 workstr; int done; short item; UINT update; UINT renewal; BYTE waitval[6]; hDlg = GetNewDialog(IDD_SCREENOPT, NULL, (WindowPtr)-1); if (!hDlg) { return; } chipbtn[0] = (ControlHandle)GetDlgItem(hDlg, IDC_GDC7220); chipbtn[1] = (ControlHandle)GetDlgItem(hDlg, IDC_GDC72020); grcgbtn[0] = (ControlHandle)GetDlgItem(hDlg, IDC_GRCGNON); grcgbtn[1] = (ControlHandle)GetDlgItem(hDlg, IDC_GRCG); grcgbtn[2] = (ControlHandle)GetDlgItem(hDlg, IDC_GRCG2); grcgbtn[3] = (ControlHandle)GetDlgItem(hDlg, IDC_EGC); c16btn = (ControlHandle)GetDlgItem(hDlg, IDC_PC980124); lcdbtn[0] = (ControlHandle)GetDlgItem(hDlg, IDC_LCD); lcdbtn[1] = (ControlHandle)GetDlgItem(hDlg, IDC_LCDX); skipbtn = (ControlHandle)GetDlgItem(hDlg, IDC_SKIPLINE); chip = (np2cfg.uPD72020)?1:0; setchip(chipbtn, chip); grcg = np2cfg.grcg & 3; setgrcg(grcgbtn, grcg); color16 = (np2cfg.color16)?1:0; SetControlValue(c16btn, color16); val = np2cfg.wait[0]; if (val > 32) { val = 32; } SPRINTF(work, str_u, val); mkstr255(workstr, work); SetDialogItemText(GetDlgItem(hDlg, IDC_TRAMWAIT), workstr); val = np2cfg.wait[2]; if (val > 32) { val = 32; } SPRINTF(work, str_u, val); mkstr255(workstr, work); SetDialogItemText(GetDlgItem(hDlg, IDC_VRAMWAIT), workstr); val = np2cfg.wait[4]; if (val > 32) { val = 32; } SPRINTF(work, str_u, val); mkstr255(workstr, work); SetDialogItemText(GetDlgItem(hDlg, IDC_GRCGWAIT), workstr); val = np2cfg.realpal; if (val > 64) { val = 64; } SPRINTF(work, str_d, val - 32); mkstr255(workstr, work); SetDialogItemText(GetDlgItem(hDlg, IDC_REALPAL), workstr); lcd = np2cfg.LCD_MODE & 3; SetControlValue(lcdbtn[0], lcd & 1); SetControlValue(lcdbtn[1], (lcd & 2) >> 1); skipline = (np2cfg.skipline)?1:0; SetControlValue(skipbtn, skipline); SPRINTF(work, str_u, np2cfg.skiplight); mkstr255(workstr, work); SetDialogItemText(GetDlgItem(hDlg, IDC_SKIPLIGHT), workstr); SetDialogDefaultItem(hDlg, IDOK); SetDialogCancelItem(hDlg, IDCANCEL); done = 0; while(!done) { ModalDialog(NULL, &item); switch(item) { case IDOK: update = 0; if (np2cfg.uPD72020 != chip) { np2cfg.uPD72020 = chip; update |= SYS_UPDATECFG; gdc_restorekacmode(); gdcs.grphdisp |= GDCSCRN_ALLDRAW2; } if (np2cfg.grcg != grcg) { np2cfg.grcg = grcg; update |= SYS_UPDATECFG; gdcs.grphdisp |= GDCSCRN_ALLDRAW2; } if (np2cfg.color16 != color16) { np2cfg.color16 = color16; update |= SYS_UPDATECFG; } GetDialogItemText(GetDlgItem(hDlg, IDC_TRAMWAIT), workstr); mkcstr(work, sizeof(work), workstr); val = milstr_solveINT(work); if (val > 32) { val = 32; } waitval[0] = val; waitval[1] = (val)?1:0; GetDialogItemText(GetDlgItem(hDlg, IDC_VRAMWAIT), workstr); mkcstr(work, sizeof(work), workstr); val = milstr_solveINT(work); if (val > 32) { val = 32; } waitval[2] = val; waitval[3] = (val)?1:0; GetDialogItemText(GetDlgItem(hDlg, IDC_GRCGWAIT), workstr); mkcstr(work, sizeof(work), workstr); val = milstr_solveINT(work); if (val > 32) { val = 32; } waitval[4] = val; waitval[5] = (val)?1:0; if (memcmp(np2cfg.wait, waitval, 6)) { CopyMemory(np2cfg.wait, waitval, 6); update |= SYS_UPDATECFG; } GetDialogItemText(GetDlgItem(hDlg, IDC_REALPAL), workstr); mkcstr(work, sizeof(work), workstr); val = milstr_solveINT(work) + 32; if (val > 64) { val = 64; } if (np2cfg.realpal != val) { np2cfg.realpal = val; update |= SYS_UPDATECFG; } renewal = 0; if (np2cfg.skipline != skipline) { np2cfg.skipline = skipline; renewal = 1; } GetDialogItemText(GetDlgItem(hDlg, IDC_SKIPLIGHT), workstr); mkcstr(work, sizeof(work), workstr); val = milstr_solveINT(work); if (val > 255) { val = 255; } if (np2cfg.skiplight != val) { np2cfg.skiplight = val; renewal = 1; } if (renewal) { pal_makeskiptable(); } if (np2cfg.LCD_MODE != lcd) { np2cfg.LCD_MODE = lcd; pal_makelcdpal(); renewal = 1; } if (renewal) { update |= SYS_UPDATECFG; scrndraw_redraw(); } sysmng_update(update); done = IDOK; break; case IDCANCEL: done = IDCANCEL; break; case IDC_LCD: lcd ^= 1; SetControlValue(lcdbtn[0], lcd & 1); break; case IDC_LCDX: lcd ^= 2; SetControlValue(lcdbtn[1], (lcd & 2) >> 1); break; case IDC_SKIPLINE: skipline ^= 1; SetControlValue(skipbtn, skipline); break; case IDC_GDC7220: chip = 0; setchip(chipbtn, chip); break; case IDC_GDC72020: chip = 1; setchip(chipbtn, chip); break; case IDC_GRCGNON: grcg = 0; setgrcg(grcgbtn, grcg); break; case IDC_GRCG: grcg = 1; setgrcg(grcgbtn, grcg); break; case IDC_GRCG2: grcg = 2; setgrcg(grcgbtn, grcg); break; case IDC_EGC: grcg = 3; setgrcg(grcgbtn, grcg); break; case IDC_PC980124: color16 ^= 1; SetControlValue(c16btn, color16); break; } } DisposeDialog(hDlg); }
Boolean QTInfo_EditAnnotation (Movie theMovie, OSType theType) { DialogPtr myDialog = NULL; short myItem; short mySavedResFile; GrafPtr mySavedPort; Handle myHandle = NULL; short myItemKind; Handle myItemHandle; UserData myUserData = NULL; Rect myItemRect; Str255 myString; Boolean myIsChanged = false; OSErr myErr = noErr; ////////// // // save the current resource file and graphics port // ////////// mySavedResFile = CurResFile(); GetPort(&mySavedPort); // set the application's resource file UseResFile(gAppResFile); // get the movie user data myUserData = GetMovieUserData(theMovie); if (myUserData == NULL) goto bail; ////////// // // create the dialog box in which the user will add or edit the annotation // ////////// myDialog = GetNewDialog(kEditTextResourceID, NULL, (WindowPtr)-1L); if (myDialog == NULL) goto bail; MacSetPort(GetDialogPort(myDialog)); SetDialogDefaultItem(myDialog, kEditTextItemOK); SetDialogCancelItem(myDialog, kEditTextItemCancel); // get a string for the specified annotation type switch (theType) { case kUserDataTextFullName: GetIndString(myString, kTextKindsResourceID, kTextKindsFullName); break; case kUserDataTextCopyright: GetIndString(myString, kTextKindsResourceID, kTextKindsCopyright); break; case kUserDataTextInformation: GetIndString(myString, kTextKindsResourceID, kTextKindsInformation); break; } GetDialogItem(myDialog, kEditTextItemEditLabel, &myItemKind, &myItemHandle, &myItemRect); SetDialogItemText(myItemHandle, myString); ////////// // // set the current annotation of the specified type, if it exists // ////////// myHandle = NewHandleClear(4); if (myHandle != NULL) { myErr = GetUserDataText(myUserData, myHandle, theType, 1, GetScriptManagerVariable(smRegionCode)); if (myErr == noErr) { QTInfo_TextHandleToPString(myHandle, myString); GetDialogItem(myDialog, kEditTextItemEditBox, &myItemKind, &myItemHandle, &myItemRect); SetDialogItemText(myItemHandle, myString); SelectDialogItemText(myDialog, kEditTextItemEditBox, 0, myString[0]); } DisposeHandle(myHandle); } MacShowWindow(GetDialogWindow(myDialog)); ////////// // // display and handle events in the dialog box until the user clicks OK or Cancel // ////////// do { ModalDialog(gModalFilterUPP, &myItem); } while ((myItem != kEditTextItemOK) && (myItem != kEditTextItemCancel)); ////////// // // handle the selected button // ////////// if (myItem != kEditTextItemOK) goto bail; // retrieve the edited text myHandle = NewHandleClear(4); if (myHandle != NULL) { GetDialogItem(myDialog, kEditTextItemEditBox, &myItemKind, &myItemHandle, &myItemRect); GetDialogItemText(myItemHandle, myString); QTInfo_PStringToTextHandle(myString, myHandle); myErr = AddUserDataText(myUserData, myHandle, theType, 1, GetScriptManagerVariable(smRegionCode)); myIsChanged = (myErr == noErr); DisposeHandle(myHandle); } bail: // restore the previous resource file and graphics port MacSetPort(mySavedPort); UseResFile(mySavedResFile); if (myDialog != NULL) DisposeDialog(myDialog); return(myIsChanged); }
Boolean DoUI (GPtr globals) { short item, lastitem; short numberErr = noErr; long x; DialogPtr dp; DialogTHndl dialogHdl; dialogHdl = (DialogTHndl) GetResource ('DLOG', uiID); if (dialogHdl == NULL || *dialogHdl == NULL) return false; else { HNoPurge ((Handle) dialogHdl); CenterDialog (dialogHdl); dp = GetNewDialog (uiID, nil, (WindowPtr) -1); /* I am throwing away the results from these routines. Toolbox TechNote 37 does not document what error values they return. Also, the worst that happens is that the interface isn't quite right. */ (void) SetDialogDefaultItem (dp, ok); (void) SetDialogCancelItem (dp, cancel); (void) SetDialogTracksCursor (dp, TRUE); SetRadioGroupState (dp, kFirstItem, kLastItem, kFirstItem + gWhatArea); SetRadioGroupState (dp, kUseRadio1, kUseRadioLast, kUseRadio1 + gWhatChannels); SetRadioGroupState (dp, kCreateRadio1, kCreateRadioLast, kCreateRadio1 + gCreate); ShowHideItem (dp, kPercentStatic, (gWhatArea == iSelectRandom)); ShowHideItem (dp, kPercentEdit, (gWhatArea == iSelectRandom)); ShowHideItem (dp, kPercentSymbol, (gWhatArea == iSelectRandom)); StuffNumber(dp, kPercentEdit, gPercent); if (gWhatArea == iSelectRandom) SelectTextItem(dp, kPercentEdit); SelectWindow (GetDialogWindow(dp)); do { MoveableModalDialog (dp, gStuff->processEvent, nil, &item); if (lastitem != item && item != cancel) { /* we just left this area. Check to make sure its within bounds. */ switch (lastitem) { case kPercentEdit: numberErr = FetchNumber(dp, kPercentEdit, kPercentMin, kPercentMax, &x); if (numberErr != noErr) { // shows alert if there's an error AlertNumber(dp, kPercentEdit, kPercentMin, kPercentMax, &x, AlertID, numberErr); item = kPercentEdit; // stay here } gPercent = x; break; } } switch (item) { case ok: gWhatArea = GetRadioGroupState(dp, kFirstItem, kLastItem) - kFirstItem; gWhatChannels = GetRadioGroupState(dp, kUseRadio1, kUseRadioLast) - kUseRadio1; gCreate = GetRadioGroupState(dp, kCreateRadio1, kCreateRadioLast) - kCreateRadio1; if (gWhatArea == iSelectRandom) { numberErr = FetchNumber(dp, kPercentEdit, kPercentMin, kPercentMax, &x); if (numberErr != noErr) { // shows alert if there's an error AlertNumber(dp, kPercentEdit, kPercentMin, kPercentMax, &x, AlertID, numberErr); item = kPercentEdit; // go back } else gPercent = x; // it's okay, move on } break; case cancel: gResult = userCanceledErr; break; case kPercentEdit: // grab the number whether it's right or not numberErr = FetchNumber(dp, kPercentEdit, kPercentMin, kPercentMax, &x); if (numberErr == noErr) { // no errors getting the number gPercent = x; // update display here } break; default: if (item >= kFirstItem && item <= kLastItem) { SetRadioGroupState (dp, kFirstItem, kLastItem, item); ShowHideItem (dp, kPercentStatic, (item == iSelectRandom + kFirstItem)); ShowHideItem (dp, kPercentEdit, (item == iSelectRandom + kFirstItem)); ShowHideItem (dp, kPercentSymbol, (item == iSelectRandom + kFirstItem)); if (item == iSelectRandom + kFirstItem) SelectTextItem(dp, kPercentEdit); } else if (item >= kUseRadio1 && item <= kUseRadioLast) SetRadioGroupState (dp, kUseRadio1, kUseRadioLast, item); else if (item >= kCreateRadio1 && item <= kCreateRadioLast) SetRadioGroupState (dp, kCreateRadio1, kCreateRadioLast, item); break; } lastitem = item; } while (item != ok && item != cancel); DisposeDialog (dp); if (dialogHdl != NULL && *dialogHdl != NULL) HPurge ((Handle) dialogHdl); dp = NULL; dialogHdl = NULL; return item == ok; } // else }
Word BURGER_API Burger::OkCancelAlertMessage(const char *Message,const char *Title) { Word Result; Word8 *TitleStr; /* Pointer to the window title */ DialogPtr MyDialog; /* My dialog pointer */ Handle ItemList; /* Handle to the item list */ Rect DialogRect; /* Rect of the dialog window */ Rect WorkRect; Word TitleLen; /* Length of the title */ Word MessLen; /* Length of the caption */ short ItemHit; /* Junk */ GrafPtr MyPort; /* My grafport */ //Word Foo; //Foo = InputSetState(FALSE); Result = FALSE; /* Assume cancel */ GetPort(&MyPort); /* Save the current port */ /* Center my dialog to the screen */ #if ACCESSOR_CALLS_ARE_FUNCTIONS GetPortBounds(MyPort,&WorkRect); #else WorkRect = MyPort->portRect; #endif DialogRect.top = static_cast<short>((((WorkRect.bottom-WorkRect.top)-190)/2)+WorkRect.top); DialogRect.left = static_cast<short>((((WorkRect.right-WorkRect.left)-350)/2)+WorkRect.left); DialogRect.bottom = static_cast<short>(DialogRect.top+190); DialogRect.right = static_cast<short>(DialogRect.left+350); TitleLen = 0; /* Assume no length */ if (Title) { TitleLen = Burger::StringLength(Title); /* Get the length of the title string */ } TitleStr = (Word8 *)Burger::Alloc(TitleLen+1); /* Get memory of pascal string */ if (TitleStr) { /* Did I get the memory? */ Burger::MemoryCopy(TitleStr+1,Title,TitleLen); TitleStr[0] = static_cast<Word8>(TitleLen); /* Set the pascal length */ MessLen = Burger::StringLength(Message); /* Size of the message */ ItemList = NewHandle(static_cast<Size>(sizeof(TemplateX)+MessLen)); if (ItemList) { /* Ok? */ TemplateX[sizeof(TemplateX)-1]=static_cast<Word8>(MessLen); /* Save the message length */ Burger::MemoryCopy(ItemList[0],TemplateX,sizeof(TemplateX)); /* Copy the template */ Burger::MemoryCopy((ItemList[0])+sizeof(TemplateX),Message,MessLen); /* Copy the message */ MyDialog = NewDialog(0,&DialogRect,(Word8 *)TitleStr,TRUE,5,(WindowPtr)-1,FALSE,0,ItemList); if (MyDialog) { SetDialogDefaultItem(MyDialog,1); /* Default for OK button */ SetDialogCancelItem(MyDialog,2); /* Default for cancel button */ ModalDialog(0,&ItemHit); /* Handle the event */ if (ItemHit==1) { /* Pressed ok? */ Result = TRUE; } DisposeDialog(MyDialog); /* Kill the dialog */ } else { DisposeHandle(ItemList); /* I must kill this myself! */ } } Burger::Free(TitleStr); /* Kill the title */ } SetPort(MyPort); /* Restore my grafport */ //InputSetState(Foo); /* Restore Inputsprocket */ return Result; }
// // AskIfNewResolutionWorks() creates a dialog box in the center of the screen. The dialog asks the // user if the current display setting works. This is necessary because a number of display settings // listed by the OS dont actually work and leave the user with a black screen. The dialog has a 5 // second timeout. If the user does not hit ok within 5 seconds the cancel item is chosen automatically // for him. This feature allows the user to do nothing (which he will probably do if confronted by a // black screen) and still be ok. The method that I have employed to do the timeout requires Appearances // 1.1. I believe this was introduced with OS 8.5. If you want to support back to OS 8.1, then you will // have to do your own modal dialog event proc that implements a timeout. The dialog has not default // button by default. Cmd-period and esc trigger the cancel button. // // OSStatus AskIfNewResolutionWorks( ScreenRef screen ) { DEBUGMESSAGE( "Querying user whether the new resolution works...." ); if( ! screen ) return noErr; //Read the new screen dimensions RLDrawInfo screenData; Rect dialogBounds = {0,0,130, 340}; OSStatus error = GetCurrentScreenDrawingInfo( screen, &screenData ); if( error ) { DEBUGMESSAGE( "Unable to get current screen drawing information. Got back error # " << error ); return error; } //Make a copy of our dialog item list. This will be destroyed when the dialog is destroyed. Handle ditlCopy = LoadDITL(); HandToHand( &ditlCopy ); //Center the dialog rect on the screen { SInt32 horizontalOffset = (SInt32( screenData.bounds.right) + SInt32( screenData.bounds.left ) - SInt32(dialogBounds.right) + SInt32(dialogBounds.left) ) / 2; SInt32 verticalOffset = (SInt32( screenData.bounds.bottom) + SInt32( screenData.bounds.top ) - SInt32(dialogBounds.bottom) + SInt32(dialogBounds.top) ) / 2; dialogBounds.left += horizontalOffset; dialogBounds.right += horizontalOffset; dialogBounds.top += verticalOffset; dialogBounds.bottom += verticalOffset; } //Init a new dialog hidden DialogPtr dialog = NewFeaturesDialog( NULL, &dialogBounds, "\pResolution Verification", true, kWindowModalDialogProc, (WindowPtr) -1L, false, TickCount(), ditlCopy, 0 ); if( ! dialog ) { DEBUGMESSAGE( "Unable to init the \"AskIfNewResolutionWorks\" dialog window. Perhaps there is insufficient free memory or the DITL did not load properly at library startup?" ); return rlOutOfMemory; } //Make sure the dialog cancel item is button # 2 SetDialogCancelItem( dialog, 2 ); //Set dialog to timeout after 5 seconds SetDialogTimeout( dialog, 2, 5 ); for( bool done = false; !done; ) { short itemHit = 0; ModalDialog ( NULL, &itemHit ); switch( itemHit ) { case 2: //cancel DEBUGMESSAGE( "The user hit cancel or the dialog timed out. The new resolution is probably not good." ); done = true; error = rlRezNotFound; break; case 3: //ok DEBUGMESSAGE( "The user hit ok. The new resolution seems to be Okay!" ); done = true; error = noErr; break; } } DisposeDialog( dialog ); return error; }