From: Andrew Trevorrow on
Does wxWidgets provide a standard "save changes" dialog for each platform?
I've searched the wx docs but I can't find anything that looks suitable.
For example, when the user quits my app but there is a modified document,
I want to bring up a dialog asking if they wish to save their changes.

I checked a few wx apps (eg. DialogBlocks) and they seem to use a simple
wxMessageBox with Yes, No and Cancel buttons. That's probably ok on
Windows, but on the Mac (and Linux?) the typical "save changes" dialog
has different button labels: Don't Save, Cancel and Save.
And on the Mac you can normally use command-D as a keyboard shortcut
for the Don't Save button.

So, before I go ahead and implement my own "save changes" dialog,
has anybody already done this?

Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Vadim Zeitlin on
On Tue, 6 Feb 2007 12:39:39 +1100 Andrew Trevorrow <andrew(a)trevorrow.com> wrote:

AT> Does wxWidgets provide a standard "save changes" dialog for each platform?

No. But it would be nice to have one, and even nicer have configurable
labels for message box buttons -- something which is languishing since a
long time in our TODO list.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Andrew Trevorrow on
The following code implements a standard "save changes" dialog for the Mac.
Feel free to use/modify/ignore it.

Andrew

// -----------------------------------------------------------------------------

#ifdef __WXMAC__

// this filter is used to detect command-D in SaveChanges dialog

Boolean SaveChangesFilter(DialogRef dlg, EventRecord* event, DialogItemIndex* item)
{
if (event->what == keyDown && (event->modifiers & cmdKey) &&
toupper(event->message & charCodeMask) == 'D') {

// temporarily highlight the Don't Save button
ControlRef ctrl;
Rect box;
GetDialogItemAsControl(dlg, kAlertStdAlertOtherButton, &ctrl);
HiliteControl(ctrl, kControlButtonPart);
GetControlBounds(ctrl, &box);
InvalWindowRect(GetDialogWindow(dlg), &box);
HIWindowFlush(GetDialogWindow(dlg));
Delay(6, NULL);
HiliteControl(ctrl, 0);

*item = kAlertStdAlertOtherButton;
return true;
}
return StdFilterProc(dlg, event, item);
}

#endif

// -----------------------------------------------------------------------------

int SaveChanges(const wxString& query, const wxString& msg)
{
#ifdef __WXMAC__
// need a more standard dialog on Mac; ie. Save/Don't Save buttons
// instead of Yes/No, and cmd-D is a shortcut for Don't Save

short result;
AlertStdCFStringAlertParamRec param;

wxMacCFStringHolder cfSave(_("Save"), wxFONTENCODING_DEFAULT);
wxMacCFStringHolder cfDontSave(_("Don't Save"), wxFONTENCODING_DEFAULT);

wxMacCFStringHolder cfTitle(query, wxFONTENCODING_DEFAULT);
wxMacCFStringHolder cfText(msg, wxFONTENCODING_DEFAULT);

param.version = kStdCFStringAlertVersionOne;
param.position = kWindowAlertPositionParentWindow;
param.movable = true;
param.flags = 0;
param.defaultText = cfSave;
param.cancelText = (CFStringRef) kAlertDefaultCancelText;
param.otherText = cfDontSave;
param.helpButton = false;
param.defaultButton = kAlertStdAlertOKButton;
param.cancelButton = kAlertStdAlertCancelButton;

ModalFilterUPP filterProc = NewModalFilterUPP(SaveChangesFilter);

DialogRef alertRef;
CreateStandardAlert(kAlertNoteAlert, cfTitle, cfText, &param, &alertRef);
RunStandardAlert(alertRef, filterProc, &result);

DisposeModalFilterUPP(filterProc);

switch (result) {
case 1: return 2; // Save
case 2: return 0; // Cancel
case 3: return 1; // Don't Save
default: return 0;
}
#else
int answer = wxMessageBox(msg, query,
wxICON_QUESTION | wxYES_NO | wxCANCEL,
wxGetActiveWindow());
switch (answer) {
case wxYES: return 2;
case wxNO: return 1;
default: return 0; // answer == wxCANCEL
}
#endif
}

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org