comparison src/frame-msw.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 501cfd01ee6d
children 697ef44129c6
comparison
equal deleted inserted replaced
409:301b9ebbdf3b 410:de805c49cfc1
78 Lisp_Object Vmswindows_frame_being_created; 78 Lisp_Object Vmswindows_frame_being_created;
79 79
80 /*---------------------------------------------------------------------*/ 80 /*---------------------------------------------------------------------*/
81 /*----- DISPLAY FRAME -----*/ 81 /*----- DISPLAY FRAME -----*/
82 /*---------------------------------------------------------------------*/ 82 /*---------------------------------------------------------------------*/
83
84 HWND
85 mswindows_get_selected_frame_hwnd (void)
86 {
87 Lisp_Object frame, device;
88
89 device = Ffind_device (Qnil, Qmswindows);
90 if (NILP (device))
91 return NULL;
92 frame = DEVICE_SELECTED_FRAME (XDEVICE (device));
93 if (NILP (frame))
94 return NULL;
95
96 return FRAME_MSWINDOWS_HANDLE (XFRAME (frame));
97 }
83 98
84 static void 99 static void
85 mswindows_init_frame_1 (struct frame *f, Lisp_Object props) 100 mswindows_init_frame_1 (struct frame *f, Lisp_Object props)
86 { 101 {
87 Lisp_Object initially_unmapped; 102 Lisp_Object initially_unmapped;
636 651
637 /* resize and move the window so that it fits in the workspace. This is 652 /* resize and move the window so that it fits in the workspace. This is
638 not restrictive since this will happen later anyway in WM_SIZE. We 653 not restrictive since this will happen later anyway in WM_SIZE. We
639 have to do this after adjusting the rect to account for menubar 654 have to do this after adjusting the rect to account for menubar
640 etc. */ 655 etc. */
641 msw_get_workspace_coords (&ws_rect); 656 mswindows_get_workspace_coords (&ws_rect);
642 pixel_width = rect.right - rect.left; 657 pixel_width = rect.right - rect.left;
643 pixel_height = rect.bottom - rect.top; 658 pixel_height = rect.bottom - rect.top;
644 if (pixel_width > ws_rect.right - ws_rect.left) 659 if (pixel_width > ws_rect.right - ws_rect.left)
645 { 660 {
646 pixel_width = ws_rect.right - ws_rect.left; 661 pixel_width = ws_rect.right - ws_rect.left;
716 731
717 /*---------------------------------------------------------------------*/ 732 /*---------------------------------------------------------------------*/
718 /*----- PRINTER FRAME -----*/ 733 /*----- PRINTER FRAME -----*/
719 /*---------------------------------------------------------------------*/ 734 /*---------------------------------------------------------------------*/
720 735
736 /*
737 * With some drvier/os combination (I discovered this with HP drviers
738 * under W2K), DC geometry is reset upon StartDoc and EndPage
739 * calls. This is called every time one of these calls is made.
740 */
741 static void
742 apply_dc_geometry (struct frame* f)
743 {
744 HDC hdc = DEVICE_MSPRINTER_HDC (XDEVICE (FRAME_DEVICE (f)));
745 SetTextAlign (hdc, TA_BASELINE | TA_LEFT | TA_NOUPDATECP);
746 SetViewportOrgEx (hdc, FRAME_MSPRINTER_PIXLEFT(f),
747 FRAME_MSPRINTER_PIXTOP(f), NULL);
748 }
749
721 void 750 void
722 msprinter_start_page (struct frame *f) 751 msprinter_start_page (struct frame *f)
723 { 752 {
724 if (!FRAME_MSPRINTER_PAGE_STARTED (f)) 753 if (!FRAME_MSPRINTER_PAGE_STARTED (f))
725 { 754 {
726 FRAME_MSPRINTER_PAGE_STARTED (f) = 1; 755 FRAME_MSPRINTER_PAGE_STARTED (f) = 1;
727 StartPage (DEVICE_MSPRINTER_HDC (XDEVICE (FRAME_DEVICE (f)))); 756 StartPage (DEVICE_MSPRINTER_HDC (XDEVICE (FRAME_DEVICE (f))));
757 apply_dc_geometry (f);
728 } 758 }
729 } 759 }
730 760
731 static void 761 static void
732 error_frame_unsizable (struct frame *f) 762 error_frame_unsizable (struct frame *f)
762 FRAME_MSPRINTER_RIGHT_MARGIN(f) = 1440; 792 FRAME_MSPRINTER_RIGHT_MARGIN(f) = 1440;
763 793
764 /* Negative for "uinspecified" */ 794 /* Negative for "uinspecified" */
765 FRAME_MSPRINTER_CHARWIDTH(f) = -1; 795 FRAME_MSPRINTER_CHARWIDTH(f) = -1;
766 FRAME_MSPRINTER_CHARHEIGHT(f) = -1; 796 FRAME_MSPRINTER_CHARHEIGHT(f) = -1;
767
768 /* nil is for "system default" for these properties. */
769 FRAME_MSPRINTER_ORIENTATION(f) = Qnil;
770 FRAME_MSPRINTER_DUPLEX(f) = Qnil;
771 } 797 }
772 798
773 static void 799 static void
774 msprinter_init_frame_3 (struct frame *f) 800 msprinter_init_frame_3 (struct frame *f)
775 { 801 {
776 DOCINFO di; 802 DOCINFO di;
777 struct device *device = XDEVICE (FRAME_DEVICE (f)); 803 struct device *device = XDEVICE (FRAME_DEVICE (f));
778 HDC hdc; 804 HDC hdc;
779 int frame_left, frame_top, frame_width, frame_height; 805 int frame_left, frame_top, frame_width, frame_height;
780
781 /* Change printer parameters */
782 {
783 DEVMODE* devmode = msprinter_get_devmode_copy (device);
784 devmode->dmFields = 0;
785
786 if (!NILP (FRAME_MSPRINTER_ORIENTATION(f)))
787 {
788 devmode->dmFields = DM_ORIENTATION;
789 if (EQ (FRAME_MSPRINTER_ORIENTATION(f), Qportrait))
790 devmode->dmOrientation = DMORIENT_PORTRAIT;
791 else if (EQ (FRAME_MSPRINTER_ORIENTATION(f), Qlandscape))
792 devmode->dmOrientation = DMORIENT_LANDSCAPE;
793 else
794 abort();
795 }
796
797 if (!NILP (FRAME_MSPRINTER_DUPLEX(f)))
798 {
799 devmode->dmFields = DM_DUPLEX;
800 if (EQ (FRAME_MSPRINTER_DUPLEX(f), Qnone))
801 devmode->dmDuplex = DMDUP_SIMPLEX;
802 if (EQ (FRAME_MSPRINTER_DUPLEX(f), Qvertical))
803 devmode->dmDuplex = DMDUP_VERTICAL;
804 if (EQ (FRAME_MSPRINTER_DUPLEX(f), Qhorizontal))
805 devmode->dmDuplex = DMDUP_HORIZONTAL;
806 else
807 abort();
808 }
809
810 assert (!FRAME_MSPRINTER_PAGE_STARTED (f));
811 msprinter_apply_devmode (device, devmode);
812 }
813 806
814 /* DC might be recreated in msprinter_apply_devmode, 807 /* DC might be recreated in msprinter_apply_devmode,
815 so do not initialize until now */ 808 so do not initialize until now */
816 hdc = DEVICE_MSPRINTER_HDC (device); 809 hdc = DEVICE_MSPRINTER_HDC (device);
817 810
872 FRAME_PIXHEIGHT(f) = frame_height; 865 FRAME_PIXHEIGHT(f) = frame_height;
873 pixel_to_char_size (f, frame_width, frame_height, &columns, &rows); 866 pixel_to_char_size (f, frame_width, frame_height, &columns, &rows);
874 change_frame_size (f, rows, columns, 0); 867 change_frame_size (f, rows, columns, 0);
875 } 868 }
876 869
877 /* Apply DC geometry */ 870 FRAME_MSPRINTER_PIXLEFT(f) = frame_left;
878 SetTextAlign (hdc, TA_BASELINE | TA_LEFT | TA_NOUPDATECP); 871 FRAME_MSPRINTER_PIXTOP(f) = frame_top;
879 SetViewportOrgEx (hdc, frame_left, frame_top, NULL);
880 SetWindowOrgEx (hdc, 0, 0, NULL);
881 872
882 /* Start print job */ 873 /* Start print job */
883 di.cbSize = sizeof (di); 874 di.cbSize = sizeof (di);
884 di.lpszDocName = (STRINGP(f->name) 875 di.lpszDocName = (STRINGP(f->name)
885 ? (char*) XSTRING_DATA(f->name) 876 ? (char*) XSTRING_DATA(f->name)
889 di.fwType = 0; 880 di.fwType = 0;
890 881
891 if (StartDoc (hdc, &di) <= 0) 882 if (StartDoc (hdc, &di) <= 0)
892 error ("Cannot start print job"); 883 error ("Cannot start print job");
893 884
885 apply_dc_geometry (f);
886
894 /* Finish frame setup */ 887 /* Finish frame setup */
895 FRAME_MSPRINTER_JOB_STARTED (f) = 1; 888 FRAME_MSPRINTER_JOB_STARTED (f) = 1;
896 FRAME_VISIBLE_P(f) = 0; 889 FRAME_VISIBLE_P(f) = 0;
897 } 890 }
898 891
899 static void 892 static void
900 msprinter_mark_frame (struct frame *f) 893 msprinter_mark_frame (struct frame *f)
901 { 894 {
902 /* NOTE: These need not be marked as long as we allow only c-defined
903 symbols for their values. Although, marking these is safer than
904 expensive. [I know a proof to the theorem postulating that a
905 gator is longer than greener. Ask me. -- kkm] */
906 mark_object (FRAME_MSPRINTER_ORIENTATION (f));
907 mark_object (FRAME_MSPRINTER_DUPLEX (f));
908 } 895 }
909 896
910 static void 897 static void
911 msprinter_delete_frame (struct frame *f) 898 msprinter_delete_frame (struct frame *f)
912 { 899 {
932 return make_int (FRAME_MSPRINTER_TOP_MARGIN(f)); 919 return make_int (FRAME_MSPRINTER_TOP_MARGIN(f));
933 if (EQ (Qright_margin, property)) 920 if (EQ (Qright_margin, property))
934 return make_int (FRAME_MSPRINTER_RIGHT_MARGIN(f)); 921 return make_int (FRAME_MSPRINTER_RIGHT_MARGIN(f));
935 else if (EQ (Qbottom_margin, property)) 922 else if (EQ (Qbottom_margin, property))
936 return make_int (FRAME_MSPRINTER_BOTTOM_MARGIN(f)); 923 return make_int (FRAME_MSPRINTER_BOTTOM_MARGIN(f));
937 else if (EQ (Qorientation, property))
938 return FRAME_MSPRINTER_ORIENTATION(f);
939 else if (EQ (Qduplex, property))
940 return FRAME_MSPRINTER_DUPLEX(f);
941 else 924 else
942 return Qunbound; 925 return Qunbound;
943 } 926 }
944 927
945 static int 928 static int
946 msprinter_internal_frame_property_p (struct frame *f, Lisp_Object property) 929 msprinter_internal_frame_property_p (struct frame *f, Lisp_Object property)
947 { 930 {
948 return (EQ (Qleft_margin, property) || EQ (Qtop_margin, property) || 931 return (EQ (Qleft_margin, property) || EQ (Qtop_margin, property) ||
949 EQ (Qright_margin, property) || EQ (Qbottom_margin, property) || 932 EQ (Qright_margin, property) || EQ (Qbottom_margin, property));
950 EQ (Qorientation, property) || EQ (Qduplex, property));
951 } 933 }
952 934
953 static Lisp_Object 935 static Lisp_Object
954 msprinter_frame_properties (struct frame *f) 936 msprinter_frame_properties (struct frame *f)
955 { 937 {
956 Lisp_Object props = Qnil; 938 Lisp_Object props = Qnil;
957 props = cons3 (Qorientation, FRAME_MSPRINTER_ORIENTATION(f), props);
958 props = cons3 (Qduplex, FRAME_MSPRINTER_DUPLEX(f), props);
959 props = cons3 (Qbottom_margin, 939 props = cons3 (Qbottom_margin,
960 make_int (FRAME_MSPRINTER_BOTTOM_MARGIN(f)), props); 940 make_int (FRAME_MSPRINTER_BOTTOM_MARGIN(f)), props);
961 props = cons3 (Qright_margin, 941 props = cons3 (Qright_margin,
962 make_int (FRAME_MSPRINTER_RIGHT_MARGIN(f)), props); 942 make_int (FRAME_MSPRINTER_RIGHT_MARGIN(f)), props);
963 props = cons3 (Qtop_margin, 943 props = cons3 (Qtop_margin,
1020 { 1000 {
1021 maybe_error_if_job_active (f); 1001 maybe_error_if_job_active (f);
1022 CHECK_NATNUM (val); 1002 CHECK_NATNUM (val);
1023 FRAME_MSPRINTER_BOTTOM_MARGIN(f) = XINT (val); 1003 FRAME_MSPRINTER_BOTTOM_MARGIN(f) = XINT (val);
1024 } 1004 }
1025 else if (EQ (prop, Qorientation))
1026 {
1027 maybe_error_if_job_active (f);
1028 CHECK_SYMBOL (val);
1029 if (!NILP(val) &&
1030 !EQ (val, Qportrait) &&
1031 !EQ (val, Qlandscape))
1032 signal_simple_error ("Page orientation can only be "
1033 "'portrait or 'landscape", val);
1034 FRAME_MSPRINTER_ORIENTATION(f) = val;
1035 }
1036 else if (EQ (prop, Qduplex))
1037 {
1038 maybe_error_if_job_active (f);
1039 CHECK_SYMBOL (val);
1040 if (!NILP(val) &&
1041 !EQ (val, Qnone) &&
1042 !EQ (val, Qvertical) &&
1043 !EQ (val, Qhorizontal))
1044 signal_simple_error ("Duplex can only be 'none, "
1045 "'vertical or 'horizontal", val);
1046 FRAME_MSPRINTER_DUPLEX(f) = val;
1047 }
1048 } 1005 }
1049 } 1006 }
1050 } 1007 }
1051 1008
1052 static void 1009 static void
1062 /* #### Should we eject empty pages? */ 1019 /* #### Should we eject empty pages? */
1063 if (FRAME_MSPRINTER_PAGE_STARTED (f)) 1020 if (FRAME_MSPRINTER_PAGE_STARTED (f))
1064 { 1021 {
1065 FRAME_MSPRINTER_PAGE_STARTED (f) = 0; 1022 FRAME_MSPRINTER_PAGE_STARTED (f) = 0;
1066 EndPage (DEVICE_MSPRINTER_HDC (XDEVICE (FRAME_DEVICE (f)))); 1023 EndPage (DEVICE_MSPRINTER_HDC (XDEVICE (FRAME_DEVICE (f))));
1024 apply_dc_geometry (f);
1067 } 1025 }
1068 } 1026 }
1069 1027
1070 1028
1071 void 1029 void
1210 plist to nil, as in this example: 1168 plist to nil, as in this example:
1211 1169
1212 (setq default-frame-plist '(height 55 'width 80) 1170 (setq default-frame-plist '(height 55 'width 80)
1213 default-msprinter-frame-plist '(height nil 'width nil)) 1171 default-msprinter-frame-plist '(height nil 'width nil))
1214 1172
1215
1216 orientation Printer page orientation. Can be 'nil,
1217 indicating system default, 'portrait
1218 or 'landscape.
1219
1220 duplex Duplex printing mode, subject to printer
1221 support. Can be 'nil for the device default,
1222 'none for simplex printing, 'vertical or
1223 'horizontal for duplex page bound along
1224 the corresponding page direction.
1225
1226 See also `default-frame-plist', which specifies properties which apply 1173 See also `default-frame-plist', which specifies properties which apply
1227 to all frames, not just mswindows frames. 1174 to all frames, not just mswindows frames.
1228 */ ); 1175 */ );
1229 Vdefault_msprinter_frame_plist = Qnil; 1176 Vdefault_msprinter_frame_plist = Qnil;
1230 1177