merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / utlui / tmplctrl.cxx
blob0ce43a88586ae33e3a86fa60de4f1373bf2c4203
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tmplctrl.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 // include ---------------------------------------------------------------
37 #include <svtools/style.hxx>
38 #ifndef _MENU_HXX //autogen
39 #include <vcl/menu.hxx>
40 #endif
41 #include <svtools/stritem.hxx>
42 #include <sfx2/dispatch.hxx>
43 #ifndef _STATUS_HXX //autogen
44 #include <vcl/status.hxx>
45 #endif
47 #include "wrtsh.hxx"
48 #include "view.hxx"
49 #include "swmodule.hxx"
50 #include "cmdid.h"
51 #include "docsh.hxx"
52 #include "tmplctrl.hxx"
55 // STATIC DATA -----------------------------------------------------------
58 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
60 // class TemplatePopup_Impl --------------------------------------------------
62 class TemplatePopup_Impl : public PopupMenu
64 public:
65 TemplatePopup_Impl();
67 USHORT GetCurId() const { return nCurId; }
69 private:
70 USHORT nCurId;
72 virtual void Select();
75 // -----------------------------------------------------------------------
77 TemplatePopup_Impl::TemplatePopup_Impl() :
78 PopupMenu(),
79 nCurId(USHRT_MAX)
83 // -----------------------------------------------------------------------
85 void TemplatePopup_Impl::Select()
87 nCurId = GetCurItemId();
90 // class SvxZoomStatusBarControl ------------------------------------------
92 SwTemplateControl::SwTemplateControl( USHORT _nSlotId,
93 USHORT _nId,
94 StatusBar& rStb ) :
95 SfxStatusBarControl( _nSlotId, _nId, rStb )
99 // -----------------------------------------------------------------------
101 SwTemplateControl::~SwTemplateControl()
105 // -----------------------------------------------------------------------
107 void SwTemplateControl::StateChanged(
108 USHORT /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
110 if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
111 GetStatusBar().SetItemText( GetId(), String() );
112 else if ( pState->ISA( SfxStringItem ) )
114 sTemplate = ((SfxStringItem*)pState)->GetValue();
115 GetStatusBar().SetItemText( GetId(), sTemplate );
119 // -----------------------------------------------------------------------
121 void SwTemplateControl::Paint( const UserDrawEvent& )
123 GetStatusBar().SetItemText( GetId(), sTemplate );
126 // -----------------------------------------------------------------------
128 void SwTemplateControl::Command( const CommandEvent& rCEvt )
130 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
131 GetStatusBar().GetItemText( GetId() ).Len() )
133 CaptureMouse();
134 TemplatePopup_Impl aPop;
136 SwView* pView = ::GetActiveView();
137 SwWrtShell* pWrtShell;
138 if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
139 !pWrtShell->SwCrsrShell::HasSelection()&&
140 !pWrtShell->IsSelFrmMode() &&
141 !pWrtShell->IsObjSelected())
143 SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
144 GetStyleSheetPool();
145 pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
146 if( pPool->Count() > 1 )
148 USHORT nCount = 0;
149 SfxStyleSheetBase* pStyle = pPool->First();
150 while( pStyle )
152 nCount++;
153 aPop.InsertItem( nCount, pStyle->GetName() );
154 pStyle = pPool->Next();
157 aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
158 USHORT nCurrId = aPop.GetCurId();
159 if( nCurrId != USHRT_MAX)
161 // sieht etwas umstaendlich aus, anders geht's aber nicht
162 pStyle = pPool->operator[]( nCurrId - 1 );
163 SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
164 pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
165 FN_SET_PAGE_STYLE,
166 SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
167 &aStyle, 0L );
172 ReleaseMouse();