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

« back to all changes in this revision

Viewing changes to src/FbTk/MenuIcon.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
 
// MenuIcon.cc for FbTk - Fluxbox ToolKit
2
 
// Copyright (c) 2004 - 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: MenuIcon.cc 3954 2005-04-26 01:41:55Z simonb $
24
 
 
25
 
#include "MenuIcon.hh"
26
 
 
27
 
#include "MenuTheme.hh"
28
 
#include "Image.hh"
29
 
#include "App.hh"
30
 
 
31
 
namespace FbTk {
32
 
 
33
 
MenuIcon::MenuIcon(const std::string &filename, const std::string &label, int screen_num):
34
 
    MenuItem(label.c_str()),
35
 
    m_filename(filename) {
36
 
    FbTk::PixmapWithMask *pm = Image::load(filename.c_str(), screen_num);
37
 
    if (pm != 0) {
38
 
        m_pixmap = pm->pixmap().release();
39
 
        m_mask = pm->mask().release();
40
 
        delete pm;
41
 
    }
42
 
 
43
 
}
44
 
 
45
 
void MenuIcon::updateTheme(const MenuTheme &theme) {
46
 
    FbTk::PixmapWithMask *pm = Image::load(m_filename.c_str(), theme.screenNum());
47
 
    if (pm != 0) {
48
 
        m_pixmap = pm->pixmap().release();
49
 
        m_mask = pm->mask().release();
50
 
        delete pm;
51
 
    }
52
 
}
53
 
 
54
 
void MenuIcon::draw(FbDrawable &drawable,
55
 
                    const MenuTheme &theme,
56
 
                    bool highlight, bool draw_foreground, bool draw_background,
57
 
                    int x, int y,
58
 
                    unsigned int width, unsigned int height) const {
59
 
 
60
 
    // all background
61
 
    if (draw_background) {
62
 
        Display *disp = FbTk::App::instance()->display();
63
 
        if (height - 2*theme.bevelWidth() != m_pixmap.height() &&
64
 
            !m_filename.empty()) {
65
 
            unsigned int scale_size = height - 2*theme.bevelWidth();
66
 
            m_pixmap.scale(scale_size, scale_size);
67
 
            m_mask.scale(scale_size, scale_size);
68
 
        }
69
 
 
70
 
        if (m_pixmap.drawable() != 0) {
71
 
            GC gc = theme.frameTextGC().gc();
72
 
 
73
 
            // enable clip mask
74
 
            XSetClipMask(disp, gc, m_mask.drawable());
75
 
            XSetClipOrigin(disp, gc, x + theme.bevelWidth(), y + theme.bevelWidth());
76
 
 
77
 
            drawable.copyArea(m_pixmap.drawable(),
78
 
                              gc,
79
 
                              0, 0,
80
 
                              x + theme.bevelWidth(), y + theme.bevelWidth(),
81
 
                              m_pixmap.width(), m_pixmap.height());
82
 
 
83
 
            // restore clip mask
84
 
            XSetClipMask(disp, gc, None);
85
 
        }
86
 
    }
87
 
    FbTk::MenuItem::draw(drawable, theme, highlight, 
88
 
                         draw_background, draw_foreground, x, y, width, height);
89
 
}
90
 
 
91
 
unsigned int MenuIcon::width(const MenuTheme &theme) const {
92
 
    return MenuItem::width(theme) + 2 * (theme.bevelWidth()  + height(theme));
93
 
}
94
 
 
95
 
} // end namespace FbTk
96