KeyboardWindow::KeyboardWindow()
	:
	BWindow(BRect(0, 0, 200, 200), B_TRANSLATE_SYSTEM_NAME("Keyboard"),
		B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
		| B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
	MoveTo(fSettings.WindowCorner());

	// Add the main settings view
	fSettingsView = new KeyboardView();
	BBox* fSettingsBox = new BBox("keyboard_box");
	fSettingsBox->AddChild(fSettingsView);

	// Add the "Default" button..
	fDefaultsButton = new BButton(B_TRANSLATE("Defaults"), new BMessage(BUTTON_DEFAULTS));

	// Add the "Revert" button...
	fRevertButton = new BButton(B_TRANSLATE("Revert"), new BMessage(BUTTON_REVERT));
	fRevertButton->SetEnabled(false);

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

	AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
		.Add(fSettingsBox)
		.AddGroup(B_HORIZONTAL, 7)
			.Add(fDefaultsButton)
			.Add(fRevertButton)
			.AddGlue()
		.End()
		.SetInsets(10, 10, 10, 10)
	);

	BSlider* slider = (BSlider* )FindView("key_repeat_rate");
	if (slider !=NULL)
		slider->SetValue(fSettings.KeyboardRepeatRate());

	slider = (BSlider* )FindView("delay_until_key_repeat");
	if (slider !=NULL)
		slider->SetValue(fSettings.KeyboardRepeatDelay());

	fDefaultsButton->SetEnabled(fSettings.IsDefaultable());

	// center window if it would be off-screen
	BScreen screen;
	if (screen.Frame().right < Frame().right
		|| screen.Frame().bottom < Frame().bottom) {
		CenterOnScreen();
	}

#ifdef DEBUG
	fSettings.Dump();
