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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
/*
* this file was largely taken from the oxygen gtk engine
* Copyright (c) 2010 Hugo Pereira Da Costa <[email protected]>
* Copyright (c) 2010 Ruslan Kabatsayev <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or(at your option ) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "tdegtk-animations.h"
#include "tdegtk-utils.h"
#include "../config.h"
#include <cassert>
#include <iostream>
//_________________________________________
Animations::Animations( void ):
_innerShadowsEnabled( true ),
_hooksInitialized( false )
{
#if OXYGEN_DEBUG
std::cerr << "Oxygen::Animations::Animations" << std::endl;
#endif
// create engines
#if 0
registerEngine( _backgroundHintEngine = new BackgroundHintEngine( this ) );
registerEngine( _comboBoxEngine = new ComboBoxEngine( this ) );
registerEngine( _comboBoxEntryEngine = new ComboBoxEntryEngine( this ) );
registerEngine( _dialogEngine = new DialogEngine( this ) );
registerEngine( _groupBoxEngine = new GroupBoxEngine( this ) );
registerEngine( _groupBoxLabelEngine = new GroupBoxLabelEngine( this ) );
registerEngine( _hoverEngine = new HoverEngine( this ) );
registerEngine( _mainWindowEngine = new MainWindowEngine( this ) );
registerEngine( _menuItemEngine = new MenuItemEngine( this ) );
registerEngine( _panedEngine = new PanedEngine( this ) );
registerEngine( _scrollBarEngine = new ScrollBarEngine( this ) );
registerEngine( _scrolledWindowEngine = new ScrolledWindowEngine( this ) );
registerEngine( _innerShadowEngine = new InnerShadowEngine( this ) );
#endif
registerEngine( _tabWidgetEngine = new TabWidgetEngine( this ) );
#if 0
registerEngine( _treeViewEngine = new TreeViewEngine( this ) );
registerEngine( _widgetSizeEngine = new WidgetSizeEngine( this ) );
// animations specific engines
registerEngine( _widgetStateEngine = new WidgetStateEngine( this ) );
registerEngine( _arrowStateEngine = new ArrowStateEngine( this ) );
registerEngine( _scrollBarStateEngine = new ScrollBarStateEngine( this ) );
registerEngine( _tabWidgetStateEngine = new TabWidgetStateEngine( this ) );
registerEngine( _treeViewStateEngine = new TreeViewStateEngine( this ) );
registerEngine( _menuBarStateEngine = new MenuBarStateEngine( this ) );
registerEngine( _menuStateEngine = new MenuStateEngine( this ) );
registerEngine( _toolBarStateEngine = new ToolBarStateEngine( this ) );
#endif
}
//____________________________________________________________________________________________
Animations::~Animations( void )
{
#if OXYGEN_DEBUG
std::cerr << "Oxygen::Animations::~Animations" << std::endl;
#endif
// delete all engines
for( BaseEngine::List::iterator iter = _engines.begin(); iter != _engines.end(); ++iter )
{ delete *iter; }
// disconnect all signals from map
for( WidgetMap::iterator iter = _allWidgets.begin(); iter != _allWidgets.end(); iter++ )
{ iter->second.disconnect(); }
// clear hooks
_backgroundHintHook.disconnect();
_sizeAllocationHook.disconnect();
_realizationHook.disconnect();
_innerShadowHook.disconnect();
}
#if 0
//_________________________________________
void Animations::initialize( const QtSettings& settings )
{
const bool animationsEnabled( settings.animationsEnabled() );
// pass animations configuration to engines
widgetStateEngine().setEnabled( animationsEnabled && settings.genericAnimationsEnabled() );
widgetStateEngine().setDuration( settings.genericAnimationsDuration() );
arrowStateEngine().setEnabled( animationsEnabled && settings.genericAnimationsEnabled() );
arrowStateEngine().setDuration( settings.genericAnimationsDuration() );
scrollBarStateEngine().setEnabled( animationsEnabled && settings.genericAnimationsEnabled() );
scrollBarStateEngine().setDuration( settings.genericAnimationsDuration() );
tabWidgetStateEngine().setEnabled( animationsEnabled && settings.genericAnimationsEnabled() );
tabWidgetStateEngine().setDuration( settings.genericAnimationsDuration() );
treeViewStateEngine().setEnabled( animationsEnabled && settings.genericAnimationsEnabled() );
treeViewStateEngine().setDuration( settings.genericAnimationsDuration() );
menuBarStateEngine().setAnimationsEnabled( animationsEnabled && (settings.menuBarAnimationType() != None) );
menuBarStateEngine().setFollowMouse( settings.menuBarAnimationType() == FollowMouse );
menuBarStateEngine().setDuration( settings.menuBarAnimationsDuration() );
menuBarStateEngine().setFollowMouseAnimationsDuration( settings.menuBarFollowMouseAnimationsDuration() );
menuStateEngine().setEnabled( animationsEnabled && (settings.menuAnimationType() != None) );
menuStateEngine().setFollowMouse( settings.menuAnimationType() == FollowMouse );
menuStateEngine().setDuration( settings.menuAnimationsDuration() );
menuStateEngine().setFollowMouseAnimationsDuration( settings.menuFollowMouseAnimationsDuration() );
// for now, only Fade animations mode is supported for toolbar animations
toolBarStateEngine().setEnabled( animationsEnabled && (settings.toolBarAnimationType() != None) );
toolBarStateEngine().setFollowMouse( settings.toolBarAnimationType() == FollowMouse );
toolBarStateEngine().setDuration( settings.genericAnimationsDuration() );
toolBarStateEngine().setFollowMouseAnimationsDuration( settings.toolBarAnimationsDuration() );
}
#endif
//____________________________________________________________________________________________
void Animations::initializeHooks( void )
{
if( _hooksInitialized ) return;
#if 0
_backgroundHintHook.connect( "realize", (GSignalEmissionHook)backgroundHintHook, this );
#if ENABLE_INNER_SHADOWS_HACK
if(!getenv("OXYGEN_DISABLE_INNER_SHADOWS_HACK"))
{ _innerShadowHook.connect( "realize", (GSignalEmissionHook)innerShadowHook, this ); }
#endif
#endif
_sizeAllocationHook.connect( "size-allocate", (GSignalEmissionHook)sizeAllocationHook, this );
_realizationHook.connect( "realize", (GSignalEmissionHook)realizationHook, this );
_hooksInitialized = true;
}
//____________________________________________________________________________________________
bool Animations::registerWidget( GtkWidget* widget )
{
if( _allWidgets.find( widget ) != _allWidgets.end() ) return false;
#if OXYGEN_DEBUG
std::cerr << "Oxygen::Animations::registerWidget - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl;
#endif
Signal destroyId;
destroyId.connect( G_OBJECT( widget ), "destroy", G_CALLBACK( destroyNotifyEvent ), this );
_allWidgets.insert( std::make_pair( widget, destroyId ) );
return true;
}
//____________________________________________________________________________________________
void Animations::unregisterWidget( GtkWidget* widget )
{
#if OXYGEN_DEBUG
std::cerr << "Oxygen::Animations::unregisterWidget - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl;
#endif
// find in map
WidgetMap::iterator iter( _allWidgets.find( widget ) );
assert( iter != _allWidgets.end() );
// disconnect signal
iter->second.disconnect();
// erase from map
_allWidgets.erase( widget );
// erase from all maps
for( BaseEngine::List::iterator iter = _engines.begin(); iter != _engines.end(); ++iter )
{ (*iter)->unregisterWidget( widget ); }
}
//____________________________________________________________________________________________
void Animations::setEnabled( bool value )
{
for( BaseEngine::List::iterator iter = _engines.begin(); iter != _engines.end(); ++iter )
{ (*iter)->setEnabled( value ); }
}
//____________________________________________________________________________________________
gboolean Animations::destroyNotifyEvent( GtkWidget* widget, gpointer data )
{
static_cast<Animations*>(data)->unregisterWidget( widget );
return FALSE;
}
//____________________________________________________________________________________________
gboolean Animations::sizeAllocationHook( GSignalInvocationHint*, guint, const GValue* params, gpointer data )
{
// get widget from params
GtkWidget* widget( GTK_WIDGET( g_value_get_object( params ) ) );
// check type
if( !GTK_IS_WIDGET( widget ) ) return FALSE;
// comboboxes
/*
need to force the wrap-width property to 0,
otherwise the "appears-as-list" flag is not respected, which additionally breaks the widget rendering.
This has to be done soon enoug to avoid crash with latest gtk3 versions
*/
if(
GTK_IS_COMBO_BOX( widget ) &&
Gtk::gtk_combobox_appears_as_list( widget ) &&
!gtk_combo_box_get_has_entry( GTK_COMBO_BOX( widget ) ) )
{
gtk_combo_box_set_wrap_width( GTK_COMBO_BOX( widget ), 0 );
return TRUE;
}
#if GTK_CHECK_VERSION( 3, 5, 0 )
/*
HACK: Somehow, style_updated method for GtkRange widgets is not called anymore
as soon as we (oxygen-gtk) install our hooks. This prevents some settings to be
properly initialized, such as the slider length, or the arrows for scrollbars.
Therefore we explicitly call the styleUpdated function ourselves.
*/
if( GTK_IS_RANGE( widget ) )
{
// get class
GtkWidgetClass* widgetClass = GTK_WIDGET_GET_CLASS( widget );
if( widgetClass && widgetClass->style_updated )
{ (*widgetClass->style_updated)(widget); }
}
#endif
// groupbox labels
#if ENABLE_GROUPBOX_HACK
if( static_cast<Animations*>( data )->groupBoxLabelEngine().contains( widget ) )
{
static_cast<Animations*>( data )->groupBoxLabelEngine().adjustSize( widget );
return TRUE;
}
#endif
#if ENABLE_COMBOBOX_LIST_RESIZE
// comboboxes
if( !GTK_IS_WINDOW( widget ) ) return TRUE;
GtkWindow* window( GTK_WINDOW( widget ) );
if( gtk_window_get_type_hint( window ) != GDK_WINDOW_TYPE_HINT_COMBO ) return TRUE;
Animations& animations( *static_cast<Animations*>(data) );
GtkWidget* combobox = animations.comboBoxEngine().find( widget );
if( !combobox ) combobox = animations.comboBoxEntryEngine().find( widget );
if( !combobox ) return true;
int w, h;
gtk_window_get_size( window, &w, &h );
gint sourceX, sourceY;
gint targetX, targetY;
gtk_window_get_position( window, &sourceX, &sourceY );
gdk_window_get_origin( gtk_widget_get_window( combobox ), &targetX, &targetY );
// store allocations
const GtkAllocation comboAllocation( Gtk::gtk_widget_get_allocation( combobox ) );
const GtkAllocation widgetAllocation( Gtk::gtk_widget_get_allocation( widget ) );
const bool widthChanged( widgetAllocation.width != comboAllocation.width - 6 );
const bool positionChanged( sourceX != targetX + comboAllocation.x + 3 );
#if OXYGEN_DEBUG
std::cerr
<< "Animations::comboBoxHook -"
<< " widget: " << widget
<< " widthChanged: " << widthChanged
<< " positionChanged: " << positionChanged
<< std::endl;
#endif
int uglyShadowWidth=!Gtk::gdk_default_screen_is_composited();
// perform move-resize
if( widthChanged && positionChanged )
{
gdk_window_move_resize(
gtk_widget_get_window( widget ),
targetX + comboAllocation.x + 3 - uglyShadowWidth, sourceY,
comboAllocation.width - 6 + 2*uglyShadowWidth, widgetAllocation.height );
} else if( widthChanged ) {
gdk_window_resize(
gtk_widget_get_window( widget ),
comboAllocation.width - 6 + 2*uglyShadowWidth, widgetAllocation.height );
} else if( positionChanged ) {
gdk_window_move(
gtk_widget_get_window( widget ),
targetX + comboAllocation.x + 3 - uglyShadowWidth, sourceY );
}
#endif
return true;
}
#if 0
//____________________________________________________________________________________________
gboolean Animations::backgroundHintHook( GSignalInvocationHint*, guint, const GValue* params, gpointer data )
{
// get widget from params
GtkWidget* widget( GTK_WIDGET( g_value_get_object( params ) ) );
// check type
if( !GTK_IS_WIDGET( widget ) ) return FALSE;
if( !GTK_IS_WINDOW( widget ) ) return TRUE;
Animations& animations( *static_cast<Animations*>(data) );
animations.backgroundHintEngine().registerWidget( widget );
return TRUE;
}
//____________________________________________________________________________________________
gboolean Animations::innerShadowHook( GSignalInvocationHint*, guint, const GValue* params, gpointer data )
{
// get widget from params
GtkWidget* widget( GTK_WIDGET( g_value_get_object( params ) ) );
// check type
if( !GTK_IS_WIDGET( widget ) ) return FALSE;
// check enabled state
Animations& animations( *static_cast<Animations*>(data) );
if( !animations.innerShadowsEnabled() ) return TRUE;
// blacklist
if( Gtk::g_object_is_a( G_OBJECT( widget ), "SwtFixed" ) ) return TRUE;
if( Gtk::g_object_is_a( G_OBJECT( widget ), "GtkPizza" ) ) return TRUE;
if( Gtk::g_object_is_a( G_OBJECT( widget ), "MessageList") ) return TRUE;
GtkWidget* parent(gtk_widget_get_parent(widget));
if( !GTK_IS_SCROLLED_WINDOW( parent ) ) return TRUE;
GtkWidget* child(gtk_bin_get_child(GTK_BIN(parent)));
if(child!=widget) return TRUE;
#if OXYGEN_DEBUG
std::cerr
<< "Oxygen::Animations::innerShadowHook -"
<< " widget: " << widget << " (" << G_OBJECT_TYPE_NAME(widget) << ")"
<< " parent: " << parent << " (" << G_OBJECT_TYPE_NAME(parent) << ")"
<< " widget path: " << Gtk::gtk_widget_path( widget )
<< " isTreeView: " << (GTK_IS_TREE_VIEW(widget)?"true":"false")
<< " isTextView: " << (GTK_IS_TEXT_VIEW(widget)?"true":"false")
<< std::endl;
#endif
animations.innerShadowEngine().registerWidget( parent );
animations.innerShadowEngine().registerChild( parent, widget );
return TRUE;
}
#endif
//____________________________________________________________________________________________
gboolean Animations::realizationHook( GSignalInvocationHint*, guint, const GValue* params, gpointer data )
{
// get widget from params
GtkWidget* widget( GTK_WIDGET( g_value_get_object( params ) ) );
// check type
if( !GTK_IS_WIDGET( widget ) ) return FALSE;
if( GTK_IS_NOTEBOOK( widget ) )
{ gtk_notebook_set_show_border( GTK_NOTEBOOK(widget), FALSE ); }
#if ENABLE_GROUPBOX_HACK
if( GTK_IS_LABEL( widget ) && GTK_IS_FRAME( gtk_widget_get_parent( widget ) ) )
{
GtkFrame *frame( GTK_FRAME( gtk_widget_get_parent( widget ) ) );
if( widget == gtk_frame_get_label_widget( frame ) && !Gtk::gtk_widget_find_parent( widget, "GtkPizza" ) )
{
#if OXYGEN_DEBUG
std::cout
<< "Oxygen::Animations::realizationHook -"
<< " widget: " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")"
<< " parent: " << frame << " (" << G_OBJECT_TYPE_NAME( frame ) << ")"
<< std::endl;
#endif
// modify alignment
gtk_frame_set_label_align( frame, 0.5, 0.0 );
gtk_frame_set_shadow_type( frame, GTK_SHADOW_OUT );
// register to engine
static_cast<Animations*>( data )->groupBoxLabelEngine().registerWidget( widget );
static_cast<Animations*>( data )->groupBoxLabelEngine().adjustSize( widget );
}
}
#endif
return TRUE;
}
|