Exemple #1
0
status_t
AGMSBayesianSpamFilterConfig::Archive (BMessage *into, bool deep) const
{
	status_t	errorCode;
	float		tempFloat;

	into->MakeEmpty();
	errorCode = into->AddBool ("AddMarkerToSubject", fAddSpamToSubject);

	if (errorCode == B_OK)
		errorCode = into->AddBool ("AutoTraining", fAutoTraining);

	if (errorCode == B_OK)
		errorCode = into->AddBool ("QuitServerWhenFinished", fQuitServerWhenFinished);

	if (errorCode == B_OK)
		errorCode = into->AddBool ("NoWordsMeansSpam", fNoWordsMeansSpam);

	if (errorCode == B_OK) {
		tempFloat = fGenuineCutoffRatio;
		if (fGenuineCutoffRatioTextBoxPntr != NULL)
			tempFloat = atof (fGenuineCutoffRatioTextBoxPntr->Text());
		errorCode = into->AddFloat ("GenuineCutoffRatio", tempFloat);
	}

	if (errorCode == B_OK) {
		tempFloat = fSpamCutoffRatio;
		if (fSpamCutoffRatioTextBoxPntr != NULL)
			tempFloat = atof (fSpamCutoffRatioTextBoxPntr->Text());
		errorCode = into->AddFloat ("SpamCutoffRatio", tempFloat);
	}

	return errorCode;
}
Exemple #2
0
void
LoginAlert::MessageReceived(BMessage *message)
{
	switch (message->what) {
	case 'ALTB':
	{
		int32 which;
		if (message->FindInt32("which", &which) < B_OK)
			break;
		// not 'Ok'
		if (which != 1)
			break;
		BMessage *m = new BMessage(*message);
		m->what = 'nsLO';
		m->AddPointer("URL", fUrl);
		m->AddString("Host", fHost.String());
		m->AddString("Realm", fRealm.String());
		m->AddPointer("callback", (void *)fCallback);
		m->AddPointer("callback_pw", (void *)fCallbackPw);
		m->AddString("User", fUserControl->Text());
		m->AddString("Pass", fPassControl->Text());
		BString auth(fUserControl->Text());
		auth << ":" << fPassControl->Text();
		m->AddString("Auth", auth.String());
		
		// notify the main thread
		// the event dispatcher will handle it
		nsbeos_pipe_message(m, NULL, NULL);
	}
		break;
	default:
		break;
	}
	BAlert::MessageReceived(message);
}
Exemple #3
0
filter_result
DCCFileFilter::HandleButton (BMessage *)
{
	filter_result result (B_DISPATCH_MESSAGE);
	BTextControl *paneltext (dynamic_cast<BTextControl *>(
		panel->Window()->FindView ("text view")));
    
	if (paneltext)
	{
		BDirectory dir;
		struct stat s;
		entry_ref ref;
		BEntry entry;

		panel->GetPanelDirectory (&ref);

		dir.SetTo (&ref);
		
		if (entry.SetTo (&dir, paneltext->Text()) == B_NO_ERROR
		&&  entry.GetStat (&s)               == B_NO_ERROR
		&&  S_ISREG (s.st_mode))
		{
          if (vision_app->GetBool ("dccAutoAccept"))
          {
            BMessage msg (M_FILE_PANEL_ALERT);
            msg.AddInt32 ("which", 2);
            panel->Window()->PostMessage (&msg);
            result = B_SKIP_MESSAGE; 
          }
          else
          {
			BString buffer;
			BAlert *alert;

			buffer << "The file \""
				<< paneltext->Text()
				<< "\" already exists in the specified folder.  "
					"Do you want to continue the transfer?";

			alert = new BAlert (
				"DCC Request",
				buffer.String(),
				"Cancel",
				"Replace",
				"Resume",
				B_WIDTH_AS_USUAL,
				B_OFFSET_SPACING,
				B_WARNING_ALERT);

			alert->Go (new BInvoker (
				new BMessage (M_FILE_PANEL_ALERT),
				panel->Window()));

			result = B_SKIP_MESSAGE;
	      }
		}
	}
	return result;
}
Exemple #4
0
void
MimeTypeEditor::CommitChanges()
{
	if (fPreviousText != fTextControl->Text()) {
		fEditor.Replace(0, (const uint8*)fTextControl->Text(),
			strlen(fTextControl->Text()) + 1);
	}
}
Exemple #5
0
void MainWindow::DoPriority()
{
	BTextControl *PriorityValue = (BTextControl *)FindView("MainPriorityValue");
	if (strcmp("", PriorityValue->Text())) {
		int32 value;
		value = atoi(PriorityValue->Text());
		DoPriority(value);
	}
}
Exemple #6
0
const char* HDialog::GetText(const char *name) const
{
	BTextControl *t = dynamic_cast<BTextControl *>(FindView(name));
	if (t)
		return t->Text();
	else
		return NULL;
} /* HDialog::SetText */
Exemple #7
0
filter_result
DCCFileFilter::HandleAlert (BMessage *msg)
{
	BTextControl *text (dynamic_cast<BTextControl *>(
		panel->Window()->FindView ("text view")));
	int32 which;

	msg->FindInt32 ("which", &which);

	if (which == 0 || text == 0)
	{
		return B_SKIP_MESSAGE;
	}

	entry_ref ref;
	panel->GetPanelDirectory (&ref);

	if (which == 2)
	{
		BDirectory dir (&ref);
		BFile file (&dir, text->Text(), B_READ_ONLY);
		BEntry entry (&dir, text->Text());
		BPath path;
		off_t position;

		file.GetSize (&position);
		entry.GetPath (&path);
		send_msg.AddString ("path", path.Path());
		send_msg.AddInt64  ("pos", position);

		send_msg.what = M_ADD_RESUME_DATA;
	}
	else
	{
		send_msg.AddRef ("directory", &ref);
		send_msg.AddString ("name", text->Text());
	}

	panel->Messenger().SendMessage (&send_msg);

	BMessage cmsg (B_CANCEL);
	cmsg.AddPointer ("source", panel);
	panel->Messenger().SendMessage (&cmsg);

	return B_SKIP_MESSAGE;
}
Exemple #8
0
void
MimeTypeEditor::MessageReceived(BMessage *message)
{
	switch (message->what) {
		case kMsgValueChanged:
			fEditor.Replace(0, (const uint8 *)fTextControl->Text(),
				strlen(fTextControl->Text()) + 1);
			break;

		case kMsgDataEditorUpdate:
			_UpdateText();
			break;

		default:
			BView::MessageReceived(message);
	}
}
bool IppSetupView::UpdateViewData()
{
	string error_msg;

	if (*url->Text()) {
		IppContent *request = new IppContent;
		request->setOperationId(IPP_GET_PRINTER_ATTRIBUTES);
		request->setDelimiter(IPP_OPERATION_ATTRIBUTES_TAG);
		request->setCharset("attributes-charset", "utf-8");
		request->setNaturalLanguage("attributes-natural-language", "en-us");
		request->setURI("printer-uri", url->Text());
		request->setDelimiter(IPP_END_OF_ATTRIBUTES_TAG);

		IppURLConnection conn(URL(url->Text()));
		conn.setIppRequest(request);
		conn.setRequestProperty("Connection", "close");

		HTTP_RESPONSECODE response_code = conn.getResponseCode();
		if (response_code == HTTP_OK) {
			const char *content_type = conn.getContentType();
			if (content_type && !strncasecmp(content_type, "application/ipp", 15)) {
				const IppContent *ipp_response = conn.getIppResponse();
				if (ipp_response->good()) {
					dir->WriteAttr(IPP_URL, B_STRING_TYPE, 0, url->Text(), strlen(url->Text()) + 1);
					return true;
				} else {
					error_msg = ipp_response->getStatusMessage();
				}
			} else {
				error_msg = "cannot get a IPP response.";
			}
		} else if (response_code != HTTP_UNKNOWN) {
			error_msg = conn.getResponseMessage();
		} else {
			error_msg = "cannot connect to the IPP server.";
		}
	} else {
		error_msg = "please input the printer URL.";
	}

	BAlert *alert = new BAlert("", error_msg.c_str(), "OK");
	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go();
	return false;
}
Exemple #10
0
bool
LprSetupView::UpdateViewData()
{
	if (*fServer->Text() && *fQueue->Text()) {

		try {
			LpsClient lpr(fServer->Text());
			lpr.connect();
		}

		catch (LPSException &err) {
			BAlert *alert = new BAlert("", err.what(), "OK");
			alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
			alert->Go();
			return false;
		}

		fDir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer->Text(),
			strlen(fServer->Text()) + 1);
		fDir->WriteAttr(LPR_QUEUE_NAME,  B_STRING_TYPE, 0, fQueue->Text(),
			strlen(fQueue->Text())  + 1);
		return true;
	}

	BAlert *alert = new BAlert("", "Please enter server address and printer"
		"queue name.", "OK");
	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go();
	return false;
}
Exemple #11
0
void
DocInfoWindow::_ReadFieldsFromTable(BMessage& docInfo)
{
	docInfo.MakeEmpty();

	BView* child;
	for (int32 i = 0; (child = fTable->ChildAt(i)) != NULL; i++) {
		BTextControl* textControl = dynamic_cast<BTextControl*>(child);
		if (textControl)
			docInfo.AddString(textControl->Label(), textControl->Text());
	}
}
/**
 *	@brief	Diff Them ボタンの処理
 */
void OpenFilesDialog::doDiffThem()
{
	const char* text = NULL;
	BTextControl* textControl;
	
	// 左側
	text = NULL;
	textControl = dynamic_cast<BTextControl*>(FindView(NAME_LEFT_TEXT_CONTROL));
	if (NULL != textControl)
	{
		text = textControl->Text();
	}
	if (NULL == text || '\0' == text[0])
	{
		// 左側ファイルが指定されていません
		// TODO:
		return;
	}
	BPath leftPath(text);
	
	// 右側
	text = NULL;
	textControl = dynamic_cast<BTextControl*>(FindView(NAME_RIGHT_TEXT_CONTROL));
	if (NULL != textControl)
	{
		text = textControl->Text();
	}
	if (NULL == text || '\0' == text[0])
	{
		// 左側ファイルが指定されていません
		// TODO:
		return;
	}
	BPath rightPath(text);
	
	PonpokoDiffApp* app = static_cast<PonpokoDiffApp*>(be_app);
	TextDiffWnd* newDiffWnd = app->NewTextDiffWnd();
	newDiffWnd->ExecuteDiff(leftPath, rightPath, NULL, NULL);
	PostMessage(B_QUIT_REQUESTED);
}
bool
SetupView::CheckSetup()
{
	if (*fServerAddress->Text() && *fQueuePort->Text()) {
		BNetEndpoint* ep = new BNetEndpoint(SOCK_STREAM);
		if (ep->InitCheck() == B_NO_ERROR) {
			uint16 port = atoi(fQueuePort->Text());

			if (! port)
				port = 9100;

			if (ep->Connect(fServerAddress->Text(), port) != B_OK) {
				BString text;
				text << "Fail to connect to " << fServerAddress->Text() << ":" << (int) port << "!";
				BAlert* alert = new BAlert("", text.String(), "OK");
				alert->Go();
				return false;
			};

			char str[256];
			sprintf(str, "%s:%d", fServerAddress->Text(), port);
			fPrinterDirectory->WriteAttr("transport_address", B_STRING_TYPE,
				0, str, strlen(str) + 1);
			return true;
		};
	};

	BAlert* alert = new BAlert("", "please input parameters.", "OK");
	alert->Go();
	return false;
}
Exemple #14
0
	status_t GetPrefs(BMessage& pref)
	{
		if( !mOnBox || !mNameCtrl ) return B_ERROR;
//		if( !mOnBox || !mNameCtrl || !mSkipBox ) return B_ERROR;
		BMessage		msg('null');
		if( msg.AddBool( "on", (mOnBox->Value() == B_CONTROL_ON) ? true : false ) != B_OK ) return B_ERROR;
		if( msg.AddString( "name", mNameCtrl->Text() ) != B_OK ) return B_ERROR;
		if( mRef ) msg.AddRef( "ref", mRef );
//		if( msg.AddBool( "skip", (mSkipBox->Value() == B_CONTROL_ON) ? true : false ) != B_OK ) return B_ERROR;

		if( pref.AddMessage("new item", &msg) != B_OK ) return B_ERROR;
		return B_OK;
	}
Exemple #15
0
/***********************************************************
 * MessageReceived
 ***********************************************************/
