Exemplo n.º 1
0
bool wxDialog::Create( wxWindow *parent,
    wxWindowID id,
    const wxString& title,
    const wxPoint& pos,
    const wxSize& size,
    long style,
    const wxString& name )
{
    SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );

    // All dialogs should really have this style...
    style |= wxTAB_TRAVERSAL;

    // ...but not these styles
    style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL

    if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
        return false;

#if TARGET_API_MAC_OSX
    HIViewRef growBoxRef = 0 ;
    OSStatus err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef  );
    if ( err == noErr && growBoxRef != 0 )
        HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
#endif

    return true;
}
Exemplo n.º 2
0
pascal OSStatus AutofireWindowEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	#pragma unused (inHandlerRef)
	
	OSStatus	err, result = eventNotHandledErr;
	WindowRef	tWindowRef = (WindowRef) inUserData;

	switch (GetEventClass(inEvent))
	{
		case kEventClassWindow:
			switch (GetEventKind(inEvent))
			{
				case kEventWindowClose:
					QuitAppModalLoopForWindow(tWindowRef);
					result = noErr;
			}
			
			break;

		case kEventClassCommand:
			switch (GetEventKind(inEvent))
			{
				case kEventCommandProcess:
					HICommand	tHICommand;
					HIViewRef	root;
					int			player = -1;

					root = HIViewGetRoot(tWindowRef);

					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &tHICommand);
					if (err == noErr)
					{
						switch (tHICommand.commandID)
						{
							case 'DEF1':
								player = 0;
								break;
							
							case 'DEF2':
								player = 1;
								break;
						}
						
						if (player != -1)
						{
							autofireRec[player].buttonMask = 0x0000;
							autofireRec[player].toggleMask = 0xFFF0;
							autofireRec[player].tcMask     = 0x0000;
							autofireRec[player].invertMask = 0x0000;
							autofireRec[player].frequency  = 10;
							AutofireReadAllSettings(player + 1, root);
							
							result = noErr;
						}
					}
			}
	}
	
	return result;
}
/*****************************************************
*
* Handle_ControlValueFieldOrHiliteChanged(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to handle the change of the value or hilite of our custom view, we update the static text field
*
* Inputs:   inHandlerCallRef    - reference to the current handler call chain
*           inEvent             - the event
*           inUserData          - app-specified data you passed in the call to InstallEventHandler
*
* Returns:  OSStatus            - noErr indicates the event was handled
*                                 eventNotHandledErr indicates the event was not handled and the Toolbox should take over
*/
static pascal OSStatus Handle_ControlValueFieldOrHiliteChanged(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
	{
	OSStatus status;
	HIViewRef customView = (HIViewRef)inUserData;
	
	// Finding our static text control
	HIViewRef statText;
	status = HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kStaticTextID, &statText);
	require_noerr(status, ExitValueFieldChanged);

	// Grabbing the fields that we are interested in
	CFStringRef theCFString = CFStringCreateWithFormat(NULL, NULL, CFSTR("Value: %ld, Min: %ld, Max: %ld, Hilite: %d"), GetControl32BitValue(customView), GetControl32BitMinimum(customView), GetControl32BitMaximum(customView), GetControlHilite(customView));
	require(theCFString != NULL, ExitValueFieldChanged);

	// Setting the text in the control
#ifdef MAC_OS_X_VERSION_10_4
	status = HIViewSetText(statText, theCFString);
#else
	status = SetControlData(statText, kControlEntireControl, kControlStaticTextCFStringTag, sizeof(theCFString), &theCFString);
#endif
	require_noerr(status, ExitValueFieldChanged);

	CFRelease(theCFString);

ExitValueFieldChanged:

	if (status == noErr) status = eventNotHandledErr;
	return status;
	}   // Handle_ControlValueFieldOrHiliteChanged
