xref: /aoo41x/main/sw/source/ui/utlui/tmplctrl.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <svl/style.hxx>
31cdf0e10cSrcweir #ifndef _MENU_HXX //autogen
32cdf0e10cSrcweir #include <vcl/menu.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <svl/stritem.hxx>
35cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
36cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen
37cdf0e10cSrcweir #include <vcl/status.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "wrtsh.hxx"
41cdf0e10cSrcweir #include "view.hxx"
42cdf0e10cSrcweir #include "swmodule.hxx"
43cdf0e10cSrcweir #include "cmdid.h"
44cdf0e10cSrcweir #include "docsh.hxx"
45cdf0e10cSrcweir #include "tmplctrl.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // class TemplatePopup_Impl --------------------------------------------------
54cdf0e10cSrcweir 
55cdf0e10cSrcweir class TemplatePopup_Impl : public PopupMenu
56cdf0e10cSrcweir {
57cdf0e10cSrcweir public:
58cdf0e10cSrcweir 	TemplatePopup_Impl();
59cdf0e10cSrcweir 
GetCurId() const60cdf0e10cSrcweir 	sal_uInt16			GetCurId() const { return nCurId; }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir private:
63cdf0e10cSrcweir 	sal_uInt16			nCurId;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	virtual void    Select();
66cdf0e10cSrcweir };
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // -----------------------------------------------------------------------
69cdf0e10cSrcweir 
TemplatePopup_Impl()70cdf0e10cSrcweir TemplatePopup_Impl::TemplatePopup_Impl() :
71cdf0e10cSrcweir 	PopupMenu(),
72cdf0e10cSrcweir 	nCurId(USHRT_MAX)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // -----------------------------------------------------------------------
77cdf0e10cSrcweir 
Select()78cdf0e10cSrcweir void TemplatePopup_Impl::Select()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	nCurId = GetCurItemId();
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir // class SvxZoomStatusBarControl ------------------------------------------
84cdf0e10cSrcweir 
SwTemplateControl(sal_uInt16 _nSlotId,sal_uInt16 _nId,StatusBar & rStb)85cdf0e10cSrcweir SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
86cdf0e10cSrcweir                                       sal_uInt16 _nId,
87cdf0e10cSrcweir 	                                  StatusBar& rStb ) :
88cdf0e10cSrcweir     SfxStatusBarControl( _nSlotId, _nId, rStb )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // -----------------------------------------------------------------------
93cdf0e10cSrcweir 
~SwTemplateControl()94cdf0e10cSrcweir SwTemplateControl::~SwTemplateControl()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // -----------------------------------------------------------------------
99cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)100cdf0e10cSrcweir void SwTemplateControl::StateChanged(
101cdf0e10cSrcweir     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
104cdf0e10cSrcweir 		GetStatusBar().SetItemText( GetId(), String() );
105cdf0e10cSrcweir 	else if ( pState->ISA( SfxStringItem ) )
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		sTemplate = ((SfxStringItem*)pState)->GetValue();
108cdf0e10cSrcweir 		GetStatusBar().SetItemText( GetId(), sTemplate );
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // -----------------------------------------------------------------------
113cdf0e10cSrcweir 
Paint(const UserDrawEvent &)114cdf0e10cSrcweir void SwTemplateControl::Paint( const UserDrawEvent&  )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	GetStatusBar().SetItemText( GetId(), sTemplate );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir // -----------------------------------------------------------------------
120cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)121cdf0e10cSrcweir void SwTemplateControl::Command( const CommandEvent& rCEvt )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
124cdf0e10cSrcweir 			GetStatusBar().GetItemText( GetId() ).Len() )
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 		CaptureMouse();
127cdf0e10cSrcweir 		TemplatePopup_Impl aPop;
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			SwView* pView = ::GetActiveView();
130cdf0e10cSrcweir 			SwWrtShell* pWrtShell;
131cdf0e10cSrcweir 			if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
132cdf0e10cSrcweir 				!pWrtShell->SwCrsrShell::HasSelection()&&
133cdf0e10cSrcweir 				!pWrtShell->IsSelFrmMode() &&
134cdf0e10cSrcweir 				!pWrtShell->IsObjSelected())
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
137cdf0e10cSrcweir 															GetStyleSheetPool();
138cdf0e10cSrcweir 				pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
139cdf0e10cSrcweir 				if( pPool->Count() > 1 )
140cdf0e10cSrcweir 				{
141cdf0e10cSrcweir 					sal_uInt16 nCount = 0;
142cdf0e10cSrcweir 					SfxStyleSheetBase* pStyle = pPool->First();
143cdf0e10cSrcweir 					while( pStyle )
144cdf0e10cSrcweir 					{
145cdf0e10cSrcweir 						nCount++;
146cdf0e10cSrcweir 						aPop.InsertItem( nCount, pStyle->GetName() );
147cdf0e10cSrcweir 						pStyle = pPool->Next();
148cdf0e10cSrcweir 					}
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 					aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
151cdf0e10cSrcweir                     sal_uInt16 nCurrId = aPop.GetCurId();
152cdf0e10cSrcweir                     if( nCurrId != USHRT_MAX)
153cdf0e10cSrcweir 					{
154cdf0e10cSrcweir 						// sieht etwas umstaendlich aus, anders geht's aber nicht
155cdf0e10cSrcweir                         pStyle = pPool->operator[]( nCurrId - 1 );
156cdf0e10cSrcweir 						SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
157cdf0e10cSrcweir 						pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
158cdf0e10cSrcweir 									FN_SET_PAGE_STYLE,
159cdf0e10cSrcweir 									SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
160cdf0e10cSrcweir 									&aStyle, 0L );
161cdf0e10cSrcweir 					}
162cdf0e10cSrcweir 				}
163cdf0e10cSrcweir 			}
164cdf0e10cSrcweir 		}
165cdf0e10cSrcweir 		ReleaseMouse();
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
171