Exemple #1
0
void
SplitView::Relayout()
{
	if (fSplitter)
		fSplitter->SetOrientation(Orientation());

	float max = _Size();

	if (fPosition == -1) {
		// set initial default position in the middle
		fPosition = max * fProportion;
	}
	if (fPosition > max)
		fPosition = max;

	int32 count = CountChildren();
	float last = 0;

	for (int32 index = 0; index < count; index++) {
		BView* child = ChildAt(index);
		float size;
		if (index == 0)
			size = fPosition;
		else if (Orientation() == B_VERTICAL)
			size = (Bounds().right + 1 - last) / (count - index);
		else
			size = (Bounds().bottom + 1 - last) / (count - index);

		if (index == 1 && fSplitter == NULL) {
			// we need to add a splitter
			AddChild(fSplitter = NewSplitter(), child);
			child = fSplitter;
			count++;
		}

		if (child == fSplitter)
			size = SPLITTER_WIDTH;// + (Orientation() == B_VERTICAL ? 0 : 1);

		if (Orientation() == B_VERTICAL) {
			child->MoveTo(last, 0);
			child->ResizeTo(size, Bounds().Height());
		} else {
			child->MoveTo(0, last);
			child->ResizeTo(Bounds().Width(), size);
		}

		last += size + 1;
	}
}
Exemple #2
0
TestWindow::TestWindow(BApplication* myApp)
	: BWindow(BRect(20,20,100,100),
	  "Code Profile", B_TITLED_WINDOW, 0)
{
	BRect frm = Bounds();

	BView* myview = new BView(BRect(),"testView",0,0);
	
	BOutlineListView* olist =
		new BOutlineListView(BRect(),"MyList",
							B_SINGLE_SELECTION_LIST,B_FOLLOW_NONE);
	if( myview && olist ) {
		myview->AddChild(olist);
		BView* vw = olist;
		vw->SetViewColor(0xc0,0xc0,0xc0);
		vw->Invalidate();
		vw->SetLowColor(0xc0,0xc0,0xc0);
		vw->Invalidate();
		vw->SetHighColor(0x00,0x00,0x00);
		vw->Invalidate();
		vw->SetFont(be_bold_font);
		this->AddChild(myview);
		BRect frm = vw->Frame();
		vw->ResizeTo(1,1);
		vw->Draw(vw->Bounds());
		vw->ResizeToPreferred();
		float w=0,h=0;
		vw->GetPreferredSize(&w,&h);
		printf("Preferred size = %f x %f\n",w,h);
	}
	
	string = new BStringView(BRect(0,0,100,20),"String",
								"Ready to profile...");	
	
	if( string ) {
		string->SetViewColor(0xc0,0xc0,0xc0);
		this->AddChild(string);
		float w=0, h=0;
		string->GetPreferredSize(&w,&h);
		MoveTo(30,30);
		ResizeTo(w,h);
	}
	
	BMenuBar* menu = new BMenuBar(BRect(),"MainMenu",B_FOLLOW_NONE);
	if( menu ) {
		this->AddChild(menu);
		float w=0, h=0;
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_plain_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_bold_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_fixed_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
	}
}
Exemple #3
0
BPoint HTabSheet::AdjustBottomRightOfAllPanes()
{
	BPoint overallBottomRight(0.0, 0.0);
	for(int i=0; i<fPanes.CountItems(); ++i)
	{
		BView* pane = (BView*)fPanes.ItemAt(i);
		if (!pane)
			continue;
		BPoint paneBottomRight = DetermineBottomRightOfPane(pane);
		if (overallBottomRight.x < paneBottomRight.x)
			overallBottomRight.x = paneBottomRight.x;
		if (overallBottomRight.y < paneBottomRight.y)
			overallBottomRight.y = paneBottomRight.y;
	}
	BPoint paneLeftTop;
	for(int i=0; i<fPanes.CountItems(); ++i)
	{
		BView* pane = (BView*)fPanes.ItemAt(i);
		if (!pane)
			continue;
		if (i == 0)
			paneLeftTop = pane->Frame().LeftTop();
		pane->ResizeTo(overallBottomRight.x + 1, overallBottomRight.y + 1);
	}
	return overallBottomRight+paneLeftTop;
}
void CSettingsGroup::FrameResized(float width, float height)
{
	CBox::FrameResized(width, height);

	BRect clientRect = ClientRect();

	float ypos = clientRect.top+dist;
	float columnWidth = (clientRect.Width() - numColumns*dist - dist) / numColumns;
	
	for(int32 i=0 ; i<CountChildren() ; i++) {
		BView *child = ChildAt(i);
		
		float childWidth, childHeight;
		
		child->GetPreferredSize(&childWidth, &childHeight);
		
		int32 column = i%numColumns;
		
		child->MoveTo(clientRect.left+column*(columnWidth+dist)+dist, ypos);
		child->ResizeTo(columnWidth, childHeight);
		
		if(((i+1)%numColumns) == 0)
			ypos += childHeight+dist;
	}
}
void 
TabView::Select(int32 tab)
{
	BTabView::Select(tab);

	BView *view = ViewForTab(Selection());
	if (view != NULL) {
		BRect rect = ContainerView()->Bounds();
		view->ResizeTo(rect.Width(), rect.Height());
	}
}
Exemple #6
0
void
CropView::DoLayout()
{
	BView::DoLayout();

	if (fTarget == NULL)
		return;

	fTarget->MoveTo(-fCropLeft, -fCropTop);
	fTarget->ResizeTo(Bounds().Width() + fCropLeft + fCropRight,
		Bounds().Height() + fCropTop + fCropBottom);
}
	void AddUIGroup(const char* text, Statement* statement)
	{
		if (statement->GetChildren() == NULL) return;
		DetailsBuilder builder(fParent, GetView(), GetControlBounds(), statement, fSettings);
		builder.Visit(statement->GetChildren());
		
		if (IsTop()) {
			fBounds.OffsetTo(fBounds.left, builder.GetBounds().top);
		} else {
			BView* box = GetView();
			box->ResizeTo(box->Bounds().Width(), builder.GetBounds().top + kBoxBottomMargin);
		}
	}
Exemple #8
0
/**
 *	@brief	レイアウトを調整します。
 */
