# data file for the Fltk User Interface Designer (fluid)
version 1.0303 
i18n_type 1 
i18n_include <libintl.h> 
i18n_function _ 
header_name {.h} 
code_name {.cxx}
decl {\#include <FL/Fl_Choice.H>} {public local
} 

decl {\#include <FL/Fl_Box.H>} {public local
} 

decl {\#include <FL/Fl_Button.H>} {public local
} 

decl {\#include <FL/Fl_File_Chooser.H>} {public local
} 

decl {\#include <FL/Fl_Output.H>} {public local
} 

decl {\#include <FL/Fl_Pack.H>} {public local
} 

decl {\#include <FL/Fl_Scroll.H>} {public local
} 

decl {\#include <FL/Flmm_Tabs.H>} {public local
} 

decl {\#include <FL/fl_ask.H>} {public local
} 

decl {\#include <FL/fl_draw.H>} {public local
} 

decl {\#include "oyranos_config_internal.h"
\#include "oyranos.h"
\#include "oyranos_debug.h"
\#include "oyranos_config.h"
\#include "oyranos_core.h"
\#include "oyranos_devices.h"
\#include "oyranos_helper.h"
\#include "oyranos_i18n.h"
\#include "oyranos_sentinel.h"
\#include "oyranos_texts.h"
\#include "Oy_Fl_Double_Window.h"
\#ifdef HAVE_X11
\# include <X11/Xcm/XcmEvents.h>
\#endif /* HAVE_X11 */
} {public local
} 

decl {\#include <iostream>} {public local
} 

decl {\#include <fstream>} {public local
} 

decl {\#include <cstdio>} {public local
} 

decl {int h_spacing=10;} {private global
} 

decl {int v_spacing=3;} {private global
} 

decl {int button_height=25;} {selected private global
} 

decl {\#define BOX_WIDTH 250
\#define SELECT_WIDTH 176} {public local
} 

Function {myAllocFunc(size_t size)} {private return_type {void*}
} {
  code {return new char [size];} {}
} 

Function {selectDefaultProfile_callback( Fl_Widget* w, void* )} {} {
  code {Option *op = dynamic_cast<Option*> (w->parent());
  if(op) {
    Fl_Choice *c = dynamic_cast<Fl_Choice*> (w);
    if(c) {
      std::cout << c->value() << c->text() << std::endl;
      int error = 0;
      if(strcmp(c->text(),_("[none]")) == 0)
        error = oySetDefaultProfile( (oyPROFILE_e)op->option, oySCOPE_USER, 0);
      else
        error = oySetDefaultProfile( (oyPROFILE_e)op->option, oySCOPE_USER, c->text());
      if(error) {
        fl_alert( "%s %s", _("setting"), _("failed!") );
      } else
        updateUI();

    } else fl_alert( "no Fl_Choice" );
  } else fl_alert( "%s", _("Select Profile") );} {}
} 

Function {showDefaultProfile_callback( Fl_Widget* w, void* )} {} {
  code {Option *op = dynamic_cast<Option*> (w->parent());
  if(op) {
    {
      char *pn = oyGetDefaultProfileName( (oyPROFILE_e)op->option, myAllocFunc);
      if(!pn) {
        fl_alert( "%s %s", _("showing"), _("failed!") );
      } else {
        char command[1024];
        oyProfile_s * prof = oyProfile_FromFile( pn, 0,0 );
        snprintf( command, 1024, "export PATH=$PATH:" OY_BINDIR "; iccexamin \\"%s\\"&",
                  oyProfile_GetFileName( prof, -1 ) );
        oyProfile_Release( &prof );
\#      ifdef DEBUG_
          fprintf(stderr, "%s\\n", command);
\#      endif
        int r = system( command );
        if(r >= 0x200) {
          fl_alert( "%s", _("Show Profile failed. iccexamin not found") );
          fprintf(stderr, "%s:%d command \\"%s\\" failed with error: %d.\\n",
                  __FILE__,__LINE__, command, r);
        }
      }
    }
  } else fl_alert( "%s", _("Show Profile failed") );} {}
} 

