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);
241 UndelFromListDialog::~UndelFromListDialog()
246 UndelFromListDialog::popped_down()
248 XtUnmapWidget(this->baseWidget());
252 UndelFromListDialog::popped_up()
255 XtMapWidget(this->baseWidget());
259 UndelFromListDialog::initialize()
261 DialogShell::initialize();
265 UndelFromListDialog::quit()
267 // Pop down the dialog
272 UndelFromListDialog::createWorkArea ( Widget parent )
276 Widget l1, l2, l3, l4;
278 XtWidgetGeometry size;
280 form1 = XmCreateForm(parent, "Work_Area", NULL, 0);
283 printHelpId("form1", form1);
285 rowOfLabels = XtCreateManagedWidget ("rowOfLabels",
291 printHelpId("rowOfLabels", rowOfLabels);
294 size.request_mode = CWHeight;
295 XtQueryGeometry(rowOfLabels, NULL, &size);
296 XtVaSetValues(rowOfLabels,
297 XmNpaneMaximum, size.height,
298 XmNpaneMinimum, size.height,
299 XmNrightAttachment, XmATTACH_FORM,
300 XmNleftAttachment, XmATTACH_FORM,
301 XmNtopAttachment, XmATTACH_FORM,
303 XmNorientation, XmHORIZONTAL,
306 XmNentryAlignment, XmALIGNMENT_CENTER,
309 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 14,
312 l1 = XtVaCreateManagedWidget("Label1", xmLabelGadgetClass,
314 XmNlabelString, labelStr,
317 XmStringFree(labelStr);
318 printHelpId("l1", l1);
319 /* add help callback */
320 // XtAddCallback(l1, XmNhelpCallback, HelpCB, helpId);
323 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 15,
325 l2 = XtVaCreateManagedWidget("Label2",
326 xmLabelGadgetClass, rowOfLabels,
327 XmNlabelString, labelStr,
332 XmStringFree(labelStr);
333 printHelpId("l2", l2);
334 /* add help callback */
335 // XtAddCallback(l2, XmNhelpCallback, HelpCB, helpId);
337 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 16,
339 l3 = XtVaCreateManagedWidget("Label3",
340 xmLabelGadgetClass, rowOfLabels,
341 XmNlabelString, labelStr,
344 XmStringFree(labelStr);
345 printHelpId("l3", l3);
346 /* add help callback */
347 // XtAddCallback(l3, XmNhelpCallback, HelpCB, helpId);
349 labelStr = XmStringCreateLocalized(GETMSG(DT_catd, 1, 17,
351 l4 = XtVaCreateManagedWidget("Label4",
352 xmLabelGadgetClass, rowOfLabels,
353 XmNlabelString, labelStr,
356 XmStringFree(labelStr);
357 printHelpId("l4", l4);
358 /* add help callback */
360 _list = new UndelMsgScrollingList( this->parent(), form1, "Message_List");
363 DtMail::Session * d_session = theRoamApp.session()->session();
364 DtMail::MailRc * mailrc = d_session->mailRc(error);
368 mailrc->getValue(error, "showmsgnum", &value);
369 if (error.isNotSet()) {
375 // Adjust labels so the align on the columns
376 _list->layoutLabels(l1, l2, l3, l4);
379 rowOfButtons = XtCreateManagedWidget("RowColumn",
384 printHelpId ("rowOfButtons", rowOfButtons);
386 XtVaSetValues(XtParent(_list->get_scrolling_list()),
387 XmNrightAttachment, XmATTACH_FORM,
388 XmNleftAttachment, XmATTACH_FORM,
389 XmNtopAttachment, XmATTACH_WIDGET,
390 XmNtopWidget, rowOfLabels,
392 XmNbottomAttachment, XmATTACH_WIDGET,
393 XmNbottomWidget, rowOfButtons,
397 XtVaSetValues(rowOfButtons,
398 XmNorientation, XmHORIZONTAL,
399 XmNpaneMaximum, size.height,
400 XmNpaneMinimum, size.height,
401 XmNrightAttachment, XmATTACH_FORM,
402 XmNleftAttachment, XmATTACH_FORM,
403 XmNbottomAttachment, XmATTACH_FORM,
404 XmNfractionBase, 100,
408 // Create undelete and close buttons.
409 this->addToRowOfButtons();
413 // Label should go here that says in how many days
414 // deleted messages will be destroyed, and for status.
415 rowOfMessageStatus = XtCreateManagedWidget("Message_Status",
418 XtVaSetValues(rowOfMessageStatus,
419 XmNrightAttachment, XmATTACH_FORM,
420 XmNleftAttachment, XmATTACH_FORM,
421 XmNtopAttachment, XmATTACH_FORM,
426 XtManageChild(_list->baseWidget());
427 XtManageChild(form1);
434 UndelFromListDialog::insertMsg(DtMailEnv &mail_error, MsgStruct *tmpMS)
436 _list->insertMsg(mail_error, tmpMS);
440 UndelFromListDialog::undelLast()
444 len = _list->get_messages()->length();
445 _list->get_messages()->mark_for_delete(len - 1);
446 _list->get_messages()->compact(0);
447 XmListDeletePos(_list->get_scrolling_list(), len);
453 UndelFromListDialog::undelSelected()
455 FORCE_SEGV_DECL(int, position_list);
456 FORCE_SEGV_DECL(MsgHndArray, tmpMHlist);
458 Boolean any_selected = FALSE;
460 any_selected = XmListGetSelectedPos(_list->get_scrolling_list(),
464 // Don't do anything if there aren't any messages selected.
466 if ((!any_selected) || (position_count <= 0)) return;
469 // Put the selected messages from the Deleted Messages List
470 // into the RoamMenuWindow Message Scrolling List.
473 // This is kind of tricky, because we have to get the list of
474 // selected messages before we delete the selected messages,
475 // but we have to delete the selected messages before we
476 // pass them to undelete_messages(). The reason for this
477 // is that deleteSelected() changes the is_deleted attribute
478 // of the message handle to TRUE, which will undo undelete_messages()
479 // setting is_deleted to FALSE! Did you follow all that?
481 tmpMHlist = _list->selected();
483 // Remove the selected messages from the Deleted Messages Dialog.
484 _list->deleteSelected();
486 // Add the messages to the RoamMenuWindow scrolling list.
487 MsgScrollingList *msl = parent()->list();
488 msl->undelete_messages(tmpMHlist);
490 XtFree((char*) position_list);
495 UndelFromListDialog::addToRowOfButtons()
497 FORCE_SEGV_DECL(CmdInterface, ci);
498 Widget w, prev_widget;
500 _undelete_button = new DoUndeleteCmd(
502 GETMSG(DT_catd, 1, 115, "Undelete"),
505 ci = new ButtonInterface (rowOfButtons, _undelete_button);
507 w = ci->baseWidget();
509 XmNleftAttachment, XmATTACH_POSITION,
510 XmNleftPosition, 35, // centralized tUndelete and Close buttons
511 XmNbottomAttachment, XmATTACH_FORM,
516 _close_button = new CloseUndelCmd(
518 GETMSG(DT_catd, 1, 116, "Close"),
521 ci = new ButtonInterface (rowOfButtons, _close_button);
522 w = ci->baseWidget();
524 XmNleftAttachment, XmATTACH_WIDGET,
525 XmNleftWidget, prev_widget,
527 XmNbottomAttachment, XmATTACH_FORM,
534 UndelFromListDialog::expunge(void)
536 for (int pos = 0; pos < _list->get_num_messages(); pos++) {
537 _list->get_messages()->mark_for_delete(pos);
540 _list->get_messages()->compact(0);
542 XmListDeleteAllItems(_list->get_scrolling_list());