Exemple #1
0
static pascal OSStatus NPServerDialogEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	OSStatus	err, result = eventNotHandledErr;
	WindowRef	tWindowRef = (WindowRef) inUserData;

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

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

					break;

				case kEventCommandProcess:
					err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
					if (err == noErr)
					{
						switch (tHICommand.commandID)
						{
							case 'OKAY':
								HIViewRef	ctl, root;
								HIViewID	cid;

								root = HIViewGetRoot(tWindowRef);
								cid.id = 0;
								cid.signature = 'OKAY';
								HIViewFindByID(root, cid, &ctl);
								DeactivateControl(ctl);
								cid.signature = 'CNSL';
								HIViewFindByID(root, cid, &ctl);
								DeactivateControl(ctl);

								npserver.dialogprocess = kNPSDialogProcess;
								result = noErr;
								break;

							case 'CNSL':
								npserver.dialogprocess = kNPSDialogCancel;
								result = noErr;
								break;
						}
					}

					break;
			}

			break;
	}

	return (result);
}
Exemple #2
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);
	}
}
//-------------------------------------------------------------------------------------
//	Prompt
//-------------------------------------------------------------------------------------
//	Put up a modal panel and request some text.
//
CFStringRef
Prompt( CFStringRef inPrompt, CFStringRef inDefaultText )
{
    IBNibRef 			nibRef;
	OSStatus			err;
	WindowRef			window;
	EventTypeSpec		kEvents[] = { { kEventClassCommand, kEventCommandProcess } };
	PanelInfo			info;
	HIViewRef			view;
	
	info.window = window;
	info.string = NULL;

    err = CreateNibReference( CFSTR( "main" ), &nibRef );
    require_noerr( err, CantGetNibRef );
	
	err = CreateWindowFromNib( nibRef, CFSTR( "Prompt" ), &window );
	require_noerr( err, CantCreateWindow );
	
	DisposeNibReference( nibRef );

	if ( inPrompt )
	{
		HIViewFindByID( HIViewGetRoot( window ), kPromptLabelID, &view );
		SetControlData( view, 0, kControlStaticTextCFStringTag, sizeof( CFStringRef ), &inPrompt );
	}
	
	HIViewFindByID( HIViewGetRoot( window ), kTextFieldID, &view );

	if ( inDefaultText )
		SetControlData( view, 0, kControlEditTextCFStringTag, sizeof( CFStringRef ), &inDefaultText );	

	SetKeyboardFocus( window, view, kControlFocusNextPart );

	InstallWindowEventHandler( window, InputPanelHandler, GetEventTypeCount( kEvents ),
				kEvents, &info, NULL );	
	
	ShowWindow( window );
	
	info.window = window;

	RunAppModalLoopForWindow( window );

	DisposeWindow( window );

CantCreateWindow:
CantGetNibRef:
	return info.string;
}
Exemple #4
0
static pascal OSStatus AspectRatioTextEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	OSStatus	err, result = eventNotHandledErr;
	HIViewRef	ctl, slider;
	HIViewID	cid;
	float		w, h, v;
	int			iw, ih;

	err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &ctl);
	if (err == noErr)
	{
		cid.signature = 'grap';
		cid.id = iNibGAspectRatio;
		HIViewFindByID(HIViewGetSuperview(ctl), cid, &slider);

		GetGameDisplay(&iw, &ih);
		w = (float) iw;
		h = (float) ih;

		v = (float) SNES_WIDTH / (float) SNES_HEIGHT * h;
		macAspectRatio = (int) (((4.0f / 3.0f) * h - v) / (w - v) * 10000.0f);

		SetControl32BitValue(slider, macAspectRatio);

		result = noErr;
	}

	return (result);
}
            void timerCallback()
            {
                // Wait for the moment when PT deigns to allow our view to
                // take up its actual location (see rant above)
                HIViewRef content = 0;
                HIViewFindByID (HIViewGetRoot ((WindowRef) hostWindow), kHIViewWindowContentID, &content);
                HIPoint p = { 0.0f, 0.0f };

                HIViewRef v = HIViewGetFirstSubview (parentView);
                HIViewConvertPoint (&p, v, content);

                if (p.y > 12)
                {
                    if (p.x != titleW || p.y != titleH)
                    {
                        GrafPtr oldport;
                        GetPort (&oldport);
                        SetPort (owner->GetViewPort());
                        SetOrigin (-titleW, -titleH);
                        SetPort (oldport);
                    }

                    HIViewRef v = HIViewGetFirstSubview (parentView);
                    SetControlSupervisor (v, 0);
                    stopTimer();

                    forcedRepaintTimer = new RepaintCheckTimer (*this);
                }
            }
