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 <svl/style.hxx>
21 : #include <vcl/menu.hxx>
22 : #include <svl/stritem.hxx>
23 : #include <sfx2/dispatch.hxx>
24 : #include <vcl/status.hxx>
25 :
26 : #include <swtypes.hxx>
27 : #include <utlui.hrc>
28 :
29 : #include "wrtsh.hxx"
30 : #include "view.hxx"
31 : #include "swmodule.hxx"
32 : #include "cmdid.h"
33 : #include "docsh.hxx"
34 : #include "tmplctrl.hxx"
35 :
36 405 : SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
37 :
38 0 : class SwTemplatePopup_Impl : public PopupMenu
39 : {
40 : public:
41 : SwTemplatePopup_Impl();
42 :
43 0 : sal_uInt16 GetCurId() const { return nCurId; }
44 :
45 : private:
46 : sal_uInt16 nCurId;
47 :
48 : virtual void Select() SAL_OVERRIDE;
49 : };
50 :
51 0 : SwTemplatePopup_Impl::SwTemplatePopup_Impl() :
52 : PopupMenu(),
53 0 : nCurId(USHRT_MAX)
54 : {
55 0 : }
56 :
57 0 : void SwTemplatePopup_Impl::Select()
58 : {
59 0 : nCurId = GetCurItemId();
60 0 : }
61 :
62 346 : SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
63 : sal_uInt16 _nId,
64 : StatusBar& rStb ) :
65 346 : SfxStatusBarControl( _nSlotId, _nId, rStb )
66 : {
67 346 : GetStatusBar().SetQuickHelpText(GetId(), SW_RESSTR(STR_TMPLCTRL_HINT));
68 346 : }
69 :
70 692 : SwTemplateControl::~SwTemplateControl()
71 : {
72 692 : }
73 :
74 611 : void SwTemplateControl::StateChanged(
75 : sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
76 : {
77 611 : if( eState != SfxItemState::DEFAULT || pState->ISA( SfxVoidItem ) )
78 0 : GetStatusBar().SetItemText( GetId(), OUString() );
79 611 : else if ( pState->ISA( SfxStringItem ) )
80 : {
81 611 : sTemplate = static_cast<const SfxStringItem*>(pState)->GetValue();
82 611 : GetStatusBar().SetItemText( GetId(), sTemplate );
83 : }
84 611 : }
85 :
86 0 : void SwTemplateControl::Paint( const UserDrawEvent& )
87 : {
88 0 : GetStatusBar().SetItemText( GetId(), sTemplate );
89 0 : }
90 :
91 0 : void SwTemplateControl::Command( const CommandEvent& rCEvt )
92 : {
93 0 : if ( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
94 0 : !GetStatusBar().GetItemText( GetId() ).isEmpty() )
95 : {
96 0 : SwTemplatePopup_Impl aPop;
97 : {
98 0 : SwView* pView = ::GetActiveView();
99 : SwWrtShell* pWrtShell;
100 0 : if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
101 0 : !pWrtShell->SwCrsrShell::HasSelection()&&
102 0 : !pWrtShell->IsSelFrmMode() &&
103 0 : !pWrtShell->IsObjSelected())
104 : {
105 0 : SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
106 0 : GetStyleSheetPool();
107 0 : pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
108 0 : if( pPool->Count() > 1 )
109 : {
110 0 : sal_uInt16 nCount = 0;
111 0 : SfxStyleSheetBase* pStyle = pPool->First();
112 0 : while( pStyle )
113 : {
114 0 : aPop.InsertItem( ++nCount, pStyle->GetName() );
115 0 : pStyle = pPool->Next();
116 : }
117 :
118 0 : aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
119 0 : const sal_uInt16 nCurrId = aPop.GetCurId();
120 0 : if( nCurrId != USHRT_MAX)
121 : {
122 : // looks a bit awkward, but another way is not possible
123 0 : pStyle = pPool->operator[]( nCurrId - 1 );
124 0 : SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
125 0 : pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
126 : FN_SET_PAGE_STYLE,
127 : SfxCallMode::SLOT|SfxCallMode::RECORD,
128 0 : &aStyle, 0L );
129 : }
130 : }
131 : }
132 0 : }
133 : }
134 177 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|