xref: /aoo42x/main/sw/source/ui/utlui/tmplctrl.cxx (revision efeef26f)
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_sw.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 
30 #include <svl/style.hxx>
31 #ifndef _MENU_HXX //autogen
32 #include <vcl/menu.hxx>
33 #endif
34 #include <svl/stritem.hxx>
35 #include <sfx2/dispatch.hxx>
36 #ifndef _STATUS_HXX //autogen
37 #include <vcl/status.hxx>
38 #endif
39 
40 #include "wrtsh.hxx"
41 #include "view.hxx"
42 #include "swmodule.hxx"
43 #include "cmdid.h"
44 #include "docsh.hxx"
45 #include "tmplctrl.hxx"
46 
47 
48 // STATIC DATA -----------------------------------------------------------
49 
50 
51 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
52 
53 // class TemplatePopup_Impl --------------------------------------------------
54 
55 class TemplatePopup_Impl : public PopupMenu
56 {
57 public:
58 	TemplatePopup_Impl();
59 
GetCurId() const60 	sal_uInt16			GetCurId() const { return nCurId; }
61 
62 private:
63 	sal_uInt16			nCurId;
64 
65 	virtual void    Select();
66 };
67 
68 // -----------------------------------------------------------------------
69 
TemplatePopup_Impl()70 TemplatePopup_Impl::TemplatePopup_Impl() :
71 	PopupMenu(),
72 	nCurId(USHRT_MAX)
73 {
74 }
75 
76 // -----------------------------------------------------------------------
77 
Select()78 void TemplatePopup_Impl::Select()
79 {
80 	nCurId = GetCurItemId();
81 }
82 
83 // class SvxZoomStatusBarControl ------------------------------------------
84 
SwTemplateControl(sal_uInt16 _nSlotId,sal_uInt16 _nId,StatusBar & rStb)85 SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
86                                       sal_uInt16 _nId,
87 	                                  StatusBar& rStb ) :
88     SfxStatusBarControl( _nSlotId, _nId, rStb )
89 {
90 }
91 
92 // -----------------------------------------------------------------------
93 
~SwTemplateControl()94 SwTemplateControl::~SwTemplateControl()
95 {
96 }
97 
98 // -----------------------------------------------------------------------
99 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)100 void SwTemplateControl::StateChanged(
101     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
102 {
103 	if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
104 		GetStatusBar().SetItemText( GetId(), String() );
105 	else if ( pState->ISA( SfxStringItem ) )
106 	{
107 		sTemplate = ((SfxStringItem*)pState)->GetValue();
108 		GetStatusBar().SetItemText( GetId(), sTemplate );
109 	}
110 }
111 
112 // -----------------------------------------------------------------------
113 
Paint(const UserDrawEvent &)114 void SwTemplateControl::Paint( const UserDrawEvent&  )
115 {
116 	GetStatusBar().SetItemText( GetId(), sTemplate );
117 }
118 
119 // -----------------------------------------------------------------------
120 
Command(const CommandEvent & rCEvt)121 void SwTemplateControl::Command( const CommandEvent& rCEvt )
122 {
123 	if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
124 			GetStatusBar().GetItemText( GetId() ).Len() )
125 	{
126 		CaptureMouse();
127 		TemplatePopup_Impl aPop;
128 		{
129 			SwView* pView = ::GetActiveView();
130 			SwWrtShell* pWrtShell;
131 			if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
132 				!pWrtShell->SwCrsrShell::HasSelection()&&
133 				!pWrtShell->IsSelFrmMode() &&
134 				!pWrtShell->IsObjSelected())
135 			{
136 				SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
137 															GetStyleSheetPool();
138 				pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
139 				if( pPool->Count() > 1 )
140 				{
141 					sal_uInt16 nCount = 0;
142 					SfxStyleSheetBase* pStyle = pPool->First();
143 					while( pStyle )
144 					{
145 						nCount++;
146 						aPop.InsertItem( nCount, pStyle->GetName() );
147 						pStyle = pPool->Next();
148 					}
149 
150 					aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
151                     sal_uInt16 nCurrId = aPop.GetCurId();
152                     if( nCurrId != USHRT_MAX)
153 					{
154 						// sieht etwas umstaendlich aus, anders geht's aber nicht
155                         pStyle = pPool->operator[]( nCurrId - 1 );
156 						SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
157 						pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
158 									FN_SET_PAGE_STYLE,
159 									SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
160 									&aStyle, 0L );
161 					}
162 				}
163 			}
164 		}
165 		ReleaseMouse();
166 	}
167 }
168 
169 
170 
171