1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/shl.hxx>
21 #include <vcl/menu.hxx>
22 #include <vcl/status.hxx>
23 #include <svl/intitem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <tools/urlobj.hxx>
27 #include <svx/selctrl.hxx>
28 #include <svx/dialmgr.hxx>
29 #include <svx/dialogs.hrc>
33 SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl
, SfxUInt16Item
);
35 /// Popup menu to select the selection type
36 class SelectionTypePopup
: public PopupMenu
39 SelectionTypePopup( sal_uInt16 nCurrent
);
42 /// Item id's cannot start from 0, so we need to convert
43 static sal_uInt16
id_to_state( sal_uInt16 nId
)
47 default: // fall through
48 case SELECTION_STANDARD
: return 0;
49 case SELECTION_EXTENDED
: return 1;
50 case SELECTION_ADDED
: return 2;
51 case SELECTION_BLOCK
: return 3;
55 /// Item id's cannot start from 0, so we need to convert
56 static sal_uInt16
state_to_id( sal_uInt16 nState
)
60 default: // fall through
61 case 0: return SELECTION_STANDARD
;
62 case 1: return SELECTION_EXTENDED
;
63 case 2: return SELECTION_ADDED
;
64 case 3: return SELECTION_BLOCK
;
68 SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent
)
69 : PopupMenu( ResId( RID_SVXMENU_SELECTION
, DIALOG_MGR() ) )
71 CheckItem( state_to_id( nCurrent
), true );
74 // class SvxSelectionModeControl -----------------------------------------
76 SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId
,
79 SfxStatusBarControl( _nSlotId
, _nId
, rStb
),
81 maImage( SVX_RES( RID_SVXBMP_SELECTION
) )
83 GetStatusBar().SetItemText( GetId(), String() );
86 // -----------------------------------------------------------------------
88 void SvxSelectionModeControl::StateChanged( sal_uInt16
, SfxItemState eState
,
89 const SfxPoolItem
* pState
)
91 if ( SFX_ITEM_AVAILABLE
== eState
)
93 DBG_ASSERT( pState
->ISA( SfxUInt16Item
), "invalid item type" );
94 SfxUInt16Item
* pItem
= (SfxUInt16Item
*)pState
;
95 mnState
= pItem
->GetValue();
97 SelectionTypePopup
aPop( mnState
);
98 GetStatusBar().SetQuickHelpText( GetId(), aPop
.GetItemText( state_to_id( mnState
) ) );
102 // -----------------------------------------------------------------------
104 sal_Bool
SvxSelectionModeControl::MouseButtonDown( const MouseEvent
& rEvt
)
107 SelectionTypePopup
aPop( mnState
);
108 StatusBar
& rStatusbar
= GetStatusBar();
110 if ( aPop
.Execute( &rStatusbar
, rEvt
.GetPosPixel() ) )
112 sal_uInt16 nNewState
= id_to_state( aPop
.GetCurItemId() );
113 if ( nNewState
!= mnState
)
117 ::com::sun::star::uno::Any a
;
118 SfxUInt16Item
aState( GetSlotId(), mnState
);
119 INetURLObject
aObj( m_aCommandURL
);
121 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs( 1 );
122 aArgs
[0].Name
= aObj
.GetURLPath();
123 aState
.QueryValue( a
);
134 // -----------------------------------------------------------------------
136 void SvxSelectionModeControl::Paint( const UserDrawEvent
& rUsrEvt
)
138 const Rectangle aControlRect
= getControlRect();
139 OutputDevice
* pDev
= rUsrEvt
.GetDevice();
140 Rectangle aRect
= rUsrEvt
.GetRect();
142 Size
aImgSize( maImage
.GetSizePixel() );
144 Point
aPos( aRect
.Left() + ( aControlRect
.GetWidth() - aImgSize
.Width() ) / 2,
145 aRect
.Top() + ( aControlRect
.GetHeight() - aImgSize
.Height() ) / 2 );
147 pDev
->DrawImage( aPos
, maImage
);
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */