Line data Source code
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 :
20 : #include <sfx2/app.hxx>
21 : #include <sfx2/tbxctrl.hxx>
22 : #include <sfx2/bindings.hxx>
23 : #include <sfx2/dispatch.hxx>
24 : #include <tools/gen.hxx>
25 : #include <svl/intitem.hxx>
26 : #include <sot/exchange.hxx>
27 : #include <svl/eitem.hxx>
28 : #include <vcl/toolbox.hxx>
29 : #include <svx/clipboardctl.hxx>
30 : #include <svx/clipfmtitem.hxx>
31 :
32 : #include <svtools/insdlg.hxx>
33 : #include <svx/svxids.hrc>
34 :
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::beans;
37 :
38 : /////////////////////////////////////////////////////////////////
39 :
40 18 : SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
41 :
42 :
43 0 : SvxClipBoardControl::SvxClipBoardControl(
44 : sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
45 :
46 : SfxToolBoxControl( nSlotId, nId, rTbx ),
47 : pClipboardFmtItem( 0 ),
48 : pPopup (0),
49 0 : bDisabled( sal_False )
50 : {
51 0 : addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )));
52 0 : ToolBox& rBox = GetToolBox();
53 0 : rBox.SetItemBits( nId, TIB_DROPDOWN | rBox.GetItemBits( nId ) );
54 0 : rBox.Invalidate();
55 0 : }
56 :
57 :
58 0 : SvxClipBoardControl::~SvxClipBoardControl()
59 : {
60 0 : DelPopup();
61 0 : delete pClipboardFmtItem;
62 0 : }
63 :
64 :
65 0 : SfxPopupWindow* SvxClipBoardControl::CreatePopupWindow()
66 : {
67 0 : const SvxClipboardFmtItem* pFmtItem = PTR_CAST( SvxClipboardFmtItem, pClipboardFmtItem );
68 0 : if ( pFmtItem )
69 : {
70 0 : if (pPopup)
71 0 : pPopup->Clear();
72 : else
73 0 : pPopup = new PopupMenu;
74 :
75 0 : sal_uInt16 nCount = pFmtItem->Count();
76 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
77 : {
78 0 : sal_uIntPtr nFmtID = pFmtItem->GetClipbrdFormatId( i );
79 0 : String aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
80 0 : if (!aFmtStr.Len())
81 0 : aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
82 0 : pPopup->InsertItem( (sal_uInt16)nFmtID, aFmtStr );
83 0 : }
84 :
85 0 : ToolBox& rBox = GetToolBox();
86 0 : sal_uInt16 nId = GetId();
87 0 : rBox.SetItemDown( nId, sal_True );
88 :
89 0 : pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
90 0 : (rBox.GetAlign() == WINDOWALIGN_TOP || rBox.GetAlign() == WINDOWALIGN_BOTTOM) ?
91 0 : POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
92 :
93 0 : rBox.SetItemDown( nId, sal_False );
94 :
95 0 : SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
96 :
97 0 : Any a;
98 0 : Sequence< PropertyValue > aArgs( 1 );
99 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedFormat" ));
100 0 : aItem.QueryValue( a );
101 0 : aArgs[0].Value = a;
102 : Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )),
103 0 : aArgs );
104 : }
105 :
106 0 : GetToolBox().EndSelection();
107 0 : DelPopup();
108 0 : return 0;
109 : }
110 :
111 :
112 0 : SfxPopupWindowType SvxClipBoardControl::GetPopupWindowType() const
113 : {
114 0 : return SFX_POPUPWINDOW_ONTIMEOUT;
115 : }
116 :
117 :
118 0 : void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
119 : {
120 0 : if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
121 : {
122 0 : DELETEZ( pClipboardFmtItem );
123 0 : if ( eState >= SFX_ITEM_AVAILABLE )
124 : {
125 0 : pClipboardFmtItem = pState->Clone();
126 0 : GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | TIB_DROPDOWN );
127 : }
128 0 : else if ( !bDisabled )
129 0 : GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~TIB_DROPDOWN );
130 0 : GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
131 : }
132 : else
133 : {
134 : // enable the item as a whole
135 0 : bDisabled = (GetItemState(pState) == SFX_ITEM_DISABLED);
136 0 : GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
137 : }
138 0 : }
139 :
140 :
141 0 : void SvxClipBoardControl::DelPopup()
142 : {
143 0 : if(pPopup)
144 : {
145 0 : delete pPopup;
146 0 : pPopup = 0;
147 : }
148 0 : }
149 :
150 :
151 : /////////////////////////////////////////////////////////////////
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|