/*
* Tabbed notebook
*
* Copyright (C) 2017 Patrick McDermott
*
* This file is part of Marquee.
*
* Marquee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Marquee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Marquee. If not, see .
*/
#include "notebook.h"
#include
#include
#include "tab-label.h"
#include "tab-page.h"
#include "tree.h"
#include "window.h"
#define MQ_TAB_TREE(obj) (MqTabTree *) (obj)
typedef struct {
MqTree parent_instance;
MqTabLabel *label;
MqTabPage *page;
} MqTabTree;
struct _MqNotebook {
GtkNotebook parent_instance;
MqWindow *window;
MqTabTree *tree;
};
enum {
PROP_WINDOW = 1,
N_PROPERTIES
};
static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,};
struct _MqNotebookClass {
GtkNotebookClass parent_class;
};
G_DEFINE_TYPE(MqNotebook, mq_notebook, GTK_TYPE_NOTEBOOK)
static void
get_property(GObject *object, guint property_id, GValue *value,
GParamSpec *param_spec)
{
MqNotebook *notebook;
notebook = MQ_NOTEBOOK(object);
switch (property_id) {
case PROP_WINDOW:
g_value_set_object(value, notebook->window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
param_spec);
break;
}
}
static void
set_property(GObject *object, guint property_id, const GValue *value,
GParamSpec *param_spec)
{
MqNotebook *notebook;
notebook = MQ_NOTEBOOK(object);
switch (property_id) {
case PROP_WINDOW:
notebook->window = g_value_get_object(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
param_spec);
break;
}
}
static void
mq_notebook_class_init(MqNotebookClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->get_property = get_property;
object_class->set_property = set_property;
obj_properties[PROP_WINDOW] = g_param_spec_object(
"window",
"MqWindow",
"The parent MqWindow instance",
MQ_TYPE_WINDOW,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
g_object_class_install_properties(object_class, N_PROPERTIES,
obj_properties);
}
static void
mq_notebook_init(MqNotebook *notebook)
{
notebook->tree = MQ_TAB_TREE(mq_tree_insert_root_allocated(
MQ_TREE(g_new0(MqTabTree, 1)), NULL));
gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
gtk_notebook_set_group_name(GTK_NOTEBOOK(notebook), "mq-tabs");
gtk_widget_set_can_focus(GTK_WIDGET(notebook), FALSE);
}
GtkWidget *
mq_notebook_new(MqWindow *window)
{
return g_object_new(MQ_TYPE_NOTEBOOK,
"window", window,
NULL);
}