static void MyDrawUserItem(DialogRef theDialog, DialogItemIndex itemNo) { DialogItemType itemType; Handle itemHandle; Rect itemBox; GetDialogItem(theDialog, itemNo, &itemType, &itemHandle, &itemBox); CGrafPtr savePort; GetPort(&savePort); SetPortDialogPort(theDialog); PenState penState; GetPenState(&penState); PenSize(3, 3); if (itemType & itemDisable) { Pattern gray; PenPat(GetQDGlobalsGray(&gray)); } FrameRect(&itemBox); Rect userRect = {gUserV-4, gUserH-4, gUserV+4, gUserH+4}; PaintRect(&userRect); SetPenState(&penState); SetPort(savePort); }
// -------------------------------------------------------------------------------------- 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
/* SetDialogPort(theDialog) SetDialogPort sets the current GrafPort on Macintosh and does nothing on Windows. On Macintosh, it returns the current GrafPort before SetDialogPort was called. On Windows, it returns theDialog. This routine exists solely to avoid the need for an ifdef when you need to deal with the Macintosh current GrafPort in cross-platform dialog code. Thread Safety: SetDialogPort is not thread-safe. */ CGrafPtr SetDialogPort(DialogPtr theDialog) { CGrafPtr savePort; GetPort(&savePort); SetPortDialogPort(theDialog); return savePort; }
/**************************************************************** PopErase() erases the given popup and its shadow. ****************************************************************/ void PopErase(DialogPtr theDialog, short itemNum) { GrafPtr savePort; short itemType; Handle itemHandle; Rect itemBox; GetPortGrafPtr(&savePort); SetPortDialogPort(theDialog); GetDialogItem(theDialog, itemNum, &itemType, &itemHandle, &itemBox); itemBox.right++; itemBox.bottom++; EraseRect(&itemBox); SetPortGrafPort(savePort); }
void showAboutMeDialog() { GrafPtr savePort; DialogPtr theDialog; short itemHit; GetPort(&savePort); theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1); //SetPort(theDialog); SetPortDialogPort(theDialog); do { ModalDialog(nil, &itemHit); } while (itemHit != okButton); //CloseDialog(theDialog); DisposeDialog(theDialog); SetPort(savePort); return; }
/**************************************************************** PopInvert() inverts the given popup. ****************************************************************/ void PopInvert(DialogPtr theDialog, short itemNum) { GrafPtr savePort; short itemType; Handle itemHandle; Rect itemBox; //SysEnvRec theWorld; RGBColor SaveBack, DefaultBack, DefaultFore, saveHilite; GetPortGrafPtr(&savePort); SetPortDialogPort(theDialog); GetDialogItem(theDialog, itemNum, &itemType, &itemHandle, &itemBox); // SysEnvirons(curSysEnvVers,&theWorld); //if (!theWorld.hasColorQD) { if (ColorQDAvailable()) { InvertRect( &itemBox ); return; } GetBackColor(&SaveBack); LMGetHiliteRGB(&saveHilite); DefaultMenuColors(&DefaultFore, &DefaultBack); RGBBackColor(&DefaultBack); HiliteColor(&DefaultFore); LMSetHiliteMode(LMGetHiliteMode() & 0x7F); // clear 0th bit = pHiliteBit InvertRect( &itemBox ); HiliteColor(&saveHilite); RGBBackColor(&SaveBack); SetPortGrafPort(savePort); }
// -------------------------------------------------------------------------------------- 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
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; }
// -------------------------------------------------------------------------------------- static Boolean dialogFilter(EventRecord *event, DialogRef *theDialog, DialogItemIndex *itemHit) { /* See the comments for HandleKeyDown in PrefsWindow.c about why we're using virtual key codes instead of character codes. */ Boolean eventHandled = false; char charCode, keyCode; switch (event->what) { case keyDown: // handle key presses not handled by DialogSelect case autoKey: *theDialog = GetDialogFromWindow(FrontNonFloatingWindow()); SetPortDialogPort(*theDialog); charCode = event->message & charCodeMask; keyCode = (event->message & keyCodeMask) >> 8; if ((event->modifiers & cmdKey) != 0) // check to see if any menu commands { // were selected - this isn't necessarily handling the event UInt32 menuChoice; OSErr error; MenuCommand commandID; menuChoice = MenuEvent(event); error = GetMenuItemCommandID(GetMenuRef(HiWord(menuChoice)), LoWord(menuChoice), &commandID); if (error == noErr) { if (commandID == 0) // if the menu item chosen does not have a commandID = (MenuCommand)menuChoice; // command ID HandleMenuChoice(commandID); // (but they all should) } } if ( (keyCode == kEnterKeyCode) || (keyCode == kReturnKeyCode) || (keyCode == kEscapeKeyCode) || ( ((event->modifiers & cmdKey) != 0) && (charCode == '.') ) ) { ControlRef button; unsigned long finalTicks; if ( (keyCode == kEnterKeyCode) || (keyCode == kReturnKeyCode) ) { GetDialogItemAsControl(*theDialog, kStdOkItemIndex, &button); *itemHit = kStdOkItemIndex; } else { GetDialogItemAsControl(*theDialog, kStdCancelItemIndex, &button); *itemHit = kStdCancelItemIndex; } HiliteControl(button, kControlButtonPart); Delay(8, &finalTicks); HiliteControl(button, kControlNoPart); eventHandled = true; } } return eventHandled; }
/**************************************************************** PopClick() gets called when there is a click in a dialog item that might be a popup item. It determines if the click is in a popup and if so handles the click. It brings up the popup on the item that was last selected for this menu. It returns true if the item was a popup item and the mouse was released on a valid item. In that case, it also stores the value returned by PopUpMenuSelect in *result (a long containing the menu and item ID selected). If the item selected was in this menu (as opposed to one of its submenus), that item is stored in the lastItemSelected field for this popup in the popTable. In that case, the item is also checked, and the previously selected item is unchecked. For a click on a static popup item, PopClick returns false, returns 0 in *result and doesn't call PopUpMenuSelect. -- On the IBM, this simply gets the index value of the selected item. ****************************************************************/ Boolean PopClick(DialogPtr theDialog, short itemHit, LONGPTR result) { #ifndef IBM GrafPtr savePort; short theType; Rect popBox; Rect titleBox; MenuHandle theMenu; long res; short count; char name[256]; Handle itemHandle; #else HANDLE itemHandle; #endif short i; #ifndef IBM if (OverridePopClick(theDialog, itemHit, result)) return true; #endif for ( i = 0 ; i < sa_numPopUps ; i++ ) if ( (sa_popTable[i].dialogPtr == theDialog) && (sa_popTable[i].popupItemNum == itemHit) ) break; if (i == sa_numPopUps || sa_popTable[i].bStatic) { *result = 0; return false; } #ifdef IBM itemHandle = GetDlgItem (theDialog, itemHit); sa_popTable[i].lastItemSelected = // (SendMessage (itemHandle, CB_GETCURSEL, 0, 0L)+1); //Combo box item ID's begin at 0 (SendMessage ((HWND)itemHandle, CB_GETCURSEL, 0, 0L)+1); //Combo box item ID's begin at 0 return FALSE; #else GetPortGrafPtr(&savePort); SetPortDialogPort(theDialog); theMenu = GetMenuHandle(sa_popTable[i].menuID); if (sa_popTable[i].drawProc == nil) // grow items to match size of pop-box for ( count = CountMenuItems(theMenu) ; count >= 1 ; count-- ) { GetMenuItemText(theMenu, count, (StringPtr)name); my_p2cstr((StringPtr)name); strcat(name, " "); my_c2pstr(name); SetMenuItemText(theMenu, count, (StringPtr)name); my_p2cstr((StringPtr)name); } if (sa_popTable[i].titleItemNum) { GetDialogItem(theDialog,sa_popTable[i].titleItemNum,&theType,&itemHandle,&titleBox); InvertRect(&titleBox); } GetDialogItem(theDialog,sa_popTable[i].popupItemNum,&theType,&itemHandle,&popBox); LocalToGlobal((Point *)(&popBox.top)); LocalToGlobal((Point *)(&popBox.bottom)); res = PopUpMenuSelect( theMenu, popBox.top + 1, popBox.left + 1, sa_popTable[i].lastItemSelected ); if (sa_popTable[i].titleItemNum) InvertRect(&titleBox); if (LoWord(res) && (HiWord(res) == sa_popTable[i].menuID)) { SetItemMark(theMenu, sa_popTable[i].lastItemSelected, noMark); sa_popTable[i].lastItemSelected = LoWord(res); SetItemMark(theMenu, sa_popTable[i].lastItemSelected, kCheckMark); } if (sa_popTable[i].drawProc == nil) // shrink items back to normal for ( count = CountMenuItems(theMenu) ; count >= 1 ; count-- ) { GetMenuItemText(theMenu, count, (StringPtr)name); my_p2cstr((StringPtr)name); name[strlen(name) - 5] = 0; my_c2pstr(name); SetMenuItemText(theMenu, count, (StringPtr)name); my_p2cstr((StringPtr)name); } *result = res; SetPortGrafPort(savePort); if (LoWord(res)) { PopDraw(sa_popTable[i].dialogPtr, sa_popTable[i].popupItemNum); return true; } return false; #endif //IBM }
/**************************************************************** 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); }