xref: /aoo41x/main/sc/source/ui/navipi/scenwnd.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //------------------------------------------------------------------
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
36*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
37*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
38*cdf0e10cSrcweir #include <svl/slstitm.hxx>
39*cdf0e10cSrcweir #include <svl/stritem.hxx>
40*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
41*cdf0e10cSrcweir #include <vcl/svapp.hxx>
42*cdf0e10cSrcweir #include "navipi.hxx"
43*cdf0e10cSrcweir #include "popmenu.hxx"
44*cdf0e10cSrcweir #include "scresid.hxx"
45*cdf0e10cSrcweir #include "sc.hrc"
46*cdf0e10cSrcweir #include "globstr.hrc"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //========================================================================
49*cdf0e10cSrcweir // class ScScenarioWindow ------------------------------------------------
50*cdf0e10cSrcweir //========================================================================
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) :
53*cdf0e10cSrcweir     ListBox( &rParent, WB_BORDER | WB_TABSTOP ),
54*cdf0e10cSrcweir     mrParent( rParent )
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 	Font aFont( GetFont() );
57*cdf0e10cSrcweir 	aFont.SetTransparent( sal_True );
58*cdf0e10cSrcweir 	aFont.SetWeight( WEIGHT_LIGHT );
59*cdf0e10cSrcweir 	SetFont( aFont );
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir ScScenarioListBox::~ScScenarioListBox()
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir void ScScenarioListBox::UpdateEntries( List* pNewEntryList )
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	Clear();
69*cdf0e10cSrcweir     maEntries.clear();
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     if( !pNewEntryList )
72*cdf0e10cSrcweir         return;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     switch( pNewEntryList->Count() )
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         case 0:
77*cdf0e10cSrcweir             // no scenarios in current sheet
78*cdf0e10cSrcweir             mrParent.SetComment( EMPTY_STRING );
79*cdf0e10cSrcweir         break;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir         case 1:
82*cdf0e10cSrcweir             // sheet is a scenario container, comment only
83*cdf0e10cSrcweir             mrParent.SetComment( *static_cast< String* >( pNewEntryList->First() ) );
84*cdf0e10cSrcweir         break;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         default:
87*cdf0e10cSrcweir         {
88*cdf0e10cSrcweir             // sheet contains scenarios
89*cdf0e10cSrcweir             DBG_ASSERT( pNewEntryList->Count() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" );
90*cdf0e10cSrcweir             SetUpdateMode( sal_False );
91*cdf0e10cSrcweir             String* pEntry = static_cast< String* >( pNewEntryList->First() );
92*cdf0e10cSrcweir             while( pEntry )
93*cdf0e10cSrcweir             {
94*cdf0e10cSrcweir                 ScenarioEntry aEntry;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir                 // first entry of a triple is the scenario name
97*cdf0e10cSrcweir                 aEntry.maName = *pEntry;
98*cdf0e10cSrcweir                 // second entry of a triple is the scenario comment
99*cdf0e10cSrcweir                 if( (pEntry = static_cast< String* >( pNewEntryList->Next() )) != 0 )
100*cdf0e10cSrcweir                     aEntry.maComment = *pEntry;
101*cdf0e10cSrcweir                 // third entry of a triple is the protection ("0" = not protected, "1" = protected)
102*cdf0e10cSrcweir                 if( (pEntry = static_cast< String* >( pNewEntryList->Next() )) != 0 )
103*cdf0e10cSrcweir                     aEntry.mbProtected = (pEntry->Len() > 0) && (pEntry->GetChar( 0 ) != '0');
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir                 maEntries.push_back( aEntry );
106*cdf0e10cSrcweir                 InsertEntry( aEntry.maName, LISTBOX_APPEND );
107*cdf0e10cSrcweir                 pEntry = static_cast< String* >( pNewEntryList->Next() );
108*cdf0e10cSrcweir             }
109*cdf0e10cSrcweir             SetUpdateMode( sal_True );
110*cdf0e10cSrcweir             SetNoSelection();
111*cdf0e10cSrcweir             mrParent.SetComment( EMPTY_STRING );
112*cdf0e10cSrcweir         }
113*cdf0e10cSrcweir     }
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir void ScScenarioListBox::Select()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     if( const ScenarioEntry* pEntry = GetSelectedEntry() )
119*cdf0e10cSrcweir         mrParent.SetComment( pEntry->maComment );
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void ScScenarioListBox::DoubleClick()
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     SelectScenario();
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir long ScScenarioListBox::Notify( NotifyEvent& rNEvt )
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     bool bHandled = false;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     if( rNEvt.GetType() == EVENT_KEYINPUT )
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode();
134*cdf0e10cSrcweir         switch( aCode.GetCode() )
135*cdf0e10cSrcweir         {
136*cdf0e10cSrcweir             case KEY_RETURN:
137*cdf0e10cSrcweir                 SelectScenario();
138*cdf0e10cSrcweir                 bHandled = true;
139*cdf0e10cSrcweir             break;
140*cdf0e10cSrcweir             case KEY_DELETE:
141*cdf0e10cSrcweir                 DeleteScenario( true );
142*cdf0e10cSrcweir                 bHandled = true;
143*cdf0e10cSrcweir             break;
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir     else if ( rNEvt.GetType() == EVENT_COMMAND && GetSelectEntryCount() )
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
149*cdf0e10cSrcweir         if ( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             if( const ScenarioEntry* pEntry = GetSelectedEntry() )
152*cdf0e10cSrcweir             {
153*cdf0e10cSrcweir                 if( !pEntry->mbProtected )
154*cdf0e10cSrcweir                 {
155*cdf0e10cSrcweir                     ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) );
156*cdf0e10cSrcweir                     aPopup.Execute( this, pCEvt->GetMousePosPixel() );
157*cdf0e10cSrcweir                     if (aPopup.WasHit())
158*cdf0e10cSrcweir                     {
159*cdf0e10cSrcweir                         switch( aPopup.GetSelected() )
160*cdf0e10cSrcweir                         {
161*cdf0e10cSrcweir                             case RID_NAVIPI_SCENARIO_DELETE:
162*cdf0e10cSrcweir                                 DeleteScenario( true );
163*cdf0e10cSrcweir                             break;
164*cdf0e10cSrcweir                             case RID_NAVIPI_SCENARIO_EDIT:
165*cdf0e10cSrcweir                                 EditScenario();
166*cdf0e10cSrcweir                             break;
167*cdf0e10cSrcweir                         }
168*cdf0e10cSrcweir                     }
169*cdf0e10cSrcweir                 }
170*cdf0e10cSrcweir             }
171*cdf0e10cSrcweir             bHandled = true;
172*cdf0e10cSrcweir         }
173*cdf0e10cSrcweir     }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     return bHandled ? 1 : ListBox::Notify( rNEvt );
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     size_t nPos = GetSelectEntryPos();
181*cdf0e10cSrcweir     return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0;
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir void ScScenarioListBox::ExecuteScenarioSlot( sal_uInt16 nSlotId )
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         SfxStringItem aStringItem( nSlotId, GetSelectEntry() );
189*cdf0e10cSrcweir         pViewFrm->GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aStringItem, 0L, 0L );
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir void ScScenarioListBox::SelectScenario()
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     if( GetSelectEntryCount() > 0 )
196*cdf0e10cSrcweir         ExecuteScenarioSlot( SID_SELECT_SCENARIO );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void ScScenarioListBox::EditScenario()
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     if( GetSelectEntryCount() > 0 )
202*cdf0e10cSrcweir         ExecuteScenarioSlot( SID_EDIT_SCENARIO );
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir void ScScenarioListBox::DeleteScenario( bool bQueryBox )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     if( GetSelectEntryCount() > 0 )
208*cdf0e10cSrcweir         if( !bQueryBox || (::QueryBox( 0, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) ).Execute() == RET_YES) )
209*cdf0e10cSrcweir             ExecuteScenarioSlot( SID_DELETE_SCENARIO );
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir //========================================================================
213*cdf0e10cSrcweir // class ScScenarioWindow ------------------------------------------------
214*cdf0e10cSrcweir //========================================================================
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir ScScenarioWindow::ScScenarioWindow( Window* pParent,const String& aQH_List,
217*cdf0e10cSrcweir 									const String& aQH_Comment)
218*cdf0e10cSrcweir     :   Window      ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ),
219*cdf0e10cSrcweir         aLbScenario ( *this ),
220*cdf0e10cSrcweir         aEdComment  ( this,  WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP )
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir 	Font aFont( GetFont() );
223*cdf0e10cSrcweir 	aFont.SetTransparent( sal_True );
224*cdf0e10cSrcweir 	aFont.SetWeight( WEIGHT_LIGHT );
225*cdf0e10cSrcweir 	aEdComment.SetFont( aFont );
226*cdf0e10cSrcweir 	aEdComment.SetMaxTextLen( 512 );
227*cdf0e10cSrcweir 	aLbScenario.SetPosPixel( Point(0,0) );
228*cdf0e10cSrcweir 	aLbScenario.SetHelpId(HID_SC_SCENWIN_TOP);
229*cdf0e10cSrcweir 	aEdComment.SetHelpId(HID_SC_SCENWIN_BOTTOM);
230*cdf0e10cSrcweir 	aLbScenario.Show();
231*cdf0e10cSrcweir 	aEdComment.Show();
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	aLbScenario.SetQuickHelpText(aQH_List);
234*cdf0e10cSrcweir 	aEdComment.SetQuickHelpText(aQH_Comment);
235*cdf0e10cSrcweir 	aEdComment.SetBackground( Color( COL_LIGHTGRAY ) );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
238*cdf0e10cSrcweir 	if (pViewFrm)
239*cdf0e10cSrcweir 	{
240*cdf0e10cSrcweir 		SfxBindings& rBindings = pViewFrm->GetBindings();
241*cdf0e10cSrcweir 		rBindings.Invalidate( SID_SELECT_SCENARIO );
242*cdf0e10cSrcweir 		rBindings.Update( SID_SELECT_SCENARIO );
243*cdf0e10cSrcweir 	}
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir // -----------------------------------------------------------------------
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir ScScenarioWindow::~ScScenarioWindow()
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void ScScenarioWindow::Paint( const Rectangle& rRec )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
255*cdf0e10cSrcweir 	Color aBgColor = rStyleSettings.GetFaceColor();
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 	SetBackground( aBgColor );
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	Window::Paint( rRec );
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir // -----------------------------------------------------------------------
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	if( pState )
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		aLbScenario.Enable();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 		if ( pState->ISA(SfxStringItem) )
271*cdf0e10cSrcweir 		{
272*cdf0e10cSrcweir 			String aNewEntry( ((const SfxStringItem*)pState)->GetValue() );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 			if ( aNewEntry.Len() > 0 )
275*cdf0e10cSrcweir 				aLbScenario.SelectEntry( aNewEntry );
276*cdf0e10cSrcweir 			else
277*cdf0e10cSrcweir 				aLbScenario.SetNoSelection();
278*cdf0e10cSrcweir 		}
279*cdf0e10cSrcweir 		else if ( pState->ISA(SfxStringListItem) )
280*cdf0e10cSrcweir 		{
281*cdf0e10cSrcweir 			aLbScenario.UpdateEntries( ((SfxStringListItem*)pState)->GetList() );
282*cdf0e10cSrcweir 		}
283*cdf0e10cSrcweir 	}
284*cdf0e10cSrcweir 	else
285*cdf0e10cSrcweir 	{
286*cdf0e10cSrcweir 		aLbScenario.Disable();
287*cdf0e10cSrcweir 		aLbScenario.SetNoSelection();
288*cdf0e10cSrcweir 	}
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir // -----------------------------------------------------------------------
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void ScScenarioWindow::SetSizePixel( const Size& rNewSize )
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir 	Size aSize( rNewSize );
296*cdf0e10cSrcweir 	long nHeight = aSize.Height() / 2;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	Window::SetSizePixel( aSize );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 	aSize.Height() = nHeight;
301*cdf0e10cSrcweir 	aLbScenario.SetSizePixel( aSize );
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	aSize.Height() -= 4;
304*cdf0e10cSrcweir 	aEdComment.SetPosSizePixel(	Point( 0, nHeight+4 ), aSize );
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 
310