void TextDiffView::recalcLayout()
{
	BRect bounds = Bounds();
	float leftWidth = floor((bounds.Width() + 1 - B_H_SCROLL_BAR_HEIGHT - PANE_SPLITTER_WIDTH) / 2);
	float rightWidth = (bounds.Width() + 1 - PANE_SPLITTER_WIDTH) - leftWidth;

	// 左ペイン
	BView* leftPaneView = FindView(NAME_LEFT_PANE_SCROLLER);
	if (NULL != leftPaneView)
	{
		leftPaneView->MoveTo(bounds.left, bounds.top);
		leftPaneView->ResizeTo(leftWidth - 1, bounds.Height());
	}
	
	// 右ペイン
	BView* rightPaneView = FindView(NAME_RIGHT_PANE_SCROLLER);
	if (NULL != rightPaneView)
	{
		rightPaneView->MoveTo(bounds.left + leftWidth + PANE_SPLITTER_WIDTH, bounds.top);
		rightPaneView->ResizeTo(rightWidth - 1, bounds.Height());
	}
}
Exemple #9
0
/**
	Lays out child views.
*/
void SplitView::Arrange()
{
	fLayout.Frame()= Bounds();
	fLayout.Reset();
	BView *child;
	uint32 hint = LAYOUT_HINT_NONE;
	for (int32 i = 0; (child = ChildAt(i)); i++) {
		if (i == CountChildren() - 1)
			hint |= (LAYOUT_HINT_LAST | LAYOUT_HINT_CLIP);
		BRect frame = fLayout.Next(child->Frame(), hint);
		child->MoveTo(frame.LeftTop());
		child->ResizeTo(frame.Width(), frame.Height());
	}
}
Exemple #10
0
// ---------------------------------------------------------------
// main
//
// Creates a BWindow for displaying info about the BMPTranslator
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
int
main()
{
	BApplication app("application/x-vnd.obos-bmp-translator");
	BMPTranslator *ptranslator = new BMPTranslator;
	BView *view = NULL;
	BRect rect(0, 0, 225, 175);
	if (ptranslator->MakeConfigurationView(NULL, &view, &rect)) {
		BAlert *err = new BAlert("Error",
			"Unable to create the BMPTranslator view.", "OK");
		err->Go();
		return 1;
	}
	// release the translator even though I never really used it anyway
	ptranslator->Release();
	ptranslator = NULL;

	BMPWindow *wnd = new BMPWindow(rect);
	view->ResizeTo(rect.Width(), rect.Height());
	wnd->AddChild(view);
	BPoint wndpt = B_ORIGIN;
	{
		BScreen scrn;
		BRect frame = scrn.Frame();
		frame.InsetBy(10, 23);
		// if the point is outside of the screen frame,
		// use the mouse location to find a better point
		if (!frame.Contains(wndpt)) {
			uint32 dummy;
			view->GetMouse(&wndpt, &dummy, false);
			wndpt.x -= rect.Width() / 2;
			wndpt.y -= rect.Height() / 2;
			// clamp location to screen
			if (wndpt.x < frame.left)
				wndpt.x = frame.left;
			if (wndpt.y < frame.top)
				wndpt.y = frame.top;
			if (wndpt.x > frame.right)
				wndpt.x = frame.right;
			if (wndpt.y > frame.bottom)
				wndpt.y = frame.bottom;
		}
	}
	wnd->MoveTo(wndpt);
	wnd->Show();
	app.Run();

	return 0;
}
void CInternalSettingsView::FrameResized(float width, float height)
{
	float ypos = dist;

	for(int32 i=0 ; i<CountChildren() ; i++) {
		BView *child = ChildAt(i);
		
		float childWidth, childHeight;
		
		child->GetPreferredSize(&childWidth, &childHeight);
		
		child->MoveTo(dist, ypos);
		child->ResizeTo(width-2*dist, childHeight);
		
		ypos += childHeight+dist;
	}
}
void MainView::FrameResized(float width, float height) {
	BView::ResizeTo(width, height);
	
/*	return;
	
	if (scrollView) {
		scrollView->ResizeTo(width-5, height-5);
	}
	width  -= (B_H_SCROLL_BAR_HEIGHT+9);
	height -= (B_V_SCROLL_BAR_WIDTH+9);
*/	BView* list = FindView("list");
	if (list) {
		list->ResizeTo(width, height);
	}

//	FixupScrollbars();
}
Exemple #13
0
status_t
LaunchTranslatorWindow(BTranslator *translator, const char *title, BRect rect)
{
	BView *view = NULL;
	if (translator->MakeConfigurationView(NULL, &view, &rect)) {
		BAlert *err = new BAlert("Error",
			"Unable to create the view.", "OK");
		err->Go();
		return B_ERROR;
	}
	// release the translator even though I never really used it anyway
	translator->Release();
	translator = NULL;

	TranslatorWindow *wnd = new TranslatorWindow(rect, title);
	view->ResizeTo(rect.Width(), rect.Height());
	wnd->AddChild(view);
	BPoint wndpt = B_ORIGIN;
	{
		BScreen scrn;
		BRect frame = scrn.Frame();
		frame.InsetBy(10, 23);
		// if the point is outside of the screen frame,
		// use the mouse location to find a better point
		if (!frame.Contains(wndpt)) {
			uint32 dummy;
			view->GetMouse(&wndpt, &dummy, false);
			wndpt.x -= rect.Width() / 2;
			wndpt.y -= rect.Height() / 2;
			// clamp location to screen
			if (wndpt.x < frame.left)
				wndpt.x = frame.left;
			if (wndpt.y < frame.top)
				wndpt.y = frame.top;
			if (wndpt.x > frame.right)
				wndpt.x = frame.right;
			if (wndpt.y > frame.bottom)
				wndpt.y = frame.bottom;
		}
	}
	wnd->MoveTo(wndpt);
	wnd->Show();
	
	return B_OK;
}
void ArpConfigurePanel::Select(int32 tab)
{
	inherited::Select(tab);
	
	if( Parent() ) {
		BTab* tabobj = TabAt(tab);
		if( tabobj ) {
			BView* view = tabobj->View();
			BRect frame(Frame());
			if( view ) {
				view->ResizeTo(frame.Width()-mTabWidth,
							   frame.Height()-mTabHeight);
			}
		}
		
		SendSetPanel(tab);
	}
}
void CounterView::FrameResized (float width, float height)
{
  BRect BitmapRect (0, 0, width, height);
  char  TempString [40];

  m_BndRect = Bounds ();

  m_MovingDotSize = (int) (height / 20);
  if (m_MovingDotSize < 1)
    m_MovingDotSize = 1;
  m_MoveSpeed = m_MovingDotSize / 2.0;
  
  // Resize the offscreen bitmap and its view.

  if (m_BackingBitmap != NULL)
  {
    m_BackingBitmap->RemoveChild (&m_BackingView);
    delete m_BackingBitmap;
    m_BackingBitmap = NULL;
  }

  m_BackingView.ResizeTo (width, height);

  m_BackingBitmap = new BBitmap (BitmapRect, B_RGBA32, true /* Accepts subviews */);
  if (!m_BackingBitmap->IsValid ())
  {
    delete m_BackingBitmap;
    m_BackingBitmap = NULL;
  }
  else
  {
    m_BackingBitmap->AddChild (&m_BackingView);
    m_BackingBitmap->Lock ();
    m_BackingView.SetDrawingMode (B_OP_ALPHA);
    m_BackingView.SetFontSize (height * 0.8);
    sprintf (TempString, "%d", m_CurrentCount);
    m_TextStartPoint.x = width / 2 - m_BackingView.StringWidth (TempString) / 2;
    m_TextStartPoint.y = height / 2 + height * 0.25;
    m_BackingBitmap->Unlock ();
  }
}
int
main()
{
	BApplication app("application/x-vnd.Haiku-PPMTranslator");
	BView * v = NULL;
	BRect r(0, 0, 1, 1);
	if (MakeConfig(NULL, &v, &r)) {
		BAlert * err = new BAlert("Error", 
			B_TRANSLATE("Something is wrong with the PPMTranslator!"), 
			B_TRANSLATE("OK"));
		err->Go();
		return 1;
	}
	PPMWindow *w = new PPMWindow(r);
	v->ResizeTo(r.Width(), r.Height());
	w->AddChild(v);
	BPoint o = get_window_origin();
	{
		BScreen scrn;
		BRect f = scrn.Frame();
		f.InsetBy(10,23);
		/* if not in a good place, start where the cursor is */
		if (!f.Contains(o)) {
			uint32 i;
			v->GetMouse(&o, &i, false);
			o.x -= r.Width()/2;
			o.y -= r.Height()/2;
			/* clamp location to screen */
			if (o.x < f.left) o.x = f.left;
			if (o.y < f.top) o.y = f.top;
			if (o.x > f.right) o.x = f.right;
			if (o.y > f.bottom) o.y = f.bottom;
		}
	}
	w->MoveTo(o);
	w->Show();
	app.Run();
	return 0;
}
Exemple #17
0
// ---------------------------------------------------------------
// MakeConfigurationView
//
// Makes a BView object for configuring / displaying info about
// this translator. 
//
// Preconditions:
//
// Parameters:	ioExtension,	configuration options for the
//								translator
//
//				outView,		the view to configure the
//								translator is stored here
//
//				outExtent,		the bounds of the view are
//								stored here
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
status_t
BaseTranslator::MakeConfigurationView(BMessage *ioExtension, BView **outView,
	BRect *outExtent)
{
	if (!outView || !outExtent)
		return B_BAD_VALUE;
	if (ioExtension && fSettings->LoadSettings(ioExtension) != B_OK)
		return B_BAD_VALUE;

	BView *view = NewConfigView(AcquireSettings());
		// implemented in derived class

	if (view) {
		*outView = view;
		if ((view->Flags() & B_SUPPORTS_LAYOUT) != 0)
			view->ResizeTo(view->ExplicitPreferredSize());

		*outExtent = view->Bounds();

		return B_OK;
	} else
		return BTranslator::MakeConfigurationView(ioExtension, outView,
			outExtent);
}
Exemple #18
0
FastTraxWindow :: FastTraxWindow( entry_ref * ref  )
:	BWindow( BRect( 20, 50, 40, 100 ) , "FastTraX",
		B_MODAL_WINDOW_LOOK , B_NORMAL_WINDOW_FEEL , B_NOT_RESIZABLE )
