LibreOffice Module forms (master) 1
clipboarddispatcher.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <editeng/editview.hxx>
22
23#include <com/sun/star/lang/DisposedException.hpp>
25#include <vcl/transfer.hxx>
26#include <osl/diagnose.h>
27
28
29namespace frm
30{
31
32
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::frame;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::util;
37 using namespace ::com::sun::star::beans;
38
39
40 namespace
41 {
42 URL createClipboardURL( OClipboardDispatcher::ClipboardFunc _eFunc )
43 {
44 URL aURL;
45 switch ( _eFunc )
46 {
48 aURL.Complete = ".uno:Cut";
49 break;
51 aURL.Complete = ".uno:Copy";
52 break;
54 aURL.Complete = ".uno:Paste";
55 break;
56 }
57 return aURL;
58 }
59 }
60
62 :ORichTextFeatureDispatcher( _rView, createClipboardURL( _eFunc ) )
63 ,m_eFunc( _eFunc )
64 ,m_bLastKnownEnabled( true )
65 {
66 }
67
68
70 {
71 bool bEnabled = false;
72 switch ( m_eFunc )
73 {
74 case eCut:
75 bEnabled = !getEditView()->IsReadOnly() && getEditView()->HasSelection();
76 break;
77
78 case eCopy:
79 bEnabled = getEditView()->HasSelection();
80 break;
81
82 case ePaste:
83 bEnabled = !getEditView()->IsReadOnly();
84 break;
85 }
86 return bEnabled;
87 }
88
89
91 {
93 aEvent.IsEnabled = implIsEnabled();
94 return aEvent;
95 }
96
97
99 {
100 bool bEnabled = implIsEnabled();
101 if ( m_bLastKnownEnabled == bEnabled )
102 // nothing changed -> no notification
103 return;
104 m_bLastKnownEnabled = bEnabled;
105
107 }
108
109
110 void SAL_CALL OClipboardDispatcher::dispatch( const URL& /*_rURL*/, const Sequence< PropertyValue >& /*Arguments*/ )
111 {
112 ::osl::MutexGuard aGuard( m_aMutex );
113 if ( !getEditView() )
114 throw DisposedException();
115
116 switch ( m_eFunc )
117 {
118 case eCut:
119 getEditView()->Cut();
120 break;
121
122 case eCopy:
123 getEditView()->Copy();
124 break;
125
126 case ePaste:
127 getEditView()->Paste();
128 break;
129 }
130 }
131
133 :OClipboardDispatcher( _rView, ePaste )
134 ,m_bPastePossible( false )
135 {
137 m_pClipListener->AddListener( _rView.GetWindow() );
138
139 // initial state
141 m_bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) ||
142 aDataHelper.HasFormat( SotClipboardFormatId::RTF ) || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) );
143 }
144
145
147 {
148 if ( !isDisposed() )
149 {
150 acquire();
151 dispose();
152 }
153 }
154
155
156 IMPL_LINK( OPasteClipboardDispatcher, OnClipboardChanged, TransferableDataHelper*, _pDataHelper, void )
157 {
158 OSL_ENSURE( _pDataHelper, "OPasteClipboardDispatcher::OnClipboardChanged: ooops!" );
159 m_bPastePossible = _pDataHelper->HasFormat( SotClipboardFormatId::STRING )
160 || _pDataHelper->HasFormat( SotClipboardFormatId::RTF )
161 || _pDataHelper->HasFormat( SotClipboardFormatId::RICHTEXT );
162
163 invalidate();
164 }
165
166
167 void OPasteClipboardDispatcher::disposing( ::osl::ClearableMutexGuard& _rClearBeforeNotify )
168 {
169 OSL_ENSURE( getEditView() && getEditView()->GetWindow(), "OPasteClipboardDispatcher::disposing: EditView should not (yet) be disfunctional here!" );
170 if (m_pClipListener.is())
171 {
172 if (getEditView() && getEditView()->GetWindow())
173 m_pClipListener->RemoveListener( getEditView()->GetWindow() );
174
175 m_pClipListener.clear();
176 }
177
178 OClipboardDispatcher::disposing( _rClearBeforeNotify );
179 }
180
181
183 {
185 }
186
187
188} // namespace frm
189
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
bool IsReadOnly() const
void Copy()
bool HasSelection() const
void Cut()
vcl::Window * GetWindow() const
void Paste()
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
bool HasFormat(SotClipboardFormatId nFormat) const
mutable::osl::Mutex m_aMutex
virtual void SAL_CALL dispatch(const css::util::URL &URL, const css::uno::Sequence< css::beans::PropertyValue > &Arguments) override
virtual void invalidateFeatureState_Broadcast() override
virtual css::frame::FeatureStateEvent buildStatusEvent() const override
virtual bool implIsEnabled() const
determines whether our functionality is currently available to be overridden for ePaste
OClipboardDispatcher(EditView &_rView, ClipboardFunc _eFunc)
virtual bool implIsEnabled() const override
determines whether our functionality is currently available to be overridden for ePaste
virtual void disposing(::osl::ClearableMutexGuard &_rClearBeforeNotify) override
rtl::Reference< TransferableClipboardListener > m_pClipListener
virtual ~OPasteClipboardDispatcher() override
void dispose()
clean up resources associated with this instance
virtual css::frame::FeatureStateEvent buildStatusEvent() const
virtual void disposing(::osl::ClearableMutexGuard &_rClearBeforeNotify)
URL aURL
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
IMPL_LINK(OClickableImageBaseModel, OnImageImportDone, Graphic *, i_pGraphic, void)