xref: /AOO41X/main/sd/source/ui/app/tmplctrl.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 
30 #include <vcl/menu.hxx>
31 #include <vcl/status.hxx>
32 #include <svl/style.hxx>
33 #include <svl/stritem.hxx>
34 #include <sfx2/dispatch.hxx>
35 
36 #include "tmplctrl.hxx"
37 #include "ViewShellBase.hxx"
38 #include "drawdoc.hxx"
39 #include "sdattr.hrc"
40 #include "app.hrc"
41 
42 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem );
43 
44 // class TemplatePopup_Impl --------------------------------------------------
45 
46 class TemplatePopup_Impl : public PopupMenu
47 {
48 public:
49     TemplatePopup_Impl();
50 
GetCurId() const51     sal_uInt16          GetCurId() const { return nCurId; }
52 
53 private:
54     sal_uInt16          nCurId;
55 
56     virtual void    Select();
57 };
58 
59 // -----------------------------------------------------------------------
60 
TemplatePopup_Impl()61 TemplatePopup_Impl::TemplatePopup_Impl() :
62     PopupMenu(),
63     nCurId(USHRT_MAX)
64 {
65 }
66 
67 // -----------------------------------------------------------------------
68 
Select()69 void TemplatePopup_Impl::Select()
70 {
71     nCurId = GetCurItemId();
72 }
73 
74 // class SdTemplateControl ------------------------------------------
75 
SdTemplateControl(sal_uInt16 _nSlotId,sal_uInt16 _nId,StatusBar & rStb)76 SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId,
77                                       sal_uInt16 _nId,
78                                       StatusBar& rStb ) :
79     SfxStatusBarControl( _nSlotId, _nId, rStb )
80 {
81 }
82 
83 // -----------------------------------------------------------------------
84 
~SdTemplateControl()85 SdTemplateControl::~SdTemplateControl()
86 {
87 }
88 
89 // -----------------------------------------------------------------------
90 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)91 void SdTemplateControl::StateChanged(
92     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
93 {
94     if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
95         GetStatusBar().SetItemText( GetId(), String() );
96     else if ( pState->ISA( SfxStringItem ) )
97     {
98         msTemplate = ((SfxStringItem*)pState)->GetValue();
99         GetStatusBar().SetItemText( GetId(), msTemplate );
100     }
101 }
102 
103 // -----------------------------------------------------------------------
104 
Paint(const UserDrawEvent &)105 void SdTemplateControl::Paint( const UserDrawEvent&  )
106 {
107     GetStatusBar().SetItemText( GetId(), msTemplate );
108 }
109 
110 // -----------------------------------------------------------------------
111 
Command(const CommandEvent & rCEvt)112 void SdTemplateControl::Command( const CommandEvent& rCEvt )
113 {
114     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && GetStatusBar().GetItemText( GetId() ).Len() )
115     {
116         SfxViewFrame* pViewFrame = SfxViewFrame::Current();
117 
118         sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame );
119         if( !pViewShellBase )
120             return;
121 
122         SdDrawDocument* pDoc = pViewShellBase->GetDocument();
123         if( !pDoc )
124             return;
125 
126         CaptureMouse();
127         TemplatePopup_Impl aPop;
128         {
129             const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PK_STANDARD);
130 
131             sal_uInt16 nCount = 0;
132             for( sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage )
133             {
134                 SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PK_STANDARD);
135                 if( pMaster )
136                     aPop.InsertItem( ++nCount, pMaster->GetName() );
137             }
138             aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
139 
140             sal_uInt16 nCurrId = aPop.GetCurId()-1;
141             if( nCurrId < nMasterCount )
142             {
143                 SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PK_STANDARD);
144                 SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
145                 pViewFrame->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT,SFX_CALLMODE_SLOT, &aStyle, 0L );
146                 pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
147                 pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
148             }
149         }
150 
151         ReleaseMouse();
152     }
153 }
154 
155 
156 
157