xref: /aoo42x/main/sw/source/ui/utlui/tmplctrl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 // include ---------------------------------------------------------------
32 
33 
34 #include <svl/style.hxx>
35 #ifndef _MENU_HXX //autogen
36 #include <vcl/menu.hxx>
37 #endif
38 #include <svl/stritem.hxx>
39 #include <sfx2/dispatch.hxx>
40 #ifndef _STATUS_HXX //autogen
41 #include <vcl/status.hxx>
42 #endif
43 
44 #include "wrtsh.hxx"
45 #include "view.hxx"
46 #include "swmodule.hxx"
47 #include "cmdid.h"
48 #include "docsh.hxx"
49 #include "tmplctrl.hxx"
50 
51 
52 // STATIC DATA -----------------------------------------------------------
53 
54 
55 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
56 
57 // class TemplatePopup_Impl --------------------------------------------------
58 
59 class TemplatePopup_Impl : public PopupMenu
60 {
61 public:
62 	TemplatePopup_Impl();
63 
64 	sal_uInt16			GetCurId() const { return nCurId; }
65 
66 private:
67 	sal_uInt16			nCurId;
68 
69 	virtual void    Select();
70 };
71 
72 // -----------------------------------------------------------------------
73 
74 TemplatePopup_Impl::TemplatePopup_Impl() :
75 	PopupMenu(),
76 	nCurId(USHRT_MAX)
77 {
78 }
79 
80 // -----------------------------------------------------------------------
81 
82 void TemplatePopup_Impl::Select()
83 {
84 	nCurId = GetCurItemId();
85 }
86 
87 // class SvxZoomStatusBarControl ------------------------------------------
88 
89 SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
90                                       sal_uInt16 _nId,
91 	                                  StatusBar& rStb ) :
92     SfxStatusBarControl( _nSlotId, _nId, rStb )
93 {
94 }
95 
96 // -----------------------------------------------------------------------
97 
98 SwTemplateControl::~SwTemplateControl()
99 {
100 }
101 
102 // -----------------------------------------------------------------------
103 
104 void SwTemplateControl::StateChanged(
105     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
106 {
107 	if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
108 		GetStatusBar().SetItemText( GetId(), String() );
109 	else if ( pState->ISA( SfxStringItem ) )
110 	{
111 		sTemplate = ((SfxStringItem*)pState)->GetValue();
112 		GetStatusBar().SetItemText( GetId(), sTemplate );
113 	}
114 }
115 
116 // -----------------------------------------------------------------------
117 
118 void SwTemplateControl::Paint( const UserDrawEvent&  )
119 {
120 	GetStatusBar().SetItemText( GetId(), sTemplate );
121 }
122 
123 // -----------------------------------------------------------------------
124 
125 void SwTemplateControl::Command( const CommandEvent& rCEvt )
126 {
127 	if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
128 			GetStatusBar().GetItemText( GetId() ).Len() )
129 	{
130 		CaptureMouse();
131 		TemplatePopup_Impl aPop;
132 		{
133 			SwView* pView = ::GetActiveView();
134 			SwWrtShell* pWrtShell;
135 			if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
136 				!pWrtShell->SwCrsrShell::HasSelection()&&
137 				!pWrtShell->IsSelFrmMode() &&
138 				!pWrtShell->IsObjSelected())
139 			{
140 				SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
141 															GetStyleSheetPool();
142 				pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
143 				if( pPool->Count() > 1 )
144 				{
145 					sal_uInt16 nCount = 0;
146 					SfxStyleSheetBase* pStyle = pPool->First();
147 					while( pStyle )
148 					{
149 						nCount++;
150 						aPop.InsertItem( nCount, pStyle->GetName() );
151 						pStyle = pPool->Next();
152 					}
153 
154 					aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
155                     sal_uInt16 nCurrId = aPop.GetCurId();
156                     if( nCurrId != USHRT_MAX)
157 					{
158 						// sieht etwas umstaendlich aus, anders geht's aber nicht
159                         pStyle = pPool->operator[]( nCurrId - 1 );
160 						SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
161 						pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
162 									FN_SET_PAGE_STYLE,
163 									SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
164 									&aStyle, 0L );
165 					}
166 				}
167 			}
168 		}
169 		ReleaseMouse();
170 	}
171 }
172 
173 
174 
175