,	fNameStr(NULL)
,	fContainsStr(NULL)
,	fSettingsWindow(NULL)
{
	// Load the settings
	fSettingsWindow = new SettingsWindow ;
	fSettingsWindow->Hide();
	fSettingsWindow->Show();
	
	BView	* topView ,
	     	* rightView ;
	BRect 	r ;
	
	float	mainWidth = 0;
	float	mainHeight = 0;
	
	topView = new ColouredView( BRect(0,0,50,20) , "top",
	                	B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ) ;

	rightView = new ColouredView( BRect(50,0,70,100) , "right",
	                	B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ) ;

	fNameView = new ColouredView( BRect(0,20,50,100) , "name",
	                	B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ) ;
	fFileView = new ColouredView( BRect(0,20,50,100) , "file",
	                	B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ) ;
	fDateView = new ColouredView( BRect(0,20,50,100) , "date",
	                	B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ) ;

	AddChild( topView ) ;
	AddChild( fNameView ) ;
	AddChild( fFileView ) ;
	AddChild( fDateView ) ;
	AddChild( rightView ) ;

	topView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ) ;
	rightView->SetViewColor( ui_color( B_MENU_BACKGROUND_COLOR ) ) ;
	fNameView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ) ;
	fFileView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ) ;
	fDateView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ) ;
	
	//=================================================================
	// Right View
	//=================================================================
	BButton * button ;
	button = new BButton( BRect( 7,5,20,15 ) , "exit", "Close",  
		new BMessage( B_QUIT_REQUESTED )  ) ;
	rightView->AddChild( button ) ;
	button->ResizeToPreferred() ;
	r = button->Frame() ;
	r.OffsetTo( r.left, r.bottom + 7 ) ;

	button = new BButton( r , "about", "About",  
		new BMessage( B_ABOUT_REQUESTED ) ) ;
	rightView->AddChild( button ) ;
	button->ResizeToPreferred() ;
	r = button->Frame() ;
	r.OffsetTo( r.left, r.bottom + 7 ) ;

	button = new BButton( r , "settings", "Settings",  
		new BMessage( Messages::SettingsRequested ) ) ;
	rightView->AddChild( button ) ;
	button->ResizeToPreferred() ;
	r = button->Frame() ;
	r.OffsetTo( r.left, r.bottom + 7 ) ;
	
	rightView->ResizeTo( r.right + 7 , r.bottom + 7 ) ;
	fFindButton = new BButton( r , "find", "Find",  
		new BMessage( Messages::StartFind ) , B_FOLLOW_LEFT | B_FOLLOW_BOTTOM ) ;
	rightView->AddChild( fFindButton ) ;
	fFindButton->ResizeToPreferred() ;
	fFindButton->MakeDefault( true ) ;

	//=================================================================
	// Top View
	//=================================================================
	fNameButton = new SlimButton( BRect( 7, 2, 25, 13 ) , "name", "Name",
		new BMessage( Messages::SetTab | 'N' ) ) ;
	topView->AddChild( fNameButton ) ;
	fNameButton->ResizeToPreferred() ;
	r = fNameButton->Frame() ;	
	r.OffsetTo( r.right + 7 , r.top ) ;

	fFileButton = new SlimButton( r , "file", "File",
		new BMessage( Messages::SetTab | 'F' ) ) ;
	topView->AddChild( fFileButton ) ;
	fFileButton->ResizeToPreferred() ;
	r = fFileButton->Frame() ;
	r.OffsetTo( r.right + 7 , r.top ) ;
	
	fDateButton = new SlimButton( r , "date", "Date",
		new BMessage( Messages::SetTab | 'D' ) ) ;
	topView->AddChild( fDateButton ) ;
	fDateButton->ResizeToPreferred() ;
	r = fDateButton->Frame() ;
	
	topView->ResizeTo( r.right + 7, r.bottom + 3 ) ;
	
	float width , top ;

	//=================================================================
	// Name Main View
	//=================================================================
	fpFolder = new TraxFolderPopUp( BRect( 5, 7, 15, 10 ), "location", "Find in:" ) ;
	fpFolder->InitFolders( ref ) ;
	fNameView->AddChild( fpFolder ) ;
	fpFolder->ResizeToPreferred() ;
	fpFolder->SetViewColor( fNameView->ViewColor() ) ;
	fpFolder->SetLowColor( fNameView->ViewColor() ) ;
	fpFolder->SetChoice( gSettings.fDefaultFolder ) ;
	r = fpFolder->Frame() ;
	width = r.right ;
	
	top = r.bottom + 10 ;
	fpName = new BTextControl( BRect( 5, top, r.right * 2, top + 10 ) ,
				"name", "Named:", "", NULL ) ;
	fNameView->AddChild( fpName ) ;
	fpName->ResizeToPreferred() ;
	fpName->SetDivider( fpName->StringWidth( "Named: " ) ) ;
	fpName->MakeFocus( true ) ;
	r = fpName->Frame() ;
	width = MathUtils::max( width, r.right ) ;

	top = r.bottom + 10 ;
	fpSubDirs = new BCheckBox( BRect( 5, top, 15, top + 10 ) ,
				"subdirs", "Include Sub-Directories", NULL ) ;
	fNameView->AddChild( fpSubDirs ) ;
	fpSubDirs->ResizeToPreferred() ;
	fpSubDirs->SetValue(1) ;
	r = fpSubDirs->Frame() ;
	width = MathUtils::max( width, r.right ) ;
	fNameView->ResizeTo( width + 10, r.bottom + 10 ) ;
	r = fNameView->Frame() ;
	
	mainWidth  = MathUtils::max( mainWidth, r.right ) ;
	mainHeight = MathUtils::max( mainHeight, r.bottom ) ;
	
	//=================================================================
	// File Main View
	//=================================================================
	fpContaining = new BTextControl( BRect( 3, 3, 10, 10 ) ,
				"containing", "Containing Text:", "", NULL ) ;
	fFileView->AddChild( fpContaining ) ;
	width = fpContaining->StringWidth( "Containing Text:" ) ;
	width *= 2.5 ;
	fpContaining->ResizeTo( width , 10 ) ;
	fpContaining->ResizeToPreferred() ;
	r = fpContaining->Frame() ;
	
	top = r.bottom + 7 ;
	StaticString * sv = new StaticString( BRect( 3, 3, 50, 10 ) , "kb",
							"kB" ) ;
	sv -> ResizeToPreferred() ;
	r = sv->Frame() ;
	width -= (r.Width() + 3) ;

	fpSizeGT = new BTextControl(
				BRect( 3, top, width - 3, top + 10 ) ,
				"size", "Size at least: ", "", NULL ) ;
	fFileView->AddChild( fpSizeGT ) ;
	fpSizeGT->ResizeToPreferred() ;
	fpSizeGT->SetDivider( fpContaining->Divider() ) ;
	r = fpSizeGT->Frame() ;
	fpSizeGT->ResizeTo( width - 6, r.Height() ) ;
	r = fpSizeGT->Frame() ;

	top = r.bottom - sv->Frame().Height() ;
	sv->MoveTo( width , top ) ;
	fFileView->AddChild( sv ) ;
	
	top = r.bottom + 4 ;
	sv = new StaticString( BRect( 3, 3, 50, 10 ) , "kb",
							"kB" ) ;
	sv -> ResizeToPreferred() ;
	r = sv->Frame() ;

	fpSizeLT = new BTextControl(
				BRect( 3, top, width - 3, top + 10 ) ,
				"size", "Size less than: ", "", NULL ) ;
	fFileView->AddChild( fpSizeLT ) ;
	fpSizeLT->ResizeToPreferred() ;
	fpSizeLT->SetDivider( fpContaining->Divider() ) ;
	r = fpSizeLT->Frame() ;
	fpSizeLT->ResizeTo( width - 6, r.Height() ) ;
	r = fpSizeLT->Frame() ;

	top = r.bottom - sv->Frame().Height() ;
	sv->MoveTo( width , top ) ;
	fFileView->AddChild( sv ) ;

	width = sv->Frame().right ;
	top = r.bottom + 7 ;
	fpKind = new StringPopUp( BRect( 3, top, width, top + 10 ) ,
				"kind", "Kind:  ") ;
	fpKind->AddStrings( sizeof(kKindStr)/sizeof(kKindStr[0]), kKindStr) ; 
	fFileView->AddChild( fpKind ) ;
	fpKind->ResizeToPreferred() ;
	r = fpKind->Frame() ;

	width = MathUtils::max( r.right, fpContaining->Frame().right ) ;
	fFileView->ResizeTo( width + 10, r.bottom + 10 ) ;

	r = fFileView->Frame() ;
	mainWidth  = MathUtils::max( mainWidth, r.right ) ;
	mainHeight = MathUtils::max( mainHeight, r.bottom ) ;
	
	//=================================================================
	// Date Main View
	//=================================================================
	sv = new StaticString( BRect( 3, 3, 50, 10 ) , "mod_string",
							"Modified " ) ;
	sv -> ResizeToPreferred() ;
	fDateView->AddChild( sv ) ;
	sv->SetViewColor( fDateView->ViewColor() ) ;
	sv->SetLowColor( fDateView->ViewColor() ) ;
	r = sv->Frame() ;
	width = r.right ;
	
	fpModAfter  = new BTextControl( BRect( width, 3, r.right * 2, 10 ) ,
				"mod_after", "after:", "", NULL ) ;
	fDateView->AddChild( fpModAfter ) ;
	fpModAfter->ResizeToPreferred() ;
	r = fpModAfter->Frame() ;

	fpModBefore = new BTextControl( BRect( width, r.bottom + 3, r.right * 2, r.bottom + 10 ) ,
				"mod_before", "before:", "", NULL ) ;
	fDateView->AddChild( fpModBefore ) ;
	fpModBefore->ResizeToPreferred() ;

	width = fpModBefore->StringWidth( "before: " ) ;
	fpModAfter ->ResizeTo( width * 4, r.Height() ) ;
	fpModBefore->ResizeTo( width * 4, r.Height() ) ;

	fpModAfter ->SetDivider( width ) ;
	fpModBefore->SetDivider( width ) ;

	r = fpModAfter->Frame() ;
	sv->MoveTo( 3, r.bottom - sv->Frame().Height()/3 ) ;

	r = fpModBefore->Frame() ;
	top = r.bottom + 5 ;
	r = sv->Frame() ;
	width = r.right ;
	sv = new StaticString( BRect( 3, top, 50, top + 5 ) , "cre_string",
							"Created " ) ;
	sv -> ResizeToPreferred() ;
	fDateView->AddChild( sv ) ;
	sv->SetViewColor( fDateView->ViewColor() ) ;
	sv->SetLowColor( fDateView->ViewColor() ) ;
	
	fpCreAfter  = new BTextControl( BRect( width, top, r.right * 2, top + 5 ) ,
				"cre_after", "after:", "", NULL ) ;
	fDateView->AddChild( fpCreAfter ) ;
	fpCreAfter->ResizeToPreferred() ;
	r = fpCreAfter->Frame() ;

	fpCreBefore = new BTextControl( BRect( width, r.bottom + 3, r.right * 2, r.bottom + 10 ) ,
				"cre_before", "before:", "", NULL ) ;
	fDateView->AddChild( fpCreBefore ) ;
	fpCreBefore->ResizeToPreferred() ;

	width = fpCreBefore->StringWidth( "before: " ) ;
	fpCreAfter ->ResizeTo( width * 4, r.Height() ) ;
	fpCreBefore->ResizeTo( width * 4, r.Height() ) ;

	fpCreAfter ->SetDivider( width ) ;
	fpCreBefore->SetDivider( width ) ;

	r = fpCreAfter->Frame() ;
	sv->MoveTo( 3, r.bottom - sv->Frame().Height()/3 ) ;

	r = fpCreBefore->Frame() ;
	fDateView->ResizeTo( r.right + 10, r.bottom + 10 ) ;

	r = fDateView->Frame() ;
	mainWidth  = MathUtils::max( mainWidth, r.right ) ;
	mainHeight = MathUtils::max( mainHeight, r.bottom ) ;

	//=================================================================
	// Fit Together
	//=================================================================
	float middle = MathUtils::max( topView->Frame().right , mainWidth ) ;
	float bottom = MathUtils::max( rightView->Frame().bottom , mainHeight ) ;

	width = middle - 10 ;
	fpFolder->ResizeTo( width, fpFolder->Frame().Height() ) ;	
	fpName->ResizeTo(   width, fpName  ->Frame().Height() ) ;	
	fNameView->ResizeTo( width + 10, r.bottom + 10 ) ;

	float height = bottom - topView->Frame().bottom ;

	topView->ResizeTo( middle, topView->Frame().Height() ) ;	
	rightView->MoveTo( middle + 5, 0 ) ;
	rightView->ResizeTo( rightView->Frame().Width(), bottom ) ;
	fNameView->MoveTo( 0, topView->Frame().bottom + 3) ;
	fNameView->ResizeTo( middle, height ) ;
	fFileView->MoveTo( 0, topView->Frame().bottom + 3) ;
	fFileView->ResizeTo( middle, height ) ;
	fDateView->MoveTo( 0, topView->Frame().bottom + 3) ;
	fDateView->ResizeTo( middle, height ) ;

	//=================================================================
	// Resize Window
	//=================================================================
	ResizeTo( rightView->Frame().right , rightView->Frame().bottom ) ;
	BView * bar ;
	bar = new BarView( BRect( middle,0,middle+4,bottom), "bar1" ) ;
	AddChild( bar ) ;
	bar = new RidgeView( BRect( 0, topView->Frame().bottom, middle-1, topView->Frame().bottom + 2 ), "bar2", B_HORIZONTAL ) ;
	AddChild( bar ) ;
	
	fCurrentView = fNameView ;
	fDisabledButton = fNameButton ;
	fNameButton->SetEnabled( false ) ;
	fFileView->Hide() ;
	fDateView->Hide() ;
}
/*!	\function	ColorUpdateWindow::ColorUpdateWindow
 *	\brief		Constructor.
 *	\param[in]	corner	One of the corners of the window IN SCREEN COORDINATES!
 *	\param[in]	label	Label of the color. (Usually name of the category).
 *	\param[in]	enableEditingLabel	If "true", label can be edited. If "false", it's constant.
 *	\param[in]	title			Title of the window
 *	\param[in]	defaultColor	Original color. Defaults to black.
 *	\param[in]	targetLooper	The target which receives message with the results.
 *	\param[in]	currentScreen	Defines the screen the program runs in. Usually it's
 *								B_MAIN_SCREEN_ID.
 *	\param[in]	message			The template message to be used. If this parameter is NULL,
 *								a new message is constructed.
 */
