Back to index

indicator-appmenu  12.10.0
window-menu.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2012 Canonical Limited
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the licence, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Author: Ted Gould <ted.gould@canonical.com>
00018  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include "config.h"
00022 #endif
00023 
00024 #include "window-menu.h"
00025 #include "indicator-appmenu-marshal.h"
00026 
00027 #define WINDOW_MENU_GET_PRIVATE(o) \
00028 (G_TYPE_INSTANCE_GET_PRIVATE ((o), WINDOW_MENU_TYPE, WindowMenuPrivate))
00029 
00030 /* Signals */
00031 
00032 enum {
00033        ENTRY_ADDED,
00034        ENTRY_REMOVED,
00035        ERROR_STATE,
00036        STATUS_CHANGED,
00037        SHOW_MENU,
00038        A11Y_UPDATE,
00039        LAST_SIGNAL
00040 };
00041 
00042 static guint signals[LAST_SIGNAL] = { 0 };
00043 
00044 /* Prototypes */
00045 
00046 static void window_menu_class_init (WindowMenuClass *klass);
00047 static void window_menu_init       (WindowMenu *self);
00048 static void window_menu_dispose    (GObject *object);
00049 static void window_menu_finalize   (GObject *object);
00050 
00051 G_DEFINE_TYPE (WindowMenu, window_menu, G_TYPE_OBJECT);
00052 
00053 static void
00054 window_menu_class_init (WindowMenuClass *klass)
00055 {
00056        GObjectClass *object_class = G_OBJECT_CLASS (klass);
00057 
00058        object_class->dispose = window_menu_dispose;
00059        object_class->finalize = window_menu_finalize;
00060 
00061        /* Signals */
00062        signals[ENTRY_ADDED] =  g_signal_new(WINDOW_MENU_SIGNAL_ENTRY_ADDED,
00063                                              G_TYPE_FROM_CLASS(klass),
00064                                              G_SIGNAL_RUN_LAST,
00065                                              G_STRUCT_OFFSET (WindowMenuClass, entry_added),
00066                                              NULL, NULL,
00067                                              g_cclosure_marshal_VOID__POINTER,
00068                                              G_TYPE_NONE, 1, G_TYPE_POINTER);
00069        signals[ENTRY_REMOVED] =  g_signal_new(WINDOW_MENU_SIGNAL_ENTRY_REMOVED,
00070                                              G_TYPE_FROM_CLASS(klass),
00071                                              G_SIGNAL_RUN_LAST,
00072                                              G_STRUCT_OFFSET (WindowMenuClass, entry_removed),
00073                                              NULL, NULL,
00074                                              g_cclosure_marshal_VOID__POINTER,
00075                                              G_TYPE_NONE, 1, G_TYPE_POINTER);
00076        signals[ERROR_STATE] =   g_signal_new(WINDOW_MENU_SIGNAL_ERROR_STATE,
00077                                              G_TYPE_FROM_CLASS(klass),
00078                                              G_SIGNAL_RUN_LAST,
00079                                              G_STRUCT_OFFSET (WindowMenuClass, error_state),
00080                                              NULL, NULL,
00081                                              g_cclosure_marshal_VOID__BOOLEAN,
00082                                              G_TYPE_NONE, 1, G_TYPE_BOOLEAN, G_TYPE_NONE);
00083        signals[STATUS_CHANGED] = g_signal_new(WINDOW_MENU_SIGNAL_STATUS_CHANGED,
00084                                              G_TYPE_FROM_CLASS(klass),
00085                                              G_SIGNAL_RUN_LAST,
00086                                              G_STRUCT_OFFSET (WindowMenuClass, status_changed),
00087                                              NULL, NULL,
00088                                              g_cclosure_marshal_VOID__INT,
00089                                              G_TYPE_NONE, 1, G_TYPE_INT, G_TYPE_NONE);
00090        signals[SHOW_MENU] =     g_signal_new(WINDOW_MENU_SIGNAL_SHOW_MENU,
00091                                              G_TYPE_FROM_CLASS(klass),
00092                                              G_SIGNAL_RUN_LAST,
00093                                              G_STRUCT_OFFSET (WindowMenuClass, show_menu),
00094                                              NULL, NULL,
00095                                              _indicator_appmenu_marshal_VOID__POINTER_UINT,
00096                                              G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_NONE);
00097        signals[A11Y_UPDATE] =   g_signal_new(WINDOW_MENU_SIGNAL_A11Y_UPDATE,
00098                                              G_TYPE_FROM_CLASS(klass),
00099                                              G_SIGNAL_RUN_LAST,
00100                                              G_STRUCT_OFFSET (WindowMenuClass, a11y_update),
00101                                              NULL, NULL,
00102                                              _indicator_appmenu_marshal_VOID__POINTER,
00103                                              G_TYPE_NONE, 1, G_TYPE_POINTER, G_TYPE_NONE);
00104 
00105        return;
00106 }
00107 
00108 static void
00109 window_menu_init (WindowMenu *self)
00110 {
00111 
00112 
00113        return;
00114 }
00115 
00116 static void
00117 window_menu_dispose (GObject *object)
00118 {
00119 
00120        G_OBJECT_CLASS (window_menu_parent_class)->dispose (object);
00121        return;
00122 }
00123 
00124 static void
00125 window_menu_finalize (GObject *object)
00126 {
00127 
00128        G_OBJECT_CLASS (window_menu_parent_class)->finalize (object);
00129        return;
00130 }
00131 
00132 
00133 /**************************
00134   API
00135  **************************/
00136 GList *
00137 window_menu_get_entries (WindowMenu * wm)
00138 {
00139        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00140 
00141        if (class->get_entries != NULL) {
00142               return class->get_entries(wm);
00143        } else {
00144               return NULL;
00145        }
00146 }
00147 
00148 guint
00149 window_menu_get_location (WindowMenu * wm, IndicatorObjectEntry * entry)
00150 {
00151        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00152 
00153        if (class->get_location != NULL) {
00154               return class->get_location(wm, entry);
00155        } else {
00156               return 0;
00157        }
00158 }
00159 
00160 guint
00161 window_menu_get_xid (WindowMenu * wm)
00162 {
00163        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00164 
00165        if (class->get_xid != NULL) {
00166               return class->get_xid(wm);
00167        } else {
00168               return 0;
00169        }
00170 }
00171 
00172 gboolean
00173 window_menu_get_error_state (WindowMenu * wm)
00174 {
00175        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00176 
00177        if (class->get_error_state != NULL) {
00178               return class->get_error_state(wm);
00179        } else {
00180               return TRUE;
00181        }
00182 }
00183 
00184 WindowMenuStatus
00185 window_menu_get_status (WindowMenu * wm)
00186 {
00187        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00188 
00189        if (class->get_status != NULL) {
00190               return class->get_status(wm);
00191        } else {
00192               return WINDOW_MENU_STATUS_NORMAL;
00193        }
00194 }
00195 
00196 void
00197 window_menu_entry_restore (WindowMenu * wm, IndicatorObjectEntry * entry)
00198 {
00199        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00200 
00201        if (class->entry_restore != NULL) {
00202               return class->entry_restore(wm, entry);
00203        } else {
00204               return;
00205        }
00206 }
00207 
00208 void
00209 window_menu_entry_activate (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp)
00210 {
00211        WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm);
00212 
00213        if (class->entry_activate != NULL) {
00214               return class->entry_activate(wm, entry, timestamp);
00215        } else {
00216               return;
00217        }
00218 }