Beispiel #1
0
void CGfxPopupMenu::EnableMenuItems(CMenu * pMenu, CWnd * pParent)
{
	ASSERT(pMenu);
	ASSERT(pParent);

	int nItem = pMenu->GetMenuItemCount();
	CCmdUI state;
	state.m_pMenu = pMenu;
	state.m_nIndex = nItem-1;
	state.m_nIndexMax = nItem;

	while ((--nItem)>=0)
	{
		UINT itemId = pMenu->GetMenuItemID(nItem);
		if (itemId == (UINT) -1)
		{
			CMenu *pops = pMenu->GetSubMenu(nItem);
			if (pops) EnableMenuItems(pops, pParent);
		}
		else
		{
			if (itemId != 0)
			{
				state.m_nID = itemId;
				pParent->OnCmdMsg(itemId, CN_UPDATE_COMMAND_UI, &state, NULL);
				state.DoUpdate(pParent, true);
			}
		}
		state.m_nIndex = nItem-1;
	}
}
void BeAccessibleWindow::OpenDatabase(BPath path)
{
	//If a database is already open, close it before opening a new one.
	if (GlobalSQLMgr->IsOpen())
		CloseDatabase();
	
	//Open the given database
	bool databaseOpened = GlobalSQLMgr->Open(path.Path());
	
	if (databaseOpened)
	{
		//Add database to list of recently opened files
		BeAccessibleApp* myApp = static_cast<BeAccessibleApp*>(be_app);
		myApp->AddToRecentFiles(new BString(path.Path()));
		
		//Create the beaccessible_master table if it's not there
		if (!GlobalSQLMgr->TableExists("beaccessible_master"))
		{
			BString sql = "create table beaccessible_master (name Text, type Text, "
			              "value Text, primary key (name, type));";
			GlobalSQLMgr->Execute(sql.String());
		}
	}

	Lock();
	
	//Change title of window to include database name
	BString newTitle("BeAccessible : ");
	newTitle += path.Leaf();
	SetTitle(newTitle.String());
	
	//Create tab for Tables (hopefully someday Queries, too!)
	BRect frame = Bounds();
	BRect menuHeight = fMenuBar->Bounds();
	frame.top += menuHeight.Height() + 1;
	frame.InsetBy(10.0, 10.0);

	const char* tabNames[1] = {"Tables"};

	fTabView = new TabView(frame, NULL, tabNames, 1, B_FOLLOW_ALL_SIDES); 
	fTabView->SetViewColor(216,216,216,0);
	BRect ContentRect = fTabView->GetContentArea();
	ContentRect.InsetBy(5,5);

	fTableTab = new DBTabView(ContentRect, "Table");

	BView* tabs[1];
	tabs[0] = (BView*)fTableTab;
	fTabView->AddViews(tabs);
	fMainView->AddChild(fTabView);
	
	//Select the first table as default
	fTableTab->fListView->Select(0);	
	
	//Enable certain menu items since there is now a database open
	EnableMenuItems();
	Unlock();
	
	// Save the database's full path to a string
	fPath->SetTo(path.Path());
}