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); }
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); }
/**************************************************************** UnRegisterPopUpDialog() is used when you have a popup that you want to turn off, not in the sense of being static but in the sense of not being there at all. You should erase the popup on the screen with PopErase, and then call this procedure to set the handle to nil (instead of PopDraw) so it won't get redrawn. ****************************************************************/ void UnRegisterPopUpDialog(long dialogID, DialogPtr theDialog) { #ifndef IBM short theType; Handle itemHandle; Rect itemBox; short i; #endif #ifdef IBM return; #else for ( i = 0 ; i < sa_numPopUps ; i++ ) if (sa_popTable[i].dialogID == dialogID) { GetDialogItem(theDialog, sa_popTable[i].popupItemNum, &theType, &itemHandle, &itemBox); SetDialogItem(theDialog, sa_popTable[i].popupItemNum, userItem, nil, &itemBox); } #endif }
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); }
/**************************************************************** RegisterPopUpDialog() is used to fill in the dialogPtr field of a PopTable entry and to set the user item procs of that dialog's popup items once you have loaded the dialog and have the dialog pointer. ****************************************************************/ void RegisterPopUpDialog(long dialogID, DialogPtr theDialog) { short i; #ifndef IBM short theType; Handle itemHandle; Rect itemBox; #endif for ( i = 0 ; i < sa_numPopUps ; i++ ) if (sa_popTable[i].dialogID == dialogID) { sa_popTable[i].dialogPtr = theDialog; #ifndef IBM GetDialogItem(theDialog, sa_popTable[i].popupItemNum, &theType, &itemHandle, &itemBox); SetDialogItem(theDialog, sa_popTable[i].popupItemNum, userItem, nil, &itemBox); SetDialogItemHandle(theDialog, sa_popTable[i].popupItemNum, (Handle)PopDraw); #else PopDraw(theDialog, sa_popTable[i].popupItemNum); LoadPopupMenu(theDialog, sa_popTable[i].menuID, sa_popTable[i].popupItemNum); #endif } }
/**************************************************************** PopDraw() is the function associated with the user item that invokes the popup menu. We draw the box to look like a menu cell, and then call the appropriate drawProc to fill in the cell with the actual contents. If the drawProc is nil, we draw the menu item as text. We gray the cell if the menu is disabled. Finally, we draw a down arrow to indicate that the button is a popup menu. If the popup item is static, we only draw the cell contents. ****************************************************************/ pascal_ifMac void PopDraw(DialogPtr theDialog, short itemNum) { GrafPtr savePort; short theType; Handle itemHandle; Rect itemBox; Rect cellBox; MenuHandle theMenu; //SysEnvRec theWorld; RGBColor SaveBack, SaveFore, DefaultBack, DefaultFore; char name[256]; short i; short drawStringFlag; // Added by Glen to code for support of Type-in Pop-Up menus // if drawStringFlag = 1 then we don't draw text string ... drawStringFlag = 0; for ( i = 0 ; i < sa_numPopUps ; i++ ) if ( (sa_popTable[i].dialogPtr == theDialog) && (sa_popTable[i].popupItemNum == itemNum) ) break; if (i == sa_numPopUps) { SysBeep(1); return; } // should not happen since the dialog must have been registered // for PopDraw to have been called GetPortGrafPtr(&savePort); SetPortDialogPort(theDialog); // SysEnvirons(curSysEnvVers,&theWorld); // if (theWorld.hasColorQD) { if (ColorQDAvailable()) { GetForeColor(&SaveFore); GetBackColor(&SaveBack); DefaultMenuColors(&DefaultFore, &DefaultBack); if (sa_popTable[i].bStatic) { DefaultFore = SaveFore; DefaultBack = SaveBack; } } theMenu = GetMenuHandle(sa_popTable[i].menuID); if (!theMenu) { SysBeep(1); return; } /* change item's width to match the menu */ GetDialogItem(theDialog,itemNum,&theType,&itemHandle,&itemBox); CalcMenuSize(theMenu); if (sa_popTable[i].itemWidth == 0) { if (sa_popTable[i].drawProc == nil) // itemBox.right = itemBox.left + (**theMenu).menuWidth + 20 + 2; itemBox.right = itemBox.left + GetMenuWidth(theMenu) + 20 + 2; else //itemBox.right = itemBox.left + (**theMenu).menuWidth + 2; itemBox.right = itemBox.left + GetMenuWidth(theMenu) + 2; } else if (sa_popTable[i].itemWidth == -1) { // Type-in Pop-Up Menu itemBox.right = itemBox.left + 20 + 2; drawStringFlag = 1; } else itemBox.right = itemBox.left + sa_popTable[i].itemWidth + 2; SetDialogItem(theDialog,itemNum,theType,itemHandle,&itemBox); /* draw the box */ if (TRUE) { // !sa_popTable[i].bStatic // if (theWorld.hasColorQD) RGBBackColor(&DefaultBack); if (ColorQDAvailable()) RGBBackColor(&DefaultBack); EraseRect( &itemBox ); // if (theWorld.hasColorQD) RGBForeColor(&SaveFore); if (ColorQDAvailable()) RGBForeColor(&SaveFore); PenNormal(); // if (sa_popTable[i].bStatic) PenPat((ConstPatternParam)&qd.gray); //if (sa_popTable[i].bStatic) PenPat((ConstPatternParam)&GRAY_BRUSH()); //if (sa_popTable[i].bStatic) PenPat((ConstPatternParam)&GRAY_BRUSH); if (sa_popTable[i].bStatic) PenPatQDGlobalsGray(); FrameRect(&itemBox); /* draw the shadow */ MoveTo(itemBox.left + 3, itemBox.bottom); Line((itemBox.right - itemBox.left) - 3, 0); Line(0, -((itemBox.bottom - itemBox.top) - 2)); PenNormal(); } else EraseRect( &itemBox ); /* draw the current item in the box */ // if (theWorld.hasColorQD) RGBForeColor(&DefaultFore); if (ColorQDAvailable()) RGBForeColor(&DefaultFore); // Draw text if no Type-in Pop-Up if(drawStringFlag == 0){ if (sa_popTable[i].drawProc != nil) { cellBox = itemBox; InsetRect(&cellBox, 1, 1); (* sa_popTable[i].drawProc) (theMenu, sa_popTable[i].lastItemSelected, &cellBox, // so the drawProc gets the same-size rect, // whether it's drawing in the menu or in the pop-box true, // since we are indeed drawing a pop box item //&theWorld, &DefaultFore, &DefaultBack); } else { MoveTo(itemBox.left + 15, itemBox.top + 4 + (itemBox.bottom - itemBox.top)/2); GetMenuItemText(theMenu, sa_popTable[i].lastItemSelected, (unsigned char *)name); DrawString((unsigned char *)name); } } if (TRUE) { // !sa_popTable[i].bStatic /* cover the item in gray if the menu is disabled */ // if (!((**theMenu).enableFlags & ENABLE_BIT)) { #if TARGET_API_MAC_CARBON Boolean menuIsEnabled = IsMenuItemEnabled(theMenu,0); #else Boolean menuIsEnabled = (**theMenu).enableFlags & ENABLE_BIT; #endif if (!menuIsEnabled) { //PenPat((ConstPatternParam)&qd.gray); //PenPat((ConstPatternParam)&GRAY_BRUSH); PenPatQDGlobalsGray(); PenMode(patOr); //if (theWorld.hasColorQD) RGBForeColor(&DefaultBack); if (ColorQDAvailable()) RGBForeColor(&DefaultBack); else ForeColor(whiteColor); PaintRect(&itemBox); PenNormal(); // if (theWorld.hasColorQD) RGBForeColor(&DefaultFore); if (ColorQDAvailable()) RGBForeColor(&DefaultFore); else ForeColor(blackColor); } /* draw the down arrow */ itemBox.left = itemBox.right - 20; DrawArrow(&itemBox, kDown, sa_popTable[i].bStatic); } //if (theWorld.hasColorQD) { if (ColorQDAvailable()) { RGBForeColor(&SaveFore); RGBBackColor(&SaveBack); } SetPortGrafPort(savePort); }