CalcFunctionsList/fi

From Wiki.ooo4kids.org

Jump to: navigation, search

DRF Back alt.png OOo4Kids

Calcin funktioluettelo avustimessa, riippuvuus käyttäjätasosta


Kaikki alkuperäiseen OpenOffice.org-lähdekoodiin tällä sivulla esitetyt muutokset ovat:


Muutokset Calcin lähdekoodiin

Moduuli: sc

TAG DONE.png

sc/source/ui/scfuncs.src : pitää sisällään olemassaolevien funktioden koko luettelon. Olemassa on ExtraData-kenttä (0 näkyvälle, 1 piilotetulle). Olen käyttänyt sitä niiden funktioiden piilottamiseen, joiden en halua näkyvän luettelossa.

Mutta mekanismi, jolla erotellaan aloittajat jne., ei ole helposti toteutettavissa. Ja katsoin parhaaksi kysyä Eike Rathkelta (Calcin pääkehittäjiä), miten voisin parhaiten saavuttaa tavoitteeni. Eike selitti ystävällisesti, että minun pitäisi edetä toisin.

Luettelo on RID_SC_FUNCTION_DESCRIPTIONS1 ja sitä kutsutaan ajonaikaisesti global.cxx:ssä, tarkemmin kohdassa sc/source/core/data/global.cxx ScFunctionList::ScFunctionList() if (bSuppressed) ...

Tehty valinta on:

käytetään staatista getUserLevel()

Jos taituri -> ei tehdä mitään

Jos alkaja -> jokaiselle resurssille, vertaa Id luettelosta "Beginner" löytyvään. Jos ei luettelossa-> poista Jos keskitasoinen -> jokaiselle resurssille, vertaa Id luettelosta "Average" löytyvään. Jos ei luettelossa-> poista

Ideana on: tapauksessa !bSuppressed tarkista asetuksia varten, jotta tiedetään, onko tällä hetkellä valittu funktio näkyvä vaiko ei

TODO : määritellään funktiot, jotka meillä on kolmella eri tasolla.



Ensiksi, sisällytetään sopivat otsikkotiedostot arvon noutamiseksi Common.xcu:sta

Index: sc/source/core/data/global.cxx
===================================================================
--- sc/source/core/data/global.cxx	(uudistus 275641)
+++ sc/source/core/data/global.cxx	(työkopio)
@@ -70,6 +70,7 @@
 #include <svtools/syslocale.hxx>
 #include <unotools/transliterationwrapper.hxx>
 
+
 #include "global.hxx"
 #include "scresid.hxx"
 #include "autoform.hxx"
@@ -91,13 +92,27 @@
 #include "scmod.hxx"
 #include "appoptio.hxx"
 
+#ifdef OOo4Kids
+#include "vcl/unohelp.hxx"
+#include <com/sun/star/container/XContentEnumerationAccess.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/lang/XComponent.hpp>
+
 // -----------------------------------------------------------------------


Määritä vakiot luettavuuden parantamiseksi

 
+#define SC_USER_LEVEL_BEGINNER      1
+#define SC_USER_LEVEL_AVERAGE       2
+#define SC_USER_LEVEL_EXPERT        3
+#endif
+
 #define CLIPST_AVAILABLE	0
 #define CLIPST_CAPTURED		1
 #define CLIPST_DELETE		2
 #define CLIPST_DRAW			3
 
+
 ScDocShellRef*	ScGlobal::pDrawClipDocShellRef = NULL;
 SvxSearchItem*	ScGlobal::pSearchItem = NULL;
 ScAutoFormat*	ScGlobal::pAutoFormat = NULL;


Käytä sopivaa nimiavaruutta. Allaolevat kommentit kertovat, mitä tämä koskee.


@@ -147,6 +162,75 @@
 static USHORT nPPTZoom = 0;		// ScreenZoom used to determine nScreenPPTX/Y
 
 
+#ifdef OOo4Kids
+using namespace ::com::sun::star::uno; // Reference
+using namespace ::com::sun::star::lang; // XMultiServiceFactory
+using namespace ::com::sun::star::beans; // PropertyValue
+using namespace ::com::sun::star::container; // XNameAccess
+using ::rtl::OUString;



Alla joitakin aputekijöitä ( luettavuuteen )

+
+static const OUString sULConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) );
+static const OUString sULAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) );



Rutiini getUserLevel() (sama, jota käytetään svx-osassa

+
+static short getUserLevel()
+{
+    short dUserLevel = 1; // default is beginner 
+    try
+    {
+	// get service provider
+        Reference< XMultiServiceFactory > xSMgr( vcl::unohelper::GetMultiServiceFactory() );
+        // create configuration hierachical access name
+        if( xSMgr.is() )
+	{
+	    try
+            {
+                Reference< XMultiServiceFactory > xConfigProvider(
+                    Reference< XMultiServiceFactory >(
+                        xSMgr->createInstance( sULConfigSrvc ),
+                        UNO_QUERY )
+                    );
+                if( xConfigProvider.is() )
+                {
+                    Sequence< Any > aArgs(1);
+                    PropertyValue aVal;
+                    aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
+                    aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Misc" ) );
+                    aArgs.getArray()[0] <<= aVal;
+                    Reference< XNameAccess > xConfigAccess(
+                        Reference< XNameAccess >(
+                            xConfigProvider->createInstanceWithArguments( sULAccessSrvc, aArgs ), UNO_QUERY )
+                        );
+                    if( xConfigAccess.is() )
+                    {
+                        try
+                        {
+                            short bValue = 1;
+                            Any aAny = xConfigAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserLevel" ) ) );
+                            if( aAny >>= bValue )
+                                dUserLevel = bValue;
+                        }
+                        catch( NoSuchElementException& )
+                        {
+                        }
+                        catch( WrappedTargetException& )
+                        {
+                        }
+                    }
+                }
+            }
+            catch( Exception& )
+            {
+            }
+        }
+    }
+    catch( WrappedTargetException& )
+    {
+    }
+    return dUserLevel;
+}
+#endif
+


Sitten lisäämme ScFuncUtil-muodostimen

+
 // ... oder so?
 
 BOOL bOderSo;
@@ -1250,6 +1334,9 @@
 	ScFuncDesc*		pDesc	= NULL;
 	xub_StrLen		nStrLen = 0;
 	FuncCollection*	pFuncColl;
+#ifdef OOo4Kids
+    short   nLevel = getUserLevel();
+#endif
 	USHORT i,j;
 	USHORT nDescBlock[] =
 	{


Kuten ilmoitettiin, algoritmi on:



@@ -1277,10 +1364,71 @@
 				pDesc = new ScFuncDesc;
                 bool bSuppressed = false;
 				ScFuncRes aSubRes( aRes, pDesc, bSuppressed);
+#ifdef OOo4Kids
+                bool bIsNotForThisLevel = false;
+
+                if ( nLevel != SC_USER_LEVEL_EXPERT )
+                {
+                    if ( SC_USER_LEVEL_BEGINNER == nLevel )
+                    {
+                        switch ( aRes.GetId() )
+                        {
+                            // FIXME : define the right list for Beginner
+                            case SC_OPCODE_RANDOM:
+                            case SC_OPCODE_MAX:
+                            case SC_OPCODE_MIN:
+                            case SC_OPCODE_AVERAGE:
+                            case SC_OPCODE_PI:
+                            case SC_OPCODE_MOD:
+                            case SC_OPCODE_SUM:
+                            case SC_OPCODE_PRODUCT:
+                                break;
+                            default:
+                                bIsNotForThisLevel = true;
+                                break;
+                        }
+                    }
+                    else if (  SC_USER_LEVEL_AVERAGE == nLevel )
+                    {
+                        switch ( aRes.GetId() )
+                        {
+                            // FIXME : define the right list for Average
+                            case SC_OPCODE_RANDOM:
+                            case SC_OPCODE_MAX:
+                            case SC_OPCODE_MIN:
+                            case SC_OPCODE_AVERAGE:
+                            case SC_OPCODE_PI:
+                            case SC_OPCODE_MOD:
+                            case SC_OPCODE_SUM:
+                            case SC_OPCODE_PRODUCT:
+                            case SC_OPCODE_SIN: 
+                            case SC_OPCODE_COS: 
+                            case SC_OPCODE_DEG: 
+                            case SC_OPCODE_RAD: 
+                            case SC_OPCODE_ABS: 
+                            case SC_OPCODE_SQRT: 
+                            case SC_OPCODE_NOT: 
+                            case SC_OPCODE_AND:
+                            case SC_OPCODE_OR:
+                            case SC_OPCODE_PLUS_MINUS:
+                            case SC_OPCODE_GGT:
+                            case SC_OPCODE_KGV:
+                            case SC_OPCODE_POWER:
+                                break;
+                            default:
+                                bIsNotForThisLevel = true;
+                                break;
+                        }
+                    }
+                }
+
                 // Instead of dealing with this exceptional case at 1001 places
                 // we simply don't add an entirely suppressed function to the
                 // list and delete it.
-                if (bSuppressed)
+                if ( bSuppressed || bIsNotForThisLevel )
+#else
+                if ( bSuppressed )
+#endif
                     delete pDesc;
                 else
                 {

Tärkeää: älä unohda poistaa sc-lisäosia, odotetusti vienti-tilassa


@@ -1387,10 +1538,14 @@
 
 	//	StarOne AddIns
 
-	ScUnoAddInCollection* pUnoAddIns = ScGlobal::GetAddInCollection();
-	long nUnoCount = pUnoAddIns->GetFuncCount();
-	for (long nFunc=0; nFunc<nUnoCount; nFunc++)
+#ifdef OOo4Kids
+        if ( SC_USER_LEVEL_EXPERT == nLevel )
 	{
+#endif
+	    ScUnoAddInCollection* pUnoAddIns = ScGlobal::GetAddInCollection();
+	    long nUnoCount = pUnoAddIns->GetFuncCount();
+	    for (long nFunc=0; nFunc<nUnoCount; nFunc++)
+	    {
 		pDesc = new ScFuncDesc;
 		pDesc->nFIndex = nNextId++;
 
@@ -1403,7 +1558,10 @@
 		}
 		else
 			delete pDesc;
+	    }
+#ifdef OOo4Kids
 	}
+#endif
 }


KORJATTU, katso alempaa: ei voida muuttaa käynnistämättä OOo:a uudestaan, todennäköisesti koska luettelo on välimuistissa (vaikka asiakirja suljetaan ?)

Temppu oli palauttaa funktioluettelo alkutilaan, kun ikkuna suljetaan. Seuraavalla kerralla käytettäessä UserLevel-luetaan ja jos se on muuttunut, uusi funktioluettelo täytetään. Testattu, toimii OK


ScFunctionList* ScGlobal::GetStarCalcFunctionList()
{
#ifdef OOo4Kids
        ResetFunctionList();
#else
	if ( !pStarCalcFunctionList )
#endif
		pStarCalcFunctionList = new	ScFunctionList;

	return pStarCalcFunctionList;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox