Last active
August 29, 2015 13:57
-
-
Save anaselli/9622726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/YGDialog.cc b/src/YGDialog.cc | |
index ba718df..c036e6d 100644 | |
--- a/src/YGDialog.cc | |
+++ b/src/YGDialog.cc | |
@@ -8,6 +8,7 @@ | |
#include "YGDialog.h" | |
#include "YGUtils.h" | |
#include <YDialogSpy.h> | |
+#include <YPushButton.h> | |
#include <gdk/gdkkeysyms.h> | |
#include <math.h> // easter | |
#include <string.h> | |
@@ -340,6 +341,16 @@ YGDialog::~YGDialog() | |
YGWindow::unref (m_window); | |
} | |
+void YGDialog::setDefaultButton(YPushButton* newDefaultButton) | |
+{ | |
+ YDialog::setDefaultButton( 0 ); // prevent complaints about multiple default buttons | |
+ if ( newDefaultButton ) | |
+ { | |
+ newDefaultButton->setKeyboardFocus(); | |
+ YDialog::setDefaultButton(newDefaultButton); | |
+ } | |
+} | |
+ | |
void YGDialog::openInternal() | |
{ | |
m_window->show(); | |
diff --git a/src/YGDialog.h b/src/YGDialog.h | |
index 4330801..5e126e4 100644 | |
--- a/src/YGDialog.h | |
+++ b/src/YGDialog.h | |
@@ -22,6 +22,11 @@ public: | |
YGDialog (YDialogType dialogType, YDialogColorMode colorMode); | |
virtual ~YGDialog(); | |
+ /** | |
+ * Set the dialog's default button | |
+ **/ | |
+ void setDefaultButton( YPushButton * newDefaultButton ); | |
+ | |
virtual GtkWidget *getContainer() { return m_containee; } | |
void setCloseCallback (YGWindowCloseFn closeCallback, void *closeData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2014 Angelo Naselli <anaselli@linux.it> | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be | |
included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | |
THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
*/ | |
// YesOrNo dialog libyui example. | |
// | |
// Compile with: | |
// | |
// g++ -I/usr/include/yui -lyui YesOrNo.cc -o YesOrNo | |
#include <yui/YUI.h> | |
#include <yui/YApplication.h> | |
#include <yui/YWidgetFactory.h> | |
#include <yui/YDialog.h> | |
#include <yui/YLayoutBox.h> | |
#include <yui/YEvent.h> | |
#include <yui/YPushButton.h> | |
int main( int argc, char **argv ) | |
{ | |
YDialog * dialog = YUI::widgetFactory()->createPopupDialog(); | |
YLayoutBox * vbox = YUI::widgetFactory()->createVBox( dialog ); | |
YUI::widgetFactory()->createLabel ( vbox, "Are you sure?" ); | |
YLayoutBox * hbox = YUI::widgetFactory()->createHBox( vbox ); | |
YPushButton* yesButton = YUI::widgetFactory()->createPushButton( vbox, "Yes" ); | |
YPushButton* noButton = YUI::widgetFactory()->createPushButton( vbox, "No" ); | |
dialog->setDefaultButton(noButton); | |
while (1) | |
{ | |
YEvent* pEvent = dialog->waitForEvent(); | |
if (pEvent->eventType() == YEvent::CancelEvent) { | |
break; | |
} | |
else if (pEvent->eventType() == YEvent::WidgetEvent) { | |
if ( pEvent->widget() == noButton ) { | |
std::cout << "NO" << std::endl; | |
break; | |
} | |
else if ( pEvent->widget() == yesButton ) { | |
std::cout << "YES" << std::endl; | |
break; | |
} | |
} | |
} | |
dialog->destroy(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment