1 /* medview.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: medview.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 4/30/95
31 *
32 * $Revision: 6.13 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44
45 #include <medview.h>
46 #include <document.h>
47 #include <tomedlin.h>
48 #include <objmgr.h>
49 #include <accentr.h>
50 #include <prtutil.h>
51 #ifdef WIN_MOTIF
52 #include <netscape.h>
53 #endif
54
55 #define NUM_PAGES 6
56
57 typedef struct medlineviewform {
58 FORM_MESSAGE_BLOCK
59
60 Int2 currentPage;
61
62 DoC doc;
63 TexT text;
64 GrouP controls;
65 Boolean useScrollText;
66
67 MedlineEntryPtr mep;
68
69 Boolean cleanupObjectPtr;
70 WndActnProc activateForm;
71
72 FonT jourfnt;
73 FonT volfnt;
74 FonT pagesfnt;
75 FonT titlefnt;
76 FonT authorsfnt;
77 FonT affilfnt;
78 FonT abstractfnt;
79 FonT meshfnt;
80 FonT displayFont;
81 } MedlineViewForm, PNTR MedlineViewFormPtr;
82
83 static ParData medParFmt = {FALSE, FALSE, FALSE, FALSE, TRUE, 0, 0};
84 static ColData medColFmt = {0, 0, 80, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE};
85
86 #define BUFSIZE 8192
87
88 static CharPtr buffer;
89 static CharPtr pos;
90
ClearString(void)91 static void ClearString (void)
92
93 {
94 pos = buffer;
95 *pos = '\0';
96 }
97
AddString(CharPtr string)98 static void AddString (CharPtr string)
99
100 {
101 pos = StringMove (pos, string);
102 *pos = '\0';
103 }
104
105 static ColData colFmt [3] = {
106 {0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
107 {0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, FALSE},
108 {0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE}
109 };
110
111 static ColData mshFmt [1] = {
112 {0, 0, 0, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE}
113 };
114
DisplayArticle(DoC d,MedlineEntryPtr mep,Boolean showMesh)115 static Boolean DisplayArticle (DoC d, MedlineEntryPtr mep, Boolean showMesh)
116
117 {
118 size_t len;
119 MedlineViewFormPtr mfp;
120 MedlinePtr mPtr;
121 ParData para;
122 CharPtr ptr;
123 RecT r;
124 CharPtr tmp;
125
126 mfp = (MedlineViewFormPtr) GetObjectExtra (d);
127 if (mfp != NULL) {
128 mPtr = ParseMedline (mep);
129 if (mPtr != NULL) {
130 buffer = (CharPtr) MemNew (BUFSIZE);
131 if (buffer != NULL) {
132 para.openSpace = FALSE;
133 para.keepWithNext = FALSE;
134 para.keepTogether = FALSE;
135 para.newPage = FALSE;
136 para.tabStops = FALSE;
137 para.minLines = 0;
138 para.minHeight = 0;
139 colFmt [0].font = mfp->jourfnt;
140 colFmt [1].font = mfp->volfnt;
141 colFmt [2].font = mfp->pagesfnt;
142 ObjectRect (d, &r);
143 InsetRect (&r, 4, 4);
144 mshFmt [0].pixWidth = r.right - r.left;
145 mshFmt [0].charWidth = 80;
146 ClearString ();
147 AddString (mPtr->journal);
148 AddString ("\t");
149 AddString (mPtr->volume);
150 AddString (":\t");
151 AddString (mPtr->pages);
152 AddString (" (");
153 AddString (mPtr->year);
154 AddString (")");
155 AddString (" [");
156 AddString (mPtr->uid);
157 AddString ("]");
158 AddString ("\n");
159 AppendText (d, buffer, ¶, colFmt, NULL);
160 ClearString ();
161 if (mPtr->title != NULL) {
162 AddString (mPtr->title);
163 AddString ("\n");
164 AppendText (d, buffer, NULL, NULL, mfp->titlefnt);
165 ClearString ();
166 }
167 if (mPtr->transl != NULL) {
168 AddString ("[");
169 AddString (mPtr->transl);
170 AddString ("]\n");
171 AppendText (d, buffer, NULL, NULL, mfp->titlefnt);
172 ClearString ();
173 }
174 if (mPtr->title == NULL && mPtr->transl == NULL) {
175 }
176 AddString (mPtr->authors);
177 AddString ("\n");
178 AppendText (d, buffer, NULL, NULL, mfp->authorsfnt);
179 ClearString ();
180 if (mPtr->affil != NULL) {
181 AddString (mPtr->affil);
182 AddString ("\n");
183 AppendText (d, buffer, NULL, NULL, mfp->affilfnt);
184 ClearString ();
185 }
186 if (mPtr->abstract != NULL) {
187 len = StringLen (mPtr->abstract);
188 tmp = (CharPtr) MemNew (sizeof (Char) * (len + 10));
189 ptr = StringMove (tmp, mPtr->abstract);
190 ptr = StringMove (ptr, "\n");
191 AppendText (d, tmp, NULL, NULL, mfp->abstractfnt);
192 MemFree (tmp);
193 }
194 if (showMesh) {
195 if (mPtr->mesh != NULL) {
196 AppendText (d, "MeSH Terms:\n", NULL, NULL, mfp->meshfnt);
197 AppendText (d, mPtr->mesh, ¶, mshFmt, mfp->meshfnt);
198 }
199 if (mPtr->gene != NULL) {
200 AppendText (d, "Gene Symbols:\n", NULL, NULL, mfp->meshfnt);
201 AppendText (d, mPtr->gene, ¶, mshFmt, mfp->meshfnt);
202 }
203 if (mPtr->substance != NULL) {
204 AppendText (d, "Substances:\n", NULL, NULL, mfp->meshfnt);
205 AppendText (d, mPtr->substance, ¶, mshFmt, mfp->meshfnt);
206 }
207 }
208 buffer = (CharPtr) MemFree (buffer);
209 }
210 mPtr = FreeMedline (mPtr);
211 }
212 }
213 return TRUE;
214 }
215
MedlineEntryPtrToMedlineForm(ForM f,Pointer data)216 static void MedlineEntryPtrToMedlineForm (ForM f, Pointer data)
217
218 {
219 AsnIoPtr aipout;
220 FonT fnt;
221 FILE *fp;
222 MedlineEntryPtr mep;
223 MedlineViewFormPtr mfp;
224 Char path [PATH_MAX];
225 RecT r;
226
227 mfp = (MedlineViewFormPtr) GetObjectExtra (f);
228 mep = (MedlineEntryPtr) data;
229 if (mfp != NULL && mep != NULL) {
230 if (mfp->useScrollText) {
231 ObjectRect (mfp->text, &r);
232 } else {
233 ObjectRect (mfp->doc, &r);
234 }
235 InsetRect (&r, 4, 4);
236 medColFmt.pixWidth = screenRect.right - screenRect.left;
237 medColFmt.pixInset = 8;
238 WatchCursor ();
239 if (mfp->useScrollText) {
240 Reset (mfp->text);
241 } else {
242 Reset (mfp->doc);
243 }
244 Update ();
245 SetDocAutoAdjust (mfp->doc, FALSE);
246 switch (mfp->currentPage) {
247 case ABSTRACT_PAGE :
248 if (mfp->useScrollText) {
249 TmpNam (path);
250 fp = FileOpen (path, "w");
251 if (fp != NULL) {
252 if (MedlineEntryToAbsFile (mep, fp)) {
253 FileClose (fp);
254 if (! FileToScrollText (mfp->text, path)) {
255 SetTitle (mfp->text, "(Text is too large to be displayed in this control.)");
256 }
257 } else {
258 FileClose (fp);
259 }
260 }
261 FileRemove (path);
262 } else {
263 DisplayArticle (mfp->doc, mep, FALSE);
264 }
265 break;
266 case CITATION_PAGE :
267 if (mfp->useScrollText) {
268 TmpNam (path);
269 fp = FileOpen (path, "w");
270 if (fp != NULL) {
271 if (MedlineEntryToDocFile (mep, fp)) {
272 FileClose (fp);
273 if (! FileToScrollText (mfp->text, path)) {
274 SetTitle (mfp->text, "(Text is too large to be displayed in this control.)");
275 }
276 } else {
277 FileClose (fp);
278 }
279 }
280 FileRemove (path);
281 } else {
282 DisplayArticle (mfp->doc, mep, TRUE);
283 }
284 break;
285 case MEDLINE_PAGE :
286 TmpNam (path);
287 fp = FileOpen (path, "w");
288 if (fp != NULL) {
289 fnt = programFont;
290 if (mfp->displayFont != NULL) {
291 fnt = mfp->displayFont;
292 }
293 if (MedlineEntryToDataFile (mep, fp)) {
294 FileClose (fp);
295 if (mfp->useScrollText) {
296 if (! FileToScrollText (mfp->text, path)) {
297 SetTitle (mfp->text, "(Text is too large to be displayed in this control.)");
298 }
299 } else {
300 DisplayFancy (mfp->doc, path, &medParFmt, &medColFmt, fnt, 4);
301 }
302 } else {
303 FileClose (fp);
304 }
305 }
306 FileRemove (path);
307 break;
308 case MEDASN1_PAGE :
309 TmpNam (path);
310 fp = FileOpen (path, "w");
311 if (fp != NULL) {
312 fnt = programFont;
313 if (mfp->displayFont != NULL) {
314 fnt = mfp->displayFont;
315 }
316 aipout = AsnIoNew (ASNIO_TEXT_OUT, fp, NULL, NULL, NULL);
317 if (MedlineEntryAsnWrite (mep, aipout, NULL)) {
318 AsnIoClose (aipout);
319 if (mfp->useScrollText) {
320 if (! FileToScrollText (mfp->text, path)) {
321 SetTitle (mfp->text, "(Text is too large to be displayed in this control.)");
322 }
323 } else {
324 DisplayFancy (mfp->doc, path, &medParFmt, &medColFmt, fnt, 4);
325 }
326 } else {
327 AsnIoClose (aipout);
328 }
329 }
330 FileRemove (path);
331 break;
332 case MEDXML_PAGE :
333 TmpNam (path);
334 aipout = AsnIoOpen (path, "wx");
335 if (aipout != NULL) {
336 fnt = programFont;
337 if (mfp->displayFont != NULL) {
338 fnt = mfp->displayFont;
339 }
340 if (MedlineEntryAsnWrite (mep, aipout, NULL)) {
341 AsnIoClose (aipout);
342 if (mfp->useScrollText) {
343 if (! FileToScrollText (mfp->text, path)) {
344 SetTitle (mfp->text, "(Text is too large to be displayed in this control.)");
345 }
346 } else {
347 DisplayFancy (mfp->doc, path, &medParFmt, &medColFmt, fnt, 4);
348 }
349 } else {
350 AsnIoClose (aipout);
351 }
352 }
353 FileRemove (path);
354 break;
355 default :
356 break;
357 }
358 if (! mfp->useScrollText) {
359 SetDocAutoAdjust (mfp->doc, TRUE);
360 AdjustDocScroll (mfp->doc);
361 UpdateDocument (mfp->doc, 0, 0);
362 }
363 ArrowCursor ();
364 Update ();
365 }
366 }
367
ResizeMedlineForm(WindoW w)368 static void ResizeMedlineForm (WindoW w)
369
370 {
371 RecT c;
372 Int2 diff = 0;
373 Int2 gap = 0;
374 Int2 height;
375 MedlineViewFormPtr mfp;
376 RecT r;
377 RecT s;
378 RecT t;
379 Int2 width;
380
381 mfp = (MedlineViewFormPtr) GetObjectExtra (w);
382 if (mfp == NULL) return;
383 WatchCursor ();
384 ObjectRect (w, &r);
385 width = r.right - r.left;
386 height = r.bottom - r.top;
387 SafeHide (mfp->controls);
388 if (mfp->controls != NULL) {
389 GetPosition (mfp->controls, &c);
390 }
391 if (mfp->doc != NULL) {
392 GetPosition (mfp->doc, &s);
393 if (mfp->controls != NULL) {
394 LoadRect (&t, c.left, c.top, c.right, c.bottom);
395 diff = t.bottom - t.top;
396 gap = t.top - s.bottom;
397 t.bottom = height - s.left;
398 t.top = t.bottom - diff;
399 s.right = width - s.left;
400 /*
401 s.bottom = height - s.left;
402 */
403 s.bottom = t.top - gap;
404 SetPosition (mfp->controls, &t);
405 AdjustPrnt (mfp->controls, &t, FALSE);
406 } else {
407 s.right = width - s.left;
408 s.bottom = height - s.left;
409 }
410 SetPosition (mfp->doc, &s);
411 AdjustPrnt (mfp->doc, &s, FALSE);
412 }
413 if (mfp->text != NULL) {
414 GetPosition (mfp->text, &s);
415 if (mfp->controls != NULL) {
416 LoadRect (&t, c.left, c.top, c.right, c.bottom);
417 diff = t.bottom - t.top;
418 gap = t.top - s.bottom;
419 t.bottom = height - s.left;
420 t.top = t.bottom - diff;
421 s.right = width - s.left;
422 /*
423 s.bottom = height - s.left;
424 */
425 s.bottom = t.top - gap;
426 SetPosition (mfp->controls, &t);
427 AdjustPrnt (mfp->controls, &t, FALSE);
428 } else {
429 s.right = width - s.left;
430 s.bottom = height - s.left;
431 }
432 SetPosition (mfp->text, &s);
433 AdjustPrnt (mfp->text, &s, FALSE);
434 }
435 if (mfp->doc != NULL) {
436 ObjectRect (mfp->doc, &s);
437 InsetRect (&s, 4, 4);
438 medColFmt.pixWidth = screenRect.right - screenRect.left;
439 medColFmt.pixInset = 8;
440 if (Visible (mfp->doc) && AllParentsVisible (mfp->doc)) {
441 UpdateDocument (mfp->doc, 0, 0);
442 }
443 }
444 SafeShow (mfp->controls);
445 ArrowCursor ();
446 Update ();
447 }
448
CopyMedlineViewFormToClipboard(Pointer formDataPtr)449 extern void LIBCALL CopyMedlineViewFormToClipboard (Pointer formDataPtr)
450
451 {
452 FILE *fp;
453 MedlineViewFormPtr mfp;
454 Char path [PATH_MAX];
455
456 mfp = (MedlineViewFormPtr) formDataPtr;
457 if (mfp != NULL && mfp->mep != NULL) {
458 if (mfp->useScrollText) {
459 if (mfp->text != NULL) {
460 CopyText (mfp->text);
461 }
462 } else {
463 TmpNam (path);
464 fp = FileOpen (path, "w");
465 if (fp != NULL) {
466 SaveDocument (mfp->doc, fp);
467 FileClose (fp);
468 FileToClipboard (path);
469 }
470 FileRemove (path);
471 }
472 }
473 }
474
ExportMedlineViewFormToFile(Pointer formDataPtr,CharPtr filename)475 extern void LIBCALL ExportMedlineViewFormToFile (Pointer formDataPtr, CharPtr filename)
476
477 {
478 Char ch;
479 Char dfault [32];
480 FILE *f;
481 Int2 j;
482 Int2 k;
483 MedlineViewFormPtr mfp;
484 Char path [PATH_MAX];
485
486 mfp = (MedlineViewFormPtr) formDataPtr;
487 if (mfp != NULL && mfp->mep != NULL) {
488 if (mfp->doc != NULL || mfp->text != NULL) {
489 dfault [0] = '\0';
490 GetTitle (mfp->form, dfault, sizeof (dfault));
491 j = 0;
492 k = 0;
493 ch = dfault [j];
494 while (j < sizeof (dfault) && ch != '\0') {
495 if (ch <= ' ') {
496 j++;
497 } else {
498 dfault [k] = dfault [j];
499 k++;
500 j++;
501 }
502 ch = dfault [j];
503 }
504 dfault [k] = '\0';
505 #ifdef WIN_MSWIN
506 j = 0;
507 ch = dfault [j];
508 while (j < sizeof (dfault) && ch != '\0') {
509 if (ch == '_' || IS_ALPHANUM (ch)) {
510 j++;
511 ch = dfault [j];
512 } else {
513 ch = '\0';
514 }
515 }
516 dfault [j] = '\0';
517 #endif
518 path [0] = '\0';
519 StringNCpy_0 (path, filename, sizeof (path));
520 if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), dfault)) {
521 WatchCursor ();
522 #ifdef WIN_MAC
523 f = FileOpen (path, "r");
524 if (f != NULL) {
525 FileClose (f);
526 } else {
527 FileCreate (path, "TEXT", "ttxt");
528 }
529 #endif
530 if (filename == NULL || filename [0] == '\0') {
531 f = FileOpen (path, "w");
532 } else {
533 f = FileOpen (path, "a");
534 }
535 if (f != NULL) {
536 if (mfp->useScrollText) {
537 ScrollTextToFile (mfp->text, path);
538 } else {
539 SaveDocument (mfp->doc, f);
540 }
541 FileClose (f);
542 }
543 ArrowCursor ();
544 }
545 }
546 }
547 }
548
549 #ifdef WIN_MOTIF
550 extern CharPtr Nlm_XrmGetResource (const Char PNTR _resource);
551 #endif
552
PrintMedlineViewForm(Pointer formDataPtr)553 extern void LIBCALL PrintMedlineViewForm (Pointer formDataPtr)
554
555 {
556 MedlineViewFormPtr mfp;
557 #ifdef WIN_MOTIF
558 Char cmmd [256];
559 Int2 len;
560 CharPtr printCmd;
561 Char str [PATH_MAX];
562 #endif
563
564 mfp = (MedlineViewFormPtr) formDataPtr;
565 if (mfp != NULL && mfp->mep != NULL) {
566 if (mfp->doc != NULL) {
567 PrintDocument (mfp->doc);
568 } else if (mfp->text != NULL) {
569 #ifdef WIN_MOTIF
570 TmpNam (str);
571 ScrollTextToFile (mfp->text, str);
572 printCmd = Nlm_XrmGetResource ("printCommand");
573 if (printCmd != NULL) {
574 StringNCpy_0 (cmmd, printCmd, sizeof (cmmd) - 1);
575 } else {
576 StringCpy (cmmd, "lp -c");
577 }
578 MemFree (printCmd);
579 len = (Int2) StringLen (cmmd);
580 while (len > 0 && cmmd [len] == ' ') {
581 cmmd [len] = '\0';
582 len--;
583 }
584 StringCat (cmmd, " ");
585 StringCat (cmmd, str);
586 StringCat (cmmd, "; rm ");
587 StringCat (cmmd, str);
588 system (cmmd);
589 /*
590 FileRemove (str);
591 */
592 #endif
593 }
594 }
595 }
596
SetMedlineImportExportItems(MedlineViewFormPtr mfp)597 static void SetMedlineImportExportItems (MedlineViewFormPtr mfp)
598
599 {
600 IteM exportItm;
601
602 if (mfp == NULL) return;
603 exportItm = FindFormMenuItem ((BaseFormPtr) mfp, VIB_MSG_EXPORT);
604 if (exportItm == NULL) return;
605 switch (mfp->currentPage) {
606 case ABSTRACT_PAGE :
607 SafeSetTitle (exportItm, "Export Abstract...");
608 break;
609 case CITATION_PAGE :
610 SafeSetTitle (exportItm, "Export Citation...");
611 break;
612 case MEDLINE_PAGE :
613 SafeSetTitle (exportItm, "Export MEDLINE...");
614 break;
615 case MEDASN1_PAGE :
616 SafeSetTitle (exportItm, "Export ASN.1...");
617 break;
618 case MEDXML_PAGE :
619 SafeSetTitle (exportItm, "Export XML...");
620 break;
621 default :
622 SafeSetTitle (exportItm, "Export...");
623 break;
624 }
625 }
626
ChangeMedlineViewTabs(VoidPtr data,Int2 newval,Int2 oldval)627 static void ChangeMedlineViewTabs (VoidPtr data, Int2 newval, Int2 oldval)
628
629 {
630 MedlineEntryPtr mep;
631 MedlineViewFormPtr mfp;
632
633 mfp = (MedlineViewFormPtr) data;
634 if (mfp != NULL && mfp->mep != NULL) {
635 mep = mfp->mep;
636 mfp->currentPage = newval;
637 SafeHide (mfp->doc);
638 SafeHide (mfp->text);
639 WatchCursor ();
640 Update ();
641 Reset (mfp->doc);
642 Reset (mfp->text);
643 PointerToForm (mfp->form, (Pointer) mep);
644 Update ();
645 ArrowCursor ();
646 SafeShow (mfp->doc);
647 SafeShow (mfp->text);
648 SetMedlineImportExportItems (mfp);
649 Update ();
650 if (mfp->activateForm != NULL) {
651 mfp->activateForm ((WindoW) mfp->form);
652 }
653 }
654 }
655
ChangeMedlineViewGroup(GrouP g)656 static void ChangeMedlineViewGroup (GrouP g)
657
658 {
659 MedlineViewFormPtr mfp;
660 Int2 val;
661
662 mfp = (MedlineViewFormPtr) GetObjectExtra (g);
663 if (mfp != NULL) {
664 val = GetValue (g);
665 ChangeMedlineViewTabs ((VoidPtr) mfp, val - 1, mfp->currentPage);
666 }
667 }
668
ChangeMedlineViewPopup(PopuP p)669 static void ChangeMedlineViewPopup (PopuP p)
670
671 {
672 MedlineViewFormPtr mfp;
673 Int2 val;
674
675 mfp = (MedlineViewFormPtr) GetObjectExtra (p);
676 if (mfp != NULL) {
677 val = GetValue (p);
678 ChangeMedlineViewTabs ((VoidPtr) mfp, val - 1, mfp->currentPage);
679 }
680 }
681
682 static CharPtr medlineViewFormTabs [] = {
683 "Abstract", "Citation", "MEDLINE", NULL, NULL, NULL
684 };
685
CleanupMedlineForm(GraphiC g,VoidPtr data)686 static void CleanupMedlineForm (GraphiC g, VoidPtr data)
687
688 {
689 MedlineViewFormPtr mfp;
690
691 mfp = (MedlineViewFormPtr) data;
692 if (mfp != NULL && mfp->input_entityID > 0) {
693 ObjMgrFreeUserData (mfp->input_entityID, mfp->procid, mfp->proctype, mfp->userkey);
694 }
695 if (mfp != NULL) {
696 WatchCursor ();
697 if (mfp->cleanupObjectPtr && mfp->objectDataPtr != NULL) {
698 MedlineEntryFree ((MedlineEntryPtr) mfp->objectDataPtr);
699 }
700 ArrowCursor ();
701 }
702 StdCleanupFormProc (g, data);
703 }
704
ExportMedlineViewForm(ForM f,CharPtr filename)705 static Boolean ExportMedlineViewForm (ForM f, CharPtr filename)
706
707 {
708 ExportMedlineViewFormToFile (GetObjectExtra (f), filename);
709 return TRUE;
710 }
711
MedlineViewFormMessage(ForM f,Int2 mssg)712 static void MedlineViewFormMessage (ForM f, Int2 mssg)
713
714 {
715 MedlineViewFormPtr mfp;
716 MedlineViewProcsPtr mvpp;
717
718 mfp = (MedlineViewFormPtr) GetObjectExtra (f);
719 if (mfp != NULL) {
720 switch (mssg) {
721 case VIB_MSG_REDRAW :
722 mvpp = (MedlineViewProcsPtr) GetAppProperty ("MedlineDisplayForm");
723 if (mvpp != NULL) {
724 mfp->jourfnt = mvpp->jourfnt;
725 mfp->volfnt = mvpp->volfnt;
726 mfp->pagesfnt = mvpp->pagesfnt;
727 mfp->titlefnt = mvpp->titlefnt;
728 mfp->authorsfnt = mvpp->authorsfnt;
729 mfp->affilfnt = mvpp->affilfnt;
730 mfp->abstractfnt = mvpp->abstractfnt;
731 mfp->meshfnt = mvpp->meshfnt;
732 mfp->displayFont = mvpp->displayFont;
733 SafeHide (mfp->doc);
734 SafeHide (mfp->text);
735 Update ();
736 Reset (mfp->doc);
737 Reset (mfp->text);
738 PointerToForm (mfp->form, (Pointer) mfp->mep);
739 Update ();
740 ArrowCursor ();
741 SafeShow (mfp->doc);
742 SafeShow (mfp->text);
743 }
744 break;
745 case VIB_MSG_COPY :
746 CopyMedlineViewFormToClipboard (mfp);
747 break;
748 case VIB_MSG_EXPORT :
749 ExportMedlineViewForm (f, NULL);
750 break;
751 case VIB_MSG_PRINT :
752 PrintMedlineViewForm (mfp);
753 break;
754 default :
755 if (mfp->appmessage != NULL) {
756 mfp->appmessage (f, mssg);
757 }
758 break;
759 }
760 }
761 }
762
MedlineViewFormActivate(WindoW w)763 static void MedlineViewFormActivate (WindoW w)
764
765 {
766 MedlineViewFormPtr mfp;
767
768 mfp = (MedlineViewFormPtr) GetObjectExtra (w);
769 if (mfp != NULL) {
770 if (mfp->activate != NULL) {
771 mfp->activate (w);
772 }
773 SetMedlineImportExportItems (mfp);
774 }
775 }
776
777 /*
778 static void LaunchPubMedArticle (ButtoN b)
779
780 {
781 #ifndef WIN_MAC
782 CharPtr argv [8];
783 #endif
784 CharPtr browser;
785 MedlineViewFormPtr mfp;
786 Char str [256];
787 #ifdef WIN_MOTIF
788 NS_Window window = NULL;
789 #endif
790
791 mfp = (MedlineViewFormPtr) GetObjectExtra (b);
792 if (mfp == NULL) return;
793 if (mfp->docuid < 1) return;
794 browser = GetAppProperty ("MedviewBrowserPath");
795 sprintf (str,
796 "http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query?db=m&form=6&uid=%ld&Dopt=r",
797 (long) mfp->docuid);
798 #ifdef WIN_MAC
799 if (browser == NULL || StringHasNoText (browser)) {
800 Nlm_SendURLAppleEvent (str, "MOSS", NULL);
801 } else {
802 Nlm_SendURLAppleEvent (str, NULL, browser);
803 }
804 #endif
805 #ifdef WIN_MSWIN
806 argv [0] = str;
807 argv [1] = NULL;
808 if (browser != NULL && (! StringHasNoText (browser))) {
809 if (! Execv (browser, argv)) {
810 Message (MSG_POST, "Unable to launch %s", browser);
811 }
812 } else {
813 if (! Nlm_MSWin_OpenDocument (str)) {
814 Message (MSG_POST, "Unable to launch browser");
815 }
816 }
817 #endif
818 #ifdef WIN_MOTIF
819 argv [0] = str;
820 argv [1] = NULL;
821 if (browser != NULL && (! StringHasNoText (browser))) {
822 if (! Execv (browser, argv)) {
823 Message (MSG_POST, "Unable to launch %s", browser);
824 }
825 } else {
826 if (! NS_OpenURL (&window, str, NULL, TRUE)) {
827 Message (MSG_POST, "Unable to launch netscape");
828 }
829 NS_WindowFree (window);
830 }
831 #endif
832 }
833 */
834
LaunchPubMedArticle(ButtoN b)835 static void LaunchPubMedArticle (ButtoN b)
836
837 {
838 MedlineViewFormPtr mfp;
839
840 mfp = (MedlineViewFormPtr) GetObjectExtra (b);
841 if (mfp == NULL) return;
842 if (mfp->docuid < 1) return;
843 LaunchEntrezURL ("PubMed", mfp->docuid, "Abstract");
844 }
845
SetFontIfNull(FonT f,CharPtr dfault)846 static FonT SetFontIfNull (FonT f, CharPtr dfault)
847
848 {
849 if (f != NULL) return f;
850 f = ParseFont (dfault);
851 return f;
852 }
853
SetupDefaultMvppFonts(MedlineViewProcsPtr mvpp)854 static void SetupDefaultMvppFonts (MedlineViewProcsPtr mvpp)
855
856 {
857 if (mvpp == NULL) return;
858
859 #ifdef WIN_MAC
860 mvpp->jourfnt = SetFontIfNull (mvpp->jourfnt, "Geneva,10,i");
861 mvpp->volfnt = SetFontIfNull (mvpp->volfnt, "Geneva,10,b");
862 mvpp->pagesfnt = SetFontIfNull (mvpp->pagesfnt, "Geneva,10");
863 mvpp->titlefnt = SetFontIfNull (mvpp->titlefnt, "Times,14,b");
864 mvpp->authorsfnt = SetFontIfNull (mvpp->authorsfnt, "Times,14");
865 mvpp->affilfnt = SetFontIfNull (mvpp->affilfnt, "Times,12");
866 mvpp->abstractfnt = SetFontIfNull (mvpp->abstractfnt, "Geneva,10");
867 mvpp->meshfnt = SetFontIfNull (mvpp->meshfnt, "Monaco,9");
868 mvpp->displayFont = SetFontIfNull (mvpp->displayFont, "Monaco,9");
869 #endif
870 #ifdef WIN_MSWIN
871 mvpp->jourfnt = SetFontIfNull (mvpp->jourfnt, "Arial,11,i");
872 mvpp->volfnt = SetFontIfNull (mvpp->volfnt, "Arial,11,b");
873 mvpp->pagesfnt = SetFontIfNull (mvpp->pagesfnt, "Arial,11");
874 mvpp->titlefnt = SetFontIfNull (mvpp->titlefnt, "Times New Roman,14,b");
875 mvpp->authorsfnt = SetFontIfNull (mvpp->authorsfnt, "Times New Roman,14");
876 mvpp->affilfnt = SetFontIfNull (mvpp->affilfnt, "Times New Roman,11");
877 mvpp->abstractfnt = SetFontIfNull (mvpp->abstractfnt, "Times New Roman,11");
878 mvpp->meshfnt = SetFontIfNull (mvpp->meshfnt, "Times New Roman,9");
879 mvpp->displayFont = SetFontIfNull (mvpp->displayFont, "Courier New,10");
880 #endif
881 #ifdef WIN_MOTIF
882 mvpp->jourfnt = SetFontIfNull (mvpp->jourfnt, "Helvetica,12,i");
883 mvpp->volfnt = SetFontIfNull (mvpp->volfnt, "Helvetica,12,b");
884 mvpp->pagesfnt = SetFontIfNull (mvpp->pagesfnt, "Helvetica,12");
885 mvpp->titlefnt = SetFontIfNull (mvpp->titlefnt, "Times,18,b");
886 mvpp->authorsfnt = SetFontIfNull (mvpp->authorsfnt, "Times,18");
887 mvpp->affilfnt = SetFontIfNull (mvpp->affilfnt, "Times,14");
888 mvpp->abstractfnt = SetFontIfNull (mvpp->abstractfnt, "Times,14");
889 mvpp->meshfnt = SetFontIfNull (mvpp->meshfnt, "Times,12");
890 mvpp->displayFont = SetFontIfNull (mvpp->displayFont, "Courier,10");
891 #endif
892 }
893
CreateMedlineViewForm(Int2 left,Int2 top,CharPtr title,MedlineEntryPtr mep,MedlineViewProcsPtr mvpp)894 extern ForM LIBCALL CreateMedlineViewForm (Int2 left, Int2 top, CharPtr title,
895 MedlineEntryPtr mep,
896 MedlineViewProcsPtr mvpp)
897
898 {
899 ButtoN b;
900 WndActnProc close;
901 FonT fnt;
902 GrouP g;
903 GrouP h;
904 Int2 j;
905 GrouP k;
906 MedViewControlsProc makeControls = NULL;
907 MedlineViewFormPtr mfp;
908 Int2 minwid;
909 Int2 pixheight;
910 Int2 pixwidth;
911 PopuP pops;
912 PrompT ppt;
913 RecT r;
914 GrouP rads;
915 GrouP s;
916 DialoG tbs;
917 WindoW w;
918
919 w = NULL;
920 mfp = (MedlineViewFormPtr) MemNew (sizeof (MedlineViewForm));
921 if (mfp != NULL && mep != NULL) {
922 close = StdCloseWindowProc;
923 if (mvpp == NULL) {
924 mvpp = (MedlineViewProcsPtr) GetAppProperty ("MedlineDisplayForm");
925 }
926 if (mvpp != NULL && mvpp->closeForm != NULL) {
927 close = mvpp->closeForm;
928 }
929 w = DocumentWindow (left, top, -10, -10, title,
930 close, ResizeMedlineForm);
931 SetObjectExtra (w, mfp, CleanupMedlineForm);
932 mfp->form = (ForM) w;
933 mfp->actproc = NULL;
934 mfp->toform = MedlineEntryPtrToMedlineForm;
935 mfp->exportform = ExportMedlineViewForm;
936 mfp->formmessage = MedlineViewFormMessage;
937
938 mfp->mep = mep;
939 mfp->useScrollText = FALSE;
940 if (mvpp != NULL) {
941 SetupDefaultMvppFonts (mvpp);
942 mfp->cleanupObjectPtr = mvpp->cleanupObjectPtr;
943 mfp->activateForm = mvpp->activateForm;
944 mfp->jourfnt = mvpp->jourfnt;
945 mfp->volfnt = mvpp->volfnt;
946 mfp->pagesfnt = mvpp->pagesfnt;
947 mfp->titlefnt = mvpp->titlefnt;
948 mfp->authorsfnt = mvpp->authorsfnt;
949 mfp->affilfnt = mvpp->affilfnt;
950 mfp->abstractfnt = mvpp->abstractfnt;
951 mfp->meshfnt = mvpp->meshfnt;
952 mfp->displayFont = mvpp->displayFont;
953 mfp->useScrollText = mvpp->useScrollText;
954 mfp->appmessage = mvpp->handleMessages;
955 makeControls = mvpp->makeControls;
956 }
957
958 if (mvpp != NULL && mvpp->createMenus != NULL) {
959 mvpp->createMenus (w);
960 }
961
962 g = HiddenGroup (w, -1, 0, NULL);
963 SetGroupSpacing (g, 3, 10);
964
965 if (mvpp != NULL && mvpp->showAsnPage) {
966 minwid = 35 * stdCharWidth + 17;
967 } else {
968 minwid = 27 * stdCharWidth + 17;
969 }
970 pixwidth = minwid;
971 pixheight = 14 * stdLineHeight;
972 mfp->currentPage = 0;
973
974 if (mvpp != NULL) {
975 mfp->currentPage = mvpp->initPage;
976 if (mvpp->initMedLabel != NULL) {
977 for (j = 0; medlineViewFormTabs [j] != NULL; j++) {
978 if (StringICmp (medlineViewFormTabs [j], mvpp->initMedLabel) == 0) {
979 mfp->currentPage = j;
980 }
981 }
982 }
983 if (mvpp->showAsnPage) {
984 medlineViewFormTabs [3] = "ASN.1";
985 medlineViewFormTabs [4] = "XML";
986 }
987 switch (mvpp->useFolderTabs) {
988 case CHANGE_VIEW_NOTABS :
989 break;
990 case CHANGE_VIEW_FOLDERTABS :
991 tbs = CreateFolderTabs (g, medlineViewFormTabs, mfp->currentPage,
992 0, 0, SYSTEM_FOLDER_TAB,
993 ChangeMedlineViewTabs, (Pointer) mfp);
994 ObjectRect (tbs, &r);
995 pixwidth = r.right - 2 * r.left - Nlm_vScrollBarWidth;
996 if (pixwidth < minwid) {
997 pixwidth = minwid;
998 }
999 break;
1000 case CHANGE_VIEW_TEXTTABS :
1001 tbs = CreateTextTabs (g, medlineViewFormTabs, mfp->currentPage,
1002 0, 0, SYSTEM_TEXT_TAB,
1003 ChangeMedlineViewTabs, (Pointer) mfp);
1004 ObjectRect (tbs, &r);
1005 pixwidth = r.right - 2 * r.left - Nlm_vScrollBarWidth;
1006 if (pixwidth < minwid) {
1007 pixwidth = minwid;
1008 }
1009 break;
1010 case CHANGE_VIEW_RADIOBUTTONS :
1011 k = HiddenGroup (g, -3, 0, NULL);
1012 ppt = StaticPrompt (k, "Format:", 0, 0, programFont, 'l');
1013 rads = HiddenGroup (k, 8, 0, ChangeMedlineViewGroup);
1014 SetObjectExtra (rads, (Pointer) mfp, NULL);
1015 for (j = 0; medlineViewFormTabs [j] != NULL; j++) {
1016 RadioButton (rads, medlineViewFormTabs [j]);
1017 }
1018 SetValue (rads, mfp->currentPage + 1);
1019 ObjectRect (rads, &r);
1020 pixwidth = r.right - 2 * r.left - Nlm_vScrollBarWidth;
1021 if (pixwidth < minwid) {
1022 pixwidth = minwid;
1023 }
1024 b = PushButton (k, "PubMed", LaunchPubMedArticle);
1025 SetObjectExtra (b, (Pointer) mfp, NULL);
1026 AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt, (HANDLE) rads, (HANDLE) b, NULL);
1027 break;
1028 case CHANGE_VIEW_POPUP :
1029 k = HiddenGroup (g, -3, 0, NULL);
1030 ppt = StaticPrompt (k, "Display Format", 0, popupMenuHeight, programFont, 'l');
1031 pops = PopupList (k, TRUE, ChangeMedlineViewPopup);
1032 SetObjectExtra (pops, (Pointer) mfp, NULL);
1033 for (j = 0; medlineViewFormTabs [j] != NULL; j++) {
1034 PopupItem (pops, medlineViewFormTabs [j]);
1035 }
1036 SetValue (pops, mfp->currentPage + 1);
1037 ObjectRect (pops, &r);
1038 pixwidth = r.right - 2 * r.left - Nlm_vScrollBarWidth;
1039 if (pixwidth < minwid) {
1040 pixwidth = minwid;
1041 }
1042 b = PushButton (k, "PubMed", LaunchPubMedArticle);
1043 SetObjectExtra (b, (Pointer) mfp, NULL);
1044 AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt, (HANDLE) pops, (HANDLE) b, NULL);
1045 break;
1046 default :
1047 break;
1048 }
1049 medlineViewFormTabs [3] = NULL;
1050 medlineViewFormTabs [4] = NULL;
1051 pixwidth = MAX (pixwidth, mvpp->minPixelWidth);
1052 pixheight = MAX (pixheight, mvpp->minPixelHeight);
1053 }
1054
1055 h = HiddenGroup (g, 0, 0, NULL);
1056
1057 s = HiddenGroup (h, -1, 0, NULL);
1058 if (mfp->useScrollText) {
1059 fnt = programFont;
1060 if (mfp->displayFont != NULL) {
1061 fnt = mfp->displayFont;
1062 }
1063 mfp->text = ScrollText (s, pixwidth / stdCharWidth,
1064 pixheight / stdLineHeight, fnt, FALSE, NULL);
1065 SetObjectExtra (mfp->text, mfp, NULL);
1066 } else {
1067 mfp->doc = DocumentPanel (s, pixwidth, pixheight);
1068 SetObjectExtra (mfp->doc, mfp, NULL);
1069 }
1070
1071 if (makeControls != NULL) {
1072 mfp->controls = makeControls (g, (BaseFormPtr) mfp, TYP_ML, mep->uid);
1073 }
1074
1075 RealizeWindow (w);
1076
1077 mfp->activate = NULL;
1078 if (mvpp != NULL) {
1079 mfp->activate = mvpp->activateForm;
1080 }
1081 SetActivate (w, MedlineViewFormActivate);
1082 Update ();
1083 MedlineViewFormActivate ((WindoW) mfp->form);
1084
1085 SendMessageToForm (mfp->form, VIB_MSG_INIT);
1086 if (mep != NULL) {
1087 PointerToForm (mfp->form, (Pointer) mep);
1088 }
1089 }
1090 return (ForM) w;
1091 }
1092
1093 CharPtr PersonIdPrint PROTO((PersonIdPtr pip, CharPtr buf)); /* in prtutil.h */
1094
1095 #define ART_JOURNAL 1
1096 #define ART_BOOK 2
1097
GetMedlineCaption(MedlineEntryPtr mep,CharPtr buf,size_t max)1098 static void GetMedlineCaption (MedlineEntryPtr mep, CharPtr buf, size_t max)
1099
1100 {
1101 AuthListPtr alp;
1102 AuthorPtr ap;
1103 CitArtPtr cap;
1104 CitBookPtr cbp;
1105 CitJourPtr cjp;
1106 DatePtr dp;
1107 ImprintPtr imp;
1108 ValNodePtr names;
1109 PersonIdPtr pid;
1110 Char str [64];
1111 Char tmp [16];
1112
1113 if (mep == NULL || buf == NULL || max < 1) return;
1114 cap = mep->cit;
1115 if (cap == NULL) return;
1116 alp = cap->authors;
1117 if (alp == NULL) return;
1118 str [0] = '\0';
1119 tmp [0] = '\0';
1120 if (alp->choice == 1) {
1121 names = alp->names;
1122 if (names != NULL) {
1123 ap = names->data.ptrvalue;
1124 if (ap != NULL) {
1125 pid = ap->name;
1126 if (pid != NULL) {
1127 PersonIdPrint (pid, str);
1128 }
1129 }
1130 }
1131 } else if (alp->choice == 2 || alp->choice == 3) {
1132 names = alp->names;
1133 if (names != NULL) {
1134 StringNCpy_0 (str, names->data.ptrvalue, sizeof (str) - 2);
1135 }
1136 }
1137 imp = NULL;
1138 switch (cap->from) {
1139 case ART_JOURNAL :
1140 cjp = (CitJourPtr) cap->fromptr;
1141 if (cjp != NULL) {
1142 imp = cjp->imp;
1143 }
1144 break;
1145 case ART_BOOK :
1146 cbp = (CitBookPtr) cap->fromptr;
1147 if (cbp != NULL) {
1148 imp = cbp->imp;
1149 }
1150 break;
1151 default :
1152 break;
1153 }
1154 if (imp != NULL) {
1155 dp = imp->date;
1156 if (dp != NULL) {
1157 if (dp->data [0] == 1) {
1158 sprintf (tmp, " %d", (dp->data [1] + 1900));
1159 } else if (dp->data [0] == 0 && dp->str != NULL) {
1160 sprintf (tmp, " %s", dp->str);
1161 }
1162 }
1163 }
1164 StringCat (str, tmp);
1165 StringNCpy_0 (buf, str, max);
1166 }
1167
MedlineViewGenFunc(Pointer data)1168 extern Int2 LIBCALLBACK MedlineViewGenFunc (Pointer data)
1169
1170 {
1171 MedlineEntryPtr mep;
1172 MedlineViewFormPtr mfp;
1173 OMProcControlPtr ompcp;
1174 OMUserDataPtr omudp;
1175 Char str [64];
1176 WindoW w;
1177
1178 ompcp = (OMProcControlPtr) data;
1179 mep = NULL;
1180 if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
1181 switch (ompcp->input_itemtype) {
1182 case OBJ_MEDLINE_ENTRY :
1183 mep = (MedlineEntryPtr) ompcp->input_data;
1184 break;
1185 case 0 :
1186 return OM_MSG_RET_ERROR;
1187 default :
1188 return OM_MSG_RET_ERROR;
1189 }
1190 if (mep == NULL) return OM_MSG_RET_ERROR;
1191 str [0] = '\0';
1192 GetMedlineCaption (mep, str, sizeof (str));
1193 w = (WindoW) CreateMedlineViewForm (-50, -33, str, mep, NULL);
1194 mfp = (MedlineViewFormPtr) GetObjectExtra (w);
1195 if (mfp != NULL) {
1196 mfp->input_entityID = ompcp->input_entityID;
1197 mfp->input_itemID = ompcp->input_itemID;
1198 mfp->input_itemtype = ompcp->input_itemtype;
1199 mfp->this_itemtype = OBJ_MEDLINE_ENTRY;
1200 mfp->this_subtype = 0;
1201 mfp->procid = ompcp->proc->procid;
1202 mfp->proctype = ompcp->proc->proctype;
1203 mfp->docuid = mep->uid;
1204 mfp->doctype = TYP_ML;
1205 mfp->userkey = OMGetNextUserKey ();
1206 omudp = ObjMgrAddUserData (ompcp->input_entityID, ompcp->proc->procid,
1207 OMPROC_VIEW, mfp->userkey);
1208 if (omudp != NULL) {
1209 omudp->userdata.ptrvalue = (Pointer) mfp;
1210 omudp->messagefunc = NULL;
1211 }
1212 }
1213 Show (w);
1214 Select (w);
1215 return OM_MSG_RET_DONE;
1216 }
1217
1218