summaryrefslogtreecommitdiff
path: root/svx/source/stbctrls/selctrl.cxx
blob: e54760d3a9b6457cfff2a5fe04ff02025e38835d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <tools/shl.hxx>
#include <vcl/menu.hxx>
#include <vcl/status.hxx>
#include <svl/intitem.hxx>
#include <sfx2/dispatch.hxx>
#include <tools/urlobj.hxx>

#include <svx/selctrl.hxx>
#include <svx/dialmgr.hxx>
#include <svx/dialogs.hrc>

#include "stbctrls.h"

SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);

/// Popup menu to select the selection type
class SelectionTypePopup : public PopupMenu
{
public:
    SelectionTypePopup( sal_uInt16 nCurrent );
};

/// Item id's cannot start from 0, so we need to convert
static sal_uInt16 id_to_state( sal_uInt16 nId )
{
    switch ( nId )
    {
        default: // fall through
        case SELECTION_STANDARD: return 0;
        case SELECTION_EXTENDED: return 1;
        case SELECTION_ADDED:    return 2;
        case SELECTION_BLOCK:    return 3;
    }
}

/// Item id's cannot start from 0, so we need to convert
static sal_uInt16 state_to_id( sal_uInt16 nState )
{
    switch ( nState )
    {
        default: // fall through
        case 0: return SELECTION_STANDARD;
        case 1: return SELECTION_EXTENDED;
        case 2: return SELECTION_ADDED;
        case 3: return SELECTION_BLOCK;
    }
}

SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent )
    : PopupMenu( ResId( RID_SVXMENU_SELECTION, DIALOG_MGR() ) )
{
    CheckItem( state_to_id( nCurrent ), true );
}

// class SvxSelectionModeControl -----------------------------------------

SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
                                                  sal_uInt16 _nId,
                                                  StatusBar& rStb ) :
    SfxStatusBarControl( _nSlotId, _nId, rStb ),
    mnState( 0 ),
    maImage( SVX_RES( RID_SVXBMP_SELECTION ) )
{
    GetStatusBar().SetItemText( GetId(), "" );
}

// -----------------------------------------------------------------------

void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
                                            const SfxPoolItem* pState )
{
    if ( SFX_ITEM_AVAILABLE == eState )
    {
        DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
        SfxUInt16Item* pItem = (SfxUInt16Item*)pState;
        mnState = pItem->GetValue();

        SelectionTypePopup aPop( mnState );
        GetStatusBar().SetQuickHelpText( GetId(), aPop.GetItemText( state_to_id( mnState ) ) );
    }
}

// -----------------------------------------------------------------------

sal_Bool SvxSelectionModeControl::MouseButtonDown( const MouseEvent& rEvt )
{
    CaptureMouse();
    SelectionTypePopup aPop( mnState );
    StatusBar& rStatusbar = GetStatusBar();

    if ( aPop.Execute( &rStatusbar, rEvt.GetPosPixel() ) )
    {
        sal_uInt16 nNewState = id_to_state( aPop.GetCurItemId() );
        if ( nNewState != mnState )
        {
            mnState = nNewState;

            ::com::sun::star::uno::Any a;
            SfxUInt16Item aState( GetSlotId(), mnState );
            INetURLObject aObj( m_aCommandURL );

            ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
            aArgs[0].Name  = aObj.GetURLPath();
            aState.QueryValue( a );
            aArgs[0].Value = a;

            execute( aArgs );
        }
    }
    ReleaseMouse();

    return sal_True;
}

// -----------------------------------------------------------------------

void SvxSelectionModeControl::Paint( const UserDrawEvent& rUsrEvt )
{
    const Rectangle aControlRect = getControlRect();
    OutputDevice* pDev = rUsrEvt.GetDevice();
    Rectangle aRect = rUsrEvt.GetRect();

    Size aImgSize( maImage.GetSizePixel() );

    Point aPos( aRect.Left() + ( aControlRect.GetWidth() - aImgSize.Width() ) / 2,
            aRect.Top() + ( aControlRect.GetHeight() - aImgSize.Height() ) / 2 );

    pDev->DrawImage( aPos, maImage );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */