# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kwindowlistmenu.cpp

    00001 /*****************************************************************
    00002
    00003 Copyright (c) 2000 Matthias Elter <elter@kde.org>
    00004                    Matthias Ettrich <ettrich@kde.org>
    00005
    00006 Permission is hereby granted, free of charge, to any person obtaining a copy
    00007 of this software and associated documentation files (the "Software"), to deal
    00008 in the Software without restriction, including without limitation the rights
    00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00010 copies of the Software, and to permit persons to whom the Software is
    00011 furnished to do so, subject to the following conditions:
    00012
    00013 The above copyright notice and this permission notice shall be included in
    00014 all copies or substantial portions of the Software.
    00015
    00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00022
    00023 ******************************************************************/
    00024
    00025 #include <qvaluelist.h>
    00026
    00027 #include <kwin.h>
    00028 #include <kwinmodule.h>
    00029 #include <klocale.h>
    00030 #include <kstringhandler.h>
    00031 #ifndef Q_WS_QWS //FIXME
    00032 #include <netwm.h>
    00033 #endif
    00034 #include <kapplication.h>
    00035 #include <dcopclient.h>
    00036
    00037 #undef Bool
    00038 #include "kwindowlistmenu.h"
    00039 #include "kwindowlistmenu.moc"
    00040
    00041 // helper class
    00042 class NameSortedInfoList : public QPtrList<KWin::Info>
    00043 {
    00044 public:
    00045     NameSortedInfoList() { setAutoDelete(true); };
    00046     ~NameSortedInfoList() {};
    00047
    00048 private:
    00049     int compareItems( QPtrCollection::Item s1, QPtrCollection::Item s2 );
    00050 };
    00051
    00052 int NameSortedInfoList::compareItems( QPtrCollection::Item s1, QPtrCollection::Item s2 )
    00053 {
    00054 #ifndef Q_WS_QWS //FIXME
    00055     KWin::Info *i1 = static_cast<KWin::Info *>(s1);
    00056     KWin::Info *i2 = static_cast<KWin::Info *>(s2);
    00057     QString title1, title2;
    00058     if (i1)
    00059         title1 = i1->visibleNameWithState().lower();
    00060     if (i2)
    00061         title2 = i2->visibleNameWithState().lower();
    00062     return title1.compare(title2);
    00063 #endif
    00064 }
    00065
    00066 KWindowListMenu::KWindowListMenu(QWidget *parent, const char *name)
    00067   : KPopupMenu(parent, name)
    00068 {
    00069 #ifndef Q_WS_QWS //FIXME
    00070     kwin_module = new KWinModule(this);
    00071 #endif
    00072
    00073     connect(this, SIGNAL(activated(int)), SLOT(slotExec(int)));
    00074 }
    00075
    00076 KWindowListMenu::~KWindowListMenu()
    00077 {
    00078
    00079 }
    00080
    00081 void KWindowListMenu::init()
    00082 {
    00083     int i, d;
    00084     i = 0;
    00085
    00086 #ifndef Q_WS_QWS //FIXME
    00087     int nd = kwin_module->numberOfDesktops();
    00088     int cd = kwin_module->currentDesktop();
    00089     WId active_window = kwin_module->activeWindow();
    00090
    00091     clear();
    00092     map.clear();
    00093
    00094     insertItem( i18n("Unclutter Windows"),
    00095                 this, SLOT( slotUnclutterWindows() ) );
    00096     insertItem( i18n("Cascade Windows"),
    00097                 this, SLOT( slotCascadeWindows() ) );
    00098
    00099     insertSeparator();
    00100
    00101     for (d = 1; d <= nd; d++) {
    00102         if (nd > 1)
    00103             insertItem( kwin_module->desktopName( d ), 1000 + d);
    00104
    00105         int items = 0;
    00106
    00107         if (!active_window && d == cd)
    00108             setItemChecked(1000 + d, TRUE);
    00109
    00110         NameSortedInfoList list;
    00111         list.setAutoDelete(true);
    00112
    00113         for (QValueList<WId>::ConstIterator it = kwin_module->windows().begin();
    00114              it != kwin_module->windows().end(); ++it) {
    00115             KWin::Info info = KWin::info( *it );
    00116             if ((info.desktop == d) || (d == cd && info.onAllDesktops))
    00117                 list.inSort(new KWin::Info(info));
    00118         }
    00119
    00120         for (KWin::Info* info = list.first(); info!=0; info = list.next(), i++)
    00121         {
    00122             QString title = info->visibleNameWithState();
    00123             if ( info->windowType == NET::Normal || info->windowType == NET::Unknown ) {
    00124                 QPixmap pm = KWin::icon(info->win, 16, 16, true );
    00125                 items++;
    00126                 if (items == 1 && nd > 1)
    00127                     insertSeparator();
    00128                 QString itemText =  KStringHandler::csqueeze(title,25);
    00129                 // Avoid creating unwanted accelerators.
    00130                 itemText.replace(QRegExp("&"), "&&");
    00131                 insertItem( pm, QString("   ")+ itemText, i);
    00132                 map.insert(i, info->win);
    00133                 if (info->win == active_window)
    00134                     setItemChecked(i, TRUE);
    00135             }
    00136         }
    00137         if (d < nd)
    00138             insertSeparator();
    00139     }
    00140 #endif
    00141     adjustSize();
    00142 }
    00143
    00144 void KWindowListMenu::slotExec(int id)
    00145 {
    00146 #ifndef Q_WS_QWS //FIXME
    00147     if (id > 1000)
    00148         KWin::setCurrentDesktop(id - 1000);
    00149     else if ( id >= 0 )
    00150         KWin::setActiveWindow(map[id]);
    00151 #endif
    00152 }
    00153
    00154 void KWindowListMenu::slotUnclutterWindows()
    00155 {
    00156     kapp->dcopClient()->send("kwin", "KWinInterface", "unclutterDesktop()", "");
    00157 }
    00158
    00159 void KWindowListMenu::slotCascadeWindows()
    00160 {
    00161     kapp->dcopClient()->send("kwin", "KWinInterface", "cascadeDesktop()", "");
    00162 }
    00163
    00164 void KWindowListMenu::virtual_hook( int id, void* data )
    00165 { KPopupMenu::virtual_hook( id, data ); }
    00166

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:59 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001