LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/source/window - builder.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1645 0.1 %
Date: 2013-07-09 Functions: 2 93 2.2 %
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             : #include <osl/module.hxx>
      11             : #include <sal/log.hxx>
      12             : #include <unotools/configmgr.hxx>
      13             : #include <vcl/builder.hxx>
      14             : #include <vcl/button.hxx>
      15             : #include <vcl/dialog.hxx>
      16             : #include <vcl/edit.hxx>
      17             : #include <vcl/field.hxx>
      18             : #include <vcl/fixed.hxx>
      19             : #include <vcl/fixedhyper.hxx>
      20             : #include <vcl/layout.hxx>
      21             : #include <vcl/lstbox.hxx>
      22             : #include <vcl/menubtn.hxx>
      23             : #include <vcl/mnemonic.hxx>
      24             : #include <vcl/prgsbar.hxx>
      25             : #include <vcl/scrbar.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <vcl/tabctrl.hxx>
      28             : #include <vcl/tabpage.hxx>
      29             : #include <vcl/toolbox.hxx>
      30             : #include <vcl/vclmedit.hxx>
      31             : #include <svdata.hxx>
      32             : #include <svids.hrc>
      33             : #include <window.h>
      34             : 
      35             : using namespace com::sun::star;
      36             : 
      37             : #ifdef DISABLE_DYNLOADING
      38             : #include <dlfcn.h>              //  For RTLD_DEFAULT
      39             : #endif
      40             : 
      41             : namespace
      42             : {
      43           0 :     sal_uInt16 mapStockToImageResource(OString sType)
      44             :     {
      45           0 :         sal_uInt16 nRet = 0;
      46           0 :         if (sType == "gtk-index")
      47           0 :             nRet = SV_RESID_BITMAP_INDEX;
      48           0 :         else if (sType == "gtk-refresh")
      49           0 :             nRet = SV_RESID_BITMAP_REFRESH;
      50           0 :         return nRet;
      51             :     }
      52             : 
      53           0 :     SymbolType mapStockToSymbol(OString sType)
      54             :     {
      55           0 :         SymbolType eRet = SYMBOL_NOSYMBOL;
      56           0 :         if (sType == "gtk-media-next")
      57           0 :             eRet = SYMBOL_NEXT;
      58           0 :         else if (sType == "gtk-media-previous")
      59           0 :             eRet = SYMBOL_PREV;
      60           0 :         else if (sType == "gtk-goto-first")
      61           0 :             eRet = SYMBOL_FIRST;
      62           0 :         else if (sType == "gtk-goto-last")
      63           0 :             eRet = SYMBOL_LAST;
      64           0 :         else if (sType == "gtk-go-back")
      65           0 :             eRet = SYMBOL_ARROW_LEFT;
      66           0 :         else if (sType == "gtk-go-forward")
      67           0 :             eRet = SYMBOL_ARROW_RIGHT;
      68           0 :         else if (sType == "gtk-go-up")
      69           0 :             eRet = SYMBOL_ARROW_UP;
      70           0 :         else if (sType == "gtk-go-down")
      71           0 :             eRet = SYMBOL_ARROW_DOWN;
      72           0 :         else if (sType == "gtk-missing-image")
      73           0 :             eRet = SYMBOL_IMAGE;
      74           0 :         else if (sType == "gtk-help")
      75           0 :             eRet = SYMBOL_HELP;
      76           0 :         else if (sType == "gtk-close")
      77           0 :             eRet = SYMBOL_CLOSE;
      78           0 :         else if (mapStockToImageResource(sType))
      79           0 :             eRet = SYMBOL_IMAGE;
      80           0 :         return eRet;
      81             :     }
      82             : }
      83             : 
      84           0 : void VclBuilder::loadTranslations(const com::sun::star::lang::Locale &rLocale, const OUString& rUri)
      85             : {
      86           0 :     for (int i = rLocale.Country.isEmpty() ? 1 : 0; i < 2; ++i)
      87             :     {
      88           0 :         OUStringBuffer aTransBuf;
      89           0 :         sal_Int32 nLastSlash = rUri.lastIndexOf('/');
      90           0 :         if (nLastSlash != -1)
      91           0 :             aTransBuf.append(rUri.copy(0, nLastSlash));
      92             :         else
      93             :         {
      94           0 :             aTransBuf.append('.');
      95           0 :             nLastSlash = 0;
      96             :         }
      97           0 :         aTransBuf.append("/res/").append(rLocale.Language);
      98           0 :         switch (i)
      99             :         {
     100             :             case 0:
     101           0 :                 aTransBuf.append('-').append(rLocale.Country);
     102           0 :                 break;
     103             :             default:
     104           0 :                 break;
     105             :         }
     106           0 :         sal_Int32 nEndName = rUri.lastIndexOf('.');
     107           0 :         if (nEndName == -1)
     108           0 :             nEndName = rUri.getLength();
     109           0 :         aTransBuf.append(rUri.copy(nLastSlash, nEndName-nLastSlash));
     110             : 
     111           0 :         OUString sTransUri = aTransBuf.makeStringAndClear();
     112             :         try
     113             :         {
     114           0 :             xmlreader::XmlReader reader(sTransUri);
     115           0 :             handleTranslations(reader);
     116           0 :             break;
     117             :         }
     118           0 :         catch (const ::com::sun::star::uno::Exception &)
     119             :         {
     120             :         }
     121           0 :     }
     122           0 : }
     123             : 
     124             : #if defined SAL_LOG_WARN
     125             : namespace
     126             : {
     127             :     bool isButtonType(WindowType nType)
     128             :     {
     129             :         return nType == WINDOW_PUSHBUTTON ||
     130             :                nType == WINDOW_OKBUTTON ||
     131             :                nType == WINDOW_CANCELBUTTON ||
     132             :                nType == WINDOW_HELPBUTTON ||
     133             :                nType == WINDOW_IMAGEBUTTON ||
     134             :                nType == WINDOW_MENUBUTTON ||
     135             :                nType == WINDOW_MOREBUTTON ||
     136             :                nType == WINDOW_SPINBUTTON;
     137             :     }
     138             : }
     139             : #endif
     140             : 
     141           0 : VclBuilder::VclBuilder(Window *pParent, OUString sUIDir, OUString sUIFile, OString sID, const uno::Reference<frame::XFrame>& rFrame)
     142             :     : m_sID(sID)
     143             :     , m_sHelpRoot(OUStringToOString(sUIFile, RTL_TEXTENCODING_UTF8))
     144           0 :     , m_pStringReplace(ResMgr::GetReadStringHook())
     145             :     , m_pParent(pParent)
     146             :     , m_bToplevelParentFound(false)
     147           0 :     , m_pParserState(new ParserState)
     148           0 :     , m_xFrame(rFrame)
     149             : {
     150           0 :     m_bToplevelHasDeferredInit = (pParent && pParent->IsDialog()) ? ((Dialog*)pParent)->isDeferredInit() : false;
     151           0 :     m_bToplevelHasDeferredProperties = m_bToplevelHasDeferredInit;
     152             : 
     153           0 :     sal_Int32 nIdx = m_sHelpRoot.lastIndexOf('.');
     154           0 :     if (nIdx != -1)
     155           0 :         m_sHelpRoot = m_sHelpRoot.copy(0, nIdx);
     156           0 :     m_sHelpRoot = m_sHelpRoot + OString('/');
     157             : 
     158           0 :     OUString sUri = sUIDir + sUIFile;
     159             : 
     160           0 :     com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
     161           0 :     bool bEN_US = aLocale.Language == "en" && aLocale.Country == "US" && aLocale.Variant.isEmpty();
     162           0 :     if (!bEN_US)
     163           0 :         loadTranslations(aLocale, sUri);
     164             : 
     165             :     try
     166             :     {
     167           0 :         xmlreader::XmlReader reader(sUri);
     168             : 
     169           0 :         handleChild(pParent, reader);
     170             :     }
     171           0 :     catch (const ::com::sun::star::uno::Exception &rExcept)
     172             :     {
     173             :         SAL_WARN("vcl.layout", "Unable to read .ui file: " << rExcept.Message);
     174           0 :         throw;
     175             :     }
     176             : 
     177             :     //Set Mnemonic widgets when everything has been imported
     178           0 :     for (std::vector<MnemonicWidgetMap>::iterator aI = m_pParserState->m_aMnemonicWidgetMaps.begin(),
     179           0 :         aEnd = m_pParserState->m_aMnemonicWidgetMaps.end(); aI != aEnd; ++aI)
     180             :     {
     181           0 :         FixedText *pOne = get<FixedText>(aI->m_sID);
     182           0 :         Window *pOther = get<Window>(aI->m_sValue);
     183             :         SAL_WARN_IF(!pOne || !pOther, "vcl", "missing member of Mnemonic Widget Mapping");
     184           0 :         if (pOne && pOther)
     185           0 :             pOne->set_mnemonic_widget(pOther);
     186             :     }
     187             : 
     188             :     //Set a11y relations when everything has been imported
     189           0 :     for (AtkMap::iterator aI = m_pParserState->m_aAtkInfo.begin(),
     190           0 :          aEnd = m_pParserState->m_aAtkInfo.end(); aI != aEnd; ++aI)
     191             :     {
     192           0 :         Window *pSource = aI->first;
     193           0 :         const stringmap &rMap = aI->second;
     194             : 
     195           0 :         for (stringmap::const_iterator aP = rMap.begin(),
     196           0 :             aEndP = rMap.end(); aP != aEndP; ++aP)
     197             :         {
     198           0 :             const OString &rTarget = aP->second;
     199           0 :             Window *pTarget = get<Window>(rTarget);
     200             :             SAL_WARN_IF(!pTarget, "vcl", "missing member of a11y relation: "
     201             :                 << rTarget.getStr());
     202           0 :             if (!pTarget)
     203           0 :                 continue;
     204           0 :             const OString &rType = aP->first;
     205           0 :             if (rType == "labelled-by")
     206           0 :                 pSource->SetAccessibleRelationLabeledBy(pTarget);
     207           0 :             else if (rType == "label-for")
     208           0 :                 pSource->SetAccessibleRelationLabelFor(pTarget);
     209           0 :             else if (rType == "member-of")
     210           0 :                 pSource->SetAccessibleRelationMemberOf(pTarget);
     211             :             else
     212             :             {
     213             :                 SAL_INFO("vcl.layout", "unhandled a11y relation :" << rType.getStr());
     214             :             }
     215             :         }
     216             :     }
     217             : 
     218             :     //Set radiobutton groups when everything has been imported
     219           0 :     for (std::vector<RadioButtonGroupMap>::iterator aI = m_pParserState->m_aGroupMaps.begin(),
     220           0 :          aEnd = m_pParserState->m_aGroupMaps.end(); aI != aEnd; ++aI)
     221             :     {
     222           0 :         RadioButton *pOne = get<RadioButton>(aI->m_sID);
     223           0 :         RadioButton *pOther = get<RadioButton>(aI->m_sValue);
     224             :         SAL_WARN_IF(!pOne || !pOther, "vcl", "missing member of radiobutton group");
     225           0 :         if (pOne && pOther)
     226           0 :             pOne->group(*pOther);
     227             :     }
     228             : 
     229             :     //Set ComboBox models when everything has been imported
     230           0 :     for (std::vector<ComboBoxModelMap>::iterator aI = m_pParserState->m_aModelMaps.begin(),
     231           0 :          aEnd = m_pParserState->m_aModelMaps.end(); aI != aEnd; ++aI)
     232             :     {
     233           0 :         ListBox *pTarget = get<ListBox>(aI->m_sID);
     234           0 :         const ListStore *pStore = get_model_by_name(aI->m_sValue);
     235             :         SAL_WARN_IF(!pTarget || !pStore, "vcl", "missing elements of combobox/liststore");
     236           0 :         if (pTarget && pStore)
     237           0 :             mungeModel(*pTarget, *pStore, aI->m_nActiveId);
     238             :     }
     239             : 
     240             :     //Set TextView buffers when everything has been imported
     241           0 :     for (std::vector<TextBufferMap>::iterator aI = m_pParserState->m_aTextBufferMaps.begin(),
     242           0 :          aEnd = m_pParserState->m_aTextBufferMaps.end(); aI != aEnd; ++aI)
     243             :     {
     244           0 :         VclMultiLineEdit *pTarget = get<VclMultiLineEdit>(aI->m_sID);
     245           0 :         const TextBuffer *pBuffer = get_buffer_by_name(aI->m_sValue);
     246             :         SAL_WARN_IF(!pTarget || !pBuffer, "vcl", "missing elements of textview/textbuffer");
     247           0 :         if (pTarget && pBuffer)
     248           0 :             mungeTextBuffer(*pTarget, *pBuffer);
     249             :     }
     250             : 
     251             :     //Set SpinButton adjustments when everything has been imported
     252           0 :     for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aNumericFormatterAdjustmentMaps.begin(),
     253           0 :          aEnd = m_pParserState->m_aNumericFormatterAdjustmentMaps.end(); aI != aEnd; ++aI)
     254             :     {
     255           0 :         NumericFormatter *pTarget = dynamic_cast<NumericFormatter*>(get<Window>(aI->m_sID));
     256           0 :         const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue);
     257             :         SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment");
     258           0 :         if (pTarget && pAdjustment)
     259           0 :             mungeAdjustment(*pTarget, *pAdjustment);
     260             :     }
     261             : 
     262           0 :     for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aTimeFormatterAdjustmentMaps.begin(),
     263           0 :          aEnd = m_pParserState->m_aTimeFormatterAdjustmentMaps.end(); aI != aEnd; ++aI)
     264             :     {
     265           0 :         TimeField *pTarget = dynamic_cast<TimeField*>(get<Window>(aI->m_sID));
     266           0 :         const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue);
     267             :         SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment");
     268           0 :         if (pTarget && pAdjustment)
     269           0 :             mungeAdjustment(*pTarget, *pAdjustment);
     270             :     }
     271             : 
     272           0 :     for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aDateFormatterAdjustmentMaps.begin(),
     273           0 :          aEnd = m_pParserState->m_aDateFormatterAdjustmentMaps.end(); aI != aEnd; ++aI)
     274             :     {
     275           0 :         DateField *pTarget = dynamic_cast<DateField*>(get<Window>(aI->m_sID));
     276           0 :         const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue);
     277             :         SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment");
     278           0 :         if (pTarget && pAdjustment)
     279           0 :             mungeAdjustment(*pTarget, *pAdjustment);
     280             :     }
     281             : 
     282             :     //Set ScrollBar adjustments when everything has been imported
     283           0 :     for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aScrollAdjustmentMaps.begin(),
     284           0 :          aEnd = m_pParserState->m_aScrollAdjustmentMaps.end(); aI != aEnd; ++aI)
     285             :     {
     286           0 :         ScrollBar *pTarget = get<ScrollBar>(aI->m_sID);
     287           0 :         const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue);
     288             :         SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of scrollbar/adjustment");
     289           0 :         if (pTarget && pAdjustment)
     290           0 :             mungeAdjustment(*pTarget, *pAdjustment);
     291             :     }
     292             : 
     293             :     //Set size-groups when all widgets have been imported
     294           0 :     for (std::vector<SizeGroup>::iterator aI = m_pParserState->m_aSizeGroups.begin(),
     295           0 :         aEnd = m_pParserState->m_aSizeGroups.end(); aI != aEnd; ++aI)
     296             :     {
     297           0 :         boost::shared_ptr< VclSizeGroup > xGroup(new VclSizeGroup);
     298             : 
     299           0 :         for (stringmap::iterator aP = aI->m_aProperties.begin(),
     300           0 :             aEndP = aI->m_aProperties.end(); aP != aEndP; ++aP)
     301             :         {
     302           0 :             const OString &rKey = aP->first;
     303           0 :             const OString &rValue = aP->second;
     304           0 :             xGroup->set_property(rKey, rValue);
     305             :         }
     306             : 
     307           0 :         for (std::vector<OString>::iterator aW = aI->m_aWidgets.begin(),
     308           0 :             aEndW = aI->m_aWidgets.end(); aW != aEndW; ++aW)
     309             :         {
     310           0 :             Window* pWindow = get<Window>(aW->getStr());
     311           0 :             pWindow->add_to_size_group(xGroup);
     312             :         }
     313           0 :     }
     314             : 
     315             :     //Set button images when everything has been imported
     316           0 :     std::set<OString> aImagesToBeRemoved;
     317           0 :     for (std::vector<ButtonImageWidgetMap>::iterator aI = m_pParserState->m_aButtonImageWidgetMaps.begin(),
     318           0 :          aEnd = m_pParserState->m_aButtonImageWidgetMaps.end(); aI != aEnd; ++aI)
     319             :     {
     320           0 :         PushButton *pTargetButton = NULL;
     321           0 :         RadioButton *pTargetRadio = NULL;
     322           0 :         Button *pTarget = NULL;
     323             : 
     324           0 :         if (!aI->m_bRadio)
     325             :         {
     326           0 :             pTargetButton = get<PushButton>(aI->m_sID);
     327           0 :             pTarget = pTargetButton;
     328             :         }
     329             :         else
     330             :         {
     331           0 :             pTargetRadio = get<RadioButton>(aI->m_sID);
     332           0 :             pTarget = pTargetRadio;
     333             :         }
     334             : 
     335           0 :         FixedImage *pImage = get<FixedImage>(aI->m_sValue);
     336             :         SAL_WARN_IF(!pTarget || !pImage,
     337             :             "vcl", "missing elements of button/image/stock");
     338           0 :         if (!pTarget || !pImage)
     339           0 :             continue;
     340           0 :         aImagesToBeRemoved.insert(aI->m_sValue);
     341             : 
     342           0 :         VclBuilder::StockMap::iterator aFind = m_pParserState->m_aStockMap.find(aI->m_sValue);
     343           0 :         if (aFind == m_pParserState->m_aStockMap.end())
     344             :         {
     345           0 :             if (!aI->m_bRadio)
     346           0 :                 pTargetButton->SetModeImage(pImage->GetImage());
     347             :             else
     348           0 :                 pTargetRadio->SetModeRadioImage(pImage->GetImage());
     349             :         }
     350             :         else
     351             :         {
     352           0 :             const stockinfo &rImageInfo = aFind->second;
     353           0 :             SymbolType eType = mapStockToSymbol(rImageInfo.m_sStock);
     354             :             SAL_WARN_IF(eType == SYMBOL_NOSYMBOL, "vcl", "missing stock image element for button");
     355           0 :             if (eType == SYMBOL_NOSYMBOL)
     356           0 :                 continue;
     357           0 :             if (!aI->m_bRadio)
     358           0 :                 pTargetButton->SetSymbol(eType);
     359             :             else
     360             :                 SAL_WARN_IF(eType != SYMBOL_IMAGE, "vcl.layout", "inimplemented symbol type for radiobuttons");
     361           0 :             if (eType == SYMBOL_IMAGE)
     362             :             {
     363           0 :                 Bitmap aBitmap(VclResId(mapStockToImageResource(rImageInfo.m_sStock)));
     364           0 :                 if (!aI->m_bRadio)
     365           0 :                     pTargetButton->SetModeImage(aBitmap);
     366             :                 else
     367           0 :                     pTargetRadio->SetModeRadioImage(aBitmap);
     368             :             }
     369           0 :             switch (rImageInfo.m_nSize)
     370             :             {
     371             :                 case 1:
     372           0 :                     pTarget->SetSmallSymbol();
     373           0 :                     break;
     374             :                 case 4:
     375           0 :                     break;
     376             :                 default:
     377             :                     SAL_WARN("vcl.layout", "unsupported image size " << rImageInfo.m_nSize);
     378           0 :                     break;
     379             :             }
     380             :         }
     381             :     }
     382             : 
     383             :     //There may be duplicate use of an Image, so we used a set to collect and
     384             :     //now we can remove them from the tree after their final munge
     385           0 :     for (std::set<OString>::iterator aI = aImagesToBeRemoved.begin(),
     386           0 :         aEnd = aImagesToBeRemoved.end(); aI != aEnd; ++aI)
     387             :     {
     388           0 :         delete_by_name(*aI);
     389             :     }
     390             : 
     391             :     //Set button menus when everything has been imported
     392           0 :     for (std::vector<ButtonMenuMap>::iterator aI = m_pParserState->m_aButtonMenuMaps.begin(),
     393           0 :          aEnd = m_pParserState->m_aButtonMenuMaps.end(); aI != aEnd; ++aI)
     394             :     {
     395           0 :         MenuButton *pTarget = get<MenuButton>(aI->m_sID);
     396           0 :         PopupMenu *pMenu = get_menu(aI->m_sValue);
     397             :         SAL_WARN_IF(!pTarget || !pMenu,
     398             :             "vcl", "missing elements of button/menu");
     399           0 :         if (!pTarget || !pMenu)
     400           0 :             continue;
     401           0 :         pTarget->SetPopupMenu(pMenu);
     402             :     }
     403             : 
     404             :     //Remove ScrollWindow parent widgets whose children in vcl implement scrolling
     405             :     //internally.
     406           0 :     for (std::map<Window*, Window*>::iterator aI = m_pParserState->m_aRedundantParentWidgets.begin(),
     407           0 :         aEnd = m_pParserState->m_aRedundantParentWidgets.end(); aI != aEnd; ++aI)
     408             :     {
     409           0 :         delete_by_window(aI->first);
     410             :     }
     411             : 
     412             :     //drop maps, etc. that we don't need again
     413           0 :     delete m_pParserState;
     414             : 
     415             :     SAL_WARN_IF(!m_sID.isEmpty() && (!m_bToplevelParentFound && !get_by_name(m_sID)), "vcl.layout",
     416             :         "Requested top level widget \"" << m_sID.getStr() <<
     417           0 :         "\" not found in " << sUIFile);
     418             : 
     419             : #if defined SAL_LOG_WARN
     420             :     if (m_bToplevelParentFound && m_pParent->IsDialog())
     421             :     {
     422             :         int nButtons = 0;
     423             :         bool bHasDefButton = false;
     424             :         for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
     425             :              aEnd = m_aChildren.end(); aI != aEnd; ++aI)
     426             :         {
     427             :             if (isButtonType(aI->m_pWindow->GetType()))
     428             :             {
     429             :                 ++nButtons;
     430             :                 if (aI->m_pWindow->GetStyle() & WB_DEFBUTTON)
     431             :                 {
     432             :                     bHasDefButton = true;
     433             :                     break;
     434             :                 }
     435             :             }
     436             :         }
     437             :         SAL_WARN_IF(nButtons && !bHasDefButton, "vcl.layout", "No default button defined");
     438             :     }
     439             : #endif
     440           0 : }
     441             : 
     442           0 : VclBuilder::~VclBuilder()
     443             : {
     444           0 :     for (std::vector<WinAndId>::reverse_iterator aI = m_aChildren.rbegin(),
     445           0 :          aEnd = m_aChildren.rend(); aI != aEnd; ++aI)
     446             :     {
     447           0 :         delete aI->m_pWindow;
     448             :     }
     449             : 
     450           0 :     for (std::vector<MenuAndId>::reverse_iterator aI = m_aMenus.rbegin(),
     451           0 :          aEnd = m_aMenus.rend(); aI != aEnd; ++aI)
     452             :     {
     453           0 :         delete aI->m_pMenu;
     454             :     }
     455           0 : }
     456             : 
     457           0 : void VclBuilder::handleTranslations(xmlreader::XmlReader &reader)
     458             : {
     459           0 :     xmlreader::Span name;
     460             :     int nsId;
     461             : 
     462           0 :     OString sID, sProperty;
     463             : 
     464             :     while(1)
     465             :     {
     466             :         xmlreader::XmlReader::Result res = reader.nextItem(
     467           0 :             xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
     468             : 
     469           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
     470             :         {
     471           0 :             if (name.equals("e"))
     472             :             {
     473           0 :                 while (reader.nextAttribute(&nsId, &name))
     474             :                 {
     475           0 :                     if (name.equals("g"))
     476             :                     {
     477           0 :                         name = reader.getAttributeValue(false);
     478           0 :                         sID = OString(name.begin, name.length);
     479           0 :                         sal_Int32 nDelim = sID.indexOf(':');
     480           0 :                         if (nDelim != -1)
     481           0 :                             sID = sID.copy(nDelim);
     482             :                     }
     483           0 :                     else if (name.equals("i"))
     484             :                     {
     485           0 :                         name = reader.getAttributeValue(false);
     486           0 :                         sProperty = OString(name.begin, name.length);
     487             :                     }
     488             :                 }
     489             :             }
     490             :         }
     491             : 
     492           0 :         if (res == xmlreader::XmlReader::RESULT_TEXT && !sID.isEmpty())
     493             :         {
     494           0 :             OString sTranslation(name.begin, name.length);
     495           0 :             m_pParserState->m_aTranslations[sID][sProperty] = sTranslation;
     496             :         }
     497             : 
     498           0 :         if (res == xmlreader::XmlReader::RESULT_END)
     499           0 :             sID = OString();
     500             : 
     501           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
     502           0 :             break;
     503           0 :     }
     504           0 : }
     505             : 
     506           0 : OString VclBuilder::extractCustomProperty(VclBuilder::stringmap &rMap)
     507             : {
     508           0 :     OString sCustomProperty;
     509           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("customproperty"));
     510           0 :     if (aFind != rMap.end())
     511             :     {
     512           0 :         sCustomProperty = aFind->second;
     513           0 :         rMap.erase(aFind);
     514             :     }
     515           0 :     return sCustomProperty;
     516             : }
     517             : 
     518             : namespace
     519             : {
     520           0 :     bool extractResizable(VclBuilder::stringmap &rMap)
     521             :     {
     522           0 :         bool bResizable = true;
     523           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("resizable"));
     524           0 :         if (aFind != rMap.end())
     525             :         {
     526           0 :             bResizable = toBool(aFind->second);
     527           0 :             rMap.erase(aFind);
     528             :         }
     529           0 :         return bResizable;
     530             :     }
     531             : 
     532           0 :     bool extractEntry(VclBuilder::stringmap &rMap)
     533             :     {
     534           0 :         bool bHasEntry = false;
     535           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("has-entry"));
     536           0 :         if (aFind != rMap.end())
     537             :         {
     538           0 :             bHasEntry = toBool(aFind->second);
     539           0 :             rMap.erase(aFind);
     540             :         }
     541           0 :         return bHasEntry;
     542             :     }
     543             : 
     544           0 :     bool extractOrientation(VclBuilder::stringmap &rMap)
     545             :     {
     546           0 :         bool bVertical = false;
     547           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("orientation"));
     548           0 :         if (aFind != rMap.end())
     549             :         {
     550           0 :             bVertical = aFind->second.equalsIgnoreAsciiCase("vertical");
     551           0 :             rMap.erase(aFind);
     552             :         }
     553           0 :         return bVertical;
     554             :     }
     555             : 
     556           0 :     bool extractInconsistent(VclBuilder::stringmap &rMap)
     557             :     {
     558           0 :         bool bInconsistent = false;
     559           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("inconsistent"));
     560           0 :         if (aFind != rMap.end())
     561             :         {
     562           0 :             bInconsistent = toBool(aFind->second);
     563           0 :             rMap.erase(aFind);
     564             :         }
     565           0 :         return bInconsistent;
     566             :     }
     567             : 
     568           0 :     OUString getStockText(const OString &rType)
     569             :     {
     570           0 :         if (rType == "gtk-ok")
     571           0 :             return (VclResId(SV_BUTTONTEXT_OK).toString());
     572           0 :         else if (rType == "gtk-cancel")
     573           0 :             return (VclResId(SV_BUTTONTEXT_CANCEL).toString());
     574           0 :         else if (rType == "gtk-help")
     575           0 :             return (VclResId(SV_BUTTONTEXT_HELP).toString());
     576           0 :         else if (rType == "gtk-close")
     577           0 :             return (VclResId(SV_BUTTONTEXT_CLOSE).toString());
     578           0 :         else if (rType == "gtk-revert-to-saved")
     579           0 :             return (VclResId(SV_BUTTONTEXT_RESET).toString());
     580           0 :         else if (rType == "gtk-add")
     581           0 :             return (VclResId(SV_BUTTONTEXT_ADD).toString());
     582           0 :         else if (rType == "gtk-delete")
     583           0 :             return (VclResId(SV_BUTTONTEXT_DELETE).toString());
     584           0 :         else if (rType == "gtk-remove")
     585           0 :             return (VclResId(SV_BUTTONTEXT_REMOVE).toString());
     586           0 :         else if (rType == "gtk-new")
     587           0 :             return (VclResId(SV_BUTTONTEXT_NEW).toString());
     588           0 :         else if (rType == "gtk-edit")
     589           0 :             return (VclResId(SV_BUTTONTEXT_EDIT).toString());
     590           0 :         else if (rType == "gtk-apply")
     591           0 :             return (VclResId(SV_BUTTONTEXT_APPLY).toString());
     592           0 :         else if (rType == "gtk-save")
     593           0 :             return (VclResId(SV_BUTTONTEXT_SAVE).toString());
     594           0 :         else if (rType == "gtk-undo")
     595           0 :             return (VclResId(SV_BUTTONTEXT_UNDO).toString());
     596           0 :         else if (rType == "gtk-paste")
     597           0 :             return (VclResId(SV_BUTTONTEXT_PASTE).toString());
     598           0 :         else if (rType == "gtk-media-next")
     599           0 :             return (VclResId(SV_BUTTONTEXT_NEXT).toString());
     600           0 :         else if (rType == "gtk-go-up")
     601           0 :             return (VclResId(SV_BUTTONTEXT_GO_UP).toString());
     602           0 :         else if (rType == "gtk-go-down")
     603           0 :             return (VclResId(SV_BUTTONTEXT_GO_DOWN).toString());
     604           0 :         else if (rType == "gtk-clear")
     605           0 :             return (VclResId(SV_BUTTONTEXT_CLEAR).toString());
     606             :         SAL_WARN("vcl.layout", "unknown stock type: " << rType.getStr());
     607           0 :         return OUString();
     608             :     }
     609             : 
     610           0 :     bool extractStock(VclBuilder::stringmap &rMap)
     611             :     {
     612           0 :         bool bIsStock = false;
     613           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("use-stock"));
     614           0 :         if (aFind != rMap.end())
     615             :         {
     616           0 :             bIsStock = toBool(aFind->second);
     617           0 :             rMap.erase(aFind);
     618             :         }
     619           0 :         return bIsStock;
     620             :     }
     621             : 
     622           0 :     WinBits extractRelief(VclBuilder::stringmap &rMap)
     623             :     {
     624           0 :         WinBits nBits = WB_3DLOOK;
     625           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("relief"));
     626           0 :         if (aFind != rMap.end())
     627             :         {
     628           0 :             if (aFind->second == "half")
     629           0 :                 nBits = WB_FLATBUTTON | WB_BEVELBUTTON;
     630           0 :             else if (aFind->second == "none")
     631           0 :                 nBits = WB_FLATBUTTON;
     632           0 :             rMap.erase(aFind);
     633             :         }
     634           0 :         return nBits;
     635             :     }
     636             : 
     637           0 :     OString extractLabel(VclBuilder::stringmap &rMap)
     638             :     {
     639           0 :         OString sType;
     640           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("label"));
     641           0 :         if (aFind != rMap.end())
     642             :         {
     643           0 :             sType = aFind->second;
     644           0 :             rMap.erase(aFind);
     645             :         }
     646           0 :         return sType;
     647             :     }
     648             : 
     649           0 :     OString extractActionName(VclBuilder::stringmap &rMap)
     650             :     {
     651           0 :         OString sActionName;
     652           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("action-name"));
     653           0 :         if (aFind != rMap.end())
     654             :         {
     655           0 :             sActionName = aFind->second;
     656           0 :             rMap.erase(aFind);
     657             :         }
     658           0 :         return sActionName;
     659             :     }
     660             : 
     661           0 :     Size extractSizeRequest(VclBuilder::stringmap &rMap)
     662             :     {
     663           0 :         OString sWidthRequest("0");
     664           0 :         OString sHeightRequest("0");
     665           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("width-request"));
     666           0 :         if (aFind != rMap.end())
     667             :         {
     668           0 :             sWidthRequest = aFind->second;
     669           0 :             rMap.erase(aFind);
     670             :         }
     671           0 :         aFind = rMap.find(OString("height-request"));
     672           0 :         if (aFind != rMap.end())
     673             :         {
     674           0 :             sHeightRequest = aFind->second;
     675           0 :             rMap.erase(aFind);
     676             :         }
     677           0 :         return Size(sWidthRequest.toInt32(), sHeightRequest.toInt32());
     678             :     }
     679             : 
     680           0 :     OString extractTooltipText(VclBuilder::stringmap &rMap)
     681             :     {
     682           0 :         OString sTooltipText;
     683           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("tooltip-text"));
     684           0 :         if (aFind == rMap.end())
     685           0 :             aFind = rMap.find(OString("tooltip-markup"));
     686           0 :         if (aFind != rMap.end())
     687             :         {
     688           0 :             sTooltipText = aFind->second;
     689           0 :             rMap.erase(aFind);
     690             :         }
     691           0 :         return sTooltipText;
     692             :     }
     693             : 
     694           0 :     Button* extractStockAndBuildPushButton(Window *pParent, VclBuilder::stringmap &rMap)
     695             :     {
     696           0 :         WinBits nBits = WB_CENTER|WB_VCENTER;
     697             : 
     698           0 :         nBits |= extractRelief(rMap);
     699             : 
     700           0 :         bool bIsStock = extractStock(rMap);
     701             : 
     702           0 :         Button *pWindow = NULL;
     703             : 
     704           0 :         if (bIsStock)
     705             :         {
     706           0 :             OString sType = extractLabel(rMap);
     707           0 :             if (sType == "gtk-ok")
     708           0 :                 pWindow = new OKButton(pParent, nBits);
     709           0 :             else if (sType == "gtk-cancel")
     710           0 :                 pWindow = new CancelButton(pParent, nBits);
     711           0 :             else if (sType == "gtk-close")
     712           0 :                 pWindow = new CloseButton(pParent, nBits);
     713           0 :             else if (sType == "gtk-help")
     714           0 :                 pWindow = new HelpButton(pParent, nBits);
     715             :             else
     716             :             {
     717           0 :                 pWindow = new PushButton(pParent, nBits);
     718           0 :                 pWindow->SetText(getStockText(sType));
     719           0 :             }
     720             :         }
     721             : 
     722           0 :         if (!pWindow)
     723           0 :             pWindow = new PushButton(pParent, nBits);
     724           0 :         return pWindow;
     725             :     }
     726             : 
     727           0 :     Button * extractStockAndBuildMenuButton(Window *pParent, VclBuilder::stringmap &rMap)
     728             :     {
     729           0 :         WinBits nBits = WB_CENTER|WB_VCENTER|WB_3DLOOK;
     730             : 
     731           0 :         Button *pWindow = new MenuButton(pParent, nBits);
     732             : 
     733           0 :         if (extractStock(rMap))
     734             :         {
     735           0 :             pWindow->SetText(getStockText(extractLabel(rMap)));
     736             :         }
     737             : 
     738           0 :         return pWindow;
     739             :     }
     740             : 
     741           0 :     OString extractUnit(const OString& sPattern)
     742             :     {
     743           0 :         OString sUnit(sPattern);
     744           0 :         for (sal_Int32 i = 0; i < sPattern.getLength(); ++i)
     745             :         {
     746           0 :             if (sPattern[i] != '.' && sPattern[i] != ',' && sPattern[i] != '0')
     747             :             {
     748           0 :                 sUnit = sPattern.copy(i);
     749           0 :                 break;
     750             :             }
     751             :         }
     752           0 :         return sUnit;
     753             :     }
     754             : 
     755           0 :     FieldUnit detectMetricUnit(OString sUnit)
     756             :     {
     757           0 :         FieldUnit eUnit = FUNIT_NONE;
     758             : 
     759           0 :         if (sUnit == "mm")
     760           0 :             eUnit = FUNIT_MM;
     761           0 :         else if (sUnit == "cm")
     762           0 :             eUnit = FUNIT_CM;
     763           0 :         else if (sUnit == "m")
     764           0 :             eUnit = FUNIT_M;
     765           0 :         else if (sUnit == "km")
     766           0 :             eUnit = FUNIT_KM;
     767           0 :         else if ((sUnit == "twips") || (sUnit == "twip"))
     768           0 :             eUnit = FUNIT_TWIP;
     769           0 :         else if (sUnit == "pt")
     770           0 :             eUnit = FUNIT_POINT;
     771           0 :         else if (sUnit == "pc")
     772           0 :             eUnit = FUNIT_PICA;
     773           0 :         else if (sUnit == "\"" || (sUnit == "in") || (sUnit == "inch"))
     774           0 :             eUnit = FUNIT_INCH;
     775           0 :         else if ((sUnit == "'") || (sUnit == "ft") || (sUnit == "foot") || (sUnit == "feet"))
     776           0 :             eUnit = FUNIT_FOOT;
     777           0 :         else if (sUnit == "mile" || (sUnit == "miles"))
     778           0 :             eUnit = FUNIT_MILE;
     779           0 :         else if (sUnit == "ch")
     780           0 :             eUnit = FUNIT_CHAR;
     781           0 :         else if (sUnit == "line")
     782           0 :             eUnit = FUNIT_LINE;
     783           0 :         else if (sUnit == "%")
     784           0 :             eUnit = FUNIT_PERCENT;
     785           0 :         else if (sUnit != "0")
     786           0 :             eUnit = FUNIT_CUSTOM;
     787             : 
     788           0 :         return eUnit;
     789             :     }
     790             : }
     791             : 
     792           0 : void VclBuilder::ensureDefaultWidthChars(VclBuilder::stringmap &rMap)
     793             : {
     794           0 :     OString sWidthChars("width-chars");
     795           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(sWidthChars);
     796           0 :     if (aFind == rMap.end())
     797           0 :         rMap[sWidthChars] = "25";
     798           0 : }
     799             : 
     800           0 : bool VclBuilder::extractGroup(const OString &id, stringmap &rMap)
     801             : {
     802           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("group"));
     803           0 :     if (aFind != rMap.end())
     804             :     {
     805           0 :         OString sID = aFind->second;
     806           0 :         sal_Int32 nDelim = sID.indexOf(':');
     807           0 :         if (nDelim != -1)
     808           0 :             sID = sID.copy(0, nDelim);
     809           0 :         m_pParserState->m_aGroupMaps.push_back(RadioButtonGroupMap(id, sID));
     810           0 :         rMap.erase(aFind);
     811           0 :         return true;
     812             :     }
     813           0 :     return false;
     814             : }
     815             : 
     816           0 : void VclBuilder::connectNumericFormatterAdjustment(const OString &id, const OString &rAdjustment)
     817             : {
     818           0 :     if (!rAdjustment.isEmpty())
     819           0 :         m_pParserState->m_aNumericFormatterAdjustmentMaps.push_back(WidgetAdjustmentMap(id, rAdjustment));
     820           0 : }
     821             : 
     822           0 : void VclBuilder::connectTimeFormatterAdjustment(const OString &id, const OString &rAdjustment)
     823             : {
     824           0 :     if (!rAdjustment.isEmpty())
     825           0 :         m_pParserState->m_aTimeFormatterAdjustmentMaps.push_back(WidgetAdjustmentMap(id, rAdjustment));
     826           0 : }
     827             : 
     828           0 : void VclBuilder::connectDateFormatterAdjustment(const OString &id, const OString &rAdjustment)
     829             : {
     830           0 :     if (!rAdjustment.isEmpty())
     831           0 :         m_pParserState->m_aDateFormatterAdjustmentMaps.push_back(WidgetAdjustmentMap(id, rAdjustment));
     832           0 : }
     833             : 
     834           0 : bool VclBuilder::extractScrollAdjustment(const OString &id, VclBuilder::stringmap &rMap)
     835             : {
     836           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment"));
     837           0 :     if (aFind != rMap.end())
     838             :     {
     839           0 :         m_pParserState->m_aScrollAdjustmentMaps.push_back(WidgetAdjustmentMap(id, aFind->second));
     840           0 :         rMap.erase(aFind);
     841           0 :         return true;
     842             :     }
     843           0 :     return false;
     844             : }
     845             : 
     846             : namespace
     847             : {
     848           0 :     sal_Int32 extractActive(VclBuilder::stringmap &rMap)
     849             :     {
     850           0 :         sal_Int32 nActiveId = 0;
     851           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("active"));
     852           0 :         if (aFind != rMap.end())
     853             :         {
     854           0 :             nActiveId = aFind->second.toInt32();
     855           0 :             rMap.erase(aFind);
     856             :         }
     857           0 :         return nActiveId;
     858             :     }
     859             : 
     860           0 :     bool extractSelectable(VclBuilder::stringmap &rMap)
     861             :     {
     862           0 :         bool bSelectable = false;
     863           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("selectable"));
     864           0 :         if (aFind != rMap.end())
     865             :         {
     866           0 :             bSelectable = toBool(aFind->second);
     867           0 :             rMap.erase(aFind);
     868             :         }
     869           0 :         return bSelectable;
     870             :     }
     871             : 
     872           0 :     OString extractAdjustment(VclBuilder::stringmap &rMap)
     873             :     {
     874           0 :         OString sAdjustment;
     875           0 :         VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment"));
     876           0 :         if (aFind != rMap.end())
     877             :         {
     878           0 :             sAdjustment= aFind->second;
     879           0 :             rMap.erase(aFind);
     880           0 :             return sAdjustment;
     881             :         }
     882           0 :         return sAdjustment;
     883             :     }
     884             : }
     885             : 
     886           0 : bool VclBuilder::extractModel(const OString &id, stringmap &rMap)
     887             : {
     888           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("model"));
     889           0 :     if (aFind != rMap.end())
     890             :     {
     891           0 :         m_pParserState->m_aModelMaps.push_back(ComboBoxModelMap(id, aFind->second,
     892           0 :             extractActive(rMap)));
     893           0 :         rMap.erase(aFind);
     894           0 :         return true;
     895             :     }
     896           0 :     return false;
     897             : }
     898             : 
     899           0 : bool VclBuilder::extractDropdown(VclBuilder::stringmap &rMap)
     900             : {
     901           0 :     bool bDropdown = true;
     902           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("dropdown"));
     903           0 :     if (aFind != rMap.end())
     904             :     {
     905           0 :         bDropdown = toBool(aFind->second);
     906           0 :         rMap.erase(aFind);
     907             :     }
     908           0 :     return bDropdown;
     909             : }
     910             : 
     911           0 : bool VclBuilder::extractBuffer(const OString &id, stringmap &rMap)
     912             : {
     913           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("buffer"));
     914           0 :     if (aFind != rMap.end())
     915             :     {
     916           0 :         m_pParserState->m_aTextBufferMaps.push_back(TextBufferMap(id, aFind->second));
     917           0 :         rMap.erase(aFind);
     918           0 :         return true;
     919             :     }
     920           0 :     return false;
     921             : }
     922             : 
     923           0 : bool VclBuilder::extractStock(const OString &id, stringmap &rMap)
     924             : {
     925           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("stock"));
     926           0 :     if (aFind != rMap.end())
     927             :     {
     928           0 :         stockinfo aInfo;
     929           0 :         aInfo.m_sStock = aFind->second;
     930           0 :         rMap.erase(aFind);
     931           0 :         aFind = rMap.find(OString("icon-size"));
     932           0 :         if (aFind != rMap.end())
     933             :         {
     934           0 :             aInfo.m_nSize = aFind->second.toInt32();
     935           0 :             rMap.erase(aFind);
     936             :         }
     937           0 :         m_pParserState->m_aStockMap[id] = aInfo;
     938           0 :         return true;
     939             :     }
     940           0 :     return false;
     941             : }
     942             : 
     943           0 : bool VclBuilder::extractButtonImage(const OString &id, stringmap &rMap, bool bRadio)
     944             : {
     945           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("image"));
     946           0 :     if (aFind != rMap.end())
     947             :     {
     948           0 :         m_pParserState->m_aButtonImageWidgetMaps.push_back(ButtonImageWidgetMap(id, aFind->second, bRadio));
     949           0 :         rMap.erase(aFind);
     950           0 :         return true;
     951             :     }
     952           0 :     return false;
     953             : }
     954             : 
     955           0 : void VclBuilder::extractMnemonicWidget(const OString &rLabelID, stringmap &rMap)
     956             : {
     957           0 :     VclBuilder::stringmap::iterator aFind = rMap.find(OString("mnemonic-widget"));
     958           0 :     if (aFind != rMap.end())
     959             :     {
     960           0 :         OString sID = aFind->second;
     961           0 :         sal_Int32 nDelim = sID.indexOf(':');
     962           0 :         if (nDelim != -1)
     963           0 :             sID = sID.copy(0, nDelim);
     964           0 :         m_pParserState->m_aMnemonicWidgetMaps.push_back(MnemonicWidgetMap(rLabelID, sID));
     965           0 :         rMap.erase(aFind);
     966             :     }
     967           0 : }
     968             : 
     969           0 : Window* VclBuilder::prepareWidgetOwnScrolling(Window *pParent, WinBits &rWinStyle)
     970             : {
     971             :     //For Widgets that manage their own scrolling, if one appears as a child of
     972             :     //a scrolling window shoehorn that scrolling settings to this widget and
     973             :     //return the real parent to use
     974           0 :     if (pParent && pParent->GetType() == WINDOW_SCROLLWINDOW)
     975             :     {
     976           0 :         WinBits nScrollBits = pParent->GetStyle();
     977           0 :         nScrollBits &= (WB_AUTOHSCROLL|WB_HSCROLL|WB_AUTOVSCROLL|WB_VSCROLL);
     978           0 :         rWinStyle |= nScrollBits;
     979           0 :         pParent = pParent->GetParent();
     980             :     }
     981             : 
     982           0 :     return pParent;
     983             : }
     984             : 
     985           0 : void VclBuilder::cleanupWidgetOwnScrolling(Window *pScrollParent, Window *pWindow, stringmap &rMap)
     986             : {
     987             :     //remove the redundant scrolling parent
     988           0 :     sal_Int32 nWidthReq = pScrollParent->get_width_request();
     989           0 :     rMap[OString("width-request")] = OString::valueOf(nWidthReq);
     990           0 :     sal_Int32 nHeightReq = pScrollParent->get_height_request();
     991           0 :     rMap[OString("height-request")] = OString::valueOf(nHeightReq);
     992             : 
     993           0 :     m_pParserState->m_aRedundantParentWidgets[pScrollParent] = pWindow;
     994           0 : }
     995             : 
     996             : #ifndef DISABLE_DYNLOADING
     997           0 : extern "C" { static void SAL_CALL thisModule() {} }
     998             : #endif
     999             : 
    1000           0 : Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OString &id,
    1001             :     stringmap &rMap, const std::vector<OString> &rItems)
    1002             : {
    1003           0 :     bool bIsPlaceHolder = name.isEmpty();
    1004           0 :     bool bVertical = false;
    1005             : 
    1006           0 :     if (pParent && pParent->GetType() == WINDOW_TABCONTROL)
    1007             :     {
    1008             :         //We have to add a page
    1009             : 
    1010             :         //make default pageid == position
    1011           0 :         TabControl *pTabControl = static_cast<TabControl*>(pParent);
    1012           0 :         sal_uInt16 nNewPageCount = pTabControl->GetPageCount()+1;
    1013           0 :         sal_uInt16 nNewPageId = nNewPageCount;
    1014           0 :         pTabControl->InsertPage(nNewPageId, OUString());
    1015           0 :         pTabControl->SetCurPageId(nNewPageId);
    1016             : 
    1017           0 :         if (!bIsPlaceHolder)
    1018             :         {
    1019           0 :             TabPage* pPage = new TabPage(pTabControl);
    1020           0 :             pPage->Show();
    1021             : 
    1022             :             //Make up a name for it
    1023           0 :             OString sTabPageId = get_by_window(pParent) +
    1024           0 :                 OString("-page") +
    1025           0 :                 OString::number(nNewPageCount);
    1026           0 :             m_aChildren.push_back(WinAndId(sTabPageId, pPage, false));
    1027           0 :             pPage->SetHelpId(m_sHelpRoot + sTabPageId);
    1028             : 
    1029             :             //And give the page one container as a child to make it a layout enabled
    1030             :             //tab page
    1031           0 :             VclBin* pContainer = new VclBin(pPage);
    1032           0 :             pContainer->Show();
    1033           0 :             m_aChildren.push_back(WinAndId(OString(), pContainer, false));
    1034           0 :             pContainer->SetHelpId(m_sHelpRoot + sTabPageId + OString("-bin"));
    1035           0 :             pParent = pContainer;
    1036             : 
    1037           0 :             pTabControl->SetTabPage(nNewPageId, pPage);
    1038             :         }
    1039             :     }
    1040             : 
    1041           0 :     if (bIsPlaceHolder || name == "GtkTreeSelection")
    1042           0 :         return NULL;
    1043             : 
    1044           0 :     extractButtonImage(id, rMap, name == "GtkRadioButton");
    1045             : 
    1046           0 :     Window *pWindow = NULL;
    1047           0 :     if (name == "GtkDialog")
    1048             :     {
    1049           0 :         WinBits nBits = WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE;
    1050           0 :         if (extractResizable(rMap))
    1051           0 :             nBits |= WB_SIZEABLE;
    1052           0 :         pWindow = new Dialog(pParent, nBits);
    1053             :     }
    1054           0 :     else if (name == "GtkMessageDialog")
    1055             :     {
    1056           0 :         WinBits nBits = WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE;
    1057           0 :         if (extractResizable(rMap))
    1058           0 :             nBits |= WB_SIZEABLE;
    1059           0 :         pWindow = new MessageDialog(pParent, nBits);
    1060             :     }
    1061           0 :     else if (name == "GtkBox")
    1062             :     {
    1063           0 :         bVertical = extractOrientation(rMap);
    1064           0 :         if (bVertical)
    1065           0 :             pWindow = new VclVBox(pParent);
    1066             :         else
    1067           0 :             pWindow = new VclHBox(pParent);
    1068             :     }
    1069           0 :     else if (name == "GtkHBox")
    1070           0 :         pWindow = new VclHBox(pParent);
    1071           0 :     else if (name == "GtkVBox")
    1072           0 :         pWindow = new VclVBox(pParent);
    1073           0 :     else if (name == "GtkButtonBox")
    1074             :     {
    1075           0 :         bVertical = extractOrientation(rMap);
    1076           0 :         if (bVertical)
    1077           0 :             pWindow = new VclVButtonBox(pParent);
    1078             :         else
    1079           0 :             pWindow = new VclHButtonBox(pParent);
    1080             :     }
    1081           0 :     else if (name == "GtkHButtonBox")
    1082           0 :         pWindow = new VclHButtonBox(pParent);
    1083           0 :     else if (name == "GtkVButtonBox")
    1084           0 :         pWindow = new VclVButtonBox(pParent);
    1085           0 :     else if (name == "GtkGrid")
    1086           0 :         pWindow = new VclGrid(pParent);
    1087           0 :     else if (name == "GtkFrame")
    1088           0 :         pWindow = new VclFrame(pParent);
    1089           0 :     else if (name == "GtkExpander")
    1090           0 :         pWindow = new VclExpander(pParent);
    1091           0 :     else if (name == "GtkAlignment")
    1092           0 :         pWindow = new VclAlignment(pParent);
    1093           0 :     else if (name == "GtkButton")
    1094             :     {
    1095             :         Button *pButton;
    1096           0 :         OString sMenu = extractCustomProperty(rMap);
    1097           0 :         if (sMenu.isEmpty())
    1098           0 :             pButton = extractStockAndBuildPushButton(pParent, rMap);
    1099             :         else
    1100             :         {
    1101           0 :             pButton = extractStockAndBuildMenuButton(pParent, rMap);
    1102           0 :             m_pParserState->m_aButtonMenuMaps.push_back(ButtonMenuMap(id, sMenu));
    1103             :         }
    1104           0 :         pButton->SetImageAlign(IMAGEALIGN_LEFT); //default to left
    1105           0 :         pWindow = pButton;
    1106             :     }
    1107           0 :     else if (name == "GtkRadioButton")
    1108             :     {
    1109           0 :         extractGroup(id, rMap);
    1110           0 :         WinBits nBits = WB_CENTER|WB_VCENTER|WB_3DLOOK;
    1111           0 :         OString sWrap = extractCustomProperty(rMap);
    1112           0 :         if (!sWrap.isEmpty())
    1113           0 :             nBits |= WB_WORDBREAK;
    1114           0 :         pWindow = new RadioButton(pParent, nBits);
    1115             :     }
    1116           0 :     else if (name == "GtkCheckButton")
    1117             :     {
    1118           0 :         WinBits nBits = WB_CENTER|WB_VCENTER|WB_3DLOOK;
    1119           0 :         OString sWrap = extractCustomProperty(rMap);
    1120           0 :         if (!sWrap.isEmpty())
    1121           0 :             nBits |= WB_WORDBREAK;
    1122             :         //maybe always import as TriStateBox and enable/disable tristate
    1123           0 :         bool bIsTriState = extractInconsistent(rMap);
    1124             :         CheckBox *pCheckBox = bIsTriState ?
    1125           0 :             new TriStateBox(pParent, nBits) :
    1126           0 :             new CheckBox(pParent, nBits);
    1127           0 :         if (bIsTriState)
    1128           0 :             pCheckBox->SetState(STATE_DONTKNOW);
    1129           0 :         pWindow = pCheckBox;
    1130             :     }
    1131           0 :     else if (name == "GtkSpinButton")
    1132             :     {
    1133           0 :         OString sAdjustment = extractAdjustment(rMap);
    1134           0 :         OString sPattern = extractCustomProperty(rMap);
    1135           0 :         OString sUnit = extractUnit(sPattern);
    1136             : 
    1137           0 :         WinBits nBits = WB_LEFT|WB_BORDER|WB_3DLOOK;
    1138           0 :         if (!id.endsWith("-nospin"))
    1139           0 :             nBits |= WB_SPIN;
    1140             : 
    1141           0 :         if (sPattern.isEmpty())
    1142             :         {
    1143           0 :             connectNumericFormatterAdjustment(id, sAdjustment);
    1144             :             SAL_INFO("vcl.layout", "making numeric field for " << name.getStr() << " " << sUnit.getStr());
    1145           0 :             pWindow = new NumericField(pParent, nBits);
    1146             :         }
    1147             :         else
    1148             :         {
    1149           0 :             if (sPattern == "hh:mm")
    1150             :             {
    1151           0 :                 connectTimeFormatterAdjustment(id, sAdjustment);
    1152             :                 SAL_INFO("vcl.layout", "making time field for " << name.getStr() << " " << sUnit.getStr());
    1153           0 :                 TimeField *pField = new TimeField(pParent, nBits);
    1154           0 :                 pWindow = pField;
    1155             :             }
    1156           0 :             else if (sPattern == "yy:mm:dd")
    1157             :             {
    1158           0 :                 connectDateFormatterAdjustment(id, sAdjustment);
    1159             :                 SAL_INFO("vcl.layout", "making date field for " << name.getStr() << " " << sUnit.getStr());
    1160           0 :                 DateField *pField = new DateField(pParent, nBits);
    1161           0 :                 pWindow = pField;
    1162             :             }
    1163             :             else
    1164             :             {
    1165           0 :                 connectNumericFormatterAdjustment(id, sAdjustment);
    1166           0 :                 FieldUnit eUnit = detectMetricUnit(sUnit);
    1167             :                 SAL_INFO("vcl.layout", "making metric field for " << name.getStr() << " " << sUnit.getStr());
    1168           0 :                 MetricField *pField = new MetricField(pParent, nBits);
    1169           0 :                 pField->SetUnit(eUnit);
    1170           0 :                 if (eUnit == FUNIT_CUSTOM)
    1171           0 :                     pField->SetCustomUnitText(OStringToOUString(sUnit, RTL_TEXTENCODING_UTF8));
    1172           0 :                 pWindow = pField;
    1173             :             }
    1174           0 :         }
    1175             :     }
    1176           0 :     else if (name == "GtkLinkButton")
    1177           0 :         pWindow = new FixedHyperlink(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK|WB_NOLABEL);
    1178           0 :     else if ((name == "GtkComboBox") || (name == "GtkComboBoxText") || (name == "VclComboBoxText"))
    1179             :     {
    1180           0 :         OString sPattern = extractCustomProperty(rMap);
    1181           0 :         extractModel(id, rMap);
    1182             : 
    1183           0 :         WinBits nBits = WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_DROPDOWN;
    1184             : 
    1185           0 :         if (!sPattern.isEmpty())
    1186             :         {
    1187           0 :             OString sAdjustment = extractAdjustment(rMap);
    1188           0 :             connectNumericFormatterAdjustment(id, sAdjustment);
    1189           0 :             OString sUnit = extractUnit(sPattern);
    1190           0 :             FieldUnit eUnit = detectMetricUnit(sUnit);
    1191             :             SAL_WARN("vcl.layout", "making metric box for " << name.getStr() << " " << sUnit.getStr()
    1192             :                 << " use a VclComboBoxNumeric instead");
    1193           0 :             MetricBox *pBox = new MetricBox(pParent, nBits);
    1194           0 :             pBox->EnableAutoSize(true);
    1195           0 :             pBox->SetUnit(eUnit);
    1196           0 :             if (eUnit == FUNIT_CUSTOM)
    1197           0 :                 pBox->SetCustomUnitText(OStringToOUString(sUnit, RTL_TEXTENCODING_UTF8));
    1198           0 :             pWindow = pBox;
    1199             :         }
    1200           0 :         else if (extractEntry(rMap))
    1201             :         {
    1202           0 :             ComboBox* pComboBox = new ComboBox(pParent, nBits);
    1203           0 :             pComboBox->EnableAutoSize(true);
    1204           0 :             if (!rItems.empty())
    1205             :             {
    1206           0 :                 sal_uInt16 nActiveId = extractActive(rMap);
    1207           0 :                 for (std::vector<OString>::const_iterator aI = rItems.begin(), aEnd = rItems.end(); aI != aEnd; ++aI)
    1208           0 :                     pComboBox->InsertEntry(OStringToOUString(*aI, RTL_TEXTENCODING_UTF8));
    1209           0 :                 if (nActiveId < rItems.size())
    1210           0 :                     pComboBox->SelectEntryPos(nActiveId);
    1211             :             }
    1212           0 :             pWindow = pComboBox;
    1213             :         }
    1214             :         else
    1215             :         {
    1216           0 :             ListBox *pListBox = new ListBox(pParent, nBits|WB_SIMPLEMODE);
    1217           0 :             pListBox->EnableAutoSize(true);
    1218           0 :             if (!rItems.empty())
    1219             :             {
    1220           0 :                 sal_uInt16 nActiveId = extractActive(rMap);
    1221           0 :                 for (std::vector<OString>::const_iterator aI = rItems.begin(), aEnd = rItems.end(); aI != aEnd; ++aI)
    1222           0 :                     pListBox->InsertEntry(OStringToOUString(*aI, RTL_TEXTENCODING_UTF8));
    1223           0 :                 if (nActiveId < rItems.size())
    1224           0 :                     pListBox->SelectEntryPos(nActiveId);
    1225             :             }
    1226           0 :             pWindow = pListBox;
    1227           0 :         }
    1228             :     }
    1229           0 :     else if (name == "VclComboBoxNumeric")
    1230             :     {
    1231           0 :         OString sPattern = extractCustomProperty(rMap);
    1232           0 :         OString sAdjustment = extractAdjustment(rMap);
    1233           0 :         extractModel(id, rMap);
    1234             : 
    1235           0 :         WinBits nBits = WB_LEFT|WB_VCENTER|WB_3DLOOK;
    1236             : 
    1237           0 :         bool bDropdown = VclBuilder::extractDropdown(rMap);
    1238             : 
    1239           0 :         if (bDropdown)
    1240           0 :             nBits |= WB_DROPDOWN;
    1241             : 
    1242           0 :         if (!sPattern.isEmpty())
    1243             :         {
    1244           0 :             OString sUnit = extractUnit(sPattern);
    1245           0 :             FieldUnit eUnit = detectMetricUnit(sUnit);
    1246             :             SAL_INFO("vcl.layout", "making metric box for " << name.getStr() << " " << sUnit.getStr());
    1247           0 :             connectNumericFormatterAdjustment(id, sAdjustment);
    1248           0 :             MetricBox *pBox = new MetricBox(pParent, nBits|WB_BORDER);
    1249           0 :             if (bDropdown)
    1250           0 :                 pBox->EnableAutoSize(true);
    1251           0 :             pBox->SetUnit(eUnit);
    1252           0 :             if (eUnit == FUNIT_CUSTOM)
    1253           0 :                 pBox->SetCustomUnitText(OStringToOUString(sUnit, RTL_TEXTENCODING_UTF8));
    1254           0 :             pWindow = pBox;
    1255             :         }
    1256             :         else
    1257             :         {
    1258             :             SAL_INFO("vcl.layout", "making numeric box for " << name.getStr());
    1259           0 :             connectNumericFormatterAdjustment(id, sAdjustment);
    1260           0 :             NumericBox* pBox = new NumericBox(pParent, nBits);
    1261           0 :             if (bDropdown)
    1262           0 :                 pBox->EnableAutoSize(true);
    1263           0 :             pWindow = pBox;
    1264           0 :         }
    1265             :     }
    1266           0 :     else if (name == "GtkTreeView")
    1267             :     {
    1268             :         //To-Do
    1269             :         //a) move svtools SvTreeViewBox into vcl
    1270             :         //b) make that the default target for GtkTreeView
    1271             :         //c) remove the non-drop down mode of ListBox and convert
    1272             :         //   everything over to SvTreeViewBox
    1273             :         //d) remove the users of makeSvTreeViewBox
    1274           0 :         extractModel(id, rMap);
    1275           0 :         WinBits nWinStyle = WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_SIMPLEMODE;
    1276           0 :         OString sBorder = extractCustomProperty(rMap);
    1277           0 :         if (!sBorder.isEmpty())
    1278           0 :             nWinStyle |= WB_BORDER;
    1279             :         //ListBox manages its own scrolling,
    1280           0 :         Window *pRealParent = prepareWidgetOwnScrolling(pParent, nWinStyle);
    1281           0 :         pWindow = new ListBox(pRealParent, nWinStyle);
    1282           0 :         if (pRealParent != pParent)
    1283           0 :             cleanupWidgetOwnScrolling(pParent, pWindow, rMap);
    1284             :     }
    1285           0 :     else if (name == "GtkLabel")
    1286             :     {
    1287           0 :         extractMnemonicWidget(id, rMap);
    1288           0 :         if (extractSelectable(rMap))
    1289           0 :             pWindow = new SelectableFixedText(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK);
    1290             :         else
    1291           0 :             pWindow = new FixedText(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK);
    1292             :     }
    1293           0 :     else if (name == "GtkImage")
    1294             :     {
    1295           0 :         extractStock(id, rMap);
    1296           0 :         pWindow = new FixedImage(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK);
    1297             :     }
    1298           0 :     else if (name == "GtkSeparator")
    1299             :     {
    1300           0 :         bVertical = extractOrientation(rMap);
    1301           0 :         if (bVertical)
    1302           0 :             pWindow = new FixedLine(pParent, WB_VERT);
    1303             :         else
    1304           0 :             pWindow = new FixedLine(pParent, WB_HORZ);
    1305             :     }
    1306           0 :     else if (name == "GtkScrollbar")
    1307             :     {
    1308           0 :         extractScrollAdjustment(id, rMap);
    1309           0 :         bVertical = extractOrientation(rMap);
    1310           0 :         if (bVertical)
    1311           0 :             pWindow = new ScrollBar(pParent, WB_VERT);
    1312             :         else
    1313           0 :             pWindow = new ScrollBar(pParent, WB_HORZ);
    1314             :     }
    1315           0 :     else if (name == "GtkProgressBar")
    1316             :     {
    1317           0 :         extractScrollAdjustment(id, rMap);
    1318           0 :         bVertical = extractOrientation(rMap);
    1319           0 :         if (bVertical)
    1320           0 :             pWindow = new ProgressBar(pParent, WB_VERT);
    1321             :         else
    1322           0 :             pWindow = new ProgressBar(pParent, WB_HORZ);
    1323             :     }
    1324           0 :     else if (name == "GtkScrolledWindow")
    1325             :     {
    1326           0 :         pWindow = new VclScrolledWindow(pParent);
    1327             :     }
    1328           0 :     else if (name == "GtkEventBox")
    1329             :     {
    1330           0 :         pWindow = new VclEventBox(pParent);
    1331             :     }
    1332           0 :     else if (name == "GtkEntry")
    1333             :     {
    1334           0 :         pWindow = new Edit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK);
    1335           0 :         ensureDefaultWidthChars(rMap);
    1336             :     }
    1337           0 :     else if (name == "GtkNotebook")
    1338           0 :         pWindow = new TabControl(pParent, WB_STDTABCONTROL|WB_3DLOOK);
    1339           0 :     else if (name == "GtkDrawingArea")
    1340             :     {
    1341           0 :         OString sBorder = extractCustomProperty(rMap);
    1342           0 :         pWindow = new Window(pParent, sBorder.isEmpty() ? 0 : WB_BORDER);
    1343             :     }
    1344           0 :     else if (name == "GtkTextView")
    1345             :     {
    1346           0 :         extractBuffer(id, rMap);
    1347             : 
    1348           0 :         WinBits nWinStyle = WB_LEFT;
    1349           0 :         OString sBorder = extractCustomProperty(rMap);
    1350           0 :         if (!sBorder.isEmpty())
    1351           0 :             nWinStyle |= WB_BORDER;
    1352             :         //VclMultiLineEdit manages its own scrolling,
    1353           0 :         Window *pRealParent = prepareWidgetOwnScrolling(pParent, nWinStyle);
    1354           0 :         pWindow = new VclMultiLineEdit(pRealParent, nWinStyle);
    1355           0 :         if (pRealParent != pParent)
    1356           0 :             cleanupWidgetOwnScrolling(pParent, pWindow, rMap);
    1357             :     }
    1358           0 :     else if (name == "GtkToolbar")
    1359             :     {
    1360           0 :         pWindow = new ToolBox(pParent, WB_3DLOOK | WB_TABSTOP);
    1361             :     }
    1362           0 :     else if (name == "GtkToolButton" || name == "GtkMenuToolButton")
    1363             :     {
    1364           0 :         ToolBox *pToolBox = dynamic_cast<ToolBox*>(pParent);
    1365           0 :         if (pToolBox)
    1366             :         {
    1367           0 :             OUString aCommand(OStringToOUString(extractActionName(rMap), RTL_TEXTENCODING_UTF8));
    1368             : 
    1369           0 :             ToolBoxItemBits nBits = 0;
    1370           0 :             if (name == "GtkMenuToolButton")
    1371           0 :                 nBits |= TIB_DROPDOWN;
    1372             : 
    1373           0 :             if (!aCommand.isEmpty())
    1374             :             {
    1375           0 :                 pToolBox->InsertItem(aCommand, m_xFrame, nBits, extractSizeRequest(rMap));
    1376             : 
    1377           0 :                 OUString aTooltip(OStringToOUString(extractTooltipText(rMap), RTL_TEXTENCODING_UTF8));
    1378           0 :                 if (!aTooltip.isEmpty())
    1379           0 :                     pToolBox->SetQuickHelpText(pToolBox->GetItemId(aCommand), aTooltip);
    1380             :             }
    1381             : 
    1382           0 :             return NULL; // no widget to be created
    1383             :         }
    1384             :     }
    1385             :     else
    1386             :     {
    1387           0 :         sal_Int32 nDelim = name.indexOf('-');
    1388           0 :         if (nDelim != -1)
    1389             :         {
    1390             : #ifndef DISABLE_DYNLOADING
    1391           0 :             OUStringBuffer sModuleBuf;
    1392             : #ifdef SAL_DLLPREFIX
    1393           0 :             sModuleBuf.append(SAL_DLLPREFIX);
    1394             : #endif
    1395           0 :             sModuleBuf.append(OStringToOUString(name.copy(0, nDelim), RTL_TEXTENCODING_UTF8));
    1396             : #ifdef SAL_DLLEXTENSION
    1397           0 :             sModuleBuf.append(SAL_DLLEXTENSION);
    1398             : #endif
    1399             : #endif
    1400           0 :             OUString sFunction(OStringToOUString(OString("make") + name.copy(nDelim+1), RTL_TEXTENCODING_UTF8));
    1401             : #ifndef DISABLE_DYNLOADING
    1402           0 :             OUString sModule = sModuleBuf.makeStringAndClear();
    1403           0 :             ModuleMap::iterator aI = m_aModuleMap.find(sModule);
    1404           0 :             osl::Module* pModule = NULL;
    1405           0 :             if (aI == m_aModuleMap.end())
    1406             :             {
    1407           0 :                 pModule = new osl::Module;
    1408           0 :                 pModule->loadRelative(&thisModule, sModule);
    1409           0 :                 aI = m_aModuleMap.insert(sModule, pModule).first;
    1410             :             }
    1411           0 :             customMakeWidget pFunction = (customMakeWidget)aI->second->getFunctionSymbol(sFunction);
    1412             : #else
    1413             :             customMakeWidget pFunction = (customMakeWidget)osl_getFunctionSymbol((oslModule) RTLD_DEFAULT, sFunction.pData);
    1414             : #endif
    1415           0 :             if (pFunction)
    1416           0 :                 pWindow = (*pFunction)(pParent, rMap);
    1417             :         }
    1418             :     }
    1419             :     SAL_WARN_IF(!pWindow, "vcl.layout", "probably need to implement " << name.getStr() << " or add a make" << name.getStr() << " function");
    1420           0 :     if (pWindow)
    1421             :     {
    1422           0 :         pWindow->SetHelpId(m_sHelpRoot + id);
    1423             :         SAL_INFO("vcl.layout", "for " << name.getStr() <<
    1424             :             ", created " << pWindow << " child of " <<
    1425             :             pParent << "(" << pWindow->mpWindowImpl->mpParent << "/" <<
    1426             :             pWindow->mpWindowImpl->mpRealParent << "/" <<
    1427             :             pWindow->mpWindowImpl->mpBorderWindow << ") with helpid " <<
    1428             :             pWindow->GetHelpId().getStr());
    1429           0 :         m_aChildren.push_back(WinAndId(id, pWindow, bVertical));
    1430             :     }
    1431           0 :     return pWindow;
    1432             : }
    1433             : 
    1434             : namespace
    1435             : {
    1436             :     //return true for window types which exist in vcl but are not themselves
    1437             :     //represented in the .ui format, i.e. only their children exist.
    1438           0 :     bool isConsideredGtkPseudo(Window *pWindow)
    1439             :     {
    1440           0 :         return pWindow->GetType() == WINDOW_TABPAGE;
    1441             :     }
    1442             : }
    1443             : 
    1444             : //Any properties from .ui load we couldn't set because of potential virtual methods
    1445             : //during ctor are applied here
    1446           0 : void VclBuilder::setDeferredProperties()
    1447             : {
    1448           0 :     if (!m_bToplevelHasDeferredProperties)
    1449           0 :         return;
    1450           0 :     stringmap aDeferredProperties;
    1451           0 :     aDeferredProperties.swap(m_aDeferredProperties);
    1452           0 :     m_bToplevelHasDeferredProperties = false;
    1453           0 :     set_properties(m_pParent, aDeferredProperties);
    1454             : }
    1455             : 
    1456           0 : void VclBuilder::set_properties(Window *pWindow, const stringmap &rProps)
    1457             : {
    1458           0 :     for (stringmap::const_iterator aI = rProps.begin(), aEnd = rProps.end(); aI != aEnd; ++aI)
    1459             :     {
    1460           0 :         const OString &rKey = aI->first;
    1461           0 :         const OString &rValue = aI->second;
    1462           0 :         pWindow->set_property(rKey, rValue);
    1463             :     }
    1464           0 : }
    1465             : 
    1466           0 : Window *VclBuilder::insertObject(Window *pParent, const OString &rClass,
    1467             :     const OString &rID, stringmap &rProps, stringmap &rPango,
    1468             :     stringmap &rAtk,
    1469             :     std::vector<OString> &rItems)
    1470             : {
    1471           0 :     Window *pCurrentChild = NULL;
    1472             : 
    1473           0 :     if (m_pParent && !isConsideredGtkPseudo(m_pParent) && !m_sID.isEmpty() && rID.equals(m_sID))
    1474             :     {
    1475           0 :         pCurrentChild = m_pParent;
    1476             :         //toplevels default to resizable
    1477           0 :         if (pCurrentChild->IsDialog())
    1478             :         {
    1479           0 :             Dialog *pDialog = (Dialog*)pCurrentChild;
    1480           0 :             pDialog->doDeferredInit(extractResizable(rProps));
    1481           0 :             m_bToplevelHasDeferredInit = false;
    1482             :         }
    1483           0 :         if (pCurrentChild->GetHelpId().isEmpty())
    1484             :         {
    1485           0 :             pCurrentChild->SetHelpId(m_sHelpRoot + m_sID);
    1486             :             SAL_INFO("vcl.layout", "for toplevel dialog " << this << " " <<
    1487             :                 rID.getStr() << ", set helpid " <<
    1488             :                 pCurrentChild->GetHelpId().getStr());
    1489             :         }
    1490           0 :         m_bToplevelParentFound = true;
    1491             :     }
    1492             :     else
    1493             :     {
    1494             :         //if we're being inserting under a toplevel dialog whose init is
    1495             :         //deferred due to waiting to encounter it in this .ui, and it hasn't
    1496             :         //been seen yet, then make unattached widgets parent-less toplevels
    1497           0 :         if (pParent == m_pParent && m_bToplevelHasDeferredInit)
    1498           0 :             pParent = NULL;
    1499           0 :         pCurrentChild = makeObject(pParent, rClass, rID, rProps, rItems);
    1500             :     }
    1501             : 
    1502           0 :     if (pCurrentChild)
    1503             :     {
    1504           0 :         if (pCurrentChild == m_pParent && m_bToplevelHasDeferredProperties)
    1505           0 :             m_aDeferredProperties = rProps;
    1506             :         else
    1507           0 :             set_properties(pCurrentChild, rProps);
    1508             : 
    1509           0 :         for (stringmap::iterator aI = rPango.begin(), aEnd = rPango.end(); aI != aEnd; ++aI)
    1510             :         {
    1511           0 :             const OString &rKey = aI->first;
    1512           0 :             const OString &rValue = aI->second;
    1513           0 :             pCurrentChild->set_font_attribute(rKey, rValue);
    1514             :         }
    1515             : 
    1516           0 :         m_pParserState->m_aAtkInfo[pCurrentChild] = rAtk;
    1517             :     }
    1518             : 
    1519           0 :     rProps.clear();
    1520           0 :     rPango.clear();
    1521           0 :     rAtk.clear();
    1522           0 :     rItems.clear();
    1523             : 
    1524           0 :     if (!pCurrentChild)
    1525           0 :         pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back().m_pWindow;
    1526           0 :     return pCurrentChild;
    1527             : }
    1528             : 
    1529           0 : void VclBuilder::reorderWithinParent(Window &rWindow, sal_uInt16 nNewPosition)
    1530             : {
    1531           0 :     if (rWindow.mpWindowImpl->mpParent != rWindow.mpWindowImpl->mpRealParent)
    1532             :     {
    1533             :         assert(rWindow.mpWindowImpl->mpBorderWindow ==
    1534             :             rWindow.mpWindowImpl->mpParent);
    1535             :         assert(rWindow.mpWindowImpl->mpBorderWindow->mpWindowImpl->mpParent ==
    1536             :             rWindow.mpWindowImpl->mpRealParent);
    1537           0 :         reorderWithinParent(*rWindow.mpWindowImpl->mpBorderWindow, nNewPosition);
    1538           0 :         return;
    1539             :     }
    1540           0 :     rWindow.reorderWithinParent(nNewPosition);
    1541             : }
    1542             : 
    1543           0 : void VclBuilder::handleTabChild(Window *pParent, xmlreader::XmlReader &reader)
    1544             : {
    1545           0 :     OString sID;
    1546             : 
    1547           0 :     int nLevel = 1;
    1548           0 :     stringmap aProperties;
    1549             :     while(1)
    1550             :     {
    1551           0 :         xmlreader::Span name;
    1552             :         int nsId;
    1553             : 
    1554             :         xmlreader::XmlReader::Result res = reader.nextItem(
    1555           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    1556             : 
    1557           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    1558             :         {
    1559           0 :             ++nLevel;
    1560           0 :             if (name.equals("object"))
    1561             :             {
    1562           0 :                 while (reader.nextAttribute(&nsId, &name))
    1563             :                 {
    1564           0 :                     if (name.equals("id"))
    1565             :                     {
    1566           0 :                         name = reader.getAttributeValue(false);
    1567           0 :                         sID = OString(name.begin, name.length);
    1568           0 :                         sal_Int32 nDelim = sID.indexOf(':');
    1569           0 :                         if (nDelim != -1)
    1570             :                         {
    1571           0 :                             OString sPattern = sID.copy(nDelim+1);
    1572           0 :                             aProperties[OString("customproperty")] = sPattern;
    1573           0 :                             sID = sID.copy(0, nDelim);
    1574             :                         }
    1575             :                     }
    1576             :                 }
    1577             :             }
    1578           0 :             else if (name.equals("property"))
    1579           0 :                 collectProperty(reader, sID, aProperties);
    1580             :         }
    1581             : 
    1582           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    1583           0 :             --nLevel;
    1584             : 
    1585           0 :         if (!nLevel)
    1586           0 :             break;
    1587             : 
    1588           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    1589           0 :             break;
    1590             :     }
    1591             : 
    1592           0 :     TabControl *pTabControl = static_cast<TabControl*>(pParent);
    1593           0 :     VclBuilder::stringmap::iterator aFind = aProperties.find(OString("label"));
    1594           0 :     if (aFind != aProperties.end())
    1595             :     {
    1596           0 :         sal_uInt16 nPageId = pTabControl->GetCurPageId();
    1597             :         pTabControl->SetPageText(nPageId,
    1598           0 :             OStringToOUString(aFind->second, RTL_TEXTENCODING_UTF8));
    1599           0 :         pTabControl->SetPageName(nPageId, sID);
    1600             :     }
    1601             :     else
    1602           0 :         pTabControl->RemovePage(pTabControl->GetCurPageId());
    1603           0 : }
    1604             : 
    1605             : //so that tabbing between controls goes in a visually sensible sequence
    1606             : //we sort these into a best-tab-order sequence
    1607           0 : bool VclBuilder::sortIntoBestTabTraversalOrder::operator()(const Window *pA, const Window *pB) const
    1608             : {
    1609             :     //sort child order within parent list by grid position
    1610           0 :     sal_Int32 nTopA = pA->get_grid_top_attach();
    1611           0 :     sal_Int32 nTopB = pB->get_grid_top_attach();
    1612           0 :     if (nTopA < nTopB)
    1613           0 :         return true;
    1614           0 :     if (nTopA > nTopB)
    1615           0 :         return false;
    1616           0 :     sal_Int32 nLeftA = pA->get_grid_left_attach();
    1617           0 :     sal_Int32 nLeftB = pB->get_grid_left_attach();
    1618           0 :     if (nLeftA < nLeftB)
    1619           0 :         return true;
    1620           0 :     if (nLeftA > nLeftB)
    1621           0 :         return false;
    1622             :     //sort into two groups of pack start and pack end
    1623           0 :     VclPackType ePackA = pA->get_pack_type();
    1624           0 :     VclPackType ePackB = pB->get_pack_type();
    1625           0 :     if (ePackA < ePackB)
    1626           0 :         return true;
    1627           0 :     if (ePackA > ePackB)
    1628           0 :         return false;
    1629           0 :     bool bVerticalContainer = m_pBuilder->get_window_packing_data(pA->GetParent()).m_bVerticalOrient;
    1630           0 :     bool bPackA = pA->get_secondary();
    1631           0 :     bool bPackB = pB->get_secondary();
    1632           0 :     if (!bVerticalContainer)
    1633             :     {
    1634             :         //for horizontal boxes group secondaries before primaries
    1635           0 :         if (bPackA > bPackB)
    1636           0 :             return true;
    1637           0 :         if (bPackA < bPackB)
    1638           0 :             return false;
    1639             :     }
    1640             :     else
    1641             :     {
    1642             :         //for vertical boxes group secondaries after primaries
    1643           0 :         if (bPackA < bPackB)
    1644           0 :             return true;
    1645           0 :         if (bPackA > bPackB)
    1646           0 :             return false;
    1647             :     }
    1648             :     //honour relative box positions with pack group
    1649           0 :     bPackA = m_pBuilder->get_window_packing_data(pA).m_nPosition;
    1650           0 :     bPackB = m_pBuilder->get_window_packing_data(pB).m_nPosition;
    1651           0 :     if (bPackA < bPackB)
    1652           0 :         return true;
    1653           0 :     if (bPackA > bPackB)
    1654           0 :         return false;
    1655             :     //sort labels of Frames before body
    1656           0 :     if (pA->GetParent() == pB->GetParent())
    1657             :     {
    1658           0 :         const VclFrame *pFrameParent = dynamic_cast<const VclFrame*>(pA->GetParent());
    1659           0 :         if (pFrameParent)
    1660             :         {
    1661           0 :             const Window *pLabel = pFrameParent->get_label_widget();
    1662           0 :             int nFramePosA = (pA == pLabel) ? 0 : 1;
    1663           0 :             int nFramePosB = (pB == pLabel) ? 0 : 1;
    1664           0 :             return nFramePosA < nFramePosB;
    1665             :         }
    1666             :     }
    1667           0 :     return false;
    1668             : }
    1669             : 
    1670           0 : void VclBuilder::handleChild(Window *pParent, xmlreader::XmlReader &reader)
    1671             : {
    1672           0 :     Window *pCurrentChild = NULL;
    1673             : 
    1674           0 :     xmlreader::Span name;
    1675             :     int nsId;
    1676           0 :     OString sType, sInternalChild;
    1677             : 
    1678           0 :     while (reader.nextAttribute(&nsId, &name))
    1679             :     {
    1680           0 :         if (name.equals("type"))
    1681             :         {
    1682           0 :             name = reader.getAttributeValue(false);
    1683           0 :             sType = OString(name.begin, name.length);
    1684             :         }
    1685           0 :         else if (name.equals("internal-child"))
    1686             :         {
    1687           0 :             name = reader.getAttributeValue(false);
    1688           0 :             sInternalChild = OString(name.begin, name.length);
    1689             :         }
    1690             :     }
    1691             : 
    1692           0 :     if (sType.equals("tab"))
    1693             :     {
    1694           0 :         handleTabChild(pParent, reader);
    1695           0 :         return;
    1696             :     }
    1697             : 
    1698           0 :     int nLevel = 1;
    1699             :     while(1)
    1700             :     {
    1701             :         xmlreader::XmlReader::Result res = reader.nextItem(
    1702           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    1703             : 
    1704           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    1705             :         {
    1706           0 :             if (name.equals("object") || name.equals("placeholder"))
    1707             :             {
    1708           0 :                 pCurrentChild = handleObject(pParent, reader);
    1709             : 
    1710           0 :                 bool bObjectInserted = pCurrentChild && pParent != pCurrentChild;
    1711             : 
    1712           0 :                 if (bObjectInserted)
    1713             :                 {
    1714             :                     //Internal-children default in glade to not having their visible bits set
    1715             :                     //even though they are visible (generally anyway)
    1716           0 :                     if (!sInternalChild.isEmpty())
    1717           0 :                         pCurrentChild->Show();
    1718             : 
    1719             :                     //Select the first page if its a notebook
    1720           0 :                     if (pCurrentChild->GetType() == WINDOW_TABCONTROL)
    1721             :                     {
    1722           0 :                         TabControl *pTabControl = static_cast<TabControl*>(pCurrentChild);
    1723           0 :                         pTabControl->SetCurPageId(pTabControl->GetPageId(0));
    1724             : 
    1725             :                         //To-Do add reorder capability to the TabControl
    1726             :                     }
    1727             :                     else
    1728             :                     {
    1729             :                         // We want to sort labels before contents of frames
    1730             :                         // for key board traversal, especially if there
    1731             :                         // are multiple widgets using the same mnemonic
    1732           0 :                         if (sType.equals("label"))
    1733             :                         {
    1734           0 :                             if (VclFrame *pFrameParent = dynamic_cast<VclFrame*>(pParent))
    1735           0 :                                 pFrameParent->designate_label(pCurrentChild);
    1736             :                         }
    1737           0 :                         if (sInternalChild.equals("vbox") || sInternalChild.equals("messagedialog-vbox"))
    1738             :                         {
    1739           0 :                             if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pParent))
    1740           0 :                                 pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild));
    1741             :                         }
    1742           0 :                         else if (sInternalChild.equals("action_area") || sInternalChild.equals("messagedialog-action_area"))
    1743             :                         {
    1744           0 :                             Window *pContentArea = pCurrentChild->GetParent();
    1745             :                             assert(pContentArea && pContentArea->GetType() == WINDOW_CONTAINER);
    1746           0 :                             if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pContentArea ? pContentArea->GetParent() : NULL))
    1747             :                             {
    1748           0 :                                 pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild));
    1749             :                             }
    1750             :                         }
    1751             : 
    1752             :                         //To-Do make reorder a virtual in Window, move this foo
    1753             :                         //there and see above
    1754           0 :                         std::vector<Window*> aChilds;
    1755           0 :                         for (Window* pChild = pCurrentChild->GetWindow(WINDOW_FIRSTCHILD); pChild;
    1756           0 :                             pChild = pChild->GetWindow(WINDOW_NEXT))
    1757             :                         {
    1758           0 :                             aChilds.push_back(pChild);
    1759             :                         }
    1760             : 
    1761           0 :                         bool bIsButtonBox = dynamic_cast<VclButtonBox*>(pCurrentChild) != NULL;
    1762             : 
    1763             :                         //sort child order within parent so that tabbing
    1764             :                         //between controls goes in a visually sensible sequence
    1765           0 :                         std::stable_sort(aChilds.begin(), aChilds.end(), sortIntoBestTabTraversalOrder(this));
    1766           0 :                         reorderWithinParent(aChilds, bIsButtonBox);
    1767             :                     }
    1768             :                 }
    1769             :             }
    1770           0 :             else if (name.equals("packing"))
    1771             :             {
    1772           0 :                 handlePacking(pCurrentChild, reader);
    1773             :             }
    1774             :             else
    1775           0 :                 ++nLevel;
    1776             :         }
    1777             : 
    1778           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    1779           0 :             --nLevel;
    1780             : 
    1781           0 :         if (!nLevel)
    1782           0 :             break;
    1783             : 
    1784           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    1785           0 :             break;
    1786           0 :     }
    1787             : }
    1788             : 
    1789           0 : void VclBuilder::reorderWithinParent(std::vector<Window*>& rChilds, bool bIsButtonBox)
    1790             : {
    1791           0 :     for (size_t i = 0; i < rChilds.size(); ++i)
    1792             :     {
    1793           0 :         reorderWithinParent(*rChilds[i], i);
    1794             : 
    1795           0 :         if (!bIsButtonBox)
    1796           0 :             break;
    1797             : 
    1798             :         //The first member of the group for legacy code needs WB_GROUP set and the
    1799             :         //others not
    1800           0 :         WinBits nBits = rChilds[i]->GetStyle();
    1801           0 :         nBits &= ~WB_GROUP;
    1802           0 :         if (i == 0)
    1803           0 :             nBits |= WB_GROUP;
    1804           0 :         rChilds[i]->SetStyle(nBits);
    1805             :     }
    1806           0 : }
    1807             : 
    1808           0 : void VclBuilder::collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap)
    1809             : {
    1810           0 :     xmlreader::Span span;
    1811             :     int nsId;
    1812             : 
    1813           0 :     OString sProperty;
    1814           0 :     OString sValue;
    1815             : 
    1816           0 :     while (reader.nextAttribute(&nsId, &span))
    1817             :     {
    1818           0 :         if (span.equals("name"))
    1819             :         {
    1820           0 :             span = reader.getAttributeValue(false);
    1821           0 :             sProperty = OString(span.begin, span.length);
    1822             :         }
    1823           0 :         else if (span.equals("value"))
    1824             :         {
    1825           0 :             span = reader.getAttributeValue(false);
    1826           0 :             sValue = OString(span.begin, span.length);
    1827             :         }
    1828             :     }
    1829             : 
    1830           0 :     if (!sProperty.isEmpty())
    1831           0 :         rMap[sProperty] = sValue;
    1832           0 : }
    1833             : 
    1834           0 : void VclBuilder::collectAtkAttribute(xmlreader::XmlReader &reader, stringmap &rMap)
    1835             : {
    1836           0 :     xmlreader::Span span;
    1837             :     int nsId;
    1838             : 
    1839           0 :     OString sProperty;
    1840           0 :     OString sValue;
    1841             : 
    1842           0 :     while (reader.nextAttribute(&nsId, &span))
    1843             :     {
    1844           0 :         if (span.equals("type"))
    1845             :         {
    1846           0 :             span = reader.getAttributeValue(false);
    1847           0 :             sProperty = OString(span.begin, span.length);
    1848             :         }
    1849           0 :         else if (span.equals("target"))
    1850             :         {
    1851           0 :             span = reader.getAttributeValue(false);
    1852           0 :             sValue = OString(span.begin, span.length);
    1853           0 :             sal_Int32 nDelim = sValue.indexOf(':');
    1854           0 :             if (nDelim != -1)
    1855           0 :                 sValue = sValue.copy(0, nDelim);
    1856             :         }
    1857             :     }
    1858             : 
    1859           0 :     if (!sProperty.isEmpty())
    1860           0 :         rMap[sProperty] = sValue;
    1861           0 : }
    1862             : 
    1863           0 : void VclBuilder::handleAdjustment(const OString &rID, stringmap &rProperties)
    1864             : {
    1865           0 :     m_pParserState->m_aAdjustments[rID] = rProperties;
    1866           0 : }
    1867             : 
    1868           0 : void VclBuilder::handleTextBuffer(const OString &rID, stringmap &rProperties)
    1869             : {
    1870           0 :     m_pParserState->m_aTextBuffers[rID] = rProperties;
    1871           0 : }
    1872             : 
    1873           0 : void VclBuilder::handleRow(xmlreader::XmlReader &reader, const OString &rID, sal_Int32 nRowIndex)
    1874             : {
    1875           0 :     int nLevel = 1;
    1876             : 
    1877           0 :     ListStore::row aRow;
    1878             : 
    1879             :     while(1)
    1880             :     {
    1881           0 :         xmlreader::Span name;
    1882             :         int nsId;
    1883             : 
    1884             :         xmlreader::XmlReader::Result res = reader.nextItem(
    1885           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    1886             : 
    1887           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    1888           0 :             break;
    1889             : 
    1890           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    1891             :         {
    1892           0 :             ++nLevel;
    1893           0 :             if (name.equals("col"))
    1894             :             {
    1895           0 :                 bool bTranslated = false;
    1896           0 :                 OString sValue;
    1897           0 :                 sal_uInt32 nId = 0;
    1898             : 
    1899           0 :                 while (reader.nextAttribute(&nsId, &name))
    1900             :                 {
    1901           0 :                     if (name.equals("id"))
    1902             :                     {
    1903           0 :                         name = reader.getAttributeValue(false);
    1904           0 :                         nId = OString(name.begin, name.length).toInt32();
    1905             :                     }
    1906           0 :                     else if (nId == 0 && name.equals("translatable") && reader.getAttributeValue(false).equals("yes"))
    1907             :                     {
    1908           0 :                         sValue = getTranslation(rID, OString::valueOf(nRowIndex));
    1909           0 :                         bTranslated = !sValue.isEmpty();
    1910             :                     }
    1911             :                 }
    1912             : 
    1913             :                 reader.nextItem(
    1914           0 :                     xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
    1915             : 
    1916           0 :                 if (!bTranslated)
    1917           0 :                     sValue = OString(name.begin, name.length);
    1918             : 
    1919           0 :                 if (aRow.size() < nId+1)
    1920           0 :                     aRow.resize(nId+1);
    1921           0 :                 aRow[nId] = sValue;
    1922             :             }
    1923             :         }
    1924             : 
    1925           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    1926             :         {
    1927           0 :             --nLevel;
    1928             :         }
    1929             : 
    1930           0 :         if (!nLevel)
    1931           0 :             break;
    1932             :     }
    1933             : 
    1934           0 :     m_pParserState->m_aModels[rID].m_aEntries.push_back(aRow);
    1935           0 : }
    1936             : 
    1937           0 : void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const OString &rID)
    1938             : {
    1939           0 :     int nLevel = 1;
    1940           0 :     sal_Int32 nRowIndex = 0;
    1941             : 
    1942             :     while(1)
    1943             :     {
    1944           0 :         xmlreader::Span name;
    1945             :         int nsId;
    1946             : 
    1947             :         xmlreader::XmlReader::Result res = reader.nextItem(
    1948           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    1949             : 
    1950           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    1951           0 :             break;
    1952             : 
    1953           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    1954             :         {
    1955           0 :             if (name.equals("row"))
    1956           0 :                 handleRow(reader, rID, nRowIndex++);
    1957             :             else
    1958           0 :                 ++nLevel;
    1959             :         }
    1960             : 
    1961           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    1962             :         {
    1963           0 :             --nLevel;
    1964             :         }
    1965             : 
    1966           0 :         if (!nLevel)
    1967           0 :             break;
    1968           0 :     }
    1969           0 : }
    1970             : 
    1971           0 : void VclBuilder::handleAtkObject(xmlreader::XmlReader &reader, const OString &rID, Window *pWindow)
    1972             : {
    1973             :     assert(pWindow);
    1974             : 
    1975           0 :     int nLevel = 1;
    1976             : 
    1977           0 :     stringmap aProperties;
    1978             : 
    1979             :     while(1)
    1980             :     {
    1981           0 :         xmlreader::Span name;
    1982             :         int nsId;
    1983             : 
    1984             :         xmlreader::XmlReader::Result res = reader.nextItem(
    1985           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    1986             : 
    1987           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    1988           0 :             break;
    1989             : 
    1990           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    1991             :         {
    1992           0 :             ++nLevel;
    1993           0 :             if (name.equals("property"))
    1994           0 :                 collectProperty(reader, rID, aProperties);
    1995             :         }
    1996             : 
    1997           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    1998             :         {
    1999           0 :             --nLevel;
    2000             :         }
    2001             : 
    2002           0 :         if (!nLevel)
    2003           0 :             break;
    2004             :     }
    2005             : 
    2006           0 :     for (stringmap::iterator aI = aProperties.begin(), aEnd = aProperties.end(); aI != aEnd; ++aI)
    2007             :     {
    2008           0 :         const OString &rKey = aI->first;
    2009           0 :         const OString &rValue = aI->second;
    2010             : 
    2011           0 :         if (rKey.match("AtkObject::"))
    2012           0 :             pWindow->set_property(rKey.copy(RTL_CONSTASCII_LENGTH("AtkObject::")), rValue);
    2013             :         else
    2014             :             SAL_WARN("vcl.layout", "unhandled atk prop: " << rKey.getStr());
    2015           0 :     }
    2016           0 : }
    2017             : 
    2018           0 : std::vector<OString> VclBuilder::handleItems(xmlreader::XmlReader &reader, const OString &rID)
    2019             : {
    2020           0 :     int nLevel = 1;
    2021             : 
    2022           0 :     std::vector<OString> aItems;
    2023           0 :     sal_Int32 nItemIndex = 0;
    2024             : 
    2025             :     while(1)
    2026             :     {
    2027           0 :         xmlreader::Span name;
    2028             :         int nsId;
    2029             : 
    2030             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2031           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2032             : 
    2033           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2034           0 :             break;
    2035             : 
    2036           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2037             :         {
    2038           0 :             ++nLevel;
    2039           0 :             if (name.equals("item"))
    2040             :             {
    2041           0 :                 bool bTranslated = false;
    2042           0 :                 OString sValue;
    2043             : 
    2044           0 :                 while (reader.nextAttribute(&nsId, &name))
    2045             :                 {
    2046           0 :                     if (name.equals("translatable") && reader.getAttributeValue(false).equals("yes"))
    2047             :                     {
    2048           0 :                         sValue = getTranslation(rID, OString::valueOf(nItemIndex));
    2049           0 :                         bTranslated = !sValue.isEmpty();
    2050             :                     }
    2051             :                 }
    2052             : 
    2053             :                 reader.nextItem(
    2054           0 :                     xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
    2055             : 
    2056           0 :                 if (!bTranslated)
    2057           0 :                     sValue = OString(name.begin, name.length);
    2058             : 
    2059           0 :                 if (m_pStringReplace)
    2060             :                 {
    2061           0 :                     OUString sTmp = (*m_pStringReplace)(OStringToOUString(sValue, RTL_TEXTENCODING_UTF8));
    2062           0 :                     sValue = OUStringToOString(sTmp, RTL_TEXTENCODING_UTF8);
    2063             :                 }
    2064             : 
    2065           0 :                 aItems.push_back(sValue);
    2066           0 :                 ++nItemIndex;
    2067             :             }
    2068             :         }
    2069             : 
    2070           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2071             :         {
    2072           0 :             --nLevel;
    2073             :         }
    2074             : 
    2075           0 :         if (!nLevel)
    2076           0 :             break;
    2077             :     }
    2078             : 
    2079           0 :     return aItems;
    2080             : }
    2081             : 
    2082           0 : void VclBuilder::handleMenu(xmlreader::XmlReader &reader, const OString &rID)
    2083             : {
    2084           0 :     PopupMenu *pCurrentMenu = new PopupMenu;
    2085             : 
    2086           0 :     int nLevel = 1;
    2087             : 
    2088           0 :     stringmap aProperties;
    2089             : 
    2090             :     while(1)
    2091             :     {
    2092           0 :         xmlreader::Span name;
    2093             :         int nsId;
    2094             : 
    2095             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2096           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2097             : 
    2098           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2099           0 :             break;
    2100             : 
    2101           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2102             :         {
    2103           0 :             if (name.equals("child"))
    2104             :             {
    2105           0 :                 handleMenuChild(pCurrentMenu, reader);
    2106             :             }
    2107             :             else
    2108             :             {
    2109           0 :                 ++nLevel;
    2110           0 :                 if (name.equals("property"))
    2111           0 :                     collectProperty(reader, rID, aProperties);
    2112             :             }
    2113             :         }
    2114             : 
    2115           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2116             :         {
    2117           0 :             --nLevel;
    2118             :         }
    2119             : 
    2120           0 :         if (!nLevel)
    2121           0 :             break;
    2122             :     }
    2123             : 
    2124           0 :     m_aMenus.push_back(MenuAndId(rID, pCurrentMenu));
    2125           0 : }
    2126             : 
    2127           0 : void VclBuilder::handleMenuChild(PopupMenu *pParent, xmlreader::XmlReader &reader)
    2128             : {
    2129           0 :     xmlreader::Span name;
    2130             :     int nsId;
    2131             : 
    2132           0 :     int nLevel = 1;
    2133             :     while(1)
    2134             :     {
    2135             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2136           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2137             : 
    2138           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2139             :         {
    2140           0 :             if (name.equals("object") || name.equals("placeholder"))
    2141             :             {
    2142           0 :                 handleMenuObject(pParent, reader);
    2143             :             }
    2144             :             else
    2145           0 :                 ++nLevel;
    2146             :         }
    2147             : 
    2148           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2149           0 :             --nLevel;
    2150             : 
    2151           0 :         if (!nLevel)
    2152           0 :             break;
    2153             : 
    2154           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2155           0 :             break;
    2156           0 :     }
    2157           0 : }
    2158             : 
    2159           0 : void VclBuilder::handleMenuObject(PopupMenu *pParent, xmlreader::XmlReader &reader)
    2160             : {
    2161           0 :     OString sClass;
    2162           0 :     OString sID;
    2163           0 :     OString sCustomProperty;
    2164             : 
    2165           0 :     xmlreader::Span name;
    2166             :     int nsId;
    2167             : 
    2168           0 :     while (reader.nextAttribute(&nsId, &name))
    2169             :     {
    2170           0 :         if (name.equals("class"))
    2171             :         {
    2172           0 :             name = reader.getAttributeValue(false);
    2173           0 :             sClass = OString(name.begin, name.length);
    2174             :         }
    2175           0 :         else if (name.equals("id"))
    2176             :         {
    2177           0 :             name = reader.getAttributeValue(false);
    2178           0 :             sID = OString(name.begin, name.length);
    2179           0 :             sal_Int32 nDelim = sID.indexOf(':');
    2180           0 :             if (nDelim != -1)
    2181             :             {
    2182           0 :                 sCustomProperty = sID.copy(nDelim+1);
    2183           0 :                 sID = sID.copy(0, nDelim);
    2184             :             }
    2185             :         }
    2186             :     }
    2187             : 
    2188           0 :     int nLevel = 1;
    2189             : 
    2190           0 :     stringmap aProperties, aAccelerators;
    2191             : 
    2192           0 :     if (!sCustomProperty.isEmpty())
    2193           0 :         aProperties[OString("customproperty")] = sCustomProperty;
    2194             : 
    2195             :     while(1)
    2196             :     {
    2197             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2198           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2199             : 
    2200           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2201           0 :             break;
    2202             : 
    2203           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2204             :         {
    2205           0 :             ++nLevel;
    2206           0 :             if (name.equals("property"))
    2207           0 :                 collectProperty(reader, sID, aProperties);
    2208           0 :             else if (name.equals("accelerator"))
    2209           0 :                 collectAccelerator(reader, aAccelerators);
    2210             :         }
    2211             : 
    2212           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2213             :         {
    2214           0 :             --nLevel;
    2215             :         }
    2216             : 
    2217           0 :         if (!nLevel)
    2218           0 :             break;
    2219             :     }
    2220             : 
    2221           0 :     insertMenuObject(pParent, sClass, sID, aProperties, aAccelerators);
    2222           0 : }
    2223             : 
    2224           0 : void VclBuilder::handleSizeGroup(xmlreader::XmlReader &reader, const OString &rID)
    2225             : {
    2226           0 :     m_pParserState->m_aSizeGroups.push_back(SizeGroup(rID));
    2227           0 :     SizeGroup &rSizeGroup = m_pParserState->m_aSizeGroups.back();
    2228             : 
    2229           0 :     int nLevel = 1;
    2230             : 
    2231             :     while(1)
    2232             :     {
    2233           0 :         xmlreader::Span name;
    2234             :         int nsId;
    2235             : 
    2236             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2237           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2238             : 
    2239           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2240           0 :             break;
    2241             : 
    2242           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2243             :         {
    2244           0 :             ++nLevel;
    2245           0 :             if (name.equals("widget"))
    2246             :             {
    2247           0 :                 while (reader.nextAttribute(&nsId, &name))
    2248             :                 {
    2249           0 :                     if (name.equals("name"))
    2250             :                     {
    2251           0 :                         name = reader.getAttributeValue(false);
    2252           0 :                         OString sWidget = OString(name.begin, name.length);
    2253           0 :                         sal_Int32 nDelim = sWidget.indexOf(':');
    2254           0 :                         if (nDelim != -1)
    2255           0 :                             sWidget = sWidget.copy(0, nDelim);
    2256           0 :                         rSizeGroup.m_aWidgets.push_back(sWidget);
    2257             :                     }
    2258             :                 }
    2259             :             }
    2260             :             else
    2261             :             {
    2262           0 :                 if (name.equals("property"))
    2263           0 :                     collectProperty(reader, rID, rSizeGroup.m_aProperties);
    2264             :             }
    2265             :         }
    2266             : 
    2267           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2268             :         {
    2269           0 :             --nLevel;
    2270             :         }
    2271             : 
    2272           0 :         if (!nLevel)
    2273           0 :             break;
    2274           0 :     }
    2275           0 : }
    2276             : 
    2277           0 : OString VclBuilder::convertMnemonicMarkup(const OString &rIn)
    2278             : {
    2279           0 :     OStringBuffer aRet(rIn);
    2280           0 :     for (sal_Int32 nI = 0; nI < aRet.getLength(); ++nI)
    2281             :     {
    2282           0 :         if (aRet[nI] == '_' && nI+1 < aRet.getLength())
    2283             :         {
    2284           0 :             if (aRet[nI+1] != '_')
    2285           0 :                 aRet[nI] = MNEMONIC_CHAR;
    2286             :             else
    2287           0 :                 aRet.remove(nI, 1);
    2288           0 :             ++nI;
    2289             :         }
    2290             :     }
    2291           0 :     return aRet.makeStringAndClear();
    2292             : }
    2293             : 
    2294             : namespace
    2295             : {
    2296           0 :     KeyCode makeKeyCode(const OString &rKey)
    2297             :     {
    2298           0 :         if (rKey == "Insert")
    2299           0 :             return KeyCode(KEY_INSERT);
    2300           0 :         else if (rKey == "Delete")
    2301           0 :             return KeyCode(KEY_DELETE);
    2302             : 
    2303             :         assert (rKey.getLength() == 1);
    2304           0 :         sal_Char cChar = rKey.toChar();
    2305             : 
    2306           0 :         if (cChar >= 'a' && cChar <= 'z')
    2307           0 :             return KeyCode(KEY_A + (cChar - 'a'));
    2308           0 :         else if (cChar >= 'A' && cChar <= 'Z')
    2309           0 :             return KeyCode(KEY_A + (cChar - 'A'));
    2310           0 :         else if (cChar >= '0' && cChar <= '9')
    2311           0 :             return KeyCode(KEY_0 + (cChar - 'A'));
    2312             : 
    2313           0 :         return KeyCode(cChar);
    2314             :     }
    2315             : }
    2316             : 
    2317           0 : void VclBuilder::insertMenuObject(PopupMenu *pParent, const OString &rClass, const OString &rID,
    2318             :     stringmap &rProps, stringmap &rAccels)
    2319             : {
    2320           0 :     sal_uInt16 nOldCount = pParent->GetItemCount();
    2321           0 :     sal_uInt16 nNewId = nOldCount + 1;
    2322             : 
    2323           0 :     if (rClass == "GtkMenuItem")
    2324             :     {
    2325           0 :         OUString sLabel(OStringToOUString(convertMnemonicMarkup(extractLabel(rProps)), RTL_TEXTENCODING_UTF8));
    2326           0 :         pParent->InsertItem(nNewId, sLabel, MIB_TEXT, rID);
    2327             :     }
    2328           0 :     else if (rClass == "GtkSeparatorMenuItem")
    2329             :     {
    2330           0 :         pParent->InsertSeparator(rID);
    2331             :     }
    2332             : 
    2333             :     SAL_WARN_IF(nOldCount == pParent->GetItemCount(), "vcl.layout", "probably need to implement " << rClass.getStr());
    2334             : 
    2335           0 :     if (nOldCount != pParent->GetItemCount())
    2336             :     {
    2337           0 :         pParent->SetHelpId(nNewId, m_sHelpRoot + rID);
    2338             : 
    2339           0 :         for (stringmap::iterator aI = rProps.begin(), aEnd = rProps.end(); aI != aEnd; ++aI)
    2340             :         {
    2341           0 :             const OString &rKey = aI->first;
    2342           0 :             const OString &rValue = aI->second;
    2343             : 
    2344           0 :             if (rKey == "tooltip-markup")
    2345           0 :                 pParent->SetTipHelpText(nNewId, OStringToOUString(rValue, RTL_TEXTENCODING_UTF8));
    2346           0 :             else if (rKey == "tooltip-text")
    2347           0 :                 pParent->SetTipHelpText(nNewId, OStringToOUString(rValue, RTL_TEXTENCODING_UTF8));
    2348           0 :             else if (rKey == "visible")
    2349           0 :                 pParent->ShowItem(nNewId, toBool(rValue));
    2350           0 :             else if (rKey == "has-default" && toBool(rValue))
    2351           0 :                 pParent->SetSelectedEntry(nNewId);
    2352             :             else
    2353             :                 SAL_INFO("vcl.layout", "unhandled property: " << rKey.getStr());
    2354             :         }
    2355             : 
    2356           0 :         for (stringmap::iterator aI = rAccels.begin(), aEnd = rAccels.end(); aI != aEnd; ++aI)
    2357             :         {
    2358           0 :             const OString &rSignal = aI->first;
    2359           0 :             const OString &rValue = aI->second;
    2360             : 
    2361           0 :             if (rSignal == "activate")
    2362           0 :                 pParent->SetAccelKey(nNewId, makeKeyCode(rValue));
    2363             :             else
    2364             :                 SAL_INFO("vcl.layout", "unhandled accelerator for: " << rSignal.getStr());
    2365             :         }
    2366             :     }
    2367             : 
    2368           0 :     rProps.clear();
    2369           0 : }
    2370             : 
    2371           0 : Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader)
    2372             : {
    2373           0 :     OString sClass;
    2374           0 :     OString sID;
    2375           0 :     OString sCustomProperty;
    2376             : 
    2377           0 :     xmlreader::Span name;
    2378             :     int nsId;
    2379             : 
    2380           0 :     while (reader.nextAttribute(&nsId, &name))
    2381             :     {
    2382           0 :         if (name.equals("class"))
    2383             :         {
    2384           0 :             name = reader.getAttributeValue(false);
    2385           0 :             sClass = OString(name.begin, name.length);
    2386             :         }
    2387           0 :         else if (name.equals("id"))
    2388             :         {
    2389           0 :             name = reader.getAttributeValue(false);
    2390           0 :             sID = OString(name.begin, name.length);
    2391           0 :             sal_Int32 nDelim = sID.indexOf(':');
    2392           0 :             if (nDelim != -1)
    2393             :             {
    2394           0 :                 sCustomProperty = sID.copy(nDelim+1);
    2395           0 :                 sID = sID.copy(0, nDelim);
    2396             :             }
    2397             :         }
    2398             :     }
    2399             : 
    2400           0 :     if (sClass == "GtkListStore")
    2401             :     {
    2402           0 :         handleListStore(reader, sID);
    2403           0 :         return NULL;
    2404             :     }
    2405           0 :     else if (sClass == "GtkMenu")
    2406             :     {
    2407           0 :         handleMenu(reader, sID);
    2408           0 :         return NULL;
    2409             :     }
    2410           0 :     else if (sClass == "GtkSizeGroup")
    2411             :     {
    2412           0 :         handleSizeGroup(reader, sID);
    2413           0 :         return NULL;
    2414             :     }
    2415           0 :     else if (sClass == "AtkObject")
    2416             :     {
    2417           0 :         handleAtkObject(reader, sID, pParent);
    2418           0 :         return NULL;
    2419             :     }
    2420             : 
    2421           0 :     int nLevel = 1;
    2422             : 
    2423           0 :     stringmap aProperties, aPangoAttributes, aAtkAttributes;
    2424           0 :     std::vector<OString> aItems;
    2425             : 
    2426           0 :     if (!sCustomProperty.isEmpty())
    2427           0 :         aProperties[OString("customproperty")] = sCustomProperty;
    2428             : 
    2429           0 :     Window *pCurrentChild = NULL;
    2430             :     while(1)
    2431             :     {
    2432             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2433           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2434             : 
    2435           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2436           0 :             break;
    2437             : 
    2438           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2439             :         {
    2440           0 :             if (name.equals("child"))
    2441             :             {
    2442           0 :                 if (!pCurrentChild)
    2443             :                 {
    2444             :                     pCurrentChild = insertObject(pParent, sClass, sID,
    2445           0 :                         aProperties, aPangoAttributes, aAtkAttributes, aItems);
    2446             :                 }
    2447           0 :                 handleChild(pCurrentChild, reader);
    2448             :             }
    2449           0 :             else if (name.equals("items"))
    2450           0 :                 aItems = handleItems(reader, sID);
    2451             :             else
    2452             :             {
    2453           0 :                 ++nLevel;
    2454           0 :                 if (name.equals("property"))
    2455           0 :                     collectProperty(reader, sID, aProperties);
    2456           0 :                 else if (name.equals("attribute"))
    2457           0 :                     collectPangoAttribute(reader, aPangoAttributes);
    2458           0 :                 else if (name.equals("relation"))
    2459           0 :                     collectAtkAttribute(reader, aAtkAttributes);
    2460           0 :                 else if (name.equals("action-widget"))
    2461           0 :                     handleActionWidget(reader);
    2462             :             }
    2463             :         }
    2464             : 
    2465           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2466             :         {
    2467           0 :             --nLevel;
    2468             :         }
    2469             : 
    2470           0 :         if (!nLevel)
    2471           0 :             break;
    2472             :     }
    2473             : 
    2474           0 :     if (sClass == "GtkAdjustment")
    2475             :     {
    2476           0 :         handleAdjustment(sID, aProperties);
    2477           0 :         return NULL;
    2478             :     }
    2479           0 :     else if (sClass == "GtkTextBuffer")
    2480             :     {
    2481           0 :         handleTextBuffer(sID, aProperties);
    2482           0 :         return NULL;
    2483             :     }
    2484             : 
    2485           0 :     if (!pCurrentChild)
    2486             :     {
    2487             :         pCurrentChild = insertObject(pParent, sClass, sID, aProperties,
    2488           0 :             aPangoAttributes, aAtkAttributes, aItems);
    2489             :     }
    2490             : 
    2491           0 :     return pCurrentChild;
    2492             : }
    2493             : 
    2494           0 : void VclBuilder::handlePacking(Window *pCurrent, xmlreader::XmlReader &reader)
    2495             : {
    2496           0 :     xmlreader::Span name;
    2497             :     int nsId;
    2498             : 
    2499           0 :     int nLevel = 1;
    2500             : 
    2501             :     while(1)
    2502             :     {
    2503             :         xmlreader::XmlReader::Result res = reader.nextItem(
    2504           0 :             xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
    2505             : 
    2506           0 :         if (res == xmlreader::XmlReader::RESULT_DONE)
    2507           0 :             break;
    2508             : 
    2509           0 :         if (res == xmlreader::XmlReader::RESULT_BEGIN)
    2510             :         {
    2511           0 :             ++nLevel;
    2512           0 :             if (name.equals("property"))
    2513           0 :                 applyPackingProperty(pCurrent, reader);
    2514             :         }
    2515             : 
    2516           0 :         if (res == xmlreader::XmlReader::RESULT_END)
    2517             :         {
    2518           0 :             --nLevel;
    2519             :         }
    2520             : 
    2521           0 :         if (!nLevel)
    2522           0 :             break;
    2523           0 :     }
    2524           0 : }
    2525             : 
    2526           0 : void VclBuilder::applyPackingProperty(Window *pCurrent,
    2527             :     xmlreader::XmlReader &reader)
    2528             : {
    2529           0 :     if (!pCurrent)
    2530           0 :         return;
    2531             : 
    2532           0 :     xmlreader::Span name;
    2533             :     int nsId;
    2534             : 
    2535           0 :     if (pCurrent->GetType() == WINDOW_SCROLLWINDOW)
    2536             :     {
    2537           0 :         std::map<Window*, Window*>::iterator aFind = m_pParserState->m_aRedundantParentWidgets.find(pCurrent);
    2538           0 :         if (aFind != m_pParserState->m_aRedundantParentWidgets.end())
    2539             :         {
    2540           0 :             pCurrent = aFind->second;
    2541             :             assert(pCurrent);
    2542             :         }
    2543             :     }
    2544             : 
    2545           0 :     while (reader.nextAttribute(&nsId, &name))
    2546             :     {
    2547           0 :         if (name.equals("name"))
    2548             :         {
    2549           0 :             name = reader.getAttributeValue(false);
    2550           0 :             OString sKey(name.begin, name.length);
    2551           0 :             sKey = sKey.replace('_', '-');
    2552             :             reader.nextItem(
    2553           0 :                 xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
    2554           0 :             OString sValue(name.begin, name.length);
    2555             : 
    2556           0 :             if (sKey == "expand")
    2557             :             {
    2558           0 :                 bool bTrue = (sValue[0] == 't' || sValue[0] == 'T' || sValue[0] == '1');
    2559           0 :                 pCurrent->set_expand(bTrue);
    2560             :             }
    2561           0 :             else if (sKey == "fill")
    2562             :             {
    2563           0 :                 bool bTrue = (sValue[0] == 't' || sValue[0] == 'T' || sValue[0] == '1');
    2564           0 :                 pCurrent->set_fill(bTrue);
    2565             :             }
    2566           0 :             else if (sKey == "pack-type")
    2567             :             {
    2568           0 :                 VclPackType ePackType = (sValue[0] == 'e' || sValue[0] == 'E') ? VCL_PACK_END : VCL_PACK_START;
    2569           0 :                 pCurrent->set_pack_type(ePackType);
    2570             :             }
    2571           0 :             else if (sKey == "left-attach")
    2572             :             {
    2573           0 :                 pCurrent->set_grid_left_attach(sValue.toInt32());
    2574             :             }
    2575           0 :             else if (sKey == "top-attach")
    2576             :             {
    2577           0 :                 pCurrent->set_grid_top_attach(sValue.toInt32());
    2578             :             }
    2579           0 :             else if (sKey == "width")
    2580             :             {
    2581           0 :                 pCurrent->set_grid_width(sValue.toInt32());
    2582             :             }
    2583           0 :             else if (sKey == "height")
    2584             :             {
    2585           0 :                 pCurrent->set_grid_height(sValue.toInt32());
    2586             :             }
    2587           0 :             else if (sKey == "padding")
    2588             :             {
    2589           0 :                 pCurrent->set_padding(sValue.toInt32());
    2590             :             }
    2591           0 :             else if (sKey == "position")
    2592             :             {
    2593           0 :                 set_window_packing_position(pCurrent, sValue.toInt32());
    2594             :             }
    2595           0 :             else if (sKey == "secondary")
    2596             :             {
    2597           0 :                 pCurrent->set_secondary(toBool(sValue));
    2598             :             }
    2599             :             else
    2600             :             {
    2601             :                 SAL_WARN("vcl.layout", "unknown packing: " << sKey.getStr());
    2602           0 :             }
    2603             :         }
    2604             :     }
    2605             : }
    2606             : 
    2607           0 : OString VclBuilder::getTranslation(const OString &rID, const OString &rProperty) const
    2608             : {
    2609           0 :     Translations::const_iterator aWidgetFind = m_pParserState->m_aTranslations.find(rID);
    2610           0 :     if (aWidgetFind != m_pParserState->m_aTranslations.end())
    2611             :     {
    2612           0 :         const WidgetTranslations &rWidgetTranslations = aWidgetFind->second;
    2613           0 :         WidgetTranslations::const_iterator aPropertyFind = rWidgetTranslations.find(rProperty);
    2614           0 :         if (aPropertyFind != rWidgetTranslations.end())
    2615           0 :             return aPropertyFind->second;
    2616             :     }
    2617           0 :     return OString();
    2618             : }
    2619             : 
    2620           0 : void VclBuilder::collectProperty(xmlreader::XmlReader &reader, const OString &rID, stringmap &rMap)
    2621             : {
    2622           0 :     xmlreader::Span name;
    2623             :     int nsId;
    2624             : 
    2625           0 :     OString sProperty;
    2626           0 :     OString sValue;
    2627             : 
    2628           0 :     bool bTranslated = false;
    2629             : 
    2630           0 :     while (reader.nextAttribute(&nsId, &name))
    2631             :     {
    2632           0 :         if (name.equals("name"))
    2633             :         {
    2634           0 :             name = reader.getAttributeValue(false);
    2635           0 :             sProperty = OString(name.begin, name.length);
    2636             :         }
    2637           0 :         else if (name.equals("translatable") && reader.getAttributeValue(false).equals("yes"))
    2638             :         {
    2639           0 :             sValue = getTranslation(rID, sProperty);
    2640           0 :             bTranslated = !sValue.isEmpty();
    2641             :         }
    2642             : 
    2643             :     }
    2644             : 
    2645           0 :     reader.nextItem(xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
    2646           0 :     if (!bTranslated)
    2647           0 :         sValue = OString(name.begin, name.length);
    2648             : 
    2649           0 :     if (!sProperty.isEmpty())
    2650             :     {
    2651           0 :         sProperty = sProperty.replace('_', '-');
    2652           0 :         if (m_pStringReplace)
    2653             :         {
    2654           0 :             OUString sTmp = (*m_pStringReplace)(OStringToOUString(sValue, RTL_TEXTENCODING_UTF8));
    2655           0 :             rMap[sProperty] = OUStringToOString(sTmp, RTL_TEXTENCODING_UTF8);
    2656             :         }
    2657             :         else
    2658             :         {
    2659           0 :             rMap[sProperty] = sValue;
    2660             :         }
    2661           0 :     }
    2662           0 : }
    2663             : 
    2664           0 : void VclBuilder::handleActionWidget(xmlreader::XmlReader &reader)
    2665             : {
    2666           0 :     xmlreader::Span name;
    2667             :     int nsId;
    2668             : 
    2669           0 :     OString sResponse;
    2670             : 
    2671           0 :     while (reader.nextAttribute(&nsId, &name))
    2672             :     {
    2673           0 :         if (name.equals("response"))
    2674             :         {
    2675           0 :             name = reader.getAttributeValue(false);
    2676           0 :             sResponse = OString(name.begin, name.length);
    2677             :         }
    2678             :     }
    2679             : 
    2680           0 :     reader.nextItem(xmlreader::XmlReader::TEXT_RAW, &name, &nsId);
    2681           0 :     OString sID = OString(name.begin, name.length);
    2682           0 :     sal_Int32 nDelim = sID.indexOf(':');
    2683           0 :     if (nDelim != -1)
    2684           0 :         sID = sID.copy(0, nDelim);
    2685           0 :     set_response(sID, sResponse.toInt32());
    2686           0 : }
    2687             : 
    2688             : 
    2689           0 : void VclBuilder::collectAccelerator(xmlreader::XmlReader &reader, stringmap &rMap)
    2690             : {
    2691           0 :     xmlreader::Span name;
    2692             :     int nsId;
    2693             : 
    2694           0 :     OString sProperty;
    2695           0 :     OString sValue;
    2696             : 
    2697           0 :     while (reader.nextAttribute(&nsId, &name))
    2698             :     {
    2699           0 :         if (name.equals("key"))
    2700             :         {
    2701           0 :             name = reader.getAttributeValue(false);
    2702           0 :             sValue = OString(name.begin, name.length);
    2703             :         }
    2704           0 :         else if (name.equals("signal"))
    2705             :         {
    2706           0 :             name = reader.getAttributeValue(false);
    2707           0 :             sProperty = OString(name.begin, name.length);
    2708             :         }
    2709             : 
    2710             :     }
    2711             : 
    2712           0 :     if (!sProperty.isEmpty() && !sValue.isEmpty())
    2713             :     {
    2714           0 :         rMap[sProperty] = sValue;
    2715           0 :     }
    2716           0 : }
    2717             : 
    2718           0 : Window *VclBuilder::get_widget_root()
    2719             : {
    2720           0 :     return m_aChildren.empty() ? NULL : m_aChildren[0].m_pWindow;
    2721             : }
    2722             : 
    2723           0 : Window *VclBuilder::get_by_name(OString sID)
    2724             : {
    2725           0 :     for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
    2726           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2727             :     {
    2728           0 :         if (aI->m_sID.equals(sID))
    2729           0 :             return aI->m_pWindow;
    2730             :     }
    2731             : 
    2732           0 :     return NULL;
    2733             : }
    2734             : 
    2735           0 : PopupMenu *VclBuilder::get_menu(OString sID)
    2736             : {
    2737           0 :     for (std::vector<MenuAndId>::iterator aI = m_aMenus.begin(),
    2738           0 :          aEnd = m_aMenus.end(); aI != aEnd; ++aI)
    2739             :     {
    2740           0 :         if (aI->m_sID.equals(sID))
    2741           0 :             return aI->m_pMenu;
    2742             :     }
    2743             : 
    2744           0 :     return NULL;
    2745             : }
    2746             : 
    2747           0 : short VclBuilder::get_response(const Window *pWindow) const
    2748             : {
    2749           0 :     for (std::vector<WinAndId>::const_iterator aI = m_aChildren.begin(),
    2750           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2751             :     {
    2752           0 :         if (aI->m_pWindow == pWindow)
    2753             :         {
    2754           0 :             return aI->m_nResponseId;
    2755             :         }
    2756             :     }
    2757             : 
    2758             :     //how did we not find sID ?
    2759             :     assert(false);
    2760           0 :     return RET_CANCEL;
    2761             : }
    2762             : 
    2763           0 : void VclBuilder::set_response(OString sID, short nResponse)
    2764             : {
    2765           0 :     for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
    2766           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2767             :     {
    2768           0 :         if (aI->m_sID.equals(sID))
    2769             :         {
    2770           0 :             aI->m_nResponseId = nResponse;
    2771           0 :             return;
    2772             :         }
    2773             :     }
    2774             : 
    2775             :     //how did we not find sID ?
    2776             :     assert(false);
    2777             : }
    2778             : 
    2779           0 : void VclBuilder::delete_by_name(OString sID)
    2780             : {
    2781           0 :     for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
    2782           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2783             :     {
    2784           0 :         if (aI->m_sID.equals(sID))
    2785             :         {
    2786           0 :             delete aI->m_pWindow;
    2787           0 :             m_aChildren.erase(aI);
    2788           0 :             break;
    2789             :         }
    2790             :     }
    2791           0 : }
    2792             : 
    2793           0 : void VclBuilder::delete_by_window(const Window *pWindow)
    2794             : {
    2795           0 :     for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
    2796           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2797             :     {
    2798           0 :         if (aI->m_pWindow == pWindow)
    2799             :         {
    2800           0 :             delete aI->m_pWindow;
    2801           0 :             m_aChildren.erase(aI);
    2802           0 :             break;
    2803             :         }
    2804             :     }
    2805           0 : }
    2806             : 
    2807           0 : OString VclBuilder::get_by_window(const Window *pWindow) const
    2808             : {
    2809           0 :     for (std::vector<WinAndId>::const_iterator aI = m_aChildren.begin(),
    2810           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2811             :     {
    2812           0 :         if (aI->m_pWindow == pWindow)
    2813           0 :             return aI->m_sID;
    2814             :     }
    2815             : 
    2816           0 :     return OString();
    2817             : }
    2818             : 
    2819           0 : VclBuilder::PackingData VclBuilder::get_window_packing_data(const Window *pWindow) const
    2820             : {
    2821             :     //We've stored the return of new Control, some of these get
    2822             :     //border windows placed around them which are what you get
    2823             :     //from GetChild, so scoot up a level if necessary to get the
    2824             :     //window whose position value we have
    2825             :     const Window *pPropHolder = pWindow->mpWindowImpl->mpClientWindow ?
    2826           0 :         pWindow->mpWindowImpl->mpClientWindow : pWindow;
    2827             : 
    2828           0 :     for (std::vector<WinAndId>::const_iterator aI = m_aChildren.begin(),
    2829           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2830             :     {
    2831           0 :         if (aI->m_pWindow == pPropHolder)
    2832           0 :             return aI->m_aPackingData;
    2833             :     }
    2834             : 
    2835           0 :     return PackingData();
    2836             : }
    2837             : 
    2838           0 : void VclBuilder::set_window_packing_position(const Window *pWindow, sal_Int32 nPosition)
    2839             : {
    2840           0 :     for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
    2841           0 :          aEnd = m_aChildren.end(); aI != aEnd; ++aI)
    2842             :     {
    2843           0 :         if (aI->m_pWindow == pWindow)
    2844           0 :             aI->m_aPackingData.m_nPosition = nPosition;
    2845             :     }
    2846           0 : }
    2847             : 
    2848           0 : const VclBuilder::ListStore *VclBuilder::get_model_by_name(OString sID) const
    2849             : {
    2850           0 :     std::map<OString, ListStore>::const_iterator aI = m_pParserState->m_aModels.find(sID);
    2851           0 :     if (aI != m_pParserState->m_aModels.end())
    2852           0 :         return &(aI->second);
    2853           0 :     return NULL;
    2854             : }
    2855             : 
    2856           0 : const VclBuilder::TextBuffer *VclBuilder::get_buffer_by_name(OString sID) const
    2857             : {
    2858           0 :     std::map<OString, TextBuffer>::const_iterator aI = m_pParserState->m_aTextBuffers.find(sID);
    2859           0 :     if (aI != m_pParserState->m_aTextBuffers.end())
    2860           0 :         return &(aI->second);
    2861           0 :     return NULL;
    2862             : }
    2863             : 
    2864           0 : const VclBuilder::Adjustment *VclBuilder::get_adjustment_by_name(OString sID) const
    2865             : {
    2866           0 :     std::map<OString, Adjustment>::const_iterator aI = m_pParserState->m_aAdjustments.find(sID);
    2867           0 :     if (aI != m_pParserState->m_aAdjustments.end())
    2868           0 :         return &(aI->second);
    2869           0 :     return NULL;
    2870             : }
    2871             : 
    2872           0 : void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId)
    2873             : {
    2874           0 :     for (std::vector<ListStore::row>::const_iterator aI = rStore.m_aEntries.begin(), aEnd = rStore.m_aEntries.end();
    2875             :         aI != aEnd; ++aI)
    2876             :     {
    2877           0 :         const ListStore::row &rRow = *aI;
    2878           0 :         sal_uInt16 nEntry = rTarget.InsertEntry(OStringToOUString(rRow[0], RTL_TEXTENCODING_UTF8));
    2879           0 :         if (rRow.size() > 1)
    2880             :         {
    2881           0 :             sal_IntPtr nValue = rRow[1].toInt32();
    2882           0 :             rTarget.SetEntryData(nEntry, (void*)nValue);
    2883             :         }
    2884             :     }
    2885           0 :     if (nActiveId < rStore.m_aEntries.size())
    2886           0 :         rTarget.SelectEntryPos(nActiveId);
    2887           0 : }
    2888             : 
    2889           0 : void VclBuilder::mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment)
    2890             : {
    2891           0 :     int nMul = rtl_math_pow10Exp(1, rTarget.GetDecimalDigits());
    2892             : 
    2893           0 :     for (stringmap::const_iterator aI = rAdjustment.begin(), aEnd = rAdjustment.end(); aI != aEnd; ++aI)
    2894             :     {
    2895           0 :         const OString &rKey = aI->first;
    2896           0 :         const OString &rValue = aI->second;
    2897             : 
    2898           0 :         if (rKey == "upper")
    2899             :         {
    2900           0 :             sal_Int64 nUpper = rValue.toDouble() * nMul;
    2901           0 :             rTarget.SetMax(nUpper);
    2902           0 :             rTarget.SetLast(nUpper);
    2903             :         }
    2904           0 :         else if (rKey == "lower")
    2905             :         {
    2906           0 :             sal_Int64 nLower = rValue.toDouble() * nMul;
    2907           0 :             rTarget.SetMin(nLower);
    2908           0 :             rTarget.SetFirst(nLower);
    2909             :         }
    2910           0 :         else if (rKey == "value")
    2911             :         {
    2912           0 :             sal_Int64 nValue = rValue.toDouble() * nMul;
    2913           0 :             rTarget.SetValue(nValue);
    2914             :         }
    2915           0 :         else if (rKey == "step-increment")
    2916             :         {
    2917           0 :             sal_Int64 nSpinSize = rValue.toDouble() * nMul;
    2918           0 :             rTarget.SetSpinSize(nSpinSize);
    2919             :         }
    2920             :         else
    2921             :         {
    2922             :             SAL_INFO("vcl.layout", "unhandled property :" << rKey.getStr());
    2923             :         }
    2924             :     }
    2925           0 : }
    2926             : 
    2927           0 : void VclBuilder::mungeAdjustment(TimeField &rTarget, const Adjustment &rAdjustment)
    2928             : {
    2929           0 :     for (stringmap::const_iterator aI = rAdjustment.begin(), aEnd = rAdjustment.end(); aI != aEnd; ++aI)
    2930             :     {
    2931           0 :         const OString &rKey = aI->first;
    2932           0 :         const OString &rValue = aI->second;
    2933             : 
    2934           0 :         if (rKey == "upper")
    2935             :         {
    2936           0 :             Time aUpper(rValue.toInt32());
    2937           0 :             rTarget.SetMax(aUpper);
    2938           0 :             rTarget.SetLast(aUpper);
    2939             :         }
    2940           0 :         else if (rKey == "lower")
    2941             :         {
    2942           0 :             Time aLower(rValue.toInt32());
    2943           0 :             rTarget.SetMin(aLower);
    2944           0 :             rTarget.SetFirst(aLower);
    2945             :         }
    2946           0 :         else if (rKey == "value")
    2947             :         {
    2948           0 :             Time aValue(rValue.toInt32());
    2949           0 :             rTarget.SetTime(aValue);
    2950             :         }
    2951             :         else
    2952             :         {
    2953             :             SAL_INFO("vcl.layout", "unhandled property :" << rKey.getStr());
    2954             :         }
    2955             :     }
    2956           0 : }
    2957             : 
    2958           0 : void VclBuilder::mungeAdjustment(DateField &rTarget, const Adjustment &rAdjustment)
    2959             : {
    2960           0 :     for (stringmap::const_iterator aI = rAdjustment.begin(), aEnd = rAdjustment.end(); aI != aEnd; ++aI)
    2961             :     {
    2962           0 :         const OString &rKey = aI->first;
    2963           0 :         const OString &rValue = aI->second;
    2964             : 
    2965           0 :         if (rKey == "upper")
    2966             :         {
    2967           0 :             Date aUpper(rValue.toInt32());
    2968           0 :             rTarget.SetMax(aUpper);
    2969           0 :             rTarget.SetLast(aUpper);
    2970             :         }
    2971           0 :         else if (rKey == "lower")
    2972             :         {
    2973           0 :             Date aLower(rValue.toInt32());
    2974           0 :             rTarget.SetMin(aLower);
    2975           0 :             rTarget.SetFirst(aLower);
    2976             :         }
    2977           0 :         else if (rKey == "value")
    2978             :         {
    2979           0 :             Date aValue(rValue.toInt32());
    2980           0 :             rTarget.SetDate(aValue);
    2981             :         }
    2982             :         else
    2983             :         {
    2984             :             SAL_INFO("vcl.layout", "unhandled property :" << rKey.getStr());
    2985             :         }
    2986             :     }
    2987           0 : }
    2988             : 
    2989           0 : void VclBuilder::mungeAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment)
    2990             : {
    2991           0 :     for (stringmap::const_iterator aI = rAdjustment.begin(), aEnd = rAdjustment.end(); aI != aEnd; ++aI)
    2992             :     {
    2993           0 :         const OString &rKey = aI->first;
    2994           0 :         const OString &rValue = aI->second;
    2995             : 
    2996           0 :         if (rKey == "upper")
    2997           0 :             rTarget.SetRangeMax(rValue.toInt32());
    2998           0 :         else if (rKey == "lower")
    2999           0 :             rTarget.SetRangeMin(rValue.toInt32());
    3000           0 :         else if (rKey == "value")
    3001           0 :             rTarget.SetThumbPos(rValue.toInt32());
    3002           0 :         else if (rKey == "step-increment")
    3003           0 :             rTarget.SetLineSize(rValue.toInt32());
    3004           0 :         else if (rKey == "page-increment")
    3005           0 :             rTarget.SetPageSize(rValue.toInt32());
    3006             :         else
    3007             :         {
    3008             :             SAL_INFO("vcl.layout", "unhandled property :" << rKey.getStr());
    3009             :         }
    3010             :     }
    3011           0 : }
    3012             : 
    3013           0 : void VclBuilder::mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rTextBuffer)
    3014             : {
    3015           0 :     for (stringmap::const_iterator aI = rTextBuffer.begin(), aEnd = rTextBuffer.end(); aI != aEnd; ++aI)
    3016             :     {
    3017           0 :         const OString &rKey = aI->first;
    3018           0 :         const OString &rValue = aI->second;
    3019             : 
    3020           0 :         if (rKey == "text")
    3021           0 :             rTarget.SetText(OStringToOUString(rValue, RTL_TEXTENCODING_UTF8));
    3022             :         else
    3023             :         {
    3024             :             SAL_INFO("vcl.layout", "unhandled property :" << rKey.getStr());
    3025             :         }
    3026             :     }
    3027         465 : }
    3028             : 
    3029             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10