Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
GUI.GTK2
Viewing contents of GUI_GTK2-0.1/dialog.cmod

#include "global.h"
#include "svalue.h"
#include "interpret.h"

#include 

/* This must be included last! */
#include "module.h"

#include "gtk2.h"

/*! @module GUI */
/*! @module GTK2 */
/*! @class Dialog
 *! 
 *! Create popup windows
 *!
 *!
 *! @b{ Object Hierarchy @}
 *!
 *! @[Object] -> @[Widget] -> @[Container] -> @[Bin]
 *! -> @[Window] -> Dialog
 *!
 *!
 *! @b{ Signal Prototypes @}
 *!
 *! @i{"close"@} void user_function (Dialog dialog, mixed user_data)
 *!
 *! @i{"response"@} void user_function (Dialog dialog, int response_id, mixed user_data)
 *!
 *! Emitted when an action widget is clicked, the dialog receives a delete
 *! event, or the application programmer calls @[response()]. On a delete
 *! event, the response ID is @[GUI.GTK2.Dialog.Response.NONE]. Otherwise,
 *! it depends on which action widget was clicked.
 */

PIKECLASS Dialog
 program_flags PROGRAM_USES_PARENT;
{
  INHERIT Window;

  /*! @decl void create()
   *!
   *! Creates a new dialog box. Widgets should not be packed@
   *! into this Window directly, but into the vbox and action_area.
   *! 
   *! @decl void create(string title,Window parent,int flags, string first_button_text)
   *!
   *! FIXME: write doc
   */
#define  tObjImpl_WINDOW tObj 
  PIKEFUN void create(void|string title, void|Window window, void|int flags, void|mapping buttons)
  {
    if (args==0)
    {
      GTK2_LOW=(void*)gtk_dialog_new();
    }
    else
    {
      gchar* t;
      GtkWindow* w;
      
      push_string(title);
      f_string_to_utf8(1);
      if (args>0)
        t=(gchar*)Pike_sp[-1].u.string->str;
      else t=NULL;      /* should never be evaluated */
      pop_stack();

      if (args>1)
        w=GTK_WINDOW(
          ((struct Object_struct*)get_storage(
            Pike_sp[-args].u.ptr,
            Object_program)
          )->data
        );
      else
        w=NULL;

      if (args>2)
        GTK2_LOW=(void*)gtk_dialog_new_with_buttons(t,w,flags->u.integer,NULL);
      else
        GTK2_LOW=(void*)gtk_dialog_new_with_buttons(t,w,0,NULL);
      /* FIXME: add buttons */
      
    }
    pop_n_elems(args);
  }

  /*! @decl int run()
   *!
   *! Blocks in a recursive main loop until the dialog either emits@
   *! the response signal, or is destroyed. If the dialog is destroyed@
   *! during the call to run(), Dialog returns GUI.GTK2.Response.NONE.@
   *! Otherwise, it returns the response ID from the "response" signal@
   *! emission. Before entering the recursive main loop, run() calls@
   *! show() on the Dialog for you. Note that you still need to show@
   *! any children of the dialog yourself.
   *!
   *! During run(), the default behavior of "delete_event" is disabled;@
   *! if the dialog receives "delete_event", it will not be destroyed@
   *! as windows usually are, and run() will return@
   *! @[GUI.GTK2.Dialog.Response.DELETE_EVENT]. Also, during run() the@
   *! dialog will be modal. You can force run() to return at any time by@
   *! calling @[response()] to emit the "response" signal. Destroying the@
   *! dialog during @[run()] is a very bad idea, because your post-run code@
   *! won't know whether the dialog was destroyed or not.
   *!
   *! After @[run()] returns, you are responsible for hiding or destroying@
   *! the dialog if you wish to do so.
   *!
   *! @note
   *! Even though the recursive main loop gives the effect of a modal@
   *! dialog (it prevents the user from interacting with other windows@
   *! while the dialog is run), callbacks such as timeouts, IO channel@
   *! watches, DND drops, etc, will be triggered during a @[run()] call.
   *!
   *! @returns
   *! response ID
   */
  PIKEFUN int run()
  {
    gint i=gtk_dialog_run(GTK_DIALOG(GTK2_LOW));
    RETURN i;
  }

  /*! @decl void response(int response_id)
   *!
   *! Emits the "response" signal with the given response ID. Used@
   *! to indicate that the user has responded to the dialog in some@
   *! way; typically either you or @[run()] will be monitoring the@
   *! "response" signal and take appropriate action.
   *!
   *! @param response_id
   *!   response ID
   */
  PIKEFUN void response(int response_id)
  {
    gtk_dialog_response(GTK_DIALOG(GTK2_LOW), response_id);
    pop_n_elems(args);
  }

  /*! @decl Button add_button(string button_text,int response_id)
   *!
   *! Adds a button with the given text (or a stock button, if@
   *! button_text is a stock ID) and sets things up so that clicking@
   *! the button will emit the "response" signal with the given@
   *! response_id. The button is appended to the end of the dialog's@
   *! action area. The button widget is returned, but usually you don't need it.
   *!
   *! @param button_text
   *!    text of button, or stock ID
   *! @param response_id
   *!    response ID for the button
   *! @returns
   *!    the Button that was added
   */
#define tObjImpl_BUTTON tObj
  PIKEFUN Button add_button(string button_text,int response_id)
  {
    struct object* wid;
    push_string(button_text);
    f_string_to_utf8(1);
    GtkWidget* w=gtk_dialog_add_button(GTK_DIALOG(GTK2_LOW),
      Pike_sp[-1].u.string->str,
      response_id);
    pop_stack();
    wid=fast_clone_object(Button_program);
    ((struct Object_struct*)get_storage(wid, Object_program))->data=(void*)w;
    RETURN wid;
  }

  /*! @decl int(0..1) get_has_separator() 
   *!
   *! Accessor for whether the dialog has a separator.
   *! 
   *! @returns
   *!    1 if the dialog has a separator, 0 otherwise
   */
  PIKEFUN int(0..1) get_has_separator()
  {
    gboolean b=gtk_dialog_get_has_separator(GTK_DIALOG(GTK2_LOW));
    RETURN (b?1:0);
  }

  /*! @decl void set_default_response(int response_id)
   *!
   *! Sets the last widget in the dialog's action area with the@
   *! given response_id as the default widget for the dialog.@
   *! Pressing "Enter" normally activates the default widget.
   *!
   *! @param response_id
   *!    a response ID
   */
  PIKEFUN void set_default_response(int response_id)
  {
    gtk_dialog_set_default_response(GTK_DIALOG(GTK2_LOW),(gint)response_id);
    pop_n_elems(args);
  }

  /*! @decl void set_has_separator(int(0..1) setting)
   *!
   *! Sets whether the dialog has a separator above the buttons.@
   *! 1 by default.
   *!
   *! @param setting
   *!    1 to have a separator
   */
  PIKEFUN void set_has_separator(int(0..1) setting)
  {
    gtk_dialog_set_has_separator(GTK_DIALOG(GTK2_LOW),(setting?TRUE:FALSE));
  }

  /*! @decl void set_response_sensitive(int response_id, int(0..1) setting)
   *!
   *! Calls GUI.GTK2.Widget's set_sensitive(setting) for each widget in the@
   *! dialog's action area with the given response_id. A convenient way to@
   *! sensitize/desensitize dialog buttons.
   */
  PIKEFUN void set_response_sensitive(int response_id, int(0..1) setting)
  {
    gtk_dialog_set_response_sensitive(GTK_DIALOG(GTK2_LOW),
      response_id,(setting?TRUE:FALSE));
    pop_n_elems(args);
  }

  INIT
  {

  }

  EXIT
  {
  }

}

/*! @endclass */
/*! @endmodule */
/*! @endmodule */

void pike_init_gtk2_dialog(void)
{
  INIT
}

void pike_exit_gtk2_dialog(void)
{
  EXIT
}


gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University