/* * Copyright 2015 Javier S. Pedro * * This file is part of MDock. * * MDock 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. * * MDock 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 Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MDock. If not, see . */ #include "mdock-mate-panel-applet.h" #include #include G_DEFINE_TYPE(MDockMatePanelApplet, mdock_mate_panel_applet, PANEL_TYPE_APPLET) static void display_preferences_dialog(GtkAction *action, MDockMatePanelApplet *self) { // TODO } static void display_about_dialog(GtkAction *action, MDockMatePanelApplet *self) { GtkWindow *parent = NULL; GtkWidget *parent_widget = gtk_widget_get_toplevel(GTK_WIDGET(self)); if (GTK_IS_WINDOW(parent_widget)) { parent = GTK_WINDOW(parent_widget); } gtk_show_about_dialog(parent, "program-name", "MDock Mate Panel Applet", NULL); } static const GtkActionEntry menu_verbs[] = { { "MDockPreferences", GTK_STOCK_PROPERTIES, N_("_Preferences"), NULL, NULL, G_CALLBACK (display_preferences_dialog) }, { "MDockAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, G_CALLBACK (display_about_dialog) } }; static gboolean transform_applet_orient_to_orientation(GBinding *binding, const GValue *from_value, GValue *to_value, gpointer user_data) { MatePanelAppletOrient orient = g_value_get_enum(from_value); switch (orient) { case MATE_PANEL_APPLET_ORIENT_DOWN: case MATE_PANEL_APPLET_ORIENT_UP: g_value_set_enum(to_value, GTK_ORIENTATION_HORIZONTAL); break; case MATE_PANEL_APPLET_ORIENT_LEFT: case MATE_PANEL_APPLET_ORIENT_RIGHT: g_value_set_enum(to_value, GTK_ORIENTATION_VERTICAL); break; } } static void mdock_mate_panel_applet_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { MDockMatePanelApplet *self = MDOCK_MATE_PANEL_APPLET(widget); if (self->dock) { gtk_widget_size_allocate(GTK_WIDGET(self->dock), allocation); } GTK_WIDGET_CLASS(mdock_mate_panel_applet_parent_class)->size_allocate(widget, allocation); } static void mdock_mate_panel_applet_size_request(GtkWidget *widget, GtkRequisition *requisition) { MDockMatePanelApplet *self = MDOCK_MATE_PANEL_APPLET(widget); if (self->dock) { gtk_widget_size_request(GTK_WIDGET(self->dock), requisition); } } static void mdock_mate_panel_applet_class_init(MDockMatePanelAppletClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); widget_class->size_allocate = mdock_mate_panel_applet_size_allocate; widget_class->size_request = mdock_mate_panel_applet_size_request; } static void mdock_mate_panel_applet_init(MDockMatePanelApplet *self) { self->dock = MDOCK_WIDGET(mdock_widget_new()); gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(self->dock)); g_object_bind_property_full(self, "orient", self->dock, "orientation", G_BINDING_DEFAULT, transform_applet_orient_to_orientation, NULL, NULL, NULL); GtkActionGroup *action_group = gtk_action_group_new("MDock Mate Panel Applet Actions"); gtk_action_group_add_actions(action_group, menu_verbs, G_N_ELEMENTS(menu_verbs), self); mate_panel_applet_set_flags(MATE_PANEL_APPLET(self), MATE_PANEL_APPLET_EXPAND_MINOR); mate_panel_applet_setup_menu(MATE_PANEL_APPLET(self), "" "", action_group); g_object_unref(action_group); gtk_widget_show(GTK_WIDGET(self->dock)); } MatePanelApplet *mdock_mate_panel_applet_new(void) { return MATE_PANEL_APPLET(g_object_new(MDOCK_TYPE_MATE_PANEL_APPLET, NULL)); }