On Sat, Apr 13, 2013 at 03:09:57PM -0500, Henry Tiquet Leyva wrote: > Hello Ariel, > > I added this at the code above: > > css::uno::Reference < css::drawing::XDrawPagesSupplier > > rDrawDoc(xcomponent, css::uno::UNO_QUERY_THROW); > > // query the XDrawPages Interface > css::uno::Reference < css::drawing::XDrawPages > rDrawPages = > rDrawDoc->getDrawPages(); > > // query the XIndexAccess Interface > css::uno::Reference< css::container::XIndexAccess > > rPageIndexAccess(rDrawPages, css::uno::UNO_QUERY_THROW); > > css::uno::Any DrawPage = rPageIndexAccess->getByIndex(0); > > But now I get this error: > error: 'xComponent' was not declared in this scope > > I would like to know how to declare it.
Did you add it to the code in http://ooo.pastebin.ca/2357487? Usually, in a client application, you access a document by loading it: http://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XComponentLoader.html#loadComponentFromURL loadComponentFromURL() returns a ::com::sun::star::lang::XComponent. In that pastebin code, this is: Reference < XComponent > xcomponent = rComponentLoader->loadComponentFromURL( OUString::createFromAscii("private:factory/sdraw"), OUString(RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 0, Sequence< ::com::sun::star::beans::PropertyValue>()); In the code in my attachment, as I wasn't going to use this css::lang::XComponent interface, I queried for the css::drawing::XDrawPagesSupplier directly, no need for an intermediate, unused, variable. See code attached in this mail for a more complete sample (you may want to translate the Java example in the SDK to C++ in order to get used to Draw/Impress API). Regards -- Ariel Constenla-Haile La Plata, Argentina
#************************************************************** # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # #************************************************************** # On *nix can be overridden with # make PRJ=$OO_SDK_HOME PRJ=../../../.. SETTINGS=$(PRJ)/settings include $(SETTINGS)/settings.mk include $(SETTINGS)/std.mk include $(SETTINGS)/dk.mk # Define non-platform/compiler specific settings APP_NAME=HelloDraw MAINTARGET=$(APP_NAME)_Example #this should be in odk/settings/std.mk OUT_DEPLOY=$(OUT)/deploy OUT_APP_INC=$(OUT_INC)/$(APP_NAME) OUT_APP_GEN=$(OUT_MISC)/$(APP_NAME) OUT_APP_OBJ=$(OUT_OBJ)/$(APP_NAME) OUT_APP_LIB=$(SHAREDLIB_OUT)/$(APP_NAME) OUT_APP_BIN=$(OUT_BIN)/$(APP_NAME) OUT_APP_DEPLOY=$(OUT_DEPLOY)/$(APP_NAME) CXXFILES = main.cxx OBJFILES = $(patsubst %.cxx,$(OUT_APP_OBJ)/%.$(OBJ_EXT),$(CXXFILES)) ifneq "$(DEBUG)" "" CC_DEFINES+=-DOSL_DEBUG_LEVEL=3 endif # Targets .PHONY: ALL ALL : \ $(MAINTARGET) include $(SETTINGS)/stdtarget.mk $(OUT_APP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) -$(MKDIR) $(subst /,$(PS),$(@D)) $(CC) $(CC_FLAGS) $(STL_INCLUDES) $(CC_INCLUDES) -I$(OUT_APP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< $(OUT_APP_BIN)/_$(APP_NAME)$(EXE_EXT) : $(OBJFILES) -$(MKDIR) $(subst /,$(PS),$(@D)) -$(MKDIR) $(subst /,$(PS),$(OUT_APP_GEN)) ifeq "$(OS)" "WIN" $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_APP_GEN)/$(basename $(@F)).map \ $(OBJFILES) $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) else $(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $(OBJFILES) \ $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) $(STDC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALHELPERDYLIB) $(SALDYLIB) ifeq "$(OS)" "MACOSX" $(INSTALL_NAME_URELIBS_BIN) $@ endif endif $(OUT_APP_BIN)/$(APP_NAME)$(EXE_EXT) : $(OUT_APP_BIN)/_$(APP_NAME)$(EXE_EXT) -$(MKDIR) $(subst /,$(PS),$(@D)) $(COPY) $(subst /,$(PS),$(BIN_DIR)/unoapploader$(EXE_EXT)) $(subst /,$(PS),$@) # workaround for touch problem under Windows with full qualified paths make -t $@ $(MAINTARGET) : $(OUT_APP_BIN)/$(APP_NAME)$(EXE_EXT) @echo -------------------------------------------------------------------------------- @echo Please use the following command to execute the example! @echo - @echo $(MAKE) $(APP_NAME).run @echo -------------------------------------------------------------------------------- $(APP_NAME).run: $(OUT_APP_BIN)/$(APP_NAME)$(EXE_EXT) cd $(subst /,$(PS),$(OUT_APP_BIN)) && $(basename $@) .PHONY: clean clean : -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_INC)) -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_GEN)) -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_OBJ)) -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_LIB)) -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_BIN)) -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_DEPLOY))
/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ #include <cppuhelper/bootstrap.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/frame/FrameSearchFlag.hpp> #include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/util/Color.hpp> #include <algorithm> #include <iostream> #define RGB( r,g,b ) ((::com::sun::star::util::Color)(((sal_uInt32)((sal_uInt8)(b))))|(((sal_uInt32)((sal_uInt8)(g)))<<8)|(((sal_uInt32)((sal_uInt8)(r)))<<16)) namespace css = ::com::sun::star; using rtl::OUString; int main( void ) { try { css::uno::Reference< css::uno::XComponentContext > xContext( cppu::bootstrap() ); css::uno::Reference< css::frame::XComponentLoader > xLoader( xContext->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), xContext ), css::uno::UNO_QUERY_THROW ); css::uno::Reference < css::drawing::XDrawPagesSupplier > xDoc( xLoader->loadComponentFromURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/sdraw" ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), css::frame::FrameSearchFlag::ALL, css::uno::Sequence < css::beans::PropertyValue >() ), css::uno::UNO_QUERY_THROW ); css::uno::Reference< css::lang::XMultiServiceFactory > xDocFactory( xDoc, css::uno::UNO_QUERY_THROW ); css::uno::Reference< css::drawing::XDrawPages > xDrawPages( xDoc->getDrawPages() ); OSL_ENSURE( xDrawPages.is(), "No XDrawPages!" ); css::uno::Reference< css::drawing::XDrawPage > xPage; if ( !xDrawPages->hasElements() ) { xPage.set( xDrawPages->insertNewByIndex( 0 ), css::uno::UNO_SET_THROW ); } else { xPage.set( xDrawPages->getByIndex( 0 ), css::uno::UNO_QUERY_THROW ); } css::uno::Reference< css::beans::XPropertySet > xPageProps( xPage, css::uno::UNO_QUERY_THROW ); css::uno::Reference< css::drawing::XShape > xShape( xDocFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.EllipseShape" ) ) ), css::uno::UNO_QUERY_THROW ); css::uno::Reference< css::beans::XPropertySet > xShapeProps( xShape, css::uno::UNO_QUERY_THROW ); sal_Int32 nTop( 0 ); sal_Int32 nLeft( 0 ); xPageProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BorderTop" ) ) ) >>= nTop; xPageProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BorderLeft" ) ) ) >>= nLeft; xShapeProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" ) ), css::uno::makeAny( css::drawing::FillStyle_SOLID ) ); xShapeProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FillColor" ) ), css::uno::makeAny( RGB( 255, 0, 0 ) ) ); xShape->setPosition( css::awt::Point( std::max( 0, nLeft ), std::max( 0, nTop ) ) ); xShape->setSize( css::awt::Size( 5000, 5000 ) ); xPage->add( xShape ); } catch ( const css::uno::Exception &e ) { std::cerr << "Caught an exception: " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << '\n'; } return 0; }
pgpI71eMpF1XZ.pgp
Description: PGP signature