Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9580/src/gui
Modified Files:
wxComposeView.cpp
Log Message:
Allow dropping messages from a folder to the composer window.
Index: wxComposeView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxComposeView.cpp,v
retrieving revision 1.391
retrieving revision 1.392
diff -b -u -2 -r1.391 -r1.392
--- wxComposeView.cpp 15 Nov 2005 15:22:30 -0000 1.391
+++ wxComposeView.cpp 16 Nov 2005 15:58:40 -0000 1.392
@@ -72,5 +72,5 @@
#include <wx/fontmap.h>
#include <wx/fontutil.h> // for wxNativeFontInfo
-#include <wx/dnd.h>
+
// windows.h included from wx/fontutil.h under Windows #defines this
#ifdef __CYGWIN__
@@ -101,4 +101,8 @@
#include "modules/Calendar.h"
+#include "Mdnd.h"
+#include "UIdArray.h"
+
+
// ----------------------------------------------------------------------------
// options we use here
@@ -1909,22 +1913,88 @@
-// A simple subclass of wxFileDropTarget so that the composer
-// window can be dropped files to be attached to the message...
+
//
-// Todo: also allow messages to be dropped (but this is much more complicated)
+// wxDataObjectCompositeEx: written by Gunnar Roth <gunnar.roth <at> gmx.de>
+// See http://article.gmane.org/gmane.comp.lib.wxwidgets.general/22384
+//
+// The problem with the wxDataObjectComposite is that it is not possible
+// to know which wxDataObject did receive the data... Let's store it.
+//
+class wxDataObjectCompositeEx : public wxDataObjectComposite
+{
+private:
+ wxDataObjectSimple *m_dataObjectLast;
-class wxComposeViewFileDropTarget : public wxFileDropTarget {
public:
- wxComposeViewFileDropTarget(wxComposeView* composeView)
- : wxFileDropTarget()
+ wxDataObjectCompositeEx()
+ {
+ m_dataObjectLast = NULL;
+ }
+
+ bool SetData(const wxDataFormat& format, size_t len, const void *buf)
+ {
+ m_dataObjectLast = GetObject(format);
+ wxCHECK_MSG( m_dataObjectLast, FALSE, wxT("unsupported format in
wxDataObjectCompositeEx"));
+ return m_dataObjectLast->SetData(len, buf);
+ }
+
+ wxDataObjectSimple *GetActualDataObject()
+ {
+ return m_dataObjectLast;
+ }
+};
+
+
+class wxComposeViewDropTarget : public wxDropTarget
+{
+private:
+ wxComposeView* m_composeView;
+ wxFileDataObject* m_fileDataObject;
+ MMessagesDataObject* m_messageDataObject;
+
+public:
+ wxComposeViewDropTarget(wxComposeView* composeView)
+ : wxDropTarget()
, m_composeView(composeView)
- {}
+ , m_fileDataObject(new wxFileDataObject())
+ , m_messageDataObject(new MMessagesDataObject())
+ {
+ wxDataObjectComposite* dataObjectComposite = new wxDataObjectCompositeEx();
+ dataObjectComposite->Add(m_messageDataObject);
+ dataObjectComposite->Add(m_fileDataObject);
+ SetDataObject(dataObjectComposite);
+ }
+
+ virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) {
+ if ( !GetData() )
+ {
+ wxLogDebug(_T("Failed to get drag and drop data"));
+ return wxDragNone;
+ }
- // This method is called when a set of files is dropped onto the window
- virtual bool OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const
wxArrayString& filenames) {
+ // Let's see which wxDataObject got the data...
+ wxDataObjectSimple* dobj =
((wxDataObjectCompositeEx*)GetDataObject())->GetActualDataObject();
+ if ( dobj == (wxDataObjectSimple *)m_messageDataObject )
+ {
+ // We got messages dropped (from inside M itself)
+ return OnDropMessages(x, y, m_messageDataObject->GetFolder(),
m_messageDataObject->GetMessages()) ? def : wxDragNone;
+ }
+ else if ( dobj == m_fileDataObject )
+ {
+ // We got files dropped from outside M
+ return OnDropFiles(x, y, m_fileDataObject->GetFilenames()) ? def :
wxDragNone;
+ }
+ return wxDragNone;
+ }
+
+
+ bool OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const
wxArrayString& filenames) {
size_t countFiles = filenames.GetCount();
+ if ( countFiles <= 0 )
+ {
+ return false;
+ }
for ( size_t nFiles = 0; nFiles < countFiles; nFiles++ )
{
- // Insert each of them as an attachment
m_composeView->InsertFile(filenames[nFiles]);
}
@@ -1932,8 +2002,21 @@
}
-private:
- wxComposeView* m_composeView;
+ bool OnDropMessages(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), MailFolder*
folder, const UIdArray& messages) {
+ if ( messages.Count() <= 0 )
+ {
+ return false;
+ }
+ for ( size_t i = 0; i < messages.Count(); i++ )
+ {
+ Message_obj msg(folder->GetMessage(messages[i]));
+ wxString str;
+ msg->WriteToString(str);
+ m_composeView->InsertData(wxStrdup(str), str.Length(),
_T("message/rfc822"), _T(""));
+ }
+ return true;
+ }
};
+
void
wxComposeView::Create(wxWindow * WXUNUSED(parent), Profile *parentProfile)
@@ -1955,8 +2038,7 @@
CreateToolAndStatusBars();
- // Create the wxFileDropTarget subclass that allows to
- // drop files in the Composer window
- SetDropTarget(new wxComposeViewFileDropTarget(this));
-
+ // Create the wxDropTarget subclass that allows to
+ // drop files or messages in the Composer window
+ SetDropTarget(new wxComposeViewDropTarget(this));
// create the child controls
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates