1 /* 2 * Copyright (C) 2002 2003 2004 2009, Magnus Hjorth 3 * 4 * This file is part of mhWaveEdit. 5 * 6 * mhWaveEdit is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * mhWaveEdit is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with mhWaveEdit; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 22 /* This is a dropdown read-only combo box with text items. Under GTK 1.2-2.2 23 * this is done as a subclass of GtkCombo with some extra trickery and under 24 * 2.4 and later it's a simple subclass of GtkComboBox. */ 25 26 27 #ifndef COMBO_H_INCLUDED 28 #define COMBO_H_INCLUDED 29 30 #include "main.h" 31 32 #define COMBO(obj) GTK_CHECK_CAST(obj,combo_get_type(),Combo) 33 #define COMBO_CLASS(klass) GTK_CHECK_CLASS_CAST(klass,combo_get_type(),ComboClass) 34 #define IS_COMBO(obj) GTK_CHECK_TYPE(obj,combo_get_type()) 35 36 #if (GTK_MAJOR_VERSION == 1) || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4) 37 #define COMBO_OLDSCHOOL 38 #define COMBO_PARENT_TYPE GtkCombo 39 #define COMBO_PARENT_CLASS GtkComboClass 40 #define COMBO_PARENT_TYPE_FUNC gtk_combo_get_type 41 #else 42 #define COMBO_PARENT_TYPE GtkComboBox 43 #define COMBO_PARENT_CLASS GtkComboBoxClass 44 #define COMBO_PARENT_TYPE_FUNC gtk_combo_box_get_type 45 #endif 46 47 typedef struct { 48 COMBO_PARENT_TYPE parent; 49 #ifdef COMBO_OLDSCHOOL 50 int chosen_index, next_chosen_index; 51 #else 52 /* Until GTK+ 2.6 comes out with the 53 gtk_combo_box_get_active_text function, this will have to 54 make do. */ 55 GList *strings; 56 #endif 57 int max_request_width; 58 } Combo; 59 60 typedef struct { 61 COMBO_PARENT_CLASS parent_class; 62 void (*selection_changed)(Combo *obj); 63 } ComboClass; 64 65 GtkType combo_get_type(void); 66 GtkWidget *combo_new(void); 67 void combo_set_items(Combo *combo, GList *item_strings, int default_index); 68 void combo_set_selection(Combo *combo, int item_index); 69 /* The removed item must not be currently selected */ 70 void combo_remove_item(Combo *combo, int item_index); 71 int combo_selected_index(Combo *combo); 72 73 /* Result must be freed by caller */ 74 char *combo_selected_string(Combo *combo); 75 76 void combo_set_max_request_width(Combo *c, int w); 77 78 #endif 79