[polari] lib: Implement FixedSizeFrame in JS
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] lib: Implement FixedSizeFrame in JS
- Date: Wed, 23 Dec 2015 20:52:53 +0000 (UTC)
commit 1bfd31f21a1605fc0a09e6c0698ad9dea27c4fc1
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Dec 23 21:40:28 2015 +0100
lib: Implement FixedSizeFrame in JS
Gjs now supports externally contructed GObjects, so we no longer
need to implement it in C to use it with GtkBuilder.
data/resources/main-window.ui | 2 +-
src/Makefile-lib.am | 2 -
src/application.js | 2 +-
src/lib/polari-fixed-size-frame.c | 219 -------------------------------------
src/lib/polari-fixed-size-frame.h | 31 -----
src/mainWindow.js | 71 ++++++++++++
6 files changed, 73 insertions(+), 254 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 7b86ede..f1472d3 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -186,7 +186,7 @@
<property name="hexpand">False</property>
<property name="transition_type">slide-right</property>
<child>
- <object class="PolariFixedSizeFrame" id="frame1">
+ <object class="Gjs_FixedSizeFrame" id="frame1">
<property name="visible">True</property>
<property name="hexpand">False</property>
<property name="width">200</property>
diff --git a/src/Makefile-lib.am b/src/Makefile-lib.am
index c76b1a9..839f07b 100644
--- a/src/Makefile-lib.am
+++ b/src/Makefile-lib.am
@@ -2,14 +2,12 @@ pkglib_LTLIBRARIES = libpolari-1.0.la
libpolari_headers = \
lib/polari-drag-helper.h \
- lib/polari-fixed-size-frame.h \
lib/polari-room.h \
lib/polari-util.h \
$(NULL)
libpolari_sources = \
lib/polari-drag-helper.c \
- lib/polari-fixed-size-frame.c \
lib/polari-room.c \
lib/polari-util.c \
$(NULL)
diff --git a/src/application.js b/src/application.js
index f454f82..3d67ad7 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,7 +35,7 @@ const Application = new Lang.Class({
vfunc_startup: function() {
this.parent();
- let w = new Polari.FixedSizeFrame(); // register gtype
+ let w = new MainWindow.FixedSizeFrame(); // register gtype
w.destroy();
this._chatroomManager = ChatroomManager.getDefault();
diff --git a/src/mainWindow.js b/src/mainWindow.js
index e6b8327..d783862 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -1,6 +1,7 @@
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Tp = imports.gi.TelepathyGLib;
@@ -19,6 +20,76 @@ const Utils = imports.utils;
const CONFIGURE_TIMEOUT = 100; /* ms */
+const FixedSizeFrame = new Lang.Class({
+ Name: 'FixedSizeFrame',
+ Extends: Gtk.Frame,
+ Properties: {
+ height: GObject.ParamSpec.int('height',
+ 'height',
+ 'height',
+ GObject.ParamFlags.READWRITE,
+ -1, GLib.MAXINT32, -1),
+ width: GObject.ParamSpec.int('width',
+ 'width',
+ 'width',
+ GObject.ParamFlags.READWRITE,
+ -1, GLib.MAXINT32, -1)
+ },
+
+ _init: function(params) {
+ this._height = -1;
+ this._width = -1;
+
+ this.parent(params);
+ },
+
+ _queueRedraw: function() {
+ let child = this.get_child();
+ if (child)
+ child.queue_resize();
+ this.queue_draw();
+ },
+
+ get height() {
+ return this._height;
+ },
+
+ set height(height) {
+ if (height == this._height)
+ return;
+ this._height = height;
+ this.notify('height');
+ this._queueRedraw();
+ },
+
+ get width() {
+ return this._width;
+ },
+
+ set width(width) {
+ if (width == this._width)
+ return;
+
+ this._width = width;
+ this.notify('width');
+ this._queueRedraw();
+ },
+
+ vfunc_get_preferred_width_for_height: function(forHeight) {
+ if (this._width < 0)
+ return this.parent(forHeight);
+ else
+ return [this._width, this._width];
+ },
+
+ vfunc_get_preferred_height_for_width: function(forWidth) {
+ if (this._height < 0)
+ return this.parent(forWidth);
+ else
+ return [this._height, this._height];
+ }
+});
+
const MainWindow = new Lang.Class({
Name: 'MainWindow',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]