1 /* $TOG: DtFindD.C /main/5 1998/07/24 16:12:13 mgreess $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
4 * (c) Copyright 1993, 1994 International Business Machines Corp. *
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
6 * (c) Copyright 1993, 1994 Novell, Inc. *
12 #include "DtSetModList.h"
13 #include "DtWorkArea.h"
17 #include "Container.h"
19 #include "DtPrtJobIcon.h"
21 #include "dtprintinfomsg.h"
23 #include <unistd.h> // This is for the getuid function
25 DtJobList::DtJobList(AnyUI *parent)
26 : Container(parent, "found_container", SCROLLED_VERTICAL_ROW_COLUMN,
32 class _JobIcon : public IconObj
35 DtPrtJobIcon *job_icon;
39 _JobIcon(AnyUI *parent, DtPrtJobIcon *obj, IconFields);
42 _JobIcon::_JobIcon(AnyUI *parent, DtPrtJobIcon *obj, IconFields fields)
43 : IconObj(parent, (char *)obj->Name(), "DtPrtjb", NULL, NULL, NULL,
47 job_list = obj->Parent();
48 printer = job_list->Parent();
51 void DtJobList::NotifySelected(BaseUI *obj)
53 Container::NotifySelected(obj);
57 DtFindD *findD = (DtFindD *) Parent();
60 findD->cancel_jobs->Active(false);
61 findD->goto_job->Active(false);
66 findD->goto_job->Active(true);
68 findD->goto_job->Active(false);
69 findD->cancel_jobs->Active(true);
73 DtFindD::DtFindD(MotifUI *parent,
75 SelectProc select_proc)
76 : Dialog(parent, name)
78 _has_been_posted = false;
80 mainw = (DtMainW *) parent;
81 _select_proc = select_proc;
82 if (getuid() == 0) // check to see if we are root
83 prompt = new Prompt(this, MESSAGE(JobName1L));
85 prompt = new Prompt(this, MESSAGE(MyJobNameL));
86 prompt->AttachRight();
90 Container *rc = new Container(this, "rc", HORIZONTAL_ROW_COLUMN,
92 if (getuid() == 0) // check to see if we are root
93 match_any_user = new Button(rc, MESSAGE(OnlyRootJobsL), TOGGLE_BUTTON);
95 match_any_user = NULL;
96 ignore_case = new Button(rc, MESSAGE(IgnoreCaseL), TOGGLE_BUTTON);
97 ignore_case->Selected(true);
98 exact_match = new Button(rc, MESSAGE(ExactMatchL), TOGGLE_BUTTON);
100 rc->AttachTop(prompt, 5);
102 Sep *sep = new Sep(this);
106 sep->AttachTop(rc, 5);
108 field1 = new LabelObj(this, MESSAGE(JobName1L));
109 field1->AttachLeft(22);
110 field1->AttachTop(sep, 5);
111 field2 = new LabelObj(this, MESSAGE(PrinterL));
112 field2->AttachLeft(field1);
113 field2->AttachTop(sep, 5);
114 field3 = new LabelObj(this, MESSAGE(OwnerL));
115 field3->AttachLeft(field2);
116 field3->AttachTop(sep, 5);
117 field3->Visible(false);
118 field4 = new LabelObj(this, MESSAGE(PositionL));
119 field4->AttachLeft(field2);
120 field4->AttachRight();
121 field4->AttachTop(sep, 5);
123 Container *form = new Container(this, "form", FORM);
124 goto_job = new Button(form, MESSAGE(GotoL), PUSH_BUTTON, GotoCB, this);
125 goto_job->Active(false);
126 cancel_jobs = new Button(form, MESSAGE(CancelPrintJobsL), PUSH_BUTTON,
128 cancel_jobs->Active(false);
129 form->AttachBottom(5);
132 goto_job->AttachBottom();
133 goto_job->AttachTop();
134 cancel_jobs->AttachBottom();
135 cancel_jobs->AttachTop();
137 found_container = new DtJobList(this);
138 found_container->AttachRight();
139 found_container->AttachLeft();
140 found_container->AttachBottom(form, 10);
141 found_container->AttachTop(field1);
143 start = new Button(this, MESSAGE(StartFindL), PUSH_BUTTON, StartCB, this);
144 stop = new Button(this, MESSAGE(StopFindL), PUSH_BUTTON, StopCB, this);
145 close_it = new Button(this, MESSAGE(CloseL), PUSH_BUTTON, CancelCB, this);
147 help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
149 DefaultButton(start);
150 CancelButton(close_it);
158 boolean DtFindD::SetVisiblity(boolean flag)
160 if (_has_been_posted == false)
162 Dialog::SetVisiblity(flag);
164 int width = StringWidth(Name()) + 30;
169 _has_been_posted = true;
170 int w1 = cancel_jobs->Width();
171 int w2 = goto_job->Width();
172 int offset = (width - (w1 + w2)) / 3;
173 goto_job->AttachLeft(offset);
174 cancel_jobs->AttachRight(offset);
175 cancel_jobs->AttachLeft(NULL, 0);
177 found_container->DeleteChildren();
178 cancel_jobs->Active(false);
179 goto_job->Active(false);
182 match_any_user->Selected(false);
183 match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
185 Dialog::SetVisiblity(flag);
191 void DtFindD::UpdateMatchAnyUser()
194 match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
197 boolean DtFindD::MatchAnyUser()
201 if (match_any_user->Active() == false)
204 return (match_any_user->Selected() ? false : true);
210 void DtFindD::Start()
213 mainw->in_find = true;
214 mainw->WorkingCursor(true);
215 stop->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
216 help->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
219 close_it->Active(false);
220 start->Active(false);
221 prompt->Active(false);
222 ignore_case->Active(false);
223 exact_match->Active(false);
224 found_container->DeleteChildren();
225 cancel_jobs->Active(false);
226 goto_job->Active(false);
228 match_any_user->Active(false);
229 found_container->BeginUpdate();
232 if (mainw->container->NumChildren())
234 BaseUI *icon = mainw->container->Children()[0];
235 _prev_visible = icon->Visible();
236 _prev_opened = icon->Open();
238 AddTimeOut(CheckQueue, NULL, 200);
241 void DtFindD::Cancel()
249 if (_cur_obj > mainw->container->NumChildren())
251 _cur_obj = mainw->container->NumChildren() + 1;
252 found_container->EndUpdate();
254 DefaultButton(start);
256 close_it->Active(true);
257 prompt->Active(true);
258 ignore_case->Active(true);
259 exact_match->Active(true);
261 if (mainw->setModList && mainw->setModList->Visible())
262 mainw->setModList->Reset();
264 match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
270 char *value = prompt->Value();
271 if (!value || *value == '\0')
273 else if (*value == '*')
275 value1 = new char[strlen(value) + 2];
276 sprintf(value1, ".%s", value);
279 mainw->container->FindByName(value, 0, &n_matches, &matches,
281 exact_match->Selected() ? false : true,
282 ignore_case->Selected() ? false : true);
286 IconFields fields = new IconFieldsRec;
293 fields->n_fields = n_fields;
294 fields->field_spacing = 20;
295 fields->fields = new char *[n_fields];
296 fields->fields_widths = new int[n_fields];
297 fields->alignments = new LabelType[n_fields];
298 fields->draw_fields = NULL;
299 fields->selected = NULL;
300 fields->active = NULL;
302 fields->name_width = StringWidth(MESSAGE(JobName1L));
303 fields->fields_widths[0] = StringWidth(MESSAGE(PrinterL));
304 fields->alignments[0] = LEFT_JUSTIFIED;
307 fields->fields_widths[1] = StringWidth(MESSAGE(OwnerL));
308 fields->fields_widths[2] = StringWidth(MESSAGE(PositionL));
309 fields->alignments[1] = LEFT_JUSTIFIED;
310 fields->alignments[2] = RIGHT_JUSTIFIED;
311 if (field3->Visible() == false)
313 field3->Visible(true);
314 field4->AttachLeft(field3);
319 fields->alignments[1] = RIGHT_JUSTIFIED;
320 fields->fields_widths[1] = StringWidth(MESSAGE(PositionL));
321 if (field4->Visible())
323 field4->AttachLeft(field2);
324 field3->Visible(false);
327 for (i = 0; i < n_matches; i++)
329 DtPrtJobIcon *job = (DtPrtJobIcon *)matches[i];
330 if ((w = StringWidth(job->Name())) > fields->name_width)
331 fields->name_width = w;
332 w = StringWidth(job->Parent()->Parent()->Name());
333 if (w > fields->fields_widths[0])
334 fields->fields_widths[0] = w;
337 char *s = job->PrintJobObj()->AttributeValue((char *)OWNER);
338 if ((w = StringWidth(s)) > fields->fields_widths[1])
339 fields->fields_widths[1] = w;
342 if (fields->name_width % 2)
343 fields->name_width += 1;
345 if (fields->fields_widths[0] % 2)
346 fields->fields_widths[0] += 1;
350 if (fields->fields_widths[1] % 2)
351 fields->fields_widths[1] += 1;
352 if (fields->fields_widths[2] % 2)
353 fields->fields_widths[2] += 1;
357 if (fields->fields_widths[1] % 2)
358 fields->fields_widths[1] += 1;
361 field1->Width(fields->name_width + 20);
362 field2->Width(fields->fields_widths[0] + 20);
363 field3->Width(fields->fields_widths[1] + 20);
365 field4->Width(fields->fields_widths[2] + 20);
367 for (i = 0; i < n_matches; i++)
369 DtPrtJobIcon *job = (DtPrtJobIcon *)matches[i];
371 sprintf(number, "%d", job->Order() + 1);
372 fields->fields[0] = (char *)job->Parent()->Parent()->Name();
375 char *s = job->PrintJobObj()->AttributeValue((char *)OWNER);
376 fields->fields[1] = s;
377 fields->fields[2] = number;
380 fields->fields[1] = number;
381 _JobIcon *icon = new _JobIcon(found_container, job, fields);
384 delete fields->fields;
385 delete fields->fields_widths;
386 delete fields->alignments;
390 new LabelObj(found_container, MESSAGE(NoMatchesL));
392 mainw->WorkingCursor(false);
394 mainw->in_find = false;
397 void DtFindD::UpdateQueue()
399 if (_cur_obj < mainw->container->NumChildren())
401 BaseUI *icon = mainw->container->Children()[_cur_obj];
402 char *message = new char[200];
403 sprintf(message, MESSAGE(SearchL), icon->Name());
404 found_container->UpdateMessage(message);
407 DtPrinterIcon *icon1 = (DtPrinterIcon *)icon;
408 icon1->waitForChildren = true;
410 icon1->waitForChildren = false;
412 if (icon1->QueueObj()->NumChildren() == 0)
418 char *value = prompt->Value();
419 if (!value || *value == '\0')
421 else if (*value == '*')
423 value1 = new char[strlen(value) + 2];
424 sprintf(value1, ".%s", value);
427 icon1->FindByName(value, 0, &n_matches, NULL, _select_proc,
428 exact_match->Selected() ? false : true,
429 ignore_case->Selected() ? false : true);
438 if (_prev_visible == false)
439 icon->Visible(false);
440 if (_prev_opened == false)
444 if (_cur_obj < mainw->container->NumChildren())
446 icon = mainw->container->Children()[_cur_obj];
447 _prev_visible = icon->Visible();
448 _prev_opened = icon->Open();
450 AddTimeOut(CheckQueue, NULL, 200);
452 else if (_cur_obj == mainw->container->NumChildren())
456 boolean DtFindD::HandleHelpRequest()
458 mainw->DisplayHelp("FindDialogDE");
462 void DtFindD::CheckQueue(BaseUI *obj, void *)
464 ((DtFindD *)obj)->UpdateQueue();
467 BaseUI *DtFindD::FindJob(BaseUI *obj)
470 BaseUI *job = ((_JobIcon *)obj)->job_icon;
471 BaseUI **children = ((_JobIcon *)obj)->job_list->Children();
472 int n_children = ((_JobIcon *)obj)->job_list->NumChildren();
473 for (i = 0; i < n_children; i++)
474 if (job == children[i])
476 Dialog *dialog = new Dialog(mainw, (char *) Name(),
477 MESSAGE(NotFoundMessageL), INFORMATION,
479 dialog->Visible(true);
483 void DtFindD::GotoCB(void *data)
485 DtFindD *obj = (DtFindD *) data;
488 obj->found_container->Selection(&n_items, &selection);
491 BaseUI *print_job = obj->FindJob(selection[0]);
494 print_job->MakeVisible();
495 print_job->Selected(true);
501 void DtFindD::CancelJobsCB(void *data)
503 DtFindD *obj = (DtFindD *) data;
504 extern void ActionCB(void *data, BaseUI *obj, char *actionReferenceName);
508 obj->found_container->Selection(&n_items, &selection);
512 for (i = 0; i < n_items; i++)
514 BaseUI *print_job = obj->FindJob(selection[i]);
517 DtApp *app = (DtApp *)obj->mainw->Parent();
518 app->ActionCB(print_job, (char *)CANCEL_PRINT_JOB);
525 void DtFindD::CloseCB()
530 void DtFindD::CancelCB(void *data)
532 DtFindD *obj = (DtFindD *) data;
536 void DtFindD::StartCB(void *data)
538 DtFindD *obj = (DtFindD *) data;
542 void DtFindD::StopCB(void *data)
544 DtFindD *obj = (DtFindD *) data;
545 obj->_cur_obj = obj->mainw->container->NumChildren();
548 void DtFindD::HelpCB(void *data)
550 DtFindD *obj = (DtFindD *) data;
551 obj->HandleHelpRequest();
554 void DtFindD::DeleteJobFromList(BaseUI *obj)
557 int n_children = found_container->NumChildren();
558 _JobIcon **children = (_JobIcon **)found_container->Children();
559 for (i = 0; i < n_children; i++)
561 if (obj->Parent() == children[i]->job_list)
563 if (children[i]->job_icon == obj)
565 children[i]->Selected(false);
573 void DtFindD::UpdatePrinter(BaseUI *printer)
575 int n_children = found_container->NumChildren();
579 _JobIcon **children = (_JobIcon **)found_container->Children();
581 int width = StringWidth(MESSAGE(PrinterL));
582 BaseUI *last_printer = NULL;
583 for (i = 0; i < n_children; i++)
585 if (last_printer != children[i]->printer)
587 last_printer = children[i]->printer;
588 if ((w1 = StringWidth(last_printer->Name())) > width)
595 // Create a widget and resize it to the desired width, then resize the
596 // row column to the width + margin space. I have to do this because
597 // the row column widget does not resize itself correctly.
599 XtVaGetValues(found_container->InnerWidget(), XmNwidth, &wid, NULL);
600 wid -= field2->Width();
602 new LabelObj(found_container, " ");
603 children = (_JobIcon **)found_container->Children();
604 children[n_children]->Order(0);
606 children[0]->Width((int)wid);
608 XtVaSetValues(found_container->InnerWidget(), XmNwidth, (int)wid, NULL);
610 field2->Width(width + 20);
611 for (i = 1; i < n_children; i++)
613 if (printer == children[i]->printer)
614 children[i]->Field(0, (char *)printer->Name(), width);
616 children[i]->Field(0, NULL, width);
621 void DtFindD::UpdatePositions(BaseUI *printer)
626 int n_children = found_container->NumChildren();
630 _JobIcon **children = (_JobIcon **)found_container->Children();
631 int i, index = children[0]->NumberFields() - 1;
632 for (i = 0; i < n_children; i++)
634 if (printer == children[i]->printer)
635 children[i]->Field(index, children[i]->job_icon->TopString(), 0);