bool QuartzWindow::open( uint32 /* WindowClass */ wc, int* /* WindowAttributes */ attrs, int left, int top, int right, int bottom, const char* title, const char* font_name, int font_size ) { HIRect bounds = (HIRect) CGRectMake(left, top, right, bottom); OSStatus err = HIWindowCreate(wc, attrs, NULL, kHICoordSpace72DPIGlobal, &bounds, &_quartz_win); if (err != noErr) return false; SetWRefCon(my_window(), (int32)this); CFStringRef cftitle = CFStringCreateWithCString(NULL, title, kCFStringEncodingMacRoman); SetWindowTitleWithCFString(my_window(), cftitle); CFRelease(cftitle); WindowSet::add_window(my_window()); _is_open = true; init_colors(); init_events(); return true; }
bool setPlayerWinTitle(CFStringRef sTitle) { CFMutableStringRef sFinalStr = NULL; OSStatus iErr = noErr; if (NULL == (sFinalStr = CFStringCreateMutableCopy(NULL, 8 + CFStringGetLength(sTitle), CFSTR("Frogg - ")))) { fprintf(stderr, "setPlayerWinTitle() - CFStringCreateMutableCopy() failed!\n"); return false; } else { CFStringAppend(sFinalStr, sTitle); if (noErr != (iErr = SetWindowTitleWithCFString(g_refPlayerWin, sFinalStr))) { CFRelease(sFinalStr); fprintf(stderr, "setPlayerWinTitle() - SetWindowTitleWithCFString() failed, returning %lu!\n", (unsigned long) iErr); return false; } CFRelease(sFinalStr); return true; } }
bool AquaGui::createWindow(const char* title, int width, int height) { CFStringRef windowTitle = NULL; OSStatus result; Rect theBounds = {0, 0, 0, 0}; EventTypeSpec eventType; // Specifier for event type EventHandlerUPP handlerUPP; // Pointer to event handler routine _width = width; _height = height; SetRect(&theBounds, 0, 0, width, height); OSStatus status = CreateNewWindow ( kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &theBounds, &myWindow); windowTitle = CFStringCreateWithCString(NULL, title, NULL); result = SetWindowTitleWithCFString(myWindow, windowTitle); if(windowTitle != NULL)CFRelease(windowTitle); createMenu(); eventType.eventClass = kEventClassWindow; // Set event class eventType.eventKind = kEventWindowClose; // Set event kind handlerUPP = NewEventHandlerUPP(DoWindowClose); // Point to handler InstallWindowEventHandler (myWindow, handlerUPP, // Install handler 1, &eventType, NULL, NULL); assert(_glue.prepDrawingArea(_width, _height, GetWindowPort(myWindow))); return true; }
//------------------------------------------------------------------------ void platform_support::caption(const wchar_t* cap) { strcpy(m_caption, cap); if(m_specific->m_window) { SetWindowTitleWithCFString (m_specific->m_window, CFStringCreateWithCStringNoCopy (nil, cap, kCFStringEncodingASCII, nil)); } }
void OSXWindowImpl::setTitle(const char* text) { CFStringRef s = CFStringCreateWithCString( kCFAllocatorDefault , text , kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWindowRef, s ); }
void _glfwMacDWSetWindowTitle( const char *title ) { CFStringRef windowTitle = CFStringCreateWithCString( kCFAllocatorDefault, title, kCFStringEncodingISOLatin1 ); // Don't care if we fail (void)SetWindowTitleWithCFString( _glfwWin.MacWindow, windowTitle ); CFRelease( windowTitle ); }
bool Sys_CreateWindow(const char *title, unsigned int w, unsigned int h, bool fs) { OSErr result; ProcessSerialNumber psn; windowRect.top = 100; windowRect.left = 100; windowRect.bottom = windowRect.top + h; windowRect.right = windowRect.left + w; g_Window.height = h; g_Window.width = w; g_Window.fs = fs; result = CreateNewWindow(kDocumentWindowClass, (kWindowStandardDocumentAttributes | kWindowInWindowMenuAttribute | kWindowStandardHandlerAttribute) & ~kWindowResizableAttribute, &windowRect, &g_Window.window); if (result != noErr) return false; SetWindowTitleWithCFString( g_Window.window, CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()) ); result = GetCurrentProcess(&psn); if (result == noErr) { TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); } ShowWindow(g_Window.window); SelectWindow(g_Window.window); g_Window.glctx = createContext(g_Window.window); if (!g_Window.glctx) return false; /* static EventTypeSpec suspendResume[2] = {{kEventClassApplication, kEventAppActivated}, {kEventClassApplication, kEventAppDeactivated}}; InstallApplicationEventHandler(NewEventHandlerUPP(suspendResumeHandler), 2, suspendResume, &g_Window.window, NULL); */ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(quitEventHandler), 0, false); return true; }
int ioSetTitleOfWindow(int windowIndex, char * newTitle, int sizeOfTitle) { char string[256]; if (sizeOfTitle > 255) return -1; memcpy(string,newTitle,sizeOfTitle); string[sizeOfTitle] = 0x00; CFStringRef windowTitleCFString = CFStringCreateWithCString (nil,string,kCFStringEncodingUTF8); SetWindowTitleWithCFString (windowHandleFromIndex(windowIndex),windowTitleCFString); CFRelease(windowTitleCFString); return 1; }
//--------------------------------------------------------------------- // Sets up the window's title and proxy icon based on the given file. // void SetWindowTitleAndProxyFromCFURL(WindowRef window, CFURLRef file) { CFStringRef title; FSRef fileAsFSRef; require( (CFURLGetFSRef(file, &fileAsFSRef) != false), CantGetFSRef ); verify_noerr( HIWindowSetProxyFSRef(window, &fileAsFSRef) ); title = CFURLCopyLastPathComponent(file); verify_noerr( SetWindowTitleWithCFString(window, title) ); CFRelease(title); CantGetFSRef: return; }
void _glfwPlatformSetWindowTitle( const char *title ) { CFStringRef windowTitle; if( !_glfwWin.fullscreen ) { windowTitle = CFStringCreateWithCString( kCFAllocatorDefault, title, kCFStringEncodingISOLatin1 ); (void)SetWindowTitleWithCFString( _glfwWin.window, windowTitle ); CFRelease( windowTitle ); } }
void cv::setWindowTitle(const String& winname, const String& title) { CvWindow* window = icvFindWindowByName(winname.c_str()); if (!window) { namedWindow(winname); window = icvFindWindowByName(winname.c_str()); } if (!window) CV_Error(Error::StsNullPtr, "NULL window"); if (noErr != SetWindowTitleWithCFString(window->window, CFStringCreateWithCString(NULL, title.c_str(), kCFStringEncodingASCII))) CV_Error_(Error::StsError, ("Failed to set \"%s\" window title to \"%s\"", winname.c_str(), title.c_str())); }
OSStatus DisplayAlert(CFStringRef error, CFStringRef explanation, OSStatus status) { DialogRef dialog; if (status == 0) CreateStandardAlert(kAlertStopAlert, error, explanation, NULL, &dialog); else { CFStringRef exp; if (status > 0) { char s[8]; CFStringRef stat = UTCreateStringForOSType(status); CFStringGetCString(stat, s, sizeof(s), kCFStringEncodingMacRoman); CFRelease(stat); exp = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s: '%s' (0x%x)"), CFStringGetCStringPtr(explanation, kCFStringEncodingMacRoman), s, status); } else { exp = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s: %d (0x%x)"), CFStringGetCStringPtr(explanation, kCFStringEncodingMacRoman), status, status); } CreateStandardAlert(kAlertStopAlert, error, exp, NULL, &dialog); } SetWindowTitleWithCFString(GetDialogWindow(dialog), CFSTR("Accordion")); RunStandardAlert(dialog, NULL, NULL); return noErr; }
//--------------------------------------------------------------------- // Creates one of our simple document windows and returns a ref to it. // WindowRef MyCreateNewDocumentWindow(void) { IBNibRef nib; WindowRef window = NULL; OSStatus status; // Create one of our special main document windows status = CreateNibReference(CFSTR("main"), &nib); require_noerr( status, CantGetNIBRef ); status = CreateWindowFromNib(nib, CFSTR("MainDocumentWindow"), &window); require_noerr( status, CantCreateWindow ); // Set its default options status = MySetTextViewOptions(GetTextViewFromWindow(window)); check_noerr( status ); // Make the window transparent status = MakeWindowTransparent(window); check_noerr( status ); // Make the TextView partially transparent status = TextViewSetAlpha(GetTextViewFromWindow(window), 0.25); check_noerr( status ); // Initialize the window title and proxy icon status = SetWindowTitleWithCFString(window, CFSTR("Untitled")); check_noerr( status ); status = SetWindowProxyCreatorAndType(window, kUnknownType, kUnknownType, kOnSystemDisk); check_noerr( status ); // Show the window ShowWindow(window); // Cleanup CantGetViewRef: CantCreateWindow: DisposeNibReference(nib); CantGetNIBRef: return window; }
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::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, 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 main(int argc, char **argv) { // We assume that all the logs we're looking for reside on the current drive gDirUtilp->initAppDirs("SecondLife"); LLError::initForApplication( gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "")); // Rename current log file to ".old" std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "updater.log.old"); std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "updater.log"); LLFile::rename(log_file.c_str(), old_log_file.c_str()); // Set the log file to updater.log LLError::logToFile(log_file); ///////////////////////////////////////// // // Process command line arguments // gUpdateURL = NULL; gProductName = NULL; gBundleID = NULL; gDmgFile = NULL; gMarkerPath = NULL; parse_args(argc, argv); if ((gUpdateURL == NULL) && (gDmgFile == NULL)) { llinfos << "Usage: mac_updater -url <url> | -dmg <dmg file> [-name <product_name>] [-program <program_name>]" << llendl; exit(1); } else { llinfos << "Update url is: " << gUpdateURL << llendl; if (gProductName) { llinfos << "Product name is: " << gProductName << llendl; } else { gProductName = "Second Life"; } if (gBundleID) { llinfos << "Bundle ID is: " << gBundleID << llendl; } else { gBundleID = "com.secondlife.indra.viewer"; } } llinfos << "Starting " << gProductName << " Updater" << llendl; // Real UI... OSStatus err; IBNibRef nib = NULL; err = CreateNibReference(CFSTR("AutoUpdater"), &nib); char windowTitle[MAX_PATH]; /* Flawfinder: ignore */ snprintf(windowTitle, sizeof(windowTitle), "%s Updater", gProductName); CFStringRef windowTitleRef = NULL; windowTitleRef = CFStringCreateWithCString(NULL, windowTitle, kCFStringEncodingUTF8); if(err == noErr) { err = CreateWindowFromNib(nib, CFSTR("Updater"), &gWindow); } if (err == noErr) { err = SetWindowTitleWithCFString(gWindow, windowTitleRef); } CFRelease(windowTitleRef); if(err == noErr) { // Set up an event handler for the window. EventTypeSpec handlerEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCustom, kEventCustomProgress }, { kEventClassCustom, kEventCustomDone } }; InstallStandardEventHandler(GetWindowEventTarget(gWindow)); InstallWindowEventHandler( gWindow, NewEventHandlerUPP(dialogHandler), GetEventTypeCount (handlerEvents), handlerEvents, 0, &gEventHandler); } if(err == noErr) { ShowWindow(gWindow); SelectWindow(gWindow); } if(err == noErr) { pthread_create(&updatethread, NULL, &updatethreadproc, NULL); } if(err == noErr) { RunAppModalLoopForWindow(gWindow); } void *threadresult; pthread_join(updatethread, &threadresult); if(!gCancelled && (gFailure != noErr)) { // Something went wrong. Since we always just tell the user to download a new version, we don't really care what. AlertStdCFStringAlertParamRec params; SInt16 retval_mac = 1; DialogRef alert = NULL; OSStatus err; params.version = kStdCFStringAlertVersionOne; params.movable = false; params.helpButton = false; params.defaultText = (CFStringRef)kAlertDefaultOKText; params.cancelText = 0; params.otherText = 0; params.defaultButton = 1; params.cancelButton = 0; params.position = kWindowDefaultPosition; params.flags = 0; err = CreateStandardAlert( kAlertStopAlert, CFSTR("Error"), CFSTR("An error occurred while updating Second Life. Please download the latest version from www.secondlife.com."), ¶ms, &alert); if(err == noErr) { err = RunStandardAlert( alert, NULL, &retval_mac); } if(gMarkerPath != 0) { // Create a install fail marker that can be used by the viewer to // detect install problems. std::ofstream stream(gMarkerPath); if(stream) stream << -1; } exit(-1); } else { exit(0); } if(gWindow != NULL) { DisposeWindow(gWindow); } if(nib != NULL) { DisposeNibReference(nib); } return 0; }
BOOL create_confirm_Internal (HWND hwnd, SQLPOINTER dsn, SQLPOINTER text, SQLCHAR waMode) { EventTypeSpec controlSpec = { kEventClassControl, kEventControlHit }; RgnHandle cursorRgn = NULL; ControlID controlID; ControlRef control; WindowRef wconfirm; TCONFIRM confirm_t; EventRecord event; IBNibRef nibRef; CFStringRef msg; OSStatus err; /* Search the bundle for a .nib file named 'odbcadmin'. */ err = CreateNibReferenceWithCFBundle (CFBundleGetBundleWithIdentifier (CFSTR ("org.iodbc.drvproxy")), CFSTR ("confirmation"), &nibRef); if (err == noErr) { /* Nib found ... so create the window */ CreateWindowFromNib (nibRef, CFSTR ("Dialog"), &wconfirm); DisposeNibReference (nibRef); /* Set the title with the DSN name */ if (dsn) { if (waMode == 'A') msg = CFStringCreateWithBytes (NULL, (unsigned char*)dsn, STRLEN(dsn), kCFStringEncodingUTF8, false); else msg = convert_wchar_to_CFString((wchar_t*)dsn); SetWindowTitleWithCFString (wconfirm, msg); CFRelease(msg); } /* Install handlers for the finish button, the cancel */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, CONFYES_CNTL, wconfirm, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (confirmadm_yes_clicked), 1, &controlSpec, &confirm_t, NULL); GETCONTROLBYID (controlID, CNTL_SIGNATURE, CONFNO_CNTL, wconfirm, control); InstallEventHandler (GetControlEventTarget (control), NewEventHandlerUPP (confirmadm_no_clicked), 1, &controlSpec, &confirm_t, NULL); /* Change the static field with the message */ GETCONTROLBYID (controlID, CNTL_SIGNATURE, CONFTEXT_CNTL, wconfirm, control); if (waMode == 'A') SetControlData (control, 0, kControlEditTextTextTag, STRLEN (text), text); else { msg = convert_wchar_to_CFString((wchar_t*)text); SetControlData (control, 0, kControlEditTextCFStringTag, sizeof(CFStringRef), &msg); CFRelease(msg); } DrawOneControl (control); confirm_t.yes_no = FALSE; confirm_t.mainwnd = wconfirm; /* Show the window and run the loop */ ShowWindow (wconfirm); /* The main loop */ while (confirm_t.mainwnd) WaitNextEvent (everyEvent, &event, 60L, cursorRgn); } else goto error; return confirm_t.yes_no; error: fprintf (stderr, "Can't load Window. Err: %d\n", (int) err); return confirm_t.yes_no; }
void CL_DisplayWindow_OpenGL::set_title(const std::string &title) { CFStringRef s = CFStringCreateWithCString(0, title.c_str(), kCFStringEncodingISOLatin1); SetWindowTitleWithCFString(window_ref, s); CFRelease(s); }
void CARBON_GUI::set_title(char *txt) { CFStringRef title = CFStringCreateWithCString(NULL,txt,0); SetWindowTitleWithCFString (window,title); CFRelease(title); }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { if(m_specific->m_sys_format == pix_format_undefined) { return false; } m_window_flags = flags; // application EventTypeSpec eventType; EventHandlerUPP handlerUPP; eventType.eventClass = kEventClassApplication; eventType.eventKind = kEventAppQuit; handlerUPP = NewEventHandlerUPP(DoAppQuit); InstallApplicationEventHandler (handlerUPP, 1, &eventType, nil, nil); eventType.eventClass = kEventClassMouse; eventType.eventKind = kEventMouseDown; handlerUPP = NewEventHandlerUPP(DoMouseDown); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventMouseUp; handlerUPP = NewEventHandlerUPP(DoMouseUp); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventMouseDragged; handlerUPP = NewEventHandlerUPP(DoMouseDragged); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventClass = kEventClassKeyboard; eventType.eventKind = kEventRawKeyDown; handlerUPP = NewEventHandlerUPP(DoKeyDown); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventRawKeyUp; handlerUPP = NewEventHandlerUPP(DoKeyUp); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventRawKeyRepeat; handlerUPP = NewEventHandlerUPP(DoKeyDown); // 'key repeat' is translated to 'key down' InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); WindowAttributes windowAttrs; Rect bounds; // window windowAttrs = kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute; SetRect (&bounds, 0, 0, width, height); OffsetRect (&bounds, 100, 100); CreateNewWindow (kDocumentWindowClass, windowAttrs, &bounds, &m_specific->m_window); if(m_specific->m_window == nil) { return false; } // I assume the text is ASCII. // Change to kCFStringEncodingMacRoman, kCFStringEncodingISOLatin1, kCFStringEncodingUTF8 or what else you need. SetWindowTitleWithCFString (m_specific->m_window, CFStringCreateWithCStringNoCopy (nil, m_caption, kCFStringEncodingASCII, nil)); eventType.eventClass = kEventClassWindow; eventType.eventKind = kEventWindowClose; handlerUPP = NewEventHandlerUPP(DoWindowClose); InstallWindowEventHandler (m_specific->m_window, handlerUPP, 1, &eventType, this, NULL); eventType.eventKind = kEventWindowDrawContent; handlerUPP = NewEventHandlerUPP(DoWindowDrawContent); InstallWindowEventHandler (m_specific->m_window, handlerUPP, 1, &eventType, this, NULL); // Periodic task // Instead of an idle function I use the Carbon event timer. // You may decide to change the wait value which is currently 50 milliseconds. EventLoopRef mainLoop; EventLoopTimerUPP timerUPP; EventLoopTimerRef theTimer; mainLoop = GetMainEventLoop(); timerUPP = NewEventLoopTimerUPP (DoPeriodicTask); InstallEventLoopTimer (mainLoop, 0, 50 * kEventDurationMillisecond, timerUPP, this, &theTimer); m_specific->create_pmap(width, height, &m_rbuf_window); m_initial_width = width; m_initial_height = height; on_init(); on_resize(width, height); m_specific->m_redraw_flag = true; ShowWindow (m_specific->m_window); SetPortWindowPort (m_specific->m_window); return true; }
bool Window::configInitAGLWindow() { AGLContext context = getAGLContext(); if( !context ) { sendError( ERROR_AGLWINDOW_NO_CONTEXT ); return false; } // window const bool decoration = getIAttribute(WindowSettings::IATTR_HINT_DECORATION) != OFF; WindowAttributes winAttributes = ( decoration ? kWindowStandardDocumentAttributes : kWindowNoTitleBarAttribute | kWindowNoShadowAttribute | kWindowResizableAttribute ) | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute; // top, left, bottom, right const PixelViewport& pvp = getPixelViewport(); const int32_t menuHeight = decoration ? EQ_AGL_MENUBARHEIGHT : 0 ; Rect windowRect = { short( pvp.y + menuHeight ), short( pvp.x ), short( pvp.getYEnd() + menuHeight ), short( pvp.getXEnd( )) }; WindowRef windowRef; Global::enterCarbon(); const OSStatus status = CreateNewWindow( kDocumentWindowClass, winAttributes, &windowRect, &windowRef ); if( status != noErr ) { sendError( ERROR_AGLWINDOW_CREATEWINDOW_FAILED ) << lexical_cast< std::string >( status ); Global::leaveCarbon(); return false; } // window title const std::string& name = getName(); std::stringstream windowTitle; if( name.empty( )) { windowTitle << "Equalizer"; #ifndef NDEBUG windowTitle << " (" << getpid() << ")"; #endif } else windowTitle << name; CFStringRef title = CFStringCreateWithCString( kCFAllocatorDefault, windowTitle.str().c_str(), kCFStringEncodingMacRoman ); SetWindowTitleWithCFString( windowRef, title ); CFRelease( title ); if( !aglSetWindowRef( context, windowRef )) { sendError( ERROR_AGLWINDOW_SETWINDOW_FAILED ) << aglError(); Global::leaveCarbon(); return false; } // show ShowWindow( windowRef ); // Do focus hell ProcessSerialNumber selfProcess = { 0, kCurrentProcess }; SetFrontProcess( &selfProcess ); Global::leaveCarbon(); setCarbonWindow( windowRef ); return true; }
void _debug( code_part part, const char *function, const char *str, ... ) { va_list ap; static char outputBuffer[MAX_LEN_LOG_LINE]; static unsigned int repeated = 0; /* times current message repeated */ static unsigned int next = 2; /* next total to print update */ static unsigned int prev = 0; /* total on last update */ va_start(ap, str); vssprintf(outputBuffer, str, ap); va_end(ap); ssprintf(inputBuffer[useInputBuffer1 ? 1 : 0], "[%s] %s", function, outputBuffer); if (sstrcmp(inputBuffer[0], inputBuffer[1]) == 0) { // Received again the same line repeated++; if (repeated == next) { if (repeated > 2) { ssprintf(outputBuffer, "last message repeated %u times (total %u repeats)", repeated - prev, repeated); } else { ssprintf(outputBuffer, "last message repeated %u times", repeated - prev); } printToDebugCallbacks(outputBuffer); prev = repeated; next *= 2; } } else { // Received another line, cleanup the old if (repeated > 0 && repeated != prev && repeated != 1) { /* just repeat the previous message when only one repeat occurred */ if (repeated > 2) { ssprintf(outputBuffer, "last message repeated %u times (total %u repeats)", repeated - prev, repeated); } else { ssprintf(outputBuffer, "last message repeated %u times", repeated - prev); } printToDebugCallbacks(outputBuffer); } repeated = 0; next = 2; prev = 0; } if (!repeated) { time_t rawtime; struct tm * timeinfo; char ourtime[15]; //HH:MM:SS time ( &rawtime ); timeinfo = localtime ( &rawtime ); strftime (ourtime,15,"%I:%M:%S",timeinfo); // Assemble the outputBuffer: ssprintf(outputBuffer, "%-8s|%s: %s", code_part_names[part], ourtime, useInputBuffer1 ? inputBuffer[1] : inputBuffer[0]); printToDebugCallbacks(outputBuffer); // Throw up a dialog box for windows users since most don't have a clue to check the stderr.txt file for information // Use for (duh) Fatal errors, that force us to terminate the game. if (part == LOG_FATAL) { #if defined(WZ_OS_WIN) char wbuf[512]; ssprintf(wbuf, "%s\n\nPlease check your stderr.txt file in the same directory as the program file for more details. \ \nDo not forget to upload both the stderr.txt file and the warzone2100.rpt file in your bug reports!", useInputBuffer1 ? inputBuffer[1] : inputBuffer[0]); MessageBoxA( NULL, wbuf, "Warzone has terminated unexpectedly", MB_OK|MB_ICONERROR); #elif defined(WZ_OS_MAC32) // FIXME: Needs to be made compatible with 64bit AlertStdCFStringAlertParamRec param; DialogRef dialog; OSStatus err; DialogItemIndex itemHit; char aBuffer[512]; GetStandardAlertDefaultParams( ¶m, kStdCFStringAlertVersionOne ); param.movable = true; ssprintf(aBuffer, "%s\n\nPlease check your logs for more details.\n", useInputBuffer1 ? inputBuffer[1] : inputBuffer[0] ); err = CreateStandardAlert( kAlertStopAlert, CFStringCreateWithCString( nil, aBuffer, kCFStringEncodingMacRoman), CFSTR( "Run Console.app and search for wz2100 and copy that to a file.\ \n\nFor the Crash report on 10.4/10.5 check\ \n~/Library/Logs/CrashReporter,\ \non 10.6 check ~/Library/Logs/DiagnosticReports\ \nDo not forget to upload and attach those to a bug report at http://developer.wz2100.net/newticket\ \nThanks!" ), ¶m, &dialog ); SetWindowTitleWithCFString( GetDialogWindow( dialog ), CFSTR( "Warzone has terminated unexpectedly" ) ); RunStandardAlert( dialog, NULL, &itemHit ); #endif }
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; }
void SkOSWindow::onSetTitle(const char title[]) { CFStringRef str = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8); SetWindowTitleWithCFString((WindowRef)fHWND, str); CFRelease(str); }
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); }
/***************************************************** * * Do_NewWindowFromIB(outWindow) * * Purpose: called to create a new window that has been constructed with Interface Builder * * 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_NewWindowFromIB(WindowRef * outWindow) { OSStatus status; WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; CFMutableStringRef theNewTitle = NULL; // Create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. status = CreateWindowFromNib(gIBNibRef, CFSTR("MainWindow"), &aWindowRef); require_noerr(status, CreateWindowFromNib); require(aWindowRef != NULL, CreateWindowFromNib); WindowDataPtr wdr = (WindowDataPtr)calloc(1, sizeof(WindowDataRec)); require(wdr != NULL, CantAllocateWindowData); SetWRefCon(aWindowRef, (long)wdr); status = CopyWindowTitleAsCFString(aWindowRef, &theTitle); require_noerr(status, CopyWindowTitleAsCFString); theNewTitle = CFStringCreateMutableCopy(NULL, 0, theTitle); require(theNewTitle != NULL, CFStringCreateMutableCopy); CFStringAppendFormat(theNewTitle, NULL, CFSTR(" %ld"), ++gWindowCount); status = SetWindowTitleWithCFString(aWindowRef, theNewTitle); 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); HIViewID littleArrowsId = { 'LARC', 100 }; HIViewRef littleArrows; status = HIViewFindByID(HIViewGetRoot(aWindowRef), littleArrowsId, &littleArrows); require_noerr(status, HIViewFindByID); require(littleArrows != NULL, HIViewFindByID); SetControlAction(littleArrows, LittleArrowsControlAction); EventTypeSpec eventTypeCVFC = {kEventClassControl, kEventControlValueFieldChanged}; status = HIViewInstallEventHandler(littleArrows, Handle_PostLittleArrowsClick, 1, &eventTypeCVFC, (void *)littleArrows, 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); HIViewFindByID: CantInstallEventHandler: SetWindowTitleWithCFString: CFStringCreateMutableCopy: CopyWindowTitleAsCFString: if (theTitle != NULL) CFRelease(theTitle); if (theNewTitle != NULL) CFRelease(theNewTitle); CantAllocateWindowData: CreateWindowFromNib: if (outWindow != NULL) *outWindow = aWindowRef; return status; } // Do_NewWindowFromIB
CV_IMPL int cvNamedWindow( const char* name, int flags ) { int result = 0; CV_FUNCNAME( "cvNamedWindow" ); if (!wasInitialized) cvInitSystem(0, NULL); // to be able to display a window, we need to be a 'faceful' application // http://lists.apple.com/archives/carbon-dev/2005/Jun/msg01414.html static bool switched_to_faceful = false; if (! switched_to_faceful) { ProcessSerialNumber psn = { 0, kCurrentProcess }; OSStatus ret = TransformProcessType (&psn, kProcessTransformToForegroundApplication ); if (ret == noErr) { SetFrontProcess( &psn ); switched_to_faceful = true; } else { fprintf(stderr, "Failed to tranform process type: %d\n", (int) ret); fflush (stderr); } } __BEGIN__; WindowRef outWindow = NULL; OSStatus err = noErr; Rect contentBounds = {100,100,320,440}; CvWindow* window; UInt wAttributes = 0; int len; const EventTypeSpec genericWindowEventHandler[] = { { kEventClassMouse, kEventMouseMoved}, { kEventClassMouse, kEventMouseUp}, { kEventClassMouse, kEventMouseDown}, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowBoundsChanged }//FD }; if( !name ) CV_ERROR( CV_StsNullPtr, "NULL name string" ); if( icvFindWindowByName( name ) != 0 ){ result = 1; EXIT; } len = strlen(name); CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1)); memset( window, 0, sizeof(*window)); window->name = (char*)(window + 1); memcpy( window->name, name, len + 1 ); window->flags = flags; window->signature = CV_WINDOW_MAGIC_VAL; window->image = 0; window->last_key = 0; window->on_mouse = 0; window->on_mouse_param = 0; window->next = hg_windows; window->prev = 0; if( hg_windows ) hg_windows->prev = window; hg_windows = window; wAttributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute; err = CreateNewWindow ( kDocumentWindowClass,wAttributes,&contentBounds,&outWindow); if (err != noErr) fprintf(stderr,"Erreur while creating the window\n"); SetWindowTitleWithCFString(outWindow,CFStringCreateWithCString(NULL,name,kCFStringEncodingASCII)); if (err != noErr) fprintf(stdout,"Erreur SetWindowTitleWithCFString\n"); window->window = outWindow; err = InstallWindowEventHandler(outWindow, NewEventHandlerUPP(windowEventHandler), GetEventTypeCount(genericWindowEventHandler), genericWindowEventHandler, outWindow, NULL); ShowWindow( outWindow ); result = 1; __END__; return result; }
/***************************************************** * * 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
void BaseApp::setWindowTitle(const char *title){ SetWindowTitleWithCFString(window, CFStringCreateWithCString(NULL, title, kCFStringEncodingMacRoman)); }