Exemplo n.º 4
0
//-------------------------------------------------------------------------------------
//	InputPanelHandler
//-------------------------------------------------------------------------------------
//	Deal with events in our prompt panel. We merely respond to the cancel and OK commands
// 	that are sent from the push buttons and terminate our modal loop. If OK is pressed,
//	we get the string and store it in our PanelInfo structure.
//
static OSStatus
InputPanelHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
{
	HICommand			command;
	OSStatus			result = eventNotHandledErr;
	PanelInfo*			info = (PanelInfo*)inUserData;
	
	GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL,
			sizeof( HICommand ), NULL, &command );

	if ( command.commandID == kHICommandCancel )
	{
		QuitAppModalLoopForWindow( info->window );
		result = noErr;
	}
	else if ( command.commandID == kHICommandOK )
	{
		HIViewRef		textField;
		
		HIViewFindByID( HIViewGetRoot( info->window ), kTextFieldID, &textField );
		GetControlData( textField, 0, kControlEditTextCFStringTag, sizeof( CFStringRef ), &info->string, NULL );
		QuitAppModalLoopForWindow( info->window );
	}
	
	return result;
}
Exemplo n.º 5
0
static void NPClientBeginPlayerListSheet(void)
{
	OSStatus	err;
	CFStringRef	ref;
	HIViewRef	ctl, root;
	HIViewID	cid;

	root = HIViewGetRoot(sRef);
	cid.signature = 'PLNM';

	for (int i = 0; i < NP_MAX_PLAYERS; i++)
	{
		if (npcinfo[i].ready)
		{
			cid.id = npcinfo[i].player;
			HIViewFindByID(root, cid, &ctl);
			ref = CFStringCreateWithCString(kCFAllocatorDefault, npcinfo[i].name, MAC_PATH_ENCODING);
			if (ref)
			{
				SetStaticTextCFString(ctl, ref, false);
				CFRelease(ref);
			}
			else
				SetStaticTextCFString(ctl, CFSTR("unknown"), false);
		}
	}

	err = ShowSheetWindow(sRef, mRef);
}
Exemplo n.º 6
0
//---------------------------------------------------------------------
// Returns the HITextView ref from one of our windows.
//
HIViewRef GetTextViewFromWindow(WindowRef window)
{
	HIViewRef textView = NULL;

	if( window != NULL )
		verify_noerr( HIViewFindByID(HIViewGetRoot(window), gTextViewID, &textView) );

	return textView;
}
Exemplo n.º 7
0
/* initialize the status window (used to show console messages in the graphic environment */
void CARBON_GUI::setupStatusWindow() 
{
	OSStatus err=CreateWindowFromNib(nibRef,CFSTR("StatusWindow"),&statusWindow);
	if(err!=noErr) msg->error("Can't create status window (%d)!!",err);
	//SetDrawerParent(statusWindow,window);
	//SetDrawerPreferredEdge(statusWindow,kWindowEdgeBottom);
	//SetDrawerOffsets(statusWindow,20,20);
	
	/* install an eventHandler to intercept close requests */
	err = InstallWindowEventHandler (statusWindow, 
		NewEventHandlerUPP (StatusWindowEventHandler), 
		GetEventTypeCount(statusEvents), statusEvents, this, NULL);
	if(err != noErr) msg->error("Can't install status window eventHandler");
	
	/* and then install a command handler (to handle "clear" requests) */
	err=InstallWindowEventHandler(statusWindow,NewEventHandlerUPP(StatusWindowCommandHandler),
		GetEventTypeCount(commands),commands,this,NULL);
		
	/* obtain an HIViewRef for the status text box ... we have to use it 
	 * to setup various properties and to obain a TXNObject needed to manage its content */
	const ControlID txtid={ CARBON_GUI_APP_SIGNATURE, STATUS_TEXT_ID };
	err= HIViewFindByID(HIViewGetRoot(statusWindow), txtid, &statusTextView);
	if(err!=noErr) return;// msg->warning("Can't get textView for status window (%d)!!",err);
	statusText = HITextViewGetTXNObject(statusTextView);
	if(!statusText) {
		msg->error("Can't get statusText object from status window!!");
	}
//	TXNControlTag iControlTags[1] = { kTXNAutoScrollBehaviorTag };
//	TXNControlData iControlData[1] = { kTXNAutoScrollNever }; //kTXNAutoScrollWhenInsertionVisible };
//	err = TXNSetTXNObjectControls(statusText,false,1,iControlTags,iControlData);
	//TextViewSetObjectControlData
	//TextViewSetObjectControlData(statusText,kTXNAutoScrollBehaviorTag,kUn kTXNAutoScrollWhenInsertionVisible)
	/* setup status text font size and color */
	// Create type attribute data structure
	UInt32   fontSize = 10 << 16; // needs to be in Fixed format
	TXNAttributeData fsData,fcData;
	fsData.dataValue=fontSize;
	fcData.dataPtr=(void *)&black;
	TXNTypeAttributes attributes[] = {
		//{ kTXNQDFontStyleAttribute, kTXNQDFontStyleAttributeSize, bold },
		{ kTXNQDFontColorAttribute, kTXNQDFontColorAttributeSize,fcData}, //&lgrey },
		{ kTXNQDFontSizeAttribute, kTXNFontSizeAttributeSize,fsData }
	};
	err= TXNSetTypeAttributes( statusText, 2, attributes,
		kTXNStartOffset,kTXNEndOffset );
		
	/* block user input in the statusText box */
	TXNControlTag tags[] = { kTXNNoUserIOTag };
	TXNControlData vals[] = { kTXNReadOnly };
	err=TXNSetTXNObjectControls(statusText,false,1,tags,vals);
	if(err!=noErr) msg->error("Can't set statusText properties (%d)!!",err);
	// TXNSetScrollbarState(statusText,kScrollBarsAlwaysActive);
		
	//struct TXNBackground bg = {  kTXNBackgroundTypeRGB, black };
	//TXNSetBackground(statusText,&bg);
}
Exemplo n.º 8
0
bool8 NPServerDialog (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	npserver.dialogcancel = true;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		WindowRef	tWindowRef;

		err = CreateWindowFromNib(nibRef, CFSTR("ClientList"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		eref;
			EventLoopTimerRef	tref;
			EventHandlerUPP		eventUPP;
			EventLoopTimerUPP	timerUPP;
			EventTypeSpec		windowEvents[] = { { kEventClassCommand, kEventCommandProcess      },
												   { kEventClassCommand, kEventCommandUpdateStatus } };
			HIViewRef			ctl;
			HIViewID			cid = { 'Chse', 0 };

			npserver.dialogprocess = kNPSDialogInit;

			eventUPP = NewEventHandlerUPP(NPServerDialogEventHandler);
			err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref);

			timerUPP = NewEventLoopTimerUPP(NPServerDialogTimerHandler);
			err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) tWindowRef, &tref);

			HIViewFindByID(HIViewGetRoot(tWindowRef), cid, &ctl);
			HIViewSetVisible(ctl, false);

			MoveWindowPosition(tWindowRef, kWindowServer, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowServer);

			err = RemoveEventLoopTimer(tref);
			DisposeEventLoopTimerUPP(timerUPP);

			err = RemoveEventHandler(eref);
			DisposeEventHandlerUPP(eventUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);
	}

	return (!npserver.dialogcancel);
}
Exemplo n.º 9
0
IPopupMenu* IGraphicsCarbon::CreateIPopupMenu(IPopupMenu* pMenu, IRECT* pAreaRect)
{
  // Get the plugin gui frame rect within the host's window
  HIRect rct;
  HIViewGetFrame(this->mView, &rct);

  // Get the host's window rect within the screen
  Rect wrct;
  GetWindowBounds(this->mWindow, kWindowContentRgn, &wrct);

  #ifdef RTAS_API
  int xpos = wrct.left + this->GetLeftOffset() + pAreaRect->L;
  int ypos = wrct.top + this->GetTopOffset() + pAreaRect->B + 5;
  #else
  HIViewRef contentView;
  HIViewFindByID(HIViewGetRoot(this->mWindow), kHIViewWindowContentID, &contentView);
  HIViewConvertRect(&rct, HIViewGetSuperview((HIViewRef)this->mView), contentView);

  int xpos = wrct.left + rct.origin.x + pAreaRect->L;
  int ypos = wrct.top + rct.origin.y + pAreaRect->B + 5;
  #endif

  MenuRef menuRef = CreateMenu(pMenu);

  if (menuRef)
  {
    int32_t popUpItem = 1;
    int32_t PopUpMenuItem = PopUpMenuSelect(menuRef, ypos, xpos, popUpItem);

    short result = LoWord(PopUpMenuItem) - 1;
    short menuIDResult = HiWord(PopUpMenuItem);
    IPopupMenu* resultMenu = 0;

    if (menuIDResult != 0)
    {
      MenuRef usedMenuRef = GetMenuHandle(menuIDResult);

      if (usedMenuRef)
      {
        if (GetMenuItemRefCon(usedMenuRef, 0, (URefCon*)&resultMenu) == noErr)
        {
          resultMenu->SetChosenItemIdx(result);
        }
      }
    }

    CFRelease(menuRef);

    return resultMenu;
  }
  else
  {
    return 0;
  }
}
Exemplo n.º 10
0
int main(int argc, char* argv[])
{
    IBNibRef 		nibRef;
    WindowRef 		window;
    HIViewRef		textView;
	OSStatus		err;

    // 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"), &nibRef);
    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(nibRef, CFSTR("MenuBar"));
    require_noerr( err, CantSetMenuBar );
    
    // Then create a window. "MainDocumentWindow" is the name of the window object. This name is set in 
    // InterfaceBuilder when the nib is created.
    err = CreateWindowFromNib(nibRef, CFSTR("MainDocumentWindow"), &window);
    require_noerr( err, CantCreateWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);

	// Make the window's content area transparent
	err = MakeWindowTransparent(window);
    require_noerr( err, CantMakeWindowTransparent );

	// Get a reference to the TextView in the main window
	err = HIViewFindByID(HIViewGetRoot(window), gTextViewID, &textView);
	require_noerr( err, CantGetTextView );

	// Install our default options in the TextView
	err = MySetTextViewOptions(textView);
	require_noerr( err, CantSetTextViewOptions );

	// Make the TextView partially transparent
	err = TextViewSetAlpha(textView, 0.25);
	require_noerr( err, CantSetTextViewOptions );
	
    // The window was created hidden so show it.
    ShowWindow( window );

    // Call the event loop
    RunApplicationEventLoop();

CantSetTextViewOptions:
CantGetTextView:
CantMakeWindowTransparent:
CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
	return err;
}
Exemplo n.º 11
0
OSStatus
GetTextViewFromWindow( WindowRef window, HIViewRef& textView )
{
	OSStatus status = paramErr;
	if( window != NULL )
	{
		status = HIViewFindByID(HIViewGetRoot(window), kTextViewControlID, &textView);
		check_noerr( status );
	}
	return status;
}
Exemplo n.º 12
0
static
OSStatus InstallWindowEventHandlers( WindowRef windowRef )
{
	static const EventTypeSpec 	inputEventSpec[] = { 
		{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } };
		
	static const EventTypeSpec	windowEventSpec[] = {
		{ kEventClassWindow, kEventWindowClosed },
		{ kEventClassWindow, kEventWindowBoundsChanged } };

	static const EventTypeSpec	viewEventSpec[] = {
		{ kEventClassControl,	kEventControlDraw } };

	OSStatus 			err;
	DrawContextStruct	*newContext;

	// allocate a new draw context
	newContext = calloc( 1, sizeof( DrawContextStruct ) );
	require_action( newContext != NULL, InstallWindowEventHandlers_err,
		err = paramErr );
	
	HIViewFindByID(HIViewGetRoot(windowRef), myHIViewID, &newContext->viewRef);
	newContext->windowRef = windowRef;
	
	
	// install a key event handler
	err = InstallWindowEventHandler( windowRef, NewEventHandlerUPP( HandleKeyEvent ), GetEventTypeCount( inputEventSpec ), inputEventSpec, (void *) newContext, NULL );
	require_noerr( err, InstallWindowEventHandlersEvent_err );
	
	// install a general window event handler
	err = InstallWindowEventHandler( windowRef, NewEventHandlerUPP( HandleWindowEvent ), GetEventTypeCount( windowEventSpec ), windowEventSpec, (void *) newContext, NULL );
	require_noerr( err, InstallWindowEventHandlersEvent_err );
	
	// install handler for the HI view
	err = HIViewInstallEventHandler( newContext->viewRef, NewEventHandlerUPP( HandleViewEvent ), GetEventTypeCount( viewEventSpec ), viewEventSpec, (void *) newContext, NULL);
	require_noerr( err, InstallWindowEventHandlersEvent_err );
	
	// also, set the context as the window refcon
	SetWRefCon( windowRef, (SRefCon) newContext );

	return noErr;
	
InstallWindowEventHandlersEvent_err:

	// make sure that if we're bailing to get rid of the allocated buffer
	free( newContext );

InstallWindowEventHandlers_err:
	
	return err;

}
Exemplo n.º 13
0
static void DeleteCheatItem (void)
{
	OSStatus	err;
	HIViewRef	ctl, root;
	HIViewID	cid;
	Handle		selectedItems;
	ItemCount	selectionCount;

	selectedItems = NewHandle(0);
	if (!selectedItems)
		return;

	err = GetDataBrowserItems(dbRef, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, selectedItems);
	selectionCount = (GetHandleSize(selectedItems) / sizeof(DataBrowserItemID));

	if (selectionCount == 0)
	{
		DisposeHandle(selectedItems);
		return;
	}

	err = RemoveDataBrowserItems(dbRef, kDataBrowserNoItem, selectionCount, (DataBrowserItemID *) *selectedItems, kDataBrowserItemNoProperty);

	for (unsigned int i = 0; i < selectionCount; i++)
	{
		citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].valid   = false;
		citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].enabled = false;
		numofcheats--;
	}

	DisposeHandle(selectedItems);

	root = HIViewGetRoot(wRef);
	cid.id = 0;

	if (numofcheats < MAC_MAX_CHEATS)
	{
		cid.signature = kNewButton;
		HIViewFindByID(root, cid, &ctl);
		err = ActivateControl(ctl);
	}

	if (numofcheats == 0)
	{
		cid.signature = kAllButton;
		HIViewFindByID(root, cid, &ctl);
		err = DeactivateControl(ctl);
	}
}
Exemplo n.º 14
0
static void AddCheatItem (void)
{
	OSStatus			err;
	HIViewRef			ctl, root;
	HIViewID			cid;
	DataBrowserItemID	id[1];
	unsigned int		i;

	if (numofcheats == MAC_MAX_CHEATS)
		return;

	for (i = 0; i < MAC_MAX_CHEATS; i++)
		if (citem[i].valid == false)
			break;

	if (i == MAC_MAX_CHEATS)
		return;

	numofcheats++;
	citem[i].valid   = true;
	citem[i].enabled = false;
	citem[i].address = 0;
	citem[i].value   = 0;
	sprintf(citem[i].description, "Cheat %03" PRIu32, citem[i].id);

	id[0] = citem[i].id;
	err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, 1, id, kDataBrowserItemNoProperty);
	err = RevealDataBrowserItem(dbRef, id[0], kCmAddress, true);

	root = HIViewGetRoot(wRef);
	cid.id = 0;

	if (numofcheats == MAC_MAX_CHEATS)
	{
		cid.signature = kNewButton;
		HIViewFindByID(root, cid, &ctl);
		err = DeactivateControl(ctl);
	}

	if (numofcheats)
	{
		cid.signature = kAllButton;
		HIViewFindByID(root, cid, &ctl);
		err = ActivateControl(ctl);
	}
}
Exemplo n.º 15
0
    //-------------------------------------------------------------------------------------------------//
    void OSXCarbonWindow::windowMovedOrResized()
    {
        // External windows will call this method.
        if(mView != NULL)
        {
            // Determine the AGL_BUFFER_RECT for the view. The coordinate 
            // system for this rectangle is relative to the owning window, with 
            // the origin at the bottom left corner and the y-axis inverted.
            
            // Also, when leaving fullscreen, the display properties are not guaranteed to be
            // the same as when we were windowed previously.  So resize the window and views back
            // to their original dimensions.
            HIRect newFrame = CGRectMake(mLeft, mTop+22, mWidth, mHeight);
            HIRect viewBounds = CGRectZero, winBounds = CGRectZero;

            SizeWindow(mWindow, mWidth, mHeight, true);
            HIViewSetFrame(mView, &newFrame);

            HIViewGetBounds(mView, &viewBounds);
            HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));

            HIViewGetBounds(root, &winBounds);
            HIViewConvertRect(&viewBounds, mView, root);

            // Set the AGL buffer rectangle (i.e. the bounds that we will use) 
            GLint bufferRect[4]; 
            bufferRect[0] = viewBounds.origin.x; // 0 = left edge 
            bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge 
            bufferRect[2] = viewBounds.size.width; // width of buffer rect 
            bufferRect[3] = viewBounds.size.height; // height of buffer rect 
            
            aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); 
            aglEnable(mAGLContext, AGL_BUFFER_RECT); 
            aglUpdateContext(mAGLContext);
            
            mLeft = viewBounds.origin.x; 
            mTop = bufferRect[1];
        }
        
        for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) 
        { 
            (*it).second->_updateDimensions(); 
        }
    }
