OO.o clipboard patch questions

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dacha
Posts: 10
Joined: Fri Jul 15, 2011 10:18 am

OO.o clipboard patch questions

Post by dacha »

Hi

After working with OO.o basic macros for a few days, I couldn't find a way to copy a value from the watch window of the Basic IDE, so I tried hacking OO.o to do it.

4 hours of compiling OO.o later, and a day of C++ hacking after that, I can get a popup menu to come up when you right-click the watch window in the Basic IDE. This new popup menu contains "Copy", and when you click it, it puts the currently selected watch row's "Value" field into the clipboard. Now on the copying side I put a ::rtl::OUString into the Any and specify "text/plain;charset=utf-16" as the MIME type, but on the pasting side the MIME type has changed to "text/plain;charset=utf-8" yet the bytes coming out are still UTF-16...

My patch is attached and the part of it that copies is quoted below, can someone who knows OO.o internals please take a look and tell me what's wrong?

Thank you

Code: Select all

diff -r 6b24005a31b8 basctl/source/basicide/baside2b.cxx
--- a/basctl/source/basicide/baside2b.cxx	Wed Apr 06 15:10:04 2011 +0200
+++ b/basctl/source/basicide/baside2b.cxx	Sun Jul 17 19:41:21 2011 +0200
@@ -52,6 +52,7 @@
 #include <basobj.hxx>
 #include <iderdll.hxx>
 #include <iderdll2.hxx>
+#include <dlgedclip.hxx>
 #include <vcl/taskpanelist.hxx>
 #include <vcl/help.hxx>
 
@@ -1763,9 +1764,14 @@
     return xPeer;
 }
 
-WatchTreeListBox::WatchTreeListBox( Window* pParent, WinBits nWinBits )
-	: SvHeaderTabListBox( pParent, nWinBits )
-{}
+WatchTreeListBox::WatchTreeListBox( Window* pParent, WinBits nWinBits ) :
+	SvHeaderTabListBox( pParent, nWinBits ),
+	m_ClipboardDataFlavors(1)
+{
+	m_ClipboardDataFlavors[0].MimeType = ::rtl::OUString::createFromAscii("text/plain;charset=utf-16");
+	m_ClipboardDataFlavors[0].HumanPresentableName = ::rtl::OUString::createFromAscii("Unicode Text");
+	m_ClipboardDataFlavors[0].DataType = ::getCppuType( (::rtl::OUString*)0 );
+}
 
 WatchTreeListBox::~WatchTreeListBox()
 {
@@ -1890,6 +1896,52 @@
 	}
 }
 
+void __EXPORT WatchTreeListBox::Command( const CommandEvent& rCEvt )
+{
+	if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
+	{
+		Point aPos( rCEvt.IsMouseEvent() ? rCEvt.GetMousePosPixel() : Point(1,1) );
+		SvLBoxEntry* pEntry = GetCurEntry();
+		if ( pEntry )
+		{
+			PopupMenu aWatchPropMenu( IDEResId( RID_POPUP_WATCHPROPS ) );
+			switch ( aWatchPropMenu.Execute( this, aPos ) )
+			{
+				case RID_COPYWATCH:
+				{
+					Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard();
+					if ( xClipboard.is() )
+					{
+						String value = SvHeaderTabListBox::GetEntryText( pEntry, ITEM_ID_VALUE-1 );
+
+						Sequence< Any > aSeqData(1);
+						Any any;
+						::rtl::OUString tmp = value;
+//sal_Unicode *s = (sal_Unicode*)tmp.getStr();
+//FILE *f = fopen("/tmp/log.txt", "w");
+//while (*s)
+//{
+//  fprintf(f, "%c", (char)*s);
+//  s++;
+//}
+//fprintf(f, "\n");
+//fclose(f);
+						any <<= tmp;
+						aSeqData[0] = any;
+						DlgEdTransferableImpl* pTrans = new DlgEdTransferableImpl( m_ClipboardDataFlavors , aSeqData );
+
+						const sal_uInt32 nRef = Application::ReleaseSolarMutex();
+						xClipboard->setContents( pTrans , pTrans );
+						Application::AcquireSolarMutex( nRef );
+					}
+					Invalidate();
+				}
+				break;
+			}
+		}
+	}
+}
+
 SbxBase* WatchTreeListBox::ImplGetSBXForEntry( SvLBoxEntry* pEntry, bool& rbArrayElement )
 {
 	SbxBase* pSBX = NULL;
Post Reply