OOFILE  1.9
oofRepPreviewPP.cpp
Go to the documentation of this file.
1 #ifndef H_OOFREPWIN
2  #include "oofRepPPWindow.h"
3 #endif
4 #ifndef REPMACGUIPREVPP
5  #include "oofRepPreviewPP.h"
6 #endif
7 #include <Fonts.h>
8 
9 
10 // -------------------------------------------------------
11 // o o f R e p M a c G U I P r e v i e w P P
12 // -------------------------------------------------------
13 
14 
16  mPICTs(0),
17  mCommander(0)
18 
19 {
20 #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON!=0
21 
22  mFlatFormat = 0;
23  mFlatSettings = 0;
24 #endif
25 }
26 
27 void
29 {
30  assert(!mPICTs);
31  mPICTs = inPICTs;
32  pageSetup(inPageSetup);
33 }
34 
35 
37 {
38  if (mPrintRecordH)
39  ::DisposeHandle((Handle)mPrintRecordH); // kept until dtor in case redrawn
40 #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON!=0
41 
42  if(mFlatFormat)
43  ::DisposeHandle((Handle)mFlatFormat);
44  if(mFlatSettings)
45  ::DisposeHandle((Handle)mFlatSettings);
46 #endif
47 }
48 
49 
50 void
52 {
53 // NOTE calcPageHeight is called earlier
54  ::MoveTo(0,0);
55 }
56 
57 
58 void
60 {
61  ::ClosePicture();
62  // SHould we actually make sure that the page is ended by the report
63  // and hence this is an empty picture ?
64  assert(mPICTs); // guard against partial init
65  mPICTs->Add(mCurPagePICT); // This makes a copy
66  ::KillPicture(mCurPagePICT);
67  ::SetPort(mSavedPort);
68 }
69 
70 
71 void
73 {
74  // NOTE: Due to the use of ClosePicture() - This routine MUST be called exactly
75  // once for each page generated !
76  ::ClosePicture();
77  mPICTs->Add(mCurPagePICT); // This makes a copy
78  ::KillPicture(mCurPagePICT);
79  // Make a fresh PICT
80  ::HLock((Handle)mPrintRecordH);
81  TPrint tPr=**mPrintRecordH;
82  ::ClipRect(&mPaperRect); // Important: set clipRgn
83  mCurPagePICT=::OpenPicture(&mPaperRect);
84  ::HUnlock((Handle)mPrintRecordH);
85 
86  // Frame the printable area, useful in debugging and maybe later option
87  // may need to be called like this in CalcPageHeight as well
88 /* {
89  Rect printableArea=tPr.prInfo.rPage;
90  ::OffsetRect(&printableArea,mOffset.h,mOffset.v);
91  ::FrameRect(&printableArea);
92  }
93 */
94 
95  ::MoveTo(0,0);
96 }
97 
98 
99 void
101 {
102  if (S) {
103  /* short leading, unsigned char styleNum */
104  Str255 pFontName;
105  pFontName[0]=strlen(S->fontName());
106 
107  memcpy(&pFontName[1],S->fontName(),pFontName[0]);
108  #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON!=0
109  FMFontFamily theFontFamily;
110  theFontFamily =::FMGetFontFamilyFromName (pFontName);
111  ::TextFont(theFontFamily);
112  #else
113  short fontNo;
114  ::GetFNum(pFontName,&fontNo);
115  ::TextFont(fontNo);
116  #endif
117  ::TextSize(S->fontSize());
118  ::TextFace(S->fontStyle());
119  ::RGBForeColor(S->color());
120  }
121 }
122 
123 
124 unsigned short
126 {
127  changeTextStyle(theStyle);
128  FontInfo fi;
129  ::GetFontInfo(&fi);
130 
131  return (fi.ascent+fi.descent+fi.leading) + theStyle->leading();
132 }
133 
134 
135 /*void
136 oofRepMacGUIPreviewPP::moveToVerticalPos(unsigned long pos)
137 {
138  ::MoveTo(0,pos);
139 }
140 */ // See comments in oofRepEnvironment
141 
142 //=-=-=-=-=-
143 #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON!=0
144 unsigned long
146 {
147 
148  ::GetPort(&mSavedPort);
149  if(!mPrintRecordH){
150  PMPrintSettings settings = kPMNoPrintSettings; ; // why do i have to do this
151  PMPageFormat format = kPMNoPageFormat; ;
152  //PMPrintContext printContext;
153  //Boolean accepted;
154 
155  OSStatus begErr = ::PMBegin();
156  OSStatus err = ::PMNewPrintSettings(&settings);
157  OSStatus defErr = ::PMDefaultPrintSettings(settings);
158  OSStatus seterr = ::PMSetLastPage (settings,kPMPrintAllPages,false);
159  OSStatus newFErr = ::PMNewPageFormat (&format);
160  OSStatus newPFrr = ::PMDefaultPageFormat(format);
161  assert(!begErr&&begErr!=kPMGeneralError);// TODO - Handle errors
162  OSStatus makeorecErr = ::PMMakeOldPrintRecord (settings,format,(char***)&mPrintRecordH);
163  OSStatus dsipErr = ::PMDisposePageFormat (format);
164  dsipErr = ::PMDisposePrintSettings (settings);
165  begErr = ::PMEnd();
166  //todo add exceptions
167  }
168  ::HLock((Handle)mPrintRecordH);
169  TPrint tPr=**mPrintRecordH;
170  mOffset.h=-tPr.rPaper.left;
171  mOffset.v=-tPr.rPaper.top;
172  mPaperRect=tPr.rPaper;
173  ::OffsetRect(&mPaperRect,mOffset.h,mOffset.v);
174  ::ClipRect(&mPaperRect); // Important: set clipRgn
175  mCurPagePICT=::OpenPicture(&mPaperRect);
176  ::HUnlock((Handle)mPrintRecordH);
177 
178  return mPaperRect.bottom-mPaperRect.top;
179 }
180 
181 #else
182 
183 
184 unsigned long
186 {
187 
188  ::GetPort(&mSavedPort);
189 #ifdef OOF_PRECARBON_PP_PRINTING
190  if(!mPrintRecordH) {
191  // Get the default print record - for pagesizing, etc.
192  mPrintRecordH=UPrintingMgr::CreatePrintRecord();
193  if (!mPrintRecordH) {
194  dbConnect::raise("Unable to get printer details - please select a printer in the Chooser", false);
195  mPaperRect = oofRect(0,0,0,0);
196  return 0; //**** early exit - failed to get height
197  }
198  }
199 #else
200  StPrintSession Session(UPrinting::GetAppPrintSpec());
201  LPrintSpec& theSpec = UPrinting::GetAppPrintSpec();
202  if(!mPrintRecordH) {
203  mPrintRecordH = (THPrint)theSpec.GetPrintRecord(); //we take ownership of the handle
204  if (!mPrintRecordH) {
205  dbConnect::raise("Unable to get printer details - please select a printer in the Chooser", false);
206  mPaperRect = oofRect(0,0,0,0);
207  return 0; //**** early exit - failed to get height
208  }
209  }
210 #endif// OOF_PRECARBON_PP_PRINTING
211  // Make a fresh PICT
212  ::HLock((Handle)mPrintRecordH);
213  TPrint tPr=**mPrintRecordH;
214  mOffset.h=-tPr.rPaper.left;
215  mOffset.v=-tPr.rPaper.top;
216  mPaperRect=tPr.rPaper;
217  ::OffsetRect(&mPaperRect,mOffset.h,mOffset.v);
218  ::ClipRect(&mPaperRect); // Important: set clipRgn
219  mCurPagePICT=::OpenPicture(&mPaperRect);
220  ::HUnlock((Handle)mPrintRecordH);
221 
222  return mPaperRect.bottom-mPaperRect.top;
223 }
224 
225 #endif
226 
227 
228 
229 unsigned long
231 {
232  return mPaperRect.right-mPaperRect.left;
233 }
234 
235 
236 unsigned long
238 {
239  if (!mPICTs)
240  return 0;
241  else
242  return mPICTs->recordNumber();
243 }
244 
245 #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON!=0
246 
247 Handle
248 oofRepMacGUIPreviewPP::getFlatSettings( ) // caller owns the handle
249 {
250  Handle settings = nil;
251 
252 
253  if (mFlatSettings)
254  settings = mFlatSettings;
255  ::HLock(mFlatFormat);
256  OSErr memErr = ::HandToHand(&settings);
257  ::HUnlock(mFlatFormat);
258 
259  return settings;
260 
261 }
262 
263 
264 Handle
265 oofRepMacGUIPreviewPP::getFlatFormat( ) // caller owns handle
266 {
267 
268  Handle format = nil;
269 
270  if (mFlatFormat)
271  format = mFlatFormat;
272  ::HLock(mFlatFormat);
273  OSErr memErr = ::HandToHand(&format);
274  Size howbigS = ::GetHandleSize (format);
275  Size howbigSMem = ::GetHandleSize (mFlatFormat);
276  ::HUnlock(mFlatFormat);
277  return format;
278 }
279 
280 
281 Handle
282 oofRepMacGUIPreviewPP::getOldRecord( ) // caller owns the handle
283 {
284 
285 
286  Handle record = nil;
287  record = (char**)mPrintRecordH;
288  OSErr memErr = ::HandToHand(&record);
289  return record;
290 
291 }
292 #endif // Carbon
unsigned long previewPageOrdinal() const
returns ordinal number, NOT the printable page number which may reset
Cross-platform way to specify rectangle with Mac-style setter.
Definition: oofRect.h:39
unsigned char fontStyle() const
Definition: oofrep.h:2556
virtual unsigned long calcPageWidth()
static void raise(std::ostream &, bool terminateAfterMsg=true)
short leading() const
Definition: oofrep.h:2563
unsigned long recordNumber() const
Ordinal record number of current record in selection.
Definition: oof1.h:2041
virtual void endEnvironment()
void finishConstruction(dbRepPICTs *PICTs, THPrint pageSetup=nil)
GrafPtr mSavedPort
Definition: oofrepMac.h:78
dbTable used by oofRepMacGUIPreviewPP to store database of PICTs.
THPrint pageSetup() const
Definition: oofrepMac.h:60
unsigned short fontSize() const
Definition: oofrep.h:2548
virtual void drawPageBreak()
const oofString & fontName() const
Definition: oofrep.h:2540
virtual void startEnvironment()
virtual unsigned long calcPageHeight()
THPrint mPrintRecordH
Definition: oofrepMac.h:77
const oofColor & color() const
Definition: oofrep.h:2570
Cross-platform specification of text style.
Definition: oofrep.h:732
virtual void changeTextStyle(oofRepTextStyle *)
virtual unsigned short heightOfTextStyle(oofRepTextStyle *)