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 :
32 232 : SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem );
33 :
34 : // class SdTemplatePopup_Impl --------------------------------------------------
35 :
36 0 : class SdTemplatePopup_Impl : public PopupMenu
37 : {
38 : public:
39 : SdTemplatePopup_Impl();
40 :
41 0 : sal_uInt16 GetCurId() const { return nCurId; }
42 :
43 : private:
44 : sal_uInt16 nCurId;
45 :
46 : virtual void Select() SAL_OVERRIDE;
47 : };
48 :
49 0 : SdTemplatePopup_Impl::SdTemplatePopup_Impl() :
50 : PopupMenu(),
51 0 : nCurId(USHRT_MAX)
52 : {
53 0 : }
54 :
55 0 : void SdTemplatePopup_Impl::Select()
56 : {
57 0 : nCurId = GetCurItemId();
58 0 : }
59 :
60 : // class SdTemplateControl ------------------------------------------
61 :
62 196 : SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId,
63 : sal_uInt16 _nId,
64 : StatusBar& rStb ) :
65 196 : SfxStatusBarControl( _nSlotId, _nId, rStb )
66 : {
67 196 : }
68 :
69 392 : SdTemplateControl::~SdTemplateControl()
70 : {
71 392 : }
72 :
73 205 : void SdTemplateControl::StateChanged(
74 : sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
75 : {
76 205 : if( eState != SfxItemState::DEFAULT || pState->ISA( SfxVoidItem ) )
77 0 : GetStatusBar().SetItemText( GetId(), OUString() );
78 205 : else if ( pState->ISA( SfxStringItem ) )
79 : {
80 205 : msTemplate = ((SfxStringItem*)pState)->GetValue();
81 205 : GetStatusBar().SetItemText( GetId(), msTemplate );
82 : }
83 205 : }
84 :
85 0 : void SdTemplateControl::Paint( const UserDrawEvent& )
86 : {
87 0 : GetStatusBar().SetItemText( GetId(), msTemplate );
88 0 : }
89 :
90 0 : void SdTemplateControl::Command( const CommandEvent& rCEvt )
91 : {
92 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && !GetStatusBar().GetItemText( GetId() ).isEmpty() )
93 : {
94 0 : SfxViewFrame* pViewFrame = SfxViewFrame::Current();
95 :
96 0 : sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame );
97 0 : if( !pViewShellBase )
98 0 : return;
99 :
100 0 : SdDrawDocument* pDoc = pViewShellBase->GetDocument();
101 0 : if( !pDoc )
102 0 : return;
103 :
104 0 : CaptureMouse();
105 0 : SdTemplatePopup_Impl aPop;
106 : {
107 0 : const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PK_STANDARD);
108 :
109 0 : sal_uInt16 nCount = 0;
110 0 : for( sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage )
111 : {
112 0 : SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PK_STANDARD);
113 0 : if( pMaster )
114 0 : aPop.InsertItem( ++nCount, pMaster->GetName() );
115 : }
116 0 : aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
117 :
118 0 : sal_uInt16 nCurrId = aPop.GetCurId()-1;
119 0 : if( nCurrId < nMasterCount )
120 : {
121 0 : SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PK_STANDARD);
122 0 : SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
123 0 : pViewFrame->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT,SfxCallMode::SLOT, &aStyle, 0L );
124 0 : pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
125 0 : pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
126 : }
127 : }
128 :
129 0 : ReleaseMouse();
130 : }
131 114 : }
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|