Tag: cws_dev300_dba30d
User: fs      
Date: 2008-05-29 11:31:01+0000
Modified:
   dba/dbaccess/source/ui/browser/unodatbr.cxx

Log:
 during #i80943#: refactoring: requestContextMenu superseded by 
IContextMenuProvider

File Changes:

Directory: /dba/dbaccess/source/ui/browser/
===========================================

File [changed]: unodatbr.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/browser/unodatbr.cxx?r1=1.200.8.1&r2=1.200.8.2
Delta lines:  +83 -152
----------------------
--- unodatbr.cxx        2008-05-28 19:19:15+0000        1.200.8.1
+++ unodatbr.cxx        2008-05-29 11:30:59+0000        1.200.8.2
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: unodatbr.cxx,v $
- * $Revision: 1.200.8.1 $
+ * $Revision: 1.200.8.2 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -381,7 +381,8 @@
 
                m_pTreeView->setCopyHandler(LINK(this, SbaTableQueryBrowser, 
OnCopyEntry));
 
-               m_pTreeView->getListBox()->setControlActionListener(this);
+        m_pTreeView->getListBox()->setContextMenuProvider( this );
+               m_pTreeView->getListBox()->setControlActionListener( this );
                m_pTreeView->SetHelpId(HID_CTL_TREEVIEW);
 
                // a default pos for the splitter, so that the listbox is about 
80 (logical) pixels wide
@@ -1516,24 +1517,62 @@
        if (!getBrowserView() || !getBrowserView()->getVclControl())
                return aReturn;
 
-       switch (nId)
+       switch ( nId )
        {
                case ID_BROWSER_CLOSE:
                        // the close button should always be enabled
                        aReturn.bEnabled = !m_bEnableBrowser;
                        return aReturn;
+
        // "toggle explorer" is always enabled (if we have a explorer)
                case ID_BROWSER_EXPLORER:
-               {               // this slot is available even if no form is 
loaded
                        aReturn.bEnabled = m_bEnableBrowser;
                        aReturn.bChecked = haveExplorer();
                        return aReturn;
-               }
+
                case ID_BROWSER_REMOVEFILTER:
-                       aReturn = SbaXDataBrowserController::GetState(nId);
+                       return SbaXDataBrowserController::GetState( nId );
+
+        case ID_TREE_CLOSE_CONN:
+        case ID_TREE_EDIT_DATABASE:
+        case ID_BROWSER_COPY:
+        {
+            SvLBoxEntry* pCurrentEntry( 
m_pTreeView->getListBox()->GetCurEntry() );
+            EntryType eType = getEntryType( pCurrentEntry );
+            if ( eType == etUnknown )
                        return aReturn;
+
+            SvLBoxEntry* pDataSourceEntry = 
m_pTreeView->getListBox()->GetRootLevelParent( pCurrentEntry );
+            DBTreeListModel::DBTreeListUserData* pDSData
+                =   pDataSourceEntry
+                ?      static_cast< DBTreeListModel::DBTreeListUserData* >( 
pDataSourceEntry->GetUserData() )
+                :      NULL;
+
+            if ( nId == ID_TREE_CLOSE_CONN )
+            {
+                aReturn.bEnabled = ( pDSData != NULL ) && 
pDSData->xConnection.is();
+            }
+            else if ( nId == ID_TREE_EDIT_DATABASE )
+            {
+                ::utl::OConfigurationTreeRoot aConfig( 
::utl::OConfigurationTreeRoot::createWithServiceFactory( getORB(),
+                    ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"/org.openoffice.Office.DataAccess/ApplicationIntegration/InstalledFeatures/Common"
 ) ) ) );
+                sal_Bool bHaveEditDatabase( sal_True );
+                OSL_VERIFY( aConfig.getNodeValue( 
"EditDatabaseFromDataSourceView" ) >>= bHaveEditDatabase );
+                aReturn.bEnabled = getORB().is() && ( pDataSourceEntry != NULL 
) && bHaveEditDatabase;
+            }
+            else if ( nId == ID_BROWSER_COPY )
+            {
+                if ( !m_pTreeView->HasChildPathFocus() )
+                    // handled below
+                    break;
+                aReturn.bEnabled = isEntryCopyAllowed( pCurrentEntry );
+            }
+
+            return aReturn;
+        }
        }
 
+    // all slots not handled above are not available if no form is loaded
        if (!isLoaded())
                return aReturn;
 
@@ -1600,9 +1639,9 @@
                 {
                     DBG_UNHANDLED_EXCEPTION();
                 }
