2012-03-26 12:15:22 +01:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version : MPL 1.1 / GPLv3 + / LGPLv3 +
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 ( the " License " ) ; you may not use this file except in compliance with
* the License . You may obtain a copy of the License at
* http : //www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
* for the specific language governing rights and limitations under the
* License .
*
* The Initial Developer of the Original Code is
* Caolán McNamara < caolanm @ redhat . com > ( Red Hat , Inc . )
2012-03-27 14:20:17 +01:00
* Portions created by the Initial Developer are Copyright ( C ) 2012 the
2012-03-26 12:15:22 +01:00
* Initial Developer . All Rights Reserved .
*
* Contributor ( s ) : Caolán McNamara < caolanm @ redhat . com >
*
* Alternatively , the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later ( the " GPLv3+ " ) , or
* the GNU Lesser General Public License Version 3 or later ( the " LGPLv3+ " ) ,
* in which case the provisions of the GPLv3 + or the LGPLv3 + are applicable
* instead of those above .
*/
# include <vcl/builder.hxx>
# include <vcl/button.hxx>
# include <vcl/dialog.hxx>
2012-03-27 14:32:24 +01:00
# include <vcl/edit.hxx>
2012-04-04 09:30:41 +01:00
# include <vcl/field.hxx>
2012-03-26 12:15:22 +01:00
# include <vcl/fixed.hxx>
# include <vcl/layout.hxx>
2012-04-04 09:30:41 +01:00
# include <vcl/lstbox.hxx>
2012-06-07 15:11:02 +01:00
# include <vcl/tabctrl.hxx>
# include <vcl/tabpage.hxx>
2012-05-22 12:33:28 +01:00
# include <window.h>
2012-03-26 12:15:22 +01:00
2012-04-25 11:12:55 +01:00
VclBuilder : : VclBuilder ( Window * pParent , rtl : : OUString sUri , rtl : : OString sID )
: m_sID ( sID )
, m_pParent ( pParent )
2012-03-26 12:15:22 +01:00
{
xmlreader : : XmlReader reader ( sUri ) ;
2012-03-27 14:20:17 +01:00
handleChild ( pParent , reader ) ;
2012-03-26 12:15:22 +01:00
2012-04-30 10:19:19 +01:00
//Set radiobutton groups when everything has been imported
2012-06-06 08:56:46 +01:00
for ( std : : vector < RadioButtonGroupMap > : : iterator aI = m_aGroupMaps . begin ( ) ,
aEnd = m_aGroupMaps . end ( ) ; aI ! = aEnd ; + + aI )
2012-04-30 10:19:19 +01:00
{
RadioButton * pOne = static_cast < RadioButton * > ( get_by_name ( aI - > m_sID ) ) ;
2012-06-06 08:56:46 +01:00
RadioButton * pOther = static_cast < RadioButton * > ( get_by_name ( aI - > m_sValue ) ) ;
2012-04-30 10:19:19 +01:00
SAL_WARN_IF ( ! pOne | | ! pOther , " vcl " , " missing member of radiobutton group " ) ;
if ( pOne & & pOther )
pOne - > group ( * pOther ) ;
}
//drop maps now
2012-06-06 08:56:46 +01:00
std : : vector < RadioButtonGroupMap > ( ) . swap ( m_aGroupMaps ) ;
//Set ComboBox models when everything has been imported
for ( std : : vector < ComboBoxModelMap > : : iterator aI = m_aModelMaps . begin ( ) ,
aEnd = m_aModelMaps . end ( ) ; aI ! = aEnd ; + + aI )
{
ListBox * pTarget = static_cast < ListBox * > ( get_by_name ( aI - > m_sID ) ) ;
ListStore * pStore = static_cast < ListStore * > ( get_model_by_name ( aI - > m_sValue ) ) ;
SAL_WARN_IF ( ! pTarget | | ! pStore , " vcl " , " missing elements of combobox/liststore " ) ;
if ( pTarget & & pStore )
mungemodel ( * pTarget , * pStore ) ;
}
//drop maps now
std : : vector < ComboBoxModelMap > ( ) . swap ( m_aModelMaps ) ;
for ( std : : vector < ModelAndId > : : iterator aI = m_aModels . begin ( ) ,
aEnd = m_aModels . end ( ) ; aI ! = aEnd ; + + aI )
{
delete aI - > m_pModel ;
}
std : : vector < ModelAndId > ( ) . swap ( m_aModels ) ;
2012-04-30 10:19:19 +01:00
//auto-show (really necessary ?, maybe drop it when complete)
2012-04-25 11:12:55 +01:00
for ( std : : vector < WinAndId > : : iterator aI = m_aChildren . begin ( ) ,
2012-03-26 12:15:22 +01:00
aEnd = m_aChildren . end ( ) ; aI ! = aEnd ; + + aI )
{
2012-04-25 11:12:55 +01:00
Window * pWindow = aI - > m_pWindow ;
2012-03-26 12:15:22 +01:00
if ( pWindow )
{
pWindow - > Show ( ) ;
}
}
}
VclBuilder : : ~ VclBuilder ( )
{
2012-04-25 11:12:55 +01:00
for ( std : : vector < WinAndId > : : reverse_iterator aI = m_aChildren . rbegin ( ) ,
2012-03-26 12:15:22 +01:00
aEnd = m_aChildren . rend ( ) ; aI ! = aEnd ; + + aI )
{
2012-05-22 12:33:28 +01:00
if ( aI - > m_bOwned )
delete aI - > m_pWindow ;
2012-03-26 12:15:22 +01:00
}
}
2012-04-16 11:33:57 +01:00
namespace
{
bool extractOrientation ( VclBuilder : : stringmap & rMap )
{
bool bVertical = false ;
VclBuilder : : stringmap : : iterator aFind = rMap . find ( rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " orientation " ) ) ) ;
if ( aFind ! = rMap . end ( ) )
{
bVertical = aFind - > second . equalsIgnoreAsciiCaseL ( RTL_CONSTASCII_STRINGPARAM ( " vertical " ) ) ;
rMap . erase ( aFind ) ;
}
return bVertical ;
}
Window * extractStockAndBuildButton ( Window * pParent , VclBuilder : : stringmap & rMap )
{
WinBits nBits = WB_CENTER | WB_VCENTER | WB_3DLOOK ;
bool bIsStock = false ;
VclBuilder : : stringmap : : iterator aFind = rMap . find ( rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " use-stock " ) ) ) ;
if ( aFind ! = rMap . end ( ) )
{
bIsStock = toBool ( aFind - > second ) ;
rMap . erase ( aFind ) ;
}
Window * pWindow = NULL ;
if ( bIsStock )
{
rtl : : OString sType ;
aFind = rMap . find ( rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " label " ) ) ) ;
if ( aFind ! = rMap . end ( ) )
{
sType = aFind - > second ;
rMap . erase ( aFind ) ;
}
if ( sType . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " gtk-ok " ) ) )
pWindow = new OKButton ( pParent , nBits ) ;
else if ( sType . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " gtk-cancel " ) ) )
pWindow = new CancelButton ( pParent , nBits ) ;
else if ( sType . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " gtk-help " ) ) )
pWindow = new HelpButton ( pParent , nBits ) ;
else
fprintf ( stderr , " unknown stock type %s \n " , sType . getStr ( ) ) ;
}
if ( ! pWindow )
pWindow = new PushButton ( pParent , nBits ) ;
return pWindow ;
}
}
2012-04-30 10:19:19 +01:00
bool VclBuilder : : extractGroup ( const rtl : : OString & id , stringmap & rMap )
{
VclBuilder : : stringmap : : iterator aFind = rMap . find ( rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " group " ) ) ) ;
if ( aFind ! = rMap . end ( ) )
{
2012-06-06 08:56:46 +01:00
m_aGroupMaps . push_back ( RadioButtonGroupMap ( id , aFind - > second ) ) ;
rMap . erase ( aFind ) ;
return true ;
}
return false ;
}
bool VclBuilder : : extractModel ( const rtl : : OString & id , stringmap & rMap )
{
VclBuilder : : stringmap : : iterator aFind = rMap . find ( rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " model " ) ) ) ;
if ( aFind ! = rMap . end ( ) )
{
m_aModelMaps . push_back ( ComboBoxModelMap ( id , aFind - > second ) ) ;
2012-04-30 10:19:19 +01:00
rMap . erase ( aFind ) ;
return true ;
}
return false ;
}
Window * VclBuilder : : makeObject ( Window * pParent , const rtl : : OString & name , const rtl : : OString & id , stringmap & rMap )
2012-03-26 12:15:22 +01:00
{
2012-06-09 10:33:31 +01:00
if ( pParent & & pParent - > GetType ( ) = = WINDOW_TABCONTROL )
2012-06-07 15:11:02 +01:00
{
//We have to add a page
2012-06-12 16:02:26 +01:00
//make default pageid == -position. Partitioning the
//id space into negative numbers for auto-generated
//ids and positive numbers for the handleTabChild
//derived ids
TabControl * pTabControl = static_cast < TabControl * > ( pParent ) ;
sal_uInt16 nNewPageId = - ( pTabControl - > GetPageCount ( ) + 1 ) ;
2012-06-07 15:11:02 +01:00
pTabControl - > InsertPage ( nNewPageId , rtl : : OUString ( ) ) ;
pTabControl - > SetCurPageId ( nNewPageId ) ;
2012-06-12 16:02:26 +01:00
bool bIsPlaceHolder = name . isEmpty ( ) ;
if ( ! bIsPlaceHolder )
{
TabPage * pPage = new TabPage ( pTabControl ) ;
m_aChildren . push_back ( WinAndId ( rtl : : OString ( ) , pPage ) ) ;
//And give the page one container as a child to make it a layout enabled
//tab page
VclBin * pContainer = new VclBin ( pPage ) ;
m_aChildren . push_back ( WinAndId ( rtl : : OString ( ) , pContainer ) ) ;
pParent = pContainer ;
pTabControl - > SetTabPage ( nNewPageId , pPage ) ;
}
2012-06-07 15:11:02 +01:00
}
2012-03-26 12:15:22 +01:00
Window * pWindow = NULL ;
2012-03-27 14:20:17 +01:00
if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkDialog " ) ) )
2012-04-05 21:28:08 +01:00
pWindow = new Dialog ( pParent , WB_SIZEMOVE | WB_3DLOOK | WB_CLOSEABLE ) ;
2012-03-27 14:20:17 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkBox " ) ) )
{
2012-04-16 11:33:57 +01:00
if ( extractOrientation ( rMap ) )
2012-03-27 14:20:17 +01:00
pWindow = new VclVBox ( pParent ) ;
else
pWindow = new VclHBox ( pParent ) ;
}
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkButtonBox " ) ) )
{
2012-04-16 11:33:57 +01:00
if ( extractOrientation ( rMap ) )
2012-03-27 14:20:17 +01:00
pWindow = new VclVButtonBox ( pParent ) ;
else
pWindow = new VclHButtonBox ( pParent ) ;
}
2012-04-05 20:43:33 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkGrid " ) ) )
pWindow = new VclGrid ( pParent ) ;
2012-04-11 11:41:54 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkFrame " ) ) )
pWindow = new VclFrame ( pParent ) ;
2012-04-16 10:12:57 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkAlignment " ) ) )
pWindow = new VclAlignment ( pParent ) ;
2012-03-27 14:20:17 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkButton " ) ) )
2012-04-16 11:33:57 +01:00
pWindow = extractStockAndBuildButton ( pParent , rMap ) ;
2012-03-27 14:20:17 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkRadioButton " ) ) )
2012-04-30 10:19:19 +01:00
{
extractGroup ( id , rMap ) ;
2012-04-04 09:30:41 +01:00
pWindow = new RadioButton ( pParent , WB_CENTER | WB_VCENTER | WB_3DLOOK ) ;
2012-04-30 10:19:19 +01:00
}
2012-03-27 14:32:24 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkCheckButton " ) ) )
2012-04-04 09:30:41 +01:00
pWindow = new CheckBox ( pParent , WB_CENTER | WB_VCENTER | WB_3DLOOK ) ;
2012-03-27 16:32:28 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkSpinButton " ) ) )
2012-05-23 14:25:22 +01:00
pWindow = new MetricField ( pParent , WB_RIGHT | WB_SPIN | WB_BORDER | WB_3DLOOK ) ;
2012-03-27 16:32:28 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkComboBox " ) ) )
2012-06-06 08:56:46 +01:00
{
extractModel ( id , rMap ) ;
2012-06-13 16:31:45 +01:00
ListBox * pListBox = new ListBox ( pParent , WB_LEFT | WB_DROPDOWN | WB_VCENTER | WB_3DLOOK ) ;
pListBox - > SetDropDownLineCount ( 64 ) ; //arbitrary
pWindow = pListBox ;
2012-06-06 08:56:46 +01:00
}
2012-06-08 20:59:06 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkTreeView " ) ) )
{
extractModel ( id , rMap ) ;
pWindow = new ListBox ( pParent , WB_LEFT | WB_VCENTER | WB_3DLOOK ) ;
}
2012-03-27 14:20:17 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkLabel " ) ) )
2012-04-04 09:30:41 +01:00
pWindow = new FixedText ( pParent , WB_CENTER | WB_VCENTER | WB_3DLOOK ) ;
2012-03-27 14:32:24 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkEntry " ) ) )
2012-06-07 15:11:02 +01:00
pWindow = new Edit ( pParent , WB_LEFT | WB_VCENTER | WB_BORDER | WB_3DLOOK ) ;
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkNotebook " ) ) )
pWindow = new TabControl ( pParent , WB_STDTABCONTROL | WB_3DLOOK ) ;
2012-06-07 23:03:18 +01:00
else if ( name . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkDrawingArea " ) ) )
pWindow = new Window ( pParent ) ;
2012-03-26 12:15:22 +01:00
else
2012-03-27 14:20:17 +01:00
fprintf ( stderr , " TO-DO, implement %s \n " , name . getStr ( ) ) ;
2012-05-23 13:32:19 +01:00
if ( pWindow )
{
fprintf ( stderr , " for %s, created %p child of %p (%p/%p/%p) \n " , name . getStr ( ) , pWindow , pParent , pWindow - > mpWindowImpl - > mpParent , pWindow - > mpWindowImpl - > mpRealParent , pWindow - > mpWindowImpl - > mpBorderWindow ) ;
2012-06-07 15:11:02 +01:00
m_aChildren . push_back ( WinAndId ( id , pWindow ) ) ;
2012-05-23 13:32:19 +01:00
}
2012-03-26 12:15:22 +01:00
return pWindow ;
}
2012-06-13 14:24:01 +01:00
namespace
{
//return true for window types which exist in vcl but are not themselves
//represented in the .ui format, i.e. only their children exist.
bool isConsideredPseudo ( Window * pWindow )
{
return pWindow - > GetType ( ) = = WINDOW_TABPAGE ;
}
}
2012-04-25 11:12:55 +01:00
Window * VclBuilder : : insertObject ( Window * pParent , const rtl : : OString & rClass , const rtl : : OString & rID , stringmap & rMap )
2012-03-26 12:15:22 +01:00
{
2012-04-25 11:12:55 +01:00
Window * pCurrentChild = NULL ;
2012-03-26 12:15:22 +01:00
2012-06-13 14:24:01 +01:00
if ( m_pParent & & ! isConsideredPseudo ( m_pParent ) & & ! m_sID . isEmpty ( ) & & rID . equals ( m_sID ) )
2012-03-27 14:20:17 +01:00
{
2012-04-25 11:12:55 +01:00
pCurrentChild = m_pParent ;
//toplevels default to resizable
if ( pCurrentChild - > IsDialog ( ) )
2012-05-18 14:05:20 +01:00
pCurrentChild - > SetStyle ( pCurrentChild - > GetStyle ( ) | WB_SIZEMOVE | WB_3DLOOK ) ;
2012-04-25 11:12:55 +01:00
}
else
{
2012-04-30 10:19:19 +01:00
pCurrentChild = makeObject ( pParent , rClass , rID , rMap ) ;
2012-04-25 11:12:55 +01:00
if ( ! pCurrentChild )
fprintf ( stderr , " missing object! \n " ) ;
}
2012-03-26 12:15:22 +01:00
2012-04-25 11:12:55 +01:00
if ( pCurrentChild )
{
2012-03-27 14:20:17 +01:00
for ( stringmap : : iterator aI = rMap . begin ( ) , aEnd = rMap . end ( ) ; aI ! = aEnd ; + + aI )
2012-03-26 12:15:22 +01:00
{
2012-03-27 14:20:17 +01:00
const rtl : : OString & rKey = aI - > first ;
const rtl : : OString & rValue = aI - > second ;
2012-04-16 10:50:23 +01:00
pCurrentChild - > set_property ( rKey , rValue ) ;
2012-03-26 12:15:22 +01:00
}
}
2012-04-16 10:50:23 +01:00
rMap . clear ( ) ;
2012-03-26 12:15:22 +01:00
if ( ! pCurrentChild )
{
fprintf ( stderr , " missing object! \n " ) ;
2012-04-25 11:12:55 +01:00
pCurrentChild = m_aChildren . empty ( ) ? pParent : m_aChildren . back ( ) . m_pWindow ;
2012-03-26 12:15:22 +01:00
}
2012-03-27 14:20:17 +01:00
return pCurrentChild ;
}
2012-03-26 12:15:22 +01:00
2012-05-23 13:17:44 +01:00
sal_uInt16 VclBuilder : : getPositionWithinParent ( Window & rWindow )
{
if ( rWindow . mpWindowImpl - > mpParent ! = rWindow . mpWindowImpl - > mpRealParent )
{
assert ( rWindow . mpWindowImpl - > mpBorderWindow = =
rWindow . mpWindowImpl - > mpParent ) ;
assert ( rWindow . mpWindowImpl - > mpBorderWindow - > mpParent = =
rWindow . mpWindowImpl - > mpRealParent ) ;
return getPositionWithinParent ( * rWindow . mpWindowImpl - > mpBorderWindow ) ;
}
assert ( rWindow . GetParent ( ) = = rWindow . GetRealParent ( ) ) ;
sal_uInt16 nPosition = 0 ;
Window * pChild = rWindow . GetParent ( ) - > mpWindowImpl - > mpFirstChild ;
while ( pChild )
{
if ( pChild = = & rWindow )
break ;
pChild = pChild - > mpWindowImpl - > mpNext ;
+ + nPosition ;
}
return nPosition ;
}
void VclBuilder : : reorderWithinParent ( Window & rWindow , sal_uInt16 nNewPosition )
{
if ( rWindow . mpWindowImpl - > mpParent ! = rWindow . mpWindowImpl - > mpRealParent )
{
assert ( rWindow . mpWindowImpl - > mpBorderWindow = =
rWindow . mpWindowImpl - > mpParent ) ;
assert ( rWindow . mpWindowImpl - > mpBorderWindow - > mpParent = =
rWindow . mpWindowImpl - > mpRealParent ) ;
reorderWithinParent ( * rWindow . mpWindowImpl - > mpBorderWindow , nNewPosition ) ;
return ;
}
rWindow . reorderWithinParent ( nNewPosition ) ;
}
2012-06-07 15:11:02 +01:00
void VclBuilder : : handleTabChild ( Window * pParent , xmlreader : : XmlReader & reader )
2012-03-27 14:20:17 +01:00
{
2012-06-12 16:02:26 +01:00
rtl : : OString sID ;
2012-03-26 12:15:22 +01:00
int nLevel = 1 ;
2012-06-07 15:11:02 +01:00
stringmap aProperties ;
while ( 1 )
{
xmlreader : : Span name ;
int nsId ;
xmlreader : : XmlReader : : Result res = reader . nextItem (
xmlreader : : XmlReader : : TEXT_NONE , & name , & nsId ) ;
if ( res = = xmlreader : : XmlReader : : RESULT_BEGIN )
{
+ + nLevel ;
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " property " ) ) )
collectProperty ( reader , aProperties ) ;
2012-06-12 16:02:26 +01:00
else if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " object " ) ) )
{
while ( reader . nextAttribute ( & nsId , & name ) )
{
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " id " ) ) )
{
name = reader . getAttributeValue ( false ) ;
sID = rtl : : OString ( name . begin , name . length ) ;
}
}
}
2012-06-07 15:11:02 +01:00
}
if ( res = = xmlreader : : XmlReader : : RESULT_END )
- - nLevel ;
if ( ! nLevel )
break ;
if ( res = = xmlreader : : XmlReader : : RESULT_DONE )
break ;
}
2012-03-26 12:15:22 +01:00
2012-06-12 13:05:14 +01:00
TabControl * pTabControl = static_cast < TabControl * > ( pParent ) ;
2012-06-07 15:11:02 +01:00
VclBuilder : : stringmap : : iterator aFind = aProperties . find ( rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " label " ) ) ) ;
if ( aFind ! = aProperties . end ( ) )
2012-06-12 16:02:26 +01:00
{
2012-06-07 15:11:02 +01:00
pTabControl - > SetPageText ( pTabControl - > GetCurPageId ( ) , rtl : : OStringToOUString ( aFind - > second , RTL_TEXTENCODING_UTF8 ) ) ;
2012-06-12 16:02:26 +01:00
sal_Int32 nID = 0 ;
//To make it easier to retro fit pre-builder dialog code we take the
//notebook child id (falling back to notebook label id) and if its a
//positive number use that as the page id so existing code can find the
//right tabpage by id
TabPage * pPage = pTabControl - > GetTabPage ( pTabControl - > GetCurPageId ( ) ) ;
if ( pPage )
{
VclBin * pContainer = static_cast < VclBin * > ( pPage - > GetWindow ( WINDOW_FIRSTCHILD ) ) ;
Window * pChild = pContainer - > get_child ( ) ;
nID = pChild ? get_by_window ( pChild ) . toInt32 ( ) : 0 ;
}
if ( nID = = 0 )
nID = sID . toInt32 ( ) ;
if ( nID > 0 )
pTabControl - > ReassignPageId ( pTabControl - > GetCurPageId ( ) , nID ) ;
}
2012-06-12 13:05:14 +01:00
else
pTabControl - > RemovePage ( pTabControl - > GetCurPageId ( ) ) ;
2012-06-07 15:11:02 +01:00
}
void VclBuilder : : handleChild ( Window * pParent , xmlreader : : XmlReader & reader )
{
2012-03-27 16:32:28 +01:00
Window * pCurrentChild = NULL ;
2012-06-07 15:11:02 +01:00
xmlreader : : Span name ;
int nsId ;
rtl : : OString sType ;
while ( reader . nextAttribute ( & nsId , & name ) )
{
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " type " ) ) )
{
name = reader . getAttributeValue ( false ) ;
sType = rtl : : OString ( name . begin , name . length ) ;
}
}
if ( sType . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " tab " ) ) )
{
handleTabChild ( pParent , reader ) ;
return ;
}
int nLevel = 1 ;
2012-03-26 12:15:22 +01:00
while ( 1 )
{
xmlreader : : XmlReader : : Result res = reader . nextItem (
xmlreader : : XmlReader : : TEXT_NONE , & name , & nsId ) ;
2012-03-27 14:20:17 +01:00
if ( res = = xmlreader : : XmlReader : : RESULT_BEGIN )
{
2012-06-12 13:05:14 +01:00
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " object " ) ) | | name . equals ( RTL_CONSTASCII_STRINGPARAM ( " placeholder " ) ) )
2012-03-27 14:20:17 +01:00
{
2012-03-27 16:32:28 +01:00
pCurrentChild = handleObject ( pParent , reader ) ;
2012-03-28 14:10:13 +01:00
2012-06-12 16:02:26 +01:00
bool bObjectInserted = pCurrentChild & & pParent ! = pCurrentChild ;
if ( bObjectInserted )
2012-03-28 14:10:13 +01:00
{
2012-06-07 15:11:02 +01:00
//Select the first page if its a notebook
2012-06-09 10:33:31 +01:00
if ( pCurrentChild - > GetType ( ) = = WINDOW_TABCONTROL )
2012-03-28 14:10:13 +01:00
{
2012-06-07 15:11:02 +01:00
TabControl * pTabControl = static_cast < TabControl * > ( pCurrentChild ) ;
2012-06-12 16:02:26 +01:00
pTabControl - > SetCurPageId ( pTabControl - > GetPageId ( 0 ) ) ;
2012-03-28 14:10:13 +01:00
2012-06-07 15:11:02 +01:00
//To-Do add reorder capability to the TabControl
2012-03-28 14:10:13 +01:00
}
2012-06-07 15:11:02 +01:00
else
{
//To-Do make reorder a virtual in Window, move this foo
//there and see above
rtl : : OString sPosition ( RTL_CONSTASCII_STRINGPARAM ( " position " ) ) ;
std : : vector < Window * > aChilds ;
for ( Window * pChild = pCurrentChild - > GetWindow ( WINDOW_FIRSTCHILD ) ; pChild ;
pChild = pChild - > GetWindow ( WINDOW_NEXT ) )
{
aChilds . push_back ( pChild ) ;
}
for ( size_t i = 0 ; i < aChilds . size ( ) ; + + i )
{
sal_uInt16 nPosition = aChilds [ i ] - > getWidgetProperty < sal_uInt16 > ( sPosition , 0xFFFF ) ;
if ( nPosition = = 0xFFFF )
continue ;
reorderWithinParent ( * aChilds [ i ] , nPosition ) ;
}
2012-05-22 12:33:28 +01:00
# if TODO
//sort by ltr ttb
2012-06-07 15:11:02 +01:00
rtl : : OString sLeftAttach ( RTL_CONSTASCII_STRINGPARAM ( " left-attach " ) ) ;
rtl : : OString sTopAttach ( RTL_CONSTASCII_STRINGPARAM ( " top-attach " ) ) ;
for ( size_t i = 0 ; i < aChilds . size ( ) ; + + i )
{
sal_uInt16 nPosition = aChilds [ i ] - > getWidgetProperty < sal_uInt16 > ( sPosition , 0xFFFF ) ;
if ( nPosition = = 0xFFFF )
continue ;
reorderWithinParent ( * aChilds [ i ] , nPosition ) ;
}
2012-05-22 12:33:28 +01:00
# endif
2012-06-07 15:11:02 +01:00
}
2012-03-28 14:10:13 +01:00
}
2012-03-27 16:32:28 +01:00
}
else if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " packing " ) ) )
{
handlePacking ( pCurrentChild , reader ) ;
2012-03-27 14:20:17 +01:00
}
else
+ + nLevel ;
}
if ( res = = xmlreader : : XmlReader : : RESULT_END )
- - nLevel ;
if ( ! nLevel )
break ;
2012-03-26 12:15:22 +01:00
if ( res = = xmlreader : : XmlReader : : RESULT_DONE )
break ;
2012-03-27 14:20:17 +01:00
}
}
2012-03-26 12:15:22 +01:00
2012-06-06 08:56:46 +01:00
void VclBuilder : : handleListStore ( xmlreader : : XmlReader & reader , const rtl : : OString & rID )
{
m_aModels . push_back ( ModelAndId ( rID , new ListStore ) ) ;
int nLevel = 1 ;
while ( 1 )
{
xmlreader : : Span name ;
int nsId ;
xmlreader : : XmlReader : : Result res = reader . nextItem (
xmlreader : : XmlReader : : TEXT_NONE , & name , & nsId ) ;
if ( res = = xmlreader : : XmlReader : : RESULT_DONE )
break ;
if ( res = = xmlreader : : XmlReader : : RESULT_BEGIN )
{
+ + nLevel ;
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " col " ) ) )
{
reader . nextItem (
xmlreader : : XmlReader : : TEXT_NORMALIZED , & name , & nsId ) ;
rtl : : OString sValue ( name . begin , name . length ) ;
m_aModels . back ( ) . m_pModel - > m_aEntries . push_back ( sValue ) ;
}
}
if ( res = = xmlreader : : XmlReader : : RESULT_END )
{
- - nLevel ;
}
if ( ! nLevel )
break ;
}
}
2012-03-27 16:32:28 +01:00
Window * VclBuilder : : handleObject ( Window * pParent , xmlreader : : XmlReader & reader )
2012-03-27 14:20:17 +01:00
{
rtl : : OString sClass ;
2012-04-25 11:12:55 +01:00
rtl : : OString sID ;
2012-03-26 12:15:22 +01:00
2012-03-27 14:20:17 +01:00
xmlreader : : Span name ;
int nsId ;
while ( reader . nextAttribute ( & nsId , & name ) )
{
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " class " ) ) )
2012-03-26 12:15:22 +01:00
{
2012-03-27 14:20:17 +01:00
name = reader . getAttributeValue ( false ) ;
sClass = rtl : : OString ( name . begin , name . length ) ;
2012-03-26 12:15:22 +01:00
}
2012-04-25 11:12:55 +01:00
else if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " id " ) ) )
{
name = reader . getAttributeValue ( false ) ;
sID = rtl : : OString ( name . begin , name . length ) ;
}
2012-03-27 14:20:17 +01:00
}
2012-06-06 08:56:46 +01:00
if ( sClass . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " GtkListStore " ) ) )
{
handleListStore ( reader , sID ) ;
return NULL ;
}
2012-03-27 14:20:17 +01:00
int nLevel = 1 ;
stringmap aProperties ;
2012-03-26 12:15:22 +01:00
2012-03-27 14:20:17 +01:00
Window * pCurrentChild = NULL ;
while ( 1 )
{
xmlreader : : XmlReader : : Result res = reader . nextItem (
xmlreader : : XmlReader : : TEXT_NONE , & name , & nsId ) ;
if ( res = = xmlreader : : XmlReader : : RESULT_DONE )
break ;
if ( res = = xmlreader : : XmlReader : : RESULT_BEGIN )
2012-03-26 12:15:22 +01:00
{
2012-03-27 14:20:17 +01:00
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " child " ) ) )
{
if ( ! pCurrentChild )
2012-04-25 11:12:55 +01:00
pCurrentChild = insertObject ( pParent , sClass , sID , aProperties ) ;
2012-03-27 14:20:17 +01:00
handleChild ( pCurrentChild , reader ) ;
}
else
{
+ + nLevel ;
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " property " ) ) )
collectProperty ( reader , aProperties ) ;
}
2012-03-26 12:15:22 +01:00
}
if ( res = = xmlreader : : XmlReader : : RESULT_END )
{
- - nLevel ;
}
if ( ! nLevel )
break ;
}
2012-03-27 14:20:17 +01:00
if ( ! pCurrentChild )
2012-04-25 11:12:55 +01:00
pCurrentChild = insertObject ( pParent , sClass , sID , aProperties ) ;
2012-03-27 14:20:17 +01:00
2012-03-27 16:32:28 +01:00
return pCurrentChild ;
2012-03-26 12:15:22 +01:00
}
2012-03-27 16:32:28 +01:00
void VclBuilder : : handlePacking ( Window * pCurrent , xmlreader : : XmlReader & reader )
{
xmlreader : : Span name ;
int nsId ;
int nLevel = 1 ;
while ( 1 )
{
xmlreader : : XmlReader : : Result res = reader . nextItem (
xmlreader : : XmlReader : : TEXT_NONE , & name , & nsId ) ;
if ( res = = xmlreader : : XmlReader : : RESULT_DONE )
break ;
if ( res = = xmlreader : : XmlReader : : RESULT_BEGIN )
{
+ + nLevel ;
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " property " ) ) )
applyPackingProperty ( pCurrent , reader ) ;
}
if ( res = = xmlreader : : XmlReader : : RESULT_END )
{
- - nLevel ;
}
if ( ! nLevel )
break ;
}
}
void VclBuilder : : applyPackingProperty ( Window * pCurrent ,
xmlreader : : XmlReader & reader )
2012-03-26 12:15:22 +01:00
{
2012-03-27 16:32:28 +01:00
if ( ! pCurrent )
return ;
2012-06-07 23:03:18 +01:00
xmlreader : : Span name ;
int nsId ;
2012-03-27 14:20:17 +01:00
while ( reader . nextAttribute ( & nsId , & name ) )
{
2012-03-27 16:32:28 +01:00
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " name " ) ) )
{
name = reader . getAttributeValue ( false ) ;
rtl : : OString sKey ( name . begin , name . length ) ;
2012-04-05 20:43:33 +01:00
sKey = sKey . replace ( ' _ ' , ' - ' ) ;
2012-03-27 16:32:28 +01:00
reader . nextItem (
xmlreader : : XmlReader : : TEXT_NORMALIZED , & name , & nsId ) ;
rtl : : OString sValue ( name . begin , name . length ) ;
if ( sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " expand " ) ) | |
sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " fill " ) ) )
{
bool bTrue = ( sValue [ 0 ] = = ' t ' | | sValue [ 0 ] = = ' T ' | | sValue [ 0 ] = = ' 1 ' ) ;
pCurrent - > setChildProperty ( sKey , bTrue ) ;
}
2012-03-28 14:10:13 +01:00
else if ( sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " position " ) ) )
{
pCurrent - > setChildProperty ( sKey , static_cast < sal_uInt16 > ( sValue . toInt32 ( ) ) ) ;
}
2012-04-05 20:43:33 +01:00
else if ( sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " pack-type " ) ) )
2012-03-29 10:27:27 +01:00
{
sal_Int32 nPackType = ( sValue [ 0 ] = = ' e ' | | sValue [ 0 ] = = ' e ' ) ? VCL_PACK_END : VCL_PACK_START ;
2012-04-05 20:43:33 +01:00
pCurrent - > setChildProperty ( sKey , nPackType ) ;
}
else if (
sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " left-attach " ) ) | |
sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " top-attach " ) ) | |
sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " width " ) ) | |
sKey . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " height " ) )
)
{
pCurrent - > setChildProperty ( sKey , sValue . toInt32 ( ) ) ;
2012-03-29 10:27:27 +01:00
}
2012-03-27 16:32:28 +01:00
else
fprintf ( stderr , " unknown packing %s \n " , sKey . getStr ( ) ) ;
}
}
}
void VclBuilder : : collectProperty ( xmlreader : : XmlReader & reader , stringmap & rMap )
{
xmlreader : : Span name ;
int nsId ;
2012-03-26 12:15:22 +01:00
2012-03-27 16:32:28 +01:00
while ( reader . nextAttribute ( & nsId , & name ) )
{
2012-03-26 12:15:22 +01:00
if ( name . equals ( RTL_CONSTASCII_STRINGPARAM ( " name " ) ) )
{
name = reader . getAttributeValue ( false ) ;
2012-03-27 14:20:17 +01:00
rtl : : OString sProperty ( name . begin , name . length ) ;
2012-04-16 10:50:23 +01:00
sProperty = sProperty . replace ( ' _ ' , ' - ' ) ;
2012-03-27 14:20:17 +01:00
reader . nextItem (
xmlreader : : XmlReader : : TEXT_NORMALIZED , & name , & nsId ) ;
rtl : : OString sValue ( name . begin , name . length ) ;
2012-04-30 10:19:19 +01:00
//replace '_' with '-' except for property values that
//refer to widget ids themselves. TO-DO, drop conversion
//and just use foo_bar properties throughout
if ( sProperty . equalsL ( RTL_CONSTASCII_STRINGPARAM ( " group " ) ) )
rMap [ sProperty ] = sValue ;
else
rMap [ sProperty ] = sValue . replace ( ' _ ' , ' - ' ) ;
2012-03-26 12:15:22 +01:00
}
}
}
Window * VclBuilder : : get_widget_root ( )
{
2012-04-25 11:12:55 +01:00
return m_aChildren . empty ( ) ? NULL : m_aChildren [ 0 ] . m_pWindow ;
}
Window * VclBuilder : : get_by_name ( rtl : : OString sID )
{
for ( std : : vector < WinAndId > : : iterator aI = m_aChildren . begin ( ) ,
aEnd = m_aChildren . end ( ) ; aI ! = aEnd ; + + aI )
{
if ( aI - > m_sID . equals ( sID ) )
return aI - > m_pWindow ;
}
return NULL ;
2012-03-26 12:15:22 +01:00
}
2012-06-12 16:02:26 +01:00
rtl : : OString VclBuilder : : get_by_window ( const Window * pWindow )
{
for ( std : : vector < WinAndId > : : iterator aI = m_aChildren . begin ( ) ,
aEnd = m_aChildren . end ( ) ; aI ! = aEnd ; + + aI )
{
if ( aI - > m_pWindow = = pWindow )
return aI - > m_sID ;
}
return rtl : : OString ( ) ;
}
2012-06-06 08:56:46 +01:00
VclBuilder : : ListStore * VclBuilder : : get_model_by_name ( rtl : : OString sID )
{
for ( std : : vector < ModelAndId > : : iterator aI = m_aModels . begin ( ) ,
aEnd = m_aModels . end ( ) ; aI ! = aEnd ; + + aI )
{
if ( aI - > m_sID . equals ( sID ) )
return aI - > m_pModel ;
}
return NULL ;
}
2012-05-22 12:33:28 +01:00
void VclBuilder : : swapGuts ( Window & rOrig , Window & rReplacement )
{
# if 1
sal_uInt16 nPosition = getPositionWithinParent ( rOrig ) ;
rReplacement . take_properties ( rOrig ) ;
2012-05-23 13:17:44 +01:00
reorderWithinParent ( rReplacement , nPosition ) ;
2012-05-22 12:33:28 +01:00
assert ( nPosition = = getPositionWithinParent ( rReplacement ) ) ;
# else
//rReplacement is intended to be not inserted into
//anything yet
assert ( ! rReplacement . mpWindowImpl - > mpParent ) ;
rReplacement . ImplInit ( rOrig . GetParent ( ) , rOrig . GetStyle ( ) , NULL ) ;
assert ( rReplacement . GetParent ( ) = = rOrig . GetParent ( ) ) ;
rReplacement . ImplRemoveWindow ( false ) ;
Window * pParent = rOrig . mpWindowImpl - > mpParent ;
Window * pOrigsNext = rOrig . mpWindowImpl - > mpNext ;
Window * pOrigsPrev = rOrig . mpWindowImpl - > mpPrev ;
std : : swap ( rOrig . mpWindowImpl , rReplacement . mpWindowImpl ) ;
std : : swap ( rOrig . m_aWidgetProperties , rReplacement . m_aWidgetProperties ) ;
assert ( rReplacement . mpWindowImpl - > mpPrev = = pOrigsPrev ) ;
assert ( rReplacement . mpWindowImpl - > mpNext = = pOrigsNext ) ;
if ( pOrigsNext )
pOrigsNext - > mpWindowImpl - > mpPrev = & rReplacement ;
else
pParent - > mpWindowImpl - > mpLastChild = & rReplacement ;
if ( pOrigsPrev )
pOrigsPrev - > mpWindowImpl - > mpNext = & rReplacement ;
else
pParent - > mpWindowImpl - > mpFirstChild = & rReplacement ;
assert ( ! rOrig . mpWindowImpl - > mpNext & & ! rOrig . mpWindowImpl - > mpPrev ) ;
//now put this at the end of the window list
rOrig . ImplInsertWindow ( pParent ) ;
# endif
2012-05-23 13:17:44 +01:00
fprintf ( stderr , " swapped %p for %p %p/%p/%p \n " , & rReplacement , & rOrig , rReplacement . mpWindowImpl - > mpParent , rReplacement . mpWindowImpl - > mpRealParent , rReplacement . mpWindowImpl - > mpBorderWindow ) ;
2012-05-22 12:33:28 +01:00
}
bool VclBuilder : : replace ( rtl : : OString sID , Window & rReplacement )
{
for ( std : : vector < WinAndId > : : iterator aI = m_aChildren . begin ( ) ,
aEnd = m_aChildren . end ( ) ; aI ! = aEnd ; + + aI )
{
if ( aI - > m_sID . equals ( sID ) )
{
Window * pOrig = aI - > m_pWindow ;
swapGuts ( * pOrig , rReplacement ) ;
delete pOrig ;
aI - > m_pWindow = & rReplacement ;
aI - > m_bOwned = false ;
return true ;
}
}
fprintf ( stderr , " no sign of %s \n " , sID . getStr ( ) ) ;
return false ;
}
2012-06-06 08:56:46 +01:00
void VclBuilder : : mungemodel ( ListBox & rTarget , ListStore & rStore )
{
for ( std : : vector < rtl : : OString > : : iterator aI = rStore . m_aEntries . begin ( ) , aEnd = rStore . m_aEntries . end ( ) ;
aI ! = aEnd ; + + aI )
{
rTarget . InsertEntry ( rtl : : OStringToOUString ( * aI , RTL_TEXTENCODING_UTF8 ) ) ;
}
2012-06-06 10:29:16 +01:00
if ( ! rStore . m_aEntries . empty ( ) )
rTarget . SelectEntryPos ( 0 ) ;
2012-06-06 08:56:46 +01:00
}
2012-03-26 12:15:22 +01:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */