summaryrefslogtreecommitdiff
path: root/sw/qa/tiledrendering/tiledrendering.cxx
blob: a6205a6ea521c9e02f26ccb462ac23cef8cc8bc9 (plain)
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
/* -*- 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 <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 <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 <sfx2/filedlghelper.hxx>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
#include <sfx2/filedlghelper.hxx>

class UIPreviewApp : public Application
{
public:
    virtual void Init();
    virtual int Main();
};

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::sfx2;

class TiledRenderingDialog: public ModalDialog{
public:
    TiledRenderingDialog() : ModalDialog(DIALOG_NO_PARENT, "TiledRendering", "qa/sw/ui/tiledrendering.ui")
    {
        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);
    }
    virtual ~TiledRenderingDialog()
    {
    }

    DECL_LINK ( RenderHdl, Button * );
    DECL_LINK ( ChooseDocumentHdl, Button * );

    sal_Int32 extractInt(const char * name)
    {
        NumericField * pField;
        get(pField,name);
        OUString aString(pField->GetText());
        std::cerr << "param " << name << " returned " << aString <<"\n";
        return aString.toInt32();
    }

};

IMPL_LINK ( TiledRenderingDialog,  RenderHdl, Button *, EMPTYARG )
{
    extractInt("spinContextWidth");
    extractInt("spinContextHeight");
    extractInt("spinTilePosX");
    extractInt("spinTilePosY");
    extractInt("spinTileWidth");
    extractInt("spinTileHeight");
    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 aFilePath =xFP->getFiles().getConstArray()[0];
        std::cerr << aFilePath <<"\n";
    }
    return 1;
}

void UIPreviewApp::Init()
{
    uno::Reference<uno::XComponentContext> xContext =
        cppu::defaultBootstrap_InitialComponentContext();
    uno::Reference<lang::XMultiComponentFactory> xFactory =
        xContext->getServiceManager();
    uno::Reference<lang::XMultiServiceFactory> xSFactory =
        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() );
}

int UIPreviewApp::Main()
{
    //std::vector<OUString> uifiles;
    //for (sal_uInt16 i = 0; i < GetCommandLineParamCount(); ++i)
    //{
    //    OUString aFileUrl;
    //   osl::File::getFileURLFromSystemPath(GetCommandLineParam(i), aFileUrl);
    //    uifiles.push_back(aFileUrl);
    //}
    //if (uifiles.empty())
    //{
    //    fprintf(stderr, "Usage: ui-previewer file.ui\n");
    //    return EXIT_FAILURE;
    //}

    // turn on tooltips
    Help::EnableQuickHelp();

    try
    {

        TiledRenderingDialog pDialog;

        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 UIPreviewApp aApp;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */