bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / utlui / tmplctrl.cxx
blob456faf6e7d8bf99d5b3ddd3013b392648291a2bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include "wrtsh.hxx"
28 #include "view.hxx"
29 #include "swmodule.hxx"
30 #include "cmdid.h"
31 #include "docsh.hxx"
32 #include "tmplctrl.hxx"
34 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
36 class SwTemplatePopup_Impl : public PopupMenu
38 public:
39 SwTemplatePopup_Impl();
41 sal_uInt16 GetCurId() const { return nCurId; }
43 private:
44 sal_uInt16 nCurId;
46 virtual void Select();
49 SwTemplatePopup_Impl::SwTemplatePopup_Impl() :
50 PopupMenu(),
51 nCurId(USHRT_MAX)
55 void SwTemplatePopup_Impl::Select()
57 nCurId = GetCurItemId();
60 // class SvxZoomStatusBarControl
62 SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
63 sal_uInt16 _nId,
64 StatusBar& rStb ) :
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() )
95 CaptureMouse();
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()->
106 GetStyleSheetPool();
107 pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
108 if( pPool->Count() > 1 )
110 sal_uInt16 nCount = 0;
111 SfxStyleSheetBase* pStyle = pPool->First();
112 while( pStyle )
114 nCount++;
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(
127 FN_SET_PAGE_STYLE,
128 SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
129 &aStyle, 0L );
134 ReleaseMouse();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */