Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 7, 2016
0 parents commit eb4e956
Show file tree
Hide file tree
Showing 167 changed files with 19,151 additions and 0 deletions.
Binary file added 2766.pdf
Binary file not shown.
Binary file added 2767.pdf
Binary file not shown.
Binary file added 9781590596135.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions Chapter01/listing1-1.php
@@ -0,0 +1,46 @@
<?php
/**
* A simple Object Oriented example.
*/
class Ralph {

public $name = 'Ralph';
protected $suffix = 'Sr';

public function __construct()
{
echo 'My name is ' . $this->name . ' ' . $this->suffix . ".\n";
}

public function giveBirth()
{
echo "It's a boy!\n";
return new Ralph_Jr();
}
}

class Ralph_Jr extends Ralph {

protected $suffix = 'Jr';

public function giveBirth()
{
throw new Exception('Ralph Jr. can\'t have kids!');
}
}

$senior = new Ralph();
$junior = $senior->giveBirth();

try {
$junior->giveBirth();
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
10 changes: 10 additions & 0 deletions Chapter01/listing1-2.php
@@ -0,0 +1,10 @@
<?php
$window = new GtkWindow();
$window->connect_object('destroy', array('Gtk', 'main_quit'));

$dateTime = new GtkLabel(date('Y-m-d H:i:s'));

$window->add($dateTime);
$window->show_all();
Gtk::main();
?>
15 changes: 15 additions & 0 deletions Chapter01/listing1-3.php
@@ -0,0 +1,15 @@
<?php
/**
* A really simple PHP-GTK application.
*/
$window = new GtkWindow();
$window->connect_object('destroy', array('Gtk', 'main_quit'));
$window->show();
Gtk::main();
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
17 changes: 17 additions & 0 deletions Chapter01/listing1_4.java
@@ -0,0 +1,17 @@
import javax.swing.*;

public class listing1_4 {

public static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(
createAndShowGUI();
);
createAndShowGUI();
}
}
43 changes: 43 additions & 0 deletions Chapter03/listing3-1.php
@@ -0,0 +1,43 @@
<?php
/**
* A PHP implementation of GtkObject.
*/
class GtkObject {

private $flags;
private $refCounter;

public function destroy()
{
unset($this);
}

public function flags()
{
return $this->flags;
}

public function set_flags($flags)
{
$this->flags = $this->flags | $flags;
}

public function sink()
{
if (--$this->refCounter < 1) {
$this->destroy();
}
}

public function unset_flags($flags)
{
$this->flags = $this->flags & ~$flags;
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
41 changes: 41 additions & 0 deletions Chapter03/listing3-2.php
@@ -0,0 +1,41 @@
<?php
/**
* An example to show the various states of a widget.
*/
$widget = new GtkWindow();

// If you try to grab the window before realizing
// the object you will get nothing.
var_dump($widget->window);
var_dump($widget->flags());

$widget->realize();

// Now that the widget is realized, we can grab
// the window property.
var_dump($widget->window);
var_dump($widget->flags());

$widget->show();

// Showing and hiding a widget changes the value
// of its flags.
var_dump($widget->flags());

$widget->hide();

var_dump($widget->flags());

$widget->unrealize();

// Now that the widget is realized, we can grab
// the window property.
var_dump($widget->window);
var_dump($widget->flags());
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
23 changes: 23 additions & 0 deletions Chapter03/listing3-3.php
@@ -0,0 +1,23 @@
<?php
/**
* An example to what happens when you try to add a widget to two containers.
*/
$window = new GtkWindow();
$frame = new GtkFrame();
$button = new GtkButton("I'm a button");

$window->add($button);
$frame->add($button);

/*
Spits out this message:
(listing-3.php:1870): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a container of type GtkFrame, but the widget is already inside a container of type GtkWindow, the GTK+ FAQ at http://www.gtk.org/faq/ explains how to reparent a widget.
*/

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
41 changes: 41 additions & 0 deletions Chapter03/listing3-4.php
@@ -0,0 +1,41 @@
<?php
/**
* Getting, setting and changing a widgets parent.
*/
function testForParent($widget)
{
$parent = $widget->get_parent();

echo 'The ' . get_class($widget) . ' has ';
if (isset($parent)) {
echo 'a ' . get_class($parent);
} else {
echo 'no';
}
echo " parent.\n";
}

// Start with three widgets.
$window = new GtkWindow();
$frame = new GtkFrame('I am a frame');
$button = new GtkButton("I'm a button");

testForParent($button);

$button->set_parent($frame);
testForParent($button);

// What if we want the button to be added directly to
// the window?
$button->unparent();
$button->set_parent($window);
testForParent($button);
$button->unparent();
testForParent($button);
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
43 changes: 43 additions & 0 deletions Chapter03/listing3-5.php
@@ -0,0 +1,43 @@
<?php
/**
* Getting, setting and changing a widgets parent.
*/
function testForParent($widget)
{
$parent = $widget->get_parent();

echo 'The ' . get_class($widget) . ' has ';
if (isset($parent)) {
echo 'a ' . get_class($parent);
} else {
echo 'no';
}
echo " parent.\n";
}

// Start with three widgets.
$window = new GtkWindow();
$frame = new GtkFrame('I am a frame');
$button = new GtkButton("I'm a button");

testForParent($button);

$frame->add($button);
testForParent($button);

// What if we want the button to be added directly to
// the window?
$frame->remove($button);
$window->add($button);
testForParent($button);

// No switch it back to the frame.
$button->reparent($frame);
testForParent($button);
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
38 changes: 38 additions & 0 deletions Chapter04/listing4-1.php
@@ -0,0 +1,38 @@
<?php
/**
* Reacting to events.
*/
function setParentFunction($widget)
{
$parent = $widget->get_parent();

echo 'The ' . get_class($widget) . ' has ';
if (isset($parent)) {
echo 'a ' . get_class($parent);
} else {
echo 'no';
}
echo " parent.\n";
}

// Start with three widgets.
$window = new GtkWindow();
$frame = new GtkFrame('I am a frame');
$button = new GtkButton("I'm a button");

// Connect the event to our test function
$button->connect('parent-set', 'setParentFunction');

// Now set some parents.
$button->set_parent($window);
$button->unparent();
$frame->add($button);

$button->reparent($window);
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>
46 changes: 46 additions & 0 deletions Chapter04/listing4-2.php
@@ -0,0 +1,46 @@
<?php
/**
* Reacting to events.
*/
class ExtendedButton extends GtkButton {

public function __construct($label)
{
parent::__construct($label);

$this->connect('parent-set', array($this, 'printParentSet'));
}

public function printParentSet($widget)
{
$parent = $widget->get_parent();

echo 'The ' . get_class($widget) . ' has ';
if (isset($parent)) {
echo 'a ' . get_class($parent);
} else {
echo 'no';
}
echo " parent.\n";
}
}

// Start with three widgets.
$window = new GtkWindow();
$frame = new GtkFrame('I am a frame');
$button = new ExtendedButton("I'm a button");

// Now set some parents.
$button->set_parent($window);
$button->unparent();
$frame->add($button);

$frame->connect('parent-set', array('ExtendedButton', 'printParentSet'));
$window->add($frame);
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
?>

0 comments on commit eb4e956

Please sign in to comment.