Пример #1
0
ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry)
	: BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position),
		"Application Type", B_TITLED_WINDOW,
		B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
	fChangedProperties(0)
{
	// add the menu

	BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
	AddChild(menuBar);

	BMenu* menu = new BMenu("File");
	fSaveMenuItem = new BMenuItem("Save", new BMessage(kMsgSave), 'S');
	fSaveMenuItem->SetEnabled(false);
	menu->AddItem(fSaveMenuItem);
	BMenuItem* item;
	menu->AddItem(item = new BMenuItem("Save into resource file" B_UTF8_ELLIPSIS,
		NULL));
	item->SetEnabled(false);

	menu->AddSeparatorItem();
	menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED),
		'W', B_COMMAND_KEY));
	menuBar->AddItem(menu);

	// Top view and signature

	BRect rect = Bounds();
	rect.top = menuBar->Bounds().Height() + 1.0f;
	BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(topView);

	rect = topView->Bounds().InsetByCopy(8.0f, 8.0f);
	fSignatureControl = new BTextControl(rect, "signature", "Signature:", NULL,
		new BMessage(kMsgSignatureChanged), B_FOLLOW_LEFT_RIGHT);
	fSignatureControl->SetModificationMessage(
		new BMessage(kMsgSignatureChanged));
	fSignatureControl->SetDivider(fSignatureControl->StringWidth(
		fSignatureControl->Label()) + 4.0f);
	float width, height;
	fSignatureControl->GetPreferredSize(&width, &height);
	fSignatureControl->ResizeTo(rect.Width(), height);
	topView->AddChild(fSignatureControl);

	// filter out invalid characters that can't be part of a MIME type name
	BTextView* textView = fSignatureControl->TextView();
	textView->SetMaxBytes(B_MIME_TYPE_LENGTH);
	const char* disallowedCharacters = "<>@,;:\"()[]?=";
	for (int32 i = 0; disallowedCharacters[i]; i++) {
		textView->DisallowChar(disallowedCharacters[i]);
	}

	// "Application Flags" group

	BFont font(be_bold_font);
	font_height fontHeight;
	font.GetHeight(&fontHeight);

	width = font.StringWidth("Icon") + 16.0f;
	if (width < B_LARGE_ICON + 16.0f)
		width = B_LARGE_ICON + 16.0f;

	rect.top = fSignatureControl->Frame().bottom + 4.0f;
	rect.bottom = rect.top + 100.0f;
	rect.right -= width + 8.0f;
	BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
	topView->AddChild(box);

	fFlagsCheckBox = new BCheckBox(rect, "flags", "Application flags",
		new BMessage(kMsgToggleAppFlags));
	fFlagsCheckBox->SetValue(B_CONTROL_ON);
	fFlagsCheckBox->ResizeToPreferred();
	box->SetLabel(fFlagsCheckBox);

	rect.top = fFlagsCheckBox->Bounds().Height() + 4.0f;
	fSingleLaunchButton = new BRadioButton(rect, "single", "Single launch",
		new BMessage(kMsgAppFlagsChanged));
	fSingleLaunchButton->ResizeToPreferred();
	box->AddChild(fSingleLaunchButton);

	rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f);
	fMultipleLaunchButton = new BRadioButton(rect, "multiple",
		"Multiple launch", new BMessage(kMsgAppFlagsChanged));
	fMultipleLaunchButton->ResizeToPreferred();
	box->AddChild(fMultipleLaunchButton);

	rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f);
	fExclusiveLaunchButton = new BRadioButton(rect, "exclusive",
		"Exclusive launch", new BMessage(kMsgAppFlagsChanged));
	fExclusiveLaunchButton->ResizeToPreferred();
	box->AddChild(fExclusiveLaunchButton);

	rect.top = fSingleLaunchButton->Frame().top;
	rect.left = fExclusiveLaunchButton->Frame().right + 4.0f;
	fArgsOnlyCheckBox = new BCheckBox(rect, "args only", "Args only",
		new BMessage(kMsgAppFlagsChanged));
	fArgsOnlyCheckBox->ResizeToPreferred();
	box->AddChild(fArgsOnlyCheckBox);

	rect.top += fArgsOnlyCheckBox->Bounds().Height();
	fBackgroundAppCheckBox = new BCheckBox(rect, "background",
		"Background app", new BMessage(kMsgAppFlagsChanged));
	fBackgroundAppCheckBox->ResizeToPreferred();
	box->AddChild(fBackgroundAppCheckBox);

	box->ResizeTo(box->Bounds().Width(),
		fExclusiveLaunchButton->Frame().bottom + 8.0f);

	// "Icon" group

	rect = box->Frame();
#ifdef __ANTARES__
	rect.top += box->TopBorderOffset();
#endif
	rect.left = rect.right + 8.0f;
	rect.right += width + 8.0f;
	float iconBoxWidth = rect.Width();
	box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	box->SetLabel("Icon");
#ifdef __ANTARES__
	box->MoveBy(0.0f, -box->TopBorderOffset());
	box->ResizeBy(0.0f, box->TopBorderOffset());
#endif
	topView->AddChild(box);

	rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f);
#ifdef __ANTARES__
	rect.OffsetBy(0.0f, (box->Bounds().Height() + box->TopBorderOffset()
		- rect.Height()) / 2.0f);
#else
	rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f);
#endif
	if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f)
		rect.top = fontHeight.ascent + fontHeight.descent + 4.0f;
	fIconView = new IconView(rect, "icon");
	fIconView->SetModificationMessage(new BMessage(kMsgIconChanged));
	box->AddChild(fIconView);

	// "Supported Types" group

	rect.top = box->Frame().bottom + 8.0f;
	rect.bottom = rect.top + box->Bounds().Height();
	rect.left = 8.0f;
	rect.right = Bounds().Width() - 8.0f;
	BBox* typeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
	typeBox->SetLabel("Supported types");
	topView->AddChild(typeBox);

	rect = typeBox->Bounds().InsetByCopy(8.0f, 6.0f);
	rect.top += ceilf(fontHeight.ascent);
	fAddTypeButton = new BButton(rect, "add type", "Add" B_UTF8_ELLIPSIS,
		new BMessage(kMsgAddType), B_FOLLOW_RIGHT);
	fAddTypeButton->ResizeToPreferred();
	fAddTypeButton->MoveBy(rect.right - fAddTypeButton->Bounds().Width()
		- B_LARGE_ICON - 16.0f, 0.0f);
	typeBox->AddChild(fAddTypeButton);

	rect = fAddTypeButton->Frame();
	rect.OffsetBy(0, rect.Height() + 4.0f);
	fRemoveTypeButton = new BButton(rect, "remove type", "Remove",
		new BMessage(kMsgRemoveType), B_FOLLOW_RIGHT);
	typeBox->AddChild(fRemoveTypeButton);

	rect.right = rect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
	rect.left = 10.0f;
	rect.top = 8.0f + ceilf(fontHeight.ascent);
	rect.bottom -= 2.0f;
		// take scrollview border into account
	fTypeListView = new SupportedTypeListView(rect, "type listview",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL);
	fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));

	BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView,
		B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true);

	typeBox->ResizeTo(typeBox->Bounds().Width(), fRemoveTypeButton->Frame().bottom + 8.0f);
	typeBox->AddChild(scrollView);

	rect.left = fRemoveTypeButton->Frame().right + 8.0f;
#ifdef __ANTARES__
	rect.top = (box->Bounds().Height() + box->TopBorderOffset() - B_LARGE_ICON) / 2.0f;
#else
	rect.top = (box->Bounds().Height() - B_LARGE_ICON) / 2.0f;
#endif
	rect.right = rect.left + B_LARGE_ICON - 1.0f;
	rect.bottom = rect.top + B_LARGE_ICON - 1.0f;
	fTypeIconView = new IconView(rect, "type icon", B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged));
	typeBox->AddChild(fTypeIconView);

	// "Version Info" group

	rect.top = typeBox->Frame().bottom + 8.0f;
	rect.bottom = rect.top + typeBox->Bounds().Height();
	rect.left = 8.0f;
	rect.right = Bounds().Width() - 8.0f;
	box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
		// the resizing mode will later also be set to B_FOLLOW_BOTTOM
	box->SetLabel("Version info");
	topView->AddChild(box);

	BMenuField* menuField;
#if 0
	BPopUpMenu *popUpMenu = new BPopUpMenu("version info", true, true);
	item = new BMenuItem("Version Info", NULL);
	item->SetMarked(true);
	popUpMenu->AddItem(item);
	item = new BMenuItem("System Version Info", NULL);
	popUpMenu->AddItem(item);

	menuField = new BMenuField(BRect(0, 0, 100, 15),
		"version kind", NULL, popUpMenu, true);
	menuField->ResizeToPreferred();
	box->SetLabel(menuField);