Exemplo n.º 16
0
    //-------------------------------------------------------------------------------------------------//
    void OSXCarbonWindow::windowResized()
    {
        // Ensure the context is current
        if(!mIsFullScreen)
        {
            // Determine the AGL_BUFFER_RECT for the view. The coordinate 
            // system for this rectangle is relative to the owning window, with 
            // the origin at the bottom left corner and the y-axis inverted. 
            HIRect newFrame = CGRectMake(mLeft, mTop+22, mWidth, mHeight);
            HIRect viewBounds = CGRectZero, winBounds = CGRectZero;

            SizeWindow(mWindow, mWidth, mHeight, true);
            HIViewSetFrame(mView, &newFrame);

            HIViewGetBounds(mView, &viewBounds);
            HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));

            HIViewGetBounds(root, &winBounds);
            HIViewConvertRect(&viewBounds, mView, root);

            // Set the AGL buffer rectangle (i.e. the bounds that we will use) 
            GLint bufferRect[4]; 
            bufferRect[0] = viewBounds.origin.x; // 0 = left edge 
            bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge 
            bufferRect[2] = viewBounds.size.width; // width of buffer rect 
            bufferRect[3] = viewBounds.size.height; // height of buffer rect 

            aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); 
            aglEnable(mAGLContext, AGL_BUFFER_RECT); 
            aglUpdateContext(mAGLContext);

            mLeft = viewBounds.origin.x; 
            mTop = bufferRect[1]; 
        }
        else
        {
            swapCGLBuffers();
        }
        
        for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) 
        { 
            (*it).second->_updateDimensions(); 
        }
    }
Exemplo n.º 17
0
static pascal void DBItemNotificationCallBack (HIViewRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message)
{
	OSStatus	err;
	HIViewRef	ctl;
	HIViewID	cid = { kDelButton, 0 };
	ItemCount	selectionCount;

	switch (message)
	{
		case kDataBrowserSelectionSetChanged:
			HIViewFindByID(HIViewGetRoot(wRef), cid, &ctl);

			err = GetDataBrowserItemCount(browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &selectionCount);
			if (selectionCount == 0)
				err = DeactivateControl(ctl);
			else
				err = ActivateControl(ctl);
	}
}
Exemplo n.º 18
0
OSStatus
TextViewFocusInWindow( WindowRef window )
{
	OSStatus status = paramErr;
	HIViewRef textView = NULL;
	HIViewRef scrollView = NULL;
	
	// Get the HITextView from the window
	status = GetTextViewFromWindow( window, textView );
	
	require_action( textView != NULL, EXIT, status = paramErr );
	scrollView = HIViewGetSuperview( textView );
	require_action( scrollView != NULL, EXIT, status = paramErr );
	
	HIViewSetFirstSubViewFocus( HIViewGetRoot(window), textView );
	status = HIViewSetNextFocus( scrollView, NULL );
	status = HIViewAdvanceFocus ( scrollView, 0 /*modifiers*/ );

	EXIT:
	return status;
}
Exemplo n.º 19
0
 //-------------------------------------------------------------------------------------------------//
 void OSXCarbonWindow::resize(unsigned int width, unsigned int height)
 {
     if(!mWindow)
         return;
     
     // Check if the window size really changed
     if(mWidth == width && mHeight == height)
         return;
     mWidth = width;
     mHeight = height;
     if (mIsExternal)
     {
         HIRect viewBounds = CGRectZero, winBounds = CGRectZero;
         HIViewGetBounds(mView, &viewBounds);
         HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
         HIViewGetBounds(root, &winBounds);
         HIViewConvertRect(&viewBounds, mView, root);
         mLeft = viewBounds.origin.x;
         mTop = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height);
         
         // Set the AGL buffer rectangle (i.e. the bounds that we will use) 
         GLint bufferRect[4];      
         bufferRect[0] = mLeft; // 0 = left edge 
         bufferRect[1] = mTop; // 0 = bottom edge 
         bufferRect[2] = mWidth; // width of buffer rect 
         bufferRect[3] = mHeight; // height of buffer rect 
         aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
         for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) 
         { 
             (*it).second->_updateDimensions(); 
         }
     }
     else
     {
         SizeWindow(mWindow, width, height, true);
     }
 }
