1 #ifndef oxygencomboboxentryengine_h 2 #define oxygencomboboxentryengine_h 3 /* 4 * this file is part of the oxygen gtk engine 5 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser 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 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 20 * MA 02110-1301, USA. 21 */ 22 23 24 #include "oxygengenericengine.h" 25 #include "oxygendatamap.h" 26 #include "oxygencomboboxentrydata.h" 27 28 #include <gtk/gtk.h> 29 30 namespace Oxygen 31 { 32 //! forward declaration 33 class Animations; 34 35 //! stores data associated to editable comboboxentryes 36 /*! 37 ensures that the text entry and the button of editable comboboxentryes 38 gets hovered and focus flags at the same time 39 */ 40 class ComboBoxEntryEngine: public GenericEngine<ComboBoxEntryData> 41 { 42 43 public: 44 45 //! constructor ComboBoxEntryEngine(Animations * widget)46 ComboBoxEntryEngine( Animations* widget ): 47 GenericEngine<ComboBoxEntryData>( widget ) 48 {} 49 50 //! destructor ~ComboBoxEntryEngine(void)51 virtual ~ComboBoxEntryEngine( void ) 52 {} 53 54 //!@name modifiers 55 //@{ 56 57 //! assign button to data matching widget setButton(GtkWidget * widget,GtkWidget * value)58 void setButton( GtkWidget* widget, GtkWidget* value ) 59 { data().value( widget ).setButton( value ); } 60 61 //! assign entry to data matching widget setEntry(GtkWidget * widget,GtkWidget * value)62 void setEntry( GtkWidget* widget, GtkWidget* value ) 63 { data().value( widget ).setEntry( value ); } 64 65 //! button focus setButtonFocus(GtkWidget * widget,bool value)66 void setButtonFocus( GtkWidget* widget, bool value ) 67 { data().value( widget ).setButtonFocus( value ); } 68 69 //! button focus setButtonHovered(GtkWidget * widget,bool value)70 void setButtonHovered( GtkWidget* widget, bool value ) 71 { data().value( widget ).setButtonHovered( value ); } 72 73 //! entry focus setEntryFocus(GtkWidget * widget,bool value)74 void setEntryFocus( GtkWidget* widget, bool value ) 75 { data().value( widget ).setEntryFocus( value ); } 76 77 //@} 78 79 //!@name accessors 80 //@{ 81 82 //! returns pressed combobox if any 83 inline GtkWidget* find( GtkWidget* ); 84 85 //! true if either button or entry has focus hasFocus(GtkWidget * widget)86 bool hasFocus( GtkWidget* widget ) 87 { return data().value( widget ).hasFocus(); } 88 89 //! true if comboBox is hovered hovered(GtkWidget * widget)90 bool hovered( GtkWidget* widget ) 91 { return data().value( widget ).hovered(); } 92 93 //@} 94 95 }; 96 97 //_________________________________________________ find(GtkWidget * value)98 GtkWidget* ComboBoxEntryEngine::find( GtkWidget* value ) 99 { 100 GtkWidget* topLevel( gtk_widget_get_toplevel( value ) ); 101 DataMap<ComboBoxEntryData>::Map& dataMap( data().map() ); 102 for( DataMap<ComboBoxEntryData>::Map::iterator iter = dataMap.begin(); iter != dataMap.end(); iter++ ) 103 { 104 if( iter->second.pressed() ) 105 { 106 iter->second.setList( topLevel ); 107 return iter->first; 108 } 109 } 110 111 for( DataMap<ComboBoxEntryData>::Map::iterator iter = dataMap.begin(); iter != dataMap.end(); iter++ ) 112 { if( iter->second.list() == topLevel ) return iter->first; } 113 114 return 0L; 115 116 } 117 118 } 119 120 #endif 121