Skip to content

Commit

Permalink
Added GdkEventKey, add key prop as event of callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
scorninpc committed Jul 4, 2019
1 parent 254c725 commit 820e7d2
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 37 deletions.
5 changes: 5 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,16 @@ extern "C"
// GdkEvent
Php::Class<GdkEvent_> gdkevent("GdkEvent");
// gdkevent.method<&GdkEvent_::__construct>("__construct");
// gdkevent.method<&GdkEvent_::__get>("__get");
// gdkevent.property("type", 0);

// GdkEventButton
Php::Class<GdkEventButton_> gdkeventbutton("GdkEventButton");
// gdkevent.method<&GdkEvent_::__construct>("__construct");
// gdkevent.property("type", 0);

// GdkEventKey
Php::Class<GdkEventKey_> gdkeventkey("GdkEventKey");


// GdkPixbuf
Expand Down Expand Up @@ -3165,6 +3169,7 @@ extern "C"
extension.add(std::move(gdkvisual));
extension.add(std::move(gdkevent));
extension.add(std::move(gdkeventbutton));
extension.add(std::move(gdkeventkey));
extension.add(std::move(gdkpixbuf));
extension.add(std::move(gdkrgba));

Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "src/Gdk.h"
#include "src/GdkEvent.h"
#include "src/GdkEventButton.h"
#include "src/GdkEventKey.h"
#include "src/GdkPixbuf.h"

#include "src/GdkWindow.h"
Expand Down
69 changes: 36 additions & 33 deletions src/GdkEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
#include "GdkEvent.h"


/**
* c++ constructor
*/
GdkEvent_::GdkEvent_()
{

}

//
GdkEvent *GdkEvent_::get_instance()
{
Expand All @@ -30,36 +22,47 @@ void GdkEvent_::populate(GdkEvent *event)
// get self reference as Php::Value object
Php::Value self(this);

// initialize a public property
// GdkEventType
self["type"] = event->type;
// self["any"] = Php::Object("GdkEventAny", &event->any);
// self["expose"] = event->expose;
// self["visibility"] = event->visibility;
// self["motion"] = event->motion;

// GtkEventButton
GdkEventButton_ *eventbutton_ = new GdkEventButton_();
Php::Value gdkeventbutton = Php::Object("GdkEventButton", eventbutton_);
eventbutton_->populate(event->button);
self["button"] = eventbutton_;

// self["touch"] = event->touch;
// self["scroll"] = event->scroll;
// self["key"] = event->key;
// self["crossing"] = event->crossing;
// self["focus_change"] = event->focus_change;
// self["configure"] = event->configure;
// self["property"] = event->property;
// self["selection"] = event->selection;
// self["owner_change"] = event->owner_change;
// self["proximity"] = event->proximity;
// self["dnd"] = event->dnd;
// self["window_state"] = event->window_state;
// self["setting"] = event->setting;
// self["grab_broken"] = event->grab_broken;
// self["touchpad_swipe"] = event->touchpad_swipe;
// self["touchpad_pinch"] = event->touchpad_pinch;
// self["pad_button"] = event->pad_button;
// self["pad_axis"] = event->pad_axis;
// self["pad_group_mode"] = event->pad_group_mode;
// GtkEventKey
GdkEventKey_ *eventkey_ = new GdkEventKey_();
Php::Value gdkeventkey = Php::Object("GdkEventKey", eventkey_);
eventkey_->populate(event->key);
self["key"] = eventkey_;


/**
https://developer.gnome.org/gdk3/stable/gdk3-Events.html#gdk-event-get-event-type
https://developer.gnome.org/gtk-tutorial/stable/a2767.html
union _GdkEvent
{
GdkEventType type;
GdkEventAny any;
GdkEventExpose expose;
GdkEventNoExpose no_expose;
GdkEventVisibility visibility;
GdkEventMotion motion;
GdkEventButton button;
GdkEventKey key;
GdkEventCrossing crossing;
GdkEventFocus focus_change;
GdkEventConfigure configure;
GdkEventProperty property;
GdkEventSelection selection;
GdkEventProximity proximity;
GdkEventClient client;
GdkEventDND dnd;
};
*/

}
}
10 changes: 6 additions & 4 deletions src/GdkEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <gtk/gtk.h>

#include "GdkEventButton.h"
#include "GdkEventKey.h"

/**
*
Expand All @@ -21,17 +22,18 @@
/**
* C++ constructor and destructor
*/
GdkEvent_();

GdkEvent *get_instance();

GdkEvent_() = default;
virtual ~GdkEvent_() = default;
//
GdkEvent *get_instance();
void set_instance(GdkEvent *event);

/**
* Populate GdkEvent to PHPGTK::GDKEVENT
*/
void populate(GdkEvent *event);

Php::Value __get(const Php::Value &name);
};

#endif
34 changes: 34 additions & 0 deletions src/GdkEventKey.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#include "GdkEventKey.h"


/**
* c++ constructor
*/
GdkEventKey_::GdkEventKey_()
{

}


void GdkEventKey_::populate(GdkEventKey event)
{
// get self reference as Php::Value object
Php::Value self(this);

// initialize a public property
self["type"] = (int)event.type;
// self["window"] = (int)event.window; // GdkWindow
self["send_event"] = (int)event.send_event;
self["time"] = (int)event.time;
self["state"] = (int)event.state;
self["keyval"] = (int)event.keyval;
self["length"] = (int)event.length;
self["string"] = event.string;
self["keycode"] = self["hardware_keycode"] = (int)event.hardware_keycode;
self["group"] = (int)event.group;
self["is_modifier"] = (int)event.is_modifier;



}
29 changes: 29 additions & 0 deletions src/GdkEventKey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#ifndef _PHPGTK_GDKEVENTKEY_H_
#define _PHPGTK_GDKEVENTKEY_H_

#include <phpcpp.h>
#include <gtk/gtk.h>

/**
*
*/
class GdkEventKey_ : public Php::Base
{
/**
* Publics
*/
public:

/**
* C++ constructor and destructor
*/
GdkEventKey_();

/**
* Populate GdkEventKey to PHPGTK::GdkEventKey
*/
void populate(GdkEventKey event);
};

#endif
10 changes: 10 additions & 0 deletions test5.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
$style_context = $gtk_label->get_style_context();
$style_context->add_provider($css_provider, 600);

// GtkEntry
$gtk_entry = new GtkEntry();
$gtk_entry->connect("key-release-event", function($widget, $event) {
var_dump($event->key);
});
$gtk_entry->connect("button-release-event", function($widget, $event) {
var_dump($event->button);
});

// GtkSourceView
$gtk_sourceview = new GtkSourceView();
$gtk_sourceview_scroll = new GtkScrolledWindow();
Expand All @@ -24,6 +33,7 @@
// Box
$hbox = new GtkBox(GtkOrientation::VERTICAL);
$hbox->pack_start($gtk_label, FALSE, FALSE);
$hbox->pack_start($gtk_entry, FALSE, FALSE);
$hbox->pack_start($gtk_sourceview_scroll, TRUE, TRUE);

// GtkWindow
Expand Down

0 comments on commit 820e7d2

Please sign in to comment.