Esempio n. 1
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() ;
}