tdemainwindowiface.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Ian Reinhart Geiser <geiseri@yahoo.com> 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the Lesser GNU General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 General Public License for more details. 00013 00014 You should have received a copy of the Lesser GNU General Public License 00015 along with this program; see the file COPYING. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "tdemainwindowiface.h" 00021 00022 #include <dcopclient.h> 00023 #include <tdeapplication.h> 00024 #include <kdcopactionproxy.h> 00025 #include <kdcoppropertyproxy.h> 00026 #include <tdemainwindow.h> 00027 #include <tdeaction.h> 00028 #include <tqclipboard.h> 00029 00030 #include <twin.h> 00031 00032 TDEMainWindowInterface::TDEMainWindowInterface(TDEMainWindow * mainWindow) 00033 : DCOPObject( mainWindow->name()) 00034 { 00035 m_MainWindow = mainWindow; 00036 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00037 m_dcopPropertyProxy = new KDCOPPropertyProxy(TQT_TQOBJECT(m_MainWindow)); 00038 } 00039 00040 TDEMainWindowInterface::~TDEMainWindowInterface() 00041 { 00042 delete m_dcopActionProxy; 00043 delete m_dcopPropertyProxy; 00044 } 00045 00046 QCStringList TDEMainWindowInterface::actions() 00047 { 00048 delete m_dcopActionProxy; 00049 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00050 QCStringList tmp_actions; 00051 TQValueList<TDEAction *> lst = m_dcopActionProxy->actions(); 00052 TQValueList<TDEAction *>::ConstIterator it = lst.begin(); 00053 TQValueList<TDEAction *>::ConstIterator end = lst.end(); 00054 for (; it != end; ++it ) 00055 if ((*it)->isPlugged()) 00056 tmp_actions.append( (TQCString)(*it)->name() ); 00057 return tmp_actions; 00058 } 00059 bool TDEMainWindowInterface::activateAction( TQCString action) 00060 { 00061 delete m_dcopActionProxy; 00062 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00063 TDEAction *tmp_Action = m_dcopActionProxy->action(action); 00064 if (tmp_Action) 00065 { 00066 tmp_Action->activate(); 00067 return true; 00068 } 00069 else 00070 return false; 00071 } 00072 bool TDEMainWindowInterface::disableAction( TQCString action) 00073 { 00074 delete m_dcopActionProxy; 00075 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00076 TDEAction *tmp_Action = m_dcopActionProxy->action(action); 00077 if (tmp_Action) 00078 { 00079 tmp_Action->setEnabled(false); 00080 return true; 00081 } 00082 else 00083 return false; 00084 } 00085 bool TDEMainWindowInterface::enableAction( TQCString action) 00086 { 00087 delete m_dcopActionProxy; 00088 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00089 TDEAction *tmp_Action = m_dcopActionProxy->action(action); 00090 if (tmp_Action) 00091 { 00092 tmp_Action->setEnabled(true); 00093 return true; 00094 } 00095 else 00096 return false; 00097 } 00098 bool TDEMainWindowInterface::actionIsEnabled( TQCString action) 00099 { 00100 delete m_dcopActionProxy; 00101 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00102 TDEAction *tmp_Action = m_dcopActionProxy->action(action); 00103 if (tmp_Action) 00104 { 00105 return tmp_Action->isEnabled(); 00106 } 00107 else 00108 return false; 00109 } 00110 TQCString TDEMainWindowInterface::actionToolTip( TQCString action) 00111 { 00112 delete m_dcopActionProxy; 00113 m_dcopActionProxy = new KDCOPActionProxy( m_MainWindow->actionCollection(), this ); 00114 TDEAction *tmp_Action = m_dcopActionProxy->action(action); 00115 if (tmp_Action) 00116 { 00117 return tmp_Action->toolTip().utf8(); 00118 } 00119 else 00120 return "Error no such object!"; 00121 } 00122 00123 DCOPRef TDEMainWindowInterface::action( const TQCString &name ) 00124 { 00125 return DCOPRef( kapp->dcopClient()->appId(), m_dcopActionProxy->actionObjectId( name ) ); 00126 } 00127 00128 TQMap<TQCString,DCOPRef> TDEMainWindowInterface::actionMap() 00129 { 00130 return m_dcopActionProxy->actionMap(); 00131 } 00132 00133 int TDEMainWindowInterface::getWinID() 00134 { 00135 return (int) m_MainWindow->winId(); 00136 } 00137 void TDEMainWindowInterface::grabWindowToClipBoard() 00138 { 00139 TQClipboard *clipboard = TQApplication::clipboard(); 00140 clipboard->setPixmap(TQPixmap::grabWidget(m_MainWindow)); 00141 } 00142 void TDEMainWindowInterface::hide() 00143 { 00144 m_MainWindow->hide(); 00145 } 00146 void TDEMainWindowInterface::maximize() 00147 { 00148 m_MainWindow->showMaximized(); 00149 } 00150 void TDEMainWindowInterface::minimize() 00151 { 00152 m_MainWindow->showMinimized(); 00153 } 00154 void TDEMainWindowInterface::resize(int newX, int newY) 00155 { 00156 m_MainWindow->resize(newX, newY); 00157 } 00158 void TDEMainWindowInterface::move(int newX, int newY) 00159 { 00160 m_MainWindow->move(newX, newY); 00161 } 00162 void TDEMainWindowInterface::setGeometry(int newX, int newY, int newWidth, int newHeight) 00163 { 00164 m_MainWindow->setGeometry(newX, newY, newWidth, newHeight); 00165 } 00166 void TDEMainWindowInterface::raise() 00167 { 00168 m_MainWindow->raise(); 00169 } 00170 void TDEMainWindowInterface::lower() 00171 { 00172 m_MainWindow->lower(); 00173 } 00174 void TDEMainWindowInterface::restore() 00175 { 00176 m_MainWindow->showNormal(); 00177 } 00178 void TDEMainWindowInterface::close() 00179 { 00180 m_MainWindow->close(); 00181 } 00182 void TDEMainWindowInterface::show() 00183 { 00184 m_MainWindow->show(); 00185 } 00186 void TDEMainWindowInterface::setActiveWindow() 00187 { 00188 m_MainWindow->setActiveWindow(); 00189 } 00190 void TDEMainWindowInterface::setActiveWindowFocused() 00191 { 00192 // just in case we don't have a WM running 00193 m_MainWindow->raise(); 00194 m_MainWindow->setActiveWindow(); 00195 00196 // activate window (try to work around focus-stealing prevention) 00197 KWin::forceActiveWindow(m_MainWindow->winId()); 00198 } 00199 QCStringList TDEMainWindowInterface::functionsDynamic() 00200 { 00201 return m_dcopPropertyProxy->functions(); 00202 } 00203 bool TDEMainWindowInterface::processDynamic(const TQCString &fun, const TQByteArray &data, TQCString& replyType, TQByteArray &replyData) 00204 { 00205 return m_dcopPropertyProxy->processPropertyRequest( fun, data, replyType, replyData); 00206 00207 } 00208