2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
26 * $TOG: Undelete.C /main/9 1998/09/24 17:33:53 mgreess $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 #include <Xm/LabelG.h>
45 #include <Xm/RowColumn.h>
46 #include "Undelete.hh"
47 #include "MsgScrollingList.hh"
48 #include "RoamMenuWindow.h"
50 #include "QueryDialogManager.hh"
51 #endif /* DEAD_WOOD */
52 #include "DialogShell.h"
53 #include "Application.h"
54 #include "ButtonInterface.h"
58 #include "MsgHndArray.hh"
60 #include "MemUtils.hh"
62 #include "DtMailGenDialog.hh"
65 UndelMsgScrollingList::UndelMsgScrollingList (RoamMenuWindow *rmw, Widget w,
67 : MsgScrollingList(rmw, w, string)
71 UndelMsgScrollingList::~UndelMsgScrollingList()
76 UndelMsgScrollingList::extended_selection(DtMailEnv &, int)
82 UndelMsgScrollingList::deleteSelected(Boolean)
84 // SR - Added stuff below. Made code more efficient also.
85 FORCE_SEGV_DECL(MsgStruct, a_del_msg_struct);
86 FORCE_SEGV_DECL(MsgStruct, tmpMS);
87 int position_in_list, i;
88 FORCE_SEGV_DECL(int, position_list);
96 XmNitemCount, &num_msgs,
99 any_selected = XmListGetSelectedPos(_w,
103 if (!any_selected) return;
105 for (i=0; i < position_count; i++ ) {
106 position_in_list = *(position_list + i);
108 a_del_msg_struct = get_message_struct(position_in_list);
109 _msgs->mark_for_delete(position_in_list - 1);
116 // Delete the items from the scrolling list
117 XmListDeletePositions(_w,
121 // XnListGetSelectedPos allocated memory for the array and
122 // wants us to free it. See documentation.
125 num_msgs = _msgs->length();
126 XtFree((char*) position_list);
130 UndelMsgScrollingList::insertMsg(DtMailMessageHandle tmpMH)
132 MsgScrollingList::insertMsg(tmpMH);
136 UndelMsgScrollingList::insertMsg(
137 DtMailEnv &mail_error,
143 _msgs->append(tmpMS);
145 DtMailHeaderLine info;
147 DtMail::MailBox * mbox = this->parent()->mailbox();
149 mbox->getMessageSummary(mail_error,
150 tmpMS->message_handle,
153 DtMail::Message * msg = mbox->getMessage(mail_error, tmpMS->message_handle);
156 if (mail_error.isSet()) {
160 item = formatHeader(info,
161 tmpMS->sessionNumber,
162 show_with_attachments(msg),
163 msg->flagIsSet(mail_error, DtMailMessageNew));
164 XmListAddItem( _w , item, 0 );
165 XmStringFree( item );
171 UndelMsgScrollingList::loadMsgs(
172 DtMailEnv &mail_error,
173 MsgHndArray *deleted_msgs,
180 DtMailHeaderLine info;
181 DtMail::Message * msg;
184 msg_hdrs = (XmString *)malloc(sizeof(XmString) * count);
185 memset(msg_hdrs, 0, sizeof(XmString) * count);
187 DtMail::MailBox * mbox = this->parent()->mailbox();
189 for (i = 0; i < count; i ++) {
190 tmpMS = deleted_msgs->at(i);
191 _msgs->append(tmpMS);
193 mbox->getMessageSummary(mail_error,
194 tmpMS->message_handle,
198 msg = mbox->getMessage(mail_error, tmpMS->message_handle);
200 if (mail_error.isSet()) {
204 msg_hdrs[i] = formatHeader(info,
205 tmpMS->sessionNumber,
206 show_with_attachments(msg),
207 msg->flagIsSet(mail_error, DtMailMessageNew));
210 XmListAddItems(_w, msg_hdrs, count, 0);
212 // Free the strings we added to the header array.
213 for (i = 0; i < count; i++) {
214 XmStringFree(msg_hdrs[i]);
223 UndelFromListDialog::loadMsgs(
224 DtMailEnv &mail_error,
225 MsgHndArray *deleted_msgs,
229 _list->loadMsgs(mail_error, deleted_msgs, count);
232 UndelFromListDialog::UndelFromListDialog (
234 RoamMenuWindow *parent
235 ) : DialogShell ( name, parent )
237 assert (theApplication != NULL);
239 _undelete_button = NULL;
240 _close_button = NULL;
241 _undel_list_button = NULL;
244 rowOfMessageStatus = NULL;
248 UndelFromListDialog::~UndelFromListDialog()
253 UndelFromListDialog::popped_down()
255 XtUnmapWidget(this->baseWidget());
259 UndelFromListDialog::popped_up()
262 XtMapWidget(this->baseWidget());
266 UndelFromListDialog::initialize()
268 DialogShell::initialize();
272 UndelFromListDialog::quit()
274 // Pop down the dialog
279 UndelFromListDialog::createWorkArea ( Widget parent )
283 Widget l1, l2, l3, l4;
285 XtWidgetGeometry size;
287 form1 = XmCreateForm(parent, "Work_Area", NULL, 0);
290 printHelpId("form1", form1);
292 rowOfLabels = XtCreateManagedWidget ("rowOfLabels",
298 printHelpId("rowOfLabels", rowOfLabels);
301 size.request_mode = CWHeight;
302 XtQueryGeometry(rowOfLabels, NULL, &size);
303 XtVaSetValues(rowOfLabels,
304 XmNpaneMaximum, size.height,
305 XmNpaneMinimum, size.height,
306 XmNrightAttachment, XmATTACH_FORM,
307 XmNleftAttachment, XmATTACH_FORM,
308 XmNtopAttachment, XmATTACH_FORM,
310 XmNorientation, XmHORIZONTAL,
313 XmNentryAlignment, XmALIGNMENT_CENTER,
316 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 14,
319 l1 = XtVaCreateManagedWidget("Label1", xmLabelGadgetClass,
321 XmNlabelString, labelStr,
324 XmStringFree(labelStr);
325 printHelpId("l1", l1);
326 /* add help callback */
327 // XtAddCallback(l1, XmNhelpCallback, HelpCB, helpId);
330 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 15,
332 l2 = XtVaCreateManagedWidget("Label2",
333 xmLabelGadgetClass, rowOfLabels,
334 XmNlabelString, labelStr,
339 XmStringFree(labelStr);
340 printHelpId("l2", l2);
341 /* add help callback */
342 // XtAddCallback(l2, XmNhelpCallback, HelpCB, helpId);
344 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 16,
346 l3 = XtVaCreateManagedWidget("Label3",
347 xmLabelGadgetClass, rowOfLabels,
348 XmNlabelString, labelStr,
351 XmStringFree(labelStr);
352 printHelpId("l3", l3);
353 /* add help callback */
354 // XtAddCallback(l3, XmNhelpCallback, HelpCB, helpId);
356 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 17,
358 l4 = XtVaCreateManagedWidget("Label4",
359 xmLabelGadgetClass, rowOfLabels,
360 XmNlabelString, labelStr,
363 XmStringFree(labelStr);
364 printHelpId("l4", l4);
365 /* add help callback */
367 _list = new UndelMsgScrollingList( this->parent(), form1, "Message_List");
370 DtMail::Session * d_session = theRoamApp.session()->session();
371 DtMail::MailRc * mailrc = d_session->mailRc(error);
375 mailrc->getValue(error, "showmsgnum", &value);
376 if (error.isNotSet()) {
382 // Adjust labels so the align on the columns
383 _list->layoutLabels(l1, l2, l3, l4);
386 rowOfButtons = XtCreateManagedWidget("RowColumn",
391 printHelpId ("rowOfButtons", rowOfButtons);
393 XtVaSetValues(XtParent(_list->get_scrolling_list()),
394 XmNrightAttachment, XmATTACH_FORM,
395 XmNleftAttachment, XmATTACH_FORM,
396 XmNtopAttachment, XmATTACH_WIDGET,
397 XmNtopWidget, rowOfLabels,
399 XmNbottomAttachment, XmATTACH_WIDGET,
400 XmNbottomWidget, rowOfButtons,
404 XtVaSetValues(rowOfButtons,
405 XmNorientation, XmHORIZONTAL,
406 XmNpaneMaximum, size.height,
407 XmNpaneMinimum, size.height,
408 XmNrightAttachment, XmATTACH_FORM,
409 XmNleftAttachment, XmATTACH_FORM,
410 XmNbottomAttachment, XmATTACH_FORM,
411 XmNfractionBase, 100,
415 // Create undelete and close buttons.
416 this->addToRowOfButtons();
420 // Label should go here that says in how many days
421 // deleted messages will be destroyed, and for status.
422 rowOfMessageStatus = XtCreateManagedWidget("Message_Status",
425 XtVaSetValues(rowOfMessageStatus,
426 XmNrightAttachment, XmATTACH_FORM,
427 XmNleftAttachment, XmATTACH_FORM,
428 XmNtopAttachment, XmATTACH_FORM,
433 XtManageChild(_list->baseWidget());
434 XtManageChild(form1);
441 UndelFromListDialog::insertMsg(DtMailEnv &mail_error, MsgStruct *tmpMS)
443 _list->insertMsg(mail_error, tmpMS);
447 UndelFromListDialog::undelLast()
451 len = _list->get_messages()->length();
452 _list->get_messages()->mark_for_delete(len - 1);
453 _list->get_messages()->compact(0);
454 XmListDeletePos(_list->get_scrolling_list(), len);
460 UndelFromListDialog::undelSelected()
462 FORCE_SEGV_DECL(int, position_list);
463 FORCE_SEGV_DECL(MsgHndArray, tmpMHlist);
465 Boolean any_selected = FALSE;
467 any_selected = XmListGetSelectedPos(_list->get_scrolling_list(),
471 // Don't do anything if there aren't any messages selected.
473 if ((!any_selected) || (position_count <= 0)) return;
476 // Put the selected messages from the Deleted Messages List
477 // into the RoamMenuWindow Message Scrolling List.
480 // This is kind of tricky, because we have to get the list of
481 // selected messages before we delete the selected messages,
482 // but we have to delete the selected messages before we
483 // pass them to undelete_messages(). The reason for this
484 // is that deleteSelected() changes the is_deleted attribute
485 // of the message handle to TRUE, which will undo undelete_messages()
486 // setting is_deleted to FALSE! Did you follow all that?
488 tmpMHlist = _list->selected();
490 // Remove the selected messages from the Deleted Messages Dialog.
491 _list->deleteSelected();
493 // Add the messages to the RoamMenuWindow scrolling list.
494 MsgScrollingList *msl = parent()->list();
495 msl->undelete_messages(tmpMHlist);
497 XtFree((char*) position_list);
502 UndelFromListDialog::addToRowOfButtons()
504 FORCE_SEGV_DECL(CmdInterface, ci);
505 Widget w, prev_widget;
507 _undelete_button = new DoUndeleteCmd(
509 GETMSG(DT_catd, 1, 115, "Undelete"),
512 ci = new ButtonInterface (rowOfButtons, _undelete_button);
514 w = ci->baseWidget();
516 XmNleftAttachment, XmATTACH_POSITION,
517 XmNleftPosition, 35, // centralized tUndelete and Close buttons
518 XmNbottomAttachment, XmATTACH_FORM,
523 _close_button = new CloseUndelCmd(
525 GETMSG(DT_catd, 1, 116, "Close"),
528 ci = new ButtonInterface (rowOfButtons, _close_button);
529 w = ci->baseWidget();
531 XmNleftAttachment, XmATTACH_WIDGET,
532 XmNleftWidget, prev_widget,
534 XmNbottomAttachment, XmATTACH_FORM,
541 UndelFromListDialog::expunge(void)
543 for (int pos = 0; pos < _list->get_num_messages(); pos++) {
544 _list->get_messages()->mark_for_delete(pos);
547 _list->get_messages()->compact(0);
549 XmListDeleteAllItems(_list->get_scrolling_list());