1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <comphelper/processfactory.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <osl/file.hxx>
#include <vcl/builder.hxx>
#include <vcl/dialog.hxx>
#include <vcl/help.hxx>
#include <vcl/svapp.hxx>
#include <vcl/vclmain.hxx>
#include <vcl/field.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/virdev.hxx>
#include <sfx2/filedlghelper.hxx>
#include <swmodule.hxx>
#include <wrtsh.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::sfx2;
class TiledRenderingApp : public Application
{
private:
uno::Reference<uno::XComponentContext> xContext;
uno::Reference<lang::XMultiComponentFactory> xFactory;
uno::Reference<lang::XMultiServiceFactory> xSFactory;
uno::Reference<uno::XInterface> xDesktop;
uno::Reference<frame::XComponentLoader> xLoader;
uno::Reference<lang::XComponent> xComponent;
public:
virtual void Init();
virtual int Main();
void Open(OUString & aFileUrl);
};
class TiledRenderingDialog: public ModalDialog
{
private:
TiledRenderingApp *mpApp;
NumericField *mpContextWidth;
NumericField *mpContextHeight;
NumericField *mpTilePosX;
NumericField *mpTilePosY;
NumericField *mpTileWidth;
NumericField *mpTileHeight;
FixedImage *mpImage;
public:
TiledRenderingDialog(TiledRenderingApp * app) :
ModalDialog(DIALOG_NO_PARENT, "TiledRendering", "qa/sw/ui/tiledrendering.ui"),
mpApp(app)
{
PushButton * renderButton;
get(renderButton, "buttonRenderTile");
renderButton->SetClickHdl( LINK( this, TiledRenderingDialog, RenderHdl));
PushButton * chooseDocumentButton;
get(chooseDocumentButton, "buttonChooseDocument");
chooseDocumentButton->SetClickHdl( LINK( this, TiledRenderingDialog, ChooseDocumentHdl));
SetStyle(GetStyle()|WB_CLOSEABLE);
get(mpContextWidth, "spinContextWidth");
get(mpContextHeight, "spinContextHeight");
get(mpTilePosX, "spinTilePosX");
get(mpTilePosY, "spinTilePosY");
get(mpTileWidth, "spinTileWidth");
get(mpTileHeight, "spinTileHeight");
get(mpImage, "imageTile");
}
virtual ~TiledRenderingDialog()
{
}
DECL_LINK ( RenderHdl, Button * );
DECL_LINK ( ChooseDocumentHdl, Button * );
int extractInt(const NumericField *pField)
{
OUString aString(pField->GetText());
return aString.toInt32();
}
};
IMPL_LINK ( TiledRenderingDialog, RenderHdl, Button *, EMPTYARG )
{
int contextWidth = extractInt(mpContextWidth);
int contextHeight = extractInt(mpContextHeight);
int tilePosX = extractInt(mpTilePosX);
int tilePosY = extractInt(mpTilePosY);
int tileWidth = extractInt(mpTileWidth);
int tileHeight = extractInt(mpTileHeight);
// do the same thing we are doing in touch_lo_draw_tile()
SwWrtShell *pViewShell = GetActiveWrtShell();
if (pViewShell)
{
// TODO create a VirtualDevice based on SystemGraphicsData instead so
// that we get direct rendering; something like:
//
// SystemGraphicsData aData;
// [setup the aData]
// VirtualDevice aDevice(&aData, [color depth]);
/*
// FIXME don't use pViewShell()->GetOut() directly, we need an own
// device here, something like
#ifdef IOS
VirtualDevice aDevice(8);
#else
VirtualDevice aDevice(1);
#endif
aDevice.SetReferenceDevice(VirtualDevice::REFDEV_MODE_MSO1);
MapMode aMapMode(aDevice.GetMapMode());
aMapMode.SetMapUnit(MAP_TWIP);
aDevice.SetMapMode(aMapMode);
aDevice.SetOutputSizePixel(Size(contextWidth, contextHeight));
*/
pViewShell->PaintTile(pViewShell->GetOut(), Rectangle(tilePosX, tilePosY, tileWidth, tileHeight));
// FIXME pViewShell->PaintTile(&aDevice, Rectangle(tilePosX, tilePosY, tileWidth, tileHeight));
// copy the aDevice content to mpImage
// FIXME BitmapEx aBitmap(pViewShell->GetOut()->GetBitmapEx(Point(0,0), aDevice.PixelToLogic(Size(contextWidth, contextHeight))));
BitmapEx aBitmap(pViewShell->GetOut()->GetBitmapEx(Point(0,0), pViewShell->GetOut()->PixelToLogic(Size(contextWidth, contextHeight))));
mpImage->SetImage(Image(aBitmap));
// update the dialog size
setOptimalLayoutSize();
}
return 1;
}
IMPL_LINK ( TiledRenderingDialog, ChooseDocumentHdl, Button *, EMPTYARG )
{
FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
if( aDlgHelper.Execute() == ERRCODE_NONE )
{
OUString aFileUrl =xFP->getFiles().getConstArray()[0];
mpApp->Open(aFileUrl);
}
return 1;
}
void TiledRenderingApp::Open(OUString & aFileUrl)
{
static const OUString TARGET("_default");
static const Sequence<beans::PropertyValue> PROPS (0);
if(xComponent.get())
{
xComponent->dispose();
xComponent.clear();
}
xComponent.set(xLoader->loadComponentFromURL(aFileUrl, TARGET, 0, PROPS));
}
void TiledRenderingApp::Init()
{
xContext.set(cppu::defaultBootstrap_InitialComponentContext());
xFactory.set(xContext->getServiceManager());
xSFactory.set(uno::Reference<lang::XMultiServiceFactory> (xFactory, uno::UNO_QUERY_THROW));
comphelper::setProcessServiceFactory(xSFactory);
// Create UCB (for backwards compatibility, in case some code still uses
// plain createInstance w/o args directly to obtain an instance):
::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext() );
xDesktop.set(xFactory->createInstanceWithContext(OUString("com.sun.star.frame.Desktop"), xContext));
xLoader.set(frame::Desktop::create(xContext));
}
int TiledRenderingApp::Main()
{
if(GetCommandLineParamCount()>0)
{
OUString aFileUrl;
osl::File::getFileURLFromSystemPath(GetCommandLineParam(0), aFileUrl);
Open(aFileUrl);
}
Help::EnableQuickHelp();
try
{
TiledRenderingDialog pDialog(this);
pDialog.Execute();
}
catch (const uno::Exception &e)
{
fprintf(stderr, "fatal error: %s\n", OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
}
return EXIT_SUCCESS;
}
void vclmain::createApplication()
{
static TiledRenderingApp aApp;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|