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_sc.hxx" 30 31 32 33 //------------------------------------------------------------------ 34 35 #include <sfx2/bindings.hxx> 36 #include <sfx2/dispatch.hxx> 37 #include <sfx2/viewfrm.hxx> 38 #include <svl/slstitm.hxx> 39 #include <svl/stritem.hxx> 40 #include <vcl/msgbox.hxx> 41 #include <vcl/svapp.hxx> 42 #include "navipi.hxx" 43 #include "popmenu.hxx" 44 #include "scresid.hxx" 45 #include "sc.hrc" 46 #include "globstr.hrc" 47 48 //======================================================================== 49 // class ScScenarioWindow ------------------------------------------------ 50 //======================================================================== 51 52 ScScenarioListBox::ScScenarioListBox( ScScenarioWindow& rParent ) : 53 ListBox( &rParent, WB_BORDER | WB_TABSTOP ), 54 mrParent( rParent ) 55 { 56 Font aFont( GetFont() ); 57 aFont.SetTransparent( sal_True ); 58 aFont.SetWeight( WEIGHT_LIGHT ); 59 SetFont( aFont ); 60 } 61 62 ScScenarioListBox::~ScScenarioListBox() 63 { 64 } 65 66 void ScScenarioListBox::UpdateEntries( List* pNewEntryList ) 67 { 68 Clear(); 69 maEntries.clear(); 70 71 if( !pNewEntryList ) 72 return; 73 74 switch( pNewEntryList->Count() ) 75 { 76 case 0: 77 // no scenarios in current sheet 78 mrParent.SetComment( EMPTY_STRING ); 79 break; 80 81 case 1: 82 // sheet is a scenario container, comment only 83 mrParent.SetComment( *static_cast< String* >( pNewEntryList->First() ) ); 84 break; 85 86 default: 87 { 88 // sheet contains scenarios 89 DBG_ASSERT( pNewEntryList->Count() % 3 == 0, "ScScenarioListBox::UpdateEntries - wrong list size" ); 90 SetUpdateMode( sal_False ); 91 String* pEntry = static_cast< String* >( pNewEntryList->First() ); 92 while( pEntry ) 93 { 94 ScenarioEntry aEntry; 95 96 // first entry of a triple is the scenario name 97 aEntry.maName = *pEntry; 98 // second entry of a triple is the scenario comment 99 if( (pEntry = static_cast< String* >( pNewEntryList->Next() )) != 0 ) 100 aEntry.maComment = *pEntry; 101 // third entry of a triple is the protection ("0" = not protected, "1" = protected) 102 if( (pEntry = static_cast< String* >( pNewEntryList->Next() )) != 0 ) 103 aEntry.mbProtected = (pEntry->Len() > 0) && (pEntry->GetChar( 0 ) != '0'); 104 105 maEntries.push_back( aEntry ); 106 InsertEntry( aEntry.maName, LISTBOX_APPEND ); 107 pEntry = static_cast< String* >( pNewEntryList->Next() ); 108 } 109 SetUpdateMode( sal_True ); 110 SetNoSelection(); 111 mrParent.SetComment( EMPTY_STRING ); 112 } 113 } 114 } 115 116 void ScScenarioListBox::Select() 117 { 118 if( const ScenarioEntry* pEntry = GetSelectedEntry() ) 119 mrParent.SetComment( pEntry->maComment ); 120 } 121 122 void ScScenarioListBox::DoubleClick() 123 { 124 SelectScenario(); 125 } 126 127 long ScScenarioListBox::Notify( NotifyEvent& rNEvt ) 128 { 129 bool bHandled = false; 130 131 if( rNEvt.GetType() == EVENT_KEYINPUT ) 132 { 133 KeyCode aCode = rNEvt.GetKeyEvent()->GetKeyCode(); 134 switch( aCode.GetCode() ) 135 { 136 case KEY_RETURN: 137 SelectScenario(); 138 bHandled = true; 139 break; 140 case KEY_DELETE: 141 DeleteScenario( true ); 142 bHandled = true; 143 break; 144 } 145 } 146 else if ( rNEvt.GetType() == EVENT_COMMAND && GetSelectEntryCount() ) 147 { 148 const CommandEvent* pCEvt = rNEvt.GetCommandEvent(); 149 if ( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU ) 150 { 151 if( const ScenarioEntry* pEntry = GetSelectedEntry() ) 152 { 153 if( !pEntry->mbProtected ) 154 { 155 ScPopupMenu aPopup( ScResId( RID_POPUP_NAVIPI_SCENARIO ) ); 156 aPopup.Execute( this, pCEvt->GetMousePosPixel() ); 157 if (aPopup.WasHit()) 158 { 159 switch( aPopup.GetSelected() ) 160 { 161 case RID_NAVIPI_SCENARIO_DELETE: 162 DeleteScenario( true ); 163 break; 164 case RID_NAVIPI_SCENARIO_EDIT: 165 EditScenario(); 166 break; 167 } 168 } 169 } 170 } 171 bHandled = true; 172 } 173 } 174 175 return bHandled ? 1 : ListBox::Notify( rNEvt ); 176 } 177 178 const ScScenarioListBox::ScenarioEntry* ScScenarioListBox::GetSelectedEntry() const 179 { 180 size_t nPos = GetSelectEntryPos(); 181 return (nPos < maEntries.size()) ? &maEntries[ nPos ] : 0; 182 } 183 184 void ScScenarioListBox::ExecuteScenarioSlot( sal_uInt16 nSlotId ) 185 { 186 if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() ) 187 { 188 SfxStringItem aStringItem( nSlotId, GetSelectEntry() ); 189 pViewFrm->GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aStringItem, 0L, 0L ); 190 } 191 } 192 193 void ScScenarioListBox::SelectScenario() 194 { 195 if( GetSelectEntryCount() > 0 ) 196 ExecuteScenarioSlot( SID_SELECT_SCENARIO ); 197 } 198 199 void ScScenarioListBox::EditScenario() 200 { 201 if( GetSelectEntryCount() > 0 ) 202 ExecuteScenarioSlot( SID_EDIT_SCENARIO ); 203 } 204 205 void ScScenarioListBox::DeleteScenario( bool bQueryBox ) 206 { 207 if( GetSelectEntryCount() > 0 ) 208 if( !bQueryBox || (::QueryBox( 0, WinBits( WB_YES_NO | WB_DEF_YES ), ScGlobal::GetRscString( STR_QUERY_DELSCENARIO ) ).Execute() == RET_YES) ) 209 ExecuteScenarioSlot( SID_DELETE_SCENARIO ); 210 } 211 212 //======================================================================== 213 // class ScScenarioWindow ------------------------------------------------ 214 //======================================================================== 215 216 ScScenarioWindow::ScScenarioWindow( Window* pParent,const String& aQH_List, 217 const String& aQH_Comment) 218 : Window ( pParent, WB_TABSTOP | WB_DIALOGCONTROL ), 219 aLbScenario ( *this ), 220 aEdComment ( this, WB_BORDER | WB_LEFT | WB_READONLY | WB_VSCROLL | WB_TABSTOP ) 221 { 222 Font aFont( GetFont() ); 223 aFont.SetTransparent( sal_True ); 224 aFont.SetWeight( WEIGHT_LIGHT ); 225 aEdComment.SetFont( aFont ); 226 aEdComment.SetMaxTextLen( 512 ); 227 aLbScenario.SetPosPixel( Point(0,0) ); 228 aLbScenario.SetHelpId(HID_SC_SCENWIN_TOP); 229 aEdComment.SetHelpId(HID_SC_SCENWIN_BOTTOM); 230 aLbScenario.Show(); 231 aEdComment.Show(); 232 233 aLbScenario.SetQuickHelpText(aQH_List); 234 aEdComment.SetQuickHelpText(aQH_Comment); 235 aEdComment.SetBackground( Color( COL_LIGHTGRAY ) ); 236 237 SfxViewFrame* pViewFrm = SfxViewFrame::Current(); 238 if (pViewFrm) 239 { 240 SfxBindings& rBindings = pViewFrm->GetBindings(); 241 rBindings.Invalidate( SID_SELECT_SCENARIO ); 242 rBindings.Update( SID_SELECT_SCENARIO ); 243 } 244 } 245 246 // ----------------------------------------------------------------------- 247 248 ScScenarioWindow::~ScScenarioWindow() 249 { 250 } 251 252 void ScScenarioWindow::Paint( const Rectangle& rRec ) 253 { 254 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 255 Color aBgColor = rStyleSettings.GetFaceColor(); 256 257 SetBackground( aBgColor ); 258 259 Window::Paint( rRec ); 260 } 261 262 // ----------------------------------------------------------------------- 263 264 void ScScenarioWindow::NotifyState( const SfxPoolItem* pState ) 265 { 266 if( pState ) 267 { 268 aLbScenario.Enable(); 269 270 if ( pState->ISA(SfxStringItem) ) 271 { 272 String aNewEntry( ((const SfxStringItem*)pState)->GetValue() ); 273 274 if ( aNewEntry.Len() > 0 ) 275 aLbScenario.SelectEntry( aNewEntry ); 276 else 277 aLbScenario.SetNoSelection(); 278 } 279 else if ( pState->ISA(SfxStringListItem) ) 280 { 281 aLbScenario.UpdateEntries( ((SfxStringListItem*)pState)->GetList() ); 282 } 283 } 284 else 285 { 286 aLbScenario.Disable(); 287 aLbScenario.SetNoSelection(); 288 } 289 } 290 291 // ----------------------------------------------------------------------- 292 293 void ScScenarioWindow::SetSizePixel( const Size& rNewSize ) 294 { 295 Size aSize( rNewSize ); 296 long nHeight = aSize.Height() / 2; 297 298 Window::SetSizePixel( aSize ); 299 300 aSize.Height() = nHeight; 301 aLbScenario.SetSizePixel( aSize ); 302 303 aSize.Height() -= 4; 304 aEdComment.SetPosSizePixel( Point( 0, nHeight+4 ), aSize ); 305 } 306 307 308 309 310