Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <svl/style.hxx>
22 : #include <vcl/menu.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <sfx2/dispatch.hxx>
25 : #include <vcl/status.hxx>
26 :
27 : #include "wrtsh.hxx"
28 : #include "view.hxx"
29 : #include "swmodule.hxx"
30 : #include "cmdid.h"
31 : #include "docsh.hxx"
32 : #include "tmplctrl.hxx"
33 :
34 411 : SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
35 :
36 0 : class SwTemplatePopup_Impl : public PopupMenu
37 : {
38 : public:
39 : SwTemplatePopup_Impl();
40 :
41 0 : sal_uInt16 GetCurId() const { return nCurId; }
42 :
43 : private:
44 : sal_uInt16 nCurId;
45 :
46 : virtual void Select();
47 : };
48 :
49 0 : SwTemplatePopup_Impl::SwTemplatePopup_Impl() :
50 : PopupMenu(),
51 0 : nCurId(USHRT_MAX)
52 : {
53 0 : }
54 :
55 0 : void SwTemplatePopup_Impl::Select()
56 : {
57 0 : nCurId = GetCurItemId();
58 0 : }
59 :
60 : // class SvxZoomStatusBarControl
61 :
62 378 : SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
63 : sal_uInt16 _nId,
64 : StatusBar& rStb ) :
65 378 : SfxStatusBarControl( _nSlotId, _nId, rStb )
66 : {
67 378 : }
68 :
69 756 : SwTemplateControl::~SwTemplateControl()
70 : {
71 756 : }
72 :
73 607 : void SwTemplateControl::StateChanged(
74 : sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
75 : {
76 607 : if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
77 0 : GetStatusBar().SetItemText( GetId(), String() );
78 607 : else if ( pState->ISA( SfxStringItem ) )
79 : {
80 607 : sTemplate = ((SfxStringItem*)pState)->GetValue();
81 607 : GetStatusBar().SetItemText( GetId(), sTemplate );
82 : }
83 607 : }
84 :
85 0 : void SwTemplateControl::Paint( const UserDrawEvent& )
86 : {
87 0 : GetStatusBar().SetItemText( GetId(), sTemplate );
88 0 : }
89 :
90 0 : void SwTemplateControl::Command( const CommandEvent& rCEvt )
91 : {
92 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
93 0 : GetStatusBar().GetItemText( GetId() ).Len() )
94 : {
95 0 : CaptureMouse();
96 0 : SwTemplatePopup_Impl aPop;
97 : {
98 0 : SwView* pView = ::GetActiveView();
99 : SwWrtShell* pWrtShell;
100 0 : if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
101 0 : !pWrtShell->SwCrsrShell::HasSelection()&&
102 0 : !pWrtShell->IsSelFrmMode() &&
103 0 : !pWrtShell->IsObjSelected())
104 : {
105 0 : SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
106 0 : GetStyleSheetPool();
107 0 : pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
108 0 : if( pPool->Count() > 1 )
109 : {
110 0 : sal_uInt16 nCount = 0;
111 0 : SfxStyleSheetBase* pStyle = pPool->First();
112 0 : while( pStyle )
113 : {
114 0 : nCount++;
115 0 : aPop.InsertItem( nCount, pStyle->GetName() );
116 0 : pStyle = pPool->Next();
117 : }
118 :
119 0 : aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
120 0 : sal_uInt16 nCurrId = aPop.GetCurId();
121 0 : if( nCurrId != USHRT_MAX)
122 : {
123 : // looks a bit awkward, but another way is not possible
124 0 : pStyle = pPool->operator[]( nCurrId - 1 );
125 0 : SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
126 0 : pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
127 : FN_SET_PAGE_STYLE,
128 : SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
129 0 : &aStyle, 0L );
130 : }
131 : }
132 : }
133 : }
134 0 : ReleaseMouse();
135 : }
136 99 : }
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|