• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
ksharedpixmap.cpp
1/*
2 *
3 *
4 * This file is part of the KDE libraries.
5 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * Shared pixmap client for KDE.
13 */
14#include "config.h"
15
16#include <tqrect.h>
17#include <tqsize.h>
18#include <tqstring.h>
19#include <tqpixmap.h>
20#include <tqwindowdefs.h>
21#include <tqwidget.h>
22
23#ifdef TQ_WS_X11
24
25#include <tdeapplication.h>
26#include <krootprop.h>
27#include <ksharedpixmap.h>
28#include <kdebug.h>
29#include <stdlib.h> // for abs
30
31#include <X11/Xlib.h>
32
33// Make sure to include all this X-based shit before we clean up the mess.
34// Needed for --enable-final. Not needed by this file itself!
35#include <X11/Xutil.h>
36#ifdef HAVE_MITSHM
37#include <X11/extensions/XShm.h>
38#endif
39
40#include <netwm.h>
41
42// Clean up the mess
43
44#undef Bool
45#undef Above
46#undef Below
47#undef KeyPress
48#undef KeyRelease
49#undef FocusOut
50
55class TDESharedPixmapPrivate
56{
57public:
58 Atom pixmap;
59 Atom target;
60 Atom selection;
61 TQRect rect;
62};
63
64TDESharedPixmap::TDESharedPixmap()
65 : TQWidget(0L, "shpixmap comm window")
66{
67 d = new TDESharedPixmapPrivate;
68 init();
69}
70
71
72TDESharedPixmap::~TDESharedPixmap()
73{
74 delete d;
75}
76
77
78void TDESharedPixmap::init()
79{
80 d->pixmap = XInternAtom(tqt_xdisplay(), "PIXMAP", false);
81 TQCString atom;
82 atom.sprintf("target prop for window %lx", static_cast<unsigned long int>(winId()));
83 d->target = XInternAtom(tqt_xdisplay(), atom.data(), false);
84 d->selection = None;
85}
86
87
88bool TDESharedPixmap::isAvailable(const TQString & name) const
89{
90 TQString str = TQString("KDESHPIXMAP:%1").arg(name);
91 Atom sel = XInternAtom(tqt_xdisplay(), str.latin1(), true);
92 if (sel == None)
93 return false;
94 return XGetSelectionOwner(tqt_xdisplay(), sel) != None;
95}
96
97
98bool TDESharedPixmap::loadFromShared(const TQString & name, const TQRect & rect)
99{
100 d->rect = rect;
101 if (d->selection != None)
102 // already active
103 return false;
104
105 TQPixmap::resize(0, 0); // invalidate
106
107 TQString str = TQString("KDESHPIXMAP:%1").arg(name);
108 d->selection = XInternAtom(tqt_xdisplay(), str.latin1(), true);
109 if (d->selection == None)
110 return false;
111 if (XGetSelectionOwner(tqt_xdisplay(), d->selection) == None)
112 {
113 d->selection = None;
114 return false;
115 }
116
117 XConvertSelection(tqt_xdisplay(), d->selection, d->pixmap, d->target,
118 winId(), CurrentTime);
119 return true;
120}
121
122
123bool TDESharedPixmap::x11Event(XEvent *event)
124{
125 if (event->type != SelectionNotify)
126 return false;
127
128 XSelectionEvent *ev = &event->xselection;
129 if (ev->selection != d->selection)
130 return false;
131
132 if ((ev->target != d->pixmap) || (ev->property == None))
133 {
134 kdWarning(270) << k_funcinfo << "illegal selection notify event.\n";
135 d->selection = None;
136 emit done(false);
137 return true;
138 }
139
140 // Read pixmap handle from ev->property
141
142 int dummy, format;
143 unsigned long nitems, ldummy;
144 unsigned char *pixmap_id = 0;
145 Atom type;
146
147 XGetWindowProperty(tqt_xdisplay(), winId(), ev->property, 0, 1, false,
148 d->pixmap, &type, &format, &nitems, &ldummy,
149 &pixmap_id);
150
151 if (nitems != 1 || !pixmap_id)
152 {
153 kdWarning(270) << k_funcinfo << "could not read property, nitems = " << nitems << "\n";
154 emit done(false);
155 return true;
156 }
157
158 Window root;
159 unsigned int width, height, udummy;
160 void *drawable_id = (void *) pixmap_id;
161 Drawable pixmap = *(Drawable*) drawable_id;
162
163 if (!XGetGeometry(tqt_xdisplay(), pixmap, &root, &dummy, &dummy, &width, &height, &udummy, &udummy)) {
164 return false;
165 }
166
167 if (d->rect.isEmpty())
168 {
169 TQPixmap::resize(width, height);
170 XCopyArea(tqt_xdisplay(), pixmap, ((KPixmap*)this)->handle(), tqt_xget_temp_gc(tqt_xscreen(), false),
171 0, 0, width, height, 0, 0);
172
173 XFree(pixmap_id);
174 XDeleteProperty(tqt_xdisplay(), winId(), ev->property);
175 d->selection = None;
176 emit done(true);
177 return true;
178 }
179
180 // Do some more processing here: Generate a tile that can be used as a
181 // background tile for the rectangle "rect".
182
183 //Check for origin off screen
184 TQPoint origin(0, 0);
185 if( d->rect.topLeft().x() < 0 || d->rect.topLeft().y() < 0 ) {
186 //Save the offset and relocate the rect corners
187 TQPoint tl = d->rect.topLeft();
188 TQPoint br = d->rect.bottomRight();
189 if( tl.x() < 0 ) {
190 origin.setX( abs( tl.x() ) );
191 tl.setX( 0 );
192 }
193 if( tl.y() < 0 ) {
194 origin.setY( abs( tl.y() ) );
195 tl.setY( 0 );
196 }
197 TQRect adjustedRect( tl, br );
198 d->rect = adjustedRect;
199 }
200
201 unsigned w = d->rect.width(), h = d->rect.height();
202 unsigned tw = TQMIN(width, w), th = TQMIN(height, h);
203 unsigned xa = d->rect.x() % width, ya = d->rect.y() % height;
204 unsigned t1w = TQMIN(width-xa,tw), t1h = TQMIN(height-ya,th);
205
206 TQPixmap::resize( tw+origin.x(), th+origin.y() );
207
208 XCopyArea(tqt_xdisplay(), pixmap, (static_cast<KPixmap*>(this))->handle(), tqt_xget_temp_gc(tqt_xscreen(), false),
209 xa, ya, t1w+origin.x(), t1h+origin.y(), origin.x(), origin.y() );
210 XCopyArea(tqt_xdisplay(), pixmap, (static_cast<KPixmap*>(this))->handle(), tqt_xget_temp_gc(tqt_xscreen(), false),
211 0, ya, tw-t1w, t1h, t1w, 0);
212 XCopyArea(tqt_xdisplay(), pixmap, (static_cast<KPixmap*>(this))->handle(), tqt_xget_temp_gc(tqt_xscreen(), false),
213 xa, 0, t1w, th-t1h, 0, t1h);
214 XCopyArea(tqt_xdisplay(), pixmap, (static_cast<KPixmap*>(this))->handle(), tqt_xget_temp_gc(tqt_xscreen(), false),
215 0, 0, tw-t1w, th-t1h, t1w, t1h);
216
217 XFree(pixmap_id);
218
219 d->selection = None;
220 XDeleteProperty(tqt_xdisplay(), winId(), ev->property);
221 emit done(true);
222 return true;
223}
224
225
226#include "ksharedpixmap.moc"
227#endif
KPixmap
kdWarning
kdbgstream kdWarning(int area=0)
KNotifyClient::event
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.