ColorUpdateWindow::ColorUpdateWindow( BPoint corner,
								  	  BString& label,
								  	  rgb_color &defaultColor,
								  	  bool enableEditingLabel,
								  	  BString title,
								      BHandler *targetHandler,
								      screen_id currentScreen,
								   	  BMessage* message )
	:
	BWindow( BRect( 100, 100, 300, 500 ),
			 title.String(),
			 B_MODAL_WINDOW,
			 B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS | B_WILL_ACCEPT_FIRST_CLICK ),
	originalString( label ),
	originalColor( defaultColor),
	labelView( NULL ),
	okButton( NULL ),
	revertButton( NULL ),
	messageToSend( NULL ),
	target( targetHandler ),
	dirty( false )
{
	BSize layoutSize;
	BLayoutItem* item = NULL;
	float width, height, dontCare;
	BView* background = new BView( this->Bounds(),
								   "Background",
								   B_FOLLOW_LEFT | B_FOLLOW_TOP,
								   B_FRAME_EVENTS | B_WILL_DRAW );
	if ( !background )
	{
		/* Panic! */
		exit(1);
	}
	background->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );	
	
	this->enableEditingLabel = enableEditingLabel;
	
	/* There are three parts in the interface of the control.
	 * Upmost is the label, which, according to the user's settings,
	 * can be editable or not.
	 * Next is the color control.
	 * Last is the row of two buttons, Revert and Ok.
	 */

	// Debugging
	printf( "Color Selected = %u, Color Reverted = %u.\n",
			kColorSelected,
			kColorReverted );

	// Construct background view and layout
	BGridLayout* layout = new BGridLayout( B_VERTICAL );
	if ( !layout ) { /* Panic! */ exit(1); }
	layout->SetInsets( 5, 5, 5, 5 );
	
	background->SetLayout( layout );
	this->AddChild( background );

	// Constructing the name label, editable or not.
	if ( enableEditingLabel )
	{
		labelView = new BTextControl( BRect(0, 0, 1, 1),
									  "Label",
								   	  NULL,
								   	  label.String(),
								   	  NULL );
	} else {
		labelView = new BStringView( BRect (0, 0, 1, 1),
									 "Label",
									 label.String() );
	}
	if ( !labelView )
	{
		/* Panic! */
		exit(1);
	}
	labelView->ResizeToPreferred();
	item = layout->AddView( labelView, 0, 0, 3, 1 );
	if ( !item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_CENTER ) );
