Пример #1
0
void
TFilePanel::SetSaveText(const char* text)
{
	if (text == NULL)
		return;

	BTextControl* textControl
		= dynamic_cast<BTextControl*>(FindView("text view"));
	if (textControl != NULL) {
		textControl->SetText(text);
		if (textControl->TextView() != NULL)
			textControl->TextView()->SelectAll();
	}
}
Пример #2
0
BTextControl*
DocInfoWindow::_AddPasswordControl(BRect r, BView* panel, const char* name,
	const char* label)
{
	BString text;
	_DocInfo()->FindString(name, &text);
	BTextControl* textControl = new BTextControl(r, name, label, "", NULL,
		B_FOLLOW_LEFT_RIGHT);
	panel->AddChild(textControl);
	textControl->ResizeToPreferred();
	textControl->TextView()->HideTyping(true);
	textControl->TextView()->SetText(text.String());

	return textControl;
}
Пример #3
0
/*
 * Returns 0 if cancel was chose, otherwise
 * returns the game no
 *
 */
unsigned GameByID(int gameno /* default # */)
{
BTextView *T;
BTextControl *tC;
register int i;
char buffer[256];


	if (!gameno) gameno = 1;

	sprintf(buffer, "%d%c", gameno, 0);

	tC = new BTextControl( *(new BRect(10, 10, 20, 50)),
			"Game Number", buffer, NULL);

	T = tC->TextView();
	/* 
	 * Make sure only #s can be entered 
	 */
	for (i = 0; i < 256; i++)
		T->DisallowChar(i);

	for (i = '0'; i < '9' + 1; i++)
		T->AllowChar(i);

	AddChild(tC)

	Show();	// start running

}
Пример #4
0
BFIV_PrefWin::BFIV_PrefWin(BRect frame)
    : BWindow(frame, "Preferences", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
{
    BRect rect = Bounds();
    BView *back;
    BTextControl *scratchPath;
    BButton *cancelButton, *okButton, *selectButton;
    font_height fontHeight;
    float fontSize, tmp;

    // private data
    filePanel = NULL;

    // some font voodoo
    be_plain_font->GetHeight(&fontHeight);
    fontSize = fontHeight.ascent + fontHeight.descent;

    // the background
    back = new BView(rect, "background", B_FOLLOW_ALL, 0);
    back->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    AddChild(back);

    // the select button
    tmp = be_plain_font->StringWidth("Select");
    rect.Set(frame.Width() - tmp - 20., 5., frame.Width() - 5., 5. + fontSize + 10.);
    selectButton = new BButton(rect, "select", "Select", new BMessage(SELECT_SCRATCH_PATH));
    back->AddChild(selectButton);

    // the path
    rect.Set(5.,5., selectButton->Frame().left - 5., 5. + fontSize + 10.);
    scratchPath = new BTextControl(rect, "path", "Scratch Location", NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
    back->AddChild(scratchPath);
    scratchPath->SetText(((BFIV_App *)be_app)->ScratchDirectory()); // current dir
    scratchPath->TextView()->MakeEditable(false); // only works after AddChild() (!!)


    // the ok button
    tmp = be_plain_font->StringWidth("OK");
    rect.Set(frame.Width() - tmp - 35., Frame().Height() - fontSize - 20., frame.Width() - 10., Frame().Height() - 10.);
    okButton = new BButton(rect, "ok", "OK", new BMessage(APPLY_PREFS_CHANGE));
    back->AddChild(okButton);
    okButton->MakeDefault(true);

    // the cancel button
    tmp = be_plain_font->StringWidth("Cancel");
    rect.Set(okButton->Frame().left - tmp - 20., okButton->Frame().top, okButton->Frame().left - 5., okButton->Frame().bottom);
    cancelButton = new BButton(rect, "cancel", "Cancel", new BMessage(B_QUIT_REQUESTED));
    back->AddChild(cancelButton);
}
Пример #5
0
Window::Window()
	: BWindow(BRect(100, 100, 590, 260), "EventMask-Test",
			B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
{
	BView* view = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(view);

	BTextControl* textControl = new BTextControl(BRect(10, 10, 290, 30),
		"text", "Type to test focus suspending:", "", NULL, B_FOLLOW_LEFT_RIGHT);
	textControl->SetDivider(textControl->StringWidth(textControl->Label()) + 8);
	view->AddChild(textControl);

	textControl = new BTextControl(BRect(300, 10, 420, 30),
		"all", "All keys:", "", NULL, B_FOLLOW_LEFT_RIGHT);
	textControl->SetDivider(textControl->StringWidth(textControl->Label()) + 8);
	view->AddChild(textControl);
	textControl->TextView()->SetEventMask(B_KEYBOARD_EVENTS, 0);

	BRect rect(10, 40, 120, 120);
	for (int32 i = 0; i < 4; i++) {
		uint32 options = 0;
		switch (i) {
			case 1:
				options = B_SUSPEND_VIEW_FOCUS;
				break;
			case 2:
				options = B_LOCK_WINDOW_FOCUS;
				break;
			case 3:
				options = B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS;
				break;
		}

		fViews[i] = new PositionView(rect, options);
		view->AddChild(fViews[i]);

		rect.OffsetBy(120, 0);
	}

	BCheckBox* checkBox = new BCheckBox(BRect(10, 130, 200, 160), "permanent", "Get all pointer events", new BMessage(kMsgPointerEvents));
	view->AddChild(checkBox);
}
Пример #6
0
Fenster::Fenster() : BWindow( BRect( 20, 40, 620, 460), "PecoRename", B_TITLED_WINDOW, 0){
// Menü
	BMenuBar* MenuBar = new BMenuBar( BRect( 0, 0, 0, 0 ), "MenuBar" );

	BMenu* Menu;

	Menu = new BMenu(STR_MENU_FILE);
	MenuBar->AddItem(Menu);

	Menu->AddItem(new BMenuItem(STR_MENU_NEW, 				new BMessage(MSG_MENU_NEW), 'N'));
	Menu->AddItem(new BMenuItem(STR_MENU_OPEN, 				new BMessage(MSG_SELECT_FILES), 'O'));
	Menu->AddSeparatorItem();
	Menu->AddItem(new BMenuItem(STR_MENU_ABOUT, 			new BMessage(B_ABOUT_REQUESTED)));
	Menu->AddSeparatorItem();
	Menu->AddItem(new BMenuItem(STR_MENU_QUIT, 				new BMessage(B_QUIT_REQUESTED), 'Q'));

	Menu = new BMenu(STR_MENU_TOOLS);
	MenuBar->AddItem(Menu);

	Menu->AddItem(new BMenuItem(STR_MENU_CREATE_SCRIPT, 	new BMessage(MSG_MENU_SCRIPT)));

	Menu = new BMenu(STR_MENU_HELP);
	MenuBar->AddItem(Menu);

	Menu->AddItem(new BMenuItem(STR_MENU_DOCU, new BMessage(MSG_MENU_DOCU)));

	AddChild( MenuBar );
// Größe bestimmen + Fenster anpassen
	float BarWidth, BarHeight;
	MenuBar->GetPreferredSize ( &BarWidth, &BarHeight );
	SetSizeLimits( 600, 600, 10000, 155 + BarHeight + 5 * be_plain_font->Size() + 2 * be_bold_font->Size());

// Main Frame
	BRect MainFrame = Bounds();
	MainFrame.top += BarHeight;

	MainView* mainView = new MainView( MainFrame );
	AddChild( mainView );
	
	BTextControl*	TextControl = (BTextControl *)FindView("pfadView");
	TextControl->TextView()->MakeEditable(false);

};
Пример #7
0
void HDialog::SetText(const char *name, const char *text)
{
	BView *c = FindView(name);
	if (!c)
	{
		ASSERT(false);
		return;
	}

	BTextControl *tc = dynamic_cast<BTextControl*>(c);

	if (tc)
	{
		tc->SetText(text);
		if (tc->IsFocus())
			tc->TextView()->SelectAll();
	}
	else if (typeid(*c) == typeid(BStringView))
		static_cast<BStringView *>(c)->SetText(text);

} /* HDialog::SetText */
Пример #8
0
void BrowserWindow::MessageReceived( BMessage* pcMsg )
{
	switch( pcMsg->what )
	{
	case ID_URL_CHANGED:
	{

		std::string cURL = m_pcURLView->Text();

		for ( uint i = 0 ; i <= cURL.size() ; ++i ) {
			if ( i == cURL.size() || isalnum( cURL[i] ) == false ) {
				if ( i == cURL.size() || cURL[i] != ':' ) {
					std::string cTmp = cURL;
					cURL = "http://";
					for ( uint j = 0 ; j < cTmp.size() ; ++j ) {
						if ( cTmp[j] != '/' ) {
							cURL.insert( cURL.end(), cTmp.begin() + j, cTmp.end() );
							break;
						}
					}
				}
				break;
			}
		}
		m_pcHTMLPart->view()->MakeFocus();
		OpenURL( cURL, KParts::URLArgs() );
//----------------------------------------------
#if 0
		uint32 nEvents = 0;
		pcMsg->FindInt( "events", &nEvents );
		
		if ( nEvents & os::TextView::EI_ESC_PRESSED ) {
			m_pcURLView->Set( m_pcHTMLPart->url().prettyURL().utf8().data() );
			m_pcHTMLPart->view()->MakeFocus();
		break;
		}
		if ( nEvents & os::TextView::EI_ENTER_PRESSED ) {
		std::string cURL = m_pcURLView->GetBuffer()[0];

		for ( uint i = 0 ; i <= cURL.size() ; ++i ) {
			if ( i == cURL.size() || isalnum( cURL[i] ) == false ) {
				if ( i == cURL.size() || cURL[i] != ':' ) {
					std::string cTmp = cURL;
					cURL = "http://";
					for ( uint j = 0 ; j < cTmp.size() ; ++j ) {
						if ( cTmp[j] != '/' ) {
							cURL.insert( cURL.end(), cTmp.begin() + j, cTmp.end() );
							break;
						}
					}
				}
				break;
			}
		}
		UpdateHistory();
		AddHistoryEntry();
		m_pcHTMLPart->view()->MakeFocus();
		OpenURL( cURL, KParts::URLArgs() );
		UpdateHistory();
		}
#endif
		break;
	}
	case ID_ACTIVATE_URLEDIT:
		m_pcURLView->MakeFocus( true );
#if 0
		m_pcURLView->SetCursor( -1, 0 );
#endif
		m_pcURLView->TextView()->SelectAll();
		break;
	case ID_RELOAD:
	{
		KParts::URLArgs cArgs;
		cArgs.reload = true;
		cArgs.xOffset = m_pcHTMLPart->browserExtension()->xOffset();
		cArgs.yOffset = m_pcHTMLPart->browserExtension()->yOffset();
#if 0
		OpenURL( m_pcURLView->GetBuffer()[0], cArgs );
#endif
		OpenURL( m_pcURLView->Text(), cArgs );
		break;
	}
	case ID_NEW_WINDOW:
	{
		BrowserWindow* pcNewWindow = new BrowserWindow( Frame().OffsetByCopy( 30.0f, 30.0f ), false );
		pcNewWindow->Show();
#if 0
		UpdateHistory();
		std::vector<HistoryEntry*> cHistory = m_cHistory;
		cHistory.resize( m_nCurHistoryPos + 1 );
		BrowserWindow* pcNewWindow = new BrowserWindow( GetFrame() + os::Point( 30.0f, 30.0f ), &cHistory, false );
		pcNewWindow->GoHistory(0);
		pcNewWindow->Show( true );
		pcNewWindow->MakeFocus( true );	
#endif
		break;
	}
	case ID_OPEN_LINK:
	{
		BString cURL;
		pcMsg->FindString( "url", &cURL );
		BrowserWindow* pcNewWindow = new BrowserWindow( Frame().OffsetByCopy( 30.0f, 30.0f ), false  );
		pcNewWindow->OpenURL( cURL.String(), KParts::URLArgs() );
		pcNewWindow->Show();
#if 0
		std::string cURL;
		pcMsg->FindString( "url", &cURL );
		std::vector<HistoryEntry*> cHistory = m_cHistory;
		cHistory.resize( m_nCurHistoryPos + 1 );
		BrowserWindow* pcNewWindow = new BrowserWindow( GetFrame() + os::Point( 30.0f, 30.0f ), &cHistory, false );
		pcNewWindow->OpenURL( cURL, KParts::URLArgs() );
		pcNewWindow->AddHistoryEntry();
		pcNewWindow->Show( true );
		pcNewWindow->MakeFocus( true );	
#endif
		break;
	}
	case ID_SAVE_LINK:
	{
		BString cURL;
		pcMsg->FindString( "url", &cURL );

		m_pcHTMLPart->browserExtension()->SaveURL( cURL.String(), "Save link as..." );
		break;
	}
	case ID_COPY_LINK_LOCATION:
	{
#if 0
		std::string cURL;
		pcMsg->FindString( "url", &cURL );

		os::Clipboard cClipboard;
		cClipboard.Lock();
		cClipboard.Clear();
		os::Message* pcData = cClipboard.GetData();
		pcData->AddString( "text/plain", cURL );
		cClipboard.Commit();
		cClipboard.Unlock();
#endif
		break;
	}
	case ID_COPY:
	{
#if 0
		if ( m_cSelectedText.empty() ) {
			break;
		}
		os::Clipboard cClipboard;
		cClipboard.Lock();
		cClipboard.Clear();
		os::Message* pcData = cClipboard.GetData();
		pcData->AddString( "text/plain", m_cSelectedText );
		cClipboard.Commit();
		cClipboard.Unlock();
#endif
		break;
	}
	case ID_FIND:
#if 0
		if ( m_pcSearchDialog == NULL ) {
		m_pcHTMLPart->findTextBegin();
		m_pcSearchDialog = new FindDialog( os::Messenger(this), os::Message(ID_DO_SEARCH), os::Message(ID_SEARCH_CLOSED) );
		m_pcSearchDialog->Show();
		m_pcSearchDialog->MakeFocus();
		}
#endif
		break;
	case ID_DO_SEARCH:
	{
#if 0
		bool bFromTop = false;
		pcMsg->FindBool( "from_top", &bFromTop );
		pcMsg->FindBool( "case_sensitive", &m_bSearchCaseSensitive );
		pcMsg->FindString( "string", &m_cLastSearchStr );

		KHTMLView* pcActiveView = dynamic_cast<KHTMLView*>(GetFocusChild());
		
		KHTMLPart* pcPart = m_pcHTMLPart;
		if ( pcActiveView != NULL ) {
		pcPart = pcActiveView->part();
		}
		if ( bFromTop ) {
		pcPart->findTextBegin();
		}
		pcPart->findTextNext( m_cLastSearchStr.c_str(), true, m_bSearchCaseSensitive );
		break;
#endif
	}
	case ID_REPEAT_FIND:
#if 0
		if ( m_cLastSearchStr.empty() == false ) {
		KHTMLView* pcActiveView = dynamic_cast<KHTMLView*>(GetFocusChild());
		
		KHTMLPart* pcPart = m_pcHTMLPart;
		if ( pcActiveView != NULL ) {
			pcPart = pcActiveView->part();
		}		
		pcPart->findTextNext( m_cLastSearchStr.c_str(), true, m_bSearchCaseSensitive );
		} else if ( m_pcSearchDialog == NULL ) {
		m_pcHTMLPart->findTextBegin();
		m_pcSearchDialog = new FindDialog( os::Messenger(this), os::Message(ID_DO_SEARCH), os::Message(ID_SEARCH_CLOSED) );
		m_pcSearchDialog->Show();
		m_pcSearchDialog->MakeFocus();
		}
		break;
	case ID_SEARCH_CLOSED:
		m_pcSearchDialog = NULL;
		break;
#endif
	case ID_GOHOME:
		OpenURL( "http://www.openbeos.org/", KParts::URLArgs() );
#if 0
		UpdateHistory();
		AddHistoryEntry();
		OpenURL( "http://www.atheos.cx/", KParts::URLArgs() );
		UpdateHistory();
#endif
		break;
#if 0
	case ID_PREV_URL:
		GoHistory( -1 );
		break;
	case ID_NEXT_URL:
		GoHistory( 1 );
		break;
#endif
	case ID_START_DOWNLOAD:
	{
#if 0
		DownloadNode* psNode = NULL;
		std::string   cPath;
		pcMsg->FindPointer( "node", (void**) &psNode );
		pcMsg->FindString( "path", &cPath );

		
		if ( psNode == NULL ) {
		break; // Should never happen
		}
		psNode->m_cPath = cPath;
		const std::string cDstDir = os::Path( cPath.c_str() ).GetDir();

		try {
		os::FSNode cDirNode( cDstDir );
		if ( cDirNode.GetDev() == psNode->m_pcTmpFile->GetDev() ) {
			rename( psNode->m_pcTmpFile->GetPath().c_str(), cPath.c_str() );
			psNode->m_pcTmpFile->Detatch(); // Make sure the destructor don't do anything silly.
		} else {
			psNode->m_pcFile = new os::File( cPath, O_WRONLY | O_CREAT );
			psNode->m_pcTmpFile->Seek( 0, SEEK_SET );
			char anBuffer[32*1024];
			for (;;) {
			int nLen = psNode->m_pcTmpFile->Read( anBuffer, sizeof(anBuffer) );
			if ( nLen < 0 ) {
				throw os::errno_exception( "Failed to copy temporary file" );
			}
			if ( psNode->m_pcFile->Write( anBuffer, nLen ) != nLen ) {
				throw os::errno_exception( "Failed to copy temporary file" );
			}
			if ( nLen < int(sizeof(anBuffer)) ) {
				break;
			}
			}
			delete psNode->m_pcTmpFile;
			psNode->m_pcTmpFile = NULL;
		}
		} catch(...) {
		(new os::Alert( "Error: Failed to create file!",
				os::String().Format( "Failed to create '%s'", cPath.c_str() ), 0,
				"Sorry!", NULL ))->Go(NULL);
		}
		
		psNode->m_pcRequester = NULL;

		if ( psNode->m_bDone == false ) {
		Message cCancelMsg( ID_CANCEL_DOWNLOAD );
		cCancelMsg.AddPointer( "node", psNode );
		
		psNode->m_pcProgressDlg = new DownloadProgress( os::Rect( 100, 100, 449, 349 ), os::String().Format( "Download: %s", cPath.c_str() ),
								psNode->m_cURL,
								cPath,
								psNode->m_nContentSize,
								psNode->m_nStartTime,
								os::Messenger( this ),
								cCancelMsg );

		psNode->m_pcProgressDlg->Show();
		} else {
		delete psNode->m_pcTmpFile;
		delete psNode->m_pcFile;
		delete psNode;
		}
#endif
		break;
	}
	case ID_CANCEL_DOWNLOAD:
	{
#if 0
		DownloadNode* psNode = NULL;
		pcMsg->FindPointer( "node", (void**) &psNode );
		
		if ( psNode == NULL ) {
		break; // Should never happen
		}
		if ( psNode->m_pcProgressDlg != NULL ) {
		psNode->m_pcProgressDlg->Terminate();
		psNode->m_pcProgressDlg = NULL;
		}
		if ( psNode->m_cPath.empty() == false ) {
		unlink( psNode->m_cPath.c_str() );
		}
		if ( psNode->m_bDone == false ) {
		psNode->m_pcRequester = NULL;
		psNode->m_bCanceled = true;
		delete psNode->m_pcTmpFile;
		psNode->m_pcTmpFile = NULL;
		delete psNode->m_pcFile;
		psNode->m_pcFile = NULL;
		} else {
		delete psNode->m_pcTmpFile;
		delete psNode->m_pcFile;
		delete psNode;		
		}
#endif
		break;
	}
	default:
		BWindow::MessageReceived( pcMsg );
		break;
	}
}
Пример #9
0
//----------------Real code----------------------
BMailProtocolConfigView::BMailProtocolConfigView(uint32 options_mask)
	:
	BView (BRect(0,0,100,20), "protocol_config_view", B_FOLLOW_LEFT
		| B_FOLLOW_TOP, B_WILL_DRAW),
	fBodyDownloadConfig(NULL)
{
	BRect rect(5,5,245,25);
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// determine font height
	font_height fontHeight;
	GetFontHeight(&fontHeight);
	sItemHeight = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 13;
	rect.bottom = rect.top - 2 + sItemHeight;

	if (options_mask & B_MAIL_PROTOCOL_HAS_HOSTNAME)
		AddChild(AddTextField(rect, "host", B_TRANSLATE("Mail server:")));

	if (options_mask & B_MAIL_PROTOCOL_HAS_USERNAME)
		AddChild(AddTextField(rect, "user", B_TRANSLATE("Username:"******"pass",
			B_TRANSLATE("Password:"******"flavor", B_TRANSLATE("Connection type:")));

	if (options_mask & B_MAIL_PROTOCOL_HAS_AUTH_METHODS)
		AddChild(AddMenuField(rect, "auth_method", B_TRANSLATE("Login type:")));

	// set divider
	float width = FindWidestLabel(this);
	for (int32 i = CountChildren();i-- > 0;) {
		if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
			text->SetDivider(width + 6);
	}

	if (options_mask & B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER) {
		AddChild(AddCheckBox(rect, "leave_mail_on_server",
			B_TRANSLATE("Leave mail on server"), new BMessage('lmos')));
		BCheckBox* box = AddCheckBox(rect, "delete_remote_when_local",
			B_TRANSLATE("Remove mail from server when deleted"));
		box->SetEnabled(false);
		AddChild(box);
	}

	if (options_mask & B_MAIL_PROTOCOL_PARTIAL_DOWNLOAD) {
		fBodyDownloadConfig = new BodyDownloadConfig();
		fBodyDownloadConfig->MoveBy(0, rect.bottom + 5);
		AddChild(fBodyDownloadConfig);
	}

	// resize views
	float height;
	GetPreferredSize(&width,&height);
	ResizeTo(width,height);
	for (int32 i = CountChildren();i-- > 0;) {
		// this doesn't work with BTextControl, does anyone know why? -- axeld.
		if (BView *view = ChildAt(i))
			view->ResizeTo(width - 10,view->Bounds().Height());
	}
}