~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/FbTk/Button.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
 
// Button.cc for FbTk - fluxbox toolkit
2
 
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//
4
 
// Permission is hereby granted, free of charge, to any person obtaining a
5
 
// copy of this software and associated documentation files (the "Software"),
6
 
// to deal in the Software without restriction, including without limitation
7
 
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 
// and/or sell copies of the Software, and to permit persons to whom the
9
 
// Software is furnished to do so, subject to the following conditions:
10
 
//
11
 
// The above copyright notice and this permission notice shall be included in
12
 
// all copies or substantial portions of the Software.
13
 
//
14
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
 
// DEALINGS IN THE SOFTWARE.
21
 
 
22
 
// $Id: Button.cc 3933 2005-04-13 14:39:25Z simonb $
23
 
 
24
 
#include "Button.hh"
25
 
 
26
 
#include "Command.hh"
27
 
#include "EventManager.hh"
28
 
#include "App.hh"
29
 
 
30
 
namespace FbTk {
31
 
 
32
 
Button::Button(int screen_num, int x, int y,
33
 
               unsigned int width, unsigned int height):
34
 
    FbWindow(screen_num, x, y, width, height,
35
 
             ExposureMask | ButtonPressMask | ButtonReleaseMask),
36
 
    m_background_pm(0),
37
 
    m_pressed_pm(0),
38
 
    m_pressed_color(),
39
 
    m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)),
40
 
    m_pressed(false) {
41
 
 
42
 
    // add this to eventmanager
43
 
    FbTk::EventManager::instance()->add(*this, *this); 
44
 
}
45
 
 
46
 
Button::Button(const FbWindow &parent, int x, int y, 
47
 
               unsigned int width, unsigned int height):
48
 
    FbWindow(parent, x, y, width, height,
49
 
             ExposureMask | ButtonPressMask | ButtonReleaseMask),
50
 
    m_background_pm(0),
51
 
    m_pressed_pm(0),
52
 
    m_pressed_color(),
53
 
    m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())),
54
 
    m_pressed(false) {
55
 
    // add this to eventmanager
56
 
    FbTk::EventManager::instance()->add(*this, *this);
57
 
}
58
 
 
59
 
Button::~Button() {
60
 
 
61
 
}
62
 
 
63
 
void Button::setOnClick(RefCount<Command> &cmd, int button) {
64
 
    // we only handle buttons 1 to 5
65
 
    if (button > 5 || button == 0)
66
 
        return;
67
 
    //set on click command for the button
68
 
    m_onclick[button - 1] = cmd;
69
 
}
70
 
 
71
 
void Button::setPressedPixmap(Pixmap pm) {
72
 
    m_pressed_pm = pm;
73
 
}
74
 
 
75
 
void Button::setPressedColor(const FbTk::Color &color) {
76
 
    m_pressed_pm = None;
77
 
    m_pressed_color = color;
78
 
}
79
 
 
80
 
void Button::setBackgroundColor(const Color &color) {
81
 
    m_background_pm = 0; // we're using background color now
82
 
    m_background_color = color;    
83
 
    FbTk::FbWindow::setBackgroundColor(color);
84
 
}
85
 
 
86
 
void Button::setBackgroundPixmap(Pixmap pm) {
87
 
    m_background_pm = pm;
88
 
    FbTk::FbWindow::setBackgroundPixmap(pm);
89
 
}
90
 
 
91
 
void Button::buttonPressEvent(XButtonEvent &event) {
92
 
    bool update = false;
93
 
    if (m_pressed_pm != 0) {
94
 
        update = true;
95
 
        FbTk::FbWindow::setBackgroundPixmap(m_pressed_pm);
96
 
    } else if (m_pressed_color.isAllocated()) {
97
 
        update = true;
98
 
        FbTk::FbWindow::setBackgroundColor(m_pressed_color);
99
 
    }
100
 
        
101
 
    m_pressed = true;    
102
 
    if (update) {
103
 
        clear();
104
 
    }
105
 
}
106
 
 
107
 
void Button::buttonReleaseEvent(XButtonEvent &event) {
108
 
    m_pressed = false;
109
 
    bool update = false;
110
 
    if (m_background_pm) {
111
 
        if (m_pressed_pm != 0) {
112
 
            update = true;
113
 
            setBackgroundPixmap(m_background_pm);
114
 
        }
115
 
    } else if (m_pressed_color.isAllocated()) {
116
 
        update = true;
117
 
        setBackgroundColor(m_background_color);
118
 
    }
119
 
 
120
 
    if (update)
121
 
        clear(); // clear background
122
 
 
123
 
    // finaly, execute command (this must be done last since this object might be deleted by the command)
124
 
    if (event.button > 0 && event.button <= 5 &&
125
 
        event.x > 0 && event.x < static_cast<signed>(width()) &&
126
 
        event.y > 0 && event.y < static_cast<signed>(height()) &&
127
 
        m_onclick[event.button -1].get() != 0)
128
 
        m_onclick[event.button - 1]->execute();
129
 
 
130
 
 
131
 
}
132
 
 
133
 
void Button::exposeEvent(XExposeEvent &event) {
134
 
    clearArea(event.x, event.y, event.width, event.height);
135
 
}
136
 
 
137
 
}; // end namespace FbTk