Related: tdf#137748 "Update" should have use-underline
[LibreOffice.git] / vcl / osx / DropTarget.hxx
blobaafb6449599f89442a4cd0dcf65e10adc9642c70
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 #ifndef INCLUDED_VCL_OSX_DROPTARGET_HXX
21 #define INCLUDED_VCL_OSX_DROPTARGET_HXX
23 #include "DataFlavorMapping.hxx"
24 #include <cppuhelper/compbase.hxx>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
28 #include <com/sun/star/datatransfer/dnd/XDropTargetListener.hpp>
29 #include <com/sun/star/datatransfer/dnd/DropTargetDragEnterEvent.hpp>
30 #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
31 #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <cppuhelper/basemutex.hxx>
35 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
37 #include <premac.h>
38 #import <Cocoa/Cocoa.h>
39 #include <postmac.h>
41 class DropTarget;
42 class AquaSalFrame;
44 /* The functions declared in this protocol are actually
45 declared in vcl/inc/osx/salframe.h. Because we want
46 to avoid importing VCL headers in UNO services and
47 on the other hand want to avoid warnings caused by
48 gcc complaining about unknowness of these functions
49 we declare them in a protocol here and cast at the
50 appropriate places.
52 @protocol DraggingDestinationHandler
53 -(void)registerDraggingDestinationHandler:(id)theHandler;
54 -(void)unregisterDraggingDestinationHandler:(id)theHandler;
55 @end
57 @interface DropTargetHelper : NSObject
59 DropTarget* mDropTarget;
62 -(DropTargetHelper*)initWithDropTarget:(DropTarget*)pdt;
64 -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
65 -(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
66 -(void)draggingExited:(id <NSDraggingInfo>)sender;
67 -(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
68 -(BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
69 -(void)concludeDragOperation:(id <NSDraggingInfo>)sender;
71 @end
73 class DropTarget: public cppu::BaseMutex,
74 public cppu::WeakComponentImplHelper< css::lang::XInitialization,
75 css::datatransfer::dnd::XDropTarget,
76 css::datatransfer::dnd::XDropTargetDragContext,
77 css::datatransfer::dnd::XDropTargetDropContext,
78 css::lang::XServiceInfo >
80 public:
81 DropTarget();
82 virtual ~DropTarget() override;
83 DropTarget(const DropTarget&) = delete;
84 DropTarget& operator=(const DropTarget&) = delete;
86 // Overrides WeakComponentImplHelper::disposing which is called by
87 // WeakComponentImplHelper::dispose
88 // Must be called.
89 virtual void SAL_CALL disposing() override;
91 // XInitialization
92 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
94 // XDropTarget
95 virtual void SAL_CALL addDropTargetListener( const css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >& dtl ) override;
97 virtual void SAL_CALL removeDropTargetListener( const css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >& dtl ) override;
99 // Default is not active
100 virtual sal_Bool SAL_CALL isActive() override;
101 virtual void SAL_CALL setActive(sal_Bool isActive) override;
102 virtual sal_Int8 SAL_CALL getDefaultActions() override;
103 virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override;
105 // XDropTargetDragContext
106 virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) override;
107 virtual void SAL_CALL rejectDrag() override;
109 // XDropTargetDragContext
110 virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation) override;
111 virtual void SAL_CALL rejectDrop() override;
112 virtual void SAL_CALL dropComplete(sal_Bool success) override;
114 // XServiceInfo
115 virtual OUString SAL_CALL getImplementationName() override;
116 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
117 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
119 // NSDraggingDestination protocol functions
120 NSDragOperation draggingEntered(id sender);
121 NSDragOperation draggingUpdated(id sender);
122 void draggingExited(id sender);
123 static BOOL prepareForDragOperation();
124 BOOL performDragOperation();
125 void concludeDragOperation(id sender);
127 /* If multiple actions are supported by the drag source and
128 the user did not choose a specific action by pressing a
129 modifier key choose a default action to be proposed to
130 the application.
132 sal_Int8 determineDropAction(sal_Int8 dropActions, id sender) const;
134 private:
135 void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dte);
136 void fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee);
137 void fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte);
138 void fire_dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde);
139 void fire_dropActionChanged(const css::datatransfer::dnd::DropTargetDragEvent& dtde);
141 private:
142 css::uno::Reference< css::datatransfer::dnd::XDropTargetDragContext > mXCurrentDragContext;
143 css::uno::Reference< css::datatransfer::dnd::XDropTargetDropContext > mXCurrentDropContext;
144 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mXCurrentDragClipboard;
145 DataFlavorMapperPtr_t mDataFlavorMapper;
146 id mView;
147 AquaSalFrame* mpFrame;
148 DropTargetHelper* mDropTargetHelper;
149 bool mbActive;
150 sal_Int8 mDragSourceSupportedActions;
151 sal_Int8 mSelectedDropAction;
152 sal_Int8 mDefaultActions;
155 #endif // INCLUDED_VCL_OSX_DROPTARGET_HXX
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */