1 // GContext.cc for FbTk - fluxbox toolkit
2 // Copyright (c) 2003 - 2006 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: GContext.cc 4199 2006-02-16 06:53:05Z mathias $
23 
24 #include "GContext.hh"
25 
26 #include "App.hh"
27 #include "FbDrawable.hh"
28 #include "FbPixmap.hh"
29 #include "Color.hh"
30 #include "Font.hh"
31 
32 namespace FbTk {
33 
34 Display *GContext::m_display = 0;
35 
GContext(const FbTk::FbDrawable & drawable)36 GContext::GContext(const FbTk::FbDrawable &drawable):
37     m_gc(XCreateGC(drawable.display(), drawable.drawable(), 0, 0)) {
38 
39     if (m_display == 0)
40         m_display = drawable.display();
41 
42     setGraphicsExposure(false);
43 }
44 
GContext(Drawable drawable)45 GContext::GContext(Drawable drawable):
46     m_gc(XCreateGC(m_display != 0 ? m_display : FbTk::App::instance()->display(),
47                    drawable,
48                    0, 0)) {
49     if (m_display == 0)
50         m_display = FbTk::App::instance()->display();
51     setGraphicsExposure(false);
52 }
53 
GContext(Drawable d,const GContext & gc)54 GContext::GContext(Drawable d, const GContext &gc):
55     m_gc(XCreateGC(m_display != 0 ? m_display : FbTk::App::instance()->display(),
56                    d,
57                    0, 0)) {
58     if (m_display == 0)
59         m_display = FbTk::App::instance()->display();
60     setGraphicsExposure(false);
61     copy(gc);
62 }
63 
~GContext()64 GContext::~GContext() {
65     if (m_gc)
66         XFreeGC(m_display, m_gc);
67 }
68 
69 /// not implemented!
70 //void GContext::setFont(const FbTk::Font &font) {
71     //!! TODO
72 //}
copy(GC gc)73 void GContext::copy(GC gc) {
74     // copy gc with mask: all
75     XCopyGC(m_display, gc, ~0, m_gc);
76 }
77 
copy(const GContext & gc)78 void GContext::copy(const GContext &gc) {
79     // copy X gc
80     copy(gc.gc());
81 
82     //!! TODO: copy our extended gcontext
83 
84 }
85 
86 } // end namespace FbTk
87