From 013e8707dac20dee4c72840989b69757bf26e72b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 10 Apr 2014 12:34:30 -0400 Subject: [PATCH] Removed unnecessary space if the secondaryText argument to MsgBox***() is an empty string. This doesn't change much on Mac OS X; it always shows the informational text field, showing an empty string by default. On GTK+ it seems to get rid of the bold over the primary text; I'm going to assume this is intentional (it looks that way on GTK+ 2; the HIG docs have outdated screenshots...). --- dialog.go | 3 ++- dialog_darwin.go | 4 +++- dialog_unix.go | 17 ++++++++++++++--- dialog_windows.go | 5 ++++- futureplans.md | 1 + test/main.go | 7 ++++++- todo.md | 1 - 7 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dialog.go b/dialog.go index 5173a5d..ae94685 100644 --- a/dialog.go +++ b/dialog.go @@ -8,7 +8,8 @@ import ( // MsgBox displays an informational message box to the user with just an OK button. // primaryText should be a short string describing the message, and will be displayed with additional emphasis on platforms that support it. -// secondaryText can be used to provide more information. +// Optionally, secondaryText can be used to show additional information. +// If you pass an empty string for secondaryText, neither additional information nor space for additional information will be shown. // On platforms that allow for the message box window to have a title, os.Args[0] is used. func MsgBox(primaryText string, secondaryText string) { msgBox(primaryText, secondaryText) diff --git a/dialog_darwin.go b/dialog_darwin.go index 89c3211..6de751a 100644 --- a/dialog_darwin.go +++ b/dialog_darwin.go @@ -33,7 +33,9 @@ func _msgBox(primarytext string, secondarytext string, style uintptr, button0 st uitask <- func() { box := C.objc_msgSend_noargs(_NSAlert, _new) C.objc_msgSend_id(box, _setMessageText, toNSString(primarytext)) - C.objc_msgSend_id(box, _setInformativeText, toNSString(secondarytext)) + if secondarytext != "" { + C.objc_msgSend_id(box, _setInformativeText, toNSString(secondarytext)) + } C.objc_msgSend_uint(box, _setAlertStyle, C.uintptr_t(style)) C.objc_msgSend_id(box, _addButtonWithTitle, toNSString(button0)) C.objc_msgSend_noargs(box, _runModal) diff --git a/dialog_unix.go b/dialog_unix.go index 3889086..ec1a4e1 100644 --- a/dialog_unix.go +++ b/dialog_unix.go @@ -12,7 +12,15 @@ import ( // #include "gtk_unix.h" // /* because cgo seems to choke on ... */ // /* TODO does NULL parent make the box application-global? docs are unclear */ -// GtkWidget *gtkNewMsgBox(GtkMessageType type, GtkButtonsType buttons, char *title, char *text) { GtkWidget *k = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, type, buttons, "%s", (gchar *) title); gtk_message_dialog_format_secondary_text((GtkMessageDialog *) k, "%s", (gchar *) text); return k; } +// GtkWidget *gtkNewMsgBox(GtkMessageType type, GtkButtonsType buttons, char *title, char *text) +// { +// GtkWidget *k; +// +// k = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, type, buttons, "%s", (gchar *) title); +// if (text != NULL) +// gtk_message_dialog_format_secondary_text((GtkMessageDialog *) k, "%s", (gchar *) text); +// return k; +// } import "C" func _msgBox(primarytext string, secondarytext string, msgtype C.GtkMessageType, buttons C.GtkButtonsType) (result C.gint) { @@ -21,8 +29,11 @@ func _msgBox(primarytext string, secondarytext string, msgtype C.GtkMessageType, uitask <- func() { cprimarytext := C.CString(primarytext) defer C.free(unsafe.Pointer(cprimarytext)) - csecondarytext := C.CString(secondarytext) - defer C.free(unsafe.Pointer(csecondarytext)) + csecondarytext := (*C.char)(nil) + if secondarytext != "" { + csecondarytext = C.CString(secondarytext) + defer C.free(unsafe.Pointer(csecondarytext)) + } box := C.gtkNewMsgBox(msgtype, buttons, cprimarytext, csecondarytext) response := C.gtk_dialog_run((*C.GtkDialog)(unsafe.Pointer(box))) C.gtk_widget_destroy(box) diff --git a/dialog_windows.go b/dialog_windows.go index 4627110..6f22df4 100644 --- a/dialog_windows.go +++ b/dialog_windows.go @@ -79,7 +79,10 @@ var ( func _msgBox(primarytext string, secondarytext string, uType uint32) (result int) { // http://msdn.microsoft.com/en-us/library/windows/desktop/aa511267.aspx says "Use task dialogs whenever appropriate to achieve a consistent look and layout. Task dialogs require Windows Vista® or later, so they aren't suitable for earlier versions of Windows. If you must use a message box, separate the main instruction from the supplemental instruction with two line breaks." - text := primarytext + "\n\n" + secondarytext + text := primarytext + if secondarytext != "" { + text += "\n\n" + secondarytext + } ret := make(chan uiret) defer close(ret) uitask <- &uimsg{ diff --git a/futureplans.md b/futureplans.md index 4dc1eb2..bda2c29 100644 --- a/futureplans.md +++ b/futureplans.md @@ -61,6 +61,7 @@ far off: - gtk+ HIG reference: https://developer.gnome.org/hig-book/3.4/controls-lists.html.en - mac HIG reference: ??? - go over the old new thing's scrollbar series to make sure I'm doing everything right with scrollbars in Windows Areas +- change the MsgBox() calls to encourage good alert dialog design??????? maybe? TODO big things: - make sure every sysData function only performs a single invocation to uitask; see http://blogs.msdn.com/b/oldnewthing/archive/2005/10/10/479124.aspx#479182 diff --git a/test/main.go b/test/main.go index 44f57a1..f19c655 100644 --- a/test/main.go +++ b/test/main.go @@ -248,7 +248,9 @@ func myMain() { w := NewWindow("Main Window", 320, 240) b := NewButton("Click Me") b2 := NewButton("Or Me") - s2 := NewHorizontalStack(b, b2) + bmsg := NewButton("Or Even Me!") + s2 := NewHorizontalStack(b, b2, bmsg) + s2.SetStretchy(2) c := NewCheckbox("Check Me") cb1 := NewEditableCombobox("You can edit me!", "Yes you can!", "Yes you will!") cb2 := NewCombobox("You can't edit me!", "No you can't!", "No you won't!") @@ -371,6 +373,9 @@ _=curtime pbar.SetProgress(-1) case <-invalidButton.Clicked: invalidTest(cb1, lb1, nil, nil) + case <-bmsg.Clicked: + MsgBox("Title Only", "") + MsgBox("Title and Text", "Text and Title") } } w.Hide() diff --git a/todo.md b/todo.md index 6d92819..ae9f48a 100644 --- a/todo.md +++ b/todo.md @@ -1,6 +1,5 @@ so I don't forget: - should Labels be selectable? -- Message boxes should not show secondary text if none is specified. [TODO figure out what I meant by this] - add bounds checking to Area's sizing methods - describe thread-safety of Area.SetSize() - should all instances of -1 as error returns from Windows functions be changed to ^0 or does the uintptr() conversion handle sign extension?