<commit_before>/*  $Id$

    Part of XPCE

    Author:  <NAME> and <NAME>
    E-mail:  <EMAIL>
    WWW:     http://www.swi.psy.uva.nl/projects/xpce/
    Copying: GPL-2.  See the file COPYING or http://www.gnu.org

    Copyright (C) 1990-2001 SWI, University of Amsterdam. All rights reserved.
*/

#include <h/kernel.h>
#include <h/dialog.h>

static status
initialiseButton(Button b, Name name, Message msg, Name acc)
{ createDialogItem(b, name);

  assign(b, default_button, OFF);

  assign(b, message, msg);
  if ( notDefault(acc) )
    assign(b, accelerator, acc);

  return requestComputeGraphical(b, DEFAULT);
}


int
accelerator_code(Name a)
{ if ( isName(a) )
  { char *s = strName(a);
    
    if ( s[0] == '\\' && s[1] == 'e' && isletter(s[2]) && s[3] == EOS )
      return s[2];
    if ( s[1] == EOS && isletter(s[0]) )
      return s[0];
  }

  return 0;
}


static status
RedrawWinMenuBarButton(Button b, Area a)
{ int x, y, w, h;
  Any ofg = NIL;
  int flags = 0;

  initialiseDeviceGraphical(b, &x, &y, &w, &h);
  NormaliseArea(x, y, w, h);
  
  if ( b->status == NAME_preview )
  { Any fg = getClassVariableValueObject(b, NAME_selectedForeground);
    Any bg = getClassVariableValueObject(b, NAME_selectedBackground);

    if ( !fg ) fg = WHITE_COLOUR;
    if ( !bg ) bg = BLACK_COLOUR;
    r_fill(x, y, w, h, bg);
    ofg = r_colour(fg);
  }

  if ( b->active == OFF )
    flags |= LABEL_INACTIVE;

  RedrawLabelDialogItem(b, accelerator_code(b->accelerator),
			x, y, w, h,
			NAME_center, NAME_center, flags);

  if ( notNil(ofg) )
    r_colour(ofg);

  succeed;
}


