コード例 #1
0
ファイル: ChatWindow.cpp プロジェクト: HaikuArchives/IMKit
ChatWindow::ChatWindow(entry_ref & ref)
:	BWindow( 
		BRect(100,100,400,300), 
		"unknown contact - unknown status", 
		B_TITLED_WINDOW,
		B_ASYNCHRONOUS_CONTROLS | B_AVOID_FOCUS
	),
	fEntry(ref),
	fMan( new IM::Manager(BMessenger(this))),
	fChangedNotActivated(false),
	fStatusBar(NULL),
	fSendButton(NULL),
	fProtocolHack(NULL)
{

	bool command, sendButton;
	int32 iconBarSize;
	
	BMessage chatSettings;
	im_load_client_settings("im_emoclient", &chatSettings);
	
	if ( chatSettings.FindBool("command_sends", &command) != B_OK )
		command = true;
	if ( chatSettings.FindBool("show_send_button", &sendButton) != B_OK )
		sendButton = true;
	if ( chatSettings.FindInt32("icon_size", &iconBarSize) != B_OK )
		iconBarSize = kLargeIcon;
	if ( iconBarSize <= 0 )
		iconBarSize = kLargeIcon;
	if (chatSettings.FindString("people_handler", &fPeopleHandler) != B_OK) {
		fPeopleHandler = kDefaultPeopleHandler;
	};
	if (chatSettings.FindString("other", &fOtherText) != B_OK ) {
		fOtherText.SetTo( "$name$ ($nickname$) ($protocol$) ");
	}
	
	// Set window size limits
	SetSizeLimits(
		220, 8000, // width,
		150, 8000  // height
	);
	
	// get the size of various things
	font_height height;
	be_plain_font->GetHeight(&height);
	fFontHeight = height.ascent + height.descent + height.leading;
	
	// default window size
	BRect windowRect(100, 100, 400, 300);
	BPoint inputDivider(0, 150);
	
	// load window size if possible
	if (LoadSettings() == B_OK) {
		bool was_ok = true;
		
		if (fWindowSettings.FindRect("windowrect", &windowRect) != B_OK) {
			was_ok = false;
		}
		if (fWindowSettings.FindPoint("inputdivider", &inputDivider) != B_OK) {
			was_ok = false;
		}
		
		if ( !was_ok )
		{
			windowRect = BRect(100, 100, 400, 300);
			inputDivider = BPoint(0, 200);
		}
	}
	
	// sanity check for divider location
	if ( inputDivider.y > windowRect.Height() - 50 ) {
		LOG("im_emoclient", liLow, "Insane divider, fixed.");
		inputDivider.y = windowRect.Height() - 50;
	};
	
	// set size and position
	MoveTo(windowRect.left, windowRect.top);
	ResizeTo(windowRect.Width(), windowRect.Height());
	
	// create views
	BRect textRect = Bounds();
	BRect inputRect = Bounds();
	BRect dockRect = Bounds();

	dockRect.bottom = iconBarSize + kDockPadding;
	fDock = new IconBar(dockRect);
	
#if B_BEOS_VERSION > B_BEOS_VERSION_5
	fDock->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR);
	fDock->SetLowUIColor(B_UI_PANEL_BACKGROUND_COLOR);
	fDock->SetHighUIColor(B_UI_PANEL_TEXT_COLOR);
#else
	fDock->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
	fDock->SetLowColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
	fDock->SetHighColor(0, 0, 0, 0);
#endif
	AddChild(fDock);
	
	// add buttons
	ImageButton * btn;
	BBitmap * icon;
//	long err = 0;
	BPath iconDir;
	BPath iconPath;
	BRect buttonRect(0,0,iconBarSize+8,iconBarSize+8);
	find_directory(B_USER_SETTINGS_DIRECTORY, &iconDir, true);
	iconDir.Append("im_kit/icons");
	
//	People Button
	icon = IconForHandler(fPeopleHandler.String(), iconBarSize);
	btn = MakeButton(icon, "Show contact in People", new BMessage(SHOW_INFO), buttonRect);
	fDock->AddItem(btn);
		
//	Email button
	icon = IconForHandler("text/x-email", iconBarSize);
	btn = MakeButton(icon, "Send email to contact", new BMessage(EMAIL), buttonRect);
	fDock->AddItem(btn);
	
//	Block Button
	iconPath = iconDir;
	iconPath.Append("Block");
	icon = ReadNodeIcon(iconPath.Path(), iconBarSize, true);
	btn = MakeButton(icon, "Block messages from contact", new BMessage(BLOCK), buttonRect);
	fDock->AddItem(btn);

//	Log Button
	icon = IconForHandler("application/x-vnd.BeClan.im_binlog_viewer", iconBarSize);
	btn = MakeButton(icon, "View chat history for contact", new BMessage(VIEW_LOG), buttonRect);
	fDock->AddItem(btn);
	
//	Webpage Button
	icon = IconForHandler("text/html", iconBarSize);
	btn = MakeButton(icon, "View contact's web page", new BMessage(VIEW_WEBPAGE), buttonRect);
	fDock->AddItem(btn);
	
// Emoticons	
	iconPath = iconDir;
	iconPath.Append("emoticons");
	icon = ReadNodeIcon(iconPath.Path(), iconBarSize);
	btn = MakeButton(icon, "Emoticons", new BMessage(VIEW_EMOTICONS), buttonRect);
	fDock->AddItem(btn);
	

	textRect.top = fDock->Bounds().bottom+1;
	textRect.InsetBy(2,2);
	textRect.bottom = inputDivider.y;
	textRect.right -= B_V_SCROLL_BAR_WIDTH;
	
	float sendButtonWidth = sendButton ? 50 : 0;
	
	inputRect.InsetBy(2.0, 2.0);
	inputRect.top = inputDivider.y + 7;
	inputRect.right -= B_V_SCROLL_BAR_WIDTH + sendButtonWidth;
	inputRect.bottom -= fFontHeight + (kPadding * 4);
	
	BRect inputTextRect = inputRect;
	inputTextRect.OffsetTo(kPadding, kPadding);
	inputTextRect.InsetBy(kPadding * 2, kPadding * 2);
	
	fInput = new BTextView(inputRect, "input", inputTextRect, B_FOLLOW_ALL,
		B_WILL_DRAW);
	
#if B_BEOS_VERSION > B_BEOS_VERSION_5
	fInput->SetViewUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR);
	fInput->SetLowUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR);
	fInput->SetHighUIColor(B_UI_DOCUMENT_TEXT_COLOR);
#else
	fInput->SetViewColor(245, 245, 245, 0);
	fInput->SetLowColor(245, 245, 245, 0);
	fInput->SetHighColor(0, 0, 0, 0);
#endif

	fInputScroll = new BScrollView(
		"input_scroller", fInput,
		B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, 0,
		false,
		true,
		B_PLAIN_BORDER
	);

	AddChild(fInputScroll);	
	
	fInput->SetWordWrap(true);
	fInput->SetStylable(false);
	fInput->MakeSelectable(true);
	
	if ( sendButton ) {
		BRect sendRect = fInputScroll->Frame();
		sendRect.left = sendRect.right+1;
		sendRect.right = Bounds().right;
		
		fSendButton = new BButton(
			sendRect, "sendButton", _T("Send"), new BMessage(SEND_MESSAGE),
			B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM
		);
	
		AddChild( fSendButton );
	}
	
	BRect statusRect = Bounds();
	statusRect.top = inputRect.bottom + kPadding;
	
	fStatusBar = new StatusBar(statusRect);
	
	AddChild(fStatusBar);
#if B_BEOS_VERSION > B_BEOS_VERSION_5
	fStatusBar->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR);
	fStatusBar->SetLowUIColor(B_UI_PANEL_BACKGROUND_COLOR);
	fStatusBar->SetHighUIColor(B_UI_PANEL_TEXT_COLOR);
#else
	fStatusBar->SetViewColor(245, 245, 245, 0);
	fStatusBar->SetLowColor(245, 245, 245, 0);
	fStatusBar->SetHighColor(0, 0, 0, 0);
#endif
	
	BPopUpMenu *pop = new BPopUpMenu("Protocols", true, true);
	fProtocolMenu = new BMenuField(
		BRect(kPadding, kPadding, Bounds().bottom - kPadding, 100),
		"Field", NULL, pop);
	fStatusBar->AddItem(fProtocolMenu);
	
	// fInfoView must be the LAST thing added to fStatusBar, otherwise the
	// resizing of it will be all bonkers.
	fInfoView = new BStringView(BRect(fProtocolMenu->Frame().right+5, 2,
		fStatusBar->Bounds().right - kPadding,
		fStatusBar->Bounds().bottom - kPadding), "infoView",
		"", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	fStatusBar->AddItem(fInfoView);
#if B_BEOS_VERSION > B_BEOS_VERSION_5
	fInfoView->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR);
	fInfoView->SetLowUIColor(B_UI_PANEL_BACKGROUND_COLOR);
	fInfoView->SetHighUIColor(B_UI_PANEL_TEXT_COLOR);
#else
	fInfoView->SetViewColor(245, 245, 245, 0);
	fInfoView->SetLowColor(245, 245, 245, 0);
	fInfoView->SetHighColor(0, 0, 0, 0);
#endif
	
	// need to build the menu here since it fiddles with fInfoView
	BuildProtocolMenu();
	BMenuItem *first = pop->ItemAt(0);
	if (first) first->SetMarked(true);

	BRect resizeRect = Bounds();
	resizeRect.top = inputDivider.y + 1;
	resizeRect.bottom = inputDivider.y + 4;
	
	fResize = new ResizeView(fInputScroll, resizeRect, "resizer",
		B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT);
	AddChild(fResize);
	
	Theme::TimestampFore = C_TIMESTAMP_DUMMY;
	Theme::TimestampBack = C_TIMESTAMP_DUMMY;
	Theme::TimespaceFore = MAX_COLORS;
	Theme::TimespaceBack = MAX_COLORS;
	Theme::TimespaceFont = MAX_FONTS;
	Theme::TimestampFont = F_TIMESTAMP_DUMMY;
	Theme::NormalFore = C_TEXT;
	Theme::NormalBack = C_TEXT;
	Theme::NormalFont = F_TEXT;
	Theme::SelectionBack = C_SELECTION;
	
	fTheme = new Theme("ChatWindow", MAX_COLORS + 1, MAX_COLORS + 1, MAX_FONTS + 1);

	//NormalTextRender *ntr=new NormalTextRender(be_plain_font);
	
	fTheme->WriteLock();
	fTheme->SetForeground(C_URL, 5, 5, 150);
	fTheme->SetBackground(C_URL, 255, 255, 255);
	//fTheme->SetTextRender(C_URL, ntr);
	
	fTheme->SetForeground(C_TIMESTAMP, 130, 130, 130);
	fTheme->SetBackground(C_TIMESTAMP, 255, 255, 255);
	//fTheme->SetTextRender(F_TIMESTAMP, ntr);

	fTheme->SetForeground(C_TEXT, 0, 0, 0);
	fTheme->SetBackground(C_TEXT, 255, 255, 255);
	//fTheme->SetTextRender(F_TEXT, ntr);
	
	fTheme->SetForeground(C_ACTION, 0, 0, 0);
	fTheme->SetBackground(C_ACTION, 255, 255, 255);
	//fTheme->SetTextRender(F_ACTION, ntr);
	
	fTheme->SetForeground(C_SELECTION, 255, 255, 255);
	fTheme->SetBackground(C_SELECTION, 0, 0, 0);

	fTheme->SetForeground(C_OWNNICK, 0, 0, 255);
	fTheme->SetBackground(C_OWNNICK, 255, 255, 255);
	
	fTheme->SetForeground(C_OTHERNICK, 255, 0, 0);
	fTheme->SetBackground(C_OTHERNICK, 255, 255, 255);
	
	//SmileTextRender *str=new SmileTextRender();
	fTheme->SetTextRender(F_EMOTICON,&str);	
	

	fTheme->WriteUnlock();
	
//	IM::Contact con(&fEntry);
//	char id[256];
//	con.ConnectionAt(0, id);

	fText = ((ChatApp *)be_app)->GetRunView(/*id*/ fEntry);
	if (fText == NULL) {
		fText = new RunView(
			textRect, "text", fTheme,
			B_FOLLOW_ALL, B_WILL_DRAW
		);

#if B_BEOS_VERSION > B_BEOS_VERSION_5
		fText->SetViewUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR);
		fText->SetLowUIColor(B_UI_DOCUMENT_BACKGROUND_COLOR);
		fText->SetHighUIColor(B_UI_DOCUMENT_TEXT_COLOR);
#else
		fText->SetViewColor(245, 245, 245, 0);
		fText->SetLowColor(245, 245, 245, 0);
		fText->SetHighColor(0, 0, 0, 0);