Exemple #6
0
static pascal OSStatus InputRateTextEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	OSStatus	err, result = eventNotHandledErr;
	HIViewRef	ctl, slider;
	HIViewID	cid;
	SInt32		value;
	char		num[10];

	err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &ctl);
	if (err == noErr)
	{
		cid.signature = 'snd_';
		cid.id = iNibSInputRate;
		HIViewFindByID(HIViewGetSuperview(ctl), cid, &slider);
		value = GetControl32BitValue(slider);

		value /= 50;
		value *= 50;
		if (value > 33000)
			value = 33000;
		if (value < 31000)
			value = 31000;

		SetControl32BitValue(slider, value);
		sprintf(num, "%ld", value);
		SetEditTextCStr(ctl, num, true);

		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
Exemple #8
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, kCFStringEncodingUTF8);
			if (ref)
			{
				SetStaticTextCFString(ctl, ref, false);
				CFRelease(ref);
			}
			else
				SetStaticTextCFString(ctl, CFSTR("unknown"), false);
		}
	}

	err = ShowSheetWindow(sRef, mRef);
}
//-------------------------------------------------------------------------------------
//	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;
}
Exemple #10
0
static void SelectTabPane (HIViewRef tabControl, SInt16 index)
{
	HIViewRef	sup, userPane, selectedPane = NULL;
	HIViewID	cid;

	lastTabIndex = index;

	sup = HIViewGetSuperview(tabControl);
	cid.signature = 'tabs';

	for (int i = 1; i < tabList[0] + 1; i++)
	{
		cid.id = tabList[i];
		HIViewFindByID(sup, cid, &userPane);

		if (i == index)
			selectedPane = userPane;
		else
			HIViewSetVisible(userPane, false);
	}

	if (selectedPane != NULL)
		HIViewSetVisible(selectedPane, true);

	HIViewSetNeedsDisplay(tabControl, true);
}
Exemple #11
0
static pascal OSStatus MacOSXDialogCommandProcess(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* inUserData)
{
	HICommand aCommand;
	OSStatus status = eventNotHandledErr;
	
	GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand);
	
	switch (aCommand.commandID)
	{
		case kHICommandOK:
			// we got a valid click on the OK button so let's quit our local run loop
			QuitAppModalLoopForWindow((WindowRef) inUserData);
			break;
		case 'CBED':
		{
			// we still enable or disable the custom spot view depending on whether the box is checked or not
			HIViewRef checkBox = ((HICommandExtended *)&aCommand)->source.control;
			SInt32 enable = GetControl32BitValue(checkBox);
			HIViewID hidcsv = {0, 13};
			HIViewRef customSpotView;
			HIViewFindByID(HIViewGetRoot(GetControlOwner(checkBox)), hidcsv, &customSpotView);
			if (enable)
				ActivateControl(customSpotView);
			else
				DeactivateControl(customSpotView);
			HIViewSetNeedsDisplay(customSpotView, true);
		}
			break;
	}
	
	return status;
}
/*****************************************************
*
* Handle_PostLittleArrowsClick(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to update the static text with the current value of the little arrows control
*
* 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_PostLittleArrowsClick(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
	OSStatus status = eventNotHandledErr;
	ControlRef littleArrows = (ControlRef)inUserData;

	SInt32 value = GetControl32BitValue(littleArrows);
	
	HIViewID staticTextID = { 'STTC', 100 };
	HIViewRef staticText;
	status = HIViewFindByID(HIViewGetRoot(GetControlOwner(littleArrows)), staticTextID, &staticText);
	require_noerr(status, HIViewFindByID);
	require(littleArrows != NULL, HIViewFindByID);
	
	CFStringRef theValueStr = CFStringCreateWithFormat(NULL, NULL, CFSTR("%ld"), value);
	require(theValueStr != NULL, CFStringCreateWithFormat);

	HIViewSetText(staticText, theValueStr);
	CFRelease(theValueStr);

CFStringCreateWithFormat:
HIViewFindByID:

	if (status == noErr)
		status = eventNotHandledErr;

	return status;
}   // Handle_PostLittleArrowsClick
Exemple #13
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;
}
Exemple #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);
	}
}
//---------------------------------------------------------------------
// 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;
}
Exemple #16
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);
}
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;
  }
}
Exemple #18
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);
}
Exemple #19
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;
}
Exemple #20
0
OSStatus
GetTextViewFromWindow( WindowRef window, HIViewRef& textView )
{
	OSStatus status = paramErr;
	if( window != NULL )
	{
		status = HIViewFindByID(HIViewGetRoot(window), kTextViewControlID, &textView);
		check_noerr( status );
	}
	return status;
}
Exemple #21
0
//-----------------------------------------------------------------------------------
//	ValueChanged
//-----------------------------------------------------------------------------------
void TMultiPane::ValueChanged()
{
	HIViewRef subPane;
	SInt32 value = GetValue();
	SInt32 min = GetMinimum();
	SInt32 max = GetMaximum();

	for (SInt32 i = min; i <= max; ++i) {
		HIViewID id = { kSubPanelSignature + mID, i };
		OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane);
		if (result == noErr) {
			HIViewSetVisible( subPane, false);
                }
	}
	HIViewID id = { kSubPanelSignature + mID, value };
	OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane);
	if (result == noErr) {
		HIViewSetVisible( subPane, true);
        }  
	Invalidate();
}
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;

}
Exemple #23
0
static pascal void AutofireSliderActionProc (HIViewRef slider, HIViewPartCode partCode)
{
	HIViewRef	ctl;
	HIViewID	cid;
	char		num[10];

	GetControlID(slider, &cid);
	cid.signature = 'Num_';
	HIViewFindByID(HIViewGetSuperview(slider), cid, &ctl);

	sprintf(num, "%ld", GetControl32BitValue(slider));
	SetStaticTextCStr(ctl, num, true);
}
Exemple #24
0
static void AutofireReadAllSettings (int player, HIViewRef parent)
{
	HIViewRef	ctl;
	HIViewID	cid;
	char		num[10];

	AutofireReadSetting(player * 1,    autofireRec[player - 1].buttonMask, parent);
	AutofireReadSetting(player * 11,   autofireRec[player - 1].toggleMask, parent);
	AutofireReadSetting(player * 111,  autofireRec[player - 1].tcMask,     parent);
	AutofireReadSetting(player * 1111, autofireRec[player - 1].invertMask, parent);

	cid.id = player;

	cid.signature = 'Num_';
	HIViewFindByID(parent, cid, &ctl);
	sprintf(num, "%ld", autofireRec[player - 1].frequency);
	SetStaticTextCStr(ctl, num, false);

	cid.signature = 'Slid';
	HIViewFindByID(parent, cid, &ctl);
	SetControl32BitValue(ctl, autofireRec[player - 1].frequency);
}
Exemple #25
0
static pascal void InputRateSliderActionProc (HIViewRef slider, HIViewPartCode partCode)
{
	HIViewRef	ctl;
	HIViewID	cid;
	char		num[10];

	cid.signature = 'snd_';
	cid.id = iNibSInputRateText;
	HIViewFindByID(HIViewGetSuperview(slider), cid, &ctl);

	sprintf(num, "%ld", GetControl32BitValue(slider));
	SetStaticTextCStr(ctl, num, true);
}
Exemple #26
0
//-----------------------------------------------------------------------------------
//	Draw
//-----------------------------------------------------------------------------------
//	The fun part of the control
//
void TMultiPane::Draw(
					  RgnHandle				inLimitRgn,
					  CGContextRef			inContext )
{
    bool compositing = (inContext != 0);
	if (!compositing) {
            HIViewRef subPane;
            TViewNoCompositingCompatible::Draw(inLimitRgn,inContext); // For background handling
		// First look for 9999 : this is our background if we have one
		HIViewID id = { kSubPanelSignature + mID, 9999 };
		OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane);
		if (result == noErr) {
			Draw1Control( subPane);
		} else {
			// Else, redraw just the subpane
			HIViewID id = { kSubPanelSignature + mID, GetValue() };
			OSStatus result = HIViewFindByID(GetViewRef(), id, &subPane);
			if (result == noErr) {
				Draw1Control( subPane);
			}
		}
	}
}
Exemple #27
0
static void AutofireWriteAllSettings (int player, HIViewRef parent)
{
	HIViewRef	ctl;
	HIViewID	cid;

	AutofireWriteSetting(player * 1,    &(autofireRec[player - 1].buttonMask), parent);
	AutofireWriteSetting(player * 11,   &(autofireRec[player - 1].toggleMask), parent);
	AutofireWriteSetting(player * 111,  &(autofireRec[player - 1].tcMask),     parent);
	AutofireWriteSetting(player * 1111, &(autofireRec[player - 1].invertMask), parent);

	cid.id = player;
	cid.signature = 'Slid';
	HIViewFindByID(parent, cid, &ctl);
	autofireRec[player - 1].frequency = GetControl32BitValue(ctl);
}
/*
	Ask the content view for its frame metrics then position the content
	view based on those metrics.
*/
OSStatus HandleStarFrameBoundsChanged(
	EventHandlerCallRef inCallRef,
	EventRef inEvent,
	StarFrameData* frameData)
{
	OSStatus retVal = eventNotHandledErr;
	HIViewRef contentView = NULL;

	// If we can find our content view change it to match the new bounds
	verify_noerr(HIViewFindByID(frameData->hiSelf, kHIViewWindowContentID, &contentView));
	if(NULL != contentView) {
		retVal = PositionContentViewWithMetrics(frameData->hiSelf, contentView);
	}

	return retVal;
}
Exemple #29
0
static pascal void LittleArrowsActionProc (HIViewRef arrows, HIViewPartCode partCode)
{
	HIViewRef	ctl;
	HIViewID	cid = { 'msc2', iNibMTurboSkipText };
	char		num[8];

	if (partCode == kControlUpButtonPart)
		SetControl32BitValue(arrows, GetControl32BitValue(arrows) + 1);
	else
	if (partCode == kControlDownButtonPart)
		SetControl32BitValue(arrows, GetControl32BitValue(arrows) - 1);

	HIViewFindByID(HIViewGetSuperview(arrows), cid, &ctl);
	sprintf(num, "%ld", GetControl32BitValue(arrows));
	SetStaticTextCStr(ctl, num, true);
}
Exemple #30
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);
	}
}