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 .
21 #include <svl/style.hxx>
22 #include <vcl/menu.hxx>
23 #include <svl/stritem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <vcl/status.hxx>
29 #include "swmodule.hxx"
32 #include "tmplctrl.hxx"
34 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl
, SfxStringItem
);
36 class SwTemplatePopup_Impl
: public PopupMenu
39 SwTemplatePopup_Impl();
41 sal_uInt16
GetCurId() const { return nCurId
; }
46 virtual void Select();
49 SwTemplatePopup_Impl::SwTemplatePopup_Impl() :
55 void SwTemplatePopup_Impl::Select()
57 nCurId
= GetCurItemId();
60 // class SvxZoomStatusBarControl
62 SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId
,
65 SfxStatusBarControl( _nSlotId
, _nId
, rStb
)
69 SwTemplateControl::~SwTemplateControl()
73 void SwTemplateControl::StateChanged(
74 sal_uInt16
/*nSID*/, SfxItemState eState
, const SfxPoolItem
* pState
)
76 if( eState
!= SFX_ITEM_AVAILABLE
|| pState
->ISA( SfxVoidItem
) )
77 GetStatusBar().SetItemText( GetId(), String() );
78 else if ( pState
->ISA( SfxStringItem
) )
80 sTemplate
= ((SfxStringItem
*)pState
)->GetValue();
81 GetStatusBar().SetItemText( GetId(), sTemplate
);
85 void SwTemplateControl::Paint( const UserDrawEvent
& )
87 GetStatusBar().SetItemText( GetId(), sTemplate
);
90 void SwTemplateControl::Command( const CommandEvent
& rCEvt
)
92 if ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
&&
93 GetStatusBar().GetItemText( GetId() ).Len() )
96 SwTemplatePopup_Impl aPop
;
98 SwView
* pView
= ::GetActiveView();
99 SwWrtShell
* pWrtShell
;
100 if( pView
&& 0 != (pWrtShell
= pView
->GetWrtShellPtr()) &&
101 !pWrtShell
->SwCrsrShell::HasSelection()&&
102 !pWrtShell
->IsSelFrmMode() &&
103 !pWrtShell
->IsObjSelected())
105 SfxStyleSheetBasePool
* pPool
= pView
->GetDocShell()->
107 pPool
->SetSearchMask(SFX_STYLE_FAMILY_PAGE
, SFXSTYLEBIT_ALL
);
108 if( pPool
->Count() > 1 )
110 sal_uInt16 nCount
= 0;
111 SfxStyleSheetBase
* pStyle
= pPool
->First();
115 aPop
.InsertItem( nCount
, pStyle
->GetName() );
116 pStyle
= pPool
->Next();
119 aPop
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel());
120 sal_uInt16 nCurrId
= aPop
.GetCurId();
121 if( nCurrId
!= USHRT_MAX
)
123 // looks a bit awkward, but another way is not possible
124 pStyle
= pPool
->operator[]( nCurrId
- 1 );
125 SfxStringItem
aStyle( FN_SET_PAGE_STYLE
, pStyle
->GetName() );
126 pWrtShell
->GetView().GetViewFrame()->GetDispatcher()->Execute(
128 SFX_CALLMODE_SLOT
|SFX_CALLMODE_RECORD
,
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */