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 <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>
26 :
27 : #include <svx/selctrl.hxx>
28 : #include <svx/dialmgr.hxx>
29 : #include <svx/dialogs.hrc>
30 :
31 : #include "stbctrls.h"
32 :
33 15 : SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);
34 :
35 : /// Popup menu to select the selection type
36 0 : class SelectionTypePopup : public PopupMenu
37 : {
38 : public:
39 : SelectionTypePopup( sal_uInt16 nCurrent );
40 : };
41 :
42 : /// Item id's cannot start from 0, so we need to convert
43 0 : static sal_uInt16 id_to_state( sal_uInt16 nId )
44 : {
45 0 : switch ( nId )
46 : {
47 : default: // fall through
48 0 : case SELECTION_STANDARD: return 0;
49 0 : case SELECTION_EXTENDED: return 1;
50 0 : case SELECTION_ADDED: return 2;
51 0 : case SELECTION_BLOCK: return 3;
52 : }
53 : }
54 :
55 : /// Item id's cannot start from 0, so we need to convert
56 0 : static sal_uInt16 state_to_id( sal_uInt16 nState )
57 : {
58 0 : switch ( nState )
59 : {
60 : default: // fall through
61 0 : case 0: return SELECTION_STANDARD;
62 0 : case 1: return SELECTION_EXTENDED;
63 0 : case 2: return SELECTION_ADDED;
64 0 : case 3: return SELECTION_BLOCK;
65 : }
66 : }
67 :
68 0 : SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent )
69 0 : : PopupMenu( ResId( RID_SVXMENU_SELECTION, DIALOG_MGR() ) )
70 : {
71 0 : CheckItem( state_to_id( nCurrent ), true );
72 0 : }
73 :
74 : // class SvxSelectionModeControl -----------------------------------------
75 :
76 0 : SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
77 : sal_uInt16 _nId,
78 : StatusBar& rStb ) :
79 : SfxStatusBarControl( _nSlotId, _nId, rStb ),
80 : mnState( 0 ),
81 0 : maImage( SVX_RES( RID_SVXBMP_SELECTION ) )
82 : {
83 0 : GetStatusBar().SetItemText( GetId(), String() );
84 0 : }
85 :
86 : // -----------------------------------------------------------------------
87 :
88 0 : void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
89 : const SfxPoolItem* pState )
90 : {
91 0 : if ( SFX_ITEM_AVAILABLE == eState )
92 : {
93 : DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
94 0 : SfxUInt16Item* pItem = (SfxUInt16Item*)pState;
95 0 : mnState = pItem->GetValue();
96 :
97 0 : SelectionTypePopup aPop( mnState );
98 0 : GetStatusBar().SetQuickHelpText( GetId(), aPop.GetItemText( state_to_id( mnState ) ) );
99 : }
100 0 : }
101 :
102 : // -----------------------------------------------------------------------
103 :
104 0 : sal_Bool SvxSelectionModeControl::MouseButtonDown( const MouseEvent& rEvt )
105 : {
106 0 : CaptureMouse();
107 0 : SelectionTypePopup aPop( mnState );
108 0 : StatusBar& rStatusbar = GetStatusBar();
109 :
110 0 : if ( aPop.Execute( &rStatusbar, rEvt.GetPosPixel() ) )
111 : {
112 0 : sal_uInt16 nNewState = id_to_state( aPop.GetCurItemId() );
113 0 : if ( nNewState != mnState )
114 : {
115 0 : mnState = nNewState;
116 :
117 0 : ::com::sun::star::uno::Any a;
118 0 : SfxUInt16Item aState( GetSlotId(), mnState );
119 0 : INetURLObject aObj( m_aCommandURL );
120 :
121 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
122 0 : aArgs[0].Name = aObj.GetURLPath();
123 0 : aState.QueryValue( a );
124 0 : aArgs[0].Value = a;
125 :
126 0 : execute( aArgs );
127 : }
128 : }
129 0 : ReleaseMouse();
130 :
131 0 : return sal_True;
132 : }
133 :
134 : // -----------------------------------------------------------------------
135 :
136 0 : void SvxSelectionModeControl::Paint( const UserDrawEvent& rUsrEvt )
137 : {
138 0 : const Rectangle aControlRect = getControlRect();
139 0 : OutputDevice* pDev = rUsrEvt.GetDevice();
140 0 : Rectangle aRect = rUsrEvt.GetRect();
141 :
142 0 : Size aImgSize( maImage.GetSizePixel() );
143 :
144 0 : Point aPos( aRect.Left() + ( aControlRect.GetWidth() - aImgSize.Width() ) / 2,
145 0 : aRect.Top() + ( aControlRect.GetHeight() - aImgSize.Height() ) / 2 );
146 :
147 0 : pDev->DrawImage( aPos, maImage );
148 0 : }
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|