* added support for the editing icons comming in via
B_EDIT_ICON_DATA messages, doesn't load an icon yet (won't look into it within the next 10 hours... ;-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19311 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -63,9 +63,3 @@ resource vector_icon {
|
||||
$"D413BED4133ED4133ED41347F4A24A588915FF"
|
||||
};
|
||||
|
||||
|
||||
//resource large_icon array {
|
||||
//};
|
||||
//
|
||||
//resource mini_icon array {
|
||||
//};
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <FilePanel.h>
|
||||
#include <IconEditorProtocol.h>
|
||||
|
||||
#include "support_settings.h"
|
||||
|
||||
@@ -33,6 +34,7 @@
|
||||
#include "MainWindow.h"
|
||||
#include "MessageExporter.h"
|
||||
#include "MessageImporter.h"
|
||||
#include "MessengerSaver.h"
|
||||
#include "PathContainer.h"
|
||||
#include "RDefExporter.h"
|
||||
#include "SavePanel.h"
|
||||
@@ -172,6 +174,23 @@ IconEditorApp::MessageReceived(BMessage* message)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_EDIT_ICON_DATA: {
|
||||
BMessenger messenger;
|
||||
if (message->FindMessenger("reply to", &messenger) < B_OK) {
|
||||
// required
|
||||
break;
|
||||
}
|
||||
const uint8* data;
|
||||
ssize_t size;
|
||||
if (message->FindData("icon data", B_VECTOR_ICON_TYPE,
|
||||
(const void**)&data, &size) < B_OK) {
|
||||
// optional (new icon will be created)
|
||||
data = NULL;
|
||||
size = 0;
|
||||
}
|
||||
_Open(messenger, data, size);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
@@ -358,6 +377,66 @@ IconEditorApp::_Open(const entry_ref& ref, bool append)
|
||||
}
|
||||
}
|
||||
|
||||
// _Open
|
||||
void
|
||||
IconEditorApp::_Open(const BMessenger& externalObserver,
|
||||
const uint8* data, size_t size)
|
||||
{
|
||||
if (!externalObserver.IsValid())
|
||||
return;
|
||||
|
||||
Icon* icon = new (nothrow) Icon();
|
||||
if (!icon)
|
||||
return;
|
||||
|
||||
if (data && size > 0) {
|
||||
// try to open the icon from the provided data
|
||||
FlatIconImporter flatImporter;
|
||||
status_t ret = flatImporter.Import(icon, const_cast<uint8*>(data), size);
|
||||
// NOTE: the const_cast is a bit ugly, but no harm is done
|
||||
// the reason is that the LittleEndianBuffer knows read and write
|
||||
// mode, in this case it is used read-only, and it does not assume
|
||||
// ownership of the buffer
|
||||
|
||||
if (ret < B_OK) {
|
||||
// inform user of failure at this point
|
||||
BString helper("Opening the icon failed!");
|
||||
helper << "\n\n" << "Error: " << strerror(ret);
|
||||
BAlert* alert = new BAlert("bad news", helper.String(),
|
||||
"Bummer", NULL, NULL);
|
||||
// launch alert asynchronously
|
||||
alert->Go(NULL);
|
||||
|
||||
delete icon;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// keep the mainwindow locked while switching icons
|
||||
bool mainWindowLocked = fMainWindow && fMainWindow->Lock();
|
||||
|
||||
AutoWriteLocker locker(fDocument);
|
||||
|
||||
if (mainWindowLocked)
|
||||
fMainWindow->SetIcon(NULL);
|
||||
|
||||
// incorporate the loaded icon into the document
|
||||
// (either replace it or append to it)
|
||||
fDocument->MakeEmpty();
|
||||
fDocument->SetIcon(icon);
|
||||
|
||||
fDocument->SetNativeSaver(new MessengerSaver(externalObserver));
|
||||
|
||||
locker.Unlock();
|
||||
|
||||
if (mainWindowLocked) {
|
||||
fMainWindow->Unlock();
|
||||
// cause the mainwindow to adopt icon in
|
||||
// it's own thread
|
||||
fMainWindow->PostMessage(MSG_SET_ICON);
|
||||
}
|
||||
}
|
||||
|
||||
// _CreateSaver
|
||||
DocumentSaver*
|
||||
IconEditorApp::_CreateSaver(const entry_ref& ref, uint32 exportMode)
|
||||
|
||||
@@ -66,6 +66,8 @@ class IconEditorApp : public BApplication {
|
||||
void _MakeIconEmpty();
|
||||
void _Open(const entry_ref& ref,
|
||||
bool append = false);
|
||||
void _Open(const BMessenger& externalObserver,
|
||||
const uint8* data, size_t size);
|
||||
DocumentSaver* _CreateSaver(const entry_ref& ref,
|
||||
uint32 exportMode);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ for sourceDir in $(sourceDirs) {
|
||||
}
|
||||
|
||||
# system headers
|
||||
UseLibraryHeaders agg expat ;
|
||||
UseLibraryHeaders agg expat icon ;
|
||||
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ Application Icon-O-Matic :
|
||||
BitmapSetSaver.cpp
|
||||
DocumentSaver.cpp
|
||||
FileSaver.cpp
|
||||
MessengerSaver.cpp
|
||||
SimpleFileSaver.cpp
|
||||
|
||||
# generic/command
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
#include "MessengerSaver.h"
|
||||
|
||||
#include <IconEditorProtocol.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "Document.h"
|
||||
#include "FlatIconExporter.h"
|
||||
|
||||
// constructor
|
||||
MessengerSaver::MessengerSaver(const BMessenger& messenger)
|
||||
: fMessenger(messenger)
|
||||
{
|
||||
}
|
||||
|
||||
// destructor
|
||||
MessengerSaver::~MessengerSaver()
|
||||
{
|
||||
}
|
||||
|
||||
// Save
|
||||
status_t
|
||||
MessengerSaver::Save(Document* document)
|
||||
{
|
||||
#if HAIKU_TARGET_PLATFORM_HAIKU
|
||||
if (!fMessenger.IsValid())
|
||||
return B_NO_INIT;
|
||||
|
||||
FlatIconExporter exporter;
|
||||
BMallocIO stream;
|
||||
status_t ret = exporter.Export(document->Icon(), &stream);
|
||||
if (ret < B_OK)
|
||||
return ret;
|
||||
|
||||
BMessage message(B_ICON_DATA_EDITED);
|
||||
ret = message.AddData("icon data", B_VECTOR_ICON_TYPE,
|
||||
stream.Buffer(), stream.BufferLength());
|
||||
if (ret < B_OK)
|
||||
return ret;
|
||||
|
||||
return fMessenger.SendMessage(&message);
|
||||
#else
|
||||
return B_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef MESSENGER_SAVER_H
|
||||
#define MESSENGER_SAVER_H
|
||||
|
||||
#include <Messenger.h>
|
||||
|
||||
#include "DocumentSaver.h"
|
||||
|
||||
class MessengerSaver : public DocumentSaver {
|
||||
public:
|
||||
MessengerSaver(const BMessenger& messenger);
|
||||
virtual ~MessengerSaver();
|
||||
|
||||
virtual status_t Save(Document* document);
|
||||
|
||||
private:
|
||||
BMessenger fMessenger;
|
||||
};
|
||||
|
||||
#endif // MESSENGER_SAVER_H
|
||||
Reference in New Issue
Block a user