message-box.zc
来自「实现树形结构」· ZC 代码 · 共 111 行
ZC
111 行
//[c]Simple Message Boxes
//[c]
//[of]:license
//[c] Code Browser - a folding text editor for programmers
//[c] Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c] This program is free software; you can redistribute it and/or modify
//[c] it under the terms of the GNU General Public License as published by
//[c] the Free Software Foundation; either version 2 of the License, or
//[c] (at your option) any later version.
//[c]
//[c] This program is distributed in the hope that it will be useful,
//[c] but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c] MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//[c] GNU General Public License for more details.
//[c]
//[c] You should have received a copy of the GNU General Public License
//[c] along with this program; if not, write to the Free Software
//[c] Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//[cf]
//[of]:imports
import "base/types"
//[c]
import "private/sys-graphics"
import "user/box"
//[c]
import "glib/glib"
import "gdk/gdk"
import "gtk/gtk"
//[cf]
//[of]:constants
//[c]
public enum message box type
mb ok
mb ok cancel
mb yes no cancel
mb yes no
end
//[c]
public enum message box code
id ok = GTK_RESPONSE_OK
id cancel = GTK_RESPONSE_CANCEL
id yes = GTK_RESPONSE_YES
id no = GTK_RESPONSE_NO
end
//[cf]
//[c]
//[of]:message box (parent, text, title, type)
//[c]
public func message box (
parent: box,
text: string,
title: string,
type: message box type)
def gtk type : GtkButtonsType
switch type
case mb ok
gtk type = GTK_BUTTONS_OK
case mb ok cancel
gtk type = GTK_BUTTONS_OK_CANCEL
else
gtk type = GTK_BUTTONS_YES_NO
end
def window = nil : GtkWindow
if not nil (parent)
window = widget (parent): GtkWindow
end
def dialog = gtk_message_dialog_new_nofmt (window,
(GTK_DIALOG_MODAL:int | GTK_DIALOG_DESTROY_WITH_PARENT:int):GtkDialogFlags,
GTK_MESSAGE_INFO,
gtk type,
to UTF8 (text)) : GtkDialog
// special case yes-no-cancel: add cancel button manually
// since the presets does not exist
if type == mb yes no cancel
gtk_dialog_add_button (
dialog,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL : gint)
end
// the default in a yes-no[-cancel] dialogs is yes in order
// to have the same behavior between GTK+ and Windows
if type == mb yes no cancel || type == mb yes no
gtk_dialog_set_default_response (dialog, GTK_RESPONSE_YES : gint)
end
gtk_window_set_title (dialog, to UTF8 (title))
def code = gtk_dialog_run (dialog)
gtk_widget_destroy (dialog)
if code == GTK_RESPONSE_DELETE_EVENT : int
switch type
case mb ok
code = id ok : int
case mb ok cancel, mb yes no cancel
code = id cancel : int
else
code = id no : int
end
end
return code : message box code
end
//[cf]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?