1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* copyright : (C) 2001-2002 by Richard Moore
* License : This file is released under the terms of the LGPL, version 2.
* email : rich@kde.org
*/
#include <tqobjectlist.h>
#include <tqpixmap.h>
#include <tqtimer.h>
#include <tqtooltip.h>
#include <ksystemtray.h>
#include <twin.h>
#include "twindowinfo.h"
#include "twindowinfo.moc"
static const int UNSPECIFIED_TIMEOUT = -1;
static const int DEFAULT_MESSAGE_TIMEOUT = 3000;
KWindowInfo::KWindowInfo( TQWidget *parent, const char *name )
: TQObject( parent, name ), win( parent ), autoDel( false )
{
}
KWindowInfo::~KWindowInfo()
{
}
void KWindowInfo::showMessage( TQWidget *window, const TQString &text, int timeout )
{
KWindowInfo *info = new KWindowInfo( window );
info->autoDel = true;
info->message( text, timeout );
if ( timeout == 0 )
delete info;
}
void KWindowInfo::showMessage( TQWidget *window, const TQString &text, const TQPixmap &pix, int timeout )
{
KWindowInfo *info = new KWindowInfo( window );
info->autoDel = true;
info->message( text, pix, timeout );
}
void KWindowInfo::message( const TQString &text )
{
message( text, TQPixmap(), UNSPECIFIED_TIMEOUT );
}
void KWindowInfo::message( const TQString &text, const TQPixmap &pix )
{
message( text, pix, UNSPECIFIED_TIMEOUT );
}
void KWindowInfo::message( const TQString &text, int timeout )
{
message( text, TQPixmap(), timeout );
}
void KWindowInfo::message( const TQString &text, const TQPixmap &pix, int timeout )
{
if ( timeout != 0 )
save();
display( text, pix );
if ( timeout < 0 )
timeout = DEFAULT_MESSAGE_TIMEOUT;
if ( timeout != 0 )
TQTimer::singleShot( timeout, this, TQ_SLOT( restore() ) );
}
void KWindowInfo::permanent( const TQString &text )
{
#ifdef TQ_WS_X11
oldMiniIcon = KWin::icon( win->winId(), 16, 16, true );
oldIcon = KWin::icon( win->winId(), 34, 34, false );
if ( oldIcon.isNull() )
oldIcon = KWin::icon( win->winId(), 32, 32, true );
#endif
permanent( text, oldIcon );
}
void KWindowInfo::permanent( const TQString &text, const TQPixmap &pix )
{
if ( !oldText.isNull() ) {
TQObjectList *l = queryList( "TQTimer" );
TQObjectListIt it( *l );
TQObject *obj;
while ( (obj = it.current()) != 0 ) {
++it;
delete obj;
}
delete l;
}
oldText = TQString::null;
display( text, pix );
}
void KWindowInfo::display( const TQString &text, const TQPixmap &pix )
{
TQPixmap icon;
if ( pix.isNull() )
icon.load( "bell.png" );
else
icon = pix;
if ( win->inherits( "KSystemTray" ) ) {
KSystemTray *tray = static_cast<KSystemTray *>( win );
tray->setPixmap( icon );
TQToolTip::add( tray, text );
return;
}
win->setCaption( text );
win->setIcon( icon );
#ifdef TQ_WS_X11
KWin::setIcons( win->winId(), icon, icon );
#endif
}
void KWindowInfo::save()
{
if ( !oldText.isNull() )
return;
if ( win->inherits( "KSystemTray" ) ) {
KSystemTray *tray = static_cast<KSystemTray *>( win );
oldIcon = *(tray->pixmap());
oldText = TQToolTip::textFor( tray );
return;
}
oldText = win->caption();
#ifdef TQ_WS_X11
oldMiniIcon = KWin::icon( win->winId(), 16, 16, true );
oldIcon = KWin::icon( win->winId(), 34, 34, false );
if ( oldIcon.isNull() )
oldIcon = KWin::icon( win->winId(), 32, 32, true );
#endif
if ( oldIcon.isNull() ) {
const TQPixmap *px = win->icon();
if ( px )
oldIcon = *px;
else
oldIcon.resize( 0, 0 );
}
}
void KWindowInfo::restore()
{
if ( win->inherits( "KSystemTray" ) ) {
KSystemTray *tray = static_cast<KSystemTray *>( win );
tray->setPixmap( oldIcon );
TQToolTip::add( tray, oldText );
oldText = TQString::null;
return;
}
win->setIcon( oldIcon );
#ifdef TQ_WS_X11
KWin::setIcons( win->winId(), oldIcon, oldMiniIcon );
#endif
win->setCaption( oldText );
oldText = TQString::null;
if ( autoDel )
delete this;
}
|