static void
draw_generic_button_face(Button b,
			 int x, int y, int w, int h,
			 int up, int defb, int focus)
{ Elevation z = getClassVariableValueObject(b, NAME_elevation);
  
  if ( z && notNil(z) )			/* 3-d style */
  { int up = (b->status == NAME_inactive || b->status == NAME_active);
     
    if ( b->look == NAME_motif || b->look == NAME_win )
    { int bx = x, by = y, bw = w, bh = h;

      if ( b->look == NAME_motif )
      { if ( focus ) /* was: (defb && !obhf) || (focus && kbf) ) */
	{ static Elevation e = NULL;
  
	  if ( !e )
	    e = newObject(ClassElevation, ONE, 0);
  
	  bx -= 4; by -= 4; bw += 8; bh += 8;
	  r_3d_box(bx, by, bw, bh, valInt(b->radius), e, FALSE);
	}
	if ( focus )			/* was kbf && focus */
	{ int pen = valInt(b->pen);
  
	  bx -= pen; by -= pen; bw += 2*pen; bh += 2*pen;
	  r_thickness(pen);
	  r_box(bx, by, bw, bh, valInt(b->radius), NIL);
	}
      } else
      { if ( defb )
	{ int pen = valInt(b->pen);
  
	  bx -= pen; by -= pen; bw += 2*pen; bh += 2*pen;
	  r_thickness(pen);
	  r_box(bx, by, bw, bh, valInt(b->radius), NIL);
	}
      }
    }

    r_3d_box(x, y, w, h, valInt(b->radius), z, up);
  } else				/* 2-d style */
  { int swapc  = 0;
    int pen    = valInt(b->pen);
    int radius = valInt(b->radius);<commit_msg>* Added indication of default button in OpenLook style<commit_after>/*  $Id$

    Part of XPCE

    Author:  <NAME> and <NAME>
    E-mail:  <EMAIL>
    WWW:     http://www.swi.psy.uva.nl/projects/xpce/
    Copying: GPL-2.  See the file COPYING or http://www.gnu.org

    Copyright (C) 1990-2001 SWI, University of Amsterdam. All rights reserved.
*/

#include <h/kernel.h>
#include <h/dialog.h>

static status
initialiseButton(Button b, Name name, Message msg, Name acc)
{ createDialogItem(b, name);

  assign(b, default_button, OFF);

  assign(b, message, msg);
  if ( notDefault(acc) )
    assign(b, accelerator, acc);

  return requestComputeGraphical(b, DEFAULT);
}


int
accelerator_code(Name a)
{ if ( isName(a) )
  { char *s = strName(a);
    
    if ( s[0] == '\\' && s[1] == 'e' && isletter(s[2]) && s[3] == EOS )
      return s[2];
    if ( s[1] == EOS && isletter(s[0]) )
      return s[0];
  }

  return 0;
}


static status
RedrawWinMenuBarButton(Button b, Area a)
{ int x, y, w, h;
  Any ofg = NIL;
  int flags = 0;

  initialiseDeviceGraphical(b, &x, &y, &w, &h);
  NormaliseArea(x, y, w, h);
  
  if ( b->status == NAME_preview )
  { Any fg = getClassVariableValueObject(b, NAME_selectedForeground);
    Any bg = getClassVariableValueObject(b, NAME_selectedBackground);

    if ( !fg ) fg = WHITE_COLOUR;
    if ( !bg ) bg = BLACK_COLOUR;
    r_fill(x, y, w, h, bg);
    ofg = r_colour(fg);
  }

  if ( b->active == OFF )
    flags |= LABEL_INACTIVE;

  RedrawLabelDialogItem(b, accelerator_code(b->accelerator),
			x, y, w, h,
			NAME_center, NAME_center, flags);

  if ( notNil(ofg) )
    r_colour(ofg);

  succeed;
}


static void
draw_generic_button_face(Button b,
			 int x, int y, int w, int h,
			 int up, int defb, int focus)
{ Elevation z = getClassVariableValueObject(b, NAME_elevation);
  int r = valInt(b->radius);

  if ( z && notNil(z) )			/* 3-d style */
  { int up = (b->status == NAME_inactive || b->status == NAME_active);
     
    if ( b->look == NAME_motif || b->look == NAME_win )
    { int bx = x, by = y, bw = w, bh = h;

      if ( b->look == NAME_motif )
      { if ( focus ) /* was: (defb && !obhf) || (focus && kbf) ) */
	{ static Elevation e = NULL;
  
	  if ( !e )
	    e = newObject(ClassElevation, ONE, 0);
  
	  bx -= 4; by -= 4; bw += 8; bh += 8;
	  r_3d_box(bx, by, bw, bh, r, e, FALSE);
	}
	if ( focus )			/* was kbf && focus */
	{ int pen = valInt(b->pen);
  
	  bx -= pen; by -= pen; bw += 2*pen; bh += 2*pen;
	  r_thickness(pen);
	  r_box(bx, by, bw, bh, r, NIL);
	}
      } else
      { if ( defb )
	{ int pen = valInt(b->pen);
  
	  bx -= pen; by -= pen; bw += 2*pen; bh += 2*pen;
	  r_thickness(pen);
	  r_box(bx, by, bw, bh, r, NIL);
	}
      }
    }

    r_3d_box(x, y, w, h, r, z, up);
    if ( b->look == NAME_openLook && defb )
    { Any old;

      old = r_colour(r_elevation_shadow(z));
      r_box(x+2, y+2, w-4, h-4, r, NIL);
      r_colour(old);
    }
  } else				/* 2-d style */
  { int swapc  = 0;
    int pen    = valInt(b->pen);
    int radius = valInt(b->radius);
{'fraction_non_alphanumeric': 0.17359579161717292, 'fraction_numerical': 0.011878499915153572, 'mean_word_length': 2.6159509202453988, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1053714', 'n_tokens_mistral': 2604, 'n_tokens_neox': 2406, 'n_words': 627}