LCOV - code coverage report
Current view: top level - include/vcl - builder.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 55 0.0 %
Date: 2014-04-14 Functions: 0 493 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 INCLUDED_VCL_BUILDER_HXX
      11             : #define INCLUDED_VCL_BUILDER_HXX
      12             : 
      13             : #include <typeinfo>
      14             : #include <osl/module.hxx>
      15             : #include <tools/resmgr.hxx>
      16             : #include <vcl/dllapi.h>
      17             : #include <vcl/window.hxx>
      18             : #include <xmlreader/xmlreader.hxx>
      19             : #include <map>
      20             : #include <set>
      21             : #include <stack>
      22             : #include <vector>
      23             : #include <boost/noncopyable.hpp>
      24             : #ifdef check
      25             : #  //some problem with MacOSX and a check define
      26             : #  undef check
      27             : #endif
      28             : #include <boost/ptr_container/ptr_map.hpp>
      29             : 
      30             : #include <com/sun/star/frame/XFrame.hpp>
      31             : 
      32             : class ListBox;
      33             : class NumericFormatter;
      34             : class PopupMenu;
      35             : class ScrollBar;
      36             : class DateField;
      37             : class TimeField;
      38             : class VclExpander;
      39             : class VclMultiLineEdit;
      40             : 
      41             : class VCL_DLLPUBLIC VclBuilder: private boost::noncopyable
      42             : {
      43             : public:
      44             :     typedef std::map<OString, OString> stringmap;
      45             :     typedef ::Window* (*customMakeWidget)(::Window *pParent, stringmap &rVec);
      46             : private:
      47             :     typedef boost::ptr_map<OUString, osl::Module> ModuleMap;
      48             :     //We store these until the builder is deleted, that way we can use the
      49             :     //ui-previewer on custom widgets and guarantee the modules they are from
      50             :     //exist for the duration of the dialog
      51             :     ModuleMap m_aModuleMap;
      52             : 
      53             :     //If the toplevel window has any properties which need to be set on it,
      54             :     //but the toplevel is the owner of the builder, then its ctor
      55             :     //has not been completed during the building, so properties for it
      56             :     //are collected here and need to be set afterwards, e.g. during
      57             :     //Show or Execute
      58             :     stringmap m_aDeferredProperties;
      59             : 
      60             :     struct PackingData
      61             :     {
      62             :         bool m_bVerticalOrient;
      63             :         sal_Int32 m_nPosition;
      64           0 :         PackingData(bool bVerticalOrient = false, sal_Int32 nPosition = -1)
      65             :             : m_bVerticalOrient(bVerticalOrient)
      66           0 :             , m_nPosition(nPosition)
      67             :         {
      68           0 :         }
      69             :     };
      70             : 
      71           0 :     struct WinAndId
      72             :     {
      73             :         OString m_sID;
      74             :         ::Window *m_pWindow;
      75             :         short m_nResponseId;
      76             :         PackingData m_aPackingData;
      77           0 :         WinAndId(const OString &rId, ::Window *pWindow, bool bVertical)
      78             :             : m_sID(rId)
      79             :             , m_pWindow(pWindow)
      80             :             , m_nResponseId(RET_CANCEL)
      81           0 :             , m_aPackingData(bVertical)
      82             :         {
      83           0 :         }
      84             :     };
      85             :     std::vector<WinAndId> m_aChildren;
      86             : 
      87           0 :     struct MenuAndId
      88             :     {
      89             :         OString m_sID;
      90             :         PopupMenu *m_pMenu;
      91           0 :         MenuAndId(const OString &rId, PopupMenu *pMenu)
      92             :             : m_sID(rId)
      93           0 :             , m_pMenu(pMenu)
      94             :         {
      95           0 :         }
      96             :     };
      97             :     std::vector<MenuAndId> m_aMenus;
      98             : 
      99           0 :     struct StringPair
     100             :     {
     101             :         OString m_sID;
     102             :         OString m_sValue;
     103           0 :         StringPair(const OString &rId, const OString &rValue)
     104             :             : m_sID(rId)
     105           0 :             , m_sValue(rValue)
     106             :         {
     107           0 :         }
     108             :     };
     109             : 
     110             :     typedef StringPair RadioButtonGroupMap;
     111             : 
     112           0 :     struct ButtonImageWidgetMap
     113             :     {
     114             :         OString m_sID;
     115             :         OString m_sValue;
     116             :         bool m_bRadio;
     117           0 :         ButtonImageWidgetMap(const OString &rId, const OString &rValue, bool bRadio)
     118             :             : m_sID(rId)
     119             :             , m_sValue(rValue)
     120           0 :             , m_bRadio(bRadio)
     121             :         {
     122           0 :         }
     123             :     };
     124             : 
     125             :     typedef StringPair TextBufferMap;
     126             :     typedef StringPair WidgetAdjustmentMap;
     127             :     typedef StringPair ButtonMenuMap;
     128             :     typedef StringPair MnemonicWidgetMap;
     129             : 
     130           0 :     struct ComboBoxModelMap
     131             :     {
     132             :         OString m_sID;
     133             :         OString m_sValue;
     134             :         sal_Int32 m_nActiveId;
     135           0 :         ComboBoxModelMap(const OString &rId, const OString &rValue, sal_Int32 nActiveId)
     136             :             : m_sID(rId)
     137             :             , m_sValue(rValue)
     138           0 :             , m_nActiveId(nActiveId)
     139             :         {
     140           0 :         }
     141             :     };
     142             : 
     143           0 :     struct ListStore
     144             :     {
     145             :         typedef std::vector<OString> row;
     146             :         std::vector<row> m_aEntries;
     147             :     };
     148             :     const ListStore* get_model_by_name(const OString& sID) const;
     149             :     static void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
     150             : 
     151             :     typedef stringmap TextBuffer;
     152             :     const TextBuffer* get_buffer_by_name(const OString& sID) const;
     153             :     static void mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rTextBuffer);
     154             : 
     155             :     typedef stringmap Adjustment;
     156             :     const Adjustment *get_adjustment_by_name(const OString& sID) const;
     157             :     static void mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment);
     158             :     static void mungeAdjustment(DateField &rTarget, const Adjustment &rAdjustment);
     159             :     static void mungeAdjustment(TimeField &rTarget, const Adjustment &rAdjustment);
     160             :     static void mungeAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment);
     161             : 
     162             :     typedef std::map<OString, OString> WidgetTranslations;
     163             :     typedef std::map<OString, WidgetTranslations> Translations;
     164             : 
     165           0 :     struct stockinfo
     166             :     {
     167             :         OString m_sStock;
     168             :         int m_nSize;
     169           0 :         stockinfo() : m_nSize(4) {}
     170             :     };
     171             : 
     172             :     typedef std::map<OString, stockinfo> StockMap;
     173             : 
     174           0 :     struct SizeGroup
     175             :     {
     176             :         OString m_sID;
     177             :         std::vector<OString> m_aWidgets;
     178             :         stringmap m_aProperties;
     179           0 :         SizeGroup(const OString &rId)
     180           0 :             : m_sID(rId)
     181             :         {
     182           0 :         }
     183             :     };
     184             : 
     185             :     typedef std::map< ::Window*, stringmap> AtkMap;
     186             : 
     187           0 :     struct ParserState
     188             :     {
     189             :         std::vector<RadioButtonGroupMap> m_aGroupMaps;
     190             : 
     191             :         std::vector<ComboBoxModelMap> m_aModelMaps;
     192             :         std::map<OString, ListStore> m_aModels;
     193             : 
     194             :         std::vector<TextBufferMap> m_aTextBufferMaps;
     195             :         std::map<OString, TextBuffer> m_aTextBuffers;
     196             : 
     197             :         std::vector<WidgetAdjustmentMap> m_aNumericFormatterAdjustmentMaps;
     198             :         std::vector<WidgetAdjustmentMap> m_aTimeFormatterAdjustmentMaps;
     199             :         std::vector<WidgetAdjustmentMap> m_aDateFormatterAdjustmentMaps;
     200             :         std::vector<WidgetAdjustmentMap> m_aScrollAdjustmentMaps;
     201             :         std::map<OString, Adjustment> m_aAdjustments;
     202             : 
     203             :         std::vector<ButtonImageWidgetMap> m_aButtonImageWidgetMaps;
     204             :         StockMap m_aStockMap;
     205             : 
     206             :         std::vector<ButtonMenuMap> m_aButtonMenuMaps;
     207             : 
     208             :         Translations m_aTranslations;
     209             : 
     210             :         std::map< ::Window*, ::Window*> m_aRedundantParentWidgets;
     211             : 
     212             :         std::vector<SizeGroup> m_aSizeGroups;
     213             : 
     214             :         AtkMap m_aAtkInfo;
     215             : 
     216             :         std::vector<MnemonicWidgetMap> m_aMnemonicWidgetMaps;
     217             : 
     218             :         std::vector<VclExpander*> m_aExpanderWidgets;
     219             : 
     220             :         sal_uInt16 m_nLastToolbarId;
     221             : 
     222           0 :         ParserState()
     223           0 :             : m_nLastToolbarId(0)
     224           0 :         {}
     225             :     };
     226             : 
     227             :     void loadTranslations(const LanguageTag &rLanguageTag, const OUString &rUri);
     228             :     OString getTranslation(const OString &rId, const OString &rProperty) const;
     229             : 
     230             :     OString m_sID;
     231             :     OString m_sHelpRoot;
     232             :     ResHookProc m_pStringReplace;
     233             :     ::Window *m_pParent;
     234             :     bool m_bToplevelHasDeferredInit;
     235             :     bool m_bToplevelHasDeferredProperties;
     236             :     bool m_bToplevelParentFound;
     237             :     ParserState *m_pParserState;
     238             : 
     239             :     ::Window *get_by_name(const OString& sID);
     240             :     void delete_by_name(const OString& sID);
     241             : 
     242             :     class sortIntoBestTabTraversalOrder
     243             :         : public std::binary_function<const ::Window*, const ::Window*, bool>
     244             :     {
     245             :         VclBuilder *m_pBuilder;
     246             :     public:
     247           0 :         sortIntoBestTabTraversalOrder(VclBuilder *pBuilder)
     248           0 :             : m_pBuilder(pBuilder)
     249             :         {
     250           0 :         }
     251             :         bool operator()(const ::Window *pA, const ::Window *pB) const;
     252             :     };
     253             : 
     254             :     /// XFrame to be able to extract labels and other properties of the UNO commands (like of .uno:Bold).
     255             :     css::uno::Reference<css::frame::XFrame> m_xFrame;
     256             : 
     257             : public:
     258             :     VclBuilder(::Window *pParent, const OUString& sUIRootDir, const OUString& sUIFile,
     259             :             const OString& sID = OString(),
     260             :             const com::sun::star::uno::Reference<com::sun::star::frame::XFrame> &rFrame = com::sun::star::uno::Reference<com::sun::star::frame::XFrame>());
     261             :     ~VclBuilder();
     262             :     ::Window *get_widget_root();
     263             :     //sID must exist and be of type T
     264           0 :     template <typename T> T* get(T*& ret, const OString& sID)
     265             :     {
     266           0 :         ::Window *w = get_by_name(sID);
     267             :         SAL_WARN_IF(!w, "vcl.layout", "widget \"" << sID.getStr() << "\" not found in .ui");
     268             :         SAL_WARN_IF(!dynamic_cast<T*>(w),
     269             :             "vcl.layout", ".ui widget \"" << sID.getStr() << "\" needs to correspond to vcl type " << typeid(T).name());
     270             :         assert(w && dynamic_cast<T*>(w));
     271           0 :         ret = static_cast<T*>(w);
     272           0 :         return ret;
     273             :     }
     274             :     PopupMenu* get_menu(PopupMenu*& ret, const OString& sID)
     275             :     {
     276             :         ret = get_menu(sID);
     277             :         SAL_WARN_IF(!ret, "vcl.layout", "menu \"" << sID.getStr() << "\" not found in .ui");
     278             :         assert(ret);
     279             :         return ret;
     280             :     }
     281             :     //sID may not exist, but must be of type T if it does
     282           0 :     template <typename T /*= ::Window if we had c++11*/> T* get(const OString& sID)
     283             :     {
     284           0 :         ::Window *w = get_by_name(sID);
     285             :         SAL_WARN_IF(w && !dynamic_cast<T*>(w),
     286             :             "vcl.layout", ".ui widget \"" << sID.getStr() << "\" needs to correspond to vcl type " << typeid(T).name());
     287             :         assert(!w || dynamic_cast<T*>(w));
     288           0 :         return static_cast<T*>(w);
     289             :     }
     290             :     //sID may not exist
     291             :     PopupMenu* get_menu(const OString& sID);
     292             : 
     293             :     //given an sID return the response value for that widget
     294             :     short get_response(const ::Window *pWindow) const;
     295             : 
     296             :     OString get_by_window(const ::Window *pWindow) const;
     297             :     void delete_by_window(const ::Window *pWindow);
     298             : 
     299             :     //apply the properties of rProps to pWindow
     300             :     static void set_properties(::Window *pWindow, const stringmap &rProps);
     301             : 
     302             :     //Convert _ gtk markup to ~ vcl markup
     303             :     static OString convertMnemonicMarkup(const OString &rIn);
     304             : 
     305             :     static OString extractCustomProperty(stringmap &rMap);
     306             : 
     307             :     static bool extractDropdown(stringmap &rMap);
     308             : 
     309             :     //add a default value of 25 width-chars to a map if width-chars not set
     310             :     static void ensureDefaultWidthChars(VclBuilder::stringmap &rMap);
     311             : 
     312             :     //see m_aDeferredProperties, you need this for toplevel dialogs
     313             :     //which build themselves from their ctor. The properties on
     314             :     //the top level are stored in m_aDeferredProperties and need
     315             :     //to be applied post ctor
     316             :     void setDeferredProperties();
     317             : 
     318             :     //Helpers to retrofit all the existing code to the builder
     319             :     static void reorderWithinParent(std::vector< ::Window*>& rChilds, bool bIsButtonBox);
     320             :     static void reorderWithinParent(::Window &rWindow, sal_uInt16 nNewPosition);
     321             : 
     322             :     css::uno::Reference<css::frame::XFrame> getFrame() { return m_xFrame; }
     323             : private:
     324             :     ::Window *insertObject(::Window *pParent,
     325             :         const OString &rClass, const OString &rID,
     326             :         stringmap &rProps, stringmap &rPangoAttributes,
     327             :         stringmap &rAtkProps, std::vector<OString> &rItems);
     328             : 
     329             :     ::Window *makeObject(::Window *pParent,
     330             :         const OString &rClass, const OString &rID,
     331             :         stringmap &rVec, const std::vector<OString> &rItems);
     332             : 
     333             :     void connectNumericFormatterAdjustment(const OString &id, const OString &rAdjustment);
     334             :     void connectTimeFormatterAdjustment(const OString &id, const OString &rAdjustment);
     335             :     void connectDateFormatterAdjustment(const OString &id, const OString &rAdjustment);
     336             : 
     337             :     bool extractGroup(const OString &id, stringmap &rVec);
     338             :     bool extractModel(const OString &id, stringmap &rVec);
     339             :     bool extractBuffer(const OString &id, stringmap &rVec);
     340             :     bool extractScrollAdjustment(const OString &id, stringmap &rVec);
     341             :     bool extractButtonImage(const OString &id, stringmap &rMap, bool bRadio);
     342             :     bool extractStock(const OString &id, stringmap &rMap);
     343             :     void extractMnemonicWidget(const OString &id, stringmap &rMap);
     344             : 
     345             :     void handleTranslations(xmlreader::XmlReader &reader);
     346             : 
     347             :     void handleChild(::Window *pParent, xmlreader::XmlReader &reader);
     348             :     ::Window* handleObject(::Window *pParent, xmlreader::XmlReader &reader);
     349             :     void handlePacking(::Window *pCurrent, ::Window *pParent, xmlreader::XmlReader &reader);
     350             :     void applyPackingProperty(::Window *pCurrent, ::Window *pParent, xmlreader::XmlReader &reader);
     351             :     void collectProperty(xmlreader::XmlReader &reader, const OString &rID, stringmap &rVec);
     352             :     void collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
     353             :     void collectAtkAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
     354             :     void collectAccelerator(xmlreader::XmlReader &reader, stringmap &rMap);
     355             : 
     356             :     void insertMenuObject(PopupMenu *pParent, const OString &rClass, const OString &rID,
     357             :         stringmap &rProps, stringmap &rAccels);
     358             :     void handleMenuChild(PopupMenu *pParent, xmlreader::XmlReader &reader);
     359             :     void handleMenuObject(PopupMenu *pParent, xmlreader::XmlReader &reader);
     360             : 
     361             :     void handleListStore(xmlreader::XmlReader &reader, const OString &rID);
     362             :     void handleRow(xmlreader::XmlReader &reader, const OString &rID, sal_Int32 nRowIndex);
     363             :     void handleAdjustment(const OString &rID, stringmap &rProperties);
     364             :     void handleTextBuffer(const OString &rID, stringmap &rProperties);
     365             :     void handleTabChild(::Window *pParent, xmlreader::XmlReader &reader);
     366             :     void handleMenu(xmlreader::XmlReader &reader, const OString &rID);
     367             :     std::vector<OString> handleItems(xmlreader::XmlReader &reader, const OString &rID);
     368             : 
     369             :     void handleSizeGroup(xmlreader::XmlReader &reader, const OString &rID);
     370             : 
     371             :     void handleAtkObject(xmlreader::XmlReader &reader, const OString &rID, ::Window *pWindow);
     372             : 
     373             :     void handleActionWidget(xmlreader::XmlReader &reader);
     374             : 
     375             :     PackingData get_window_packing_data(const ::Window *pWindow) const;
     376             :     void set_window_packing_position(const ::Window *pWindow, sal_Int32 nPosition);
     377             : 
     378             :     ::Window* prepareWidgetOwnScrolling(::Window *pParent, WinBits &rWinStyle);
     379             :     void cleanupWidgetOwnScrolling(::Window *pScrollParent, ::Window *pWindow, stringmap &rMap);
     380             : 
     381             :     void set_response(const OString& sID, short nResponse);
     382             : };
     383             : 
     384             : 
     385             : //helper baseclass to ease retro fitting dialogs/tabpages that load a resource
     386             : //to load a .ui file instead
     387             : //
     388             : //vcl requires the Window Children of a Parent Window to be destroyed before
     389             : //the Parent Window.  VclBuilderContainer owns the VclBuilder which owns the
     390             : //Children Window. So the VclBuilderContainer dtor must be called before
     391             : //the Parent Window dtor.
     392             : //
     393             : //i.e.  class Dialog : public SystemWindow, public VclBuilderContainer
     394             : //not   class Dialog : public VclBuilderContainer, public SystemWindow
     395             : 
     396             : class VCL_DLLPUBLIC VclBuilderContainer
     397             : {
     398             : protected:
     399             :     VclBuilder *m_pUIBuilder;
     400             : public:
     401             :     VclBuilderContainer();
     402             :     virtual ~VclBuilderContainer();
     403             :     static OUString getUIRootDir();
     404           0 :     bool hasBuilder() const { return m_pUIBuilder != NULL; }
     405             :     css::uno::Reference<css::frame::XFrame> getFrame() { return m_pUIBuilder->getFrame(); }
     406           0 :     template <typename T> T* get(T*& ret, const OString& sID)
     407             :     {
     408           0 :         return m_pUIBuilder->get<T>(ret, sID);
     409             :     }
     410           0 :     template <typename T /*= ::Window if we had c++11*/> T* get(const OString & sID)
     411             :     {
     412           0 :         return m_pUIBuilder->get<T>(sID);
     413             :     }
     414             :     PopupMenu* get_menu(PopupMenu*& ret, const OString & sID)
     415             :     {
     416             :         return m_pUIBuilder->get_menu(ret, sID);
     417             :     }
     418           0 :     PopupMenu* get_menu(const OString & sID)
     419             :     {
     420           0 :         return m_pUIBuilder->get_menu(sID);
     421             :     }
     422           0 :     void setDeferredProperties()
     423             :     {
     424           0 :         if (!m_pUIBuilder)
     425           0 :             return;
     426           0 :         m_pUIBuilder->setDeferredProperties();
     427             :     }
     428             : };
     429             : 
     430             : /*
     431             :  * @return true if rValue is "True", "true", "1", etc.
     432             :  */
     433             : bool VCL_DLLPUBLIC toBool(const OString &rValue);
     434             : 
     435             : #endif
     436             : 
     437             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10