1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * Copyright (c) 2010 Ruslan Kabatsayev <b7.10110111@gmail.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or(at your option ) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #include "oxygenmainwindowdata.h" 23 #include "../oxygengtkutils.h" 24 25 #include <gtk/gtk.h> 26 27 namespace Oxygen 28 { 29 30 //________________________________________________________________________________ connect(GtkWidget * widget)31 void MainWindowData::connect( GtkWidget* widget ) 32 { 33 _target = widget; 34 _locked = false; 35 _configureId.connect( G_OBJECT(widget), "configure-event", G_CALLBACK( configureNotifyEvent ), this); 36 } 37 38 //________________________________________________________________________________ disconnect(GtkWidget * widget)39 void MainWindowData::disconnect( GtkWidget* widget ) 40 { 41 _target = 0L; 42 43 // reset timeout and locked flag 44 _timer.stop(); 45 _locked = false; 46 47 _configureId.disconnect(); 48 } 49 50 //________________________________________________________________________________ updateSize(int width,int height)51 void MainWindowData::updateSize( int width, int height ) 52 { 53 54 if( width == _width && height == _height ) return; 55 _width = width; 56 _height = height; 57 58 // schedule delayed timeOut 59 if( !_timer.isRunning() ) 60 { 61 62 _timer.start( 50, (GSourceFunc)delayedUpdate, this ); 63 _locked = false; 64 65 } else _locked = true; 66 67 } 68 69 //________________________________________________________________________________ configureNotifyEvent(GtkWidget * widget,GdkEventConfigure * event,gpointer data)70 gboolean MainWindowData::configureNotifyEvent(GtkWidget* widget, GdkEventConfigure* event, gpointer data ) 71 { 72 static_cast<MainWindowData*>(data)->updateSize( event->width, event->height ); 73 return FALSE; 74 } 75 76 //________________________________________________________________________________ delayedUpdate(gpointer pointer)77 gboolean MainWindowData::delayedUpdate( gpointer pointer ) 78 { 79 80 MainWindowData& data( *static_cast<MainWindowData*>(pointer) ); 81 if( !data._target ) 82 { 83 84 // if target is invalid, reset timeout and return 85 data._locked = false; 86 return FALSE; 87 88 } else if( data._locked ) { 89 90 // if locked, reset the flag and re-run timer 91 data._locked = false; 92 return TRUE; 93 94 } else { 95 96 // otherwise, trigger update 97 gtk_widget_queue_draw( data._target ); 98 return FALSE; 99 100 } 101 102 } 103 104 } 105