void
HAddressView::MessageReceived(BMessage *message)
{
	switch(message->what)
	{
	case M_ACCOUNT_CHANGE:
	{
		const char* name;
		if(message->FindString("name",&name) != B_OK)
			break;
		ChangeAccount(name);
		PRINT(("Name:%s\n",name));
		break;
	}
	case M_SEL_GROUP:
	{
		BMenu *menu;
		BTextControl *control;
		if(message->FindPointer("menu",(void**)&menu) != B_OK ||
			message->FindPointer("control",(void**)&control) != B_OK)
			break;
		if(control)
		{
			BString text = control->Text();
			if(text.Length() != 0)
				text += ",";
			int32 count = menu->CountItems();
			for(int32 i = 0;i < count;i++)
			{
				const char* label = menu->ItemAt(i)->Label();
				text += label;
				if(i != count-1)
					text += ",";
			}
			control->SetText(text.String() );
		}
		break;
	}
	default:
		BView::MessageReceived(message);
	}
}
Exemple #16
0
void
DocInfoWindow::_AddKey(BMessage *msg, bool textControl)
{
	void *p;
	if (msg->FindPointer("source", &p) != B_OK || p == NULL)
		return;

	const char* key = NULL;
	if (textControl) {
		BTextControl *text = reinterpret_cast<BTextControl*>(p);
		key = text->Text();
	} else {
		BMenuItem *item = reinterpret_cast<BMenuItem*>(p);
		key = item->Label();
	}

	if (!_IsKeyValid(key))
		return;

	BMessage docInfo;
	_ReadFieldsFromTable(docInfo);

	if (!docInfo.HasString(key)) {
		// key is valid and is not in list already
		docInfo.AddString(key, "");

		float width = fTable->Bounds().Width() - 4.0;
		BTextControl *textControl =
			_AddFieldToTable(BRect(2.0, 0.0, width, 20.0), key, "");

		float rowHeight = textControl->Bounds().Height();
		int32 count = fKeyList->CountItems();
		float fieldsHeight = (rowHeight * count) + (2 * count);
		textControl->MoveTo(2.0, fieldsHeight - rowHeight);

		_AdjustScrollBar(rowHeight, fieldsHeight);
	}
}
void
PartitionsPage::PageCompleted()
{
	BGridLayout* layout = (BGridLayout*)fPartitions->GetLayout();
	int32 index = 0;

	for (int32 row = 0; row < layout->CountRows(); row += 3, index++) {
		BCheckBox* showBox
			= dynamic_cast<BCheckBox*>(layout->ItemAt(0, row)->View());
		BTextControl* nameControl
			= dynamic_cast<BTextControl*>(layout->ItemAt(1, row)->View());
		if (nameControl == NULL || showBox == NULL)
			debugger("partitions page is broken");

		BMessage partition;
		if (fSettings->FindMessage("partition", index, &partition) != B_OK)
			continue;

		partition.ReplaceBool("show", showBox->Value() != 0);
		partition.ReplaceString("name", nameControl->Text());

		fSettings->ReplaceMessage("partition", index, &partition);
	}
}
Exemple #18
0
void YabWindow::MessageReceived(BMessage *message)
{
	// if(message) message->PrintToStream();
	switch(message->what)
	{
		case YABBUTTON:
			{
				BString tmpMessage("");
                        	BButton *myButtonPressed;
                        	message->FindPointer("source",(void **) &myButtonPressed);
				tmpMessage += myButtonPressed->Name();
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABMENU:
			{
				BString tmpMessage("");
				BMenuItem *mySelectedMenu;
                        	message->FindPointer("source",(void **) &mySelectedMenu);
				BMenu *myMenu = mySelectedMenu->Menu();
				tmpMessage += ((BMenuBar*)myMenu->Supermenu())->Parent()->Name();
				tmpMessage += ":";
				tmpMessage += myMenu->Name();
				tmpMessage += ":";
                        	tmpMessage += mySelectedMenu->Label(); 
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABSUBMENU:
			{
				BString tmpMessage("");
				BMenuItem *mySelectedMenu;
                        	message->FindPointer("source",(void **) &mySelectedMenu);
				BMenu *myMenu = mySelectedMenu->Menu();
				tmpMessage += ((BMenuBar*)myMenu->Supermenu()->Supermenu())->Parent()->Name();
				tmpMessage += ":";
				tmpMessage += myMenu->Supermenu()->Name();
				tmpMessage += ":";
				tmpMessage += myMenu->Name();
				tmpMessage += ":";
                        	tmpMessage += mySelectedMenu->Label(); 
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABTEXTCONTROL:
			{
				BString tmpMessage("");
				BTextControl *myTextControl;
                        	message->FindPointer("source",(void **) &myTextControl);
				tmpMessage += myTextControl->Name();
				tmpMessage += ":";
				tmpMessage += myTextControl->Text();
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABCHECKBOX:
			{
				BString tmpMessage("");
				BCheckBox *myCheckBox;
                        	message->FindPointer("source",(void **) &myCheckBox);
				tmpMessage += myCheckBox->Name();
				tmpMessage += ":";
				if(myCheckBox->Value()==B_CONTROL_ON)
					tmpMessage += "ON|";
				else
					tmpMessage += "OFF|";
				messageString += tmpMessage;
			}
			break;
		case YABRADIOBUTTON:
			{
				BString tmpMessage("");
				BRadioButton *myRadioButton;
                        	message->FindPointer("source",(void **) &myRadioButton);
				tmpMessage += myRadioButton->Name();
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABLISTBOXINVOKE:
			{
				BListView *myList;
				message->FindPointer("source",(void **) &myList);
				int i = myList->CurrentSelection();
				if(i>=0)
				{
					BString tmpMessage("");
					tmpMessage += myList->Name();
					tmpMessage += ":_Invoke:";
					// tmpMessage += ((BStringItem*)(myList->ItemAt(i)))->Text();
					tmpMessage << i+1;
					tmpMessage += "|";
					messageString += tmpMessage;
				}
			}
			break;
		case YABLISTBOXSELECT:
			{
				BListView *myList;
				message->FindPointer("source",(void **) &myList);
				int i = myList->CurrentSelection();
				if(i>=0)
				{
					BString tmpMessage("");
					tmpMessage += myList->Name();
					tmpMessage += ":_Select:";
					// tmpMessage += ((BStringItem*)(myList->ItemAt(i)))->Text();
					tmpMessage << i+1;
					tmpMessage += "|";
					messageString += tmpMessage;
				}
			}
			break;
		case YABDROPBOX:
			{
				BString tmpMessage("");
				BMenuItem *myMenuItem;
				message->FindPointer("source",(void **) &myMenuItem);
				tmpMessage += (myMenuItem->Menu())->Supermenu()->Parent()->Name();
				tmpMessage += ":";
				tmpMessage += myMenuItem->Label();
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABSLIDER:
			{
				BString tmpMessage("");
                        	BSlider *mySlider;
                        	message->FindPointer("source",(void **) &mySlider);
				tmpMessage += mySlider->Name();
				tmpMessage += ":";
				tmpMessage << mySlider->Value();
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABCOLORCONTROL:
			{
				rgb_color col;
				BString tmpMessage("");
                        	BColorControl *myCControl;
                        	message->FindPointer("source",(void **) &myCControl);
				tmpMessage += myCControl->Name();
				tmpMessage += ":";
				col = myCControl->ValueAsColor();
				tmpMessage << col.red << ":" << col.green << ":" << col.blue;
				tmpMessage += "|";
				messageString += tmpMessage;
			}
			break;
		case YABTREEBOXINVOKE:
			{
				BOutlineListView *myList;
				message->FindPointer("source",(void **) &myList);
				int i = myList->FullListCurrentSelection();
				if(i>=0)
				{
					BString tmpMessage("");
					const char* txt = ((BStringItem*)(myList->FullListItemAt(i)))->Text();
					tmpMessage += myList->Name();
					tmpMessage += ":_Invoke:";
					tmpMessage << i+1;
					/*
					int n = tmpMessage.Length();
					BListItem *superitem = myList->Superitem(myList->FullListItemAt(i));
					while(superitem)
					{
						BString t("");
						t << ((BStringItem*)superitem)->Text() << ":";
						tmpMessage.Insert(t,n);
						superitem = myList->Superitem(superitem);
					}
					tmpMessage += txt;*/
					tmpMessage += "|";
					messageString += tmpMessage;
				}
			}
			break;
		case YABTREEBOXSELECT:
			{
				BOutlineListView *myList;
				message->FindPointer("source",(void **) &myList);
				int i = myList->FullListCurrentSelection();
				if(i>=0)
				{
					BString tmpMessage("");
					const char* txt = ((BStringItem*)(myList->FullListItemAt(i)))->Text();
					tmpMessage += myList->Name();
					tmpMessage += ":_Select:";
					tmpMessage << i+1;
					/*
					int n = tmpMessage.Length();
					BListItem *superitem = myList->Superitem(myList->FullListItemAt(i));
					while(superitem)
					{
						BString t("");
						t << ((BStringItem*)superitem)->Text() << ":";
						tmpMessage.Insert(t,n);
						superitem = myList->Superitem(superitem);
					}
					tmpMessage += txt;*/
					tmpMessage += "|";
					messageString += tmpMessage;
				}
			}
			break;
		case YABFILEBOXSELECT:
			{
				BColumnListView *myList;
				message->FindPointer("source",(void **) &myList);
				BRow *myRow = NULL;
				if(myList) myRow = myList->CurrentSelection();
				if(myRow)
				{
				//	if(!myList->IsFocus()) myList->MakeFocus();
					BString tmpMessage("");
					tmpMessage += myList->Name();
					tmpMessage += ":_Select:";
					tmpMessage << myList->IndexOf(myRow)+1; 
					tmpMessage += "|";
					messageString += tmpMessage;
				}
			}
			break;
		case YABFILEBOXINVOKE:
			{
				BColumnListView *myList;
				message->FindPointer("source",(void **) &myList);
				BRow *myRow = NULL;
				if(myList) myRow = myList->CurrentSelection();
				if(myRow)
				{
				//	if(!myList->IsFocus()) myList->MakeFocus();
					BString tmpMessage("");
					tmpMessage += myList->Name();
					tmpMessage += ":_Invoke:";
					tmpMessage << myList->IndexOf(myRow)+1; 
					tmpMessage += "|";
					messageString += tmpMessage;
				}
			}
			break;
		case YABSHORTCUT:
			{
				const char* myMsg;
				if(message->FindString("shortcut", &myMsg) == B_OK)
				{
					messageString += myMsg;
					messageString += "|";
				}
			}
			break;
		default:
			BWindow::MessageReceived(message);
			break;
	}
}
Exemple #19
0
void
TFilePanel::AdjustButton()
{
	// adjust button state
	BButton* button = dynamic_cast<BButton*>(FindView("default button"));
	if (button == NULL)
		return;

	BTextControl* textControl
		= dynamic_cast<BTextControl*>(FindView("text view"));
	BObjectList<BPose>* selectionList = fPoseView->SelectionList();
	BString buttonText = fButtonText;
	bool enabled = false;

	if (fIsSavePanel && textControl != NULL) {
		enabled = textControl->Text()[0] != '\0';
		if (fPoseView->IsFocus()) {
			fPoseView->ShowSelection(true);
			if (selectionList->CountItems() == 1) {
				Model* model = selectionList->FirstItem()->TargetModel();
				if (model->ResolveIfLink()->IsDirectory()) {
					enabled = true;
					buttonText = B_TRANSLATE("Open");
				} else {
					// insert the name of the selected model into
					// the text field
					textControl->SetText(model->Name());
					textControl->MakeFocus(true);
				}
			}
		} else
			fPoseView->ShowSelection(false);
	} else {
		int32 count = selectionList->CountItems();
		if (count) {
			enabled = true;

			// go through selection list looking at content
			for (int32 index = 0; index < count; index++) {
				Model* model = selectionList->ItemAt(index)->TargetModel();

				uint32 modelFlavor = GetLinkFlavor(model, false);
				uint32 linkFlavor = GetLinkFlavor(model, true);

				// if only one item is selected and we're not in dir
				// selection mode then we don't disable button ever
				if ((modelFlavor == B_DIRECTORY_NODE
						|| linkFlavor == B_DIRECTORY_NODE)
					&& count == 1)
				  break;

				if ((fNodeFlavors & modelFlavor) == 0
					&& (fNodeFlavors & linkFlavor) == 0) {
		    		enabled = false;
					break;
				}
			}
		}
	}

	button->SetLabel(buttonText.String());
	button->SetEnabled(enabled);
}
Exemple #20
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;
	}
}
Exemple #21
0
void PecoApp::CreateScript(BMessage *msg) {
	entry_ref	directory;
	const char	*name;
	msg->FindRef("directory", &directory);
	msg->FindString("name", &name);
	
	BPath path(&directory);
	path.Append(name);
	
	BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);

	// Initiate
	fWindow->Lock();
	fStatusBar->SetMaxValue(fList->CountItems());
	BTextControl* 	pfadView = (BTextControl *)fWindow->FindView("pfadView");
	BString			Pfad(pfadView->Text());
	fWindow->Unlock();

	FileListItem	*ListItem;
	BString			AlterName, NeuerName;
	BString			output = 
					"#!/bin/sh\n"
					"\n"
					"# This script was created with PecoRename by Werner Freytag.\n"
					"# Visit http://www.pecora.de/pecorename for details!\n\n"
					"alert \"This script will rename files.\n\n"
					"Do you really want to continue?\" \"Yes\" \"No\"\n\n"
					"if [ $? -ne 0 ]\n"
					"then\n"
					"	exit 0\n"
					"fi\n\n";
	
	for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) {
		fWindow->Lock();
		fStatusBar->Update(1);
		fWindow->Unlock();
		if (ListItem->fNewName.String() != "" ) {
			AlterName = Pfad; AlterName.Append("/").Append(ListItem->fName);
			AlterName.Replace("\"", "\\\"", AlterName.Length());
			NeuerName = Pfad; NeuerName.Append("/").Append(ListItem->fNewName);
			NeuerName.Replace("\"", "\\\"", NeuerName.Length());
			output << "mv \"" << AlterName.String() << "\" \"" << NeuerName.String() << "\"\n";
		}
	}
	
	file.Write(output.String(), output.Length());
	
	mode_t	perms;
	
	file.GetPermissions(&perms);
	file.SetPermissions(perms | S_IXUSR | S_IXGRP | S_IXOTH );
	
	BNode		node(file);
	BNodeInfo	node_info(&node);
	node_info.SetType("text/plain");
	
	fWindow->Lock();
	fStatusBar->Reset(STATUS_STATUS);
	fWindow->Unlock();

}
Exemple #22
0
status_t
ProtocolSettings::Save(const char* account, BView* parent)
{
	if (!parent)
		debugger("Couldn't save protocol's settings GUI on a NULL parent!");

	BMessage* settings = new BMessage();

	BMessage cur;
	for (int32 i = 0; fTemplate->FindMessage("setting", i, &cur) == B_OK; i++) {
		const char* name = cur.FindString("name");

		// Skip NULL names
		if (!name)
			continue;

		int32 type = -1;
		if (cur.FindInt32("type", &type) != B_OK)
			continue;

		BView* view = parent->FindView(name);
		if (!view)
			continue;

		BTextControl* textControl
			= dynamic_cast<BTextControl*>(view);
		if (textControl) {
			switch (type) {
				case B_STRING_TYPE:
					settings->AddString(name, textControl->Text());
					break;
				case B_INT32_TYPE:
					settings->AddInt32(name, atoi(textControl->Text()));
					break;
				default:
					return B_ERROR;
			}
		}

		BMenuField* menuField
			= dynamic_cast<BMenuField*>(view);
		if (menuField) {
			BMenuItem* item = menuField->Menu()->FindMarked();
			if (!item)
				return B_ERROR;

			switch (type) {
				case B_STRING_TYPE:
					settings->AddString(name, item->Label());
					break;
				case B_INT32_TYPE:
					settings->AddInt32(name, atoi(item->Label()));
					break;
				default:
					return B_ERROR;
			}
		}

		BCheckBox* checkBox
			= dynamic_cast<BCheckBox*>(view);
		if (checkBox)
			settings->AddBool(name, (checkBox->Value() == B_CONTROL_ON));

		NotifyingTextView* textView
			= dynamic_cast<NotifyingTextView*>(view);
		if (textView)
			settings->AddString(name, textView->Text());
	}

	return _Save(account, settings);
}
Exemple #23
0
void
PBox::GetData(BMessage* data){
			
			
			
			BView * panel = fPrefView;
			BMessage cur;
			
			for (int i = 0; fTemplate.FindMessage("setting", i, &cur) == B_OK; i++) {
				const char *name = cur.FindString("name");
				int32 type = -1;
				
				cur.FindInt32("type", &type);
				
				if ( dynamic_cast<BTextControl*>(panel->FindView(name))) { 
//					Free text
					BTextControl * ctrl = (BTextControl*)panel->FindView(name);
				
					switch (type) {
						case B_STRING_TYPE: {
							data->AddString(name, ctrl->Text() );
						} break;
						case B_INT32_TYPE: {
							data->AddInt32(name, atoi(ctrl->Text()) );
						} break;
						default: {
							return;
						};
					};
				} else if (dynamic_cast<BMenuField*>(panel->FindView(name))) {
//					Provided option
					BMenuField * ctrl = (BMenuField*)panel->FindView(name);
					BMenuItem * item = ctrl->Menu()->FindMarked();
					
									
					if (!item) return;
					
					switch (type) {
						case B_STRING_TYPE: {
							data->AddString(name, item->Label() );
							BString index(name);
							index << "_index";
							data->AddInt32(index.String(), ctrl->Menu()->IndexOf(item)); //index 
						} break;
						case  B_INT32_TYPE: {
							data->AddInt32(name, atoi(item->Label()) );
							BString index(name);
							index << "_index";
							data->AddInt32(index.String(), ctrl->Menu()->IndexOf(item)); //index
						} break;
						default: {
							return;
						};
					}
				} else
				if (dynamic_cast<BCheckBox*>(panel->FindView(name))) {
// 					Boolean setting
					BCheckBox * box = (BCheckBox*)panel->FindView(name);
					
					if ( box->Value() == B_CONTROL_ON ) {
						data->AddBool(name,true);
					} else {
						data->AddBool(name,false);
					}
				} else if (dynamic_cast<BTextView *>(panel->FindView(name))) {
					BTextView *view = (BTextView *)panel->FindView(name);
					data->AddString(name, view->Text());
				};
				
				
			};

		
}
Exemple #24
0
void PecoApp::DoIt() {

	if (NothingToDo()) return;
	
	FileListItem	*ListItem;
	
	BAlert	*myAlert	= new BAlert(NULL, MESSAGE_REALLY_DOIT, STR_CONTINUE, STR_CANCEL);
	if (myAlert->Go() == 1) return;
		for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) {
		if (ListItem->fErrorStatus == 1 ) {
			BAlert	*myAlert	= new BAlert(NULL, MESSAGE_WILL_HAVE_PROBS, STR_CONTINUE, STR_CANCEL);
			if (myAlert->Go() == 1) return;
			break;
		}
	}

	bool 	noerror = true, nomoreerrors=false, canceled=false;

	fWindow->Lock();
	fStatusBar->SetText(STATUS_RENAMING);
	fStatusBar->SetMaxValue(fList->CountItems());

	BButton		*okButton = (BButton *)fWindow->FindView("DoIt");
	okButton->SetEnabled(false);
	
	BTextControl* 	pfadView = (BTextControl *)fWindow->FindView("pfadView");
	BString	Pfad(pfadView->Text());
	fWindow->Unlock();
	
	BString	AlterName, NeuerName;
	BEntry	Datei;
	
	for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) {
		fWindow->Lock();
		fStatusBar->Update(1);
		fWindow->Unlock();
		if (canceled) { ListItem->fErrorStatus=0; continue; }
		if (ListItem->fNewName.String() != "" ) {
			AlterName = Pfad; AlterName.Append("/").Append(ListItem->fName);
			NeuerName = Pfad; NeuerName.Append("/").Append(ListItem->fNewName);
			Datei.SetTo(AlterName.String());
			if ( Datei.Rename(NeuerName.String()) != B_OK ) {
				ListItem->fErrorStatus=1;
				fWindow->Lock();
				fListView->InvalidateItem(i);
				fWindow->Unlock();

				if (!nomoreerrors) {
					noerror = false;

					BString		ErrorMessage(MESSAGE_HAVE_PROBLEM);
					ErrorMessage.ReplaceFirst("%1", ListItem->fName.String());
					ErrorMessage.ReplaceFirst("%2", ListItem->fNewName.String());
					
					BAlert	*myAlert	= new BAlert(NULL, ErrorMessage.String(), STR_CANCEL, STR_CONTINUE, STR_CONTINUE_WO_MSG, B_WIDTH_AS_USUAL, B_WARNING_ALERT);

					int32	result = myAlert->Go();
					if (result == 0) { canceled = true; continue; }
					if (result == 2) nomoreerrors = true;
				}
				
			} else {
			
				fWindow->Lock();
				ListItem->SetName(ListItem->fNewName);
				ListItem->SetNewName("");
				fListView->InvalidateItem(i);
				fWindow->Unlock();

			}
		}
	}

//	NoRenamer();

	fWindow->Lock();
	fStatusBar->Reset(STATUS_STATUS);
	fWindow->Unlock();

	if (noerror) MakeList();
	else {
		fStatusBar->SetText(STATUS_DIDIT_BAD);

		BAlert	*myAlert	= new BAlert(NULL, MESSAGE_MARKED_FILES, STR_OK);
		myAlert->Go();
	}
	
}
Exemple #25
0
void
NumberEditor::CommitChanges()
{
	if (fPreviousText == fTextControl->Text())
		return;

	const char *number = fTextControl->Text();
	uint8 buffer[8];

	switch (fEditor.Type()) {
		case B_FLOAT_TYPE:
		{
			float value = strtod(number, NULL);
			*(float *)buffer = value;
			break;
		}
		case B_DOUBLE_TYPE:
		{
			double value = strtod(number, NULL);
			*(double *)buffer = value;
			break;
		}
		case B_INT8_TYPE:
		{
			int64 value = strtoll(number, NULL, 0);
			if (value > CHAR_MAX)
				value = CHAR_MAX;
			else if (value < CHAR_MIN)
				value = CHAR_MIN;
			*(int8 *)buffer = (int8)value;
			break;
		}
		case B_UINT8_TYPE:
		{
			int64 value = strtoull(number, NULL, 0);
			if (value > UCHAR_MAX)
				value = UCHAR_MAX;
			*(uint8 *)buffer = (uint8)value;
			break;
		}
		case B_INT16_TYPE:
		{
			int64 value = strtoll(number, NULL, 0);
			if (value > SHRT_MAX)
				value = SHRT_MAX;
			else if (value < SHRT_MIN)
				value = SHRT_MIN;
			*(int16 *)buffer = (int16)value;
			break;
		}
		case B_UINT16_TYPE:
		{
			int64 value = strtoull(number, NULL, 0);
			if (value > USHRT_MAX)
				value = USHRT_MAX;
			*(uint16 *)buffer = (uint16)value;
			break;
		}
		case B_INT32_TYPE:
		case B_SSIZE_T_TYPE:
		{
			int64 value = strtoll(number, NULL, 0);
			if (value > LONG_MAX)
				value = LONG_MAX;
			else if (value < LONG_MIN)
				value = LONG_MIN;
			*(int32 *)buffer = (int32)value;
			break;
		}
		case B_UINT32_TYPE:
		case B_SIZE_T_TYPE:
		case B_POINTER_TYPE:
		{
			uint64 value = strtoull(number, NULL, 0);
			if (value > ULONG_MAX)
				value = ULONG_MAX;
			*(uint32 *)buffer = (uint32)value;
			break;
		}
		case B_INT64_TYPE:
		case B_OFF_T_TYPE:
		{
			int64 value = strtoll(number, NULL, 0);
			*(int64 *)buffer = value;
			break;
		}
		case B_UINT64_TYPE:
		{
			uint64 value = strtoull(number, NULL, 0);
			*(uint64 *)buffer = value;
			break;
		}
		default:
			return;
	}

	fEditor.Replace(0, buffer, _Size());
	fPreviousText.SetTo((char *)buffer);
}
void
EditButtonWindow::MessageReceived(BMessage *msg)
{
	BMessage mymsg(51000);
	int32 id,vl;
	BTextControl *xt = NULL;
	char *txt = "";
	WrkWindow *win = DefWin,*wi = OldWindow;

	msg->FindInt32("be:value",&vl);
	msg->FindInt32("index",&id);

	if (msg->FindPointer("source",(void **)&xt) == B_OK)
	{
		if (is_instance_of(xt,BTextControl))
		{
			txt = xt->Text();		
		}	
	}

	switch(msg->what)
	{
		case	73500:
		case	73501:
		case	73502:
		{
			CheckItemBox *it;
			int k;

			for (k = 0; k < idcmp->CountItems(); k++)
			{
				if (it = (CheckItemBox *)idcmp->ItemAt(k))
				{
					switch(msg->what)
					{
						case	73500:	it->checked = true;		break;
						case	73501:	it->checked = false;	break;
						case	73502:	it->checked = !it->checked;	break;
					}

					ChangeFlags(k,it->checked);

					idcmp->InvalidateItem(idcmp->IndexOf(it));
				}			
			}
		}
		break;

		case	73600:
		case	73601:
		case	73602:
		{
			CheckItemBox *it;
			int k;

			for (k = 0; k < lv->CountItems(); k++)
			{
				if (it = (CheckItemBox *)lv->ItemAt(k))
				{
					switch(msg->what)
					{
						case	73600:	it->checked = true;		break;
						case	73601:	it->checked = false;	break;
						case	73602:	it->checked = !it->checked;	break;
					}

					ChangeView(k,it->checked);

					lv->InvalidateItem(lv->IndexOf(it));
				}			
			}
		}
		break;

		case	2200:
		{
			OpenColorPicker(msg);
		}
		break;

		case BEAIM_NEW_COLOR_PICKED:
		{
			ColorView *bt;

			if (msg->FindPointer("pt",(void **)&bt) == B_OK)
			{
				rgb_color cl,*startColor;
				ssize_t size;
	
				msg->FindData( "color",B_RGB_COLOR_TYPE,(const void**)&startColor,&size );

				cl.red 		= startColor->red;
				cl.green 	= startColor->green;
				cl.blue 	= startColor->blue;

				bt->SetColor(cl);
			}

			SetNewColor(msg);
		}
		break;	

		case	tab_tab_list:
		{
			AddListWindow(win->sellist.ItemAt(0));
		}
		break;

		case	tab_menu_list:
		{
			create_mmxmenu();
		}
		break;

		case	tab_menu_editlist:
		{
			struct MyGadget *gad;

			if (gad = win->sellist.ItemAt(0))
			{
				window_menu(&gad->name);
			}
		}
		break;

		case	window_minh:
		{
			if (wi)
			{
				wi->minh = vl;			
			}
		}
		break;

		case	window_maxh:
		{
			if (wi)
			{
				wi->maxh = vl;			
			}
		}
		break;

		case	window_minw:
		{
			if (wi)
			{
				wi->minw = vl;			
			}
		}
		break;

		case	window_maxw:
		{
			if (wi)
			{
				wi->maxw = vl;			
			}
		}
		break;

		case	tab_font:
		{
			struct MyGadget *gad;

			if (wi = win)
			{
				if (gad = win->sellist.ItemAt(0))
				{
					font_window(gad->FontType,gad->FontSize,gad->FontAntiliasing,&gad->FontName[0],&gad->FontStyle[0]);
				}
					else
				{
					font_window(wi->FontType,wi->FontSize,wi->FontAntiliasing,&wi->FontName[0],&wi->FontStyle[0]);
				}
			}		
		}
		break;

		case	window_type:
		{
			if (wi)
			{
				wi->typewin = id;			

				ChangeWindowType(wi,id);
			}
		}
		break;

		case	window_look:
		{
			if (wi)
			{
				wi->look = id;			
			}
		}
		break;

		case	window_feel:
		{
			if (wi)
			{
				wi->feel = id;			
			}
		}
		break;

		case	window_workspace:
		{
			if (wi)
			{
				wi->wrk = id;			
			}
		}
		break;
			
		case	9000:
		{
			mymsg.AddInt32("x",vl);	
	
			win->PostMessage(&mymsg);
		}
		break;

		case	9001:
		{
			mymsg.AddInt32("y",vl);	
	
			win->PostMessage(&mymsg);
		}
		break;

		case	9002:
		{
			mymsg.AddInt32("w",vl);	
	
			win->PostMessage(&mymsg);
		}
		break;

		case	9003:
		{
			mymsg.AddInt32("h",vl);	
	
			win->PostMessage(&mymsg);
		}
		break;

		case	9004:
		{
			if (strcmp(txt,"") != 0)
			{
				if (is_title_available(txt))
				{
					if (win)
					{
						if (gad = win->sellist.ItemAt(0))
						{
							strcpy(&gad->Name[0],txt);		
						}
							else
						{
							strcpy(&win->Name[0],txt);		
						}
					}
				}
					else
				{
err:				if (EditorWin)
					{
						BAutolock lock(EditorWin);

						if (win)
						{
							if (gad = win->sellist.ItemAt(0))
							{
								EditorWin->name->SetText(&gad->Name[0]);
							}
								else
							{
								EditorWin->name->SetText(&win->Name[0]);
							}
						}	
					}	
				}	
			}
				else
			{
				::beep();
				
				goto err;
			}	
		}
		break;

		case	9005:
		{
			if (win)
			{
				if (gad = win->sellist.ItemAt(0))
				{
					strcpy(&gad->Title[0],txt);		

					ChangeGadgetLabel(gad,txt);
				}
					else
				{
					strcpy(&win->WTitle[0],txt);		

					win->Lock();

					win->ChangeTitleWindow();

					win->Unlock();
				}
			}	
		}
		break;

		case	9006:
		{
			if (gad)
			{
				gad->msg = atoi(txt);
			}
		}
		break;

		case	tab_focus:
		{
			gad->focus = id;		
		}
		break;

		case	align_type:
		{
			if (id == 2)
			{
				EnableRadio(true);

				SetChoiceInMenu(alignx->Menu(),gad->alignx,true);
				SetChoiceInMenu(aligny->Menu(),gad->aligny,true);

			}
				else
			{
				EnableRadio(false);
			}	

			gad->align = id;
		}
		break;
		
		case	align_x:
		{
			gad->alignx = id;
		}
		break;	

		case	align_y:
		{
			gad->aligny = id;
		}
		break;	

		case	gad_derived:
		{
			gad->derived = vl;
		}
		break;

//**************************** BUTTON *****************

		case	tab_button_default:
		{
			gad->data.button.defaut = id;

			set_button_defaut(gad,id);
		}
		break;

		case	tab_button_enabled:
		case	tab_checkbox_enabled:
		{
			gad->enable = id;

			SetEnableGadget(gad,id);
		}
		break;

//**************************** BBOX *****************

		case	tab_bbox_border:
		{
			gad->data.bbox.style = id;

			set_bbox_border(gad,id);
		}
		break;

		case	tab_bbox_label:
		{
			strcpy(&gad->data.bbox.Label[0],txt);

			set_bbox_label(gad,txt);		
		}
		break;

//**************************** CHECKBOX *****************

		case	tab_checkbox_checked:
		{
			gad->data.bcheckbox.checked = id;

			set_checkbox_checked(gad,id);
		}
		break;

//**************************** RADIO *****************

		case	tab_radio_value:
		{
			gad->data.rad.val = id;

			set_radio_checked(gad,id);
		}
		break;

		case	tab_radio_enable:
		{
			gad->enable = id;

			set_radio_enabled(gad,id);
		}
		break;

//**************************** STRING *****************

		case	tab_string_alignlab:
		{
			gad->data.string.alignlab = id;

			set_string_alignment_label(gad,id);		
		}
		break;

		case	tab_string_aligntxt:
		{
			gad->data.string.aligntxt = id;

			set_string_alignment_text(gad,id);		
		}
		break;

		case	tab_string_diviser:
		{
			gad->data.string.pixdiv = vl;

			set_string_divider(gad,vl);		
		}
		break;

		case	tab_string_label:
		{
			strcpy(&gad->data.string.Text[0],txt);

			set_string_label(gad,txt);		
		}
		break;

//**************************** STATUS *****************

		case	tab_status_trail:
		{
			strcpy(&gad->data.sta.Trail[0],txt);

			set_status_label(gad,txt);		
		}
		break;

		case	tab_status_label:
		{
			strcpy(&gad->data.sta.Label[0],txt);

			set_status_trail(gad,txt);		
		}
		break;

		case	tab_status_value:
		{
			gad->data.sta.value = vl;

			set_status_value(gad,vl);
		}
		break;

		case	tab_status_barheight:
		{
			gad->data.sta.barheight = vl;

			set_status_barheight(gad,vl);
		}
		break;

		case	tab_status_max:
		{
			gad->data.sta.maxvalue = vl;

			set_status_maxvalue(gad,vl);
		}
		break;

//**************************** SCROLLER *****************

		case	tab_scroller_value:
		{
			gad->data.bscroller.pos = vl;

			set_scroller_value(gad,vl);
		}
		break;

		case	tab_scroller_min:
		{
			gad->data.bscroller.min = vl;
		}
		break;

		case	tab_scroller_max:
		{
			gad->data.bscroller.max = vl;
		}
		break;

		case	tab_scroller_minstep:
		{
			gad->data.bscroller.minstep = vl;

			set_scroller_minstep(gad,vl);
		}
		break;

		case	tab_scroller_maxstep:
		{
			gad->data.bscroller.maxstep = vl;

			set_scroller_maxstep(gad,vl);
		}
		break;

		case	tab_scroller_minrange:
		{
			gad->data.bscroller.minrange = vl;

			set_scroller_minrange(gad,vl);
		}
		break;

		case	tab_scroller_maxrange:
		{
			gad->data.bscroller.maxrange = vl;

			set_scroller_maxrange(gad,vl);
		}
		break;

//**************************** TAB *****************

		case	tab_tab_width:
		{
			gad->data.tab.tabwidth = id;

			set_tab_width(gad,id);
		}
		break;

		case	tab_tab_height:
		{
			gad->data.tab.tabheight = vl;

			set_tab_height(gad,vl);
		}
		break;

		case	tab_tab_selected:
		{
			gad->data.tab.sel = vl;

			set_tab_select(gad,vl);
		}
		break;

//**************************** MX *****************

		case	tab_mx_align:
		{
			gad->data.mx.align = id;

			set_mx_align(gad,id);
		}
		break;

		case	tab_mx_diviser:
		{
			gad->data.mx.pixdiv = vl;

			set_mx_divider(gad,vl);
		}
		break;

		case	tab_mx_label:
		{
			strcpy(&gad->data.mx.Label[0],txt);

			set_mx_label(gad,txt);		
		}
		break;

//**************************** SLIDER *****************

		case	tab_slider_style:
		{
			gad->data.bslider.style = id;

			set_slider_style(gad,id);
		}
		break;

		case	tab_slider_hashtype:
		{
			gad->data.bslider.hashtype = id;

			set_slider_hashtype(gad,id);
		}
		break;

		case	tab_slider_hashcount:
		{
			gad->data.bslider.hashcount = vl;

			set_slider_hashcount(gad,vl);
		}
		break;

		case	tab_slider_value:
		{
			gad->data.bslider.pos = vl;

			set_slider_value(gad,vl);
		}
		break;

		case	tab_slider_min:
		{
			gad->data.bslider.min = vl;
		}
		break;

		case	tab_slider_max:
		{
			gad->data.bslider.max = vl;
		}
		break;

		case	tab_slider_thickness:
		{
			gad->data.bslider.thickness = vl;

			set_slider_thickness(gad,vl);
		}
		break;

		case	tab_slider_keyinc:
		{
			gad->data.bslider.keyinc = vl;

			set_slider_keyinc(gad,vl);
		}
		break;

		case	tab_slider_label:
		{
			strcpy(&gad->data.bslider.Label[0],txt);

			set_slider_label(gad,txt);		
		}
		break;

		case	tab_slider_minlabel:
		{
			strcpy(&gad->data.bslider.MinLabel[0],txt);

			set_slider_minlabel(gad,txt);		
		}
		break;

		case	tab_slider_maxlabel:
		{
			strcpy(&gad->data.bslider.MaxLabel[0],txt);

			set_slider_maxlabel(gad,txt);		
		}
		break;

//**************************** COLOR *****************

		case	tab_color_layout:
		{
			gad->data.col.layout = id;

			set_color_layout(gad,id);
		}
		break;

		case	tab_color_cellsize:
		{
			gad->data.col.cellsize = id;

			set_color_cellsize(gad,id);
		}
		break;

		case	tab_color_drawbuffered:
		{
			gad->data.col.redrawbuffer = id;
		}
		break;

//**************************** LV *****************

		case	tab_lv_multi:
		{
			gad->data.lv.multi = id;
		}
		break;

//**************************** OLV *****************

		case	tab_olv_multi:
		{
			gad->data.olv.multi = id;
		}
		break;

//**************************** TEXT *****************

		case	tab_text_align:
		{
			gad->data.txt.align = id;

			set_text_align(gad,id);
		}
		break;

		case	tab_number_align:
		{
			gad->data.num.align = id;

			set_text_align(gad,id);
		}
		break;

		case	tab_text_label:
		{
			strcpy(&gad->data.txt.Label[0],txt);

			set_text_text(gad,txt);		
		}
		break;

		case	tab_number_number:
		{
			strcpy(&gad->data.num.Label[0],txt);

			set_number_value(gad,atoi(txt));		
		}
		break;

//**************************** TEDIT *****************

		case	tab_tedit_align:
		{
			gad->data.edi.align = id;
		}
		break;

		case	tab_tedit_selectable:
		{
			gad->data.edi.selectable = id;
		}
		break;

		case	tab_tedit_editable:
		{
			gad->data.edi.editable = id;
		}
		break;

		case	tab_tedit_wordwrap:
		{
			gad->data.edi.wordwrap = id;
		}
		break;

		case	tab_tedit_setstylable:
		{
			gad->data.edi.stylable = id;
		}
		break;

		case	tab_tedit_autoident:
		{
			gad->data.edi.autoident = id;
		}
		break;

		case	tab_tedit_tabwidth:
		{
			gad->data.edi.tabwidth = vl;
		}
		break;

		case	tab_tedit_maxbytes:
		{
			gad->data.edi.maxchars = vl;
		}
		break;

//**************************** END *****************
	
		default:
		{
			BWindow::MessageReceived(msg);
		}
	}
}
Exemple #27
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;
	}
}