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