void
Window::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kMsgShowAlert:
		{
			int32 count = fCountSlider->Value();

			BAlert* alert = new BAlert("Test title", "Lorem ipsum dolor sit "
				"amet, consectetur adipiscing elit. Suspendisse vel iaculis "
				"quam. Donec faucibus erat nunc, ac ullamcorper justo sodales.",
				"short 1", count > 1 ? "a bit longer 2" : NULL,
				count > 2 ? "very very long button 3" : NULL,
				_ButtonWidth(), _ButtonSpacing(), _AlertType());
			alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
			int result = alert->Go();
			if (result < 0) {
				fLastStringView->SetText("Canceled alert");
			} else {
				fLastStringView->SetText(BString().SetToFormat(
					"Pressed button %d", result + 1).String());
			}
			break;
		}
		default:
			BWindow::MessageReceived(message);
	}
}
Exemple #2
0
void
ImageView::_UpdateImage()
{
	// ToDo: add scroller if necessary?!

	BAutolock locker(fEditor);

	// we need all the data...

	size_t viewSize = fEditor.ViewSize();
	// that may need some more memory...
	if ((off_t)viewSize < fEditor.FileSize())
		fEditor.SetViewSize(fEditor.FileSize());

	const char *data;
	if (fEditor.GetViewBuffer((const uint8 **)&data) != B_OK) {
		fEditor.SetViewSize(viewSize);
		return;
	}

	if (fBitmap != NULL && (fEditor.Type() == B_MINI_ICON_TYPE
			|| fEditor.Type() == B_LARGE_ICON_TYPE)) {
		// optimize icon update...
		fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8);
		fEditor.SetViewSize(viewSize);
		return;
	}
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
	if (fBitmap != NULL && fEditor.Type() == B_VECTOR_ICON_TYPE
		&& fScaleSlider->Value() * 8 - 1 == fBitmap->Bounds().Width()) {
		if (BIconUtils::GetVectorIcon((const uint8 *)data,
				(size_t)fEditor.FileSize(), fBitmap) == B_OK) {
			fEditor.SetViewSize(viewSize);
			return;
		}
	}
#endif

	delete fBitmap;
	fBitmap = NULL;

	switch (fEditor.Type()) {
		case B_MINI_ICON_TYPE:
			fBitmap = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8);
			if (fBitmap->InitCheck() == B_OK)
				fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8);
			break;
		case B_LARGE_ICON_TYPE:
			fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
			if (fBitmap->InitCheck() == B_OK)
				fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8);
			break;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
		case B_VECTOR_ICON_TYPE:
			fBitmap = new BBitmap(BRect(0, 0, fScaleSlider->Value() * 8 - 1,
				fScaleSlider->Value() * 8 - 1), B_RGB32);
			if (fBitmap->InitCheck() != B_OK
				|| BIconUtils::GetVectorIcon((const uint8 *)data,
					(size_t)fEditor.FileSize(), fBitmap) != B_OK) {
				delete fBitmap;
				fBitmap = NULL;
			}
			break;
#endif
		case B_PNG_FORMAT:
		{
			BMemoryIO stream(data, fEditor.FileSize());
			fBitmap = BTranslationUtils::GetBitmap(&stream);
			break;
		}
		case B_MESSAGE_TYPE:
		{
			BMessage message;
			// ToDo: this could be problematic if the data is not large
			//		enough to contain the message...
			if (message.Unflatten(data) == B_OK)
				fBitmap = new BBitmap(&message);
			break;
		}
	}

	// Update the bitmap description. If no image can be displayed,
	// we will show our "unsupported" message

	if (fBitmap != NULL && fBitmap->InitCheck() != B_OK) {
		delete fBitmap;
		fBitmap = NULL;
	}

	if (fBitmap != NULL) {
		char buffer[256];
		const char *type = B_TRANSLATE("Unknown type");
		switch (fEditor.Type()) {
			case B_MINI_ICON_TYPE:
			case B_LARGE_ICON_TYPE:
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
			case B_VECTOR_ICON_TYPE:
#endif
				type = B_TRANSLATE("Icon");
				break;
			case B_PNG_FORMAT:
				type = B_TRANSLATE("PNG format");
				break;
			case B_MESSAGE_TYPE:
				type = B_TRANSLATE("Flattened bitmap");
				break;
			default:
				break;
		}
		const char *colorSpace;
		switch (fBitmap->ColorSpace()) {
			case B_GRAY1:
			case B_GRAY8:
				colorSpace = B_TRANSLATE("Grayscale");
				break;
			case B_CMAP8:
				colorSpace = B_TRANSLATE("8 bit palette");
				break;
			case B_RGB32:
			case B_RGBA32:
			case B_RGB32_BIG:
			case B_RGBA32_BIG:
				colorSpace = B_TRANSLATE("32 bit");
				break;
			case B_RGB15:
			case B_RGBA15:
			case B_RGB15_BIG:
			case B_RGBA15_BIG:
				colorSpace = B_TRANSLATE("15 bit");
				break;
			case B_RGB16:
			case B_RGB16_BIG:
				colorSpace = B_TRANSLATE("16 bit");
				break;
			default:
				colorSpace = B_TRANSLATE("Unknown format");
				break;
		}
		snprintf(buffer, sizeof(buffer), "%s, %g x %g, %s", type,
			fBitmap->Bounds().Width() + 1, fBitmap->Bounds().Height() + 1, 
			colorSpace);
		fDescriptionView->SetText(buffer);
	} else
		fDescriptionView->SetText(B_TRANSLATE_COMMENT("Could not read image", 
			"Image means here a picture file, not a disk image."));

	// Update the view size to match the image and its description

	float width, height;
	fDescriptionView->GetPreferredSize(&width, &height);
	fDescriptionView->ResizeTo(width, height);

	BRect rect = fDescriptionView->Bounds();
	if (fBitmap != NULL) {
		BRect bounds = fBitmap->Bounds();
		rect.bottom += bounds.Height() + 5;

		if (fScaleSlider != NULL && rect.Width() < fScaleSlider->Bounds().Width())
			rect.right = fScaleSlider->Bounds().right;
		if (bounds.Width() > rect.Width())
			rect.right = bounds.right;

		// center description below the bitmap
		fDescriptionView->MoveTo((rect.Width() - fDescriptionView->Bounds().Width()) / 2,
			bounds.Height() + 5);

		if (fScaleSlider != NULL) {
			// center slider below description
			rect.bottom += fScaleSlider->Bounds().Height() + 5;
			fScaleSlider->MoveTo((rect.Width() - fScaleSlider->Bounds().Width()) / 2,
				fDescriptionView->Frame().bottom + 5);

			if (fScaleSlider->IsHidden())
				fScaleSlider->Show();
		}
	} else if (fScaleSlider != NULL && !fScaleSlider->IsHidden())
		fScaleSlider->Hide();

	ResizeTo(rect.Width(), rect.Height());
	if (Parent()) {
		// center within parent view
		BRect parentBounds = Parent()->Bounds();
		MoveTo((parentBounds.Width() - rect.Width()) / 2,
			(parentBounds.Height() - rect.Height()) / 2);
	}

	Invalidate();

	// restore old view size
	fEditor.SetViewSize(viewSize);
}
Exemple #3
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 #4
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;
	}
}