LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/vcl - builder.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 37 0.0 %
Date: 2012-12-27 Functions: 0 181 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef _VCLBUILDER_HXX
      11             : #define _VCLBUILDER_HXX
      12             : 
      13             : #include <typeinfo>
      14             : #include <vcl/dllapi.h>
      15             : #include <vcl/window.hxx>
      16             : #include <xmlreader/xmlreader.hxx>
      17             : #include <map>
      18             : #include <set>
      19             : #include <stack>
      20             : #include <vector>
      21             : 
      22             : class ListBox;
      23             : class NumericFormatter;
      24             : class PopupMenu;
      25             : class ScrollBar;
      26             : class VclMultiLineEdit;
      27             : 
      28             : class VCL_DLLPUBLIC VclBuilder
      29             : {
      30             : public:
      31             :     typedef std::map<OString, OString> stringmap;
      32             :     typedef Window* (*customMakeWidget)(Window *pParent, stringmap &rVec);
      33             : private:
      34             : 
      35             :     struct PackingData
      36             :     {
      37             :         bool m_bVerticalOrient;
      38             :         sal_Int32 m_nPosition;
      39           0 :         PackingData(bool bVerticalOrient = false, sal_Int32 nPosition = -1)
      40             :             : m_bVerticalOrient(bVerticalOrient)
      41           0 :             , m_nPosition(nPosition)
      42             :         {
      43           0 :         }
      44             :     };
      45             : 
      46           0 :     struct WinAndId
      47             :     {
      48             :         OString m_sID;
      49             :         Window *m_pWindow;
      50             :         PackingData m_aPackingData;
      51           0 :         WinAndId(const OString &rId, Window *pWindow, bool bVertical)
      52             :             : m_sID(rId)
      53             :             , m_pWindow(pWindow)
      54           0 :             , m_aPackingData(bVertical)
      55             :         {
      56           0 :         }
      57             :     };
      58             :     std::vector<WinAndId> m_aChildren;
      59             : 
      60           0 :     struct MenuAndId
      61             :     {
      62             :         OString m_sID;
      63             :         PopupMenu *m_pMenu;
      64           0 :         MenuAndId(const OString &rId, PopupMenu *pMenu)
      65             :             : m_sID(rId)
      66           0 :             , m_pMenu(pMenu)
      67             :         {
      68           0 :         }
      69             :     };
      70             :     std::vector<MenuAndId> m_aMenus;
      71             : 
      72           0 :     struct StringPair
      73             :     {
      74             :         OString m_sID;
      75             :         OString m_sValue;
      76           0 :         StringPair(const OString &rId, const OString &rValue)
      77             :             : m_sID(rId)
      78           0 :             , m_sValue(rValue)
      79             :         {
      80           0 :         }
      81             :     };
      82             : 
      83             :     typedef StringPair RadioButtonGroupMap;
      84             :     typedef StringPair ButtonImageWidgetMap;
      85             :     typedef StringPair TextBufferMap;
      86             :     typedef StringPair WidgetAdjustmentMap;
      87             :     typedef StringPair ButtonMenuMap;
      88             : 
      89           0 :     struct ComboBoxModelMap
      90             :     {
      91             :         OString m_sID;
      92             :         OString m_sValue;
      93             :         sal_Int32 m_nActiveId;
      94           0 :         ComboBoxModelMap(const OString &rId, const OString &rValue, sal_Int32 nActiveId)
      95             :             : m_sID(rId)
      96             :             , m_sValue(rValue)
      97           0 :             , m_nActiveId(nActiveId)
      98             :         {
      99           0 :         }
     100             :     };
     101             : 
     102           0 :     struct ListStore
     103             :     {
     104             :         typedef std::vector<OString> row;
     105             :         std::vector<row> m_aEntries;
     106             :     };
     107             :     const ListStore* get_model_by_name(OString sID) const;
     108             :     static void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
     109             : 
     110             :     typedef stringmap TextBuffer;
     111             :     const TextBuffer* get_buffer_by_name(OString sID) const;
     112             :     static void mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rTextBuffer);
     113             : 
     114             :     typedef stringmap Adjustment;
     115             :     const Adjustment *get_adjustment_by_name(OString sID) const;
     116             :     static void mungeSpinAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment);
     117             :     static void mungeScrollAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment);
     118             : 
     119             :     typedef std::map<OString, OString> WidgetTranslations;
     120             :     typedef std::map<OString, WidgetTranslations> Translations;
     121             : 
     122           0 :     struct stockinfo
     123             :     {
     124             :         OString m_sStock;
     125             :         int m_nSize;
     126           0 :         stockinfo() : m_nSize(4) {}
     127             :     };
     128             : 
     129             :     typedef std::map<OString, stockinfo> StockMap;
     130             : 
     131           0 :     struct ParserState
     132             :     {
     133             :         std::vector<RadioButtonGroupMap> m_aGroupMaps;
     134             : 
     135             :         std::vector<ComboBoxModelMap> m_aModelMaps;
     136             :         std::map<OString, ListStore> m_aModels;
     137             : 
     138             :         std::vector<TextBufferMap> m_aTextBufferMaps;
     139             :         std::map<OString, TextBuffer> m_aTextBuffers;
     140             : 
     141             :         std::vector<WidgetAdjustmentMap> m_aSpinAdjustmentMaps;
     142             :         std::vector<WidgetAdjustmentMap> m_aScrollAdjustmentMaps;
     143             :         std::map<OString, Adjustment> m_aAdjustments;
     144             : 
     145             :         std::vector<ButtonImageWidgetMap> m_aButtonImageWidgetMaps;
     146             :         StockMap m_aStockMap;
     147             : 
     148             :         std::vector<ButtonMenuMap> m_aButtonMenuMaps;
     149             : 
     150             :         Translations m_aTranslations;
     151             : 
     152             :         std::map<Window*, Window*> m_aRedundantParentWidgets;
     153             :     };
     154             : 
     155             :     void loadTranslations(const com::sun::star::lang::Locale &rLocale, const OUString &rUri);
     156             :     OString getTranslation(const OString &rId, const OString &rProperty) const;
     157             : 
     158             :     OString m_sID;
     159             :     OString m_sHelpRoot;
     160             :     OString m_sProductName;
     161             :     Window *m_pParent;
     162             :     bool m_bToplevelHasDeferredInit;
     163             :     bool m_bToplevelParentFound;
     164             :     ParserState *m_pParserState;
     165             : 
     166             :     Window *get_by_name(OString sID);
     167             :     void delete_by_name(OString sID);
     168             : 
     169             :     PopupMenu *get_menu_by_name(OString sID);
     170             : 
     171             :     class sortIntoBestTabTraversalOrder
     172             :         : public std::binary_function<const Window*, const Window*, bool>
     173             :     {
     174             :         VclBuilder *m_pBuilder;
     175             :     public:
     176           0 :         sortIntoBestTabTraversalOrder(VclBuilder *pBuilder)
     177           0 :             : m_pBuilder(pBuilder)
     178             :         {
     179           0 :         }
     180             :         bool operator()(const Window *pA, const Window *pB) const;
     181             :     };
     182             : public:
     183             :     VclBuilder(Window *pParent, OUString sUIRootDir, OUString sUIFile, OString sID = OString());
     184             :     ~VclBuilder();
     185             :     Window *get_widget_root();
     186             :     //sID must exist and be of type T
     187           0 :     template <typename T> T* get(T*& ret, OString sID)
     188             :     {
     189           0 :         Window *w = get_by_name(sID);
     190             :         SAL_WARN_IF(!w, "vcl.layout", "widget \"" << sID.getStr() << "\" not found in .ui");
     191             :         SAL_WARN_IF(!dynamic_cast<T*>(w),
     192             :             "vcl.layout", ".ui widget \"" << sID.getStr() << "\" needs to correspond to vcl type " << typeid(T).name());
     193             :         assert(w && dynamic_cast<T*>(w));
     194           0 :         ret = static_cast<T*>(w);
     195           0 :         return ret;
     196             :     }
     197             :     //sID may not exist, but must be of type T if it does
     198           0 :     template <typename T /*=Window if we had c++11*/> T* get(OString sID)
     199             :     {
     200           0 :         Window *w = get_by_name(sID);
     201             :         SAL_WARN_IF(w && !dynamic_cast<T*>(w),
     202             :             "vcl.layout", ".ui widget \"" << sID.getStr() << "\" needs to correspond to vcl type " << typeid(T).name());
     203             :         assert(!w || dynamic_cast<T*>(w));
     204           0 :         return static_cast<T*>(w);
     205             :     }
     206             :     OString get_by_window(const Window *pWindow) const;
     207             :     void delete_by_window(const Window *pWindow);
     208             : 
     209             :     //Convert _ gtk markup to ~ vcl markup
     210             :     static OString convertMnemonicMarkup(const OString &rIn);
     211             : 
     212             : private:
     213             :     Window *insertObject(Window *pParent, const OString &rClass, const OString &rID,
     214             :         stringmap &rProps, stringmap &rPangoAttributes, std::vector<OString> &rItems);
     215             : 
     216             :     Window *makeObject(Window *pParent, const OString &rClass, const OString &rID,
     217             :         stringmap &rVec, const std::vector<OString> &rItems);
     218             : 
     219             :     bool extractGroup(const OString &id, stringmap &rVec);
     220             :     bool extractModel(const OString &id, stringmap &rVec);
     221             :     bool extractBuffer(const OString &id, stringmap &rVec);
     222             :     bool extractSpinAdjustment(const OString &id, stringmap &rVec);
     223             :     bool extractScrollAdjustment(const OString &id, stringmap &rVec);
     224             :     bool extractImage(const OString &id, stringmap &rMap);
     225             :     bool extractStock(const OString &id, stringmap &rMap);
     226             : 
     227             :     void handleTranslations(xmlreader::XmlReader &reader);
     228             : 
     229             :     void handleChild(Window *pParent, xmlreader::XmlReader &reader);
     230             :     Window* handleObject(Window *pParent, xmlreader::XmlReader &reader);
     231             :     void handlePacking(Window *pCurrent, xmlreader::XmlReader &reader);
     232             :     void applyPackingProperty(Window *pCurrent, xmlreader::XmlReader &reader);
     233             :     void collectProperty(xmlreader::XmlReader &reader, const OString &rID, stringmap &rVec);
     234             :     void collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
     235             :     void collectAccelerator(xmlreader::XmlReader &reader, stringmap &rMap);
     236             : 
     237             :     void insertMenuObject(PopupMenu *pParent, const OString &rClass, const OString &rID,
     238             :         stringmap &rProps, stringmap &rAccels);
     239             :     void handleMenuChild(PopupMenu *pParent, xmlreader::XmlReader &reader);
     240             :     void handleMenuObject(PopupMenu *pParent, xmlreader::XmlReader &reader);
     241             : 
     242             :     void handleListStore(xmlreader::XmlReader &reader, const OString &rID);
     243             :     void handleRow(xmlreader::XmlReader &reader, const OString &rID, sal_Int32 nRowIndex);
     244             :     void handleAdjustment(const OString &rID, stringmap &rProperties);
     245             :     void handleTextBuffer(const OString &rID, stringmap &rProperties);
     246             :     void handleTabChild(Window *pParent, xmlreader::XmlReader &reader);
     247             :     void handleMenu(xmlreader::XmlReader &reader, const OString &rID);
     248             :     std::vector<OString> handleItems(xmlreader::XmlReader &reader, const OString &rID);
     249             : 
     250             :     PackingData get_window_packing_data(const Window *pWindow) const;
     251             :     void set_window_packing_position(const Window *pWindow, sal_Int32 nPosition);
     252             : 
     253             :     //Helpers to retrofit all the existing code to the builder
     254             :     static void reorderWithinParent(Window &rWindow, sal_uInt16 nNewPosition);
     255             : };
     256             : 
     257             : 
     258             : //helper baseclass to ease retro fitting dialogs/tabpages that load a resource
     259             : //to load a .ui file instead
     260             : //
     261             : //vcl requires the Window Children of a Parent Window to be destroyed before
     262             : //the Parent Window.  VclBuilderContainer owns the VclBuilder which owns the
     263             : //Children Window. So the VclBuilderContainer dtor must be called before
     264             : //the Parent Window dtor.
     265             : //
     266             : //i.e.  class Dialog : public SystemWindow, public VclBuilderContainer
     267             : //not   class Dialog : public VclBuilderContainer, public SystemWindow
     268             : 
     269             : class VCL_DLLPUBLIC VclBuilderContainer
     270             : {
     271             : protected:
     272             :     VclBuilder *m_pUIBuilder;
     273             : public:
     274             :     VclBuilderContainer();
     275             :     virtual ~VclBuilderContainer();
     276             :     static OUString getUIRootDir();
     277           0 :     template <typename T> T* get(T*& ret, OString sID)
     278             :     {
     279           0 :         return m_pUIBuilder->get<T>(ret, sID);
     280             :     }
     281           0 :     template <typename T /*=Window if we had c++11*/> T* get(OString sID)
     282             :     {
     283           0 :         return m_pUIBuilder->get<T>(sID);
     284             :     }
     285             : };
     286             : 
     287             : /*
     288             :  * @return true if rValue is "True", "true", "1", etc.
     289             :  */
     290             : bool VCL_DLLPUBLIC toBool(const OString &rValue);
     291             : 
     292             : #endif
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10