Main.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: Main.c /main/6 1996/06/07 12:04:30 daniel $ */
  24. #include "PrintDemo.h"
  25. /*
  26. * VideoShell structure definition
  27. */
  28. typedef struct _VideoShell
  29. {
  30. Widget widget;
  31. Boolean print_only;
  32. String file_name;
  33. } VideoShell;
  34. /*
  35. * application-level resources
  36. */
  37. static XrmOptionDescRec XrmOptions[] =
  38. {
  39. {"-print", "printOnly", XrmoptionNoArg, (caddr_t)"True"},
  40. {"-fileName", "fileName", XrmoptionSepArg, (caddr_t)NULL},
  41. };
  42. static XtResource VideoResources[] =
  43. {
  44. {"printOnly", "PrintOnly", XmRBoolean, sizeof (Boolean),
  45. XtOffsetOf (VideoShell, print_only), XmRImmediate, (XtPointer)False,
  46. },
  47. {"fileName", "FileName", XmRString, sizeof (char *),
  48. XtOffsetOf (VideoShell, file_name), XmRImmediate, (XtPointer)NULL,
  49. },
  50. };
  51. /*
  52. * static function declarations
  53. */
  54. static VideoShell* VideoShell_new(Display* display);
  55. /*
  56. * ------------------------------------------------------------------------
  57. * Name: VideoShell_new
  58. *
  59. * Description:
  60. *
  61. * Allocates a new VideoShell data structure.
  62. *
  63. * This function creates a top level application shell on the passed
  64. * video display.
  65. *
  66. * Return value:
  67. *
  68. * A pointer to the new VideoShell structure.
  69. */
  70. static VideoShell*
  71. VideoShell_new(Display* display)
  72. {
  73. VideoShell* me = (VideoShell*)XtCalloc(1, sizeof(VideoShell));
  74. me->widget = XtVaAppCreateShell(NULL, APP_CLASS,
  75. applicationShellWidgetClass,
  76. display,
  77. XmNtitle, "DtPrint Demo",
  78. NULL);
  79. XtGetApplicationResources(me->widget, me,
  80. VideoResources, XtNumber(VideoResources),
  81. NULL, 0);
  82. return me;
  83. }
  84. /*
  85. * ------------------------------------------------------------------------
  86. * Name: CloseProgramCB
  87. *
  88. * Description:
  89. *
  90. * Exit the program.
  91. *
  92. * Return value:
  93. *
  94. * None.
  95. */
  96. void
  97. CloseProgramCB(
  98. Widget w,
  99. XtPointer client_data,
  100. XtPointer call_data)
  101. {
  102. AppPrintData * p = (AppPrintData *) client_data ;
  103. /* we want to wait for the current job to complete before exiting */
  104. /* if a job is running, just unmap the windows and install itself
  105. as endjob callback, which will be called when printed_lines is
  106. back to zero */
  107. if (p->printed_lines) {
  108. /* put up a dialog saying it's waiting for the job
  109. to complete */
  110. XtAddCallback(p->print_shell, XmNendJobCallback, CloseProgramCB, p);
  111. } else {
  112. exit(0);
  113. }
  114. }
  115. static String fallbacks[] = {
  116. "Dtprint.Print*background:white",
  117. "Dtprint.Print*renderTable:-dt-application-bold-r-normal-serif-0-0-0-0-p-0-iso8859-1",
  118. "Dtprint.Print*shadowThickness:0",
  119. "Dtprint.Print*highlightThickness:0",
  120. "Dtprint.Print*pform.marginHeight: 1in",
  121. "Dtprint.Print*pform.marginWidth: 1in",
  122. "Dtprint.Print*ptext.Attachment:attach_form",
  123. NULL
  124. };
  125. /*
  126. * ------------------------------------------------------------------------
  127. * Name: main
  128. *
  129. * Description:
  130. *
  131. * "main" function for the DtPrint demo program.
  132. *
  133. *
  134. */
  135. int main(int argc, char* argv[])
  136. {
  137. XtAppContext app_context;
  138. VideoShell* video_shell;
  139. MainWindow* main_window;
  140. Display* video_display;
  141. AppPrintData* p;
  142. /*
  143. * attempt to open the X video display
  144. */
  145. XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
  146. XtToolkitInitialize();
  147. app_context = XtCreateApplicationContext();
  148. video_display = XtOpenDisplay(app_context, NULL, NULL, APP_CLASS,
  149. XrmOptions, XtNumber(XrmOptions),
  150. &argc, argv);
  151. XtAppSetFallbackResources(app_context, fallbacks);
  152. if(video_display == (Display*)NULL)
  153. {
  154. /*
  155. * parse command line and determine if "GUI-less" printing is
  156. * desired
  157. */
  158. /*
  159. * XXX exit for now
  160. */
  161. fprintf(stderr, "unable to open display\n");
  162. return 1;
  163. }
  164. /*
  165. * Create the top level video shell
  166. */
  167. video_shell = VideoShell_new(video_display);
  168. /*
  169. * one AppPrintData object per app
  170. */
  171. p = AppPrintData_new();
  172. p->print_only = video_shell->print_only;
  173. /*
  174. * check to see if we're running the app, or just printing (e.g. from
  175. * within a print action)
  176. */
  177. if(video_shell->print_only)
  178. {
  179. /*
  180. * create the application-specific object, and add it to the
  181. * AppPrintData structure.
  182. */
  183. p->app_object = AppObject_new((Widget)NULL, video_shell->file_name);
  184. /*
  185. * create the print setup box as the child of the top level shell
  186. */
  187. CreatePrintSetup(video_shell->widget, p);
  188. /*
  189. * set the cancel button to exit the program
  190. */
  191. XtAddCallback(p->print_dialog, DtNcancelCallback, CloseProgramCB, p);
  192. /*
  193. * manage the print setup box
  194. */
  195. XtManageChild(p->print_dialog);
  196. }
  197. else
  198. {
  199. /*
  200. * create the main window
  201. */
  202. main_window = MainWindow_new(video_shell->widget);
  203. /*
  204. * add callbacks to the main window
  205. */
  206. XtAddCallback(main_window->print_menu_button, XmNactivateCallback,
  207. PrintMenuCB, p);
  208. p->pr_button = main_window->print_menu_button;
  209. XtAddCallback(main_window->quick_print_button, XmNactivateCallback,
  210. QuickPrintCB, p);
  211. XtAddCallback(main_window->exit_button, XmNactivateCallback,
  212. CloseProgramCB, p);
  213. /*
  214. * create the application-specific object, and add it to the
  215. * AppPrintData structure.
  216. */
  217. p->app_object =
  218. AppObject_new(main_window->widget, video_shell->file_name);
  219. /*
  220. * manage the main window
  221. */
  222. XtManageChild(main_window->widget);
  223. }
  224. /*
  225. * main loop
  226. */
  227. XtRealizeWidget(video_shell->widget);
  228. XtAppMainLoop(app_context);
  229. /*
  230. * we never get here, but this makes the compiler happy
  231. */
  232. return 0;
  233. }