Thursday, August 11, 2005

The ReportPreview.app is a pretty good general preview application for Visual FoxPro 9. The look of it mimics the report preview screen we had prior to Visual FoxPro 9 and it provides much of the same functionality as well as some new features available in Visual FoxPro 9 thrown in for good measure. However, some Visual FoxPro developers are having problems with certain aspects of it.

Running ReportPreview.app as a modal preview (report form command) in a TopLevel form application will cause the print preview toolbar to stop responding. That's because the ReportPreview.app brings the preview form up in a modal state and toolbars are not accessible when a modal form is active. For the most part, this is as it should be and is in-line with Microsoft Windows conventions. The answer is to include the NOWAIT clause in the report form command or you can modify the ReportPreview.pjx to force it into a modeless state when this situation occurs. Easy enough right? Well, the problem with this approach is it usually defeats the very thing that the developer is attempting to do... mainly, bring up a modal preview window in a TopLevel application (I want the preview window to come up, then I want to wait until the user has released the preview window before continuing with my code execution).

If you haven't run into the aforementioned problem you can reproduce it by opening up the Taskpane in Visual FoxPro and go to the Solutions Samples area. Then expand the "New in Visual FoxPro 9.0" node and look for the "The typical multiple detail band report" sample. Over on the right-hand side of the sample there is a little report and magnifying glass button that says "Click here to view the code" in its tooltip, click that button. Next modify the ShowWindow property of the form that pops up (ShowWindow = 2 - As Top-Level Form). Close the form and save your changes, then run the sample. You'll notice that the toolbar does not respond to user events. To close the sample you'll have to close the report from the "X" in the top right corner of the preview window.

Another thing about the ReportPreview.app is that it looks a little antiquated to me. I may be the only one that feels this way, but I suspect not. Now, before the flames start... I'm not saying that I don't think the MS Fox Team didn't do a good job. I'm all for having them just give us access and allow us, as seasoned Visual FoxPro developers, develop the rest. I don't want them wasting time mocking up Visual FoxPro forms and applications that I can create myself. I feel like we are all well served by them opening the guts of Visual FoxPro up to us as developers, give a basic example of the new feature's use, and then let us do the rest.

So, last night I decided to rip into the ReportPreview.pjx and see what I could do. I made an exact copy of the entire Report Preview project folder from XSource and then began modifying it. Basically keeping the stuff I liked, deleting the stuff I didn't, and modifying the rest. The result was a ReportPreviewEx.app that can be used in lieu of the ReportPreview.app. To use it you'll need to set the _reportpreview system variable to the new application:

_reportpreview = "reportpreviewex.app"

This will cause Visual FoxPro to use the new print preview application. To try it out run one of the report samples in the Solutions Samples area of the Taskpane underneath the "New in Visual FoxPro 9.0" node. The names of the samples are "A multiple detail band report used for calculations" and "The typical multiple detail band report".

This new application doesn't suffer from some of the drawbacks the ReportPreview.app does. For instance, instead of toolbar, I placed the buttons and such directly on the frxpreviewform class. This fixes the problem with modal previews in a TopLevel application and is more in-line with print preview windows such as the one in Internet Explorer.

I ran into more than a few issues while creating this, but almost all of them have been resolved successfully. However, one issue that is still plaguing me is the way the MS Fox Team failed to implement double-buffering correctly when rendering emf content in an image control. Emf file format is perfect for reports because meta-files scale better than anything else on the planet. But, when you are running the print preview you are going to see a slight flicker. Regrettably the MS Fox Team has not opened up the internal painting routines to us, so I am unable to insert the proper code that should be used when Visual FoxPro is repainting the image controls. That having been said, I added a property to the frxpreviewform form class of the frxpreview.vcx that allows you to try out all the other formats and their results. The property is "outputimagetype" and has the following possible values: tiff, bmp, png, jpeg, gif, emf. If you want to try another format that doesn't have the flicker and still has perhaps acceptable quality, change the property to "png". The drawback to this format is that it looks blurry at large zoom levels and Visual FoxPro turns into a bit of a performance hog with its internal painting routines.

I posted a comment on Calvin Hsia's blog recently asking him to pull the curtain back further on the internal painting routines for Visual FoxPro, and I've asked other members of the Fox Team in the past to please give us a little insight into this so we can address issues such as this effectively and help Microsoft out a little at the same time. Regrettably, they have ignored me so far. I wish that their new goal of transparency extended towards the Visual FoxPro core as well. I understand that they have trade secrets/intellectual property rights to consider, but I think they could use some help in this particular area.

Now some of you are no doubt thinking, why didn't Craig just use the outputpage method of the Report Listener class to render to a canvas object (shape or container control). The reason is that Visual FoxPro will paint right over the top of anything that gets in the way of the canvas object. So, if you have a bunch of canvas objects inside a container and you are allowing the canvas objects to be slid around inside the container so that portions of them are outside the dimensions of the visible container (left = -150 or top = -200 or whatever), the Report Listener doesn't respect the container's borders, so it starts rendering the report right over the top of other form elements. So, the answer is to use an image control and temporary off-screen bitmaps assigned to their picture property. Why not a container (it has a picture property)? Well with the image control I pick up a little more overhead, but it gives me some really good additional functionality for free (such as the stretch property that makes zooming in and out on print preview a breeze from a coding standpoint). There's more to this whole sorted saga, but I think you get the general idea.

So, here's a screen capture of the new print preveiw, a link to download the ReportPreviewEx.app, and an additional link to download the entire source -- IMPORTANT NOTE: I've just looked through the redist.txt that comes with Visual FoxPro and I cannot find anywhere that certain elements of the ReportPreview.pjx are on the allowable list - I will email Microsoft for clarification - until I hear back from them, I have removed the source code link.

Download ReportPreviewEx Application (approx. 47 KB)

ReportPreviewEx Application Screen Capture

Thursday, August 11, 2005 9:47:12 PM (Central Daylight Time, UTC-05:00)  #    Comments [9]
Saturday, August 13, 2005 4:46:21 AM (Central Daylight Time, UTC-05:00)
Craig, nice post, and wonderful job on the EX version of ReportPreview.App. It's great to see creative work like this that builds on the ReportPreview source code, inspired in part from fruitful discussions such as we've had on the Universal Thread.

I feel inspired, in turn, to respond to a few of the things you have said here:

>> Running ReportPreview.app as a modal preview
>> in a TopLevel form application will cause the
>> print preview toolbar to stop responding.
>> That's because the ReportPreview.app brings
>> the preview form up in a modal state and
>> toolbars are not accessible when a modal form
>> is active.

Only when it is a child of a topform window. This is actually a _bug_ in the product. I hope it gets fixed in SP1.

>> If you haven't run into the aforementioned problem
>> you can reproduce it by [..]

People can also download a simple repro example (that is independent of the reporting apps) from www.spacefold.com/colin/archive/articles/reportpreview/repro.prg.

>> Another thing about the ReportPreview.app is that
>> it looks a little antiquated to me. I may be the
>> only one that feels this way, but I suspect not.

The requirement of the first-ever Xbase preview in VFP to match the old one as close as possible is defensible. Can you imagine the firestorm if the preview looked and behaved substantially different from previous versions? Every developer would be picking over the design decisions because the single most important feature they needed was omitted... or complaining because their KEYBOARD'd keypresses on preview startup, and their other favorite tricks, no longer worked.

Given the multitude of conditions and clauses that the preview *had to* support (Topforms, IN WINDOW, WINDOW, ACTIVATE, NOWAIT, etc) it's a miracle that it works as similarly to the old preview as it does.

Lucky for VFP developers, when we create our own apps, we have no such constraints. I look forward, as I'm sure you do also, to seeing what everybody comes up with that fits their own needs and doesn't have to be a "one size fits all" solution.

Perhaps the Sedna timeframe will give the VFP Team the luxury to provide additional solutions as well.

>> This new application doesn't suffer from some of the
>> drawbacks the ReportPreview.app does.

Not counting the modal-in-topform bug, what drawbacks are you talking about? (The fact that it doesn't look like IE's is not a drawback. Neither does OneNote's preview.)

>> why didn't Craig just use the outputpage method
>> of the Report Listener class to render to a
>> canvas object (shape or container control).
>> The reason is that Visual FoxPro will paint
>> right over the top of anything that gets in
>> the way of the canvas object.

Actually, this limitation does not exist! Rather than explain here, you may want to read an article where I describe how to implement an alternative preview UI with a shape that does what you wanted without the overhead you incurred. (See www.spacefold.com/colin/archive/articles/reportpreview/techniques.htm.)

Anyway, regards and thanks again for a very interesting post!
Sunday, August 14, 2005 12:59:15 AM (Central Daylight Time, UTC-05:00)
Hi Colin,

Thanks for stopping by my blog, for the amazing article regarding print preview in Visual FoxPro, and for the additional repro code. That article is a must read for anyone wanting to further their knowledge in that area. Here are my responses to various points in your above comment.

"Only when it is a child of a topform window. This is actually a _bug_ in the product. I hope it gets fixed in SP1."

Not exactly sure how a developer would create a modal preview in a TopLevel form application without having it be a child of a topform window.

I agree with your assertions defending the ReportPreview implementation being close to the look and functionality in previous versions of Visual FoxPro. I don't think it would have hurt to toss in some updated icons, but that's a minor point.

"Not counting the modal-in-topform bug, what drawbacks are you talking about?"

There are a few... bringing up a multi-page report in one-up view then using the pagedown key to the very end, then switching to 4-up view will not show 4 pages and also creates a big black rectangle at the bottom of the viewport (bug in the viewport code in Visual FoxPro). Also, when viewing at a larger xoom where the 4-up and 2-up are disabled... the "2" and "4" keys on the keyboard will still access these disabled items... even the context menu has the disabled page items selected and checked.

"The fact that it doesn't look like IE's is not a drawback. Neither does OneNote's preview."

It was not my intention to hold the IE preview up as the standard by which all others should live by. I can see how I gave that impression though. It was merely a print preview window that didn't use a toolbar, but instead had the controls right on the window... like what I was doing.

Lastly, I really appreciate the heads-up on the clip parameters being documented incorrectly. This will be incorporated in my next version of the ReportPreviewEx.app. I have a long way to go and only spent a few hours on what I have now... so more to come. Thanks again for stopping by Colin - I've really enjoyed our conversations regarding the print preview in Visual FoxPro and sure wish I had seen your article before I created the ReportPreviewEx... it would have saved me some time. Also, if you're not blogging yet, you should.



Sunday, August 14, 2005 3:08:19 AM (Central Daylight Time, UTC-05:00)
>> when viewing at a larger xoom where the 4-up
>> and 2-up are disabled... the "2" and "4" keys on
>> the keyboard will still access these disabled
>> items... even the context menu has the disabled
>> page items selected and checked.

Wow. This is a bug I didn't know about! I know it's minor but we should see about getting this fixed in SP1. Thanks!
Friday, September 16, 2005 8:19:21 PM (Central Daylight Time, UTC-05:00)
Hola, he tratado de colocar en uso la aplicacion y no he podido, me gustaria si pueden enviarme un projecto sencillo para probarlo?

Agradezco su colaboracion
Thursday, January 12, 2006 6:13:41 AM (Central Standard Time, UTC-06:00)
I have a problem to try printing selected pages!
When I preview pages in shapes classe vfp (MyReportObject.OutputPage(m.NumberPage, .oPreviewContainer, 2)) - is work!
How I can print the chosen pages with use OutputPage(;
nPageNo, ;
eDevice, ;
nDeviceType ;
[,nleft, nTop, nWidth, nHeight ;
[,nClipLeft,nClipTop, nClipWidth, nClipHeight]])
I believe, that:
nDeviceType = 0 for PRINT DEVICE
eDevice = ?????
Best Regards, Aleksey
Friday, May 19, 2006 7:52:14 PM (Central Daylight Time, UTC-05:00)
Preview with the Data session window open and you'll see the report.app's data session. Thanks for clarifying that this is a new app - I was wondering why the new data session was being referenced on the fly.
Craig Roberts
Thursday, June 22, 2006 6:56:59 PM (Central Daylight Time, UTC-05:00)
Hi Craig -- great design on this preview app (great discussion as well). Any chance the source code is still available?
Friday, June 29, 2007 4:45:51 PM (Central Daylight Time, UTC-05:00)
Hi Craig,

Since MS released all the XSource, I think that we can distribute source files.

Regards

Cesar
Friday, September 07, 2007 2:49:54 PM (Central Daylight Time, UTC-05:00)
Hey Craig,

Have you been able to get permission from MS to distribute your source code for your report previewer?
MikeS
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):


 

Archive

<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456