Example #1
0
bool
make_sure_frame_is_on_screen(BRect& frame, BWindow* window)
{
	BScreen* screen = window != NULL ? new BScreen(window)
		: new BScreen(B_MAIN_SCREEN_ID);

	bool success = false;
	if (frame.IsValid() && screen->IsValid()) {
		BRect screenFrame = screen->Frame();
		if (!screenFrame.Contains(frame)) {
			// make sure frame fits in the screen
			if (frame.Width() > screenFrame.Width())
				frame.right -= frame.Width() - screenFrame.Width() + 10.0;
			if (frame.Height() > screenFrame.Height())
				frame.bottom -= frame.Height() - screenFrame.Height() + 30.0;
			// frame is now at the most the size of the screen
			if (frame.right > screenFrame.right)
				frame.OffsetBy(-(frame.right - screenFrame.right), 0.0);
			if (frame.bottom > screenFrame.bottom)
				frame.OffsetBy(0.0, -(frame.bottom - screenFrame.bottom));
			if (frame.left < screenFrame.left)
				frame.OffsetBy((screenFrame.left - frame.left), 0.0);
			if (frame.top < screenFrame.top)
				frame.OffsetBy(0.0, (screenFrame.top - frame.top));
		}
		success = true;
	}
	delete screen;
	return success;
}
Example #2
0
void
ShowImageWindow::_ResizeWindowToImage()
{
	BBitmap* bitmap = fImageView->Bitmap();
	BScreen screen;
	if (bitmap == NULL || !screen.IsValid())
		return;

	// TODO: use View::GetPreferredSize() instead?
	BRect r(bitmap->Bounds());
	float width = r.Width() + B_V_SCROLL_BAR_WIDTH;
	float height = r.Height() + 1 + fBar->Frame().Height()
		+ B_H_SCROLL_BAR_HEIGHT;

	BRect frame = screen.Frame();
	const float windowBorder = 5;
	// dimensions so that window does not reach outside of screen
	float maxWidth = frame.Width() + 1 - windowBorder - Frame().left;
	float maxHeight = frame.Height() + 1 - windowBorder - Frame().top;

	// We have to check size limits manually, otherwise
	// menu bar will be too short for small images.

	float minW, maxW, minH, maxH;
	GetSizeLimits(&minW, &maxW, &minH, &maxH);
	if (maxWidth > maxW)
		maxWidth = maxW;
	if (maxHeight > maxH)
		maxHeight = maxH;
	if (width < minW)
		width = minW;
	if (height < minH)
		height = minH;

	if (width > maxWidth)
		width = maxWidth;
	if (height > maxHeight)
		height = maxHeight;

	ResizeTo(width, height);
}
Example #3
0
void
ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
{
	BScreen screen;
	if (!screen.IsValid())
		return;

	BRect r(pbitmap->Bounds());
	float width = r.Width() + 2 * PEN_SIZE + B_V_SCROLL_BAR_WIDTH;
	float height = r.Height() + 2 * PEN_SIZE + 1 + fBar->Frame().Height() +
		B_H_SCROLL_BAR_HEIGHT;

	BRect frame = screen.Frame();
	const float windowBorder = 5;
	// dimensions so that window does not reach outside of screen
	float maxWidth = frame.Width() + 1 - windowBorder - Frame().left;
	float maxHeight = frame.Height() + 1 - windowBorder - Frame().top;

	// We have to check size limits manually, otherwise
	// menu bar will be too short for small images.

	float minW, maxW, minH, maxH;
	GetSizeLimits(&minW, &maxW, &minH, &maxH);
	if (maxWidth > maxW)
		maxWidth = maxW;
	if (maxHeight > maxH)
		maxHeight = maxH;
	if (width < minW)
		width = minW;
	if (height < minH)
		height = minH;

	if (width > maxWidth)
		width = maxWidth;
	if (height > maxHeight)
		height = maxHeight;

	ResizeTo(width, height);
}
Example #4
0
void PrefsWindow::ResetToDefaults(uint32 resetFlag)
{
	prefsLock.Lock();
	
	if (resetFlag & PrefsConstants::K_RESET_COLOUR_PREFS == 1)
	{
		preferences.AddData(K_FG_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_BLACK,sizeof(rgb_color));
		preferences.AddData(K_BG_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_WHITE,sizeof(rgb_color));
		preferences.AddData(K_GEN_CMD_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_RED,sizeof(rgb_color));
		preferences.AddData(K_FORMAT_CMD_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_GREEN,sizeof(rgb_color));
		preferences.AddData(K_SPECIAL_CMD_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_PURPLE,sizeof(rgb_color));
		preferences.AddData(K_MATH_MODE_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_NAVY_BLUE,sizeof(rgb_color));
		preferences.AddData(K_COMMA_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_RED,sizeof(rgb_color));
		preferences.AddData(K_COMMENT_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_BLUE,sizeof(rgb_color));
		preferences.AddData(K_PUNC_SYMBOL_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_PURPLE,sizeof(rgb_color));
		//preferences.AddData(K_HTML_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_ORANGE,sizeof(rgb_color));	
		preferences.AddData(K_RGBTEXT_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_BLACK,sizeof(rgb_color));
		preferences.AddData(K_BUBBLE_COLOUR,B_RGB_COLOR_TYPE,&ColourConstants::K_BUBBLE_DEFAULT,sizeof(rgb_color));
	}			
	
	if (resetFlag & PrefsConstants::K_RESET_COMMAND_PREFS == 1)
	{
		preferences.AddString(K_LATEX_CMD, "latex $.tex");
		preferences.AddString(K_DVIPDF_CMD, "dvipdf $.dvi");
		preferences.AddString(K_DVIPS_CMD, "dvips -o $.ps $.dvi");
		preferences.AddString(K_PS2PDF_CMD, "ps2pdf $.ps");
		preferences.AddString(K_PDFLATEX_CMD, "pdflatex $.tex");
		preferences.AddString(K_LATEX2HTML_CMD, "latex2html $.tex");
		preferences.AddString(K_POSTSCRIPT_CMD, "gs -sDEVICE=bealpha4 $.ps");
	}
	
	if (resetFlag & PrefsConstants::K_RESET_TOOLBAR_PREFS == 1)
	{			
		preferences.AddBool(K_IS_GREEK_HIDDEN, false);
		preferences.AddBool(K_IS_BIG_HIDDEN, true);
		preferences.AddBool(K_IS_BINARY_HIDDEN, true);
		preferences.AddBool(K_IS_MISC_HIDDEN, true);
		preferences.AddBool(K_IS_BIN_REL_HIDDEN, true);
		preferences.AddBool(K_IS_MMA_HIDDEN, true);
		preferences.AddBool(K_IS_INT_HIDDEN, true);
		preferences.AddBool(K_IS_TYPE_FACE_HIDDEN, true);
		preferences.AddBool(K_IS_FUNCTION_HIDDEN, true);
		
		preferences.AddBool(K_IS_TEXTBAR_INVERTED, true);
		preferences.AddBool(K_IS_RECENT_DOCS_SHOWN, true);
		preferences.AddBool(K_IS_ACTIVATION_OK, true);
	}	
	
	if (resetFlag & PrefsConstants::K_RESET_GENERAL_PREFS == 1)
	{
		preferences.AddFloat(K_FONT_SIZE, 12.0f);
		preferences.AddBool(K_AUTO_INDENT, true);
		preferences.AddBool(K_IS_SYNTAX, true);
		
		preferences.AddBool(K_IS_CASE_SENSITIVE, false);
		preferences.AddBool(K_IS_WRAP_AROUND, false);
		preferences.AddBool(K_IS_SEARCH_BACKWARDS, false);
		preferences.AddBool(K_IS_ALL_DOCS, false);	
		
		preferences.AddString(K_NUM_RECENT_DOCS, "20");	
		preferences.AddString(K_COLS, "4");
		preferences.AddString(K_ROWS, "4");
		preferences.AddString(K_DATE_FLAGS, "");
	}
		
 	BScreen screen;
	BRect mainWindowRect(0,0,500,500);
	if(screen.IsValid())
	{
		BRect f = screen.Frame();
		mainWindowRect = BRect(f.left+4,f.top+24,f.right-5,f.bottom-5);
	}	
	preferences.AddRect(K_MAIN_WINDOW_RECT, mainWindowRect);
	//???
	preferences.AddMessage(K_SPLIT_MSG, NULL);
	preferences.AddMessage(K_SPLIT_LEFT_MSG, NULL);
	
	prefsLock.Unlock();
}