Example #1
0
void StatusItem::GeneratePopUp(BPoint point, BRect openrect)
{
	BString str(value);
	str.Append(" ");
	BString url;
	URLCrunch crunch(str.String(), str.Length());
	BPopUpMenu* menu = new BPopUpMenu("URLs");
	BMessage msg(M_LOAD_URL);
	BMessage* allocmsg(NULL);
	BMenuItem* item(NULL);

	while (crunch.Crunch(&url) != B_ERROR) {
		allocmsg = new BMessage(msg);
		allocmsg->AddString("url", url.String());
		item = new BMenuItem(url.String(), allocmsg);
		menu->AddItem(item);
		allocmsg = NULL;
	}

	if (menu->CountItems() > 0) {
		menu->SetTargetForItems(be_app);
		menu->SetAsyncAutoDestruct(true);
		menu->Go(point, true, true, openrect, true);
	} else {
		delete menu;
	}
}
Example #2
0
BPopUpMenu*
DeskbarView::_BuildMenu()
{
	BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
	menu->SetFont(be_plain_font);

	menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE (
		"Create new message", "N) 新規メッセージ作成")B_UTF8_ELLIPSIS,
		new BMessage(MD_OPEN_NEW)));
	menu->AddSeparatorItem();

	BMessenger tracker(kTrackerSignature);
	BNavMenu* navMenu;
	BMenuItem* item;
	BMessage* msg;
	entry_ref ref;

	BPath path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	path.Append("Mail/Menu Links");

	BDirectory directory;
	if (_CreateMenuLinks(directory, path)) {
		int32 count = 0;

		while (directory.GetNextRef(&ref) == B_OK) {
			count++;

			path.SetTo(&ref);
			// the true here dereferences the symlinks all the way :)
			BEntry entry(&ref, true);

			// do we want to use the NavMenu, or just an ordinary BMenuItem?
			// we are using the NavMenu only for directories and queries
			bool useNavMenu = false;

			if (entry.InitCheck() == B_OK) {
				if (entry.IsDirectory())
					useNavMenu = true;
				else if (entry.IsFile()) {
					// Files should use the BMenuItem unless they are queries
					char mimeString[B_MIME_TYPE_LENGTH];
					BNode node(&entry);
					BNodeInfo info(&node);
					if (info.GetType(mimeString) == B_OK
						&& strcmp(mimeString, "application/x-vnd.Be-query")
							== 0)
						useNavMenu = true;
				}
				// clobber the existing ref only if the symlink derefernces
				// completely, otherwise we'll stick with what we have
				entry.GetRef(&ref);
			}

			msg = new BMessage(B_REFS_RECEIVED);
			msg->AddRef("refs", &ref);

			if (useNavMenu) {
				item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(),
					B_REFS_RECEIVED, tracker), msg);
				navMenu->SetNavDir(&ref);
			} else
				item = new BMenuItem(path.Leaf(), msg);

			menu->AddItem(item);
			if(entry.InitCheck() != B_OK)
				item->SetEnabled(false);
		}
		if (count > 0)
			menu->AddSeparatorItem();
	}

	// Hack for R5's buggy Query Notification
	#ifdef HAIKU_TARGET_PLATFORM_BEOS
		menu->AddItem(new BMenuItem(
			MDR_DIALECT_CHOICE("Refresh New Mail Count",
				"未読メールカウントを更新"),
			new BMessage(MD_REFRESH_QUERY)));
	#endif

	// The New E-mail query

	if (fNewMessages > 0) {
		BString string;
		MDR_DIALECT_CHOICE(
			string << fNewMessages << " new message"
				<< (fNewMessages != 1 ? "s" : B_EMPTY_STRING),
			string << fNewMessages << " 通の未読メッセージ");

		_GetNewQueryRef(ref);

		item = new BMenuItem(navMenu = new BNavMenu(string.String(),
			B_REFS_RECEIVED, BMessenger(kTrackerSignature)),
			msg = new BMessage(B_REFS_RECEIVED));
		msg->AddRef("refs", &ref);
		navMenu->SetNavDir(&ref);

		menu->AddItem(item);
	} else {
		menu->AddItem(item = new BMenuItem(
			MDR_DIALECT_CHOICE ("No new messages","未読メッセージなし"), NULL));
		item->SetEnabled(false);
	}

	BMailAccounts accounts;
	if (modifiers() & B_SHIFT_KEY) {
		BMenu *accountMenu = new BMenu(
			MDR_DIALECT_CHOICE ("Check for mails only","R) メール受信のみ"));
		BFont font;
		menu->GetFont(&font);
		accountMenu->SetFont(&font);

		for (int32 i = 0; i < accounts.CountAccounts(); i++) {
			BMailAccountSettings* account = accounts.AccountAt(i);

			BMessage* message = new BMessage(MD_CHECK_FOR_MAILS);
			message->AddInt32("account", account->AccountID());

			accountMenu->AddItem(new BMenuItem(account->Name(), message));
		}
		if (accounts.CountAccounts() == 0) {
			item = new BMenuItem("<no accounts>", NULL);
			item->SetEnabled(false);
			accountMenu->AddItem(item);
		}
		accountMenu->SetTargetForItems(this);
		menu->AddItem(new BMenuItem(accountMenu,
			new BMessage(MD_CHECK_FOR_MAILS)));

		// Not used:
		// menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE (
		// "Check For Mails Only","メール受信のみ"), new BMessage(MD_CHECK_FOR_MAILS)));
		menu->AddItem(new BMenuItem(
			MDR_DIALECT_CHOICE ("Send pending mails", "M) 保留メールを送信"),
		new BMessage(MD_SEND_MAILS)));
	} else {
		menu->AddItem(item = new BMenuItem(
			MDR_DIALECT_CHOICE ("Check for mail now", "C) メールチェック"),
			new BMessage(MD_CHECK_SEND_NOW)));
		if (accounts.CountAccounts() == 0)
			item->SetEnabled(false);
	}

	menu->AddSeparatorItem();
	menu->AddItem(new BMenuItem(
		MDR_DIALECT_CHOICE ("Preferences", "P) メール環境設定") B_UTF8_ELLIPSIS,
		new BMessage(MD_OPEN_PREFS)));

	if (modifiers() & B_SHIFT_KEY) {
		menu->AddItem(new BMenuItem(
			MDR_DIALECT_CHOICE ("Shutdown mail services", "Q) 終了"),
			new BMessage(B_QUIT_REQUESTED)));
	}

	// Reset Item Targets (only those which aren't already set)

	for (int32 i = menu->CountItems(); i-- > 0;) {
		item = menu->ItemAt(i);
		if (item && (msg = item->Message()) != NULL) {
			if (msg->what == B_REFS_RECEIVED)
				item->SetTarget(tracker);
			else
				item->SetTarget(this);
		}
	}
	return menu;
}
Example #3
0
PrefsWindow::PrefsWindow(BRect frame)
	:
	BWindow(frame, TR("Program settings"), B_TITLED_WINDOW,
		B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
	AddShortcut('1', B_COMMAND_KEY, new BMessage(M_SET_TAB_0));
	AddShortcut('2', B_COMMAND_KEY, new BMessage(M_SET_TAB_1));

	// general

	fProjectFolder = new PathBox("projectfolder", gProjectPath.GetFullPath(), "");
	fProjectFolder->MakeValidating(true);
	SetToolTip(fProjectFolder, TR("The default path for new projects."));

	fShowProjectFolder = new BCheckBox("showfolder",
		TR("Show project folder on open"), new BMessage);
	SetToolTip(fShowProjectFolder, TR("When checked, a project's folder is "
		"shown in Tracker when it is opened."));
	if (gShowFolderOnOpen)
		fShowProjectFolder->SetValue(B_CONTROL_ON);

	fDontAddHeaders = new BCheckBox("dontaddheaders",
		TR("Omit header files from projects"), NULL);
	SetToolTip(fDontAddHeaders, TR("If checked, header files are not automatically "
		"added to projects."));
	if (gDontManageHeaders)
		fDontAddHeaders->SetValue(B_CONTROL_ON);

	fSlowBuilds = new BCheckBox("slowbuilds", TR("Use single thread"), NULL);
	SetToolTip(fSlowBuilds, TR("Build with just one thread instead of one thread "
		"per processor"));
	if (gSingleThreadedBuild)
		fSlowBuilds->SetValue(B_CONTROL_ON);

	fCCache = new BCheckBox("ccache", TR("Use ccache to build faster"), NULL);
	SetToolTip(fCCache, TR("Compiler caching is another way to speed up builds"));
	if (gCCacheAvailable) {
		if (gUseCCache)
			fCCache->SetValue(B_CONTROL_ON);
	} else {
		BString label = fCCache->Label();
		label << " -- " << TR("unavailable");
		fCCache->SetLabel(label.String());
		fCCache->SetEnabled(false);
	}

	fFastDep = new BCheckBox("fastdep", TR("Use fastdep dependency checker"), NULL);
	SetToolTip(fFastDep, TR("Use the fastdep dependency checker instead of gcc"));
	if (gFastDepAvailable) {
		if (gUseFastDep)
			fFastDep->SetValue(B_CONTROL_ON);
	} else {
		BString label = fFastDep->Label();
		label << " -- " << TR("unavailable");
		fFastDep->SetLabel(label.String());
		fFastDep->SetEnabled(false);
	}

	BBox* buildBox = new BBox(B_FANCY_BORDER,
		BLayoutBuilder::Group<>(B_VERTICAL, 0)
			.Add(fSlowBuilds)
			.Add(fCCache)
			.Add(fFastDep)
			.SetInsets(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING,
				B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.View());
	buildBox->SetLabel(TR("Build"));

	fAutoSyncModules = new BCheckBox("autosync",
		TR("Automatically synchronize modules"), NULL);
	SetToolTip(fAutoSyncModules, TR("Automatically synchronize modules in your "
		"projects with the those in the code library"));
	if (gAutoSyncModules)
		fAutoSyncModules->SetValue(B_CONTROL_ON);

	fBackupFolder = new PathBox("backupfolder", gBackupPath.GetFullPath(), "");
	fBackupFolder->MakeValidating(true);
	SetToolTip(fBackupFolder, TR("Sets the location for project backups"));

	fTabs[0] = BLayoutBuilder::Grid<>(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
		.Add(new BStringView("projects folder label", TR("Projects folder:")), 0, 0)
		.Add(fProjectFolder, 1, 0)

		.AddGroup(B_VERTICAL, 0.0f, 1, 1)
			.Add(fShowProjectFolder)
			.Add(fDontAddHeaders)
			.End()

		.Add(buildBox, 1, 2)

		.Add(fAutoSyncModules, 1, 3)

		.Add(new BStringView("backups folder label", TR("Backups folder:")), 0, 4)
		.Add(fBackupFolder, 1, 4)

		.SetInsets(B_USE_DEFAULT_SPACING)
		.View();
	fTabs[0]->SetName(TR("General"));
	fTabs[0]->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

#ifndef BUILD_CODE_LIBRARY
	fAutoSyncModules->Hide();
#endif

	// source control

	BPopUpMenu* scmMenu = new BPopUpMenu("SCM Chooser");
	scmMenu->AddItem(new BMenuItem(TR("None"), NULL));
	scmMenu->AddSeparatorItem();
	scmMenu->AddItem(new BMenuItem(TR("Git"), NULL));
	scmMenu->AddItem(new BMenuItem(TR("Mercurial"), NULL));
	scmMenu->AddItem(new BMenuItem(TR("Subversion"), NULL));

	fSCMChooser = new BMenuField("scmchooser", TR("Preferred source control:"),
		scmMenu);

#ifdef DISABLE_GIT_SUPPORT
	scmMenu->ItemAt(2)->SetEnabled(false);
#endif

	BMenuItem* marked = scmMenu->ItemAt(gDefaultSCM);
	if (marked != NULL)
		marked->SetMarked(true);
	else
		scmMenu->ItemAt(0)->SetMarked(true);

	if (!marked->IsEnabled()) {
		// if the default SCM is disabled unmark it and mark the first one that
		// is enabled.
		marked->SetMarked(false);
		for (int32 i = 0; i < scmMenu->CountItems(); i++) {
			if (scmMenu->ItemAt(i)->IsEnabled()) {
				scmMenu->ItemAt(i)->SetMarked(true);
				break;
			}
		}
	}

	fSVNRepoFolder = new PathBox("svnrepofolder", gSVNRepoPath.GetFullPath(), "");
	fSVNRepoFolder->MakeValidating(true);
	SetToolTip(fSVNRepoFolder, TR("Sets the location for the 'server' side of "
		"local Subversion repositories."));

	fTabs[1] = BLayoutBuilder::Group<>(B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fSCMChooser->CreateLabelLayoutItem(), 0, 0)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0)
				.Add(fSCMChooser->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()
	
			.Add(new BStringView("svn repo folder label",
				TR("Subversion repository folder:")), 0, 1)
			.Add(fSVNRepoFolder, 1, 1)
			.End()
		.AddGlue()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.View();
	fTabs[1]->SetName(TR("Source control"));
	fTabs[1]->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// tab view

	fTabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
	fTabView->SetBorder(B_NO_BORDER);
	fTabView->AddTab(fTabs[0]);
	fTabView->AddTab(fTabs[1]);
	fTabView->Select(0L);

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.AddStrut(B_USE_SMALL_SPACING)
		.Add(fTabView)
		.End();

	fProjectFolder->MakeFocus(true);

	CenterOnScreen();
}
Example #4
0
TemplateWindow::TemplateWindow(const BRect& frame)
	:
	BWindow(frame, TR("Choose a project type"), B_TITLED_WINDOW,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
	RegisterWindow();

	CheckTemplates();

	DPath templatePath(gAppPath.GetFolder());
	templatePath << TR("Templates");
	fTempList.ScanFolder(templatePath.GetFullPath());

	// project type

	BPopUpMenu* projectTypeMenu = new BPopUpMenu("Project type");
	for (int32 i = 0; i < fTempList.CountTemplates(); i++) {
		ProjectTemplate* ptemp = fTempList.TemplateAt(i);
		entry_ref ref = ptemp->GetRef();
		projectTypeMenu->AddItem(new BMenuItem(ref.name,
			new BMessage(M_TEMPLATE_SELECTED)));
	}
	projectTypeMenu->ItemAt(0L)->SetMarked(true);

	fTemplateField = new BMenuField("templatefield", TR("Project type: "),
		projectTypeMenu);
	fTemplateField->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// project name

	fNameBox = new AutoTextControl("namebox", TR("Project name:"), "",
		new BMessage(M_NAME_CHANGED));
	SetToolTip(fNameBox, TR("The name of your project. "
		"It can be the same as the Target name, but it does not have to be."));

	// target name

	fTargetBox = new AutoTextControl("targetbox", TR("Target name:"), "BeApp",
		new BMessage(M_TARGET_CHANGED));
	SetToolTip(fTargetBox, TR("The name of the compiled application or library"));

	// project path

	fPathBox = new PathBox("pathbox", gProjectPath.GetFullPath(), "");
	fPathBox->SetExplicitMinSize(BSize(be_plain_font->StringWidth("M") * 36,
		B_SIZE_UNSET)),
	SetToolTip(fPathBox, TR("Set the location for your project."));

	// source control

	BPopUpMenu* scmMenu = new BPopUpMenu("SCM Chooser");
	scmMenu->AddItem(new BMenuItem(TR("Mercurial"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(TR("Git"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(TR("Subversion"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(TR("None"), new BMessage()));

	if (!gHgAvailable) {
		scmMenu->ItemAt(0)->SetEnabled(false);
		scmMenu->ItemAt(0)->SetLabel(TR("Mercurial unavailable"));
	}
	if (!gGitAvailable) {
		scmMenu->ItemAt(1)->SetEnabled(false);
		scmMenu->ItemAt(1)->SetLabel(TR("Git unavailable"));
	}
	if (!gSvnAvailable) {
		scmMenu->ItemAt(2)->SetEnabled(false);
		scmMenu->ItemAt(2)->SetLabel(TR("Subversion unavailable"));
	}

	fSCMChooser = new BMenuField("scmchooser", TR("Source control: "), scmMenu);
	fSCMChooser->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	SetToolTip(fSCMChooser,
		TR("Choose the source control manager for your project, if any."));

	scmMenu->ItemAt(gDefaultSCM)->SetMarked(true);

	BMenuItem* item = scmMenu->FindMarked();
	if (!item->IsEnabled()) {
		item->SetMarked(false);
		for (int32 i = 0; i < scmMenu->CountItems(); i++) {
			if (scmMenu->ItemAt(i)->IsEnabled()) {
				scmMenu->ItemAt(i)->SetMarked(true);
				break;
			}
		}
	}

	// create folder check box

	fCreateFolder = new BCheckBox(TR("Create project folder"));
	fCreateFolder->SetValue(B_CONTROL_ON);
	SetToolTip(fCreateFolder, TR("If checked, a folder for your project will be created "
		"in the folder in the Location box above."));

	// create project button

	fCreateProjectButton = new BButton("ok", TR("Create project") B_UTF8_ELLIPSIS,
		new BMessage(M_CREATE_PROJECT));
	fCreateProjectButton->SetEnabled(false);
	fCreateProjectButton->MakeDefault(true);

	// layout

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fTemplateField->CreateLabelLayoutItem(), 0, 0)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0)
				.Add(fTemplateField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()

			.Add(fNameBox->CreateLabelLayoutItem(), 0, 1)
			.Add(fNameBox->CreateTextViewLayoutItem(), 1, 1)

			.Add(fTargetBox->CreateLabelLayoutItem(), 0, 2)
			.Add(fTargetBox->CreateTextViewLayoutItem(), 1, 2)

			.Add(new BStringView("location", TR("Location:")), 0, 3)
			.Add(fPathBox, 1, 3)

			.Add(fSCMChooser->CreateLabelLayoutItem(), 0, 4)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 4)
				.Add(fSCMChooser->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()

			.Add(fCreateFolder, 1, 5)
			.End()
		.AddGlue()
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fCreateProjectButton)
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	fNameBox->MakeFocus(true);

	CenterOnScreen();
}
/*!	\brief		Updates targets of all controls currently in the view.
 *	\details	BView::AttachToWindow(), among other things, modifies the targets
 *				of controls to point to main looper of the application. This is
 *				not desirable way. This function corrects it.
 */
void		CalendarModulePreferencesView::UpdateTargetting( void )
{
	BCheckBox* tempCheckBox = NULL;
	int i, limit;

	// Updating calendar chooser part
	BMenuItem* menuItem = NULL;
	if ( calendarModules ) {
		limit = calendarModules->CountItems();
		for ( i = 0; i < limit; ++i )
		{
			menuItem = dynamic_cast< BMenuItem* >( calendarModules->ItemAt( i ) );
			if ( menuItem )
				menuItem->SetTarget( this );
		}
	}

	// Update Weekends selector box
	BBox* tempBBox = ( BBox* )this->FindView( "Weekend selector" );
	if ( tempBBox ) {
		limit = tempBBox->CountChildren();
		for ( i = 0; i < limit; ++i )
		{
			tempCheckBox = dynamic_cast< BCheckBox* >( tempBBox->ChildAt( i ) );
			if ( tempCheckBox )
				tempCheckBox->SetTarget( this );
		}
	}
	
	// Update First day of week chooser
	BPopUpMenu* tempMenu = ( BPopUpMenu* )this->FindView( "First day of week" );
	if ( tempMenu )
	{
		limit = tempMenu->CountItems();
		for ( i = 0; i < limit; ++i )
		{
			menuItem = dynamic_cast< BMenuItem* >( tempMenu->ItemAt( i ) );
			if ( menuItem )
				menuItem->SetTarget( this );
		}
	}
	
	// Update day-month-year order chooser
	tempMenu = ( BPopUpMenu* )this->FindView( "DmyOrderChooser" );
	if ( tempMenu )
	{
		limit = tempMenu->CountItems();
		for ( i = 0; i < limit; ++i )
		{
			menuItem = dynamic_cast< BMenuItem* >( tempMenu->ItemAt( i ) );
			if ( menuItem )
				menuItem->SetTarget( this );
		}
	}
	
	// Update the target of Color selector
	CategoryListView* catListView = ( CategoryListView* )this->FindView("Colors list view");
	if ( catListView )
	{
		catListView->SetTarget( this );
	}
	
}	// <-- end of function CalendarModulePreferencesView::UpdateTargetting
/*!	
 *	\brief			Create a menu to select the module user is setting up.
 *	\note			This is an internal function.
 */
BPopUpMenu*		CalendarModulePreferencesView::PopulateModulesMenu( void )
{
	BPopUpMenu* toReturn = NULL;
	BMenuItem* 	toAdd = NULL;
	BMessage*  	toSend = NULL;
	BString		moduleId;	// Note: this is not a pointer!
	CalendarModule* currentCalModule = NULL;
	
	toReturn = new BPopUpMenu("Calendar Modules");
	if ( ! toReturn )
	{ 
		/* Panic! */
		exit (1);
	}
	
	// Looping on all calendar modules available in the system.
	for ( uint i=0; i < NUMBER_OF_CALENDAR_MODULES; ++i )
	{
		// Obtain the next calendar module
		currentCalModule = (CalendarModule *)global_ListOfCalendarModules.ItemAt( i );
		if ( !currentCalModule )
		{
			continue;	// Skipping unavailable ones
		}
		
		// Create the message
		toSend = new BMessage( kCalendarModuleChosen );
		if ( !toSend )
		{
			/* Panic! */
			exit(1);
		}
		
		// Add the ID of the module to the message
		moduleId = currentCalModule->Identify();
		toSend->AddString( "Module ID", moduleId );
		
		// Create the menu item
		toAdd = new BMenuItem( moduleId.String(), toSend );
		if ( ! toAdd )
		{
			/* Panic! */
			exit(1);
		}
		toAdd->SetTarget( this );
		
		// Add the newly created item to the menu
		toReturn->AddItem( toAdd );
		
		// Gregorian calendar module is the default one
		if ( moduleId == "Gregorian" )
		{
			toAdd->SetMarked( true );
		}
		
	}	/* <-- end of "for ( every calendar module )" */
	
	// At least something should be marked.
	if ( ( ! toReturn->FindMarked() ) && ( toReturn->CountItems() > 0 ) )
	{
		toReturn->ItemAt( 0 )->SetMarked( true );	
	}
	
	return toReturn;
}	// <-- end of function "CalendarModulePreferencesView::PopulateModulesMenu"
Example #7
0
void
TestView::MessageReceived(BMessage *msg)
{
	switch (msg->what)
	{
		case M_TEST_CHOSEN:
		{
			SetTest(msg);
			break;
		}
		case M_MODE_CHOSEN:
		{
			BString mode;
			if (msg->FindString("mode",&mode) != B_OK)
				break;
			
			SetMode(mode.String());
			break;
		}
		case M_VALUE_CHANGED:
		{
			BString str;
			if (fTest->FindString("value",&str) == B_OK)
				fTest->ReplaceString("value",fValueBox->Text());
			else
				fTest->AddString("value",fValueBox->Text());
			break;
		}
		case M_SHOW_TEST_MENU:
		{
			BPopUpMenu *menu = (BPopUpMenu*)BPopUpMenu::Instantiate(&fArchivedTestMenu);
			menu->SetTargetForItems(this);
			
			for (int32 i = 0; i < menu->CountItems(); i++)
			{
				BMenuItem *item = menu->ItemAt(i);
				if (item->Submenu())
					item->Submenu()->SetTargetForItems(this);
			}
			
			BPoint pt;
			uint32 buttons;
			GetMouse(&pt,&buttons);
			ConvertToScreen(&pt);
			pt.x -= 10.0;
			if (pt.x < 0.0)
				pt.x = 0.0;
			
			pt.y -= 10.0;
			if (pt.y < 0.0)
				pt.y = 0.0;
			
			menu->SetAsyncAutoDestruct(true);
			menu->Go(pt,true,true,true);
			break;
		}
		case M_SHOW_TYPE_MENU:
		{
			BPopUpMenu *menu = (BPopUpMenu*)BPopUpMenu::Instantiate(&gArchivedTypeMenu);
			menu->SetTargetForItems(this);
			
			for (int32 i = 0; i < menu->CountItems(); i++)
			{
				BMenuItem *item = menu->ItemAt(i);
				if (item->Submenu())
					item->Submenu()->SetTargetForItems(this);
			}
			
			BPoint pt;
			uint32 buttons;
			GetMouse(&pt,&buttons);
			ConvertToScreen(&pt);
			pt.x -= 10.0;
			if (pt.x < 0.0)
				pt.x = 0.0;
			
			pt.y -= 10.0;
			if (pt.y < 0.0)
				pt.y = 0.0;
			
			menu->SetAsyncAutoDestruct(true);
			menu->Go(pt,true,true,true);
			break;
		}
		case M_SHOW_MODE_MENU:
		{
			ShowModeMenu();
			break;
		}
		default:
		{
			BView::MessageReceived(msg);
			break;
		}
	}

}