Function {selectBehaviourCallback( Fl_Widget* w, void* x )} {} {
  code {Option *op = dynamic_cast<Option*> (w->parent());
  if(op) {
    Fl_Choice *c = dynamic_cast<Fl_Choice*> (w);
    if(c) {
      std::cout << (intptr_t)x << c->user_data() << c->value() << c->text() << std::endl;
      int error = 0;

      if(op->option == oyWIDGET_POLICY)
      {
        error = oyPolicySet( c->text(), NULL );
      } else if(oyWIDGET_CMM_START < op->option &&
                op->option < oyWIDGET_CMM_END)
      {
        char * t = oyCMMNameToRegistration( c->text(), (oyCMM_e)op->option,
                                            oyNAME_NAME, 0, malloc ),
             * pattern = oyCMMRegistrationToName( t, (oyCMM_e)op->option,
                                            oyNAME_PATTERN, 0, malloc );
        error = oySetCMMPattern( (oyCMM_e)op->option, 0, oySCOPE_USER, pattern );
        if(t); free(t);
        if(pattern); free(pattern);
      } else
        error = oySetBehaviour( (oyBEHAVIOUR_e)op->option, oySCOPE_USER, c->value());

      if(error) {
        fl_alert( "%s %s %s", _("setting"), _("failed!"), c->text() );
      }

      updateUI();
    } else fl_alert( "no Fl_Choice" );
  } else fl_alert( "%s", _("Select Behaviour") );} {}
} 

Function {debug_me( )} {} {
  code {int nonsense = 0;
  ++nonsense;} {}
} 

class OyFl_Pack {: {public Fl_Pack}
} {
  Function {OyFl_Pack(int x, int y, int w, int h , const char *t = 0) : Fl_Pack(x,y,w,h,t)} {} {
    code {} {}
  }
  Function {draw()} {open private
  } {
    code {int nw = 0, nh = 0;
  Fl_Scroll * scroll = dynamic_cast <Fl_Scroll*> (parent());
  if( scroll )
  {
    nw = parent()->w() - Fl::box_dw( parent()->box() ) - scroll->scrollbar.w() - spacing();
  } else {
    nw = parent()->w() - Fl::box_dw( parent()->box() );
  }
  w( nw );


  nh = parent()->h() - Fl::box_dh( parent()->box() );
  if( horizontal() )
    Fl_Pack::size( nw, Fl_Pack::h() );
  else
    Fl_Pack::size( Fl_Pack::w(), nh );

  // prearrange if one widget is resizeable
  Fl_Widget *re = resizable();
  if( re )
  {
    int n = children();
    int pos_x = Fl::box_dx(box()) + spacing(),
        pos_y = Fl::box_dy(box()) + spacing(),
        pos_x2 = pos_x + w() - Fl::box_dw(box()) - spacing(),
        pos_y2 = pos_y + h() - Fl::box_dh(box()) - spacing();
    int re_i = 0;
    
    for( int i = 0; i < n; ++i )
    {
      Fl_Widget *o = child( i );
      if( o == re )
      {
        re_i = i;
        break;
      }
      
      if( horizontal() )
      {
        o->position( pos_x, o->y() );
        pos_x += o->w() + spacing();
      } else {
        o->position( o->x(), pos_y );
        pos_y += o->h() + spacing();
      }
    }
    
    for( int i = n - 1; i > re_i; --i )
    {
      Fl_Widget *o = child( i );
      if( horizontal() )
      {
        o->position( pos_x2 - o->w(), o->y() );
        pos_x2 -= o->w() + spacing();
      } else {
        o->position( o->x(), pos_y2 - o->h());
        pos_y2 -= o->h() + spacing();
      }
    }
    
    if(horizontal())
      re->resize( pos_x, re->y(), pos_x2-pos_x, re->h() );
    else
      re->resize( re->x(), pos_y, re->w(), pos_y2-pos_y );

  }


  Fl_Pack::draw();} {}
  }
} 

