Include file ExtMessageRequester.pbi
Code: Select all
; Extended Message Requester include file (p) 2012 Frarth
; ------------------------------------------------------------------
EnableExplicit
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
#GTK_BUTTONS_YESNOCANCEL = 6
#MR_BUTTON_YES = #GTK_RESPONSE_YES
#MR_BUTTON_NO = #GTK_RESPONSE_NO
#MR_BUTTON_CANCEL = #GTK_RESPONSE_CANCEL
#MR_ICON_ERROR = #GTK_MESSAGE_ERROR * $200
#MR_ICON_INFORMATION = #GTK_MESSAGE_INFO * $200
#MR_ICON_QUESTION = #GTK_MESSAGE_QUESTION * $200
#MR_ICON_WARNING = #GTK_MESSAGE_WARNING * $200
CompilerElse
#MR_BUTTON_YES = #PB_MessageRequester_Yes
#MR_BUTTON_NO = #PB_MessageRequester_No
#MR_BUTTON_CANCEL = #PB_MessageRequester_Cancel
#MR_ICON_ERROR = #MB_ICONERROR
#MR_ICON_INFORMATION = #MB_ICONINFORMATION
#MR_ICON_QUESTION = #MB_ICONQUESTION
#MR_ICON_WARNING = #MB_ICONWARNING
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Declare GTK_MessageRequester(Title.s, Message.s, Buttons.l = #GTK_BUTTONS_OK, Type.l = #GTK_MESSAGE_INFO, Sub1.s = "", Sub2.s = "")
CompilerEndIf
Declare.i MessageRequesterX(Title.s, Message.s, Flags.l = 0)
Code: Select all
; Extended MessageRequester (p) 2012 Frarth
; ----------------------------------------------------
EnableExplicit
XIncludeFile "ExtMessageRequester.pbi"
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Procedure GTK_MessageRequester(Title.s, Message.s, Buttons.l = #GTK_BUTTONS_OK, Type.l = #GTK_MESSAGE_INFO, Sub1.s = "", Sub2.s = "")
Protected *dialog.GtkMessageDialog
Protected result.i
*dialog = gtk_message_dialog_new_(0, #True, Type, Buttons, Message, Sub1, Sub2)
gtk_window_set_title_(*dialog, Title)
If Buttons = #GTK_BUTTONS_YESNOCANCEL
gtk_dialog_add_button_(*dialog, #GTK_STOCK_CANCEL, #GTK_RESPONSE_CANCEL)
gtk_dialog_add_button_(*dialog, #GTK_STOCK_NO, #GTK_RESPONSE_NO)
gtk_dialog_add_button_(*dialog, #GTK_STOCK_YES, #GTK_RESPONSE_YES)
EndIf
result = gtk_dialog_run_(*dialog)
gtk_widget_destroy_(*dialog)
ProcedureReturn result
EndProcedure
CompilerEndIf
Procedure.i MessageRequesterX(Title.s, Message.s, Flags.l = 0)
Protected buttons.l, result.l, type.l
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Select Flags & $1FF
Case #PB_MessageRequester_YesNo
buttons = #GTK_BUTTONS_YES_NO
Case #PB_MessageRequester_YesNoCancel
buttons = #GTK_BUTTONS_YESNOCANCEL
Case #PB_MessageRequester_Ok
buttons = #GTK_BUTTONS_OK
EndSelect
; TYPE
type = Flags / $200
result = GTK_MessageRequester(Title, Message, buttons, type)
CompilerElse ; Windows, Mac
result = MessageRequester(Title, Message, Flags)
CompilerEndIf
ProcedureReturn result
EndProcedure
; Example
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
gtk_init_(0,0)
CompilerEndIf
Define response.i
response = MessageRequesterX("Test", "Are you sure you want to use this stuff?", #PB_MessageRequester_YesNoCancel | #MR_ICON_QUESTION)
If response = #MR_BUTTON_YES
Debug "That is a YES!"
ElseIf response = #MR_BUTTON_NO
Debug "No, too bad."
Else
Debug "Please make up your mind!"
EndIf