Hi Carsten,

Carsten Driesner escribió:
Thomas Krumbein wrote:
Hey,

I just found the Interface com.sun.star.awt.XPrinterServer which
provides a method getPrinterNames.

But: which service supports this Interface? I cannot find one?

Can somebody give me an advice?

com.sun.star.awt.PrinterServer

getting the available printer names is one of the most wanted things by
extension developers.

It seemed that there was no API for getting the available printers'
names, nor the tray, etc. see issues 87883 and 87495

http://www.openoffice.org/issues/show_bug.cgi?id=87883
http://www.openoffice.org/issues/show_bug.cgi?id=87495

As I said somewhere else
(http://dba.openoffice.org/servlets/ReadMsg?listName=users&msgNo=6097)

IMHO, the one that developed the printing API was too lazy: internally all these is available cf. the Printer class in /vcl/inc/vcl/print.hxx

For 87883
static const std::vector< rtl::OUString >& GetPrinterQueues();

For 87495
USHORT  GetPaperBin() const;
BOOL    SetPaper( Paper ePaper );
et al.

How many month can take to wrap this into a new or existing interface/service?

well, it seems that the one that developed VCLXPrinterServer was...
let's say not much careful:

com.sun.star.awt.PrinterServer can *NOT* be used from OOo Basic, because
  com::sun::star::lang::XTypeProvider is not declared to be inherited by
that class (although it is implemented in the class). So for OOo Basic,
createUnoService("com.sun.star.awt.PrinterServer") returns indeed an
object not null, but that implements no interfaces, so it has no methods.

And to the printer names issue: there *is* an API for that, in
com.sun.star.awt.XPrinterServer, as we all thought in first time but
couldn't see it from Basic: VCLXPrinterServer::getPrinterNames()
implements what I suggested above to solve i87883, that is
Printer::GetPrinterQueues()

::com::sun::star::uno::Sequence< ::rtl::OUString >
VCLXPrinterServer::getPrinterNames(  )
throw(::com::sun::star::uno::RuntimeException)
{
     const std::vector<rtl::OUString>& rQueues =
Printer::GetPrinterQueues();
        sal_uInt32 nPrinters = rQueues.size();

        ::com::sun::star::uno::Sequence< ::rtl::OUString >        aNames( 
nPrinters );
        for ( sal_uInt32 n = 0; n < nPrinters; n++ )
                aNames.getArray()[n] = rQueues[n];

        return aNames;
}


Besides this, css.lang.XserviceInfo is not implemented.
I created a patch (attached here), and re-builded the toolkit module:
now XPrinterServer.getPrinterNames() returns the available printers in
OOo Basic.

I still wonder if what I quoted in
http://www.openoffice.org/servlets/ReadMsg?list=dev&msgNo=22097 is still
true:

According to http://api.openoffice.org/servlets/ReadMsg?listName=dev&msgNo=6496 (from 2003 but still applies)

"the interface was designed for an OOo/SO
running on a server where the printers are connected at the client.
Thus. for printing the client is a print server."

So if Cor is looking for something he can use in OOoBasic with a normal printer, c.s.s.awt.XPrinterServer won't work (at least in my notebook where I have no printer server, createUnoService("com.sun.star.awt.PrinterServer") instantiates an object only supporting com.sun.star.uno.XInterface , that is, c.s.s.awt.XPrinterServer is not available)

at *least* XPrinterServer.getPrinterNames() *does* work, I will have to
check the other methods.


Regards
Ariel

PS: Carsten, don't think I forgot the Menu API enhancement, I'm still
working on it, it happened that it took me more time to implement than I
thought (I had to debug vcl, etc.) . I'll try to finish something this
weekend and write a wiki page about the API enhacement proposal in order
to discuss here.


--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[EMAIL PROTECTED]

http://www.ArielConstenlaHaile.com.ar/ooo/



"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.


Index: inc/toolkit/awt/vclxprinter.hxx
===================================================================
RCS file: /cvs/gsl/toolkit/inc/toolkit/awt/vclxprinter.hxx,v
retrieving revision 1.5
diff -b -w -U 3 -r1.5 vclxprinter.hxx
--- inc/toolkit/awt/vclxprinter.hxx     11 Apr 2008 08:47:32 -0000      1.5
+++ inc/toolkit/awt/vclxprinter.hxx     21 Aug 2008 18:36:31 -0000
@@ -37,10 +37,14 @@
 #include <com/sun/star/awt/XPrinterServer.hpp>
 #include <com/sun/star/awt/XInfoPrinter.hpp>
 #include <com/sun/star/lang/XTypeProvider.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
 #include <cppuhelper/weak.hxx>
+#include <cppuhelper/implbase2.hxx>
 #include <osl/mutex.hxx>
 
+#include <toolkit/helper/macros.hxx>
 #include <toolkit/helper/mutexandbroadcasthelper.hxx>
+#include <toolkit/helper/servicenames.hxx>
 #include <cppuhelper/propshlp.hxx>
 
 class Printer;
@@ -203,12 +207,14 @@
 //     ----------------------------------------------------
 //     class VCLXPrinterServer
 //     ----------------------------------------------------
-
-class VCLXPrinterServer :      public ::com::sun::star::awt::XPrinterServer,
-                                                       public  
::cppu::OWeakObject
+typedef ::cppu::WeakImplHelper2<
+                                   ::com::sun::star::awt::XPrinterServer,
+                                   ::com::sun::star::lang::XServiceInfo
+                               >   TVCLXPrinterServer_Base;
+class VCLXPrinterServer :      public TVCLXPrinterServer_Base
 {
 public:
-    
+/*
        // ::com::sun::star::uno::XInterface
     ::com::sun::star::uno::Any                                 SAL_CALL 
queryInterface( const ::com::sun::star::uno::Type & rType ) 
throw(::com::sun::star::uno::RuntimeException);
        void                                                                    
        SAL_CALL acquire() throw()      { OWeakObject::acquire(); }
@@ -217,11 +223,14 @@
     // ::com::sun::star::lang::XTypeProvider
        ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >  
SAL_CALL getTypes() throw(::com::sun::star::uno::RuntimeException);
        ::com::sun::star::uno::Sequence< sal_Int8 >                             
                SAL_CALL getImplementationId() 
throw(::com::sun::star::uno::RuntimeException);
-
+*/
        // ::com::sun::star::awt::XPrinterServer
     ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 
getPrinterNames(  ) throw(::com::sun::star::uno::RuntimeException);
     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > 
SAL_CALL createPrinter( const ::rtl::OUString& printerName ) 
throw(::com::sun::star::uno::RuntimeException);
     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > 
SAL_CALL createInfoPrinter( const ::rtl::OUString& printerName ) 
throw(::com::sun::star::uno::RuntimeException);
+
+    DECLIMPL_SERVICEINFO( VCLXPrinterServer, szServiceName2_PrinterServer )
+
 };
 
 
Index: source/awt/vclxprinter.cxx
===================================================================
RCS file: /cvs/gsl/toolkit/source/awt/vclxprinter.cxx,v
retrieving revision 1.10
diff -b -w -U 3 -r1.10 vclxprinter.cxx
--- source/awt/vclxprinter.cxx  11 Apr 2008 09:19:01 -0000      1.10
+++ source/awt/vclxprinter.cxx  21 Aug 2008 18:36:34 -0000
@@ -414,6 +414,7 @@
 //     class VCLXPrinterServer
 //     ----------------------------------------------------
 
+/*
 // ::com::sun::star::uno::XInterface
 ::com::sun::star::uno::Any VCLXPrinterServer::queryInterface( const 
::com::sun::star::uno::Type & rType ) 
throw(::com::sun::star::uno::RuntimeException)
 {
@@ -426,6 +427,7 @@
 IMPL_XTYPEPROVIDER_START( VCLXPrinterServer )
        getCppuType( ( ::com::sun::star::uno::Reference< 
::com::sun::star::awt::XPrinterServer>* ) NULL )
 IMPL_XTYPEPROVIDER_END
+*/
 
 // ::com::sun::star::awt::XPrinterServer
 ::com::sun::star::uno::Sequence< ::rtl::OUString > 
VCLXPrinterServer::getPrinterNames(  ) 
throw(::com::sun::star::uno::RuntimeException)


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

Reply via email to