class OyFl_Box {: {public Fl_Box}
} {
  Function {OyFl_Box(int x, int y, int w, int h , const char *t = 0) : Fl_Box(x,y,w,h,t)} {open
  } {
    code {if(t)
  {
    label_orig = (char*)malloc (strlen(t)+1);
    printf("%s %d\\n",t, (int)strlen(t));
    sprintf(label_orig, "%s", t);
  } else
    label_orig = 0;} {}
  }
  Function {draw()} {open private
  } {
    code {int wl=0, hl=0, // have to be zeroed
       ws; // ws - label widgets start width
  char *txt = 0;
  int len = 0;
  int last_utf8_len = 0;
  if(label_orig)
  {
    ws = w();
    Fl_Box::label( label_orig );
    measure_label(wl,hl);
    if(wl < ws)
    {
      if(strlen(label_orig))
        Fl_Box::copy_label(label_orig);
    } else {

      txt = (char*)malloc (strlen(label_orig)+1);
      strcpy(txt, label_orig);
      Fl_Box::label(txt);
      do {
        //txt = (char*)Fl_Box::label();
        len = strlen(txt);
        if(len > 3)
        {
/*
 * Index into the table below with the first byte of a UTF-8 sequence to
 * get the number of trailing bytes that are supposed to follow it.
 * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
 * left as-is for anyone who may want to do such conversion, which was
 * allowed in earlier algorithms.
 */
static const char trailingBytesForUTF8[256] = {
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
};
          // now we have to get the last character length
          int ilen = 0;
          last_utf8_len = 0;
          do {
            last_utf8_len = 1 + trailingBytesForUTF8[ (unsigned char)txt[ilen] ];
            ilen += last_utf8_len;
          } while (len-3 > ilen);
          sprintf( &txt[ilen - last_utf8_len], "..." );
          Fl_Box::label(txt);
        } else
          break;
        measure_label(wl,hl);
      } while(wl > ws);

      //Fl_Box::label(txt);
    }
  }
\#ifdef DEBUG
  if(label_orig)
    if(strlen(label_orig))
      printf("%d %s %d %d/%d %d\\n",__LINE__,Fl_Box::label(), (int)strlen(Fl_Box::label()), wl, ws, last_utf8_len);
\#endif
  Fl_Box::draw();} {}
  }
  decl {char *label_orig;} {private local
  }
  Function {label()} {return_type {const char *}
  } {
    code {return label_orig;} {}
  }
  Function {label(const char * l)} {open
  } {
    code {label_orig = new char (strlen(l)+1);
  strcpy(label_orig, l);
  Fl_Box::label( l );} {}
  }
  Function {copy_label(const char* l)} {open
  } {
    code {label_orig = new char (strlen(l)+1);
  strcpy(label_orig, l);
  Fl_Box::copy_label(l);} {}
  }
} 

