(********************************************************************)
(*                                                                  *)
(*  gkb_act.s7i   Generate code for graphics keyboard actions.      *)
(*  Copyright (C) 1990 - 1994, 2004 - 2014  Thomas Mertes           *)
(*                                                                  *)
(*  This file is part of the Seed7 compiler.                        *)
(*                                                                  *)
(*  This program is free software; you can redistribute it and/or   *)
(*  modify it under the terms of the GNU General Public License as  *)
(*  published by the Free Software Foundation; either version 2 of  *)
(*  the License, or (at your option) any later version.             *)
(*                                                                  *)
(*  This program is distributed in the hope that it will be useful, *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
(*  GNU General Public License for more details.                    *)
(*                                                                  *)
(*  You should have received a copy of the GNU General Public       *)
(*  License along with this program; if not, write to the           *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const ACTION: GKB_GETC            is action "GKB_GETC";
const ACTION: GKB_GETS            is action "GKB_GETS";
const ACTION: GKB_INPUT_READY     is action "GKB_INPUT_READY";
const ACTION: GKB_LINE_READ       is action "GKB_LINE_READ";
const ACTION: GKB_RAW_GETC        is action "GKB_RAW_GETC";
const ACTION: GKB_SELECT_INPUT    is action "GKB_SELECT_INPUT";
const ACTION: GKB_WINDOW          is action "GKB_WINDOW";
const ACTION: GKB_WORD_READ       is action "GKB_WORD_READ";
const ACTION: GKB_BUTTON_PRESSED  is action "GKB_BUTTON_PRESSED";
const ACTION: GKB_CLICKED_XPOS    is action "GKB_CLICKED_XPOS";
const ACTION: GKB_CLICKED_YPOS    is action "GKB_CLICKED_YPOS";


const proc: gkb_prototypes (inout file: c_prog) is func

  begin
    declareExtern(c_prog, "boolType    gkbButtonPressed (charType);");
    declareExtern(c_prog, "intType     gkbClickedXpos (void);");
    declareExtern(c_prog, "intType     gkbClickedYpos (void);");
    declareExtern(c_prog, "charType    gkbGetc (void);");
    declareExtern(c_prog, "striType    gkbGets (intType);");
    declareExtern(c_prog, "boolType    gkbInputReady (void);");
    declareExtern(c_prog, "striType    gkbLineRead (charType *);");
    declareExtern(c_prog, "charType    gkbRawGetc (void);");
    declareExtern(c_prog, "void        gkbSelectInput (winType, charType, boolType);");
    declareExtern(c_prog, "winType     gkbWindow (void);");
    declareExtern(c_prog, "striType    gkbWordRead (charType *);");
  end func;


const proc: process (GKB_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbGetc()";
  end func;


const proc: process (GKB_GETS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "gkbGets(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (GKB_INPUT_READY, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbInputReady()";
  end func;


const proc: process (GKB_LINE_READ, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "gkbLineRead(&(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= "))";
  end func;


const proc: process (GKB_RAW_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbRawGetc()";
  end func;


const proc: process (GKB_SELECT_INPUT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "gkbSelectInput(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (GKB_WINDOW, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "gkbWindow()";
  end func;


const proc: process (GKB_WORD_READ, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "gkbWordRead(&(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= "))";
  end func;


const proc: process (GKB_BUTTON_PRESSED, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbButtonPressed(";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (GKB_CLICKED_XPOS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbClickedXpos()";
  end func;


const proc: process (GKB_CLICKED_YPOS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbClickedYpos()";
  end func;