void *OpenURL(char *url) { DWORD c,r; pthread_mutex_lock(&lock); // make sure only 1 thread at a time can do the following r=++req; // increment the request counter for this request pthread_mutex_unlock(&lock); RemoveEventLoopTimer(prebuftimer); // stop prebuffer monitoring BASS_StreamFree(chan); // close old stream PostCustomEvent('open',0,0); c=BASS_StreamCreateURL(url,0,BASS_STREAM_BLOCK|BASS_STREAM_STATUS|BASS_STREAM_AUTOFREE,StatusProc,0); free(url); // free temp URL buffer pthread_mutex_lock(&lock); if (r!=req) { // there is a newer request, discard this stream pthread_mutex_unlock(&lock); if (c) BASS_StreamFree(c); return; } chan=c; // this is now the current stream pthread_mutex_unlock(&lock); if (!chan) { PostCustomEvent('end ',0,0); // Error("Can't play the stream"); } else InstallEventLoopTimer(GetMainEventLoop(),kEventDurationNoWait,kEventDurationSecond/20,NewEventLoopTimerUPP(PrebufTimerProc),0,&prebuftimer); // start prebuffer monitoring return NULL; }
IGraphicsCarbon::~IGraphicsCarbon() { if (mTextEntryView) { RemoveEventHandler(mTextEntryHandler); mTextEntryHandler = 0; #if USE_MLTE TXNFocus(mTextEntryView, false); TXNClear(mTextEntryView); TXNDeleteObject(mTextEntryView); #else HIViewRemoveFromSuperview(mTextEntryView); #endif mTextEntryView = 0; mEdControl = 0; mEdParam = 0; } RemoveEventLoopTimer(mTimer); RemoveEventHandler(mControlHandler); RemoveEventHandler(mWindowHandler); mTimer = 0; mView = 0; // DisposeRgn(mRgn); }
void st_scheduler::stop_polling() { assert(m_pTimer != NULL); OSStatus lStatus = RemoveEventLoopTimer(m_pTimer); assert(lStatus == noErr); m_pTimer = NULL; }
bool QEventDispatcherMac::unregisterTimer(int id) { #ifndef QT_NO_DEBUG if (id < 1) { qWarning("QEventDispatcherUNIX::unregisterTimer: invalid argument"); return false; } else if (thread() != QThread::currentThread()) { qWarning("QObject::killTimer: timers cannot be stopped from another thread"); return false; } #endif Q_D(QEventDispatcherMac); if(!d->macTimerList || id <= 0) return false; // not init'd or invalid timer for (int i = 0; i < d->macTimerList->size(); ++i) { const MacTimerInfo &t = d->macTimerList->at(i); if (t.id == id) { if (t.mac_timer) { RemoveEventLoopTimer(t.mac_timer); if (t.pending) { EventComparatorUPP fnc = NewEventComparatorUPP(find_timer_event); FlushSpecificEventsFromQueue(GetMainEventQueue(), fnc, (void *)&t); DisposeEventComparatorUPP(fnc); } } else { d->zero_timer_count--; } d->macTimerList->removeAt(i); return true; } } return false; }
pascal void TimerCallback(EventLoopTimerRef timerRef, void *userData) #endif { IdleList *prev = &idleList; IdleList *item = prev->next; while(item) { if(item->remove) { prev->next = item->next; //remove item from list and close gap delete item; item = prev->next; if(prev == &idleList && prev->next == 0) //stop timer after last item removed { #if _WIN32 KillTimer(NULL, timer); #elif defined(__linux__) timer = 0; while (thread) usleep(1000); #else //OSX RemoveEventLoopTimer(timer); #endif timer = 0; } } else { item->effect->idle(); //call idle() for each item in list prev = item; item = item->next; } } }
pascal void PrebufTimerProc(EventLoopTimerRef inTimer, void *inUserData) { // monitor prebuffering progress DWORD progress=BASS_StreamGetFilePosition(chan,BASS_FILEPOS_BUFFER) *100/BASS_StreamGetFilePosition(chan,BASS_FILEPOS_END); // percentage of buffer filled if (progress>75 || !BASS_StreamGetFilePosition(chan,BASS_FILEPOS_CONNECTED)) { // over 75% full (or end of download) RemoveEventLoopTimer(prebuftimer); // finished prebuffering, stop monitoring { // get the broadcast name and URL const char *icy=BASS_ChannelGetTags(chan,BASS_TAG_ICY); if (!icy) icy=BASS_ChannelGetTags(chan,BASS_TAG_HTTP); // no ICY tags, try HTTP if (icy) { for (;*icy;icy+=strlen(icy)+1) { if (!strncasecmp(icy,"icy-name:",9)) SetStaticText(31,icy+9); if (!strncasecmp(icy,"icy-url:",8)) SetStaticText(32,icy+8); } } else SetStaticText(31,""); } // get the stream title and set sync for subsequent titles DoMeta(); BASS_ChannelSetSync(chan,BASS_SYNC_META,0,&MetaSync,0); // Shoutcast BASS_ChannelSetSync(chan,BASS_SYNC_OGG_CHANGE,0,&MetaSync,0); // Icecast/OGG // set sync for end of stream BASS_ChannelSetSync(chan,BASS_SYNC_END,0,&EndSync,0); // play it! BASS_ChannelPlay(chan,FALSE); } else { char text[20]; sprintf(text,"buffering... %d%%",progress); SetStaticText(31,text); } }
void cutils_test_refr_timer() { int i, fireTimes = 0; const int kNumRefr = 5; const EventTimerInterval kRefrTime = 0.5; // keep this shorter than 1 sec EventLoopTimerRef timer = NULL, rltimer = NULL; OSStatus err; EventLoopTimerUPP upp; LOG0("---- cutils_test_refr_timer ---------------------------------------"); // start timer with long fire delay refr_timer(&timer, &cutils_test_refr_timercb, 2, 0, &fireTimes); for (i = 0; i < kNumRefr; i++) { // refresh timer with shorter fire delay. This should just (1) override // the previous one-shot fire and (2) continuously prolong the // firing time making the timer fire only once refr_timer(&timer, &cutils_test_refr_timercb, kRefrTime, 0, &fireTimes); } // execution flow never blocks, so given the long fire delays our // fireTimes counter must still be 0 LOG("cutils_test_refr_timer:: fireTimes=%d", fireTimes); assert(fireTimes == 0); // install another timer just to get out of the run loop (see below): // we'll make it fire way after the sum of all previous fire delays upp = NewEventLoopTimerUPP(killrl_timercb); err = InstallEventLoopTimer(GetMainEventLoop(), kNumRefr * kRefrTime * 5, 0, upp, NULL, &rltimer); assert(err == 0); // we need to run the app event loop to actually let the `timer' work RunApplicationEventLoop(); LOG("cutils_test_refr_timer:: fireTimes=%d", fireTimes); assert(fireTimes == 1); err = RemoveEventLoopTimer(rltimer); assert(err == 0); err = RemoveEventLoopTimer(timer); assert(err == 0); }
int prHIDStopEventLoop(VMGlobals *g, int numArgsPushed) { if (gTimer) { RemoveEventLoopTimer(gTimer); gTimer = NULL; } return errNone; }
void wxCarbonTimerImpl::Stop() { if (m_info->m_timerRef) RemoveEventLoopTimer( m_info->m_timerRef ); if (m_info->m_proc) DisposeEventLoopTimerUPP( m_info->m_proc ); m_info->m_proc = NULL; m_info->m_timerRef = kInvalidID; }
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); }
/* * void nativeAbort(int handle) */ JNIEXPORT void JNICALL Java_com_scriptographer_ai_Timer_nativeAbort( JNIEnv *env, jobject obj, jint handle) { try { #ifdef WIN_ENV KillTimer(NULL, (UINT_PTR) handle); #endif // WIN_ENV #ifdef MAC_ENV RemoveEventLoopTimer((EventLoopTimerRef) handle); #endif // MAC_ENV } EXCEPTION_CONVERT(env); }
int R_carbonRemoveIdle(SEXP rep) { EventLoopTimerRef ref; OSStatus status; ref = getCarbonTimer(rep); status = RemoveEventLoopTimer(ref); return( status == noErr ? 1 : 0); }
void releaseHIDDevices () { if (gTimer) { RemoveEventLoopTimer(gTimer); gTimer = NULL; } HIDReleaseAllDeviceQueues(); HIDReleaseDeviceList(); gNumberOfHIDDevices = 0; }
AutoAwayPlugin::~AutoAwayPlugin() { #ifdef WIN32 _IdleUIGetLastInputTime = NULL; if (hLibUI) FreeLibrary(hLibUI); #endif #ifdef HAVE_CARBON_CARBNON_H RemoveEventLoopTimer(mTimerRef); #endif free_data(autoAwayData, &data); }
void EndHIDInput (void) { // remove timer if (gHIDTimer) RemoveEventLoopTimer (gHIDTimer); gHIDTimer = NULL; // dump array InitHIDInputArray (); // dump devices if (HIDHaveDeviceList()) HIDReleaseDeviceList (); }
myTMTaskPtr myTMRemove( myTMTaskPtr task) { if (!task) return NULL; if(task->primed) { RemoveEventLoopTimer(task->task); } delete task; return NULL; }
static pascal void timer_proc( EventLoopTimerRef inTimer, void *task) { myTMTaskPtr mytask=(myTMTaskPtr)task; mytask->primed=false; if ((*mytask->func)()) { mytask->primed=true; } else { RemoveEventLoopTimer(inTimer); } }
int prHIDRunEventLoop(VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 1; //class PyrSlot *b = g->sp; //num double eventtime; int err = slotDoubleVal(b, &eventtime); if (err) return err; if(gTimer) { RemoveEventLoopTimer(gTimer); gTimer = NULL; } InstallEventLoopTimer (GetCurrentEventLoop(), 0, (EventTimerInterval) eventtime, GetTimerUPP (), 0, &gTimer); //HIDSetQueueCallback(pCurrentHIDDevice, callback); return errNone; }
pxError pxWindow::setAnimationFPS(long fps) { if (theTimer) { RemoveEventLoopTimer(theTimer); } if (fps > 0) { EventLoopRef mainLoop; EventLoopTimerUPP timerUPP; mainLoop = GetMainEventLoop(); timerUPP = NewEventLoopTimerUPP (doPeriodicTask); InstallEventLoopTimer (mainLoop, 0, (1000/fps) * kEventDurationMillisecond, timerUPP, this, &theTimer); } return PX_OK; }
AutoAwayPlugin::~AutoAwayPlugin() { #ifdef WIN32 _IdleUIGetLastInputTime = NULL; if (hLibUI) FreeLibrary(hLibUI); #elif defined(HAVE_CARBON_CARBNON_H) && !defined(HAVE_X) RemoveEventLoopTimer(mTimerRef); #else // We load static Xss in our autoaway.so's process space, but the bastard // registers for shutdown in the XDisplay variable, so after autoaway.so // unloads, its code will still be called (as part of the XCloseDisplay). // As Xss offers no function to unregister itself, we'll have to be a little // messy here: QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it(*list); QWidget *w = it.current(); delete list; if (w != NULL) { Display* dpy = w->x11Display(); LockDisplay(dpy); // Original code from Xlib's ClDisplay.c _XExtension *ext, *prev_ext = NULL; for (ext = dpy->ext_procs; ext; prev_ext = ext, ext = ext->next) { if (ext->name && (strcmp(ext->name, ScreenSaverName) == 0)) { if (ext->close_display) (*ext->close_display)(dpy, &ext->codes); if (prev_ext) prev_ext->next = ext->next; else dpy->ext_procs = ext->next; Xfree((char*)ext); break; } } UnlockDisplay(dpy); } #endif free_data(autoAwayData, &data); }
void WindowBase::DisableEvent() { if( !mIsEventEnable ) return; OSXWindowData *windowData = (OSXWindowData *) GetWRefCon(mWindowHandle); if(windowData != NULL) { if( windowData->StartedApplicationLoop ) QuitApplicationEventLoop(); PRCORE_ASSERT_EXCEPTION( noErr != RemoveEventHandler (windowData->EventHandlerReference) ); PRCORE_ASSERT_EXCEPTION( noErr != RemoveEventLoopTimer (windowData->EventMainLoopReference) ); windowData->EventMainLoopReference = NULL; delete windowData; } mIsEventEnable=false; }
bool QEventDispatcherMac::unregisterTimers(QObject *obj) { #ifndef QT_NO_DEBUG if (!obj) { qWarning("QEventDispatcherUNIX::unregisterTimers: invalid argument"); return false; } else if (obj->thread() != thread() || thread() != QThread::currentThread()) { qWarning("QObject::killTimers: timers cannot be stopped from another thread"); return false; } #endif Q_D(QEventDispatcherMac); if(!d->macTimerList) // not initialized return false; MacTimerList removes; for (int i = 0; i < d->macTimerList->size(); ++i) { const MacTimerInfo &t = d->macTimerList->at(i); if (t.obj == obj) { if (t.mac_timer) { RemoveEventLoopTimer(t.mac_timer); if (t.pending) { EventComparatorUPP fnc = NewEventComparatorUPP(find_timer_event); FlushSpecificEventsFromQueue(GetMainEventQueue(), fnc, (void *)&t); DisposeEventComparatorUPP(fnc); } } else { d->zero_timer_count--; } removes += t; } } for (MacTimerList::Iterator it = removes.begin(); it != removes.end(); ++it) { for (int i = 0; i < d->macTimerList->size(); ++i) { const MacTimerInfo &info = d->macTimerList->at(i); if (info.id == (*it).id) d->macTimerList->removeAt(i); } } return true; }
void DoKillMovie() { if (mMovieController && mMovie) { OSErr err = noErr; /* stop movie */ MCDoAction(mMovieController, mcActionPlay, (void*)Long2Fix(0)); #ifdef __APPLE_CC__ err = QTUninstallNextTaskNeededSoonerCallback(mTaskNeededSoonerCallback,mMovieTimerState.theEventTimer); #else err = mQTUninstallNextTaskPtr(mTaskNeededSoonerCallback,mMovieTimerState.theEventTimer); #endif RemoveEventLoopTimer(mMovieTimerState.theEventTimer); /* remove draw complete proc. */ SetMovieDrawingCompleteProc(mMovie, movieDrawingCallWhenChanged, nil, NULL); DisposeMovieDrawingCompleteUPP(mMyDrawCompleteProc); DisposeMungData(); DisposeMovieController(mMovieController); DisposeMovie(mMovie); DisposeEventLoopTimerUPP(mEventLoopTimer); #ifdef __APPLE_CC__ DisposeQTNextTaskNeededSoonerCallbackUPP(mTaskNeededSoonerCallback); #else mDisposeQTNextTaskPtr(mTaskNeededSoonerCallback); #endif mMovieController = nil; mMovie = nil; } }
QEventDispatcherMac::~QEventDispatcherMac() { Q_D(QEventDispatcherMac); //timer cleanup d->zero_timer_count = 0; if(d->macTimerList) { for (int i = 0; i < d->macTimerList->size(); ++i) { const MacTimerInfo &t = d->macTimerList->at(i); if (t.mac_timer) { RemoveEventLoopTimer(t.mac_timer); if (t.pending) { EventComparatorUPP fnc = NewEventComparatorUPP(find_timer_event); FlushSpecificEventsFromQueue(GetMainEventQueue(), fnc, (void *)&t); DisposeEventComparatorUPP(fnc); } } } delete d->macTimerList; d->macTimerList = 0; } if(timerUPP) { DisposeEventLoopTimerUPP(timerUPP); timerUPP = 0; } // Remove CFSockets from the runloop. for (MacSocketHash::ConstIterator it = d->macSockets.constBegin(); it != d->macSockets.constEnd(); ++it) { MacSocketInfo *socketInfo = (*it); if (CFSocketIsValid(socketInfo->socket)) { qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop); CFRunLoopSourceInvalidate(socketInfo->runloop); CFRelease(socketInfo->runloop); CFSocketInvalidate(socketInfo->socket); CFRelease(socketInfo->socket); } } CFRunLoopRemoveSource(runLoopForCarbonLoop(GetMainEventLoop()), d->postedEventsSource, kCFRunLoopCommonModes); CFRelease(d->postedEventsSource); d->postedEventsSource = 0; }
//------------------------------------------------------------------------------------------------------- bool checkEffectEditor (AEffect* effect) { if ((effect->flags & effFlagsHasEditor) == 0) { printf ("This plug does not have an editor!\n"); return false; } #if _WIN32 theEffect = effect; MyDLGTEMPLATE t; t.style = WS_POPUPWINDOW|WS_DLGFRAME|DS_MODALFRAME|DS_CENTER; t.cx = 100; t.cy = 100; DialogBoxIndirectParam (GetModuleHandle (0), &t, 0, (DLGPROC)EditorProc, (LPARAM)effect); theEffect = 0; #elif _LINUX Display *dpy; Window win; XEvent e; char effect_name[256]; // arbitrary, vst GetEffectName is max 32 chars Atom wmDeleteMessage, prop_atom, val_atom; // create the window dpy = XOpenDisplay(NULL); win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 300, 300, 0, 0, 0); // we want an event when the window is being closed wmDeleteMessage = XInternAtom(dpy, "WM_DELETE_WINDOW", false); XSetWMProtocols(dpy, win, &wmDeleteMessage, 1); // Make the window a Dialog, maybe the window manager will place it centered prop_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); val_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); XChangeProperty(dpy, win, prop_atom, XA_ATOM, 32, PropModeReplace, (unsigned char *)&val_atom, 1); // prepare the plugin name in the title bar effect->dispatcher(effect, effGetEffectName, 0, 0, effect_name, 0); strcat(effect_name, " [minihost]"); XStoreName(dpy, win, effect_name); // Get and prepare editor size ERect* eRect = 0; printf ("HOST> Get editor rect..\n"); effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0); if (eRect) { int width = eRect->right - eRect->left; int height = eRect->bottom - eRect->top; printf("GetRect -> %d, %d\n", width, height); XResizeWindow(dpy, win, width, height); } // ? Is it correct to effEditGetRect above, before effEditOpen ? // Display the window, let the plugin populate it printf ("HOST> Open editor...\n"); XMapWindow(dpy, win); XFlush(dpy); effect->dispatcher (effect, effEditOpen, 0, (VstIntPtr) dpy, (void*) win, 0); // Needs adjusting according to events we want to handle in the loop below XSelectInput(dpy, win, SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | ExposureMask | KeyPressMask); while (true) { XNextEvent(dpy, &e); // handle events as needed if (e.type == ClientMessage && e.xclient.data.l[0] == wmDeleteMessage) { break; } } printf ("HOST> Close editor..\n"); effect->dispatcher (effect, effEditClose, 0, 0, 0, 0); XCloseDisplay(dpy); #elif TARGET_API_MAC_CARBON WindowRef window; Rect mRect = {0, 0, 300, 300}; OSStatus err = CreateNewWindow (kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCompositingAttribute | kWindowAsyncDragAttribute | kWindowStandardHandlerAttribute, &mRect, &window); if (err != noErr) { printf ("HOST> Could not create mac window !\n"); return false; } static EventTypeSpec eventTypes[] = { { kEventClassWindow, kEventWindowClose } }; InstallWindowEventHandler (window, windowHandler, GetEventTypeCount (eventTypes), eventTypes, window, NULL); printf ("HOST> Open editor...\n"); effect->dispatcher (effect, effEditOpen, 0, 0, window, 0); ERect* eRect = 0; printf ("HOST> Get editor rect..\n"); effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0); if (eRect) { int width = eRect->right - eRect->left; int height = eRect->bottom - eRect->top; Rect bounds; GetWindowBounds (window, kWindowContentRgn, &bounds); bounds.right = bounds.left + width; bounds.bottom = bounds.top + height; SetWindowBounds (window, kWindowContentRgn, &bounds); } RepositionWindow (window, NULL, kWindowCenterOnMainScreen); ShowWindow (window); EventLoopTimerRef idleEventLoopTimer; InstallEventLoopTimer (GetCurrentEventLoop (), kEventDurationSecond / 25., kEventDurationSecond / 25., idleTimerProc, effect, &idleEventLoopTimer); RunAppModalLoopForWindow (window); RemoveEventLoopTimer (idleEventLoopTimer); printf ("HOST> Close editor..\n"); effect->dispatcher (effect, effEditClose, 0, 0, 0, 0); ReleaseWindow (window); #endif return true; }
Kopete::IdlePlatform::~IdlePlatform() { RemoveEventLoopTimer( d->mTimerRef ); delete d; }
AquaGui::~AquaGui() { if (_advance_timer) { RemoveEventLoopTimer(*_advance_timer); } }
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); } }
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); }
/*----------------------------------------------------------------------------------------------------------*/ pascal OSStatus ScrollingTextViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { OSStatus result = eventNotHandledErr; ScrollingTextBoxData* myData = (ScrollingTextBoxData*)inRefcon; switch (GetEventClass(inEvent)) { case kEventClassHIObject: switch (GetEventKind(inEvent)) { case kEventHIObjectConstruct: { // allocate some instance data myData = (ScrollingTextBoxData*) calloc(1, sizeof(ScrollingTextBoxData)); // get our superclass instance HIViewRef epView; GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(epView), NULL, &epView); // remember our superclass in our instance data and initialize other fields myData->view = epView; // set the control ID so that we can find it later with HIViewFindByID result = SetControlID(myData->view, &kScrollingTextBoxViewID); // store our instance data into the event result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData); break; } case kEventHIObjectDestruct: { if (myData->theTimer != NULL) RemoveEventLoopTimer(myData->theTimer); CFRelease(myData->theText); free(myData); result = noErr; break; } case kEventHIObjectInitialize: { // always begin kEventHIObjectInitialize by calling through to the previous handler result = CallNextEventHandler(inCaller, inEvent); // if that succeeded, do our own initialization if (result == noErr) { GetEventParameter(inEvent, kEventParamScrollingText, typeCFStringRef, NULL, sizeof(myData->theText), NULL, &myData->theText); CFRetain(myData->theText); GetEventParameter(inEvent, kEventParamAutoScroll, typeBoolean, NULL, sizeof(myData->autoScroll), NULL, &myData->autoScroll); GetEventParameter(inEvent, kEventParamDelayBeforeAutoScroll, typeUInt32, NULL, sizeof(myData->delayBeforeAutoScroll), NULL, &myData->delayBeforeAutoScroll); GetEventParameter(inEvent, kEventParamDelayBetweenAutoScroll, typeUInt32, NULL, sizeof(myData->delayBetweenAutoScroll), NULL, &myData->delayBetweenAutoScroll); GetEventParameter(inEvent, kEventParamAutoScrollAmount, typeSInt16, NULL, sizeof(myData->autoScrollAmount), NULL, &myData->autoScrollAmount); myData->theTimer = NULL; } break; } default: break; } break; case kEventClassScrollable: switch (GetEventKind(inEvent)) { case kEventScrollableGetInfo: { // we're being asked to return information about the scrolled view that we set as Event Parameters HISize imageSize = {50.0, myData->height}; SetEventParameter(inEvent, kEventParamImageSize, typeHISize, sizeof(imageSize), &imageSize); HISize lineSize = {50.0, 20.0}; SetEventParameter(inEvent, kEventParamLineSize, typeHISize, sizeof(lineSize), &lineSize); HIRect bounds; HIViewGetBounds(myData->view, &bounds); SetEventParameter(inEvent, kEventParamViewSize, typeHISize, sizeof(bounds.size), &bounds.size); SetEventParameter(inEvent, kEventParamOrigin, typeHIPoint, sizeof(myData->originPoint), &myData->originPoint); result = noErr; break; } case kEventScrollableScrollTo: { // we're being asked to scroll, we just do a sanity check and ask for a redraw HIPoint where; GetEventParameter(inEvent, kEventParamOrigin, typeHIPoint, NULL, sizeof(where), NULL, &where); HIViewSetNeedsDisplay(myData->view, true); myData->originPoint.y = (where.y < 0.0)?0.0:where.y; HIViewSetBoundsOrigin(myData->view, 0, myData->originPoint.y); break; } default: break; } break; case kEventClassControl: switch (GetEventKind(inEvent)) { // sets the feature of the view. case kEventControlInitialize: { result = CallNextEventHandler(inCaller, inEvent); if (result != noErr) break; UInt32 features = 0; result = GetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, NULL, sizeof(features), NULL, &features); if (result == noErr) features |= kControlSupportsEmbedding; else features = kControlSupportsEmbedding; result = SetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, sizeof features, &features); break; } // Our parent view just changed dimensions, so we determined our new height. case kEventControlSetData: CFRelease(myData->theText); CFStringRef *p; GetEventParameter(inEvent, kEventParamControlDataBuffer, typePtr, NULL, sizeof(p), NULL, &p); myData->theText = *p; CFRetain(myData->theText); // fallthrough case kEventControlBoundsChanged: { HIRect bounds; HIViewGetBounds(myData->view, &bounds); // // If we're building on Panther (or later) then HIThemeGetTextDimensions is available, else we use GetThemeTextDimensions // #if PANTHER_BUILD // // Furthermore, if we're running on Panther then we can call HIThemeGetTextDimensions else we call GetThemeTextDimensions // if (GetHIToolboxVersion() >= Panther_HIToolbox_Version) { HIThemeTextInfo textInfo = {0, kThemeStateActive, kScrollingTextBoxFontID, kHIThemeTextHorizontalFlushLeft, kHIThemeTextVerticalFlushTop, kHIThemeTextBoxOptionStronglyVertical, kHIThemeTextTruncationNone, 0, false}; HIThemeGetTextDimensions(myData->theText, bounds.size.width - kMargin - kMargin, &textInfo, NULL, &myData->height, NULL); } else #endif { Point pointBounds; pointBounds.h = (int)(bounds.size.width - kMargin - kMargin); GetThemeTextDimensions(myData->theText, kScrollingTextBoxFontID, kThemeStateActive, true, &pointBounds, NULL); myData->height = pointBounds.v; } myData->height += 2.0 * kMargin; HIViewSetNeedsDisplay(myData->view, true); result = eventNotHandledErr; break; } // Draw the view. case kEventControlDraw: { CGContextRef context; result = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context); HIRect bounds; HIViewGetBounds(myData->view, &bounds); CGContextSaveGState(context); CGAffineTransform transform = CGAffineTransformIdentity; // adjust the transform so the text doesn't draw upside down transform = CGAffineTransformScale(transform, 1, -1); CGContextSetTextMatrix(context, transform); // now that the proper parameters and configurations have been dealt with, let's draw result = ScrollingTextBoxDraw(context, &bounds, myData); CGContextRestoreGState(context); if (myData->autoScroll) CGContextStrokeRect(context, bounds); // we postpone starting the autoscroll timer until after we do our first drawing if ( (myData->autoScroll) && (myData->theTimer == NULL) ) InstallEventLoopTimer(GetCurrentEventLoop(), TicksToEventTime(myData->delayBeforeAutoScroll), TicksToEventTime(myData->delayBetweenAutoScroll), myScrollingTextTimeProc, myData, &myData->theTimer); result = noErr; break; } default: break; } break; default: break; } return result; }