merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / navipi / scenwnd.cxx
blobecb67a251b10b4701ee4929270bacbdac71e00e3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scenwnd.cxx,v $
10 * $Revision: 1.9.90.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <svtools/slstitm.hxx>
42 #include <svtools/stritem.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <vcl/svapp.hxx>
45 #include "navipi.hxx"
46 #include "popmenu.hxx"
47 #include "scresid.hxx"
48 #include "sc.hrc"
49 #include "globstr.hrc"
51 //========================================================================
52 // class ScScenarioWindow ------------------------------------------------
53 //========================================================================
55 ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) :
56 ListBox( &rParent, WB_BORDER | WB_TABSTOP ),
57 mrParent( rParent )
59 Font aFont( GetFont() );
60 aFont.SetTransparent( TRUE );
61 aFont.SetWeight( WEIGHT_LIGHT );
62 SetFont( aFont );
65 ScScenarioListBox::~ScScenarioListBox()
69 void ScScenarioListBox::UpdateEntries( List* pNewEntryList )
71 Clear();
72 maEntries.clear();
74 if( !pNewEntryList )
75 return;
77 switch( pNewEntryList->Count() )
79 case 0:
80 // no scenarios in current sheet
81 mrParent.SetComment( EMPTY_STRING );
82 break;
84 case 1:
85 // sheet is a scenario container, comment only
86 mrParent.SetComment( *static_cast< String* >( pNewEntryList->First() ) );
87 break;
89 default:
91 // sheet contains scenarios
92 DBG_ASSERT( pNewEntryList->Count() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" );
93 SetUpdateMode( FALSE );
94 String* pEntry = static_cast< String* >( pNewEntryList->First() );
95 while( pEntry )
97 ScenarioEntry aEntry;
99 // first entry of a triple is the scenario name
100 aEntry.maName = *pEntry;
101 // second entry of a triple is the scenario comment
102 if( (pEntry = static_cast< String* >( pNewEntryList->Next() )) != 0 )
103 aEntry.maComment = *pEntry;
104 // third entry of a triple is the protection ("0" = not protected, "1" = protected)
105 if( (pEntry = static_cast< String* >( pNewEntryList->Next() )) != 0 )
106 aEntry.mbProtected = (pEntry->Len() > 0) && (pEntry->GetChar( 0 ) != '0');
108 maEntries.push_back( aEntry );
109 InsertEntry( aEntry.maName, LISTBOX_APPEND );
110 pEntry = static_cast< String* >( pNewEntryList->Next() );
112 SetUpdateMode( TRUE );
113 SetNoSelection();
114 mrParent.SetComment( EMPTY_STRING );
119 void ScScenarioListBox::Select()
121 if( const ScenarioEntry* pEntry = GetSelectedEntry() )
122 mrParent.SetComment( pEntry->maComment );
125 void ScScenarioListBox::DoubleClick()
127 SelectScenario();
130 long ScScenarioListBox::Notify( NotifyEvent& rNEvt )
132 bool bHandled = false;
134 if( rNEvt.GetType() == EVENT_KEYINPUT )
136 KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode();
137 switch( aCode.GetCode() )
139 case KEY_RETURN:
140 SelectScenario();
141 bHandled = true;
142 break;
143 case KEY_DELETE:
144 DeleteScenario( true );
145 bHandled = true;
146 break;
149 else if ( rNEvt.GetType() == EVENT_COMMAND && GetSelectEntryCount() )
151 const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
152 if ( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
154 if( const ScenarioEntry* pEntry = GetSelectedEntry() )
156 if( !pEntry->mbProtected )
158 ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) );
159 aPopup.Execute( this, pCEvt->GetMousePosPixel() );
160 if (aPopup.WasHit())
162 switch( aPopup.GetSelected() )
164 case RID_NAVIPI_SCENARIO_DELETE:
165 DeleteScenario( true );
166 break;
167 case RID_NAVIPI_SCENARIO_EDIT:
168 EditScenario();
169 break;
174 bHandled = true;
178 return bHandled ? 1 : ListBox::Notify( rNEvt );
181 const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const
183 size_t nPos = GetSelectEntryPos();
184 return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0;
187 void ScScenarioListBox::ExecuteScenarioSlot( USHORT nSlotId )
189 if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
191 SfxStringItem aStringItem( nSlotId, GetSelectEntry() );
192 pViewFrm->GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aStringItem, 0L, 0L );
196 void ScScenarioListBox::SelectScenario()
198 if( GetSelectEntryCount() > 0 )
199 ExecuteScenarioSlot( SID_SELECT_SCENARIO );
202 void ScScenarioListBox::EditScenario()
204 if( GetSelectEntryCount() > 0 )
205 ExecuteScenarioSlot( SID_EDIT_SCENARIO );
208 void ScScenarioListBox::DeleteScenario( bool bQueryBox )
210 if( GetSelectEntryCount() > 0 )
211 if( !bQueryBox || (::QueryBox( 0, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) ).Execute() == RET_YES) )
212 ExecuteScenarioSlot( SID_DELETE_SCENARIO );
215 //========================================================================
216 // class ScScenarioWindow ------------------------------------------------
217 //========================================================================
219 ScScenarioWindow::ScScenarioWindow( Window* pParent,const String& aQH_List,
220 const String& aQH_Comment)
221 : Window ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ),
222 aLbScenario ( *this ),
223 aEdComment ( this, WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP )
225 Font aFont( GetFont() );
226 aFont.SetTransparent( TRUE );
227 aFont.SetWeight( WEIGHT_LIGHT );
228 aEdComment.SetFont( aFont );
229 aEdComment.SetMaxTextLen( 512 );
230 aLbScenario.SetPosPixel( Point(0,0) );
231 aLbScenario.SetHelpId(HID_SC_SCENWIN_TOP);
232 aEdComment.SetHelpId(HID_SC_SCENWIN_BOTTOM);
233 aLbScenario.Show();
234 aEdComment.Show();
236 aLbScenario.SetQuickHelpText(aQH_List);
237 aEdComment.SetQuickHelpText(aQH_Comment);
238 aEdComment.SetBackground( Color( COL_LIGHTGRAY ) );
240 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
241 if (pViewFrm)
243 SfxBindings& rBindings = pViewFrm->GetBindings();
244 rBindings.Invalidate( SID_SELECT_SCENARIO );
245 rBindings.Update( SID_SELECT_SCENARIO );
249 // -----------------------------------------------------------------------
251 ScScenarioWindow::~ScScenarioWindow()
255 void ScScenarioWindow::Paint( const Rectangle& rRec )
257 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
258 Color aBgColor = rStyleSettings.GetFaceColor();
260 SetBackground( aBgColor );
262 Window::Paint( rRec );
265 // -----------------------------------------------------------------------
267 void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
269 if( pState )
271 aLbScenario.Enable();
273 if ( pState->ISA(SfxStringItem) )
275 String aNewEntry( ((const SfxStringItem*)pState)->GetValue() );
277 if ( aNewEntry.Len() > 0 )
278 aLbScenario.SelectEntry( aNewEntry );
279 else
280 aLbScenario.SetNoSelection();
282 else if ( pState->ISA(SfxStringListItem) )
284 aLbScenario.UpdateEntries( ((SfxStringListItem*)pState)->GetList() );
287 else
289 aLbScenario.Disable();
290 aLbScenario.SetNoSelection();
294 // -----------------------------------------------------------------------
296 void ScScenarioWindow::SetSizePixel( const Size& rNewSize )
298 Size aSize( rNewSize );
299 long nHeight = aSize.Height() / 2;
301 Window::SetSizePixel( aSize );
303 aSize.Height() = nHeight;
304 aLbScenario.SetSizePixel( aSize );
306 aSize.Height() -= 4;
307 aEdComment.SetPosSizePixel( Point( 0, nHeight+4 ), aSize );