File indexing completed on 2024-05-12 05:34:33

0001 #ifndef oxygencomboboxengine_h
0002 #define oxygencomboboxengine_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 
0011 #include "oxygengenericengine.h"
0012 #include "oxygendatamap.h"
0013 #include "oxygencomboboxdata.h"
0014 
0015 #include <gtk/gtk.h>
0016 
0017 namespace Oxygen
0018 {
0019     //! forward declaration
0020     class Animations;
0021 
0022     //! stores data associated to editable comboboxes
0023     /*!
0024     ensures that the text  and the button of editable comboboxes
0025     gets hovered and focus flags at the same time
0026     */
0027     class ComboBoxEngine: public GenericEngine<ComboBoxData>
0028     {
0029 
0030         public:
0031 
0032         //! constructor
0033         ComboBoxEngine( Animations* widget ):
0034             GenericEngine<ComboBoxData>( widget )
0035             {}
0036 
0037         //! destructor
0038         virtual ~ComboBoxEngine( void )
0039         {}
0040 
0041         //!@name modifiers
0042         //@{
0043 
0044         //! assign button to data matching widget
0045         void setButton( GtkWidget* widget, GtkWidget* value )
0046         { data().value( widget ).setButton( value ); }
0047 
0048         //! button focus
0049         void setButtonFocus( GtkWidget* widget, bool value )
0050         { data().value( widget ).setButtonFocus( value ); }
0051 
0052         //! register child
0053         void registerChild( GtkWidget* widget, GtkWidget* child )
0054         { data().value( widget ).registerChild( child ); }
0055 
0056         //@}
0057 
0058         //!@name accessors
0059         //@{
0060 
0061         //! find combobox matching widget
0062         /*! the widget can be any of those in a visible list */
0063         inline GtkWidget* find( GtkWidget* );
0064 
0065         //! true if either button or is pressed
0066         bool pressed( GtkWidget* widget )
0067         { return data().value( widget ).pressed(); }
0068 
0069         //! true if either button or entry has focus
0070         bool hasFocus( GtkWidget* widget )
0071         { return data().value( widget ).hasFocus(); }
0072 
0073         //! true if comboBox is hovered
0074         bool hovered( GtkWidget* widget )
0075         { return data().value( widget ).hovered(); }
0076 
0077         //@}
0078 
0079     };
0080 
0081     //_________________________________________________
0082     GtkWidget* ComboBoxEngine::find( GtkWidget* value )
0083     {
0084         GtkWidget* topLevel( gtk_widget_get_toplevel( value ) );
0085         DataMap<ComboBoxData>::Map& dataMap( data().map() );
0086         for( DataMap<ComboBoxData>::Map::iterator iter = dataMap.begin(); iter != dataMap.end(); iter++ )
0087         {
0088             if( iter->second.pressed() )
0089             {
0090                 iter->second.setList( topLevel );
0091                 return iter->first;
0092             }
0093         }
0094 
0095         for( DataMap<ComboBoxData>::Map::iterator iter = dataMap.begin(); iter != dataMap.end(); iter++ )
0096         { if( iter->second.list() == topLevel ) return iter->first; }
0097 
0098         return 0L;
0099 
0100     }
0101 
0102 }
0103 
0104 #endif