#endif

	Show();
}
Ejemplo n.º 2
0
filter_result
MouseDownFilter(BMessage* message, BHandler** handlers, BMessageFilter* filter)
{
	BWindow* window = dynamic_cast<BWindow*> (filter->Looper());
	if (window == NULL)
		return B_DISPATCH_MESSAGE;

	MagStringView* magStringView = dynamic_cast<MagStringView*> (handlers[0]);
	if (magStringView == NULL)
		return B_DISPATCH_MESSAGE;

	BPoint point;
	message->FindPoint("be:view_where", &point);
	BRect bounds(magStringView->Bounds());
	if (!bounds.Contains(point))
		return B_DISPATCH_MESSAGE;

	ImageView* imageView = dynamic_cast<ImageView*>(window->FindView("image_view"));
	if (imageView == NULL)
		return B_DISPATCH_MESSAGE;

	magStringView->SetEventMask(B_POINTER_EVENTS);

	gPopUpSlider = PopUpSlider::Instantiate(BMessenger(imageView, window),
		new BMessage(HS_SET_MAGNIFYING_SCALE), 10, 1600);

	// Convert nonlinear from [0.1,16] -> [10,1600]
	float value = 1590.0 * log10((9.0 * (imageView->getMagScale() - 0.1) / 15.9)
		+ 1.0) + 10.0;

	BSlider* slider = gPopUpSlider->Slider();
	slider->SetValue(int32(value));
	slider->SetModificationMessage(new BMessage(HS_SET_MAGNIFYING_SCALE));

	BRect rect(slider->BarFrame());
	float offset = (slider->Position() * (rect.Width() - 1.0)) + 8.0;

	rect = gPopUpSlider->Bounds();
	bounds = magStringView->ConvertToScreen(bounds);

	message->FindPoint("screen_where", &point);
	gPopUpSlider->MoveTo(point.x - offset, bounds.top - rect.Height());
	gPopUpSlider->Go();

	return B_SKIP_MESSAGE;
}
Ejemplo n.º 3
0
void PrefsWindow::MessageReceived(BMessage* message)
{
	switch(message->what)
	{
		case PrefsConstants::K_PREFS_VIEW_RESET_COLOUR_DEFAULTS:
		{
			ResetToDefaults(PrefsConstants::K_RESET_COLOUR_PREFS);
		}
		break;		
		case PrefsConstants::K_PREFS_VIEW_RESET_COMMAND_DEFAULTS:
		{
			ResetToDefaults(PrefsConstants::K_RESET_COMMAND_PREFS);
		}		
		break;
		case PrefsConstants::K_PREFS_VIEW_RESET_TOOLBAR_DEFAULTS:
		{
			ResetToDefaults(PrefsConstants::K_RESET_TOOLBAR_PREFS);	
		}
		break;
		case PrefsConstants::K_PREFS_VIEW_RESET_GENERAL_DEFAULTS:
		{
			ResetToDefaults(PrefsConstants::K_RESET_GENERAL_PREFS);
		}
		break;
		case PrefsConstants::K_PREFS_UPDATE:
		{			
			//update the preferences message, from view values
			BString prefsID;			
			if (message->FindString(K_PREFS_ID, &prefsID) == B_OK)
			{
				BView *changedView = m_parent->FindView(prefsID.String());
				prefsLock.Lock();
				//different view have different kinds of values
				if (is_instance_of(changedView, BTextControl))
				{
					//a textcontrol value was changed, update preferences with new text
					BTextControl *textControl = dynamic_cast<BTextControl*>(changedView);
					preferences.ReplaceString(prefsID.String(), textControl->Text());
				}
				else if (is_instance_of(changedView, BCheckBox))
				{
					//a checkbox value was changed, update preferences with new bool value(on/off)
					BCheckBox *checkBox = dynamic_cast<BCheckBox*>(changedView);
					preferences.ReplaceBool(prefsID.String(), checkBox->Value());
				}
				else if (is_instance_of(changedView, BSlider))
				{
					//a slider value was changed, update preferences with new slider value
					BSlider *slider = dynamic_cast<BSlider*>(changedView);
					preferences.ReplaceInt32(prefsID.String(), slider->Value());
				}
				else if (is_instance_of(changedView, ColourButton))
				{
					//a colourcontrol value was changed, update preferences with new colour
					ColourButton *colourControl = dynamic_cast<ColourButton*>(changedView);
					preferences.ReplaceData(prefsID.String(),B_RGB_COLOR_TYPE, &colourControl->Value(), sizeof(rgb_color));
				}
				prefsLock.Unlock();
			}
		}
		break;
		case PrefsConstants::K_LOAD_PREFERENCES:
		{
			//set preferences view values to values of the preferences message
			BString prefsID;
			if (message->FindString(K_PREFS_ID, &prefsID) == B_OK)
			{
				//find out which view value has to be updated
				BView *changedView = m_parent->FindView(prefsID.String());
				prefsLock.Lock();
				char *name;
				uint32 type;
				int32 count;
				for (int32 i = 0; preferences.GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++)
				{
					//find out what kind of field we are using
					switch (type)
					{
						case B_INT32_TYPE:
						{
							int32 value;
							preferences.FindInt32(name, &value);
							if (is_instance_of(changedView, BSlider))
							{
								BSlider *slider = dynamic_cast<BSlider*>(changedView);
								slider->SetValue(value);
							}
						}
						break;
						case B_BOOL_TYPE:
						{
							bool value;
							preferences.FindBool(name, &value);
							if (is_instance_of(changedView, BCheckBox))
							{
								BCheckBox *checkBox = dynamic_cast<BCheckBox*>(changedView);
								checkBox->SetValue(value);
							}
						}
						break;
						case B_RGB_COLOR_TYPE:
						{
							rgb_color *colour;
							ssize_t size;
							preferences.FindData(name, B_RGB_COLOR_TYPE, (const void**)&colour, &size);
							if (is_instance_of(changedView, ColourButton))
							{
								ColourButton *colourControl = dynamic_cast<ColourButton*>(changedView);
								colourControl->SetValue(*colour);
							}
						}
						break;
						case B_STRING_TYPE:
						{
							BString string;
							preferences.FindString(name, &string);
							if (is_instance_of(changedView, ColourButton))
							{
								BTextControl *textControl = dynamic_cast<BTextControl*>(changedView);
								textControl->SetText(string.String());
							}
						}
						break;
					}
				} 				
				prefsLock.Unlock();
				//make sure the new view values are drawn!
				changedView->Invalidate();
			}
		}
		break;
		default:
			BWindow::MessageReceived(message);
		break;
	}
}
void
KeyboardWindow::MessageReceived(BMessage* message)
{
	BSlider* slider = NULL;

	switch (message->what) {
		case BUTTON_DEFAULTS:
		{
			fSettings.Defaults();

			slider = (BSlider* )FindView("key_repeat_rate");
			if (slider !=NULL)
				slider->SetValue(fSettings.KeyboardRepeatRate());

			slider = (BSlider* )FindView("delay_until_key_repeat");
			if (slider !=NULL)
				slider->SetValue(fSettings.KeyboardRepeatDelay());

			fDefaultsButton->SetEnabled(false);

  			fRevertButton->SetEnabled(true);
			break;
		}
		case BUTTON_REVERT:
		{
			fSettings.Revert();

			slider = (BSlider* )FindView("key_repeat_rate");
			if (slider !=NULL)
				slider->SetValue(fSettings.KeyboardRepeatRate());

			slider = (BSlider* )FindView("delay_until_key_repeat");
			if (slider !=NULL)
				slider->SetValue(fSettings.KeyboardRepeatDelay());

			fDefaultsButton->SetEnabled(fSettings.IsDefaultable());

  			fRevertButton->SetEnabled(false);
			break;
		}
		case SLIDER_REPEAT_RATE:
		{
			int32 rate;
			if (message->FindInt32("be:value", &rate) != B_OK)
				break;
			fSettings.SetKeyboardRepeatRate(rate);

			fDefaultsButton->SetEnabled(fSettings.IsDefaultable());

			fRevertButton->SetEnabled(true);
			break;
		}
		case SLIDER_DELAY_RATE:
		{
			int32 delay;
			if (message->FindInt32("be:value", &delay) != B_OK)
				break;

			// We need to look at the value from the slider and make it "jump"
			// to the next notch along. Setting the min and max values of the
			// slider to 1 and 4 doesn't work like the real Keyboard app.
			if (delay < 375000)
				delay = 250000;
			if (delay >= 375000 && delay < 625000)
				delay = 500000;
			if (delay >= 625000 && delay < 875000)
				delay = 750000;
			if (delay >= 875000)
				delay = 1000000;

			fSettings.SetKeyboardRepeatDelay(delay);

			slider = (BSlider* )FindView("delay_until_key_repeat");
			if (slider != NULL)
				slider->SetValue(delay);

			fDefaultsButton->SetEnabled(fSettings.IsDefaultable());

			fRevertButton->SetEnabled(true);
			break;
		}

		default:
			BWindow::MessageReceived(message);
			break;
	}
}
Ejemplo n.º 5
0
BView* PrefsWindow::constructColourBox(BRect frame)
{
	BBox* colourBox = new BBox(frame);
	colourBox->SetLabel("TexView");

	float	offset = 30.0f,
			texViewWidth = 280.0f,
			texHeight = 200.0f,
			adjust = 5.0f,
			cbheight = 14.0f,
			cbspacing = 10.0f,
			bwidth = 80.0f,
			bheight = 30.0f,
			bspacing = 10.0f	
			;
			
	BRect bounds = colourBox->Bounds();
	
	float texViewX1 = bounds.right - texViewWidth - (offset * 2.0f / 3.0f);
	float texViewX2 = bounds.right - (offset * 2.0f / 3.0f) - B_V_SCROLL_BAR_WIDTH;
	BRect texViewRect(texViewX1, offset - adjust, texViewX2, offset + texHeight - adjust);	
	BRect texViewTextRect(texViewRect);
		
	/*TexView *texView = new TexView(texViewRect, texViewTextRect, prefs);
	BString sampleText = "Welcome to \\betex!\\\\\n%This is a Comment\n$Phe\\alpha r the Calculus$\n\\subsection{About \\betex}\n\\betex is \\textbf{cool}!\\\\\n``To Be Or Not To Be\'\'\n";
	texView->SetText(sampleText.String(),sampleText.Length());
	texView->MakeEditable(false);
	texView->MakeSelectable(false);
	
	BScrollView *texViewScroll = new BScrollView("textViewScroll", texView, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE, false, true, B_FANCY_BORDER);
	texViewScroll->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	colourBox->AddChild(texViewScroll);	
	texView->SetTextRect(texView->Bounds());*/	
	
	//fg colour button
	BRect ccRect((offset*2/3),offset-adjust,offset+150,offset+cbheight-adjust);	
	rgb_color fgColour;
	ColourButton *fgColourButton = new ColourButton(ccRect, GetPrefsMessage(K_FG_COLOUR), fgColour," Text");
	colourBox->AddChild(fgColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color bgColour;
	ColourButton *bgColourButton = new ColourButton(ccRect, GetPrefsMessage(K_BG_COLOUR), bgColour, "Background");
	colourBox->AddChild(bgColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color genericCmdColour;
	ColourButton *genericCmdColourButton = new ColourButton(ccRect, GetPrefsMessage(K_GEN_CMD_COLOUR), genericCmdColour, "Generic Commands");
	colourBox->AddChild(genericCmdColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color formatCmdColour;
	ColourButton *formatCmdColourButton  = new ColourButton(ccRect, GetPrefsMessage(K_FORMAT_CMD_COLOUR), formatCmdColour, "Formatting Commands");
	colourBox->AddChild(formatCmdColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color specialCmdColour;
	ColourButton *specialCmdColourButton = new ColourButton(ccRect, GetPrefsMessage(K_SPECIAL_CMD_COLOUR), specialCmdColour, "Special Commands");
	colourBox->AddChild(specialCmdColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color mathModeColour;
	ColourButton *mathModeColourButton = new ColourButton(ccRect, GetPrefsMessage(K_MATH_MODE_COLOUR), mathModeColour, "Math Mode");
	colourBox->AddChild(mathModeColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color commaColour;
	ColourButton *commaColourButton = new ColourButton(ccRect, GetPrefsMessage(K_COMMA_COLOUR), commaColour, "Quotation Marks");
	colourBox->AddChild(commaColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color commentColour;
	ColourButton *commentColourButton = new ColourButton(ccRect,GetPrefsMessage(K_COMMENT_COLOUR),commentColour,"Comments");
	colourBox->AddChild(commentColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	rgb_color puncSymbolColour;
	ColourButton *puncSymbolColourButton = new ColourButton(ccRect,GetPrefsMessage(K_PUNC_SYMBOL_COLOUR),puncSymbolColour,"Punctuation / Symbols");
	colourBox->AddChild(puncSymbolColourButton);
	
	ccRect.OffsetBy(0,cbheight+cbspacing);
	//rgb_color htmlColour;
	//ColourButton *htmlColourButton = new ColourButton(ccRect,GetPrefsMessage(K_HTML_COLOUR), htmlColour,"Urls");
	//colourBox->AddChild(htmlColourButton);
	
	BRect cbRect = colourBox->Bounds();
	BRect cbbtnRect(cbRect.right - bspacing - bwidth, cbRect.bottom - bspacing - bheight, cbRect.right - bspacing, cbRect.bottom - bspacing);
	BButton *resetColourDefaults = new BButton(cbbtnRect,"fResetColorDefaults","Defaults",new BMessage(PrefsConstants::K_PREFS_VIEW_RESET_COLOUR_DEFAULTS));
	colourBox->AddChild(resetColourDefaults);
	
	float	sliderWidth = 300.0f,
			vertOffset = 50.0f,
			minVal = 5.0f,
			maxVal = 30.0f
			;		
	BRect sliderFrame(ccRect.left, ccRect.top + vertOffset, ccRect.left + sliderWidth, ccRect.top + vertOffset + 100.0f);
	BSlider *fontSizeSlider = new BSlider(sliderFrame, K_FONT_SIZE, "Font Size", GetPrefsMessage(K_FONT_SIZE), minVal, maxVal);
	colourBox->AddChild(fontSizeSlider);
	
	fontSizeSlider->SetBarColor(ui_color(B_WINDOW_TAB_COLOR));
	fontSizeSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fontSizeSlider->SetHashMarkCount(26);
	float fontSize = 12.0f;
	fontSizeSlider->SetValue(fontSize);
	fontSizeSlider->SetLimitLabels("Small","Large");
	fontSizeSlider->SetModificationMessage(GetPrefsMessage(K_FONT_SIZE));
		
	rgb_color fire_r = {223,0,50};
	const rgb_color* fillcolor = &fire_r;
	fontSizeSlider->UseFillColor(true,fillcolor);
	
	return colourBox;
}