-
                        }
                        break;
+
                        case ID_BROWSER_TITLE:
                                {
                                        Reference<XPropertySet> 
xProp(getRowSet(),UNO_QUERY);
@@ -1637,17 +1676,14 @@
                                break;
 
                        case ID_BROWSER_COPY:
-                               if(m_pTreeView->HasChildPathFocus())
-                                       aReturn.bEnabled = 
isEntryCopyAllowed(m_pTreeView->getListBox()->GetCurEntry());
-                               else if (getBrowserView() && 
getBrowserView()->getVclControl() && 
!getBrowserView()->getVclControl()->IsEditing())
+                OSL_ENSURE( !m_pTreeView->HasChildPathFocus(), 
"SbaTableQueryBrowser::GetState( ID_BROWSER_COPY ): this should have been 
handled above!" );
+                               if (getBrowserView() && 
getBrowserView()->getVclControl() && 
!getBrowserView()->getVclControl()->IsEditing())
                                {
                                        SbaGridControl* pControl = 
getBrowserView()->getVclControl();
                                        aReturn.bEnabled = 
pControl->canCopyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
-                               }
-                               else
-                                       return 
SbaXDataBrowserController::GetState(nId);
                                break;
-
+                               }
+                // NO break here
                        default:
                                return SbaXDataBrowserController::GetState(nId);
                }
