1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or(at your option ) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 * MA 02110-1301, USA. 19 */ 20 21 #include "oxygendialogengine.h" 22 #include "../oxygengtktypenames.h" 23 #include "../oxygengtkutils.h" 24 #include "../config.h" 25 26 #include <string> 27 28 namespace Oxygen 29 { 30 //_________________________________________________________ registerWidget(GtkWidget * widget)31 bool DialogEngine::registerWidget( GtkWidget* widget ) 32 { 33 if( contains( widget ) ) return false; 34 35 GtkDialog* dialog(GTK_DIALOG(widget)); 36 37 GtkResponseType responses[]={ 38 GTK_RESPONSE_HELP, 39 (GtkResponseType)1, // FIXME: This id is commonly used, but doesn't seem to be documented anywhere... 40 GTK_RESPONSE_OK, 41 GTK_RESPONSE_YES, 42 GTK_RESPONSE_ACCEPT, 43 GTK_RESPONSE_APPLY, 44 GTK_RESPONSE_REJECT, 45 GTK_RESPONSE_CLOSE, 46 GTK_RESPONSE_NO, 47 GTK_RESPONSE_CANCEL 48 }; 49 50 const int numOfResponseIDs=sizeof(responses)/sizeof(responses[0]); 51 52 #if OXYGEN_DEBUG 53 std::cerr<<"DialogEngine::registerWidget - Initial response table: "; 54 for(int i=0; i<numOfResponseIDs; i++) 55 { std::cerr << Gtk::TypeNames::response( responses[i] ) << ", "; } 56 std::cerr<<std::endl; 57 #endif 58 59 int numOfResponsesFound=0; 60 for(int i=0; i<numOfResponseIDs; i++) 61 { 62 GtkWidget* button( Gtk::gtk_dialog_find_button(dialog,responses[i]) ); 63 if( !button ) continue; 64 65 #if OXYGEN_DEBUG 66 std::cerr << "responseID found: " << Gtk::TypeNames::response( responses[i] ) << "; button \"" << gtk_button_get_label(GTK_BUTTON(button)) << "\"" << std::endl; 67 #endif 68 // i is always >= numOfResponsesFound, so this will copy response id nearer to start, but never to end 69 responses[numOfResponsesFound]=responses[i]; 70 numOfResponsesFound++; 71 72 } 73 74 #if OXYGEN_DEBUG 75 std::cerr << "DialogEngine::registerWidget - numOfResponsesFound: " << numOfResponsesFound << std::endl; 76 std::cerr << "List of responses found: { "; 77 78 for(int i=0; i<numOfResponsesFound; i++) 79 { std::cerr << Gtk::TypeNames::response( responses[i] ) << (i==numOfResponsesFound-1 ? " " :", "); } 80 81 std::cerr << "}; remaining in the list: { "; 82 83 for(int i=numOfResponsesFound; i<numOfResponseIDs; i++) 84 { std::cerr << Gtk::TypeNames::response( responses[i] ) << (i==numOfResponseIDs-1 ? " " :", "); } 85 86 std::cerr << "}\n"; 87 #endif 88 89 // change order 90 gtk_dialog_set_alternative_button_order_from_array( dialog, numOfResponsesFound, (gint*) responses ); 91 92 // insert in set 93 _data.insert( widget ); 94 95 // call base class 96 BaseEngine::registerWidget( widget ); 97 return true; 98 99 } 100 } 101