void
SCFeedbackDirector::UpdateExtraMenu()
{
    JXTextMenu* menu = itsOutputFn->GetExtraMenu();
    menu->EnableItem(itsBuildH0Index);
    menu->EnableItem(itsBuildHinfIndex);
}
示例#2
0
JXTextMenu*
CBApp::CreateHelpMenu
	(
	JXMenuBar*			menuBar,
	const JCharacter*	idNamespace
	)
{
	JXTextMenu* menu = menuBar->AppendTextMenu(kHelpMenuTitleStr);
	menu->SetMenuItems(kHelpMenuStr, idNamespace);
	menu->SetUpdateAction(JXMenu::kDisableNone);

	menu->SetItemImage(kHelpTOCCmd,    jx_help_toc);
	menu->SetItemImage(kHelpWindowCmd, jx_help_specific);

	return menu;
}
void
TestWidget::BuildXlsfontsMenu
	(
	JXMenu*			owner,
	JXContainer*	enclosure
	)
{
	JXTextMenu* menu = jnew JXTextMenu(owner, kXlsfontsMenuCmd, enclosure);
	assert( menu != NULL );
	menu->SetUpdateAction(JXMenu::kDisableNone);

	JPtrArray<JString> fontList(JPtrArrayT::kDeleteAll);
	GetXFontManager()->GetXFontNames(JRegex("^-.*-(courier|helvetica)-.*$"),
									   &fontList);
	const JSize fontCount = fontList.GetElementCount();
	for (JIndex i=1; i<=fontCount; i++)
		{
		JString* fontName = fontList.NthElement(i);
		menu->AppendItem(*fontName);
		}

	menu->AppendItem("I wish Netscape's bookmark list would scroll like this!!!");
	const JSize count = menu->GetItemCount();
	menu->SetItemFontStyle(count, JFontStyle(kJTrue, kJFalse, 0, kJFalse,
											 GetColormap()->GetBlackColor()));
	if (count > 1)
		{
		menu->ShowSeparatorAfter(count-1);
		}
}
void
CBJavaTreeDirector::UpdateTreeMenu()
{
	JXTextMenu* treeMenu = GetTreeMenu();

	treeMenu->EnableItem(kEditSearchPathsCmd);
	treeMenu->EnableItem(kUpdateCurrentCmd);

	if (!itsJavaTree->IsEmpty())
		{
		treeMenu->EnableItem(kFindFnCmd);
		treeMenu->EnableItem(kTreeExpandAllCmd);

		if (itsJavaTree->NeedsMinimizeMILinks())
			{
			treeMenu->EnableItem(kForceMinMILinksCmd);
			}
		}

	JBoolean hasSelection, canCollapse, canExpand;
	itsJavaTree->GetMenuInfo(&hasSelection, &canCollapse, &canExpand);
	if (hasSelection)
		{
		treeMenu->EnableItem(kTreeOpenSourceCmd);
		treeMenu->EnableItem(kTreeOpenFnListCmd);
		treeMenu->EnableItem(kTreeSelParentsCmd);
		treeMenu->EnableItem(kTreeSelDescendantsCmd);
		treeMenu->EnableItem(kCopySelNamesCmd);
		}
	if (canCollapse)
		{
		treeMenu->EnableItem(kTreeCollapseCmd);
		}
	if (canExpand)
		{
		treeMenu->EnableItem(kTreeExpandCmd);
		}

	if (HasFunctionBrowsers())
		{
		treeMenu->EnableItem(kCloseFnWindCmd);
		}
}
TestWidget::TestWidget
	(
	const JBoolean		isMaster,
	const JBoolean		isImage,
	JXMenuBar*			menuBar,
	JXScrollbarSet*		scrollbarSet,
	JXContainer*		enclosure,
	const HSizingOption	hSizing,
	const VSizingOption	vSizing,
	const JCoordinate	x,
	const JCoordinate	y,
	const JCoordinate	w,
	const JCoordinate	h
	)
	:
	JXScrollableWidget(scrollbarSet, enclosure, hSizing, vSizing, x,y, w,h),
	itsRNG()
{
JIndex i;

	itsFillFlag       = kJFalse;
	itsRandPointCount = 10;
	itsResizeDialog   = NULL;

	SetBackColor(GetColormap()->GetDefaultBackColor());

	// cursors

	JXDisplay* display = GetDisplay();
	itsTrekCursor      = display->CreateBuiltInCursor("XC_trek",     XC_trek);
	itsGumbyCursor     = display->CreateBuiltInCursor("XC_gumby",    XC_gumby);
	itsBogosityCursor  = display->CreateBuiltInCursor("XC_bogosity", XC_bogosity);
	itsFleurCursor     = display->CreateBuiltInCursor("XC_fleur",    XC_fleur);
	SetDefaultCursor(itsTrekCursor);

	// menus

	itsActionsMenu = menuBar->AppendTextMenu(kActionsMenuTitleStr);
	itsActionsMenu->SetTitleFontStyle(GetColormap()->GetWhiteColor());
	itsActionsMenu->SetShortcuts(kActionsMenuShortcutStr);
	itsActionsMenu->SetMenuItems(kActionsMenuStr);
	itsActionsMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsActionsMenu);

	itsPointMenu = jnew JXTextMenu(itsActionsMenu, kPointMenuCmd, menuBar);
	assert( itsPointMenu != NULL );
	itsPointMenu->SetMenuItems(kPointMenuStr);
	itsPointMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsPointMenu);

	// This tests the JX response to an empty menu.
	JXTextMenu* emptyMenu = jnew JXTextMenu(itsActionsMenu, kEmptyMenuCmd, menuBar);
	assert( emptyMenu != NULL );

	JXMenu* prevMenu     = itsActionsMenu;
	JIndex prevMenuIndex = kAdviceMenuCmd;
	for (i=1; i<=kAdviceMenuCount; i++)
		{
		JXTextMenu* adviceMenu = jnew JXTextMenu(prevMenu, prevMenuIndex, menuBar);
		assert( adviceMenu != NULL );
		adviceMenu->SetMenuItems(kAdviceMenuStr[i-1]);
		adviceMenu->SetUpdateAction(JXMenu::kDisableNone);

		if (i == kAdviceBoldMenuIndex)
			{
			adviceMenu->SetItemFontStyle(2,
				JFontStyle(kJTrue, kJFalse, 0, kJFalse, GetColormap()->GetBlackColor()));
			}

		prevMenu      = adviceMenu;
		prevMenuIndex = 2;
		}

	BuildXlsfontsMenu(itsActionsMenu, menuBar);

	// secret menus are a bad idea because the user can't find them!

	itsSecretMenu = jnew JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10);
	assert( itsSecretMenu != NULL );
	itsSecretMenu->SetMenuItems(kSecretMenuStr);
	itsSecretMenu->SetUpdateAction(JXMenu::kDisableNone);
	itsSecretMenu->SetToHiddenPopupMenu(kJTrue);		// will assert() otherwise
	itsSecretMenu->Hide();
	ListenTo(itsSecretMenu);

	itsSecretSubmenu = jnew JXTextMenu(itsSecretMenu, kSecretSubmenuIndex, this);
	assert( itsSecretSubmenu != NULL );
	itsSecretSubmenu->SetMenuItems(kSecretSubmenuStr);
	itsSecretSubmenu->SetUpdateAction(JXMenu::kDisableNone);
	// we don't ListenTo() it because it's only there for show

	// image from xpm

	itsXPMImage = jnew JXImage(GetDisplay(), JXPM(macapp_xpm));
	assert( itsXPMImage != NULL );

	// partial image from image

	itsPartialXPMImage = jnew JXImage(*itsXPMImage, JRect(5,5,14,16));
	assert( itsPartialXPMImage != NULL );

	// home symbol

	itsHomeImage = jnew JXImage(GetDisplay(), JXPM(home_xpm));
	assert( itsHomeImage != NULL );

	itsHomeRect = itsHomeImage->GetBounds();
	itsHomeRect.Shift(120, 10);

	// buffer contents of Widget in JXImage

	itsImageBuffer = NULL;
	if (isImage)
		{
		CreateImageBuffer();
		}

	// initial size

	SetBounds(400,400);

	// enclosed objects

	itsAnimButton = 
		jnew JXTextButton("Start", this, JXWidget::kFixedLeft, JXWidget::kFixedTop,
						 37,175, 50,30);
	assert( itsAnimButton != NULL );
	itsAnimButton->SetShortcuts("#A");
	ListenTo(itsAnimButton);

	if (isMaster)
		{
		itsQuitButton = 
			jnew JXTextButton(JGetString("Quit::TestWidget"), this, JXWidget::kFixedRight, JXWidget::kFixedBottom,
							 x,y, 50,30);
		assert( itsQuitButton != NULL );

		JXColormap* colormap = GetColormap();
		itsQuitButton->CenterWithinEnclosure(kJTrue, kJTrue);
		itsQuitButton->SetFontStyle(JFontStyle(kJTrue, kJFalse, 0, kJFalse, colormap->GetRedColor()));
		itsQuitButton->SetNormalColor(colormap->GetCyanColor());
		itsQuitButton->SetPushedColor(colormap->GetBlueColor());

		ListenTo(itsQuitButton);
		}
	else
		{
		itsQuitButton = NULL;
		}

	ExpandToFitContent();

	// drops on iconfied window

	JXWindowIcon* windowIcon;
	const JBoolean hasIconWindow = GetWindow()->GetIconWidget(&windowIcon);
	assert( hasIconWindow );
	ListenTo(windowIcon);
}
void
JXMenuBar::WidthChanged()
{
	if (itsMenus->IsEmpty() || itsIgnoreWidthChangedCount > 0)
		{
		return;
		}

	itsIgnoreWidthChangedCount++;

	// put all menus back in menubar

	ClearOverflowMenu();

	// check if menus fit on menubar

	const JRect ap = GetAperture();

	JXMenu* m   = itsMenus->LastElement();
	JRect frame = m->GetFrame();
	if (frame.xcenter() < ap.right)
		{
		assert( itsIgnoreWidthChangedCount > 0 );
		itsIgnoreWidthChangedCount--;
		return;
		}

	// create menu to hold overflow

	JXImage* image = new JXImage(GetDisplay(), jx_down_chevron);
	assert( image != NULL );

	JXTextMenu* overflowMenu =
		new JXTextMenu(image, kJTrue, this, kFixedLeft, kFixedTop, 0,0, 10,10);
	assert( overflowMenu != NULL );
	overflowMenu->SetUpdateAction(JXMenu::kDisableNone);

	overflowMenu->SetMenuBar(this);		// don't show down arrow at right of title
	const JCoordinate extraWidth = overflowMenu->GetFrameWidth();
	overflowMenu->SetMenuBar(NULL);

	// move menus to overflow menu

	while (frame.right > ap.right - extraWidth)
		{
		const JString& title = m->GetTitleText();
		if (title.IsEmpty())
			{
			break;
			}

		overflowMenu->PrependItem(title);
		overflowMenu->AttachSubmenu(1, m);
		if (itsMenus->IsEmpty())
			{
			break;
			}

		m     = itsMenus->LastElement();
		frame = m->GetFrame();
		}

	if (overflowMenu->IsEmpty())
		{
		delete overflowMenu;
		overflowMenu = NULL;
		}
	else
		{
		AppendMenu(overflowMenu);
		itsOverflowMenu = overflowMenu;
		}

	assert( itsIgnoreWidthChangedCount > 0 );
	itsIgnoreWidthChangedCount--;
}
示例#7
0
void
JXToolBar::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	JBoolean propagate = kJTrue;

	JPrefsManager* prefsMgr;
	JIndex prefID;
	const JBoolean hasPrefs = GetPrefInfo(&prefsMgr, &prefID);

	if (message.Is(JXButton::kPushed))
		{
		const JSize count = itsButtons->GetElementCount();
		for (JIndex i=1; i<=count; i++)
			{
			JXToolBarButton* button = itsButtons->NthElement(i);
			if (sender == button)
				{
				JXTextMenu* menu = button->GetMenu();
				menu->PrepareToOpenMenu();
				JIndex itemIndex;
				if (button->GetMenuItemIndex(&itemIndex) &&
					menu->itsBaseItemData->IsEnabled(itemIndex))
					{
					JXDisplay* display = GetDisplay();	// need local copy, since we might be deleted
					Display* xDisplay  = *display;
					Window xWindow     = (GetWindow())->GetXWindow();

					menu->BroadcastSelection(itemIndex, kJFalse);

					if (!JXDisplay::WindowExists(display, xDisplay, xWindow))
						{
						// we have been deleted
						return;
						}

					UpdateButtons();
					}
				propagate = kJFalse;
				break;
				}
			}
		}

	else if (sender == itsTimerTask && message.Is(JXTimerTask::kTimerWentOff))
		{
		UpdateButtons();
		propagate = kJFalse;
		}

	else if (sender == itsEditDialog && message.Is(JXDialogDirector::kDeactivated))
		{
		const JXDialogDirector::Deactivated* info =
			dynamic_cast(const JXDialogDirector::Deactivated*, &message);
		assert(info != NULL);
		if (info->Successful())
			{
			ExtractChanges();
			}
		delete itsMenuTree;
		itsMenuTree = NULL;
		itsEditDialog = NULL;
		propagate = kJFalse;
		}
	else if (hasPrefs &&
void
SCFeedbackDirector::BuildWindow
(
    SCCircuitDocument* doc
)
{
    const SCCircuit* circuit = doc->GetCircuit();

    JArray<JCoordinate> heights(4);
    heights.AppendElement(kInitExprHeight);
    heights.AppendElement(kInitExprHeight);
    heights.AppendElement(kInitExprHeight);
    heights.AppendElement(kInitExprHeight);

    JArray<JCoordinate> minHeights(4);
    minHeights.AppendElement(kMinExprHeight);
    minHeights.AppendElement(kMinExprHeight);
    minHeights.AppendElement(kMinExprHeight);
    minHeights.AppendElement(kMinExprHeight);

// begin JXLayout

    JXWindow* window = new JXWindow(this, 360,520, "");
    assert( window != NULL );

    itsMainPartition =
        new JXVertPartition(heights, 0, minHeights, window,
                            JXWidget::kHElastic, JXWidget::kVElastic, 0,110, 365,415);
    assert( itsMainPartition != NULL );

    itsInputSource =
        new SCComponentMenu(circuit, SCACSourceFilter, "Input source:", window,
                            JXWidget::kFixedLeft, JXWidget::kFixedTop, 20,20, 150,30);
    assert( itsInputSource != NULL );

    itsDepSource =
        new SCComponentMenu(circuit, SCDepSourceFilter, "Dependent source:", window,
                            JXWidget::kFixedLeft, JXWidget::kFixedTop, 20,60, 150,30);
    assert( itsDepSource != NULL );

    itsEvalButton =
        new JXTextButton(JGetString("itsEvalButton::SCFeedbackDirector::JXLayout"), window,
                         JXWidget::kFixedRight, JXWidget::kFixedTop, 230,20, 80,20);
    assert( itsEvalButton != NULL );

    JXStaticText* layoutMessage =
        new JXStaticText(JGetString("layoutMessage::SCFeedbackDirector::JXLayout"), window,
                         JXWidget::kFixedRight, JXWidget::kFixedTop, 240,50, 110,60);
    assert( layoutMessage != NULL );

// end JXLayout

    const JCoordinate kMinWindowWidth = window->GetBoundsWidth();

    window->SetTitle("Feedback Theorem");
    window->SetMinSize(kMinWindowWidth, window->GetBoundsHeight());

    layoutMessage->SetText(
        "Output fn\nH0  |  Hinf\n T   |  Tn\nScratch area");

    itsInputSource->SetToPopupChoice(kJTrue);
    itsDepSource->SetToPopupChoice(kJTrue);

    ListenTo(itsEvalButton);

    // create sub-partitions

    const JCoordinate w =
        (itsMainPartition->GetBoundsWidth() - JPartition::kDragRegionSize)/2;
    JArray<JCoordinate> widths(2);
    widths.AppendElement(w);
    widths.AppendElement(w);

    const JCoordinate wMin = (kMinWindowWidth - JPartition::kDragRegionSize)/2;
    JArray<JCoordinate> minWidths(2);
    minWidths.AppendElement(wMin);
    minWidths.AppendElement(wMin);

    JXContainer* encl = itsMainPartition->GetCompartment(2);
    itsHPartition =
        new JXHorizPartition(widths, 0, minWidths, encl,
                             JXWidget::kHElastic, JXWidget::kVElastic,
                             0,0, encl->GetBoundsWidth(), encl->GetBoundsHeight());
    assert( itsHPartition != NULL );

    encl = itsMainPartition->GetCompartment(3);
    itsTPartition =
        new JXHorizPartition(widths, 0, minWidths, encl,
                             JXWidget::kHElastic, JXWidget::kVElastic,
                             0,0, encl->GetBoundsWidth(), encl->GetBoundsHeight());
    assert( itsTPartition != NULL );

    // create expressions

    SCExprEditorSet* exprSet =
        new SCExprEditorSet(doc, &itsOutputFn,
                            itsMainPartition->GetCompartment(1),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsH0,
                            itsHPartition->GetCompartment(1),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsHinf,
                            itsHPartition->GetCompartment(2),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsT,
                            itsTPartition->GetCompartment(1),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsTn,
                            itsTPartition->GetCompartment(2),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsScratchFn,
                            itsMainPartition->GetCompartment(4),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    // add our menu items

    JXTextMenu* menu = itsOutputFn->GetExtraMenu();

    menu->AppendItem(kBuildH0FormItemStr);
    itsBuildH0Index = menu->GetItemCount();

    menu->AppendItem(kBuildHinfFormItemStr);
    itsBuildHinfIndex = menu->GetItemCount();

    menu->ShowSeparatorAfter(itsBuildH0Index-1);
    ListenTo(menu);
}
示例#9
0
CBTextEditor::CBTextEditor
	(
	CBTextDocument*		document,
	const JCharacter*	fileName,
	JXMenuBar*			menuBar,
	CBTELineIndexInput*	lineInput,
	CBTEColIndexInput*	colInput,
	JXScrollbarSet*		scrollbarSet,
	JXContainer*		enclosure,
	const HSizingOption	hSizing,
	const VSizingOption	vSizing,
	const JCoordinate	x,
	const JCoordinate	y,
	const JCoordinate	w,
	const JCoordinate	h
	)
	:
	JXTEBase(kFullEditor, kJTrue, kJFalse, scrollbarSet,
			 enclosure, hSizing, vSizing, x,y, w,h),
	itsLastModifiers(GetDisplay())
{
	itsDoc = document;
	ListenTo(itsDoc);

	UpdateWritable(fileName);

	itsLineInput = lineInput;
	itsLineInput->SetTE(this, colInput);

	itsColInput = colInput;
	itsColInput->SetTE(this);

	itsTokenStartList = JTEStyler::NewTokenStartList();

	itsBalanceWhileTypingFlag     = kJTrue;
	itsScrollToBalanceFlag        = kJTrue;
	itsBeepWhenTypeUnbalancedFlag = kJTrue;

	itsSmartTabFlag = kJTrue;

	// create edit menu

	JXTextMenu* editMenu = AppendEditMenu(menuBar, kJTrue, kJTrue, kJTrue, kJTrue, kJTrue, kJTrue, kJFalse, kJFalse);
	const JSize editCount = editMenu->GetItemCount();
	editMenu->ShowSeparatorAfter(editCount);

	itsExecScriptCmdIndex = editCount + 1;
	editMenu->AppendItem(kExecScriptStr, JXMenu::kPlainType, NULL,
						 kExecScriptNMShortcutStr, kExecScriptAction);
	editMenu->SetItemImage(itsExecScriptCmdIndex, jx_run_script);

	editMenu->AppendItem(kExecScriptSubmenuStr);
	CreateScriptMenu(editMenu, editCount + 2);

	// create search menu

	JXTextMenu* searchMenu = AppendSearchReplaceMenu(menuBar);
	itsFirstSearchMenuItem = searchMenu->GetItemCount() + 1;
	searchMenu->ShowSeparatorAfter(itsFirstSearchMenuItem-1);
	searchMenu->AppendMenuItems(kSearchMenuStr, "CBTextEditor");
	ListenTo(searchMenu);

	searchMenu->SetItemImage(itsFirstSearchMenuItem + kBalanceCmd,     jcc_balance_braces);
	searchMenu->SetItemImage(itsFirstSearchMenuItem + kViewManPageCmd, jcc_view_man_page);

	// create menus when needed

	itsFnMenu         = NULL;
	itsCompletionMenu = NULL;
	itsContextMenu    = NULL;

	// font

	CBPrefsManager* prefsMgr = CBGetPrefsManager();

	JString fontName;
	JSize fontSize;
	prefsMgr->GetDefaultFont(&fontName, &fontSize);
	SetFont(fontName, fontSize, kDefTabCharCount);

	// colors

	SetDefaultFontStyle(prefsMgr->GetColor(CBPrefsManager::kTextColorIndex));

	SetBackColor(prefsMgr->GetColor(CBPrefsManager::kBackColorIndex));
	SetFocusColor(GetBackColor());

	SetCaretColor(prefsMgr->GetColor(CBPrefsManager::kCaretColorIndex));
	SetSelectionColor(prefsMgr->GetColor(CBPrefsManager::kSelColorIndex));
	SetSelectionOutlineColor(prefsMgr->GetColor(CBPrefsManager::kSelLineColorIndex));

	// right margin

	itsDrawRightMarginFlag = kJFalse;
	itsRightMarginWidth    = 80;
	itsRightMarginColor    = prefsMgr->GetColor(CBPrefsManager::kRightMarginColorIndex);
	SetWhitespaceColor(itsRightMarginColor);

	// misc setup

	ShouldBroadcastCaretLocationChanged(kJTrue);
	UpdateTabHandling();
	ListenTo(this);

	(scrollbarSet->GetVScrollbar())->SetScrollDelay(0);

	UseMultipleUndo();
	SetLastSaveLocation();
	ShouldAutoIndent(kJTrue);
	CBShouldAllowDragAndDrop(kJTrue);	// new users expect it
	ShouldMoveToFrontOfText(kJTrue);

	itsLineInput->ShareEditMenu(this);
	itsColInput->ShareEditMenu(this);

	SetCharacterInWordFunction(CBMIsCharacterInWord);

	JTEKeyHandler* handler;
	CBInstallEmulator((CBGetPrefsManager())->GetEmulator(), this, &handler);
}