2012-03-26 12:15:22 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.)
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011 the
|
|
|
|
* Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Caolán McNamara <caolanm@redhat.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
|
|
|
|
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
|
|
|
|
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
|
|
|
|
* instead of those above.
|
|
|
|
*/
|
|
|
|
#ifndef _VCLBUILDER_HXX
|
|
|
|
#define _VCLBUILDER_HXX
|
|
|
|
|
|
|
|
#include <vcl/dllapi.h>
|
|
|
|
#include <vcl/window.hxx>
|
|
|
|
#include <xmlreader/xmlreader.hxx>
|
2012-03-27 14:20:17 +01:00
|
|
|
#include <map>
|
2012-06-07 15:11:02 +01:00
|
|
|
#include <stack>
|
2012-03-26 12:15:22 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2012-06-06 08:56:46 +01:00
|
|
|
class ListBox;
|
2012-08-17 13:49:40 +01:00
|
|
|
class NumericFormatter;
|
2012-06-06 08:56:46 +01:00
|
|
|
|
2012-03-26 12:15:22 +01:00
|
|
|
class VCL_DLLPUBLIC VclBuilder
|
|
|
|
{
|
2012-06-15 12:30:19 +01:00
|
|
|
public:
|
|
|
|
typedef std::map<rtl::OString, rtl::OString> stringmap;
|
2012-08-20 10:50:32 +01:00
|
|
|
typedef Window* (*customMakeWidget)(Window *pParent);
|
2012-03-26 12:15:22 +01:00
|
|
|
private:
|
2012-04-25 11:12:55 +01:00
|
|
|
struct WinAndId
|
|
|
|
{
|
|
|
|
rtl::OString m_sID;
|
|
|
|
Window *m_pWindow;
|
2012-08-15 11:19:06 +01:00
|
|
|
sal_Int32 m_nPosition;
|
2012-05-22 12:33:28 +01:00
|
|
|
bool m_bOwned;
|
2012-04-25 11:12:55 +01:00
|
|
|
WinAndId(const rtl::OString &rId, Window *pWindow)
|
|
|
|
: m_sID(rId)
|
|
|
|
, m_pWindow(pWindow)
|
2012-08-15 11:19:06 +01:00
|
|
|
, m_nPosition(-1)
|
2012-05-22 12:33:28 +01:00
|
|
|
, m_bOwned(true)
|
2012-04-25 11:12:55 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
std::vector<WinAndId> m_aChildren;
|
2012-04-30 10:19:19 +01:00
|
|
|
|
2012-06-06 08:56:46 +01:00
|
|
|
struct ListStore
|
|
|
|
{
|
2012-08-30 12:41:18 +01:00
|
|
|
typedef std::vector<rtl::OString> row;
|
|
|
|
std::vector<row> m_aEntries;
|
2012-06-06 08:56:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ModelAndId
|
|
|
|
{
|
|
|
|
rtl::OString m_sID;
|
|
|
|
ListStore *m_pModel;
|
|
|
|
ModelAndId(const rtl::OString &rId, ListStore *pListStore)
|
|
|
|
: m_sID(rId)
|
|
|
|
, m_pModel(pListStore)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StringPair
|
2012-04-30 10:19:19 +01:00
|
|
|
{
|
|
|
|
rtl::OString m_sID;
|
2012-06-06 08:56:46 +01:00
|
|
|
rtl::OString m_sValue;
|
|
|
|
StringPair(const rtl::OString &rId, const rtl::OString &rValue)
|
2012-04-30 10:19:19 +01:00
|
|
|
: m_sID(rId)
|
2012-06-06 08:56:46 +01:00
|
|
|
, m_sValue(rValue)
|
2012-04-30 10:19:19 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2012-06-06 08:56:46 +01:00
|
|
|
|
|
|
|
typedef StringPair RadioButtonGroupMap;
|
|
|
|
typedef StringPair ComboBoxModelMap;
|
2012-08-23 15:38:30 +01:00
|
|
|
|
2012-06-06 08:56:46 +01:00
|
|
|
ListStore *get_model_by_name(rtl::OString sID);
|
|
|
|
static void mungemodel(ListBox &rTarget, ListStore &rStore);
|
2012-04-30 10:19:19 +01:00
|
|
|
|
2012-06-15 12:30:19 +01:00
|
|
|
typedef stringmap Adjustment;
|
|
|
|
|
|
|
|
struct AdjustmentAndId
|
|
|
|
{
|
|
|
|
rtl::OString m_sID;
|
|
|
|
Adjustment m_aAdjustment;
|
|
|
|
AdjustmentAndId(const rtl::OString &rId, Adjustment &rAdjustment)
|
|
|
|
: m_sID(rId)
|
|
|
|
{
|
|
|
|
m_aAdjustment.swap(rAdjustment);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef StringPair SpinButtonAdjustmentMap;
|
2012-08-23 15:38:30 +01:00
|
|
|
|
2012-06-15 12:30:19 +01:00
|
|
|
Adjustment *get_adjustment_by_name(rtl::OString sID);
|
2012-08-17 13:49:40 +01:00
|
|
|
static void mungeadjustment(NumericFormatter &rTarget, Adjustment &rAdjustment);
|
2012-06-15 12:30:19 +01:00
|
|
|
|
2012-08-07 15:27:51 +01:00
|
|
|
typedef std::map<rtl::OString, rtl::OString> WidgetTranslations;
|
|
|
|
typedef std::map<rtl::OString, WidgetTranslations> Translations;
|
2012-08-23 15:38:30 +01:00
|
|
|
|
|
|
|
struct ParserState
|
|
|
|
{
|
|
|
|
std::vector<RadioButtonGroupMap> m_aGroupMaps;
|
|
|
|
std::vector<ComboBoxModelMap> m_aModelMaps;
|
|
|
|
std::vector<ModelAndId> m_aModels;
|
|
|
|
std::vector<AdjustmentAndId> m_aAdjustments;
|
|
|
|
std::vector<SpinButtonAdjustmentMap> m_aAdjustmentMaps;
|
|
|
|
Translations m_aTranslations;
|
|
|
|
};
|
2012-08-07 15:27:51 +01:00
|
|
|
|
|
|
|
rtl::OString getTranslation(const rtl::OString &rId, const rtl::OString &rProperty) const;
|
|
|
|
|
2012-04-25 11:12:55 +01:00
|
|
|
rtl::OString m_sID;
|
2012-08-16 14:04:00 +01:00
|
|
|
rtl::OString m_sHelpRoot;
|
2012-04-25 11:12:55 +01:00
|
|
|
Window *m_pParent;
|
2012-08-23 15:38:30 +01:00
|
|
|
ParserState *m_pParserState;
|
2012-08-22 21:18:52 +01:00
|
|
|
|
|
|
|
Window *get_by_name(rtl::OString sID);
|
2012-03-26 12:15:22 +01:00
|
|
|
public:
|
2012-08-16 14:04:00 +01:00
|
|
|
VclBuilder(Window *pParent, rtl::OUString sUIRootDir, rtl::OUString sUIFile, rtl::OString sID = rtl::OString());
|
2012-03-26 12:15:22 +01:00
|
|
|
~VclBuilder();
|
|
|
|
Window *get_widget_root();
|
2012-08-22 21:18:52 +01:00
|
|
|
template <typename T> T* get(T*& ret, rtl::OString sID)
|
|
|
|
{
|
|
|
|
Window *w = get_by_name(sID);
|
|
|
|
ret = static_cast<T*>(w);
|
|
|
|
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
|
|
|
if (w)
|
|
|
|
{
|
|
|
|
ret = dynamic_cast<T*>(w);
|
|
|
|
assert(ret);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-23 13:33:53 +01:00
|
|
|
template <typename T /*=Window if we had c++11*/> T* get(rtl::OString sID)
|
2012-08-22 21:18:52 +01:00
|
|
|
{
|
|
|
|
Window *w = get_by_name(sID);
|
|
|
|
T* ret = static_cast<T*>(w);
|
|
|
|
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
|
|
|
if (w)
|
|
|
|
{
|
|
|
|
ret = dynamic_cast<T*>(w);
|
|
|
|
assert(ret);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:19:06 +01:00
|
|
|
rtl::OString get_by_window(const Window *pWindow) const;
|
2012-05-22 12:33:28 +01:00
|
|
|
//for the purposes of retrofitting this to the existing code
|
|
|
|
//look up sID, clone its properties into replacement and
|
|
|
|
//splice replacement into the tree instead of it, without
|
|
|
|
//taking ownership of it
|
|
|
|
bool replace(rtl::OString sID, Window &rReplacement);
|
2012-03-26 12:15:22 +01:00
|
|
|
private:
|
2012-04-25 11:12:55 +01:00
|
|
|
Window *insertObject(Window *pParent, const rtl::OString &rClass, const rtl::OString &rID, stringmap &rVec);
|
2012-04-30 10:19:19 +01:00
|
|
|
Window *makeObject(Window *pParent, const rtl::OString &rClass, const rtl::OString &rID, stringmap &rVec);
|
|
|
|
bool extractGroup(const rtl::OString &id, stringmap &rVec);
|
2012-06-06 08:56:46 +01:00
|
|
|
bool extractModel(const rtl::OString &id, stringmap &rVec);
|
2012-06-15 12:30:19 +01:00
|
|
|
bool extractAdjustment(const rtl::OString &id, stringmap &rVec);
|
2012-03-26 12:15:22 +01:00
|
|
|
|
2012-08-07 15:27:51 +01:00
|
|
|
void handleTranslations(xmlreader::XmlReader &reader);
|
|
|
|
|
2012-03-27 14:20:17 +01:00
|
|
|
void handleChild(Window *pParent, xmlreader::XmlReader &reader);
|
2012-03-27 16:32:28 +01:00
|
|
|
Window* handleObject(Window *pParent, xmlreader::XmlReader &reader);
|
|
|
|
void handlePacking(Window *pCurrent, xmlreader::XmlReader &reader);
|
|
|
|
void applyPackingProperty(Window *pCurrent, xmlreader::XmlReader &reader);
|
2012-08-07 15:27:51 +01:00
|
|
|
void collectProperty(xmlreader::XmlReader &reader, const rtl::OString &rID, stringmap &rVec);
|
2012-05-22 12:33:28 +01:00
|
|
|
|
2012-06-06 08:56:46 +01:00
|
|
|
void handleListStore(xmlreader::XmlReader &reader, const rtl::OString &rID);
|
2012-08-30 12:41:18 +01:00
|
|
|
void handleRow(xmlreader::XmlReader &reader, const rtl::OString &rID, sal_Int32 nRowIndex);
|
2012-06-15 12:30:19 +01:00
|
|
|
void handleAdjustment(const rtl::OString &rID, stringmap &rProperties);
|
2012-06-07 15:11:02 +01:00
|
|
|
void handleTabChild(Window *pParent, xmlreader::XmlReader &reader);
|
2012-06-06 08:56:46 +01:00
|
|
|
|
2012-08-15 11:19:06 +01:00
|
|
|
sal_Int32 get_window_packing_position(const Window *pWindow) const;
|
|
|
|
void set_window_packing_position(const Window *pWindow, sal_Int32 nPosition);
|
|
|
|
|
2012-05-22 12:33:28 +01:00
|
|
|
//Helpers to retrofit all the existing code the the builder
|
|
|
|
static void swapGuts(Window &rOrig, Window &rReplacement);
|
|
|
|
static sal_uInt16 getPositionWithinParent(Window &rWindow);
|
2012-05-23 13:17:44 +01:00
|
|
|
static void reorderWithinParent(Window &rWindow, sal_uInt16 nNewPosition);
|
2012-03-26 12:15:22 +01:00
|
|
|
};
|
|
|
|
|
2012-06-13 14:24:01 +01:00
|
|
|
|
|
|
|
//allows retro fitting existing dialogs/tabpages that load a resource
|
|
|
|
//to load a .ui file instead
|
2012-08-15 13:19:58 +01:00
|
|
|
//
|
|
|
|
//vcl requires the Window Children of a Parent Window to be destroyed before
|
|
|
|
//the Parent Window. VclBuilderContainer owns the VclBuilder which owns the
|
|
|
|
//Children Window. So the VclBuilderContainer dtor must be called before
|
|
|
|
//the Parent Window dtor.
|
|
|
|
//
|
|
|
|
//i.e. class Dialog : public SystemWindow, public VclBuilderContainer
|
|
|
|
//not class Dialog : public VclBuilderContainer, public SystemWindow
|
2012-06-13 14:24:01 +01:00
|
|
|
class ResId;
|
|
|
|
|
|
|
|
class VCL_DLLPUBLIC VclBuilderContainer
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
VclBuilder *m_pUIBuilder;
|
|
|
|
public:
|
|
|
|
VclBuilderContainer();
|
2012-08-15 13:19:58 +01:00
|
|
|
virtual ~VclBuilderContainer();
|
2012-09-10 16:59:55 +01:00
|
|
|
static rtl::OUString getUIRootDir();
|
2012-06-13 14:24:01 +01:00
|
|
|
static VclBuilder* overrideResourceWithUIXML(Window *pWindow, const ResId& rResId);
|
2012-08-20 09:59:16 +01:00
|
|
|
static bool replace_buildable(Window *pParent, const ResId& rResId, Window &rReplacement);
|
2012-08-30 00:56:52 +01:00
|
|
|
template <typename T> T* get(T*& ret, rtl::OString sID)
|
|
|
|
{
|
|
|
|
return m_pUIBuilder->get<T>(ret, sID);
|
|
|
|
}
|
|
|
|
template <typename T /*=Window if we had c++11*/> T* get(rtl::OString sID)
|
|
|
|
{
|
|
|
|
return m_pUIBuilder->get<T>(sID);
|
|
|
|
}
|
2012-06-13 14:24:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-26 12:15:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|