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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_basctl.hxx" 24 25 #include <ide_pch.hxx> 26 27 #include <basic/sbx.hxx> 28 #ifndef _SV_CMDEVT_HXX 29 #include <vcl/cmdevt.hxx> 30 #endif 31 #include <vcl/taskpanelist.hxx> 32 #include <objdlg.hrc> 33 #include <objdlg.hxx> 34 #include <bastypes.hxx> 35 #include <basidesh.hrc> 36 #include <basidesh.hxx> 37 #include <iderdll.hxx> 38 #include <iderdll2.hxx> 39 #include <sbxitem.hxx> 40 41 //#ifndef _SFX_HELP_HXX //autogen 42 //#include <sfx2/sfxhelp.hxx> 43 //#endif 44 45 ObjectTreeListBox::ObjectTreeListBox( Window* pParent, const ResId& rRes ) 46 : BasicTreeListBox( pParent, rRes ) 47 { 48 } 49 50 ObjectTreeListBox::~ObjectTreeListBox() 51 { 52 } 53 54 void ObjectTreeListBox::Command( const CommandEvent& ) 55 { 56 } 57 58 void ObjectTreeListBox::MouseButtonDown( const MouseEvent& rMEvt ) 59 { 60 BasicTreeListBox::MouseButtonDown( rMEvt ); 61 62 if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) ) 63 { 64 OpenCurrent(); 65 } 66 } 67 68 void ObjectTreeListBox::KeyInput( const KeyEvent& rEvt ) 69 { 70 if ( rEvt.GetKeyCode() == KEY_RETURN && OpenCurrent() ) 71 { 72 return; 73 } 74 BasicTreeListBox::KeyInput( rEvt ); 75 } 76 77 bool ObjectTreeListBox::OpenCurrent() 78 { 79 BasicEntryDescriptor aDesc( GetEntryDescriptor( GetCurEntry() ) ); 80 81 if ( aDesc.GetType() == OBJ_TYPE_METHOD ) 82 { 83 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 84 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 85 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 86 if( pDispatcher ) 87 { 88 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(), 89 aDesc.GetMethodName(), ConvertType( aDesc.GetType() ) ); 90 pDispatcher->Execute( SID_BASICIDE_SHOWSBX, 91 SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L ); 92 return true; 93 } 94 } 95 return false; 96 } 97 98 ObjectCatalog::ObjectCatalog( Window * pParent ) 99 :FloatingWindow( pParent, IDEResId( RID_BASICIDE_OBJCAT ) ) 100 ,aMacroTreeList( this, IDEResId( RID_TLB_MACROS ) ) 101 ,aToolBox(this, IDEResId(RID_TB_TOOLBOX), IDEResId(RID_IMGLST_TB_HC)) 102 ,aMacroDescr( this, IDEResId( RID_FT_MACRODESCR ) ) 103 { 104 FreeResource(); 105 106 aToolBox.SetOutStyle( TOOLBOX_STYLE_FLAT ); 107 aToolBox.SetSizePixel( aToolBox.CalcWindowSizePixel() ); 108 aToolBox.SetSelectHdl( LINK( this, ObjectCatalog, ToolBoxHdl ) ); 109 110 aMacroTreeList.SetStyle( WB_BORDER | WB_TABSTOP | 111 WB_HASLINES | WB_HASLINESATROOT | 112 WB_HASBUTTONS | WB_HASBUTTONSATROOT | 113 WB_HSCROLL ); 114 115 aMacroTreeList.SetSelectHdl( LINK( this, ObjectCatalog, TreeListHighlightHdl ) ); 116 aMacroTreeList.SetAccessibleName(String(IDEResId(RID_STR_TLB_MACROS))); 117 aMacroTreeList.ScanAllEntries(); 118 aMacroTreeList.GrabFocus(); 119 120 CheckButtons(); 121 122 Point aPos = IDE_DLL()->GetExtraData()->GetObjectCatalogPos(); 123 Size aSize = IDE_DLL()->GetExtraData()->GetObjectCatalogSize(); 124 if ( aPos.X() == INVPOSITION ) 125 { 126 // Zentriert nach AppWin: 127 Window* pWin = GetParent(); 128 aPos = pWin->OutputToScreenPixel( Point( 0, 0 ) ); 129 Size aAppWinSz = pWin->GetSizePixel(); 130 Size aDlgWinSz = GetSizePixel(); 131 aPos.X() += aAppWinSz.Width() / 2; 132 aPos.X() -= aDlgWinSz.Width() / 2; 133 aPos.Y() += aAppWinSz.Height() / 2; 134 aPos.Y() -= aDlgWinSz.Height() / 2; 135 } 136 SetPosPixel( aPos ); 137 if ( aSize.Width() ) 138 SetOutputSizePixel( aSize ); 139 140 Resize(); // damit der Resize-Handler die Controls anordnet 141 142 // make object catalog keyboard accessible 143 pParent->GetSystemWindow()->GetTaskPaneList()->AddWindow( this ); 144 } 145 146 ObjectCatalog::~ObjectCatalog() 147 { 148 GetParent()->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( this ); 149 } 150 151 void __EXPORT ObjectCatalog::Move() 152 { 153 IDE_DLL()->GetExtraData()->SetObjectCatalogPos( GetPosPixel() ); 154 } 155 156 sal_Bool __EXPORT ObjectCatalog::Close() 157 { 158 aCancelHdl.Call( this ); 159 return sal_True; 160 } 161 162 void __EXPORT ObjectCatalog::Resize() 163 { 164 Size aOutSz = GetOutputSizePixel(); 165 IDE_DLL()->GetExtraData()->SetObjectCatalogSize( aOutSz ); 166 167 Point aTreePos = aMacroTreeList.GetPosPixel(); 168 Size aDescrSz = aMacroDescr.GetSizePixel(); 169 170 Size aTreeSz; 171 long nCtrlWidth = aOutSz.Width() - 2*aTreePos.X(); 172 aTreeSz.Width() = nCtrlWidth; 173 aTreeSz.Height() = aOutSz.Height() - aTreePos.Y() - 174 2*aTreePos.X() - aDescrSz.Height(); 175 176 if ( aTreeSz.Height() > 0 ) 177 { 178 aMacroTreeList.SetSizePixel( aTreeSz ); 179 180 Point aDescrPos( aTreePos.X(), aTreePos.Y()+aTreeSz.Height()+aTreePos.X() ); 181 182 aMacroDescr.SetPosSizePixel( aDescrPos, Size( nCtrlWidth, aDescrSz.Height() ) ); 183 184 String aDesc = aMacroDescr.GetText(); 185 aMacroDescr.SetText(String()); 186 aMacroDescr.SetText(aDesc); 187 } 188 189 // Die Buttons oben bleiben immer unverändert stehen... 190 } 191 192 IMPL_LINK( ObjectCatalog, ToolBoxHdl, ToolBox*, pToolBox ) 193 { 194 sal_uInt16 nCurItem = pToolBox->GetCurItemId(); 195 switch ( nCurItem ) 196 { 197 case TBITEM_SHOW: 198 { 199 SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 200 SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs ); 201 SFX_APP()->ExecuteSlot( aRequest ); 202 203 SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry(); 204 DBG_ASSERT( pCurEntry, "Entry?!" ); 205 BasicEntryDescriptor aDesc( aMacroTreeList.GetEntryDescriptor( pCurEntry ) ); 206 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 207 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 208 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 209 if ( aDesc.GetType() == OBJ_TYPE_MODULE || 210 aDesc.GetType() == OBJ_TYPE_DIALOG || 211 aDesc.GetType() == OBJ_TYPE_METHOD ) 212 { 213 if( pDispatcher ) 214 { 215 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(), 216 aDesc.GetMethodName(), aMacroTreeList.ConvertType( aDesc.GetType() ) ); 217 pDispatcher->Execute( SID_BASICIDE_SHOWSBX, 218 SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L ); 219 } 220 } 221 else 222 { 223 ErrorBox( this, WB_OK, String( IDEResId( RID_STR_OBJNOTFOUND ) ) ).Execute(); 224 aMacroTreeList.GetModel()->Remove( pCurEntry ); 225 CheckButtons(); 226 } 227 } 228 break; 229 } 230 231 return 0; 232 } 233 234 void ObjectCatalog::CheckButtons() 235 { 236 SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry(); 237 BasicEntryType eType = pCurEntry ? ((BasicEntry*)pCurEntry->GetUserData())->GetType() : OBJ_TYPE_UNKNOWN; 238 if ( eType == OBJ_TYPE_DIALOG || eType == OBJ_TYPE_MODULE || eType == OBJ_TYPE_METHOD ) 239 aToolBox.EnableItem( TBITEM_SHOW, sal_True ); 240 else 241 aToolBox.EnableItem( TBITEM_SHOW, sal_False ); 242 } 243 244 IMPL_LINK_INLINE_START( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox ) 245 { 246 if ( pBox->IsSelected( pBox->GetHdlEntry() ) ) 247 UpdateFields(); 248 return 0; 249 } 250 IMPL_LINK_INLINE_END( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox ) 251 252 void ObjectCatalog::UpdateFields() 253 { 254 SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry(); 255 if ( pCurEntry ) 256 { 257 CheckButtons(); 258 aMacroDescr.SetText( String() ); 259 SbxVariable* pVar = aMacroTreeList.FindVariable( pCurEntry ); 260 if ( pVar ) 261 { 262 SbxInfoRef xInfo = pVar->GetInfo(); 263 if ( xInfo.Is() ) 264 aMacroDescr.SetText( xInfo->GetComment() ); 265 } 266 } 267 } 268 269 void ObjectCatalog::UpdateEntries() 270 { 271 aMacroTreeList.UpdateEntries(); 272 } 273 274 void ObjectCatalog::SetCurrentEntry( BasicEntryDescriptor& rDesc ) 275 { 276 aMacroTreeList.SetCurrentEntry( rDesc ); 277 } 278 279 ObjectCatalogToolBox_Impl::ObjectCatalogToolBox_Impl( 280 Window * pParent, ResId const & rResId, 281 ResId const & rImagesHighContrastId): 282 ToolBox(pParent, rResId), 283 m_aImagesNormal(GetImageList()), 284 m_aImagesHighContrast(rImagesHighContrastId), 285 m_bHighContrast(false) 286 { 287 setImages(); 288 } 289 290 // virtual 291 void ObjectCatalogToolBox_Impl::DataChanged(DataChangedEvent const & rDCEvt) 292 { 293 ToolBox::DataChanged(rDCEvt); 294 if ((rDCEvt.GetType() == DATACHANGED_SETTINGS 295 || rDCEvt.GetType() == DATACHANGED_DISPLAY) 296 && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0) 297 setImages(); 298 } 299 300 void ObjectCatalogToolBox_Impl::setImages() 301 { 302 bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode(); 303 if (bHC != m_bHighContrast) 304 { 305 SetImageList(bHC ? m_aImagesHighContrast : m_aImagesNormal); 306 m_bHighContrast = bHC; 307 } 308 } 309 310 /* vim: set noet sw=4 ts=4: */ 311