void
GMessageViewDir::BuildWindow
	(
	const JString& mailfile
	)
{
	JSize w = 500;
	JSize h = 300;
	JXWindow* window = new JXWindow(this, w,h, mailfile);
    assert( window != NULL );

	window->SetWMClass(GMGetWMClassInstance(), GMGetViewWindowClass());
    GGetPrefsMgr()->GetViewWindowSize(window);
	w = window->GetFrameWidth();
	h = window->GetFrameHeight();

    window->SetMinSize(w, 150);
    window->ShouldFocusWhenShow(kJTrue);

	JXMenuBar* menuBar =
		new JXMenuBar(window,
			JXWidget::kHElastic, JXWidget::kFixedTop,
			0, 0, w - kJXDefaultMenuBarHeight, kJXDefaultMenuBarHeight);
	assert(menuBar != NULL);

	JXEngravedRect* eRect =
		new JXEngravedRect(window,
			JXWidget::kFixedRight, JXWidget::kFixedTop,
			w - kJXDefaultMenuBarHeight, 0, kJXDefaultMenuBarHeight, kJXDefaultMenuBarHeight);
	assert(eRect != NULL);

	GMMessageDragSource* mds =
		new GMMessageDragSource(this, window,
			JXWidget::kFixedRight, JXWidget::kFixedTop,
			w - kJXDefaultMenuBarHeight + kJXDefaultBorderWidth,
			0 + kJXDefaultBorderWidth,
			kJXDefaultMenuBarHeight - 2 * kJXDefaultBorderWidth + 1,
			kJXDefaultMenuBarHeight - 2 * kJXDefaultBorderWidth + 1);
	assert(mds != NULL);

	itsFileMenu = menuBar->AppendTextMenu(kFileMenuTitleStr);
	itsFileMenu->SetMenuItems(kFileMenuStr);
	itsFileMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsFileMenu);

	JPtrArray<JString> nodes(JPtrArrayT::kDeleteAll);
	GGetMailboxTreeDir()->GetTopLevelNodes(&nodes);

	itsTransferMenu = new JXFSDirMenu(nodes, itsFileMenu, kTransferToCmd, menuBar);
	assert(itsTransferMenu != NULL);
	ListenTo(itsTransferMenu);

	JDirInfo* info;
	if (itsTransferMenu->GetDirInfo(&info))
		{
		info->SetContentFilter(GMGetMailRegexStr());
		}

	itsCopyMenu = new JXFSDirMenu(nodes, itsFileMenu, kCopyToCmd, menuBar);
	assert(itsCopyMenu != NULL);
	ListenTo(itsCopyMenu);

	if (itsCopyMenu->GetDirInfo(&info))
		{
		info->SetContentFilter(GMGetMailRegexStr());
		}

	ListenTo(GGetMailboxTreeDir());

	itsMessageMenu = menuBar->AppendTextMenu(kMessageMenuTitleStr);
	itsMessageMenu->SetMenuItems(kMessageMenuStr);
	itsMessageMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsMessageMenu);

	itsToolBar =
		new JXToolBar(GGetPrefsMgr(), kGViewToolBarID,
			menuBar, w, 150, window,
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, kJXDefaultMenuBarHeight, w, h - kJXDefaultMenuBarHeight);
	assert(itsToolBar != NULL);

	const JSize newHeight	= itsToolBar->GetWidgetEnclosure()->GetBoundsHeight();

	const JFontManager* fm	= window->GetFontManager();
	JSize lineHeight =
		fm->GetLineHeight(GGetPrefsMgr()->GetDefaultMonoFont(),
						  GGetPrefsMgr()->GetDefaultFontSize(),
						  JFontStyle());


	const JCoordinate headerheight  = (lineHeight * 4) + (lineHeight/2); //58;

	JArray<JCoordinate> sizes;
	JArray<JCoordinate> minSizes;

	sizes.AppendElement(headerheight);
	minSizes.AppendElement(20);
	sizes.AppendElement(w - headerheight);
	minSizes.AppendElement(50);
	JIndex elasticIndex = 2;

	itsPart =
		new JXVertPartition(sizes, elasticIndex,
			minSizes, itsToolBar->GetWidgetEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0,
			w, newHeight);
	assert(itsPart != NULL);

	itsSBSet =
		new JXScrollbarSet(itsPart->GetCompartment(2),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0,0,
			100,100);
	assert(itsSBSet != NULL);
	itsSBSet->FitToEnclosure(kJTrue, kJTrue);

	itsView =
		new GMessageView(menuBar, itsSBSet, itsSBSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0,0,10,10);
	assert (itsView != NULL);
	itsView->FitToEnclosure(kJTrue, kJTrue);
	itsView->SetPTPrinter(GMGetAltPTPrinter());

	window->InstallShortcuts(itsView, "#_");
	ListenTo(itsView);

	JXScrollbarSet* sbs =
		new JXScrollbarSet(itsPart->GetCompartment(1),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0,0,
			100,50);
	assert(sbs != NULL);
	sbs->FitToEnclosure(kJTrue, kJTrue);

	itsHeader =
		new GMessageView(sbs, sbs->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0,0,10,10);
	assert (itsHeader != NULL);
	itsHeader->FitToEnclosure(kJTrue, kJTrue);

	itsHeader->ShareEditMenu(itsView);
	itsHeader->ShareSearchMenu(itsView);

	GMDirectorMenu* menu =
		new GMDirectorMenu(kWindowsMenuTitleStr, menuBar,
			JXWidget::kFixedLeft, JXWidget::kVElastic, 0,0, 10,10);
	assert(menu != NULL);
	menuBar->AppendMenu(menu);

	itsPrefsMenu = menuBar->AppendTextMenu(kPrefsMenuTitleStr);
	itsPrefsMenu->SetMenuItems(kPrefsMenuStr);
	itsPrefsMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsPrefsMenu);

	itsHelpMenu = menuBar->AppendTextMenu(kHelpMenuTitleStr);
	itsHelpMenu->SetMenuItems(kHelpMenuStr);
	itsHelpMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsHelpMenu);

	itsFileMenu->SetItemImage(kNewCmd, filenew);
	itsFileMenu->SetItemImage(kNewMBox, envelopes);
	itsFileMenu->SetItemImage(kOpenCmd, fileopen);
	itsFileMenu->SetItemImage(kSaveCmd, filefloppy);
	itsFileMenu->SetItemImage(kPrintCmd, fileprint);
	itsFileMenu->SetItemImage(kShowNextCmd, mini_right);
	itsFileMenu->SetItemImage(kDeleteShowNextCmd, mini_del_right);
	itsFileMenu->SetItemImage(kShowPrevCmd, mini_left);

	itsMessageMenu->SetItemImage(kDecryptCmd, unlock_xpm);
	itsMessageMenu->SetItemImage(kSaveAttachCmd, paperclip);
	itsMessageMenu->SetItemImage(kReplyCmd, reply_xpm);
	itsMessageMenu->SetItemImage(kReplySenderCmd, reply_sender_xpm);
	itsMessageMenu->SetItemImage(kReplyAllCmd, reply_all_xpm);
	itsMessageMenu->SetItemImage(kForwardCmd, forward_xpm);
	itsMessageMenu->SetItemImage(kRedirectCmd, redirect_xpm);

	itsHelpMenu->SetItemImage(kTOCCmd, jx_help_toc);
	itsHelpMenu->SetItemImage(kThisWindowCmd, JXPM(jx_help_specific));

	itsToolBar->LoadPrefs();

	if (itsToolBar->IsEmpty())
		{
		itsToolBar->AppendButton(itsFileMenu, kNewCmd);
		itsToolBar->AppendButton(itsFileMenu, kOpenCmd);
		itsToolBar->NewGroup();

		itsToolBar->AppendButton(itsFileMenu, kSaveCmd);
		itsToolBar->NewGroup();

		itsToolBar->AppendButton(itsFileMenu, kPrintCmd);
		itsToolBar->NewGroup();

		itsToolBar->AppendButton(itsFileMenu, kShowNextCmd);
		itsToolBar->AppendButton(itsFileMenu, kShowPrevCmd);
		itsToolBar->AppendButton(itsFileMenu, kDeleteShowNextCmd);
		itsToolBar->NewGroup();

		itsToolBar->AppendButton(itsMessageMenu, kReplyCmd);
		itsToolBar->AppendButton(itsMessageMenu, kReplySenderCmd);
		itsToolBar->AppendButton(itsMessageMenu, kReplyAllCmd);
		itsToolBar->AppendButton(itsMessageMenu, kForwardCmd);
		itsToolBar->AppendButton(itsMessageMenu, kRedirectCmd);
		}

	itsMenuIcon = new JXImage(window->GetDisplay(), jx_plain_file_small);
	assert(itsMenuIcon != NULL);
	itsMenuIcon->ConvertToRemoteStorage();
}
void
GPMMainDirector::BuildWindow()
{
// begin JXLayout

	JXWindow* window = new JXWindow(this, 530,350, "");
	assert( window != NULL );

	JXMenuBar* menuBar =
		new JXMenuBar(window,
					JXWidget::kHElastic, JXWidget::kFixedTop, 0,0, 540,30);
	assert( menuBar != NULL );

	itsToolBar =
		new JXToolBar(GPMGetPrefsManager(), kGPMMainToolBarID, menuBar, 540, 250, window,
					JXWidget::kHElastic, JXWidget::kVElastic, 0,30, 530,300);
	assert( itsToolBar != NULL );

	itsFullCmdDisplay =
		new JXStaticText("", kJFalse, kJTrue, NULL, window,
					JXWidget::kHElastic, JXWidget::kFixedBottom, 0,330, 530,20);
	assert( itsFullCmdDisplay != NULL );

// end JXLayout

	window->SetTitle("Drakon Process Manager");
	window->SetCloseAction(JXWindow::kQuitApp);
	window->SetWMClass(GPMGetWMClassInstance(), GPMGetMainWindowClass());

	JXImage* image = new JXImage(GetDisplay(), gpm_main_window_icon);
	assert( image != NULL );
	window->SetIcon(image);

	// system stats

	itsSystemStats =
		new GPMSystemStats(itsProcessList, itsToolBar->GetWidgetEnclosure(),
					   JXWidget::kHElastic, JXWidget::kFixedTop,
					   0,kStatusMargin, 100,kStatusHeight);
	assert( itsSystemStats != NULL );
	itsSystemStats->FitToEnclosure(kJTrue, kJFalse);

	// tab group

	itsTabGroup =
		new JXTabGroup(itsToolBar->GetWidgetEnclosure(),
					   JXWidget::kHElastic, JXWidget::kVElastic,
					   0,0, 100,100);
	assert( itsTabGroup != NULL );
	itsTabGroup->FitToEnclosure();
	ListenTo(itsTabGroup->GetCardEnclosure());

	const JCoordinate statusHeight = kStatusHeight + 2*kStatusMargin;
	itsTabGroup->AdjustSize(0, -statusHeight);
	itsTabGroup->Move(0, statusHeight);

	JXWidgetSet* listTab = itsTabGroup->AppendTab("List");
	JXWidgetSet* treeTab = itsTabGroup->AppendTab("Tree");

	// list view

	JXScrollbarSet* scrollbarSet =
		new JXScrollbarSet(listTab, JXWidget::kHElastic, JXWidget::kVElastic,
						   0,0, 100,100);
	assert( scrollbarSet != NULL );
	scrollbarSet->FitToEnclosure();

	const JCoordinate kHeaderHeight	= 25;
	const JCoordinate tableHeight   = scrollbarSet->GetScrollEnclosure()->GetBoundsHeight() - kHeaderHeight;

	itsProcessTable =
		new GPMProcessTable(itsProcessList, itsFullCmdDisplay,
			scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0,kHeaderHeight, 100,tableHeight);
	assert( itsProcessTable != NULL );
	itsProcessTable->FitToEnclosure(kJTrue, kJFalse);

	GPMListHeaderWidget* tableHeader =
		new GPMListHeaderWidget(itsProcessTable, itsProcessList,
			scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kFixedTop,
			0,0, 100,kHeaderHeight);
	assert( tableHeader != NULL );
	tableHeader->FitToEnclosure(kJTrue, kJFalse);

	// tree view

	scrollbarSet =
		new JXScrollbarSet(treeTab, JXWidget::kHElastic, JXWidget::kVElastic,
						   0,0, 100,100);
	assert( scrollbarSet != NULL );
	scrollbarSet->FitToEnclosure();

	JNamedTreeList* treeList = new JNamedTreeList(itsProcessList->GetProcessTree());
	assert( treeList != NULL );

	itsProcessTree =
		new GPMProcessTreeList(itsProcessList, treeList, itsFullCmdDisplay,
			scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0,kHeaderHeight, 100,tableHeight);
	assert( itsProcessTree != NULL );
	itsProcessTree->FitToEnclosure(kJTrue, kJFalse);

	GPMTreeHeaderWidget* treeHeader =
		new GPMTreeHeaderWidget(itsProcessTree, itsProcessList,
			scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kFixedTop,
			0,0, 100,kHeaderHeight);
	assert( treeHeader != NULL );
	treeHeader->FitToEnclosure(kJTrue, kJFalse);

	itsProcessTable->SetDefaultRowHeight(itsProcessTree->GetDefaultRowHeight());

	// focus hocus pocus

	window->UnregisterFocusWidget(itsFullCmdDisplay);
	window->RegisterFocusWidget(itsFullCmdDisplay);

	// menus

	itsFileMenu = menuBar->AppendTextMenu(kFileMenuTitleStr);
	itsFileMenu->SetMenuItems(kFileMenuStr);
	itsFileMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsFileMenu);

	itsProcessMenu = menuBar->AppendTextMenu(kProcessMenuTitleStr);
	itsProcessMenu->SetMenuItems(kProcessMenuStr, "GPMProcessTable");
	ListenTo(itsProcessMenu);

	itsProcessMenu->SetItemImage(kShowAllCmd, JXPM(gpm_all_processes));
	itsProcessMenu->SetItemImage(kEndCmd, JXPM(gpm_stop));
	itsProcessMenu->SetItemImage(kKillCmd, JXPM(jx_edit_clear));
	itsProcessMenu->SetItemImage(kPauseCmd, JXPM(gpm_pause));
	itsProcessMenu->SetItemImage(kContinueCmd, JXPM(gpm_cont));
	itsProcessMenu->SetItemImage(kReNiceCmd, JXPM(gpm_slow));

	itsPrefsMenu = menuBar->AppendTextMenu(kPrefsMenuTitleStr);
	itsPrefsMenu->SetMenuItems(kPrefsMenuStr);
	itsPrefsMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsPrefsMenu);

	itsHelpMenu = menuBar->AppendTextMenu(kHelpMenuTitleStr);
	itsHelpMenu->SetMenuItems(kHelpMenuStr);
	itsHelpMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsHelpMenu);

	itsHelpMenu->SetItemImage(kTOCCmd,        jx_help_toc);
	itsHelpMenu->SetItemImage(kThisWindowCmd, jx_help_specific);

	// must be done after creating widgets

	itsToolBar->LoadPrefs();
	if (itsToolBar->IsEmpty())
		{
		itsToolBar->AppendButton(itsFileMenu, kQuitCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsProcessMenu, kShowAllCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsProcessMenu, kEndCmd);
		itsToolBar->AppendButton(itsProcessMenu, kKillCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsProcessMenu, kPauseCmd);
		itsToolBar->AppendButton(itsProcessMenu, kContinueCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsProcessMenu, kReNiceCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsHelpMenu, kTOCCmd);
		itsToolBar->AppendButton(itsHelpMenu, kThisWindowCmd);
		}
}
void
CMSourceDirector::BuildWindow()
{
	const JIndex prefID = itsType == kMainSourceType ? kMainSrcToolBarID  :
						  itsType == kMainAsmType    ? kMainAsmToolBarID  :
						  itsType == kAsmType        ? kOtherAsmToolBarID :
						  kOtherSrcToolBarID;

// begin JXLayout

	JXWindow* window = jnew JXWindow(this, 600,550, "");
	assert( window != NULL );

	itsMenuBar =
		jnew JXMenuBar(window,
					JXWidget::kHElastic, JXWidget::kFixedTop, 0,0, 600,30);
	assert( itsMenuBar != NULL );

	itsToolBar =
		jnew JXToolBar(CMGetPrefsManager(), prefID, itsMenuBar, window,
					JXWidget::kHElastic, JXWidget::kVElastic, 0,30, 600,500);
	assert( itsToolBar != NULL );

	itsFileDisplay =
		jnew JXFileNameDisplay("", window,
					JXWidget::kHElastic, JXWidget::kFixedBottom, 20,530, 580,20);
	assert( itsFileDisplay != NULL );

	CMFileDragSource* dragSource =
		jnew CMFileDragSource(this, window,
					JXWidget::kFixedLeft, JXWidget::kFixedBottom, 0,530, 20,20);
	assert( dragSource != NULL );

// end JXLayout

	window->SetTitle(JGetString(
		itsType == kMainAsmType ? "InitAsmWindowTitle::CMSourceDirector" :
								  "InitSourceWindowTitle::CMSourceDirector"));

	window->SetMinSize(300, 200);

	if (itsType == kMainSourceType)
		{
		window->SetCloseAction(JXWindow::kDeactivateDirector);

		window->SetWMClass(CMGetWMClassInstance(), CMGetMainSourceWindowClass());
		CMGetPrefsManager()->GetWindowSize(kMainCodeWindSizeID, window);

		JXDisplay* display = GetDisplay();
		JXImage* icon      = jnew JXImage(display, medic_current_source_window);
		assert( icon != NULL );
		window->SetIcon(icon);
		}
	else if (itsType == kMainAsmType)
		{
		window->SetCloseAction(JXWindow::kDeactivateDirector);

		window->SetWMClass(CMGetWMClassInstance(), CMGetMainAsmWindowClass());
		CMGetPrefsManager()->GetWindowSize(kMainAsmWindSizeID, window);

		JXDisplay* display = GetDisplay();
		JXImage* icon      = jnew JXImage(display, medic_current_asm_window);
		assert( icon != NULL );
		window->SetIcon(icon);
		}
	else if (itsType == kAsmType)
		{
		window->SetWMClass(CMGetWMClassInstance(), CMGetAsmViewWindowClass());
		CMGetPrefsManager()->GetWindowSize(kAsmWindSizeID, window, kJTrue);
		}
	else
		{
		window->SetWMClass(CMGetWMClassInstance(), CMGetSourceViewWindowClass());
		CMGetPrefsManager()->GetWindowSize(kCodeWindSizeID, window, kJTrue);
		}

	JCoordinate w = window->GetFrameWidth();

	itsFileMenu = itsMenuBar->AppendTextMenu(kFileMenuTitleStr);
	itsFileMenu->SetMenuItems(kFileMenuStr, "CMSourceDirector");
	itsFileMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsFileMenu);

	itsFileMenu->SetItemImage(kOpenCmd,  jx_file_open);
	itsFileMenu->SetItemImage(kPrintCmd, jx_file_print);

	// appends Edit & Search menus

	const JCoordinate kInitTableWidth = 50;

	JXScrollbarSet* scrollbarSet =
		jnew JXScrollbarSet(itsToolBar->GetWidgetEnclosure(),
						   JXWidget::kHElastic, JXWidget::kVElastic, 0,0, 100,100);
	assert( scrollbarSet != NULL );
	scrollbarSet->FitToEnclosure();

	JXContainer* encl = scrollbarSet->GetScrollEnclosure();

	itsText =
		jnew CMSourceText(this, itsCommandDir, itsMenuBar, scrollbarSet, encl,
						 JXWidget::kHElastic, JXWidget::kVElastic,
						 kInitTableWidth, 0,
						 encl->GetApertureWidth()-kInitTableWidth, 100);
	assert( itsText != NULL );
	itsText->FitToEnclosure(kJFalse, kJTrue);
	ListenTo(itsText);

	if (itsType == kMainAsmType || itsType == kAsmType)
		{
		itsTable =
			jnew CMLineAddressTable(this, itsText, scrollbarSet, encl,
								   JXWidget::kFixedLeft, JXWidget::kVElastic,
								   0, 0, kInitTableWidth, 100);
		}
	else
		{
		itsTable =
			jnew CMLineNumberTable(this, itsText, scrollbarSet, encl,
								  JXWidget::kFixedLeft, JXWidget::kVElastic,
								  0, 0, kInitTableWidth, 100);
		}
	assert( itsTable != NULL );
	itsTable->FitToEnclosure(kJFalse, kJTrue);

	// requires itsText

	itsDebugMenu = itsCommandDir->CreateDebugMenu(itsMenuBar);
	ListenTo(itsDebugMenu);

	itsFnMenu =
		jnew CBFunctionMenu(NULL, kCBUnknownFT, itsText, itsMenuBar,
						   JXWidget::kFixedLeft, JXWidget::kFixedTop,
						   0,0, 10,10);
	assert( itsFnMenu != NULL );
	itsFnMenu->Hide();

	itsPrefsMenu = itsMenuBar->AppendTextMenu(kPrefsMenuTitleStr);
	itsPrefsMenu->SetMenuItems(kPrefsMenuStr, "CMSourceDirector");
	itsPrefsMenu->SetUpdateAction(JXMenu::kDisableNone);
	if (IsMainSourceWindow())
		{
		itsPrefsMenu->RemoveItem(kWindowSizeCmd);
		}
	ListenTo(itsPrefsMenu);

	itsHelpMenu = itsMenuBar->AppendTextMenu(kHelpMenuTitleStr);
	itsHelpMenu->SetMenuItems(kHelpMenuStr, "CMSourceDirector");
	itsHelpMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsHelpMenu);

	itsHelpMenu->SetItemImage(kTOCCmd,        jx_help_toc);
	itsHelpMenu->SetItemImage(kThisWindowCmd, jx_help_specific);

	if (!IsMainSourceWindow())
		{
		(GetDisplay()->GetWDManager())->DirectorCreated(this);
		}
}