[PATCH 4/7] add support for MousePointer attribute in controls

Noel Power noel.power at novell.com
Thu Apr 5 06:17:24 PDT 2012


For Useforms it doesn't quite work exactly as MSO, for examply if we set the MousePointer for the Userform it works as expected until we mouse over another control at which point the mouse pointer is changed to that of the control. In MSO it would appear that the Userform mousepointer is king, perhaps all that is necessary is to apply the mouse pointer to each contained control, needs some investigation. Also only a limited number of the possible mouse pointer styles are processed, the conversions of mso -> lo pointer styles ( and vice-versa ) and not really tested to see if they all make sense
---
 oovbaapi/ooo/vba/msforms/XControl.idl   |    1 +
 vbahelper/source/msforms/vbacontrol.cxx |   84 ++++++++++++++++++++++++++++++-
 vbahelper/source/msforms/vbacontrol.hxx |    2 +
 3 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/oovbaapi/ooo/vba/msforms/XControl.idl b/oovbaapi/ooo/vba/msforms/XControl.idl
index 5ece205..9f2c6ee 100644
--- a/oovbaapi/ooo/vba/msforms/XControl.idl
+++ b/oovbaapi/ooo/vba/msforms/XControl.idl
@@ -44,6 +44,7 @@ interface XControl
     [attribute] string RowSource;
     [attribute] boolean Enabled;
     [attribute] boolean Visible;
+    [attribute] long MousePointer;
     //Size. there are some defferent between Mso and OOo.
     //Mso use double but OOo use long. OOo 1 =  1/100mm but Mso use pt.
     //in Dialogs Mso uses pixels
diff --git a/vbahelper/source/msforms/vbacontrol.cxx b/vbahelper/source/msforms/vbacontrol.cxx
index 195e34e..03cd014 100644
--- a/vbahelper/source/msforms/vbacontrol.cxx
+++ b/vbahelper/source/msforms/vbacontrol.cxx
@@ -45,6 +45,7 @@
 #include <com/sun/star/document/XCodeNameQuery.hpp>
 #include <com/sun/star/form/XChangeListener.hpp>
 #include <ooo/vba/XControlProvider.hpp>
+#include <ooo/vba/msforms/fmMousePointer.hpp>
 #ifdef VBA_OOBUILD_HACK
 #include <svtools/bindablecontrolhelper.hxx>
 #endif
@@ -65,8 +66,8 @@
 #include "vbasystemaxcontrol.hxx"
 #include "vbaimage.hxx"
 #include <vbahelper/helperdecl.hxx>
-
-
+#include <toolkit/helper/vclunohelper.hxx>
+#include <vcl/window.hxx>
 using namespace com::sun::star;
 using namespace ooo::vba;
 
@@ -423,6 +424,85 @@ void SAL_CALL ScVbaControl::setForeColor( ::sal_Int32 _forecolor ) throw (::com:
      m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TextColor" ) ), uno::makeAny( XLRGBToOORGB( _forecolor ) ) );
 }
 