//	item->SetExplicitMinSize( BSize( width, height ) );
	
	// Construct color control
	BMessage* toSend = new BMessage( kColorChanged );
	if ( !toSend ) { /* Panic! */ exit(1); }
	colorControl = new BColorControl( BPoint( 0, 0 ),
								      B_CELLS_32x8,
								      4.0,
								      "Color Control",
								      toSend );
	if ( !colorControl )
	{
		/* Panic! */
		exit(1);
	}
	colorControl->GetPreferredSize( &width, &height );
	colorControl->ResizeTo( width, height );
	colorControl->SetTarget( this );
	item = layout->AddView( colorControl, 0, 1, 3, 1 );
	if ( !item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );

	// Construct last two buttons
	// Revert button
	toSend = new BMessage( kColorReverted );
	if ( !toSend ) { /* Panic! */ exit(1); }
	revertButton = new BButton( BRect( 0, 0, 1, 1),
								"Revert button",
								"Revert",
								toSend );
	if ( !revertButton ) { /* Panic! */ exit(1); }
	revertButton->ResizeToPreferred();
	
	// Ok button
	toSend = new BMessage( kColorSelected );
	if ( !toSend ) { /* Panic! */ exit(1); }
	okButton = new BButton( BRect( 0, 0, 1, 1),
						    "Ok button",
						    "Ok",
						    toSend,
						    B_FOLLOW_RIGHT | B_FOLLOW_TOP );
	if ( !okButton ) { /* Panic! */ exit(1); }
	okButton->ResizeToPreferred();
	
	// Attach the buttons to current layout
	item = layout->AddView( revertButton, 0, 2 );
	if ( ! item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_MIDDLE ) );
		// Note I'm skipping one cell - this is for showing current color!
	item = layout->AddView( okButton, 2, 2 );
	if ( ! item ) { /* Panic! */ exit(1); }
	item->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_MIDDLE ) );
	
	// Make "Ok" button the default
	okButton->MakeDefault( true );
	
	// Now, find the correct place for this window. 
	// We have one of the corners from constructor, we need to position the window
	// in such manner that it will be fully visible and keep one of the corners in
	// the specified point.
	layout->Relayout( true );
	layoutSize = layout->PreferredSize();
	this->ResizeTo( layoutSize.width, layoutSize.height );
	background->ResizeTo( layoutSize.width, layoutSize.height );
	
	float windowWidth = layoutSize.width, windowHeight = layoutSize.height;
	BScreen* mainScreen = new BScreen( currentScreen ); // Get access to current screen
	display_mode currentDisplayMode;
	mainScreen->GetMode( &currentDisplayMode );		// Obtain the width and height of screen
	
	// The following booleans uniquely define where the window be located regarding
	// given corner.
	bool leftFromCorner = false, upFromCorner = false;
	
	// Check where the window should span regarding to the corner
	if ( corner.x + windowWidth >= currentDisplayMode.virtual_width )
	{
		if ( corner.x - windowWidth < 0 )
		{
			corner.x = 0;
			leftFromCorner = false;
		}
		else
		{
			leftFromCorner = true;
		}
	}
	
	if ( corner.y + windowHeight >= currentDisplayMode.virtual_height )
	{
		if ( corner.y - windowHeight < 0 )
		{
			corner.y = 0;
			upFromCorner = false;
		}
		else
		{
			upFromCorner = true;
		}	
	}
	
	// Calculate new top-left corner of the window
	if ( leftFromCorner ) 	{ corner.x -= windowWidth; }
	if ( upFromCorner )		{ corner.y -= windowHeight; }
	
	// Move the window to calculated position
	this->MoveTo( corner );
	
	// Show the window
	this->Show();
	colorControl->Invoke();
}	// <-- end of constructor for ColorUpdateWindow
Exemple #20
0
void HDialog::CreateField(int kind, BPositionIO& data, BView*& inside)
{
	dRect r;
	char name[256];
	char label[256];
	uint32 cmd;
	BView *v;

	switch (kind)
	{
		case 'btn ':
			data >> r >> name >> label >> cmd;
			inside->AddChild(v = new BButton(r.ToBe(), name, label, new BMessage(cmd)));
			if (cmd == msg_OK || strcmp(name, "ok") == 0)
				SetDefaultButton(static_cast<BButton*>(v));
			break;
		case 'radb':
			data >> r >> name >> label;
			inside->AddChild(new BRadioButton(r.ToBe(), name, label, new BMessage(msg_FieldChanged)));
			break;
		case 'chkb':
			data >> r >> name >> label;
			inside->AddChild(new BCheckBox(r.ToBe(), name, label, new BMessage(msg_FieldChanged)));
			break;
		case 'edit':
		{
			char val[256], allowed[256];
			short max, divider;
			data >> r >> name >> label >> val >> allowed >> max >> divider;

			BRect b = r.ToBe();

			inside->AddChild(v = new BTextControl(b, name, *label ? label : NULL,
				val, new BMessage(msg_FieldChanged), B_FOLLOW_NONE));

			BTextView *tv = static_cast<BTextControl*>(v)->TextView();
			if (*allowed)
			{
				for (int i = 0; i < 256; i++)
					if (isprint(i))
					{
						if (strchr(allowed, i)) tv->AllowChar(i);
						else tv->DisallowChar(i);
					}
			}

			if (max) tv->SetMaxBytes(max);
			if (divider) static_cast<BTextControl*>(v)->SetDivider(divider * gFactor);

			if (v->Bounds().Height() < b.Height())
			{
				float d = v->Bounds().Height() - tv->Bounds().Height();
				v->ResizeTo(b.Width(), b.Height());
				tv->ResizeTo(tv->Bounds().Width(), b.Height() - d);
			}
			break;
		}
		case 'capt':
			data >> r >> name >> label;
			inside->AddChild(v = new BStringView(r.ToBe(), name, label));
			v->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
			break;
		case 'popu':
		{
			short id, div;
			data >> r >> name >> label >> id >> div;
			inside->AddChild(v = new BMenuField(r.ToBe(), name, *label ? label : NULL,
				HResources::GetMenu(id, true)));
			if (div) static_cast<BMenuField*>(v)->SetDivider(div * gFactor);
			break;
		}
		case 'tabb':
			data >> r >> name;
			inside->AddChild(v = new HTabSheet(r.ToBe(), name));
			inside = v;
			break;
		case 'tabe':
			inside = inside->Parent();
			break;
		case 'shet':
			data >> name >> label;
			inside = dynamic_cast<HTabSheet*>(inside)->AddSheet(name, label);
			break;
		case 'shte':
			inside = inside->Parent();
			break;
		case 'box ':
			data >> r >> name;
			inside->AddChild(v = new BBox(r.ToBe(), name));
			if (*name) dynamic_cast<BBox*>(v)->SetLabel(name);
			v->SetFont(be_plain_font);
			inside = v;
			break;
		case 'boxe':
			inside = inside->Parent();
			break;
		case 'list':
		case 'olst':
		{
			data >> r >> name;

			BRect lr = r.ToBe();
			lr.right -= B_V_SCROLL_BAR_WIDTH;

			BListView *lv;
			if (kind == 'list')
				lv = new BListView(lr, name);
			else
				lv = new BOutlineListView(lr, name);
			strcat(name, "_scr");
			inside->AddChild(new BScrollView(name, lv, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true));
			break;
		}
		case 'clct':
		{
			data >> r >> name >> label;
			rgb_color c = { 255, 100, 100, 0 };
			inside->AddChild(v = new HColorControl(r.ToBe(), name, label, c));
			v->SetViewColor(inside->ViewColor());
			break;
		}
		case 'line':
		{
			HDlogView *dv = dynamic_cast<HDlogView*>(inside);

			data >> r;

			if (dv)
				dv->AddMyLine(r.ToBe());
			break;
		}
		case 'sldr':
		{
			int32 msg, vMin, vMax, thumb;
			data >> r >> name >> label >> msg >> vMin >> vMax >> thumb;
			inside->AddChild(new BSlider(r.ToBe(), name, label, new BMessage(msg), vMin, vMax, (thumb_style)thumb));
			break;
		}
		default:
		{
			if (sFieldMap && sFieldMap->find(kind) != sFieldMap->end())
				(*sFieldMap)[kind](kind, data, inside);
			else
				throw HErr("Unknown type for dialog item (%4.4s)", &kind);
		}
	}
} /* HDialog::CreateField */
Exemple #21
0
BView *
DefaultMediaTheme::MakeViewFor(BParameterGroup& group, const BRect* hintRect)
{
	CALLED();

	if (group.Flags() & B_HIDDEN_PARAMETER)
		return NULL;

	BRect rect;
	if (hintRect != NULL)
		rect = *hintRect;

	GroupView *view = new GroupView(rect, group.Name());

	// Create the parameter views - but don't add them yet

	rect.OffsetTo(B_ORIGIN);
	rect.InsetBySelf(5, 5);

	BList views;
	for (int32 i = 0; i < group.CountParameters(); i++) {
		BParameter *parameter = group.ParameterAt(i);
		if (parameter == NULL)
			continue;

		BView *parameterView = MakeSelfHostingViewFor(*parameter,
			hintRect ? &rect : NULL);
		if (parameterView == NULL)
			continue;

		parameterView->SetViewColor(view->ViewColor());
			// ToDo: dunno why this is needed, but the controls
			// sometimes (!) have a white background without it

		views.AddItem(parameterView);
	}

	// Identify a title view, and add it at the top if present

	TitleView *titleView = dynamic_cast<TitleView *>((BView *)views.ItemAt(0));
	if (titleView != NULL) {
		view->AddChild(titleView);
		rect.OffsetBy(0, titleView->Bounds().Height());
	}

	// Add the sub-group views

	rect.right = rect.left + 20;
	rect.bottom = rect.top + 20;
	float lastHeight = 0;

	for (int32 i = 0; i < group.CountGroups(); i++) {
		BParameterGroup *subGroup = group.GroupAt(i);
		if (subGroup == NULL)
			continue;

		BView *groupView = MakeViewFor(*subGroup, &rect);
		if (groupView == NULL)
			continue;

		if (i > 0) {
			// add separator view
			BRect separatorRect(groupView->Frame());
			separatorRect.left -= 3;
			separatorRect.right = separatorRect.left + 1;
			if (lastHeight > separatorRect.Height())
				separatorRect.bottom = separatorRect.top + lastHeight;

			view->AddChild(new SeparatorView(separatorRect));
		}

		view->AddChild(groupView);

		rect.OffsetBy(groupView->Bounds().Width() + 5, 0);

		lastHeight = groupView->Bounds().Height();
		if (lastHeight > rect.Height())
			rect.bottom = rect.top + lastHeight - 1;
	}

	view->ResizeTo(rect.left + 10, rect.bottom + 5);
	view->SetContentBounds(view->Bounds());

	if (group.CountParameters() == 0)
		return view;

	// add the parameter views part of the group

	if (group.CountGroups() > 0) {
		rect.top = rect.bottom + 10;
		rect.bottom = rect.top + 20;
	}

	bool center = false;

	for (int32 i = 0; i < views.CountItems(); i++) {
		BView *parameterView = static_cast<BView *>(views.ItemAt(i));

		if (parameterView->Bounds().Width() + 5 > rect.Width())
			rect.right = parameterView->Bounds().Width() + rect.left + 5;

		// we don't need to add the title view again
		if (parameterView == titleView)
			continue;

		// if there is a BChannelSlider (ToDo: or any vertical slider?)
		// the views will be centered
		if (dynamic_cast<BChannelSlider *>(parameterView) != NULL)
			center = true;

		parameterView->MoveTo(parameterView->Frame().left, rect.top);
		view->AddChild(parameterView);

		rect.OffsetBy(0, parameterView->Bounds().Height() + 5);
	}

	if (views.CountItems() > (titleView != NULL ? 1 : 0))
		view->ResizeTo(rect.right + 5, rect.top + 5);

	// center the parameter views if needed, and tweak some views

	float width = view->Bounds().Width();

	for (int32 i = 0; i < views.CountItems(); i++) {
		BView *subView = static_cast<BView *>(views.ItemAt(i));
		BRect frame = subView->Frame();

		if (center)
			subView->MoveTo((width - frame.Width()) / 2, frame.top);
		else {
			// tweak the PopUp views to look better
			if (dynamic_cast<BOptionPopUp *>(subView) != NULL)
				subView->ResizeTo(width, frame.Height());
		}
	}

	view->SetContentBounds(view->Bounds());
	return view;
}
// SavePanel class
SavePanel::SavePanel(const char* name,
					 BMessenger* target,
					 entry_ref* startDirectory,
					 uint32 nodeFlavors,
					 bool allowMultipleSelection,
					 BMessage* message,
					 BRefFilter* filter,
					 bool modal,
					 bool hideWhenDone)
	: BFilePanel(B_SAVE_PANEL, target, startDirectory,
				 nodeFlavors, allowMultipleSelection,
				 message, filter, modal, hideWhenDone),
	  BHandler(name),
	  fConfigWindow(NULL),
	  fFormatM(NULL),
	  fExportMode(EXPORT_MODE_ICON_RDEF)
{
	BWindow* window = Window();
	if (!window || !window->Lock())
		return;

	window->SetTitle(B_TRANSLATE("Save image"));

	// add this instance as BHandler to the window's looper
	window->AddHandler(this);
	
	// find a couple of important views and mess with their layout
	BView* background = Window()->ChildAt(0);
	BButton* cancel = dynamic_cast<BButton*>(background->FindView("cancel button"));
	BView* textview = background->FindView("text view");
	BScrollBar* hscrollbar = dynamic_cast<BScrollBar*>(background->FindView("HScrollBar"));

	if (!background || !cancel || !textview || !hscrollbar) {
		printf("SavePanel::SavePanel() - couldn't find necessary controls.\n");
		return;
	}

	_BuildMenu();

	BRect rect = textview->Frame();
	rect.top = cancel->Frame().top;
	font_height fh;
	be_plain_font->GetHeight(&fh);
	rect.bottom = rect.top + fh.ascent + fh.descent + 5.0;

	fFormatMF = new BMenuField(rect, "format popup", B_TRANSLATE("Format"),
								fFormatM, true,	
								B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
								B_WILL_DRAW | B_NAVIGABLE);
	fFormatMF->SetDivider(be_plain_font->StringWidth(
		B_TRANSLATE("Format")) + 7);
	fFormatMF->MenuBar()->ResizeToPreferred();
	fFormatMF->ResizeToPreferred();

	float height = fFormatMF->Bounds().Height() + 8.0;

	// find all the views that are in the way and
	// move up them up the height of the menu field
	BView *poseview = background->FindView("PoseView");
	if (poseview) poseview->ResizeBy(0, -height);
	BButton *insert = (BButton *)background->FindView("default button");
	if (hscrollbar) hscrollbar->MoveBy(0, -height);
	BScrollBar *vscrollbar = (BScrollBar *)background->FindView("VScrollBar");
	if (vscrollbar) vscrollbar->ResizeBy(0, -height);
	BView *countvw = (BView *)background->FindView("CountVw");
	if (countvw) countvw->MoveBy(0, -height);
	textview->MoveBy(0, -height);

#if HAIKU_TARGET_PLATFORM_DANO
	fFormatMF->MoveTo(textview->Frame().left, fFormatMF->Frame().top + 2);
#else
	fFormatMF->MoveTo(textview->Frame().left, fFormatMF->Frame().top);
#endif

	background->AddChild(fFormatMF);

	// Build the "Settings" button relative to the format menu
	rect = cancel->Frame();
	rect.OffsetTo(fFormatMF->Frame().right + 5.0, rect.top);
	fSettingsB = new BButton(rect, "settings", 
							 B_TRANSLATE("Settings"B_UTF8_ELLIPSIS),
							 new BMessage(MSG_SETTINGS),
							 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
							 B_WILL_DRAW | B_NAVIGABLE);
	fSettingsB->ResizeToPreferred();
	background->AddChild(fSettingsB);
	fSettingsB->SetTarget(this);

	textview->ResizeTo(fSettingsB->Frame().right - fFormatMF->Frame().left,
					   textview->Frame().Height());

	// Make sure the smallest window won't draw the "Settings" button over anything else
	float minWindowWidth = textview->Bounds().Width()
							+ cancel->Bounds().Width()
							+ (insert ? insert->Bounds().Width() : 0.0)
							+ 90;
	Window()->SetSizeLimits(minWindowWidth, 10000, 250, 10000);
	if (Window()->Bounds().IntegerWidth() + 1 < minWindowWidth)
		Window()->ResizeTo(minWindowWidth, Window()->Bounds().Height());


	window->Unlock();
}
Exemple #23
0
void TestWindow::MakeTermSettings()
{
	BView* settings = 0;
	BView* root = 0;
	BWindow* win = 0;
	
	try {
		// Pick some arbitrary initial frame for the window.
		BRect initFrame(0,0,100,100);
		
		// Create our three objects: the settings view, the top-level view
		// in the window, and the window itself.
		settings = GetTermSettings(BMessenger(), BMessage());
		root = new BView(initFrame, "root", B_FOLLOW_ALL, B_WILL_DRAW);
		win = new BWindow(initFrame, "Terminal Settings",
							B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
							B_ASYNCHRONOUS_CONTROLS);
		
		// Set the background color of the root view and add it to the window.
		root->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		win->AddChild(root);
		
		// Set the size and position of the settings view -- inset a little
		// from the root -- and add it.
		float fw = be_plain_font->StringWidth("W");
		font_height fhs;
		be_plain_font->GetHeight(&fhs);
		float fh = fhs.ascent+fhs.descent+fhs.leading;
		
		settings->MoveTo(fw, fh);
		settings->ResizeTo(initFrame.right-fw*2, initFrame.bottom-fh*2);
		root->AddChild(settings);
		
		win->Run();
		mTermWin = win;
		mTermSet = settings;
		
		if( root ) {
			// Send a message to the view with our current global settings.
			// If the view is an ArpRootView, it will get the message and
			// know what to do with it.
			const BMessage* curGlobs = this->root->Globals()->GlobalValues();
			if( curGlobs ) {
				BMessage globals(*curGlobs);
				globals.what = ARP_PREF_MSG;
				BMessage ret;
				mTermSet.SendMessage(&globals, &ret);
			}
		}
		
		// Get preferred size of settings view, and make final window dimensions
		// from this.
		float width=0, height=0;
		settings->GetPreferredSize(&width, &height);
		width += fw*2;
		height += fh*2;
		
		float minw=0,minh=0,maxw=0,maxh=0;
		win->GetSizeLimits(&minw,&maxw,&minh,&maxh);
		win->SetSizeLimits(width,maxw,height,maxh);
		
		BRect frm = Frame();
		win->ResizeTo(width, height);
		BRect cfrm = Frame();
		win->MoveTo( frm.left
					+ (frm.Width()-cfrm.Width())/2,
				 	frm.top
				 	+ (frm.Height()-cfrm.Height())/2);
		
		win->Show();
		mTermWin = win;
		mTermSet = settings;
	} catch(...) {
		delete settings;
		delete root;
		delete win;
	}
}
Exemple #24
0
void SeqSplitterView::MouseMoved(	BPoint where,
									uint32 code,
									const BMessage* message)
{
	if (code == B_ENTERED_VIEW) {
		if (mDirection == B_VERTICAL && gVrtCursor) SetViewCursor(gVrtCursor);
		if (mDirection == B_HORIZONTAL && gHrzCursor) SetViewCursor(gHrzCursor);
	}
	if( !mMouseDown || !Window() || !Window()->CurrentMessage() ) return;
	BView*	prev = PreviousSibling();
	BView*	next = NextSibling();
	if( !prev || !next ) return;
	
	// The mouse moved message's "where" field is in window
	// coordinates.  We need to use that instead of view
	// coordinates because the changes in this view's frame
	// are asynchronous with the mouse events we receive.
	BPoint	screenWhere;
	Window()->CurrentMessage()->FindPoint("where", &screenWhere);
	Window()->ConvertToScreen(&screenWhere);
	BPoint	delta = screenWhere - mPointDown;
	
	bool	locked = false;
//printf("recived mouse of %f\n", where.x);

if( Window() && Window()->Lock() ) {
	locked = true;
	Window()->BeginViewTransaction();
}
	if( mDirection == B_VERTICAL ) {
		/* Move me
		 */
		float	prevLeft = prev->Frame().left;
		float	nextRight = next->Frame().right;
		float	x = mFrameDown.left + delta.x;
		float	y = mFrameDown.top;
		if( x < prevLeft ) x = prevLeft;
		if( x + Bounds().Width() > nextRight ) x = nextRight - Bounds().Width();
		MoveTo( x, y );
		/* Move prev
		 */
		float	height = prev->Bounds().Height();
		float	prevRight = Frame().left - 1;
		prev->ResizeTo( prevRight - prevLeft, height );
		/* Move next
		 */
		height = next->Bounds().Height();
		float	nextTop = next->Frame().top;
		float	nextLeft = Frame().right + 1;
//printf("\tsending out move to %f\n", nextLeft);
		BRect	f = next->Frame();
		if( f.left != nextLeft ) next->MoveTo( nextLeft, nextTop );
		if( f.Width() != nextRight - nextLeft ) next->ResizeTo( nextRight - nextLeft, height );
#if 0
		next->MoveTo( nextLeft, nextTop );
		next->ResizeTo( nextRight - nextLeft, height );
#endif
	} else {
		/* Move me
		 */
		float	prevTop = prev->Frame().top;
		float	nextBottom = next->Frame().bottom;
		float	x = mFrameDown.left;
		float	y = mFrameDown.top + delta.y;
		if( y < prevTop ) y = prevTop;
		if( y + Bounds().Height() > nextBottom ) y = nextBottom - Bounds().Height();
		MoveTo( x, y );
		/* Move prev
		 */
		float	width = prev->Bounds().Width();
		float	prevBottom = Frame().top - 1;
		prev->ResizeTo( width, prevBottom - prevTop );
		/* Move next
		 */
		width = next->Bounds().Width();
		float	nextLeft = next->Frame().left;
		float	nextTop = Frame().bottom + 1;
		next->MoveTo( nextLeft, nextTop );
		next->ResizeTo( width, nextBottom - nextTop );
	}
if( locked ) {
	Window()->EndViewTransaction();
	Window()->Unlock();
}
}
Exemple #25
0
void
PBox::AttachedToWindow(){
	
	//calc font height (for nice control size)	
	font_height fontHeight;
	be_bold_font->GetHeight(&fontHeight);
	fFontHeight = fontHeight.descent + fontHeight.leading + fontHeight.ascent;


	BRect frame = Bounds();
	frame.InsetBy(5,5);
	
	BRect temp = frame;
	temp.bottom = temp.top + 40;	
	
	SettingsTextView *testo1=new SettingsTextView(temp,"testo",_T("Settings"));
	AddChild(testo1);
	frame.top +=40;
	//BSeparator *sep=new BSeparator(frame,"sep","cippa");
	//sep->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	//AddChild(sep);

	//frame.InsetBy(kEdgeOffset, kEdgeOffset);
	//frame.top += fFontHeight; //some space

#if SCROLLBAR
	frame.right -= B_V_SCROLL_BAR_WIDTH + 2;
#endif
	
			BView *view = new BView(frame, "", B_FOLLOW_ALL_SIDES,B_WILL_DRAW);
						
#if B_BEOS_VERSION > B_BEOS_VERSION_5
			view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
			view->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
			view->SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
#else
			view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
			view->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
			view->SetHighColor(0, 0, 0, 0);
#endif

	
			float settings_height = BuildGUI(fTemplate, fData, view);
					

			view->ResizeTo( view->Bounds().Width(), settings_height);
#if	SCROLLBAR			


			BScrollView * scroller = new BScrollView(
				"scroller", view, B_FOLLOW_ALL,
				0, false, true
			);
			float scroll_height = scroller->Bounds().Height();
			float diff = settings_height - scroll_height;
			if ( diff < 0 ) diff = 0;
			
			scroller->ScrollBar(B_VERTICAL)->SetRange(0, diff);

			view = scroller;
#endif
			fPrefView = view;

			AddChild(fPrefView);
			
			testo1->SetText(fTemplate.FindString("name"));
}