void* CContextOSX::CreateMainWindow(SSize /*Size*/, tint32 /*iWindowsOnly_MenuResourceID = -1*/, tint32 /*iWindowsOnly_IconResourceID = -1*/) { gpMainContext = this; IBNibRef sNibRef; OSStatus err; static const EventTypeSpec kAppEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kCoreEventClass, kAEOpenDocuments } }; // Create a Nib reference, passing the name of the nib file (without the .nib extension). // CreateNibReference only searches into the application bundle. err = CreateNibReference( CFSTR("main"), &sNibRef ); // require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib( sNibRef, CFSTR("MenuBar") ); // require_noerr( err, CantSetMenuBar ); // Install our handler for common commands on the application target // InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), // GetEventTypeCount( kAppEvents ), kAppEvents, // 0, NULL ); WindowRef gpWindow; err = CreateWindowFromNib( sNibRef, CFSTR("MainWindow"), &gpWindow ); // Position new windows in a staggered arrangement on the main screen RepositionWindow( gpWindow, NULL, kWindowCascadeOnMainScreen ); // The window was created hidden, so show it // ShowWindow( gpWindow ); ::InvalMenuBar(); ::DrawMenuBar(); // Install application event handler InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), GetEventTypeCount( kAppEvents ), kAppEvents, this, NULL ); InstallWindowEventHandler(gpWindow, GetWindowEventHandlerUPP(), GetEventTypeCount(kWindowEvents), kWindowEvents, gpWindow, NULL); return (void*)gpWindow; }
void MoveWindowPosition (WindowRef window, int which, Boolean resize) { if (savewindowpos) { MoveWindow(window, windowPos[which].h, windowPos[which].v, false); if (resize) { if ((windowSize[which].width > 0) && (windowSize[which].height > 0)) SizeWindow(window, (short) windowSize[which].width, (short) windowSize[which].height, false); } } else RepositionWindow(window, NULL, kWindowAlertPositionOnMainScreen); }
bool AquaGui::run() { double interval = _interval / 1000.0; OSStatus ret = InstallEventLoopTimer (GetMainEventLoop(), 0, interval, DoAdvanceMovie, this, _advance_timer); if (ret != noErr) { return false; } RepositionWindow(myWindow, NULL, kWindowCascadeOnMainScreen); SelectWindow(myWindow); ShowWindow(myWindow); SetWindowModified(myWindow, false); RunApplicationEventLoop(); return true; }
bool COSXScreen::leave() { if (m_isPrimary) { // warp to center warpCursor(m_xCenter, m_yCenter); // capture events HideWindow(m_hiddenWindow); ShowWindow(m_userInputWindow); RepositionWindow(m_userInputWindow, m_userInputWindow, kWindowCenterOnMainScreen); SetUserFocusWindow(m_userInputWindow); // The OS will coalesce some events if they are similar enough in a // short period of time this is bad for us since we need every event // to send it over to other machines. So disable it. SetMouseCoalescingEnabled(false, NULL); CGSetLocalEventsSuppressionInterval(0.0001); // disable global hotkeys //setGlobalHotKeysEnabled(false); } else { // hide cursor if (!m_cursorHidden) { // CGDisplayHideCursor(m_displayID); m_cursorHidden = true; } // warp the mouse to the cursor center fakeMouseMove(m_xCenter, m_yCenter); // FIXME -- prepare to show cursor if it moves // take keyboard focus // FIXME } // now off screen m_isOnScreen = false; return true; }
WindowRef PluginCarbonWindow::createTransparentWindow() { WindowRef window; OSStatus const createWindowError = CreateNewWindow(kUtilityWindowClass , kWindowNoShadowAttribute | kWindowStandardHandlerAttribute | kWindowNoTitleBarAttribute , &initialWindowBounds , &window); if (createWindowError != noErr) return 0; ASSERT(window); RepositionWindow(window, 0, kWindowCenterOnMainScreen); OSStatus const transparentError = MakeWindowTransparent(window); if (transparentError != noErr) { DisposeWindow(window); return 0; } ShowWindow(window); return window; }
Prefs_Window::Prefs_Window() { Carbon_Window::make( kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowStandardHandlerAttribute ); Carbon_Window::set_title( "Preferences" ); Row_Placer rows( window_width ); change_icon_box.make_checkbox( window(), rows.place( 20 ), "Update File Icon When Played", 'Updt' ); change_icon_box.set_value( prefs.change_icon ); set_control_help( change_icon_box, "Automatically changes icons of music files when they are played" ); disable_surround_box.make_checkbox( window(), rows.place( 20 ), "Disable SNES Surround", 'Updt' ); disable_surround_box.set_value( prefs.disable_surround ); set_control_help( disable_surround_box, "Disables surround effect used in some SNES soundtracks" ); SizeWindow( window(), window_width, rows.bounds().bottom + 4, true ); RepositionWindow( window(), NULL, kWindowCenterOnMainScreen ); Carbon_Window::restore_top_left( prefs.prefs_pos ); }
void CBidDialog::OnShowWindow(BOOL bShow, UINT nStatus) { CRect rect,parentRect; // if (bShow) { // showing RepositionWindow(); // if the neural net bidding engine is active, show the dialog // if (m_nBiddingEngine == 1) // pMAINFRAME->MakeDialogVisible(twNNetOutputDialog); } else { // if the neural net bidding engine is active, hide the dialog // if (m_nBiddingEngine == 1) // pMAINFRAME->HideDialog(twNNetOutputDialog); } // CDialog::OnShowWindow(bShow, nStatus); }
static void create_window(ws_state_list *p) { Rect screenRect, wRect; CGrafPtr screenPort; screenPort = CreateNewPort(); GetPortBounds(screenPort, &screenRect); DisposePort(screenPort); p->width = p->height = 500; p->swidth = screenRect.right - screenRect.left; p->sheight = screenRect.bottom - screenRect.top; p->window[0] = p->window[2] = 0.0; p->window[1] = p->window[3] = 1.0; p->viewport[0] = p->viewport[2] = 0; p->viewport[1] = (double)p->width * MWIDTH / p->swidth; p->viewport[3] = (double)p->height * MWIDTH / p->sheight; SetRect(&wRect, 0, 0, p->width, p->height); CreateNewWindow( kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &wRect, &p->win); SetWindowTitleWithCFString(p->win, CFSTR("GKS 5")); ChangeWindowAttributes(p->win, 0, kWindowCloseBoxAttribute | kWindowResizableAttribute); RepositionWindow(p->win, NULL, kWindowCascadeOnMainScreen); ShowWindow(p->win); GetWindowPortBounds(p->win, &wRect); ClipRect(&wRect); set_xform(); }
void OSXCarbonWindow::createNewWindow(unsigned int width, unsigned int height, String title) { if(!mWindow) { // Create the window rect in global coords ::Rect windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = width; windowRect.bottom = height; // Set the default attributes for the window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes; // default: "resize" windowAttrs |= kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowHideOnFullScreenAttribute | kWindowNoShadowAttribute; // Create the window CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWindow); // Color the window background black SetThemeWindowBackground(mWindow, kThemeBrushBlack, true); // Set the title of our window CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, title.c_str(), kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWindow, titleRef ); CFRelease(titleRef); mWindowTitle = title; // Center our window on the screen RepositionWindow( mWindow, NULL, kWindowCenterOnMainScreen ); // Get our view HIViewFindByID( HIViewGetRoot( mWindow ), kHIViewWindowContentID, &mView ); // Set up our UPP for Window Events EventTypeSpec eventSpecs[] = { {kEventClassWindow, kEventWindowActivated}, {kEventClassWindow, kEventWindowDeactivated}, {kEventClassWindow, kEventWindowShown}, {kEventClassWindow, kEventWindowHidden}, {kEventClassWindow, kEventWindowDragCompleted}, {kEventClassWindow, kEventWindowBoundsChanged}, {kEventClassWindow, kEventWindowExpanded}, {kEventClassWindow, kEventWindowCollapsed}, {kEventClassWindow, kEventWindowClosed}, {kEventClassWindow, kEventWindowClose} }; EventHandlerUPP handlerUPP = NewEventHandlerUPP(WindowEventUtilities::_CarbonWindowHandler); // Install the standard event handler for the window EventTargetRef target = GetWindowEventTarget(mWindow); InstallStandardEventHandler(target); // We also need to install the WindowEvent Handler, we pass along the window with our requests InstallEventHandler(target, handlerUPP, 10, eventSpecs, (void*)this, &mEventHandlerRef); } HIRect winBounds = CGRectZero; HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView)); HIViewGetBounds(root, &winBounds); HIRect viewBounds = CGRectZero; HIViewGetBounds(mView, &viewBounds); // Display and select our window if(!mHidden && mVisible) { ShowWindow(mWindow); SelectWindow(mWindow); } // Add our window to the window event listener class WindowEventUtilities::_addRenderWindow(this); }
//------------------------------------------------------------------------------------------------------- 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; }
/***************************************************** * * Do_NewWindowFromAPI(outWindow) * * Purpose: called to create a new window using only API calls fron MacWindows.h, Controls.h, and HIView.h * * Notes: called by Do_NewWindow() * * Inputs: outWindow - if not NULL, the address where to return the WindowRef * - if not NULL, the callee will have to ShowWindow * * Returns: OSStatus - error code (0 == no error) */ static OSStatus Do_NewWindowFromAPI(WindowRef * outWindow) { WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; OSStatus status; // Create a window Rect bounds = {0, 0, 360, 480}; status = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute | kWindowCompositingAttribute | kWindowMetalAttribute, &bounds, &aWindowRef); require_noerr(status, CreateNewWindow); require(aWindowRef != NULL, CreateNewWindow); status = RepositionWindow(aWindowRef, NULL, kWindowCascadeOnMainScreen); require_noerr(status, RepositionWindow); HIViewRef contentView; status = HIViewFindByID(HIViewGetRoot(aWindowRef), kHIViewWindowContentID, &contentView); require_noerr(status, HIViewFindByID); ControlRef aControlRef; Rect statBounds = {113, 20, 177, 460}; ControlFontStyleRec style = {kControlUseJustMask, 0, 0, 0, 0, teJustCenter}; status = CreateStaticTextControl(NULL, &statBounds, CFSTR("Click in the LittleArrows control above."), &style, &aControlRef); require_noerr(status, CreateStaticTextControl); HIViewID staticTextID = { 'STTC', 100 }; HIViewSetID(aControlRef, staticTextID); status = HIViewAddSubview(contentView, aControlRef); require_noerr(status, HIViewAddSubview); Rect littleArrowBounds = {51, 234, 73, 247}; status = CreateLittleArrowsControl(NULL, &littleArrowBounds, 0, 0, 10, 1, &aControlRef); require_noerr(status, CreateLittleArrowsControl); status = HIViewAddSubview(contentView, aControlRef); require_noerr(status, HIViewAddSubview); SetControlAction(aControlRef, LittleArrowsControlAction); EventTypeSpec eventTypeCVFC = {kEventClassControl, kEventControlValueFieldChanged}; status = HIViewInstallEventHandler(aControlRef, Handle_PostLittleArrowsClick, 1, &eventTypeCVFC, (void *)aControlRef, NULL); require_noerr(status, CantInstallEventHandler); Rect buttonBounds = {320, 390, 340, 460}; status = CreatePushButtonControl(NULL, &buttonBounds, CFSTR("OK"), &aControlRef); require_noerr(status, CreatePushButtonControl); status = SetControlCommandID(aControlRef, kHICommandOK); require_noerr(status, SetControlCommandID); status = HIViewAddSubview(contentView, aControlRef); require_noerr(status, HIViewAddSubview); status = SetWindowDefaultButton(aWindowRef, aControlRef); require_noerr(status, SetWindowDefaultButton); WindowDataPtr wdr = (WindowDataPtr)calloc(1, sizeof(WindowDataRec)); require(wdr != NULL, CantAllocateWindowData); SetWRefCon(aWindowRef, (long)wdr); theTitle = CFStringCreateWithFormat(NULL, NULL, CFSTR("LittleArrowsShowcase Window From API #%ld"), ++gWindowCount); require(theTitle != NULL, CFStringCreateWithFormat); status = SetWindowTitleWithCFString(aWindowRef, theTitle); require_noerr(status, SetWindowTitleWithCFString); EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)aWindowRef, NULL); require_noerr(status, CantInstallEventHandler); EventTypeSpec eventTypeWC = {kEventClassWindow, kEventWindowClosed}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowIsClosing, 1, &eventTypeWC, (void *)aWindowRef, NULL); require_noerr(status, CantInstallEventHandler); // The window was created hidden so show it if the outWindow parameter is NULL, // if it's not, it will be the responsibility of the caller to show it. if (outWindow == NULL) ShowWindow(aWindowRef); SetWindowModified(aWindowRef, false); CantInstallEventHandler: SetWindowTitleWithCFString: CFStringCreateWithFormat: if (theTitle != NULL) CFRelease(theTitle); CantAllocateWindowData: SetWindowDefaultButton: SetControlCommandID: CreatePushButtonControl: CreateLittleArrowsControl: HIViewAddSubview: CreateStaticTextControl: HIViewFindByID: RepositionWindow: CreateNewWindow: if (outWindow != NULL) *outWindow = aWindowRef; return status; } // Do_NewWindowFromAPI
int _glfwPlatformOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode, _GLFWhints* hints ) { OSStatus error; ProcessSerialNumber psn; unsigned int windowAttributes; // TO DO: Refactor this function! _glfwWin.WindowFunctions = ( _glfwWin.Fullscreen ? &_glfwMacFSWindowFunctions : &_glfwMacDWWindowFunctions ); // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( !_glfwWin.Fullscreen ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; if( hints->Stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, hints->AuxBuffers); _setAGLAttribute( AGL_RED_SIZE, redbits ); _setAGLAttribute( AGL_GREEN_SIZE, greenbits ); _setAGLAttribute( AGL_BLUE_SIZE, bluebits ); _setAGLAttribute( AGL_ALPHA_SIZE, alphabits ); _setAGLAttribute( AGL_DEPTH_SIZE, depthbits ); _setAGLAttribute( AGL_STENCIL_SIZE, stencilbits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, hints->AccumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, hints->AccumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, hints->AccumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, hints->AccumAlphaBits ); if( hints->Samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, hints->Samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( pixelFormat == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a pixel format\n" ); return GL_FALSE; } // store pixel format's values for _glfwPlatformGetWindowParam's use _getAGLAttribute( AGL_ACCELERATED, _glfwWin.Accelerated ); _getAGLAttribute( AGL_RED_SIZE, _glfwWin.RedBits ); _getAGLAttribute( AGL_GREEN_SIZE, _glfwWin.GreenBits ); _getAGLAttribute( AGL_BLUE_SIZE, _glfwWin.BlueBits ); _getAGLAttribute( AGL_ALPHA_SIZE, _glfwWin.AlphaBits ); _getAGLAttribute( AGL_DEPTH_SIZE, _glfwWin.DepthBits ); _getAGLAttribute( AGL_STENCIL_SIZE, _glfwWin.StencilBits ); _getAGLAttribute( AGL_ACCUM_RED_SIZE, _glfwWin.AccumRedBits ); _getAGLAttribute( AGL_ACCUM_GREEN_SIZE, _glfwWin.AccumGreenBits ); _getAGLAttribute( AGL_ACCUM_BLUE_SIZE, _glfwWin.AccumBlueBits ); _getAGLAttribute( AGL_ACCUM_ALPHA_SIZE, _glfwWin.AccumAlphaBits ); _getAGLAttribute( AGL_AUX_BUFFERS, _glfwWin.AuxBuffers ); _getAGLAttribute( AGL_STEREO, _glfwWin.Stereo ); _getAGLAttribute( AGL_SAMPLES_ARB, _glfwWin.Samples ); _glfwWin.RefreshRate = hints->RefreshRate; // create AGL context _glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL ); aglDestroyPixelFormat( pixelFormat ); if( _glfwWin.AGLContext == NULL ) { fprintf( stderr, "glfwOpenWindow failing because it can't create an OpenGL context\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if (_glfwLibrary.Unbundled) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't get its PSN\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } /* Keith Bauer 2007-07-12 - I don't believe this is desirable if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } */ } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute \ | kWindowCollapseBoxAttribute \ | kWindowStandardHandlerAttribute ); if( hints->WindowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.MacWindow ) ); if( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't create a window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler ); error = InstallWindowEventHandler( _glfwWin.MacWindow, _glfwWin.WindowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "glfwOpenWindow failing because it can't install window event handlers\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.MacWindow, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.AGLContext, GetWindowPort( _glfwWin.MacWindow ) ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't draw to the window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.AGLContext ) ) { fprintf( stderr, "glfwOpenWindow failing because it can't make the OpenGL context current\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // show window ShowWindow( _glfwWin.MacWindow ); return GL_TRUE; } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; CGLPixelFormatObj CGLpfObj; long numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; GLint rgbaAccumDepth = 0; int rgbChannelDepth = 0; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( hints->Stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( hints->Samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)hints->Samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( hints->AccumRedBits \ + hints->AccumGreenBits \ + hints->AccumBlueBits \ + hints->AccumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphabits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)depthbits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)stencilbits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)hints->AuxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &CGLpfObj, &numCGLvs ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( CGLpfObj, NULL, &_glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAColorSize, &rgbColorDepth ); if( rgbColorDepth == 24 || rgbColorDepth == 32 ) { rgbChannelDepth = 8; } if( rgbColorDepth == 16 ) { rgbChannelDepth = 5; } // get pixel depth of accumulator - I haven't got the slightest idea // how this number conforms to any other channel depth than 8 bits, // so this might end up giving completely knackered results... (void)CGLDescribePixelFormat( CGLpfObj, 0, kCGLPFAAccumSize, &rgbaAccumDepth ); if( rgbaAccumDepth == 32 ) { rgbaAccumDepth = 8; } // store values of pixel format for _glfwPlatformGetWindowParam's use _getCGLAttribute( kCGLPFAAccelerated, _glfwWin.Accelerated ); _getCGLAttribute( rgbChannelDepth, _glfwWin.RedBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.GreenBits ); _getCGLAttribute( rgbChannelDepth, _glfwWin.BlueBits ); _getCGLAttribute( kCGLPFAAlphaSize, _glfwWin.AlphaBits ); _getCGLAttribute( kCGLPFADepthSize, _glfwWin.DepthBits ); _getCGLAttribute( kCGLPFAStencilSize, _glfwWin.StencilBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumRedBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumGreenBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumBlueBits ); _getCGLAttribute( rgbaAccumDepth, _glfwWin.AccumAlphaBits ); _getCGLAttribute( kCGLPFAAuxBuffers, _glfwWin.AuxBuffers ); _getCGLAttribute( kCGLPFAStereo, _glfwWin.Stereo ); _glfwWin.RefreshRate = hints->RefreshRate; // destroy our pixel format (void)CGLDestroyPixelFormat( CGLpfObj ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, /* Check further to the right -> */ height, hints->RefreshRate, NULL, NULL ); if( optimalMode == NULL ) { return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.CGLContext ); if( cglErr != kCGLNoError ) { return GL_FALSE; } return GL_TRUE; } }
int _glfwPlatformOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode, int accumredbits, int accumgreenbits, int accumbluebits, int accumalphabits, int auxbuffers, int stereo, int refreshrate ) { OSStatus error; // TO DO: Refactor this function! _glfwWin.WindowFunctions = (mode == GLFW_FULLSCREEN ? &_glfwMacFSWindowFunctions : &_glfwMacDWWindowFunctions); // create pixel format attribute list GLint pixelFormatAttributes[256]; int numAttrs = 0; pixelFormatAttributes[numAttrs++] = AGL_RGBA; pixelFormatAttributes[numAttrs++] = AGL_DOUBLEBUFFER; if ( mode == GLFW_FULLSCREEN ) { pixelFormatAttributes[numAttrs++] = AGL_FULLSCREEN; } if ( stereo ) { pixelFormatAttributes[numAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, auxbuffers); _setAGLAttribute( AGL_RED_SIZE, redbits ); _setAGLAttribute( AGL_GREEN_SIZE, greenbits ); _setAGLAttribute( AGL_BLUE_SIZE, bluebits ); _setAGLAttribute( AGL_ALPHA_SIZE, alphabits ); _setAGLAttribute( AGL_DEPTH_SIZE, depthbits ); _setAGLAttribute( AGL_STENCIL_SIZE, stencilbits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, accumredbits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, accumgreenbits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, accumbluebits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, accumalphabits ); pixelFormatAttributes[numAttrs++] = AGL_NONE; // create pixel format. AGLDevice mainMonitor = GetMainDevice(); AGLPixelFormat pixelFormat = aglChoosePixelFormat( &mainMonitor, 1, pixelFormatAttributes ); if ( pixelFormat == NULL ) { return GL_FALSE; } // store pixel format's values for _glfwPlatformGetWindowParam's use _getAGLAttribute( AGL_ACCELERATED, _glfwWin.Accelerated ); _getAGLAttribute( AGL_RED_SIZE, _glfwWin.RedBits ); _getAGLAttribute( AGL_GREEN_SIZE, _glfwWin.GreenBits ); _getAGLAttribute( AGL_BLUE_SIZE, _glfwWin.BlueBits ); _getAGLAttribute( AGL_ALPHA_SIZE, _glfwWin.AlphaBits ); _getAGLAttribute( AGL_DEPTH_SIZE, _glfwWin.DepthBits ); _getAGLAttribute( AGL_STENCIL_SIZE, _glfwWin.StencilBits ); _getAGLAttribute( AGL_ACCUM_RED_SIZE, _glfwWin.AccumRedBits ); _getAGLAttribute( AGL_ACCUM_GREEN_SIZE, _glfwWin.AccumGreenBits ); _getAGLAttribute( AGL_ACCUM_BLUE_SIZE, _glfwWin.AccumBlueBits ); _getAGLAttribute( AGL_ACCUM_ALPHA_SIZE, _glfwWin.AccumAlphaBits ); _getAGLAttribute( AGL_AUX_BUFFERS, _glfwWin.AuxBuffers ); _getAGLAttribute( AGL_STEREO, _glfwWin.Stereo ); _glfwWin.RefreshRate = refreshrate; // create AGL context _glfwWin.AGLContext = aglCreateContext( pixelFormat, NULL ); aglDestroyPixelFormat( pixelFormat ); if ( _glfwWin.AGLContext == NULL ) { _glfwPlatformCloseWindow(); return GL_FALSE; } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; error = CreateNewWindow( kDocumentWindowClass, GLFW_WINDOW_ATTRIBUTES, &windowContentBounds, &( _glfwWin.MacWindow ) ); if ( ( error != noErr ) || ( _glfwWin.MacWindow == NULL ) ) { _glfwPlatformCloseWindow(); return GL_FALSE; } if ( !_glfwWin.Fullscreen ) { _glfwWin.WindowUPP = NewEventHandlerUPP( _glfwWindowEventHandler ); error = InstallWindowEventHandler( _glfwWin.MacWindow, _glfwWin.WindowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if ( error != noErr ) { _glfwPlatformCloseWindow(); return GL_FALSE; } } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.MacWindow, NULL, kWindowCenterOnMainScreen ); // TO DO: put this somewhere else; this is a bit too soon ShowWindow( _glfwWin.MacWindow ); // show window, attach OpenGL context, &c if ( mode == GLFW_FULLSCREEN ) { CGDisplayErr cgError; cgError = CGCaptureAllDisplays(); if ( cgError != CGDisplayNoErr ) { _glfwPlatformCloseWindow(); return GL_FALSE; } HideMenuBar(); // I have no idea if this will work at all, particularly on // multi-monitor systems. Might need to use CGL for full-screen // setup and AGL for windowed (ugh!). if ( !aglSetFullScreen( _glfwWin.AGLContext, width, height, refreshrate, 0 ) ) { _glfwPlatformCloseWindow(); return GL_FALSE; } } else { if ( !aglSetDrawable( _glfwWin.AGLContext, GetWindowPort( _glfwWin.MacWindow ) ) ) { _glfwPlatformCloseWindow(); return GL_FALSE; } } // Make OpenGL context current; if ( !aglSetCurrentContext( _glfwWin.AGLContext ) ) { _glfwPlatformCloseWindow(); return GL_FALSE; } return GL_TRUE; }
// -------------------------------------------------------------------------------------- void OpenPrefsWindow(void) { OSStatus error; SInt16 windowResourceID, visibleUserPaneResourceID, invisibleUserPaneResourceID, pixelDepth; WindowRef window; ControlRef containerControl, embeddedControl; short iconListBottom; Rect iconListRect; Boolean isColorDevice; ListHandle iconList; EventTypeSpec windowEvents[] = { {kEventClassWindow, kEventWindowActivated}, {kEventClassWindow, kEventWindowDeactivated}, {kEventClassWindow, kEventWindowHandleContentClick}, {kEventClassWindow, kEventWindowGetMinimumSize}, {kEventClassWindow, kEventWindowResizeCompleted}, {kEventClassWindow, kEventWindowClose}, {kEventClassWindow, kEventWindowDrawContent}, {kEventClassWindow, kEventWindowContextualMenuSelect}, {kEventClassControl, kEventControlClick}, {kEventClassMouse, kEventMouseWheelMoved}, {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent} }; if (!RunningInMacOSX()) { windowResourceID = rPrefsWindowPlatinum; visibleUserPaneResourceID = cPlatinumWindowUserPaneVisible; invisibleUserPaneResourceID = cPlatinumWindowUserPaneInvisible; gPrefsWindowHeight = kPrefsWindowPlatinumHeight; gPrefsWindowWidth = kPrefsWindowPlatinumWidth; gMinimumSpacing = kPlatinumMinimumSpacing; gWindowEdgeSpacing = kPlatinumWindowEdgeSpacing; } else { windowResourceID = rPrefsWindowAqua; visibleUserPaneResourceID = cAquaWindowUserPaneVisible; invisibleUserPaneResourceID = cAquaWindowUserPaneInvisible; gPrefsWindowHeight = kPrefsWindowAquaHeight; gPrefsWindowWidth = kPrefsWindowAquaWidth; gMinimumSpacing = kAquaMinimumSpacing; gWindowEdgeSpacing = kAquaWindowEdgeSpacing; } error = CreateWindowFromResource(windowResourceID, &window); if (error != noErr) ExitToShell(); RepositionWindow(window, NULL, kWindowCascadeOnMainScreen); // CreateWindowFromResource // doesn't call this for you like GetNewCWindow does #if TARGET_API_MAC_CARBON // we would just set the standard handler attribute in the Carbon // Platinum 'wind' resource but that makes it not work under CarbonLib for some reason ChangeWindowAttributes(window, kWindowStandardHandlerAttribute, kWindowNoAttributes); #endif SetPortWindowPort(window); SetThemeWindowBackground(window, kThemeBrushModelessDialogBackgroundActive, true); CreateRootControl(window, &containerControl); /* Get each user pane and embed each preference panel's controls (for the demonstration there is only some static text identifying each panel number). We could just as easily have used AutoEmbedControl but why make the system figure out which control to use as the embedder when we already know? */ containerControl = GetNewControl(visibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 1"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 2"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 3"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 4"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 5"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 6"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 7"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 8"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 7, "Panel 9"); containerControl = GetNewControl(invisibleUserPaneResourceID, window); embeddedControl = GetNewControl(cStaticText, window); EmbedControl(embeddedControl, containerControl); SetControlData(embeddedControl, kControlEntireControl, kControlStaticTextTextTag, 8, "Panel 10"); gPanelNumber = 1; GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice); // draw the list with a SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); // white background // get the bottom-most iconListBottom = gPrefsWindowHeight - gWindowEdgeSpacing; // coordinate we can use iconListBottom -= (gPrefsWindowHeight - gWindowEdgeSpacing - gWindowEdgeSpacing) % kCellHeight; // then subtract out the partial cell height that would // be drawn on the bottom so that it's not actually drawn SetRect(&iconListRect, gWindowEdgeSpacing, gWindowEdgeSpacing, gWindowEdgeSpacing + kListWidth, iconListBottom); iconList = createIconList(window, iconListRect); SetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), &iconList); #if TARGET_API_MAC_OS8 CalculateBalloonHelpRects(window); #else gWindowEventHandler = NewEventHandlerUPP(windowEventHandler); InstallWindowEventHandler(window, gWindowEventHandler, GetEventTypeCount(windowEvents), windowEvents, NULL, NULL); InstallPrefsWindowHelpTags(window); #endif DisableMenuItem(GetMenuRef(mDemonstration), iPrefsWindow); EnableMenuItem(GetMenuRef(mFile), iClose); ShowWindow(window); } // OpenPrefsWindow
int doMain (int argc, char **argv) { osx_AllowForeground(); // OSG init OSG::osgInit(argc, argv); // create the graph // beacon for camera and light OSG::NodeUnrecPtr b1n = OSG::Node::create(); OSG::GroupUnrecPtr b1 = OSG::Group::create(); b1n->setCore( b1 ); // transformation OSG::NodeUnrecPtr t1n = OSG::Node::create(); OSG::TransformUnrecPtr t1 = OSG::Transform::create(); t1n->setCore( t1 ); t1n->addChild( b1n ); cam_trans = t1; // light OSG::NodeUnrecPtr dlight = OSG::Node::create(); OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create(); dlight->setCore( dl ); dl->setAmbient( .0, .0, .0, 1 ); dl->setDiffuse( .8, .8, .8, .8 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); // root root = OSG::Node::create(); OSG::GroupUnrecPtr gr1 = OSG::Group::create(); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); // Load the file OSG::NodeUnrecPtr file = NULL; if ( argc > 1 ) file = OSG::SceneFileHandler::the()->read(argv[1]); if ( file == NULL ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = OSG::makeTorus( .5, 2, 16, 16 ); } OSG::Thread::getCurrentChangeList()->commitChanges(); file->updateVolume(); OSG::Vec3f min,max; file->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; dlight->addChild( file ); std::cerr << "Tree: " << std::endl; //root->dump(); // Camera cam = OSG::PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( OSG::osgDegree2Rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 100000 ); // Background OSG::SolidBackgroundUnrecPtr bkgnd = OSG::SolidBackground::create(); bkgnd->setColor(OSG::Color3f(0,0,1)); // Viewport vp = OSG::Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); // Action ract = OSG::RenderAction::create(); // tball OSG::Vec3f pos; pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; OSG::Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); tball.setMode( OSG::Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( OSG::Trackball::OSGFree ); tball.setTranslationScale(scale); tball.setRotationCenter(tCenter); // Carbon init // Create window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes | kWindowLiveResizeAttribute | kWindowStandardHandlerAttribute; Rect contentRect; SetRect(&contentRect, 0, 0, 300, 300); WindowRef window; CreateNewWindow(kDocumentWindowClass, windowAttrs, &contentRect, &window); SetWindowTitleWithCFString(window, CFSTR("testWindowCarbon")); // Install event handler EventHandlerUPP eventHandlerUPP = NewEventHandlerUPP(eventHandler); EventTypeSpec eventList[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseDragged }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged } }; InstallWindowEventHandler(window, eventHandlerUPP, GetEventTypeCount(eventList), eventList, /*this*/0, 0); // Initialize OpenGL GLint attribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_DEPTH_SIZE, 16, AGL_NONE }; AGLPixelFormat pixelFormat = aglChoosePixelFormat(0, 0, attribs); if (pixelFormat == 0) std::cerr << "Cannot choose pixel format" << std::endl; AGLContext context = aglCreateContext(pixelFormat, 0); aglDestroyPixelFormat(pixelFormat); if (context == 0) std::cerr << "Cannot create context" << std::endl; aglSetDrawable(context, GetWindowPort(window)); // Create OpenSG window win = OSG::CarbonWindow::create(); win->addPort( vp ); win->setContext ( context ); win->init(); win->resize( 300, 300 ); // Show window RepositionWindow(window, 0, kWindowCascadeOnMainScreen); ShowWindow(window); win->activate(); // do some OpenGL init. Will move into State Chunks later. glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); // Main loop ( event dispatching ) RunApplicationEventLoop(); // Cleanup aglDestroyContext(context); DisposeWindow(window); DisposeEventHandlerUPP(eventHandlerUPP); ract = NULL; win = NULL; root = NULL; file = NULL; vp = NULL; cam_trans = NULL; cam = NULL; return 0; }
void OSXCarbonWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height) { if (mIsFullScreen != fullScreen || width != mWidth || height != mHeight) { // Set the full screen flag mIsFullScreen = fullScreen; createAGLContext(mFSAA, mColourDepth); if (mIsFullScreen) { GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); CGLContextObj share = NULL; aglGetCGLContext(mAGLContext, (void**)&share); // Create the CGL context object if it doesn't already exist, sharing the AGL context. if(!mCGLContext) { void *cglPixFormat; aglGetCGLPixelFormat(mAGLPixelFormat, (void **)&cglPixFormat); mCGLContext = OGRE_NEW OSXCGLContext(mCGLContextObj, (CGLPixelFormatObj) cglPixFormat); } // Create the context, keeping the current colour depth and FSAA settings createCGLFullscreen(width, height, getColourDepth(), getFSAA(), share); rs->_switchContext(mContext); // Hide the Carbon window HideWindow(mWindow); // And tell the rendersystem to stop rendering to it too WindowEventUtilities::_removeRenderWindow(this); } else { // Create a new AGL context and pixel format if necessary createAGLContext(mFSAA, mColourDepth); // Create a window if we haven't already, existence check is done within the functions if(!mWindow) { if(mIsExternal) createWindowFromExternal(mView); else createNewWindow(width, height, mWindowTitle); } // Destroy the current CGL context, we will create a new one when/if we go back to full screen destroyCGLFullscreen(); // Set the drawable, and current context // If you do this last, there is a moment before the rendering window pops-up #if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 aglSetDrawable(mAGLContext, GetWindowPort(mWindow)); #else aglSetWindowRef(mAGLContext, mWindow); #endif aglSetCurrentContext(mAGLContext); if(!mCarbonContext) { mCarbonContext = OGRE_NEW OSXCarbonContext(mAGLContext, mAGLPixelFormat); } GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); mContext = mCarbonContext; rs->_switchContext(mContext); WindowEventUtilities::_addRenderWindow(this); ShowWindow(mWindow); SelectWindow(mWindow); RepositionWindow(mWindow, NULL, kWindowCenterOnMainScreen); } mWidth = width; mHeight = height; } }
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; }
static Rboolean Quartz_Open(NewDevDesc *dd, QuartzDesc *xd, char *dsp, double wid, double hgt, int bg) { OSStatus err; WindowRef devWindow = NULL; Rect devBounds, mainRect; Str255 Title; char buffer[250]; int devnum = devNumber((DevDesc *)dd); xd->windowWidth = wid*72; xd->windowHeight = hgt*72; xd->window = NULL; xd->context = NULL; xd->auxcontext = NULL; xd->bg = dd->startfill = bg; /* 0xffffffff; transparent */ dd->startcol = R_RGB(0, 0, 0); /* Create a new window with the specified size */ SetRect(&devBounds, 0, 0, xd->windowWidth, xd->windowHeight ) ; err = CreateNewWindow( kDocumentWindowClass, kWindowStandardHandlerAttribute|kWindowVerticalZoomAttribute | kWindowCollapseBoxAttribute|kWindowResizableAttribute | kWindowCloseBoxAttribute , & devBounds, & devWindow); SetWindowBounds(devWindow, kWindowContentRgn, &devBounds); mainRect = (*GetMainDevice()) -> gdRect; switch(xd->QuartzPos){ case kQuartzTopRight: /* Top Right */ RepositionWindow (devWindow, NULL, kWindowCascadeOnMainScreen); GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); devBounds.left = mainRect.right - devBounds.right + 1; devBounds.right = mainRect.right; SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); break; case kQuartzBottomRight: /* Bottom Right */ GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); devBounds.left = mainRect.right - devBounds.right + 1; devBounds.right = mainRect.right; devBounds.top = mainRect.bottom - devBounds.bottom + 1; devBounds.bottom = mainRect.bottom; SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); break; case kQuartzBottomLeft: /* Bottom Left */ GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); devBounds.top = mainRect.bottom - devBounds.bottom + 1; devBounds.bottom = mainRect.bottom; SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); break; case kQuartzCenter: /* Center */ RepositionWindow (devWindow, NULL, kWindowCenterOnMainScreen); break; case kQuartzTopLeft: /* TopLeft */ RepositionWindow (devWindow, NULL, kWindowCascadeOnMainScreen); break; default: break; } sprintf(buffer,"Quartz (%d) - Active",devnum+1); CopyCStringToPascal(buffer,Title); SetWTitle(devWindow, Title); ShowWindow(devWindow); err = InstallWindowEventHandler( devWindow, NewEventHandlerUPP(QuartzEventHandler), GetEventTypeCount(QuartzEvents), QuartzEvents, (void *)devWindow, NULL); if(err != noErr) return(0); xd->window = devWindow; xd->color = xd->fill = R_TRANWHITE; xd->resize = false; xd->lineType = 0; xd->lineWidth = 1; return TRUE; }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::create( const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams ) { bool hasDepthBuffer; String title = name; size_t fsaa_samples = 0; int left = 0; int top = 0; int depth = 32; if( miscParams ) { NameValuePairList::const_iterator opt = NULL; // Full screen anti aliasing opt = miscParams->find( "FSAA" ); if( opt != miscParams->end() ) fsaa_samples = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "left" ); if( opt != miscParams->end() ) left = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "top" ); if( opt != miscParams->end() ) top = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "title" ); if( opt != miscParams->end() ) title = opt->second; opt = miscParams->find( "depthBuffer" ); if( opt != miscParams->end() ) hasDepthBuffer = StringConverter::parseBool( opt->second ); opt = miscParams->find( "colourDepth" ); if( opt != miscParams->end() ) depth = StringConverter::parseUnsignedInt( opt->second ); } if(fullScreen) { GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext *mainContext = (OSXContext*)rs->_getMainContext(); CGLContextObj share = NULL; if(mainContext == 0) { share = NULL; } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* aglShare = static_cast<OSXCarbonContext*>(mainContext); aglGetCGLContext(aglShare->getContext(), &((void*)share)); } else if(mainContext->getContextType() == "CGL") { OSXCGLContext* cglShare = static_cast<OSXCGLContext*>(mainContext); share = cglShare->getContext(); } // create the context createCGLFullscreen(width, height, depth, fsaa_samples, share); } else { int i = 0; AGLPixelFormat pixelFormat; GLint attribs[ 20 ]; attribs[ i++ ] = AGL_NO_RECOVERY; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_ACCELERATED; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_RGBA; attribs[ i++ ] = AGL_DOUBLEBUFFER; attribs[ i++ ] = AGL_ALPHA_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_STENCIL_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_DEPTH_SIZE; attribs[ i++ ] = depth; if(fsaa_samples > 1) { attribs[ i++ ] = AGL_MULTISAMPLE; attribs[ i++ ] = 1; attribs[ i++ ] = AGL_SAMPLE_BUFFERS_ARB; attribs[ i++ ] = fsaa_samples; } attribs[ i++ ] = AGL_NONE; pixelFormat = aglChoosePixelFormat( NULL, 0, attribs ); // Create the AGLContext from our pixel format // Share it with main GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext* mainContext = static_cast<OSXContext*>( rs->_getMainContext() ); if(mainContext == 0) { mAGLContext = aglCreateContext(pixelFormat, NULL); } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* context = static_cast<OSXCarbonContext*>( rs->_getMainContext() ); AGLContext shared = context->getContext(); mAGLContext = aglCreateContext(pixelFormat, context->getContext()); } else { // If we do not have an AGL, we can not clone it using this window LogManager::getSingleton().logMessage( "Warning: You asked to create a second window, " "when the previous window was not of this type. OgreOSXCarbonWindow can only share " "with an AGL context."); } NameValuePairList::const_iterator opt = 0; if(miscParams) opt = miscParams->find("externalWindowHandle"); if(!miscParams || opt == miscParams->end()) { // create the window rect in global coords ::Rect windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = width; windowRect.bottom = height; // set the default attributes for the window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes; // default: "resize" if (miscParams) { opt = miscParams->find("border"); if( opt != miscParams->end() ) { String borderType = opt->second; if( borderType == "none" ) windowAttrs = kWindowNoTitleBarAttribute; else if( borderType == "fixed" ) windowAttrs = kWindowStandardFloatingAttributes; } } windowAttrs |= kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowHideOnFullScreenAttribute; // Create the window CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWindow); // Color the window background black SetThemeWindowBackground (mWindow, kThemeBrushBlack, true); // Set the title of our window CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, title.c_str(), kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWindow, titleRef ); // Center our window on the screen RepositionWindow( mWindow, NULL, kWindowCenterOnMainScreen ); // Get our view HIViewFindByID( HIViewGetRoot( mWindow ), kHIViewWindowContentID, &mView ); // Set up our UPP for Window Events EventTypeSpec eventSpecs[] = { {kEventClassWindow, kEventWindowActivated}, {kEventClassWindow, kEventWindowDeactivated}, {kEventClassWindow, kEventWindowShown}, {kEventClassWindow, kEventWindowHidden}, {kEventClassWindow, kEventWindowDragCompleted}, {kEventClassWindow, kEventWindowBoundsChanged}, {kEventClassWindow, kEventWindowExpanded}, {kEventClassWindow, kEventWindowCollapsed}, {kEventClassWindow, kEventWindowClosed}, {kEventClassWindow, kEventWindowClose} }; EventHandlerUPP handlerUPP = NewEventHandlerUPP(WindowEventUtilities::_CarbonWindowHandler); // Install the standard event handler for the window EventTargetRef target = GetWindowEventTarget(mWindow); InstallStandardEventHandler(target); // We also need to install the WindowEvent Handler, we pass along the window with our requests InstallEventHandler(target, handlerUPP, 10, eventSpecs, (void*)this, &mEventHandlerRef); // Display and select our window ShowWindow(mWindow); SelectWindow(mWindow); // Add our window to the window event listener class WindowEventUtilities::_addRenderWindow(this); } else { // TODO: The Contol is going to report the incorrect location with a // Metalic / Textured window. The default windows work just fine. // First get the HIViewRef / ControlRef mView = (HIViewRef)StringConverter::parseUnsignedLong(opt->second); mWindow = GetControlOwner(mView); // Lets try hiding the HIView //HIViewSetVisible(mView, false); // Get the rect bounds ::Rect ctrlBounds; GetControlBounds(mView, &ctrlBounds); GLint bufferRect[4]; bufferRect[0] = ctrlBounds.left; // left edge bufferRect[1] = ctrlBounds.bottom; // bottom edge bufferRect[2] = ctrlBounds.right - ctrlBounds.left; // width of buffer rect bufferRect[3] = ctrlBounds.bottom - ctrlBounds.top; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable (mAGLContext, AGL_BUFFER_RECT); mIsExternal = true; } // Set the drawable, and current context // If you do this last, there is a moment before the rendering window pops-up // This could go once inside each case above, before the window is displayed, // if desired. aglSetDrawable(mAGLContext, GetWindowPort(mWindow)); aglSetCurrentContext(mAGLContext); // Give a copy of our context to the render system mContext = new OSXCarbonContext(mAGLContext, pixelFormat); } mName = name; mWidth = width; mHeight = height; mActive = true; mClosed = false; mCreated = true; mIsFullScreen = fullScreen; }
int _glfwPlatformOpenWindow( int width, int height, const _GLFWwndconfig *wndconfig, const _GLFWfbconfig *fbconfig ) { OSStatus error; unsigned int windowAttributes; ProcessSerialNumber psn; // TODO: Break up this function! _glfwWin.windowUPP = NULL; _glfwWin.mouseUPP = NULL; _glfwWin.keyboardUPP = NULL; _glfwWin.commandUPP = NULL; _glfwWin.window = NULL; _glfwWin.aglContext = NULL; _glfwWin.aglPixelFormat = NULL; _glfwWin.cglContext = NULL; _glfwWin.cglPixelFormat = NULL; _glfwWin.refreshRate = wndconfig->refreshRate; // Fail if OpenGL 3.0 or above was requested if( wndconfig->glMajor > 2 ) { fprintf( stderr, "OpenGL 3.0+ is not yet supported on Mac OS X\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( _glfwLibrary.Unbundled ) { if( GetCurrentProcess( &psn ) != noErr ) { fprintf( stderr, "Failed to get the process serial number\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( TransformProcessType( &psn, kProcessTransformToForegroundApplication ) != noErr ) { fprintf( stderr, "Failed to become a foreground application\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } if( wndconfig->mode == GLFW_FULLSCREEN ) { if( SetFrontProcess( &psn ) != noErr ) { fprintf( stderr, "Failed to become the front process\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } } } if( !installEventHandlers() ) { fprintf( stderr, "Failed to install Carbon application event handlers\n" ); _glfwPlatformTerminate(); return GL_FALSE; } // Windowed or fullscreen; AGL or CGL? Quite the mess... // AGL appears to be the only choice for attaching OpenGL contexts to // Carbon windows, but it leaves the user no control over fullscreen // mode stretching. Solution: AGL for windowed, CGL for fullscreen. if( wndconfig->mode == GLFW_WINDOW ) { // create AGL pixel format attribute list GLint AGLpixelFormatAttributes[256]; int numAGLAttrs = 0; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_RGBA; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_DOUBLEBUFFER; AGLpixelFormatAttributes[numAGLAttrs++] = AGL_CLOSEST_POLICY; if( fbconfig->stereo ) { AGLpixelFormatAttributes[numAGLAttrs++] = AGL_STEREO; } _setAGLAttribute( AGL_AUX_BUFFERS, fbconfig->auxBuffers); _setAGLAttribute( AGL_RED_SIZE, fbconfig->redBits ); _setAGLAttribute( AGL_GREEN_SIZE, fbconfig->greenBits ); _setAGLAttribute( AGL_BLUE_SIZE, fbconfig->blueBits ); _setAGLAttribute( AGL_ALPHA_SIZE, fbconfig->alphaBits ); _setAGLAttribute( AGL_DEPTH_SIZE, fbconfig->depthBits ); _setAGLAttribute( AGL_STENCIL_SIZE, fbconfig->stencilBits ); _setAGLAttribute( AGL_ACCUM_RED_SIZE, fbconfig->accumRedBits ); _setAGLAttribute( AGL_ACCUM_GREEN_SIZE, fbconfig->accumGreenBits ); _setAGLAttribute( AGL_ACCUM_BLUE_SIZE, fbconfig->accumBlueBits ); _setAGLAttribute( AGL_ACCUM_ALPHA_SIZE, fbconfig->accumAlphaBits ); if( fbconfig->samples > 1 ) { _setAGLAttribute( AGL_SAMPLE_BUFFERS_ARB, 1 ); _setAGLAttribute( AGL_SAMPLES_ARB, fbconfig->samples ); AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NO_RECOVERY; } AGLpixelFormatAttributes[numAGLAttrs++] = AGL_NONE; // create pixel format descriptor AGLDevice mainMonitor = GetMainDevice(); _glfwWin.aglPixelFormat = aglChoosePixelFormat( &mainMonitor, 1, AGLpixelFormatAttributes ); if( _glfwWin.aglPixelFormat == NULL ) { fprintf( stderr, "Failed to choose AGL pixel format: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // create AGL context _glfwWin.aglContext = aglCreateContext( _glfwWin.aglPixelFormat, NULL ); if( _glfwWin.aglContext == NULL ) { fprintf( stderr, "Failed to create AGL context: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // create window Rect windowContentBounds; windowContentBounds.left = 0; windowContentBounds.top = 0; windowContentBounds.right = width; windowContentBounds.bottom = height; windowAttributes = ( kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute ); if( wndconfig->windowNoResize ) { windowAttributes |= kWindowLiveResizeAttribute; } else { windowAttributes |= ( kWindowFullZoomAttribute | kWindowResizableAttribute ); } error = CreateNewWindow( kDocumentWindowClass, windowAttributes, &windowContentBounds, &( _glfwWin.window ) ); if( ( error != noErr ) || ( _glfwWin.window == NULL ) ) { fprintf( stderr, "Failed to create Carbon window\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } _glfwWin.windowUPP = NewEventHandlerUPP( windowEventHandler ); error = InstallWindowEventHandler( _glfwWin.window, _glfwWin.windowUPP, GetEventTypeCount( GLFW_WINDOW_EVENT_TYPES ), GLFW_WINDOW_EVENT_TYPES, NULL, NULL ); if( error != noErr ) { fprintf( stderr, "Failed to install Carbon window event handler\n" ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Don't care if we fail here (void)SetWindowTitleWithCFString( _glfwWin.window, CFSTR( "GLFW Window" ) ); (void)RepositionWindow( _glfwWin.window, NULL, kWindowCenterOnMainScreen ); if( !aglSetDrawable( _glfwWin.aglContext, GetWindowPort( _glfwWin.window ) ) ) { fprintf( stderr, "Failed to set the AGL context as the Carbon window drawable: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // Make OpenGL context current if( !aglSetCurrentContext( _glfwWin.aglContext ) ) { fprintf( stderr, "Failed to make AGL context current: %s\n", aglErrorString( aglGetError() ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } ShowWindow( _glfwWin.window ); } else { CGDisplayErr cgErr; CGLError cglErr; CFDictionaryRef optimalMode; GLint numCGLvs = 0; CGLPixelFormatAttribute CGLpixelFormatAttributes[64]; int numCGLAttrs = 0; // variables for enumerating color depths GLint rgbColorDepth; // CGL pixel format attributes _setCGLAttribute( kCGLPFADisplayMask, CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ) ); if( fbconfig->stereo ) { CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAStereo; } if( fbconfig->samples > 1 ) { _setCGLAttribute( kCGLPFASamples, (CGLPixelFormatAttribute)fbconfig->samples ); _setCGLAttribute( kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1 ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; } CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAFullScreen; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFADoubleBuffer; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAAccelerated; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFANoRecovery; CGLpixelFormatAttributes[ numCGLAttrs++ ] = kCGLPFAMinimumPolicy; _setCGLAttribute( kCGLPFAAccumSize, (CGLPixelFormatAttribute)( fbconfig->accumRedBits \ + fbconfig->accumGreenBits \ + fbconfig->accumBlueBits \ + fbconfig->accumAlphaBits ) ); _setCGLAttribute( kCGLPFAAlphaSize, (CGLPixelFormatAttribute)fbconfig->alphaBits ); _setCGLAttribute( kCGLPFADepthSize, (CGLPixelFormatAttribute)fbconfig->depthBits ); _setCGLAttribute( kCGLPFAStencilSize, (CGLPixelFormatAttribute)fbconfig->stencilBits ); _setCGLAttribute( kCGLPFAAuxBuffers, (CGLPixelFormatAttribute)fbconfig->auxBuffers ); CGLpixelFormatAttributes[ numCGLAttrs++ ] = (CGLPixelFormatAttribute)NULL; // create a suitable pixel format with above attributes.. cglErr = CGLChoosePixelFormat( CGLpixelFormatAttributes, &_glfwWin.cglPixelFormat, &numCGLvs ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to choose CGL pixel format: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // ..and create a rendering context using that pixel format cglErr = CGLCreateContext( _glfwWin.cglPixelFormat, NULL, &_glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to create CGL context: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } // enumerate depth of RGB channels - unlike AGL, CGL works with // a single parameter reflecting the full depth of the frame buffer (void)CGLDescribePixelFormat( _glfwWin.cglPixelFormat, 0, kCGLPFAColorSize, &rgbColorDepth ); // capture the display for our application cgErr = CGCaptureAllDisplays(); if( cgErr != kCGErrorSuccess ) { fprintf( stderr, "Failed to capture Core Graphics displays\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // find closest matching NON-STRETCHED display mode.. optimalMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty( kCGDirectMainDisplay, rgbColorDepth, width, height, wndconfig->refreshRate, NULL, NULL ); if( optimalMode == NULL ) { fprintf( stderr, "Failed to retrieve Core Graphics display mode\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // ..and switch to that mode cgErr = CGDisplaySwitchToMode( kCGDirectMainDisplay, optimalMode ); if( cgErr != kCGErrorSuccess ) { fprintf( stderr, "Failed to switch to Core Graphics display mode\n"); _glfwPlatformCloseWindow(); return GL_FALSE; } // switch to our OpenGL context, and bring it up fullscreen cglErr = CGLSetCurrentContext( _glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to make CGL context current: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } cglErr = CGLSetFullScreen( _glfwWin.cglContext ); if( cglErr != kCGLNoError ) { fprintf( stderr, "Failed to set CGL fullscreen mode: %s\n", CGLErrorString( cglErr ) ); _glfwPlatformCloseWindow(); return GL_FALSE; } } return GL_TRUE; }
bool CSMNativeWindow::init(void) { osx_AllowForeground(); CSMDrawer *pDrawer = this->getParent(); CarbonWindowUnrecPtr pCarbonWindow = OSG::CarbonWindow::create(); AGLPixelFormat pixelFormat = NULL; std::vector<int> pfForm; pfForm.push_back(AGL_RGBA); pfForm.push_back(AGL_DEPTH_SIZE); pfForm.push_back(16); pfForm.push_back(AGL_DOUBLEBUFFER); if(_sfRequestSamples.getValue() > 0) { pfForm.push_back(AGL_SAMPLE_BUFFERS_ARB); pfForm.push_back(1); pfForm.push_back(AGL_SAMPLES_ARB); pfForm.push_back(_sfRequestSamples.getValue()); } if(this->requestStereoVisual() == true) { fprintf(stderr, "Choose stereo format\n"); pfForm.push_back(AGL_STEREO); } pfForm.push_back(AGL_NONE); pixelFormat = aglChoosePixelFormat(NULL, 0, &(pfForm.front())); fprintf(stderr, "Got pf : %p\n", pixelFormat); if(pixelFormat == NULL) { fprintf(stderr, "no RGB visual with depth buffer : :0.0"); exit(0); } _pContext = aglCreateContext(pixelFormat, 0); aglDestroyPixelFormat(pixelFormat); UInt32 uiWidth; UInt32 uiHeight; Int32 iXPos = 0; Int32 iYPos = 0; if(this->getXPos() > 0.f && this->getYPos() > 0.f) { iXPos = Int32(this->getXPos()); iYPos = Int32(this->getYPos()); } if(this->getXSize() >= 1.f) { uiWidth = UInt32(this->getXSize()); } else if(this->getXSize() <= 0.f) { uiWidth = 300; //DisplayWidth(_pDisplay, vi->screen); } else { uiWidth = 300; //UInt32(Real32(DisplayWidth(_pDisplay, vi->screen)) * // this->getXSize()); } if(this->getYSize() >= 1.f) { uiHeight = UInt32(this->getYSize()); } else if(this->getYSize() <= 0.f) { uiHeight = 300; //DisplayHeight(_pDisplay, vi->screen); } else { uiHeight = 300; //UInt32(Real32(DisplayHeight(_pDisplay, vi->screen)) * // this->getYSize()); } WindowAttributes windowAttrs = (kWindowStandardDocumentAttributes | kWindowLiveResizeAttribute | kWindowStandardHandlerAttribute ); Rect contentRect; SetRect(&contentRect, iXPos, iYPos, iXPos + uiWidth, iYPos + uiHeight); CreateNewWindow(kDocumentWindowClass, windowAttrs, &contentRect, &_pLocalWindow); SetWindowTitleWithCFString(_pLocalWindow, CFSTR("OpenSG - CSM")); // Install event handler _pEventHandler = NewEventHandlerUPP(eventHandler); EventTypeSpec eventList[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseDragged }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged } }; InstallWindowEventHandler(_pLocalWindow, _pEventHandler, GetEventTypeCount(eventList), eventList, this, 0); aglSetWindowRef(_pContext, _pLocalWindow); _pCarbWindow = pCarbonWindow; _pCarbWindow->setContext(_pContext); _pCarbWindow->init ( ); _pCarbWindow->resize ( uiWidth, uiHeight); std::string windowName(" OpenSG - CSM - "); _pCarbWindow->activate(); windowName += reinterpret_cast<const char *>(glGetString(GL_VERSION)); windowName += " - "; windowName += reinterpret_cast<const char *>(glGetString(GL_RENDERER)); _pCarbWindow->deactivate(); SetWTitle(_pLocalWindow, reinterpret_cast<const unsigned char *>(windowName.c_str())); // Show window RepositionWindow(_pLocalWindow, 0, kWindowCascadeOnMainScreen); ShowWindow (_pLocalWindow ); if(ComplexSceneManager::the() != NULL) ComplexSceneManager::the()->setMainloop( &CSMNativeWindow::carbonMainLoop); _pWindow = _pCarbWindow; _bRun = true; Inherited::init(); return true; }
// Window proc for dialog LRESULT CALLBACK DownloadDlgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: GetPrivateProfileString("Strings", "Status File Info", "", gszFileInfo, sizeof(gszFileInfo), szFileIniConfig); DisableSystemMenuItems(hWndDlg, FALSE); if(gbShowDownloadRetryMsg) SetDlgItemText(hWndDlg, IDC_MESSAGE0, diDownload.szMessageRetry0); else SetDlgItemText(hWndDlg, IDC_MESSAGE0, diDownload.szMessageDownload0); EnableWindow(GetDlgItem(hWndDlg, IDRESUME), FALSE); SetDlgItemText(hWndDlg, IDC_STATIC1, sgInstallGui.szStatus); SetDlgItemText(hWndDlg, IDC_STATIC2, sgInstallGui.szFile); SetDlgItemText(hWndDlg, IDC_STATIC4, sgInstallGui.szTo); SetDlgItemText(hWndDlg, IDC_STATIC3, sgInstallGui.szUrl); SetDlgItemText(hWndDlg, IDCANCEL, sgInstallGui.szCancel_); SetDlgItemText(hWndDlg, IDPAUSE, sgInstallGui.szPause_); SetDlgItemText(hWndDlg, IDRESUME, sgInstallGui.szResume_); SendDlgItemMessage (hWndDlg, IDC_STATIC1, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_STATIC2, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_STATIC3, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDCANCEL, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDPAUSE, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDRESUME, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_MESSAGE0, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_STATUS_STATUS, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_STATUS_FILE, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_STATUS_URL, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); SendDlgItemMessage (hWndDlg, IDC_STATUS_TO, WM_SETFONT, (WPARAM)sgInstallGui.definedFont, 0L); RepositionWindow(hWndDlg, BANNER_IMAGE_DOWNLOAD); ClosePreviousDialog(); return FALSE; case WM_SIZE: switch(wParam) { case SIZE_MINIMIZED: SetMinimizedDownloadTitle((int)GetPercentSoFar()); gbDlgDownloadMinimized = TRUE; gbDlgDownloadJustMinimized = TRUE; break; case SIZE_RESTORED: SetStatusUrl(); SetRestoredDownloadTitle(); gbDlgDownloadMinimized = FALSE; break; } return(FALSE); case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: if(AskCancelDlg(hWndDlg)) gdwDownloadDialogStatus = CS_CANCEL; break; case IDPAUSE: if(!gtiPaused.bTickStarted) { gtiPaused.dwTickBegin = GetTickCount(); gtiPaused.bTickStarted = TRUE; gtiPaused.bTickDownloadResumed = FALSE; } EnableWindow(GetDlgItem(hWndDlg, IDPAUSE), FALSE); EnableWindow(GetDlgItem(hWndDlg, IDRESUME), TRUE); gdwDownloadDialogStatus = CS_PAUSE; break; case IDRESUME: gtiPaused.dwTickEnd = GetTickCount(); gtiPaused.dwTickDif = GetTickDif(gtiPaused.dwTickEnd, gtiPaused.dwTickBegin); gtiPaused.bTickDownloadResumed = TRUE; EnableWindow(GetDlgItem(hWndDlg, IDRESUME), FALSE); EnableWindow(GetDlgItem(hWndDlg, IDPAUSE), TRUE); gdwDownloadDialogStatus = CS_NONE; break; default: break; } return(TRUE); } return(FALSE); // didn't handle the message }