class Option {: {public OyFl_Pack} private
} {
  decl {OyFl_Box   *box;
  Fl_Choice*choice;

  oyWIDGET_e option;
  oyWIDGET_TYPE_e type;
  int       i;} {public local
  }
  Function {Option( int x, int y, int w, int h, const char *name,
  oyWIDGET_e option_,
  oyWIDGET_TYPE_e type_,
  int choices_n,
  const char **choices,
  int current,
  const char *tooltip,
  int flags) : OyFl_Pack(x, y, w, h)} {open
  } {
    code {Fl_Pack::type( FL_HORIZONTAL );
  Fl_Pack::spacing(h_spacing);

  option = option_;
  type = type_;

  debug_me();

  /*int weigth = BOX_WIDTH + SELECT_WIDTH + 4 * h_spacing + button_height;
  if(w < weigth)
    Fl_Pack::size( weigth, Fl_Pack::h() );
  w = Fl_Pack::w();*/

  switch((unsigned int)type)
  {
  // == Profiles ==
  case oyWIDGETTYPE_DEFAULT_PROFILE:
  case oyWIDGETTYPE_PROFILE:
  {
    // Profile name box
    box = new OyFl_Box( x, y,
                      OyFl_Pack::w() - SELECT_WIDTH - button_height - 4*h_spacing, button_height,
                      name );
    box->tooltip( tooltip );
    box->align(FL_ALIGN_LEFT | FL_ALIGN_CLIP|FL_ALIGN_INSIDE);

    if( flags & OY_LAYOUT_NO_CHOICES )
    {
      const char* default_p = NULL;
      if(current >= 0)
        default_p = choices[current];
      if(default_p) {
        DBG_PROG_S( (default_p) )
      } else
        default_p = "";
      if(default_p) {
        box = new OyFl_Box( w - BOX_WIDTH - SELECT_WIDTH - button_height - 3*h_spacing, y,
                          190, button_height, default_p );
        box->align( FL_ALIGN_LEFT | FL_ALIGN_CLIP | FL_ALIGN_INSIDE );

        // identify
        box->user_data( (void*)(intptr_t)option );

        Fl_Group::end();
        Fl_Group::resizable( box );
        return;
      }
    }

    // Choice
    choice = new Fl_Choice( box->x()+box->w(), OyFl_Pack::y(),
                            SELECT_WIDTH, h );
    choice->callback( selectDefaultProfile_callback );
    choice->tooltip( tooltip );
    DBG_PROG_V((choice->size()))

    // Profile viewer
    Fl_Button *button = new Fl_Button( w - button_height - h_spacing, y,
                                       button_height, button_height, "@-3DnArrow" );
    button->callback( showDefaultProfile_callback );
    button->tooltip(_("Show in external Viewer"));

    // identify
    choice->user_data( (void*)(intptr_t)option );
  }
  break;

  // == Behaviour ==
  case oyWIDGETTYPE_BEHAVIOUR:
  case oyWIDGETTYPE_CHOICE:
  {
    // name box
    box = new OyFl_Box( x, y,
                      w - SELECT_WIDTH - button_height - 4*h_spacing, button_height,
                      name );
    box->tooltip( tooltip );
    box->align(FL_ALIGN_LEFT | FL_ALIGN_CLIP|FL_ALIGN_INSIDE);

    if( flags & OY_LAYOUT_NO_CHOICES )
    {
      const char* default_p = NULL;
      if(current >= 0)
        default_p = choices[current];
      if(default_p) {
        DBG_PROG_S( (default_p) )
      } else
        default_p = "";
      if(default_p) {
        box = new OyFl_Box( w - BOX_WIDTH - SELECT_WIDTH - button_height - 3*h_spacing, y,
                          190, button_height, default_p );
        box->align( FL_ALIGN_LEFT | FL_ALIGN_CLIP | FL_ALIGN_INSIDE );

        // identify
        box->user_data( (void*)(intptr_t)option );

        Fl_Group::end();
        Fl_Group::resizable( box );
        return;
      }
    }

    // Choice
    choice = new Fl_Choice( w - SELECT_WIDTH - h_spacing, y,
                            SELECT_WIDTH + button_height + h_spacing, h );
    choice->callback( selectBehaviourCallback );
    choice->tooltip( tooltip );

    // identify
    choice->user_data( (void*)(intptr_t)option );
  }
  break;

  // == List ==
  case oyWIDGETTYPE_LIST:
  {
    int count = choices_n;

    box = NULL;

    Fl_Pack::type( FL_VERTICAL );
    Fl_Pack::spacing(3);
    Fl_Pack::user_data( (void*)(intptr_t)option );

    Fl_Pack::size( w, parent()->h() );

    ListEntry *pp = 0;
    int width = 0;
    new Fl_Box(0,0,10, h_spacing);

    //parent()->box(FL_ENGRAVED_FRAME);

    for (int i = 0 ; i < count ; ++i) {
      int scrollb_w = 0;
      Fl_Scroll * scroll = dynamic_cast <Fl_Scroll*> (Fl_Group::current()->parent()->parent());
      if( scroll )
      {
        scrollb_w = scroll->scrollbar.w();
      }
      pp = new ListEntry( Fl_Group::current()->x(), Fl_Group::current()->y(),
                          w - scrollb_w - spacing(), button_height,
                          choices[i], flags );
      if( width < pp->w() )
        width = pp->w();
      pp->end();
    }

  }
  } /* switch */

  
  end();
  resizable( box );} {}
  }
} 