//----------------------------------------------------------------------------//
void MacCEGuiRendererSelector::loadDialogWindow()
{
    // get our framework bundle from the app
    CFBundleRef helperFwk =
        CFBundleGetBundleWithIdentifier(
            CFSTR("net.sourceforge.crayzedsgui.CEGUISampleHelper"));

    if (helperFwk)
    {
        IBNibRef nib;
        if (!CreateNibReferenceWithCFBundle(helperFwk,
                                            CFSTR("RendererSelector"), &nib))
        {
            CreateWindowFromNib(nib, CFSTR("RendererSelector"), &d_dialog);
            DisposeNibReference (nib);

            // find popup button in the window
            const HIViewID rendererPopupID = {'PBTN', 0};
            HIViewFindByID(HIViewGetRoot(d_dialog),
                           rendererPopupID,
                           &d_rendererPopup);
        }
    }    
}
Exemplo n.º 21
0
//-------------------------------------------------------------------------------------------------//
void OSXCarbonWindow::windowMovedOrResized()
{
	// External windows will call this method.
	if(mView != NULL)
	{
		// Determine the AGL_BUFFER_RECT for the view. The coordinate 
        // system for this rectangle is relative to the owning window, with 
        // the origin at the bottom left corner and the y-axis inverted. 
        HIRect viewBounds, winBounds; 
        HIViewGetBounds(mView, &viewBounds); 
        HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView)); 
        
        HIViewGetBounds(root, &winBounds); 
        HIViewConvertRect(&viewBounds, mView, root); 
        
        // Set the AGL buffer rectangle (i.e. the bounds that we will use) 
        GLint bufferRect[4]; 
        bufferRect[0] = viewBounds.origin.x; // 0 = left edge 
        bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge 
        bufferRect[2] = viewBounds.size.width; // width of buffer rect 
        bufferRect[3] = viewBounds.size.height; // height of buffer rect 
        
        aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); 
        aglEnable (mAGLContext, AGL_BUFFER_RECT); 
        
        mWidth = viewBounds.size.width; 
        mHeight = viewBounds.size.height; 
        mLeft = viewBounds.origin.x; 
        mTop = bufferRect[1]; 
    } 
    
    for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) 
    { 
        (*it).second->_updateDimensions(); 
    }
}
Exemplo n.º 22
0
/*****************************************************
*
* 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
Exemplo n.º 23
0
/*****************************************************
*
* 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
Exemplo n.º 24
0
static pascal void NPServerDialogTimerHandler (EventLoopTimerRef inTimer, void *userData)
{
	WindowRef	window = (WindowRef) userData;
	CFStringRef	ref;
	HIViewRef	ctl, root;
	HIViewID	cid;
	int			n = 0;

	root = HIViewGetRoot(window);

	for (int c = 0; c < NP_MAX_PLAYERS; c++)
	{
		cid.id = c;

		cid.signature = 'Pnum';
		HIViewFindByID(root, cid, &ctl);
		if (npplayer[c].ready)
		{
			char	num[4];

			num[0] = '1' + n;
			num[1] = 'P';
			num[2] = 0;
			SetStaticTextCStr(ctl, num, true);
			n++;
		}

		cid.signature = 'IP__';
		HIViewFindByID(root, cid, &ctl);
		if (npplayer[c].online)
		{
			ref = CFStringCreateWithCString(kCFAllocatorDefault, npplayer[c].ip, MAC_PATH_ENCODING);
			if (ref)
			{
				SetStaticTextCFString(ctl, ref, true);
				CFRelease(ref);
			}
			else
				SetStaticTextCFString(ctl, CFSTR("unknown"), true);
		}
		else
			SetStaticTextCFString(ctl, CFSTR(""), true);

		cid.signature = 'Name';
		HIViewFindByID(root, cid, &ctl);
		if (npplayer[c].online)
		{
			ref = CFStringCreateWithCString(kCFAllocatorDefault, npplayer[c].name, MAC_PATH_ENCODING);
			if (ref)
			{
				SetStaticTextCFString(ctl, ref, true);
				CFRelease(ref);
			}
			else
				SetStaticTextCFString(ctl, CFSTR("unknown"), true);
		}
		else
			SetStaticTextCFString(ctl, CFSTR(""), true);

		cid.signature = 'Stat';
		HIViewFindByID(root, cid, &ctl);
		if (npplayer[c].online)
		{
			if (npplayer[c].ready)
				ref = CFCopyLocalizedString(CFSTR("NPReady"), "NPReady");
			else
				ref = CFCopyLocalizedString(CFSTR("NPConnecting"), "NPConnecting");

			if (ref)
			{
				SetStaticTextCFString(ctl, ref, true);
				CFRelease(ref);
			}
			else
				SetStaticTextCFString(ctl, CFSTR("error"), true);
		}
		else
			SetStaticTextCFString(ctl, CFSTR(""), true);
	}

	switch (npserver.dialogprocess)
	{
		case kNPSDialogNone:
			break;

		case kNPSDialogInit:
			NPNotification("  kNPSDialogInit", -1);
			npserver.dialogprocess = kNPSDialogNone;
			NPServerBeginListenLoop();
			break;

		case kNPSDialogProcess:
			NPNotification("  kNPSDialogProcess", -1);
			npserver.dialogprocess = kNPSDialogNone;
			NPServerEndListenLoop();
			cid.id = 0;
			cid.signature = 'Chse';
			HIViewFindByID(root, cid, &ctl);
			HIViewSetVisible(ctl, true);
			NPServerDetachProcessThread();
			break;

		case kNPSDialogDone:
			NPNotification("  kNPSDialogDone", -1);
			npserver.dialogprocess = kNPSDialogNone;
			npserver.dialogcancel = false;
			QuitAppModalLoopForWindow(window);
			break;

		case kNPSDialogCancel:
			NPNotification("  kNPSDialogCancel", -1);
			npserver.dialogprocess = kNPSDialogNone;
			NPServerEndListenLoop();
			npserver.dialogcancel = true;
			QuitAppModalLoopForWindow(window);
			break;
	}
}
Exemplo n.º 25
0
static WindowRef DrawDialogTheMacOSXWay(void)
{
	// Create a window. "DLOG:257" is the name of the window object. This name is set in 
	// InterfaceBuilder when the resource file is imported.
	
	OSStatus status = noErr;
	IBNibRef nibRef;
	WindowRef window  = NULL;
	
	static HIObjectClassRef	theClass;
	if (theClass == NULL)
	{
		static EventTypeSpec kFactoryEvents[] =
	{
				{ kEventClassHIObject, kEventHIObjectConstruct },
				{ kEventClassHIObject, kEventHIObjectInitialize },
				{ kEventClassHIObject, kEventHIObjectDestruct },
				{ kEventClassControl, kEventControlHitTest },
				{ kEventClassControl, kEventControlTrack },
				{ kEventClassControl, kEventControlBoundsChanged },
				{ kEventClassControl, kEventControlDraw }
	};
		HIObjectRegisterSubclass(kCustomSpotViewClassID, kHIViewClassID, 0, CustomSpotViewHandler, GetEventTypeCount(kFactoryEvents), kFactoryEvents, 0, &theClass);
	}
	
	status = CreateNibReference(CFSTR("main"), &nibRef);
	require_noerr(status, CantGetNibRef);
	
	status = CreateWindowFromNib(nibRef, CFSTR("DLOG:257"), &window);
	require_noerr(status, CantCreateWindow);
	
	// Let's react to User's commands.
	EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess};
	InstallEventHandler(GetWindowEventTarget(window), MacOSXDialogCommandProcess, 1, &eventTypeCP, window, NULL);
	
	// we still assign the key filter on our edit text box so that only digits can be entered
	HIViewID hidnst = {0, 9};
	HIViewRef numEditText;
	HIViewFindByID(HIViewGetRoot(window), hidnst, &numEditText);
	ControlKeyFilterUPP keyFilter = MyEditKeyFilter;
	SetControlData(numEditText, kControlEntireControl, kControlEditTextKeyFilterTag, sizeof(keyFilter), &keyFilter);
	SetKeyboardFocus(window, numEditText, kControlFocusNextPart);
	
	// we still set the action proc for the scroll bar so that the PageUp/PageDown/Up/Down buttons work
	// and still associate the previous edit text box with the scroll bar so it gets updated
	HIViewID hidsb = {0, 14};
	HIViewRef scrollBar;
	HIViewFindByID(HIViewGetRoot(window), hidsb, &scrollBar);
	SetControlAction(scrollBar, ScrollBar32BitActionProc);
	SetControlReference(scrollBar, (SInt32)numEditText);
	
	// Move it!
	MoveWindow(window, 854, 271, false);
	
	// and use the replacement for ModalDialog
	// one good thing is that our behaviors are no longer half-done at the dialog level
	// and half-done at the control level, they are all handled by the view handlers
	ShowWindow(window);
	
CantCreateWindow:
CantGetNibRef:
		return (window);
}
Exemplo n.º 26
0
//-------------------------------------------------------------------------------------------------//
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;
}
OSStatus _Growl_ShowUpdatePromptForVersion(CFStringRef updateVersion) {
	OSStatus err = noErr;

	if (_checkOSXVersion()) {
		CFBundleRef bundle = CFBundleGetBundleWithIdentifier(GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER);
		if (!bundle)
			NSLog(CFSTR("GrowlInstallationPrompt: could not locate framework bundle (forget about installing Growl); had looked for bundle with identifier '%@'"), GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER);
		else {
			IBNibRef nib = NULL;
			err = CreateNibReferenceWithCFBundle(bundle, CFSTR("GrowlInstallationPrompt-Carbon"), &nib);
			if (err != noErr) {
				NSLog(CFSTR("GrowlInstallationPrompt: could not obtain nib: CreateNibReferenceWithCFBundle(%@, %@) returned %li"), bundle, CFSTR("GrowlInstallationPrompt-Carbon"), (long)err);
			} else {
				WindowRef window = NULL;

				err = CreateWindowFromNib(nib, CFSTR("Installation prompt"), &window);
				DisposeNibReference(nib);

				if (err != noErr) {
					NSLog(CFSTR("GrowlInstallationPrompt: could not obtain window from nib: CreateWindowFromNib(%p, %@) returned %li"), nib, CFSTR("Installation prompt"), (long)err);
				} else {
					OSStatus fillOutTextErr = _fillOutTextInWindow(window, (updateVersion != nil));
					OSStatus fillOutIconErr = _fillOutIconInWindow(window);

					err = (fillOutTextErr != noErr) ? fillOutTextErr : (fillOutIconErr != noErr) ? fillOutIconErr : noErr;
					if (err == noErr) {
						if (updateVersion) {
							//store the update version on the window.
							updateVersion = CFRetain(updateVersion);
							err = SetWindowProperty(window,
													GROWL_SIGNATURE,
													GIPC_UPDATE_VERSION,
													sizeof(updateVersion),
													&updateVersion);
							if (err != noErr)
								NSLog(CFSTR("GrowlInstallationPrompt: SetWindowProperty returned %li"), (long)err);
						}

						EventHandlerUPP handlerUPP = NewEventHandlerUPP(_handleCommandInWindow);

						struct EventTypeSpec types[] = {
							{ .eventClass = kEventClassCommand, .eventKind = kEventCommandProcess },
						};

						EventHandlerRef handler = NULL;
						err = InstallWindowEventHandler(window,
														handlerUPP,
														GetEventTypeCount(types),
														types,
														/*refcon*/ window,
														&handler);
						if (err != noErr)
							NSLog(CFSTR("GrowlInstallationPrompt: InstallWindowEventHandler returned %li"), (long)err);
						else {
							HIViewID chasingArrowsID = { GROWL_SIGNATURE, chasingArrowsIDNumber };
							HIViewRef chasingArrows = NULL;

							//stop and hide the chasing arrows, until the user clicks Install.
							OSStatus chasingArrowsErr = HIViewFindByID(HIViewGetRoot(window), chasingArrowsID, &chasingArrows);
							if (chasingArrowsErr == noErr) {
								Boolean truth = false;
								SetControlData(chasingArrows,
											   kControlEntireControl,
											   kControlChasingArrowsAnimatingTag,
											   sizeof(truth),
											   &truth);
								HIViewSetVisible(chasingArrows, false);
							}

							SelectWindow(window);
							ShowWindow(window);

							err = RunAppModalLoopForWindow(window);
							if (err != noErr)
								NSLog(CFSTR("GrowlInstallationPrompt: RunAppModalLoopForWindow(%p) returned %li"), window, (long)err);

							RemoveEventHandler(handler);
						}
						DisposeEventHandlerUPP(handlerUPP);
					}

					ReleaseWindow(window);
				}
			}
		}
	}
