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
|
/* -*- 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/.
*/
/*
* =======================================================================
*
* This is a quick hack to test some stuff. Work in progress. Don't touch
* and don't bother inspecting too closely.
*
* =======================================================================
*/
#include <iostream>
#include <math.h>
#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 <comphelper/processfactory.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <osl/file.hxx>
#include <sal/log.hxx>
#include <tools/stream.hxx>
#include <vcl/builder.hxx>
#include <vcl/toolkit/button.hxx>
#include <vcl/toolkit/dialog.hxx>
#include <vcl/toolkit/fixed.hxx>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/image.hxx>
#include <vcl/svapp.hxx>
#include <vcl/vclmain.hxx>
#include <vcl/wrkwin.hxx>
using namespace com::sun::star;
namespace {
const int WIDTH = 1000, HEIGHT = 800;
double getTimeNow()
{
TimeValue aValue;
osl_getSystemTime(&aValue);
return static_cast<double>(aValue.Seconds) +
static_cast<double>(aValue.Nanosec) / (1000*1000*1000);
}
class MyWorkWindow : public WorkWindow
{
double mnStartTime;
int mnPaintCount;
public:
Graphic maGraphic;
BitmapEx *mpBitmap;
VclPtr<FixedBitmap> mpFixedBitmap;
MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle );
virtual ~MyWorkWindow() override { disposeOnce(); }
virtual void dispose() override { mpFixedBitmap.clear(); WorkWindow::dispose(); }
void LoadGraphic( const OUString& sImageFile );
virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& rRect ) override;
virtual void Resize() override;
};
}
MyWorkWindow::MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle )
: WorkWindow(pParent, nWinStyle)
, mpBitmap(nullptr)
, mpFixedBitmap(nullptr)
{
mnPaintCount = 0;
mnStartTime = getTimeNow();
EnableInput();
}
void MyWorkWindow::LoadGraphic( const OUString& sImageFile )
{
SvFileStream aFileStream( sImageFile, StreamMode::READ );
GraphicFilter aGraphicFilter;
if (aGraphicFilter.ImportGraphic(maGraphic, sImageFile, aFileStream) != ERRCODE_NONE)
{
SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile << "'");
return;
}
}
void MyWorkWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
std::cout << "==> Paint! " << mnPaintCount++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - mnStartTime << std::endl;
Size aGraphicSize( maGraphic.GetSizePixel() );
float aspect = static_cast<float>(aGraphicSize.Width()) / aGraphicSize.Height();
Size aSize;
if( aspect >= (float(WIDTH)) / HEIGHT )
aSize = Size( WIDTH, HEIGHT/aspect );
else
aSize = Size( WIDTH * aspect, HEIGHT );
aSize.setWidth( aSize.Width() * (1 + (0.1*sin(mnPaintCount/60.))) );
aSize.setHeight( aSize.Height() * (1 + (0.1*sin(mnPaintCount/50.))) );
BitmapEx aEmpty;
mpFixedBitmap->SetBitmap( aEmpty );
GraphicConversionParameters aConv( aSize );
mpBitmap = new BitmapEx(maGraphic.GetBitmapEx( aConv ));
mpFixedBitmap->SetBitmap( *mpBitmap );
mpFixedBitmap->SetSizePixel( aSize );
WorkWindow::Paint(rRenderContext, rRect);
if (mnPaintCount == 100)
Application::Quit();
Invalidate( InvalidateFlags::Children );
}
void MyWorkWindow::Resize()
{
SAL_INFO("vcl.icontest", "Resize " << GetSizePixel());
}
namespace {
class IconTestApp : public Application
{
public:
virtual void Init() override;
virtual int Main() override;
IconTestApp() : nRet(EXIT_SUCCESS) {};
private:
int nRet;
void DoItWithVcl(const OUString& sImageFile);
};
}
void IconTestApp::Init()
{
nRet = EXIT_SUCCESS;
uno::Reference<uno::XComponentContext> xContext =
cppu::defaultBootstrap_InitialComponentContext();
uno::Reference<lang::XMultiComponentFactory> xFactory =
xContext->getServiceManager();
uno::Reference<lang::XMultiServiceFactory> xSFactory(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() );
}
int IconTestApp::Main()
{
if (GetCommandLineParamCount() != 1)
{
fprintf(stderr, "Usage: imagetest <image>\n");
return EXIT_FAILURE;
}
OUString sImageFile( GetCommandLineParam( 0 ) );
DoItWithVcl( sImageFile );
return nRet;
}
void IconTestApp::DoItWithVcl( const OUString& sImageFile)
{
try
{
VclPtrInstance<MyWorkWindow> pWindow( nullptr, WB_APP | WB_STDWORK | WB_SIZEABLE | WB_CLOSEABLE | WB_CLIPCHILDREN );
pWindow->SetText(u"VCL Image Test"_ustr);
pWindow->LoadGraphic( sImageFile );
pWindow->mpFixedBitmap = VclPtr<FixedBitmap>::Create( pWindow );
pWindow->mpFixedBitmap->SetPosPixel( Point( 0, 0 ) );
pWindow->mpFixedBitmap->Show();
pWindow->Hide();
pWindow->Show();
Execute();
}
catch (const uno::Exception &e)
{
fprintf(stderr, "fatal error: %s\n", OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
nRet = EXIT_FAILURE;
}
catch (const std::exception &e)
{
fprintf(stderr, "fatal error: %s\n", e.what());
nRet = EXIT_FAILURE;
}
}
void vclmain::createApplication()
{
static IconTestApp aApp;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|