@@ -1666,6 +1702,19 @@
 {
        switch (nId)
        {
+               case ID_TREE_EDIT_DATABASE:
+            implAdministrate( m_pTreeView->getListBox()->GetCurEntry() );
+                       break;
+
+        case ID_TREE_CLOSE_CONN:
+            openHelpAgent( HID_DSBROWSER_DISCONNECTING );
+            closeConnection( m_pTreeView->getListBox()->GetRootLevelParent( 
m_pTreeView->getListBox()->GetCurEntry() ) );
+            break;
+
+        case ID_TREE_ADMINISTRATE:
+            ::svx::administrateDatabaseRegistration( getView() );
+            break;
+
                case ID_BROWSER_REFRESH:
                {
                        if ( !SaveModified( ) )
@@ -3230,6 +3279,10 @@
 // 
-----------------------------------------------------------------------------
 void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo )
 {
+    OSL_PRECOND( _pApplyTo, "SbaTableQueryBrowser::implAdministrate: illegal 
entry!" );
+    if ( !_pApplyTo )
+        return;
+
        try
        {
                // get the desktop object
@@ -3293,144 +3346,22 @@
 }
 
 // 
-----------------------------------------------------------------------------
-sal_Bool SbaTableQueryBrowser::requestContextMenu( const CommandEvent& _rEvent 
)
+PopupMenu* SbaTableQueryBrowser::getContextMenu( Control& _rControl )
 {
-    ::Point aPosition;
-       SvLBoxEntry* pEntry = NULL;
-       SvLBoxEntry* pOldSelection = NULL;
-       if (_rEvent.IsMouseEvent())
-       {
-               aPosition = _rEvent.GetMousePosPixel();
-               // ensure that the entry which the user clicked at is selected
-               pEntry = m_pTreeView->getListBox()->GetEntry(aPosition);
-               if (pEntry && !m_pTreeView->getListBox()->IsSelected(pEntry))
-               {
-                       pOldSelection = 
m_pTreeView->getListBox()->FirstSelected();
-                       m_pTreeView->getListBox()->lockAutoSelect();
-                       m_pTreeView->getListBox()->Select(pEntry);
-                       m_pTreeView->getListBox()->unlockAutoSelect();
-               }
-       }
-       else
-       {
-               // use the center of the current entry
-               pEntry = m_pTreeView->getListBox()->GetCurEntry();
-               OSL_ENSURE(pEntry,"No current entry!");
-               aPosition = m_pTreeView->getListBox()->GetEntryPosition(pEntry);
-               aPosition.X() += 
m_pTreeView->getListBox()->GetOutputSizePixel().Width() / 2;
-               aPosition.Y() += m_pTreeView->getListBox()->GetEntryHeight() / 
2;
-       }
-
-       // disable entries according to the currently selected entry
-
-       // does the datasource which the selected entry belongs to has an open 
connection ?
-       SvLBoxEntry* pDSEntry = NULL;
-       DBTreeListModel::DBTreeListUserData* pDSData = NULL;
-       DBTreeListModel::DBTreeListUserData* pEntryData = NULL;
-       if(pEntry)
-       {
-               pDSEntry = 
m_pTreeView->getListBox()->GetRootLevelParent(pEntry);
-               pDSData =       pDSEntry
-                               ?       
static_cast<DBTreeListModel::DBTreeListUserData*>(pDSEntry->GetUserData())
-                               :       NULL;
-               pEntryData = 
static_cast<DBTreeListModel::DBTreeListUserData*>(pEntry->GetUserData());
-       }
-
-
-       EntryType eType = pEntryData ? pEntryData->eType : etUnknown;
-
-       ModuleRes nMenuRes( MENU_BROWSER_DEFAULTCONTEXT );
-       PopupMenu aContextMenu( nMenuRes );
-       PopupMenu* pDynamicSubMenu = NULL;
-
-       // enable menu entries
-       if (!pDSData || !pDSData->xConnection.is())
-       {
-               aContextMenu.EnableItem(ID_TREE_CLOSE_CONN, sal_False);
-       }
-       aContextMenu.EnableItem(SID_COPY,       sal_False);
+    OSL_PRECOND( m_pTreeView->getListBox() == &_rControl,
+        "SbaTableQueryBrowser::getContextMenu: where does this come from?" );
+    if ( m_pTreeView->getListBox() != &_rControl )
+        return NULL;
 
-    ::utl::OConfigurationTreeRoot aConfig( 
::utl::OConfigurationTreeRoot::createWithServiceFactory( getORB(),
-        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"/org.openoffice.Office.DataAccess/ApplicationIntegration/InstalledFeatures/Common"
 ) ) ) );
-    sal_Bool bHaveEditDatabase( sal_True );
-    OSL_VERIFY( aConfig.getNodeValue( ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM( "EditDatabaseFromDataSourceView" ) ) ) >>= 
bHaveEditDatabase );
-       aContextMenu.EnableItem( ID_TREE_EDIT_DATABASE, bHaveEditDatabase );
-
-       if ( pEntry )
-       {
-
-               switch (eType)
-               {
-                       // 1. for tables/views
-                       case etTableContainer:
-                       case etTableOrView:
-                       {
-                               aContextMenu.EnableItem( SID_COPY, 
etTableOrView == eType );
-                       }
-                       break;
-
-                       // 3. for queries
-                       case etQueryContainer:
-                       case etQuery:
-                       {
-                               // 3.2 actions on existing queries
-                               aContextMenu.EnableItem( SID_COPY, etQuery == 
eType );
-                       }
-                       break;
-            case etDatasource:
-            case etUnknown:
-                break;
-               }
-       }
-
-       if (!getORB().is())
-               // no ORB -> no administration dialog
-               aContextMenu.EnableItem(ID_TREE_EDIT_DATABASE, sal_False);
-
-       // no disabled entries
-       aContextMenu.RemoveDisabledEntries();
-
-       USHORT nPos = aContextMenu.Execute(m_pTreeView->getListBox(), 
aPosition);
-
-       delete pDynamicSubMenu;
-       pDynamicSubMenu = NULL;
-
-       // restore the old selection
-       if (pOldSelection)
-       {
-               m_pTreeView->getListBox()->lockAutoSelect();
-               m_pTreeView->getListBox()->Select(pOldSelection);
-               m_pTreeView->getListBox()->unlockAutoSelect();
-       }
-
-       switch (nPos)
-       {
-               case ID_TREE_EDIT_DATABASE:
-                       implAdministrate(pEntry);
-                       break;
-
-               case ID_TREE_CLOSE_CONN:
-                       openHelpAgent(HID_DSBROWSER_DISCONNECTING);
-                       closeConnection(pDSEntry);
-                       break;
-
-               case SID_COPY:
-               {
-                       TransferableHelper* pTransfer = implCopyObject( pEntry, 
(etQuery == eType) ? CommandType::QUERY : CommandType::TABLE );
-                       Reference< XTransferable> aEnsureDelete = pTransfer;
-
-                       if (pTransfer)
-                               pTransfer->CopyToClipboard(getView());
-               }
-               break;
-
-        case ID_TREE_ADMINISTRATE:
-            ::svx::administrateDatabaseRegistration( getView() );
-            break;
-       }
+    return new PopupMenu( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
+}
 
-       return sal_True;        // handled
+// 
-----------------------------------------------------------------------------
+IController& SbaTableQueryBrowser::getCommandController()
+{
+    return *this;
 }
+
 // 
-----------------------------------------------------------------------------
 sal_Bool SbaTableQueryBrowser::implGetQuerySignature( ::rtl::OUString& 
_rCommand, sal_Bool& _bEscapeProcessing )
 {




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to