class ListEntry {open : {public OyFl_Pack} private
} {
  decl {Fl_Box   *box;
  Fl_Button*button_add, *button_remove;
  int flags;} {public local
  }
  Function {ListEntry( int x, int y, int w, int h, const char * name, int flags )
    : OyFl_Pack(x, y, w, h)} {open
  } {
    code {Fl_Pack::type( FL_HORIZONTAL );
    Fl_Pack::spacing(h_spacing);
    Fl_Group::resizable(0);

    box = new Fl_Box( 0, 0, w-button_height-spacing(), button_height, name );
    box->align(FL_ALIGN_LEFT | FL_ALIGN_CLIP|FL_ALIGN_INSIDE);

    new Fl_Box( 0, 0, button_height, button_height );

    int width=0, height=0;

    box->measure_label(width, height);

    /*int scroll_w = 50; //default_profiles_pack->w() - 3*h_spacing - button_height;
    int b_w = scroll_w;
    if(width > scroll_w)
      b_w = width;

    box->size( b_w + h_spacing, 25 ); */

    Fl_Pack::resizable(box);
    //Fl_Pack::size( parent()->w(), Fl_Pack::h() );
    //if(name) delete [] name; // dont delete as it belongs now to the widget} {}
  }
} 

Function {addTab( Flmm_Tabs* tabs, const oyGROUP_e *groups )} {private return_type {Fl_Group*}
} {
  code {Fl_Group *parent = /*dynamic_cast <Fl_Group>*/ tabs; // parent tab
  Fl_Group *tab = NULL; // actual tab

  if( !parent )
    WARNc_S( "wrong widget" );

  for( int k = 1; k <= groups[0]; ++k )
  {
    int i = 0;
    int wcount = parent->children();
    tab = NULL;
    const char *g_name = NULL;
    oyWidgetTitleGet( (oyWIDGET_e)groups[k], NULL, &g_name, NULL, NULL );

    for( i = 0; i < wcount; ++i )
    {
      const char *c_name = parent->child( i )->label(); // current name

      if( c_name && g_name )
      if( strcmp( c_name, g_name ) == 0 )
      {
        // a widget with the searched label was found => tab exists allready
        tab = (Flmm_Tabs*) parent->child( i );
        tab->box( FL_THIN_UP_BOX );
        break;
      }
    }

    if( !tab )
    {
      const char *tooltip = NULL;
      const char *title = NULL;
      oyWidgetTitleGet( (oyWIDGET_e)groups[k], NULL, &title, &tooltip, NULL );

      parent->begin();
        Fl_Widget *wid = (Fl_Widget*)parent->user_data();
        if( !wid ) wid = parent;

        int x = parent->x() + Fl::box_dx( wid->box() ) + v_spacing,
            y = parent->y() + Fl::box_dy( wid->box() ) + button_height,// + v_spacing,
            w = parent->w() - Fl::box_dw( wid->box() ) - 2*v_spacing,
            h = parent->h() - Fl::box_dh( wid->box() ) - button_height - 2*v_spacing;
        printf("%d+%d,%dx%d\\n", x,y,w,h);
        if( k < groups[0] )
        {
          tab = new Flmm_Tabs(   x,y,w,h, title);
          tab->tooltip( tooltip );
          tab->user_data( tab );
          tab->box( FL_THIN_UP_BOX );
          tab->end();
        } else {
          tab = new Fl_Scroll( x,y,w,h, title );
          tab->tooltip( tooltip );
          tab->box( FL_NO_BOX ); //FL_THIN_UP_BOX );
          { OyFl_Pack* o = new OyFl_Pack( x + Fl::box_dx( tab->box() ) + v_spacing,
                                      y + Fl::box_dy( tab->box() ) + v_spacing,// + button_height,
                                      w - Fl::box_dw(parent->box()) - 2*v_spacing,
                                      h - Fl::box_dh( parent->box() ) - button_height );
            o->box( FL_NO_BOX );
            o->spacing( v_spacing );
            o->end();
            tab->user_data( o );
            tab->resizable( o );
          }
          tab->end();
        }
      parent->end();
      parent->resizable( tab );
    }
    parent = const_cast <Fl_Group*> (dynamic_cast<Fl_Group*>(tab));
  }

  if( tab )
    return (Fl_Group*)tab->user_data();
  else
    return NULL;} {}
} 

Function {getWidget( Fl_Group* group, oyWIDGET_e oywid )} {private return_type {Fl_Widget*}
} {
  code {Fl_Widget *wid = NULL;

  if( !group )
    WARNc_S( "wrong widget" );

    int wcount = group->children();

    for( int i = 0; i < wcount; ++i )
    {
      if( dynamic_cast <Fl_Widget*>( group->child( i ) ) )
      {
        oyWIDGET_e w_id = (oyWIDGET_e)(intptr_t)group->child( i )->user_data(); // widget id
        if( w_id && oywid )
          if( w_id == oywid )
            return dynamic_cast <Fl_Widget*>( group->child( i ) );
      }

      if( dynamic_cast <Fl_Group*>( group->child( i ) ) )
      {
        wid = getWidget( dynamic_cast <Fl_Group*>( group->child( i ) ),
                            oywid );
        if(wid)
          return wid;
      }
    }

  return wid;} {}
} 

Function {getTab( Flmm_Tabs* tabs, oyGROUP_e group, Fl_Group **container )} {private return_type {Fl_Group*}
} {
  code {Fl_Group *parent = /*dynamic_cast <Fl_Group>*/ tabs; // parent tab
  Fl_Group *tab = NULL; // actual tab

  if( container )
    *container = NULL;

  if( !parent )
    WARNc_S( "wrong widget" );

    int wcount = parent->children();
    tab = NULL;
    const char *g_name = NULL;
    oyWidgetTitleGet( (oyWIDGET_e)group, NULL, &g_name, NULL, NULL );

    for( int i = 0; i < wcount; ++i )
    {
      const char *c_name = parent->child( i )->label(); // current name

      if( c_name && g_name )
      if( strcmp( c_name, g_name ) == 0 )
      {
        tab = (Flmm_Tabs*) parent->child( i );
        wcount = tab->children();
        for( i = 0; i < wcount; ++i )
          if( dynamic_cast <Fl_Pack*>( tab->child( i ) ) )
          {
            Fl_Pack *p = dynamic_cast <Fl_Pack*>( tab->child( i ) );
            if( p && p == tab->user_data() )
              *container = p;
            return tab;
          }
        return tab;
      }
    }

  return tab;} {}
} 

Function {refreshOptions()} {private
} {
  code {double scale = top_group->scale();
  button_height = OY_ROUND(scale * 25);
  v_spacing = OY_ROUND(scale * 3);
  h_spacing = OY_ROUND(scale * 10);
  top_tabs->damage( FL_DAMAGE_ALL );
  top_tabs->redraw();

  oyGetPersistentStrings( NULL );

  Option *op = 0;

  int n = 0;
  oyWIDGET_e *wl = oyWidgetListGet( oyGROUP_ALL, &n, myAllocFunc );

  // fill in all the options
  for( int i = 0 ; i < n ; ++i )
      {
        const oyGROUP_e * groups;
        int             count = 0,
                        current = 0,
                        flags = 0;
        const char    * tooltip = NULL;
        const char   ** names = NULL;
        const char    * name = NULL;
        oyWIDGET_e        oywid = wl[i];
        oyWIDGET_TYPE_e   type = oyWidgetTitleGet(  oywid,
                                                  &groups, &name, &tooltip,
                                                  &flags );
        if(type == oyWIDGETTYPE_CHOICE ||
           type == oyWIDGETTYPE_BEHAVIOUR ||
           type == oyWIDGETTYPE_DEFAULT_PROFILE ||
           type == oyWIDGETTYPE_PROFILE ||
           type == oyWIDGETTYPE_LIST)
        {
          Fl_Group *w = addTab( top_tabs, groups );

          oyOptionChoicesGet2( oywid, 0, oyNAME_NAME, &count, &names, &current );
          /*for(int en = 0; en < count; ++en)
            printf("%s\\n", names[en]);*/

          if(oywid == oyWIDGET_POLICY)
          {
            if(current >= 0)
              policy_box->label( names[current] );
            else
              policy_box->label( _("----") );
          }

          if(w)
          {
            int bh = button_height;
            int by = w->y();

            Fl_Widget *wid = getWidget( top_tabs, oywid );
            Fl_Choice * choice = dynamic_cast <Fl_Choice*>( wid );
            Fl_Box * box = dynamic_cast <Fl_Box*>( wid );
            Fl_Pack * pack = dynamic_cast <Fl_Pack*>( wid );
            if(!box && !choice)
            {
              if(pack)
              {
                op = dynamic_cast <Option*>( pack );
                w->remove( pack );
                delete op;
                w->damage( FL_DAMAGE_ALL );
                w->redraw();
              }

              w->begin();
                if( flags & OY_LAYOUT_MIDDLE )
                {
                  const char *nn[2] = { "","" };
                  op = new Option( w->x(), by, w->w() - Fl::box_dw(w->box()),
                         2*bh, "",
                         oyWIDGET_BEHAVIOUR_START,
                         type, 1,nn,1,"", OY_LAYOUT_NO_CHOICES | flags );
                }

                op = new Option( w->x(), by, Fl_Group::current()->w()
                                       - Fl::box_dw(Fl_Group::current()->box()),
                         bh, name,
                         oywid, type, count, names, current, tooltip, flags );
              w->end();
            }

            // fill in the data
            if(!pack)
            {
              wid = getWidget( top_tabs, oywid );
              choice = dynamic_cast <Fl_Choice*>( wid );
              box = dynamic_cast <Fl_Box*>( wid );
              if(box || choice)
              {
                if(choice)
                {
                  int j;
                  choice->clear();
                  for(j = 0; j < count; ++j)
                    choice->add( names[j] );

                  if(current >= 0 && names && names[current])
                    choice->value( choice->find_item( names[current] ) );
                  else
                    choice->value( -1 );
                }
                if(box)
                {
                  if( current >= 0 )
                    box->label( names[current] );
                  else
                    box->label( "" );
                }
              }
            }
          }
        }
      }
  delete [] wl;

  // resize the top group
  if( op )
  {
    int tw = top_group->w(),
        ow = op->w();
    if( tw < ow )
      top_group->size( ow, top_group->h() );
  }} {}
} 

Function {createUI()} {open
} {
  code {top_tabs->clear();
  } {}
}

Function {updateUI()} {} {
  code {//! internal@todo start refreshing when the UI has finished
  // ping X11 observers about option change
  // ... by setting a known property again to its old value
  oyOptions_s * opts = oyOptions_New(NULL), * results = 0;
  int error = oyOptions_Handle( "//"OY_TYPE_STD"/send_native_update_event",
                      opts,"send_native_update_event",
                      &results );
  oyOptions_Release( &opts );

  if(error)
    printf("send_native_update_event failed");

  Fl::add_idle(updateUIIdle);} {}
} 

Function {updateUIIdle(void*)} {} {
  code {Fl::remove_idle(updateUIIdle);
  //! internal refreshing when the UI has finished
  refreshOptions();} {}
} 

Function {} {open C
} {
  code {Fl::scheme("plastic");

\#ifdef USE_GETTEXT
  setlocale(LC_ALL,"");
\#endif
  oyExportStart_(EXPORT_CHECK_NO);
  
  Fl::add_handler( event_handler );} {}
  Fl_Window top_group {
    label {Oyranos Configuration} open
    xywh {564 361 505 410} type Double resizable
    class Oy_Fl_Double_Window size_range {305 255 0 0} visible
  } {
    Fl_Pack {} {open
      xywh {0 0 480 70} type HORIZONTAL
      class OyFl_Pack
    } {
      Fl_Box {} {
        image {../../oyranos_logo64.png} xywh {0 0 85 70} align 16
      }
      Fl_Box {} {
        label {Oyranos Configuration}
        xywh {95 0 385 70} labeltype ENGRAVED_LABEL labelsize 18 align 24 resizable
        code0 {o->redraw();}
        class OyFl_Box
      }
    }
    Fl_Tabs top_tabs {open
      xywh {0 70 505 301} selection_color 52 resizable
      class Flmm_Tabs
    } {
      Fl_Group {} {
        label Policy open
        tooltip {Reset to a standard Policy for Oyranos.} xywh {10 95 485 266} resizable
      } {}
    }
    Fl_Button {} {
      label {@-3reload}
      callback {//Fl::pushed(&bPL);
  updateUI();}
      tooltip Refresh xywh {10 375 50 25} when 6
    }
    Fl_Pack {} {open
      xywh {160 371 255 35} type HORIZONTAL
    } {
      Fl_Box {} {
        label {Active Policy:}
        xywh {160 371 120 35} align 24
      }
      Fl_Box policy_box {
        label {----}
        xywh {280 371 135 35} align 20
      }
    }
  }
  code {createUI();
  updateUI();} {}
} 

Function {listWindow( Fl_Widget *w )} {} {
  code {Fl_Group *g = dynamic_cast <Fl_Group*> (w);

  static int level = 0;


  if( g )
  {
    int n = g->children();

    std::cout << std::endl;
    for(int i = 0; i < level; ++i) std::cout << " ";

    std::cout << "Group t" << (int)w->type() << " " << w->x()<<"+"<<w->y()<<"+"<<w->w()<<"x"<<w->h() <<
                 " \\"" << (w->label()?w->label():"") << "\\":";

    ++level;
    for( int i = 0; i < n; ++i )
    {
      listWindow( g->child(i) );
    }
    --level;
    std::cout << std::endl;
  } else
  {
    std::cout << " t" << (int)w->type() << " " << w->x()<<"+"<<w->y()<<"+"<<w->w()<<"x"<<w->h() <<
                 " " << (w->label()?w->label():"- ");
  }} {}
} 

Function {event_handler( int e )} {open return_type int
} {
  code {int found = 0;

  switch (e)
  {
  case FL_SHORTCUT:
      /*if(Fl::event_key() == FL_Escape) {
        found = 1;
      } else
      if(Fl::event_key() == 'q'
       && Fl::event_state() == FL_CTRL) {
        exit();
        found = 1;
      } else*/
      if(Fl::event_key() == FL_F + 1) {
        make_help();
        found = 1;
      }
  break;
  }
  
  return found;} {}
} 

Function {make_help()} {open
} {
  Fl_Window help_window {
    label {Oyranos Help} open
    xywh {1192 298 505 410} type Double resizable
    class Oy_Fl_Double_Window visible
  } {
    Fl_Help_View help_browser {
      xywh {0 0 505 410} box THIN_UP_BOX color 16 resizable
    }
  }
  code {help_window->show();
    const char * opts[] = {"add_html_header","1",
                           "add_oyranos_title","1",
                           "add_oyranos_copyright","1",
                           NULL};
  help_browser->value( oyDescriptionToHTML(oyGROUP_ALL, opts,0) );} {}
} 
