~ubuntu-branches/ubuntu/precise/fluxbox/precise

« back to all changes in this revision

Viewing changes to src/SendToMenu.cc

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// SendToMenu.cc for Fluxbox
2
 
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//                and Simon Bowden    (rathnor at users.sourceforge.net)
4
 
// 
5
 
// Permission is hereby granted, free of charge, to any person obtaining a
6
 
// copy of this software and associated documentation files (the "Software"),
7
 
// to deal in the Software without restriction, including without limitation
8
 
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 
// and/or sell copies of the Software, and to permit persons to whom the
10
 
// Software is furnished to do so, subject to the following conditions:
11
 
//
12
 
// The above copyright notice and this permission notice shall be included in
13
 
// all copies or substantial portions of the Software.
14
 
//
15
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 
// DEALINGS IN THE SOFTWARE.
22
 
 
23
 
// $Id: SendToMenu.cc 4062 2005-06-23 03:07:25Z fluxgen $
24
 
 
25
 
#include "SendToMenu.hh"
26
 
 
27
 
#include "Window.hh"
28
 
#include "Screen.hh"
29
 
#include "fluxbox.hh"
30
 
#include "Workspace.hh"
31
 
#include "WindowCmd.hh"
32
 
 
33
 
#include "FbTk/MultiButtonMenuItem.hh"
34
 
#include "FbTk/Command.hh"
35
 
 
36
 
class SendToCmd: public FbTk::Command {
37
 
public:
38
 
    SendToCmd(int workspace, bool follow):
39
 
        m_workspace(workspace),
40
 
        m_follow(follow) { }
41
 
    void execute() {
42
 
        if (WindowCmd<void>::window() != 0)
43
 
            WindowCmd<void>::window()->screen().sendToWorkspace(m_workspace, WindowCmd<void>::window(), m_follow);
44
 
    }
45
 
private:
46
 
    const int m_workspace;
47
 
    const bool m_follow;
48
 
};
49
 
 
50
 
SendToMenu::SendToMenu(BScreen &screen):
51
 
    FbMenu(screen.menuTheme(),
52
 
           screen.imageControl(), 
53
 
           *screen.layerManager().getLayer(Fluxbox::instance()->getMenuLayer())) {
54
 
    // listen to:
55
 
    // workspace count signal
56
 
    // workspace names signal
57
 
    // current workspace signal
58
 
    screen.workspaceCountSig().attach(this);
59
 
    screen.workspaceNamesSig().attach(this);
60
 
    screen.currentWorkspaceSig().attach(this);
61
 
 
62
 
    disableTitle();
63
 
    // build menu
64
 
    update(0);
65
 
}
66
 
 
67
 
void SendToMenu::update(FbTk::Subject *subj) {
68
 
    if (subj != 0) {
69
 
        if (subj == &(theme().reconfigSig())) {
70
 
            // we got reconfig Theme signal, let base menu handle it 
71
 
            FbTk::Menu::update(subj);
72
 
            return;
73
 
        }
74
 
        
75
 
    }
76
 
    // rebuild menu
77
 
 
78
 
    removeAll();
79
 
    BScreen *screen = Fluxbox::instance()->findScreen(screenNumber());
80
 
    const BScreen::Workspaces &wlist = screen->getWorkspacesList();
81
 
    for (size_t i = 0; i < wlist.size(); ++i) {
82
 
        FbTk::RefCount<FbTk::Command> sendto_cmd(new SendToCmd(i, false));
83
 
        FbTk::RefCount<FbTk::Command> sendto_follow_cmd(new SendToCmd(i, true));
84
 
        
85
 
        FbTk::MultiButtonMenuItem* item = new FbTk::MultiButtonMenuItem(3, wlist[i]->name().c_str());
86
 
        item->setCommand(1, sendto_cmd);
87
 
        item->setCommand(2, sendto_follow_cmd);
88
 
        item->setCommand(3, sendto_cmd);
89
 
        insert(item);
90
 
    }
91
 
 
92
 
    updateMenu();
93
 
}
94
 
 
95
 
void SendToMenu::show() {
96
 
    if (WindowCmd<void>::window() != 0) {
97
 
        for (unsigned int i=0; i < numberOfItems(); ++i)
98
 
            setItemEnabled(i, true);
99
 
        setItemEnabled(WindowCmd<void>::window()->workspaceNumber(), false);
100
 
        updateMenu();
101
 
    }
102
 
    FbTk::Menu::show();
103
 
}
104