Ejemplo n.º 1
0
void
FontSelectionView::SetDefaults()
{
	font_family family;
	font_style style;
	float size;
	const char* fontName;

	if (strcmp(Name(), "menu") == 0)
		fontName = "plain";
	else
		fontName = Name();

	if (_get_system_default_font_(fontName, family, style, &size) != B_OK) {
		Revert();
		return;
	}

	BFont defaultFont;
	defaultFont.SetFamilyAndStyle(family, style);
	defaultFont.SetSize(size);

	if (defaultFont == fCurrentFont)
		return;

	_SelectCurrentFont(false);

	fCurrentFont = defaultFont;
	_UpdateFontPreview();

	_SelectCurrentFont(true);
	_SelectCurrentSize();
}
Ejemplo n.º 2
0
FontSelectionView::FontSelectionView(const char* name, const char* label,
		bool separateStyles, const BFont* currentFont)
	:
	BHandler(name),
	fMessage(NULL),
	fTarget(NULL)
{
	if (currentFont == NULL)
		fCurrentFont = _DefaultFont();
	else
		fCurrentFont = *currentFont;

	fSavedFont = fCurrentFont;

	fSizesMenu = new BPopUpMenu("size menu");
	fFontsMenu = new BPopUpMenu("font menu");

	// font menu
	fFontsMenuField = new BMenuField("fonts", label, fFontsMenu, B_WILL_DRAW);
	fFontsMenuField->SetAlignment(B_ALIGN_RIGHT);

	// styles menu, if desired
	if (separateStyles) {
		fStylesMenu = new BPopUpMenu("styles menu");
		fStylesMenuField = new BMenuField("styles", B_TRANSLATE("Style:"),
			fStylesMenu, B_WILL_DRAW);
	} else {
		fStylesMenu = NULL;
		fStylesMenuField = NULL;
	}

	// size menu
	fSizesMenuField = new BMenuField("size", B_TRANSLATE("Size:"), fSizesMenu,
		B_WILL_DRAW);
	fSizesMenuField->SetAlignment(B_ALIGN_RIGHT);

	// preview
	fPreviewText = new BStringView("preview text",
		B_TRANSLATE_COMMENT("The quick brown fox jumps over the lazy dog.",
		"Don't translate this literally ! Use a phrase showing all "
		"chars from A to Z."));

	fPreviewText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
		B_SIZE_UNLIMITED));
	fPreviewText->SetHighUIColor(B_PANEL_BACKGROUND_COLOR, 1.65);

	fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS);
	fPreviewBox->AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_HALF_ITEM_SPACING)
		.Add(fPreviewText)
		.SetInsets(B_USE_HALF_ITEM_SPACING, B_USE_HALF_ITEM_SPACING,
			B_USE_HALF_ITEM_SPACING, B_USE_HALF_ITEM_SPACING)
		.TopView()
	);
	_UpdateFontPreview();
}
Ejemplo n.º 3
0
void
FontSelectionView::SetFont(const BFont& font)
{
	if (font == fCurrentFont && font == fSavedFont)
		return;

	_SelectCurrentFont(false);
	fSavedFont = fCurrentFont = font;
	_UpdateFontPreview();

	_SelectCurrentFont(true);
	_SelectCurrentSize(true);
}
Ejemplo n.º 4
0
void
FontSelectionView::Revert()
{
	if (!IsRevertable())
		return;

	_SelectCurrentFont(false);

	fCurrentFont = fSavedFont;
	_UpdateFontPreview();

	_SelectCurrentFont(true);
	_SelectCurrentSize(true);
}
Ejemplo n.º 5
0
FontSelectionView::FontSelectionView(const char* name, const char* label,
		bool separateStyles, const BFont* currentFont)
	:
	BHandler(name),
	fMessage(NULL),
	fTarget(NULL)
{
	if (currentFont == NULL)
		fCurrentFont = _DefaultFont();
	else
		fCurrentFont = *currentFont;

	fSavedFont = fCurrentFont;

	fSizesMenu = new BPopUpMenu("size menu");
	fFontsMenu = new BPopUpMenu("font menu");

	// font menu
	fFontsMenuField = new BMenuField("fonts", label, fFontsMenu, B_WILL_DRAW);
	fFontsMenuField->SetFont(be_bold_font);

	// styles menu, if desired
	if (separateStyles) {
		fStylesMenu = new BPopUpMenu("styles menu");
		fStylesMenuField = new BMenuField("styles", B_TRANSLATE("Style:"),
			fStylesMenu, B_WILL_DRAW);
	} else {
		fStylesMenu = NULL;
		fStylesMenuField = NULL;
	}

	// size menu
	fSizesMenuField = new BMenuField("size", B_TRANSLATE("Size:"), fSizesMenu,
		B_WILL_DRAW);
	fSizesMenuField->SetAlignment(B_ALIGN_RIGHT);

	// preview
	fPreviewText = new BStringView("preview text",
		B_TRANSLATE_COMMENT("The quick brown fox jumps over the lazy dog.",
		"Don't translate this literally ! Use a phrase showing all "
		"chars from A to Z."));

	fPreviewText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
		B_SIZE_UNLIMITED));
	fPreviewText->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
		1.65));
	fPreviewText->SetAlignment(B_ALIGN_RIGHT);
	_UpdateFontPreview();
}
Ejemplo n.º 6
0
void
FontSelectionView::SetDefaults()
{
	BFont defaultFont = _DefaultFont();
	if (defaultFont == fCurrentFont)
		return;

	_SelectCurrentFont(false);

	fCurrentFont = defaultFont;
	_UpdateFontPreview();

	_SelectCurrentFont(true);
	_SelectCurrentSize(true);
}
Ejemplo n.º 7
0
void
FontSelectionView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kMsgSetSize:
		{
			int32 size;
			if (message->FindInt32("size", &size) != B_OK
				|| size == fCurrentFont.Size())
				break;

			fCurrentFont.SetSize(size);
			_UpdateFontPreview();
			_Invoke();
			break;
		}

		case kMsgSetFamily:
		{
			const char* family;
			if (message->FindString("family", &family) != B_OK)
				break;

			font_style style;
			fCurrentFont.GetFamilyAndStyle(NULL, &style);

			BMenuItem* familyItem = fFontsMenu->FindItem(family);
			if (familyItem != NULL) {
				_SelectCurrentFont(false);

				BMenuItem* styleItem;
				if (fStylesMenuField != NULL)
					styleItem = fStylesMenuField->Menu()->FindMarked();
				else {
					styleItem = familyItem->Submenu()->FindItem(style);
					if (styleItem == NULL)
						styleItem = familyItem->Submenu()->ItemAt(0);
				}

				if (styleItem != NULL) {
					styleItem->SetMarked(true);
					fCurrentFont.SetFamilyAndStyle(family, styleItem->Label());
					_UpdateFontPreview();
				}
				if (fStylesMenuField != NULL)
					_AddStylesToMenu(fCurrentFont, fStylesMenuField->Menu());
			}

			_Invoke();
			break;
		}

		case kMsgSetStyle:
		{
			const char* family;
			const char* style;
			if (message->FindString("family", &family) != B_OK
				|| message->FindString("style", &style) != B_OK)
				break;

			BMenuItem *familyItem = fFontsMenu->FindItem(family);
			if (!familyItem)
				break;

			_SelectCurrentFont(false);
			familyItem->SetMarked(true);

			fCurrentFont.SetFamilyAndStyle(family, style);
			_UpdateFontPreview();
			_Invoke();
			break;
		}

		default:
			BHandler::MessageReceived(message);
	}
}
Ejemplo n.º 8
0
void
FontSelectionView::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case kMsgSetSize:
		{
			int32 size = fFontSizeSpinner->Value();
			if (size == fCurrentFont.Size())
				break;

			fCurrentFont.SetSize(size);
			_UpdateFontPreview();
			break;
		}

		case kMsgSetFamily:
		{
			const char* family;
			if (msg->FindString("family", &family) != B_OK)
				break;

			font_style style;
			fCurrentFont.GetFamilyAndStyle(NULL, &style);

			BMenuItem* familyItem = fFontsMenu->FindItem(family);
			if (familyItem != NULL) {
				_SelectCurrentFont(false);

				BMenuItem* item = familyItem->Submenu()->FindItem(style);
				if (item == NULL)
					item = familyItem->Submenu()->ItemAt(0);

				if (item != NULL) {
					item->SetMarked(true);
					fCurrentFont.SetFamilyAndStyle(family, item->Label());
					_UpdateFontPreview();
				}
			}
			break;
		}

		case kMsgSetStyle:
		{
			const char* family;
			const char* style;
			if (msg->FindString("family", &family) != B_OK
				|| msg->FindString("style", &style) != B_OK)
				break;

			BMenuItem *familyItem = fFontsMenu->FindItem(family);
			if (!familyItem)
				break;

			_SelectCurrentFont(false);
			familyItem->SetMarked(true);

			fCurrentFont.SetFamilyAndStyle(family, style);
			_UpdateFontPreview();
			break;
		}

		default:
			BView::MessageReceived(msg);
	}
}