int init_macintosh( void)
{
	static int initdone = 0;
	Handle menuBar;
	long attributes;

	/* semaphore required for preemptive threads */
	if( initdone) return initdone == 1;
	initdone = -1;

	/* should I check for MLNK resource too as launch-filtering is done based on it? */
	/* too late--since I'm running there likely wasn't a problem (this time anyway). */
	
	menuBar = GetNewMBar(rMenuBar);
	if( menuBar){
		SetMenuBar(menuBar);
		DisposeHandle(menuBar);
	}else{
		MenuHandle am, fm, em;
		am = NewMenu( mApple, (unsigned char*)"\001\024");
		fm = NewMenu( mFile, (unsigned char*)"\004File");
		em = NewMenu( mEdit, (unsigned char*)"\004Edit");
		if( !am || !fm || !em) return 0;
		AppendMenu( am, (unsigned char*)"\022About MathLink\252\311;-");
                DisableMenuItem(am, 0);
		InsertMenu( am, 0);
		AppendMenu( fm, (unsigned char*)"\006Quit/Q");
		InsertMenu( fm, 0);
		AppendMenu( em, (unsigned char*)"\043Undo/Z;-;Cut/X;Copy/C;Paste/V;Clear");
                DisableMenuItem(em, 0);
		InsertMenu( em, 0);
	}

	AppendResMenu( GetMenuHandle(mApple), 'DRVR');
	set_about_item();
	DrawMenuBar();
	about_filter_upp =  NewModalFilterUPP( about_filter);
	outline_hook_upp = NewUserItemUPP( outline_hook);
	if( Gestalt( gestaltAppleEventsAttr, &attributes) == noErr
	&& ((1 << gestaltAppleEventsPresent) & attributes)){
		handle_core_ae_upp = NewAEEventHandlerUPP( handle_core_ae);
		(void) AEInstallEventHandler( kCoreEventClass, typeWildCard, handle_core_ae_upp, 0, false);
	}else{
		return 0; /* this may be too strong since I am, after all, running. */
	}

	initdone = 1;
	return initdone == 1;
}
/* 辅助函数-Log信息台-配置右键弹出菜单 */
void showLogBoxRightClickMenu(int pHdl, int ctrlID, int xPoint, int yPoint){
	int menuBar = NewMenuBar(0);
	int menuIDForPop = NewMenu(menuBar, "" , -1);
	NewMenuItem(menuBar, menuIDForPop, "Save Log to File", -1, 0, logBoxRightClickMenuCallback, NULL);
	NewMenuItem(menuBar, menuIDForPop, "Clear Log Console", -1, 0, logBoxRightClickMenuCallback, NULL);
	RunPopupMenu(menuBar, menuIDForPop, 
		pHdl, yPoint, xPoint, 0, 0, 0, 0);
}
Example #3
0
static int ReadMenu(CurPos &cp, const char *MenuName) {
    unsigned char obj;
    unsigned short len;

    int menu = -1, item = -1;

    menu = NewMenu(MenuName);

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_ITEM:
            {
                if (len == 0) {
                    item = NewItem(menu, 0);
                } else {
                    const char *s = GetCharStr(cp, len);
                    int Cmd;
                    if (s == 0) return -1;
                    item = NewItem(menu, s);
                    if ((obj = GetObj(cp, len)) != CF_MENUSUB) return -1;
                    if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
                    Menus[menu].Items[item].Cmd = Cmd + 65536;
                }
            }
            break;
        case CF_SUBMENU:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_NORMAL);
            }
            break;

        case CF_SUBMENUCOND:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_CONDITIONAL);
            }
            break;

        case CF_END:
            return 0;
        default:
            return -1;
        }
    }
    return -1;
}
Example #4
0
void MenuModule::told_view_newmenu(){
	
	
	//QPoint pos =this->pos()+this->modebutton->pos();
	
	//pos.setY(pos.y()+34);
	QPoint btn_pos = modebutton->pos();
	QPoint arrow_pos_to_menumodule = btn_pos + QPoint(0, modebutton->height());
//	pCurCanvasManagement->getView()->ModuleMenuPressed(parentWidget()->mapToGlobal(arrow_pos_to_menumodule), moduletype);
	emit NewMenu(this->moduletype, arrow_pos_to_menumodule);
}
extern pascal MenuRef NewSystemMenu(ConstStr255Param title)
	// See comment in interface part.
{
	MenuRef result;
	THz oldZone;
	
	assert(title != NULL);
	
	oldZone = SetSystemZone();
	result = NewMenu(0, title);
	assert(result == NULL || ValidateSystemMenuRef(result));
	SetZone(oldZone);
	return result;
}
/* 辅助函数-为图表创建右键弹出菜单(只对Graph类的控件有效) */
void showMenuPopup(int pHdl, int ctrlID, int xPoint, int yPoint){
	int i = getGraphIndex(pHdl, 0);
	int menuBar = NewMenuBar(0);
	int menuIDForPop = NewMenu(menuBar, "" , -1);
	char openStr[25]="Open Analysis Window";
	char closeStr[25]="Close Analysis Window";
	char pauseStr[20] = "Pause";
	char startStr[20] = "Start";
	if(tabFlag == 0){
		NewMenuItem(menuBar, menuIDForPop, signalShowingStat[i]>0?pauseStr:startStr, -1, 0, menuPopupCallback, NULL);
		NewMenuItem(menuBar, menuIDForPop, PopPanels[i]>0?closeStr:openStr, -1, 0, menuPopupCallback, NULL);
	}else{
		NewMenuItem(menuBar, menuIDForPop, signalShowingStat[i]>0?pauseStr:startStr, -1, 0, menuPopupCallback, NULL);
		NewMenuItem(menuBar, menuIDForPop, PopPanels[i]>0?closeStr:openStr, -1, 0, menuPopupCallback, NULL);
	}//if-else
	RunPopupMenu(menuBar, menuIDForPop, 
		pHdl, yPoint, xPoint, 0, 0, 0, 0);
	///DisplayPanel(menuPopupHdl);
}
EXPORT(sqInt) primitiveNewMenu(void) {
	MenuHandle menuHandle;
	ConstStr255Param constStr255;
	sqInt menuID;
	char *menuTitle;
	sqInt _return_value;

	menuID = interpreterProxy->stackIntegerValue(1);
	interpreterProxy->success(interpreterProxy->isBytes(interpreterProxy->stackValue(0)));
	menuTitle = ((char *) (interpreterProxy->firstIndexableField(interpreterProxy->stackValue(0))));
	if (interpreterProxy->failed()) {
		return null;
	}
	constStr255 = ((ConstStr255Param) menuTitle);
	menuHandle = NewMenu(menuID,constStr255);
	_return_value = interpreterProxy->positive64BitIntegerFor(((long) menuHandle));
	if (interpreterProxy->failed()) {
		return null;
	}
	interpreterProxy->popthenPush(3, _return_value);
	return null;
}
Example #8
0
/*	CreatePopMenu(theDialog, popupItemNumber, titleItemNumber, itemList, initialItem)

	Creates a popup menu in the specified dialog.
	
	popupItemNumber is the dialog item number for the popup menu.
	On Macintosh, this must be a CNTL item representing a popup button control.
	See notes above under "About Carbon Popup Menus".
	
	titleItemNumber is the dialog item number for the static text title for the popup menu.
	Prior to XOP Toolkit 5, on Macintosh, this item was highlighted when the user
	clicked on the popup menu. As of XOP Toolkit 5, it is no longer used by must be
	present for backward compatibility.
	
	itemList is a semicolon-separated list of items to insert into the menu.
	For example, "Red;Green;Blue".
	
	initialItem is the 1-based number of the item in the popup menu that should
	be initially selected.
	
	The menu handle allocated here will be disposed when you call KillPopMenus
	at the end of the dialog.
	
	In contrast to Macintosh menu manager routines, this routine does not
	treat any characters as meta-characters.

	Thread Safety: CreatePopMenu is not thread-safe.
*/
int
CreatePopMenu(DialogPtr theDialog, int popupItemNumber, int titleItemNumber, const char* itemList, int initialItem)
{
	MenuHandle mH;
	ControlHandle controlH;
	int menuID;
	int i;
	int err;

	if (gPopMenuInfoP == NULL) {
		// gPopMenuInfoP is used by KillPopMenusAfterDialogIsKilled to keep track of which menu IDs are free for use with popup menus.
		gPopMenuInfoP = (XOPPopMenuInfo*)NewPtrClear(MAX_POPUP_MENUS*(sizeof(XOPPopMenuInfo)));	// Assume never more than MAX_POPUP_MENUS popups.
		if (gPopMenuInfoP == NULL)
			return NOMEM;
	}
	
	if (err = XOPGetDialogItemAsControl(theDialog, popupItemNumber, &controlH))
		return err;

	/*	Find a free menu ID. Menus IDs from 1100-1199 are reserved for XOPs.
		This routine uses the range 1150 to 1199 for dialog popup menus.
	*/
	mH = NULL;
	menuID = FIRST_POPUP_MENU_ID;
	for(i=0; i<MAX_POPUP_MENUS; i++) {
		if (gPopMenuInfoP[i].menuID == 0) {
			char menuName[64];
			sprintf(menuName, "Menu %d", menuID);
			{
				unsigned char temp[256];
				CopyCStringToPascal(menuName, temp);
				mH = NewMenu(menuID, temp);
			}
			if (mH == NULL)
				return NOMEM;
			break;
		}
		menuID += 1;
	}
	if (mH == NULL)					// Ran out of menu IDs.
		return -1;					// Very unlikely.
	
	XOPFillMenuNoMeta(mH, 0, itemList);
	
	/*	Tell the control what menu handle it should use. According to Eric Schlegel from Apple,
		the menu does not need to be in the menu list. If this succeeds, the control now owns
		the menu handle and will dispose it.
	*/
	err = SetControlData(controlH, kControlMenuPart, kControlPopupButtonOwnedMenuRefTag, sizeof(mH), &mH);
	if (err!=0 || mH!=GetControlPopupMenuHandle(controlH)) {
		/*	If here, you are probably need to double-check your popupItemNumber
			or your CNTL resource or your DITL resource.
		*/
		DisposeMenu(mH);
		return err ? err:-1;		// Should never happen.
	}

	SetPopMenuMax(theDialog, popupItemNumber);
	
	// Store the menu ID so we can tell what menu ID is free the next time we create a popup menu.
	gPopMenuInfoP[menuID-FIRST_POPUP_MENU_ID].theDialog = theDialog;
	gPopMenuInfoP[menuID-FIRST_POPUP_MENU_ID].menuID = menuID;
	
	// Set the initially-selected item.
	SetPopItem(theDialog, popupItemNumber, initialItem);
	
	return 0;
}
Example #9
0
//callback associated with the controls on a panel that is loaded at run-time
int CVICALLBACK RuntimeCtrlCB (int panelHandle, int control, int event, void *callbackdata, int eventData1, int eventData2)
{
	char childWindowMenu[MAX_STRING_SIZE];
	int isChildPanel;
	int numCtrls;
	int menuBarHandle;
	int menuID;
	int ctrlType;
	char ctrlString[MAX_STRING_SIZE];
	char menuString[MAX_STRING_SIZE];
	CTRLSTRUCT* ctrlArray = callbackdata;
	int releaseID =0;

	switch(event)
	{
		case EVENT_RIGHT_CLICK:
			if(ctrlArray == NULL)
				return 0;

			menuBarHandle = NewMenuBar (0);
			menuID = NewMenu(menuBarHandle,"",-1);

			GetCtrlAttribute(panelHandle,control,ATTR_CTRL_STYLE,&ctrlType);

			GetStyleNameForCtrl(ctrlType, ctrlString);
			sprintf(menuString,"Control Type: %s",ctrlString);

			NewMenuItem(menuBarHandle,menuID,menuString,-1,0,NULL,NULL);

			GetPanelAttribute(panelHandle,ATTR_NUM_CTRLS,&numCtrls);

			strcpy(ctrlString, FindCtrlCBName(ctrlArray,control,numCtrls));

			sprintf(menuString,"Ctrl Callback: %s",strlen(ctrlString)==0?"<null>":ctrlString);

			NewMenuItem(menuBarHandle,menuID,menuString,-1,0,NULL,NULL);

			InsertSeparator(menuBarHandle, menuID, -1);
			GetPanelAttribute (panelHandle, ATTR_PANEL_PARENT, &isChildPanel);

			if(!isChildPanel)
			   sprintf(childWindowMenu,"Confine Window");
			else
			   sprintf(childWindowMenu,"Release Window");

			releaseID = NewMenuItem (menuBarHandle, menuID, childWindowMenu, -1, 0, 0, 0);

			if(releaseID == RunPopupMenu(menuBarHandle,menuID,panelHandle,eventData1,eventData2,0,0,0,0))
			{
			   SetPanelParenthood(panelHandle,isChildPanel);
			}

			DiscardMenu(menuBarHandle,menuID);
			DiscardMenuBar(menuBarHandle);

			//indicate to the panel that this is a control callback
			gbCtrlCB = 1;
 		break;
	}

	return 0;
}