#endif

	rect.top = 4.0f + ceilf(fontHeight.ascent + fontHeight.descent);
	rect.bottom = rect.top + height;
	fMajorVersionControl = new BTextControl(rect, "major", "Version:", NULL,
		NULL);
	fMajorVersionControl->SetDivider(fMajorVersionControl->StringWidth(
		fMajorVersionControl->Label()) + 4.0f);
	fMajorVersionControl->GetPreferredSize(&width, &height);
	width = 12.0f + fMajorVersionControl->StringWidth("99");
	fMajorVersionControl->ResizeTo(fMajorVersionControl->Divider() + width, height);
	_MakeNumberTextControl(fMajorVersionControl);
	box->AddChild(fMajorVersionControl);

	rect.left = fMajorVersionControl->Frame().right + 1.0f;
	fMiddleVersionControl = new BTextControl(rect, "middle", ".", NULL,
		NULL);
	fMiddleVersionControl->SetDivider(fMiddleVersionControl->StringWidth(
		fMiddleVersionControl->Label()) + 4.0f);
	fMiddleVersionControl->ResizeTo(fMiddleVersionControl->Divider() + width, height);
	_MakeNumberTextControl(fMiddleVersionControl);
	box->AddChild(fMiddleVersionControl);

	rect.left = fMiddleVersionControl->Frame().right + 1.0f;
	fMinorVersionControl = new BTextControl(rect, "middle", ".", NULL,
		NULL);
	fMinorVersionControl->SetDivider(fMinorVersionControl->StringWidth(
		fMinorVersionControl->Label()) + 4.0f);
	fMinorVersionControl->ResizeTo(fMinorVersionControl->Divider() + width, height);
	_MakeNumberTextControl(fMinorVersionControl);
	box->AddChild(fMinorVersionControl);

	fVarietyMenu = new BPopUpMenu("variety", true, true);
	fVarietyMenu->AddItem(new BMenuItem("Development", NULL));
	fVarietyMenu->AddItem(new BMenuItem("Alpha", NULL));
	fVarietyMenu->AddItem(new BMenuItem("Beta", NULL));
	fVarietyMenu->AddItem(new BMenuItem("Gamma", NULL));
	fVarietyMenu->AddItem(item = new BMenuItem("Golden master", NULL));
	item->SetMarked(true);
	fVarietyMenu->AddItem(new BMenuItem("Final", NULL));

	rect.top--;
		// BMenuField oddity
	rect.left = fMinorVersionControl->Frame().right + 6.0f;
	menuField = new BMenuField(rect,
		"variety", NULL, fVarietyMenu, true);
	menuField->ResizeToPreferred();
	box->AddChild(menuField);

	rect.top++;
	rect.left = menuField->Frame().right;
	rect.right = rect.left + 30.0f;	
	fInternalVersionControl = new BTextControl(rect, "internal", "/", NULL,
		NULL);
	fInternalVersionControl->SetDivider(fInternalVersionControl->StringWidth(
		fInternalVersionControl->Label()) + 4.0f);
	fInternalVersionControl->ResizeTo(fInternalVersionControl->Divider() + width, height);
	box->AddChild(fInternalVersionControl);

	rect = box->Bounds().InsetByCopy(8.0f, 0.0f);
	rect.top = fInternalVersionControl->Frame().bottom + 8.0f;
	fShortDescriptionControl = new BTextControl(rect, "short desc", "Short description:",
		NULL, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	float labelWidth = fShortDescriptionControl->StringWidth(
		fShortDescriptionControl->Label()) + 4.0f;
	fShortDescriptionControl->SetDivider(labelWidth);
	fShortDescriptionControl->GetPreferredSize(&width, &height);
	fShortDescriptionControl->ResizeTo(rect.Width(), height);

	// TODO: workaround for a GCC 4.1.0 bug? Or is that really what the standard says?
	version_info versionInfo;
	fShortDescriptionControl->TextView()->SetMaxBytes(sizeof(versionInfo.short_info));
	box->AddChild(fShortDescriptionControl);

	rect.OffsetBy(0.0f, fShortDescriptionControl->Bounds().Height() + 5.0f);
	rect.right = rect.left + labelWidth;
	StringView* label = new StringView(rect, NULL, "Long description:", NULL);
	label->SetDivider(labelWidth);
	box->AddChild(label);

	rect.left = rect.right + 3.0f;
	rect.top += 1.0f;
	rect.right = box->Bounds().Width() - 10.0f - B_V_SCROLL_BAR_WIDTH;
	rect.bottom = rect.top + fShortDescriptionControl->Bounds().Height() * 3.0f - 1.0f;
	fLongDescriptionView = new TabFilteringTextView(rect, "long desc",
		rect.OffsetToCopy(B_ORIGIN), B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS
		| B_NAVIGABLE);
	fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info));

	scrollView = new BScrollView("desc scrollview", fLongDescriptionView,
		B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
	box->ResizeTo(box->Bounds().Width(), scrollView->Frame().bottom + 8.0f);
	box->AddChild(scrollView);

	// Adjust window size and limits

	width = fInternalVersionControl->Frame().right + 16.0f;
	float minWidth = fBackgroundAppCheckBox->Frame().right + iconBoxWidth + 32.0f;
	if (width > minWidth)
		minWidth = width;

	ResizeTo(Bounds().Width() > minWidth ? Bounds().Width() : minWidth,
		box->Frame().bottom + topView->Frame().top + 8.0f);
	SetSizeLimits(minWidth, 32767.0f, Bounds().Height(), 32767.0f);
	typeBox->SetResizingMode(B_FOLLOW_ALL);
	box->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);

	fSignatureControl->MakeFocus(true);

	BMimeType::StartWatching(this);
	_SetTo(entry);
}
Пример #2
0
void
KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
	BRect rect, bool pressed)
{
	rgb_color base = key->dark ? kDarkColor : kBrightColor;
	rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
	key_kind keyKind = kNormalKey;
	int32 deadKey = 0;
	bool secondDeadKey = false;
	bool isDeadKeyEnabled = true;

	char text[32];
	if (fKeymap != NULL) {
		_GetKeyLabel(key, text, sizeof(text), keyKind);
		deadKey = fKeymap->DeadKey(key->code, fModifiers, &isDeadKeyEnabled);
		secondDeadKey = fKeymap->IsDeadSecondKey(key->code, fModifiers,
			fDeadKey);
	} else {
		// Show the key code if there is no keymap
		snprintf(text, sizeof(text), "%02" B_PRIx32, key->code);
	}

	_SetFontSize(view, keyKind);

	if (secondDeadKey)
		base = kSecondDeadKeyColor;
	else if (deadKey > 0 && isDeadKeyEnabled)
		base = kDeadKeyColor;

	if (key->shape == kRectangleKeyShape) {
		_DrawKeyButton(view, rect, updateRect, base, background, pressed);

		rect.InsetBy(1, 1);

		_GetAbbreviatedKeyLabelIfNeeded(view, rect, key, text, sizeof(text));
		be_control_look->DrawLabel(view, text, rect, updateRect,
			base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
	} else if (key->shape == kEnterKeyShape) {
		BRect topLeft = rect;
		BRect topRight = rect;
		BRect bottomLeft = rect;
		BRect bottomRight = rect;

		// TODO: for some reason, this does not always equal the bottom of
		// the other keys...
		bottomLeft.top = floorf(rect.top
			+ fLayout->DefaultKeySize().height * fFactor - fGap - 1);
		bottomLeft.right = floorf(rect.left
			+ (key->frame.Width() - key->second_row) * fFactor - fGap - 2);

		topLeft.bottom = bottomLeft.top;
		topLeft.right = bottomLeft.right + 1;
			// add one to make the borders meet

		topRight.bottom = topLeft.bottom;
		topRight.left = topLeft.right;

		bottomRight.top = bottomLeft.top;
		bottomRight.left = bottomLeft.right;

		// draw top left corner
		be_control_look->DrawButtonFrame(view, topLeft, updateRect,
			4.0f, 0.0f, 4.0f, 0.0f, base, background,
			pressed ? BControlLook::B_ACTIVATED : 0,
			BControlLook::B_LEFT_BORDER | BControlLook::B_TOP_BORDER
				| BControlLook::B_BOTTOM_BORDER);
		be_control_look->DrawButtonBackground(view, topLeft, updateRect,
			4.0f, 0.0f, 4.0f, 0.0f, base,
			pressed ? BControlLook::B_ACTIVATED : 0,
			BControlLook::B_LEFT_BORDER | BControlLook::B_TOP_BORDER
				| BControlLook::B_BOTTOM_BORDER);

		// draw top right corner
		be_control_look->DrawButtonFrame(view, topRight, updateRect,
			0.0f, 4.0f, 0.0f, 0.0f, base, background,
			pressed ? BControlLook::B_ACTIVATED : 0,
			BControlLook::B_TOP_BORDER | BControlLook::B_RIGHT_BORDER);
		be_control_look->DrawButtonBackground(view, topRight, updateRect,
			0.0f, 4.0f, 0.0f, 0.0f, base,
			pressed ? BControlLook::B_ACTIVATED : 0,
			BControlLook::B_TOP_BORDER | BControlLook::B_RIGHT_BORDER);

		// draw bottom right corner
		be_control_look->DrawButtonFrame(view, bottomRight, updateRect,
			0.0f, 0.0f, 4.0f, 4.0f, base, background,
			pressed ? BControlLook::B_ACTIVATED : 0,
			BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER
				 | BControlLook::B_BOTTOM_BORDER);
		be_control_look->DrawButtonBackground(view, bottomRight, updateRect,
			0.0f, 0.0f, 4.0f, 4.0f, base,
			pressed ? BControlLook::B_ACTIVATED : 0,
			BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER
				 | BControlLook::B_BOTTOM_BORDER);

		// clip out the bottom left corner
		bottomLeft.right += 1;
		bottomLeft.top -= 2;
		BRegion region(rect);
		region.Exclude(bottomLeft);
		view->ConstrainClippingRegion(&region);

		// Fill in the rect with the background color
		SetHighColor(background);
		FillRect(rect);

		// draw the button background
		BRect bgRect = rect.InsetByCopy(2, 2);
		be_control_look->DrawButtonBackground(view, bgRect, updateRect,
			4.0f, 4.0f, 0.0f, 4.0f, base,
			pressed ? BControlLook::B_ACTIVATED : 0);

		rect.left = bottomLeft.right;
		_GetAbbreviatedKeyLabelIfNeeded(view, rect, key, text, sizeof(text));

		// draw the button label
		be_control_look->DrawLabel(view, text, rect, updateRect,
			base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));

		// reset the clipping region
		view->ConstrainClippingRegion(NULL);
	}
}
Пример #3
0
// StartConfig
void
IFSSaver::StartConfig(BView *view)
{
	BRect bounds = view->Bounds();
	bounds.InsetBy(10.0, 10.0);
	BRect frame(0.0, 0.0, bounds.Width(), 20.0);

	// the additive check box
	fAdditiveCB = new BCheckBox(frame, "additive setting",
								B_TRANSLATE("Render dots additive"),
								new BMessage(MSG_TOGGLE_ADDITIVE),
								B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);

	fAdditiveCB->SetValue(fAdditive);

	fAdditiveCB->ResizeToPreferred();
	bounds.bottom -= fAdditiveCB->Bounds().Height() * 2.0;
	fAdditiveCB->MoveTo(bounds.LeftBottom());

	view->AddChild(fAdditiveCB);

	// the additive check box
	fSpeedS = new BSlider(frame, "speed setting",
						  B_TRANSLATE("Morphing speed:"),
						  new BMessage(MSG_SET_SPEED),
						  1, 12, B_BLOCK_THUMB,
						  B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);

	fSpeedS->SetValue(fSpeed);
	fSpeedS->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fSpeedS->SetHashMarkCount(12);

	fSpeedS->ResizeToPreferred();
	bounds.bottom -= fSpeedS->Bounds().Height() + 15.0;
	fSpeedS->MoveTo(bounds.LeftBottom());

	view->AddChild(fSpeedS);

	// the info text view
	BRect textRect = bounds;
	textRect.OffsetTo(0.0, 0.0);
	BTextView* textView = new BTextView(bounds, B_EMPTY_STRING, textRect,
										B_FOLLOW_ALL, B_WILL_DRAW);
	textView->SetViewColor(view->ViewColor());
	textView->Insert(B_TRANSLATE("Iterated Function System\n\n"
					 ""B_UTF8_COPYRIGHT" 1997 Massimino Pascal\n\n"
					 "xscreensaver port by Stephan Aßmus\n"
					 "<[email protected]>"));


	textView->SetStylable(true);
	textView->SetFontAndColor(0, 24, be_bold_font);
//	textView->SetFontAndColor(25, 255, be_plain_font);

	textView->MakeEditable(false);

	view->AddChild(textView);

	// make sure we receive messages from the views we added
	if (BWindow* window = view->Window())
		window->AddHandler(this);

	fAdditiveCB->SetTarget(this);
	fSpeedS->SetTarget(this);
}
Пример #4
0
void
SLoadingModulesView::ReGetBitmap()
{
	BWindow *window = Window();
	if(!window) return;

	bool is_hidden = window->IsHidden();

	if(!is_hidden) window->Hide();

	BScreen screen(window);
	BBitmap *screen_bitmap = NULL;
	BRect rect = screen.Frame().OffsetToCopy(B_ORIGIN);
	if(screen.GetBitmap(&screen_bitmap, false, &rect) == B_OK)
	{
		if(screen_bitmap)
		{
			if(bitmap) delete bitmap;
			rect = ConvertToScreen(Bounds());
			bitmap = new BBitmap(rect.OffsetToCopy(B_ORIGIN), B_BITMAP_ACCEPTS_VIEWS, B_RGB32);
			if(bitmap)
			{
				SAutolock<BBitmap> autolock(bitmap);
				BView *bitmap_view = new BView(bitmap->Bounds(), NULL, B_FOLLOW_NONE, B_WILL_DRAW);
				bitmap->AddChild(bitmap_view);
				bitmap_view->PushState();
				bitmap_view->SetDrawingMode(B_OP_COPY);
				bitmap_view->DrawBitmap(screen_bitmap, rect, rect.OffsetToCopy(B_ORIGIN));
				bitmap_view->SetDrawingMode(B_OP_ALPHA);

				BPoint circle_center;
				float circle_radius = bitmap->Bounds().Height() / 2;
				circle_center.x = bitmap->Bounds().left + circle_radius;
				circle_center.y = bitmap->Bounds().top + circle_radius;
				
				bitmap_view->SetHighColor(ViewColor());
				bitmap_view->FillArc(circle_center, circle_radius, circle_radius, 0, 360);
				bitmap_view->SetHighColor(220, 220, 220, 150);
				bitmap_view->StrokeArc(circle_center, circle_radius, circle_radius, 45, 180);
				bitmap_view->SetHighColor(20, 20, 20, 150);
				bitmap_view->StrokeArc(circle_center, circle_radius, circle_radius, 225, 180);

				BRect rect = bitmap->Bounds();
				rect.left = circle_center.x;
				rect.InsetBy(0, 5);

				bitmap_view->SetHighColor(ViewColor());
				bitmap_view->FillRoundRect(rect, 3, 3);
				bitmap_view->SetHighColor(220, 220, 220, 150);
				bitmap_view->StrokeRoundRect(rect, 3, 3);
				bitmap_view->SetHighColor(20, 20, 20, 150);
				rect.left += 1; rect.top += 1;
				bitmap_view->StrokeRoundRect(rect, 3, 3);
				rect.right -= 1; rect.bottom -= 1;
				bitmap_view->SetHighColor(ViewColor());
				bitmap_view->FillArc(circle_center, circle_radius - 1, circle_radius - 1, 0, 360);
				bitmap_view->FillRoundRect(rect, 3, 3);

				bitmap_view->PopState();
				bitmap_view->Sync();
			}
			delete screen_bitmap;
		}
	}

	if(!is_hidden) window->Show();
}
Пример #5
0
void
Model::TrackIconSource(icon_size size)
{
	PRINT(("tracking %s icon\n", size == B_LARGE_ICON ? "large" : "small"));
	BRect rect;
	if (size == B_MINI_ICON)
		rect.Set(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1);
	else
		rect.Set(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);

	BBitmap bitmap(rect, B_CMAP8);

	BModelOpener opener(this);

	if (Node() == NULL) {
		PRINT(("track icon error - no node\n"));
		return;
	}

	if (IsSymLink()) {
		PRINT(("tracking symlink icon\n"));
		if (fLinkTo) {
			fLinkTo->TrackIconSource(size);
			return;
		}
	}

	if (fBaseType == kVolumeNode) {
		BVolume volume(NodeRef()->device);
		status_t result = volume.GetIcon(&bitmap, size);
		PRINT(("getting icon from volume %s\n", strerror(result)));
	} else {
		BNodeInfo nodeInfo(Node());

		status_t err = nodeInfo.GetIcon(&bitmap, size);
		if (err == B_OK) {
			// file knew which icon to use, we are done
			PRINT(("track icon - got icon from file\n"));
			return;
		}

		char preferredApp[B_MIME_TYPE_LENGTH];
		err = nodeInfo.GetPreferredApp(preferredApp);
		if (err == B_OK && preferredApp[0]) {
			BMimeType preferredAppType(preferredApp);
			err = preferredAppType.GetIconForType(MimeType(), &bitmap, size);
			if (err == B_OK) {
				PRINT(("track icon - got icon for type %s from preferred app %s for file\n",
					MimeType(), preferredApp));
				return;
			}
		}

		BMimeType mimeType(MimeType());
		err = mimeType.GetIcon(&bitmap, size);
		if (err == B_OK) {
			// the system knew what icon to use for the type, we are done
			PRINT(("track icon - signature %s, got icon from system\n",
				MimeType()));
			return;
		}

		err = mimeType.GetPreferredApp(preferredApp);
		if (err != B_OK) {
			// no preferred App for document, give up
			PRINT(("track icon - signature %s, no prefered app, error %s\n",
				MimeType(), strerror(err)));
			return;
		}

		BMimeType preferredAppType(preferredApp);
		err = preferredAppType.GetIconForType(MimeType(), &bitmap, size);
		if (err == B_OK) {
			// the preferred app knew icon to use for the type, we are done
			PRINT(("track icon - signature %s, got icon from preferred app %s\n",
				MimeType(), preferredApp));
			return;
		}
		PRINT(("track icon - signature %s, preferred app %s, no icon, error %s\n",
			MimeType(), preferredApp, strerror(err)));
	}
}
Пример #6
0
// c'tor
TempoView::TempoView(SeqGlobal& seqGlobal, BRect frame) :
		m_seqGlobal(seqGlobal),
		BView(frame, "tempo-view", B_FOLLOW_TOP|B_FOLLOW_LEFT,
					B_WILL_DRAW) {
					
	// create sliders
	BRect sliderRect = Bounds();
	sliderRect.bottom = 40;
	// (leave room for the border)
	sliderRect.InsetBy(2,2);

	//---------------------------------------//	
	// coarse-tempo slider:
	// measured in 10ths
	//---------------------------------------//	

	m_pCoarseSlider = new TempoSlider(sliderRect,
		"coarse-bpm-slider", NULL,
		new BMessage(TEMPO_SET_BPM),
		10, 3000); // min & max values (x10)
		
	// set to init value
	int32 nBPMT = m_seqGlobal.getTempo(); // returns in 1000ths of a BPM
	m_pCoarseSlider->SetValue(nBPMT/100); 
	
	// set min/max labels
	m_pCoarseSlider->SetLimitLabels("1.0", "300.0");
	
	// set hash marks
	m_pCoarseSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	m_pCoarseSlider->SetHashMarkCount(10);
	
	// add
	AddChild(m_pCoarseSlider);
#if 0
	//---------------------------------------//	
	// fine-tempo slider (+/- 1 BPM)
	// measured in 1000ths
	//---------------------------------------//	

	sliderRect.OffsetBy(0, 40);
	m_pFineSlider = new TempoSlider(sliderRect,
		"fine-bpm-slider", NULL,
		new BMessage(TEMPO_SET_BPM_FINE),
		-1000, 1000); // min & max in BPM/1000

	// set to init (center) value
	m_pFineSlider->SetValue(0);

	// set labels
	updateFineSliderLabels(nBPMT);
	
	// set hash marks
	m_pFineSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	m_pFineSlider->SetHashMarkCount(3);
	
	m_pFineSlider->SetSnoozeAmount(10000);
	
	// add
	AddChild(m_pFineSlider);
#endif /* 0 */
	// prepare for drawing; set color:
	rgb_color bgGray = {219,219,219,255};
	SetViewColor(bgGray);
}
void BeAccessibleWindow::OpenDatabase(BPath path)
{
	//If a database is already open, close it before opening a new one.
	if (GlobalSQLMgr->IsOpen())
		CloseDatabase();
	
	//Open the given database
	bool databaseOpened = GlobalSQLMgr->Open(path.Path());
	
	if (databaseOpened)
	{
		//Add database to list of recently opened files
		BeAccessibleApp* myApp = static_cast<BeAccessibleApp*>(be_app);
		myApp->AddToRecentFiles(new BString(path.Path()));
		
		//Create the beaccessible_master table if it's not there
		if (!GlobalSQLMgr->TableExists("beaccessible_master"))
		{
			BString sql = "create table beaccessible_master (name Text, type Text, "
			              "value Text, primary key (name, type));";
			GlobalSQLMgr->Execute(sql.String());
		}
	}

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

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

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

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

	BView* tabs[1];
	tabs[0] = (BView*)fTableTab;
	fTabView->AddViews(tabs);
	fMainView->AddChild(fTabView);
	
	//Select the first table as default
	fTableTab->fListView->Select(0);	
	
	//Enable certain menu items since there is now a database open
	EnableMenuItems();
	Unlock();
	
	// Save the database's full path to a string
	fPath->SetTo(path.Path());
}
Пример #8
0
void
ConfigWindow::MessageReceived(BMessage *msg)
{
	float fontFactor = be_plain_font->Size() / 12.0f;
	BRect autoConfigRect(0, 0, 400 * fontFactor, 300 * fontFactor);
	BRect frame;

	AutoConfigWindow *autoConfigWindow = NULL;
	switch (msg->what) {
		case B_COLORS_UPDATED:
		{
			rgb_color textColor;
			if (msg->FindColor(ui_color_name(B_PANEL_TEXT_COLOR), &textColor)
					== B_OK) {
				BFont font;
				fHowToTextView->SetFontAndColor(&font, 0, &textColor);
			}
			break;
		}

		case kMsgAccountsRightClicked:
		{
			BPoint point;
			msg->FindPoint("point", &point);
			int32 index = msg->FindInt32("index");
			AccountItem* clickedItem = dynamic_cast<AccountItem*>(
				fAccountsListView->ItemAt(index));
			if (clickedItem == NULL || clickedItem->Type() != ACCOUNT_ITEM)
				break;

			BPopUpMenu rightClickMenu("accounts", false, false);

			BMenuItem* inMenuItem = new BMenuItem(B_TRANSLATE("Incoming"),
				NULL);
			BMenuItem* outMenuItem = new BMenuItem(B_TRANSLATE("Outgoing"),
				NULL);
			rightClickMenu.AddItem(inMenuItem);
			rightClickMenu.AddItem(outMenuItem);

			BMailAccountSettings* settings = clickedItem->Account();
			if (settings->IsInboundEnabled())
				inMenuItem->SetMarked(true);
			if (settings->IsOutboundEnabled())
				outMenuItem->SetMarked(true);

			BMenuItem* selectedItem = rightClickMenu.Go(point);
			if (selectedItem == NULL)
				break;
			if (selectedItem == inMenuItem) {
				AccountItem* item = dynamic_cast<AccountItem*>(
					fAccountsListView->ItemAt(index + 1));
				if (item == NULL)
					break;
				if (settings->IsInboundEnabled()) {
					settings->SetInboundEnabled(false);
					item->SetEnabled(false);
				} else {
					settings->SetInboundEnabled(true);
					item->SetEnabled(true);
				}
			} else {
				AccountItem* item = dynamic_cast<AccountItem*>(
					fAccountsListView->ItemAt(index + 2));
				if (item == NULL)
					break;
				if (settings->IsOutboundEnabled()) {
					settings->SetOutboundEnabled(false);
					item->SetEnabled(false);
				} else {
					settings->SetOutboundEnabled(true);
					item->SetEnabled(true);
				}
			}
		}

		case kMsgAccountSelected:
		{
			int32 index;
			if (msg->FindInt32("index", &index) != B_OK || index < 0) {
				// deselect current item
				_ReplaceConfigView(_BuildHowToView());
				break;
			}
			AccountItem* item = (AccountItem*)fAccountsListView->ItemAt(index);
			if (item != NULL)
				_AccountSelected(item);
			break;
		}

		case kMsgAddAccount:
		{
			frame = Frame();
			autoConfigRect.OffsetTo(
				frame.left + (frame.Width() - autoConfigRect.Width()) / 2,
				frame.top + (frame.Width() - autoConfigRect.Height()) / 2);
			autoConfigWindow = new AutoConfigWindow(autoConfigRect, this);
			autoConfigWindow->Show();
			break;
		}

		case kMsgRemoveAccount:
		{
			int32 index = fAccountsListView->CurrentSelection();
			if (index >= 0) {
				AccountItem *item = (AccountItem *)fAccountsListView->ItemAt(
					index);
				if (item != NULL) {
					_RemoveAccount(item->Account());
					_ReplaceConfigView(_BuildHowToView());
				}
			}
			break;
		}

		case kMsgIntervalUnitChanged:
		{
			int32 index;
			if (msg->FindInt32("index",&index) == B_OK)
				fIntervalControl->SetEnabled(index != 0);
			break;
		}

		case kMsgShowStatusWindowChanged:
		{
			// the status window stuff is the only "live" setting
			BMessenger messenger("application/x-vnd.Be-POST");
			if (messenger.IsValid())
				messenger.SendMessage(msg);
			break;
		}

		case kMsgRevertSettings:
			_RevertToLastSettings();
			break;

		case kMsgSaveSettings:
			fSaveSettings = true;
			_SaveSettings();
			AccountUpdated(fLastSelectedAccount);
			_ReplaceConfigView(_BuildHowToView());
			fAccountsListView->DeselectAll();
			break;

		default:
			BWindow::MessageReceived(msg);
			break;
	}
}
Пример #9
0
void MonthWindowView::DrawMonth()
{
 Bmp->Lock();
 
 float y=yearStringView->Frame().bottom+h_cell;
 float x=0;
 
 if(NewMonth)
 {
  BmpView->SetHighColor(VIEW_COLOR);
  BmpView->FillRect(BRect(0,y+1,
                    BmpView->Bounds().right,todayStringView->Frame().top-6));
  BmpView->SetHighColor(0,0,0,0);
  NewMonth=false;
 }
 
 int byear=cyear; // base year
 if(tyear<byear) byear=tyear;
  
 int day1=0, m=0, k=byear;
 
 while(k<cyear)
 {
  day1++;

  if(k%4==0) // leap year?
   if((k%100!=0) || (k%400==0)) day1++; // yes
  
  k++;
 }
 while(++m<cmonth)
 {
  day1+=(monthDays[m-1]-28);
  if(m==2) if((cyear%4)==0) if((cyear%100!=0) || (cyear%400==0)) day1++;
 }
 day1++; // day1 is number of 1st day of chosen month in chosen year
 day1=day1%7;
 
 int day2=0;
 m=0;
 k=byear;
 while(k<tyear)
 {
  day2++;
  if((k%4)==0) if((k%100!=0) || (k%400==0)) day2++;
  k++;
 }
 while(++m<tmonth)
 {
  day2+=(monthDays[m-1]-28);
  if(m==2) if((tyear%4)==0) if((tyear%100!=0) || (tyear%400==0)) day2++;
 }
 day2+=tday; // day2 - number of today's day in today's year
 day2=day2%7;
 
 k=(twday==0) ? 6 : twday-1;
 
 k=k-day2+day1;
 while(k<0) k+=7;
 k=k%7;
 cwday1=k;
 
 x=w_cell*k+1;
 y+=h_cell;
 
 int qu_days=monthDays[cmonth-1]; // quantity of days in month
 
 if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
 
 BString s;
 int t=0;
 while(t<qu_days)
 {
  t++;
  
  s<<t;
  
  if(cyear==tyear) if(cmonth==tmonth) if(t==tday) BmpView->SetHighColor(200,0,0,0);
  BmpView->DrawString(s.String(),BPoint(x+(w_cell-StringWidth(s.String()))/2,y));
  if(cyear==tyear) if(cmonth==tmonth) if(t==tday) BmpView->SetHighColor(0,0,0,0);
  
  if(t==cday)
  {
   cwday=k;
   if(which_focused==2) BmpView->SetHighColor(ACTIVE_COLOR);
   else BmpView->SetHighColor(NOACTIVE_COLOR);
   cursor.Set(x,y-h_cell+5,x+w_cell-1,y+4);
   BmpView->StrokeRect(cursor);
   BmpView->SetHighColor(0,0,0,0);
  }
  
  x+=w_cell;
  k++;
  s.SetTo("");
  
  if(k==7)
  {
   k=0;
   y+=h_cell;
   x=1;
  }
 }
 
 BmpView->Sync();
 Bmp->Unlock();
 Draw(Bounds());
}
Пример #10
0
bool
InsertionIntoEmptyArea::FindOptimalAreaFor(const BPoint& point,	BRect dragFrame,
	BSize target, BSize minSize, area_ref& ref, area_ref& maximalArea,
	Area* movedArea)
{
	if (!fView->FindEmptyArea(point, maximalArea, movedArea))
		return false;

	BRect currentFrame;
	if (movedArea != NULL)
		currentFrame = movedArea->Frame();
	MaximizeEmptyArea(maximalArea, dragFrame, currentFrame);

	ref = maximalArea;

	const float kSnapDistance = 10;

	// first reduce the area again if we are close to tab
	BRect emptyFrame = ref.Frame();
	float interestingWidth = dragFrame.Width();
	if (target.width >= 0 && emptyFrame.Width() > interestingWidth
		&& dragFrame.right + kSnapDistance < emptyFrame.right
		&& dragFrame.left - kSnapDistance > emptyFrame.left) {
		XTab* betterLeft = fView->GetXTabNearPoint(dragFrame.LeftTop(),
			kSnapDistance);
		if (betterLeft != NULL && (movedArea == NULL
			|| (betterLeft != movedArea->Left()
				&& betterLeft != movedArea->Right()))) {
			if (emptyFrame.right - betterLeft->Value() >= interestingWidth)
				ref.left = betterLeft;
		} else {
			XTab* betterRight = fView->GetXTabNearPoint(dragFrame.RightTop(),
				kSnapDistance);
			if (betterRight != NULL && (movedArea == NULL
				|| (betterRight != movedArea->Left()
					&& betterRight != movedArea->Right()))) {
				if (betterRight->Value() - emptyFrame.left >= interestingWidth)
					ref.right = betterRight;
			}
		}
	}
	float interestingHeight = dragFrame.Height();
	if (target.height >= 0 && emptyFrame.Height() > interestingHeight
		&& dragFrame.bottom + kSnapDistance < emptyFrame.bottom
		&& dragFrame.top - kSnapDistance > emptyFrame.top) {
		YTab* betterTop = fView->GetYTabNearPoint(dragFrame.LeftTop(),
			kSnapDistance);
		if (betterTop != NULL && (movedArea == NULL
			|| (betterTop != movedArea->Top()
			&& betterTop != movedArea->Bottom()))) {
			if (emptyFrame.bottom - betterTop->Value() >= interestingHeight)
				ref.top = betterTop;
		} else {
			YTab* betterBottom = fView->GetYTabNearPoint(dragFrame.RightBottom(),
				kSnapDistance);
			if (betterBottom != NULL && (movedArea == NULL
				|| (betterBottom != movedArea->Top()
					&& betterBottom != movedArea->Bottom()))) {
				if (betterBottom->Value() - emptyFrame.top >= interestingHeight)
					ref.bottom = betterBottom;
			}
		}
	}

	bool xSnapped = true;
	bool ySnapped = true;

	const float kNewTabSnapDistance = 15;
	// snap to area border
	emptyFrame = ref.Frame();
	InnerAreaTabs innerAreaTabs(fView->fOverlapManager.GetTabConnections());
	if (target.width >= 0
		&& emptyFrame.Width() - target.width > kNewTabSnapDistance) {
		if (dragFrame.left - emptyFrame.left < kNewTabSnapDistance) {
			ref.right = innerAreaTabs.FindHorizontalInnerTab(
				emptyFrame.left + target.width, kNewTabSnapDistance,
				maximalArea);
			if (ref.right != NULL && ref.right->Value() <= ref.left->Value())
				ref.right = NULL;
		} else if (emptyFrame.right - dragFrame.right < kNewTabSnapDistance) {
			ref.left = innerAreaTabs.FindHorizontalInnerTab(
				emptyFrame.right - target.width, kNewTabSnapDistance,
				maximalArea);
			if (ref.left != NULL && ref.right->Value() <= ref.left->Value())
				ref.left = NULL;
		} else
			xSnapped = false;
	}

	if (target.height >= 0
		&& emptyFrame.Height() - target.height > kNewTabSnapDistance) {
		if (dragFrame.top - emptyFrame.top < kNewTabSnapDistance) {
			ref.bottom = innerAreaTabs.FindVerticalInnerTab(
				emptyFrame.top + target.height, kNewTabSnapDistance,
				maximalArea);
			if (ref.bottom != NULL && ref.bottom->Value() <= ref.top->Value())
				ref.bottom = NULL;
		} else if (emptyFrame.bottom - dragFrame.bottom < kNewTabSnapDistance) {
			ref.top = innerAreaTabs.FindVerticalInnerTab(
				emptyFrame.bottom - target.height, kNewTabSnapDistance,
				maximalArea);
			if (ref.top != NULL && ref.bottom->Value() <= ref.top->Value())
				ref.top = NULL;
		} else
			ySnapped = false;
	}

	//free placement
	if (!fView->Editor()->FreePlacement())
		return true;

	if (!xSnapped) {
		ref.left = NULL;
		ref.right = NULL;
	}
	if (!ySnapped) {
		ref.top = NULL;
		ref.bottom = NULL;
	}

	return true;
}
Пример #11
0
void
InsertionIntoEmptyArea::MaximizeEmptyArea(area_ref& ref, BRect target, BRect ignore)
{
	BALMLayout* layout = fView->Layout();
	BRegion takenSpace = fView->fTakenSpace;
	takenSpace.Exclude(ignore);
	area_info areaInfo(ref, layout);
	// try to match the target

	XTab* left = ref.left;
	while (left->Value() > target.left) {
		left = layout->XTabAt(areaInfo.left - 1, true);
		if (left == NULL)
			break;
		area_ref newRef = ref;
		newRef.left = left;
		BRect frame = newRef.Frame();
		frame.InsetBy(1, 1);
		if (takenSpace.Intersects(frame))
			break;
		areaInfo.left -= 1;
		ref.left = left;
	}
	XTab* right = ref.right;
	while (right->Value() < target.right) {
		right = layout->XTabAt(areaInfo.right + 1, true);
		if (right == NULL)
			break;
		area_ref newRef = ref;
		newRef.right = right;
		BRect frame = newRef.Frame();
		frame.InsetBy(1, 1);
		if (takenSpace.Intersects(frame))
			break;
		areaInfo.right += 1;
		ref.right = right;
	}
	YTab* top = ref.top;
	while (top->Value() > target.top) {
		top = layout->YTabAt(areaInfo.top - 1, true);
		if (top == NULL)
			break;
		area_ref newRef = ref;
		newRef.top = top;
		BRect frame = newRef.Frame();
		frame.InsetBy(1, 1);
		if (takenSpace.Intersects(frame))
			break;
		areaInfo.top -= 1;
		ref.top = top;
	}
	YTab* bottom = ref.bottom;
	while (bottom->Value() < target.bottom) {
		bottom = layout->YTabAt(areaInfo.bottom + 1, true);
		if (bottom == NULL)
			break;
		area_ref newRef = ref;
		newRef.bottom = bottom;
		BRect frame = newRef.Frame();
		frame.InsetBy(1, 1);
		if (takenSpace.Intersects(frame))
			break;
		areaInfo.bottom += 1;
		ref.bottom = bottom;
	}

	// maximize further
	while (true) {
		BRect previousFrame = ref.Frame();
		
		left = layout->XTabAt(areaInfo.left - 1, true);
		right = layout->XTabAt(areaInfo.right + 1, true);
		top = layout->YTabAt(areaInfo.top - 1, true);
		bottom = layout->YTabAt(areaInfo.bottom + 1, true);

		float leftDelta = -1;
		if (left != NULL) {
			BRect newFrame(previousFrame);
			newFrame.left = left->Value();
			newFrame.InsetBy(1, 1);
			if (!takenSpace.Intersects(newFrame)) {
				leftDelta = previousFrame.Height()
					* (previousFrame.left - left->Value());
			}
		}
		float rightDelta = -1;
		if (right != NULL) {
			BRect newFrame(previousFrame);
			newFrame.right = right->Value();
			newFrame.InsetBy(1, 1);
			if (!takenSpace.Intersects(newFrame)) {
				rightDelta = previousFrame.Height()
					* (right->Value() - previousFrame.right);
			}
		}
		float topDelta = -1;
		if (top != NULL) {
			BRect newFrame(previousFrame);
			newFrame.top = top->Value();
			newFrame.InsetBy(1, 1);
			if (!takenSpace.Intersects(newFrame)) {
				topDelta = previousFrame.Width()
					* (previousFrame.top - top->Value());
			}
		}
		float bottomDelta = -1;
		if (bottom != NULL) {
			BRect newFrame(previousFrame);
			newFrame.bottom = bottom->Value();
			newFrame.InsetBy(1, 1);
			if (!takenSpace.Intersects(newFrame)) {
				bottomDelta = previousFrame.Width()
					* (bottom->Value() - previousFrame.bottom);
			}
		}
		if (leftDelta > 0 && leftDelta > rightDelta && leftDelta > topDelta
			&& leftDelta > bottomDelta) {
			ref.left = left;
			areaInfo.left = layout->IndexOf(left, true);
		} else if (rightDelta > 0 && rightDelta > topDelta
			&& rightDelta > bottomDelta) {
			ref.right = right;
			areaInfo.right = layout->IndexOf(right, true);
		} else if (topDelta > 0 && topDelta > bottomDelta) {
			ref.top = top;
			areaInfo.top = layout->IndexOf(top, true);
		} else if (bottomDelta > 0) {
			ref.bottom = bottom;
			areaInfo.bottom = layout->IndexOf(bottom, true);
		}

		BRect newFrame = ref.Frame();
		if (fuzzy_equal(previousFrame.Width(), newFrame.Width())
			&& fuzzy_equal(previousFrame.Height(), newFrame.Height()))
			break;
	}
}
Пример #12
0
CharacterWindow::CharacterWindow()
	:
	BWindow(BRect(100, 100, 700, 550), B_TRANSLATE_SYSTEM_NAME("CharacterMap"),
		B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
			| B_AUTO_UPDATE_SIZE_LIMITS)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	} else {
		float scaling = be_plain_font->Size() / 12.0f;
		ResizeTo(Frame().Width() * scaling, Frame().Height() * scaling);
		CenterOnScreen();
	}

	// create GUI
	BMenuBar* menuBar = new BMenuBar("menu");

	fFilterControl = new BTextControl(B_TRANSLATE("Filter:"), NULL, NULL);
	fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged));

	BButton* clearButton = new BButton("clear", B_TRANSLATE("Clear"),
		new BMessage(kMsgClearFilter));

	fUnicodeBlockView = new UnicodeBlockView("unicodeBlocks");
	fUnicodeBlockView->SetSelectionMessage(
		new BMessage(kMsgUnicodeBlockSelected));

	BScrollView* unicodeScroller = new BScrollView("unicodeScroller",
		fUnicodeBlockView, 0, false, true);

	fCharacterView = new CharacterView("characters");
	fCharacterView->SetTarget(this, kMsgCharacterChanged);

	fGlyphView = new BStringView("glyph", "");
	fGlyphView->SetExplicitMaxSize(BSize(B_SIZE_UNSET,
		fGlyphView->PreferredSize().Height()));

	// TODO: have a context object shared by CharacterView/UnicodeBlockView
	bool show;
	if (settings.FindBool("show private blocks", &show) == B_OK) {
		fCharacterView->ShowPrivateBlocks(show);
		fUnicodeBlockView->ShowPrivateBlocks(show);
	}
	if (settings.FindBool("show contained blocks only", &show) == B_OK) {
		fCharacterView->ShowContainedBlocksOnly(show);
		fUnicodeBlockView->ShowPrivateBlocks(show);
	}

	const char* family;
	const char* style;
	BString displayName;

	if (settings.FindString("font family", &family) == B_OK
		&& settings.FindString("font style", &style) == B_OK) {
		_SetFont(family, style);
		displayName << family << " " << style;
	} else {
		font_family currentFontFamily;
		font_style currentFontStyle;
		fCharacterView->CharacterFont().GetFamilyAndStyle(&currentFontFamily,
			&currentFontStyle);
		displayName << currentFontFamily << " " << currentFontStyle;
	}

	int32 fontSize;
	if (settings.FindInt32("font size", &fontSize) == B_OK) {
		BFont font = fCharacterView->CharacterFont();
		if (fontSize < kMinFontSize)
			fontSize = kMinFontSize;
		else if (fontSize > kMaxFontSize)
			fontSize = kMaxFontSize;
		font.SetSize(fontSize);

		fCharacterView->SetCharacterFont(font);
	} else
		fontSize = (int32)fCharacterView->CharacterFont().Size();

	BScrollView* characterScroller = new BScrollView("characterScroller",
		fCharacterView, 0, false, true);

	fFontSizeSlider = new FontSizeSlider("fontSizeSlider",
		displayName,
		new BMessage(kMsgFontSizeChanged), kMinFontSize, kMaxFontSize);
	fFontSizeSlider->SetValue(fontSize);

	fCodeView = new BStringView("code", "-");
	fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
		fCodeView->PreferredSize().Height()));

	// Set minimum width for character pane to prevent UI
	// from jumping when longer code strings are displayed.
	// use 'w' character for sizing as it's likely the widest
	// character for a Latin font.  40 characters is a little
	// wider than needed so hopefully this covers other
	// non-Latin fonts that may be wider.
	BFont viewFont;
	fCodeView->GetFont(&viewFont);
	fCharacterView->SetExplicitMinSize(BSize(viewFont.StringWidth("w") * 40,
		B_SIZE_UNSET));

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.Add(menuBar)
		.AddGroup(B_HORIZONTAL)
			.SetInsets(B_USE_WINDOW_SPACING)
			.AddGroup(B_VERTICAL)
				.AddGroup(B_HORIZONTAL)
					.Add(fFilterControl)
					.Add(clearButton)
				.End()
				.Add(unicodeScroller)
			.End()
			.AddGroup(B_VERTICAL)
				.Add(characterScroller)
				.Add(fFontSizeSlider)
				.AddGroup(B_HORIZONTAL)
					.Add(fGlyphView)
					.Add(fCodeView);

	// Add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	BMenuItem* item;

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	menu = new BMenu(B_TRANSLATE("View"));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show private blocks"),
		new BMessage(kMsgPrivateBlocks)));
	item->SetMarked(fCharacterView->IsShowingPrivateBlocks());
