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 <vcl/menu.hxx>
21 : #include <vcl/status.hxx>
22 : #include <svl/style.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <sfx2/dispatch.hxx>
25 :
26 : #include "tmplctrl.hxx"
27 : #include "ViewShellBase.hxx"
28 : #include "drawdoc.hxx"
29 : #include "sdattr.hrc"
30 : #include "app.hrc"
31 : #include <sdresid.hxx>
32 : #include "strings.hrc"
33 :
34 84 : SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem );
35 :
36 : // class SdTemplatePopup_Impl --------------------------------------------------
37 :
38 0 : class SdTemplatePopup_Impl : public PopupMenu
39 : {
40 : public:
41 : SdTemplatePopup_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 : SdTemplatePopup_Impl::SdTemplatePopup_Impl() :
52 : PopupMenu(),
53 0 : nCurId(USHRT_MAX)
54 : {
55 0 : }
56 :
57 0 : void SdTemplatePopup_Impl::Select()
58 : {
59 0 : nCurId = GetCurItemId();
60 0 : }
61 :
62 : // class SdTemplateControl ------------------------------------------
63 :
64 63 : SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId,
65 : sal_uInt16 _nId,
66 : StatusBar& rStb ) :
67 63 : SfxStatusBarControl( _nSlotId, _nId, rStb )
68 : {
69 63 : GetStatusBar().SetQuickHelpText(GetId(), SD_RESSTR(STR_STATUSBAR_MASTERPAGE));
70 63 : }
71 :
72 126 : SdTemplateControl::~SdTemplateControl()
73 : {
74 126 : }
75 :
76 108 : void SdTemplateControl::StateChanged(
77 : sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
78 : {
79 108 : if( eState != SfxItemState::DEFAULT || pState->ISA( SfxVoidItem ) )
80 0 : GetStatusBar().SetItemText( GetId(), OUString() );
81 108 : else if ( pState->ISA( SfxStringItem ) )
82 : {
83 108 : msTemplate = static_cast<const SfxStringItem*>(pState)->GetValue();
84 108 : GetStatusBar().SetItemText( GetId(), msTemplate );
85 : }
86 108 : }
87 :
88 0 : void SdTemplateControl::Paint( const UserDrawEvent& )
89 : {
90 0 : GetStatusBar().SetItemText( GetId(), msTemplate );
91 0 : }
92 :
93 0 : void SdTemplateControl::Command( const CommandEvent& rCEvt )
94 : {
95 0 : if ( rCEvt.GetCommand() == CommandEventId::ContextMenu && !GetStatusBar().GetItemText( GetId() ).isEmpty() )
96 : {
97 0 : SfxViewFrame* pViewFrame = SfxViewFrame::Current();
98 :
99 0 : sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame );
100 0 : if( !pViewShellBase )
101 0 : return;
102 :
103 0 : SdDrawDocument* pDoc = pViewShellBase->GetDocument();
104 0 : if( !pDoc )
105 0 : return;
106 :
107 0 : SdTemplatePopup_Impl aPop;
108 : {
109 0 : const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PK_STANDARD);
110 :
111 0 : sal_uInt16 nCount = 0;
112 0 : for( sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage )
113 : {
114 0 : SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PK_STANDARD);
115 0 : if( pMaster )
116 0 : aPop.InsertItem( ++nCount, pMaster->GetName() );
117 : }
118 0 : aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
119 :
120 0 : sal_uInt16 nCurrId = aPop.GetCurId()-1;
121 0 : if( nCurrId < nMasterCount )
122 : {
123 0 : SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PK_STANDARD);
124 0 : SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
125 0 : pViewFrame->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT,SfxCallMode::SLOT, &aStyle, 0L );
126 0 : pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
127 0 : pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
128 : }
129 0 : }
130 : }
131 66 : }
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|