OOFILE  1.9
oofGrPP.cpp
Go to the documentation of this file.
1 // ===========================================================================
2 // oofGrWin.cp
3 // ===========================================================================
4 //
5 
6 
7 #ifndef H_OOFGRPHS
8  #include "oofGrphs.h"
9 #endif
10 #ifndef H_OOFGRWIN
11  #include "oofGrPP.h"
12 #endif
13 
20 #include <PP_Macros.h>
21 #if !defined(__PowerPlant__) || __PowerPlant__ < 0x02118000
22  #define OOF_PRECARBON_PP_PRINTING
23 #endif
24 
25 #ifndef H_OOFPLOTPANE
26  #include "CPlotPane.h"
27 #endif
28 #ifndef _H_LApplication
29  #include <LApplication.h>
30 #endif
31 #ifndef _H_LGrowZone
32  #include <LGrowZone.h>
33 #endif
34 #ifndef _H_UDrawingState
35  #include <UDrawingState.h>
36 #endif
37 #ifndef _H_UMemoryMgr
38  #include <UMemoryMgr.h>
39 #endif
40 #ifndef _H_URegistrar
41  #include <URegistrar.h>
42 #endif
43 #ifndef _H_UDesktop
44  #include <UDesktop.h>
45 #endif
46 #ifdef OOF_PRECARBON_PP_PRINTING
47  #ifndef _H_UPrintingMgr
48  #include <UPrintingMgr.h>
49  #endif
50 #else
51  #ifndef _H_UPrinting
52  #include <UPrinting.h>
53  #endif
54 #endif
55 #ifndef _H_LStream
56  #include <LStream.h>
57 #endif
58 #ifndef _H_LPrintout
59  #include <LPrintout.h>
60 #endif
61 #ifndef _H_LPlaceHolder
62  #include <LPlaceHolder.h>
63 #endif
64 #ifndef __SCRAP__
65  #include <Scrap.h>
66 #endif
67 #ifndef _H_PP_Messages
68  #include <PP_Messages.h>
69 #endif
70 #ifndef _H_LString
71  #include <LString.h>
72 #endif
73 
74 #ifdef OOF_MEM_DEBUG_LAST_INCLUDE
75  #include OOF_MEM_DEBUG_LAST_INCLUDE
76 #endif
77 
78 #ifndef OOF_NO_STDLIB
79  #ifndef std
80  using namespace std;
81  #endif
82 #endif
83 
84 #define PPob_WIND_Graph 29003
85 #define PPob_PANE_Plot 301
86 
87 // ---------------------------------------------------------------------------
88 // oofGraphWindow
89 // ---------------------------------------------------------------------------
90 
91 // Register the functions to create our custom Pane classes
92 void
94 {
95  URegistrar::RegisterClass(oofGraphWindow::class_ID, (ClassCreatorFunc)oofGraphWindow::CreateFromStream);
96  URegistrar::RegisterClass(CPlotPane::class_ID,(ClassCreatorFunc)CPlotPane::CreatePlotPaneStream);
97 
98 // standard PowerPlant classes
99 #if (__MWERKS__ >= 0x2000)
100 // Assume later compiler implies PowerPlant 1.8 or above
101  RegisterClass_(LWindow);
102  RegisterClass_(LPrintout);
103  RegisterClass_(LPlaceHolder);
104 #else
105 // Older PowerPlant
106  URegistrar::RegisterClass(LWindow::class_ID, (ClassCreatorFunc)LWindow::CreateWindowStream);
107  URegistrar::RegisterClass(LPrintout::class_ID, (ClassCreatorFunc)LPrintout::CreatePrintoutStream);
108  URegistrar::RegisterClass(LPlaceHolder::class_ID, (ClassCreatorFunc)LPlaceHolder::CreatePlaceHolderStream);
109 #endif
110 }
111 
112 
113 //----------
114 // The read-from-stream constructor just reads a window object.
116  LStream *inStream)
117  : LWindow(inStream)
118 {
119 }
120 
121 // UReanimator factory
124 {
125  return new oofGraphWindow(inStream);
126 }
127 
128 
129 // Destructor
131 {
132  delete mGraphPtr;
133 }
134 
135 
136 // Common Factory
139  LCommander* inSuperCommander,
140  oofGraph* inGraphPtr,
141  dbView *theView,
142  const char* theTitle,
143  unsigned long AxisLength)
144 {
145  oofGraphWindow* displayWindow = ((oofGraphWindow *)LWindow::CreateWindow(PPob_WIND_Graph, inSuperCommander));
146  LStr255 windowName(theTitle);
147  displayWindow->SetDescriptor(windowName);
148  displayWindow->mGraphPtr = inGraphPtr;
149 
150 // MUST FocusDraw AND SetPortFont() to ensure an environment in which we can measure text
151  displayWindow->FocusDraw();
152  //let's find our pane..
153  CPlotPane *PlotView = (CPlotPane *) displayWindow->FindPaneByID(PPob_PANE_Plot);
154  PlotView->SetPortFont();
155 
156 
157  Rect theFrame;
158  PlotView->CalcLocalFrameRect( theFrame );
159  inGraphPtr->setPaneRect( theFrame );
160  inGraphPtr->finishConstruction(theView, theTitle, AxisLength);
162  inGraphPtr->setDrawStyles( tempIter /*oofDrawStyleSetDefaultIteration()*/);
163 
164  PlotView->SetGraph(inGraphPtr);
165 
166  displayWindow->Show();
167  return displayWindow;
168 }
169 
170 
171 //-- Printing Stuff--
172 
173 #define PPob_Prto_PictText 29004 // Printout for printing the scrolling view
174 #define PPob_place_PictText 911 // Placeholder for the main body
175 
176 void
178 {
179  UDesktop::Deactivate();
180 #ifdef OOF_PRECARBON_PP_PRINTING
181  Boolean wantToPrint = UPrintingMgr::AskPrintJob(UPrintingMgr::GetDefaultPrintRecord());
182 #else
183  Boolean wantToPrint = UPrinting::AskPrintJob(UPrinting::GetAppPrintSpec());
184 #endif
185 
186  UDesktop::Activate();
187 
188  if (!wantToPrint)
189  return; // USER CANCELLED PRINT
190 
191  // set graph to mono
193 
194  // Read the Printout resource and find the place
195  // holders for the scrolling view.
196 
197  LPrintout *thePrintout = LPrintout::CreatePrintout(PPob_Prto_PictText);
198  LPlaceHolder *thePlace = (LPlaceHolder*) thePrintout->FindPaneByID(PPob_place_PictText);
199 
200  // Now find the view in this window
201  // and install it into its place holder.
202 
203  LView *theView = (LView *) FindPaneByID(PPob_PANE_Plot);
204  thePlace->InstallOccupant(theView, kAlignAbsoluteCenter);
205 
206  // This is the function that starts the printing.
207 
208  thePrintout->DoPrintJob();
209 
210  // The Printout's destructor takes care of setting the
211  // views back to where they came from.
212 
213  delete thePrintout;
214 
216 }
217 // Respond to commands
218 
219 Boolean
221  CommandT inCommand,
222  void *ioParam)
223 {
224  Boolean cmdHandled = true;
225 
226  switch (inCommand) {
227 
228  // +++ Add cases here for the commands you handle
229  // Remember to add same cases to FindCommandStatus below
230  // to enable/disable the menu items for the commands
231 
232  case cmd_PageSetup:
233  DoPageSetup();
234  break;
235 
236  case cmd_Print:
237  DoPrint();
238  break;
239 
240  case cmd_Copy:
241  CopyToScrap();
242  break;
243 
244  default:
245  cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
246  break;
247  }
248 
249  return cmdHandled;
250 }
251 
252 
253 // Pass back status of a (menu) command
254 
255 void
257  CommandT inCommand,
258  Boolean &outEnabled,
259  Boolean &outUsesMark,
260  UInt16 &outMark,
261  Str255 outName)
262 {
263  switch (inCommand) {
264 
265  case cmd_Print:
266  case cmd_PageSetup:
267  case cmd_Copy:
268  outEnabled = true;
269  break;
270 
271  default:
272  LWindow::FindCommandStatus(inCommand, outEnabled, outUsesMark,
273  outMark, outName);
274  break;
275  }
276 }
277 
278 
279 
280 // copied from LDocApplication
281 void
283 {
284  UDesktop::Deactivate();
285 #ifdef OOF_PRECARBON_PP_PRINTING
286  UPrintingMgr::AskPageSetup(UPrintingMgr::GetDefaultPrintRecord());
287 #else
288  const Boolean wantToPrint = UPrinting::AskPageSetup(UPrinting::GetAppPrintSpec());
289 #endif
290  UDesktop::Activate();
291 }
292 
293 
298 void
300 {
301  FocusDraw();
302 
303  // Get our Frame Rectangle
304  CPlotPane *PlotView = (CPlotPane *) FindPaneByID(PPob_PANE_Plot);
305  Rect theFrame;
306  PlotView->CalcLocalFrameRect(theFrame);
307 
308  ClipRect(&theFrame);
309  PicHandle hPic = ::OpenPicture(&theFrame);
310  mGraphPtr->draw();
311  ::ClosePicture();
312 #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON!=0
313 
314  OSStatus lErr = ::ClearCurrentScrap ();
315  assert(!lErr);
316  ScrapRef scrap;
317  lErr = ::GetCurrentScrap (&scrap);
318  assert(!lErr);
319  ::HLock((Handle)hPic);
320  OSStatus pSErr = ::PutScrapFlavor (scrap, kScrapFlavorTypePicture, kScrapFlavorMaskTranslated ,GetHandleSize((Handle)hPic),*hPic);
321 
322 #else
323 
324  OSErr lErr=::ZeroScrap();
325 
326  assert(!lErr);
327 
328  ::HLock((Handle)hPic);
329  ::PutScrap(GetHandleSize((Handle)hPic),'PICT',*hPic); // Copy the PICT to the scrap !
330 #endif
331  ::HUnlock((Handle)hPic);
332 
333 // DisposHandle((Handle)hPic);
334 }
335 
336 
337 // ---------------------------------------------------------------------------
338 // BarGraphWindow
339 // ---------------------------------------------------------------------------
342  dbView *theView,
343  const char* theTitle,
344  unsigned long AxisLength)
345 {
346  return CreateWindow(inSuperCommander, new oofBarGraph, theView, theTitle, AxisLength);
347 }
348 
349 
350 // ---------------------------------------------------------------------------
351 // StackedBarGraphWindow
352 // ---------------------------------------------------------------------------
355  dbView *theView,
356  const char* theTitle,
357  unsigned long AxisLength)
358 {
359  return CreateWindow(inSuperCommander, new oofStackedBarGraph, theView, theTitle, AxisLength);
360 }
361 
362 // ---------------------------------------------------------------------------
363 // StackedBarGraphWindowWithOverlay
364 // ---------------------------------------------------------------------------
367  dbView *theView,
368  const char* theTitle,
369  unsigned long NumOverlaid,
370  unsigned long AxisLength)
371 {
372  oofStackedBarGraph* newGraph = new oofStackedBarGraph;
373 
374  newGraph->setOverlaid(NumOverlaid);
375 
376  return CreateWindow(inSuperCommander, newGraph, theView, theTitle, AxisLength);
377 }
378 
379 // ---------------------------------------------------------------------------
380 // StackedBarGraphWindowWithOverlayView
381 // ---------------------------------------------------------------------------
384  dbView *theView,
385  const char* theTitle,
386  dbView *overlayView,
387  unsigned long AxisLength)
388 {
389  oofStackedBarGraph* newGraph = new oofStackedBarGraph;
390 
391  newGraph->setOverlayView(overlayView);
392 
393  return CreateWindow(inSuperCommander, newGraph, theView, theTitle, AxisLength);
394 }
395 
396 // ---------------------------------------------------------------------------
397 // OrdinalStackedBarGraphWindow
398 // ---------------------------------------------------------------------------
401  dbView *theView,
402  const char* theTitle,
403  unsigned long AxisLength)
404 {
405  return CreateWindow(inSuperCommander, new oofOrdinalStackedBarGraph, theView, theTitle, AxisLength);
406 }
407 
408 // ---------------------------------------------------------------------------
409 // ColumnGraphWindow
410 // ---------------------------------------------------------------------------
413  dbView *theView,
414  const char* theTitle,
415  unsigned long AxisLength)
416 {
417  return CreateWindow(inSuperCommander, new oofColumnGraph, theView, theTitle, AxisLength);
418 }
419 
420 
421 // ---------------------------------------------------------------------------
422 // PointGraphWindow
423 // ---------------------------------------------------------------------------
426  dbView *theView,
427  const char* theTitle,
428  unsigned long AxisLength)
429 {
430  return CreateWindow(inSuperCommander, new oofPointGraph, theView, theTitle, AxisLength);
431 }
432 
433 
434 // ---------------------------------------------------------------------------
435 // LineGraphWindow
436 // ---------------------------------------------------------------------------
439  dbView *theView,
440  const char* theTitle,
441  unsigned long AxisLength)
442 {
443  return CreateWindow(inSuperCommander, new oofLineGraph, theView, theTitle, AxisLength);
444 }
445 
446 
447 // ---------------------------------------------------------------------------
448 // XYGraphWindow
449 // ---------------------------------------------------------------------------
452  dbView *theView,
453  const char* theTitle,
454  unsigned long AxisLength)
455 {
456  return CreateWindow(inSuperCommander, new oofXYGraph, theView, theTitle, AxisLength);
457 }
458 
459 // ---------------------------------------------------------------------------
460 // PieChartWindow
461 // ---------------------------------------------------------------------------
464  dbView *theView,
465  const char* theTitle)
466 {
467  return CreateWindow(inSuperCommander, new oofPieGraph, theView, theTitle);
468 }
469 
470 
void DoPrint()
Definition: oofGrPP.cpp:177
Preview window used to show an oofGraph in PowerPlant framework.
Definition: oofGrMfc.h:19
Graph of oofGeoPoint arbitrary points from XY data, no assumptions of order.
Definition: oofGrphs.h:234
Circular graph of oofGeoSector wedge-like pieces.
Definition: oofGrphs.h:325
void setStyleToColor()
Definition: oofGrphs.cpp:183
Graph of oofGeoBar horizontal bars where each series is percentage of one bar, all same length...
Definition: oofGrphs.h:305
virtual Boolean ObeyCommand(CommandT inCommand, void *ioParam=nil)
Definition: oofGrPP.cpp:220
static void RegisterClass()
Definition: oofGrPP.cpp:93
Graph of oofGeoBar horizontal bars where each point in series is percentage of one bar...
Definition: oofGrphs.h:282
static oofGraphWindow * CreatePieChartWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle)
Definition: oofGrPP.cpp:463
Graph of oofGeoBar horizontal bars.
Definition: oofGrphs.h:259
void setPaneRect(Rect inRect)
Definition: oofGrphs.cpp:105
Macintosh structure for a rectangle.
void CopyToScrap()
Put graph in clipboard as PICT.
Definition: oofGrPP.cpp:299
static oofGraphWindow * CreateStackedBarGraphWindowWithOverlay(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long NumOverlaid, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:366
static oofGraphWindow * CreateOrdinalStackedBarGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:400
Graph of oofGeoColumn vertical bars.
Definition: oofGrphs.h:163
void DoPageSetup()
Definition: oofGrPP.cpp:282
static oofGraphWindow * CreatePointGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:425
void draw()
Definition: oofGrphs.cpp:81
void setDrawStyles(oofDrawStyleSet &)
Definition: oofGrphs.cpp:120
Graph class subclassed to draw different graph types.
Definition: oofGrphs.h:71
PowerPlant base for anything that handles commands.
static oofGraphWindow * CreateFromStream(LStream *)
Definition: oofGrPP.cpp:123
Graph of oofGeoPoint individual points.
Definition: oofGrphs.h:184
static oofGraphWindow * CreateLineGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:438
PowerPlant base class for scrollable, resizable window.
Provide an iterable set of fields.
Definition: oofview.h:26
virtual void SetGraph(oofGraph *theGraph)
Definition: CPlotPane.cpp:95
Common set generator generates well-distributed colours.
Definition: oofDStyl.h:131
static oofGraphWindow * CreateWindow(LCommander *inSuperCommander, oofGraph *inGraphPtr, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:138
virtual void finishConstruction(dbView *, const char *theTitle, unsigned long yAxisHeight)=0
virtual ~oofGraphWindow()
Definition: oofGrMFC.cpp:88
Graph of oofGeoLine connected points.
Definition: oofGrphs.h:209
PowerPlant base class for scrollable display.
static oofGraphWindow * CreateStackedBarGraphWindowWithOverlayView(LCommander *inSuperCommander, dbView *theView, const char *theTitle, dbView *overlayView, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:383
static CPlotPane * CreatePlotPaneStream(LStream *inStream)
Definition: CPlotPane.cpp:25
oofGraph * mGraphPtr
Definition: oofGrPP.h:35
void setOverlayView(dbView *clonedView)
will become adoptedView in future
Definition: oofGrphs.cpp:288
void setStyleToMono()
Definition: oofGrphs.cpp:176
static oofGraphWindow * CreateXYGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:451
Pane for embedding in a Mac window that draws an oofGraph.
Definition: CPlotPane.h:19
#define PPob_Prto_PictText
Definition: oofGrPP.cpp:173
static oofGraphWindow * CreateStackedBarGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:354
#define PPob_WIND_Graph
Definition: oofGrPP.cpp:84
static oofGraphWindow * CreateBarGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:341
static oofGraphWindow * CreateColumnGraphWindow(LCommander *inSuperCommander, dbView *theView, const char *theTitle, unsigned long AxisLength=0)
Definition: oofGrPP.cpp:412
void SetPortFont()
Definition: CPlotPane.cpp:125
virtual void FindCommandStatus(CommandT inCommand, Boolean &outEnabled, Boolean &outUsesMark, UInt16 &outMark, Str255 outName)
Definition: oofGrPP.cpp:256
#define PPob_PANE_Plot
Definition: oofGrPP.cpp:85
void setOverlaid(unsigned long numOverlaid)
Definition: oofGrphs.cpp:281
#define PPob_place_PictText
Definition: oofGrPP.cpp:174