Пример #1
0
int32 color_tear_drag (void *data)
{
	colorTearInfo *tearInfo = (colorTearInfo *) data;
	uint32 buttons = 1;
	BPoint point;
	ColorMenu *menu = tearInfo->parent;
	BRect place = tearInfo->dragRect;
	BView *view = tearInfo->someView;
	// It might seem a good idea to use `menu' as the view, but
	// this gave errors: `Method requires owner but doesn't have one'.
	delete tearInfo;	// The caller doesn't do this (race condition otherwise)

	// printf ("Entering loop; view = %p\n", view);
	while (buttons)
	{
		view->Window()->Lock();
		view->GetMouse (&point, &buttons);
		view->Window()->Unlock();
		snooze (50000);
	}
	// printf ("Exited loop\n");
	view->Window()->Lock();
	point = view->ConvertToScreen (point);
	view->Window()->Unlock();

	// printf ("Released at (%.0f, %.0f)\n", point.x, point.y);
	place.OffsetTo (point);
	
	menu->getParent()->lock->Lock();
	menu->TearDone (place, !menu->getParent()->MenuWinOnScreen);
	menu->getParent()->lock->Unlock();

	return B_NO_ERROR;
}
Пример #2
0
/*!	Returns the current mouse position in screen coordinates.
	Since there is no method to retrieve this in the Be API without a view,
	this looks a bit more complicated.
*/
static BPoint
mouse_position()
{
	BWindow* window = new BWindow(BRect(-1000, -1000, -900, -900), "mouse",
		B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
		B_AVOID_FRONT | B_AVOID_FOCUS);
	BView* view = new BView(window->Bounds(), "mouse", B_FOLLOW_ALL, 0);
	window->AddChild(view);
	window->Run();

	window->Lock();

	BPoint position;
	uint32 buttons;
	view->GetMouse(&position, &buttons);
	view->ConvertToScreen(&position);

	window->Quit();

	return position;
}
Пример #3
0
void
ModulesView::_OpenSaver()
{
	// create new screen saver preview & config

	BView* view = fPreviewView->AddPreview();
	fCurrentName = fSettings.ModuleName();
	fSaverRunner = new ScreenSaverRunner(Window(), view, true, fSettings);
	BScreenSaver* saver = _ScreenSaver();

#ifdef __HAIKU__
	BRect rect = fSettingsBox->InnerFrame().InsetByCopy(4, 4);
#else
	BRect rect = fSettingsBox->Bounds().InsetByCopy(4, 4);
	rect.top += 14;
#endif
	fSettingsView = new BView(rect, "SettingsView", B_FOLLOW_ALL, B_WILL_DRAW);
	fSettingsView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	fSettingsBox->AddChild(fSettingsView);

	if (saver != NULL) {
		fSaverRunner->Run();
		saver->StartConfig(fSettingsView);
	}

	if (fSettingsView->ChildAt(0) == NULL) {
		// There are no settings at all, we add the module name here to
		// let it look a bit better at least.
		BPrivate::BuildScreenSaverDefaultSettingsView(fSettingsView,
			fSettings.ModuleName()[0] ? fSettings.ModuleName() :
			B_TRANSLATE("Blackness"), saver || !fSettings.ModuleName()[0]
				? B_TRANSLATE("No options available") :
				B_TRANSLATE("Could not load screen saver"));
	}

	ScreenSaverWindow* window = dynamic_cast<ScreenSaverWindow*>(Window());
	if (window == NULL)
		return;

	// find the minimal size of the settings view

	float right = 0, bottom = 0;
	int32 i = 0;
	while ((view = fSettingsView->ChildAt(i++)) != NULL) {
		// very simple heuristic...
		float viewRight = view->Frame().right;
		if ((view->ResizingMode() & _rule_(0, 0xf, 0, 0xf))
				== B_FOLLOW_LEFT_RIGHT) {
			float width, height;
			view->GetPreferredSize(&width, &height);
			viewRight = view->Frame().left + width / 2;
		} else if ((view->ResizingMode() & _rule_(0, 0xf, 0, 0xf))
				== B_FOLLOW_RIGHT)
			viewRight = 8 + view->Frame().Width();

		float viewBottom = view->Frame().bottom;
		if ((view->ResizingMode() & _rule_(0xf, 0, 0xf, 0))
				== B_FOLLOW_TOP_BOTTOM) {
			float width, height;
			view->GetPreferredSize(&width, &height);
			viewBottom = view->Frame().top + height;
		} else if ((view->ResizingMode() & _rule_(0xf, 0, 0xf, 0))
				== B_FOLLOW_BOTTOM)
			viewBottom = 8 + view->Frame().Height();

		if (viewRight > right)
			right = viewRight;
		if (viewBottom > bottom)
			bottom = viewBottom;
	}

	if (right < kMinSettingsWidth)
		right = kMinSettingsWidth;
	if (bottom < kMinSettingsHeight)
		bottom = kMinSettingsHeight;

	BPoint leftTop = fSettingsView->LeftTop();
	fSettingsView->ConvertToScreen(&leftTop);
	window->ConvertFromScreen(&leftTop);
	window->SetMinimalSizeLimit(leftTop.x + right + 16,
		leftTop.y + bottom + 16);
}
Пример #4
0
void
ChatWindow::MessageReceived( BMessage * msg )
{
	switch ( msg->what )
	{
		case IM::SETTINGS_UPDATED: {
			if (msg->FindString("people_handler", &fPeopleHandler) != B_OK) {
				fPeopleHandler = kDefaultPeopleHandler;
			};
			
			RebuildDisplay();
		} break;
		case IM::USER_STOPPED_TYPING: {
			BMessage im_msg(IM::MESSAGE);
			im_msg.AddInt32("im_what",IM::USER_STOPPED_TYPING);
			im_msg.AddRef("contact",&fEntry);
			fMan->SendMessage(&im_msg);
			
			stopSelfTypingTimer();
		} break;
		case IM::USER_STARTED_TYPING: {
			BMessage im_msg(IM::MESSAGE);
			im_msg.AddInt32("im_what", IM::USER_STARTED_TYPING);
			im_msg.AddRef("contact", &fEntry);
			fMan->SendMessage(&im_msg);
			
			startSelfTypingTimer();
		} break;
		case IM::DESKBAR_ICON_CLICKED:
		{ // deskbar icon clicked, move to current workspace and activate
			SetWorkspaces( 1 << current_workspace() );
			Activate();
		}	break;
		
		case IM::ERROR:
		case IM::MESSAGE:
		{
			entry_ref contact;
			
			if ( msg->FindRef("contact",&contact) != B_OK )
				return;
				
			if ( contact != fEntry )
				// message not for us, skip it.
				return;
			
			int32 im_what=IM::ERROR;
			
			if ( msg->FindInt32("im_what",&im_what) != B_OK )
				im_what = IM::ERROR;
			
//			int32 old_sel_start, old_sel_end;
			
			char timestr[10];
			time_t now = time(NULL);
			strftime(timestr, sizeof(timestr),"[%H:%M]: ", localtime(&now) );
				
			switch ( im_what )
			{
				case IM::STATUS_CHANGED:
				{
					// This means we're rebuilding menus we don't rally need to rebuild..
					BuildProtocolMenu();
				}	break;
				
				case IM::MESSAGE_SENT:
				{
					fText->Append(timestr, C_TIMESTAMP, C_TIMESTAMP, F_TIMESTAMP);

					BString message;
					msg->FindString("message", &message);
					if (message.Compare("/me ", 4) == 0) {
						fText->Append(_T("* You "), C_ACTION, C_ACTION, F_ACTION);
						message.Remove(0, 4);
						fText->Append(message.String(), C_ACTION, C_ACTION, F_ACTION);
					} else {
						fText->Append(_T("You say: "), C_OWNNICK, C_OWNNICK, F_TEXT);
						//fText->Append(msg->FindString("message"), C_TEXT, C_TEXT, F_TEXT);
					    emoticor->AddText(fText,msg->FindString("message"), C_TEXT, F_TEXT,C_TEXT,F_EMOTICON); //by xeD

					}
					fText->Append("\n", C_TEXT, C_TEXT, F_TEXT);
					fText->ScrollToSelection();
				}	break;
				
				case IM::ERROR:
				{
					BMessage error;
					msg->FindMessage("message", &error);
					
					int32 error_what = -1;
					
					error.FindInt32("im_what", &error_what );
					
					if ( error_what != IM::USER_STARTED_TYPING && 
						 error_what != IM::USER_STOPPED_TYPING )
					{ // ignore messages du to typing
						fText->Append(timestr, C_TIMESTAMP, C_TIMESTAMP, F_TIMESTAMP);
						fText->Append("Error: ", C_TEXT, C_TEXT, F_TEXT);
						fText->Append(msg->FindString("error"), C_TEXT, C_TEXT, F_TEXT);
						fText->Append("\n", C_TEXT, C_TEXT, F_TEXT);
					
						if (!IsActive()) startNotify();
					}
				}	break;
				
				case IM::MESSAGE_RECEIVED:
				{
					if ( msg->FindString("message") == NULL )
					{ // no message to display, probably opened by user
						return;
					}
					
					fText->Append(timestr, C_TIMESTAMP, C_TIMESTAMP, F_TIMESTAMP);
					
					BString protocol = msg->FindString("protocol");
					BString message = msg->FindString("message");
					
					
										
					if (protocol.Length() > 0) {
						fName.ReplaceAll("$protocol$",protocol.String());
					} else {
						fName.ReplaceAll("$protocol$"," ");
					};
					
					if (message.Compare("/me ", 4) == 0) {
						fText->Append("* ", C_ACTION, C_ACTION, F_ACTION);
						fText->Append(fName.String(), C_ACTION, C_ACTION, F_ACTION);
						fText->Append(" ", C_ACTION, C_ACTION, F_ACTION);
						message.Remove(0, 4);
						fText->Append(message.String(), C_ACTION, C_ACTION, F_ACTION);
					} else {
						fText->Append(fName.String(), C_OTHERNICK, C_OTHERNICK, F_TEXT);
						fText->Append(": ", C_OTHERNICK, C_OTHERNICK, F_TEXT);
						emoticor->AddText(fText,msg->FindString("message"), C_TEXT, F_TEXT,C_TEXT,F_EMOTICON); //by xeD

					}
					fText->Append("\n", C_TEXT, C_TEXT, F_TEXT);
					fText->ScrollToSelection();

					if (!IsActive()) startNotify();
					
					stopTypingTimer();
				}	break;
				
				case IM::CONTACT_STARTED_TYPING: {	
					startTypingTimer();
				} break;
				
				case IM::CONTACT_STOPPED_TYPING: {
					stopTypingTimer();
				} break;
				
			}
			
			fText->ScrollToSelection();
			
		}	break;
		
		case SEND_MESSAGE:
		{
			if (fInput->TextLength() == 0) return;
			BMessage im_msg(IM::MESSAGE);
			im_msg.AddInt32("im_what",IM::SEND_MESSAGE);
			im_msg.AddRef("contact",&fEntry);
			im_msg.AddString("message", fInput->Text() );
			
			BMenu *menu = fProtocolMenu->Menu();
			if (menu) {
				IconMenuItem *item = dynamic_cast<IconMenuItem*>(menu->FindMarked());
				if ( item )
				{
					BString connection = item->Extra();
					if (connection.Length() > 0) 
					{
						IM::Connection conn(connection.String());
						
						im_msg.AddString("protocol", conn.Protocol());
						im_msg.AddString("id", conn.ID());
					}
				}	
			};
			
			if ( fMan->SendMessage(&im_msg) == B_OK ) {
				fInput->SetText("");
			} else {
				LOG("im_emoclient", liHigh, "Error sending message to im_server");

				fText->Append(_T("Error: im_server not running, can't send message\n"), C_TEXT, C_TEXT, F_TEXT);
					
				fText->ScrollToSelection();
			};
		}	break;
		
		case SHOW_INFO:
		{
			BMessage open_msg(B_REFS_RECEIVED);
			open_msg.AddRef("refs", &fEntry);
			
			be_roster->Launch(fPeopleHandler.String(), &open_msg);
		}	break;
		
		case VIEW_LOG: {
			BMessage open(B_REFS_RECEIVED);
			open.AddRef("refs", &fEntry);
			be_roster->Launch("application/x-vnd.BeClan.im_binlog_viewer", &open);
		} break;
		
		case VIEW_WEBPAGE: {
			entry_ref htmlRef;
			be_roster->FindApp("application/x-vnd.Be.URL.http", &htmlRef);
			BPath htmlPath(&htmlRef);

			BMessage argv(B_ARGV_RECEIVED);
			argv.AddString("argv", htmlPath.Path());

			int32 length = -1;
			char *url = ReadAttribute(BNode(&fEntry), "META:url", &length);
			if ((url != NULL) && (length > 1)) {
				url = (char *)realloc(url, (length + 1) * sizeof(char));
				url[length] = '\0';
				
				argv.AddString("argv", url);	
				argv.AddInt32("argc", 2);
	
				be_roster->Launch(&htmlRef, &argv);
			} else {
				LOG("im_emoclient", liMedium, "Contact had no homepage");
			};
			
			if (url) free(url);
		} break;
		case VIEW_EMOTICONS: {
			//find emoticon button
 			BView* button = FindView("Emoticons");
 			BRect buttonBounds = button->Bounds();
 			//move emoticon window to just below the button
 			BPoint emotLeftBottom = button->ConvertToScreen(buttonBounds.LeftBottom());
 				
 			popup->SetTargetForItems(this);	
			popup->Go(emotLeftBottom,true,true);
			
		} break;
		case ADD_EMOTICON:
		{
			
			int32 index=msg->FindInt32("index");
			BString txt;
			emoticor->config->menu.FindString("face",index,&txt);
			txt << " ";
			fInput->Insert(txt.String());
		} break;
		case EMAIL:
		{
			BMessage open_msg(B_REFS_RECEIVED);
			open_msg.AddRef("refs", &fEntry);
			// "application/x-vnd.Be-MAIL"
			be_roster->Launch("text/x-email", &open_msg );
		}	break;
		
		case BLOCK:
		{
			IM::Contact contact(fEntry);
			
			char status[256];
			
			if ( contact.GetStatus( status, sizeof(status) ) != B_OK )
				status[0] = 0;
			
			if ( strcmp(status, BLOCKED_TEXT) == 0 )
			{ // already blocked, unblocked
				contact.SetStatus(OFFLINE_TEXT);
				
				BMessage update_msg(IM::UPDATE_CONTACT_STATUS);
				update_msg.AddRef("contact", &fEntry);
				
				fMan->SendMessage( &update_msg );
			} else
			{
				if ( contact.SetStatus(BLOCKED_TEXT) != B_OK )
				{
					LOG("im_emoclient", liHigh, "Block: Error setting contact status");
				}
			}
		}	break;
		
		case AUTH:
		{
			BMessage auth_msg(IM::MESSAGE);
			auth_msg.AddInt32("im_what", IM::REQUEST_AUTH);
			auth_msg.AddRef("contact", &fEntry);
			
			fMan->SendMessage( &auth_msg );
		}	break;
		
		case B_NODE_MONITOR:
		{
			int32 opcode=0;
			
			if ( msg->FindInt32("opcode",&opcode) != B_OK )
				return;
			
			switch ( opcode )
			{
				case B_ENTRY_REMOVED: {
					// oops. should we close down this window now?
					// Nah, we'll just disable everything.
					fInput->MakeEditable(false);
					fInput->SetViewColor( 198,198,198 );
					fInput->Invalidate();
					
					BString title( Title() );
					title += " - DELETED!";
					SetTitle( title.String() );
				}	break;
				case B_ENTRY_MOVED:
				{
					entry_ref ref;
					
					msg->FindInt32("device", &ref.device);
					msg->FindInt64("to directory", &ref.directory);
					ref.set_name( msg->FindString("name") );
					
					fEntry = ref;
					
					BEntry entry(&fEntry);
					if ( !entry.Exists() )
					{
						LOG("im_emoclient", liHigh, "Entry moved: New entry invalid");
					}
				}	break;
				case B_STAT_CHANGED:
				case B_ATTR_CHANGED:
					reloadContact();
					BuildProtocolMenu();
					break;
			}
		}	break;
		
		case kResizeMessage: {
			BView *view = NULL;
			msg->FindPointer("view", reinterpret_cast<void**>(&view));
			if (dynamic_cast<BScrollView *>(view)) {
				BPoint point;
				msg->FindPoint("loc", &point);
				
				fResize->MoveTo(fResize->Frame().left, point.y);
				
				fTextScroll->ResizeTo(fTextScroll->Frame().Width(), point.y - 1 - fDock->Frame().Height() - 1);
				
				fInputScroll->MoveTo(fInputScroll->Frame().left, point.y + 3);
				fInputScroll->ResizeTo( 
					fInputScroll->Bounds().Width(),
					fStatusBar->Frame().top - fInputScroll->Frame().top
				);
				fInput->SetTextRect(fInput->Bounds());
				fInput->ScrollToSelection();
				
				if ( fSendButton )
				{
					fSendButton->MoveTo(fSendButton->Frame().left, point.y + 3);
					fSendButton->ResizeTo( 
						fSendButton->Bounds().Width(),
						fStatusBar->Frame().top - fSendButton->Frame().top
					);
				}
			};
		} break;
		
		case B_MOUSE_WHEEL_CHANGED: {
			fText->MessageReceived(msg);
		} break;
		
		case B_COPY: {
			int32 start = 0;
			int32 end = 0;
			
			fInput->GetSelection(&start, &end);
			
			//printf("%ld - > %ld\n", start, end);
		} break;
		
		case B_SIMPLE_DATA: {
			entry_ref ref;
			BNode node;
//			attr_info info;
			
			for (int i = 0; msg->FindRef("refs", i, &ref) == B_OK; i++) {
				node = BNode(&ref);
				
				char *type = ReadAttribute(node, "BEOS:TYPE");
				if (strcmp(type, "application/x-person") == 0) {
					char *name = ReadAttribute(node, "META:name");
					char *nickname = ReadAttribute(node, "META:nickname");
					char connection[100];
					IM::Contact con(ref);
					con.ConnectionAt(0, connection);

					if (fInput->TextLength() > 0) fInput->Insert("\n");
					fInput->Insert(name);
					fInput->Insert(" (");
					fInput->Insert(nickname);
					fInput->Insert("): ");
					fInput->Insert(connection);

					free(name);
					free(nickname);
				};
				free(type);
			};
			fInput->ScrollToOffset(fInput->TextLength());
		} break;
		
		case CLEAR_TYPING:
			stopTypingTimer();
			break;
		
		case PROTOCOL_SELECTED: {
			// a protocol has been selected. Since BMenuField doesn't resize until later,
			// we have to wait 1000us before actually responding to the change, see below
			if ( fProtocolHack )
				delete fProtocolHack;
			BMessage protoHack(PROTOCOL_SELECTED2);
			fProtocolHack = new BMessageRunner( BMessenger(this), &protoHack, 1000, 1 );
		}	break;
		
		case PROTOCOL_SELECTED2:
			// do what should be done on protocol change
			fStatusBar->PositionViews();
			fInfoView->ResizeTo(
				fStatusBar->Bounds().Width() - fInfoView->Frame().left,
				fInfoView->Bounds().Height()
			);
			break;
		
		default:
			BWindow::MessageReceived(msg);
	}
}