tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / vcl / qa / cppunit / dndtest.cxx
blob9120c19c0e9c7d60f7dab5e1759d0d008ec8e4a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unotest/filters-test.hxx>
21 #include <test/bootstrapfixture.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/wrkwin.hxx>
26 #include <vcl/toolkit/lstbox.hxx>
28 #include <cppuhelper/implbase.hxx>
30 #include <com/sun/star/lang/XComponent.hpp>
31 #include <com/sun/star/datatransfer/XTransferable.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
33 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
34 #include <com/sun/star/datatransfer/dnd/XDragSourceListener.hpp>
35 #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp>
36 #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
37 #include <com/sun/star/datatransfer/dnd/XDragGestureListener.hpp>
39 using namespace ::com::sun::star::io;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::datatransfer;
43 using namespace ::com::sun::star::datatransfer::clipboard;
44 using namespace ::com::sun::star::datatransfer::dnd;
46 class MyWin : public WorkWindow
48 public:
49 MyWin( vcl::Window* pParent, WinBits nWinStyle );
51 void MouseMove( const MouseEvent& rMEvt );
52 void MouseButtonDown( const MouseEvent& rMEvt );
53 void MouseButtonUp( const MouseEvent& rMEvt );
54 void KeyInput( const KeyEvent& rKEvt );
55 void KeyUp( const KeyEvent& rKEvt );
56 void Paint( const Rectangle& rRect );
57 void Resize();
60 class MyDragAndDropListener: public ::cppu::WeakImplHelper < XDropTargetListener, XDragGestureListener, XDragSourceListener >
62 vcl::Window * m_pWindow;
64 public:
66 explicit MyDragAndDropListener( vcl::Window * pWindow ) : m_pWindow( pWindow ) {};
68 virtual void SAL_CALL dragGestureRecognized( const DragGestureEvent& dge ) throw(RuntimeException);
69 virtual void SAL_CALL drop( const DropTargetDropEvent& dtde ) throw(RuntimeException);
70 virtual void SAL_CALL dragEnter( const DropTargetDragEnterEvent& dtde ) throw(RuntimeException);
71 virtual void SAL_CALL dragExit( const DropTargetEvent& dte ) throw(RuntimeException);
72 virtual void SAL_CALL dragOver( const DropTargetDragEvent& dtde ) throw(RuntimeException);
73 virtual void SAL_CALL dropActionChanged( const DropTargetDragEvent& dtde ) throw(RuntimeException);
74 virtual void SAL_CALL dragDropEnd( const DragSourceDropEvent& dsde ) throw(RuntimeException);
75 virtual void SAL_CALL dragEnter( const DragSourceDragEvent& dsdee ) throw(RuntimeException);
76 virtual void SAL_CALL dragExit( const DragSourceEvent& dse ) throw(RuntimeException);
77 virtual void SAL_CALL dragOver( const DragSourceDragEvent& dsde ) throw(RuntimeException);
78 virtual void SAL_CALL dropActionChanged( const DragSourceDragEvent& dsde ) throw(RuntimeException);
79 virtual void SAL_CALL disposing( const EventObject& eo ) throw(RuntimeException);
82 class MyInfoBox : public InfoBox
85 public:
87 explicit MyInfoBox( vcl::Window* pParent );
90 class MyListBox : public ListBox
93 public:
95 explicit MyListBox( vcl::Window* pParent );
98 class StringTransferable : public ::cppu::WeakImplHelper< XTransferable >
100 const OUString m_aData;
101 Sequence< DataFlavor > m_aFlavorList;
103 public:
104 explicit StringTransferable( const OUString& rString ) : m_aData( rString ), m_aFlavorList( 1 )
106 DataFlavor df;
108 df.MimeType = "text/plain;charset=utf-16";
109 df.DataType = cppu::UnoType<OUString>::get();
111 m_aFlavorList[0] = df;
114 virtual Any SAL_CALL getTransferData( const DataFlavor& aFlavor ) throw(UnsupportedFlavorException, IOException, RuntimeException);
115 virtual Sequence< DataFlavor > SAL_CALL getTransferDataFlavors( ) throw(RuntimeException);
116 virtual bool SAL_CALL isDataFlavorSupported( const DataFlavor& aFlavor ) throw(RuntimeException);
119 class VclDnDTest : public test::BootstrapFixture
121 public:
122 VclDnDTest() : BootstrapFixture(true, false) {}
124 /// Play with drag and drop
125 void testDnD();
127 CPPUNIT_TEST_SUITE(VclDnDTest);
128 CPPUNIT_TEST(testDnD);
129 CPPUNIT_TEST_SUITE_END();
132 void VclDnDTest::testDnD()
134 MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
135 aMainWin.SetText( OUString( "Drag And Drop - Workbench" ) );
136 aMainWin.Show();
138 // test the clipboard code
139 Reference< XClipboard > xClipboard = aMainWin.GetClipboard();
140 CPPUNIT_ASSERT_MESSAGE("System clipboard not available",
141 xClipboard.is());
143 MyInfoBox aInfoBox( &aMainWin );
144 aInfoBox.Execute();
146 MyListBox aListBox( &aMainWin );
147 aListBox.setPosSizePixel( 10, 10, 100, 100 );
148 aListBox.InsertEntry( OUString("TestItem"));
149 aListBox.Show();
152 MyWin::MyWin( vcl::Window* pParent, WinBits nWinStyle ) :
153 WorkWindow( pParent, nWinStyle )
155 Reference< XDropTargetListener > xListener = new MyDragAndDropListener( this );
157 Reference< XDropTarget > xDropTarget = GetDropTarget();
158 if( xDropTarget.is() )
160 xDropTarget->addDropTargetListener( xListener );
161 xDropTarget->setActive( true );
164 Reference< XDragGestureRecognizer > xRecognizer = GetDragGestureRecognizer();
165 if( xRecognizer.is() )
166 xRecognizer->addDragGestureListener( Reference< XDragGestureListener > ( xListener, UNO_QUERY ) );
169 void MyWin::MouseMove( const MouseEvent& rMEvt )
171 WorkWindow::MouseMove( rMEvt );
174 void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
176 WorkWindow::MouseButtonDown( rMEvt );
179 void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
181 WorkWindow::MouseButtonUp( rMEvt );
184 void MyWin::KeyInput( const KeyEvent& rKEvt )
186 WorkWindow::KeyInput( rKEvt );
189 void MyWin::KeyUp( const KeyEvent& rKEvt )
191 WorkWindow::KeyUp( rKEvt );
194 void MyWin::Paint( const Rectangle& rRect )
196 WorkWindow::Paint( rRect );
199 void MyWin::Resize()
201 WorkWindow::Resize();
204 void SAL_CALL MyDragAndDropListener::dragGestureRecognized( const DragGestureEvent& dge ) throw(RuntimeException)
206 Reference< XDragSource > xDragSource( dge.DragSource, UNO_QUERY );
207 xDragSource->startDrag( dge, -1, 0, 0, new StringTransferable( OUString("TestString") ), this );
210 void SAL_CALL MyDragAndDropListener::drop( const DropTargetDropEvent& dtde ) throw(RuntimeException)
212 dtde.Context->dropComplete( true );
215 void SAL_CALL MyDragAndDropListener::dragEnter( const DropTargetDragEnterEvent& dtdee ) throw(RuntimeException)
217 dtdee.Context->acceptDrag( dtdee.DropAction );
220 void SAL_CALL MyDragAndDropListener::dragExit( const DropTargetEvent& ) throw(RuntimeException)
224 void SAL_CALL MyDragAndDropListener::dragOver( const DropTargetDragEvent& dtde ) throw(RuntimeException)
226 dtde.Context->acceptDrag( dtde.DropAction );
229 void SAL_CALL MyDragAndDropListener::dropActionChanged( const DropTargetDragEvent& dtde ) throw(RuntimeException)
231 dtde.Context->acceptDrag( dtde.DropAction );
234 void SAL_CALL MyDragAndDropListener::dragDropEnd( const DragSourceDropEvent& ) throw(RuntimeException)
238 void SAL_CALL MyDragAndDropListener::dragEnter( const DragSourceDragEvent& ) throw(RuntimeException)
242 void SAL_CALL MyDragAndDropListener::dragExit( const DragSourceEvent& ) throw(RuntimeException)
246 void SAL_CALL MyDragAndDropListener::dragOver( const DragSourceDragEvent& ) throw(RuntimeException)
250 void SAL_CALL MyDragAndDropListener::dropActionChanged( const DragSourceDragEvent& ) throw(RuntimeException)
254 void SAL_CALL MyDragAndDropListener::disposing( const EventObject& ) throw(RuntimeException)
258 MyInfoBox::MyInfoBox( vcl::Window* pParent ) : InfoBox( pParent,
259 OUString("dragging over this box should result in another window id in the drag log.") )
261 Reference< XDropTargetListener > xListener = new MyDragAndDropListener( this );
263 Reference< XDropTarget > xDropTarget = GetDropTarget();
264 if( xDropTarget.is() )
266 xDropTarget->addDropTargetListener( xListener );
267 xDropTarget->setActive( true );
270 Reference< XDragGestureRecognizer > xRecognizer = GetDragGestureRecognizer();
271 if( xRecognizer.is() )
272 xRecognizer->addDragGestureListener( Reference< XDragGestureListener > ( xListener, UNO_QUERY ) );
275 MyListBox::MyListBox( vcl::Window* pParent ) : ListBox( pParent )
277 Reference< XDropTargetListener > xListener = new MyDragAndDropListener( this );
279 Reference< XDropTarget > xDropTarget = GetDropTarget();
280 if( xDropTarget.is() )
282 xDropTarget->addDropTargetListener( xListener );
283 xDropTarget->setActive( true );
286 Reference< XDragGestureRecognizer > xRecognizer = GetDragGestureRecognizer();
287 if( xRecognizer.is() )
288 xRecognizer->addDragGestureListener( Reference< XDragGestureListener > ( xListener, UNO_QUERY ) );
291 Any SAL_CALL StringTransferable::getTransferData( const DataFlavor& )
292 throw(UnsupportedFlavorException, IOException, RuntimeException)
294 return makeAny( m_aData );
297 Sequence< DataFlavor > SAL_CALL StringTransferable::getTransferDataFlavors( )
298 throw(RuntimeException)
300 return m_aFlavorList;
303 bool SAL_CALL StringTransferable::isDataFlavorSupported( const DataFlavor& )
304 throw(RuntimeException)
306 return true;
309 CPPUNIT_TEST_SUITE_REGISTRATION(VclDnDTest);
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */