File indexing completed on 2024-04-28 05:32:20

0001 /*
0002     this file is part of the oxygen gtk engine
0003     SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "oxygentaboptions.h"
0009 #include "oxygenstyleoptions.h"
0010 #include "oxygengtkutils.h"
0011 
0012 #include <cmath>
0013 
0014 namespace Oxygen
0015 {
0016 
0017     //______________________________________________________________________
0018     TabOptions::TabOptions( GtkWidget* widget, GtkStateType state, GtkPositionType position, int x, int y, int w, int h )
0019     {
0020 
0021         // strange: all tabs but the current one are painted with the active flag
0022         if( state != GTK_STATE_ACTIVE ) (*this) |= CurrentTab;
0023 
0024         // get allocated size
0025         const GtkAllocation allocation( Gtk::gtk_widget_get_allocation( widget ) );
0026         int borderWidth( GTK_IS_CONTAINER( widget ) ? gtk_container_get_border_width( GTK_CONTAINER( widget ) ):0 );
0027 
0028 
0029         // this simple comparison seems robust enough and much simpler
0030         // than any other implementation
0031         switch( position )
0032         {
0033             default:
0034             case GTK_POS_TOP:
0035             case GTK_POS_BOTTOM:
0036             if( x == allocation.x + borderWidth ) (*this) |= FirstTabAligned;
0037             if( x+w == allocation.x + allocation.width - borderWidth ) (*this) |= LastTabAligned;
0038             break;
0039 
0040             case GTK_POS_LEFT:
0041             case GTK_POS_RIGHT:
0042             if( y == allocation.y + borderWidth ) (*this) |= FirstTabAligned;
0043             if( y+h == allocation.y + allocation.height - borderWidth ) (*this) |= LastTabAligned;
0044             break;
0045         }
0046 
0047     }
0048 
0049 }