You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
837 lines
27 KiB
837 lines
27 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kxmlguifactory_p.h"
|
||
|
#include "kxmlguiclient.h"
|
||
|
#include "kxmlguibuilder.h"
|
||
|
|
||
15 years ago
|
#include <tqwidget.h>
|
||
15 years ago
|
|
||
|
#include <kglobal.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include <assert.h>
|
||
|
|
||
|
using namespace KXMLGUI;
|
||
|
|
||
15 years ago
|
void ActionList::plug( TQWidget *container, int index ) const
|
||
15 years ago
|
{
|
||
|
ActionListIt it( *this );
|
||
|
for (; it.current(); ++it )
|
||
|
it.current()->plug( container, index++ );
|
||
|
}
|
||
|
|
||
15 years ago
|
void ActionList::unplug( TQWidget *container ) const
|
||
15 years ago
|
{
|
||
|
ActionListIt it( *this );
|
||
|
for (; it.current(); ++it )
|
||
|
it.current()->unplug( container );
|
||
|
}
|
||
|
|
||
15 years ago
|
ContainerNode::ContainerNode( TQWidget *_container, const TQString &_tagName,
|
||
|
const TQString &_name, ContainerNode *_parent,
|
||
15 years ago
|
KXMLGUIClient *_client, KXMLGUIBuilder *_builder,
|
||
15 years ago
|
int id, const TQString &_mergingName,
|
||
|
const TQString &_groupName, const TQStringList &customTags,
|
||
|
const TQStringList &containerTags )
|
||
15 years ago
|
: parent( _parent ), client( _client ), builder( _builder ),
|
||
|
builderCustomTags( customTags ), builderContainerTags( containerTags ),
|
||
|
container( _container ), containerId( id ), tagName( _tagName ), name( _name ),
|
||
|
groupName( _groupName ), index( 0 ), mergingName( _mergingName )
|
||
|
{
|
||
|
children.setAutoDelete( true );
|
||
|
clients.setAutoDelete( true );
|
||
|
|
||
|
if ( parent )
|
||
|
parent->children.append( this );
|
||
|
}
|
||
|
|
||
|
void ContainerNode::removeChild( ContainerNode *child )
|
||
|
{
|
||
14 years ago
|
MergingIndexList::Iterator mergingIt = findIndex( child->mergingName );
|
||
15 years ago
|
adjustMergingIndices( -1, mergingIt );
|
||
|
children.removeRef( child );
|
||
|
}
|
||
|
|
||
|
/*
|
||
14 years ago
|
* Find a merging index with the given name. Used to find an index defined by <Merge name="blah"/>
|
||
15 years ago
|
* or by a <DefineGroup name="foo" /> tag.
|
||
|
*/
|
||
14 years ago
|
MergingIndexList::Iterator ContainerNode::findIndex( const TQString &name )
|
||
15 years ago
|
{
|
||
|
MergingIndexList::Iterator it( mergingIndices.begin() );
|
||
|
MergingIndexList::Iterator end( mergingIndices.end() );
|
||
|
for (; it != end; ++it )
|
||
|
if ( (*it).mergingName == name )
|
||
|
return it;
|
||
|
return it;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Check if the given container widget is a child of this node and return the node structure
|
||
14 years ago
|
* if found.
|
||
15 years ago
|
*/
|
||
14 years ago
|
ContainerNode *ContainerNode::findContainerNode( TQWidget *container )
|
||
15 years ago
|
{
|
||
|
ContainerNodeListIt it( children );
|
||
|
|
||
|
for (; it.current(); ++it )
|
||
|
if ( it.current()->container == container )
|
||
|
return it.current();
|
||
|
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Find a container recursively with the given name. Either compares _name with the
|
||
|
* container's tag name or the value of the container's name attribute. Specified by
|
||
|
* the tag bool .
|
||
|
*/
|
||
14 years ago
|
ContainerNode *ContainerNode::findContainer( const TQString &_name, bool tag )
|
||
15 years ago
|
{
|
||
|
if ( ( tag && tagName == _name ) ||
|
||
|
( !tag && name == _name ) )
|
||
|
return this;
|
||
|
|
||
|
ContainerNodeListIt it( children );
|
||
|
for (; it.current(); ++it )
|
||
|
{
|
||
14 years ago
|
ContainerNode *res = it.current()->findContainer( _name, tag );
|
||
15 years ago
|
if ( res )
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Finds a child container node (not recursively) with the given name and tagname. Explicitly
|
||
|
* leaves out container widgets specified in the exludeList . Also ensures that the containers
|
||
|
* belongs to currClient.
|
||
|
*/
|
||
14 years ago
|
ContainerNode *ContainerNode::findContainer( const TQString &name, const TQString &tagName,
|
||
15 years ago
|
const TQPtrList<TQWidget> *excludeList,
|
||
15 years ago
|
KXMLGUIClient * /*currClient*/ )
|
||
|
{
|
||
|
ContainerNode *res = 0L;
|
||
|
ContainerNodeListIt nIt( children );
|
||
|
|
||
|
if ( !name.isEmpty() )
|
||
|
{
|
||
|
for (; nIt.current(); ++nIt )
|
||
|
if ( nIt.current()->name == name &&
|
||
14 years ago
|
!excludeList->containsRef( nIt.current()->container ) )
|
||
15 years ago
|
{
|
||
|
res = nIt.current();
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
if ( !tagName.isEmpty() )
|
||
|
for (; nIt.current(); ++nIt )
|
||
|
{
|
||
|
if ( nIt.current()->tagName == tagName &&
|
||
14 years ago
|
!excludeList->containsRef( nIt.current()->container )
|
||
15 years ago
|
/*
|
||
|
* It is a bad idea to also compare the client, because
|
||
|
* we don't want to do so in situations like these:
|
||
|
*
|
||
|
* <MenuBar>
|
||
|
* <Menu>
|
||
|
* ...
|
||
|
*
|
||
|
* other client:
|
||
|
* <MenuBar>
|
||
|
* <Menu>
|
||
|
* ...
|
||
|
*
|
||
|
&& nIt.current()->client == currClient )
|
||
|
*/
|
||
|
)
|
||
|
{
|
||
|
res = nIt.current();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
14 years ago
|
ContainerClient *ContainerNode::findChildContainerClient( KXMLGUIClient *currentGUIClient,
|
||
15 years ago
|
const TQString &groupName,
|
||
15 years ago
|
const MergingIndexList::Iterator &mergingIdx )
|
||
|
{
|
||
|
if ( !clients.isEmpty() )
|
||
|
{
|
||
|
ContainerClientListIt clientIt( clients );
|
||
|
|
||
|
for (; clientIt.current(); ++clientIt )
|
||
|
if ( clientIt.current()->client == currentGUIClient )
|
||
|
{
|
||
|
if ( groupName.isEmpty() )
|
||
|
return clientIt.current();
|
||
|
|
||
|
if ( groupName == clientIt.current()->groupName )
|
||
|
return clientIt.current();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ContainerClient *client = new ContainerClient;
|
||
|
client->client = currentGUIClient;
|
||
|
client->groupName = groupName;
|
||
|
|
||
|
if ( mergingIdx != mergingIndices.end() )
|
||
|
client->mergingName = (*mergingIdx).mergingName;
|
||
|
|
||
|
clients.append( client );
|
||
|
|
||
|
return client;
|
||
|
}
|
||
|
|
||
|
void ContainerNode::plugActionList( BuildState &state )
|
||
|
{
|
||
|
MergingIndexList::Iterator mIt( mergingIndices.begin() );
|
||
|
MergingIndexList::Iterator mEnd( mergingIndices.end() );
|
||
|
for (; mIt != mEnd; ++mIt )
|
||
|
plugActionList( state, mIt );
|
||
|
|
||
15 years ago
|
TQPtrListIterator<ContainerNode> childIt( children );
|
||
15 years ago
|
for (; childIt.current(); ++childIt )
|
||
|
childIt.current()->plugActionList( state );
|
||
|
}
|
||
|
|
||
|
void ContainerNode::plugActionList( BuildState &state, const MergingIndexList::Iterator &mergingIdxIt )
|
||
|
{
|
||
15 years ago
|
static const TQString &tagActionList = KGlobal::staticQString( "actionlist" );
|
||
15 years ago
|
|
||
|
MergingIndex mergingIdx = *mergingIdxIt;
|
||
|
|
||
15 years ago
|
TQString k( mergingIdx.mergingName );
|
||
15 years ago
|
|
||
14 years ago
|
if ( k.find( tagActionList ) == -1 )
|
||
15 years ago
|
return;
|
||
|
|
||
|
k = k.mid( tagActionList.length() );
|
||
|
|
||
|
if ( mergingIdx.clientName != state.clientName )
|
||
|
return;
|
||
|
|
||
|
if ( k != state.actionListName )
|
||
|
return;
|
||
|
|
||
14 years ago
|
ContainerClient *client = findChildContainerClient( state.guiClient,
|
||
14 years ago
|
TQString(),
|
||
15 years ago
|
mergingIndices.end() );
|
||
|
|
||
|
client->actionLists.insert( k, state.actionList );
|
||
|
|
||
|
state.actionList.plug( container, mergingIdx.value );
|
||
|
|
||
|
adjustMergingIndices( state.actionList.count(), mergingIdxIt );
|
||
|
}
|
||
|
|
||
|
void ContainerNode::unplugActionList( BuildState &state )
|
||
|
{
|
||
|
MergingIndexList::Iterator mIt( mergingIndices.begin() );
|
||
|
MergingIndexList::Iterator mEnd( mergingIndices.end() );
|
||
|
for (; mIt != mEnd; ++mIt )
|
||
|
unplugActionList( state, mIt );
|
||
|
|
||
15 years ago
|
TQPtrListIterator<ContainerNode> childIt( children );
|
||
15 years ago
|
for (; childIt.current(); ++childIt )
|
||
|
childIt.current()->unplugActionList( state );
|
||
|
}
|
||
|
|
||
|
void ContainerNode::unplugActionList( BuildState &state, const MergingIndexList::Iterator &mergingIdxIt )
|
||
|
{
|
||
15 years ago
|
static const TQString &tagActionList = KGlobal::staticQString( "actionlist" );
|
||
15 years ago
|
|
||
|
MergingIndex mergingIdx = *mergingIdxIt;
|
||
|
|
||
15 years ago
|
TQString k = mergingIdx.mergingName;
|
||
15 years ago
|
|
||
14 years ago
|
if ( k.find( tagActionList ) == -1 )
|
||
15 years ago
|
return;
|
||
|
|
||
|
k = k.mid( tagActionList.length() );
|
||
|
|
||
|
if ( mergingIdx.clientName != state.clientName )
|
||
|
return;
|
||
|
|
||
|
if ( k != state.actionListName )
|
||
|
return;
|
||
|
|
||
14 years ago
|
ContainerClient *client = findChildContainerClient( state.guiClient,
|
||
14 years ago
|
TQString(),
|
||
15 years ago
|
mergingIndices.end() );
|
||
|
|
||
14 years ago
|
ActionListMap::Iterator lIt( client->actionLists.find( k ) );
|
||
15 years ago
|
if ( lIt == client->actionLists.end() )
|
||
|
return;
|
||
|
|
||
|
lIt.data().unplug( container );
|
||
|
|
||
|
adjustMergingIndices( -int(lIt.data().count()), mergingIdxIt );
|
||
|
|
||
|
client->actionLists.remove( lIt );
|
||
|
}
|
||
|
|
||
|
void ContainerNode::adjustMergingIndices( int offset,
|
||
|
const MergingIndexList::Iterator &it )
|
||
|
{
|
||
|
MergingIndexList::Iterator mergingIt = it;
|
||
|
MergingIndexList::Iterator mergingEnd = mergingIndices.end();
|
||
|
|
||
|
for (; mergingIt != mergingEnd; ++mergingIt )
|
||
|
(*mergingIt).value += offset;
|
||
|
|
||
|
index += offset;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool ContainerNode::destruct( TQDomElement element, BuildState &state )
|
||
15 years ago
|
{
|
||
|
destructChildren( element, state );
|
||
|
|
||
|
unplugActions( state );
|
||
|
|
||
|
// remove all merging indices the client defined
|
||
|
MergingIndexList::Iterator cmIt = mergingIndices.begin();
|
||
|
while ( cmIt != mergingIndices.end() )
|
||
|
if ( (*cmIt).clientName == state.clientName )
|
||
|
cmIt = mergingIndices.remove( cmIt );
|
||
|
else
|
||
|
++cmIt;
|
||
|
|
||
|
// ### check for merging index count, too?
|
||
|
if ( clients.count() == 0 && children.count() == 0 && container &&
|
||
|
client == state.guiClient )
|
||
|
{
|
||
15 years ago
|
TQWidget *parentContainer = 0L;
|
||
15 years ago
|
|
||
|
if ( parent && parent->container )
|
||
|
parentContainer = parent->container;
|
||
|
|
||
|
assert( builder );
|
||
|
|
||
|
builder->removeContainer( container, parentContainer, element, containerId );
|
||
|
|
||
|
client = 0L;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if ( client == state.guiClient )
|
||
|
client = 0L;
|
||
|
|
||
|
return false;
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
void ContainerNode::destructChildren( const TQDomElement &element, BuildState &state )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPtrListIterator<ContainerNode> childIt( children );
|
||
15 years ago
|
while ( childIt.current() )
|
||
|
{
|
||
|
ContainerNode *childNode = childIt.current();
|
||
|
|
||
14 years ago
|
TQDomElement childElement = findElementForChild( element, childNode );
|
||
15 years ago
|
|
||
|
// destruct returns true in case the container really got deleted
|
||
|
if ( childNode->destruct( childElement, state ) )
|
||
|
removeChild( childNode );
|
||
|
else
|
||
|
++childIt;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement ContainerNode::findElementForChild( const TQDomElement &baseElement,
|
||
15 years ago
|
ContainerNode *childNode )
|
||
|
{
|
||
15 years ago
|
static const TQString &attrName = KGlobal::staticQString( "name" );
|
||
15 years ago
|
|
||
|
// ### slow
|
||
15 years ago
|
for ( TQDomNode n = baseElement.firstChild(); !n.isNull();
|
||
15 years ago
|
n = n.nextSibling() )
|
||
|
{
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if ( e.tagName().lower() == childNode->tagName &&
|
||
|
e.attribute( attrName ) == childNode->name )
|
||
|
return e;
|
||
|
}
|
||
|
|
||
15 years ago
|
return TQDomElement();
|
||
15 years ago
|
}
|
||
|
|
||
|
void ContainerNode::unplugActions( BuildState &state )
|
||
|
{
|
||
|
if ( !container )
|
||
|
return;
|
||
|
|
||
|
ContainerClientListIt clientIt( clients );
|
||
|
|
||
|
/*
|
||
|
Disabled because it means in KToolBar::saveState isHidden is always true then,
|
||
|
which is clearly wrong.
|
||
|
|
||
|
if ( clients.count() == 1 && clientIt.current()->client == client &&
|
||
|
client == state.guiClient )
|
||
|
container->hide(); // this container is going to die, that's for sure.
|
||
|
// in this case let's just hide it, which makes the
|
||
|
// destruction faster
|
||
|
*/
|
||
|
|
||
|
while ( clientIt.current() )
|
||
|
//only unplug the actions of the client we want to remove, as the container might be owned
|
||
|
//by a different client
|
||
|
if ( clientIt.current()->client == state.guiClient )
|
||
|
{
|
||
|
unplugClient( clientIt.current() );
|
||
|
clients.removeRef( clientIt.current() );
|
||
|
}
|
||
|
else
|
||
|
++clientIt;
|
||
|
}
|
||
|
|
||
|
void ContainerNode::unplugClient( ContainerClient *client )
|
||
|
{
|
||
15 years ago
|
static const TQString &tagActionList = KGlobal::staticQString( "actionlist" );
|
||
15 years ago
|
|
||
|
assert( builder );
|
||
|
|
||
|
// now quickly remove all custom elements (i.e. separators) and unplug all actions
|
||
|
|
||
15 years ago
|
TQValueList<int>::ConstIterator custIt = client->customElements.begin();
|
||
|
TQValueList<int>::ConstIterator custEnd = client->customElements.end();
|
||
15 years ago
|
for (; custIt != custEnd; ++custIt )
|
||
|
builder->removeCustomElement( container, *custIt );
|
||
|
|
||
|
client->actions.unplug( container );
|
||
|
|
||
|
// now adjust all merging indices
|
||
|
|
||
14 years ago
|
MergingIndexList::Iterator mergingIt = findIndex( client->mergingName );
|
||
15 years ago
|
|
||
|
adjustMergingIndices( - int( client->actions.count()
|
||
|
+ client->customElements.count() ),
|
||
|
mergingIt );
|
||
|
|
||
|
// unplug all actionslists
|
||
|
|
||
|
ActionListMap::ConstIterator alIt = client->actionLists.begin();
|
||
|
ActionListMap::ConstIterator alEnd = client->actionLists.end();
|
||
|
for (; alIt != alEnd; ++alIt )
|
||
|
{
|
||
|
alIt.data().unplug( container );
|
||
|
|
||
14 years ago
|
// construct the merging index key (i.e. like named merging) , find the
|
||
15 years ago
|
// corresponding merging index and adjust all indices
|
||
15 years ago
|
TQString mergingKey = alIt.key();
|
||
15 years ago
|
mergingKey.prepend( tagActionList );
|
||
|
|
||
14 years ago
|
MergingIndexList::Iterator mIt = findIndex( mergingKey );
|
||
15 years ago
|
if ( mIt == mergingIndices.end() )
|
||
|
continue;
|
||
|
|
||
|
adjustMergingIndices( -int(alIt.data().count()), mIt );
|
||
|
|
||
|
// remove the actionlists' merging index
|
||
|
// ### still needed? we clean up below anyway?
|
||
|
mergingIndices.remove( mIt );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ContainerNode::reset()
|
||
|
{
|
||
15 years ago
|
TQPtrListIterator<ContainerNode> childIt( children );
|
||
15 years ago
|
for (; childIt.current(); ++childIt )
|
||
|
childIt.current()->reset();
|
||
|
|
||
|
if ( client )
|
||
|
client->setFactory( 0L );
|
||
|
}
|
||
|
|
||
15 years ago
|
int ContainerNode::calcMergingIndex( const TQString &mergingName,
|
||
15 years ago
|
MergingIndexList::Iterator &it,
|
||
|
BuildState &state,
|
||
|
bool ignoreDefaultMergingIndex )
|
||
|
{
|
||
|
MergingIndexList::Iterator mergingIt;
|
||
|
|
||
|
if ( mergingName.isEmpty() )
|
||
14 years ago
|
mergingIt = findIndex( state.clientName );
|
||
15 years ago
|
else
|
||
14 years ago
|
mergingIt = findIndex( mergingName );
|
||
15 years ago
|
|
||
|
MergingIndexList::Iterator mergingEnd = mergingIndices.end();
|
||
|
it = mergingEnd;
|
||
|
|
||
|
if ( ( mergingIt == mergingEnd && state.currentDefaultMergingIt == mergingEnd ) ||
|
||
|
ignoreDefaultMergingIndex )
|
||
|
return index;
|
||
|
|
||
|
if ( mergingIt != mergingEnd )
|
||
|
it = mergingIt;
|
||
|
else
|
||
|
it = state.currentDefaultMergingIt;
|
||
|
|
||
|
return (*it).value;
|
||
|
}
|
||
|
|
||
15 years ago
|
int BuildHelper::calcMergingIndex( const TQDomElement &element, MergingIndexList::Iterator &it, TQString &group )
|
||
15 years ago
|
{
|
||
15 years ago
|
static const TQString &attrGroup = KGlobal::staticQString( "group" );
|
||
15 years ago
|
|
||
|
bool haveGroup = false;
|
||
|
group = element.attribute( attrGroup );
|
||
|
if ( !group.isEmpty() ) {
|
||
|
group.prepend( attrGroup );
|
||
|
haveGroup = true;
|
||
|
}
|
||
|
|
||
|
int idx;
|
||
|
if ( haveGroup )
|
||
|
idx = parentNode->calcMergingIndex( group, it, m_state, ignoreDefaultMergingIndex );
|
||
|
else if ( m_state.currentClientMergingIt == parentNode->mergingIndices.end() )
|
||
|
idx = parentNode->index;
|
||
|
else
|
||
|
idx = (*m_state.currentClientMergingIt).value;
|
||
|
|
||
|
return idx;
|
||
|
}
|
||
|
|
||
|
BuildHelper::BuildHelper( BuildState &state, ContainerNode *node )
|
||
|
: containerClient( 0 ), ignoreDefaultMergingIndex( false ), m_state( state ),
|
||
|
parentNode( node )
|
||
|
{
|
||
15 years ago
|
static const TQString &defaultMergingName = KGlobal::staticQString( "<default>" );
|
||
15 years ago
|
|
||
|
// create a list of supported container and custom tags
|
||
|
customTags = m_state.builderCustomTags;
|
||
|
containerTags = m_state.builderContainerTags;
|
||
|
|
||
|
if ( parentNode->builder != m_state.builder )
|
||
|
{
|
||
|
customTags += parentNode->builderCustomTags;
|
||
|
containerTags += parentNode->builderContainerTags;
|
||
|
}
|
||
|
|
||
|
if ( m_state.clientBuilder ) {
|
||
|
customTags = m_state.clientBuilderCustomTags + customTags;
|
||
|
containerTags = m_state.clientBuilderContainerTags + containerTags;
|
||
|
}
|
||
|
|
||
14 years ago
|
m_state.currentDefaultMergingIt = parentNode->findIndex( defaultMergingName );
|
||
14 years ago
|
parentNode->calcMergingIndex( TQString(), m_state.currentClientMergingIt,
|
||
15 years ago
|
m_state, /*ignoreDefaultMergingIndex*/ false );
|
||
|
}
|
||
|
|
||
15 years ago
|
void BuildHelper::build( const TQDomElement &element )
|
||
15 years ago
|
{
|
||
15 years ago
|
for (TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if (e.isNull()) continue;
|
||
|
processElement( e );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void BuildHelper::processElement( const TQDomElement &e )
|
||
15 years ago
|
{
|
||
|
// some often used QStrings
|
||
15 years ago
|
static const TQString &tagAction = KGlobal::staticQString( "action" );
|
||
|
static const TQString &tagMerge = KGlobal::staticQString( "merge" );
|
||
|
static const TQString &tagState = KGlobal::staticQString( "state" );
|
||
|
static const TQString &tagDefineGroup = KGlobal::staticQString( "definegroup" );
|
||
|
static const TQString &tagActionList = KGlobal::staticQString( "actionlist" );
|
||
|
static const TQString &attrName = KGlobal::staticQString( "name" );
|
||
15 years ago
|
|
||
15 years ago
|
TQString tag( e.tagName().lower() );
|
||
|
TQString currName( e.attribute( attrName ) );
|
||
15 years ago
|
|
||
|
bool isActionTag = ( tag == tagAction );
|
||
|
|
||
14 years ago
|
if ( isActionTag || customTags.findIndex( tag ) != -1 )
|
||
15 years ago
|
processActionOrCustomElement( e, isActionTag );
|
||
14 years ago
|
else if ( containerTags.findIndex( tag ) != -1 )
|
||
15 years ago
|
processContainerElement( e, tag, currName );
|
||
|
else if ( tag == tagMerge || tag == tagDefineGroup || tag == tagActionList )
|
||
|
processMergeElement( tag, currName, e );
|
||
|
else if ( tag == tagState )
|
||
|
processStateElement( e );
|
||
|
}
|
||
|
|
||
15 years ago
|
void BuildHelper::processActionOrCustomElement( const TQDomElement &e, bool isActionTag )
|
||
15 years ago
|
{
|
||
|
if ( !parentNode->container )
|
||
|
return;
|
||
|
|
||
|
MergingIndexList::Iterator it( m_state.currentClientMergingIt );
|
||
|
|
||
15 years ago
|
TQString group;
|
||
15 years ago
|
int idx = calcMergingIndex( e, it, group );
|
||
|
|
||
14 years ago
|
containerClient = parentNode->findChildContainerClient( m_state.guiClient, group, it );
|
||
15 years ago
|
|
||
|
bool guiElementCreated = false;
|
||
|
if ( isActionTag )
|
||
|
guiElementCreated = processActionElement( e, idx );
|
||
|
else
|
||
|
guiElementCreated = processCustomElement( e, idx );
|
||
|
|
||
|
if ( guiElementCreated )
|
||
|
// adjust any following merging indices and the current running index for the container
|
||
|
parentNode->adjustMergingIndices( 1, it );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool BuildHelper::processActionElement( const TQDomElement &e, int idx )
|
||
15 years ago
|
{
|
||
|
assert( m_state.guiClient );
|
||
|
|
||
|
// look up the action and plug it in
|
||
|
KAction *action = m_state.guiClient->action( e );
|
||
|
|
||
|
//kdDebug() << "BuildHelper::processActionElement " << e.attribute( "name" ) << " -> " << action << " (in " << m_state.guiClient->actionCollection() << ")" << endl;
|
||
|
if ( !action )
|
||
|
return false;
|
||
|
|
||
|
action->plug( parentNode->container, idx );
|
||
|
|
||
|
// save a reference to the plugged action, in order to properly unplug it afterwards.
|
||
|
containerClient->actions.append( action );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool BuildHelper::processCustomElement( const TQDomElement &e, int idx )
|
||
15 years ago
|
{
|
||
|
assert( parentNode->builder );
|
||
|
|
||
|
int id = parentNode->builder->createCustomElement( parentNode->container, idx, e );
|
||
|
if ( id == 0 )
|
||
|
return false;
|
||
|
|
||
|
containerClient->customElements.append( id );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void BuildHelper::processStateElement( const TQDomElement &element )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString stateName = element.attribute( "name" );
|
||
15 years ago
|
|
||
|
if ( !stateName || !stateName.length() ) return;
|
||
|
|
||
15 years ago
|
for (TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if (e.isNull()) continue;
|
||
|
|
||
15 years ago
|
TQString tagName = e.tagName().lower();
|
||
15 years ago
|
|
||
|
if ( tagName != "enable" && tagName != "disable" )
|
||
|
continue;
|
||
|
|
||
|
bool processingActionsToEnable = (tagName == "enable");
|
||
|
|
||
|
// process action names
|
||
15 years ago
|
for (TQDomNode n2 = n.firstChild(); !n2.isNull(); n2 = n2.nextSibling() )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement actionEl = n2.toElement();
|
||
15 years ago
|
if ( actionEl.tagName().lower() != "action" ) continue;
|
||
|
|
||
15 years ago
|
TQString actionName = actionEl.attribute( "name" );
|
||
15 years ago
|
if ( !actionName || !actionName.length() ) return;
|
||
|
|
||
|
if ( processingActionsToEnable )
|
||
|
m_state.guiClient->addStateActionEnabled( stateName, actionName );
|
||
|
else
|
||
|
m_state.guiClient->addStateActionDisabled( stateName, actionName );
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void BuildHelper::processMergeElement( const TQString &tag, const TQString &name, const TQDomElement &e )
|
||
15 years ago
|
{
|
||
15 years ago
|
static const TQString &tagDefineGroup = KGlobal::staticQString( "definegroup" );
|
||
|
static const TQString &tagActionList = KGlobal::staticQString( "actionlist" );
|
||
|
static const TQString &defaultMergingName = KGlobal::staticQString( "<default>" );
|
||
|
static const TQString &attrGroup = KGlobal::staticQString( "group" );
|
||
15 years ago
|
|
||
15 years ago
|
TQString mergingName( name );
|
||
15 years ago
|
if ( mergingName.isEmpty() )
|
||
|
{
|
||
|
if ( tag == tagDefineGroup )
|
||
|
{
|
||
|
kdError(1000) << "cannot define group without name!" << endl;
|
||
|
return;
|
||
|
}
|
||
|
if ( tag == tagActionList )
|
||
|
{
|
||
|
kdError(1000) << "cannot define actionlist without name!" << endl;
|
||
|
return;
|
||
|
}
|
||
|
mergingName = defaultMergingName;
|
||
|
}
|
||
|
|
||
|
if ( tag == tagDefineGroup )
|
||
|
mergingName.prepend( attrGroup ); //avoid possible name clashes by prepending
|
||
|
// "group" to group definitions
|
||
|
else if ( tag == tagActionList )
|
||
|
mergingName.prepend( tagActionList );
|
||
|
|
||
14 years ago
|
if ( parentNode->findIndex( mergingName ) != parentNode->mergingIndices.end() )
|
||
15 years ago
|
return; //do not allow the redefinition of merging indices!
|
||
|
|
||
|
MergingIndexList::Iterator mIt( parentNode->mergingIndices.end() );
|
||
|
|
||
15 years ago
|
TQString group( e.attribute( attrGroup ) );
|
||
15 years ago
|
if ( !group.isEmpty() )
|
||
|
group.prepend( attrGroup );
|
||
|
|
||
|
// calculate the index of the new merging index. Usually this does not need any calculation,
|
||
|
// we just want the last available index (i.e. append) . But in case the <Merge> tag appears
|
||
|
// "inside" another <Merge> tag from a previously build client, then we have to use the
|
||
|
// "parent's" index. That's why we call calcMergingIndex here.
|
||
|
MergingIndex newIdx;
|
||
|
newIdx.value = parentNode->calcMergingIndex( group, mIt, m_state, ignoreDefaultMergingIndex );
|
||
|
newIdx.mergingName = mergingName;
|
||
|
newIdx.clientName = m_state.clientName;
|
||
|
|
||
|
// if that merging index is "inside" another one, then append it right after the "parent" .
|
||
|
if ( mIt != parentNode->mergingIndices.end() )
|
||
|
parentNode->mergingIndices.insert( ++mIt, newIdx );
|
||
|
else
|
||
|
parentNode->mergingIndices.append( newIdx );
|
||
|
|
||
|
if ( mergingName == defaultMergingName )
|
||
|
|
||
|
ignoreDefaultMergingIndex = true;
|
||
|
|
||
|
// re-calculate the running default and client merging indices.
|
||
14 years ago
|
m_state.currentDefaultMergingIt = parentNode->findIndex( defaultMergingName );
|
||
14 years ago
|
parentNode->calcMergingIndex( TQString(), m_state.currentClientMergingIt,
|
||
15 years ago
|
m_state, ignoreDefaultMergingIndex );
|
||
|
}
|
||
|
|
||
15 years ago
|
void BuildHelper::processContainerElement( const TQDomElement &e, const TQString &tag,
|
||
|
const TQString &name )
|
||
15 years ago
|
{
|
||
15 years ago
|
static const TQString &defaultMergingName = KGlobal::staticQString( "<default>" );
|
||
15 years ago
|
|
||
14 years ago
|
ContainerNode *containerNode = parentNode->findContainer( name, tag,
|
||
15 years ago
|
&containerList,
|
||
|
m_state.guiClient );
|
||
|
|
||
|
if ( !containerNode )
|
||
|
{
|
||
|
MergingIndexList::Iterator it( m_state.currentClientMergingIt );
|
||
15 years ago
|
TQString group;
|
||
15 years ago
|
|
||
|
int idx = calcMergingIndex( e, it, group );
|
||
|
|
||
|
int id;
|
||
|
|
||
|
KXMLGUIBuilder *builder;
|
||
|
|
||
15 years ago
|
TQWidget *container = createContainer( parentNode->container, idx, e, id, &builder );
|
||
15 years ago
|
|
||
|
// no container? (probably some <text> tag or so ;-)
|
||
|
if ( !container )
|
||
|
return;
|
||
|
|
||
|
parentNode->adjustMergingIndices( 1, it );
|
||
|
|
||
14 years ago
|
assert( !parentNode->findContainerNode( container ) );
|
||
15 years ago
|
|
||
|
containerList.append( container );
|
||
|
|
||
15 years ago
|
TQString mergingName;
|
||
15 years ago
|
if ( it != parentNode->mergingIndices.end() )
|
||
|
mergingName = (*it).mergingName;
|
||
|
|
||
15 years ago
|
TQStringList cusTags = m_state.builderCustomTags;
|
||
|
TQStringList conTags = m_state.builderContainerTags;
|
||
15 years ago
|
if ( builder != m_state.builder )
|
||
|
{
|
||
|
cusTags = m_state.clientBuilderCustomTags;
|
||
|
conTags = m_state.clientBuilderContainerTags;
|
||
|
}
|
||
|
|
||
|
containerNode = new ContainerNode( container, tag, name, parentNode,
|
||
|
m_state.guiClient, builder, id,
|
||
|
mergingName, group, cusTags, conTags );
|
||
|
}
|
||
|
|
||
|
BuildHelper( m_state, containerNode ).build( e );
|
||
|
|
||
|
// and re-calculate running values, for better performance
|
||
14 years ago
|
m_state.currentDefaultMergingIt = parentNode->findIndex( defaultMergingName );
|
||
14 years ago
|
parentNode->calcMergingIndex( TQString(), m_state.currentClientMergingIt,
|
||
15 years ago
|
m_state, ignoreDefaultMergingIndex );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget *BuildHelper::createContainer( TQWidget *parent, int index,
|
||
|
const TQDomElement &element, int &id,
|
||
15 years ago
|
KXMLGUIBuilder **builder )
|
||
|
{
|
||
15 years ago
|
TQWidget *res = 0L;
|
||
15 years ago
|
|
||
|
if ( m_state.clientBuilder )
|
||
|
{
|
||
|
res = m_state.clientBuilder->createContainer( parent, index, element, id );
|
||
|
|
||
|
if ( res )
|
||
|
{
|
||
|
*builder = m_state.clientBuilder;
|
||
|
return res;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
KInstance *oldInstance = m_state.builder->builderInstance();
|
||
|
KXMLGUIClient *oldClient = m_state.builder->builderClient();
|
||
|
|
||
|
m_state.builder->setBuilderClient( m_state.guiClient );
|
||
|
|
||
|
res = m_state.builder->createContainer( parent, index, element, id );
|
||
|
|
||
|
m_state.builder->setBuilderInstance( oldInstance );
|
||
|
m_state.builder->setBuilderClient( oldClient );
|
||
|
|
||
|
if ( res )
|
||
|
*builder = m_state.builder;
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
void BuildState::reset()
|
||
|
{
|
||
14 years ago
|
clientName = TQString();
|
||
|
actionListName = TQString();
|
||
15 years ago
|
actionList.clear();
|
||
|
guiClient = 0;
|
||
|
clientBuilder = 0;
|
||
|
|
||
|
currentDefaultMergingIt = currentClientMergingIt = MergingIndexList::Iterator();
|
||
|
}
|
||
|
|
||
|
/* vim: et sw=4
|
||
|
*/
|