Exemplo n.º 28
0
void
TkMacOSXUpdateClipRgn(
    TkWindow *winPtr)
{
    MacDrawable *macWin;

    if (winPtr == NULL) {
	return;
    }
    macWin = winPtr->privatePtr;
    if (macWin && macWin->flags & TK_CLIP_INVALID) {
	TkWindow *win2Ptr;

	if (Tk_IsMapped(winPtr)) {
	    int rgnChanged = 0;
	    CGRect bounds;
	    HIMutableShapeRef rgn;

	    /*
	     * Start with a region defined by the window bounds.
	     */

	    TkMacOSXWinCGBounds(winPtr, &bounds);
	    rgn = TkMacOSXHIShapeCreateMutableWithRect(&bounds);

	    /*
	     * Clip away the area of any windows that may obscure this window.
	     * For a non-toplevel window, first, clip to the parents visible
	     * clip region. Second, clip away any siblings that are higher in
	     * the stacking order. For an embedded toplevel, just clip to the
	     * container's visible clip region. Remember, we only allow one
	     * contained window in a frame, and don't support any other widgets
	     * in the frame either. This is not currently enforced, however.
	     */

	    if (!Tk_IsTopLevel(winPtr)) {
		TkMacOSXUpdateClipRgn(winPtr->parentPtr);
		if (winPtr->parentPtr) {
		    ChkErr(HIShapeIntersect,
			    winPtr->parentPtr->privatePtr->aboveVisRgn,
			    rgn, rgn);
		}
		win2Ptr = winPtr;
		while ((win2Ptr = win2Ptr->nextPtr)) {
		    if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
			continue;
		    }
		    TkMacOSXWinCGBounds(win2Ptr, &bounds);
		    ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		}
	    } else if (Tk_IsEmbedded(winPtr)) {
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    TkMacOSXUpdateClipRgn(win2Ptr);
		    ChkErr(HIShapeIntersect,
			    win2Ptr->privatePtr->aboveVisRgn, rgn, rgn);
		} else if (tkMacOSXEmbedHandler != NULL) {
		    HIShapeRef visRgn;

		    TkMacOSXCheckTmpQdRgnEmpty();
		    tkMacOSXEmbedHandler->getClipProc((Tk_Window) winPtr,
			    tkMacOSXtmpQdRgn);
		    visRgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn);
		    SetEmptyRgn(tkMacOSXtmpQdRgn);
		    ChkErr(HIShapeIntersect, visRgn, rgn, rgn);
		}

		/*
		 * TODO: Here we should handle out of process embedding.
		 */
	    } else if (winPtr->wmInfoPtr->attributes &
		    kWindowResizableAttribute) {
		HIViewRef growBoxView;
		OSErr err = HIViewFindByID(HIViewGetRoot(
			TkMacOSXDrawableWindow(winPtr->window)),
			kHIViewWindowGrowBoxID, &growBoxView);

		if (err == noErr) {
		    ChkErr(HIViewGetFrame, growBoxView, &bounds);
		    bounds = CGRectOffset(bounds,
			    -winPtr->wmInfoPtr->xInParent,
			    -winPtr->wmInfoPtr->yInParent);
		    ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		}
	    }
	    macWin->aboveVisRgn = HIShapeCreateCopy(rgn);

	    /*
	     * The final clip region is the aboveVis region (or visible region)
	     * minus all the children of this window. If the window is a
	     * container, we must also subtract the region of the embedded
	     * window.
	     */

	    win2Ptr = winPtr->childList;
	    while (win2Ptr) {
		if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
		    win2Ptr = win2Ptr->nextPtr;
		    continue;
		}
		TkMacOSXWinCGBounds(win2Ptr, &bounds);
		ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		rgnChanged = 1;
		win2Ptr = win2Ptr->nextPtr;
	    }

	    if (Tk_IsContainer(winPtr)) {
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    if (Tk_IsMapped(win2Ptr)) {
			TkMacOSXWinCGBounds(win2Ptr, &bounds);
			ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
			rgnChanged = 1;
		    }
		}

		/*
		 * TODO: Here we should handle out of process embedding.
		 */
	    }

	    if (rgnChanged) {
		HIShapeRef diffRgn = HIShapeCreateDifference(
			macWin->aboveVisRgn, rgn);

		if (!HIShapeIsEmpty(diffRgn)) {
		    macWin->visRgn = HIShapeCreateCopy(rgn);
		}
		CFRelease(diffRgn);
	    }
	    CFRelease(rgn);
	} else {
	    /*
	     * An unmapped window has empty clip regions to prevent any
	     * (erroneous) drawing into it or its children from becoming
	     * visible. [Bug 940117]
	     */

	    if (!Tk_IsTopLevel(winPtr)) {
		TkMacOSXUpdateClipRgn(winPtr->parentPtr);
	    } else if (Tk_IsEmbedded(winPtr)) {
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    TkMacOSXUpdateClipRgn(win2Ptr);
		}
	    }
	    macWin->aboveVisRgn = TkMacOSXHIShapeCreateEmpty();
	}
	if (!macWin->visRgn) {
	    macWin->visRgn = HIShapeCreateCopy(macWin->aboveVisRgn);
	}
	macWin->flags &= ~TK_CLIP_INVALID;

#ifdef TK_MAC_DEBUG_CLIP_REGIONS
	TkMacOSXDebugFlashRegion((Drawable) macWin, macWin->visRgn);
#endif /* TK_MAC_DEBUG_CLIP_REGIONS */
    }
}
Exemplo n.º 29
0
static pascal OSStatus MusicBoxEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *userData)
{
    #pragma unused (inHandlerCallRef)

    OSStatus	err, result = eventNotHandledErr;
	WindowRef	tWindowRef = (WindowRef) userData;

	switch (GetEventClass(inEvent))
	{
		case kEventClassCommand:
			switch (GetEventKind(inEvent))
			{
				HICommand	cmd;

				case kEventCommandUpdateStatus:
					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &cmd);
					if (err == noErr && cmd.commandID == 'clos')
					{
						UpdateMenuCommandStatus(false);
						result = noErr;
					}

					break;

				case kEventCommandProcess:
					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nil, sizeof(HICommand), nil, &cmd);
					if (err == noErr)
					{
						HIViewRef	root, c1, c2, c3, c4;
						HIViewID	cid;
						Rect		rct;

						switch (cmd.commandID)
						{
							case 'bar1': so.stereo_switch ^= (1 <<  0);	result = noErr;	break;
							case 'bar2': so.stereo_switch ^= (1 <<  1);	result = noErr;	break;
							case 'bar3': so.stereo_switch ^= (1 <<  2);	result = noErr;	break;
							case 'bar4': so.stereo_switch ^= (1 <<  3);	result = noErr;	break;
							case 'bar5': so.stereo_switch ^= (1 <<  4);	result = noErr;	break;
							case 'bar6': so.stereo_switch ^= (1 <<  5);	result = noErr;	break;
							case 'bar7': so.stereo_switch ^= (1 <<  6);	result = noErr;	break;
							case 'bar8': so.stereo_switch ^= (1 <<  7);	result = noErr;	break;
							case 'bar9': so.stereo_switch ^= (1 <<  8);	result = noErr;	break;
							case 'bara': so.stereo_switch ^= (1 <<  9);	result = noErr;	break;
							case 'barb': so.stereo_switch ^= (1 << 10);	result = noErr;	break;
							case 'barc': so.stereo_switch ^= (1 << 11);	result = noErr;	break;
							case 'bard': so.stereo_switch ^= (1 << 12);	result = noErr;	break;
							case 'bare': so.stereo_switch ^= (1 << 13);	result = noErr;	break;
							case 'barf': so.stereo_switch ^= (1 << 14);	result = noErr;	break;
							case 'bar0': so.stereo_switch ^= (1 << 15);	result = noErr;	break;

							case 'Paus':
								mboxPause = !mboxPause;
								S9xSetSoundMute(mboxPause);
								result = noErr;
								break;

							case 'Tr_i':
								showIndicator = !showIndicator;

								root = HIViewGetRoot(tWindowRef);
								cid.id = 0;

								cid.signature = 'Pane';
								HIViewFindByID(root, cid, &c1);
								HIViewSetVisible(c1, false);
								cid.signature = 'iMaG';
								HIViewFindByID(root, cid, &c2);
								HIViewSetVisible(c2, false);
								cid.signature = 'rCTL';
								HIViewFindByID(root, cid, &c3);
								HIViewSetVisible(c3, false);
								cid.signature = 'bCTL';
								HIViewFindByID(root, cid, &c4);
								HIViewSetVisible(c4, false);

								GetWindowBounds(tWindowRef, kWindowStructureRgn,  &rct);
								rct.bottom = rct.top + (showIndicator ? mbxOpenedHeight : mbxClosedHeight);

								err = TransitionWindow(tWindowRef, kWindowSlideTransitionEffect, kWindowResizeTransitionAction, &rct);

								HIViewSetVisible(c1, true);
								HIViewSetVisible(c2, true);
								HIViewSetVisible(c3, true);
								HIViewSetVisible(c4, true);

								result = noErr;
								break;

							case 'DONE':
								QuitAppModalLoopForWindow(tWindowRef);
								result = noErr;
								break;

							case 'HEAD':
								showIndicator = !showIndicator;
								SPCPlayDefrost();
								showIndicator = !showIndicator;
								result = noErr;
								break;

							case 'S_EF':
								HideWindow(tWindowRef);
								showIndicator = !showIndicator;
								ConfigureSoundEffects();
								showIndicator = !showIndicator;
								ShowWindow(tWindowRef);
								result = noErr;
						}
					}
			}
	}

	return result;
}
Exemplo n.º 30
0
void MusicBoxDialog(void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	if (!cartOpen)
		return;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		CFURLRef	iconURL;
		FSRef		iconFSRef;
		IconRef		actIcon;
		WindowRef	tWindowRef;

		actIcon = nil;

		if (musicboxmode == kMBXSoundEmulation)
			iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil);
		else
			iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil);

		if (iconURL)
		{
			if (CFURLGetFSRef(iconURL, &iconFSRef))
				err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon);

			CFRelease(iconURL);
		}

		err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		mboxRef, paneRef;
			EventHandlerUPP		mboxUPP, paneUPP;
			EventLoopTimerRef	timeRef;
			EventLoopTimerUPP	timeUPP;
			EventTypeSpec		mboxEvents[] = { { kEventClassCommand, kEventCommandProcess      },
												 { kEventClassCommand, kEventCommandUpdateStatus } },
								paneEvents[] = { { kEventClassControl, kEventControlDraw         } };
			CFStringRef			sref;
			CGDataProviderRef	prov;
			CGImageRef			ipng;
			CFURLRef			iurl;
			HIViewRef			ctl, root, paneView, imageView, contentView;
			HIViewID			cid;
			HIRect				bounds;
			Rect				windowRect, barRect;
			char				drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];

			mboxPause = false;
			mbxFinished = false;
			showIndicator = false;
			so.stereo_switch = ~0;

			for (int i = 0; i < MAC_MAX_PLAYERS; i++)
				controlPad[i] = 0;

			switch (drawingMethod)
			{
				case kDrawingOpenGL:
					Settings.OpenGLEnable = true;
					break;

				case kDrawingDirect:
				case kDrawingBlitGL:
					Settings.OpenGLEnable = false;
			}

			// 107's enhanced SPC player

			root = HIViewGetRoot(tWindowRef);
			cid.id = 0;

			if (musicboxmode == kMBXSoundEmulation)
			{
				cid.signature = 'HEAD';
				HIViewFindByID(root, cid, &ctl);
				EnableControl(ctl);

				StoredAPU          = new SAPU;
				StoredAPURegisters = new SAPURegisters;
				StoredSoundData    = new SSoundData;
				StoredIAPURAM      = new uint8 [0x10000];

				SPCPlayFreeze();
			}
			else
				MusicBoxForceFreeze();

			cid.signature = 'Kart';
			HIViewFindByID(root, cid, &ctl);
			SetStaticTextTrunc(ctl, truncEnd, false);
			_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
			sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING);
			if (sref)
			{
				SetStaticTextCFString(ctl, sref, false);
				CFRelease(sref);
			}

			ipng = nil;

			iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil);
			if (iurl)
			{
				prov = CGDataProviderCreateWithURL(iurl);
				if (prov)
				{
					ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault);
					CGDataProviderRelease(prov);
				}

				CFRelease(iurl);
			}

			imageView = nil;

			if (ipng)
			{
				HIViewFindByID(root, kHIViewWindowContentID, &contentView);

				err = HIImageViewCreate(ipng, &imageView);
				if (err == noErr)
				{
					bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng));
					HIViewSetFrame(imageView, &bounds);
					HIImageViewSetOpaque(imageView, false);
					HIViewSetVisible(imageView, true);
					HIViewAddSubview(contentView, imageView);
					cid.signature = 'iMaG';
					SetControlID(imageView, &cid);
				}

				CGImageRelease(ipng);
			}

			cid.signature = 'Pane';
			HIViewFindByID(root, cid, &paneView);
			HIViewGetBounds(paneView, &bounds);
			mbxViewWidth  = bounds.size.width;
			mbxViewHeight = bounds.size.height;
			mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0;
			mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0;

			if (imageView)
			{
				HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView);
				HIViewAddSubview(imageView, paneView);
			}

			cid.signature = 'Tr_i';
			HIViewFindByID(root, cid, &ctl);
			HIViewGetFrame(ctl, &bounds);
			GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect);
			mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top);

			GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);
			mbxOpenedHeight = windowRect.bottom - windowRect.top;

			windowRect.bottom = windowRect.top + mbxClosedHeight;
			SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);

			paneUPP = NewEventHandlerUPP(IndicatorEventHandler);
			err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef);

			mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler);
			err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef);

			timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler);
			err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef);

			MusicBoxInitIndicator();

			stopNow = false;
			MacStartSound();
			pthread_create(&mbxThread, nil, SoundTask, nil);

			MoveWindowPosition(tWindowRef, kWindowMusicBox, true);
			GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect);
			if (windowRect.bottom - windowRect.top > mbxClosedHeight)
			{
				showIndicator = true;
				SetControl32BitValue(ctl, 1);	// Tr_i
			}

			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);

			SaveWindowPosition(tWindowRef, kWindowMusicBox);

			stopNow = true;
			pthread_join(mbxThread, nil);
			MacStopSound();

			err = RemoveEventLoopTimer(timeRef);
			DisposeEventLoopTimerUPP(timeUPP);

			err = RemoveEventHandler(mboxRef);
			DisposeEventHandlerUPP(mboxUPP);

			err = RemoveEventHandler(paneRef);
			DisposeEventHandlerUPP(paneUPP);

			ReleaseWindow(tWindowRef);

			so.stereo_switch = ~0;

			mbxFinished = true;

			if (musicboxmode == kMBXSoundEmulation)
			{
 				SPCPlayDefrost();

				delete    StoredAPU;
				delete    StoredAPURegisters;
				delete    StoredSoundData;
				delete [] StoredIAPURAM;
			}
			else
				MusicBoxForceDefrost();

			Settings.OpenGLEnable = false;
		}

		if (actIcon)
			err = UnregisterIconRef('~9X~', 'micn');

		DisposeNibReference(nibRef);
	}
}