21 #include "tdeapplication.h"
22 #include "kxmlguibuilder.h"
23 #include "tdemenubar.h"
24 #include "tdepopupmenu.h"
25 #include "tdetoolbar.h"
26 #include "kstatusbar.h"
27 #include "tdemainwindow.h"
28 #include "tdeaction.h"
29 #include "tdeglobalsettings.h"
31 #include <kiconloader.h>
33 #include <tqobjectlist.h>
35 class KXMLGUIBuilderPrivate
38 KXMLGUIBuilderPrivate() {
40 ~KXMLGUIBuilderPrivate() {
45 TQString tagMainWindow;
49 TQString tagStatusBar;
51 TQString tagSeparator;
52 TQString tagTearOffHandle;
53 TQString tagMenuTitle;
56 TQString attrLineSeparator;
68 KXMLGUIBuilder::KXMLGUIBuilder( TQWidget *widget )
70 d =
new KXMLGUIBuilderPrivate;
73 d->tagMainWindow = TQString::fromLatin1(
"mainwindow" );
74 d->tagMenuBar = TQString::fromLatin1(
"menubar" );
75 d->tagMenu = TQString::fromLatin1(
"menu" );
76 d->tagToolBar = TQString::fromLatin1(
"toolbar" );
77 d->tagStatusBar = TQString::fromLatin1(
"statusbar" );
79 d->tagSeparator = TQString::fromLatin1(
"separator" );
80 d->tagTearOffHandle = TQString::fromLatin1(
"tearoffhandle" );
81 d->tagMenuTitle = TQString::fromLatin1(
"title" );
83 d->attrName = TQString::fromLatin1(
"name" );
84 d->attrLineSeparator = TQString::fromLatin1(
"lineseparator" );
86 d->attrText1 = TQString::fromLatin1(
"text" );
87 d->attrText2 = TQString::fromLatin1(
"Text" );
88 d->attrContext = TQString::fromLatin1(
"context" );
90 d->attrIcon = TQString::fromLatin1(
"icon" );
96 KXMLGUIBuilder::~KXMLGUIBuilder()
101 TQWidget *KXMLGUIBuilder::widget()
106 TQStringList KXMLGUIBuilder::containerTags()
const
109 res << d->tagMenu << d->tagToolBar << d->tagMainWindow << d->tagMenuBar << d->tagStatusBar;
117 if ( element.tagName().lower() == d->tagMainWindow )
120 if ( ::tqt_cast<TDEMainWindow *>( d->m_widget ) )
126 if ( element.tagName().lower() == d->tagMenuBar )
130 if ( ::tqt_cast<TDEMainWindow *>( d->m_widget ) )
139 if ( element.tagName().lower() == d->tagMenu )
147 TQWidget* p = parent;
148 while ( p && !::tqt_cast<TDEMainWindow *>( p ) )
149 p = p->parentWidget();
151 TQCString name = element.attribute( d->attrName ).utf8();
153 if (!kapp->authorizeTDEAction(name))
159 TQDomElement textElem = element.namedItem( d->attrText1 ).toElement();
160 if ( textElem.isNull() )
161 textElem = element.namedItem( d->attrText2 ).toElement();
162 TQCString text = textElem.text().utf8();
163 TQCString context = textElem.attribute(d->attrContext).utf8();
165 if ( text.isEmpty() )
166 i18nText = i18n(
"No text!" );
167 else if ( context.isEmpty() )
168 i18nText = i18n( text );
170 i18nText = i18n( context, text );
172 TQString icon = element.attribute( d->attrIcon );
175 if ( !icon.isEmpty() )
181 pix = SmallIconSet( icon, 16, instance );
184 if ( parent && ::tqt_cast<KMenuBar *>( parent ) )
186 if ( !icon.isEmpty() )
187 id =
static_cast<KMenuBar *
>(parent)->insertItem( pix, i18nText, popup, -1, index );
189 id =
static_cast<KMenuBar *
>(parent)->insertItem( i18nText, popup, -1, index );
191 else if ( parent && ::tqt_cast<TQPopupMenu *>( parent ) )
193 if ( !icon.isEmpty() )
194 id =
static_cast<TQPopupMenu *
>(parent)->insertItem( pix, i18nText, popup, -1, index );
196 id =
static_cast<TQPopupMenu *
>(parent)->insertItem( i18nText, popup, -1, index );
202 if ( element.tagName().lower() == d->tagToolBar )
204 bool honor = (element.attribute( d->attrName ) ==
"mainToolBar");
206 TQCString name = element.attribute( d->attrName ).utf8();
211 bar =
new TDEToolBar( d->m_widget, name, honor,
false );
214 if ( ::tqt_cast<TDEMainWindow *>( d->m_widget ) )
216 if ( d->m_client && !d->m_client->xmlFile().isEmpty() )
217 bar->setXMLGUIClient( d->m_client );
225 if ( element.tagName().lower() == d->tagStatusBar )
227 if ( ::tqt_cast<TDEMainWindow *>( d->m_widget ) )
244 if ( ::tqt_cast<TQPopupMenu *>( container ) )
248 if ( ::tqt_cast<KMenuBar *>( parent ) )
249 static_cast<KMenuBar *
>(parent)->removeItem(
id );
250 else if ( ::tqt_cast<TQPopupMenu *>( parent ) )
251 static_cast<TQPopupMenu *
>(parent)->removeItem(
id );
256 else if ( ::tqt_cast<TDEToolBar *>( container ) )
263 else if ( ::tqt_cast<KMenuBar *>( container ) )
272 else if ( ::tqt_cast<KStatusBar *>( container ) )
274 if ( ::tqt_cast<TDEMainWindow *>( d->m_widget ) )
280 kdWarning() <<
"Unhandled container to remove : " << container->className() <<
endl;
283 TQStringList KXMLGUIBuilder::customTags()
const
286 res << d->tagSeparator << d->tagTearOffHandle << d->tagMenuTitle;
290 int KXMLGUIBuilder::createCustomElement( TQWidget *parent,
int index,
const TQDomElement &element )
292 if ( element.tagName().lower() == d->tagSeparator )
294 if ( ::tqt_cast<TQPopupMenu *>( parent ) )
297 TQPopupMenu *menu =
static_cast<TQPopupMenu *
>(parent);
298 int count = menu->count();
302 if ((index == -1) || (index > count))
303 previousId = menu->idAt(count-1);
305 previousId = menu->idAt(index-1);
306 if (previousId != -1)
308 if (menu->text(previousId).isEmpty() &&
309 !menu->iconSet(previousId) &&
310 !menu->pixmap(previousId))
318 return menu->insertSeparator( index );
320 else if ( ::tqt_cast<TQMenuBar *>( parent ) )
321 return static_cast<TQMenuBar *
>(parent)->insertSeparator( index );
322 else if ( ::tqt_cast<TDEToolBar *>( parent ) )
326 bool isLineSep =
true;
328 TQDomNamedNodeMap attributes = element.attributes();
330 for (; i < attributes.length(); i++ )
332 TQDomAttr attr = attributes.item( i ).toAttr();
334 if ( attr.name().lower() == d->attrLineSeparator &&
335 attr.value().lower() == TQString::fromLatin1(
"false") )
352 else if ( element.tagName().lower() == d->tagTearOffHandle )
355 return static_cast<TQPopupMenu *
>(parent)->insertTearOffHandle( -1, index );
357 else if ( element.tagName().lower() == d->tagMenuTitle )
359 if ( ::tqt_cast<TDEPopupMenu *>( parent ) )
362 TQCString text = element.text().utf8();
364 if ( text.isEmpty() )
365 i18nText = i18n(
"No text!" );
367 i18nText = i18n( text );
369 TQString icon = element.attribute( d->attrIcon );
372 if ( !icon.isEmpty() )
378 pix = SmallIcon( icon, instance );
381 if ( !icon.isEmpty() )
382 return static_cast<TDEPopupMenu *
>(parent)->insertTitle( pix, i18nText, -1, index );
384 return static_cast<TDEPopupMenu *
>(parent)->insertTitle( i18nText, -1, index );
390 void KXMLGUIBuilder::removeCustomElement( TQWidget *parent,
int id )
392 if ( ::tqt_cast<TQPopupMenu *>( parent ) )
393 static_cast<TQPopupMenu *
>(parent)->removeItem(
id );
394 else if ( ::tqt_cast<TQMenuBar *>( parent ) )
395 static_cast<TQMenuBar *
>(parent)->removeItem(
id );
396 else if ( ::tqt_cast<TDEToolBar *>( parent ) )
405 void KXMLGUIBuilder::setBuilderClient(
KXMLGUIClient *client )
407 d->m_client = client;
409 setBuilderInstance( client->
instance() );
412 TDEInstance *KXMLGUIBuilder::builderInstance()
const
414 return d->m_instance;
417 void KXMLGUIBuilder::setBuilderInstance(
TDEInstance *instance )
424 if ( !d->m_widget || !::tqt_cast<TDEMainWindow *>( d->m_widget ) )
428 TQPtrListIterator<TDEToolBar> it( ( (
TDEMainWindow*)d->m_widget )->toolBarIterator() );
429 while ( ( toolbar = it.current() ) ) {
430 kdDebug() <<
"KXMLGUIBuilder::finalizeGUI toolbar=" << (
void*)toolbar <<
endl;
435 static_cast<TDEMainWindow *
>(d->m_widget)->finalizeGUI(
false );
439 void KXMLGUIBuilder::virtual_hook(
int,
void* )
virtual void removeContainer(TQWidget *container, TQWidget *parent, TQDomElement &element, int id)
Removes the given (and previously via createContainer ) created container.
virtual TQWidget * createContainer(TQWidget *parent, int index, const TQDomElement &element, int &id)
Creates a container (menubar/menu/toolbar/statusbar/separator/...) from an element in the XML file.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
virtual TDEInstance * instance() const
static int getToolButtonID()
How it works.
static TearOffHandle insertTearOffHandle()
static TDEInstance * instance()
KDE top level main window
KMenuBar * menuBar()
Returns a pointer to the menu bar.
KStatusBar * statusBar()
Returns a pointer to the status bar.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdWarning(int area=0)
kdbgstream kdDebug(int area=0)