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
23 /* $TOG: DtFindD.C /main/5 1998/07/24 16:12:13 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
34 #include "DtSetModList.h"
35 #include "DtWorkArea.h"
39 #include "Container.h"
41 #include "DtPrtJobIcon.h"
43 #include "dtprintinfomsg.h"
45 #include <unistd.h> // This is for the getuid function
47 DtJobList::DtJobList(AnyUI *parent)
48 : Container(parent, "found_container", SCROLLED_VERTICAL_ROW_COLUMN,
54 class _JobIcon : public IconObj
57 DtPrtJobIcon *job_icon;
61 _JobIcon(AnyUI *parent, DtPrtJobIcon *obj, IconFields);
64 _JobIcon::_JobIcon(AnyUI *parent, DtPrtJobIcon *obj, IconFields fields)
65 : IconObj(parent, (char *)obj->Name(), "DtPrtjb", NULL, NULL, NULL,
69 job_list = obj->Parent();
70 printer = job_list->Parent();
73 void DtJobList::NotifySelected(BaseUI *obj)
75 Container::NotifySelected(obj);
79 DtFindD *findD = (DtFindD *) Parent();
82 findD->cancel_jobs->Active(false);
83 findD->goto_job->Active(false);
88 findD->goto_job->Active(true);
90 findD->goto_job->Active(false);
91 findD->cancel_jobs->Active(true);
95 DtFindD::DtFindD(MotifUI *parent,
97 SelectProc select_proc)
98 : Dialog(parent, name)
100 _has_been_posted = false;
102 mainw = (DtMainW *) parent;
103 _select_proc = select_proc;
104 if (getuid() == 0) // check to see if we are root
105 prompt = new Prompt(this, MESSAGE(JobName1L));
107 prompt = new Prompt(this, MESSAGE(MyJobNameL));
108 prompt->AttachRight();
109 prompt->AttachLeft();
112 Container *rc = new Container(this, "rc", HORIZONTAL_ROW_COLUMN,
114 if (getuid() == 0) // check to see if we are root
115 match_any_user = new Button(rc, MESSAGE(OnlyRootJobsL), TOGGLE_BUTTON);
117 match_any_user = NULL;
118 ignore_case = new Button(rc, MESSAGE(IgnoreCaseL), TOGGLE_BUTTON);
119 ignore_case->Selected(true);
120 exact_match = new Button(rc, MESSAGE(ExactMatchL), TOGGLE_BUTTON);
122 rc->AttachTop(prompt, 5);
124 Sep *sep = new Sep(this);
128 sep->AttachTop(rc, 5);
130 field1 = new LabelObj(this, MESSAGE(JobName1L));
131 field1->AttachLeft(22);
132 field1->AttachTop(sep, 5);
133 field2 = new LabelObj(this, MESSAGE(PrinterL));
134 field2->AttachLeft(field1);
135 field2->AttachTop(sep, 5);
136 field3 = new LabelObj(this, MESSAGE(OwnerL));
137 field3->AttachLeft(field2);
138 field3->AttachTop(sep, 5);
139 field3->Visible(false);
140 field4 = new LabelObj(this, MESSAGE(PositionL));
141 field4->AttachLeft(field2);
142 field4->AttachRight();
143 field4->AttachTop(sep, 5);
145 Container *form = new Container(this, "form", FORM);
146 goto_job = new Button(form, MESSAGE(GotoL), PUSH_BUTTON, GotoCB, this);
147 goto_job->Active(false);
148 cancel_jobs = new Button(form, MESSAGE(CancelPrintJobsL), PUSH_BUTTON,
150 cancel_jobs->Active(false);
151 form->AttachBottom(5);
154 goto_job->AttachBottom();
155 goto_job->AttachTop();
156 cancel_jobs->AttachBottom();
157 cancel_jobs->AttachTop();
159 found_container = new DtJobList(this);
160 found_container->AttachRight();
161 found_container->AttachLeft();
162 found_container->AttachBottom(form, 10);
163 found_container->AttachTop(field1);
165 start = new Button(this, MESSAGE(StartFindL), PUSH_BUTTON, StartCB, this);
166 stop = new Button(this, MESSAGE(StopFindL), PUSH_BUTTON, StopCB, this);
167 close_it = new Button(this, MESSAGE(CloseL), PUSH_BUTTON, CancelCB, this);
169 help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
171 DefaultButton(start);
172 CancelButton(close_it);
180 boolean DtFindD::SetVisiblity(boolean flag)
182 if (_has_been_posted == false)
184 Dialog::SetVisiblity(flag);
186 int width = StringWidth(Name()) + 30;
191 _has_been_posted = true;
192 int w1 = cancel_jobs->Width();
193 int w2 = goto_job->Width();
194 int offset = (width - (w1 + w2)) / 3;
195 goto_job->AttachLeft(offset);
196 cancel_jobs->AttachRight(offset);
197 cancel_jobs->AttachLeft(NULL, 0);
199 found_container->DeleteChildren();
200 cancel_jobs->Active(false);
201 goto_job->Active(false);
204 match_any_user->Selected(false);
205 match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
207 Dialog::SetVisiblity(flag);
213 void DtFindD::UpdateMatchAnyUser()
216 match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
219 boolean DtFindD::MatchAnyUser()
223 if (match_any_user->Active() == false)
226 return (match_any_user->Selected() ? false : true);
232 void DtFindD::Start()
235 mainw->in_find = true;
236 mainw->WorkingCursor(true);
237 stop->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
238 help->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
241 close_it->Active(false);
242 start->Active(false);
243 prompt->Active(false);
244 ignore_case->Active(false);
245 exact_match->Active(false);
246 found_container->DeleteChildren();
247 cancel_jobs->Active(false);
248 goto_job->Active(false);
250 match_any_user->Active(false);
251 found_container->BeginUpdate();
254 if (mainw->container->NumChildren())
256 BaseUI *icon = mainw->container->Children()[0];
257 _prev_visible = icon->Visible();
258 _prev_opened = icon->Open();
260 AddTimeOut(CheckQueue, NULL, 200);
263 void DtFindD::Cancel()
271 if (_cur_obj > mainw->container->NumChildren())
273 _cur_obj = mainw->container->NumChildren() + 1;
274 found_container->EndUpdate();
276 DefaultButton(start);
278 close_it->Active(true);
279 prompt->Active(true);
280 ignore_case->Active(true);
281 exact_match->Active(true);
283 if (mainw->setModList && mainw->setModList->Visible())
284 mainw->setModList->Reset();
286 match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
292 char *value = prompt->Value();
293 if (!value || *value == '\0')
295 else if (*value == '*')
297 value1 = new char[strlen(value) + 2];
298 sprintf(value1, ".%s", value);
301 mainw->container->FindByName(value, 0, &n_matches, &matches,
303 exact_match->Selected() ? false : true,
304 ignore_case->Selected() ? false : true);
308 IconFields fields = new IconFieldsRec;
315 fields->n_fields = n_fields;
316 fields->field_spacing = 20;
317 fields->fields = new char *[n_fields];
318 fields->fields_widths = new int[n_fields];
319 fields->alignments = new LabelType[n_fields];
320 fields->draw_fields = NULL;
321 fields->selected = NULL;
322 fields->active = NULL;
324 fields->name_width = StringWidth(MESSAGE(JobName1L));
325 fields->fields_widths[0] = StringWidth(MESSAGE(PrinterL));
326 fields->alignments[0] = LEFT_JUSTIFIED;
329 fields->fields_widths[1] = StringWidth(MESSAGE(OwnerL));
330 fields->fields_widths[2] = StringWidth(MESSAGE(PositionL));
331 fields->alignments[1] = LEFT_JUSTIFIED;
332 fields->alignments[2] = RIGHT_JUSTIFIED;
333 if (field3->Visible() == false)
335 field3->Visible(true);
336 field4->AttachLeft(field3);
341 fields->alignments[1] = RIGHT_JUSTIFIED;
342 fields->fields_widths[1] = StringWidth(MESSAGE(PositionL));
343 if (field4->Visible())
345 field4->AttachLeft(field2);
346 field3->Visible(false);
349 for (i = 0; i < n_matches; i++)
351 DtPrtJobIcon *job = (DtPrtJobIcon *)matches[i];
352 if ((w = StringWidth(job->Name())) > fields->name_width)
353 fields->name_width = w;
354 w = StringWidth(job->Parent()->Parent()->Name());
355 if (w > fields->fields_widths[0])
356 fields->fields_widths[0] = w;
359 char *s = job->PrintJobObj()->AttributeValue((char *)OWNER);
360 if ((w = StringWidth(s)) > fields->fields_widths[1])
361 fields->fields_widths[1] = w;
364 if (fields->name_width % 2)
365 fields->name_width += 1;
367 if (fields->fields_widths[0] % 2)
368 fields->fields_widths[0] += 1;
372 if (fields->fields_widths[1] % 2)
373 fields->fields_widths[1] += 1;
374 if (fields->fields_widths[2] % 2)
375 fields->fields_widths[2] += 1;
379 if (fields->fields_widths[1] % 2)
380 fields->fields_widths[1] += 1;
383 field1->Width(fields->name_width + 20);
384 field2->Width(fields->fields_widths[0] + 20);
385 field3->Width(fields->fields_widths[1] + 20);
387 field4->Width(fields->fields_widths[2] + 20);
389 for (i = 0; i < n_matches; i++)
391 DtPrtJobIcon *job = (DtPrtJobIcon *)matches[i];
393 sprintf(number, "%d", job->Order() + 1);
394 fields->fields[0] = (char *)job->Parent()->Parent()->Name();
397 char *s = job->PrintJobObj()->AttributeValue((char *)OWNER);
398 fields->fields[1] = s;
399 fields->fields[2] = number;
402 fields->fields[1] = number;
403 _JobIcon *icon = new _JobIcon(found_container, job, fields);
406 delete fields->fields;
407 delete fields->fields_widths;
408 delete fields->alignments;
412 new LabelObj(found_container, MESSAGE(NoMatchesL));
414 mainw->WorkingCursor(false);
416 mainw->in_find = false;
419 void DtFindD::UpdateQueue()
421 if (_cur_obj < mainw->container->NumChildren())
423 BaseUI *icon = mainw->container->Children()[_cur_obj];
424 char *message = new char[200];
425 sprintf(message, MESSAGE(SearchL), icon->Name());
426 found_container->UpdateMessage(message);
429 DtPrinterIcon *icon1 = (DtPrinterIcon *)icon;
430 icon1->waitForChildren = true;
432 icon1->waitForChildren = false;
434 if (icon1->QueueObj()->NumChildren() == 0)
440 char *value = prompt->Value();
441 if (!value || *value == '\0')
443 else if (*value == '*')
445 value1 = new char[strlen(value) + 2];
446 sprintf(value1, ".%s", value);
449 icon1->FindByName(value, 0, &n_matches, NULL, _select_proc,
450 exact_match->Selected() ? false : true,
451 ignore_case->Selected() ? false : true);
460 if (_prev_visible == false)
461 icon->Visible(false);
462 if (_prev_opened == false)
466 if (_cur_obj < mainw->container->NumChildren())
468 icon = mainw->container->Children()[_cur_obj];
469 _prev_visible = icon->Visible();
470 _prev_opened = icon->Open();
472 AddTimeOut(CheckQueue, NULL, 200);
474 else if (_cur_obj == mainw->container->NumChildren())
478 boolean DtFindD::HandleHelpRequest()
480 mainw->DisplayHelp("FindDialogDE");
484 void DtFindD::CheckQueue(BaseUI *obj, void *)
486 ((DtFindD *)obj)->UpdateQueue();
489 BaseUI *DtFindD::FindJob(BaseUI *obj)
492 BaseUI *job = ((_JobIcon *)obj)->job_icon;
493 BaseUI **children = ((_JobIcon *)obj)->job_list->Children();
494 int n_children = ((_JobIcon *)obj)->job_list->NumChildren();
495 for (i = 0; i < n_children; i++)
496 if (job == children[i])
498 Dialog *dialog = new Dialog(mainw, (char *) Name(),
499 MESSAGE(NotFoundMessageL), INFORMATION,
501 dialog->Visible(true);
505 void DtFindD::GotoCB(void *data)
507 DtFindD *obj = (DtFindD *) data;
510 obj->found_container->Selection(&n_items, &selection);
513 BaseUI *print_job = obj->FindJob(selection[0]);
516 print_job->MakeVisible();
517 print_job->Selected(true);
523 void DtFindD::CancelJobsCB(void *data)
525 DtFindD *obj = (DtFindD *) data;
526 extern void ActionCB(void *data, BaseUI *obj, char *actionReferenceName);
530 obj->found_container->Selection(&n_items, &selection);
534 for (i = 0; i < n_items; i++)
536 BaseUI *print_job = obj->FindJob(selection[i]);
539 DtApp *app = (DtApp *)obj->mainw->Parent();
540 app->ActionCB(print_job, (char *)CANCEL_PRINT_JOB);
547 void DtFindD::CloseCB()
552 void DtFindD::CancelCB(void *data)
554 DtFindD *obj = (DtFindD *) data;
558 void DtFindD::StartCB(void *data)
560 DtFindD *obj = (DtFindD *) data;
564 void DtFindD::StopCB(void *data)
566 DtFindD *obj = (DtFindD *) data;
567 obj->_cur_obj = obj->mainw->container->NumChildren();
570 void DtFindD::HelpCB(void *data)
572 DtFindD *obj = (DtFindD *) data;
573 obj->HandleHelpRequest();
576 void DtFindD::DeleteJobFromList(BaseUI *obj)
579 int n_children = found_container->NumChildren();
580 _JobIcon **children = (_JobIcon **)found_container->Children();
581 for (i = 0; i < n_children; i++)
583 if (obj->Parent() == children[i]->job_list)
585 if (children[i]->job_icon == obj)
587 children[i]->Selected(false);
595 void DtFindD::UpdatePrinter(BaseUI *printer)
597 int n_children = found_container->NumChildren();
601 _JobIcon **children = (_JobIcon **)found_container->Children();
603 int width = StringWidth(MESSAGE(PrinterL));
604 BaseUI *last_printer = NULL;
605 for (i = 0; i < n_children; i++)
607 if (last_printer != children[i]->printer)
609 last_printer = children[i]->printer;
610 if ((w1 = StringWidth(last_printer->Name())) > width)
617 // Create a widget and resize it to the desired width, then resize the
618 // row column to the width + margin space. I have to do this because
619 // the row column widget does not resize itself correctly.
621 XtVaGetValues(found_container->InnerWidget(), XmNwidth, &wid, NULL);
622 wid -= field2->Width();
624 new LabelObj(found_container, " ");
625 children = (_JobIcon **)found_container->Children();
626 children[n_children]->Order(0);
628 children[0]->Width((int)wid);
630 XtVaSetValues(found_container->InnerWidget(), XmNwidth, (int)wid, NULL);
632 field2->Width(width + 20);
633 for (i = 1; i < n_children; i++)
635 if (printer == children[i]->printer)
636 children[i]->Field(0, (char *)printer->Name(), width);
638 children[i]->Field(0, NULL, width);
643 void DtFindD::UpdatePositions(BaseUI *printer)
648 int n_children = found_container->NumChildren();
652 _JobIcon **children = (_JobIcon **)found_container->Children();
653 int i, index = children[0]->NumberFields() - 1;
654 for (i = 0; i < n_children; i++)
656 if (printer == children[i]->printer)
657 children[i]->Field(index, children[i]->job_icon->TopString(), 0);