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/window.cmod

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

#include 

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

#include "gtk2.h"

/* Global variables
 */

/*! @module GUI */
/*! @module GTK2 */
/*! @class Window
 *!
 *! Toplevel which can contain other widgets
 */
PIKECLASS Window
 program_flags PROGRAM_USES_PARENT;
{
  INHERIT Bin;

  /*! @decl void create()
   *! @decl void create(int type)
   *! @decl void create(string title)
   *! @decl void create(string title,int type)
   *!
   *! Create a new Window
   *!
   *! @param title
   *!    The title of the Window
   *!
   *! @param type
   *!    the Window type
   */
  PIKEFUN void create(int|void|string arg1, void|int arg2)
  {
    GTK2_LOW=(void*)gtk_window_new(
      (args==1 && arg1->type==PIKE_T_INT) ? arg1->u.integer :
      ((args==2) ? arg2->u.integer : GTK_WINDOW_TOPLEVEL));

    if (args==1 && arg1->type==PIKE_T_STRING)
    {
      f_string_to_utf8(1);
      gtk_window_set_title(GTK_WINDOW(GTK2_LOW),Pike_sp[-1].u.string->str);
    }
    else if (args==2)
    {
      push_svalue(arg1);
      f_string_to_utf8(1);
      gtk_window_set_title(GTK_WINDOW(GTK2_LOW),Pike_sp[-1].u.string->str);
      pop_stack();
    }
    pop_n_elems(args);
  }

  /*! @decl void set_title(string title)
   *!
   *! Sets the title of the Window. The title of a window
   *! will be displayed in its title bar; on the X Window
   *! System, the title bar is rendered by the window manager,
   *! so exactly how the title appears to users may vary
   *! according to a user's exact configuration. The title
   *! should help a user distinguish this window from other
   *! windows they may have open. A good title might include
   *! the application name and current document filename, for example.
   */
  PIKEFUN void set_title(string title)
  {
    f_string_to_utf8(1);
    gtk_window_set_title(GTK_WINDOW(GTK2_LOW),(const gchar*)Pike_sp[-args].u.string->str);
    pop_n_elems(args);
  }

  /*! @decl void set_resizable(int resizable)
   *!
   *! Sets whether the user can resize a window.
   *! Windows are user resizable by default.
   */
  PIKEFUN void set_resizable(int resizable)
  {
    gtk_window_set_resizable(GTK_WINDOW(GTK2_LOW),resizable?TRUE:FALSE);
    pop_n_elems(args);
  }

  /*! @decl int get_resizable()
   *!
   *! Gets the value set by set_resizable().
   *!
   *! @returns
   *!  1 if the window is resizable, 0 otherwise
   */
  PIKEFUN int get_resizable()
  {
    int i=gtk_window_get_resizable(GTK_WINDOW(GTK2_LOW))?1:0;
    RETURN(i);
  }

  /*! @decl int activate_focus()
   *!
   *! Activates the current focused widget within the window.
   *! 
   *! @returns
   *!  1 if a widget got activated, 0 otherwise
   */
  PIKEFUN int activate_focus()  
  {
    int i=gtk_window_activate_focus(GTK_WINDOW(GTK2_LOW))?1:0;
    RETURN(i);
  }

  /*! @decl void set_modal(int modal)
   *!
   *! Sets a window modal or non-modal. Modal windows prevent
   *! interaction with other windows in the same application.
   *! To keep modal dialogs on top of main application windows,
   *! use set_transient_for() to make the dialog transient for
   *! the parent; most window managers will then disallow
   *! lowering the dialog below the parent.
   */
  PIKEFUN void set_modal(int modal)
  {
    gtk_window_set_modal(GTK_WINDOW(GTK2_LOW),modal?TRUE:FALSE);
    pop_n_elems(args);
  }

  /*! @decl void set_transient_for(Window parent)
   *!
   *! Dialog windows should be set transient for the main@
   *! application window they were spawned from. This allows@
   *! window managers to e.g. keep the dialog on top of the@
   *! main window, or center the dialog over the main window.
   *! 
   *! On Windows, this function will and put the child window@
   *! on top of the parent, much as the window manager would@
   *! have done on X.
   */
  PIKEFUN void set_transient_for(Window parent)
  {
    gtk_window_set_transient_for(GTK_WINDOW(GTK2_LOW),
      GTK_WINDOW(
        ((struct Object_struct*)get_storage(Pike_sp[-args].u.ptr, Object_program))->data
      ) );
    pop_n_elems(args);
  }

  /*! @decl void set_destroy_with_parent(int setting)
   *!
   *! If setting is 1, then destroying the transient parent of
   *! window will also destroy window itself. This is useful for
   *! dialogs that shouldn't persist beyond the lifetime of the
   *! main window they're associated with, for example.
   */
  PIKEFUN void set_destroy_with_parent(int setting)
  {
    gtk_window_set_destroy_with_parent(GTK_WINDOW(GTK2_LOW),setting);
    pop_n_elems(args);
  }

  /*! @decl string get_title()
   *!
   *! Retrieves the title of the window.
   */
  PIKEFUN string get_title()
  {
    const gchar* chr=gtk_window_get_title(GTK_WINDOW(GTK2_LOW));
    push_string(make_shared_binary_string(chr,strlen(chr)));
    f_utf8_to_string(1);
  }

  PIKEFUN void set_quit_main_on_close()
  {
     g_signal_connect(G_OBJECT(GTK2_LOW), "destroy",
                                        G_CALLBACK(gtk_main_quit), NULL);
  }

  INIT
  {

  }

  EXIT
  {
  }
}

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

void pike_init_gtk2_window(void)
{
  INIT
}

void pike_exit_gtk2_window(void)
{
  EXIT
}


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