ProblemIn order to prevent the user from accidentally deleting data from the database the application should display a confirmation dialog to ensure that the user wants to delete the data. The application must display the confirmation dialog, retrieve the user's selection and either delete the data, or cancel this deletion. SolutionThere is a query widget resource, XmNdeleteRecordCallback that is called whenever the application initiates a delete. The callback struct, XiDBQueryCallbackStruct(page 196 in documentation), contains and ok field. The ok field specifies whether the deletion should be performed. Setting ok to 0 prevents the deletion from occuring, if ok is 1, the data will be deleted. Using this resource, XmNdeleteRecordCallback, it is pretty straight forward to display a confirmation dialog from the callback routine. The trick is to retrieve the user's input to the dialog and use that to set the ok field in the XiDBQueryCallbackStruct. In order to capture the user's response from within this callback routine we must handle our own events! This may sound pretty complicated, but with the code we're providing below you should have this running in no time. The code below will create and display the confirmation dialog. You are only required to set the query resource, XmNdeleteRecordCallback, to the procedure name or your choice (the below code uses testMe). Within your procedure you'll need to call YesNoBox and provide the label strings for the pushbuttons on this dialog. callbacks-c.c
|