#endif

		fText->SetTimeStampFormat(NULL);
	};
	
	fTextScroll = new BScrollView(
		"scroller", fText,
		B_FOLLOW_ALL, 0,
		false, // horiz
		true, // vert
		B_PLAIN_BORDER
	);
	AddChild(fTextScroll);
	fTextScroll->MoveTo(0,fDock->Bounds().bottom+1);
	
	if ( fText->IsHidden() )
		fText->Show();
	fText->ScrollToBottom();
	
	fInput->MakeFocus();
	
	// add input filter that generates "user typing" messages and routes copy-commands
	fFilter = new InputFilter(fInput, new BMessage(SEND_MESSAGE), command, fText,
		kTypingSendRate);
	fInput->AddFilter((BMessageFilter *)fFilter);
	
	// monitor node so we get updates to status etc
	BEntry entry(&ref);
	node_ref node;
	
	entry.GetNodeRef(&node);
	watch_node( &node, B_WATCH_ALL, BMessenger(this) );
	
	// get contact info
	reloadContact();

	// set up timer for clearing typing view
	fTypingTimer = NULL;
	fTypingTimerSelf = NULL;
	
	// this message runner needed to fix a BMenuField bug.
	BMessage protoHack(PROTOCOL_SELECTED2);
	fProtocolHack = new BMessageRunner( BMessenger(this), &protoHack, 10000, 1 );
}
コード例 #2
0
MainWin::MainWin(BRect frame_rect)
	:
	BWindow(frame_rect, B_TRANSLATE_SYSTEM_NAME(NAME), B_TITLED_WINDOW,
 	B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
 ,	fController(new Controller)
 ,	fIsFullscreen(false)
 ,	fKeepAspectRatio(true)
 ,	fAlwaysOnTop(false)
 ,	fNoMenu(false)
 ,	fNoBorder(false)
 ,	fSourceWidth(720)
 ,	fSourceHeight(576)
 ,	fWidthScale(1.0)
 ,	fHeightScale(1.0)
 ,	fMouseDownTracking(false)
 ,	fFrameResizedTriggeredAutomatically(false)
 ,	fIgnoreFrameResized(false)
 ,	fFrameResizedCalled(true)
{
	BRect rect = Bounds();

	// background
	fBackground = new BView(rect, "background", B_FOLLOW_ALL,
		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
	fBackground->SetViewColor(0,0,0);
	AddChild(fBackground);

	// menu
	fMenuBar = new BMenuBar(fBackground->Bounds(), "menu");
	CreateMenu();
	fBackground->AddChild(fMenuBar);
	fMenuBar->ResizeToPreferred();
	fMenuBarHeight = (int)fMenuBar->Frame().Height() + 1;
	fMenuBar->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);

	// video view
	BRect video_rect = BRect(0, fMenuBarHeight, rect.right, rect.bottom);
	fVideoView = new VideoView(video_rect, "video display", B_FOLLOW_ALL,
		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
	fBackground->AddChild(fVideoView);

	fVideoView->MakeFocus();

//	SetSizeLimits(fControlViewMinWidth - 1, 32767,
//		fMenuBarHeight + fControlViewHeight - 1, fMenuBarHeight
//		+ fControlViewHeight - 1);

//	SetSizeLimits(320 - 1, 32767, 240 + fMenuBarHeight - 1, 32767);

	SetSizeLimits(0, 32767, fMenuBarHeight - 1, 32767);

	fController->SetVideoView(fVideoView);
	fController->SetVideoNode(fVideoView->Node());

	fVideoView->IsOverlaySupported();

	SetupInterfaceMenu();
	SelectInitialInterface();
	SetInterfaceMenuMarker();
	SetupChannelMenu();
	SetChannelMenuMarker();

	VideoFormatChange(fSourceWidth, fSourceHeight, fWidthScale, fHeightScale);

	CenterOnScreen();
}
コード例 #3
0
ファイル: EditorTextView.cpp プロジェクト: mmlr/libbsvg
void
EditorTextView::FrameResized(float new_width, float new_height)
{
	SetTextRect(BRect(0, 0, new_width, new_height));
}
コード例 #4
0
ファイル: Slider.cpp プロジェクト: gedrin/Becasso
void Slider::KeyDown (const char *bytes, int32 numBytes)
{
	if (numBytes == 1)
	{
		switch (*bytes)
		{
		case B_ESCAPE:
		{
			if (tc)
			{
				// printf ("TextControl is open\n");
				RemoveChild (tc);
				delete (tc);
				tc = NULL;
			}
			break;
		}
		case B_SPACE:
		case B_ENTER:
		{	
			//printf ("Enter\n");
			if (tc)
			{
				// printf ("TextControl is open\n");
				BMessage *key = new BMessage ('tcVC');
				MessageReceived (key);
				delete key;
			}
			else
			{
				knobpos = BPoint (float (value - min)/(max - min)*(width - knobsize), 1);
				BRect kbr = BRect (knobpos.x + sep, knobpos.y, knobpos.x + knobsize - 2 + sep, knobpos.y + height - 3);
		//		kbr.PrintToStream();
				tc = new BTextControl (kbr, "slider value field", "", "", new BMessage ('tcVC'));
				tc->SetTarget (this);
				tc->SetDivider (0);
				EnterFilter *filter = new EnterFilter (this);
				tc->TextView()->AddFilter (filter);
				char vs[64];
				sprintf (vs, fmt, value);
				tc->SetText (vs);
				AddChild (tc);
				tc->MakeFocus (true);
				inherited::KeyDown (bytes, numBytes);
			}
			break;
		}
		case B_LEFT_ARROW:
			//printf ("Left\n");
			if (value > min)
			{
				value -= step;
				Invalidate();
				NotifyTarget();
			}
			break;
		case B_RIGHT_ARROW:
			//printf ("Right\n");
			if (value < max)
			{
				value += step;
				Invalidate();
				NotifyTarget();
			}
			break;
		case B_TAB:
			// printf ("Tab\n");
			if (tc)
			{
				// printf ("TextControl is open\n");
				BMessage *key = new BMessage ('tcVC');
				MessageReceived (key);
				delete key;
			}
			else
			{
			// MakeFocus (false);
				inherited::KeyDown (bytes, numBytes);
				Invalidate();
				break;
			}
		default:
			inherited::KeyDown (bytes, numBytes);
		}
	}
	else
		inherited::KeyDown (bytes, numBytes);
}
コード例 #5
0
ファイル: main.cpp プロジェクト: HaikuArchives/Stamina
CharismaWindow::CharismaWindow(BPoint origin):
	BWindow(BRect(origin.x,origin.y,origin.x+200,origin.y+80),
		"Charisma", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 
		B_NOT_RESIZABLE|B_NOT_ZOOMABLE|B_WILL_ACCEPT_FIRST_CLICK)
{
	BRect nullrect(0,0,0,0),r;
	BMenu *m;
	BWindow *w;
	char buf[100];
	
	isminim=0;
	
	// le menu
	menubar=new BMenuBar(BRect(0,0,0,0),"menu bar");
	m=new BMenu("File");
	m->AddItem(new BMenuItem("About…",new BMessage(kMsg_About)));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("Quit",new BMessage(B_QUIT_REQUESTED),'Q'));
	menubar->AddItem(m);
	m=new BMenu("Settings");
	m->AddItem(new BMenuItem("Select Web Directory…",new BMessage(kMsg_SelectDirectory)));
	m->AddSeparatorItem();
	m->AddItem(extcontrol_item=new BMenuItem("External Control",new BMessage(kMsg_ExternalControl)));
	m->AddItem(netposautoset_item=new BMenuItem("Net+ Autosettings",new BMessage(kMsg_NetposAutosettings)));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("Clear Hits",new BMessage(kMsg_ClearHits)));
	menubar->AddItem(m);
	AddChild(menubar);

	// le fond gris
	r=Frame();
	setupview=new BView(
		BRect(0,menubar->Frame().bottom,r.Width(),r.Height()),
		"background",B_FOLLOW_NONE,B_WILL_DRAW);
	setupview->SetViewColor(0xDD,0xDD,0xDD);
	AddChild(setupview);
	
	// "Mode"
	m=new BPopUpMenu("");
	m->AddItem(new BMenuItem("Disabled",MSG));
	m->AddItem(new BMenuItem("Offline",MSG));
	m->AddItem(new BMenuItem("Online",MSG));
	modemenu=new BMenuField(
		BRect(10.0f,10.0f,20.0f,20.0f),"mode",
		"Mode:",
		m);
	BMenuField_resize(modemenu);
	setupview->AddChild(modemenu);

	// "Refresh"
	m=new BPopUpMenu("");
	m->AddItem(new BMenuItem("Dumb",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("Always",MSG));
	m->AddItem(new BMenuItem("Once per session",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("After 1 hour",MSG));
	m->AddItem(new BMenuItem("After 6 hours",MSG));
	m->AddItem(new BMenuItem("After 12 hours",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("After 1 day",MSG));
	m->AddItem(new BMenuItem("After 2 days",MSG));
	m->AddItem(new BMenuItem("After 3 days",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("After 1 week",MSG));
	m->AddItem(new BMenuItem("After 2 weeks",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("After 1 month",MSG));
	m->AddItem(new BMenuItem("After 2 month",MSG));
	m->AddItem(new BMenuItem("After 6 month",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("After 1 year",MSG));
	m->AddItem(new BMenuItem("After 2 years",MSG));
	m->AddSeparatorItem();
	m->AddItem(new BMenuItem("never",MSG));
	smartrefresh=new BMenuField(
		rectunder(modemenu),"refresh",
		"Refresh:",
		m);
	BMenuField_resize(smartrefresh);
	setupview->AddChild(smartrefresh);
	
	// "Hits"
	r.left=10.0f;
	r.top=smartrefresh->Frame().bottom+10.0f;
	r.right=r.left+setupview->StringWidth("hits: 99999");
	r.bottom=r.top+BView_textheight(setupview);
	hits=new BStringView(r,"hits","");
	setupview->AddChild(hits);

	if(!gregistered){
		sprintf(buf,"This copy is not registered");
		r.left=10.0f;
		r.top=hits->Frame().bottom+10.0f;
		r.right=r.left+setupview->StringWidth(buf);
		r.bottom=r.top+BView_textheight(setupview);
		setupview->AddChild(new BStringView(r,NULL,buf));
	}

	r=BView_childrenframe(setupview);
	setupview->ResizeTo(r.right+10,r.bottom+10);
	r=setupview->Frame();
	ResizeTo(r.right,r.bottom);
	
	hitcount=0;
	hitspulser=spawn_thread(pulsehits_,"StaminaWindow::pulsehits",
		B_NORMAL_PRIORITY,this);
	if(hitspulser<B_NO_ERROR)
		fatal(__FILE__,__LINE__,"spawn_thread failed");
	resume_thread(hitspulser);
	
	selectdirpanel=new BFilePanel(
		B_OPEN_PANEL,
		&BMessenger(this),
		NULL,
		B_DIRECTORY_NODE,
		false,
		new BMessage(kMsg_DirSelected));
	w=selectdirpanel->Window();
	w->Lock();
	w->SetTitle("Select Web Directory");
	selectdirpanel->SetButtonLabel(B_DEFAULT_BUTTON,"Select");
	r=w->FindView("cancel button")->Frame();
	r.right=r.left-15.0f;
	r.left=10.0f;
	r.bottom=r.top+BView_textheight(w->ChildAt(0));
	currentdir=new BStringView(r,"current","",B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM);
	w->ChildAt(0)->AddChild(currentdir);
	w->Unlock();
	
}
コード例 #6
0
void KlondikeView::Draw(BRect rect)
{
	
	SetDrawingMode(B_OP_ALPHA);
	
	int hSpacing = _CardHSpacing();
	
	// stock
	int revealed = 0;
	for (short i = 0; i < 24; i++)
		if (fStock[i]->fRevealed)
			revealed++;
	
	if (revealed < 24)
		DrawBitmap(fBack[0], BRect(hSpacing, 15,
			hSpacing + CARD_WIDTH, 15 + CARD_HEIGHT));
	else
		DrawBitmap(fEmpty, BRect(hSpacing, 15,
		hSpacing + CARD_WIDTH, 15 + CARD_HEIGHT));
	
	// waste
	if (fIsWasteCardPicked) {
		int lastWasteCard = fWasteCard - 1;
		
		if (lastWasteCard != -1)
			while (fStock[lastWasteCard]->fRevealed) {
				lastWasteCard--;
				if (lastWasteCard == -1) {
					break;
				}
			}
		
		if (lastWasteCard != -1)
			DrawBitmap(
				fCards[fStock[lastWasteCard]->fColor
				* CARDS_IN_SUIT + fStock[lastWasteCard]->fValue],
				BRect(2 * hSpacing + CARD_WIDTH, 15,
				2 * hSpacing + 2 * CARD_WIDTH, 15 + CARD_HEIGHT));
		else
			DrawBitmap(fEmpty, BRect(2 * hSpacing + CARD_WIDTH, 15,
				2 * hSpacing + 2 * CARD_WIDTH, 15 + CARD_HEIGHT));
	} else if (fWasteCard != -1) {
		if (fWasteCard > 23) {
			fWasteCard = -1;
			
			fPoints -= 100;
			if (fPoints < 0)
				fPoints = 0;
			
			Invalidate();
			return;
		}
		
		while (fStock[fWasteCard]->fRevealed) {
			fWasteCard++;
			if (fWasteCard > 23) {
				fWasteCard = -1;
				
				fPoints -= 100;
				if (fPoints < 0)
					fPoints = 0;
				
				break;
			}
		}
		
		rect = BRect(2 * hSpacing + CARD_WIDTH, 15,
			2 * hSpacing + 2 * CARD_WIDTH, 15 + CARD_HEIGHT);
		
		if (fWasteCard != -1)
			DrawBitmap(
				fCards[fStock[fWasteCard]->fColor
				* CARDS_IN_SUIT + fStock[fWasteCard]->fValue], rect);
		else
			DrawBitmap(fEmpty, rect);
			
	} else
		DrawBitmap(fEmpty, BRect(2 * hSpacing + CARD_WIDTH, 15,
			2 * hSpacing + 2 * CARD_WIDTH, 15 + CARD_HEIGHT));
	
	// foundations
	for (short i = 0; i < 4; i++) {
		BRect rect = BRect((i + 4)*hSpacing + (i + 3)*CARD_WIDTH, 15,
			(i + 4)*hSpacing + (i + 4)*CARD_WIDTH, 15 + CARD_HEIGHT);
		
		if (fFoundations[i]	== -1) {
			DrawBitmap(fEmpty, rect);
		} else {
			DrawBitmap(
				fCards[fFoundationsColors[i] * CARDS_IN_SUIT + fFoundations[i]],
				rect);
		}
	}
	
	// tableaux
	for (short i = 0; i < 7; i++) {
		BRect rect(hSpacing + i * (CARD_WIDTH + hSpacing), 146,
				hSpacing + (i + 1) * CARD_WIDTH + i * hSpacing,
				146 + CARD_HEIGHT);
		if (solitare.fBoard[i] == NULL)
			DrawBitmap(fEmpty, rect);
		else {
			card* currentCard;
			for (currentCard = solitare.fBoard[i]; currentCard != NULL;
					currentCard = currentCard->fNextCard) {
				if (currentCard->fRevealed == false) {
					short numberOfBacks = 0;
						// 1 back
					while (currentCard->fNextCard != NULL
						&& currentCard->fNextCard->fRevealed == false
						&& numberOfBacks < CACHED_BACKS) {
						currentCard = currentCard->fNextCard;
						numberOfBacks++;
					}
					rect.bottom += numberOfBacks * 18;
					DrawBitmap(fBack[numberOfBacks], rect);
					rect.top += 18 * numberOfBacks;
				} else if (currentCard->fEffect != E_HIDDEN) {
					DrawBitmap(fCards[currentCard->fColor * CARDS_IN_SUIT
						+ currentCard->fValue], rect);
					switch (currentCard->fEffect) {
					case E_ALPHA25:
						SetHighColor(0, 85, 0, 63);
						break;
					case E_ALPHA50:
						SetHighColor(0, 85, 0, 127);
						break;
					case E_ALPHA75:
						SetHighColor(0, 85, 0, 190);
						break;
					case E_GREEN:
						SetHighColor(0, 184, 0, 127);
						break;
					case E_RED:
						SetHighColor(255, 0, 0, 127);
						break;
					default:
						SetHighColor(0, 85, 0, 0);
					}
					FillRect(rect);
				}
				rect.top += 18;
				rect.bottom = rect.top + CARD_HEIGHT;
			}
		}
	}

	BString points = BString();
	points << fPoints;

	BFont biggerFont = BFont();
	biggerFont.SetFace(B_BOLD_FACE);
	biggerFont.SetSize(20);

	BFont bigFont = BFont();
	bigFont.SetFace(B_BOLD_FACE);
	bigFont.SetSize(18);

	BFont smallFont = BFont();
	smallFont.SetSize(12);

	SetHighColor(255, 255, 255);

	SetFont(&bigFont);
	DrawString(points,
		BPoint((windowWidth + 10 - bigFont.StringWidth(points)) / 2,
		windowHeight - 15));

	SetFont(&smallFont);
	DrawString(B_TRANSLATE("points"), BPoint((windowWidth + 10
		- smallFont.StringWidth(B_TRANSLATE("points"))) / 2, windowHeight));
	
	if (fWon) {
		SetHighColor(255, 0, 0);
		SetFont(&biggerFont);
		DrawString(B_TRANSLATE("YOU WON"), BPoint((windowWidth + 10
			- biggerFont.StringWidth(B_TRANSLATE("YOU WON"))) / 2,
			windowHeight - 40));
	}
}
コード例 #7
0
ファイル: TeamMonitorWindow.cpp プロジェクト: Ithamar/haiku
TeamMonitorWindow::TeamMonitorWindow()
	:
	BWindow(BRect(0, 0, 350, 100), B_TRANSLATE("Team monitor"),
		B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL,
		B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS
			| B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS,
		B_ALL_WORKSPACES),
	fQuitting(false),
	fUpdateRunner(NULL)
{
	BGroupLayout* layout = new BGroupLayout(B_VERTICAL);
	float inset = 10;
	layout->SetInsets(inset, inset, inset, inset);
	layout->SetSpacing(inset);
	SetLayout(layout);

	layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	fListView = new BListView("teams");
	fListView->SetSelectionMessage(new BMessage(TM_SELECTED_TEAM));

	BScrollView* scrollView = new BScrollView("scroll_teams", fListView,
		0, B_SUPPORTS_LAYOUT, false, true, B_FANCY_BORDER);
	scrollView->SetExplicitMinSize(BSize(B_SIZE_UNSET, 150));

	fKillButton = new BButton("kill", B_TRANSLATE("Kill application"),
		new BMessage(TM_KILL_APPLICATION));
	fKillButton->SetEnabled(false);

	fQuitButton = new BButton("quit", B_TRANSLATE("Quit application"),
		new BMessage(TM_QUIT_APPLICATION));
	fQuitButton->SetEnabled(false);

	fDescriptionView = new TeamDescriptionView;

	BButton* forceReboot = new BButton("force", B_TRANSLATE("Force reboot"),
		new BMessage(TM_FORCE_REBOOT));

	fRestartButton = new BButton("restart", B_TRANSLATE("Restart the desktop"),
		new BMessage(TM_RESTART_DESKTOP));

	fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
		new BMessage(TM_CANCEL));
	SetDefaultButton(fCancelButton);

	BGroupLayoutBuilder(layout)
		.Add(scrollView)
		.AddGroup(B_HORIZONTAL)
			.Add(fKillButton)
			.Add(fQuitButton)
			.AddGlue()
			.End()
		.Add(fDescriptionView)
		.AddGroup(B_HORIZONTAL)
			.Add(forceReboot)
			.AddGlue()
			.Add(fRestartButton)
			.AddGlue(inset)
			.Add(fCancelButton);

	CenterOnScreen();

	fRestartButton->Hide();

	AddShortcut('T', B_COMMAND_KEY | B_OPTION_KEY,
		new BMessage(kMsgLaunchTerminal));
	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));

	gLocalizedNamePreferred
		= BLocaleRoster::Default()->IsFilesystemTranslationPreferred();

	gTeamMonitorWindow = this;

	this->AddCommonFilter(new BMessageFilter(B_ANY_DELIVERY,
		B_ANY_SOURCE, B_KEY_DOWN, FilterKeyDown));

	if (be_app->Lock()) {
		be_app->AddCommonFilter(new BMessageFilter(B_ANY_DELIVERY,
			B_ANY_SOURCE, B_LOCALE_CHANGED, FilterLocaleChanged));
		be_app->Unlock();
	}
}
コード例 #8
0
ファイル: ModifierKeysWindow.cpp プロジェクト: RAZVOR/haiku
ModifierKeysWindow::ModifierKeysWindow()
    :
    BWindow(BRect(0, 0, 360, 220), B_TRANSLATE("Modifier keys"),
           B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
           | B_AUTO_UPDATE_SIZE_LIMITS)
{
    get_key_map(&fCurrentMap, &fCurrentBuffer);
    get_key_map(&fSavedMap, &fSavedBuffer);

    BStringView* keyRole = new BStringView("key role",
                                           B_TRANSLATE_COMMENT("Role", "As in the role of a modifier key"));
    keyRole->SetAlignment(B_ALIGN_RIGHT);
    keyRole->SetFont(be_bold_font);

    BStringView* keyLabel = new BStringView("key label",
                                            B_TRANSLATE_COMMENT("Key", "As in a computer keyboard key"));
    keyLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
    keyLabel->SetFont(be_bold_font);

    BMenuField* shiftMenuField = _CreateShiftMenuField();
    shiftMenuField->SetAlignment(B_ALIGN_RIGHT);

    BMenuField* controlMenuField = _CreateControlMenuField();
    controlMenuField->SetAlignment(B_ALIGN_RIGHT);

    BMenuField* optionMenuField = _CreateOptionMenuField();
    optionMenuField->SetAlignment(B_ALIGN_RIGHT);

    BMenuField* commandMenuField = _CreateCommandMenuField();
    commandMenuField->SetAlignment(B_ALIGN_RIGHT);

    fShiftConflictView = new ConflictView("shift warning view");
    fShiftConflictView->SetExplicitMaxSize(BSize(15, 15));

    fControlConflictView = new ConflictView("control warning view");
    fControlConflictView->SetExplicitMaxSize(BSize(15, 15));

    fOptionConflictView = new ConflictView("option warning view");
    fOptionConflictView->SetExplicitMaxSize(BSize(15, 15));

    fCommandConflictView = new ConflictView("command warning view");
    fCommandConflictView->SetExplicitMaxSize(BSize(15, 15));

    fCancelButton = new BButton("cancelButton", B_TRANSLATE("Cancel"),
                                new BMessage(B_QUIT_REQUESTED));

    fRevertButton = new BButton("revertButton", B_TRANSLATE("Revert"),
                                new BMessage(kMsgRevertModifiers));
    fRevertButton->SetEnabled(false);

    fOkButton = new BButton("okButton", B_TRANSLATE("Set modifier keys"),
                            new BMessage(kMsgApplyModifiers));
    fOkButton->MakeDefault(true);

    // Build the layout
    SetLayout(new BGroupLayout(B_VERTICAL));

    AddChild(BLayoutBuilder::Group<>(B_VERTICAL)
             .AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
             .Add(keyRole, 0, 0)
             .Add(keyLabel, 1, 0, 2, 1)

             .Add(shiftMenuField->CreateLabelLayoutItem(), 0, 1)
             .Add(shiftMenuField->CreateMenuBarLayoutItem(), 1, 1)
             .Add(fShiftConflictView, 2, 1)

             .Add(controlMenuField->CreateLabelLayoutItem(), 0, 2)
             .Add(controlMenuField->CreateMenuBarLayoutItem(), 1, 2)
             .Add(fControlConflictView, 2, 2)

             .Add(optionMenuField->CreateLabelLayoutItem(), 0, 3)
             .Add(optionMenuField->CreateMenuBarLayoutItem(), 1, 3)
             .Add(fOptionConflictView, 2, 3)

             .Add(commandMenuField->CreateLabelLayoutItem(), 0, 4)
             .Add(commandMenuField->CreateMenuBarLayoutItem(), 1, 4)
             .Add(fCommandConflictView, 2, 4)
             .End()
             .AddGlue()
             .AddGroup(B_HORIZONTAL)
             .Add(fCancelButton)
             .AddGlue()
             .Add(fRevertButton)
             .Add(fOkButton)
             .End()
             .SetInsets(B_USE_DEFAULT_SPACING)
            );

    _MarkMenuItems();
    _ValidateDuplicateKeys();

    CenterOnScreen();
}
コード例 #9
0
static BRect invalid_rect()
{
	return BRect(-1, -1, -1, -1);
}
コード例 #10
0
HApp::HApp() :BApplication(APP_SIG)
{
	HWindow *win = new HWindow(BRect(50,50,300,300),"IconMenu");
	win->Show();
}	
コード例 #11
0
ファイル: ModifierKeysWindow.cpp プロジェクト: RAZVOR/haiku
// fill out the icon with the stop symbol from app_server
void
ConflictView::_FillSavedIcon()
{
    // return if the fSavedIcon has already been filled out
    if (fSavedIcon != NULL && fSavedIcon->InitCheck() == B_OK)
        return;

    BPath path;
    status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
    if (status < B_OK) {
        FTRACE((stderr,
                "_FillWarningIcon() - find_directory failed: %s\n",
                strerror(status)));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    path.Append("app_server");
    BFile file;
    status = file.SetTo(path.Path(), B_READ_ONLY);
    if (status < B_OK) {
        FTRACE((stderr,
                "_FillWarningIcon() - BFile init failed: %s\n",
                strerror(status)));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    BResources resources;
    status = resources.SetTo(&file);
    if (status < B_OK) {
        FTRACE((stderr,
                "_WarningIcon() - BResources init failed: %s\n",
                strerror(status)));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    // Allocate the fSavedIcon bitmap
    fSavedIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32);
    if (fSavedIcon->InitCheck() < B_OK) {
        FTRACE((stderr, "_WarningIcon() - No memory for warning bitmap\n"));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    // Load the raw stop icon data
    size_t size = 0;
    const uint8* rawIcon;
    rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
              "stop", &size);

    // load vector warning icon into fSavedIcon
    if (rawIcon == NULL
            || BIconUtils::GetVectorIcon(rawIcon, size, fSavedIcon) < B_OK) {
        delete fSavedIcon;
        fSavedIcon = NULL;
    }
}
コード例 #12
0
BBitmap *targatobbitmap(
	const unsigned char* targa, int targasize)
{
	BBitmap *bitmap;
	int idlength;
	int colormaptype;
	int imagetype;
	int height;
	int width;
	int depth;
	int imagedescriptor;
	int rowbytes;
	int bitssize;
	unsigned char *bits;
	const unsigned char *ptarga;
	unsigned char *pbits;
	int i,j,k;
	int count;
	unsigned char px0,px1,px2;
	
	idlength=targa[0];
	
	colormaptype=targa[1];
	if(colormaptype!=0) return NULL;
	
	imagetype=targa[2];
	if(imagetype!=2 && imagetype!=10) return NULL;
	
	width=targa[12]+(targa[13]<<8);
	height=targa[14]+(targa[15]<<8);
	
	depth=targa[16];
	if(depth!=24) return NULL;
	
	imagedescriptor=targa[17];
	if(imagedescriptor!=0) return NULL;
	
	rowbytes=3*width;
	bitssize=height*rowbytes;
	if(imagetype==2 
	&& 18+idlength+bitssize>targasize) return NULL;	
	
	bits=new unsigned char[bitssize];
	if(!bits) return NULL;

	ptarga=targa+18+idlength;
	
	switch(imagetype){
	case 2:
		pbits=bits+(height-1)*rowbytes;
		for(j=0;j<height;j++){
			for(i=0;i<width;i++){
				pbits[2]=*ptarga++;
				pbits[1]=*ptarga++;
				pbits[0]=*ptarga++;
				pbits+=3;
			}
			pbits-=2*rowbytes;
		}
		break;

		
	case 10:	//	RLE
		pbits=bits+(height-1)*rowbytes;
		for(j=0;j<height;j++){
			for(i=0;i<width;i+=count){
				count=*ptarga++;
				if(count&0x80){
					count&=0x7F;
					count++;
					if(i+count>width) count=width-i;
					px2=*ptarga++;
					px1=*ptarga++;
					px0=*ptarga++;
					for(k=0;k<count;k++){
						pbits[2]=px2;
						pbits[1]=px1;
						pbits[0]=px0;
						pbits+=3;
					}
				}else{
					count++;
					if(i+count>width) count=width-i;
					for(k=0;k<count;k++){
						pbits[2]=*ptarga++;
						pbits[1]=*ptarga++;
						pbits[0]=*ptarga++;
						pbits+=3;
					}
				}
			}
			pbits-=2*rowbytes;
		}
		break;
	}
	
	bitmap=new BBitmap(BRect(0,0,width-1,height-1),B_RGB_32_BIT);
	bitmap->SetBits(bits,bitssize,0,B_RGB_32_BIT);
	
	delete[] bits;
		
	return bitmap;
}
コード例 #13
0
/*=============================================================================================*\
|	Draw																						|
+-----------------------------------------------------------------------------------------------+
|	Effet: Redessine la view selon son status.													|
|																								|
\*=============================================================================================*/
void BeNetButton::Draw(BRect updateRect)
{
	BPoint pPointList[8];
	BPoint cursor;
	uint32 iButton;
	float leftBmp = 0;
	float topBmp = 0;
	float leftLab = 0;
	float topLab = 0;
	bool m_bBorderIn = false;
	bool m_bBorderOut = false;
	BFont font;
	
	GetMouse(&cursor, &iButton);
	
	m_bMouseOver = false;
	if(cursor.x >= 0 && cursor.x < Bounds().Width() && cursor.y >= 0 && cursor.y < Bounds().Height())
	{
		m_bMouseOver = true;
	}

	
	//Mode de dessinement utilisant seulement des bitmap.
	if(m_iDrawMode == BENET_DM_FULL_BMP || (m_iDrawMode == BENET_DM_TOGGLE && !m_bToggle))
	{
		SetDrawingMode(B_OP_COPY);
		//Le bouton est disable.
		if(!IsEnabled())
		{
			DrawBitmap(m_pBitmap, BRect(3 * Bounds().Width(),0, 4 * Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}	
	
		//Le boutton est enfoncer
		else if(Value())
		{
			DrawBitmap(m_pBitmap, BRect(2 * Bounds().Width(),0, 3 * Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//La sourie est par dessus le bouton.
		else if(m_bMouseOver)
		{
			DrawBitmap(m_pBitmap, BRect(Bounds().Width(),0, 2 * Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//boutton par defaut
		else
		{
			DrawBitmap(m_pBitmap, BRect(0,0,Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}

	}
	else if(m_iDrawMode == BENET_DM_TOGGLE && m_bToggle)
	{
		SetDrawingMode(B_OP_COPY);		//Le bouton est disable.
		if(!IsEnabled())
		{
			DrawBitmap(m_pBitmap, BRect(3 * Bounds().Width(),Bounds().Height(), 4 * Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}	
	
		//Le boutton est enfoncer
		else if(Value())
		{
			DrawBitmap(m_pBitmap, BRect(2 * Bounds().Width(),Bounds().Height(), 3 * Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//La sourie est par dessus le bouton.
		else if(m_bMouseOver)
		{
			DrawBitmap(m_pBitmap, BRect(Bounds().Width(),Bounds().Height(), 2 * Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//boutton par defaut
		else
		{
			DrawBitmap(m_pBitmap, BRect(0,Bounds().Height(),Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}


	}
	

	
	///////////////////////////
	
	// Debut de l'ancient mode de dessinement.
	else if(m_iDrawMode == BENET_DM_DEFAULT)
	{
		//Aller chercher les propriete du font.
		GetFont(&font);		
		font_height height;
		font.GetHeight(&height);
		
		//Trouver le coin superieur gauche du bitmap.
		if(m_bLabel)
		{
			topBmp = 2;
		}
		else
		{
			if(m_bBitmap)topBmp= Bounds().Height() / 2 - m_pBitmap->Bounds().Height() / 2; 
		}
		if(m_bBitmap)leftBmp = Bounds().Width() / 2 - m_pBitmap->Bounds().Width() / 2;
		
		//Trouver le coin inferieur gauche de lu label.
		if(m_bBitmap)
		{
			topLab = Bounds().Height() -2 - height.descent;
		}
		else
		{
			topLab = Bounds().Height() / 2 + font.Size() / 2;
		}
		leftLab = Bounds().Width() / 2 - StringWidth(m_pzLabel) / 2;
		
		
		//Le bouton est disable.
		// Il est a 25% d'intensite.
		if(!IsEnabled())
		{
			SetHighColor(192,192,192,0);
			FillRect(BRect(0,0,Bounds().Width(), Bounds().Height()));
			SetDrawingMode(B_OP_BLEND);
			if(m_bBitmap)
			{
				DrawBitmap(m_pBitmap, BPoint(leftBmp,topBmp));
			}
			if(m_bLabel)
			{
				SetHighColor(0, 0, 0, 0);
				DrawString(m_pzLabel, BPoint(leftLab,topLab));
			}
			SetHighColor(192,192,192,0);
			FillRect(BRect(0,0,Bounds().Width(), Bounds().Height()));
			SetDrawingMode(B_OP_COPY);
		}	
	
		//Le boutton est enfoncer
		// les couleur du boutton sont inverser.
		else if(Value())
		{
			SetHighColor(192, 192, 192, 0);
			FillRect(BRect(2,2,Bounds().Width()-2, Bounds().Height()-2));
			if(m_bBitmap)
			{
				DrawBitmap(m_pBitmap, BPoint(leftBmp,topBmp));
			}
			if(m_bLabel)
			{
				SetHighColor(0, 0, 0, 0);
				DrawString(m_pzLabel, BPoint(leftLab,topLab));
			}			
			m_bBorderIn = true;
			SetDrawingMode(B_OP_INVERT);
			FillRect(BRect(2,2,Bounds().Width()-2, Bounds().Height()-2));
			SetDrawingMode(B_OP_COPY);
		}
		//Le boutton est simplement dessiner
		else 
		{
			if(m_bMouseOver) m_bBorderOut = true;
			SetHighColor(192, 192, 192, 0);
			FillRect(BRect(0,0,Bounds().Width(), Bounds().Height()));
			if(m_bBitmap)
			{
				DrawBitmap(m_pBitmap, BPoint(leftBmp,topBmp));
			}
			if(m_bLabel)
			{
				SetHighColor(0, 0, 0, 0);
				DrawString(m_pzLabel, BPoint(leftLab,topLab));
			}
		}
	

		//Le contour foncer
		if(m_bBorderIn || m_bBorderOut)
		{
			SetHighColor(64, 64, 64, 0);
			pPointList[0] = BPoint(0,2);
			pPointList[1] = BPoint(2,0);
			pPointList[2] = BPoint(Bounds().Width() -2,0);
			pPointList[3] = BPoint(Bounds().Width(),2);
			pPointList[4] = BPoint(Bounds().Width(),Bounds().Height() -2);
			pPointList[5] = BPoint(Bounds().Width() -2,Bounds().Height());
			pPointList[6] = BPoint(2,Bounds().Height());
			pPointList[7] = BPoint(0,Bounds().Height() -2);
			StrokePolygon(pPointList, 8, true,  B_SOLID_HIGH);	
		}

		// Le boutton est enfoncer
		if (m_bBorderIn)
		{
			SetHighColor(128, 128, 128, 0);
			pPointList[0] = BPoint(1,Bounds().Height() -2);
			pPointList[1] = BPoint(1,2);
			pPointList[2] = BPoint(2,1);
			pPointList[3] = BPoint(Bounds().Width() -2,1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);	
	
			SetHighColor(255, 255, 255, 0);
			pPointList[0] = BPoint(Bounds().Width() -1,2);
			pPointList[1] = BPoint(Bounds().Width() -1,Bounds().Height() -2);
			pPointList[2] = BPoint(Bounds().Width() -2,Bounds().Height() -1);
			pPointList[3] = BPoint(2,Bounds().Height() -1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);
			SetHighColor(192, 192, 192, 0);
		}

		// Le boutton est surelever.
		else if(m_bBorderOut)
		{	
			SetHighColor(255, 255, 255, 0);
			pPointList[0] = BPoint(1,Bounds().Height() -2);
			pPointList[1] = BPoint(1,2);
			pPointList[2] = BPoint(2,1);
			pPointList[3] = BPoint(Bounds().Width() -2,1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);	
	
			SetHighColor(128, 128, 128, 0);
			pPointList[0] = BPoint(Bounds().Width() -1,2);
			pPointList[1] = BPoint(Bounds().Width() -1,Bounds().Height() -2);
			pPointList[2] = BPoint(Bounds().Width() -2,Bounds().Height() -1);
			pPointList[3] = BPoint(2,Bounds().Height() -1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);
			SetHighColor(192, 192, 192, 0);
		}
	}
}
コード例 #14
0
void
ThemeInterfaceView::AllAttached()
{
	BView::AllAttached();

	SetViewPanelBgColor();
	
	fThemeManager = new ThemeManager;

	BRect frame = Bounds();
	frame.InsetBy(10.0, 10.0);
	
	// add the theme listview
	BRect list_frame = frame;
	list_frame.right = 130;
	fThemeList = new BListView(list_frame.InsetByCopy(3.0, 3.0), "themelist");
	fThemeListSV = new BScrollView("themelistsv", fThemeList, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true);
	AddChild(fThemeListSV);
	fThemeList->SetSelectionMessage(new BMessage(kThemeSelected));
	fThemeList->SetInvocationMessage(new BMessage(kApplyThemeBtn));
	fThemeList->SetTarget(this);

	// buttons...
	fNewBtn = new BButton(BRect(), "create", B_TRANSLATE("New"), new BMessage(kCreateThemeBtn));
	AddChild(fNewBtn);
	fNewBtn->SetTarget(this);
	fNewBtn->ResizeToPreferred();
	fNewBtn->MoveTo(fThemeListSV->Frame().right + 15.0, frame.bottom - fNewBtn->Bounds().Height());
	BPoint lt = fNewBtn->Frame().LeftTop();

	fNameText = new BTextControl(BRect(), "text", "", "My Theme", new BMessage(kCreateThemeBtn));
	AddChild(fNameText);
	fNameText->SetTarget(this);
	fNameText->ResizeToPreferred();
	// default is a bit small
	fNameText->ResizeBy(fNameText->Bounds().Width(), 0);
	fNameText->MoveTo(lt);
	fNameText->MoveBy(0, (fNewBtn->Bounds().Height() - fNameText->Bounds().Height()) / 2);
	//fNameText->MoveBy(0, - fNewBtn->Bounds().Height());
	fNameText->Hide();

	lt.x = fNewBtn->Frame().right + 10.0;
	fSaveBtn = new BButton(BRect(), "save", B_TRANSLATE("Save"), new BMessage(kSaveThemeBtn));
	AddChild(fSaveBtn);
	fSaveBtn->SetTarget(this);
	fSaveBtn->ResizeToPreferred();
	fSaveBtn->MoveTo(lt);

	lt.x = fSaveBtn->Frame().right + 10.0;
	fDeleteBtn = new BButton(BRect(), "delete", B_TRANSLATE("Delete"), new BMessage(kDeleteThemeBtn));
	AddChild(fDeleteBtn);
	fDeleteBtn->SetTarget(this);
	fDeleteBtn->ResizeToPreferred();
	fDeleteBtn->MoveTo(lt);

	// buttons...
	fSetShotBtn = new BButton(BRect(), "makeshot", B_TRANSLATE("Add screenshot"), new BMessage(kMakeScreenshot), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	AddChild(fSetShotBtn);
	fSetShotBtn->SetTarget(this);
	fSetShotBtn->ResizeToPreferred();
	
	fMoreThemesBtn = new BButton(BRect(), "getthemes", B_TRANSLATE("More themes"), new BMessage(skOnlineThemes), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	AddChild(fMoreThemesBtn);
	fMoreThemesBtn->SetTarget(this);
	fMoreThemesBtn->ResizeToPreferred();

	fDefaultsBtn = new BButton(BRect(), "defaults", B_TRANSLATE("Defaults"), new BMessage(B_PREF_APP_SET_DEFAULTS), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	AddChild(fDefaultsBtn);
	fDefaultsBtn->ResizeToPreferred();
	fDefaultsBtn->SetTarget(this);

	fApplyBtn = new BButton(BRect(), "apply", B_TRANSLATE("Apply"), new BMessage(kApplyThemeBtn), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	AddChild(fApplyBtn);
	fApplyBtn->ResizeToPreferred();
	fApplyBtn->SetTarget(this);

	float widest = max_c(fSetShotBtn->Bounds().Width(), fMoreThemesBtn->Bounds().Width());
	widest = max_c(widest, fDefaultsBtn->Bounds().Width());
	widest = max_c(widest, fApplyBtn->Bounds().Width());
	float height = fSetShotBtn->Bounds().Height();
	fSetShotBtn->ResizeTo(widest, height);
	fMoreThemesBtn->ResizeTo(widest, height);
	fDefaultsBtn->ResizeTo(widest, height);
	fApplyBtn->ResizeTo(widest, height);
	
	fSetShotBtn->MoveTo(frame.right - widest, frame.top + 5.0);
	fMoreThemesBtn->MoveTo(frame.right - widest, fSetShotBtn->Frame().bottom + 10.0);
	fApplyBtn->MoveTo(frame.right - widest, fNewBtn->Frame().top - fApplyBtn->Bounds().Height() - 10);
	fDefaultsBtn->MoveTo(frame.right - widest, fNewBtn->Frame().top - (fApplyBtn->Bounds().Height() + 10) * 2);

	// add the preview screen
	BRect preview_frame(fNewBtn->Frame().left, fThemeListSV->Frame().top, frame.right - widest - 10, fNewBtn->Frame().top - 10);

	fTabView = new BTabView(preview_frame, "tabs");
	fTabView->SetViewPanelBgColor();
	AddChild(fTabView);

	preview_frame = fTabView->ContainerView()->Bounds();

	fScreenshotTab = new BView(preview_frame, B_TRANSLATE("Screenshot"), B_FOLLOW_ALL, B_WILL_DRAW);
	fScreenshotTab->SetViewPanelBgColor();
	//AddChild(fScreenshotTab);
	fTabView->AddTab(fScreenshotTab);
	fTabView->Select(0L);

	fScreenshotPane = new ScreenshotView(preview_frame, "screenshot", B_FOLLOW_ALL, B_WILL_DRAW);
	fScreenshotTab->AddChild(fScreenshotPane);
	fScreenshotPane->SetViewPanelBgColor();
	
	fScreenshotText = new BStringView(BRect(), "sshotnone", B_TRANSLATE("No theme selected"), B_FOLLOW_ALL);
	fScreenshotText->SetFontSize(20.0);
	fScreenshotText->SetAlignment(B_ALIGN_CENTER);
	fScreenshotTab->AddChild(fScreenshotText);
	fScreenshotText->SetViewPanelBgColor();
	fScreenshotText->ResizeToPreferred();
	fScreenshotText->ResizeTo(fScreenshotTab->Bounds().Width() - 10.0, fScreenshotText->Bounds().Height());
	fScreenshotText->MoveTo(fScreenshotTab->Bounds().left + 5.0,
							((fScreenshotTab->Frame().Height() - fScreenshotText->Frame().Height()) / 2.0));


	// TODO: real preview from actual data and BControlLook & co
	//fTabView->AddTab(new BStringView(fTabView->ContainerView()->Bounds(), B_TRANSLATE("Preview"), "TODO", B_FOLLOW_ALL, B_WILL_DRAW));


	// TODO: theme informations
	fDetails = new BTextView(preview_frame, B_TRANSLATE("Details"), preview_frame.InsetByCopy(3,3), B_FOLLOW_ALL, B_WILL_DRAW);
	fDetails->SetText("TODO");
	fTabView->AddTab(fDetails);

	// Theme hyperlink
	/*
	BStringView* hlink = new BStringView(BRect(), "theme_hyperlink", B_TRANSLATE("More themes online"), new BMessage(skOnlineThemes), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
	AddChild(hlink);
	hlink->SetClickText(hlink->GetText(), *this);
	hlink->ResizeToPreferred();
	hlink->MoveTo(frame.right - hlink->Bounds().Width(), fNewBtn->Frame().top + 5);
	*/
	
	// the addons list view

	preview_frame = fTabView->ContainerView()->Bounds();
	preview_frame.right -= B_V_SCROLL_BAR_WIDTH;
	fAddonList = new BListView(preview_frame/*BRect()*/, "addonlist");

	PopulateAddonList();

	fAddonListSV = new BScrollView(B_TRANSLATE("Options"), fAddonList, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true);
	fAddonList->SetSelectionMessage(new BMessage(kThemeSelected));
	fAddonList->SetInvocationMessage(new BMessage(kApplyThemeBtn));
	fAddonList->SetTarget(this);	


	fTabView->AddTab(fAddonListSV);

	PopulateThemeList();
}
コード例 #15
0
ScreenWindow::ScreenWindow(ScreenSettings* settings)
	:
	BWindow(settings->WindowFrame(), B_TRANSLATE_SYSTEM_NAME("Screen"),
		B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
		| B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES),
	fIsVesa(false),
	fBootWorkspaceApplied(false),
	fOtherRefresh(NULL),
	fScreenMode(this),
	fUndoScreenMode(this),
	fModified(false)
{
	BScreen screen(this);

	accelerant_device_info info;
	if (screen.GetDeviceInfo(&info) == B_OK
		&& !strcasecmp(info.chipset, "VESA"))
		fIsVesa = true;

	_UpdateOriginal();
	_BuildSupportedColorSpaces();
	fActive = fSelected = fOriginal;

	fSettings = settings;

	// we need the "Current Workspace" first to get its height

	BPopUpMenu *popUpMenu = new BPopUpMenu(B_TRANSLATE("Current workspace"),
		true, true);
	fAllWorkspacesItem = new BMenuItem(B_TRANSLATE("All workspaces"),
		new BMessage(WORKSPACE_CHECK_MSG));
	popUpMenu->AddItem(fAllWorkspacesItem);
	BMenuItem *item = new BMenuItem(B_TRANSLATE("Current workspace"),
		new BMessage(WORKSPACE_CHECK_MSG));

	popUpMenu->AddItem(item);
	fAllWorkspacesItem->SetMarked(true);

	BMenuField* workspaceMenuField = new BMenuField("WorkspaceMenu", NULL,
		popUpMenu);
	workspaceMenuField->ResizeToPreferred();

	// box on the left with workspace count and monitor view

	BBox* screenBox = new BBox("screen box");
	BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 5.0);
	layout->SetInsets(10, 10, 10, 10);
	screenBox->SetLayout(layout);

	fMonitorInfo = new BStringView("monitor info", "");
	screenBox->AddChild(fMonitorInfo);

	fMonitorView = new MonitorView(BRect(0.0, 0.0, 80.0, 80.0),
		"monitor", screen.Frame().IntegerWidth() + 1,
		screen.Frame().IntegerHeight() + 1);
	screenBox->AddChild(fMonitorView);

	fColumnsControl = new BTextControl(B_TRANSLATE("Columns:"), "0",
		new BMessage(kMsgWorkspaceColumnsChanged));
	fRowsControl = new BTextControl(B_TRANSLATE("Rows:"), "0",
		new BMessage(kMsgWorkspaceRowsChanged));

	screenBox->AddChild(BLayoutBuilder::Grid<>(5.0, 5.0)
		.Add(new BStringView("", B_TRANSLATE("Workspaces")), 0, 0, 3)
		.AddTextControl(fColumnsControl, 0, 1, B_ALIGN_RIGHT)
		.AddGroup(B_HORIZONTAL, 0, 2, 1)
			.Add(_CreateColumnRowButton(true, false))
			.Add(_CreateColumnRowButton(true, true))
			.End()
		.AddTextControl(fRowsControl, 0, 2, B_ALIGN_RIGHT)
		.AddGroup(B_HORIZONTAL, 0, 2, 2)
			.Add(_CreateColumnRowButton(false, false))
			.Add(_CreateColumnRowButton(false, true))
			.End()
		.View());

	fBackgroundsButton = new BButton("BackgroundsButton",
		B_TRANSLATE("Set background" B_UTF8_ELLIPSIS),
		new BMessage(BUTTON_LAUNCH_BACKGROUNDS_MSG));
	fBackgroundsButton->SetFontSize(be_plain_font->Size() * 0.9);
	screenBox->AddChild(fBackgroundsButton);

	// box on the right with screen resolution, etc.

	BBox* controlsBox = new BBox("controls box");
	controlsBox->SetLabel(workspaceMenuField);
	BGroupView* outerControlsView = new BGroupView(B_VERTICAL, 10.0);
	outerControlsView->GroupLayout()->SetInsets(10, 10, 10, 10);
	controlsBox->AddChild(outerControlsView);

	fResolutionMenu = new BPopUpMenu("resolution", true, true);

	uint16 maxWidth = 0;
	uint16 maxHeight = 0;
	uint16 previousWidth = 0;
	uint16 previousHeight = 0;
	for (int32 i = 0; i < fScreenMode.CountModes(); i++) {
		screen_mode mode = fScreenMode.ModeAt(i);

		if (mode.width == previousWidth && mode.height == previousHeight)
			continue;

		previousWidth = mode.width;
		previousHeight = mode.height;
		if (maxWidth < mode.width)
			maxWidth = mode.width;
		if (maxHeight < mode.height)
			maxHeight = mode.height;

		BMessage* message = new BMessage(POP_RESOLUTION_MSG);
		message->AddInt32("width", mode.width);
		message->AddInt32("height", mode.height);

		BString name;
		name << mode.width << " x " << mode.height;

		fResolutionMenu->AddItem(new BMenuItem(name.String(), message));
	}

	fMonitorView->SetMaxResolution(maxWidth, maxHeight);

	fResolutionField = new BMenuField("ResolutionMenu",
		B_TRANSLATE("Resolution:"), fResolutionMenu);

	fColorsMenu = new BPopUpMenu("colors", true, false);

	for (int32 i = 0; i < kColorSpaceCount; i++) {
		if ((fSupportedColorSpaces & (1 << i)) == 0)
			continue;

		BMessage* message = new BMessage(POP_COLORS_MSG);
		message->AddInt32("bits_per_pixel", kColorSpaces[i].bits_per_pixel);
		message->AddInt32("space", kColorSpaces[i].space);

		BMenuItem* item = new BMenuItem(kColorSpaces[i].label, message);
		if (kColorSpaces[i].space == screen.ColorSpace())
			fUserSelectedColorSpace = item;

		fColorsMenu->AddItem(item);
	}

	fColorsField = new BMenuField("ColorsMenu", B_TRANSLATE("Colors:"),
		fColorsMenu);

	fRefreshMenu = new BPopUpMenu("refresh rate", true, true);

	float min, max;
	if (fScreenMode.GetRefreshLimits(fActive, min, max) != B_OK) {
		// if we couldn't obtain the refresh limits, reset to the default
		// range. Constraints from detected monitors will fine-tune this
		// later.
		min = kRefreshRates[0];
		max = kRefreshRates[kRefreshRateCount - 1];
	}

	if (min == max) {
		// This is a special case for drivers that only support a single
		// frequency, like the VESA driver
		BString name;
		refresh_rate_to_string(min, name);
		BMessage *message = new BMessage(POP_REFRESH_MSG);
		message->AddFloat("refresh", min);
		BMenuItem *item = new BMenuItem(name.String(), message);
		fRefreshMenu->AddItem(item);
		item->SetEnabled(false);
	} else {
		monitor_info info;
		if (fScreenMode.GetMonitorInfo(info) == B_OK) {
			min = max_c(info.min_vertical_frequency, min);
			max = min_c(info.max_vertical_frequency, max);
		}

		for (int32 i = 0; i < kRefreshRateCount; ++i) {
			if (kRefreshRates[i] < min || kRefreshRates[i] > max)
				continue;

			BString name;
			name << kRefreshRates[i] << " " << B_TRANSLATE("Hz");

			BMessage *message = new BMessage(POP_REFRESH_MSG);
			message->AddFloat("refresh", kRefreshRates[i]);

			fRefreshMenu->AddItem(new BMenuItem(name.String(), message));
		}

		fOtherRefresh = new BMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS),
			new BMessage(POP_OTHER_REFRESH_MSG));
		fRefreshMenu->AddItem(fOtherRefresh);
	}

	fRefreshField = new BMenuField("RefreshMenu", B_TRANSLATE("Refresh rate:"),
		fRefreshMenu);

	if (_IsVesa())
		fRefreshField->Hide();

	// enlarged area for multi-monitor settings
	{
		bool dummy;
		uint32 dummy32;
		bool multiMonSupport;
		bool useLaptopPanelSupport;
		bool tvStandardSupport;

		multiMonSupport = TestMultiMonSupport(&screen) == B_OK;
		useLaptopPanelSupport = GetUseLaptopPanel(&screen, &dummy) == B_OK;
		tvStandardSupport = GetTVStandard(&screen, &dummy32) == B_OK;

		// even if there is no support, we still create all controls
		// to make sure we don't access NULL pointers later on

		fCombineMenu = new BPopUpMenu("CombineDisplays",
			true, true);

		for (int32 i = 0; i < kCombineModeCount; i++) {
			BMessage *message = new BMessage(POP_COMBINE_DISPLAYS_MSG);
			message->AddInt32("mode", kCombineModes[i].mode);

			fCombineMenu->AddItem(new BMenuItem(kCombineModes[i].name,
				message));
		}

		fCombineField = new BMenuField("CombineMenu",
			B_TRANSLATE("Combine displays:"), fCombineMenu);

		if (!multiMonSupport)
			fCombineField->Hide();

		fSwapDisplaysMenu = new BPopUpMenu("SwapDisplays",
			true, true);

		// !order is important - we rely that boolean value == idx
		BMessage *message = new BMessage(POP_SWAP_DISPLAYS_MSG);
		message->AddBool("swap", false);
		fSwapDisplaysMenu->AddItem(new BMenuItem(B_TRANSLATE("no"), message));

		message = new BMessage(POP_SWAP_DISPLAYS_MSG);
		message->AddBool("swap", true);
		fSwapDisplaysMenu->AddItem(new BMenuItem(B_TRANSLATE("yes"), message));

		fSwapDisplaysField = new BMenuField("SwapMenu",
			B_TRANSLATE("Swap displays:"), fSwapDisplaysMenu);

		if (!multiMonSupport)
			fSwapDisplaysField->Hide();

		fUseLaptopPanelMenu = new BPopUpMenu("UseLaptopPanel",
			true, true);

		// !order is important - we rely that boolean value == idx
		message = new BMessage(POP_USE_LAPTOP_PANEL_MSG);
		message->AddBool("use", false);
		fUseLaptopPanelMenu->AddItem(new BMenuItem(B_TRANSLATE("if needed"),
			message));

		message = new BMessage(POP_USE_LAPTOP_PANEL_MSG);
		message->AddBool("use", true);
		fUseLaptopPanelMenu->AddItem(new BMenuItem(B_TRANSLATE("always"),
			message));

		fUseLaptopPanelField = new BMenuField("UseLaptopPanel",
			B_TRANSLATE("Use laptop panel:"), fUseLaptopPanelMenu);

		if (!useLaptopPanelSupport)
			fUseLaptopPanelField->Hide();

		fTVStandardMenu = new BPopUpMenu("TVStandard", true, true);

		// arbitrary limit
		uint32 i;
		for (i = 0; i < 100; ++i) {
			uint32 mode;
			if (GetNthSupportedTVStandard(&screen, i, &mode) != B_OK)
				break;

			BString name = tv_standard_to_string(mode);

			message = new BMessage(POP_TV_STANDARD_MSG);
			message->AddInt32("tv_standard", mode);

			fTVStandardMenu->AddItem(new BMenuItem(name.String(), message));
		}

		fTVStandardField = new BMenuField("tv standard",
			B_TRANSLATE("Video format:"), fTVStandardMenu);
		fTVStandardField->SetAlignment(B_ALIGN_RIGHT);

		if (!tvStandardSupport || i == 0)
			fTVStandardField->Hide();
	}

	BLayoutBuilder::Group<>(outerControlsView)
		.AddGrid(5.0, 5.0)
			.AddMenuField(fResolutionField, 0, 0, B_ALIGN_RIGHT)
			.AddMenuField(fColorsField, 0, 1, B_ALIGN_RIGHT)
			.AddMenuField(fRefreshField, 0, 2, B_ALIGN_RIGHT)
			.AddMenuField(fCombineField, 0, 3, B_ALIGN_RIGHT)
			.AddMenuField(fSwapDisplaysField, 0, 4, B_ALIGN_RIGHT)
			.AddMenuField(fUseLaptopPanelField, 0, 5, B_ALIGN_RIGHT)
			.AddMenuField(fTVStandardField, 0, 6, B_ALIGN_RIGHT)
		.End();

	// TODO: we don't support getting the screen's preferred settings
	/* fDefaultsButton = new BButton(buttonRect, "DefaultsButton", "Defaults",
		new BMessage(BUTTON_DEFAULTS_MSG));*/

	fApplyButton = new BButton("ApplyButton", B_TRANSLATE("Apply"),
		new BMessage(BUTTON_APPLY_MSG));
	fApplyButton->SetEnabled(false);
	BLayoutBuilder::Group<>(outerControlsView)
		.AddGlue()
			.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fApplyButton);

	fRevertButton = new BButton("RevertButton", B_TRANSLATE("Revert"),
		new BMessage(BUTTON_REVERT_MSG));
	fRevertButton->SetEnabled(false);

	BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0)
		.SetInsets(10, 10, 10, 10)
		.AddGroup(B_HORIZONTAL, 10.0)
			.AddGroup(B_VERTICAL)
				.AddStrut(floor(controlsBox->TopBorderOffset() / 16) - 1)
				.Add(screenBox)
			.End()
			.Add(controlsBox)
		.End()
		.AddGroup(B_HORIZONTAL, 10.0)
			.Add(fRevertButton)
			.AddGlue();

	_UpdateControls();
	_UpdateMonitor();
}
コード例 #16
0
BRect _SeqCachedTool::Bounds() const
{
	if (mNormalIcon) return mNormalIcon->Bounds();
	return BRect(0, 0, 0, 0);
}
コード例 #17
0
void KlondikeView::MouseDown(BPoint point)
{
	if (fMouseLock)
		return;
	fMouseLock = true;
	
	uint32 mouse;
	GetMouse(&point, &mouse);
	
	if (mouse == B_SECONDARY_MOUSE_BUTTON) {
		// stop auto-play if it's started
		if (fAutoPlayStarted) {
			fAutoPlayStarted = false;
			return;
		}
		
		if (fQuickAutoPlay) {
			while(MoveOneToFoundation());
			
			Invalidate();
			CheckBoard();
		}
		else {
			fAutoPlayStarted = true;
		}
		
		return;
	}

	int hSpacing = _CardHSpacing();
	
	short stack = (int)((point.x - hSpacing) / (CARD_WIDTH + hSpacing));
	
	if (point.x > (stack + 1) * (CARD_WIDTH + hSpacing))
		return;
	
	// stock
	if (point.y < 15 + CARD_HEIGHT && point.y > 15
		&& stack == 0 && point.x > hSpacing) {
		int revealed = 0;
		for (short i = 0; i < 24; i++)
			if (fStock[i]->fRevealed)
				revealed++;
		
		if (revealed < 24 && ++fWasteCard == 24) {
			fWasteCard = -1;
			
			fPoints -= 100;
			if (fPoints < 0)
				fPoints = 0;
		}
		
		Invalidate();
		return;
	}
	
	// pick up a card from waste
	if (stack == 1 && point.y < 15 + CARD_HEIGHT) {		
		if (fWasteCard == -1)
			return;
		
		if (fDoubleClick == -1)
			fDoubleClick = 1;
		else if (fDoubleClick > -1) {
			_MoveWasteToFoundation();
			
			CheckBoard();	
			Invalidate();
			fDoubleClick = -1;
			
			return;
		}
		
		card* picked = fStock[fWasteCard];
		fPickedCard = picked;
		fIsWasteCardPicked = true;
		
		BMessage msg(B_SIMPLE_DATA);
		msg.AddPointer("view", this);
		BBitmap* img = new BBitmap(
			fCards[picked->fColor * CARDS_IN_SUIT + picked->fValue]);
		
		DragMessage(&msg, img, B_OP_BLEND,
			BPoint((int)(point.x - hSpacing) % (CARD_WIDTH + hSpacing),
			point.y - 15));
		
		Invalidate();
		
		return;
	}
	
	// pick up a card from a foundation
	if (stack > 2 && stack < 7 && point.y < 15 + CARD_HEIGHT) {
		short foundation = stack - 3;
		short value = fFoundations[foundation];
		short color = fFoundationsColors[foundation];
		
		if (fFoundations[foundation] == -1)
			return;
		
		// find picked card
		for (short i = 0; i < CARDS_IN_DECK; i++) {
			if (solitare.fAllCards[i]->fValue == value
				&& solitare.fAllCards[i]->fColor == color)
			fPickedCard = solitare.fAllCards[i];
		}
		
		BMessage msg(B_SIMPLE_DATA);
		msg.AddPointer("view", this);
		BBitmap* img = new BBitmap(
			fCards[fPickedCard->fColor * CARDS_IN_SUIT + fPickedCard->fValue]);
		
		fIsFoundationCardPicked = true;
		fPickedCardBoardPos = foundation;
		fFoundations[foundation]--;
		
		DragMessage(&msg, img, B_OP_BLEND,
			BPoint((int)(point.x - hSpacing) % (CARD_WIDTH + hSpacing),
			point.y - 15));
		
		Invalidate();
		
		return;
	}

	// pick up a stack
	if (stack < 7 && solitare.fBoard[stack] != NULL
		&& point.x > hSpacing && point.y > 2 * 15 + CARD_HEIGHT) {
		// find clicked on card
		int cardNumber = 1;
		card* picked = solitare.fBoard[stack];
		while (picked->fNextCard != NULL) {
			if (point.y - 18 * cardNumber - CARD_HEIGHT - 15 < 18) {
				break;
			}
			picked = picked->fNextCard;
			cardNumber++;
		}
		if (picked->fNextCard == NULL) {
			// on last card, if below than not clicking on card
			if (point.y - 18 * cardNumber - CARD_HEIGHT - 15 >= CARD_HEIGHT) {
				return;
			}
			
			if (fDoubleClick == -1)
				fDoubleClick = 1;
			else if (fDoubleClick > -1 && fAutoPlayEnabled) {
				MoveOneToFoundation(stack, stack);
				
				CheckBoard();	
				Invalidate();
				fDoubleClick = -1;
				
				return;
			}
		}
		
		if (picked->fRevealed == false)
			return;
		
		card* currentCard = picked->fNextCard;
		card* lastCard = picked;
		short pickedHeight = 1;
		for (short i = 1; currentCard != NULL;
				i++) {
			pickedHeight++;
			if (lastCard->fColor & 1 == currentCard->fColor & 1)
				return;
			lastCard = currentCard;
			currentCard = currentCard->fNextCard;
		}
		
		fPickedCardBoardPos = stack;
		fPickedCard = picked;
		fIsCardPicked = true;

		solitare._RemoveCardFromPile(stack, picked);

		BMessage msg(B_SIMPLE_DATA);
		msg.AddPointer("view", this);
		BBitmap* img;
		if (pickedHeight == 1)
			img = new BBitmap(
				fCards[picked->fColor * CARDS_IN_SUIT + picked->fValue]);
		else {
			img = new BBitmap(BRect(0, 0, CARD_WIDTH - 1,
				CARD_HEIGHT + (pickedHeight - 1) * 18),
				fBack[0]->ColorSpace(), true);
			BView* imgView = new BView(img->Bounds(), NULL, 0, 0);
			BRect destRect = fBack[0]->Bounds();
			img->AddChild(imgView);
			img->Lock();
			currentCard = picked;

			imgView->SetDrawingMode(B_OP_COPY);
			imgView->DrawBitmap(fCards
				[currentCard->fColor * CARDS_IN_SUIT + currentCard->fValue],
				destRect);
			destRect.top = (pickedHeight - 1) * 18;
			destRect.bottom = destRect.top + CARD_HEIGHT;

			imgView->DrawBitmap(fBack[0], destRect);
				// we don't know the top card yet, so we'll overwrite this

			imgView->SetDrawingMode(B_OP_ALPHA);
			for (short j = 0; j < pickedHeight; j++) {
				destRect.top = j * 18;
				destRect.bottom = destRect.top + CARD_HEIGHT;
				imgView->DrawBitmap(fCards[currentCard->fColor
					* CARDS_IN_SUIT + currentCard->fValue], destRect);
				currentCard = currentCard->fNextCard;
			}
			
			imgView->Sync();
			img->Unlock();
			img->RemoveChild(imgView);
			delete imgView;
		}
		DragMessage(&msg, img, B_OP_BLEND,
			BPoint((int)(point.x - hSpacing) % (CARD_WIDTH + hSpacing),
			point.y - cardNumber * 18 - 131));
		
		Invalidate();
	}
}
コード例 #18
0
ファイル: ProjectWindow.cpp プロジェクト: passick/Paladin
void
ProjectWindow::MessageReceived(BMessage *msg)
{
	status_t status;
	
	if ( (msg->WasDropped() && msg->what == B_SIMPLE_DATA) || msg->what == M_ADD_FILES)
	{
		fAddFileStruct.refmsg = *msg;
		fAddFileStruct.parent = this;
		
		uint32 buttons;
		fProjectList->GetMouse(&fAddFileStruct.droppt,&buttons);
		
		thread_id addThread = spawn_thread(AddFileThread,"file adding thread",
											B_NORMAL_PRIORITY, &fAddFileStruct);
		if (addThread >= 0)
			resume_thread(addThread);
	}
	switch (msg->what)
	{
		case M_IMPORT_REFS:
		{
			fImportStruct.refmsg = *msg;
			fImportStruct.parent = this;
			
			thread_id importThread = spawn_thread(ImportFileThread,"file import thread",
												B_NORMAL_PRIORITY, &fImportStruct);
			if (importThread >= 0)
				resume_thread(importThread);
			break;
		}
		case M_BACKUP_PROJECT:
		{
			thread_id backupThread = spawn_thread(BackupThread,"project backup thread",
												B_NORMAL_PRIORITY, this);
			if (backupThread >= 0)
			{
				fStatusBar->SetText(TR("Backing up project"));
				UpdateIfNeeded();
				
				SetMenuLock(true);
				resume_thread(backupThread);
			}
			break;
		}
		case M_GET_CHECK_IN_MSG:
		{
			if (!fSourceControl)
			{
				printf("NULL source control\n");
				break;
			}
			
			BString out;
			fSourceControl->GetCheckinHeader(out);
			
			bool select = false;
			if (out.CountChars() > 1)
				out.Prepend("\n\n");
			else
			{
				out = TR("Enter the description for the changes in this revision.");
				select = true;
			}
			
			GetTextWindow *gtw = new GetTextWindow("Paladin", out.String(),
													BMessage(M_CHECK_IN_PROJECT),
													BMessenger(this));
			if (!select)
				gtw->GetTextView()->Select(0,0);
			gtw->Show();
			break;
		}
		case M_CHECK_IN_PROJECT:
		{
			BString commitstr;
			if (msg->FindString("text", &commitstr) == B_OK && fSourceControl)
			{
				SCMOutputWindow *win = new SCMOutputWindow(TR("Commit"));
				win->Show();
				fSourceControl->Commit(commitstr.String());
			}
			break;
		}
		case M_REVERT_PROJECT:
		{
			if (!fSourceControl)
				break;
			
			int32 result = ShowAlert(TR("This will undo all changes since the last commit. "
										"Continue?"), "Don't Revert", "Revert");
			if (result == 1)
			{
				SCMOutputWindow *win = new SCMOutputWindow(TR("Revert"));
				win->Show();
				fSourceControl->Revert(NULL);
			}
			break;
		}
		case M_REBUILD_FILE:
		case M_ADD_SELECTION_TO_REPO:
		case M_REMOVE_SELECTION_FROM_REPO:
		case M_REVERT_SELECTION:
		case M_DIFF_SELECTION:
		{
			ActOnSelectedFiles(msg->what);
			break;
		}
		case M_DIFF_PROJECT:
		{
			if (fSourceControl)
			{
				SCMOutputWindow *win = new SCMOutputWindow(TR("Differences"));
				win->Show();
				fSourceControl->Diff(NULL);
			}
			break;
		}
		case M_PROJECT_SCM_STATUS:
		{
			if (fSourceControl)
			{
				SCMOutputWindow *win = new SCMOutputWindow(TR("Project Status"));
				BString strstatus;
				fSourceControl->GetChangeStatus(strstatus);
				win->GetTextView()->SetText(strstatus.String());
				win->Show();
			}
			break;
		}
		case M_PUSH_PROJECT:
		{
			if (fSourceControl)
			{
				SCMOutputWindow *win = new SCMOutputWindow(TR("Push"));
				win->Show();
				fSourceControl->Push(NULL);
			}
			break;
		}
		case M_PULL_PROJECT:
		{
			if (fSourceControl)
			{
				SCMOutputWindow *win = new SCMOutputWindow(TR("Pull"));
				win->Show();
				status = fSourceControl->Pull(NULL);
				
				if (!status)
					ShowAlert("Unable to pull from the remote repository. If it "
							"uses a secure connection, please set up the appropriate "
							"SSH keys on the remote server.", "OK");
			}
			break;
		}
		case M_CULL_EMPTY_GROUPS:
		{
			CullEmptyGroups();
			break;
		}
		case M_RUN_FILE_TYPES:
		{
			int32 selection = fProjectList->FullListCurrentSelection();
			if (selection < 0)
				break;
			
			SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(selection));
			if (!item)
				break;
			SpawnFileTypes(item->GetData()->GetPath());
			break;
		}
		case M_OPEN_PARENT_FOLDER:
		{
			BMessage openmsg(B_REFS_RECEIVED);
			int32 selindex = 0;
			int32 selection = fProjectList->FullListCurrentSelection();
			selindex++;
			if (selection >= 0)
			{
				while (selection >= 0)
				{
					SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(selection));
					if (!item)
						break;
					
					SourceFile *file = item->GetData();
					BString abspath = file->GetPath().GetFullPath();
					if (abspath[0] != '/')
					{
						abspath.Prepend("/");
						abspath.Prepend(fProject->GetPath().GetFolder());
					}
					DPath filepath(abspath);
					
					entry_ref ref;
					BEntry(filepath.GetFolder()).GetRef(&ref);
					
					openmsg.AddRef("refs",&ref);
					selection = fProjectList->FullListCurrentSelection(selindex++);
				}
				
				BMessenger msgr("application/x-vnd.Be-TRAK");
				msgr.SendMessage(&openmsg);
			}
			
			break;
		}
		case M_SHOW_PROJECT_FOLDER:
		{
			entry_ref ref;
			BEntry(fProject->GetPath().GetFolder()).GetRef(&ref);
			BMessenger msgr("application/x-vnd.Be-TRAK");
			
			BMessage openmsg(B_REFS_RECEIVED);
			openmsg.AddRef("refs",&ref);
			msgr.SendMessage(&openmsg);
			break;
		}
		case M_SHOW_ASCII_TABLE:
		{
			AsciiWindow *ascwin = new AsciiWindow();
			ascwin->Show();
			break;
		}
		case M_SHOW_VREGEX:
		{
			VRegWindow *vregwin = new VRegWindow();
			vregwin->Show();
			break;
		}
		case M_SHOW_LICENSES:
		{
			LicenseManager *man = new LicenseManager(fProject->GetPath().GetFolder());
			man->Show();
			break;
		}
		case M_RUN_TOOL:
		{
			BString sig;
			if (msg->FindString("signature", &sig) == B_OK)
			{
				LaunchHelper launcher(sig.String());
				launcher.Launch();
			}
			break;
		}
		case M_MAKE_MAKE:
		{
			DPath out(fProject->GetPath().GetFolder());
			out.Append("Makefile");
			if (MakeMake(fProject,out) == B_OK);
			{
				BEntry entry(out.GetFullPath());
				entry_ref ref;
				if (entry.InitCheck() == B_OK)
				{
					entry.GetRef(&ref);
					BMessage refmsg(B_REFS_RECEIVED);
					refmsg.AddRef("refs",&ref);
					be_app->PostMessage(&refmsg);
				}
			}
			break;
		}
		case M_SHOW_CODE_LIBRARY:
		{
			#ifdef BUILD_CODE_LIBRARY
			CodeLibWindow *libwin = CodeLibWindow::GetInstance(BRect(100,100,500,350));
			libwin->Show();
			#endif
			
			break;
		}
		case M_OPEN_PARTNER:
		{
			int32 selection = fProjectList->FullListCurrentSelection();
			if (selection < 0)
				break;
			
			SourceFileItem *item = dynamic_cast<SourceFileItem*>(
									fProjectList->FullListItemAt(selection));
			if (!item)
				break;
			entry_ref ref;
			BEntry(fProject->GetPathForFile(item->GetData()).GetFullPath()).GetRef(&ref);
			BMessage refmsg(M_OPEN_PARTNER);
			refmsg.AddRef("refs",&ref);
			be_app->PostMessage(&refmsg);
			break;
		}
		case M_NEW_GROUP:
		{
			MakeGroup(fProjectList->FullListCurrentSelection());
			PostMessage(M_SHOW_RENAME_GROUP);
			break;
		}
		case M_SHOW_RENAME_GROUP:
		{
			int32 selection = fProjectList->FullListCurrentSelection();
			SourceGroupItem *groupItem = NULL;
			if (selection < 0)
			{
				// Don't need a selection if there is only one group in the project
				if (fProject->CountGroups() == 1)
					groupItem = fProjectList->ItemForGroup(fProject->GroupAt(0));
			}
			else
			{
				BStringItem *strItem = (BStringItem*)fProjectList->FullListItemAt(selection);
				groupItem = fProjectList->GroupForItem(strItem);
			}
			
			if (!groupItem)
				break;
			
			GroupRenameWindow *grwin = new GroupRenameWindow(groupItem->GetData(),
															BMessage(M_RENAME_GROUP),
															BMessenger(this));
			grwin->Show();
			break;
		}
		case M_RENAME_GROUP:
		{
			SourceGroup *group;
			BString newname;
			if (msg->FindPointer("group",(void**)&group) != B_OK ||
				msg->FindString("newname",&newname) != B_OK)
				break;
			
			group->name = newname;
			SourceGroupItem *groupItem = fProjectList->ItemForGroup(group);
			if (!groupItem)
				break;
			
			groupItem->SetText(newname.String());
			fProjectList->InvalidateItem(fProjectList->IndexOf(groupItem));
			
			fProject->Save();
			break;
		}
		case M_SORT_GROUP:
		{
			int32 selection = fProjectList->FullListCurrentSelection();
			
			SourceGroupItem *groupItem = NULL;
			if (selection < 0)
			{
				// Don't need a selection if there is only one group in the project
				if (fProject->CountGroups() == 1)
					groupItem = fProjectList->ItemForGroup(fProject->GroupAt(0));
			}
			else
			{
				BStringItem *strItem = (BStringItem*)fProjectList->FullListItemAt(selection);
				groupItem = fProjectList->GroupForItem(strItem);
			}
			
			if (!groupItem)
				break;
			
			fProjectList->SortItemsUnder(groupItem,true,compare_source_file_items);
			groupItem->GetData()->Sort();
			fProject->Save();
			
			break;
		}
		case M_TOGGLE_ERROR_WINDOW:
		{
			ToggleErrorWindow(fProject->GetErrorList());
			break;
		}
		case M_SHOW_ERROR_WINDOW:
		{
			ShowErrorWindow(fProject->GetErrorList());
			break;
		}
		case M_SHOW_PROJECT_SETTINGS:
		{
			BRect r(0,0,350,300);
			BRect screen(BScreen().Frame());
			
			r.OffsetTo((screen.Width() - r.Width()) / 2.0,
						(screen.Height() - r.Height()) / 2.0);
			
			ProjectSettingsWindow *win = new ProjectSettingsWindow(r,fProject);
			win->Show();
			break;
		}
		case M_SHOW_RUN_ARGS:
		{
			RunArgsWindow *argwin = new RunArgsWindow(fProject);
			argwin->Show();
			break;
		}
		case M_JUMP_TO_MSG:
		{
			entry_ref ref;
			if (msg->FindRef("refs",&ref) == B_OK)
			{
				msg->what = B_REFS_RECEIVED;
				be_app->PostMessage(msg);
			}
			break;
		}
		case B_ABOUT_REQUESTED:
		{
			be_app->PostMessage(B_ABOUT_REQUESTED);
			break;
		}
		case M_SHOW_OPEN_PROJECT:
		{
			be_app->PostMessage(msg);
			break;
		}
		case M_NEW_WINDOW:
		{
			be_app->PostMessage(M_NEW_PROJECT);
			break;
		}
		case M_SHOW_PROGRAM_SETTINGS:
		{
			PrefsWindow *prefwin = new PrefsWindow(BRect(0,0,500,400));
			prefwin->Show();
			break;
		}
		case M_SHOW_FIND_AND_OPEN_PANEL:
		{
			BString text;
			msg->FindString("name",&text);
			
			// Passing a NULL string to this is OK
			FindOpenFileWindow *findwin = new FindOpenFileWindow(text.String());
			findwin->Show();
			break;
		}
		case M_FILE_NEEDS_BUILD:
		{
			SourceFile *file;
			if (msg->FindPointer("file",(void**)&file) == B_OK)
			{
				SourceFileItem *item = fProjectList->ItemForFile(file);
				if (item)
				{
					item->SetDisplayState(SFITEM_NEEDS_BUILD);
					fProjectList->InvalidateItem(fProjectList->IndexOf(item));
				}
			}
			break;
		}
		case M_EDIT_FILE:
		{
			int32 i = 0;
			int32 selection = fProjectList->FullListCurrentSelection(i);
			i++;
			
			BMessage refmsg(B_REFS_RECEIVED);
			while (selection >= 0)
			{
				SourceFileItem *item = dynamic_cast<SourceFileItem*>
										(fProjectList->FullListItemAt(selection));
				if (item && item->GetData())
				{
					BString abspath = item->GetData()->GetPath().GetFullPath();
					if (abspath[0] != '/')
					{
						abspath.Prepend("/");
						abspath.Prepend(fProject->GetPath().GetFolder());
					}
					
					BEntry entry(abspath.String());
					if (entry.InitCheck() == B_OK)
					{
						entry_ref ref;
						entry.GetRef(&ref);
						refmsg.AddRef("refs",&ref);
					}
					else
					{
						if (!entry.Exists())
						{
							BString errmsg = TR("Couldn't find XXXXX. It may have been moved or renamed.");
							errmsg.ReplaceFirst("XXXXX",abspath.String());
							ShowAlert(errmsg.String());
						}
					}
				}
				else
				{
					SourceGroupItem *groupItem = dynamic_cast<SourceGroupItem*>
											(fProjectList->FullListItemAt(selection));
					if (groupItem)
					{
						if (groupItem->IsExpanded())
							fProjectList->Collapse(groupItem);
						else
							fProjectList->Expand(groupItem);
						groupItem->GetData()->expanded = groupItem->IsExpanded();
					}
					
				}
				
				selection = fProjectList->CurrentSelection(i);
				i++;
			}
			be_app->PostMessage(&refmsg);
			break;
		}
		case M_LIBWIN_CLOSED:
		{
			fShowingLibs = false;
			break;
		}
		case M_SHOW_LIBRARIES:
		{
			fShowingLibs = true;
			LibraryWindow *libwin = new LibraryWindow(Frame().OffsetByCopy(15,15),
														BMessenger(this), fProject);
			libwin->Show();
			break;
		}
		case M_SHOW_ADD_NEW_PANEL:
		{
			AddNewFileWindow *anfwin = new AddNewFileWindow(BMessage(M_ADD_NEW_FILE),
														BMessenger(this));
			anfwin->Show();
			break;
		}
		case M_SHOW_FIND_IN_PROJECT_FILES:
		{
			if (!gLuaAvailable)
			{
				ShowAlert("Paladin's multi-file Find window depends on Lua. It will "
						"need to be installed if you wish to use this feature.", "OK",
						NULL, NULL, B_STOP_ALERT);
				break;
			}
			
			FindWindow *findwin = new FindWindow();
			findwin->Show();
			break;
		}
		case M_ADD_NEW_FILE:
		{
			BString name;
			bool makepair;
			if (msg->FindString("name",&name) == B_OK && msg->FindBool("makepair",&makepair) == B_OK)
				AddNewFile(name,makepair);
			break;
		}
		case M_SHOW_ADD_PANEL:
		{
			if (!fFilePanel)
			{
				BMessenger msgr(this);
				BEntry entry(fProject->GetPath().GetFolder());
				entry_ref ref;
				entry.GetRef(&ref);
				fFilePanel = new BFilePanel(B_OPEN_PANEL,&msgr,&ref,B_FILE_NODE,true,
											new BMessage(M_ADD_FILES));
			}
			fFilePanel->Show();
			break;
		}
		case M_REMOVE_FILES:
		{
			bool save = false;
			
			for (int32 i = 0; i < fProjectList->CountItems(); i++)
			{
				SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->ItemAt(i));
				if (item && item->IsSelected())
				{
					fProjectList->RemoveItem(item);
					fProject->RemoveFile(item->GetData());
					delete item;
					save = true;
					i--;
				}
			}
			CullEmptyGroups();
			if (save)
				fProject->Save();
			break;
		}
		case M_EMPTY_CCACHE:
		{
			// We don't do this when forcing a rebuild of the sources because sometimes it
			// can take quite a while
			if (gUseCCache && gCCacheAvailable)
			{
				fStatusBar->SetText(TR("Emptying build cache"));
				UpdateIfNeeded();
				system("ccache -c > /dev/null");
				fStatusBar->SetText("");
				UpdateIfNeeded();
			}
			break;
		}
		case M_FORCE_REBUILD:
		{
			fProject->ForceRebuild();
			
			for (int32 i = 0; i < fProjectList->FullListCountItems(); i++)
			{
				SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(i));
				if (!item)
					continue;
				
				SourceFile *file = item->GetData();
				if (file->UsesBuild())
				{
					item->SetDisplayState(SFITEM_NEEDS_BUILD);
					fProjectList->InvalidateItem(i);
				}
			}
			// This is necessary because InvalidateItem() uses indices from ItemAt(),
			// not FullListItemAt
			fProjectList->Invalidate();
			break;
		}
		case M_UPDATE_DEPENDENCIES:
		{
			UpdateDependencies();
			break;
		}
		case M_MAKE_PROJECT:
		case M_BUILD_PROJECT:
		{
			fBuildingFile = 0;
			DoBuild(POSTBUILD_NOTHING);
			break;
		}
		case M_RUN_PROJECT:
		{
			DoBuild(POSTBUILD_RUN);
			break;
		}
		case M_RUN_IN_TERMINAL:
		{
			DoBuild(POSTBUILD_RUN_IN_TERMINAL);
			break;
		}
		case M_DEBUG_PROJECT:
		{
			if (!fProject->Debug())
			{
				BString errmsg = TR("Your project does not have debugging information compiled ");
				errmsg << TR("in and will need to be rebuilt to debug. Do you wish to rebuild and ")
					<< TR("run the debugger?");
				int32 result = ShowAlert("Debugging information needs to compiled into "
										"your project. This may take some time for large "
										"projects. Do you wish to rebuild and run "
										"the debugger?",
										"Rebuild","Cancel");
				if (result == 1)
					break;
				
				fProject->SetDebug(true);
				fProject->Save();
				fProject->ForceRebuild();
			}
			
			DoBuild(POSTBUILD_DEBUG);
			break;
		}
		case M_EXAMINING_FILE:
		{
			SourceFile *file;
			if (msg->FindPointer("file",(void**)&file) == B_OK)
			{
				BString out;
				out << TR("Examining ") << file->GetPath().GetFileName();
				fStatusBar->SetText(out.String());
			}
			break;
		}
		case M_BUILDING_FILE:
		{
			SourceFile *file;
			if (msg->FindPointer("sourcefile",(void**)&file) == B_OK)
			{
				SourceFileItem *item = fProjectList->ItemForFile(file);
				if (item)
				{
					item->SetDisplayState(SFITEM_BUILDING);
					fProjectList->InvalidateItem(fProjectList->IndexOf(item));
					
					BString out;
					
					int32 count,total;
					if (msg->FindInt32("count",&count) == B_OK &&
						msg->FindInt32("total",&total) == B_OK)
					{
						fBuildingFile = MAX(fBuildingFile, count);
						out << "(" << fBuildingFile << "/" << total << ") ";
					}
					
					out << TR("Building ") << item->Text();
					fStatusBar->SetText(out.String());
				}
			}
			break;
		}
		case M_BUILDING_DONE:
		{
			SourceFile *file;
			if (msg->FindPointer("sourcefile",(void**)&file) == B_OK)
			{
				SourceFileItem *item = fProjectList->ItemForFile(file);
				if (item)
				{
					item->SetDisplayState(SFITEM_NORMAL);
					fProjectList->InvalidateItem(fProjectList->IndexOf(item));
				}
			}
			break;
		}
		case M_LINKING_PROJECT:
		{
			fStatusBar->SetText(TR("Linking"));
			break;
		}
		case M_UPDATING_RESOURCES:
		{
			fStatusBar->SetText(TR("Updating Resources"));
			break;
		}
		case M_DOING_POSTBUILD:
		{
			fStatusBar->SetText(TR("Performing Post-build tasks"));
			break;
		}
		case M_BUILD_FAILURE:
		{
			SetMenuLock(false);
			
			// fall through
		}
		case M_BUILD_MESSAGES:
		case M_BUILD_WARNINGS:
		{
			if (!fErrorWindow)
			{
				BRect screen(BScreen().Frame());
				BRect r(screen);
				r.left = r.right / 4.0;
				r.right *= .75;
				r.top = r.bottom - 200;
				
				BDeskbar deskbar;
				if (deskbar.Location() == B_DESKBAR_BOTTOM)
					r.OffsetBy(0,-deskbar.Frame().Height());
				
				fErrorWindow = new ErrorWindow(r,this);
				fErrorWindow->Show();
			}
			else
			{
				if (!fErrorWindow->IsFront())
					fErrorWindow->Activate();
			}
			fStatusBar->SetText("");
			
			// Should this be an Unflatten or an Append?
			ErrorList *errorList = fProject->GetErrorList();
			errorList->Unflatten(*msg);
			fErrorWindow->PostMessage(msg);
			break;
		}
		case M_BUILD_SUCCESS:
		{
			SetMenuLock(false);
			fStatusBar->SetText("");
			break;
		}
		case M_ERRORWIN_CLOSED:
		{
			fErrorWindow = NULL;
			break;
		}
		case M_SYNC_MODULES:
		{
			#ifdef BUILD_CODE_LIBRARY
			thread_id syncID = spawn_thread(SyncThread,"module update thread",
												B_NORMAL_PRIORITY, this);
			if (syncID >= 0)
				resume_thread(syncID);
			#endif
			break;
		}
		case M_TOGGLE_DEBUG_MENU:
		{
			ToggleDebugMenu();
			break;
		}
		case M_DEBUG_DUMP_DEPENDENCIES:
		{
			DumpDependencies(fProject);
			break;
		}
		case M_DEBUG_DUMP_INCLUDES:
		{
			DumpIncludes(fProject);
			break;
		}
		default:
		{
			DWindow::MessageReceived(msg);
			break;
		}
	}
}
コード例 #19
0
ファイル: HAddressView.cpp プロジェクト: HaikuArchives/Scooby
/***********************************************************
 * InitGUI
 ***********************************************************/
void
HAddressView::InitGUI()
{
	float divider = StringWidth(_("Subject:")) + 20;
	divider = max_c(divider , StringWidth(_("From:"))+20);
	divider = max_c(divider , StringWidth(_("To:"))+20);
	divider = max_c(divider , StringWidth(_("Bcc:"))+20);
	
	BRect rect = Bounds();
	rect.top += 5;
	rect.left += 20 + divider;
	rect.right = Bounds().right - 5;
	rect.bottom = rect.top + 25;
	
	BTextControl *ctrl;
	ResourceUtils rutils;
	const char* name[] = {"to","subject","from","cc","bcc"};
	
	for(int32 i = 0;i < 5;i++)
	{
		ctrl = new BTextControl(BRect(rect.left,rect.top
								,(i == 1)?rect.right+divider:rect.right
								,rect.bottom)
								,name[i],"","",NULL
								,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE);
		
		if(i == 1)
		{
			ctrl->SetLabel(_("Subject:"));
			ctrl->SetDivider(divider);
			ctrl->MoveBy(-divider,0);
		}else{
			ctrl->SetDivider(0);
		}
		BMessage *msg = new BMessage(M_MODIFIED);
		msg->AddPointer("pointer",ctrl);
		ctrl->SetModificationMessage(msg);
		ctrl->SetEnabled(!fReadOnly);
		AddChild(ctrl);
	
		rect.OffsetBy(0,25);
		switch(i)
		{
		case 0:
			fTo = ctrl;
			break;
		case 1:
			fSubject = ctrl;
			break;
		case 2:
			fFrom = ctrl;
			fFrom->SetEnabled(false);
			fFrom->SetFlags(fFrom->Flags() & ~B_NAVIGABLE);
			break;
		case 3:
			fCc = ctrl;
			break;
		case 4:
			fBcc = ctrl;
			break;
		}
	}
	//
	BRect menuRect= Bounds();
	menuRect.top += 5;
	menuRect.left += 22;
	menuRect.bottom = menuRect.top + 25;
	menuRect.right = menuRect.left + 16;
	
	BMenu *toMenu = new BMenu(_("To:"));
	BMenu *ccMenu = new BMenu(_("Cc:"));
	BMenu *bccMenu = new BMenu(_("Bcc:"));
	BQuery query;
	BVolume volume;
	BVolumeRoster().GetBootVolume(&volume);
	query.SetVolume(&volume);
	query.SetPredicate("((META:email=*)&&(BEOS:TYPE=application/x-person))");

	if(!fReadOnly && query.Fetch() == B_OK)
	{
		BString addr[4],name,group,nick;
		entry_ref ref;
		BList peopleList;
	
	
		while(query.GetNextRef(&ref) == B_OK)
		{
			BNode node(&ref);
			if(node.InitCheck() != B_OK)
				continue;
			
			ReadNodeAttrString(&node,"META:name",&name);		
			ReadNodeAttrString(&node,"META:email",&addr[0]);
			ReadNodeAttrString(&node,"META:email2",&addr[1]);
			ReadNodeAttrString(&node,"META:email3",&addr[2]);
			ReadNodeAttrString(&node,"META:email4",&addr[3]);
			ReadNodeAttrString(&node,"META:group",&group);
			ReadNodeAttrString(&node,"META:nickname",&nick);
			
			for(int32 i = 0;i < 4;i++)
			{
				if(addr[i].Length() > 0)
				{
					if(nick.Length() > 0)
					{
						nick += " <";
						nick += addr[i];
						nick += ">";
						fAddrList.AddItem(strdup(nick.String()));
					}
					fAddrList.AddItem(strdup(addr[i].String()));
					
					BString title = name;
					title << " <" << addr[i] << ">";
				
					AddPersonToList(peopleList,title.String(),group.String());
				}
			}
		}
		
		// Sort people data
		peopleList.SortItems(HAddressView::SortPeople);
		// Build menus
		BTextControl *control[3] = {fTo,fCc,fBcc};
		BMenu *menus[3] = {toMenu,ccMenu,bccMenu};
		int32 count = peopleList.CountItems();
		PersonData *data;
		bool needSeparator = false;
		bool hasSeparator = false;
		for(int32 k = 0;k < 3;k++)
		{
			for(int32 i = 0;i < count;i++)
			{
				BMessage *msg = new BMessage(M_ADDR_MSG);
				msg->AddPointer("pointer",control[k]);
				data =  (PersonData*)peopleList.ItemAt(i);
				msg->AddString("email",data->email);
				if(needSeparator && !hasSeparator && strlen(data->group) == 0)
				{
					menus[k]->AddSeparatorItem();
					hasSeparator = true;
				}else
					needSeparator = true;
				AddPerson(menus[k],data->email,data->group,msg,0,0);
			}
			hasSeparator = false;
			needSeparator = false;
		}
		// free all data
		while(count > 0)
		{
			data =  (PersonData*)peopleList.RemoveItem(--count);
			free(data->email);
			free(data->group);
			delete data;
		}
	}
	BMenuField *field = new BMenuField(menuRect,"ToMenu","",toMenu,
							B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW);
	field->SetDivider(0);
	field->SetEnabled(!fReadOnly);
	AddChild(field);
	
	rect = menuRect;
	rect.OffsetBy(0,28);
	rect.left = Bounds().left + 5;
	rect.right = rect.left + 16;
	rect.top += 26;
	rect.bottom = rect.top + 16;
	ArrowButton *arrow = new ArrowButton(rect,"addr_arrow"
										,new BMessage(M_EXPAND_ADDRESS));
	AddChild(arrow);
	//==================== From menu
	BMenu *fromMenu = new BMenu(_("From:"));
	BPath path;
	::find_directory(B_USER_SETTINGS_DIRECTORY,&path);
	path.Append(APP_NAME);
	path.Append("Accounts");
	BDirectory dir(path.Path());
	BEntry entry;
	status_t err = B_OK;
	int32 account_count = 0;
	while(err == B_OK)
	{
		if((err = dir.GetNextEntry(&entry)) == B_OK && !entry.IsDirectory())
		{
			char name[B_FILE_NAME_LENGTH+1];
			entry.GetName(name);
			BMessage *msg = new BMessage(M_ACCOUNT_CHANGE);
			msg->AddString("name",name);
			BMenuItem *item = new BMenuItem(name,msg);
			fromMenu->AddItem(item);
			item->SetTarget(this,Window());
			account_count++;
		}
	}
	if(account_count != 0)
	{
		int32 smtp_account;
		((HApp*)be_app)->Prefs()->GetData("smtp_account",&smtp_account);
		BMenuItem *item(NULL);
		if(account_count > smtp_account)
			item = fromMenu->ItemAt(smtp_account);
		if(!item)
			item = fromMenu->ItemAt(0);
		if(item)
		{
			ChangeAccount(item->Label());
			item->SetMarked(true);
		}
	}else{
		(new BAlert("",_("Could not find mail accounts"),_("OK"),NULL,NULL,B_WIDTH_AS_USUAL,B_INFO_ALERT))->Go();
		Window()->PostMessage(B_QUIT_REQUESTED);
	}
	fromMenu->SetRadioMode(true);
	
	menuRect.OffsetBy(0,25*2);
	field = new BMenuField(menuRect,"FromMenu","",fromMenu,
							B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW);
	field->SetDivider(0);
	
	AddChild(field);
	//=================== CC menu
	menuRect.OffsetBy(0,25);
	field = new BMenuField(menuRect,"CcMenu","",ccMenu,
							B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW);
	field->SetDivider(0);
	field->SetEnabled(!fReadOnly);
	AddChild(field);

	//=================== BCC menu	
	menuRect.OffsetBy(0,25);
	field = new BMenuField(menuRect,"BccMenu","",bccMenu,
							B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW);
	field->SetDivider(0);
	field->SetEnabled(!fReadOnly);
	AddChild(field);
	

}
コード例 #20
0
SCMImportWindow::SCMImportWindow(void)
  :	DWindow(BRect(0,0,350,350), "Import from Repository")
{
	MakeCenteredOnShow(true);
	
	BMenu *menu = new BMenu("Providers");
	
	for (int32 i = 0; i < fProviderMgr.CountImporters(); i++)
	{
		SCMProjectImporter *importer = fProviderMgr.ImporterAt(i);
		if (!importer)
			continue;
		
		BMessage *msg = new BMessage(M_USE_PROVIDER);
		menu->AddItem(new BMenuItem(importer->GetName(), msg));
	}
	
	// Disable custom commands for now	
//	menu->AddSeparatorItem();
//	menu->AddItem(new BMenuItem("Custom", new BMessage(M_USE_CUSTOM_PROVIDER)));
	
	menu->SetLabelFromMarked(true);
	menu->ItemAt(0L)->SetMarked(true);
	
	fProviderField = new BMenuField("repofield", "Provider: ", menu);
	
	menu = new BMenu("Methods");
	if (gHgAvailable)
		menu->AddItem(new BMenuItem("Mercurial", new BMessage(M_UPDATE_COMMAND)));
	
	if (gGitAvailable)
		menu->AddItem(new BMenuItem("Git", new BMessage(M_UPDATE_COMMAND)));
	
	if (gSvnAvailable)
		menu->AddItem(new BMenuItem("Subversion", new BMessage(M_UPDATE_COMMAND)));
	menu->SetLabelFromMarked(true);
	menu->ItemAt(0L)->SetMarked(true);
	fProvider = fProviderMgr.ImporterAt(0);
		
	fSCMField = new BMenuField("scmfield", "Method: ", menu);
		
	fProjectBox = new AutoTextControl("project", "Project: ", "",
									new BMessage(M_UPDATE_COMMAND));
	
	fAnonymousBox = new BCheckBox("anonymous", "Anonymous check-out",
									new BMessage(M_TOGGLE_ANONYMOUS));
	fAnonymousBox->SetValue(B_CONTROL_ON);
	
	fUserNameBox = new AutoTextControl("username", "Username: ", "",
									new BMessage(M_UPDATE_COMMAND));
	fUserNameBox->SetEnabled(false);
	
	fRepository = new AutoTextControl("repository", "Repository Owner: ", "",
									new BMessage(M_UPDATE_COMMAND));	
	
	fCommandLabel = new BStringView("commandlabel", "Command: ");	
	fCommandView = new BTextView("command");
	
	BScrollView *scroll = new BScrollView("scrollview", fCommandView,
											0, false, true);
	fCommandView->MakeEditable(false);
	
	fOK = new BButton("ok", "Import", new BMessage(M_SCM_IMPORT));
	
	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.SetInsets(10)
		.Add(fProviderField)
		.Add(fSCMField)
		.Add(fRepository)
		.Add(fProjectBox)
		.Add(fAnonymousBox)
		.Add(fUserNameBox)
		.Add(fCommandLabel)
		.Add(scroll)
		.Add(fOK)
	.End();
		
	fOK->MakeDefault(true);
	fOK->SetEnabled(false);
	
	UpdateCommand();
	fProviderField->MakeFocus(true);
	
}
コード例 #21
0
ファイル: Slider.cpp プロジェクト: gedrin/Becasso
void Slider::MouseDown (BPoint point)
// Note: Still assumes horizontal slider ATM!
{
	if (tc)	// TextControl still visible...  Block other mouse movement.
		return;
		
	BPoint knobpos = BPoint (float (value - min)/(max - min)*(width - knobsize), 1);
	knob = BRect (knobpos.x + 1, knobpos.y + 1, knobpos.x + knobsize - 2, knobpos.y + height - 2);
	ulong buttons;
	buttons = Window()->CurrentMessage()->FindInt32 ("buttons");
	float px = -1;
	bool dragging = false;
	if (click != 2 && buttons & B_PRIMARY_MOUSE_BUTTON && !(modifiers() & B_CONTROL_KEY))
	{
		BPoint bp, pbp;
		uint32 bt;
		GetMouse (&pbp, &bt, true);
		bigtime_t start = system_time();
		if (knob.Contains (BPoint (pbp.x - sep, pbp.y)))
		{
			while (system_time() - start < dcspeed)
			{
				snooze (20000);
				GetMouse (&bp, &bt, true);
				if (!bt && click != 2)
				{
					click = 0;
				}
				if (bt && !click)
				{
					click = 2;
				}
				if (bp != pbp)
					break;
			}
		}
		if (click != 2)
		{
			// Now we're dragging...
			while (buttons)
			{
				BPoint p = BPoint (point.x - sep, point.y);
				float x = p.x;
				if (!(knob.Contains (p)) && !dragging)
				{
					if (x > knob.left)
					{
						value += step * (x - knob.right)/10;
					}
					else
					{
						value += step * (x - knob.left)/10;
					}
					if (value < min)
						value = min;
					if (value > max)
						value = max;
					if (step > 1 && fmod (value - min, step))	// Hack hack!
						value = int ((value - min)/step)*step + min;
		//			if (fmt[strlen (fmt) - 2] == '0')
		//				value = int (value + 0.5);
					offslid->Lock();
					Invalidate (BRect (sep + 1, 0, offslid->Bounds().Width() + sep, height));
					offslid->Unlock();
					NotifyTarget();
				}
				else if (px != p.x && step <= 1)	// Hacks galore!
				{
					dragging = true;
					value = (x - knobsize/2) / (width - knobsize) * (max - min) + min;
					//printf ("x = %f, knobsize = %f, value = %f\n", x, knobsize, value);
					//printf ("Value: %f ", value);
					if (value < min)
						value = min;
					if (value > max)
						value = max;
					if (step > 1 && fmod (value - min, step))
						value = int ((value - min)/step)*step + min;
					if (fmt[strlen (fmt) - 2] == '0')
						value = int (value + 0.5);
					//printf ("-> %f\n", value);
					offslid->Lock();
					Invalidate (BRect (sep + 1, 0, offslid->Bounds().Width() + sep, height));
					offslid->Unlock();
					px = p.x;
					NotifyTarget();
				}
				knobpos = BPoint (float (value - min)/(max - min)*(width - knobsize), 1);
				knob = BRect (knobpos.x + 1, knobpos.y + 1, knobpos.x + knobsize - 2, knobpos.y + height - 2);
				snooze (20000);
				GetMouse (&point, &buttons, true);
			}
			click = 1;
		}
	}
	if (click == 2 || buttons & B_SECONDARY_MOUSE_BUTTON || modifiers() & B_CONTROL_KEY)
	{
		click = 1;
		if (tc)
		{
			RemoveChild (tc);
			delete tc;
		}
		knobpos = BPoint (float (value - min)/(max - min)*(width - knobsize), 1);
		BRect kbr = BRect (knobpos.x + sep, knobpos.y, knobpos.x + knobsize - 2 + sep, knobpos.y + height - 3);
//		kbr.PrintToStream();
		tc = new BTextControl (kbr, "slider value field", "", "", new BMessage ('tcVC'));
		tc->SetTarget (this);
		tc->SetDivider (0);
		EnterFilter *filter = new EnterFilter (this);
		tc->TextView()->AddFilter (filter);
		char vs[64];
		sprintf (vs, fmt, value);
		tc->SetText (vs);
		AddChild (tc);
		tc->MakeFocus (true);
	}
	NotifyTarget ();
}
コード例 #22
0
ファイル: InterfaceWindow.cpp プロジェクト: Kafay/vlc
InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
                                  const char * name )
    : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
               B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),

      /* Initializations */
      p_intf( _p_intf ),
      p_input( NULL ),
      p_playlist( NULL ),

      fFilePanel( NULL ),
      fLastUpdateTime( system_time() ),
      fSettings( new BMessage( 'sett' ) )
{
    p_playlist = pl_Hold( p_intf );

    var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
    var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
    var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, this );
    var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, this );
    var_AddCallback( p_playlist, "item-current", PlaylistChanged, this );

    char psz_tmp[1024];
#define ADD_ELLIPSIS( a ) \
    memset( psz_tmp, 0, 1024 ); \
    snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );

    BScreen screen;
    BRect screen_rect = screen.Frame();
    BRect window_rect;
    window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
                     ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
                     ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
                     ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
    fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
    window_rect.Set( screen_rect.right - 500,
                     screen_rect.top + 50,
                     screen_rect.right - 150,
                     screen_rect.top + 250 );
#if 0
    fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
    window_rect.Set( screen_rect.right - 550,
                     screen_rect.top + 300,
                     screen_rect.right - 150,
                     screen_rect.top + 500 );
#endif
    fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );

    // the media control view
    p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
    p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );

    float width, height;
    p_mediaControl->GetPreferredSize( &width, &height );

    // set up the main menu
    fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
                             B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );

    // make menu bar resize to correct height
    float menuWidth, menuHeight;
    fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
    fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
    // take care of proper size for ourself
    height += fMenuBar->Bounds().Height();
    ResizeTo( width, height );

    p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
    AddChild( fMenuBar );


    // Add the file Menu
    BMenu* fileMenu = new BMenu( _("File") );
    fMenuBar->AddItem( fileMenu );
    ADD_ELLIPSIS( _("Open File") );
    fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
    fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
    ADD_ELLIPSIS( _("Open Subtitles") );
    fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );

    fileMenu->AddSeparatorItem();
    ADD_ELLIPSIS( _("About") );
    BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
    item->SetTarget( be_app );
    fileMenu->AddItem( item );
    fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );

    fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
    fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );

    /* Add the Audio menu */
    fAudioMenu = new BMenu( _("Audio") );
    fMenuBar->AddItem ( fAudioMenu );
    fAudioMenu->AddItem( fLanguageMenu );
    fAudioMenu->AddItem( fSubtitlesMenu );

    fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
    fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
    fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
    fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );

    /* Add the Navigation menu */
    fNavigationMenu = new BMenu( _("Navigation") );
    fMenuBar->AddItem( fNavigationMenu );
    fNavigationMenu->AddItem( fPrevTitleMI );
    fNavigationMenu->AddItem( fNextTitleMI );
    fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
    fNavigationMenu->AddSeparatorItem();
    fNavigationMenu->AddItem( fPrevChapterMI );
    fNavigationMenu->AddItem( fNextChapterMI );
    fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );

    /* Add the Speed menu */
    fSpeedMenu = new BMenu( _("Speed") );
    fSpeedMenu->SetRadioMode( true );
    fSpeedMenu->AddItem(
        fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
    fSpeedMenu->AddItem(
        fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
    fSpeedMenu->AddItem(
        fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
    fSpeedMenu->AddItem(
        fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
    fSpeedMenu->AddItem(
        fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
    fSpeedMenu->AddItem(
        fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
    fSpeedMenu->AddItem(
        fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
    fMenuBar->AddItem( fSpeedMenu );

    /* Add the Show menu */
    fShowMenu = new BMenu( _("Window") );
#if 0
    ADD_ELLIPSIS( _("Playlist") );
    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
#endif
    ADD_ELLIPSIS( _("Messages") );
    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
    ADD_ELLIPSIS( _("Preferences") );
    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
    fMenuBar->AddItem( fShowMenu );

    // add the media control view after the menubar is complete
    // because it will set the window size limits in AttachedToWindow()
    // and the menubar needs to report the correct PreferredSize()
    AddChild( p_mediaControl );

    /* Prepare fow showing */
    _SetMenusEnabled( false );
    p_mediaControl->SetEnabled( false );

    _RestoreSettings();

    Show();
}
コード例 #23
0
ファイル: Alert.cpp プロジェクト: tqh/haiku-efi
BBitmap*
BAlert::_CreateTypeIcon()
{
	if (Type() == B_EMPTY_ALERT)
		return NULL;

	// The icons are in the app_server resources
	BBitmap* icon = NULL;
	BPath path;
	status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
	if (status != B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - find_directory "
			"failed: %s\n", strerror(status)));
		return NULL;
	}

	path.Append("app_server");
	BFile file;
	status = file.SetTo(path.Path(), B_READ_ONLY);
	if (status != B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - BFile init failed: %s\n",
			strerror(status)));
		return NULL;
	}

	BResources resources;
	status = resources.SetTo(&file);
	if (status != B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - BResources init "
			"failed: %s\n", strerror(status)));
		return NULL;
	}

	// Which icon are we trying to load?
	const char* iconName;
	switch (fType) {
		case B_INFO_ALERT:
			iconName = "info";
			break;
		case B_IDEA_ALERT:
			iconName = "idea";
			break;
		case B_WARNING_ALERT:
			iconName = "warn";
			break;
		case B_STOP_ALERT:
			iconName = "stop";
			break;

		default:
			// Alert type is either invalid or B_EMPTY_ALERT;
			// either way, we're not going to load an icon
			return NULL;
	}

	int32 iconSize = 32 * icon_layout_scale();
	// Allocate the icon bitmap
	icon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
		0, B_RGBA32);
	if (icon == NULL || icon->InitCheck() < B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - No memory for bitmap\n"));
		delete icon;
		return NULL;
	}

	// Load the raw icon data
	size_t size = 0;
	const uint8* rawIcon;

	// Try to load vector icon
	rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
		iconName, &size);
	if (rawIcon != NULL
		&& BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK) {
		return icon;
	}

	// Fall back to bitmap icon
	rawIcon = (const uint8*)resources.LoadResource(B_LARGE_ICON_TYPE,
		iconName, &size);
	if (rawIcon == NULL) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - Icon resource not found\n"));
		delete icon;
		return NULL;
	}

	// Handle color space conversion
	if (icon->ColorSpace() != B_CMAP8) {
		BIconUtils::ConvertFromCMAP8(rawIcon, iconSize, iconSize,
			iconSize, icon);
	}

	return icon;
}
コード例 #24
0
void
NodeHarnessWin::MessageReceived(BMessage *msg)
{
    status_t err;

    switch (msg->what)
    {
    case BUTTON_CONNECT:
        mIsConnected = true;

        // set the button states appropriately
        mConnectButton->SetEnabled(false);
        mStartButton->SetEnabled(true);

        // set up the node network
        {
            BMediaRoster* r = BMediaRoster::Roster();

            // connect to the mixer
            err = r->GetAudioMixer(&mConnection.consumer);
            ErrorCheck(err, "unable to get the system mixer");

            // fire off a window with the ToneProducer's controls in it
            BParameterWeb* web;
            r->GetParameterWebFor(mConnection.producer, &web);
            BView* view = BMediaTheme::ViewFor(web);
            BWindow* win = new BWindow(BRect(250, 200, 300, 300), "Controls",
                                       B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS);
            win->AddChild(view);
            win->ResizeTo(view->Bounds().Width(), view->Bounds().Height());
            win->Show();

            // set the producer's time source to be the "default" time source, which
            // the Mixer uses too.
            r->GetTimeSource(&mTimeSource);
            r->SetTimeSourceFor(mConnection.producer.node, mTimeSource.node);

            // got the nodes; now we find the endpoints of the connection
            media_input mixerInput;
            media_output soundOutput;
            int32 count = 1;
            err = r->GetFreeOutputsFor(mConnection.producer, &soundOutput, 1, &count);
            ErrorCheck(err, "unable to get a free output from the producer node");
            count = 1;
            err = r->GetFreeInputsFor(mConnection.consumer, &mixerInput, 1, &count);
            ErrorCheck(err, "unable to get a free input to the mixer");

            // got the endpoints; now we connect it!
            media_format format;
            format.type = B_MEDIA_RAW_AUDIO;
            format.u.raw_audio = media_raw_audio_format::wildcard;
            err = r->Connect(soundOutput.source, mixerInput.destination, &format, &soundOutput, &mixerInput);
            ErrorCheck(err, "unable to connect nodes");

            // the inputs and outputs might have been reassigned during the
            // nodes' negotiation of the Connect().  That's why we wait until
            // after Connect() finishes to save their contents.
            mConnection.format = format;
            mConnection.source = soundOutput.source;
            mConnection.destination = mixerInput.destination;

            // Set an appropriate run mode for the producer
            r->SetRunModeNode(mConnection.producer, BMediaNode::B_INCREASE_LATENCY);
        }
        break;

    case BUTTON_START:
        mStartButton->SetEnabled(false);
        mStopButton->SetEnabled(true);

        // start the producer running
        {
            BMediaRoster* r = BMediaRoster::Roster();
            BTimeSource* ts = r->MakeTimeSourceFor(mConnection.producer);
            if (!ts)
            {
                fprintf(stderr, "* ERROR - MakeTimeSourceFor(producer) returned NULL!\n");
                exit(1);
            }

            // make sure we give the producer enough time to run buffers through
            // the node chain, otherwise it'll start up already late
            bigtime_t latency = 0;
            r->GetLatencyFor(mConnection.producer, &latency);
            r->StartNode(mConnection.producer, ts->Now() + latency);
            ts->Release();
            mIsRunning = true;
        }
        break;

    case BUTTON_STOP:
        StopNodes();
        break;

    default:
        BWindow::MessageReceived(msg);
        break;
    }
}
コード例 #25
0
SelectionWindow::SelectionWindow(BContainerWindow* window)
	:
	BWindow(BRect(0, 0, 270, 0), B_TRANSLATE("Select"),	B_TITLED_WINDOW,
		B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_V_RESIZABLE
			| B_NO_WORKSPACE_ACTIVATION | B_ASYNCHRONOUS_CONTROLS
			| B_NOT_ANCHORED_ON_ACTIVATE),
	fParentWindow(window)
{
	if (window->Feel() & kDesktopWindowFeel) {
		// The window will not show up if we have
		// B_FLOATING_SUBSET_WINDOW_FEEL and use it with the desktop window
		// since it's never in front.
		SetFeel(B_NORMAL_WINDOW_FEEL);
	}

	AddToSubset(fParentWindow);

	BView* backgroundView = new BView(Bounds(), "bgView", B_FOLLOW_ALL,
		B_WILL_DRAW);
	backgroundView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	AddChild(backgroundView);

	BMenu* menu = new BPopUpMenu("");
	menu->AddItem(new BMenuItem(B_TRANSLATE("starts with"),	NULL));
	menu->AddItem(new BMenuItem(B_TRANSLATE("ends with"), NULL));
	menu->AddItem(new BMenuItem(B_TRANSLATE("contains"), NULL));
	menu->AddItem(new BMenuItem(B_TRANSLATE("matches wildcard expression"),
		NULL));
	menu->AddItem(new BMenuItem(B_TRANSLATE("matches regular expression"),
		NULL));

	menu->SetLabelFromMarked(true);
	menu->ItemAt(3)->SetMarked(true);
		// Set wildcard matching to default.

	// Set up the menu field
	fMatchingTypeMenuField = new BMenuField(BRect(7, 6,
		Bounds().right - 5, 0), NULL, B_TRANSLATE("Name"), menu);
	backgroundView->AddChild(fMatchingTypeMenuField);
	fMatchingTypeMenuField->SetDivider(fMatchingTypeMenuField->StringWidth(
		B_TRANSLATE("Name")) + 8);
	fMatchingTypeMenuField->ResizeToPreferred();

	// Set up the expression text control
	fExpressionTextControl = new BTextControl(BRect(7,
			fMatchingTypeMenuField->Bounds().bottom + 11,
			Bounds().right - 6, 0),
		NULL, NULL, NULL, NULL, B_FOLLOW_LEFT_RIGHT);
	backgroundView->AddChild(fExpressionTextControl);
	fExpressionTextControl->ResizeToPreferred();
	fExpressionTextControl->MakeFocus(true);

	// Set up the Invert checkbox
	fInverseCheckBox = new BCheckBox(
		BRect(7, fExpressionTextControl->Frame().bottom + 6, 6, 6), NULL,
		B_TRANSLATE("Invert"), NULL);
	backgroundView->AddChild(fInverseCheckBox);
	fInverseCheckBox->ResizeToPreferred();

	// Set up the Ignore Case checkbox
	fIgnoreCaseCheckBox = new BCheckBox(
		BRect(fInverseCheckBox->Frame().right + 10,
			fInverseCheckBox->Frame().top, 6, 6),
		NULL, B_TRANSLATE("Ignore case"), NULL);
	fIgnoreCaseCheckBox->SetValue(1);
	backgroundView->AddChild(fIgnoreCaseCheckBox);
	fIgnoreCaseCheckBox->ResizeToPreferred();

	// Set up the Select button
	fSelectButton = new BButton(BRect(0, 0, 5, 5), NULL,
		B_TRANSLATE("Select"), new BMessage(kSelectButtonPressed),
		B_FOLLOW_RIGHT);

	backgroundView->AddChild(fSelectButton);
	fSelectButton->ResizeToPreferred();
	fSelectButton->MoveTo(Bounds().right - 10 - fSelectButton->Bounds().right,
		fExpressionTextControl->Frame().bottom + 9);
	fSelectButton->MakeDefault(true);
#if !B_BEOS_VERSION_DANO
	fSelectButton->SetLowColor(backgroundView->ViewColor());
	fSelectButton->SetViewColor(B_TRANSPARENT_COLOR);
#endif

	font_height fh;
	be_plain_font->GetHeight(&fh);
	// Center the checkboxes vertically to the button
	float topMiddleButton =
		(fSelectButton->Bounds().Height() / 2 -
		(fh.ascent + fh.descent + fh.leading + 4) / 2)
		+ fSelectButton->Frame().top;
	fInverseCheckBox->MoveTo(fInverseCheckBox->Frame().left, topMiddleButton);
	fIgnoreCaseCheckBox->MoveTo(fIgnoreCaseCheckBox->Frame().left,
		topMiddleButton);

	float bottomMinWidth = 32 + fSelectButton->Bounds().Width()
		+ fInverseCheckBox->Bounds().Width()
		+ fIgnoreCaseCheckBox->Bounds().Width();
	float topMinWidth = be_plain_font->StringWidth(
		B_TRANSLATE("Name matches wildcard expression:###"));
	float minWidth = bottomMinWidth > topMinWidth
		? bottomMinWidth : topMinWidth;

	class EscapeFilter : public BMessageFilter {
	public:
		EscapeFilter(BWindow* target)
			:
			BMessageFilter(B_KEY_DOWN),
			fTarget(target)
		{
		}

		virtual filter_result Filter(BMessage* message, BHandler** _target)
		{
			int8 byte;
			if (message->what == B_KEY_DOWN
				&& message->FindInt8("byte", &byte) == B_OK
				&& byte == B_ESCAPE) {
				fTarget->Hide();
				return B_SKIP_MESSAGE;
			}
			return B_DISPATCH_MESSAGE;
		}

	private:
		BWindow* fTarget;
	};
	AddCommonFilter(new(std::nothrow) EscapeFilter(this));

	Run();

	Lock();
	ResizeTo(minWidth, fSelectButton->Frame().bottom + 6);

	SetSizeLimits(minWidth, 1280, Bounds().bottom, Bounds().bottom);

	MoveCloseToMouse();
	Unlock();
}
コード例 #26
0
ファイル: main.cpp プロジェクト: Ithamar/cosmoe
void BitmapView::MouseDown( BPoint cPosition )
{
	MakeFocus( true );

	Icon* pcIcon = FindIcon( cPosition );

	if ( pcIcon != NULL )
	{
		if (  pcIcon->m_bSelected )
		{
			if ( m_nHitTime + 500000 >= system_time() )
			{
				if ( pcIcon->GetName() == "Root (List)" )
				{
					BWindow*   pcWindow = new DirWindow( BRect( 200, 150, 600, 400 ), "/" );
					pcWindow->Activate();
				}
				else if ( pcIcon->GetName() == "Root (Icon)" )
				{
					BWindow*   pcWindow = new DirIconWindow( BRect( 20, 20, 359, 220 ), "/", g_pcBackDrop );
					pcWindow->Activate();
				}
				else  if ( pcIcon->GetName() == "Terminal" )
				{
					pid_t nPid = fork();
					if ( nPid == 0 )
					{
						set_thread_priority( -1, 0 );
						execlp( "cterm", "cterm", NULL );
						exit( 1 );
					}
				}
				else  if ( pcIcon->GetName() == "Prefs" )
				{
					pid_t nPid = fork();
					if ( nPid == 0 )
					{
						set_thread_priority( -1, 0 );
						execlp( "guiprefs", "guiprefs", NULL );
						exit( 1 );
					}
				}
				else  if ( pcIcon->GetName() == "Pulse" )
				{
					pid_t nPid = fork();
					if ( nPid == 0 )
					{
						set_thread_priority( -1, 0 );
						execlp( "pulse", "pulse", NULL );
						exit( 1 );
					}
				}
				else  if ( pcIcon->GetName() == "Calculator" )
				{
					pid_t nPid = fork();
					if ( nPid == 0 )
					{
						set_thread_priority( -1, 0 );
						execlp( "calc", "calc", NULL );
						exit( 1 );
					}
				}
				else  if ( pcIcon->GetName() == "Editor" )
				{
					pid_t nPid = fork();
					if ( nPid == 0 )
					{
						set_thread_priority( -1, 0 );
						execlp( "aedit", "aedit", NULL );
						exit( 1 );
					}
				}
				else  if ( pcIcon->GetName() == "Guido" )
				{
					pid_t nPid = fork();
					if ( nPid == 0 )
					{
						set_thread_priority( -1, 0 );
						execlp( "guido", "guido", NULL );
						exit( 1 );
					}
				}
			}
			else
			{
				m_bCanDrag = true;
			}
			m_nHitTime = system_time();
			return;
		}
	}

	for ( uint i = 0 ; i < m_cIcons.size() ; ++i )
	{
		m_cIcons[i]->Select( this, false );
	}

	if ( pcIcon != NULL )
	{
		m_bCanDrag = true;
		pcIcon->Select( this, true );
	}
	else
	{
		m_bSelRectActive = true;
		m_cSelRect = BRect( cPosition.x, cPosition.y, cPosition.x, cPosition.y );
		SetDrawingMode( B_OP_INVERT );
		DrawFrame( m_cSelRect, FRAME_TRANSPARENT | FRAME_THIN );
	}

	Flush();
	m_cLastPos = cPosition;
	m_nHitTime = system_time();
}
コード例 #27
0
ファイル: NotificationView.cpp プロジェクト: mariuz/haiku
void
NotificationView::_LoadIcon()
{
	// First try to get the icon from the caller application
	app_info info;
	BMessenger msgr = fDetails->ReturnAddress();

	if (msgr.IsValid())
		be_roster->GetRunningAppInfo(msgr.Team(), &info);
	else if (fType == B_PROGRESS_NOTIFICATION)
		be_roster->GetAppInfo("application/x-vnd.Haiku-notification_server",
			&info);

	BPath path;
	path.SetTo(&info.ref);

	fBitmap = _ReadNodeIcon(path.Path(), fParent->IconSize());
	if (fBitmap)
		return;

	// If that failed get icons from app_server
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) != B_OK)
		return;

	path.Append("app_server");

	BFile file(path.Path(), B_READ_ONLY);
	if (file.InitCheck() != B_OK)
		return;

	BResources res(&file);
	if (res.InitCheck() != B_OK)
		return;

	// Which one should we choose?
	const char* iconName = "";
	switch (fType) {
		case B_INFORMATION_NOTIFICATION:
			iconName = "info";
			break;
		case B_ERROR_NOTIFICATION:
			iconName = "stop";
			break;
		case B_IMPORTANT_NOTIFICATION:
			iconName = "warn";
			break;
		default:
			return;
	}

	// Allocate the bitmap
	fBitmap = new BBitmap(BRect(0, 0, (float)B_LARGE_ICON - 1,
		(float)B_LARGE_ICON - 1), B_RGBA32);
	if (!fBitmap || fBitmap->InitCheck() != B_OK) {
		fBitmap = NULL;
		return;
	}

	// Load raw icon data
	size_t size = 0;
	const uint8* data = (const uint8*)res.LoadResource(B_VECTOR_ICON_TYPE,
		iconName, &size);
	if ((data == NULL
		|| BIconUtils::GetVectorIcon(data, size, fBitmap) != B_OK))
		fBitmap = NULL;
}
コード例 #28
0
ファイル: NodeHarnessApp.cpp プロジェクト: DonCN/haiku
void
NodeHarnessApp::ReadyToRun()
{
	BWindow* win = new NodeHarnessWin(BRect(100, 200, 210, 330), "ToneProducer");
	win->Show();
}
コード例 #29
0
ファイル: StatusView.cpp プロジェクト: AmirAbrams/haiku
StatusView::StatusView()
	:
	BView(NULL, B_WILL_DRAW),
	fCurrentFileInfo(NULL)
{
	SetViewColor(kPieBGColor);
	SetLowColor(kPieBGColor);

	fSizeView = new BStringView(NULL, kEmptyStr);
	fSizeView->SetExplicitMinSize(BSize(StringWidth("9999.99 GiB"),
		B_SIZE_UNSET));
	fSizeView->SetExplicitMaxSize(BSize(StringWidth("9999.99 GiB"),
		B_SIZE_UNSET));

	char testLabel[256];
	snprintf(testLabel, sizeof(testLabel), B_TRANSLATE_COMMENT("%d files",
		"For UI layouting only, use the longest plural form for your language"),
		999999);

	fCountView = new BStringView(NULL, kEmptyStr);
	float width, height;
	fCountView->GetPreferredSize(&width, &height);
	fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel),
		B_SIZE_UNSET));
	fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height));

	fPathView = new BStringView(NULL, kEmptyStr);
	fPathView->GetPreferredSize(&width, &height);
	fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height));

	fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"),
		new BMessage(kBtnRescan));

	fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED));

	BBox* divider1 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
		B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);

	BBox* divider2 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
		B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);

	divider1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
	divider2->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED));

	SetLayout(new BGroupLayout(B_VERTICAL));

	AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 0)
		.AddGroup(B_VERTICAL, 0)
			.Add(fPathView)
			.Add(divider1)
			.AddGroup(B_HORIZONTAL, 0)
				.Add(fCountView)
				.Add(divider2)
				.Add(fSizeView)
				.End()
			.End()
		.AddStrut(kSmallHMargin)
		.Add(fRefreshBtn)
		.SetInsets(kSmallVMargin, kSmallVMargin, kSmallVMargin, kSmallVMargin)
	);
}
コード例 #30
0
ファイル: Enclosures.cpp プロジェクト: mmanley/Antares
void
TListItem::DrawItem(BView *owner, BRect r, bool /* complete */)
{
	if (IsSelected()) {
		owner->SetHighColor(180, 180, 180);
		owner->SetLowColor(180, 180, 180);
	} else {
		owner->SetHighColor(255, 255, 255);
		owner->SetLowColor(255, 255, 255);
	}
	owner->FillRect(r);
	owner->SetHighColor(0, 0, 0);

	BFont font = *be_plain_font;
	font.SetSize(font.Size() * kPlainFontSizeScale);
	owner->SetFont(&font);
	owner->MovePenTo(r.left + 24, r.bottom - 4);

	if (fComponent) {
		// if it's already a mail component, we don't have an icon to
		// draw, and the entry_ref is invalid
		BMailAttachment *attachment = dynamic_cast<BMailAttachment *>(fComponent);

		char name[B_FILE_NAME_LENGTH * 2];
		if ((attachment == NULL) || (attachment->FileName(name) < B_OK))
			strcpy(name, "unnamed");

		BMimeType type;
		if (fComponent->MIMEType(&type) == B_OK)
			sprintf(name + strlen(name), ", Type: %s", type.Type());

		owner->DrawString(name);

		BRect iconRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1);

		BBitmap bitmap(iconRect, B_COLOR_8_BIT);
		if (GetTrackerIcon(type, &bitmap, B_MINI_ICON) == B_NO_ERROR) {
			BRect rect(r.left + 4, r.top + 1, r.left + 4 + 15, r.top + 1 + 15);
			owner->SetDrawingMode(B_OP_OVER);
			owner->DrawBitmap(&bitmap, iconRect, rect);
			owner->SetDrawingMode(B_OP_COPY);
		} else {
			// ToDo: find some nicer image for this :-)
			owner->SetHighColor(150, 150, 150);
			owner->FillEllipse(BRect(r.left + 8, r.top + 4, r.left + 16, r.top + 13));
		}
		return;
	}

	BFile file(&fRef, O_RDONLY);
	BEntry entry(&fRef);
	BPath path;
	if (entry.GetPath(&path) == B_OK && file.InitCheck() == B_OK) {
		owner->DrawString(path.Path());

		BNodeInfo info(&file);
		BRect sr(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1);

		BBitmap bitmap(sr, B_COLOR_8_BIT);
		if (info.GetTrackerIcon(&bitmap, B_MINI_ICON) == B_NO_ERROR) {
			BRect dr(r.left + 4, r.top + 1, r.left + 4 + 15, r.top + 1 + 15);
			owner->SetDrawingMode(B_OP_OVER);
			owner->DrawBitmap(&bitmap, sr, dr);
			owner->SetDrawingMode(B_OP_COPY);
		}
	} else
		owner->DrawString("<missing attachment>");
}