static void SelectTabPane (HIViewRef tabControl, SInt16 index) { HIViewRef sup, userPane, selectedPane = NULL; HIViewID cid; lastTabIndex = index; sup = HIViewGetSuperview(tabControl); cid.signature = 'tabs'; for (int i = 1; i < tabList[0] + 1; i++) { cid.id = tabList[i]; HIViewFindByID(sup, cid, &userPane); if (i == index) selectedPane = userPane; else HIViewSetVisible(userPane, false); } if (selectedPane != NULL) HIViewSetVisible(selectedPane, true); HIViewSetNeedsDisplay(tabControl, true); }
wxMacSearchFieldControl::wxMacSearchFieldControl( wxTextCtrl *wxPeer, const wxString& str, const wxPoint& pos, const wxSize& size, long style ) : wxMacUnicodeTextControl( wxPeer ) { m_font = wxPeer->GetFont() ; m_windowStyle = style ; m_selection.selStart = m_selection.selEnd = 0; Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; wxString st = str ; wxMacConvertNewlines10To13( &st ) ; wxCFStringRef cf(st , m_font.GetEncoding()) ; m_valueTag = kControlEditTextCFStringTag ; OptionBits attributes = kHISearchFieldAttributesSearchIcon; HIRect hibounds = { { bounds.left, bounds.top }, { bounds.right-bounds.left, bounds.bottom-bounds.top } }; verify_noerr( HISearchFieldCreate( &hibounds, attributes, 0, // MenuRef CFSTR(""), &m_controlRef ) ); HIViewSetVisible (m_controlRef, true); verify_noerr( SetData<CFStringRef>( 0, kControlEditTextCFStringTag , cf ) ) ; ::InstallControlEventHandler( m_controlRef, GetwxMacSearchControlEventHandlerUPP(), GetEventTypeCount(eventList), eventList, wxPeer, NULL); SetNeedsFrame(false); wxMacUnicodeTextControl::InstallEventHandlers(); }
void MacWebWidget::hideEvent ( QHideEvent * event ) { QWidget::hideEvent(event); if ( m_hiWebView && m_container) { HIViewRemoveFromSuperview( m_hiWebView ); HIViewSetVisible( m_hiWebView, false ); } }
void MacWebWidget::showEvent ( QShowEvent * event ) { QWidget::showEvent(event); if ( m_hiWebView && m_container) { setWebViewFrame(); HIViewAddSubview( (HIViewRef)m_container->winId(), m_hiWebView ); HIViewSetVisible( m_hiWebView, true ); } }
// -------------------------------------------------------------------------------------- pascal void IconDataBrowserItemSelectionCompCB(ControlRef browser, DataBrowserItemID item, DataBrowserItemNotification message) { #pragma unused (browser) IconDBItemDataRec *itemData; itemData = (IconDBItemDataRec *)item; switch (message) { case kDataBrowserItemSelected: HIViewSetVisible(itemData->userPane, true); break; case kDataBrowserItemDeselected: HIViewSetVisible(itemData->userPane, false); break; } }
bool8 NPServerDialog (void) { OSStatus err; IBNibRef nibRef; npserver.dialogcancel = true; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { WindowRef tWindowRef; err = CreateWindowFromNib(nibRef, CFSTR("ClientList"), &tWindowRef); if (err == noErr) { EventHandlerRef eref; EventLoopTimerRef tref; EventHandlerUPP eventUPP; EventLoopTimerUPP timerUPP; EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; HIViewRef ctl; HIViewID cid = { 'Chse', 0 }; npserver.dialogprocess = kNPSDialogInit; eventUPP = NewEventHandlerUPP(NPServerDialogEventHandler); err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref); timerUPP = NewEventLoopTimerUPP(NPServerDialogTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) tWindowRef, &tref); HIViewFindByID(HIViewGetRoot(tWindowRef), cid, &ctl); HIViewSetVisible(ctl, false); MoveWindowPosition(tWindowRef, kWindowServer, false); ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowServer); err = RemoveEventLoopTimer(tref); DisposeEventLoopTimerUPP(timerUPP); err = RemoveEventHandler(eref); DisposeEventHandlerUPP(eventUPP); CFRelease(tWindowRef); } DisposeNibReference(nibRef); } return (!npserver.dialogcancel); }
//----------------------------------------------------------------------------------- // ValueChanged //----------------------------------------------------------------------------------- void TMultiPane::ValueChanged() { HIViewRef subPane; SInt32 value = GetValue(); SInt32 min = GetMinimum(); SInt32 max = GetMaximum(); for (SInt32 i = min; i <= max; ++i) { HIViewID id = { kSubPanelSignature + mID, i }; OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane); if (result == noErr) { HIViewSetVisible( subPane, false); } } HIViewID id = { kSubPanelSignature + mID, value }; OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane); if (result == noErr) { HIViewSetVisible( subPane, true); } Invalidate(); }
extern OSStatus HICreateScrollingTextBox( const HIRect * inBounds, /* can be NULL */ CFStringRef inScrollingText, Boolean inAutoScroll, UInt32 inDelayBeforeAutoScroll, UInt32 inDelayBetweenAutoScroll, UInt16 inAutoScrollAmount, HIViewRef * outHIView) { *outHIView = NULL; EventRef theInitializeEvent = NULL; HIViewRef scrollView; OSStatus status; status = CreateEvent(NULL, kEventClassHIObject, kEventHIObjectInitialize, GetCurrentEventTime(), kEventAttributeUserEvent, &theInitializeEvent); // settings SetEventParameter(theInitializeEvent, kEventParamScrollingText, typeCFStringRef, sizeof(inScrollingText), &inScrollingText); SetEventParameter(theInitializeEvent, kEventParamAutoScroll, typeBoolean, sizeof(inAutoScroll), &inAutoScroll); SetEventParameter(theInitializeEvent, kEventParamDelayBeforeAutoScroll, typeUInt32, sizeof(inDelayBeforeAutoScroll), &inDelayBeforeAutoScroll); SetEventParameter(theInitializeEvent, kEventParamDelayBetweenAutoScroll, typeUInt32, sizeof(inDelayBetweenAutoScroll), &inDelayBetweenAutoScroll); SetEventParameter(theInitializeEvent, kEventParamAutoScrollAmount, typeSInt16, sizeof(inAutoScrollAmount), &inAutoScrollAmount); HIObjectRef hiObject; status = HIObjectCreate(GetScrollingTextBoxClass(), theInitializeEvent, &hiObject); HIViewSetVisible((HIViewRef)hiObject, true); if (!inAutoScroll) { // // Manual scrolling, we need to be embedded in a scroll view // status = HIScrollViewCreate(kHIScrollViewOptionsVertScroll, &scrollView); status = HIViewAddSubview(scrollView, (HIViewRef)hiObject); if (inBounds != NULL) HIViewSetFrame(scrollView, inBounds); EventTypeSpec event = {kEventClassControl, kEventControlDraw}; InstallEventHandler(GetControlEventTarget(scrollView), FrameView, 1, &event, NULL, NULL); *outHIView = scrollView; } else { if (inBounds != NULL) HIViewSetFrame((HIViewRef)hiObject, inBounds); *outHIView = (HIViewRef)hiObject; } return status; }
void IGraphicsCarbon::EndUserInput(bool commit) { RemoveEventHandler(mTextEntryHandler); mTextEntryHandler = 0; if (commit) { CFStringRef str; if (GetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str), &str, NULL) == noErr) { char txt[MAX_PARAM_LEN]; CFStringGetCString(str, txt, MAX_PARAM_LEN, kCFStringEncodingUTF8); CFRelease(str); if (mEdParam) mGraphicsMac->SetFromStringAfterPrompt(mEdControl, mEdParam, txt); else mEdControl->TextFromTextEntry(txt); } } HIViewSetVisible(mTextEntryView, false); HIViewRemoveFromSuperview(mTextEntryView); if (mIsComposited) { //IRECT* pR = mEdControl->GetRECT(); //HIViewSetNeedsDisplayInRect(mView, &CGRectMake(pR->L, pR->T, pR->W(), pR->H()), true); HIViewSetNeedsDisplay(mView, true); } else { if (mEdControl) { mEdControl->SetDirty(false); mEdControl->Redraw(); } } SetThemeCursor(kThemeArrowCursor); SetUserFocusWindow(kUserFocusAuto); mTextEntryView = 0; mEdControl = 0; mEdParam = 0; }
OSStatus CreateMouseTrackingView(HIViewRef parentView, const Rect* inBounds, HIViewID* inViewID) { #define kCanvasClassID CFSTR( "com.apple.sample.canvasview" ) OSStatus err; EventRef event; HIViewRef theView; // Register this class err = MyMTViewRegister(kCanvasClassID); require_noerr( err, CantRegister ); // Make an initialization event err = CreateEvent( NULL, kEventClassHIObject, kEventHIObjectInitialize, GetCurrentEventTime(), 0, &event ); require_noerr( err, CantCreateEvent ); // If bounds were specified, push them into the initialization event // so that they can be used in the initialization handler. if ( inBounds != NULL ) { err = SetEventParameter(event, kCanvasBoundsParam, typeQDRectangle, sizeof(Rect), inBounds); require_noerr( err, CantSetParameter ); } err = HIObjectCreate(kCanvasClassID, event, (HIObjectRef*)&theView); require_noerr(err, CantCreate); if (parentView != NULL) { err = HIViewAddSubview(parentView, theView); } SetControlID(theView, inViewID); // useful if a handler needs to call GetControlByID() HIViewSetVisible(theView, true); CantCreate: CantSetParameter: CantCreateEvent: ReleaseEvent( event ); CantRegister: return err; }
/* Handle the initialization event for a star-shaped frame. This routine creates the content view, installs its event handler, and sets its initial location. */ OSStatus HandleStarFrameInitialize( EventHandlerCallRef inCallRef, EventRef inEvent, StarFrameData *frameData) { OSStatus retVal = eventNotHandledErr; HIViewRef contentView; // The frame view must support embedding HIViewChangeFeatures(frameData->hiSelf, kHIViewAllowsSubviews, kHIViewIsOpaque); // Create the content view for the frame. retVal = HIObjectCreate(kHIViewClassID, NULL, (HIObjectRef *)&contentView); if(noErr == retVal && NULL != contentView) { HIViewChangeFeatures(contentView, kHIViewAllowsSubviews, kHIViewIsOpaque); SetControlID(contentView, &kHIViewWindowContentID); // content view must be visible. verify_noerr(HIViewSetVisible(contentView, true)); // Make sure the content view is handling events verify_noerr(InstallControlEventHandler( contentView, gContentViewHandlerUPP, GetEventTypeCount(gContentViewHandledEvents), gContentViewHandledEvents, NULL, NULL)); // set the location of the content view appropriately PositionContentViewWithMetrics(frameData->hiSelf, contentView); // add the content view as a subview of me. verify_noerr(HIViewAddSubview(frameData->hiSelf, contentView)); retVal = noErr; } return retVal; }
static pascal OSStatus MusicBoxEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *userData) { #pragma unused (inHandlerCallRef) OSStatus err, result = eventNotHandledErr; WindowRef tWindowRef = (WindowRef) userData; switch (GetEventClass(inEvent)) { case kEventClassCommand: switch (GetEventKind(inEvent)) { HICommand cmd; case kEventCommandUpdateStatus: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &cmd); if (err == noErr && cmd.commandID == 'clos') { UpdateMenuCommandStatus(false); result = noErr; } break; case kEventCommandProcess: err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &cmd); if (err == noErr) { HIViewRef root, c1, c2, c3, c4; HIViewID cid; Rect rct; switch (cmd.commandID) { case 'bar1': so.stereo_switch ^= (1 << 0); result = noErr; break; case 'bar2': so.stereo_switch ^= (1 << 1); result = noErr; break; case 'bar3': so.stereo_switch ^= (1 << 2); result = noErr; break; case 'bar4': so.stereo_switch ^= (1 << 3); result = noErr; break; case 'bar5': so.stereo_switch ^= (1 << 4); result = noErr; break; case 'bar6': so.stereo_switch ^= (1 << 5); result = noErr; break; case 'bar7': so.stereo_switch ^= (1 << 6); result = noErr; break; case 'bar8': so.stereo_switch ^= (1 << 7); result = noErr; break; case 'bar9': so.stereo_switch ^= (1 << 8); result = noErr; break; case 'bara': so.stereo_switch ^= (1 << 9); result = noErr; break; case 'barb': so.stereo_switch ^= (1 << 10); result = noErr; break; case 'barc': so.stereo_switch ^= (1 << 11); result = noErr; break; case 'bard': so.stereo_switch ^= (1 << 12); result = noErr; break; case 'bare': so.stereo_switch ^= (1 << 13); result = noErr; break; case 'barf': so.stereo_switch ^= (1 << 14); result = noErr; break; case 'bar0': so.stereo_switch ^= (1 << 15); result = noErr; break; case 'Paus': mboxPause = !mboxPause; S9xSetSoundMute(mboxPause); result = noErr; break; case 'Tr_i': showIndicator = !showIndicator; root = HIViewGetRoot(tWindowRef); cid.id = 0; cid.signature = 'Pane'; HIViewFindByID(root, cid, &c1); HIViewSetVisible(c1, false); cid.signature = 'iMaG'; HIViewFindByID(root, cid, &c2); HIViewSetVisible(c2, false); cid.signature = 'rCTL'; HIViewFindByID(root, cid, &c3); HIViewSetVisible(c3, false); cid.signature = 'bCTL'; HIViewFindByID(root, cid, &c4); HIViewSetVisible(c4, false); GetWindowBounds(tWindowRef, kWindowStructureRgn, &rct); rct.bottom = rct.top + (showIndicator ? mbxOpenedHeight : mbxClosedHeight); err = TransitionWindow(tWindowRef, kWindowSlideTransitionEffect, kWindowResizeTransitionAction, &rct); HIViewSetVisible(c1, true); HIViewSetVisible(c2, true); HIViewSetVisible(c3, true); HIViewSetVisible(c4, true); result = noErr; break; case 'DONE': QuitAppModalLoopForWindow(tWindowRef); result = noErr; break; case 'HEAD': showIndicator = !showIndicator; SPCPlayDefrost(); showIndicator = !showIndicator; result = noErr; break; case 'S_EF': HideWindow(tWindowRef); showIndicator = !showIndicator; ConfigureSoundEffects(); showIndicator = !showIndicator; ShowWindow(tWindowRef); result = noErr; } } } } return result; }
void MusicBoxDialog(void) { OSStatus err; IBNibRef nibRef; if (!cartOpen) return; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { CFURLRef iconURL; FSRef iconFSRef; IconRef actIcon; WindowRef tWindowRef; actIcon = nil; if (musicboxmode == kMBXSoundEmulation) iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil); else iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil); if (iconURL) { if (CFURLGetFSRef(iconURL, &iconFSRef)) err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon); CFRelease(iconURL); } err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef); if (err == noErr) { EventHandlerRef mboxRef, paneRef; EventHandlerUPP mboxUPP, paneUPP; EventLoopTimerRef timeRef; EventLoopTimerUPP timeUPP; EventTypeSpec mboxEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }, paneEvents[] = { { kEventClassControl, kEventControlDraw } }; CFStringRef sref; CGDataProviderRef prov; CGImageRef ipng; CFURLRef iurl; HIViewRef ctl, root, paneView, imageView, contentView; HIViewID cid; HIRect bounds; Rect windowRect, barRect; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; mboxPause = false; mbxFinished = false; showIndicator = false; so.stereo_switch = ~0; for (int i = 0; i < MAC_MAX_PLAYERS; i++) controlPad[i] = 0; switch (drawingMethod) { case kDrawingOpenGL: Settings.OpenGLEnable = true; break; case kDrawingDirect: case kDrawingBlitGL: Settings.OpenGLEnable = false; } // 107's enhanced SPC player root = HIViewGetRoot(tWindowRef); cid.id = 0; if (musicboxmode == kMBXSoundEmulation) { cid.signature = 'HEAD'; HIViewFindByID(root, cid, &ctl); EnableControl(ctl); StoredAPU = new SAPU; StoredAPURegisters = new SAPURegisters; StoredSoundData = new SSoundData; StoredIAPURAM = new uint8 [0x10000]; SPCPlayFreeze(); } else MusicBoxForceFreeze(); cid.signature = 'Kart'; HIViewFindByID(root, cid, &ctl); SetStaticTextTrunc(ctl, truncEnd, false); _splitpath(Memory.ROMFilename, drive, dir, fname, ext); sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING); if (sref) { SetStaticTextCFString(ctl, sref, false); CFRelease(sref); } ipng = nil; iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil); if (iurl) { prov = CGDataProviderCreateWithURL(iurl); if (prov) { ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault); CGDataProviderRelease(prov); } CFRelease(iurl); } imageView = nil; if (ipng) { HIViewFindByID(root, kHIViewWindowContentID, &contentView); err = HIImageViewCreate(ipng, &imageView); if (err == noErr) { bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng)); HIViewSetFrame(imageView, &bounds); HIImageViewSetOpaque(imageView, false); HIViewSetVisible(imageView, true); HIViewAddSubview(contentView, imageView); cid.signature = 'iMaG'; SetControlID(imageView, &cid); } CGImageRelease(ipng); } cid.signature = 'Pane'; HIViewFindByID(root, cid, &paneView); HIViewGetBounds(paneView, &bounds); mbxViewWidth = bounds.size.width; mbxViewHeight = bounds.size.height; mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0; mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0; if (imageView) { HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView); HIViewAddSubview(imageView, paneView); } cid.signature = 'Tr_i'; HIViewFindByID(root, cid, &ctl); HIViewGetFrame(ctl, &bounds); GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect); mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); mbxOpenedHeight = windowRect.bottom - windowRect.top; windowRect.bottom = windowRect.top + mbxClosedHeight; SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); paneUPP = NewEventHandlerUPP(IndicatorEventHandler); err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef); mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler); err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef); timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef); MusicBoxInitIndicator(); stopNow = false; MacStartSound(); pthread_create(&mbxThread, nil, SoundTask, nil); MoveWindowPosition(tWindowRef, kWindowMusicBox, true); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); if (windowRect.bottom - windowRect.top > mbxClosedHeight) { showIndicator = true; SetControl32BitValue(ctl, 1); // Tr_i } ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowMusicBox); stopNow = true; pthread_join(mbxThread, nil); MacStopSound(); err = RemoveEventLoopTimer(timeRef); DisposeEventLoopTimerUPP(timeUPP); err = RemoveEventHandler(mboxRef); DisposeEventHandlerUPP(mboxUPP); err = RemoveEventHandler(paneRef); DisposeEventHandlerUPP(paneUPP); ReleaseWindow(tWindowRef); so.stereo_switch = ~0; mbxFinished = true; if (musicboxmode == kMBXSoundEmulation) { SPCPlayDefrost(); delete StoredAPU; delete StoredAPURegisters; delete StoredSoundData; delete [] StoredIAPURAM; } else MusicBoxForceDefrost(); Settings.OpenGLEnable = false; } if (actIcon) err = UnregisterIconRef('~9X~', 'micn'); DisposeNibReference(nibRef); } }
static pascal OSStatus CustomSpotViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { OSStatus result = eventNotHandledErr; CustomSpotViewData* myData = (CustomSpotViewData*)inRefcon; switch (GetEventClass(inEvent)) { case kEventClassHIObject: switch (GetEventKind(inEvent)) { case kEventHIObjectConstruct: { myData = (CustomSpotViewData*) calloc(1, sizeof(CustomSpotViewData)); GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(myData->view), NULL, &myData->view); result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData); break; } case kEventHIObjectInitialize: { HIRect bounds; GetEventParameter(inEvent, kEventParamBounds, typeHIRect, NULL, sizeof(bounds), NULL, &bounds); myData->spot.x = CGRectGetMidX(bounds) - CGRectGetMinX(bounds); myData->spot.y = CGRectGetMidY(bounds) - CGRectGetMinY(bounds); HIViewSetVisible(myData->view, true); break; } case kEventHIObjectDestruct: { free(myData); result = noErr; break; } default: break; } break; case kEventClassControl: switch (GetEventKind(inEvent)) { case kEventControlDraw: { CGContextRef context; HIRect bounds; result = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context); HIViewGetBounds(myData->view, &bounds); if (!IsControlActive(myData->view)) { CGContextSetGrayStrokeColor(context, 0.5, 0.3); CGContextSetGrayFillColor(context, 0.5, 0.3); } else { CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.7); CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.7); } CGContextSetLineWidth(context, 3.0); CGContextStrokeRect(context, bounds); HIRect spot = { {myData->spot.x - 4.0, myData->spot.y - 4.0}, {8.0, 8.0} }; CGContextFillRect(context, spot); result = noErr; break; } case kEventControlBoundsChanged: { HIRect newHIBounds; GetEventParameter(inEvent, kEventParamCurrentBounds, typeHIRect, NULL, sizeof(newHIBounds), NULL, &newHIBounds); myData->spot.x = CGRectGetMidX(newHIBounds) - CGRectGetMinX(newHIBounds); myData->spot.y = CGRectGetMidY(newHIBounds) - CGRectGetMinY(newHIBounds); break; } case kEventControlHitTest: { HIPoint pt; HIRect bounds; GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(pt), NULL, &pt); HIViewGetBounds(myData->view, &bounds); ControlPartCode part = (CGRectContainsPoint(bounds, pt))?kControlButtonPart:kControlNoPart; result = SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part); break; } case kEventControlTrack: { Point qdPoint; Rect qdWindowBounds; HIPoint hiPoint; HIRect hiViewBounds; MouseTrackingResult mouseStatus = kMouseTrackingMouseDown; HIViewGetBounds(myData->view, &hiViewBounds); GetWindowBounds(GetControlOwner(myData->view), kWindowStructureRgn, &qdWindowBounds); // handle the first mouseDown before moving GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(hiPoint), NULL, &hiPoint); while (mouseStatus != kMouseTrackingMouseUp) { if (CGRectContainsPoint(hiViewBounds, hiPoint)) { if (hiPoint.x < hiViewBounds.origin.x+4) hiPoint.x = hiViewBounds.origin.x+4; if (hiPoint.x > hiViewBounds.origin.x+hiViewBounds.size.width-4) hiPoint.x = hiViewBounds.origin.x+hiViewBounds.size.width-4; if (hiPoint.y < hiViewBounds.origin.y+4) hiPoint.y = hiViewBounds.origin.y+4; if (hiPoint.y > hiViewBounds.origin.y+hiViewBounds.size.height-4) hiPoint.y = hiViewBounds.origin.y+hiViewBounds.size.height-4; myData->spot = hiPoint; HIViewSetNeedsDisplay(myData->view, true); } // a -1 GrafPtr to TrackMouseLocation yields global coordinates TrackMouseLocation((GrafPtr)-1L, &qdPoint, &mouseStatus); // convert to window-relative coordinates hiPoint.x = qdPoint.h - qdWindowBounds.left; hiPoint.y = qdPoint.v - qdWindowBounds.top; // convert to view-relative coordinates HIViewConvertPoint(&hiPoint, NULL, myData->view); } break; } default: break; } break; default: break; } return result; }
/***************************************************** * * Handle_WindowCommandProcess(inHandlerCallRef, inEvent, inUserData) * * Purpose: called to handle of the events generated by the various controls of the HICustomView_Tester window * * Inputs: inHandlerCallRef - reference to the current handler call chain * inEvent - the event * inUserData - app-specified data you passed in the call to InstallEventHandler * * Returns: OSStatus - noErr indicates the event was handled * eventNotHandledErr indicates the event was not handled and the Toolbox should take over */ static pascal OSStatus Handle_WindowCommandProcess(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData) { OSStatus status; HIViewRef customView = (HIViewRef)inUserData; // getting the command HICommandExtended aCommand; status = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(aCommand), NULL, &aCommand); require_noerr(status, ExitCommandProcess); status = eventNotHandledErr; // cheking that the command came from a control if ( ! (aCommand.attributes & kHICommandFromControl) ) goto ExitCommandProcess; switch (aCommand.commandID) { // // Asking for a refresh of the custom view // case 'SNDt': HIViewSetNeedsDisplay(customView, true); status = noErr; break; // // Setting the control value of the custom view // case 'SV00': SetControl32BitValue(customView, 0); status = noErr; break; case 'SV01': SetControl32BitValue(customView, 1); status = noErr; break; case 'SV17': SetControl32BitValue(customView, 17); status = noErr; break; case 'SVTH': SetControl32BitValue(customView, 1000); status = noErr; break; case 'SVet': { HIViewRef editText; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText); char buffer[11]; Size actualSize; GetControlData(editText, kControlEntireControl, kControlEditTextTextTag, 10, buffer, &actualSize); if (actualSize > 10) actualSize = 10; buffer[actualSize] = 0; SetControl32BitValue(customView, atoi(buffer)); } status = noErr; break; // // Setting the state of the custom view // case 'CHlt': // setting the hilite to non-0 also stomps the previous hilite state if any // and we don't want that in our testing if (GetControl32BitValue(aCommand.source.control) == 1) HiliteControl(customView, 1); else HiliteControl(customView, 0); status = noErr; break; case 'CEnb': { HIViewRef hiliteControl; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckHiliteID, &hiliteControl); if (GetControl32BitValue(aCommand.source.control) == 1) EnableControl(customView); else DisableControl(customView); UInt16 prevHilite = GetControlHilite(customView); if ((prevHilite == kControlInactivePart) || (prevHilite == kControlDisabledPart)) DisableControl(hiliteControl); else EnableControl(hiliteControl); HIViewSetNeedsDisplay(customView, true); } status = noErr; break; case 'CAct': { HIViewRef hiliteControl; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckHiliteID, &hiliteControl); if (GetControl32BitValue(aCommand.source.control) == 1) ActivateControl(customView); else DeactivateControl(customView); UInt16 prevHilite = GetControlHilite(customView); if ((prevHilite == kControlInactivePart) || (prevHilite == kControlDisabledPart)) DisableControl(hiliteControl); else EnableControl(hiliteControl); HIViewSetNeedsDisplay(customView, true); } status = noErr; break; // // Testing the custom view in or as a scroller in a HIScrollView // case 'CTiS': case 'CTaS': if (GetControl32BitValue(aCommand.source.control) == 1) { // create a HIScrollView and install it where and as the custom view was HIViewRef scrollView; status = HIScrollViewCreate(kHIScrollViewValidOptions, &scrollView); require_noerr(status, ExitCommandProcess); HIRect frame; status = HIViewGetFrame(customView, &frame); require_noerr(status, ExitCommandProcess); status = HIViewSetFrame(scrollView, &frame); require_noerr(status, ExitCommandProcess); HIViewSetLayoutInfo(scrollView, &kBindToParentLayout); HIViewSetLayoutInfo(customView, &kNoBindLayout); status = HIViewAddSubview(HIViewGetSuperview(customView), scrollView); require_noerr(status, ExitCommandProcess); if (aCommand.commandID == 'CTiS') { // if we are testing the custom view in a scroller, we embed it in a scrolling User Pane // that we embed in the HIScrollView Rect boundsRect = {0, 0, 1000, 1000}; HIViewRef userPane; status = CreateUserPaneControl(NULL, &boundsRect, kControlSupportsEmbedding, &userPane); require_noerr(status, ExitCommandProcess); EventTypeSpec userPaneEvents[] = { {kEventClassScrollable, kEventScrollableGetInfo}, {kEventClassScrollable, kEventScrollableScrollTo} }; InstallControlEventHandler(userPane, UserPaneHandler, 2, userPaneEvents, userPane, NULL); status = HIViewAddSubview(scrollView, userPane); require_noerr(status, ExitCommandProcess); status = HIViewAddSubview(userPane, customView); require_noerr(status, ExitCommandProcess); HIViewSetVisible(userPane, true); } else { // else we just embed the custom view directly in the HIScrollView status = HIViewAddSubview(scrollView, customView); require_noerr(status, ExitCommandProcess); } HIViewSetVisible(scrollView, true); // the 2 modes are not compatible so we disable the other check box HIViewRef otherCheckToDisable; if (aCommand.commandID == 'CTiS') HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestAsScrollID, &otherCheckToDisable); else HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestInScrollID, &otherCheckToDisable); require_noerr(status, ExitCommandProcess); DisableControl(otherCheckToDisable); // if we reach here, status is already set to noErr so we don't set it again } else { // we remove the HIScrollView and set the custom view back to where and as it was HIViewRef scrollView; if (aCommand.commandID == 'CTiS') scrollView = HIViewGetSuperview(HIViewGetSuperview(customView)); else scrollView = HIViewGetSuperview(customView); status = HIViewAddSubview(HIViewGetSuperview(scrollView), customView); require_noerr(status, ExitCommandProcess); HIRect frame; status = HIViewGetFrame(scrollView, &frame); require_noerr(status, ExitCommandProcess); status = HIViewSetFrame(customView, &frame); require_noerr(status, ExitCommandProcess); HIViewSetLayoutInfo(customView, &kBindToParentLayout); // by releasing the HIScrollView, we also release the scrolling User Pane if any // which was embedded inside CFRelease(scrollView); // we renable the other check box HIViewRef otherCheckToEnable; if (aCommand.commandID == 'CTiS') HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestAsScrollID, &otherCheckToEnable); else HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kCheckTestInScrollID, &otherCheckToEnable); require_noerr(status, ExitCommandProcess); EnableControl(otherCheckToEnable); // if we reach here, status is already set to noErr so we don't set it again } break; } ExitCommandProcess: return status; } // Handle_WindowCommandProcess
static pascal void NPClientDialogTimerHandler (EventLoopTimerRef inTimer, void *userData) { WindowRef window = (WindowRef) userData; HIViewRef ctl; HIViewID cid = { 'CHAS', 0 }; HIViewFindByID(HIViewGetRoot(mRef), cid, &ctl); switch (npclient.dialogprocess) { case kNPCDialogNone: break; case kNPCDialogCancel: NPNotification(" kNPCDialogCancel", -1); npclient.dialogprocess = kNPCDialogNone; npclient.dialogcancel = true; QuitAppModalLoopForWindow(mRef); break; case kNPCDialogInit: NPNotification(" kNPCDialogInit", -1); npclient.dialogprocess = kNPCDialogNone; break; case kNPCDialogConnect: NPNotification(" kNPCDialogConnect", -1); npclient.dialogprocess = kNPCDialogNone; HIViewSetVisible(ctl, true); NPClientDetachConnectThread(); break; case kNPCDialogConnectFailed: NPNotification(" kNPCDialogConnectFailed", -1); npclient.dialogprocess = kNPCDialogNone; npclient.dialogcancel = true; QuitAppModalLoopForWindow(mRef); break; case kNPCDialogOpenBegin: NPNotification(" kNPCDialogOpenBegin", -1); npclient.dialogprocess = kNPCDialogNone; HIViewSetVisible(ctl, false); NPClientStoreConfig(); if (!NPClientBeginOpenROMImage(window)) { NPClientDisconnect(); NPClientRestoreConfig(); npclient.dialogprocess = kNPCDialogCancel; } break; case kNPCDialogOpenEnd: NPNotification(" kNPCDialogOpenEnd", -1); npclient.dialogprocess = kNPCDialogNone; if (!NPClientEndOpenROMImage()) { NPClientDisconnect(); NPClientRestoreConfig(); npclient.dialogprocess = kNPCDialogCancel; } else npclient.dialogprocess = kNPCDialogPrepare; break; case kNPCDialogPrepare: NPNotification(" kNPCDialogPrepare", -1); npclient.dialogprocess = kNPCDialogNone; HIViewSetVisible(ctl, true); NPClientDetachPrepareThread(); break; case kNPCDialogPrepareFailed: NPNotification(" kNPCDialogPrepareFailed", -1); npclient.dialogprocess = kNPCDialogNone; NPClientRestoreConfig(); npclient.dialogcancel = true; QuitAppModalLoopForWindow(mRef); break; case kNPCDialogShowList: NPNotification(" kNPCDialogShowList", -1); npclient.dialogprocess = kNPCDialogNone; HIViewSetVisible(ctl, false); npclient.dialogsheet = true; NPClientBeginPlayerListSheet(); break; case kNPCDialogDone: NPNotification(" kNPCDialogDone", -1); npclient.dialogprocess = kNPCDialogNone; NPClientEndPlayerListSheet(); npclient.dialogsheet = false; npclient.dialogcancel = false; QuitAppModalLoopForWindow(mRef); break; } }
bool8 NPClientDialog (void) { OSStatus err; IBNibRef nibRef; npclient.dialogcancel = true; npclient.dialogsheet = false; npclient.configsaved = false; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { err = CreateWindowFromNib(nibRef, CFSTR("Connect"), &mRef); if (err == noErr) { err = CreateWindowFromNib(nibRef, CFSTR("PlayerList"), &sRef); if (err == noErr) { EventHandlerRef eref, seref; EventLoopTimerRef tref; EventHandlerUPP eventUPP, sheetUPP; EventLoopTimerUPP timerUPP; EventTypeSpec windowEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; CFStringRef ref; HIViewRef ctl, root; HIViewID cid; npclient.dialogprocess = kNPCDialogInit; eventUPP = NewEventHandlerUPP(NPClientDialogEventHandler); err = InstallWindowEventHandler(mRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) mRef, &eref); timerUPP = NewEventLoopTimerUPP(NPClientDialogTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) mRef, &tref); sheetUPP = NewEventHandlerUPP(NPClientSheetEventHandler); err = InstallWindowEventHandler(sRef, sheetUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) sRef, &seref); root = HIViewGetRoot(mRef); cid.id = 0; cid.signature = 'CHAS'; HIViewFindByID(root, cid, &ctl); HIViewSetVisible(ctl, false); cid.signature = 'SVIP'; HIViewFindByID(root, cid, &ctl); SetEditTextCStr(ctl, npServerIP, false); cid.signature = 'CLNM'; HIViewFindByID(root, cid, &ctl); ref = CFStringCreateWithCString(kCFAllocatorDefault, npName, kCFStringEncodingUTF8); if (ref) { SetEditTextCFString(ctl, ref, false); CFRelease(ref); } else SetEditTextCFString(ctl, CFSTR("unknown"), false); MoveWindowPosition(mRef, kWindowClient, false); ShowWindow(mRef); err = HIViewAdvanceFocus(root, 0); err = RunAppModalLoopForWindow(mRef); HideWindow(mRef); SaveWindowPosition(mRef, kWindowClient); err = RemoveEventHandler(seref); DisposeEventHandlerUPP(sheetUPP); err = RemoveEventLoopTimer(tref); DisposeEventLoopTimerUPP(timerUPP); err = RemoveEventHandler(eref); DisposeEventHandlerUPP(eventUPP); CFRelease(sRef); } CFRelease(mRef); } DisposeNibReference(nibRef); } return (!npclient.dialogcancel); }
int main(int argc, char *argv[]) { WindowRef window; HIViewRef content; HIViewRef combo; HIViewRef group; HIViewRef check; HIViewRef text; HIViewRef slider; HIViewRef quit; MenuRef menu; HIRect rect; // Window bounds Rect bounds = {0, 0, 436, 590}; // Create window CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowCompositingAttribute, &bounds, &window); // Set the title SetWindowTitleWithCFString(window, CFSTR("Accordion")); // Create an application menu CreateNewMenu(0, 0, &menu); // Set menu title SetMenuTitleWithCFString(menu, CFStringCreateWithPascalString(kCFAllocatorDefault, "\p\024", kCFStringEncodingMacRoman)); // Create an about item InsertMenuItemTextWithCFString(menu, CFSTR("About Accordion"), 0, 0, kHICommandAbout); // Insert the menu InsertMenu(menu, 0); // Create a standard window menu CreateStandardWindowMenu(0, &menu); // Insert the menu InsertMenu(menu, 0); // Show and position the window ShowWindow(window); RepositionWindow(window, NULL, kWindowCascadeOnMainScreen); // Find the window content HIViewFindByID(HIViewGetRoot(window), kHIViewWindowContentID, &content); // Set bounds for group box bounds.bottom = 92; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 20); // Bounds of text bounds.bottom = 16; bounds.right = 74; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Instrument:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 18); // Bounds of combo box rect.size.height = 20; rect.size.width = 168; // Create combo box HIComboBoxCreate(&rect, CFSTR(" Accordion"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetCommandID(combo, kCommandInst); // Add the instruments for (int i = 0; i < Length(instruments); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, instruments[i], kCFStringEncodingMacRoman), NULL); // Set the current instrument if (strcmp(instruments[i], " Accordion") == 0) instrument = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 102, 16); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Reverse"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDReverse); HIViewSetCommandID(check, kCommandReverse); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 17); // Bounds of text bounds.bottom = 16; bounds.right = 32; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Key:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 400, 18); // Bounds of combo box rect.size.width = 90; // Create combo box HIComboBoxCreate(&rect, CFSTR(" A/D/G"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetID(combo, kHIViewIDKey); HIViewSetCommandID(combo, kCommandKey); // Add keys for (int i = 0; i < Length(keys); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, keys[i], kCFStringEncodingMacRoman), NULL); // Set current key if (strcmp(keys[i], " A/D/G") == 0) key = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 440, 16); // Bounds of text bounds.bottom = 16; bounds.right = 54; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Volume:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 56); // Bounds of slider bounds.bottom = 16; bounds.right = 168; // Create slider CreateSliderControl(window, &bounds, MAXVOL, 0, MAXVOL, kControlSliderDoesNotPoint, 0, false, NULL, &slider); // Set command ID HIViewSetCommandID(slider, kCommandVolume); // Place in the group box HIViewAddSubview(group, slider); HIViewPlaceInSuperviewAt(slider, 100, 58); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Notes"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDNote); HIViewSetCommandID(check, kCommandNote); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 56); // Bounds of push button bounds.bottom = 20; bounds.right = 90; // Create push button CreatePushButtonControl(window, &bounds, CFSTR("Quit"), &quit); // Set command ID HIViewSetCommandID(quit, kHICommandQuit); // Place in the group box HIViewAddSubview(group, quit); HIViewPlaceInSuperviewAt(quit, 440, 54); // Group box bounds bounds.bottom = 48; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 132); // Font style ControlFontStyleRec style; style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontBigSystemFont; style.just = teCenter; // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Accordion"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 8); // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Play accordion on your keyboard"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 24); // Group box bounds bounds.bottom = 196; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 200); // Button bounds bounds.bottom = SIZE; bounds.right = SIZE; // Create row of bass buttons for (int i = 0; i < Length(bassdisplay); i++) { int x = 15 + 44 * i; int y = 15; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &bassdisplay[i]); // Place in the group box HIViewAddSubview(group, bassdisplay[i]); HIViewPlaceInSuperviewAt(bassdisplay[i], x, y); } // Create three rows of buttons for (int i = 0; i < Length(display); i++) { for (int j = 0; j < ((i == 1)? Length(display[i]): Length(display[i]) - 1); j++) { int x = (i == 1)? 37 + 44 * j: 59 + 44 * j; int y = 59 + 44 * i; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &display[i][j]); // Place in the group box HIViewAddSubview(group, display[i][j]); HIViewPlaceInSuperviewAt(display[i][j], x, y); } } // Create spacebar button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &spacebar); // Place in the group box HIViewAddSubview(group, spacebar); HIViewPlaceInSuperviewAt(spacebar, 16, 147); // Group box bounds, wider than the window to hide rounded corners bounds.bottom = 20; bounds.right = 598; // Create group box for fake status bar CreateGroupBoxControl(window, &bounds, NULL, false, &group); // Place in window at negative offset to hide rounded corners HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, -4, 416); // Text bounds bounds.bottom = 16; bounds.right = 590; // Font style style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontSmallSystemFont; style.just = teCenter; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Press the keyboard keys as accordion buttons " "and the space bar as the bellows. 3rd button start."), &style, &text); // Place in group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 2); // Application events type spec EventTypeSpec applicationEvents[] = {{kEventClassApplication, kEventAppFrontSwitched}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ApplicationHandler), Length(applicationEvents), applicationEvents, NULL, NULL); // Mouse events type spec EventTypeSpec mouseEvents[] = {{kEventClassMouse, kEventMouseDown}}; // Install event handler on the event dispatcher, so that we can // see mouse events before the default handler gets them InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(MouseHandler), Length(mouseEvents), mouseEvents, NULL, NULL); // Window events type spec EventTypeSpec windowEvents[] = {{kEventClassWindow, kEventWindowClose}}; // Install event handler InstallWindowEventHandler(window, NewEventHandlerUPP(WindowHandler), Length(windowEvents), windowEvents, NULL, NULL); // Combo box events type spec EventTypeSpec comboBoxEvents[] = {{kEventClassHIComboBox, kEventComboBoxListItemSelected}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ComboBoxHandler), Length(comboBoxEvents), comboBoxEvents, NULL, NULL); // Command events type spec EventTypeSpec commandEvents[] = {{kEventClassCommand, kEventCommandProcess}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(CommandHandler), Length(commandEvents), commandEvents, NULL, NULL); // Keyboard events type spec EventTypeSpec keyboardEvents[] = {{kEventClassKeyboard, kEventRawKeyDown}, {kEventClassKeyboard, kEventRawKeyUp}, {kEventClassKeyboard, kEventRawKeyModifiersChanged}}; // Install event handler on the event dispatcher InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(KeyboardHandler), Length(keyboardEvents), keyboardEvents, NULL, NULL); // Audio Unit graph AUGraph graph; // Audio Unit synthesizer and output node AUNode synthNode; AUNode outNode; // Component description ComponentDescription cd; cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; do { // New AU graph OSStatus status = NewAUGraph(&graph); if (status != noErr) { DisplayAlert(CFSTR("NewAUGraph"), CFSTR("Can't create a new AUGraph"), status); break; } // Synthesizer cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; // New synthesizer node status = AUGraphNewNode(graph, &cd, 0, NULL, &synthNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Output cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; // New output node status = AUGraphNewNode(graph, &cd, 0, NULL, &outNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Open graph status = AUGraphOpen(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphOpen"), CFSTR("Can't open AUGraph"), status); break; } // Connect synthesizer node to output node status = AUGraphConnectNodeInput(graph, synthNode, 0, outNode, 0); if (status != noErr) { DisplayAlert(CFSTR("AUGraphConnectNodeInput"), CFSTR("Can't connect AUGraph input node"), status); break; } // Get a synthesizer unit status = AUGraphGetNodeInfo(graph, synthNode, NULL, 0, NULL, &synthUnit); if (status != noErr) { DisplayAlert(CFSTR("AUGraphGetNodeInfo"), CFSTR("Can't get AUGraph node info"), status); break; } // Initialise status = AUGraphInitialize(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphInitialize"), CFSTR("Can't initialize AUGraph"), status); break; } // Start status = AUGraphStart(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphStart"), CFSTR("Can't start AUGraph"), status); break; } // Show the graph // CAShow(graph); } while (false); // Change instrument ChangeInstrument(instrument); // Run the application event loop RunApplicationEventLoop(); // Stop the graph AUGraphStop(graph); // Dispose of the graph DisposeAUGraph(graph); // Exit return 0; }
/***************************************************** * * Do_NewWindow() * * Purpose: called to create a new window that has been constructed with Interface Builder * * Inputs: none * * Returns: OSStatus - error code (0 == no error) */ OSStatus Do_NewWindow(void) { OSStatus status; static IBNibRef gIBNibRef = NULL; WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; CFMutableStringRef theNewTitle = NULL; if (gIBNibRef == NULL) { // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. status = CreateNibReference(CFSTR("main"), &gIBNibRef); require_noerr(status, CantGetNibRef); } require(gIBNibRef != NULL, CantGetNibRef); // Create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. status = CreateWindowFromNib(gIBNibRef, CFSTR("MainWindow"), &aWindowRef); require_noerr(status, CantCreateWindow); require(NULL != aWindowRef, CantCreateWindow); // Grab the title of the window and add the window count to it status = CopyWindowTitleAsCFString(aWindowRef, &theTitle); require_noerr(status, CantGetSetTitle); theNewTitle = CFStringCreateMutableCopy(NULL, 0, theTitle); require(NULL != theNewTitle, CantGetSetTitle); CFStringAppendFormat(theNewTitle, NULL, CFSTR(" %ld"), ++gWindowCount); status = SetWindowTitleWithCFString(aWindowRef, theNewTitle); require_noerr(status, CantGetSetTitle); // Create the custom view to be tested and embed it in our group box control HIViewRef groupBox; status = HIViewFindByID(HIViewGetRoot(aWindowRef), kGroupBoxID, &groupBox); require_noerr(status, CantFindGroupBox); require(groupBox != NULL, CantFindGroupBox); HIViewRef customView; status = HICreateCustomView(NULL, &customView); require_noerr(status, CantCreateCustom); require(customView != NULL, CantCreateCustom); HIRect groupBoxBounds; HIViewGetBounds(groupBox, &groupBoxBounds); groupBoxBounds.origin.x += 20; groupBoxBounds.origin.y += 34; groupBoxBounds.size.width -= 40; groupBoxBounds.size.height -= 54; HIViewSetFrame(customView, &groupBoxBounds); HIViewSetLayoutInfo(customView, &kBindToParentLayout); status = HIViewAddSubview(groupBox, customView); require_noerr(status, CantAddSubview); HIViewSetVisible(customView, true); // Let's react to User's commands. EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)customView, NULL); require_noerr(status, CantInstallEventHandler); // Let's update our static text field whenever the value or hilite of our tested custom view changes EventTypeSpec eventTypeCVFC[] = { {kEventClassControl, kEventControlValueFieldChanged}, {kEventClassControl, kEventControlHiliteChanged} }; status = InstallControlEventHandler(customView, Handle_ControlValueFieldOrHiliteChanged, 2, eventTypeCVFC, (void *)customView, NULL); require_noerr(status, CantInstallEventHandler); // We accept only numbers in our Edit text control HIViewRef editText; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText); #ifdef MAC_OS_X_VERSION_10_4 // in Tiger, only 1 event handler is necessary for the key filtering EventTypeSpec eventTypeTSCIR = {kEventClassTextField, kEventTextShouldChangeInRange}; status = InstallControlEventHandler(editText, Handle_TextShouldChangeInRange, 1, &eventTypeTSCIR, (void *)editText, NULL); require_noerr(status, CantInstallEventHandler); #else // pre-Tiger, we need a different event handler and a validation proc to handle pastes and drops. ControlEditTextValidationUPP textValidation = MyValidationProc; SetControlData(editText, kControlEntireControl, kControlEditTextValidationProcTag, sizeof(textValidation), &textValidation); EventTypeSpec eventTypeTIUFKE = {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}; status = InstallControlEventHandler(editText, Handle_TextInputEvent, 1, &eventTypeTIUFKE, (void *)editText, NULL); require_noerr(status, CantInstallEventHandler); #endif // Finishing the custom view setup SetControl32BitMinimum(customView, 0); SetControl32BitMaximum(customView, 36); SetControl32BitValue(customView, 2); // We want window and thus our custom view to be able to respond to drops status = SetAutomaticControlDragTrackingEnabledForWindow(aWindowRef, true); require_noerr(status, SetAutomaticControlDragTrackingEnabledForWindow); ShowWindow(aWindowRef); SetWindowModified(aWindowRef, false); SetAutomaticControlDragTrackingEnabledForWindow: SetControlDragTrackingEnabled: CantAddSubview: CantCreateCustom: CantFindGroupBox: CantInstallEventHandler: CantGetSetTitle: CantAllocateWindowData: CantCreateWindow: CantGetNibRef: if (theTitle != NULL) CFRelease(theTitle); if (theNewTitle != NULL) CFRelease(theNewTitle); return status; } // Do_NewWindow
SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd), fAGLCtx(NULL) { OSStatus result; WindowRef wr = (WindowRef)hWnd; HIViewRef imageView, parent; HIViewRef rootView = HIViewGetRoot(wr); HIViewFindByID(rootView, kHIViewWindowContentID, &parent); result = HIImageViewCreate(NULL, &imageView); SkASSERT(result == noErr); result = HIViewAddSubview(parent, imageView); SkASSERT(result == noErr); fHVIEW = imageView; HIViewSetVisible(imageView, true); HIViewPlaceInSuperviewAt(imageView, 0, 0); if (true) { HILayoutInfo layout; layout.version = kHILayoutInfoVersionZero; set_bindingside(&layout.binding.left, parent, kHILayoutBindLeft); set_bindingside(&layout.binding.top, parent, kHILayoutBindTop); set_bindingside(&layout.binding.right, parent, kHILayoutBindRight); set_bindingside(&layout.binding.bottom, parent, kHILayoutBindBottom); set_axisscale(&layout.scale.x, parent); set_axisscale(&layout.scale.y, parent); set_axisposition(&layout.position.x, parent, kHILayoutPositionLeft); set_axisposition(&layout.position.y, rootView, kHILayoutPositionTop); HIViewSetLayoutInfo(imageView, &layout); } HIImageViewSetOpaque(imageView, true); HIImageViewSetScaleToFit(imageView, false); static const EventTypeSpec gTypes[] = { { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyUp }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseDragged }, { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseUp }, { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassWindow, kEventWindowBoundsChanged }, // { kEventClassWindow, kEventWindowDrawContent }, { SK_MacEventClass, SK_MacEventKind } }; EventHandlerUPP handlerUPP = NewEventHandlerUPP(SkOSWindow::EventHandler); int count = SK_ARRAY_COUNT(gTypes); result = InstallEventHandler(GetWindowEventTarget(wr), handlerUPP, count, gTypes, this, nil); SkASSERT(result == noErr); gCurrOSWin = this; gCurrEventQ = GetCurrentEventQueue(); gEventTarget = GetWindowEventTarget(wr); static bool gOnce = true; if (gOnce) { gOnce = false; gPrevNewHandler = set_new_handler(sk_new_handler); } }
OSStatus _Growl_ShowUpdatePromptForVersion(CFStringRef updateVersion) { OSStatus err = noErr; if (_checkOSXVersion()) { CFBundleRef bundle = CFBundleGetBundleWithIdentifier(GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER); if (!bundle) NSLog(CFSTR("GrowlInstallationPrompt: could not locate framework bundle (forget about installing Growl); had looked for bundle with identifier '%@'"), GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER); else { IBNibRef nib = NULL; err = CreateNibReferenceWithCFBundle(bundle, CFSTR("GrowlInstallationPrompt-Carbon"), &nib); if (err != noErr) { NSLog(CFSTR("GrowlInstallationPrompt: could not obtain nib: CreateNibReferenceWithCFBundle(%@, %@) returned %li"), bundle, CFSTR("GrowlInstallationPrompt-Carbon"), (long)err); } else { WindowRef window = NULL; err = CreateWindowFromNib(nib, CFSTR("Installation prompt"), &window); DisposeNibReference(nib); if (err != noErr) { NSLog(CFSTR("GrowlInstallationPrompt: could not obtain window from nib: CreateWindowFromNib(%p, %@) returned %li"), nib, CFSTR("Installation prompt"), (long)err); } else { OSStatus fillOutTextErr = _fillOutTextInWindow(window, (updateVersion != nil)); OSStatus fillOutIconErr = _fillOutIconInWindow(window); err = (fillOutTextErr != noErr) ? fillOutTextErr : (fillOutIconErr != noErr) ? fillOutIconErr : noErr; if (err == noErr) { if (updateVersion) { //store the update version on the window. updateVersion = CFRetain(updateVersion); err = SetWindowProperty(window, GROWL_SIGNATURE, GIPC_UPDATE_VERSION, sizeof(updateVersion), &updateVersion); if (err != noErr) NSLog(CFSTR("GrowlInstallationPrompt: SetWindowProperty returned %li"), (long)err); } EventHandlerUPP handlerUPP = NewEventHandlerUPP(_handleCommandInWindow); struct EventTypeSpec types[] = { { .eventClass = kEventClassCommand, .eventKind = kEventCommandProcess }, }; EventHandlerRef handler = NULL; err = InstallWindowEventHandler(window, handlerUPP, GetEventTypeCount(types), types, /*refcon*/ window, &handler); if (err != noErr) NSLog(CFSTR("GrowlInstallationPrompt: InstallWindowEventHandler returned %li"), (long)err); else { HIViewID chasingArrowsID = { GROWL_SIGNATURE, chasingArrowsIDNumber }; HIViewRef chasingArrows = NULL; //stop and hide the chasing arrows, until the user clicks Install. OSStatus chasingArrowsErr = HIViewFindByID(HIViewGetRoot(window), chasingArrowsID, &chasingArrows); if (chasingArrowsErr == noErr) { Boolean truth = false; SetControlData(chasingArrows, kControlEntireControl, kControlChasingArrowsAnimatingTag, sizeof(truth), &truth); HIViewSetVisible(chasingArrows, false); } SelectWindow(window); ShowWindow(window); err = RunAppModalLoopForWindow(window); if (err != noErr) NSLog(CFSTR("GrowlInstallationPrompt: RunAppModalLoopForWindow(%p) returned %li"), window, (long)err); RemoveEventHandler(handler); } DisposeEventHandlerUPP(handlerUPP); } ReleaseWindow(window); } } } }
void IGraphicsCarbon::CreateTextEntry(IControl* pControl, IText* pText, IRECT* pTextRect, const char* pString, IParam* pParam) { ControlRef control = 0; if (!pControl || mTextEntryView || !mIsComposited) return; Rect r = { pTextRect->T, pTextRect->L, pTextRect->B, pTextRect->R }; // these adjustments should make it the same as the cocoa one, i.e. the same size as the pTextRect, but with the extra blue rim often this is too small //Rect r = { pTextRect->T+4, pTextRect->L+3, pTextRect->B-3, pTextRect->R -3 }; if (CreateEditUnicodeTextControl(NULL, &r, NULL, false, NULL, &control) != noErr) return; HIViewAddSubview(mView, control); const EventTypeSpec events[] = { { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyRepeat } }; InstallControlEventHandler(control, TextEntryHandler, GetEventTypeCount(events), events, this, &mTextEntryHandler); mTextEntryView = control; if (pString[0] != '\0') { CFStringRef str = CFStringCreateWithCString(NULL, pString, kCFStringEncodingUTF8); if (str) { SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str), &str); CFRelease(str); } ControlEditTextSelectionRec sel; sel.selStart = 0; sel.selEnd = strlen(pString); SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextSelectionTag, sizeof(sel), &sel); } int just = 0; switch ( pText->mAlign ) { case IText::kAlignNear: just = teJustLeft; break; case IText::kAlignCenter: just = teCenter; break; case IText::kAlignFar: just = teJustRight; break; default: just = teCenter; break; } ControlFontStyleRec font = { kControlUseJustMask | kControlUseSizeMask | kControlUseFontMask, 0, pText->mSize, 0, 0, just, 0, 0 }; CFStringRef str = CFStringCreateWithCString(NULL, pText->mFont, kCFStringEncodingUTF8); font.font = ATSFontFamilyFindFromName(str, kATSOptionFlagsDefault); SetControlData(mTextEntryView, kControlEditTextPart, kControlFontStyleTag, sizeof(font), &font); CFRelease(str); Boolean singleLineStyle = true; SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextSingleLineTag, sizeof (Boolean), &singleLineStyle); HIViewSetVisible(mTextEntryView, true); HIViewAdvanceFocus(mTextEntryView, 0); SetKeyboardFocus(mWindow, mTextEntryView, kControlEditTextPart); SetUserFocusWindow(mWindow); mEdControl = pControl; mEdParam = pParam; }
static pascal void NPServerDialogTimerHandler (EventLoopTimerRef inTimer, void *userData) { WindowRef window = (WindowRef) userData; CFStringRef ref; HIViewRef ctl, root; HIViewID cid; int n = 0; root = HIViewGetRoot(window); for (int c = 0; c < NP_MAX_PLAYERS; c++) { cid.id = c; cid.signature = 'Pnum'; HIViewFindByID(root, cid, &ctl); if (npplayer[c].ready) { char num[4]; num[0] = '1' + n; num[1] = 'P'; num[2] = 0; SetStaticTextCStr(ctl, num, true); n++; } cid.signature = 'IP__'; HIViewFindByID(root, cid, &ctl); if (npplayer[c].online) { ref = CFStringCreateWithCString(kCFAllocatorDefault, npplayer[c].ip, MAC_PATH_ENCODING); if (ref) { SetStaticTextCFString(ctl, ref, true); CFRelease(ref); } else SetStaticTextCFString(ctl, CFSTR("unknown"), true); } else SetStaticTextCFString(ctl, CFSTR(""), true); cid.signature = 'Name'; HIViewFindByID(root, cid, &ctl); if (npplayer[c].online) { ref = CFStringCreateWithCString(kCFAllocatorDefault, npplayer[c].name, MAC_PATH_ENCODING); if (ref) { SetStaticTextCFString(ctl, ref, true); CFRelease(ref); } else SetStaticTextCFString(ctl, CFSTR("unknown"), true); } else SetStaticTextCFString(ctl, CFSTR(""), true); cid.signature = 'Stat'; HIViewFindByID(root, cid, &ctl); if (npplayer[c].online) { if (npplayer[c].ready) ref = CFCopyLocalizedString(CFSTR("NPReady"), "NPReady"); else ref = CFCopyLocalizedString(CFSTR("NPConnecting"), "NPConnecting"); if (ref) { SetStaticTextCFString(ctl, ref, true); CFRelease(ref); } else SetStaticTextCFString(ctl, CFSTR("error"), true); } else SetStaticTextCFString(ctl, CFSTR(""), true); } switch (npserver.dialogprocess) { case kNPSDialogNone: break; case kNPSDialogInit: NPNotification(" kNPSDialogInit", -1); npserver.dialogprocess = kNPSDialogNone; NPServerBeginListenLoop(); break; case kNPSDialogProcess: NPNotification(" kNPSDialogProcess", -1); npserver.dialogprocess = kNPSDialogNone; NPServerEndListenLoop(); cid.id = 0; cid.signature = 'Chse'; HIViewFindByID(root, cid, &ctl); HIViewSetVisible(ctl, true); NPServerDetachProcessThread(); break; case kNPSDialogDone: NPNotification(" kNPSDialogDone", -1); npserver.dialogprocess = kNPSDialogNone; npserver.dialogcancel = false; QuitAppModalLoopForWindow(window); break; case kNPSDialogCancel: NPNotification(" kNPSDialogCancel", -1); npserver.dialogprocess = kNPSDialogNone; NPServerEndListenLoop(); npserver.dialogcancel = true; QuitAppModalLoopForWindow(window); break; } }
// Each time a new window is first opened, call this one time function to set up // the text view OSStatus SetUpTheTextView( WindowRef window ) { OSStatus status = noErr; HIViewRef textView = NULL; HIViewRef scrollView = NULL; HIViewRef scrollParentView = NULL; CMLTEViewData* mlteData = NULL; // Get the HITextView from the window status = GetTextViewFromWindow( window, textView ); require_action( textView != NULL, EXIT, status = paramErr ); // make a new custom C++ object to hold MLTE related data mlteData = new CMLTEViewData(); // DON'T FORGET TO DISPOSE THIS WHEN HITextView destructs!!! // put the custom object in the HITextView for this window // as a control property so that we can retrieve it later when we need it. status = TextViewStoreMLTEInstanceData( textView, mlteData ); require_action( textView != NULL, EXIT, status = paramErr ); // Now set the text view as we like it status = TextViewDefaultSettings( textView ); check_noerr( status ); status = TextViewAddActionNameMapper( textView ); check_noerr( status ); status = TextViewSetMargins( textView, 0 /*top*/, 0 /*left*/, 0 /*right*/ ); check_noerr( status ); // get fancy - try to add a picture behind the textView scrollView = HIViewGetSuperview( textView ); scrollParentView = HIViewGetSuperview( scrollView ); if( scrollParentView != NULL ) { HIViewRef imageViewRef = AddImage( scrollParentView ); if( imageViewRef != NULL ) { HIRect scrollFrame; HIViewGetFrame( scrollView, &scrollFrame ); HIViewSetFrame( imageViewRef, &scrollFrame ); status = HIViewSetZOrder( scrollView, kHIViewZOrderAbove, imageViewRef ); check_noerr( status ); HIViewSetVisible(imageViewRef, true); status = TextViewSetBGAlpha( textView, 0.75 ); check_noerr( status ); } } // register for menu handing status = TextViewInstallMenuHandlers( textView ); EXIT: return status; }