예제 #1
0
TestWindow::TestWindow(BApplication* myApp)
	: BWindow(BRect(20,20,100,100),
	  "Code Profile", B_TITLED_WINDOW, 0)
{
	BRect frm = Bounds();

	BView* myview = new BView(BRect(),"testView",0,0);
	
	BOutlineListView* olist =
		new BOutlineListView(BRect(),"MyList",
							B_SINGLE_SELECTION_LIST,B_FOLLOW_NONE);
	if( myview && olist ) {
		myview->AddChild(olist);
		BView* vw = olist;
		vw->SetViewColor(0xc0,0xc0,0xc0);
		vw->Invalidate();
		vw->SetLowColor(0xc0,0xc0,0xc0);
		vw->Invalidate();
		vw->SetHighColor(0x00,0x00,0x00);
		vw->Invalidate();
		vw->SetFont(be_bold_font);
		this->AddChild(myview);
		BRect frm = vw->Frame();
		vw->ResizeTo(1,1);
		vw->Draw(vw->Bounds());
		vw->ResizeToPreferred();
		float w=0,h=0;
		vw->GetPreferredSize(&w,&h);
		printf("Preferred size = %f x %f\n",w,h);
	}
	
	string = new BStringView(BRect(0,0,100,20),"String",
								"Ready to profile...");	
	
	if( string ) {
		string->SetViewColor(0xc0,0xc0,0xc0);
		this->AddChild(string);
		float w=0, h=0;
		string->GetPreferredSize(&w,&h);
		MoveTo(30,30);
		ResizeTo(w,h);
	}
	
	BMenuBar* menu = new BMenuBar(BRect(),"MainMenu",B_FOLLOW_NONE);
	if( menu ) {
		this->AddChild(menu);
		float w=0, h=0;
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_plain_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_bold_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_fixed_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
	}
}
예제 #2
0
Fenster::Fenster() : BWindow( BRect( 20, 40, 620, 460), "PecoRename", B_TITLED_WINDOW, 0){
// Menü
	BMenuBar* MenuBar = new BMenuBar( BRect( 0, 0, 0, 0 ), "MenuBar" );

	BMenu* Menu;

	Menu = new BMenu(STR_MENU_FILE);
	MenuBar->AddItem(Menu);

	Menu->AddItem(new BMenuItem(STR_MENU_NEW, 				new BMessage(MSG_MENU_NEW), 'N'));
	Menu->AddItem(new BMenuItem(STR_MENU_OPEN, 				new BMessage(MSG_SELECT_FILES), 'O'));
	Menu->AddSeparatorItem();
	Menu->AddItem(new BMenuItem(STR_MENU_ABOUT, 			new BMessage(B_ABOUT_REQUESTED)));
	Menu->AddSeparatorItem();
	Menu->AddItem(new BMenuItem(STR_MENU_QUIT, 				new BMessage(B_QUIT_REQUESTED), 'Q'));

	Menu = new BMenu(STR_MENU_TOOLS);
	MenuBar->AddItem(Menu);

	Menu->AddItem(new BMenuItem(STR_MENU_CREATE_SCRIPT, 	new BMessage(MSG_MENU_SCRIPT)));

	Menu = new BMenu(STR_MENU_HELP);
	MenuBar->AddItem(Menu);

	Menu->AddItem(new BMenuItem(STR_MENU_DOCU, new BMessage(MSG_MENU_DOCU)));

	AddChild( MenuBar );
// Größe bestimmen + Fenster anpassen
	float BarWidth, BarHeight;
	MenuBar->GetPreferredSize ( &BarWidth, &BarHeight );
	SetSizeLimits( 600, 600, 10000, 155 + BarHeight + 5 * be_plain_font->Size() + 2 * be_bold_font->Size());

// Main Frame
	BRect MainFrame = Bounds();
	MainFrame.top += BarHeight;

	MainView* mainView = new MainView( MainFrame );
	AddChild( mainView );
	
	BTextControl*	TextControl = (BTextControl *)FindView("pfadView");
	TextControl->TextView()->MakeEditable(false);

};
예제 #3
0
파일: Header.cpp 프로젝트: sahil9912/haiku
THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,
	bool resending, uint32 defaultCharacterSet, int32 defaultAccount)
	:
	BBox(rect, "m_header", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW, B_NO_BORDER),

	fAccountMenu(NULL),
	fEncodingMenu(NULL),
	fAccountID(defaultAccount),
	fAccountTo(NULL),
	fAccount(NULL),
	fBcc(NULL),
	fCc(NULL),
	fSubject(NULL),
	fTo(NULL),
	fDateLabel(NULL),
	fDate(NULL),
	fIncoming(incoming),
	fCharacterSetUserSees(defaultCharacterSet),
	fResending(resending),
	fBccMenu(NULL),
	fCcMenu(NULL),
	fToMenu(NULL),
	fEmailList(NULL)
{
	BMenuField* field;
	BMessage* msg;

	float x = StringWidth( /* The longest title string in the header area */
		B_TRANSLATE("Attachments: ")) + 9;
	float y = TO_FIELD_V;

	BMenuBar* dummy = new BMenuBar(BRect(0, 0, 100, 15), "Dummy");
	AddChild(dummy);
	float width, menuBarHeight;
	dummy->GetPreferredSize(&width, &menuBarHeight);
	dummy->RemoveSelf();
	delete dummy;

	float menuFieldHeight = menuBarHeight + 6;
	float controlHeight = menuBarHeight + floorf(be_plain_font->Size() / 1.15);

	if (!fIncoming) {
		InitEmailCompletion();
		InitGroupCompletion();
	}

	// Prepare the character set selection pop-up menu (we tell the user that
	// it is the Encoding menu, even though it is really the character set).
	// It may appear in the first line, to the right of the From box if the
	// user is reading an e-mail.  It appears on the second line, to the right
	// of the e-mail account menu, if the user is composing a message.  It lets
	// the user quickly select a character set different from the application
	// wide default one, and also shows them which character set is active.  If
	// you are reading a message, you also see an item that says "Automatic"
	// for automatic decoding character set choice.  It can slide around as the
	// window is resized when viewing a message, but not when composing
	// (because the adjacent pop-up menu can't resize dynamically due to a BeOS
	// bug).

	float widestCharacterSet = 0;
	bool markedCharSet = false;
	BMenuItem* item;

	fEncodingMenu = new BPopUpMenu(B_EMPTY_STRING);

	BCharacterSetRoster roster;
	BCharacterSet charset;
	while (roster.GetNextCharacterSet(&charset) == B_OK) {
		BString name(charset.GetPrintName());
		const char* mime = charset.GetMIMEName();
		if (mime)
			name << " (" << mime << ")";

		uint32 convertID;
		if (mime == NULL || strcasecmp(mime, "UTF-8") != 0)
			convertID = charset.GetConversionID();
		else
			convertID = B_MAIL_UTF8_CONVERSION;

		msg = new BMessage(kMsgEncoding);
		msg->AddInt32("charset", convertID);
		fEncodingMenu->AddItem(item = new BMenuItem(name.String(), msg));
		if (convertID == fCharacterSetUserSees && !markedCharSet) {
			item->SetMarked(true);
			markedCharSet = true;
		}
		if (StringWidth(name.String()) > widestCharacterSet)
			widestCharacterSet = StringWidth(name.String());
	}

	msg = new BMessage(kMsgEncoding);
	msg->AddInt32("charset", B_MAIL_US_ASCII_CONVERSION);
	fEncodingMenu->AddItem(item = new BMenuItem("US-ASCII", msg));
	if (fCharacterSetUserSees == B_MAIL_US_ASCII_CONVERSION && !markedCharSet) {
		item->SetMarked(true);
		markedCharSet = true;
	}

	if (!resending && fIncoming) {
		// reading a message, display the Automatic item
		fEncodingMenu->AddSeparatorItem();
		msg = new BMessage(kMsgEncoding);
		msg->AddInt32("charset", B_MAIL_NULL_CONVERSION);
		fEncodingMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Automatic"), msg));
		if (!markedCharSet)
			item->SetMarked(true);
	}

	// First line of the header, From for reading e-mails (includes the
	// character set choice at the right), To when composing (nothing else in
	// the row).

	BRect r;
	char string[20];
	if (fIncoming && !resending) {
		// Set up the character set pop-up menu on the right of "To" box.
		r.Set (windowRect.Width() - widestCharacterSet -
			StringWidth (B_TRANSLATE("Decoding:")) - 2 * SEPARATOR_MARGIN,
				y - 2, windowRect.Width() - SEPARATOR_MARGIN,
				y + menuFieldHeight);
		field = new BMenuField (r, "decoding", B_TRANSLATE("Decoding:"),
			fEncodingMenu, true /* fixedSize */,
			B_FOLLOW_TOP | B_FOLLOW_RIGHT,
			B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
		field->SetDivider(field->StringWidth(B_TRANSLATE("Decoding:")) + 5);
		AddChild(field);
		r.Set(SEPARATOR_MARGIN, y,
			  field->Frame().left - SEPARATOR_MARGIN, y + menuFieldHeight);
		sprintf(string, B_TRANSLATE("From:"));
	} else {
		r.Set(x - 12, y, windowRect.Width() - SEPARATOR_MARGIN,
			y + menuFieldHeight);
		string[0] = 0;
	}

	y += controlHeight;
	fTo = new TTextControl(r, string, new BMessage(TO_FIELD), fIncoming,
		resending, B_FOLLOW_LEFT_RIGHT);
	fTo->SetFilter(mail_to_filter);

	if (!fIncoming || resending) {
		fTo->SetChoiceList(&fEmailList);
		fTo->SetAutoComplete(true);
	} else {
		fTo->SetDivider(x - 12 - SEPARATOR_MARGIN);
		fTo->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
	}

	AddChild(fTo);
	msg = new BMessage(FIELD_CHANGED);
	msg->AddInt32("bitmask", FIELD_TO);
	fTo->SetModificationMessage(msg);

	if (!fIncoming || resending) {
		r.right = r.left - 5;
		r.left = r.right - ceilf(be_plain_font->StringWidth(
			B_TRANSLATE("To:")) + 25);
		r.top -= 1;
		fToMenu = new QPopupMenu(B_TRANSLATE("To:"));
		field = new BMenuField(r, "", "", fToMenu, true,
			B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
		field->SetDivider(0.0);
		field->SetEnabled(true);
		AddChild(field);
	}

	// "From:" accounts Menu and Encoding Menu.
	if (!fIncoming || resending) {
		// Put the character set box on the right of the From field.
		r.Set(windowRect.Width() - widestCharacterSet -
			StringWidth(B_TRANSLATE("Encoding:")) - 2 * SEPARATOR_MARGIN,
			y - 2, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
		BMenuField* encodingField = new BMenuField(r, "encoding",
			B_TRANSLATE("Encoding:"), fEncodingMenu, true /* fixedSize */,
			B_FOLLOW_TOP | B_FOLLOW_RIGHT,
			B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
		encodingField->SetDivider(encodingField->StringWidth(
			B_TRANSLATE("Encoding:")) + 5);
		AddChild(encodingField);

		field = encodingField;

		// And now the "from account" pop-up menu, on the left side, taking the
		// remaining space.

		fAccountMenu = new BPopUpMenu(B_EMPTY_STRING);

		BMailAccounts accounts;
		bool marked = false;
		for (int32 i = 0; i < accounts.CountAccounts(); i++) {
			BMailAccountSettings* account = accounts.AccountAt(i);
			BString name = account->Name();
			name << ":   " << account->RealName() << "  <"
				<< account->ReturnAddress() << ">";

			msg = new BMessage(kMsgFrom);
			BMenuItem *item = new BMenuItem(name, msg);

			msg->AddInt32("id", account->AccountID());

			if (defaultAccount == account->AccountID()) {
				item->SetMarked(true);
				marked = true;
			}
			fAccountMenu->AddItem(item);
		}

		if (!marked) {
			BMenuItem *item = fAccountMenu->ItemAt(0);
			if (item != NULL) {
				item->SetMarked(true);
				fAccountID = item->Message()->FindInt32("id");
			} else {
				fAccountMenu->AddItem(
					item = new BMenuItem(B_TRANSLATE("<none>"), NULL));
				item->SetEnabled(false);
				fAccountID = ~0UL;
			}
			// default account is invalid, set to marked
			// TODO: do this differently, no casting and knowledge
			// of TMailApp here....
			if (TMailApp* app = dynamic_cast<TMailApp*>(be_app))
				app->SetDefaultAccount(fAccountID);
		}

		r.Set(SEPARATOR_MARGIN, y - 2,
			  field->Frame().left - SEPARATOR_MARGIN, y + menuFieldHeight);
		field = new BMenuField(r, "account", B_TRANSLATE("From:"),
			fAccountMenu, true /* fixedSize */,
			B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT,
			B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
		AddChild(field, encodingField);
		field->SetDivider(x - 12 - SEPARATOR_MARGIN + kMenuFieldDividerOffset);
		field->SetAlignment(B_ALIGN_RIGHT);
		y += controlHeight;
	} else {
		// To: account
		bool account = BMailAccounts().CountAccounts() > 0;

		r.Set(SEPARATOR_MARGIN, y,
			  windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
		if (account)
			r.right -= SEPARATOR_MARGIN + ACCOUNT_FIELD_WIDTH;
		fAccountTo = new TTextControl(r, B_TRANSLATE("To:"), NULL, fIncoming,
			false, B_FOLLOW_LEFT_RIGHT);
		fAccountTo->SetEnabled(false);
		fAccountTo->SetDivider(x - 12 - SEPARATOR_MARGIN);
		fAccountTo->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
		AddChild(fAccountTo);

		if (account) {
			r.left = r.right + 6;  r.right = windowRect.Width() - SEPARATOR_MARGIN;
			fAccount = new TTextControl(r, B_TRANSLATE("Account:"), NULL,
				fIncoming, false, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
			fAccount->SetEnabled(false);
			AddChild(fAccount);
		}
		y += controlHeight;
	}
	
	if (fIncoming) {
		--y;
		r.Set(SEPARATOR_MARGIN, y,
			windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
		y += controlHeight;
		fCc = new TTextControl(r, B_TRANSLATE("Cc:"),
			NULL, fIncoming, false, B_FOLLOW_LEFT_RIGHT);
		fCc->SetEnabled(false);
		fCc->SetDivider(x - 12 - SEPARATOR_MARGIN);
		fCc->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
		AddChild(fCc);
	}

	--y;
	r.Set(SEPARATOR_MARGIN, y,
		windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
	y += controlHeight;
	fSubject = new TTextControl(r, B_TRANSLATE("Subject:"),
		new BMessage(SUBJECT_FIELD),fIncoming, false, B_FOLLOW_LEFT_RIGHT);
	AddChild(fSubject);
	(msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_SUBJECT);
	fSubject->SetModificationMessage(msg);
	fSubject->SetDivider(x - 12 - SEPARATOR_MARGIN);
	fSubject->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
	if (fResending)
		fSubject->SetEnabled(false);

	--y;

	if (!fIncoming) {
		r.Set(x - 12, y, CC_FIELD_H + CC_FIELD_WIDTH, y + menuFieldHeight);
		fCc = new TTextControl(r, "", new BMessage(CC_FIELD), fIncoming, false);
		fCc->SetFilter(mail_to_filter);
		fCc->SetChoiceList(&fEmailList);
		fCc->SetAutoComplete(true);
		AddChild(fCc);
		(msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_CC);
		fCc->SetModificationMessage(msg);

		r.right = r.left - 5;
		r.left = r.right - ceilf(be_plain_font->StringWidth(
			B_TRANSLATE("Cc:")) + 25);
		r.top -= 1;
		fCcMenu = new QPopupMenu(B_TRANSLATE("Cc:"));
		field = new BMenuField(r, "", "", fCcMenu, true,
			B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);

		field->SetDivider(0.0);
		field->SetEnabled(true);
		AddChild(field);

		r.Set(BCC_FIELD_H + be_plain_font->StringWidth(B_TRANSLATE("Bcc:")), y,
			  windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
		y += controlHeight;
		fBcc = new TTextControl(r, "", new BMessage(BCC_FIELD),
						fIncoming, false, B_FOLLOW_LEFT_RIGHT);
		fBcc->SetFilter(mail_to_filter);
		fBcc->SetChoiceList(&fEmailList);
		fBcc->SetAutoComplete(true);
		AddChild(fBcc);
		(msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_BCC);
		fBcc->SetModificationMessage(msg);

		r.right = r.left - 5;
		r.left = r.right - ceilf(be_plain_font->StringWidth(
			B_TRANSLATE("Bcc:")) + 25);
		r.top -= 1;
		fBccMenu = new QPopupMenu(B_TRANSLATE("Bcc:"));
		field = new BMenuField(r, "", "", fBccMenu, true,
			B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
		field->SetDivider(0.0);
		field->SetEnabled(true);
		AddChild(field);
	} else {
		y -= SEPARATOR_MARGIN;
		r.Set(SEPARATOR_MARGIN, y, x - 12 - 1, y + menuFieldHeight);
		fDateLabel = new BStringView(r, "", kDateLabel);
		fDateLabel->SetAlignment(B_ALIGN_RIGHT);
		AddChild(fDateLabel);
		fDateLabel->SetHighColor(0, 0, 0);

		r.Set(r.right + 9, y, windowRect.Width() - SEPARATOR_MARGIN,
			y + menuFieldHeight);
		fDate = new BStringView(r, "", "");
		AddChild(fDate);
		fDate->SetHighColor(0, 0, 0);

		y += controlHeight + 5;
	}
	ResizeTo(Bounds().Width(), y);
}