+struct PointerStyles
+{
+   long msoPointerStyle;
+   PointerStyle loPointStyle;
+};
+
+// 1 -> 1 map of styles ( some dubious choices in there though )
+PointerStyles styles[] = {
+  /// assuming pointer default is Arrow
+  { msforms::fmMousePointer::fmMousePointerDefault, POINTER_ARROW },
+  { msforms::fmMousePointer::fmMousePointerArrow, POINTER_ARROW },
+  { msforms::fmMousePointer::fmMousePointerCross, POINTER_CROSS },
+  { msforms::fmMousePointer::fmMousePointerIBeam, POINTER_TEXT },
+  { msforms::fmMousePointer::fmMousePointerSizeNESW,  POINTER_AUTOSCROLL_NSWE   }, // #TODO not correct, need to check, need to find the right one
+  { msforms::fmMousePointer::fmMousePointerSizeNS,  POINTER_AUTOSCROLL_NS  },
+  { msforms::fmMousePointer::fmMousePointerSizeNWSE,  POINTER_AUTOSCROLL_NSWE  }, // #TODO not correct, need to check, need to find the right one
+  { msforms::fmMousePointer::fmMousePointerSizeWE,  POINTER_AUTOSCROLL_WE },
+  { msforms::fmMousePointer::fmMousePointerUpArrow, POINTER_WINDOW_NSIZE  },
+  { msforms::fmMousePointer::fmMousePointerHourGlass, POINTER_WAIT  },
+  { msforms::fmMousePointer::fmMousePointerNoDrop, POINTER_NOTALLOWED },
+  { msforms::fmMousePointer::fmMousePointerAppStarting, POINTER_WAIT },
+  { msforms::fmMousePointer::fmMousePointerHelp, POINTER_HELP },
+  { msforms::fmMousePointer::fmMousePointerSizeAll, POINTER_CROSS },
+  { msforms::fmMousePointer::fmMousePointerCustom, POINTER_ARROW }, // not supported I guess
+
+};
+
+long lcl_loPointerToMsoPointer( PointerStyle eType )
+{
+    long nRet = msforms::fmMousePointer::fmMousePointerDefault;
+    for ( int i = 0, nElems = SAL_N_ELEMENTS( styles ); i < nElems; ++i )
+    {
+        if ( styles[ i ].loPointStyle == eType )
+        {
+            nRet = styles[ i ].msoPointerStyle;
+            break;
+        }
+    }
+    return nRet;
+}
+
+Pointer lcl_msoPointerToLOPointer( long msoPointerStyle )
+{
+    Pointer aPointer( POINTER_ARROW );
+    for ( int i = 0, nElems = SAL_N_ELEMENTS( styles ); i < nElems; ++i )
+    {
+        if ( styles[ i ].msoPointerStyle == msoPointerStyle )
+        {
+            aPointer = Pointer( styles[ i ].loPointStyle );
+            break;
+         }
+    }
+    return aPointer;
+}
+
+::sal_Int32 SAL_CALL
+ScVbaControl::getMousePointer() throw (::com::sun::star::uno::RuntimeException)
+{
+    PointerStyle eType = POINTER_ARROW; // default ?
+    Window* pWindow = VCLUnoHelper::GetWindow( getWindowPeer() );
+    if ( pWindow )
+    {
+        eType = pWindow->GetPointer().GetStyle();
+    }
+    return lcl_loPointerToMsoPointer( eType );
+}
+
+void SAL_CALL
+ScVbaControl::setMousePointer( ::sal_Int32 _mousepointer ) throw (::com::sun::star::uno::RuntimeException)
+{
+    Window* pWindow = VCLUnoHelper::GetWindow( getWindowPeer() );
+    if ( pWindow )
+    {
+        Pointer aPointer( POINTER_ARROW );
+        aPointer = lcl_msoPointerToLOPointer( _mousepointer );
+        pWindow->SetPointer( aPointer );
+    }
+}
+
 void ScVbaControl::fireEvent( script::ScriptEvent& evt )
 {
     uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
diff --git a/vbahelper/source/msforms/vbacontrol.hxx b/vbahelper/source/msforms/vbacontrol.hxx
index 9076a3e..597c635 100644
--- a/vbahelper/source/msforms/vbacontrol.hxx
+++ b/vbahelper/source/msforms/vbacontrol.hxx
@@ -107,6 +107,8 @@ public:
     virtual void SAL_CALL setTag( const ::rtl::OUString& aTag ) throw (css::uno::RuntimeException);
     virtual sal_Int32 SAL_CALL getTabIndex() throw (css::uno::RuntimeException);
     virtual void SAL_CALL setTabIndex( sal_Int32 nTabIndex ) throw (css::uno::RuntimeException);
+    virtual ::sal_Int32 SAL_CALL getMousePointer() throw (::com::sun::star::uno::RuntimeException);
+    virtual void SAL_CALL setMousePointer( ::sal_Int32 _mousepointer ) throw (::com::sun::star::uno::RuntimeException);
     //remove resouce because ooo.vba.excel.XControl is a wrapper of com.sun.star.drawing.XControlShape
     virtual void removeResouce() throw( css::uno::RuntimeException );
     virtual ::sal_Int32 SAL_CALL getForeColor() throw (::com::sun::star::uno::RuntimeException);
-- 
1.7.3.4


--------------070704010006060703060206
Content-Type: text/plain; charset=UTF-8;
 name="0005-add-vba-support-for-BackColor-AutoSize-Locked-attrib.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0005-add-vba-support-for-BackColor-AutoSize-Locked-attrib.pa";
 filename*1="tch"



More information about the LibreOffice mailing list