// TODO: this feature is not yet supported by Haiku!
#if 0
	menu->AddItem(item = new BMenuItem("Only show blocks contained in font",
		new BMessage(kMsgContainedBlocks)));
	item->SetMarked(fCharacterView->IsShowingContainedBlocksOnly());
#endif
	menuBar->AddItem(menu);

	fFontMenu = _CreateFontMenu();
	menuBar->AddItem(fFontMenu);

	AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter));
	AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView));

	// TODO: why is this needed?
	fUnicodeBlockView->SetTarget(this);

	fFilterControl->MakeFocus();

	fUnicodeBlockView->SelectBlockForCharacter(0);
}
Пример #13
0
void
ColorSwatch::Draw (BRect)
{
	PushState();

	SetDrawingMode (B_OP_COPY);

	rgb_color high (HighColor());
	BRect colorPad (Bounds());
	SetHighColor (ValueAsColor());

	FillRect (colorPad);

	rgb_color light (ShiftColor (ValueAsColor(), 0.4));
	rgb_color dark	(ShiftColor (ValueAsColor(), 1.2));

	BeginLineArray (10);
	AddLine (
		colorPad.LeftTop(),
		colorPad.RightTop() - BPoint (1, 0),
		light);

	AddLine (
		colorPad.LeftTop(),
		colorPad.LeftBottom() - BPoint (0, 1),
		light);

	AddLine (
		colorPad.RightTop() + BPoint (0, 1),
		colorPad.RightBottom(),
		dark);

	AddLine (
		colorPad.RightBottom(),
		colorPad.LeftBottom() + BPoint (1, 0),
		dark);

	light = ShiftColor (ViewColor(), 0.1);
	dark	= ShiftColor (ViewColor(), 1.4);
	colorPad.InsetBy (-1, -1);

	BPoint hless (-1, 0);
	BPoint hmore (1, 0);
	BPoint vless (0, -1);
	BPoint vmore (0, 1);

	if (IsFocus() && Window()->IsActive())
	{
		light = general_info.mark_color;
		dark	= general_info.mark_color;
		hless = hmore = vless = vmore = BPoint (0, 0);
	}
	else
	{
		// A little blue residue clean up
		AddLine (
			colorPad.RightTop(),
			colorPad.RightTop(),
			ViewColor());
		AddLine (
			colorPad.LeftBottom(),
			colorPad.LeftBottom(),
			ViewColor());
	}

	AddLine (
		colorPad.LeftTop(),
		colorPad.RightTop() + hless,
		dark);

	AddLine (
		colorPad.LeftTop(),
		colorPad.LeftBottom() + vless,
		dark);

	AddLine (
		colorPad.RightTop() + vmore,
		colorPad.RightBottom(),
		light);

	AddLine (
		colorPad.RightBottom(),
		colorPad.LeftBottom() + hmore,
		light);

	EndLineArray();
	PopState();
}
Пример #14
0
void
BTextControl::Draw(BRect updateRect)
{
	bool enabled = IsEnabled();
	bool active = fText->IsFocus() && Window()->IsActive();

	BRect rect = fText->Frame();
	rect.InsetBy(-2, -2);

	if (be_control_look != NULL) {
		rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
		uint32 flags = 0;
		if (!enabled)
			flags |= BControlLook::B_DISABLED;
		if (active)
			flags |= BControlLook::B_FOCUSED;
		be_control_look->DrawTextControlBorder(this, rect, updateRect, base,
			flags);

		rect = Bounds();
		rect.right = fDivider - kLabelInputSpacing;
//		rect.right = fText->Frame().left - 2;
//		rect.right -= 3;//be_control_look->DefaultLabelSpacing();
		be_control_look->DrawLabel(this, Label(), rect, updateRect,
			base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE));

		return;
	}

	// outer bevel

	rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
	rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT);
	rgb_color lighten2 = tint_color(noTint, B_LIGHTEN_2_TINT);
	rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT);
	rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT);
	rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
	rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);
	rgb_color navigationColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR);

	if (enabled)
		SetHighColor(darken1);
	else
		SetHighColor(noTint);

	StrokeLine(rect.LeftBottom(), rect.LeftTop());
	StrokeLine(rect.RightTop());

	if (enabled)
		SetHighColor(lighten2);
	else
		SetHighColor(lighten1);

	StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom());
	StrokeLine(BPoint(rect.right, rect.top + 1.0f), rect.RightBottom());

	// inner bevel

	rect.InsetBy(1.0f, 1.0f);

	if (active) {
		SetHighColor(navigationColor);
		StrokeRect(rect);
	} else {
		if (enabled)
			SetHighColor(darken4);
		else
			SetHighColor(darken2);

		StrokeLine(rect.LeftTop(), rect.LeftBottom());
		StrokeLine(rect.LeftTop(), rect.RightTop());

		SetHighColor(noTint);
		StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom());
		StrokeLine(BPoint(rect.right, rect.top + 1.0f));
	}

	// label

	if (Label()) {
		_ValidateLayoutData();
		font_height& fontHeight = fLayoutData->font_info;

		float y = Bounds().top + (Bounds().Height() + 1 - fontHeight.ascent
			- fontHeight.descent) / 2 + fontHeight.ascent;
		float x;

		float labelWidth = StringWidth(Label());
		switch (fLabelAlign) {
			case B_ALIGN_RIGHT:
				x = fDivider - labelWidth - kLabelInputSpacing;
				break;

			case B_ALIGN_CENTER:
				x = fDivider - labelWidth / 2.0;
				break;

			default:
				x = 0.0;
				break;
		}

		BRect labelArea(x, Bounds().top, x + labelWidth, Bounds().bottom);
		if (x < fDivider && updateRect.Intersects(labelArea)) {
			labelArea.right = fText->Frame().left - kLabelInputSpacing;

			BRegion clipRegion(labelArea);
			ConstrainClippingRegion(&clipRegion);
			SetHighColor(IsEnabled() ? ui_color(B_CONTROL_TEXT_COLOR)
				: tint_color(noTint, B_DISABLED_LABEL_TINT));
			DrawString(Label(), BPoint(x, y));
		}
	}
}
Пример #15
0
void
make_window_visible(BWindow* window, bool mayResize)
{
	uint32 flags = window->Flags();
	BRect screen = BScreen(window).Frame();
	BRect frame = window->Frame();
	screen.InsetBy(4, 8);
	screen.OffsetBy(0, 8);

	if (mayResize) {
		float width = frame.Width();
		float height = frame.Height();
		if (screen.Width() < width && !(flags & B_NOT_H_RESIZABLE))
			width = screen.Width();
		if (screen.Height() < height && !(flags & B_NOT_V_RESIZABLE))
			height = screen.Height();
		if (width != frame.Width() || height != frame.Height()) {
			window->ResizeTo(width, height);
			frame.right = frame.left + width;
			frame.bottom = frame.top + height;
		}
	}
	if (frame.right > screen.right)
		window->MoveBy(screen.right-frame.right, 0);
	if (frame.bottom > screen.bottom)
		window->MoveBy(0, screen.bottom-frame.bottom);
	if (frame.left < screen.left)
		window->MoveTo(screen.left, frame.top);
	if (frame.top < screen.top)
		window->MoveBy(0, screen.top-frame.top);
}
Пример #16
0
void MonthWindowView::KeyDown(const char *bytes, int32 numBytes)
{
 switch(bytes[0])
 {
  case B_TAB:
  {
   Bmp->Lock();
   switch(which_focused)
   {
    case 0: // months
    {
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left,
                                monthMStringView[0]->Frame().bottom+1),
                         BPoint(monthMStringView[1]->Frame().right,
                                monthMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 1: // years
    {
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left,
                                yearMStringView[0]->Frame().bottom+1),
                         BPoint(yearMStringView[1]->Frame().right,
                                yearMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 2: // days of month
    {
     BmpView->SetHighColor(NOACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 3: // today
    {
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeLine(BPoint(todayStringView->Frame().left,
                                todayStringView->Frame().bottom+1),
                         BPoint(todayStringView->Frame().right,
                                todayStringView->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
   }
   
   // changing which_focused
   if(modifiers() & B_SHIFT_KEY)
   {
    if(which_focused==0)
      which_focused=3;
    else which_focused--;
   }
   else // simply Tab
   {
    if(which_focused==3)
     which_focused=0;
    else which_focused++;
   }
   
   // drawing with new which_focused
   switch(which_focused)
   {
    case 0: // months
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left,
                                monthMStringView[0]->Frame().bottom+1),
                         BPoint(monthMStringView[1]->Frame().right,
                                monthMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 1: // years
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left,
                                yearMStringView[0]->Frame().bottom+1),
                         BPoint(yearMStringView[1]->Frame().right,
                                yearMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 2: // days of month
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 3: // today
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeLine(BPoint(todayStringView->Frame().left,
                                todayStringView->Frame().bottom+1),
                         BPoint(todayStringView->Frame().right,
                                todayStringView->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
   }
   BmpView->Sync();
   Bmp->Unlock();
   Draw(Bounds());
   break;
  } // B_TAB
  
  case B_DOWN_ARROW:
  {
   if(which_focused==0) // month
   { 
    BMessage msg('MON0');
    MessageReceived(&msg);
   }
   else if(which_focused==1) // year
   {
    BMessage msg('YEA0');
    MessageReceived(&msg);
   }
   else if(which_focused==2) // days of month
   {
    int qu_days=monthDays[cmonth-1];
    if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
    if((cday+7)<=qu_days)
    {
     Bmp->Lock();
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeRect(cursor);
     cursor.OffsetBySelf(0, h_cell);
     cday+=7;
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     BmpView->Sync();
     Bmp->Unlock();
     Draw(Bounds());
    }
   }
   break;
  }
  
  case B_UP_ARROW:
  {
   // Test whether Ctrl+UpArrow is pressed
   if(modifiers() & B_CONTROL_KEY)
    Window()->PostMessage(B_QUIT_REQUESTED);
   else
   {
    if(which_focused==0) // month
    {
     BMessage msg('MON1');
     MessageReceived(&msg);
    }
    else if(which_focused==1) // year
    {
     BMessage msg('YEA1');
     MessageReceived(&msg);
    }
    else if(which_focused==2) // days of month
    {
     if((cday-7)>=1)
     {
      Bmp->Lock();
      BmpView->SetHighColor(VIEW_COLOR);
      BmpView->StrokeRect(cursor);
      cursor.OffsetBySelf(0, -h_cell);
      cday-=7;
      BmpView->SetHighColor(ACTIVE_COLOR);
      BmpView->StrokeRect(cursor);
      BmpView->SetHighColor(0,0,0);
      BmpView->Sync();
      Bmp->Unlock();
      Draw(Bounds());
     }
    }
   }
   break;
  }
  
  case B_LEFT_ARROW:
  {
   if(which_focused==0) // month
   {
    BMessage msg('MON0');
    MessageReceived(&msg);
   }
   else if(which_focused==1) // year
   {
    BMessage msg('YEA0');
    MessageReceived(&msg);
   }
   else if(which_focused==2) // days of month
   {
    if(cday>1)
    {
     Bmp->Lock();
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeRect(cursor);
     if(cwday>0) // by dates no matter of day of week
     {
      cursor.OffsetBySelf(-w_cell,0);
      cwday--;
     }
     else // cwday==0
     {
      cursor.OffsetBySelf(w_cell*6,-h_cell);
      cwday=6;
     }
     cday--;
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     BmpView->Sync();
     Bmp->Unlock();
     Draw(Bounds());
    }
    else // 1st of month, go month before
    {
     if(cyear>first_year || cmonth>1) // one can go
     {
      int cm=(cmonth==1) ? 12 : cmonth-1;
      int qu_days=monthDays[cm-1];
      if(cm==2) if(cyear%4==0) 
       if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
       // it is correct not to pay attention to year changing
       // because if we moved to february then year was not changed
       // but if month is other then february 
       // then it has the same number of days every year.
      cday=qu_days;
      
      BMessage msg('MON0');
      MessageReceived(&msg); // here month, cwday and year (if needed) will be changed
     }
    }
   }
   break;
  }
  
  case B_RIGHT_ARROW:
  {
   if(which_focused==0) // month
   {
    BMessage msg('MON1');
    MessageReceived(&msg);
   }
   else if(which_focused==1) // year
   {
    BMessage msg('YEA1');
    MessageReceived(&msg);
   }
   else if(which_focused==2) // days of month
   {
    int qu_days=monthDays[cmonth-1];
    if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
    if(cday<qu_days)
    {
     Bmp->Lock();
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeRect(cursor);
     if(cwday<6) // by dates no matter of day of week
     {
      cursor.OffsetBySelf(w_cell,0);
      cwday++;
     }
     else // cwday==6
     {
      cursor.OffsetBySelf(-w_cell*6,h_cell);
      cwday=0;
     }
     cday++;
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     BmpView->Sync();
     Bmp->Unlock();
     Draw(Bounds());
    }
    else // last of month, go next month
    {
     if(cyear<last_year || cmonth<12) // one can go
     {
      cday=1;
      BMessage msg('MON1');
      MessageReceived(&msg); // here month, cwday and year (if needed) will be changed
     }
    }
   }
   break;
  }
  
  case B_ESCAPE:
  {
   Window()->PostMessage(B_QUIT_REQUESTED);
   break;
  }
  
  case B_ENTER:
  {
   if(which_focused==2)
   {
    // here it is needed to send dayPressed (==cwday), cyear, cmonth
    // to window and leave
    BMessage *msg=new BMessage('MVME');
    msg->AddInt32("day",cday);
    msg->AddInt32("month",cmonth);
    msg->AddInt32("year",cyear);
    Window()->PostMessage(msg);
   }
   else if(which_focused==3)
   {
    BMessage msg('TODA');
    MessageReceived(&msg);
   }
   break;
  }
  
  case B_SPACE: // the same as B_ENTER
  {
   if(which_focused==2)
   {
    // here it is needed to send dayPressed (==cwday), cyear, cmonth
    // to window and leave
    BMessage *msg=new BMessage('MVME');
    msg->AddInt32("day",cday);
    msg->AddInt32("month",cmonth);
    msg->AddInt32("year",cyear);
    Window()->PostMessage(msg);
   }
   else if(which_focused==3)
   {
    BMessage msg('TODA');
    MessageReceived(&msg);
   }
   break;
  }
  
  default: 
   BView::KeyDown(bytes, numBytes);
 }
}
Пример #17
0
void
ObjectView::AttachedToWindow()
{
	float position[] = {0.0, 3.0, 3.0, 0.0};
	float position1[] = {-3.0, -3.0, 3.0, 0.0};
	float position2[] = {3.0, 0.0, 0.0, 0.0};
	float local_view[] = {0.0, 0.0};
//	float ambient[] = {0.1745, 0.03175, 0.03175};
//	float diffuse[] = {0.61424, 0.10136, 0.10136};
//	float specular[] = {0.727811, 0.626959, 0.626959};
//	rgb_color black = {0, 0, 0, 255};
	BRect bounds = Bounds();

	BGLView::AttachedToWindow();
	Window()->SetPulseRate(100000);

	LockGL();

	glEnable(GL_DITHER);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glDepthFunc(GL_LESS);

	glShadeModel(GL_SMOOTH);

	glLightfv(GL_LIGHT0, GL_POSITION, position);
	glLightfv(GL_LIGHT0 + 1, GL_POSITION, position1);
	glLightfv(GL_LIGHT0 + 2, GL_POSITION, position2);
	glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_SPECULAR, lights[lightWhite].specular);
	glLightfv(GL_LIGHT0, GL_DIFFUSE,lights[lightWhite].diffuse);
	glLightfv(GL_LIGHT0, GL_AMBIENT,lights[lightWhite].ambient);
	glEnable(GL_LIGHT1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, lights[lightBlue].specular);
	glLightfv(GL_LIGHT1, GL_DIFFUSE,lights[lightBlue].diffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT,lights[lightBlue].ambient);

	glFrontFace(GL_CW);
	glEnable(GL_LIGHTING);
	glEnable(GL_AUTO_NORMAL);
	glEnable(GL_NORMALIZE);

	glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0);

	glClearColor(bgColor[0], bgColor[1], bgColor[2], 1.0);
	glColor3f(1.0, 1.0, 1.0);

	glViewport(0, 0, (GLint)bounds.IntegerWidth() + 1,
				(GLint)bounds.IntegerHeight() + 1);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	float scale = displayScale;
	glOrtho(-scale, scale, -scale, scale, -scale * depthOfView,
			scale * depthOfView);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	UnlockGL();

	fDrawThread = spawn_thread(simonThread, "Simon", B_NORMAL_PRIORITY, this);
	resume_thread(fDrawThread);
	fForceRedraw = true;
	setEvent(drawEvent);
}
Пример #18
0
void
BColorControl::_DrawColorArea(BView* target, BRect updateRect)
{
	BRect rect = _PaletteFrame();
	bool enabled = IsEnabled();

	rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
	rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT);

	if (be_control_look != NULL) {
		uint32 flags = 0;
		if (!enabled)
			flags |= BControlLook::B_DISABLED;

		be_control_look->DrawTextControlBorder(target, rect, updateRect, noTint,
			flags);
	} else {
		rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT);
		rgb_color lightenmax = tint_color(noTint, B_LIGHTEN_MAX_TINT);
		rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
		rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);

		// first bevel
		if (enabled)
			target->SetHighColor(darken1);
		else
			target->SetHighColor(noTint);

		target->StrokeLine(rect.LeftBottom(), rect.LeftTop());
		target->StrokeLine(rect.LeftTop(), rect.RightTop());
		if (enabled)
			target->SetHighColor(lightenmax);
		else
			target->SetHighColor(lighten1);

		target->StrokeLine(BPoint(rect.left + 1.0f, rect.bottom),
			rect.RightBottom());
		target->StrokeLine(rect.RightBottom(),
			BPoint(rect.right, rect.top + 1.0f));

		rect.InsetBy(1.0f, 1.0f);

		// second bevel
		if (enabled)
			target->SetHighColor(darken4);
		else
			target->SetHighColor(darken2);

		target->StrokeLine(rect.LeftBottom(), rect.LeftTop());
		target->StrokeLine(rect.LeftTop(), rect.RightTop());
		target->SetHighColor(noTint);
		target->StrokeLine(BPoint(rect.left + 1.0f, rect.bottom),
			rect.RightBottom());
		target->StrokeLine(rect.RightBottom(),
			BPoint(rect.right, rect.top + 1.0f));
	}

	if (fPaletteMode) {
		int colBegin = max_c(0, -1 + int(updateRect.left) / int(fCellSize));
		int colEnd = min_c(fColumns,
			2 + int(updateRect.right) / int(fCellSize));
		int rowBegin = max_c(0, -1 + int(updateRect.top) / int(fCellSize));
		int rowEnd = min_c(fRows, 2 + int(updateRect.bottom)
			/ int(fCellSize));

		// grid
		if (enabled)
			target->SetHighColor(darken1);
		else
			target->SetHighColor(noTint);

		for (int xi = 0; xi < fColumns + 1; xi++) {
			float x = fPaletteFrame.left + float(xi) * fCellSize;
			target->StrokeLine(BPoint(x, fPaletteFrame.top),
				BPoint(x, fPaletteFrame.bottom));
		}
		for (int yi = 0; yi < fRows + 1; yi++) {
			float y = fPaletteFrame.top + float(yi) * fCellSize;
			target->StrokeLine(BPoint(fPaletteFrame.left, y),
				BPoint(fPaletteFrame.right, y));
		}

		// colors
		for (int col = colBegin; col < colEnd; col++) {
			for (int row = rowBegin; row < rowEnd; row++) {
				uint8 colorIndex = row * fColumns + col;
				float x = fPaletteFrame.left + col * fCellSize;
				float y = fPaletteFrame.top + row * fCellSize;

				target->SetHighColor(system_colors()->color_list[colorIndex]);
				target->FillRect(BRect(x + 1, y + 1,
					x + fCellSize - 1, y + fCellSize - 1));
			}
		}
	} else {
		rgb_color white = { 255, 255, 255, 255 };
		rgb_color red   = { 255, 0, 0, 255 };
		rgb_color green = { 0, 255, 0, 255 };
		rgb_color blue  = { 0, 0, 255, 255 };

		rgb_color compColor = { 0, 0, 0, 255 };
		if (!enabled) {
			compColor.red = compColor.green = compColor.blue = 156;
			red.red = green.green = blue.blue = 70;
			white.red = white.green = white.blue = 70;
		}
		_DrawColorRamp(_RampFrame(0), target, white, compColor, 0, false,
			updateRect);
		_DrawColorRamp(_RampFrame(1), target, red, compColor, 0, false,
			updateRect);
		_DrawColorRamp(_RampFrame(2), target, green, compColor, 0, false,
			updateRect);
		_DrawColorRamp(_RampFrame(3), target, blue, compColor, 0, false,
			updateRect);
	}
}
Пример #19
0
SudokuWindow::SudokuWindow()
	:
	BWindow(BRect(100, 100, 500, 520), B_TRANSLATE_SYSTEM_NAME("Sudoku"),
		B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
	fGenerator(NULL),
	fStoredState(NULL),
	fExportFormat(kExportAsText)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
		frame.OffsetTo(B_ORIGIN);
	} else
		frame = Bounds();

	if (settings.HasMessage("stored state")) {
		fStoredState = new BMessage;
		if (settings.FindMessage("stored state", fStoredState) != B_OK) {
			delete fStoredState;
			fStoredState = NULL;
		}
	}

	int32 level = 0;
	settings.FindInt32("level", &level);

	// create GUI

	BMenuBar* menuBar = new BMenuBar(Bounds(), "menu");
	AddChild(menuBar);

	frame.top = menuBar->Frame().bottom;

	BView* top = new BView(frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(top);

	fSudokuView = new SudokuView(
		top->Bounds().InsetByCopy(10, 10).OffsetToSelf(0, 0),
		"sudoku view", settings, B_FOLLOW_NONE);
	CenteredViewContainer* container = new CenteredViewContainer(fSudokuView,
		top->Bounds().InsetByCopy(10, 10),
		"center", B_FOLLOW_ALL);
	container->SetHighColor(top->ViewColor());
	top->AddChild(container);

	// add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	fNewMenu = new BMenu(B_TRANSLATE("New"));
	menu->AddItem(new BMenuItem(fNewMenu, new BMessage(kMsgGenerateSudoku)));
	fNewMenu->Superitem()->SetShortcut('N', B_COMMAND_KEY);

	BMessage* message = new BMessage(kMsgGenerateSudoku);
	message->AddInt32("level", kEasyLevel);
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Easy"), message));
	message = new BMessage(kMsgGenerateSudoku);
	message->AddInt32("level", kAdvancedLevel);
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Advanced"), message));
	message = new BMessage(kMsgGenerateSudoku);
	message->AddInt32("level", kHardLevel);
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Hard"), message));

	fNewMenu->AddSeparatorItem();
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Blank"),
		new BMessage(kMsgNewBlank)));

	menu->AddItem(new BMenuItem(B_TRANSLATE("Start again"),
		new BMessage(kMsgStartAgain)));
	menu->AddSeparatorItem();
	BMenu* recentsMenu = BRecentFilesList::NewFileListMenu(
		B_TRANSLATE("Open file" B_UTF8_ELLIPSIS), NULL, NULL, this, 10, false,
		NULL, kSignature);
	BMenuItem *item;
	menu->AddItem(item = new BMenuItem(recentsMenu,
		new BMessage(kMsgOpenFilePanel)));
	item->SetShortcut('O', B_COMMAND_KEY);

	menu->AddSeparatorItem();

	BMenu* subMenu = new BMenu(B_TRANSLATE("Export as" B_UTF8_ELLIPSIS));
	message = new BMessage(kMsgExportAs);
	message->AddInt32("as", kExportAsText);
	subMenu->AddItem(new BMenuItem(B_TRANSLATE("Text"), message));
	message= new BMessage(kMsgExportAs);
	message->AddInt32("as", kExportAsHTML);
	subMenu->AddItem(new BMenuItem(B_TRANSLATE("HTML"), message));
	menu->AddItem(subMenu);

	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Copy"),
		new BMessage(B_COPY), 'C'));

	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	item->SetTarget(be_app);
	menuBar->AddItem(menu);

	// "View" menu
	menu = new BMenu(B_TRANSLATE("View"));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark invalid values"),
		new BMessage(kMsgMarkInvalid)));
	if ((fSudokuView->HintFlags() & kMarkInvalid) != 0)
		item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark valid hints"),
		new BMessage(kMsgMarkValidHints)));
	if ((fSudokuView->HintFlags() & kMarkValidHints) != 0)
		item->SetMarked(true);
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	// "Help" menu
	menu = new BMenu(B_TRANSLATE("Help"));
	menu->AddItem(fUndoItem = new BMenuItem(B_TRANSLATE("Undo"),
		new BMessage(B_UNDO), 'Z'));
	fUndoItem->SetEnabled(false);
	menu->AddItem(fRedoItem = new BMenuItem(B_TRANSLATE("Redo"),
		new BMessage(B_REDO), 'Z', B_SHIFT_KEY));
	fRedoItem->SetEnabled(false);
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Snapshot current"),
		new BMessage(kMsgStoreState)));
	menu->AddItem(fRestoreStateItem = new BMenuItem(
		B_TRANSLATE("Restore snapshot"), new BMessage(kMsgRestoreState)));
	fRestoreStateItem->SetEnabled(fStoredState != NULL);
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Set all hints"),
		new BMessage(kMsgSetAllHints)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Solve"),
		new BMessage(kMsgSolveSudoku)));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Solve single field"),
		new BMessage(kMsgSolveSingle)));
	menu->SetTargetForItems(fSudokuView);
	menuBar->AddItem(menu);

	fOpenPanel = new BFilePanel(B_OPEN_PANEL);
	fOpenPanel->SetTarget(this);
	fSavePanel = new BFilePanel(B_SAVE_PANEL);
	fSavePanel->SetTarget(this);

	_SetLevel(level);

	fSudokuView->StartWatching(this, kUndoRedoChanged);
		// we like to know whenever the undo/redo state changes

	fProgressWindow = new ProgressWindow(this,
		new BMessage(kMsgAbortSudokuGenerator));

	if (fSudokuView->Field()->IsEmpty())
		PostMessage(kMsgGenerateSudoku);
}
Пример #20
0
status_t TToolTipView::ToolTipThread(tool_tip *tip)
{
	uint32	buttons;
	BPoint	where;
	BScreen	s(B_MAIN_SCREEN_ID);
	BRect	screen = s.Frame();

	screen.InsetBy(2, 2);
	while (!tip->quit) {
		if (tip->tool_tip_window->LockWithTimeout(0) == B_NO_ERROR)
		{
            if (tip->tool_tip_view->Window())
			tip->tool_tip_view->GetMouse(&where, &buttons,false);

/*			 if (tip->tool_tip_view->Window())
			  if (tip->tool_tip_view->Window()->CurrentMessage())
			  {
  			   tip->tool_tip_view->Window()->CurrentMessage()->FindPoint("where", &where);
			   tip->tool_tip_view->Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
			  }
*/
			tip->tool_tip_view->ConvertToScreen(&where);

			tip->stopped = tip->stop;
			if (tip->reset) {
				if (tip->showing)
					tip->tool_tip_window->Hide();
				tip->stop = false;
				tip->stopped = false;
				tip->reset = false;
				tip->shown = false;
				tip->showing = false;
				tip->start_time = system_time() + tip->settings.delay;
			}
			else if (tip->showing) {
				if ((tip->stop) ||
					(!tip->settings.enabled) ||
					(!tip->app_active) ||
					(!tip->bounds.Contains(where)) ||
					(tip->expire_time < system_time()) ||
					(abs((int)tip->start.x - (int)where.x) > kSLOP) ||
					(abs((int)tip->start.y - (int)where.y) > kSLOP) ||
					(buttons)) {
					tip->tool_tip_window->Hide();
					tip->shown = tip->settings.one_time_only;
					tip->showing = false;
					tip->tip_timed_out = (tip->expire_time < system_time());
					tip->start_time = system_time() + tip->settings.delay;
				}
			}
			else if ((tip->settings.enabled) &&
					 (!tip->stopped) &&
					 (tip->app_active) &&
					 (!tip->shown) &&
					 (!tip->tip_timed_out) &&
					 (!buttons) &&
					 (tip->bounds.Contains(where)) &&
					 (tip->start_time < system_time())) {
				tip->start = where;
				tip->tool_tip_view->AdjustWindow();
				tip->tool_tip_window->Show();
				tip->tool_tip_window->Activate(false);
				tip->showing = true;
				tip->expire_time = system_time() + tip->settings.hold;
				tip->start = where;
			}
			else if ((abs((int)tip->start.x - (int)where.x) > kSLOP) ||
					 (abs((int)tip->start.y - (int)where.y) > kSLOP)) {
				tip->start = where;
				tip->start_time = system_time() + tip->settings.delay;
				tip->tip_timed_out = false;
			}
			if (buttons)
				tip->start_time = system_time() + tip->settings.delay;
			tip->tool_tip_window->Unlock();
		}
		snooze(50000);
	}
	return B_NO_ERROR;
}
BeAccessibleWindow::BeAccessibleWindow(BRect frame, BList* recentFiles)
				: BWindow(frame, "BeAccessible", B_TITLED_WINDOW, 0)
{
	//Create MenuBar
	BRect rect = Bounds();
	rect.bottom = MENU_BAR_HEIGHT;
	
	fMenuBar = new BMenuBar(rect, "MenuBar");
	AddChild(fMenuBar);
	
	//Create Menus
	fFileMenu	= new BMenu("File");
	fMenuBar->AddItem(fFileMenu);
	fOpenRecentMenu = new BMenu("Open Recent");
	fToolsMenu = new BMenu("Tools");
	fMenuBar->AddItem(fToolsMenu);
	
	//Create MenuItems
	fFileMenu->AddItem(new BMenuItem("New", new BMessage(MENU_FILE_NEW_MSG), 'N'));
	fFileMenu->AddItem(new BMenuItem("Open", new BMessage(MENU_FILE_OPEN_MSG), 'O'));
	fFileMenu->AddSeparatorItem();
	
	BMenu* externalDataMenu = new BMenu("Get External Data");
	fFileMenu->AddItem(externalDataMenu);
	fImportItem = new BMenuItem("Import Text File", new BMessage(IMPORT_FILE_REQUESTED_MSG));
	externalDataMenu->AddItem(fImportItem);
	fFileMenu->AddSeparatorItem();
	
	fCloseItem = new BMenuItem("Close", new BMessage(MENU_FILE_CLOSE_MSG), 'W');
	fFileMenu->AddItem(fCloseItem);
	fFileMenu->AddSeparatorItem();

	BMenuItem* about = new BMenuItem("About BeAccessible", new BMessage(B_ABOUT_REQUESTED));
	fFileMenu->AddItem(about);
	about->SetTarget(be_app);
	
	fFileMenu->AddSeparatorItem();
	BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q');
	quitItem->SetTarget(be_app);
	fFileMenu->AddItem(quitItem);


	fCompactItem = new BMenuItem("Compact", new BMessage(COMPACT_DATABASE_MSG));
	fToolsMenu->AddItem(fCompactItem);
	
	// Create MenuItems for recent files
	for(int i = 0; i < recentFiles->CountItems(); i++)
	{
		BString* file = (BString*)recentFiles->ItemAt(i);
		BPath path(file->String());
		
		BMessage* fileMsg = new BMessage(OPEN_DATABASE_MSG);
		fileMsg->AddString("path", file->String());
		fOpenRecentMenu->AddItem(new BMenuItem(path.Leaf(), fileMsg));
	}
	
	// Add the Open Recent menu between the Open and Close menu items
	fFileMenu->AddItem(fOpenRecentMenu, 2);
	
	fCloseItem->SetEnabled(false);
	fCompactItem->SetEnabled(false);
	fImportItem->SetEnabled(false);

    //Set up View
	frame.OffsetTo(B_ORIGIN);
	fMainView = new BView(frame, "BeAccessibleView", B_FOLLOW_ALL, B_WILL_DRAW);
	fMainView->SetViewColor(216,216,216,0);
	
	AddChild(fMainView);
	Show();
	
    //Set up File->Open and File->Save panels
    BMessage newMsg(NEW_FILE_REQUESTED), importMsg(IMPORT_FILE_MSG);
   	fOpenFile = new BFilePanel(B_OPEN_PANEL, NULL, NULL, 0, false);
   	fNewFile = new BFilePanel(B_SAVE_PANEL, NULL, NULL, 0, false, &newMsg);
   	fImportFile = new BFilePanel(B_OPEN_PANEL, NULL, NULL, 0, false, &importMsg);
   	
   	//Edit the look of the ImportFile panel
   	fImportFile->Window()->SetTitle("BeAccessible: Import");
	fImportFile->SetButtonLabel(B_DEFAULT_BUTTON, "Import");
	   	
   	//Initalize data members
   	fTabView = NULL;
   	fTableTab = NULL;
   	fQueryTab = NULL;
   	fNewGrid = NULL;
   	fPath = new BString;
}
Пример #22
0
void 
TestResultItem::DrawItem(BView *owner, BRect itemRect, bool drawEverthing)
{
	owner->SetDrawingMode(B_OP_COPY);
	
	owner->PushState();
	if (IsSelected()) {
		rgb_color lowColor = owner->LowColor();
		owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
	}
	else if (fOk) {
		// green background color on success
		owner->SetHighColor(200, 255, 200);
	}
	else {
		// red background color on failure
		owner->SetHighColor(255, 200, 200);
	}
	owner->FillRect(itemRect);
	owner->PopState();

	itemRect.InsetBy(1, 1);
	
	owner->MovePenTo(itemRect.left+1, itemRect.top+1);
	if (fDirectBitmap != NULL) {
		owner->DrawBitmap(fDirectBitmap);
	}
	owner->MovePenBy(fBitmapSize.Width() + distance, 0);

	if (fOriginalBitmap != NULL) {
		owner->DrawBitmap(fOriginalBitmap);
	}
	owner->MovePenBy(fBitmapSize.Width() + distance, 0);
	
	if (fArchivedBitmap != NULL) {
		owner->DrawBitmap(fArchivedBitmap);
	}
	owner->MovePenBy(fBitmapSize.Width() + distance, 0);
	
	owner->DrawBitmap(fDirectBitmap);
	owner->SetDrawingMode(B_OP_SUBTRACT);
	owner->DrawBitmap(fOriginalBitmap);

	owner->MovePenBy(fBitmapSize.Width() + distance, 0);

	owner->SetDrawingMode(B_OP_OVER);	
	BFont font;
	owner->GetFont(&font);
	// vertically center text 
	float baseLine = itemRect.top + (itemRect.IntegerHeight() / 2 + font.Size() / 2);
	owner->MovePenTo(owner->PenLocation().x, baseLine);
	owner->DrawString(fName.String());

	if (fErrorMessage.Length() == 0)
		return;

	owner->PushState();	
	font.SetFace(B_ITALIC_FACE);
	owner->SetFont(&font);
	owner->SetHighColor(255, 0, 0);
	owner->MovePenBy(distance, 0);
	owner->DrawString(fErrorMessage.String());
	owner->PopState();
}
Пример #23
0
void
BStatusBar::Draw(BRect updateRect)
{
	rgb_color shineColor = ui_color(B_SHINE_COLOR);
	rgb_color shadowColor = ui_color(B_SHADOW_COLOR);
	rgb_color barColor = ui_color(B_STATUSBAR_COLOR);

	BFont font;
	font_height fontHeight;

	GetFont(&font);
	font.GetHeight(&fontHeight);
	float sHeight = fontHeight.ascent + fontHeight.descent;

	if (!IsEnabled()) {
		shineColor.disable(ViewColor());
		shadowColor.disable(ViewColor());
		barColor.disable(ViewColor());
	}

	BPoint penLocation;

	MovePenTo(B_ORIGIN);
	MovePenBy(0, fontHeight.ascent + 1);

	if (fLabel != NULL) {
		if (!IsEnabled()) MovePenBy(1, 1);
		penLocation = PenLocation();

		SetHighColor(IsEnabled() ? ui_color(B_PANEL_TEXT_COLOR) : ui_color(B_SHINE_COLOR).disable(ViewColor()));
		SetLowColor(ViewColor());
		DrawString(fLabel);

		if (!IsEnabled()) {
			SetHighColor(ui_color(B_SHADOW_COLOR).disable(ViewColor()));
			DrawString(fLabel, penLocation - BPoint(1, 1));
		}

		MovePenBy(font.Spacing() * font.Size(), 0);
	}

	if (fText != NULL) {
		if (!IsEnabled()) MovePenBy(1, 1);
		penLocation = PenLocation();

		SetHighColor(IsEnabled() ? ui_color(B_PANEL_TEXT_COLOR) : ui_color(B_SHINE_COLOR).disable(ViewColor()));
		SetLowColor(ViewColor());
		DrawString(fText);

		if (!IsEnabled()) {
			SetHighColor(ui_color(B_SHADOW_COLOR).disable(ViewColor()));
			DrawString(fText, penLocation - BPoint(1, 1));
		}
	}

	MovePenTo(Frame().Width(), 0);
	MovePenBy(0, fontHeight.ascent + 1);

	if (fTrailingLabel != NULL) {
		MovePenBy(-(font.StringWidth(fTrailingLabel) + 1), 0);
		if (!IsEnabled()) MovePenBy(1, 1);
		penLocation = PenLocation();

		SetHighColor(IsEnabled() ? ui_color(B_PANEL_TEXT_COLOR) : ui_color(B_SHINE_COLOR).disable(ViewColor()));
		SetLowColor(ViewColor());
		DrawString(fTrailingLabel);

		if (!IsEnabled()) {
			SetHighColor(ui_color(B_SHADOW_COLOR).disable(ViewColor()));
			penLocation -= BPoint(1, 1);
			DrawString(fTrailingLabel, penLocation);
		}

		MovePenTo(penLocation + BPoint(-(font.Spacing() * font.Size()), 0));
	}

	if (fTrailingText != NULL) {
		MovePenBy(-(font.StringWidth(fTrailingText) + 1), 0);
		if (!IsEnabled()) MovePenBy(1, 1);
		penLocation = PenLocation();

		SetHighColor(IsEnabled() ? ui_color(B_PANEL_TEXT_COLOR) : ui_color(B_SHINE_COLOR).disable(ViewColor()));
		SetLowColor(ViewColor());
		DrawString(fTrailingText);

		if (!IsEnabled()) {
			SetHighColor(ui_color(B_SHADOW_COLOR).disable(ViewColor()));
			DrawString(fTrailingText, penLocation - BPoint(1, 1));
		}
	}

	BRect rect = Frame().OffsetToSelf(B_ORIGIN);
	if (fLabel != NULL || fTrailingLabel != NULL || fText != NULL || fTrailingText != NULL) rect.top += sHeight + 5;
	if (rect.IsValid() == false) return;

	rect.bottom = rect.top + fBarHeight;
	SetHighColor(shineColor.mix_copy(0, 0, 0, 5));
	FillRect(rect);
	SetHighColor(shineColor);
	StrokeRect(rect);
	SetHighColor(shadowColor);
	StrokeLine(rect.LeftBottom(), rect.RightBottom());
	StrokeLine(rect.RightTop());

	rect.InsetBy(1, 1);
	if (rect.IsValid() == false) return;

	BRect barRect = rect;
	SetHighColor(barColor);
	if (fCurrentValue < fMaxValue) barRect.right = barRect.left + barRect.Width() * fCurrentValue / fMaxValue;
	FillRect(barRect);
}
Пример #24
0
void
PowerStatusView::_DrawBattery(BRect rect)
{
	float quarter = floorf((rect.Height() + 1) / 4);
	rect.top += quarter;
	rect.bottom -= quarter;

	rect.InsetBy(2, 0);

	float left = rect.left;
	rect.left += rect.Width() / 11;

	if (LowColor().Brightness() > 100)
		SetHighColor(0, 0, 0);
	else
		SetHighColor(128, 128, 128);

	float gap = 1;
	if (rect.Height() > 8) {
		gap = ceilf((rect.left - left) / 2);

		// left
		FillRect(BRect(rect.left, rect.top, rect.left + gap - 1, rect.bottom));
		// right
		FillRect(BRect(rect.right - gap + 1, rect.top, rect.right,
			rect.bottom));
		// top
		FillRect(BRect(rect.left + gap, rect.top, rect.right - gap,
			rect.top + gap - 1));
		// bottom
		FillRect(BRect(rect.left + gap, rect.bottom + 1 - gap,
			rect.right - gap, rect.bottom));
	} else
		StrokeRect(rect);

	FillRect(BRect(left, floorf(rect.top + rect.Height() / 4) + 1,
		rect.left - 1, floorf(rect.bottom - rect.Height() / 4)));

	int32 percent = fPercent;
	if (percent > 100)
		percent = 100;
	else if (percent < 0 || !fHasBattery)
		percent = 0;

	if (percent > 0) {
		rect.InsetBy(gap, gap);
		rgb_color base = (rgb_color){84, 84, 84, 255};
		if (LowColor().Brightness() < 128)
			base = (rgb_color){172, 172, 172, 255};

		if (be_control_look != NULL) {
			BRect empty = rect;
			if (fHasBattery && percent > 0)
				empty.left += empty.Width() * percent / 100.0;

			be_control_look->DrawButtonBackground(this, empty, empty, base,
				fHasBattery
					? BControlLook::B_ACTIVATED : BControlLook::B_DISABLED,
				fHasBattery && percent > 0
					? (BControlLook::B_ALL_BORDERS
						& ~BControlLook::B_LEFT_BORDER)
					: BControlLook::B_ALL_BORDERS);
		}

		if (fHasBattery) {
			if (percent <= kLowBatteryPercentage)
				base.set_to(180, 0, 0);
			else if (percent <= kNoteBatteryPercentage)
				base.set_to(200, 140, 0);
			else
				base.set_to(20, 180, 0);

			rect.right = rect.left + rect.Width() * percent / 100.0;

			if (be_control_look != NULL) {
				be_control_look->DrawButtonBackground(this, rect, rect, base,
					fHasBattery ? 0 : BControlLook::B_DISABLED);
			} else
				FillRect(rect);
		}
	}

	if (fOnline) {
		// When charging, draw a lightning symbol over the battery.
		SetHighColor(255, 255, 0, 180);
		SetDrawingMode(B_OP_ALPHA);
		SetScale(std::min(Bounds().Width(), Bounds().Height()) / 16);

		static const BPoint points[] = {
			BPoint(2, 13),
			BPoint(9, 5),
			BPoint(9, 7),
			BPoint(16, 2),
			BPoint(8, 11),
			BPoint(8, 9)
		};
		FillPolygon(points, 6);

		SetScale(1);
		SetDrawingMode(B_OP_OVER);
	}

	SetHighColor(0, 0, 0);
}
Пример #25
0
SplitWindow::SplitWindow(BRect frame, Proxy* theProxy, BHandler* targetHandler, Prefs* prefs,
	uint32 total = 0, uint8 pam = 1, SplCat* sc = 0) : 
	BWindow(frame, "Transaction Split", B_FLOATING_WINDOW_LOOK, 
	B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE)
{
	#ifdef DEBUG
	printf("SplitWindow::SplitWindow\n");
	printf("\tsc = %p\n", sc);
	#endif

	this->prefs = prefs;

//	char buffer[20];
	frame.OffsetTo(0, 0);
	v = new BView(frame, "backview", B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
	v->SetViewColor(222, 222, 222);
	AddChild(v);
	BButton* b = new BButton(BRect(20, frame.bottom - 40, 100,
		frame.bottom - 20), "AddCatButton", "Add Category",
		new BMessage(AddCatMSG), B_FOLLOW_BOTTOM);
	v->AddChild(b);
	b = new BButton(BRect(frame.right - 100, frame.bottom - 40,
		frame.right - 20, frame.bottom - 20), "SplitEnter", "Enter",
		new BMessage(SplitEnterMSG), B_FOLLOW_BOTTOM);
	b->MakeDefault(true);
	v->AddChild(b);
	BStringView* sv = new BStringView(BRect(frame.right - 150,
		frame.bottom - 75, frame.right - 70, frame.bottom - 55),
		"TotalField", "Total", B_FOLLOW_BOTTOM);
	v->AddChild(sv);
	sv = new BStringView(BRect(frame.right - 150, frame.bottom - 95, 
		frame. right - 100, frame.bottom - 75), "DifferenceField", 
		"Difference", B_FOLLOW_BOTTOM);
	v->AddChild(sv);

	totalText = new BStringView(BRect(frame.right - 85,
		frame.bottom - 75, frame.right - 20, frame.bottom - 55),
		"TotalNumField", prefs->currencyToString(total).c_str(), B_FOLLOW_BOTTOM);
	totalText->SetAlignment(B_ALIGN_RIGHT);
	v->AddChild(totalText);
	diffText = new BStringView(BRect(frame.right - 85,
		frame.bottom - 95, frame.right - 20, frame.bottom - 75),
		"DiffNumField", prefs->currencyToString(total).c_str(), B_FOLLOW_BOTTOM);
	diffText->SetAlignment(B_ALIGN_RIGHT);
	v->AddChild(diffText);
	depRadio = new BRadioButton(BRect(120, frame.bottom - 45,
		180, frame.bottom - 45), "DepositRadioButton", "Deposit", 0,
		B_FOLLOW_BOTTOM);
	v->AddChild(depRadio);
	pamRadio = new BRadioButton(BRect(120, frame.bottom - 25,
		180, frame.bottom - 25), "PaymentRadioButton", "Payment", 0,
		B_FOLLOW_BOTTOM);
	v->AddChild(pamRadio);
	if (pam == 0)
		depRadio->SetValue(1);
	else if (pam == 1)
		pamRadio->SetValue(1);

	ypos = 25;
	this->total = total;
	this->pam = pam;
	this->theProxy = theProxy;
	this->catS = theProxy->GetCatS();
	this->targetHandler = targetHandler;
	catnum = 0;

	if (!sc)
		AddCat();
	else
	{
		list<int32>::iterator itera = sc->amtL->begin();

		for (cal::iterator iterc = sc->catL->begin(); iterc !=
			sc->catL->end(); iterc++)
		{
			AddCat();
			(*catTexts.rbegin())->SetText((*iterc)->Name().c_str());
			(*amtTexts.rbegin())->SetText(prefs->currencyToString(*itera).c_str());
			itera++;
		}
	}
}
Пример #26
0
void
PowerStatusView::Draw(BRect updateRect)
{
	bool drawBackground = Parent() == NULL
		|| (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0;
	if (drawBackground)
		FillRect(updateRect, B_SOLID_LOW);

	float aspect = Bounds().Width() / Bounds().Height();
	bool below = aspect <= 1.0f;

	font_height fontHeight;
	GetFontHeight(&fontHeight);
	float baseLine = ceilf(fontHeight.ascent);

	char text[64];
	_SetLabel(text, sizeof(text));

	float textHeight = ceilf(fontHeight.descent + fontHeight.ascent);
	float textWidth = StringWidth(text);
	bool showLabel = fShowLabel && text[0];

	BRect iconRect;

	if (fShowStatusIcon) {
		iconRect = Bounds();
		if (showLabel) {
			if (below)
				iconRect.bottom -= textHeight + 4;
			else
				iconRect.right -= textWidth + 4;
		}

		// make a square
		iconRect.bottom = min_c(iconRect.bottom, iconRect.right);
		iconRect.right = iconRect.bottom;

		if (iconRect.Width() + 1 >= kMinIconWidth
			&& iconRect.Height() + 1 >= kMinIconHeight) {
			_DrawBattery(iconRect);
		} else {
			// there is not enough space for the icon
			iconRect.Set(0, 0, -1, -1);
		}
	}

	if (showLabel) {
		BPoint point(0, baseLine);

		if (iconRect.IsValid()) {
			if (below) {
				point.x = (iconRect.Width() - textWidth) / 2;
				point.y += iconRect.Height() + 2;
			} else {
				point.x = iconRect.Width() + 2;
				point.y += (iconRect.Height() - textHeight) / 2;
			}
		} else {
			point.x = (Bounds().Width() - textWidth) / 2;
			point.y += (Bounds().Height() - textHeight) / 2;
		}

		if (drawBackground)
			SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
		else {
			SetDrawingMode(B_OP_OVER);
			if (LowColor().Brightness() > 100)
				SetHighColor(0, 0, 0);
			else
				SetHighColor(255, 255, 255);
		}

		DrawString(text, point);
	}
}
Пример #27
0
/***** Constructor ****/
DisplayView::DisplayView(BRect frame,const char *name, float tabHeight)
	: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW)//,
{
	SetViewColor(216, 216, 216);
	int space = 5;
	int boxHight = 200;
	int boxWidth = (Bounds().Width() / 2) / 2;
	int chkBoxWidth = 15;
	int chkBoxHight = 15;
	
// ---------------------
	BRect boxRect = BRect(Bounds().left + space, Bounds().top + space, Bounds().left + boxWidth, Bounds().top + boxHight);
	fBoxGeneral = new BBox(boxRect, "fBoxGeneral", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE, B_FANCY_BORDER);
	fBoxGeneral->SetLabel("General");
	
	BRect rect = BRect(boxRect.left + space, boxRect.top + space, boxRect.Width() - space, boxRect.top + chkBoxWidth);
	
/*	fChkboxFulscreen = new BCheckBox(rect, "fChkboxFulscreen", "Full Screen", new BMessage(S9x_FULLSCREEN),B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);
	fChkboxFulscreen->SetValue(settings.ui.S9x_FULLSCREEN);
	fBoxGeneral->AddChild(fChkboxFulscreen);*/
	
//	rect.OffsetBy(0, space + chkBoxHight);
	fChkboxBiLiner = new BCheckBox(rect, "fChkboxBiLiner", "Bi-Linear Mode 7", new BMessage(S9x_BILINER7), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
	fChkboxBiLiner->SetValue(settings.graphics.s9x_Mode7Interpolate);
	fBoxGeneral->AddChild(fChkboxBiLiner);

	rect.OffsetBy(0, space + chkBoxHight);	
	fChkboxShowFrameRate = new BCheckBox(rect, "fChkboxShowFrameRate", "Show Frame Rate", new BMessage(S9x_SHOWFRAMERATE), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
	fChkboxShowFrameRate->SetValue(settings.graphics.s9x_DisplayFrameRate);
	fBoxGeneral->AddChild(fChkboxShowFrameRate);

/*	rect.OffsetBy(0, space + chkBoxHight);
	fChkboxStretchImage = new BCheckBox(rect, "fChkboxStretchImage", "Stretch Image", new BMessage(S9x_STRETSHIMAGE), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
//	fChkboxStretchImage->SetValue(settings.ui.s9x_extended);
	fBoxGeneral->AddChild(fChkboxStretchImage);*/

	AddChild(fBoxGeneral);

// ---------------------
	boxRect.OffsetBy(space + boxRect.Width(), 0);
	fBoxSnesImage = new BBox(boxRect, "fBoxSnesImage", B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE, B_FANCY_BORDER);
	fBoxSnesImage->SetLabel("Snes Image");

	boxRect.OffsetBy(-(boxRect.Width()+ space), 0);
	rect = BRect(boxRect.left + space, boxRect.top + space, boxRect.Width() - space, boxRect.top + chkBoxHight);
	fChkboxExtendHeight = new BCheckBox(rect, "fChkboxExtendHeight", "Extend Height", new BMessage(S9x_EXTENDED), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
	fChkboxExtendHeight->SetValue(settings.ui.s9x_extended);
	fBoxSnesImage->AddChild(fChkboxExtendHeight);


	rect.OffsetBy(0, space + chkBoxHight);
	fChkboxRender16Bit = new BCheckBox(rect, "fChkboxRender16Bit", "Render 16-bit", new BMessage(S9x_RENDER16BIT), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
	fChkboxRender16Bit->SetValue(settings.graphics.s9x_SixteenBit);
	fBoxSnesImage->AddChild(fChkboxRender16Bit);


	rect.OffsetBy(0, space + chkBoxHight);
	fChkboxTransparency = new BCheckBox(rect, "fChkboxTransparency", "Transparency", new BMessage(S9x_TRANSPARENCY), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
	fChkboxTransparency->SetValue(settings.graphics.s9x_Transparency);
	fBoxSnesImage->AddChild(fChkboxTransparency);

	rect.OffsetBy(0, space + chkBoxHight);
	fChkboxHiRes = new BCheckBox(rect, "fChkboxHiRes", "Support Hi Res", new BMessage(S9x_HIRES), B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE);	
	fChkboxHiRes->SetValue(settings.graphics.s9x_SupportHiRes);
	fBoxSnesImage->AddChild(fChkboxHiRes);

	AddChild(fBoxSnesImage);

// ---------------------
//	Lock();	
	boxRect.OffsetBy(space + boxRect.Width(), 0);
	boxRect = BRect(boxRect.left, boxRect.top, boxRect.right + boxWidth - space * 3, Bounds().bottom - (tabHeight + (space*2)));
	boxRect.OffsetBy(space + boxWidth, 0);
	fBoxFullScreen = new BBox(boxRect, "fBoxFullScreen", B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE, B_FANCY_BORDER);
	fBoxFullScreen->SetLabel("Fullscreen Display Settings");
	
	rect.OffsetTo(space, space*4);
	rect = BRect(rect.left, rect.top - space, (rect.left + boxRect.Width())- space*2 , boxRect.bottom - space*2);	
	fColumnList = new DisplayModeColumnListView (rect, "ColumnList", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW |B_NAVIGABLE);
	fColumnList->AddColumn(new DisplayModeColumn("Video Mode", 200, 10, 150, 0),0);
	fColumnList->AddColumn(new BStringColumn("Status", 100, 10, 100, 0),1);

	fBoxFullScreen->AddChild(fColumnList);
	AddChild(fBoxFullScreen);

	display_mode *modes;
	uint32 mode_count;
	BRow *cRow;
	if (BScreen().GetModeList(&modes, &mode_count) == B_NO_ERROR) {
		qsort(modes, mode_count, sizeof(display_mode), compare_mode);
		
		display_mode prevDisplayMode;
		
		for(unsigned int i = 0; i < mode_count; i++) {			
			if(compare_mode(&prevDisplayMode, &modes[i])){
				cRow = new BRow();
				cRow->SetField(new DisplayModeField(modes[i]), 0);
				cRow->SetField(new BStringField("Supported"), 1);
				fColumnList->AddRow(cRow, (int32)i);
				prevDisplayMode = modes[i];
			}
		}
	}
//	BMessage *m = new BMessage(ID_REFRESH);
//	m->AddPointer("ColumnList", fColumnList);
//	message->AddInt32("width", mode.width);
//	message->AddInt32("height", mode.height);
//	fColumnList->SetSelectionMessage(m);
	
// ---------------------
	boxRect = BRect(Bounds().left + space, Bounds().top + boxHight + space*2, boxRect.left - space, boxHight);
	fBoxOutputImageProcessing = new BBox(boxRect, "boxOutputImageProcessing", B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_NAVIGABLE, B_FANCY_BORDER);
	fBoxOutputImageProcessing->SetLabel("Output Image Processing");
	AddChild(fBoxOutputImageProcessing);	
}
Пример #28
0
void BitmapMenuItem::GetBitmapSize(float* width, float* height)
{
	BRect r = m_bitmap.Bounds();
	*width = r.Width() + 4; // 2-pixel boundary on either side
	*height = r.Height() + 4; // 2-pixel boundary on top/bottom
}
Пример #29
0
// ResourceUsageWindow::InitWindow -- Initialization Commands here
void ResourceUsageWindow::InitWindow(BList &list)
{
	BRect rtab = Bounds();
	BRect rlist = Bounds();
	rtab.top += 10;
	rlist.top += 10;
	rlist.left += 12;
	rlist.right -= 15 + B_V_SCROLL_BAR_WIDTH;
	rlist.bottom -= 47;

	// Create the TabView and Tabs
	BTabView *tabView = new BTabView(rtab,"resource_usage_tabview");
	tabView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	
	rtab = tabView->Bounds();
	rtab.InsetBy(5,5);
	
	// Create the ListViews
	BListView *IRQListView = new BListView(rlist, "IRQListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	BListView *DMAListView = new BListView(rlist, "DMAListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	BListView *IORangeListView = new BListView(rlist, "IORangeListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	BListView *memoryListView = new BListView(rlist, "memoryListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	
	BScrollView *IRQScrollView = new BScrollView("scroll_list1", IRQListView,
		B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true, B_FANCY_BORDER);
	BScrollView *DMAScrollView = new BScrollView("scroll_list2", DMAListView,
		B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true, B_FANCY_BORDER);
	BScrollView *IORangeScrollView = new BScrollView("scroll_list3",
		IORangeListView, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true,
		B_FANCY_BORDER);
	BScrollView *memoryScrollView = new BScrollView("scroll_list4",
		memoryListView, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true,
		B_FANCY_BORDER);
	
	BTab *tab = new BTab();
	tabView->AddTab(IRQScrollView, tab);
	tab->SetLabel(B_TRANSLATE("IRQ"));
	tab = new BTab();
	tabView->AddTab(DMAScrollView, tab);
	tab->SetLabel(B_TRANSLATE("DMA"));
	tab = new BTab();
	tabView->AddTab(IORangeScrollView, tab);
	tab->SetLabel(B_TRANSLATE("IO Range"));
	tab = new BTab();
	tabView->AddTab(memoryScrollView, tab);
	tab->SetLabel(B_TRANSLATE("Memory Range"));
	
	{
		uint32 mask = 1;
		
		for (int i=0;i<16;mask<<=1,i++) {
			bool first = true;
			
			for (int32 j=0; j<list.CountItems(); j++) {
				DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
				struct device_configuration *current = deviceInfo->GetCurrent();
				resource_descriptor r;
				
				int32 num = count_resource_descriptors_of_type(current,
					B_IRQ_RESOURCE);
				
				for (int32 k=0;k<num;k++) {
					get_nth_resource_descriptor_of_type(current, k, B_IRQ_RESOURCE,
							&r, sizeof(resource_descriptor));
					
					if (mask & r.d.m.mask) {
						IRQListView->AddItem(new IRQDMAItem(first ? i : -1,
							deviceInfo->GetCardName()));
						first = false;
					}
				}
			}
			
			if (first) {
				IRQListView->AddItem(new IRQDMAItem(i, ""));
			}
		}
	}
	
	{
		uint32 mask = 1;
		
		for (int i=0;i<8;mask<<=1,i++) {
			bool first = true;
			
			for (int32 j=0; j<list.CountItems(); j++) {
				DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
				struct device_configuration *current = deviceInfo->GetCurrent();
				resource_descriptor r;
				
				int32 num = count_resource_descriptors_of_type(current,
					B_DMA_RESOURCE);
				
				for (int32 k=0;k<num;k++) {
					get_nth_resource_descriptor_of_type(current, k,
						B_DMA_RESOURCE,	&r, sizeof(resource_descriptor));
					
					if (mask & r.d.m.mask) {
						DMAListView->AddItem(new IRQDMAItem(first ? i : -1,
							deviceInfo->GetCardName()));
						first = false;
					}
				}
			}
			
			if (first) {
				DMAListView->AddItem(new IRQDMAItem(i, ""));
			}
		}
	}

	{
		for (int32 j=0; j<list.CountItems(); j++) {
			DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
			struct device_configuration *current = deviceInfo->GetCurrent();
			resource_descriptor r;
			
			int32 num = count_resource_descriptors_of_type(current,
				B_IO_PORT_RESOURCE);
			
			for (int32 k=0;k<num;k++) {
				get_nth_resource_descriptor_of_type(current, k,
					B_IO_PORT_RESOURCE,	&r, sizeof(resource_descriptor));
				
				IORangeListView->AddItem(new RangeItem(r.d.r.minbase, 
					r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetCardName()));
			}
		}
	
		IORangeListView->SortItems(&RangeItem::Compare);
	}
	
	{
		for (int32 j=0; j<list.CountItems(); j++) {
			DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
			struct device_configuration *current = deviceInfo->GetCurrent();
			resource_descriptor r;
			
			int32 num = count_resource_descriptors_of_type(current,
				B_MEMORY_RESOURCE);
			
			for (int32 k=0;k<num;k++) {
				get_nth_resource_descriptor_of_type(current, k, B_MEMORY_RESOURCE,
						&r, sizeof(resource_descriptor));
				
				memoryListView->AddItem(new RangeItem(r.d.r.minbase, 
					r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetCardName()));
			}
		}
	
		memoryListView->SortItems(&RangeItem::Compare);
	}
	
	
	BBox *background = new BBox(Bounds(), "background");
	background->SetBorder(B_NO_BORDER);
	AddChild(background);
	background->AddChild(tabView);
}
Пример #30
0
TeamMonitorWindow::TeamMonitorWindow()
	:
	BWindow(BRect(0, 0, 350, 400), 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);
	layout->AddView(scrollView);

	BGroupView* groupView = new BGroupView(B_HORIZONTAL);
	layout->AddView(groupView);

	fKillButton = new BButton("kill", B_TRANSLATE("Kill application"),
		new BMessage(TM_KILL_APPLICATION));
	groupView->AddChild(fKillButton);
	fKillButton->SetEnabled(false);
	
	fQuitButton = new BButton("quit", B_TRANSLATE("Quit application"),
		new BMessage(TM_QUIT_APPLICATION));
	groupView->AddChild(fQuitButton);
	fQuitButton->SetEnabled(false);

	groupView->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());

	fDescriptionView = new TeamDescriptionView;
	layout->AddView(fDescriptionView);

	groupView = new BGroupView(B_HORIZONTAL);
	layout->AddView(groupView);

	BButton* forceReboot = new BButton("force", B_TRANSLATE("Force reboot"),
		new BMessage(TM_FORCE_REBOOT));
	groupView->GroupLayout()->AddView(forceReboot);

	BSpaceLayoutItem* glue = BSpaceLayoutItem::CreateGlue();
	glue->SetExplicitMinSize(BSize(inset, -1));
	groupView->GroupLayout()->AddItem(glue);

	fRestartButton = new BButton("restart", B_TRANSLATE("Restart the desktop"),
		new BMessage(TM_RESTART_DESKTOP));
	SetDefaultButton(fRestartButton);
	groupView->GroupLayout()->AddView(fRestartButton);

	glue = BSpaceLayoutItem::CreateGlue();
	glue->SetExplicitMinSize(BSize(inset, -1));
	groupView->GroupLayout()->AddItem(glue);

	fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
		new BMessage(TM_CANCEL));
	SetDefaultButton(fCancelButton);
	groupView->GroupLayout()->AddView(fCancelButton);

	BSize preferredSize = layout->View()->PreferredSize();
	if (preferredSize.width > Bounds().Width())
		ResizeTo(preferredSize.width, Bounds().Height());
	if (preferredSize.height > Bounds().Height())
		ResizeTo(Bounds().Width(), preferredSize.height);

	BRect screenFrame = BScreen(this).Frame();
	BPoint point;
	point.x = (screenFrame.Width() - Bounds().Width()) / 2;
	point.y = (screenFrame.Height() - Bounds().Height()) / 2;

	if (screenFrame.Contains(point))
		MoveTo(point);

	SetSizeLimits(Bounds().Width(), Bounds().Width() * 2,
		Bounds().Height(), screenFrame.Height());

	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;

	if (be_app->Lock()) {
		be_app->AddCommonFilter(new BMessageFilter(B_ANY_DELIVERY,
			B_ANY_SOURCE, B_LOCALE_CHANGED, FilterLocaleChanged));
		be_app->Unlock();
	}
}