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